OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
modis_grib_read.h
Go to the documentation of this file.
1 
2 #ifndef __MODIS_GRIB_READ_H
3 #define __MODIS_GRIB_READ_H
4 /*
5 !C-INC**********************************************************************
6 
7 !Description:
8  Include file for the read ancillary data routines.
9 
10 !Input Parameters: N/A
11 !Output Parameters: N/A
12 
13 !Revision History:
14 
15 !Team-unique Header:
16 
17  This software is developed by the MODIS Science Data Support
18  Team for the National Aeronautics and Space Administration,
19  Goddard Space Flight Center, under contract NAS5-32373.
20 
21 !References and credits:
22  N. Devine (devine@gsfc.nasa.gov)
23  W. Wolf (walter.wolf@sse.wisc.edu)
24 
25 !Design Notes:
26 
27 !END*************************************************************
28 */
29 
30 /* Structure for date & hours */
31 typedef struct {
32  int year;
33  int month;
34  int day;
35  int hour;
36 } grib_date_t;
37 
38 /* Structure for specifying grib records to read. See modis_grib_read(). */
39 typedef struct {
40  int rec_num;
41  char *name;
42  float *data;
43  int nx;
44  int ny;
47 
48 
49 /* Definitions */
50 
51 /* GRIB 2 business */
52 /* end GRIB 2 business */
53 
54 #ifndef INT2
55 #define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) \
56  * (int) (((a & 0x7f) << 8) + b))
57 #endif
58 
59 #define BDS_LEN(bds) ((int) ((bds[0]<<16)+(bds[1]<<8)+bds[2]))
60 
61 #define BDS_MoreFlags(bds) ((bds[3] & 16) != 0)
62 #define BDS_UnusedBits(bds) ((int) (bds[3] & 15))
63 
64 #define BDS_BinScale(bds) INT2(bds[4],bds[5])
65 
66 #define BDS_RefValue(bds) (ibm2flt(bds+6))
67 #define BDS_NumBits(bds) ((int) bds[10])
68 
69 #define BDS_DataStart(bds) ((int) (11 + BDS_MoreFlags(bds)*3))
70 
71 /* breaks if BDS_NumBits(bds) == 0 */
72 #define BDS_NValues(bds) (((BDS_LEN(bds) - BDS_DataStart(bds))*8 - \
73  BDS_UnusedBits(bds)) / BDS_NumBits(bds))
74 
75 /* undefined value -- if bitmap */
76 #define UNDEFINED 9.999e20
77 
78 /* version 1.2 of grib headers w. ebisuzaki */
79 
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)))
87 
88 /* version 1.3 of grib headers w. ebisuzaki */
89 /* this version is incomplete */
90 #ifndef INT3
91 #define INT3(a,b,c) ((1-(int) ((unsigned) (a & 0x80) >> 6)) \
92  * (int) (((a & 127) << 16)+(b<<8)+c))
93 #endif
94 #ifndef INT2
95 #define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) \
96  * (int) (((a & 127) << 8) + b))
97 #endif
98 
99 #define GDS_LEN(gds) ((int) ((gds[0]<<16)+(gds[1]<<8)+gds[2]))
100 
101 #define GDS_NV(gds) (gds[3])
102 #define GDS_DataType(gds) (gds[5])
103 
104 #define GDS_LatLon(gds) (gds[5] == 0)
105 #define GDS_Gaussian(gds) (gds[5] == 4)
106 
107 #define GDS_LatLon_nx(gds) ((int) ((gds[6] << 8) + gds[7]))
108 #define GDS_LatLon_ny(gds) ((int) ((gds[8] << 8) + gds[9]))
109 
110 /* index of NV and PV */
111 #define GDS_PL(gds) ((gds[4] == 255) ? -1 : \
112  (int) gds[3] * 4 + (int) gds[4] - 1)
113 
114 
115 
116 /*
117  * ************* local prototypes *************
118  */
119 
120 int modis_grib_setup (char* inlun, char* outlun, grib_record_t *grib_records,
121  int numofrecords, char *errmsg);
122 int modis_grib_read (char* lun, int version,
123  grib_record_t *grib_records, int N_grib_records,
124  char *errmsg );
125 
126 unsigned char *seek_grib(FILE *file, long *pos, long *len_grib,
127  unsigned char *buffer, unsigned int buf_len);
128 
129 int read_grib(FILE *file, long pos, long len_grib, unsigned char *buffer);
130 
131 int Name_Matches_PDS( char *name, char *pds );
132 
133 int parse_grib_message( unsigned char *buffer,
134  unsigned char **pds,
135  unsigned char **gds,
136  unsigned char **bms,
137  unsigned char **bds,
138  int *nx, int *ny, long *nxny, char *errmsg);
139 
140 void BDS_unpack(float *flt, unsigned char *bits, unsigned char *bitmap,
141  int n_bits, int n, double ref, double scale);
142 
143 double ibm2flt(unsigned char *ibm);
144 
145 double int_power(double x, int y);
146 
147 int GDS_grid(unsigned char *gds, int *nx, int *ny, long int *nxny);
148 
149 #define TRUE (0==0)
150 #define FALSE (1==0)
151 
152 /* version 3.4 of grib headers w. ebisuzaki */
153 /* this version is incomplete */
154 
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])
169 
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]))
173 
174 /* this requires a 32-bit default integer machine */
175 #define PDS_Field(pds) ((pds[8]<<24)+(pds[9]<<16)+(pds[10]<<8)+pds[11])
176 
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)))
192 
193 
194 /* Error messages added by N. Devine */
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
203 
204 #define VERSION "wgrib v1.5.0b10 (5-07-96) Wesley Ebisuzaki"
205 
206 #define CHECK_GRIB
207 
208 /*
209  * MSEEK = I/O buffer size for seek_grib
210  */
211 
212 #define MSEEK 1024
213 #define BUFF_ALLOC0 40000
214 
215 #ifndef min
216 #define min(a,b) ((a) < (b) ? (a) : (b))
217 #define max(a,b) ((a) < (b) ? (b) : (a))
218 #endif
219 
220 
221 #endif
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)
float32 * pos
Definition: l1_czcs_hdf.c:35
grib_date_t date
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
Definition: HISTORY.txt:413
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)
version
Definition: setup.py:15
int GDS_grid(unsigned char *gds, int *nx, int *ny, long int *nxny)