Commit 6ce92915 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

moved some helper functions to gribapi_utilities.c [patch 7/14 from Nathanael]

parent 6e3813f8
......@@ -227,6 +227,8 @@ src/gaussgrid.h -text
src/getline.c -text
src/gribapi.c -text
src/gribapi.h -text
src/gribapi_utilities.c -text
src/gribapi_utilities.h -text
src/grid.c -text
src/grid.h -text
src/ieg.h -text
......@@ -267,6 +269,8 @@ src/pio_util.c -text
src/pio_util.h -text
src/pkgconfig/cdi.pc.in -text
src/pkgconfig/cdipio.pc.in -text
src/proprietarySystemWorkarounds.c -text
src/proprietarySystemWorkarounds.h -text
src/resource_handle.c -text
src/resource_handle.h -text
src/resource_unpack.c -text
......
......@@ -50,6 +50,8 @@ libcdi_la_SOURCES = \
gaussgrid.h \
gribapi.c \
gribapi.h \
gribapi_utilities.c \
gribapi_utilities.h \
grid.c \
grid.h \
ieg.h \
......@@ -62,6 +64,8 @@ libcdi_la_SOURCES = \
namespace.h \
serialize.h \
serialize.c \
proprietarySystemWorkarounds.c \
proprietarySystemWorkarounds.h \
resource_handle.c\
resource_handle.h\
service.h \
......
......@@ -149,8 +149,11 @@ libcdi_la_DEPENDENCIES =
am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \
cdf_int.lo cdi_error.lo cdi_util.lo cdiFortran.lo \
cgribexlib.lo dmemory.lo cksum.lo cdi_cksum.lo error.lo \
extralib.lo file.lo gaussgrid.lo gribapi.lo grid.lo ieglib.lo \
institution.lo model.lo namespace.lo serialize.lo \
extralib.lo file.lo gaussgrid.lo gribapi.lo \
gribapi_utilities.lo grid.lo ieglib.lo \
institution.lo \
model.lo namespace.lo serialize.lo \
proprietarySystemWorkarounds.lo \
resource_handle.lo servicelib.lo stream_cdf.lo \
stream_cgribex.lo stream_ext.lo stream_grb.lo \
stream_gribapi.lo stream_history.lo stream_ieg.lo \
......@@ -479,6 +482,8 @@ libcdi_la_SOURCES = \
gaussgrid.h \
gribapi.c \
gribapi.h \
gribapi_utilities.c \
gribapi_utilities.h \
grid.c \
grid.h \
ieg.h \
......@@ -491,6 +496,8 @@ libcdi_la_SOURCES = \
namespace.h \
serialize.h \
serialize.c \
proprietarySystemWorkarounds.c \
proprietarySystemWorkarounds.h \
resource_handle.c\
resource_handle.h\
service.h \
......@@ -721,6 +728,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gaussgrid.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gribapi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gribapi_utilities.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grid.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ieglib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/institution.Plo@am__quote@
......@@ -741,6 +749,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_serialize.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_server.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_util.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proprietarySystemWorkarounds.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_handle.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_unpack.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/serialize.Plo@am__quote@
......
This diff is collapsed.
#ifndef INCLUDE_GUARD_CDI_GRIBAPI_UTILITIES_H
#define INCLUDE_GUARD_CDI_GRIBAPI_UTILITIES_H
#include "grib_api.h"
#include "grid.h"
#include <stdbool.h>
char* gribCopyString(grib_handle* gribHandle, const char* key);
bool gribCheckString(grib_handle* gribHandle, const char* key, const char* expectedValue);
bool gribCheckLong(grib_handle* gribHandle, const char* key, long expectedValue);
long gribGetLong(grib_handle* gh, const char* key);
long gribGetLongDefault(grib_handle* gribHandle, const char* key, long defaultValue);
double gribGetDouble(grib_handle* gh, const char* key);
double gribGetDoubleDefault(grib_handle* gribHandle, const char* key, double defaultValue);
size_t gribGetArraySize(grib_handle* gribHandle, const char* key);
void gribGetDoubleArray(grib_handle* gribHandle, const char* key, double* array); //The caller is responsible to ensure a sufficiently large buffer.
void gribGetLongArray(grib_handle* gribHandle, const char* key, long* array); //The caller is responsible to ensure a sufficiently large buffer.
long gribEditionNumber(grib_handle* gh);
char* gribMakeTimeString(grib_handle* gh, bool getEndTime); //For statistical fields, setting getEndTime produces the time of the end of the integration period, otherwise the time of the start of the integration period is returned. Returns NULL if getEndTime is set and the field does not have an integration period.
int gribapiTimeIsFC(grib_handle *gh);
int gribapiGetTsteptype(grib_handle *gh);
int gribGetDatatype(grib_handle* gribHandle);
int gribapiGetParam(grib_handle *gh);
int gribapiGetGridType(grib_handle *gh);
void gribapiGetGrid(grib_handle *gh, grid_t *grid);
#endif
#include "proprietarySystemWorkarounds.h"
#include "dmemory.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
char* myStrDup(const char* string)
{
char* result = xmalloc(strlen(string) + 1);
if(result)
{
strcpy(result, string);
}
else
{
errno = ENOMEM;
}
return result;
}
char* myAsprintf(char* format, ...)
{
va_list args;
int size = 64;
char *buffer = xmalloc(size);
int nchars;
//Try to print in the allocated space.
va_start(args, format);
nchars = vsnprintf(buffer, size, format, args);
va_end(args);
if (nchars >= size)
{
//Reallocate buffer now that we know how much space is needed.
size = nchars + 1;
buffer = xrealloc(buffer, size);
va_start(args, format);
vsnprintf(buffer, size, format, args);
va_end(args);
}
return buffer;
}
#ifndef INCLUDE_GUARD_CDI_PROPRIETARY_SYSTEM_WORKAROUNDS_H
#define INCLUDE_GUARD_CDI_PROPRIETARY_SYSTEM_WORKAROUNDS_H
char* myStrDup(const char* string); //This exactly implements the standardized behavior of strdup().
char* myAsprintf(char* format, ...) __attribute__((format(printf, 1, 2))); //This implementation differs from standard asprintf() function in the way the resulting string pointer is returned.
#endif
......@@ -8,6 +8,8 @@
#include "cdi.h"
#include "cdi_int.h"
#include "file.h"
#include "gribapi_utilities.h"
#include "stream_grb.h"
#include "varscan.h"
#include "datetime.h"
#include "vlist.h"
......@@ -61,42 +63,6 @@ int my_grib_set_string(grib_handle* h, const char* key, const char* val, size_t*
return grib_set_string(h, key, val, length);
}
static
int gribapiGetGridType(grib_handle *gh)
{
int gridtype = GRID_GENERIC;
int gribgridtype = -1;
long lpar;
{
int status;
status = grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar);
if ( status == 0 ) gribgridtype = (int) lpar;
switch (gribgridtype)
{
case GRIB2_GTYPE_LATLON: { GRIB_CHECK(grib_get_long(gh, "Ni", &lpar), 0);
if ( lpar == (long) GRIB_MISSING_LONG ) break;
}
case GRIB2_GTYPE_LATLON_ROT: { gridtype = GRID_LONLAT; break; }
case GRIB2_GTYPE_LCC: { gridtype = GRID_LCC; break; }
case GRIB2_GTYPE_GAUSSIAN: { GRIB_CHECK(grib_get_long(gh, "Ni", &lpar), 0);
if ( lpar == (long) GRIB_MISSING_LONG )
gridtype = GRID_GAUSSIAN_REDUCED;
else
gridtype = GRID_GAUSSIAN;
break;
}
case GRIB2_GTYPE_SPECTRAL: { gridtype = GRID_SPECTRAL; break; }
case GRIB2_GTYPE_GME: { gridtype = GRID_GME; break; }
case GRIB2_GTYPE_UNSTRUCTURED: { gridtype = GRID_UNSTRUCTURED; break; }
}
}
return (gridtype);
}
static
int gribapiGetIsRotated(grib_handle *gh)
{
......@@ -209,64 +175,6 @@ int gribapiGetEndStep(grib_handle *gh, int startStep, int timeunits)
return (endStep);
}
static
int gribapiTimeIsFC(grib_handle *gh)
{
long editionNumber;
int isFC = TRUE;
GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0);
if ( editionNumber > 1 )
{
long sigofrtime;
GRIB_CHECK(grib_get_long(gh, "significanceOfReferenceTime", &sigofrtime), 0);
if ( sigofrtime == 3 ) isFC = FALSE;
}
return (isFC);
}
static
int gribapiGetTsteptype(grib_handle *gh)
{
int tsteptype = TSTEP_INSTANT;
static int lprint = TRUE;
if ( gribapiTimeIsFC(gh) )
{
int status;
size_t len = 256;
char stepType[256];
status = grib_get_string(gh, "stepType", stepType, &len);
if ( status == 0 && len > 1 && len < 256 )
{
if ( strncmp("instant", stepType, len) == 0 ) tsteptype = TSTEP_INSTANT;
else if ( strncmp("avg", stepType, len) == 0 ) tsteptype = TSTEP_AVG;
else if ( strncmp("accum", stepType, len) == 0 ) tsteptype = TSTEP_ACCUM;
else if ( strncmp("max", stepType, len) == 0 ) tsteptype = TSTEP_MAX;
else if ( strncmp("min", stepType, len) == 0 ) tsteptype = TSTEP_MIN;
else if ( strncmp("diff", stepType, len) == 0 ) tsteptype = TSTEP_DIFF;
else if ( strncmp("rms", stepType, len) == 0 ) tsteptype = TSTEP_RMS;
else if ( strncmp("sd", stepType, len) == 0 ) tsteptype = TSTEP_SD;
else if ( strncmp("cov", stepType, len) == 0 ) tsteptype = TSTEP_COV;
else if ( strncmp("ratio", stepType, len) == 0 ) tsteptype = TSTEP_RATIO;
else if ( lprint )
{
Message("Time stepType %s unsupported, set to instant!", stepType);
lprint = FALSE;
}
// printf("stepType: %s %ld %d\n", stepType, len, tsteptype);
}
}
return (tsteptype);
}
static
void gribapiGetDataDateTime(grib_handle *gh, int *datadate, int *datatime)
{
......@@ -274,7 +182,7 @@ void gribapiGetDataDateTime(grib_handle *gh, int *datadate, int *datatime)
GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0);
*datadate = (int) lpar;
GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0);
GRIB_CHECK(grib_get_long(gh, "dataTime", &lpar), 0); //FIXME: This looses the seconds in GRIB2 files.
*datatime = (int) lpar*100;
}
......@@ -376,330 +284,6 @@ int gribapiGetValidityDateTime(grib_handle *gh, int *vdate, int *vtime)
return (tstepRange);
}
static
void gribapiGetGrid(grib_handle *gh, grid_t *grid)
{
long editionNumber;
GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0);
int gridtype = gribapiGetGridType(gh);
/*
if ( streamptr->unreduced && gridtype == GRID_GAUSSIAN_REDUCED )
{
gridtype = GRID_GAUSSIAN;
ISEC2_NumLon = 2*ISEC2_NumLat;
ISEC4_NumValues = ISEC2_NumLon*ISEC2_NumLat;
}
*/
memset(grid, 0, sizeof(grid_t));
size_t datasize;
GRIB_CHECK(grib_get_size(gh, "values", &datasize), 0);
long numberOfPoints;
GRIB_CHECK(grib_get_long(gh, "numberOfPoints", &numberOfPoints), 0);
switch (gridtype)
{
case GRID_LONLAT:
case GRID_GAUSSIAN:
{
long lpar;
GRIB_CHECK(grib_get_long(gh, "Ni", &lpar), 0);
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
int nlon = (int)lpar;
GRIB_CHECK(grib_get_long(gh, "Nj", &lpar), 0);
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
int nlat = (int)lpar;
if ( gridtype == GRID_GAUSSIAN )
{
GRIB_CHECK(grib_get_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", &lpar), 0);
grid->np = (int)lpar;
}
if ( numberOfPoints != nlon*nlat )
Error("numberOfPoints (%ld) and gridSize (%d) differ!", numberOfPoints, nlon*nlat);
/* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
grid->size = (int)numberOfPoints;
grid->xsize = nlon;
grid->ysize = nlat;
grid->xinc = 0;
grid->yinc = 0;
grid->xdef = 0;
GRIB_CHECK(grib_get_double(gh, "longitudeOfFirstGridPointInDegrees", &grid->xfirst), 0);
GRIB_CHECK(grib_get_double(gh, "longitudeOfLastGridPointInDegrees", &grid->xlast), 0);
GRIB_CHECK(grib_get_double(gh, "latitudeOfFirstGridPointInDegrees", &grid->yfirst), 0);
GRIB_CHECK(grib_get_double(gh, "latitudeOfLastGridPointInDegrees", &grid->ylast), 0);
GRIB_CHECK(grib_get_double(gh, "iDirectionIncrementInDegrees", &grid->xinc), 0);
if ( gridtype == GRID_LONLAT )
GRIB_CHECK(grib_get_double(gh, "jDirectionIncrementInDegrees", &grid->yinc), 0);
if ( IS_EQUAL(grid->xinc, GRIB_MISSING_DOUBLE) ) grid->xinc = 0;
/* if ( IS_NOT_EQUAL(grid->xfirst, 0) || IS_NOT_EQUAL(grid->xlast, 0) ) */
{
if ( grid->xsize > 1 )
{
if ( (grid->xfirst >= grid->xlast) && (grid->xfirst >= 180) ) grid->xfirst -= 360;
if ( editionNumber <= 1 )
{
/* correct xinc if necessary */
if ( IS_EQUAL(grid->xfirst, 0) && grid->xlast > 354 )
{
double xinc = 360. / grid->xsize;
if ( fabs(grid->xinc-xinc) > 0.0 )
{
grid->xinc = xinc;
if ( CDI_Debug ) Message("set xinc to %g", grid->xinc);
}
}
}
}
grid->xdef = 2;
}
grid->ydef = 0;
/* if ( IS_NOT_EQUAL(grid->yfirst, 0) || IS_NOT_EQUAL(grid->ylast, 0) ) */
{
if ( grid->ysize > 1 )
{
if ( editionNumber <= 1 )
{
}
}
grid->ydef = 2;
}
break;
}
case GRID_GAUSSIAN_REDUCED:
{
size_t dummy;
long *pl;
long lpar;
GRIB_CHECK(grib_get_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", &lpar), 0);
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
grid->np = (int)lpar;
GRIB_CHECK(grib_get_long(gh, "Nj", &lpar), 0);
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
int nlat = (int)lpar;
/* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
grid->size = (int)numberOfPoints;
grid->rowlon = (int *) malloc((size_t)nlat * sizeof (int));
pl = (long *) malloc((size_t)nlat * sizeof (long));
dummy = (size_t)nlat;
GRIB_CHECK(grib_get_long_array(gh, "pl", pl, &dummy), 0);
/* FIXME: assert(pl[i] >= INT_MIN && pl[i] <= INT_MIN) */
for (int i = 0; i < nlat; ++i ) grid->rowlon[i] = (int)pl[i];
free(pl);
grid->ysize = nlat;
grid->xinc = 0;
grid->yinc = 0;
grid->xdef = 0;
GRIB_CHECK(grib_get_double(gh, "longitudeOfFirstGridPointInDegrees", &grid->xfirst), 0);
GRIB_CHECK(grib_get_double(gh, "longitudeOfLastGridPointInDegrees", &grid->xlast), 0);
GRIB_CHECK(grib_get_double(gh, "latitudeOfFirstGridPointInDegrees", &grid->yfirst), 0);
GRIB_CHECK(grib_get_double(gh, "latitudeOfLastGridPointInDegrees", &grid->ylast), 0);
GRIB_CHECK(grib_get_double(gh, "iDirectionIncrementInDegrees", &grid->xinc), 0);
if ( IS_EQUAL(grid->xinc, GRIB_MISSING_DOUBLE) ) grid->xinc = 0;
/* if ( IS_NOT_EQUAL(grid->xfirst, 0) || IS_NOT_EQUAL(grid->xlast, 0) ) */
{
if ( grid->xsize > 1 )
{
if ( (grid->xfirst > grid->xlast) && (grid->xfirst >= 180) ) grid->xfirst -= 360;
if ( editionNumber <= 1 )
{
/* correct xinc if necessary */
if ( IS_EQUAL(grid->xfirst, 0) && grid->xlast > 354 )
{
double xinc = 360. / grid->xsize;
if ( fabs(grid->xinc-xinc) > 0.0 )
{
grid->xinc = xinc;
if ( CDI_Debug ) Message("set xinc to %g", grid->xinc);
}
}
}
}
grid->xdef = 2;
}
grid->ydef = 0;
/* if ( IS_NOT_EQUAL(grid->yfirst, 0) || IS_NOT_EQUAL(grid->ylast, 0) ) */
{
if ( grid->ysize > 1 )
{
if ( editionNumber <= 1 )
{
}
}
grid->ydef = 2;
}
break;
}
case GRID_LCC:
{
int nlon, nlat;
long lpar;
GRIB_CHECK(grib_get_long(gh, "Nx", &lpar), 0);
nlon = lpar;
GRIB_CHECK(grib_get_long(gh, "Ny", &lpar), 0);
nlat = lpar;
if ( numberOfPoints != nlon*nlat )
Error("numberOfPoints (%d) and gridSize (%d) differ!", (int)numberOfPoints, nlon*nlat);
grid->size = numberOfPoints;
grid->xsize = nlon;
grid->ysize = nlat;
GRIB_CHECK(grib_get_double(gh, "DxInMetres", &grid->lcc_xinc), 0);
GRIB_CHECK(grib_get_double(gh, "DyInMetres", &grid->lcc_yinc), 0);
GRIB_CHECK(grib_get_double(gh, "longitudeOfFirstGridPointInDegrees", &grid->lcc_originLon), 0);
GRIB_CHECK(grib_get_double(gh, "latitudeOfFirstGridPointInDegrees", &grid->lcc_originLat), 0);
GRIB_CHECK(grib_get_double(gh, "LoVInDegrees", &grid->lcc_lonParY), 0);
GRIB_CHECK(grib_get_double(gh, "Latin1InDegrees", &grid->lcc_lat1), 0);
GRIB_CHECK(grib_get_double(gh, "Latin2InDegrees", &grid->lcc_lat2), 0);
if ( editionNumber <= 1 )
{
GRIB_CHECK(grib_get_long(gh, "projectionCenterFlag", &lpar), 0);
grid->lcc_projflag = (int) lpar;
GRIB_CHECK(grib_get_long(gh, "scanningMode", &lpar), 0);
grid->lcc_scanflag = (int) lpar;
}
grid->xdef = 0;
grid->ydef = 0;
break;
}
case GRID_SPECTRAL:
{
size_t len = 256;
char typeOfPacking[256];
GRIB_CHECK(grib_get_string(gh, "packingType", typeOfPacking, &len), 0);
grid->lcomplex = 0;
if ( strncmp(typeOfPacking, "spectral_complex", len) == 0 ) grid->lcomplex = 1;
/* FIXME: assert(datasize >= INT_MIN && datasize <= INT_MAX) */
grid->size = (int)datasize;
long lpar;
GRIB_CHECK(grib_get_long(gh, "J", &lpar), 0);
/* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */
grid->trunc = (int)lpar;
break;
}
case GRID_GME:
{
/* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
grid->size = (int)numberOfPoints;
long lpar;
/* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */
if ( grib_get_long(gh, "nd", &lpar) == 0 ) grid->nd = (int)lpar;
/* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */
if ( grib_get_long(gh, "Ni", &lpar) == 0 ) grid->ni = (int)lpar;
/* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */
if ( grib_get_long(gh, "n2", &lpar) == 0 ) grid->ni2 = (int)lpar;
/* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */
if ( grib_get_long(gh, "n3", &lpar) == 0 ) grid->ni3 = (int)lpar;
break;
}
case GRID_UNSTRUCTURED:
{
unsigned char uuid[CDI_UUID_SIZE];
/*
char reference_link[8192];
size_t len = sizeof(reference_link);
reference_link[0] = 0;
*/
/* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
grid->size = (int)numberOfPoints;
long lpar;
if ( grib_get_long(gh, "numberOfGridUsed", &lpar) == 0 )
{
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
grid->number = (int)lpar;
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
if ( grib_get_long(gh, "numberOfGridInReference", &lpar) == 0 )
grid->position = (int)lpar;
/*
if ( grib_get_string(gh, "gridDescriptionFile", reference_link, &len) == 0 )
{
if ( strncmp(reference_link, "file://", 7) == 0 )
grid->reference = strdupx(reference_link);
}
*/
size_t len = (size_t)CDI_UUID_SIZE;
if ( grib_get_bytes(gh, "uuidOfHGrid", uuid, &len) == 0)
{
memcpy(grid->uuid, uuid, CDI_UUID_SIZE);
}
}
break;
}
case GRID_GENERIC:
{
int nlon = 0, nlat = 0;
long lpar;
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
if ( grib_get_long(gh, "Ni", &lpar) == 0 ) nlon = (int)lpar;
/* FIXME: assert(lpar <= INT_MAX && lpar >= INT_MIN) */
if ( grib_get_long(gh, "Nj", &lpar) == 0 ) nlat = (int)lpar;
/* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
grid->size = (int)numberOfPoints;
if ( nlon > 0 && nlat > 0 && nlon*nlat == grid->size )
{
grid->xsize = nlon;
grid->ysize = nlat;
}
else
{
grid->xsize = 0;
grid->ysize = 0;
}
break;
}
default:
{
Error("Unsupported grid type: %s", gridNamePtr(gridtype));
break;
}
}
grid->isRotated = FALSE;
if ( gribapiGetIsRotated(gh) )
{
grid->isRotated = TRUE;
GRIB_CHECK(grib_get_double(gh, "latitudeOfSouthernPoleInDegrees", &grid->ypole), 0);
GRIB_CHECK(grib_get_double(gh, "longitudeOfSouthernPoleInDegrees", &grid->xpole), 0);
GRIB_CHECK(