1 | #ifndef _GRID_H_ |
---|
2 | #define _GRID_H_ |
---|
3 | #include <stdlib.h> |
---|
4 | #include <stdio.h> |
---|
5 | #include <string.h> |
---|
6 | #include <values.h> |
---|
7 | |
---|
8 | #include <list.h> |
---|
9 | |
---|
10 | // la structure interval de temps |
---|
11 | typedef struct { |
---|
12 | char debut[10]; |
---|
13 | char fin[10]; |
---|
14 | }Temporal, *ptrTemporal; |
---|
15 | |
---|
16 | ptrTemporal allocTemporal(char *datdeb, char *datfin); |
---|
17 | void freeTemporal(ptrTemporal t); |
---|
18 | |
---|
19 | // la structure parametre |
---|
20 | typedef struct { |
---|
21 | int id; |
---|
22 | int unit; |
---|
23 | char *name; |
---|
24 | double mini; |
---|
25 | double maxi; |
---|
26 | }Param, *ptrParam; |
---|
27 | |
---|
28 | ptrParam allocParam(int id, int unit, char *name, double mini, double maxi); |
---|
29 | |
---|
30 | void freeParam(ptrParam); |
---|
31 | int inParamId( int *id, ptrParam p); |
---|
32 | |
---|
33 | // la structure Grid |
---|
34 | typedef struct { |
---|
35 | int width; |
---|
36 | int height; |
---|
37 | unsigned int *datas; |
---|
38 | char date[10]; |
---|
39 | unsigned int mini; // valeurs extremes calculées |
---|
40 | unsigned int maxi; |
---|
41 | }Grid, *ptrGrid; |
---|
42 | |
---|
43 | typedef struct { |
---|
44 | char date[10]; // AAAAMMJJ // |
---|
45 | double value; // valeur en flottant d'un pt de grille |
---|
46 | }Pt, *ptrPt; |
---|
47 | |
---|
48 | ptrPt allocPt( char *date, double value); |
---|
49 | #define freePt(p) free((p)) |
---|
50 | |
---|
51 | // les times series |
---|
52 | typedef struct { |
---|
53 | |
---|
54 | double lat; //position |
---|
55 | double lon; |
---|
56 | LIST pts; |
---|
57 | ptrTemporal dates; //extremes |
---|
58 | }Serial, *ptrSerial; |
---|
59 | |
---|
60 | /* structure d'une zone geographique */ |
---|
61 | typedef struct{ |
---|
62 | double latMin; |
---|
63 | double latMax; |
---|
64 | double lonMin; |
---|
65 | double lonMax; |
---|
66 | }Zone, *ptrZone; |
---|
67 | |
---|
68 | #define lat2y(zone, lat)\ |
---|
69 | (double)(((double)(lat) -(zone)->latMin ) / ((zone)->latMax - (zone)->latMin)) |
---|
70 | #define lon2x(zone, lon)\ |
---|
71 | (double)(((double)(lon) - (zone)->lonMin) / ((zone)->lonMax - (zone)->lonMin)) |
---|
72 | |
---|
73 | #define x2lon(zone, x)\ |
---|
74 | (zone)->lonMin + (double)x * ((zone)->lonMax - (zone)->lonMin); |
---|
75 | #define y2lat(zone, y)\ |
---|
76 | (zone)->latMin + (double)y * ((zone)->latMax - (zone)->latMin); |
---|
77 | |
---|
78 | /* conversions 0-1 -> grille */ |
---|
79 | #define x2i(x, grid) ((int)( (double)(x) * (double)((grid)->width ) )) |
---|
80 | #define y2j(y, grid) ((int)( (double)(y) * (double)((grid)->height ) )) |
---|
81 | #define i2x(i, grid) (((double)(i) + 0.5) / (double)((grid)->width )) |
---|
82 | #define j2y(j, grid) (((double)(j) + 0.5) / (double)((grid)->height )) |
---|
83 | |
---|
84 | /* conversions latlon -> grid */ |
---|
85 | #define lat2j(lat, g, zone) y2j(lat2y((zone), (lat)), (g)) |
---|
86 | #define lon2i(lon, g, zone) x2i(lon2x((zone), (lon)), (g)) |
---|
87 | #define i2lon(i, g, zone) x2lon(zone, i2x(i, (g)) ) |
---|
88 | #define j2lat(j, g, zone) y2lat(zone, j2y(j, (g)) ) |
---|
89 | |
---|
90 | |
---|
91 | ptrGrid allocGrid(int width, int height); |
---|
92 | ptrGrid dupGrid(ptrGrid g); |
---|
93 | void freeGrid(ptrGrid); |
---|
94 | void freeGrids(LIST grids); |
---|
95 | |
---|
96 | |
---|
97 | //grille géocaliséO |
---|
98 | typedef struct { |
---|
99 | ptrParam param; |
---|
100 | ptrGrid grid; |
---|
101 | ptrZone zone; |
---|
102 | }GridGL, *ptrGridGL; |
---|
103 | |
---|
104 | ptrGridGL allocGridGL(ptrGrid g, ptrZone z); |
---|
105 | void freeGridGL(ptrGridGL); |
---|
106 | |
---|
107 | // convertisseurs codage grille <->flottant |
---|
108 | #define int2v(i, min, max) \ |
---|
109 | (double)(min) + \ |
---|
110 | ( \ |
---|
111 | ((double)(max)-(double)(min)) / \ |
---|
112 | (double)((unsigned)MAXINT +(unsigned)MAXINT) \ |
---|
113 | ) * (double)(i) |
---|
114 | |
---|
115 | |
---|
116 | #define v2int(v, min, max) \ |
---|
117 | (unsigned int)( \ |
---|
118 | ((double)(v) - (double)(min)) * \ |
---|
119 | ((double)((unsigned)MAXINT +(unsigned)MAXINT) / \ |
---|
120 | (double)((double)(max)-(double)(min))) + \ |
---|
121 | (double)0.5 \ |
---|
122 | ) |
---|
123 | // dénition de la zone globale (uniquement enlecture ) |
---|
124 | extern const Zone globalZone; |
---|
125 | |
---|
126 | // macros de calcul de pas d'une grille en fonction du domaine geographique |
---|
127 | #define pasLat(z, g) (double)((z)->latMax -(z)->latMin)/(g)->height; |
---|
128 | #define pasLon(z, g) (double)((z)->lonMax -(z)->lonMin)/(g)->width; |
---|
129 | |
---|
130 | #endif //GRID_H_ |
---|