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