| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include "grib2.h" |
| 4 |
|
| 5 |
g2int getdim(unsigned char *csec3,g2int *width,g2int *height,g2int *iscan) |
| 6 |
//$$$ SUBPROGRAM DOCUMENTATION BLOCK |
| 7 |
// . . . . |
| 8 |
// SUBPROGRAM: getdim |
| 9 |
// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-11 |
| 10 |
// |
| 11 |
// ABSTRACT: This subroutine returns the dimensions and scanning mode of |
| 12 |
// a grid definition packed in GRIB2 Grid Definition Section 3 format. |
| 13 |
// |
| 14 |
// PROGRAM HISTORY LOG: |
| 15 |
// 2002-12-11 Gilbert |
| 16 |
// |
| 17 |
// USAGE: int getdim(unsigned char *csec3,g2int *width, |
| 18 |
// g2int *height, g2int *iscan) |
| 19 |
// INPUT ARGUMENT LIST: |
| 20 |
// csec3 - Character array that contains the packed GRIB2 GDS |
| 21 |
// |
| 22 |
// OUTPUT ARGUMENT LIST: |
| 23 |
// width - x (or i) dimension of the grid. |
| 24 |
// height - y (or j) dimension of the grid. |
| 25 |
// iscan - Scanning mode ( see Code Table 3.4 ) |
| 26 |
// |
| 27 |
// REMARKS: Returns width and height set to zero, if grid template |
| 28 |
// not recognized. |
| 29 |
// |
| 30 |
// ATTRIBUTES: |
| 31 |
// LANGUAGE: C |
| 32 |
// MACHINE: IBM SP |
| 33 |
// |
| 34 |
//$$$ |
| 35 |
{ |
| 36 |
|
| 37 |
g2int *igdstmpl,*list_opt; |
| 38 |
g2int *igds; |
| 39 |
g2int iofst,igdtlen,num_opt,jerr; |
| 40 |
|
| 41 |
igdstmpl=0; |
| 42 |
list_opt=0; |
| 43 |
igds=0; |
| 44 |
iofst=0; // set offset to beginning of section |
| 45 |
jerr= g2_unpack3(csec3,G2_UNKNOWN_SIZE,&iofst,&igds,&igdstmpl, |
| 46 |
&igdtlen,&list_opt,&num_opt); |
| 47 |
if (jerr == 0) { |
| 48 |
switch ( igds[4] ) // Template number |
| 49 |
{ |
| 50 |
case 0: // Lat/Lon |
| 51 |
case 1: |
| 52 |
case 2: |
| 53 |
case 3: |
| 54 |
{ |
| 55 |
*width=igdstmpl[7]; |
| 56 |
*height=igdstmpl[8]; |
| 57 |
*iscan=igdstmpl[18]; |
| 58 |
break; |
| 59 |
} |
| 60 |
case 10: // Mercator |
| 61 |
{ |
| 62 |
*width=igdstmpl[7]; |
| 63 |
*height=igdstmpl[8]; |
| 64 |
*iscan=igdstmpl[15]; |
| 65 |
break; |
| 66 |
} |
| 67 |
case 20: // Polar Stereographic |
| 68 |
{ |
| 69 |
*width=igdstmpl[7]; |
| 70 |
*height=igdstmpl[8]; |
| 71 |
*iscan=igdstmpl[17]; |
| 72 |
break; |
| 73 |
} |
| 74 |
case 30: // Lambert Conformal |
| 75 |
{ |
| 76 |
*width=igdstmpl[7]; |
| 77 |
*height=igdstmpl[8]; |
| 78 |
*iscan=igdstmpl[17]; |
| 79 |
break; |
| 80 |
} |
| 81 |
case 40: // Gaussian |
| 82 |
case 41: |
| 83 |
case 42: |
| 84 |
case 43: |
| 85 |
{ |
| 86 |
*width=igdstmpl[7]; |
| 87 |
*height=igdstmpl[8]; |
| 88 |
*iscan=igdstmpl[18]; |
| 89 |
break; |
| 90 |
} |
| 91 |
case 90: // Space View/Orthographic |
| 92 |
{ |
| 93 |
*width=igdstmpl[7]; |
| 94 |
*height=igdstmpl[8]; |
| 95 |
*iscan=igdstmpl[16]; |
| 96 |
break; |
| 97 |
} |
| 98 |
case 110: // Equatorial Azimuthal |
| 99 |
{ |
| 100 |
*width=igdstmpl[7]; |
| 101 |
*height=igdstmpl[8]; |
| 102 |
*iscan=igdstmpl[15]; |
| 103 |
break; |
| 104 |
} |
| 105 |
default: |
| 106 |
{ |
| 107 |
*width=0; |
| 108 |
*height=0; |
| 109 |
*iscan=0; |
| 110 |
break; |
| 111 |
} |
| 112 |
} // end switch |
| 113 |
} |
| 114 |
else { |
| 115 |
*width=0; |
| 116 |
*height=0; |
| 117 |
} |
| 118 |
|
| 119 |
if (igds != 0) free(igds); |
| 120 |
if (igdstmpl != 0) free(igdstmpl); |
| 121 |
if (list_opt != 0) free(list_opt); |
| 122 |
|
| 123 |
return 0; |
| 124 |
} |