59 long timeStep, dataDate, dataTime;
64 codes_handle* h = NULL;
66 if ((f = fopen (fileName,
"rb")) == NULL) {
67 fprintf (stderr,
"In readGribLists, Error: Unable to open file %s\n", fileName);
73 while ((h = codes_handle_new_from_file(0, f, PRODUCT_GRIB, &err)) != NULL) {
74 if (err != CODES_SUCCESS) CODES_CHECK (err, 0);
77 CODES_CHECK(codes_get_string(h,
"shortName", shortName, &lenName), 0);
78 CODES_CHECK(codes_get_long(h,
"step", &timeStep), 0);
79 CODES_CHECK(codes_get_long(h,
"dataDate", &dataDate), 0);
80 CODES_CHECK(codes_get_long(h,
"dataTime", &dataTime), 0);
81 codes_handle_delete (h);
118 fprintf (stderr,
"In readGribLists, Error nTimeStamp = %zu\n",
zone->
nTimeStamp);
132 codes_handle *h = NULL;
134 if ((f = fopen (fileName,
"rb")) == NULL) {
135 fprintf (stderr,
"In readGribParameters, Error unable to open file %s\n",fileName);
140 if ((h = codes_handle_new_from_file(0, f, PRODUCT_GRIB, &err)) == NULL) {
141 fprintf (stderr,
"In readGribParameters, Error code handle from file : %s Code error: %s\n",\
142 fileName, codes_get_error_message(err));
148 CODES_CHECK(codes_get_long (h,
"centre", &
zone->
centreId),0);
150 CODES_CHECK(codes_get_long (h,
"stepUnits", &
zone->
stepUnits),0);
152 CODES_CHECK(codes_get_long (h,
"Ni", &
zone->
nbLon),0);
153 CODES_CHECK(codes_get_long (h,
"Nj", &
zone->
nbLat),0);
155 CODES_CHECK(codes_get_double (h,
"latitudeOfFirstGridPointInDegrees",&lat1),0);
156 CODES_CHECK(codes_get_double (h,
"longitudeOfFirstGridPointInDegrees",&
zone->
lonLeft),0);
157 CODES_CHECK(codes_get_double (h,
"latitudeOfLastGridPointInDegrees",&lat2),0);
158 CODES_CHECK(codes_get_double (h,
"longitudeOfLastGridPointInDegrees",&
zone->
lonRight),0);
159 CODES_CHECK(codes_get_double (h,
"iDirectionIncrementInDegrees",&
zone->
lonStep),0);
160 CODES_CHECK(codes_get_double (h,
"jDirectionIncrementInDegrees",&
zone->
latStep),0);
163 zone -> anteMeridian =
true;
166 zone -> anteMeridian =
false;
173 codes_handle_delete (h);
200 long bitmapPresent = 0, timeStep, oldTimeStep;
201 double lat, lon, val, indicatorOfParameter;
212 if (
zone -> nDataDate > 1) {
213 fprintf (stderr,
"In readGribAll, Error Grib file with more than 1 dataDate not supported nDataDate: %zu\n",
223 fprintf (stderr,
"In readGribAll, Error calloc tGribData [iFlow]\n");
230 codes_handle* h = NULL;
232 codes_iterator* iter = NULL;
233 if ((f = fopen (fileName,
"rb")) == NULL) {
236 fprintf (stderr,
"In readGribAll, Error Unable to open file %s\n", fileName);
242 oldTimeStep = timeStep;
245 while ((h = codes_handle_new_from_file (0, f, PRODUCT_GRIB, &err)) != NULL) {
246 if (err != CODES_SUCCESS) CODES_CHECK (err, 0);
249 CODES_CHECK (codes_get_long (h,
"bitmapPresent", &bitmapPresent), 0);
251 CODES_CHECK(codes_set_double (h,
"missingValue",
MISSING), 0);
255 CODES_CHECK(codes_get_string (h,
"shortName", shortName, &lenName), 0);
256 CODES_CHECK(codes_get_long (h,
"step", &timeStep), 0);
258 long progressTime = timeStep - oldTimeStep;
261 if ((timeStep != 0) && (progressTime > 0) &&
267 fprintf (stderr,
"In readGribAll: All time Step Are Not defined message: %d, timeStep: %ld, oldTimeStep: %ld, shortName: %s\n",
270 oldTimeStep = timeStep;
272 err = codes_get_double(h,
"indicatorOfParameter", &indicatorOfParameter);
273 if (err != CODES_SUCCESS)
274 indicatorOfParameter = -1;
277 iter = codes_grib_iterator_new(h, 0, &err);
278 if (err != CODES_SUCCESS) CODES_CHECK(err, 0);
281 while (codes_grib_iterator_next(iter, &lat, &lon, &val)) {
282 if (! (
zone -> anteMeridian))
288 fprintf (stderr,
"In readGribAll: Error iGrib : %ld\n", iGrib);
291 codes_handle_delete (h);
292 codes_grib_iterator_delete (iter);
301 if ((strcmp (shortName,
"10u") == 0) || (strcmp (shortName,
"ucurr") == 0))
303 else if ((strcmp (shortName,
"10v") == 0) || (strcmp (shortName,
"vcurr") == 0))
305 else if (strcmp (shortName,
"gust") == 0)
307 else if (strcmp (shortName,
"swh") == 0)
309 else if (indicatorOfParameter ==
GUST_GFS)
312 codes_grib_iterator_delete (iter);
313 codes_handle_delete (h);
static long updateLong(long value, size_t n, size_t maxSize, long array[])
Modify array with new value if not already in array.
static long indexOf(int timeStep, double lat, double lon, const Zone *zone)
find index in gribData table
bool readGribLists(const char *fileName, Zone *zone)
Read lists zone.timeStamp, shortName, zone.dataDate, dataTime before full grib reading.