Commit 61645e23 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

EXSE: unify comparision of variables.

parent 9d6c4622
......@@ -802,9 +802,10 @@ int cgribexScanTimestep1(stream_t *streamptr)
datetime.date = vdate;
datetime.time = vtime;
compvar_t compVar = cgribexVarSet(param, level1, level2, leveltype, ISEC1_TimeRange);
record_t *records = streamptr->tsteps[tsID].records;
for ( recID = 0; recID < nrecs; recID++ )
{
if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID], 0) == 0 ) break;
if ( cgribexVarCompare(compVar, records[recID], 0) == 0 ) break;
}
if ( CDI_inventory_mode == 1 )
......@@ -864,7 +865,7 @@ int cgribexScanTimestep1(stream_t *streamptr)
taxis->vdate = (int)datetime0.date;
taxis->vtime = (int)datetime0.time;
int vlistID = streamptr->vlistID;
const int vlistID = streamptr->vlistID;
vlistDefTaxis(vlistID, taxisID);
streamScanResizeRecords1(streamptr);
......@@ -881,12 +882,11 @@ int cgribexScanTimestep1(stream_t *streamptr)
int cgribexScanTimestep2(stream_t * streamptr)
{
int rstatus = 0;
int lmv = 0, iret = 0;
off_t recpos = 0;
int leveltype = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0 = { LONG_MIN, LONG_MIN };
int nrecs, recID;
int nrecs, recID = 0;
bool warn_numavg = true;
char paramstr[32];
......@@ -911,6 +911,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET);
cdi_create_records(streamptr, tsID);
record_t *records = streamptr->tsteps[tsID].records;
const int nrecords = streamScanInitRecords2(streamptr);
......@@ -988,7 +989,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
for ( recID = 0; recID < nrecords; recID++ )
{
if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
if ( cgribexVarCompare(compVar, records[recID], 0) == 0 ) break;
}
if ( recID == nrecords )
......@@ -999,19 +1000,19 @@ int cgribexScanTimestep2(stream_t * streamptr)
if ( CDI_inventory_mode == 1 )
{
if ( streamptr->tsteps[tsID].records[recID].used )
if ( records[recID].used )
{
break;
}
else
{
streamptr->tsteps[tsID].records[recID].used = true;
records[recID].used = true;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
}
else
{
if ( streamptr->tsteps[tsID].records[recID].used )
if ( records[recID].used )
{
if ( datetimeCmp(datetime, datetime0) != 0 ) break;
......@@ -1020,7 +1021,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
}
else
{
streamptr->tsteps[tsID].records[recID].used = true;
records[recID].used = true;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
}
......@@ -1028,18 +1029,17 @@ int cgribexScanTimestep2(stream_t * streamptr)
if ( CDI_Debug )
Message("Read record %2d (id=%s lev1=%d lev2=%d) %8d %6d", nrecs_scanned, paramstr, level1, level2, vdate, vtime);
streamptr->tsteps[tsID].records[recID].size = recsize;
if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d", tsID, recID,
streamptr->tsteps[tsID].records[recID].param, param,
streamptr->tsteps[tsID].records[recID].ilevel, level1);
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID, records[recID].param, param, records[recID].ilevel, level1);
return CDI_EUFSTRUCT;
}
streamptr->tsteps[1].records[recID].position = recpos;
const int varID = streamptr->tsteps[tsID].records[recID].varID;
records[recID].position = recpos;
records[recID].size = recsize;
const int varID = records[recID].varID;
const int gridID = vlistInqVarGrid(vlistID, varID);
if ( gridInqSize(gridID) == 1 && gridInqType(gridID) == GRID_LONLAT )
{
......@@ -1057,10 +1057,9 @@ int cgribexScanTimestep2(stream_t * streamptr)
nrecs = 0;
for ( recID = 0; recID < nrecords; recID++ )
{
if ( ! streamptr->tsteps[tsID].records[recID].used )
if ( ! records[recID].used )
{
const int varID = streamptr->tsteps[tsID].records[recID].varID;
vlistDefVarTimetype(vlistID, varID, TIME_CONSTANT);
vlistDefVarTimetype(vlistID, records[recID].varID, TIME_CONSTANT);
}
else
{
......@@ -1076,18 +1075,17 @@ int cgribexScanTimestep2(stream_t * streamptr)
streamptr->record->buffer = gribbuffer;
streamptr->record->buffersize = buffersize;
return rstatus;
return 0;
}
int cgribexScanTimestep(stream_t * streamptr)
{
int rstatus = 0;
int lmv = 0, iret = 0;
off_t recpos = 0;
int leveltype = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0 = { LONG_MIN, LONG_MIN };
int vrecID, recID;
int vrecID, recID = 0;
bool warn_numavg = true;
int taxisID = -1;
int nrecs = 0;
......@@ -1105,6 +1103,7 @@ int cgribexScanTimestep(stream_t * streamptr)
size_t buffersize = streamptr->record->buffersize;
cdi_create_records(streamptr, tsID);
record_t *records = streamptr->tsteps[tsID].records;
nrecs = streamScanInitRecords(streamptr, tsID);
......@@ -1118,7 +1117,7 @@ int cgribexScanTimestep(stream_t * streamptr)
{
if ( rindex > nrecs ) break;
size_t recsize = gribGetSize(fileID);
const size_t recsize = gribGetSize(fileID);
recpos = fileGetPos(fileID);
if ( recsize == 0 )
{
......@@ -1198,7 +1197,7 @@ int cgribexScanTimestep(stream_t * streamptr)
for ( vrecID = 0; vrecID < nrecs; vrecID++ )
{
recID = streamptr->tsteps[1].recIDs[vrecID];
if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
if ( cgribexVarCompare(compVar, records[recID], 0) == 0 ) break;
}
if ( vrecID == nrecs )
......@@ -1213,12 +1212,12 @@ int cgribexScanTimestep(stream_t * streamptr)
if ( CDI_inventory_mode == 1 )
{
streamptr->tsteps[tsID].records[recID].used = true;
records[recID].used = true;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
else
{
if ( streamptr->tsteps[tsID].records[recID].used )
if ( records[recID].used )
{
char paramstr_[32];
cdiParamToString(param, paramstr_, sizeof(paramstr_));
......@@ -1232,7 +1231,7 @@ int cgribexScanTimestep(stream_t * streamptr)
}
else
{
streamptr->tsteps[tsID].records[recID].used = true;
records[recID].used = true;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
}
......@@ -1240,16 +1239,15 @@ int cgribexScanTimestep(stream_t * streamptr)
if ( CDI_Debug )
Message("Read record %2d (id=%s lev1=%d lev2=%d) %8d %6d", nrecs_scanned, paramstr, level1, level2, vdate, vtime);
if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
if ( cgribexVarCompare(compVar, records[recID], 0) != 0 )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d", tsID, recID,
streamptr->tsteps[tsID].records[recID].param, param,
streamptr->tsteps[tsID].records[recID].ilevel, level1);
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID, records[recID].param, param, records[recID].ilevel, level1);
Error("Invalid, unsupported or inconsistent record structure");
}
streamptr->tsteps[tsID].records[recID].position = recpos;
streamptr->tsteps[tsID].records[recID].size = recsize;
records[recID].position = recpos;
records[recID].size = recsize;
rindex++;
}
......@@ -1257,14 +1255,14 @@ int cgribexScanTimestep(stream_t * streamptr)
for ( vrecID = 0; vrecID < nrecs; vrecID++ )
{
recID = streamptr->tsteps[tsID].recIDs[vrecID];
if ( ! streamptr->tsteps[tsID].records[recID].used ) break;
if ( ! records[recID].used ) break;
}
if ( vrecID < nrecs )
{
cdiParamToString(streamptr->tsteps[tsID].records[recID].param, paramstr, sizeof(paramstr));
cdiParamToString(records[recID].param, paramstr, sizeof(paramstr));
gribWarning("Paramameter not found!", nrecs_scanned, tsID+1, paramstr,
streamptr->tsteps[tsID].records[recID].ilevel, streamptr->tsteps[tsID].records[recID].ilevel2);
records[recID].ilevel, records[recID].ilevel2);
return CDI_EUFSTRUCT;
}
......@@ -1293,9 +1291,7 @@ int cgribexScanTimestep(stream_t * streamptr)
streamptr->ntsteps = tsID;
}
rstatus = (int)streamptr->ntsteps;
return rstatus;
return streamptr->ntsteps;
}
#ifdef gribWarning
......
......@@ -18,11 +18,6 @@
#ifdef HAVE_LIBEXTRA
typedef struct {
int param;
int level;
} extcompvar_t;
static
int extInqDatatype(int prec, int number)
{
......@@ -215,40 +210,36 @@ void extScanTimestep1(stream_t *streamptr)
int header[4];
DateTime datetime0 = { LONG_MIN, LONG_MIN };
off_t recpos = 0;
int recID;
extcompvar_t compVar, compVar0;
extrec_t *extp = (extrec_t*) streamptr->record->exsep;
streamptr->curTsID = 0;
int tsID = tstepsNewEntry(streamptr);
if ( tsID != 0 )
Error("Internal problem! tstepsNewEntry returns %d", tsID);
if ( tsID != 0 ) Error("Internal problem! tstepsNewEntry returns %d", tsID);
taxis_t *taxis = &streamptr->tsteps[tsID].taxis;
int fileID = streamptr->fileID;
const int fileID = streamptr->fileID;
int nrecs = 0;
while ( true )
{
recpos = fileGetPos(fileID);
int status = extRead(fileID, extp);
if ( status != 0 )
if ( extRead(fileID, extp) != 0 )
{
streamptr->ntsteps = 1;
break;
}
size_t recsize = (size_t)(fileGetPos(fileID) - recpos);
extInqHeader(extp, header);
const size_t recsize = (size_t)(fileGetPos(fileID) - recpos);
int vdate = header[0];
int vtime = 0;
int rcode = header[1];
int rlevel = header[2];
int rxysize = header[3];
extInqHeader(extp, header);
int param = cdiEncodeParam(rcode, 255, 255);
const int vdate = header[0];
const int vtime = 0;
const int rcode = header[1];
const int rlevel = header[2];
const int rxysize = header[3];
const int param = cdiEncodeParam(rcode, 255, 255);
if ( nrecs == 0 )
{
......@@ -257,16 +248,11 @@ void extScanTimestep1(stream_t *streamptr)
}
else
{
compVar.param = param;
compVar.level = rlevel;
for ( recID = 0; recID < nrecs; recID++ )
{
compVar0.param = streamptr->tsteps[0].records[recID].param;
compVar0.level = streamptr->tsteps[0].records[recID].ilevel;
record_t *records = streamptr->tsteps[tsID].records;
for ( int recID = 0; recID < nrecs; recID++ )
if ( param == records[recID].param && rlevel == records[recID].ilevel )
goto tstepScanLoopFinished;
if ( memcmp(&compVar0, &compVar, sizeof(extcompvar_t)) == 0 ) break;
}
if ( recID < nrecs ) break;
DateTime datetime = { .date = vdate, .time = vtime};
if ( datetimeCmp(datetime, datetime0) )
Warning("Inconsistent verification time for code %d level %d", rcode, rlevel);
......@@ -280,18 +266,19 @@ void extScanTimestep1(stream_t *streamptr)
extAddRecord(streamptr, param, rlevel, rxysize, recsize, recpos, extp->prec, extp->number);
}
tstepScanLoopFinished:
streamptr->rtsteps = 1;
cdi_generate_vars(streamptr);
int taxisID = taxisCreate(TAXIS_ABSOLUTE);
const int taxisID = taxisCreate(TAXIS_ABSOLUTE);
taxis->type = TAXIS_ABSOLUTE;
taxis->vdate = (int)datetime0.date;
taxis->vtime = (int)datetime0.time;
taxis->rdate = taxis->vdate;
taxis->rtime = taxis->vtime;
int vlistID = streamptr->vlistID;
const int vlistID = streamptr->vlistID;
vlistDefTaxis(vlistID, taxisID);
vlist_check_contents(vlistID);
......@@ -307,13 +294,12 @@ int extScanTimestep2(stream_t *streamptr)
{
int header[4];
off_t recpos = 0;
extcompvar_t compVar, compVar0;
void *extp = streamptr->record->exsep;
streamptr->curTsID = 1;
int fileID = streamptr->fileID;
int vlistID = streamptr->vlistID;
const int fileID = streamptr->fileID;
const int vlistID = streamptr->vlistID;
int tsID = streamptr->rtsteps;
if ( tsID != 1 ) Error("Internal problem! unexpected timestep %d", tsID+1);
......@@ -323,29 +309,28 @@ int extScanTimestep2(stream_t *streamptr)
fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET);
cdi_create_records(streamptr, tsID);
record_t *records = streamptr->tsteps[tsID].records;
const int nrecords = streamScanInitRecords2(streamptr);
for ( int rindex = 0; rindex <= nrecords; rindex++ )
{
recpos = fileGetPos(fileID);
int status = extRead(fileID, extp);
if ( status != 0 )
if ( extRead(fileID, extp) != 0 )
{
streamptr->ntsteps = 2;
break;
}
size_t recsize = (size_t)(fileGetPos(fileID) - recpos);
extInqHeader(extp, header);
const size_t recsize = (size_t)(fileGetPos(fileID) - recpos);
int vdate = header[0];
int vtime = 0;
int rcode = header[1];
int rlevel = header[2];
// rxysize = header[3];
extInqHeader(extp, header);
int param = cdiEncodeParam(rcode, 255, 255);
const int vdate = header[0];
const int vtime = 0;
const int rcode = header[1];
const int rlevel = header[2];
const int param = cdiEncodeParam(rcode, 255, 255);
if ( rindex == 0 )
{
......@@ -354,24 +339,19 @@ int extScanTimestep2(stream_t *streamptr)
taxis->vtime = vtime;
}
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;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(extcompvar_t)) == 0 )
if ( param == records[recID].param && rlevel == records[recID].ilevel )
{
if ( streamptr->tsteps[tsID].records[recID].used )
if ( records[recID].used )
{
nextstep = true;
}
else
{
streamptr->tsteps[tsID].records[recID].used = true;
records[recID].used = true;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
break;
......@@ -388,30 +368,23 @@ int extScanTimestep2(stream_t *streamptr)
if ( CDI_Debug )
Message("%4d%8d%4d%8d%8d%6d", rindex+1, (int)recpos, rcode, rlevel, vdate, vtime);
streamptr->tsteps[tsID].records[recID].size = recsize;
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(extcompvar_t)) != 0 )
if ( param != records[recID].param || rlevel != records[recID].ilevel )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID,
streamptr->tsteps[tsID].records[recID].param, param,
streamptr->tsteps[tsID].records[recID].ilevel, rlevel);
tsID, recID, records[recID].param, param, records[recID].ilevel, rlevel);
return CDI_EUFSTRUCT;
}
streamptr->tsteps[1].records[recID].position = recpos;
records[recID].position = recpos;
records[recID].size = recsize;
}
int nrecs = 0;
for ( int recID = 0; recID < nrecords; recID++ )
{
if ( ! streamptr->tsteps[tsID].records[recID].used )
if ( ! records[recID].used )
{
int varID = streamptr->tsteps[tsID].records[recID].varID;
vlistDefVarTimetype(vlistID, varID, TIME_CONSTANT);
vlistDefVarTimetype(vlistID, records[recID].varID, TIME_CONSTANT);
}
else
{
......@@ -434,7 +407,7 @@ int extInqContents(stream_t *streamptr)
extScanTimestep1(streamptr);
int status = (streamptr->ntsteps == -1) ? extScanTimestep2(streamptr) : 0;
const int status = (streamptr->ntsteps == -1) ? extScanTimestep2(streamptr) : 0;
fileSetPos(streamptr->fileID, 0, SEEK_SET);
......@@ -447,7 +420,6 @@ long extScanTimestep(stream_t *streamptr)
int header[4];
off_t recpos = 0;
int nrecs = 0;
extcompvar_t compVar, compVar0;
void *extp = streamptr->record->exsep;
int tsID = streamptr->rtsteps;
......@@ -456,6 +428,7 @@ long extScanTimestep(stream_t *streamptr)
if ( streamptr->tsteps[tsID].recordSize == 0 )
{
cdi_create_records(streamptr, tsID);
record_t *records = streamptr->tsteps[tsID].records;
nrecs = streamScanInitRecords(streamptr, tsID);
......@@ -466,23 +439,21 @@ long extScanTimestep(stream_t *streamptr)
for ( int rindex = 0; rindex <= nrecs; rindex++ )
{
recpos = fileGetPos(fileID);
int status = extRead(fileID, extp);
if ( status != 0 )
if ( extRead(fileID, extp) != 0 )
{
streamptr->ntsteps = streamptr->rtsteps + 1;
break;
}
size_t recsize = (size_t)(fileGetPos(fileID) - recpos);
extInqHeader(extp, header);
const size_t recsize = (size_t)(fileGetPos(fileID) - recpos);
int vdate = header[0];
int vtime = 0;
int rcode = header[1];
int rlevel = header[2];
// rxysize = header[3];
extInqHeader(extp, header);
int param = cdiEncodeParam(rcode, 255, 255);
const int vdate = header[0];
const int vtime = 0;
const int rcode = header[1];
const int rlevel = header[2];
const int param = cdiEncodeParam(rcode, 255, 255);
// if ( rindex == nrecs ) break; gcc-4.5 internal compiler error
if ( rindex == nrecs ) continue;
......@@ -495,22 +466,15 @@ long extScanTimestep(stream_t *streamptr)
taxis->vtime = vtime;
}
compVar.param = param;
compVar.level = rlevel;
compVar0.param = streamptr->tsteps[tsID].records[recID].param;
compVar0.level = streamptr->tsteps[tsID].records[recID].ilevel;
if ( memcmp(&compVar0, &compVar, sizeof(extcompvar_t)) != 0 )
if ( param != records[recID].param || rlevel != records[recID].ilevel )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID,
streamptr->tsteps[tsID].records[recID].param, param,
streamptr->tsteps[tsID].records[recID].ilevel, rlevel);
tsID, recID, records[recID].param, param, records[recID].ilevel, rlevel);
Error("Invalid, unsupported or inconsistent record structure!");
}
streamptr->tsteps[tsID].records[recID].position = recpos;
streamptr->tsteps[tsID].records[recID].size = recsize;
records[recID].position = recpos;
records[recID].size = recsize;
if ( CDI_Debug )
Message("%4d%8d%4d%8d%8d%6d", rindex, (int)recpos, rcode, rlevel, vdate, vtime);
......
......@@ -1047,7 +1047,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
taxis->vdate = (int64_t)datetime0.date;
taxis->vtime = (int)datetime0.time;
int vlistID = streamptr->vlistID;
const int vlistID = streamptr->vlistID;
vlistDefTaxis(vlistID, taxisID);
streamScanResizeRecords1(streamptr);
......@@ -1090,6 +1090,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
fileSetPos(fileID, streamptr->tsteps[tsID].position, SEEK_SET);
cdi_create_records(streamptr, tsID);
record_t *records = streamptr->tsteps[tsID].records;
const int nrecords = streamScanInitRecords2(streamptr);
......@@ -1178,7 +1179,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
compvar2_t compVar = gribapiVarSet(param, level1, level2, leveltype1, tsteptype, perturbationNumber, gridsize, varname, tiles);
for ( recID = 0; recID < nrecords; recID++ )
if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
if ( gribapiVarCompare(compVar, records[recID], 0) == 0 ) break;
if ( recID == nrecords )
{
......@@ -1186,7 +1187,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
return CDI_EUFSTRUCT;
}
if ( streamptr->tsteps[tsID].records[recID].used )
if ( records[recID].used )
{
if ( CDI_inventory_mode == 1 ) break;
else
......@@ -1198,7 +1199,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
}
}
streamptr->tsteps[tsID].records[recID].used = true;
records[recID].used = true;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
if ( CDI_Debug )
......@@ -1209,19 +1210,17 @@ int gribapiScanTimestep2(stream_t * streamptr)
nrecs_scanned, (int)recpos, varname, paramstr, leveltype1, level1, level2, vdate, vtime);
}
streamptr->tsteps[tsID].records[recID].size = recsize;
if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
if ( gribapiVarCompare(compVar, records[recID], 0) != 0 )
{
Message("tsID = %d recID = %d param = %3d new %3d level = %3d new %3d",
tsID, recID,
streamptr->tsteps[tsID].records[recID].param, param,
streamptr->tsteps[tsID].records[recID].ilevel, level1);
tsID, recID, records[recID].param, param, records[recID].ilevel, level1);
return CDI_EUFSTRUCT;
}
streamptr->tsteps[1].records[recID].position = recpos;
int varID = streamptr->tsteps[tsID].records[recID].varID;
records[recID].position = recpos;
records[recID].size = recsize;
int varID = records[recID].varID;
/*
gridID = vlistInqVarGrid(vlistID, varID);