21 { 1, -0.499999, -0.499999 }, \
24 { 1, 127.0, 511.0 }, \
25 { 1, 127.5, 511.5 }, \
26 { 1, 511.0, 2047.0 }, \
27 { 1, 511.5, 2047.5 }, \
28 { 1, 101.97, 64.23 }, \
31 { 65, -0.499999, -0.499999 }, \
34 { 65, 127.0, 511.0 }, \
35 { 65, 127.5, 511.5 }, \
36 { 65, 511.0, 2047.0 }, \
37 { 65, 511.5, 2047.5 }, \
38 { 65, 101.97, 64.23 }, \
39 { 65, 101.0, 64.0 }, \
41 { 91, -0.499999, -0.499999 }, \
44 { 91, 127.0, 511.0 }, \
45 { 91, 127.5, 511.5 }, \
46 { 91, 511.0, 2047.0 }, \
47 { 91, 511.5, 2047.5 }, \
48 { 91, 101.97, 64.23 }, \
49 { 91, 101.0, 64.0 }, \
50 { 180, -0.5, -0.5 }, \
51 { 180, -0.499999, -0.499999 }, \
54 { 180, 127.0, 511.0 }, \
55 { 180, 127.5, 511.5 }, \
56 { 180, 511.0, 2047.0 }, \
57 { 180, 511.5, 2047.5 }, \
58 { 180, 101.97, 64.23 }, \
59 { 180, 101.0, 64.0 }, \
62 int main(
int argc,
char *argv[]) {
70 double savelon_r1, savelon_r2;
79 int32 spherecode, zonecode, projcode;
80 float64 projparam[
NPROJ];
88 intn hdfeos_status_code;
89 void *mem_status_code;
98 fprintf(stderr,
"Usage: %s hdfeos_grid_file\n", argv[0]);
108 hdfeos_status_code =
GDinqgrid(filepath, NULL, &strbufsize);
111 mem_status_code = gridlist = (
char *)malloc(strbufsize+1);
114 hdfeos_status_code = ngrid =
GDinqgrid(filepath, gridlist, NULL);
117 mem_status_code = gridname = (
char **)malloc(ngrid *
sizeof(
char *));
120 gridname[0] = strtok(gridlist,
",");
121 for (igrid = 1; igrid < ngrid; igrid++) gridname[igrid] = strtok(NULL,
",");
134 for (igrid = 0; igrid < ngrid; igrid++) {
140 hdfeos_status_code = gid =
GDattach(fid, gridname[igrid]);
150 hdfeos_status_code = ndim =
GDinqdims(gid, dimlist, dim);
154 if (dim[ndim - 1] !=
NBLOCK)
MTK_ERROR(
"File does not have 180 blocks");
156 hdfeos_status_code =
GDgridinfo(gid, &nline, &nsample, ulc, lrc);
165 printf(
"\nFilename (path/orbit): %s\n", filepath);
166 printf(
"Gridname: %s\n", gridname[igrid]);
167 printf(
"Lines/Samples: (%d, %d)\n", nline, nsample);
168 printf(
"ULC (x,y) (m): (%f, %f)\n", ulc[0], ulc[1]);
169 printf(
"LRC (x,y) (m): (%f, %f)\n", lrc[0], lrc[1]);
170 printf(
"Block offsets: (%f", offset[0]);
171 for (i = 1; i <
NOFFSET; i++) printf(
", %f", offset[i]);
179 hdfeos_status_code =
GDprojinfo(gid, &projcode, &zonecode,
180 &spherecode, projparam);
183 for_init((
long)projcode, (
long)zonecode, (
double*)projparam,
184 (
long)spherecode, NULL, NULL, &iflg, for_trans);
187 inv_init((
long)projcode, (
long)zonecode, (
double*)projparam,
188 (
long)spherecode, NULL, NULL, &iflg, inv_trans);
191 printf(
"GCTP projection code: %d\n", projcode);
192 printf(
"GCTP zone code (not used for SOM): %d\n", zonecode);
193 printf(
"GCTP sphere code: %d\n", spherecode);
194 printf(
"GCTP projection parameters: (%f",projparam[0]);
195 for (i = 1; i <
NPROJ; i++) printf(
", %f", projparam[i]);
212 printf(
" (blk, line , sample ) " 216 for (i = 0; i <
npts; i++) {
226 misrinv(b, l, s, &somx, &somy);
227 sominv(somx, somy, &lon_r, &lat_r);
229 printf(
"%2d: (%3d,%11.6f,%12.6f) -> (%17.6f,%17.6f) -> " 230 "(%10.6f,%11.6f) --|\n",
231 i, b, l, s, somx, somy, lat_r *
R2D, lon_r * R2D);
237 somfor(lon_r, lat_r, &somx, &somy);
238 misrfor(somx, somy, &b, &l, &s);
240 if (b != pts[i].block) diffflg =
'*';
243 printf(
" %c (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) <- " 244 "(%10.6f,%11.6f) <-|\n",
245 diffflg, b, l, s, somx, somy, lat_r * R2D, lon_r * R2D);
252 if (pts[i].block == 91 &&
253 pts[i].line == 0.0 &&
254 pts[i].sample == 0.0) {
257 if (pts[i].block == 91 &&
258 pts[i].line == (
float)(nline-1) &&
259 pts[i].sample == (
float)(nsample-1)) {
270 if (savelon_r1 < 0.0 && savelon_r2 > 0.0 ||
271 savelon_r1 > 0.0 && savelon_r2 < 0.0) {
272 lon_r = (savelon_r1 - savelon_r2) / 2.0;
274 lon_r = (savelon_r1 + savelon_r2) / 2.0;
281 somfor(lon_r, lat_r, &somx, &somy);
282 misrfor(somx, somy, &b, &l, &s);
284 printf(
"%2d: (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) <- " 285 "(%10.6f,%11.6f) = equator crossing\n",
286 npts, b, l, s, somx, somy, lat_r *
R2D, lon_r * R2D);
295 sominv(somx, somy, &lon_r, &lat_r);
296 misrfor(somx, somy, &b, &l, &s);
298 printf(
"%2d: (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) -> " 299 "(%10.6f,%11.6f) = ulc of block 1\n",
300 npts+1, b, l, s, somx, somy, lat_r * R2D, lon_r * R2D);
309 sominv(somx, somy, &lon_r, &lat_r);
310 misrfor(somx, somy, &b, &l, &s);
312 printf(
"%2d: (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) -> " 313 "(%10.6f,%11.6f) = lrc of block 1\n",
314 npts+2, b, l, s, somx, somy, lat_r * R2D, lon_r * R2D);
323 sominv(somx, somy, &lon_r, &lat_r);
324 misrfor(somx, somy, &b, &l, &s);
326 printf(
"%2d: (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) -> " 327 "(%10.6f,%11.6f) = SOM origin (long of asc node)\n",
328 npts+3, b, l, s, somx, somy, lat_r * R2D, lon_r * R2D);
335 lon_r = (lon_r > 0.0 ? lon_r - (180.0*
D2R) : lon_r + (180.0*
D2R));
337 somfor(lon_r, lat_r, &somx, &somy);
338 misrfor(somx, somy, &b, &l, &s);
340 printf(
"%2d: (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) <- " 341 "(%10.6f,%11.6f) = SOM origin plus 180 in long.\n",
342 npts+4, b, l, s, somx, somy, lat_r * R2D, lon_r * R2D);
350 sominv(somx, somy, &lon_r, &lat_r);
351 misrfor(somx, somy, &b, &l, &s);
353 printf(
"%2d: (%3d,%11.6f,%12.6f) <- (%17.6f,%17.6f) -> " 354 "(%10.6f,%11.6f) = equator crossing\n",
355 npts+5, b, l, s, somx, somy, lat_r * R2D, lon_r * R2D);
360 if (gridlist) free(gridlist);
361 if (gridname) free(gridname);
363 printf(
"\nNotes:\n\n" 364 "1) Given a block, fractional line and fraction sample triplet the\n" 365 " following transformations performed:\n\n" 366 " Inverse transformation: (b,l.l,s.s) -> (X,Y) -> (lat,lon) -|\n" 367 " |--------------------------------------|\n" 368 " Forward transformation: |-> (lat,lon) -> (X,Y) -> (b,l.l,s.s)\n\n" 369 "2) The transforms marked with a * did not reproduce the same\n" 370 " answer either because of rounding errors in the GCTP codes or because\n" 371 " they are out of bounds of the particular grid. The misr transform\n" 372 " routines (misr_init, misrfor and misrinv) are designed to handle out\n" 373 " of bounds conditions and return all -1's. This enables a resampling\n" 374 " routine to determine whether resampling can be done or not, if these\n" 375 " routines are used for reprojection.\n\n" 376 "3) Notice that the ULC Y/LRC Y values returned by gridinfo are incorrectly \n" 377 " switched when compared to transform number 0, 5 or 7 (depending\n" 378 " on resolution).\n\n" 379 "4) Also note that the ULC/LRC values returned by gridinfo are for block 1\n" 380 " extreme pixel edges (not pixel centers).\n\n" 381 "5) Note that SOM X is always increasing as blocks increase (in fact,\n" 382 " SOM X is zero meters at the longitude of the ascending node - the\n" 383 " 5th parameter of projection paramters). SOM Y tends to be mostly\n" 384 " positive in the Northern blocks and negative in the Southern blocks.\n" 385 " Each SOM path is a separate projection with the origin at the\n" 386 " night side equator and the longitude of the ascending node.\n\n" 387 "6) The block offsets are the number of 1.1km subregions from the\n" 388 " previous block. The first offset is relative first block.\n\n" 389 "7) The 4th and 5th projection parameter are in the format of packed\n" 390 " dddmmmsss.ss as documented in the GCTP codes (see paksz.c).\n\n" 391 "8) MISR uses the GCTP SOM projection A which specifies the inclination\n" 392 " angle and longitude of the ascending node instead of path number\n\n" 393 "9) The last six transformations compute various special case locations.\n" 394 " Note the direction of the transform arrows. Can you determine why the\n" 395 " lrc of block 1 is actually in block 2? Hint: it is not the pixel\n" 396 " center, but rather the edge.\n\n" 397 "10) Last note. Remember that the SOM projection is singular at the poles\n" 398 " and thus undefined there.\n\n"
int32 GDattach(int32, char *)
int misr_init(const int nblock, const int nline, const int nsample, const float relOff[NOFFSET], const double ulc_coord[], const double lrc_coord[])
intn GDprojinfo(int32, int32 *, int32 *, int32 *, float64 [])
int main(int argc, char *argv[])
intn GDblkSOMoffset(int32, float32 [], int32, char *)
int misrfor(const double x, const double y, int *block, float *line, float *sample)
intn GDgridinfo(int32, int32 *, int32 *, float64 [], float64 [])
int sominv(double y, double x, double *lon, double *lat)
int misrinv(const int block, const float line, const float sample, double *x, double *y)
int for_init(int outsys, int outzone, const double *outparm, int outdatum, char *fn27, char *fn83, int *iflg, int(*for_trans[])(double, double, double *, double *))
int32 GDinqdims(int32, char *, int32 [])
int32 GDinqgrid(char *, char *, int32 *)
int somfor(double lon, double lat, double *y, double *x)
HDFFCLIBAPI intf * offset
int32 GDopen(char *, intn)
int inv_init(int insys, int inzone, const double *inparm, int indatum, char *fn27, char *fn83, int *iflg, int(*inv_trans[])(double, double, double *, double *))
#define MEM_ERROR_CHECK(msg)
#define HDFEOS_ERROR_CHECK(msg)