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

mergetime: wrong time information if first input file does not contain the first time step.

parent 63c6c5e7
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* Using CDI library version 1.9.0 * Using CDI library version 1.9.0
* Version 1.9.0 release * Version 1.9.0 release
2017-06-08 Uwe Schulzweida
* mergetime: wrong time information if first input file does not contain the first time step (bug introduce in 1.8.1) [Bug #7760]
2017-06-04 Uwe Schulzweida 2017-06-04 Uwe Schulzweida
* selgridcell: read indices from mask * selgridcell: read indices from mask
......
...@@ -31,15 +31,9 @@ ...@@ -31,15 +31,9 @@
void *Mergetime(void *argument) void *Mergetime(void *argument)
{ {
int streamID1; int tsID2 = 0;
int tsID2 = 0, varID, levelID; int taxisID2 = CDI_UNDEFID;
int vlistID1, vlistID2;
int fileID;
int taxisID1, taxisID2 = CDI_UNDEFID;
int nmiss;
int vdate, vtime;
int last_vdate = -1, last_vtime = -1; int last_vdate = -1, last_vtime = -1;
int next_fileID;
bool skip_same_time = false; bool skip_same_time = false;
double *array = NULL; double *array = NULL;
typedef struct typedef struct
...@@ -55,20 +49,17 @@ void *Mergetime(void *argument) ...@@ -55,20 +49,17 @@ void *Mergetime(void *argument)
cdoInitialize(argument); cdoInitialize(argument);
{ char *envstr = getenv("SKIP_SAME_TIME");
char *envstr = getenv("SKIP_SAME_TIME"); if ( envstr )
if ( envstr ) {
{ int ival = atoi(envstr);
int ival; if ( ival == 1 )
ival = atoi(envstr); {
if ( ival == 1 ) skip_same_time = true;
{ if ( cdoVerbose )
skip_same_time = true; cdoPrint("Set SKIP_SAME_TIME to %d", ival);
if ( cdoVerbose ) }
cdoPrint("Set SKIP_SAME_TIME to %d", ival); }
}
}
}
bool lcopy = UNCHANGED_RECORD; bool lcopy = UNCHANGED_RECORD;
...@@ -76,27 +67,22 @@ void *Mergetime(void *argument) ...@@ -76,27 +67,22 @@ void *Mergetime(void *argument)
sfile_t *sf = (sfile_t*) Malloc(nfiles*sizeof(sfile_t)); sfile_t *sf = (sfile_t*) Malloc(nfiles*sizeof(sfile_t));
for ( fileID = 0; fileID < nfiles; fileID++ ) for ( int fileID = 0; fileID < nfiles; fileID++ )
{ {
if ( cdoVerbose ) cdoPrint("process: %s", cdoStreamName(fileID)->args); if ( cdoVerbose ) cdoPrint("process: %s", cdoStreamName(fileID)->args);
streamID1 = streamOpenRead(cdoStreamName(fileID)); sf[fileID].streamID = streamOpenRead(cdoStreamName(fileID));
sf[fileID].vlistID = streamInqVlist(sf[fileID].streamID);
vlistID1 = streamInqVlist(streamID1); sf[fileID].taxisID = vlistInqTaxis(sf[fileID].vlistID);
taxisID1 = vlistInqTaxis(vlistID1);
sf[fileID].streamID = streamID1;
sf[fileID].vlistID = vlistID1;
sf[fileID].taxisID = taxisID1;
} }
/* check that the contents is always the same */ // check that the contents is always the same
for ( fileID = 1; fileID < nfiles; fileID++ ) for ( int fileID = 1; fileID < nfiles; fileID++ )
vlistCompare(sf[0].vlistID, sf[fileID].vlistID, CMP_ALL); vlistCompare(sf[0].vlistID, sf[fileID].vlistID, CMP_ALL);
/* read the first time step */ // read the first time step
for ( fileID = 0; fileID < nfiles; fileID++ ) for ( int fileID = 0; fileID < nfiles; fileID++ )
{ {
sf[fileID].tsID = 0; sf[fileID].tsID = 0;
sf[fileID].nrecs = streamInqTimestep(sf[fileID].streamID, sf[fileID].tsID); sf[fileID].nrecs = streamInqTimestep(sf[fileID].streamID, sf[fileID].tsID);
...@@ -125,14 +111,14 @@ void *Mergetime(void *argument) ...@@ -125,14 +111,14 @@ void *Mergetime(void *argument)
array = (double*) Malloc(gridsize*sizeof(double)); array = (double*) Malloc(gridsize*sizeof(double));
} }
while ( TRUE ) while ( true )
{ {
bool process_timestep = true; bool process_timestep = true;
next_fileID = -1; int next_fileID = -1;
vdate = 0; int vdate = 0;
vtime = 0; int vtime = 0;
for ( fileID = 0; fileID < nfiles; fileID++ ) for ( int fileID = 0; fileID < nfiles; fileID++ )
{ {
if ( sf[fileID].streamID != -1 ) if ( sf[fileID].streamID != -1 )
if ( next_fileID == -1 || sf[fileID].vdate < vdate || if ( next_fileID == -1 || sf[fileID].vdate < vdate ||
...@@ -144,12 +130,12 @@ void *Mergetime(void *argument) ...@@ -144,12 +130,12 @@ void *Mergetime(void *argument)
} }
} }
fileID = next_fileID; int fileID = next_fileID;
if ( cdoVerbose ) if ( cdoVerbose )
cdoPrint("nextstep = %d vdate = %d vtime = %d", next_fileID, vdate, vtime); cdoPrint("nextstep = %d vdate = %d vtime = %d", fileID, vdate, vtime);
if ( next_fileID == -1 ) break; if ( fileID == -1 ) break;
if ( skip_same_time ) if ( skip_same_time )
if ( vdate == last_vdate && vtime == last_vtime ) if ( vdate == last_vdate && vtime == last_vtime )
...@@ -166,9 +152,9 @@ void *Mergetime(void *argument) ...@@ -166,9 +152,9 @@ void *Mergetime(void *argument)
{ {
if ( tsID2 == 0 ) if ( tsID2 == 0 )
{ {
vlistID1 = sf[0].vlistID; int vlistID1 = sf[fileID].vlistID;
vlistID2 = vlistDuplicate(vlistID1); int vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1); int taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1); taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2); vlistDefTaxis(vlistID2, taxisID2);
...@@ -184,6 +170,7 @@ void *Mergetime(void *argument) ...@@ -184,6 +170,7 @@ void *Mergetime(void *argument)
for ( int recID = 0; recID < sf[fileID].nrecs; recID++ ) for ( int recID = 0; recID < sf[fileID].nrecs; recID++ )
{ {
int varID, levelID;
streamInqRecord(sf[fileID].streamID, &varID, &levelID); streamInqRecord(sf[fileID].streamID, &varID, &levelID);
if ( tsID2 > 0 && sf[fileID].tsID == 0 ) if ( tsID2 > 0 && sf[fileID].tsID == 0 )
...@@ -198,6 +185,7 @@ void *Mergetime(void *argument) ...@@ -198,6 +185,7 @@ void *Mergetime(void *argument)
} }
else else
{ {
int nmiss;
streamReadRecord(sf[fileID].streamID, array, &nmiss); streamReadRecord(sf[fileID].streamID, array, &nmiss);
streamWriteRecord(streamID2, array, nmiss); streamWriteRecord(streamID2, array, nmiss);
} }
......
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