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