Commit 1fe0845b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

code cleanup

parent 497c0355
#ifndef _CDI_LIMITS_H
#define _CDI_LIMITS_H
#define MAX_STREAMS 4096 /* maximum number of streams */
#define MAX_VLISTS 4096 /* maximum number of vlists */
#define MAX_GRIDS 1024 /* maximum number of grids */
#define MAX_ZAXIS 1024 /* maximum number of zaxis */
#define MAX_TAXIS 4096 /* maximum number of taxis */
#define MAX_INSTS 1024 /* maximum number of instituts */
#define MAX_MODELS 1024 /* maximum number of models */
#define MAX_GRIDS_PS 128 /* maximum number of different grids per stream */
#define MAX_ZAXIS_PS 128 /* maximum number of different zaxis per stream */
#define MAX_STREAMS 4096 /* maximum number of streams */
#define MAX_VLISTS 4096 /* maximum number of vlists */
#define MAX_GRIDS 1024 /* maximum number of grids */
#define MAX_ZAXIS 1024 /* maximum number of zaxis */
#define MAX_TAXIS 4096 /* maximum number of taxis */
#define MAX_INSTS 1024 /* maximum number of instituts */
#define MAX_MODELS 1024 /* maximum number of models */
#define MAX_GRIDS_PS 128 /* maximum number of different grids per stream */
#define MAX_ZAXIS_PS 128 /* maximum number of different zaxis per stream */
#define MAX_ATTRIBUTES 256 /* maximum number of attributes per variable */
#endif /* _CDI_LIMITS_H */
......@@ -2036,8 +2036,8 @@ void *gribHandleNew()
void *gh = NULL;
#if defined (HAVE_LIBGRIB_API)
gh = (void *) grib_handle_new_from_template(NULL, "GRIB2");
if ( gh == NULL ) Error(func, "grib_handle_new_from_template failed!");
gh = (void *) grib_handle_new_from_samples(NULL, "GRIB2");
if ( gh == NULL ) Error(func, "grib_handle_new_from_samples failed!");
#endif
return (gh);
......@@ -2068,6 +2068,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
int param;
long bitsPerValue;
grib_handle *gh = NULL;
// extern unsigned char _grib_template_GRIB2[];
param = vlistInqVarParam(vlistID, varID);
code = vlistInqVarCode(vlistID, varID);
......@@ -2077,8 +2078,10 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(255, tabnum, code);
#if defined(GRIBAPIENCODETEST)
gh = (grib_handle *) gribHandleNew();
// gh = (grib_handle *) grib_handle_new_from_message_copy(NULL,_grib_template_GRIB2,184);
#else
gh = gribHandle;
// gh = grib_handle_clone(gribHandle);
#endif
GRIB_CHECK(grib_set_long(gh, "editionNumber", edition), 0);
......
......@@ -339,8 +339,6 @@ static void stream_init_entry(stream_t *streamptr)
streamptr->filemode = 0;
streamptr->numvals = 0;
streamptr->filename = NULL;
streamptr->ctlname = NULL;
streamptr->ctlfp = NULL;
streamptr->record = NULL;
streamptr->varsAllocated = 0;
streamptr->nrecs = 0;
......
......@@ -206,8 +206,6 @@ typedef struct {
int filemode;
off_t numvals;
char *filename;
char *ctlname;
FILE *ctlfp;
Record *record;
int nrecs; /* number of records */
int nvars; /* number of variables */
......@@ -242,6 +240,7 @@ typedef struct {
int curfile;
int nfiles;
char **fnames;
int gribHandleNums;
void *gribHandle;
}
stream_t;
......
......@@ -400,8 +400,8 @@ void vlistCopy(int vlistID2, int vlistID1)
int nvars = vlistptr1->nvars;
int nlevs, varID;
vlistptr2->vars = (VARINFO *) malloc(nvars*sizeof(VARINFO));
memcpy(vlistptr2->vars, vlistptr1->vars, nvars*sizeof(VARINFO));
vlistptr2->vars = (var_t *) malloc(nvars*sizeof(var_t));
memcpy(vlistptr2->vars, vlistptr1->vars, nvars*sizeof(var_t));
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -418,9 +418,9 @@ void vlistCopy(int vlistID2, int vlistID1)
vlistptr2->vars[varID].units = strdupx(vlistptr1->vars[varID].units);
nlevs = vlistptr1->vars[varID].nlevs;
vlistptr2->vars[varID].levinfo = (LEVINFO *) malloc(nlevs*sizeof(LEVINFO));
vlistptr2->vars[varID].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t));
memcpy(vlistptr2->vars[varID].levinfo,
vlistptr1->vars[varID].levinfo, nlevs*sizeof(LEVINFO));
vlistptr1->vars[varID].levinfo, nlevs*sizeof(levinfo_t));
vlistptr2->vars[varID].atts.nelems = 0;
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID);
......@@ -598,7 +598,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vlistptr2->nvars = nvars2;
if ( nvars2 > 0 )
vlistptr2->vars = (VARINFO *) malloc(nvars2*sizeof(VARINFO));
vlistptr2->vars = (var_t *) malloc(nvars2*sizeof(var_t));
else
vlistptr2->vars = NULL;
......@@ -610,7 +610,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
zaxisID = vlistptr1->vars[varID].zaxisID;
gridID = vlistptr1->vars[varID].gridID;
memcpy(&vlistptr2->vars[varID2], &vlistptr1->vars[varID], sizeof(VARINFO));
memcpy(&vlistptr2->vars[varID2], &vlistptr1->vars[varID], sizeof(var_t));
vlistptr1->vars[varID].fvarID = varID2;
vlistptr2->vars[varID2].fvarID = varID;
......@@ -634,7 +634,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
for ( levID = 0; levID < nlevs; levID++ )
if ( vlistptr1->vars[varID].levinfo[levID].flag ) nlevs2++;
vlistptr2->vars[varID2].levinfo = (LEVINFO *) malloc(nlevs2*sizeof(LEVINFO));
vlistptr2->vars[varID2].levinfo = (levinfo_t *) malloc(nlevs2*sizeof(levinfo_t));
vlistptr2->vars[varID2].atts.nelems = 0;
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2);
......@@ -751,8 +751,8 @@ void vlistCat(int vlistID2, int vlistID1)
nvars = nvars1 + nvars2;
vlistptr2->nvars = nvars;
vlistptr2->vars = (VARINFO *) realloc(vlistptr2->vars, nvars*sizeof(VARINFO));
memcpy(vlistptr2->vars+nvars2, vlistptr1->vars, nvars1*sizeof(VARINFO));
vlistptr2->vars = (var_t *) realloc(vlistptr2->vars, nvars*sizeof(var_t));
memcpy(vlistptr2->vars+nvars2, vlistptr1->vars, nvars1*sizeof(var_t));
for ( varID = 0; varID < nvars1; varID++ )
{
......@@ -776,8 +776,8 @@ void vlistCat(int vlistID2, int vlistID1)
vlistptr2->vars[varID2].units = strdupx(vlistptr1->vars[varID].units);
nlevs = vlistptr1->vars[varID].nlevs;
vlistptr2->vars[varID2].levinfo = (LEVINFO *) malloc(nlevs*sizeof(LEVINFO));
memcpy(vlistptr2->vars[varID2].levinfo, vlistptr1->vars[varID].levinfo, nlevs*sizeof(LEVINFO));
vlistptr2->vars[varID2].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t));
memcpy(vlistptr2->vars[varID2].levinfo, vlistptr1->vars[varID].levinfo, nlevs*sizeof(levinfo_t));
vlistptr2->vars[varID2].atts.nelems = 0;
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2);
......@@ -875,13 +875,13 @@ void vlistMerge(int vlistID2, int vlistID1)
vlistptr2->vars[varID].nlevs = nlevs;
/*
fprintf(stderr, "var %d %d %d %d %d\n", varID, nlevs1, nlevs2, nlevs, sizeof(LEVINFO));
fprintf(stderr, "var %d %d %d %d %d\n", varID, nlevs1, nlevs2, nlevs, sizeof(levinfo_t));
*/
vlistptr2->vars[varID].levinfo =
(LEVINFO *) realloc(vlistptr2->vars[varID].levinfo, nlevs*sizeof(LEVINFO));
(levinfo_t *) realloc(vlistptr2->vars[varID].levinfo, nlevs*sizeof(levinfo_t));
memcpy(vlistptr2->vars[varID].levinfo+nlevs2,
vlistptr1->vars[varID].levinfo, nlevs1*sizeof(LEVINFO));
vlistptr1->vars[varID].levinfo, nlevs1*sizeof(levinfo_t));
}
lvar = (int *) malloc(nvars2*sizeof(int));
......@@ -1470,8 +1470,8 @@ void vlistChangeZaxisIndex(int vlistID, int index, int zaxisID)
if ( nlevs != vlistptr->vars[varID].nlevs )
{
vlistptr->vars[varID].nlevs = nlevs;
vlistptr->vars[varID].levinfo = (LEVINFO *) realloc(vlistptr->vars[varID].levinfo,
nlevs*sizeof(LEVINFO));
vlistptr->vars[varID].levinfo = (levinfo_t *) realloc(vlistptr->vars[varID].levinfo,
nlevs*sizeof(levinfo_t));
for ( levID = 0; levID < nlevs; levID++ )
{
......@@ -1516,8 +1516,8 @@ void vlistChangeZaxis(int vlistID, int zaxisID1, int zaxisID2)
if ( nlevs != vlistptr->vars[varID].nlevs )
{
vlistptr->vars[varID].nlevs = nlevs;
vlistptr->vars[varID].levinfo = (LEVINFO *) realloc(vlistptr->vars[varID].levinfo,
nlevs*sizeof(LEVINFO));
vlistptr->vars[varID].levinfo = (levinfo_t *) realloc(vlistptr->vars[varID].levinfo,
nlevs*sizeof(levinfo_t));
for ( levID = 0; levID < nlevs; levID++ )
{
......
......@@ -12,21 +12,21 @@
* CDI attribute
*/
typedef struct {
size_t xsz; /* amount of space at xvalue */
size_t namesz; /* size of name */
char *name; /* attribute name */
int type; /* data type of xvalue (INT, FLT or TXT) */
int nctype;
size_t nelems; /* number of elements */
void *xvalue; /* the actual data */
} CDI_att;
size_t xsz; /* amount of space at xvalue */
size_t namesz; /* size of name */
char *name; /* attribute name */
int type; /* data type of xvalue (INT, FLT or TXT) */
int nctype;
size_t nelems; /* number of elements */
void *xvalue; /* the actual data */
} cdi_att_t;
typedef struct {
size_t nalloc; /* number allocated >= nelems */
size_t nelems; /* length of the array */
CDI_att value[MAX_ATTRIBUTES];
} CDI_atts;
size_t nalloc; /* number allocated >= nelems */
size_t nelems; /* length of the array */
cdi_att_t value[MAX_ATTRIBUTES];
} cdi_atts_t;
typedef struct
......@@ -36,62 +36,62 @@ typedef struct
int mlevelID;
int flevelID;
}
LEVINFO;
levinfo_t;
typedef struct
{
int flag;
int nlevs;
int isUsed;
int mvarID;
int fvarID;
int param;
int code;
int gridID;
int zaxisID;
int timeID; /* ( TIME_VARIABLE or TIME_CONSTANT ) */
int datatype; /* DATATYPE_PACKX for GRIB data, else DATATYPE_FLT32 or DATATYPE_FLT64 */
int instID;
int modelID;
int tableID;
int timave;
int timaccu;
int func;
int missvalused; /* TRUE if missval is defined */
char *name;
char *longname;
char *stdname;
char *units;
double missval;
double scalefactor;
double addoffset;
LEVINFO *levinfo;
int ztype;
int zlevel;
CDI_atts atts;
int flag;
int nlevs;
int isUsed;
int mvarID;
int fvarID;
int param;
int code;
int gridID;
int zaxisID;
int timeID; /* ( TIME_VARIABLE or TIME_CONSTANT ) */
int datatype; /* DATATYPE_PACKX for GRIB data, else DATATYPE_FLT32 or DATATYPE_FLT64 */
int instID;
int modelID;
int tableID;
int timave;
int timaccu;
int func;
int missvalused; /* TRUE if missval is defined */
char *name;
char *longname;
char *stdname;
char *units;
double missval;
double scalefactor;
double addoffset;
levinfo_t *levinfo;
int ztype;
int zlevel;
cdi_atts_t atts;
}
VARINFO;
var_t;
typedef struct
{
int self;
int used;
int nlock;
int nvars; /* number of variables */
int ngrids;
int nzaxis;
int ntsteps;
int taxisID;
int tableID;
int instID;
int modelID;
int varsAllocated;
int gridIDs[MAX_GRIDS_PS];
int zaxisIDs[MAX_ZAXIS_PS];
VARINFO *vars;
CDI_atts atts;
int self;
int used;
int nlock;
int nvars; /* number of variables */
int ngrids;
int nzaxis;
int ntsteps;
int taxisID;
int tableID;
int instID;
int modelID;
int varsAllocated;
int gridIDs[MAX_GRIDS_PS];
int zaxisIDs[MAX_ZAXIS_PS];
var_t *vars;
cdi_atts_t atts;
}
vlist_t;
......
......@@ -10,10 +10,10 @@
static
CDI_atts *get_attsp(vlist_t *vlistptr, int varID)
cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
{
static char func[] = "get_attsp";
CDI_atts *attsp = NULL;
cdi_atts_t *attsp = NULL;
if ( varID == CDI_GLOBAL )
{
......@@ -30,9 +30,9 @@ CDI_atts *get_attsp(vlist_t *vlistptr, int varID)
static
CDI_att *find_att(CDI_atts *attsp, const char *name)
cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
{
CDI_att *attp;
cdi_att_t *attp;
size_t attid;
size_t slen;
......@@ -57,10 +57,10 @@ CDI_att *find_att(CDI_atts *attsp, const char *name)
static
CDI_att *new_att(CDI_atts *attsp, const char *name)
cdi_att_t *new_att(cdi_atts_t *attsp, const char *name)
{
static char func[] = "new_att";
CDI_att *attp;
cdi_att_t *attp;
size_t slen;
assert(attsp != NULL);
......@@ -83,7 +83,7 @@ CDI_att *new_att(CDI_atts *attsp, const char *name)
static
void fill_att(CDI_att *attp, int type, size_t nelems, size_t xsz, const void *xvalue)
void fill_att(cdi_att_t *attp, int type, size_t nelems, size_t xsz, const void *xvalue)
{
static char func[] = "fill_att";
......@@ -121,7 +121,7 @@ int vlistInqNatts(int vlistID, int varID, int *nattsp)
static char func[] = "vlistInqNatts";
int status = CDI_NOERR;
vlist_t *vlistptr;
CDI_atts *attsp;
cdi_atts_t *attsp;
vlistptr = vlist_to_pointer(vlistID);
......@@ -157,8 +157,8 @@ int vlistInqAtt(int vlistID, int varID, int attnum, char *name, int *typep, int
static char func[] = "vlistInqAtt";
int status = CDI_NOERR;
vlist_t *vlistptr;
CDI_att *attp = NULL;
CDI_atts *attsp;
cdi_att_t *attp = NULL;
cdi_atts_t *attsp;
assert(name != NULL);
......@@ -192,8 +192,8 @@ int vlistDelAtts(int vlistID, int varID)
static char func[] = "vlistDelAtts";
int status = CDI_NOERR;
vlist_t *vlistptr;
CDI_att *attp = NULL;
CDI_atts *attsp;
cdi_att_t *attp = NULL;
cdi_atts_t *attsp;
int attid;
vlistptr = vlist_to_pointer(vlistID);
......@@ -230,8 +230,8 @@ int vlist_def_att(int type, int vlistID, int varID, const char *name, size_t len
static char func[] = "vlist_def_att";
int status = CDI_NOERR;
vlist_t *vlistptr;
CDI_att *attp;
CDI_atts *attsp;
cdi_att_t *attp;
cdi_atts_t *attsp;
if ( len != 0 && xp == NULL ) /* Null arg */
{
......@@ -260,8 +260,8 @@ int vlist_inq_att(int type, int vlistID, int varID, const char *name, size_t mxs
static char func[] = "vlist_inq_att";
int status = CDI_NOERR;
vlist_t *vlistptr;
CDI_att *attp;
CDI_atts *attsp;
cdi_att_t *attp;
cdi_atts_t *attsp;
size_t xsz;
if ( mxsz != 0 && xp == NULL ) /* Null arg */
......@@ -296,8 +296,8 @@ int vlistCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2)
static char func[] = "vlistCopyVarAtts";
int status = CDI_NOERR;
vlist_t *vlistptr1;
CDI_att *attp = NULL;
CDI_atts *attsp1;
cdi_att_t *attp = NULL;
cdi_atts_t *attsp1;
int attid;
vlistptr1 = vlist_to_pointer(vlistID1);
......
......@@ -50,7 +50,7 @@ static int vlistvarNewEntry(int vlistID)
static char func[] = "vlistvarNewEntry";
int varID = 0;
int vlistvarSize;
VARINFO *vlistvar;
var_t *vlistvar;
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
......@@ -66,11 +66,11 @@ static int vlistvarNewEntry(int vlistID)
int i;
vlistvarSize = 2;
vlistvar = (VARINFO *) malloc(vlistvarSize*sizeof(VARINFO));
vlistvar = (var_t *) malloc(vlistvarSize*sizeof(var_t));
if ( vlistvar == NULL )
{
Message(func, "vlistvarSize = %d", vlistvarSize);
SysError(func, "Allocation of VARINFO failed");
SysError(func, "Allocation of var_t failed");
}
for ( i = 0; i < vlistvarSize; i++ )
......@@ -92,11 +92,11 @@ static int vlistvarNewEntry(int vlistID)
int i;
vlistvarSize = 2*vlistvarSize;
vlistvar = (VARINFO *) realloc(vlistvar, vlistvarSize*sizeof(VARINFO));
vlistvar = (var_t *) realloc(vlistvar, vlistvarSize*sizeof(var_t));
if ( vlistvar == NULL )
{
Message(func, "vlistvarSize = %d", vlistvarSize);
SysError(func, "Reallocation of VARINFO failed");
SysError(func, "Reallocation of var_t failed");
}
varID = vlistvarSize/2;
......@@ -198,7 +198,7 @@ int vlistDefVar(int vlistID, int gridID, int zaxisID, int timeID)
nlevs = zaxisInqSize(zaxisID);
vlistptr->vars[varID].levinfo = (LEVINFO *) malloc(nlevs*sizeof(LEVINFO));
vlistptr->vars[varID].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t));
for ( levID = 0; levID < nlevs; levID++ )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment