Commit c01fe16d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

new function: vlistInqVarSzip

parent 0e853572
......@@ -2,6 +2,7 @@
* using GRIB library version 1.0.4
* splitBasetime: convert timeunit string to lower case
* new function: vlistInqVarSzip
* new function: streamNvals
* Version 1.0.4 released
......
......@@ -167,7 +167,7 @@ static void printInfo(int gridtype, int date, int time, int code, double level,
#define CDI_BIGENDIAN 0 /* Data type BIGENDIAN */
#define CDI_LITTLEENDIAN 1 /* Data type LITTLEENDIAN */
static void printFiletype(int streamID)
void printFiletype(int streamID)
{
int filetype;
......@@ -176,40 +176,29 @@ static void printFiletype(int streamID)
switch ( filetype )
{
case FILETYPE_GRB:
printf(" File format: GRIB");
printf("GRIB");
break;
case FILETYPE_NC:
printf(" File format: netCDF");
printf("netCDF");
break;
case FILETYPE_NC2:
printf(" File format: netCDF2");
printf("netCDF2");
break;
case FILETYPE_SRV:
printf(" File format: SERVICE");
switch ( streamInqByteorder(streamID) )
{
case CDI_BIGENDIAN:
printf(" BIGENDIAN"); break;
case CDI_LITTLEENDIAN:
printf(" LITTLEENDIAN"); break;
default:
printf(" byteorder: %d undefined", streamInqByteorder(streamID)); break;
}
printf("SERVICE");
break;
case FILETYPE_EXT:
printf(" File format: EXTRA");
switch ( streamInqByteorder(streamID) )
{
case CDI_BIGENDIAN:
printf(" BIGENDIAN"); break;
case CDI_LITTLEENDIAN:
printf(" LITTLEENDIAN"); break;
default:
printf(" byteorder: %d undefined", streamInqByteorder(streamID)); break;
}
printf("EXTRA");
break;
case FILETYPE_IEG:
printf(" File format: IEG");
printf("IEG");
break;
default:
printf(" File format: unsupported filetype %d" , filetype);
}
if ( filetype == FILETYPE_SRV || filetype == FILETYPE_EXT || filetype == FILETYPE_IEG )
{
switch ( streamInqByteorder(streamID) )
{
case CDI_BIGENDIAN:
......@@ -219,9 +208,24 @@ static void printFiletype(int streamID)
default:
printf(" byteorder: %d undefined", streamInqByteorder(streamID)); break;
}
break;
default:
printf(" File format: unsupported filetype %d" , filetype);
}
if ( filetype == FILETYPE_GRB )
{
int vlistID, nvars, varID;
vlistID = streamInqVlist(streamID);
nvars = vlistNvars(vlistID);
for ( varID = 0; varID < nvars; varID++ )
{
if ( vlistInqVarSzip(vlistID, varID) )
{
printf(" SZIP");
break;
}
}
}
printf("\n");
......@@ -265,6 +269,7 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
int year, month, day, hour, minute;
char pstr[4];
printf(" File format: ");
printFiletype(streamID);
if ( vardis )
......@@ -323,7 +328,15 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, " %-3s", pstr);
fprintf(stdout, " %9d", gridsize);
if ( prec > 0 && prec <= 32 )
{
if ( vlistInqVarSzip(vlistID, varID) )
fprintf(stdout, "z");
else
fprintf(stdout, " ");
}
fprintf(stdout, "%9d", gridsize);
fprintf(stdout, " %3d ", gridID + 1);
......@@ -958,7 +971,7 @@ int main(int argc, char *argv[])
free(data);
fprintf(stderr, "%ld\n", (long) streamNvals(streamID1));
/* fprintf(stderr, "%ld\n", (long) streamNvals(streamID1)); */
if ( fname2 ) streamClose(streamID2);
streamClose(streamID1);
......
......@@ -293,6 +293,9 @@ int vlistInqVarGrid(int vlistID, int varID);
int vlistInqVarZaxis(int vlistID, int varID);
int vlistInqVarTime(int vlistID, int varID);
void vlistDefVarSzip(int vlistID, int varID, int szip);
int vlistInqVarSzip(int vlistID, int varID);
/* vlistDefVarCode: Define the code number of a Variable */
void vlistDefVarCode(int vlistID, int varID, int code);
......
......@@ -676,7 +676,7 @@ int grbInqTimeSize(int streamID)
void grbAddRecord(int streamID, int code, int *isec1, int *isec2, double *fsec2,
int *isec4, long recsize, off_t position, int prec)
int *isec4, long recsize, off_t position, int prec, int szip)
{
static char func[] = "grbAddRecord";
int gridtype;
......@@ -879,6 +879,8 @@ void grbAddRecord(int streamID, int code, int *isec1, int *isec2, double *fsec2,
(*record).varID = varID;
(*record).levelID = levelID;
varDefSzip(varID, szip);
if ( varInqInst(varID) == UNDEFID )
{
int center, subcenter, instID;
......@@ -941,6 +943,7 @@ void grbScanTimestep1(int streamID)
int rdate = 0, rtime = 0, tunit = 0, fcast = 0;
TAXIS *taxis;
int vlistID;
int szip;
long unzipsize;
COMPVAR compVar, compVar0;
......@@ -983,8 +986,10 @@ void grbScanTimestep1(int streamID)
status = gribRead(fileID, gribbuffer, &readsize);
if ( status ) break;
szip = FALSE;
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 )
{
szip = TRUE;
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
if ( (long) buffersize < unzipsize )
{
......@@ -1060,7 +1065,7 @@ void grbScanTimestep1(int streamID)
if ( CDI_Debug )
Message(func, "%4d %8d %4d %8d %8d %6d", nrecs, (int)recpos, rcode, level1, vdate, vtime);
grbAddRecord(streamID, rcode, isec1, isec2, fsec2, isec4, recsize, recpos, prec);
grbAddRecord(streamID, rcode, isec1, isec2, fsec2, isec4, recsize, recpos, prec, szip);
}
streams[streamID].rtsteps = 1;
......
......@@ -42,6 +42,7 @@ typedef struct
int modelID;
int tableID;
int codetable;
int szip;
}
VARTABLE;
......@@ -63,6 +64,7 @@ static void codeInitEntry(int varID, int code)
vartable[varID].instID = UNDEFID;
vartable[varID].modelID = UNDEFID;
vartable[varID].tableID = UNDEFID;
vartable[varID].szip = FALSE;
}
......@@ -317,6 +319,7 @@ void cdiGenVars(int streamID)
int prec;
int average;
int lbounds;
int szip;
char name[256], longname[256], units[256];
double *dlevels = NULL;
double *dlevels1 = NULL;
......@@ -339,10 +342,11 @@ void cdiGenVars(int streamID)
modelID = vartable[varID].modelID;
tableID = vartable[varID].tableID;
average = vartable[varID].average;
szip = vartable[varID].szip;
zaxisID = UNDEFID;
if ( leveltype == ZAXIS_GENERIC && nlevels == 1 && ! fabs(vartable[varID].levelTable[0].level1) )
if ( leveltype == ZAXIS_GENERIC && nlevels == 1 && ! (fabs(vartable[varID].levelTable[0].level1)>0) )
leveltype = ZAXIS_SURFACE;
dlevels = (double *) malloc(nlevels*sizeof(double));
......@@ -416,6 +420,7 @@ void cdiGenVars(int streamID)
vlistDefVarCode(vlistID, varID, code);
vlistDefVarDatatype(vlistID, varID, prec);
vlistDefVarAverage(vlistID, varID, average);
vlistDefVarSzip(vlistID, varID, szip);
if ( cdiDefaultTableID != UNDEFID )
{
......@@ -577,7 +582,7 @@ int zaxisCompare(int zaxisID, int leveltype, int nlevels, int lbounds, double *l
dlevels = zaxisInqLevelsPtr(zaxisID);
for ( levelID = 0; levelID < nlevels; levelID++ )
{
if ( fabs(dlevels[levelID] - levels[levelID]) )
if ( fabs(dlevels[levelID] - levels[levelID]) > 0 )
break;
}
......@@ -691,6 +696,13 @@ int varDefZaxis(int vlistID, int leveltype, int nlevels, double *levels, int lbo
}
void varDefSzip(int varID, int szip)
{
if ( szip )
vartable[varID].szip = TRUE;
}
int varInqInst(int varID)
{
return (vartable[varID].instID);
......
......@@ -16,6 +16,7 @@ int varDefGrid(int vlistID, GRID grid, int mode);
int varDefZaxis(int vlistID, int leveltype, int nlevels, double *levels, int lbounds, double *levels1, double *levels2,
int vctsize, double *vct, char *name, char *longname, char *units, int prec, int mode);
void varDefSzip(int varID, int szip);
void varDefInst(int varID, int instID);
int varInqInst(int varID);
void varDefModel(int varID, int modelID);
......
......@@ -42,6 +42,7 @@ typedef struct
double scalefactor;
double addoffset;
LEVINFO *levinfo;
int szip;
}
VARINFO;
......
......@@ -35,6 +35,7 @@ static void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].units = NULL;
vlistptr->vars[varID].nlevs = 0;
vlistptr->vars[varID].levinfo = NULL;
vlistptr->vars[varID].szip = FALSE;
}
static int vlistvarNewEntry(int vlistID)
......@@ -1257,3 +1258,32 @@ void vlistChangeVarGrid(int vlistID, int varID, int gridID)
vlistptr->vars[varID].gridID = gridID;
}
void vlistDefVarSzip(int vlistID, int varID, int szip)
{
static char func[] = "vlistDefVarSzip";
int nvars, index;
VLIST *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(func, vlistID, varID);
vlistptr->vars[varID].szip = szip;
}
int vlistInqVarSzip(int vlistID, int varID)
{
static char func[] = "vlistInqVarSzip";
int nvars, index;
VLIST *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(func, vlistID, varID);
return (vlistptr->vars[varID].szip);
}
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