1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include "dprints.h" /* for dprints & func prototypes */ |
---|
4 | #include "gribfuncs.h" /* prototypes */ |
---|
5 | /* |
---|
6 | REVISION/MODIFICATION HISTORY: |
---|
7 | 03/07/94 written by Mugur Georgescu CSC, Monterey CA |
---|
8 | 02/01/96 modified by Steve Lowe SAIC, Monterey CA |
---|
9 | 06/19/96 modified by Alice Nakajima SAIC, Monterey CA |
---|
10 | 10/15/97/ATN init usData_type in Projection struct too |
---|
11 | 02/18/98/atn replace projection ids with constants |
---|
12 | * |
---|
13 | ******************************************************************* |
---|
14 | * A. FUNCTION gribgetgds |
---|
15 | * Decode the Grid Description Section (GDS) from the provided |
---|
16 | * pointer location and store its the in the internal GDS structure; |
---|
17 | * |
---|
18 | * INTERFACE: |
---|
19 | * int gribgetgds (curr_ptr, gds, errmsg) |
---|
20 | * |
---|
21 | * ARGUMENTS (I=input, O=output, I&O=input and output): |
---|
22 | * (I) char *curr_ptr; points to 1st octet of GDS |
---|
23 | * (O) grid_desc_sec *gds; internal GDS structure to be filled |
---|
24 | * (O) char *errmsg; returned filled if error occurred |
---|
25 | * |
---|
26 | * RETURN CODE: |
---|
27 | * 0> success, struct grid_desc_sec filled; |
---|
28 | * 1> unsupported projection number, errmsg filled; |
---|
29 | * 2> section length too short, errmsg filled; |
---|
30 | ******************************************************************* |
---|
31 | */ |
---|
32 | |
---|
33 | #if PROTOTYPE_NEEDED |
---|
34 | int gribgetgds ( char *curr_ptr, grid_desc_sec *gds, char *errmsg) |
---|
35 | #else |
---|
36 | int gribgetgds ( curr_ptr, gds, errmsg) |
---|
37 | char *curr_ptr; |
---|
38 | grid_desc_sec *gds; |
---|
39 | char *errmsg; |
---|
40 | #endif |
---|
41 | { |
---|
42 | char *func= "gribgetgds"; |
---|
43 | char *in = curr_ptr; /* pointer to the message */ |
---|
44 | unsigned long skip; /* bits to be skipped */ |
---|
45 | unsigned long something; /* value extracted from message */ |
---|
46 | int sign; /* sign + or - */ |
---|
47 | int status; |
---|
48 | FILE *fp; |
---|
49 | int i; |
---|
50 | |
---|
51 | DPRINT1 ("Entering %s\n", func); |
---|
52 | /* |
---|
53 | * |
---|
54 | * A.0 INIT status to good, skip to 0 |
---|
55 | */ |
---|
56 | status=0; skip=0; |
---|
57 | /* |
---|
58 | * |
---|
59 | * A.1 FUNCTION gbyte !GDS length |
---|
60 | * IF (length < 32 bytes) THEN |
---|
61 | * SET error status of 2 !length too short |
---|
62 | * CONTINUE to load as much info as possible into |
---|
63 | * structure 'grid_desc_sec' but will return with error |
---|
64 | * ENDIF |
---|
65 | */ |
---|
66 | gbyte(in,&something,&skip,24); DPRINT0 ("gds->head.uslength\n"); |
---|
67 | gds->head.uslength = (unsigned short) something; |
---|
68 | if (gds->head.uslength < 32) { |
---|
69 | sprintf(errmsg, |
---|
70 | "GDS length too short (%ld). Will attempt to load struct grid_desc_sec\n", |
---|
71 | gds->head.uslength); |
---|
72 | status = 2; /* corrupt length */ |
---|
73 | } |
---|
74 | |
---|
75 | /* |
---|
76 | * |
---|
77 | * A.2 FUNCTION gbyte !parm_nv |
---|
78 | */ |
---|
79 | gbyte(in,&something,&skip,8); DPRINT0 ("gds->head.usNum_v\n"); |
---|
80 | gds->head.usNum_v =(short) something; |
---|
81 | /* |
---|
82 | * |
---|
83 | * A.3 FUNCTION gbyte !parm_pv_pl |
---|
84 | */ |
---|
85 | gbyte(in,&something,&skip,8); DPRINT0 ("gds->head.usPl_Pv\n"); |
---|
86 | gds->head.usPl_Pv = (short) something; |
---|
87 | |
---|
88 | /* |
---|
89 | * |
---|
90 | * A.4 FUNCTION gbyte !data representation type |
---|
91 | */ |
---|
92 | gbyte(in,&something,&skip,8); DPRINT0 ("gds->head.usData_type\n"); |
---|
93 | gds->head.usData_type = (short) something; |
---|
94 | |
---|
95 | /* Remainder of GDS is projection dependent */ |
---|
96 | /* |
---|
97 | * |
---|
98 | * A.5 SWITCH (data type) |
---|
99 | */ |
---|
100 | |
---|
101 | switch(gds->head.usData_type) |
---|
102 | { |
---|
103 | case LATLON_PRJ: /* Lat/Lon Grid */ |
---|
104 | case GAUSS_PRJ: /* Gaussian Latitude/Longitude grid */ |
---|
105 | case ROT_LATLON_PRJ: /* Rotated Lat/Lon */ |
---|
106 | case ROT_GAUSS_PRJ: /* Rotated Gaussian */ |
---|
107 | case STR_LATLON_PRJ: /* Stretched Lat/Lon */ |
---|
108 | case STR_GAUSS_PRJ : /* Stretched Gaussian */ |
---|
109 | case STR_ROT_LATLON_PRJ : /* Stretched and Rotated Lat/Lon */ |
---|
110 | case STR_ROT_GAUSS_PRJ : /* Stretched and Rotated Gaussian */ |
---|
111 | /* |
---|
112 | * case latlon: |
---|
113 | * case gaussian_latlon: |
---|
114 | * case rotated gaussian: |
---|
115 | * case stretched latlon: |
---|
116 | * case stretched gaussian: |
---|
117 | * case stretched & rotated latlon: |
---|
118 | * case stretched & rotated gaussian: |
---|
119 | * Mark the Projection type |
---|
120 | * FUNCTION gbyte !get Number of Columns |
---|
121 | */ |
---|
122 | gds->llg.usData_type = gds->head.usData_type; |
---|
123 | |
---|
124 | gbyte(in, &something, &skip, 16); |
---|
125 | DPRINT0 ("gds->llg.usNi\n"); |
---|
126 | gds->llg.usNi = (int) something; /* get Ni */ |
---|
127 | |
---|
128 | /* |
---|
129 | * FUNCTION gbyte !get Number of Rows |
---|
130 | */ |
---|
131 | gbyte(in, &something, &skip, 16); |
---|
132 | DPRINT0 ("gds->llg.usNj\n"); |
---|
133 | gds->llg.usNj = (int) something; /* get Nj */ |
---|
134 | |
---|
135 | /* |
---|
136 | * FUNCTION gbyte !get Latitude of First point |
---|
137 | */ |
---|
138 | gbyte(in,&something,&skip,24); |
---|
139 | DPRINT0 ("Sign & gds->llg.lLat1 \n"); |
---|
140 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
141 | gds->llg.lLat1 = (long) (something) & 8388607; /* get La1 */ |
---|
142 | if(sign) /* negative value */ |
---|
143 | gds->llg.lLat1 = - gds->llg.lLat1; /* multiply by -1 */ |
---|
144 | |
---|
145 | /* |
---|
146 | * FUNCTION gbyte !get Longitude of First point |
---|
147 | */ |
---|
148 | gbyte(in,&something,&skip,24); |
---|
149 | DPRINT0 ("Sign & gds->llg.lLon1 \n"); |
---|
150 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
151 | gds->llg.lLon1 = (long) (something) & 8388607; /* get Lo1 */ |
---|
152 | if(sign) /* negative value */ |
---|
153 | gds->llg.lLon1 = - gds->llg.lLon1; /* multiply by -1 */ |
---|
154 | |
---|
155 | /* |
---|
156 | * FUNCTION gbyte !get resolution & comp flags |
---|
157 | */ |
---|
158 | gbyte(in,&something,&skip,8); |
---|
159 | DPRINT0 ("gds->llg.usRes_flag\n"); |
---|
160 | gds->llg.usRes_flag = (short) something; /* get resolution & comp flags */ |
---|
161 | |
---|
162 | gbyte(in,&something,&skip,24); |
---|
163 | DPRINT0 ("Sign & gds->llg.lLat2 \n"); |
---|
164 | /* |
---|
165 | * FUNCTION gbyte !get Latitude of Last point |
---|
166 | */ |
---|
167 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
168 | gds->llg.lLat2 = (long) (something) & 8388607; /* get La2 */ |
---|
169 | if(sign) /* negative value */ |
---|
170 | gds->llg.lLat2 = - gds->llg.lLat2; /* multiply by -1 */ |
---|
171 | |
---|
172 | /* |
---|
173 | * FUNCTION gbyte !get Longitude of Last point |
---|
174 | */ |
---|
175 | gbyte(in,&something,&skip,24); |
---|
176 | DPRINT0 ("Sign & gds->llg.lLon2 \n"); |
---|
177 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
178 | gds->llg.lLon2 = (long) (something) & 8388607; /* get Lo2 */ |
---|
179 | if(sign) /* negative value */ |
---|
180 | gds->llg.lLon2 = - gds->llg.lLon2; /* multiply by -1 */ |
---|
181 | |
---|
182 | /* |
---|
183 | * FUNCTION gbyte !get Longitudinal Increment |
---|
184 | */ |
---|
185 | gbyte(in,&something,&skip,16); |
---|
186 | DPRINT0 ("gds->llg.iDi\n"); |
---|
187 | gds->llg.iDi = (int) something; /* get Di */ |
---|
188 | |
---|
189 | /* |
---|
190 | * FUNCTION gbyte !get Latitudinal Increment |
---|
191 | */ |
---|
192 | gbyte(in,&something,&skip,16); |
---|
193 | DPRINT0 ("gds->llg.iDj\n"); |
---|
194 | gds->llg.iDj = (int) something; /* get Dj */ |
---|
195 | |
---|
196 | /* |
---|
197 | * FUNCTION gbyte !get scanning mode |
---|
198 | */ |
---|
199 | gbyte(in,&something,&skip,8); |
---|
200 | DPRINT0 ("gds->llg.usScan_mode\n"); |
---|
201 | gds->llg.usScan_mode = (short) something; /* get scaning mode flag */ |
---|
202 | |
---|
203 | /* |
---|
204 | * FUNCTION gbyte !get reserved octets 29-32 |
---|
205 | */ |
---|
206 | gbyte(in,&something,&skip,32); |
---|
207 | DPRINT0 ("gds->llg.usZero\n"); |
---|
208 | gds->llg.usZero = (long) something; /* get reserved octets 29 - 32 */ |
---|
209 | |
---|
210 | if (gds->head.usNum_v > 0) { |
---|
211 | /* |
---|
212 | * FUNCTION gbyte !get south pole lat |
---|
213 | */ |
---|
214 | gbyte(in,&something,&skip,24); |
---|
215 | DPRINT0 ("Sign & gds->llg.lLat_southpole \n"); |
---|
216 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
217 | gds->llg.lLat_southpole = (long)(something) & 8388607; /* southpole lat*/ |
---|
218 | if(sign) /* negative value */ |
---|
219 | gds->llg.lLat_southpole = - gds->llg.lLat_southpole; /* multiply -1 */ |
---|
220 | |
---|
221 | /* |
---|
222 | * FUNCTION gbyte !get south pole lon |
---|
223 | */ |
---|
224 | gbyte(in,&something,&skip,24); |
---|
225 | DPRINT0 ("Sign & gds->llg.lLon_southpole \n"); |
---|
226 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
227 | gds->llg.lLon_southpole =(long)(something) & 8388607; /* southpole lon*/ |
---|
228 | if(sign) /* negative value , multiply by -1 */ |
---|
229 | gds->llg.lLon_southpole = - gds->llg.lLon_southpole; |
---|
230 | |
---|
231 | /* |
---|
232 | * FUNCTION gbyte !angle of rotation |
---|
233 | */ |
---|
234 | gbyte(in,&something,&skip,24); |
---|
235 | DPRINT0 ("gds->llg.lRotate\n"); |
---|
236 | gds->llg.lRotate = (long) something; /* get angle of rotation */ |
---|
237 | |
---|
238 | /* |
---|
239 | * FUNCTION gbyte !get lat pole stretching |
---|
240 | */ |
---|
241 | gbyte(in,&something,&skip,24); |
---|
242 | DPRINT0 ("Sign & gds->llg.lPole_lat \n"); |
---|
243 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
244 | gds->llg.lPole_lat = (long)something & 8388607; /* lat pole stretching */ |
---|
245 | if(sign) /* negative value */ |
---|
246 | gds->llg.lPole_lat = - gds->llg.lPole_lat; /* multiply by -1 */ |
---|
247 | |
---|
248 | /* |
---|
249 | * FUNCTION gbyte !get lon pole stretching |
---|
250 | */ |
---|
251 | gbyte(in,&something,&skip,24); |
---|
252 | DPRINT0 ("Sign & gds->llg.lPole_lon \n"); |
---|
253 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
254 | gds->llg.lPole_lon= (long)(something) & 8388607; /* lon pole stretching*/ |
---|
255 | if(sign) /* negative value */ |
---|
256 | gds->llg.lPole_lon = - gds->llg.lPole_lon; /* multiply by -1 */ |
---|
257 | |
---|
258 | gbyte(in,&something,&skip,24); |
---|
259 | DPRINT0 ("gds->llg.lStretch\n"); |
---|
260 | gds->llg.lStretch = (long) something; |
---|
261 | } |
---|
262 | |
---|
263 | /* |
---|
264 | * FUNCTION gbyte !get number of columns in each row |
---|
265 | */ |
---|
266 | if (gds->llg.usNi == 65535) { |
---|
267 | if (gds->head.thin == NULL) { |
---|
268 | gds->head.thin = (int *)malloc(gds->llg.usNj*sizeof(int)); |
---|
269 | } else { |
---|
270 | gds->head.thin = (int *)realloc(gds->head.thin, |
---|
271 | gds->llg.usNj*sizeof(int)); |
---|
272 | } |
---|
273 | if (gds->head.thin == NULL) { |
---|
274 | sprintf(errmsg, |
---|
275 | "%s: failed to create array[%d] for thinned grid information", |
---|
276 | func, gds->head.thin); |
---|
277 | goto BYE; |
---|
278 | } |
---|
279 | for (i = 0; i<gds->llg.usNj; i++) { |
---|
280 | gbyte(in,&something,&skip,16); |
---|
281 | gds->head.thin[i] = (short)something; |
---|
282 | } |
---|
283 | } else { |
---|
284 | gds->head.thin = NULL; |
---|
285 | } |
---|
286 | break; |
---|
287 | |
---|
288 | case MERC_PRJ: /* Mercator Projection Grid */ |
---|
289 | /* |
---|
290 | * case Mercator Projection Grid: |
---|
291 | * Mark the Projection type |
---|
292 | * FUNCTION gbyte !get Number of Columns |
---|
293 | */ |
---|
294 | gds->merc.usData_type = gds->head.usData_type; |
---|
295 | |
---|
296 | gbyte(in,&something,&skip,16); |
---|
297 | DPRINT0 ("gds->merc.cols\n"); |
---|
298 | gds->merc.cols = (int) something; /* get Ni */ |
---|
299 | /* |
---|
300 | * FUNCTION gbyte !get Number of Rows |
---|
301 | */ |
---|
302 | gbyte(in,&something,&skip,16); |
---|
303 | DPRINT0 ("gds->merc.rows\n"); |
---|
304 | gds->merc.rows = (int) something; /* get Nj */ |
---|
305 | |
---|
306 | /* |
---|
307 | * FUNCTION gbyte !get Latitude of First Point |
---|
308 | */ |
---|
309 | gbyte(in,&something,&skip,24); |
---|
310 | DPRINT0 ("Sign & gds->merc.first_lat\n"); |
---|
311 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
312 | gds->merc.first_lat = (long) (something) & 8388607; /* get La1 */ |
---|
313 | if(sign) /* negative value */ |
---|
314 | gds->merc.first_lat = - gds->merc.first_lat; /* multiply by -1 */ |
---|
315 | |
---|
316 | /* |
---|
317 | * FUNCTION gbyte !get Longitude of First Point |
---|
318 | */ |
---|
319 | gbyte(in,&something,&skip,24); |
---|
320 | DPRINT0 ("Sign & gds->merc.first_lon\n"); |
---|
321 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
322 | gds->merc.first_lon = (long) (something) & 8388607; /* get Lo1 */ |
---|
323 | if(sign) /* negative value */ |
---|
324 | gds->merc.first_lon = - gds->merc.first_lon; /* multiply by -1 */ |
---|
325 | |
---|
326 | /* |
---|
327 | * FUNCTION gbyte !get resolution & comp flag |
---|
328 | */ |
---|
329 | gbyte(in,&something,&skip,8); |
---|
330 | DPRINT0 ("gds->merc.usRes_flag\n"); |
---|
331 | gds->merc.usRes_flag = (short) something; /* resolution & comp flags */ |
---|
332 | |
---|
333 | /* |
---|
334 | * FUNCTION gbyte !get Latitude of Last point |
---|
335 | */ |
---|
336 | gbyte(in,&something,&skip,24); |
---|
337 | DPRINT0 ("Sign & gds->merc.La2\n"); |
---|
338 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
339 | gds->merc.La2 = (long) (something) & 8388607; /* get La2 */ |
---|
340 | if(sign) /* negative value */ |
---|
341 | gds->merc.La2 = - gds->merc.La2; /* multiply by -1 */ |
---|
342 | |
---|
343 | /* |
---|
344 | * FUNCTION gbyte !get Longitude of Last point |
---|
345 | */ |
---|
346 | gbyte(in,&something,&skip,24); |
---|
347 | DPRINT0 ("Sign & gds->merc.Lo2\n"); |
---|
348 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
349 | gds->merc.Lo2 = (long) (something) & 8388607; /* get Lo2 */ |
---|
350 | if(sign) /* negative value */ |
---|
351 | gds->merc.Lo2 = - gds->merc.Lo2; /* multiply by -1 */ |
---|
352 | |
---|
353 | /* |
---|
354 | * FUNCTION gbyte !get Latitude where projection intersects Earth |
---|
355 | */ |
---|
356 | gbyte(in,&something,&skip,24); |
---|
357 | DPRINT0 ("Sign & gds->merc.latin\n"); |
---|
358 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
359 | gds->merc.latin = (long) (something) & 8388607; /* get latin */ |
---|
360 | if(sign) /* negative value */ |
---|
361 | gds->merc.latin = - gds->merc.latin; /* multiply by -1 */ |
---|
362 | |
---|
363 | skip += 8; /* skip over the reserved octet */ |
---|
364 | |
---|
365 | /* |
---|
366 | * FUNCTION gbyte !get scanning mode flag |
---|
367 | */ |
---|
368 | gbyte(in,&something,&skip,8); |
---|
369 | DPRINT0 ("gds->merc.usScan_mode\n"); |
---|
370 | gds->merc.usScan_mode = (short) something; /* get scaning mode flag */ |
---|
371 | |
---|
372 | /* |
---|
373 | * FUNCTION gbyte !get Longitudinal Increment |
---|
374 | */ |
---|
375 | gbyte(in,&something,&skip,24); |
---|
376 | DPRINT0 ("gds->merc.lon_inc\n"); |
---|
377 | gds->merc.lon_inc = (float) something; /* get Di */ |
---|
378 | |
---|
379 | /* |
---|
380 | * FUNCTION gbyte !get Latitudinal Increment |
---|
381 | */ |
---|
382 | gbyte(in,&something,&skip,24); |
---|
383 | DPRINT0 ("gds->merc.lat_inc\n"); |
---|
384 | gds->merc.lat_inc = (float) something; /* get Dj */ |
---|
385 | |
---|
386 | gbyte(in,&something,&skip,32); |
---|
387 | DPRINT0 ("gds->merc.usZero\n"); |
---|
388 | gds->merc.usZero = (long) something; |
---|
389 | |
---|
390 | if (gds->merc.cols == 65535) { |
---|
391 | gds->head.thin = (int *)calloc(gds->merc.rows,sizeof(int)); |
---|
392 | if (gds->head.thin == NULL) { |
---|
393 | sprintf(errmsg, |
---|
394 | "%s: failed to create array[%d] for thinned grid information", |
---|
395 | func, gds->head.thin); |
---|
396 | goto BYE; |
---|
397 | } |
---|
398 | for (i = 0; i<gds->merc.rows; i++) { |
---|
399 | gbyte(in,&something,&skip,16); |
---|
400 | gds->head.thin[i] = (short)something; |
---|
401 | } |
---|
402 | } else { |
---|
403 | gds->head.thin = NULL; |
---|
404 | } |
---|
405 | |
---|
406 | break; |
---|
407 | |
---|
408 | case POLAR_PRJ: /* Polar Stereographic Projection Grid */ |
---|
409 | /* |
---|
410 | * case Polar Stereographic Projection Grid: |
---|
411 | * Mark the Projection type |
---|
412 | * FUNCTION gbyte !get Number of Columns |
---|
413 | */ |
---|
414 | gds->pol.usData_type = gds->head.usData_type; |
---|
415 | |
---|
416 | gbyte(in,&something,&skip,16); |
---|
417 | DPRINT0 ("gds->pol.usNx\n"); |
---|
418 | gds->pol.usNx = (short) something; /* get Nx */ |
---|
419 | |
---|
420 | /* |
---|
421 | * FUNCTION gbyte !get Number of Rows |
---|
422 | */ |
---|
423 | gbyte(in,&something,&skip,16); |
---|
424 | DPRINT0 ("gds->pol.usNy\n"); |
---|
425 | gds->pol.usNy = (short) something; /* get Ny */ |
---|
426 | |
---|
427 | /* |
---|
428 | * FUNCTION gbyte !get Latitude of First point |
---|
429 | */ |
---|
430 | gbyte(in,&something,&skip,24); |
---|
431 | DPRINT0 ("Sign & gds->pol.lLat1\n"); |
---|
432 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
433 | gds->pol.lLat1 = (long) (something) & 8388607; /* get La1 */ |
---|
434 | if(sign) /* negative value */ |
---|
435 | gds->pol.lLat1 = - gds->pol.lLat1; /* multiply by -1 */ |
---|
436 | |
---|
437 | /* |
---|
438 | * FUNCTION gbyte !get Longitude of First point |
---|
439 | */ |
---|
440 | gbyte(in,&something,&skip,24); |
---|
441 | DPRINT0 ("Sign & gds->pol.lLon1\n"); |
---|
442 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
443 | gds->pol.lLon1 = (long) (something) & 8388607; /* get Lo1 */ |
---|
444 | if(sign) /* negative value */ |
---|
445 | gds->pol.lLon1 = - gds->pol.lLon1; /* multiply by -1 */ |
---|
446 | |
---|
447 | /* |
---|
448 | * FUNCTION gbyte !get resolution & comp flag |
---|
449 | */ |
---|
450 | gbyte(in,&something,&skip,8); |
---|
451 | DPRINT0 ("gds->pol.usRes_flag\n"); |
---|
452 | gds->pol.usRes_flag = (short) something; /* get resolution & comp flags */ |
---|
453 | |
---|
454 | /* |
---|
455 | * FUNCTION gbyte !get Orientation Longitude |
---|
456 | */ |
---|
457 | gbyte(in,&something,&skip,24); |
---|
458 | DPRINT0 ("Sign & gds->pol.lLon_orient\n"); |
---|
459 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
460 | gds->pol.lLon_orient = (long) (something) & 8388607; /* Orientation */ |
---|
461 | if(sign) /* negative value , multiply by -1 */ |
---|
462 | gds->pol.lLon_orient = - gds->pol.lLon_orient; |
---|
463 | |
---|
464 | /* |
---|
465 | * FUNCTION gbyte !get Increment along a Row |
---|
466 | */ |
---|
467 | gbyte(in,&something,&skip,24); |
---|
468 | DPRINT0 ("gds->pol.ulDx\n"); |
---|
469 | gds->pol.ulDx = (float) something; /* get Dx */ |
---|
470 | |
---|
471 | /* |
---|
472 | * FUNCTION gbyte !get Increment along a Column |
---|
473 | */ |
---|
474 | gbyte(in,&something,&skip,24); |
---|
475 | DPRINT0 ("gds->pol.ulDy\n"); |
---|
476 | gds->pol.ulDy = (float) something; /* get Dy */ |
---|
477 | |
---|
478 | /* |
---|
479 | * FUNCTION gbyte !get projection center flag |
---|
480 | */ |
---|
481 | gbyte(in,&something,&skip,8); |
---|
482 | DPRINT0 ("gds->pol.usProj_flag\n"); |
---|
483 | gds->pol.usProj_flag = (short) something; /* Projection center flag */ |
---|
484 | |
---|
485 | /* |
---|
486 | * FUNCTION gbyte !get scanning mode |
---|
487 | */ |
---|
488 | gbyte(in,&something,&skip,8); |
---|
489 | DPRINT0 ("gds->pol.usScan_mode\n"); |
---|
490 | gds->pol.usScan_mode = (short) something; /* get scaning mode flag */ |
---|
491 | |
---|
492 | /* |
---|
493 | * FUNCTION gbyte !reserved zero |
---|
494 | */ |
---|
495 | gbyte(in,&something,&skip,32); |
---|
496 | DPRINT0 ("gds->pol.usZero\n"); |
---|
497 | gds->pol.usZero = (int) something; /* get Reserved zero */ |
---|
498 | |
---|
499 | if (gds->pol.usNx == 65535) { |
---|
500 | gds->head.thin = (int *)calloc(gds->pol.usNy,sizeof(int)); |
---|
501 | if (gds->head.thin == NULL) { |
---|
502 | sprintf(errmsg, |
---|
503 | "%s: failed to create array[%d] for thinned grid information", |
---|
504 | func, gds->head.thin); |
---|
505 | goto BYE; |
---|
506 | } |
---|
507 | for (i = 0; i<gds->pol.usNy; i++) { |
---|
508 | gbyte(in,&something,&skip,16); |
---|
509 | gds->head.thin[i] = (short)something; |
---|
510 | } |
---|
511 | } else { |
---|
512 | gds->head.thin = NULL; |
---|
513 | } |
---|
514 | |
---|
515 | break; |
---|
516 | |
---|
517 | case LAMB_PRJ: /* Lambert Conformal */ |
---|
518 | case ALBERS_PRJ: /* Albers equal-area */ |
---|
519 | case OBLIQ_LAMB_PRJ: /* Oblique Lambert Conformal */ |
---|
520 | /* |
---|
521 | * case Lambert conformal, secant or tangent, conical or bipolar: |
---|
522 | * case Albers equal-area, secant or tangent, conical or bipolar: |
---|
523 | * case Oblique Lambert conformal: |
---|
524 | * Mark the Projection type |
---|
525 | * FUNCTION gbyte !get Number of Columns |
---|
526 | */ |
---|
527 | gds->lam.usData_type = gds->head.usData_type; |
---|
528 | |
---|
529 | gbyte(in,&something,&skip,16); |
---|
530 | DPRINT0 ("gds->lam.iNx\n"); |
---|
531 | gds->lam.iNx = (int) something; /* get Nx */ |
---|
532 | |
---|
533 | /* |
---|
534 | * FUNCTION gbyte !get Number of Rows |
---|
535 | */ |
---|
536 | gbyte(in,&something,&skip,16); |
---|
537 | DPRINT0 ("gds->lam.iNy\n"); |
---|
538 | gds->lam.iNy = (int) something; /* get Ny */ |
---|
539 | |
---|
540 | /* |
---|
541 | * FUNCTION gbyte !get Latitude of First Point |
---|
542 | */ |
---|
543 | gbyte(in,&something,&skip,24); |
---|
544 | DPRINT0 ("Sign & gds->lam.lLat1\n"); |
---|
545 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
546 | gds->lam.lLat1 = (long) (something) & 8388607; /* get La1 */ |
---|
547 | if(sign) /* negative value */ |
---|
548 | gds->lam.lLat1 = - gds->lam.lLat1; /* multiply by -1 */ |
---|
549 | |
---|
550 | /* |
---|
551 | * FUNCTION gbyte !get Longitude of First Point |
---|
552 | */ |
---|
553 | gbyte(in,&something,&skip,24); |
---|
554 | DPRINT0 ("Sign & gds->lam.lLon1)\n"); |
---|
555 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
556 | gds->lam.lLon1 = (long) (something) & 8388607; /* get Lo1 */ |
---|
557 | if(sign) /* negative value */ |
---|
558 | gds->lam.lLon1 = - gds->lam.lLon1; /* multiply by -1 */ |
---|
559 | |
---|
560 | /* |
---|
561 | * FUNCTION gbyte !get resolution & comp flag |
---|
562 | */ |
---|
563 | gbyte(in,&something,&skip,8); |
---|
564 | DPRINT0 ("gds->lam.usRes_flag\n"); |
---|
565 | gds->lam.usRes_flag = (short) something; /* resolution & comp flags */ |
---|
566 | |
---|
567 | /* |
---|
568 | * FUNCTION gbyte !get Orientation Longitude |
---|
569 | */ |
---|
570 | gbyte(in,&something,&skip,24); |
---|
571 | DPRINT0 ("Sign & gds->lam.lLon_orient)\n"); |
---|
572 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
573 | gds->lam.lLon_orient = (long) (something) & 8388607; /* Orientation */ |
---|
574 | if(sign) /* negative value , multiply by -1 */ |
---|
575 | gds->lam.lLon_orient = - gds->lam.lLon_orient; |
---|
576 | |
---|
577 | /* |
---|
578 | * FUNCTION gbyte !get Increment along a Row |
---|
579 | */ |
---|
580 | gbyte(in,&something,&skip,24); |
---|
581 | DPRINT0 ("gds->lam.ulDx\n"); |
---|
582 | gds->lam.ulDx = (float) something; /* get Dx */ |
---|
583 | |
---|
584 | /* |
---|
585 | * FUNCTION gbyte !get Increment along a Column |
---|
586 | */ |
---|
587 | gbyte(in,&something,&skip,24); |
---|
588 | DPRINT0 ("gds->lam.ulDy\n"); |
---|
589 | gds->lam.ulDy = (float) something; /* get Dy */ |
---|
590 | |
---|
591 | /* |
---|
592 | * FUNCTION gbyte !get Projection Center |
---|
593 | */ |
---|
594 | gbyte(in,&something,&skip,8); |
---|
595 | DPRINT0 ("gds->lam.usProj_flag\n"); |
---|
596 | gds->lam.usProj_flag= (short) something; /* Projection center flag */ |
---|
597 | |
---|
598 | /* |
---|
599 | * FUNCTION gbyte !get scanning mode flag |
---|
600 | */ |
---|
601 | gbyte(in,&something,&skip,8); |
---|
602 | DPRINT0 ("gds->usScan_mode\n"); |
---|
603 | gds->lam.usScan_mode = (short) something; /* get scaning mode flag */ |
---|
604 | |
---|
605 | /* |
---|
606 | * FUNCTION gbyte !get First lat from pole that intersects Earth |
---|
607 | */ |
---|
608 | gbyte(in,&something,&skip,24); |
---|
609 | DPRINT0 ("gds->lLat_cut1\n"); |
---|
610 | gds->lam.lLat_cut1 = (long) something; /* get latin_1 */ |
---|
611 | |
---|
612 | /* |
---|
613 | * FUNCTION gbyte !get Second lat from pole that intersects Earth |
---|
614 | */ |
---|
615 | gbyte(in,&something,&skip,24); |
---|
616 | DPRINT0 ("gds->lLat_cut2\n"); |
---|
617 | gds->lam.lLat_cut2 = (long) something; /* get latin_2 */ |
---|
618 | |
---|
619 | /* |
---|
620 | * FUNCTION gbyte !get lat of south pole |
---|
621 | */ |
---|
622 | gbyte(in,&something,&skip,24); |
---|
623 | DPRINT0 ("Sign & gds->lLat_southpole\n"); |
---|
624 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
625 | gds->lam.lLat_southpole = (long) (something) & 8388607; /* lat S.pole*/ |
---|
626 | if(sign) /* negative value , multiply by -1 */ |
---|
627 | gds->lam.lLat_southpole = - gds->lam.lLat_southpole; |
---|
628 | |
---|
629 | /* |
---|
630 | * FUNCTION gbyte !get lon of South pole |
---|
631 | */ |
---|
632 | gbyte(in,&something,&skip,24); |
---|
633 | DPRINT0 ("Sign & gds->lLon_southpole\n"); |
---|
634 | sign = (int)(something >> 23) & 1; /* get sign */ |
---|
635 | gds->lam.lLon_southpole = (long) (something) & 8388607;/* lon S.pole */ |
---|
636 | if(sign) /* negative value, multiply by -1 */ |
---|
637 | gds->lam.lLon_southpole = - gds->lam.lLon_southpole; |
---|
638 | |
---|
639 | /* |
---|
640 | * FUNCTION gbyte !get Reserved zero |
---|
641 | */ |
---|
642 | gbyte(in,&something,&skip,16); |
---|
643 | DPRINT0 ("gds->lam.usZero\n"); |
---|
644 | gds->lam.usZero = (int) something; /* Reserved zero */ |
---|
645 | |
---|
646 | gds->head.thin = NULL; |
---|
647 | |
---|
648 | if (gds->lam.iNx == 65535) { |
---|
649 | gds->head.thin = (int *)calloc(gds->lam.iNy,sizeof(int)); |
---|
650 | if (gds->head.thin == NULL) { |
---|
651 | sprintf(errmsg, |
---|
652 | "%s: failed to create array[%d] for thinned grid information", |
---|
653 | func, gds->head.thin); |
---|
654 | goto BYE; |
---|
655 | } |
---|
656 | for (i = 0; i<gds->lam.iNy; i++) { |
---|
657 | gbyte(in,&something,&skip,16); |
---|
658 | gds->head.thin[i] = (short)something; |
---|
659 | } |
---|
660 | } else { |
---|
661 | gds->head.thin = NULL; |
---|
662 | } |
---|
663 | |
---|
664 | break; |
---|
665 | |
---|
666 | default : /* other cases not implemented in this version */ |
---|
667 | /* |
---|
668 | * default: ! unsupported data types |
---|
669 | * SET Status to bad |
---|
670 | */ |
---|
671 | DPRINT2 ("%s: unknown datatype=%d\n",func, gds->head.usData_type); |
---|
672 | sprintf(errmsg,"%s: unknown datatype=%d\n",func, gds->head.usData_type); |
---|
673 | status=1; /* set status to failure */ |
---|
674 | break; |
---|
675 | /* |
---|
676 | * |
---|
677 | * A.5 ENDSWITCH |
---|
678 | */ |
---|
679 | } /* end switch on data type */ |
---|
680 | |
---|
681 | /* |
---|
682 | * |
---|
683 | * A.6 DEBUG Print |
---|
684 | * |
---|
685 | * A.7 RETURN (status) |
---|
686 | */ |
---|
687 | BYE: |
---|
688 | DPRINT2 ("Exiting %s, stat=%d\n", func,status); |
---|
689 | return(status); |
---|
690 | /* |
---|
691 | * END OF FUNCTION |
---|
692 | * |
---|
693 | */ |
---|
694 | } |
---|