Go to the documentation of this file.
2 #ifndef __MODIS_GRIB_READ_H
3 #define __MODIS_GRIB_READ_H
55 #define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) \
56 * (int) (((a & 0x7f) << 8) + b))
59 #define BDS_LEN(bds) ((int) ((bds[0]<<16)+(bds[1]<<8)+bds[2]))
61 #define BDS_MoreFlags(bds) ((bds[3] & 16) != 0)
62 #define BDS_UnusedBits(bds) ((int) (bds[3] & 15))
64 #define BDS_BinScale(bds) INT2(bds[4],bds[5])
66 #define BDS_RefValue(bds) (ibm2flt(bds+6))
67 #define BDS_NumBits(bds) ((int) bds[10])
69 #define BDS_DataStart(bds) ((int) (11 + BDS_MoreFlags(bds)*3))
72 #define BDS_NValues(bds) (((BDS_LEN(bds) - BDS_DataStart(bds))*8 - \
73 BDS_UnusedBits(bds)) / BDS_NumBits(bds))
76 #define UNDEFINED 9.999e20
80 #define BMS_LEN(bms) ((bms) == NULL ? 0 : \
81 (bms[0]<<16)+(bms[1]<<8)+bms[2])
82 #define BMS_UnusedBits(bms) ((bms) == NULL ? 0 : bms[3])
83 #define BMS_StdMap(bms) ((bms) == NULL ? 0 : ((bms[4]<<8) + bms[5]))
84 #define BMS_bitmap(bms) ((bms) == NULL ? NULL : (bms)+6)
85 #define BMS_nxny(bms) ((((bms) == NULL) || BMS_StdMap(bms)) \
86 ? 0 : (BMS_LEN(bms)*8 - 48 - BMS_UnusedBits(bms)))
91 #define INT3(a,b,c) ((1-(int) ((unsigned) (a & 0x80) >> 6)) \
92 * (int) (((a & 127) << 16)+(b<<8)+c))
95 #define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) \
96 * (int) (((a & 127) << 8) + b))
99 #define GDS_LEN(gds) ((int) ((gds[0]<<16)+(gds[1]<<8)+gds[2]))
101 #define GDS_NV(gds) (gds[3])
102 #define GDS_DataType(gds) (gds[5])
104 #define GDS_LatLon(gds) (gds[5] == 0)
105 #define GDS_Gaussian(gds) (gds[5] == 4)
107 #define GDS_LatLon_nx(gds) ((int) ((gds[6] << 8) + gds[7]))
108 #define GDS_LatLon_ny(gds) ((int) ((gds[8] << 8) + gds[9]))
111 #define GDS_PL(gds) ((gds[4] == 255) ? -1 : \
112 (int) gds[3] * 4 + (int) gds[4] - 1)
121 int numofrecords,
char *errmsg);
127 unsigned char *buffer,
unsigned int buf_len);
138 int *nx,
int *ny,
long *nxny,
char *errmsg);
140 void BDS_unpack(
float *flt,
unsigned char *bits,
unsigned char *bitmap,
141 int n_bits,
int n,
double ref,
double scale);
143 double ibm2flt(
unsigned char *ibm);
147 int GDS_grid(
unsigned char *gds,
int *nx,
int *ny,
long int *nxny);
155 #define PDS_Len1(pds) (pds[0])
156 #define PDS_Len2(pds) (pds[1])
157 #define PDS_Len3(pds) (pds[2])
158 #define PDS_LEN(pds) ((int) ((pds[0]<<16)+(pds[1]<<8)+pds[2]))
159 #define PDS_Vsn(pds) (pds[3])
160 #define PDS_Center(pds) (pds[4])
161 #define PDS_Model(pds) (pds[5])
162 #define PDS_Grid(pds) (pds[6])
163 #define PDS_HAS_GDS(pds) ((pds[7] & 128) != 0)
164 #define PDS_HAS_BMS(pds) ((pds[7] & 64) != 0)
165 #define PDS_PARAM(pds) (pds[8])
166 #define PDS_L_TYPE(pds) (pds[9])
167 #define PDS_LEVEL1(pds) (pds[10])
168 #define PDS_LEVEL2(pds) (pds[11])
170 #define PDS_KPDS5(pds) (pds[8])
171 #define PDS_KPDS6(pds) (pds[9])
172 #define PDS_KPDS7(pds) ((int) ((pds[10]<<8) + pds[11]))
175 #define PDS_Field(pds) ((pds[8]<<24)+(pds[9]<<16)+(pds[10]<<8)+pds[11])
177 #define PDS_Year(pds) (pds[12])
178 #define PDS_Month(pds) (pds[13])
179 #define PDS_Day(pds) (pds[14])
180 #define PDS_Hour(pds) (pds[15])
181 #define PDS_Minute(pds) (pds[16])
182 #define PDS_ForecastTimeUnit(pds) (pds[17])
183 #define PDS_P1(pds) (pds[18])
184 #define PDS_P2(pds) (pds[19])
185 #define PDS_TimeRange(pds) (pds[20])
186 #define PDS_NumAve(pds) ((int) ((pds[21]<<8)+pds[22]))
187 #define PDS_NumMissing(pds) (pds[23])
188 #define PDS_Century(pds) (pds[24])
189 #define PDS_Subcenter(pds) (pds[25])
190 #define PDS_DecimalScale(pds) INT2(pds[26],pds[27])
191 #define PDS_Year4(pds) (pds[12] + 100*(pds[24] - (pds[12] != 0)))
195 #define GRIB_SUCCESS 0
196 #define GRIB_MISSING_END_SECTION -1
197 #define GRIB_MISSING_GDS_NUM_DATAPOINTS 1
198 #define GRIB_BAD_SEEK 8
199 #define GRIB_MALLOC_ERROR 11
200 #define GRIB_INPUT_ERROR 12
201 #define GRIB_ERROR_IN_CALLED 13
202 #define GRIB_BAD_NUM_VS_NAME 14
204 #define VERSION "wgrib v1.5.0b10 (5-07-96) Wesley Ebisuzaki"
213 #define BUFF_ALLOC0 40000
216 #define min(a,b) ((a) < (b) ? (a) : (b))
217 #define max(a,b) ((a) < (b) ? (b) : (a))
double ibm2flt(unsigned char *ibm)
void BDS_unpack(float *flt, unsigned char *bits, unsigned char *bitmap, int n_bits, int n, double ref, double scale)
int modis_grib_read(char *lun, int version, grib_record_t *grib_records, int N_grib_records, char *errmsg)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
double int_power(double x, int y)
int parse_grib_message(unsigned char *buffer, unsigned char **pds, unsigned char **gds, unsigned char **bms, unsigned char **bds, int *nx, int *ny, long *nxny, char *errmsg)
unsigned char * seek_grib(FILE *file, long *pos, long *len_grib, unsigned char *buffer, unsigned int buf_len)
int Name_Matches_PDS(char *name, char *pds)
int read_grib(FILE *file, long pos, long len_grib, unsigned char *buffer)
int modis_grib_setup(char *inlun, char *outlun, grib_record_t *grib_records, int numofrecords, char *errmsg)
int GDS_grid(unsigned char *gds, int *nx, int *ny, long int *nxny)