Commit 127d6b69 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent 5ce46771
......@@ -39,15 +39,9 @@ int extInqDatatype(int prec, int number)
int datatype;
if ( number == 2 )
{
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_CPX64;
else datatype = DATATYPE_CPX32;
}
datatype = (prec == DOUBLE_PRECISION) ? DATATYPE_CPX64 : DATATYPE_CPX32;
else
{
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_FLT64;
else datatype = DATATYPE_FLT32;
}
datatype = (prec == DOUBLE_PRECISION) ? DATATYPE_FLT64 : DATATYPE_FLT32;
return datatype;
}
......@@ -60,15 +54,9 @@ void extDefDatatype(int datatype, int *prec, int *number)
datatype != DATATYPE_CPX32 && datatype != DATATYPE_CPX64 )
datatype = DATATYPE_FLT32;
if ( datatype == DATATYPE_CPX32 || datatype == DATATYPE_CPX64 )
*number = 2;
else
*number = 1;
*number = (datatype == DATATYPE_CPX32 || datatype == DATATYPE_CPX64) ? 2 : 1;
if ( datatype == DATATYPE_FLT64 || datatype == DATATYPE_CPX64 )
*prec = DOUBLE_PRECISION;
else
*prec = SINGLE_PRECISION;
*prec = (datatype == DATATYPE_FLT64 || datatype == DATATYPE_CPX64) ? DOUBLE_PRECISION : SINGLE_PRECISION;
}
/* not used
......@@ -110,8 +98,6 @@ int extInqRecord(stream_t *streamptr, int *varID, int *levelID)
void extReadRecord(stream_t *streamptr, double *data, int *nmiss)
{
void *extp = streamptr->record->exsep;
int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID;
int tsID = streamptr->curTsID;
......@@ -122,6 +108,7 @@ void extReadRecord(stream_t *streamptr, double *data, int *nmiss)
fileSetPos(fileID, recpos, SEEK_SET);
void *extp = streamptr->record->exsep;
int status = extRead(fileID, extp);
if ( status != 0 ) Error("Failed to read EXTRA record");
......@@ -165,9 +152,6 @@ void extCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
void extDefRecord(stream_t *streamptr)
{
extrec_t *extp = (extrec_t*) streamptr->record->exsep;
int gridID = streamptr->record->gridID;
int pdis, pcat, pnum;
cdiDecodeParam(streamptr->record->param, &pnum, &pcat, &pdis);
......@@ -175,10 +159,11 @@ void extDefRecord(stream_t *streamptr)
header[0] = streamptr->record->date;
header[1] = pnum;
header[2] = streamptr->record->level;
int gridID = streamptr->record->gridID;
header[3] = gridInqSize(gridID);
extrec_t *extp = (extrec_t*) streamptr->record->exsep;
extDefDatatype(streamptr->record->prec, &extp->prec, &extp->number);
extDefHeader(extp, header);
}
......@@ -364,7 +349,6 @@ int extScanTimestep2(stream_t *streamptr)
int header[4];
int varID;
off_t recpos = 0;
int nrecs, recID, rindex;
extcompvar_t compVar, compVar0;
void *extp = streamptr->record->exsep;
......@@ -386,10 +370,10 @@ int extScanTimestep2(stream_t *streamptr)
int nrecords = streamptr->tsteps[0].nallrecs;
streamptr->tsteps[1].recIDs = (int *) Malloc((size_t)nrecords * sizeof (int));
streamptr->tsteps[1].nrecs = 0;
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
streamptr->tsteps[1].recIDs[recID] = -1;
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = streamptr->tsteps[0].records[recID].varID;
streamptr->tsteps[tsID].records[recID].position =
......@@ -398,7 +382,7 @@ int extScanTimestep2(stream_t *streamptr)
streamptr->tsteps[0].records[recID].size;
}
for ( rindex = 0; rindex <= nrecords; rindex++ )
for ( int rindex = 0; rindex <= nrecords; rindex++ )
{
recpos = fileGetPos(fileID);
int status = extRead(fileID, extp);
......@@ -429,6 +413,7 @@ int extScanTimestep2(stream_t *streamptr)
compVar.param = param;
compVar.level = rlevel;
bool nextstep = false;
int recID;
for ( recID = 0; recID < nrecords; recID++ )
{
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
......@@ -476,8 +461,8 @@ int extScanTimestep2(stream_t *streamptr)
streamptr->tsteps[1].records[recID].position = recpos;
}
nrecs = 0;
for ( recID = 0; recID < nrecords; recID++ )
int nrecs = 0;
for ( int recID = 0; recID < nrecords; recID++ )
{
if ( ! streamptr->tsteps[tsID].records[recID].used )
{
......@@ -509,15 +494,14 @@ int extScanTimestep2(stream_t *streamptr)
int extInqContents(stream_t *streamptr)
{
int status = 0;
int fileID = streamptr->fileID;
streamptr->curTsID = 0;
extScanTimestep1(streamptr);
int status = 0;
if ( streamptr->ntsteps == -1 ) status = extScanTimestep2(streamptr);
int fileID = streamptr->fileID;
fileSetPos(fileID, 0, SEEK_SET);
return status;
......@@ -529,7 +513,7 @@ long extScanTimestep(stream_t *streamptr)
int header[4];
off_t recpos = 0;
int recID;
int rindex, nrecs = 0;
int nrecs = 0;
extcompvar_t compVar, compVar0;
void *extp = streamptr->record->exsep;
/*
......@@ -560,7 +544,7 @@ long extScanTimestep(stream_t *streamptr)
fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET);
for ( rindex = 0; rindex <= nrecs; rindex++ )
for ( int rindex = 0; rindex <= nrecs; rindex++ )
{
recpos = fileGetPos(fileID);
int status = extRead(fileID, extp);
......@@ -641,8 +625,6 @@ long extScanTimestep(stream_t *streamptr)
int extInqTimestep(stream_t *streamptr, int tsID)
{
int nrecs;
if ( tsID == 0 && streamptr->rtsteps == 0 )
Error("Call to cdiInqContents missing!");
......@@ -653,11 +635,8 @@ int extInqTimestep(stream_t *streamptr, int tsID)
while ( ( tsID + 1 ) > streamptr->rtsteps && ntsteps == UNDEFID )
ntsteps = extScanTimestep(streamptr);
if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID )
{
nrecs = 0;
}
else
int nrecs = 0;
if ( !(tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID) )
{
streamptr->curTsID = tsID;
nrecs = streamptr->tsteps[tsID].nrecs;
......@@ -839,6 +818,7 @@ void extWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
}
#endif /* HAVE_LIBEXTRA */
/*
* Local Variables:
* c-file-style: "Java"
......
......@@ -35,18 +35,13 @@
typedef struct {
int param;
int level;
} IEGCOMPVAR;
} iegcompvar_t;
static
int iegInqDatatype(int prec)
{
int datatype;
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_FLT64;
else datatype = DATATYPE_FLT32;
return datatype;
return (prec == DOUBLE_PRECISION) ? DATATYPE_FLT64 : DATATYPE_FLT32;
}
static
......@@ -58,9 +53,7 @@ int iegDefDatatype(int datatype)
if ( datatype != DATATYPE_FLT32 && datatype != DATATYPE_FLT64 )
datatype = DATATYPE_FLT32;
int prec = (datatype == DATATYPE_FLT64) ? DOUBLE_PRECISION : SINGLE_PRECISION;
return prec;
return (datatype == DATATYPE_FLT64) ? DOUBLE_PRECISION : SINGLE_PRECISION;
}
/* not used
......@@ -102,8 +95,6 @@ int iegInqRecord(stream_t *streamptr, int *varID, int *levelID)
void iegReadRecord(stream_t *streamptr, double *data, int *nmiss)
{
void *iegp = streamptr->record->exsep;
int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID;
int tsID = streamptr->curTsID;
......@@ -114,6 +105,7 @@ void iegReadRecord(stream_t *streamptr, double *data, int *nmiss)
fileSetPos(fileID, recpos, SEEK_SET);
void *iegp = streamptr->record->exsep;
int status = iegRead(fileID, iegp);
if ( status != 0 )
Error("Could not read IEG record!");
......@@ -551,13 +543,14 @@ void iegCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
void iegDefRecord(stream_t *streamptr)
{
iegrec_t *iegp = (iegrec_t*) streamptr->record->exsep;
Record *record = streamptr->record;
iegrec_t *iegp = (iegrec_t*) record->exsep;
int vlistID = streamptr->vlistID;
int byteorder = streamptr->byteorder;
int varID = streamptr->record->varID;
int levelID = streamptr->record->levelID;
int varID = record->varID;
int levelID = record->levelID;
int tsID = streamptr->curTsID;
int gridID = vlistInqVarGrid(vlistID, varID);
......@@ -580,18 +573,18 @@ void iegDefRecord(stream_t *streamptr)
iegDefGrid(iegp->igdb, gridID);
iegDefLevel(iegp->ipdb, iegp->igdb, iegp->vct, zaxisID, levelID);
int datatype = streamptr->record->prec;
int datatype = record->prec;
iegp->dprec = iegDefDatatype(datatype);
}
void iegWriteRecord(stream_t *streamptr, const double *data)
{
iegrec_t *iegp = (iegrec_t*) streamptr->record->exsep;
Record *record = streamptr->record;
iegrec_t *iegp = (iegrec_t*) record->exsep;
int fileID = streamptr->fileID;
int gridID = streamptr->record->gridID;
int gridID = record->gridID;
int gridsize = gridInqSize(gridID);
......@@ -602,7 +595,6 @@ void iegWriteRecord(stream_t *streamptr, const double *data)
iegp->refval = refval;
iegDefDataDP(iegp, data);
iegWrite(fileID, iegp);
}
......@@ -789,7 +781,7 @@ void iegScanTimestep1(stream_t *streamptr)
{
DateTime datetime0 = { LONG_MIN, LONG_MIN };
off_t recpos;
IEGCOMPVAR compVar, compVar0;
iegcompvar_t compVar, compVar0;
iegrec_t *iegp = (iegrec_t*) streamptr->record->exsep;
streamptr->curTsID = 0;
......@@ -845,7 +837,7 @@ void iegScanTimestep1(stream_t *streamptr)
compVar0.param = streamptr->tsteps[0].records[recID].param;
compVar0.level = streamptr->tsteps[0].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(IEGCOMPVAR)) == 0 ) break;
if ( memcmp(&compVar0, &compVar, sizeof(iegcompvar_t)) == 0 ) break;
}
if ( recID < nrecs ) break;
DateTime datetime = { .date = vdate, .time = vtime};
......@@ -916,7 +908,7 @@ static
int iegScanTimestep2(stream_t *streamptr)
{
off_t recpos = 0;
IEGCOMPVAR compVar, compVar0;
iegcompvar_t compVar, compVar0;
iegrec_t *iegp = (iegrec_t*) streamptr->record->exsep;
streamptr->curTsID = 1;
......@@ -990,7 +982,7 @@ int iegScanTimestep2(stream_t *streamptr)
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(IEGCOMPVAR)) == 0 )
if ( memcmp(&compVar0, &compVar, sizeof(iegcompvar_t)) == 0 )
{
if ( streamptr->tsteps[tsID].records[recID].used )
{
......@@ -1022,7 +1014,7 @@ int iegScanTimestep2(stream_t *streamptr)
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(IEGCOMPVAR)) != 0 )
if ( memcmp(&compVar0, &compVar, sizeof(iegcompvar_t)) != 0 )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID,
......@@ -1085,7 +1077,7 @@ static
long iegScanTimestep(stream_t *streamptr)
{
off_t recpos = 0;
IEGCOMPVAR compVar, compVar0;
iegcompvar_t compVar, compVar0;
iegrec_t *iegp = (iegrec_t*) streamptr->record->exsep;
if ( CDI_Debug )
......@@ -1161,7 +1153,7 @@ long iegScanTimestep(stream_t *streamptr)
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(IEGCOMPVAR)) != 0 )
if ( memcmp(&compVar0, &compVar, sizeof(iegcompvar_t)) != 0 )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID,
......@@ -1215,12 +1207,8 @@ int iegInqTimestep(stream_t *streamptr, int tsID)
while ( ( tsID + 1 ) > streamptr->rtsteps && ntsteps == UNDEFID )
ntsteps = iegScanTimestep(streamptr);
int nrecs;
if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID )
{
nrecs = 0;
}
else
int nrecs = 0;
if ( !(tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID) )
{
streamptr->curTsID = tsID;
nrecs = streamptr->tsteps[tsID].nrecs;
......@@ -1375,6 +1363,14 @@ void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
iegp->dprec = iegDefDatatype(datatype);
int gridsize = gridInqSize(gridID);
double refval = data[0];
for ( int i = 1; i < gridsize; i++ )
if ( data[i] < refval ) refval = data[i];
iegp->refval = refval;
iegDefDataDP(iegp, data);
iegWrite(fileID, iegp);
}
......
......@@ -32,34 +32,26 @@
typedef struct {
int param;
int level;
} SRVCOMPVAR;
} srvcompvar_t;
static int srvInqDatatype(int prec)
static
int srvInqDatatype(int prec)
{
int datatype;
if ( prec == DOUBLE_PRECISION ) datatype = DATATYPE_FLT64;
else datatype = DATATYPE_FLT32;
return datatype;
return (prec == DOUBLE_PRECISION) ? DATATYPE_FLT64 : DATATYPE_FLT32;
}
static int srvDefDatatype(int datatype)
static
int srvDefDatatype(int datatype)
{
int prec;
if ( datatype == DATATYPE_CPX32 || datatype == DATATYPE_CPX64 )
Error("CDI/SERVICE library does not support complex numbers!");
if ( datatype != DATATYPE_FLT32 && datatype != DATATYPE_FLT64 )
datatype = DATATYPE_FLT32;
if ( datatype == DATATYPE_FLT64 ) prec = DOUBLE_PRECISION;
else prec = SINGLE_PRECISION;
return prec;
return (datatype == DATATYPE_FLT64) ? DOUBLE_PRECISION : SINGLE_PRECISION;
}
/* not used
......@@ -101,9 +93,6 @@ int srvInqRecord(stream_t *streamptr, int *varID, int *levelID)
void srvReadRecord(stream_t *streamptr, double *data, int *nmiss)
{
int header[8];
void *srvp = streamptr->record->exsep;
int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID;
int tsID = streamptr->curTsID;
......@@ -114,10 +103,12 @@ void srvReadRecord(stream_t *streamptr, double *data, int *nmiss)
fileSetPos(fileID, recpos, SEEK_SET);
void *srvp = streamptr->record->exsep;
int status = srvRead(fileID, srvp);
if ( status != 0 )
Error("Failed to read record from SRV file");
int header[8];
srvInqHeader(srvp, header);
srvInqDataDP(srvp, data);
......@@ -145,20 +136,21 @@ void srvCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
void srvDefRecord(stream_t *streamptr)
{
int header[8];
Record *restrict record = streamptr->record;
srvrec_t *restrict srvp = (srvrec_t*) record->exsep;
int gridID = record->gridID;
Record *record = streamptr->record;
srvrec_t *srvp = (srvrec_t*) record->exsep;
int pdis, pcat, pnum;
cdiDecodeParam(record->param, &pnum, &pcat, &pdis);
int header[8];
header[0] = pnum;
header[1] = record->level;
header[2] = record->date;
header[3] = record->time;
int gridID = record->gridID;
int xsize = gridInqXsize(gridID),
ysize = gridInqYsize(gridID);
ysize = gridInqYsize(gridID);
if ( xsize == 0 || ysize == 0 )
{
xsize = gridInqSize(gridID);
......@@ -174,7 +166,6 @@ void srvDefRecord(stream_t *streamptr)
header[7] = 0;
int datatype = record->prec;
srvp->dprec = srvDefDatatype(datatype);
srvDefHeader(srvp, header);
......@@ -204,7 +195,7 @@ void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ys
record->param = param;
record->ilevel = level;
grid_t *grid = (grid_t *)Malloc(sizeof (*grid));
grid_t *grid = (grid_t*) Malloc(sizeof(*grid));
grid_init(grid);
cdiGridTypeInit(grid, GRID_GENERIC, xsize*ysize);
grid->x.size = xsize;
......@@ -254,7 +245,6 @@ void srvScanTimestep1(stream_t *streamptr)
taxis = &streamptr->tsteps[tsID].taxis;
}
int fileID = streamptr->fileID;
int nrecs = 0;
......@@ -361,7 +351,7 @@ int srvScanTimestep2(stream_t *streamptr)
{
int header[8];
off_t recpos = 0;
SRVCOMPVAR compVar, compVar0;
srvcompvar_t compVar, compVar0;
void *srvp = streamptr->record->exsep;
streamptr->curTsID = 1;
......@@ -429,7 +419,7 @@ int srvScanTimestep2(stream_t *streamptr)
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(SRVCOMPVAR)) == 0 )
if ( memcmp(&compVar0, &compVar, sizeof(srvcompvar_t)) == 0 )
{
if ( streamptr->tsteps[tsID].records[recID].used )
{
......@@ -459,7 +449,7 @@ int srvScanTimestep2(stream_t *streamptr)
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(SRVCOMPVAR)) != 0 )
if ( memcmp(&compVar0, &compVar, sizeof(srvcompvar_t)) != 0 )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID,
......@@ -504,8 +494,6 @@ int srvScanTimestep2(stream_t *streamptr)
int srvInqContents(stream_t *streamptr)
{
int fileID = streamptr->fileID;
streamptr->curTsID = 0;
srvScanTimestep1(streamptr);
......@@ -513,6 +501,7 @@ int srvInqContents(stream_t *streamptr)
int status = 0;
if ( streamptr->ntsteps == -1 ) status = srvScanTimestep2(streamptr);
int fileID = streamptr->fileID;
fileSetPos(fileID, 0, SEEK_SET);
return status;
......@@ -633,8 +622,6 @@ long srvScanTimestep(stream_t *streamptr)
int srvInqTimestep(stream_t *streamptr, int tsID)
{
int nrecs;
if ( tsID == 0 && streamptr->rtsteps == 0 )
Error("Call to cdiInqContents missing!");
......@@ -645,11 +632,8 @@ int srvInqTimestep(stream_t *streamptr, int tsID)
while ( ( tsID + 1 ) > streamptr->rtsteps && ntsteps == UNDEFID )
ntsteps = srvScanTimestep(streamptr);
if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != UNDEFID )
{
nrecs = 0;
}
else
int nrecs = 0;
if ( !(tsID >= streamptr->ntsteps && streamptr->ntsteps != UNDEFID) )
{
streamptr->curTsID = tsID;
nrecs = streamptr->tsteps[tsID].nrecs;
......@@ -673,8 +657,7 @@ void srvReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
size_t gridsize = (size_t)gridInqSize(gridID);
int tsid = streamptr->curTsID;
if ( CDI_Debug )
Message("nlevs = %d gridID = %d gridsize = %d", nlevs, gridID, gridsize);
if ( CDI_Debug ) Message("nlevs = %d gridID = %d gridsize = %d", nlevs, gridID, gridsize);
off_t currentfilepos = fileGetPos(fileID);
......@@ -716,8 +699,7 @@ void srvReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
int tsid = streamptr->curTsID;
if ( CDI_Debug )
Message("nlevs = %d gridID = %d gridsize = %d",
nlevs, gridID, gridsize);
Message("nlevs = %d gridID = %d gridsize = %d", nlevs, gridID, gridsize);
off_t currentfilepos = fileGetPos(fileID);
......@@ -848,6 +830,7 @@ void srvWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
}
#endif /* HAVE_LIBSERVICE */
/*
* Local Variables:
* c-file-style: "Java"
......
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