FV3 Bundle
mosaic_util.h
Go to the documentation of this file.
1 /***********************************************************************
2  * GNU Lesser General Public License
3  *
4  * This file is part of the GFDL Flexible Modeling System (FMS).
5  *
6  * FMS is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or (at
9  * your option) any later version.
10  *
11  * FMS is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18  **********************************************************************/
19 /***********************************************************************
20  mosaic_util.h
21  This header file provide some utilities routine that will be used in many tools.
22 
23  contact: Zhi.Liang@noaa.gov
24 ***********************************************************************/
25 #ifndef MOSAIC_UTIL_H_
26 #define MOSAIC_UTIL_H_
27 
28 #ifndef RANGE_CHECK_CRITERIA
29 #define RANGE_CHECK_CRITERIA 0.05
30 #endif
31 
32 #define min(a,b) (a<b ? a:b)
33 #define max(a,b) (a>b ? a:b)
34 #define SMALL_VALUE ( 1.e-10 )
35 
36 struct Node{
37  double x, y, z, u, u_clip;
38  int intersect; /* indicate if this point is an intersection, 0 = no, 1= yes, 2=both intersect and vertices */
39  int inbound; /* -1 uninitialized, 0 coincident, 1 outbound, 2 inbound */
40  int initialized; /* = 0 means empty list */
41  int isInside; /* = 1 means one point is inside the other polygon, 0 is not, -1 undecided. */
42  int subj_index; /* the index of subject point that an intersection follow. */
43  int clip_index; /* the index of clip point that an intersection follow */
44  struct Node *Next;
45 };
46 
47 
48 void error_handler(const char *msg);
49 
50 int nearest_index(double value, const double *array, int ia);
51 
52 int lon_fix(double *x, double *y, int n_in, double tlon);
53 
54 double minval_double(int size, const double *data);
55 
56 double maxval_double(int size, const double *data);
57 
58 double avgval_double(int size, const double *data);
59 
60 void latlon2xyz(int size, const double *lon, const double *lat, double *x, double *y, double *z);
61 
62 void xyz2latlon(int size, const double *x, const double *y, const double *z, double *lon, double *lat);
63 
64 double box_area(double ll_lon, double ll_lat, double ur_lon, double ur_lat);
65 
66 double poly_area(const double lon[], const double lat[], int n);
67 
68 int delete_vtx(double x[], double y[], int n, int n_del);
69 
70 int insert_vtx(double x[], double y[], int n, int n_ins, double lon_in, double lat_in);
71 
72 double poly_area_dimensionless(const double lon[], const double lat[], int n);
73 
74 double poly_area_no_adjust(const double x[], const double y[], int n);
75 
76 int fix_lon(double lon[], double lat[], int n, double tlon);
77 
78 void tokenize(const char * const string, const char *tokens, unsigned int varlen,
79  unsigned int maxvar, char * pstring, unsigned int * const nstr);
80 
81 double great_circle_distance(double *p1, double *p2);
82 
83 double spherical_excess_area(const double* p_ll, const double* p_ul,
84  const double* p_lr, const double* p_ur, double radius);
85 
86 void vect_cross(const double *p1, const double *p2, double *e );
87 
88 double spherical_angle(const double *v1, const double *v2, const double *v3);
89 
90 void normalize_vect(double *e);
91 
92 void unit_vect_latlon(int size, const double *lon, const double *lat, double *vlon, double *vlat);
93 
94 double great_circle_area(int n, const double *x, const double *y, const double *z);
95 
96 double * cross(const double *p1, const double *p2);
97 
98 double dot(const double *p1, const double *p2);
99 
100 int intersect_tri_with_line(const double *plane, const double *l1, const double *l2, double *p,
101  double *t);
102 
103 int invert_matrix_3x3(long double m[], long double m_inv[]);
104 
105 void mult(long double m[], long double v[], long double out_v[]);
106 
107 double metric(const double *p);
108 
109 int insidePolygon(struct Node *node, struct Node *list );
110 
111 int inside_a_polygon( double *lon1, double *lat1, int *npts, double *lon2, double *lat2);
112 
113 void rewindList(void);
114 
115 struct Node *getNext();
116 
117 void initNode(struct Node *node);
118 
119 void addEnd(struct Node *list, double x, double y, double z, int intersect, double u, int inbound, int inside);
120 
121 int addIntersect(struct Node *list, double x, double y, double z, int intersect, double u1, double u2,
122  int inbound, int is1, int ie1, int is2, int ie2);
123 
124 int length(struct Node *list);
125 
126 int samePoint(double x1, double y1, double z1, double x2, double y2, double z2);
127 
128 int sameNode(struct Node node1, struct Node node2);
129 
130 void addNode(struct Node *list, struct Node nodeIn);
131 
132 struct Node *getNode(struct Node *list, struct Node inNode);
133 
134 struct Node *getNextNode(struct Node *list);
135 
136 void copyNode(struct Node *node_out, struct Node node_in);
137 
138 void printNode(struct Node *list, char *str);
139 
140 int intersectInList(struct Node *list, double x, double y, double z);
141 
142 void insertIntersect(struct Node *list, double x, double y, double z, double u1, double u2, int inbound,
143  double x2, double y2, double z2);
144 
145 void insertAfter(struct Node *list, double x, double y, double z, int intersect, double u, int inbound,
146  double x2, double y2, double z2);
147 
148 double gridArea(struct Node *grid);
149 
150 int isIntersect(struct Node node);
151 
152 int getInbound( struct Node node );
153 
154 struct Node *getLast(struct Node *list);
155 
156 int getFirstInbound( struct Node *list, struct Node *nodeOut);
157 
158 void getCoordinate(struct Node node, double *x, double *y, double *z);
159 
160 void getCoordinates(struct Node *node, double *p);
161 
162 void setCoordinate(struct Node *node, double x, double y, double z);
163 
164 void setInbound(struct Node *interList, struct Node *list);
165 
166 int isInside(struct Node *node);
167 
168 void set_reproduce_siena_true(void);
169 
170 #ifndef __AIX
171 
172 void set_reproduce_siena_true_(void);
173 
174 int inside_a_polygon_(double *lon1, double *lat1, int *npts, double *lon2, double *lat2);
175 
176 #endif
177 #endif
int inbound
Definition: mosaic_util.h:39
real, parameter, public radius
Radius of the Earth [m].
Definition: constants.F90:72
int isInside(struct Node *node)
Definition: mosaic_util.c:1296
int invert_matrix_3x3(long double m[], long double m_inv[])
Definition: mosaic_util.c:778
void addNode(struct Node *list, struct Node nodeIn)
Definition: mosaic_util.c:987
void initNode(struct Node *node)
Definition: mosaic_util.c:841
int delete_vtx(double x[], double y[], int n, int n_del)
Definition: mosaic_util.c:376
int sameNode(struct Node node1, struct Node node2)
Definition: mosaic_util.c:978
void setCoordinate(struct Node *node, double x, double y, double z)
Definition: mosaic_util.c:1242
real function intersect(x1, y1, x2, y2, x)
int inside_a_polygon(double *lon1, double *lat1, int *npts, double *lon2, double *lat2)
Definition: mosaic_util.c:1357
real(fvprc), dimension(:), allocatable lon
double metric(const double *p)
Definition: mosaic_util.c:671
double y
Definition: mosaic_util.h:37
void set_reproduce_siena_true(void)
Definition: mosaic_util.c:42
double box_area(double ll_lon, double ll_lat, double ur_lon, double ur_lat)
Definition: mosaic_util.c:258
double poly_area(const double lon[], const double lat[], int n)
Definition: mosaic_util.c:314
int initialized
Definition: mosaic_util.h:40
int isInside
Definition: mosaic_util.h:41
int clip_index
Definition: mosaic_util.h:43
int fix_lon(double lon[], double lat[], int n, double tlon)
Definition: mosaic_util.c:409
struct Node * getLast(struct Node *list)
Definition: mosaic_util.c:1190
void addEnd(struct Node *list, double x, double y, double z, int intersect, double u, int inbound, int inside)
Definition: mosaic_util.c:855
double * cross(const double *p1, const double *p2)
int intersect_tri_with_line(const double *plane, const double *l1, const double *l2, double *p, double *t)
Definition: mosaic_util.c:727
double dot(const double *p1, const double *p2)
Definition: mosaic_util.c:663
void latlon2xyz(int size, const double *lon, const double *lat, double *x, double *y, double *z)
Definition: mosaic_util.c:211
void mult(long double m[], long double v[], long double out_v[])
Definition: mosaic_util.c:768
str
Definition: c2f.py:15
real(r8), dimension(cast_m, cast_n) p
int nearest_index(double value, const double *array, int ia)
Definition: mosaic_util.c:80
void vect_cross(const double *p1, const double *p2, double *e)
Definition: mosaic_util.c:648
double spherical_angle(const double *v1, const double *v2, const double *v3)
Definition: mosaic_util.c:541
int lon_fix(double *x, double *y, int n_in, double tlon)
void tokenize(const char *const string, const char *tokens, unsigned int varlen, unsigned int maxvar, char *pstring, unsigned int *const nstr)
Definition: mosaic_util.c:112
integer, parameter m
int getFirstInbound(struct Node *list, struct Node *nodeOut)
Definition: mosaic_util.c:1205
double spherical_excess_area(const double *p_ll, const double *p_ul, const double *p_lr, const double *p_ur, double radius)
Definition: mosaic_util.c:606
real(fp), parameter, public e
struct Node * getNextNode(struct Node *list)
Definition: mosaic_util.c:1012
void set_reproduce_siena_true_(void)
Definition: mosaic_util.c:48
int subj_index
Definition: mosaic_util.h:42
double great_circle_distance(double *p1, double *p2)
Definition: mosaic_util.c:488
int insidePolygon(struct Node *node, struct Node *list)
Definition: mosaic_util.c:1306
double z
Definition: mosaic_util.h:37
double u
Definition: mosaic_util.h:37
real(kind=kind_real), parameter u1
int insert_vtx(double x[], double y[], int n, int n_ins, double lon_in, double lat_in)
Definition: mosaic_util.c:386
void insertIntersect(struct Node *list, double x, double y, double z, double u1, double u2, int inbound, double x2, double y2, double z2)
Definition: mosaic_util.c:1074
double great_circle_area(int n, const double *x, const double *y, const double *z)
Definition: mosaic_util.c:504
double poly_area_dimensionless(const double lon[], const double lat[], int n)
Definition: mosaic_util.c:277
real(fvprc), dimension(:), allocatable lat
int intersect
Definition: mosaic_util.h:38
void insertAfter(struct Node *list, double x, double y, double z, int intersect, double u, int inbound, double x2, double y2, double z2)
int getInbound(struct Node node)
Definition: mosaic_util.c:1185
int length(struct Node *list)
Definition: mosaic_util.c:951
double avgval_double(int size, const double *data)
Definition: mosaic_util.c:193
int samePoint(double x1, double y1, double z1, double x2, double y2, double z2)
Definition: mosaic_util.c:968
void normalize_vect(double *e)
Definition: mosaic_util.c:679
integer, parameter, public npts
void setInbound(struct Node *interList, struct Node *list)
Definition: mosaic_util.c:1256
void copyNode(struct Node *node_out, struct Node node_in)
Definition: mosaic_util.c:1017
int inside_a_polygon_(double *lon1, double *lat1, int *npts, double *lon2, double *lat2)
Definition: mosaic_util.c:1402
void getCoordinates(struct Node *node, double *p)
Definition: mosaic_util.c:1232
************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************subroutine READ_RECORD_CORE_(unit, field, nwords, data, start, axsiz) integer, intent(in) ::unit type(fieldtype), intent(in) ::field integer, intent(in) ::nwords MPP_TYPE_, intent(inout) ::data(nwords) integer, intent(in) ::start(:), axsiz(:) integer(SHORT_KIND) ::i2vals(nwords)!rab used in conjunction with transfer intrinsic to determine size of a variable integer(KIND=1) ::one_byte(8) integer ::word_sz!#ifdef __sgi integer(INT_KIND) ::ivals(nwords) real(FLOAT_KIND) ::rvals(nwords)!#else! integer ::ivals(nwords)! real ::rvals(nwords)!#endif real(DOUBLE_KIND) ::r8vals(nwords) pointer(ptr1, i2vals) pointer(ptr2, ivals) pointer(ptr3, rvals) pointer(ptr4, r8vals) if(mpp_io_stack_size< nwords) call mpp_io_set_stack_size(nwords) call mpp_error(FATAL, 'MPP_READ currently requires use_netCDF option') end subroutine READ_RECORD_CORE_ subroutine READ_RECORD_(unit, field, nwords, data, time_level, domain, position, tile_count, start_in, axsiz_in)!routine that is finally called by all mpp_read routines to perform the read!a non-netCDF record contains:! field ID! a set of 4 coordinates(is:ie, js:je) giving the data subdomain! a timelevel and a timestamp(=NULLTIME if field is static)! 3D real data(stored as 1D)!if you are using direct access I/O, the RECL argument to OPEN must be large enough for the above!in a global direct access file, record position on PE is given by %record.!Treatment of timestamp:! We assume that static fields have been passed without a timestamp.! Here that is converted into a timestamp of NULLTIME.! For non-netCDF fields, field is treated no differently, but is written! with a timestamp of NULLTIME. There is no check in the code to prevent! the user from repeatedly writing a static field. integer, intent(in) ::unit, nwords type(fieldtype), intent(in) ::field MPP_TYPE_, intent(inout) ::data(nwords) integer, intent(in), optional ::time_level type(domain2D), intent(in), optional ::domain integer, intent(in), optional ::position, tile_count integer, intent(in), optional ::start_in(:), axsiz_in(:) integer, dimension(size(field%axes(:))) ::start, axsiz integer ::tlevel !, subdomain(4) integer ::i, error, is, ie, js, je, isg, ieg, jsg, jeg type(domain2d), pointer ::io_domain=> tlevel if(PRESENT(start_in) .AND. PRESENT(axsiz_in)) then if(size(start(! the data domain and compute domain must refer to the subdomain being passed ! In this ! since that attempts to gather all data on PE size(field%axes(:)) axsiz(i)
void getCoordinate(struct Node node, double *x, double *y, double *z)
Definition: mosaic_util.c:1222
int addIntersect(struct Node *list, double x, double y, double z, int intersect, double u1, double u2, int inbound, int is1, int ie1, int is2, int ie2)
Definition: mosaic_util.c:894
real(r8), dimension(cast_m, cast_n) t
double x
Definition: mosaic_util.h:37
struct Node * getNode(struct Node *list, struct Node inNode)
Definition: mosaic_util.c:994
void printNode(struct Node *list, char *str)
Definition: mosaic_util.c:1031
void error_handler(const char *msg)
Definition: mosaic_util.c:55
double u_clip
Definition: mosaic_util.h:37
real, parameter p2
Definition: sw_core_nlm.F90:47
void unit_vect_latlon(int size, const double *lon, const double *lat, double *vlon, double *vlat)
Definition: mosaic_util.c:697
double gridArea(struct Node *grid)
Definition: mosaic_util.c:1156
int isIntersect(struct Node node)
Definition: mosaic_util.c:1178
double poly_area_no_adjust(const double x[], const double y[], int n)
Definition: mosaic_util.c:351
real, parameter p1
Definition: sw_core_nlm.F90:46
int intersectInList(struct Node *list, double x, double y, double z)
Definition: mosaic_util.c:1047
struct Node * Next
Definition: mosaic_util.h:44
double minval_double(int size, const double *data)
Definition: mosaic_util.c:175
struct Node * getNext()
Definition: mosaic_util.c:823
logical function, public inside(p, lv, xv, yv, zv, nv, listv, ier)
void xyz2latlon(int size, const double *x, const double *y, const double *z, double *lon, double *lat)
Definition: mosaic_util.c:227
real(kind=kind_real), parameter u2
double maxval_double(int size, const double *data)
Definition: mosaic_util.c:156
void rewindList(void)
Definition: mosaic_util.c:813