1 /*--------------------------------------------------------------------
2  *
3  *   Copyright (c) 1999-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU Lesser General Public License as published by
7  *   the Free Software Foundation; version 3 or any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *   GNU Lesser General Public License for more details.
13  *
14  *   Contact info: www.soest.hawaii.edu/wessel
15  *--------------------------------------------------------------------*/
16 /*
17  * SPOTTER.H: Include file for programs that link with spotter.a.
18  *
19  * Author:	Paul Wessel, SOEST, Univ. of Hawaii, Honolulu, HI, USA
20  * Date:	19-JUL-2010
21  * Version:	 GMT 5
22  *
23  */
24 
25 /*!
26  * \file spotter.h
27  * \brief Include file for programs that link with spotter.
28  */
29 
30 #define EQ_RAD 6371.0087714
31 #define KM_PR_DEG (EQ_RAD * M_PI / 180.0)
32 #define BIG_CHUNK 65536
33 #define T_2_PA	250.0
34 #define PA_2_T  (1.0 / T_2_PA)
35 #define SQRT_CHI2 2.44774689322	/* This is sqrt (Chi^2) for 95% and 2 degrees of freedom */
36 
37 /* Latest GPlates rotation model and polygon IDs [Muller 2019] */
38 #define GPLATES_PLATES    "Global_EarthByte_Plate_ID_Table"		/* .txt */
39 #define GPLATES_ROTATIONS "Global_250-0Ma_Rotations_2019_v2"		/* .rot */
40 
41 #define SPOTTER_E_OPT "-E<rottable>|<ID1>-<ID2>|<plon>/<plat>/<prot>[+i]"
42 
43 /*! Structure with info on each Euler (stage) pole */
44 struct EULER {
45 	double lon, lat;		/* Location of Euler pole in degrees */
46 	double lon_r, lat_r;		/* Location of Euler pole in radians */
47 	double t_start, t_stop;		/* Stage beginning and end time in Ma */
48 	double duration;		/* Stage duration in m.y. */
49 	double omega;			/* Rotation in Degrees/m.y. */
50 	double omega_r;			/* Rotation in Radians/m.y. */
51 	double sin_lat, cos_lat;	/* Sine and Cosine of pole latitude */
52 	double C[3][3];			/* Covariance matrix for this rotation */
53 	double k_hat;			/* k_hat uncertainty scale */
54 	double g;			/* g magnitude scale */
55 	double df;			/* Degrees of freedom in the estimate of rotation */
56 	bool has_cov;			/* true if there is a covariance matrix for this R */
57 	unsigned int id[2];		/* The ID numbers for GPlates pairs */
58 };
59 
60 /*! Structure with the nearest nodes for a single flowline */
61 struct FLOWLINE {
62 	uint64_t n;		/* Number of points in this flowline */
63 	uint64_t ij;		/* Node in bathymetry grid where this flowline originated */
64 	uint64_t *node;		/* Nodes in CVA grid covered by this flowline */
65 	unsigned short *PA;	/* Predicted Ages along flowline (t = PI/250, to nearest 0.004 My) */
66 };
67 
68 /*! Structure holding all the information about a hotspot */
69 struct HOTSPOT {
70 	/* Record is lon lat abbrev id [radius toff t_on create fit plot name] */
71         double lon, lat;		/* Current location of hot spot (degrees)*/
72 	char abbrev[4];			/* Max 3-char abbreviation of hotspot name */
73         unsigned int id;		/* Hot spot id flag */
74 	double radius;			/* Uncertainty radius (in km) for hotspot location */
75 	double t_off, t_on;		/* Time interval hotspot was active */
76 	bool create, fit, plot;		/* true if we want to create, fit, or plot hotspot */
77         char name[GMT_LEN64];		/* Full name of hotspot */
78 	/* Secondary (derived) quantities */
79         double x, y, z;			/* Cartesian Current location of hot spot */
80 };
81 
82 struct SPOTTER_ROT {	/* Holds -E information */
83 	bool single;		/* True if given a single finite rotation */
84 	bool invert;		/* True if we should invert the rotation(s) */
85 	char *file;		/* File with rotations, or <ID1>-<ID2> GPlates specification */
86 	double lon, lat, w, age;	/* Single finite rotation, if given */
87 };
88 
89 /* ANSI-C Function prototypes (see spotter.c for details): */
90 
91 EXTERN_MSC void spotter_setrot (struct GMT_CTRL *GMT, struct EULER *e);
92 EXTERN_MSC unsigned int spotter_parse (struct GMT_CTRL *GMT, char option, char *arg, struct SPOTTER_ROT *R);
93 EXTERN_MSC int spotter_stage (struct GMT_CTRL *GMT, double t, struct EULER p[], unsigned int ns);
94 EXTERN_MSC void spotter_rot_usage (struct GMTAPI_CTRL *API);
95 EXTERN_MSC bool spotter_GPlates_pair (char *file);
96 EXTERN_MSC int spotter_init (struct GMT_CTRL *GMT, char *file, struct EULER **p, unsigned int flowline, bool total_out, bool invert, double *t_max);
97 EXTERN_MSC int spotter_hotspot_init (struct GMT_CTRL *GMT, char *file, bool geocentric, struct HOTSPOT **p);
98 EXTERN_MSC int spotter_backtrack  (struct GMT_CTRL *GMT, double xp[], double yp[], double tp[], unsigned int np, struct EULER p[], unsigned int ns, double d_km, double t_zero, unsigned int do_time, double wesn[], double **c);
99 EXTERN_MSC int spotter_forthtrack (struct GMT_CTRL *GMT, double xp[], double yp[], double tp[], unsigned int np, struct EULER p[], unsigned int ns, double d_km, double t_zero, unsigned int do_time, double wesn[], double **c);
100 EXTERN_MSC void spotter_total_to_stages (struct GMT_CTRL *GMT, struct EULER p[], unsigned int n, bool total_rates, bool stage_rates);
101 EXTERN_MSC void spotter_stages_to_total (struct GMT_CTRL *GMT, struct EULER p[], unsigned int n, bool total_rates, bool stage_rates);
102 EXTERN_MSC void spotter_add_rotations (struct GMT_CTRL *GMT, struct EULER a[], int n_a, struct EULER b[], int n_b, struct EULER *c[], unsigned int *n_c);
103 EXTERN_MSC double spotter_t2w (struct GMT_CTRL *GMT, struct EULER a[], unsigned int n, double t);
104 EXTERN_MSC bool spotter_conf_ellipse (struct GMT_CTRL *GMT, double lon, double lat, double t, struct EULER *p, unsigned int np, char conf, bool forward, double out[]);
105 EXTERN_MSC void spotter_matrix_transpose (struct GMT_CTRL *GMT, double At[3][3], double A[3][3]);
106 EXTERN_MSC void spotter_matrix_add (struct GMT_CTRL *GMT, double A[3][3], double B[3][3], double C[3][3]);
107 EXTERN_MSC void spotter_matrix_mult (struct GMT_CTRL *GMT, double A[3][3], double B[3][3], double C[3][3]);
108 EXTERN_MSC void spotter_make_rot_matrix2 (struct GMT_CTRL *GMT, double E[3], double w, double R[3][3]);
109 EXTERN_MSC void spotter_covar_to_record (struct GMT_CTRL *GMT, struct EULER *e, double K[]);
110 EXTERN_MSC void spotter_cov_of_inverse (struct GMT_CTRL *GMT, struct EULER *e, double Ct[3][3]);
111 EXTERN_MSC void spotter_get_rotation (struct GMT_CTRL *GMT, struct EULER *p, unsigned int np, double t, double *lon, double *lat, double *w);
112 EXTERN_MSC void spotter_matrix_to_pole (struct GMT_CTRL *GMT, double T[3][3], double *plon, double *plat, double *w);
113 EXTERN_MSC void spotter_matrix_1Dto2D (struct GMT_CTRL *GMT, double *M, double X[3][3]);
114 EXTERN_MSC void spotter_matrix_2Dto1D (struct GMT_CTRL *GMT, double *M, double X[3][3]);
115 EXTERN_MSC void spotter_inv_cov (struct GMT_CTRL *GMT, double Ci[3][3], double C[3][3]);
116 EXTERN_MSC unsigned int spotter_confregion_radial (struct GMT_CTRL *GMT, double alpha, struct EULER *p, double **X, double **Y);
117 EXTERN_MSC unsigned int spotter_confregion_ortho (struct GMT_CTRL *GMT, double alpha, struct EULER *p, double **X, double **Y);
118 EXTERN_MSC void spotter_tangentplane (struct GMT_CTRL *GMT, double lon, double lat, double R[3][3]);
119 EXTERN_MSC void spotter_project_ellipsoid_new (struct GMT_CTRL *GMT, double X[3][3], double *par);
120 EXTERN_MSC void spotter_project_ellipsoid (struct GMT_CTRL *GMT, double axis[], double D[3][3], double *par);
121 EXTERN_MSC void spotter_ellipsoid_normal (struct GMT_CTRL *GMT, double X[3], double L[3], double c, double N[3]);
122