Commit 2ba3d58f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

streamWriteVarF, streamWriteVarSliceF: added support for GRIB1 (cgribex)

parent 50fbc8ff
......@@ -3,6 +3,10 @@
* Version 1.7.0 released
* using CGRIBEX library version 1.7.0
2014-07-18 Uwe Schulzweida
* streamWriteVarF, streamWriteVarSliceF: added support for GRIB1 (cgribex)
2014-07-17 Uwe Schulzweida
* grib2: activate jpeg support in combination with masks (missing values)
......
......@@ -2224,7 +2224,7 @@ void cgribexDefEnsembleVar(int *isec1, int vlistID, int varID)
#endif
size_t cgribexEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID,
size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridID, int zaxisID,
int vdate, int vtime, int tsteptype, int numavg,
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize)
{
......@@ -2233,12 +2233,14 @@ size_t cgribexEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
long gribsize;
int iret = 0, iword = 0;
int isec0[2], isec1[4096], isec2[4096], isec3[2], isec4[512];
float fsec2f[512], fsec3f[2];
double fsec2[512], fsec3[2];
int datatype;
int param;
memset(isec1, 0, 256*sizeof(int));
fsec2[0] = 0; fsec2[1] = 0;
fsec2f[0] = 0; fsec2f[1] = 0;
gribsize = gribbuffersize / sizeof(int);
param = vlistInqVarParam(vlistID, varID);
......@@ -2277,8 +2279,18 @@ size_t cgribexEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
}
//printf("isec4[16] %d\n", isec4[16]);
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, (double*) data,
datasize, (int *) gribbuffer, gribsize, &iword, "C", &iret);
if ( memtype == MEMTYPE_FLOAT )
{
for ( int i = 0; i < ISEC2_NumVCP; ++i ) fsec2f[10+i] = fsec2[10+i];
fsec3f[ 1] = fsec3[ 1];
}
if ( memtype == MEMTYPE_FLOAT )
gribExSP(isec0, isec1, isec2, fsec2f, isec3, fsec3f, isec4, (float*) data,
datasize, (int *) gribbuffer, gribsize, &iword, "C", &iret);
else
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, (double*) data,
datasize, (int *) gribbuffer, gribsize, &iword, "C", &iret);
if ( iret ) Error("Problem during GRIB encode (errno = %d)!", iret);
......
......@@ -8,7 +8,7 @@ int cgribexScanTimestep(stream_t * streamptr);
int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss, int *zip, double missval);
size_t cgribexEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID,
size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridID, int zaxisID,
int vdate, int vtime, int tsteptype, int numavg,
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize);
......
......@@ -488,7 +488,7 @@ void grbReadVarSliceDP(stream_t * streamptr, int varID, int levelID, double *dat
}
static
size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID, int zaxisID,
size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID, int gridID, int zaxisID,
int date, int time, int tsteptype, int numavg,
long datasize, const double *data, int nmiss, unsigned char **gribbuffer,
int ljpeg, void *gribContainer)
......@@ -502,13 +502,15 @@ size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID,
gribbuffersize = datasize*4+3000;
*gribbuffer = (unsigned char *) malloc(gribbuffersize);
nbytes = cgribexEncode(varID, levelID, vlistID, gridID, zaxisID,
nbytes = cgribexEncode(memtype, varID, levelID, vlistID, gridID, zaxisID,
date, time, tsteptype, numavg,
datasize, data, nmiss, *gribbuffer, gribbuffersize);
}
else
#endif
{
if ( memtype == MEMTYPE_FLOAT ) Error("gribapiEncode() not implemented for memtype float!");
nbytes = gribapiEncode(varID, levelID, vlistID, gridID, zaxisID,
date, time, tsteptype, numavg,
datasize, data, nmiss, gribbuffer, &gribbuffersize,
......@@ -567,8 +569,6 @@ int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype
int ljpeg_warn = 1;
void *gc = NULL;
if ( memtype == MEMTYPE_FLOAT ) Error("grb_write_var_slice not implemented for memtype float!");
filetype = streamptr->filetype;
fileID = streamptr->fileID;
vlistID = streamptr->vlistID;
......@@ -619,7 +619,7 @@ int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype
}
}
nbytes = grbEncode(filetype, varID, levelID, vlistID, gridID, zaxisID, date, time, tsteptype, numavg,
nbytes = grbEncode(filetype, memtype, varID, levelID, vlistID, gridID, zaxisID, date, time, tsteptype, numavg,
datasize, (const double*) data, nmiss, &gribbuffer, ljpeg, gc);
if ( streamptr->comptype == COMPRESS_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