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

merge: check number of timesteps [Bug #5338]

parent 1179bcc4
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* using CDI library version 1.6.6 * using CDI library version 1.6.6
* Version 1.6.6 released * Version 1.6.6 released
2014-11-25 Uwe Schulzweida
* merge: check number of timesteps [Bug #5338]
2014-11-24 Uwe Schulzweida 2014-11-24 Uwe Schulzweida
* Seasstat: added support for time bounds * Seasstat: added support for time bounds
......
...@@ -6,6 +6,8 @@ Version 1.6.6 (27 November 2014): ...@@ -6,6 +6,8 @@ Version 1.6.6 (27 November 2014):
New operators: New operators:
* outputtab: table output * outputtab: table output
Fixed bugs: Fixed bugs:
* option -t table: segmentation fault if parameter table entry longname is missing
* merge: check number of timesteps [Bug #5338]
* seasmean: sets all time_bnds to the same values [Bug #5329] * seasmean: sets all time_bnds to the same values [Bug #5329]
* histcount: doesn't recognize missing values * histcount: doesn't recognize missing values
* filesdes: doesn't work for GRIB2 files [Bug #5307] * filesdes: doesn't work for GRIB2 files [Bug #5307]
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
Name: cdo Name: cdo
#BuildRequires: #BuildRequires:
Version: 1.6.5.2 Version: 1.6.6
Release: 1 Release: 1
Summary: Climate Data Operators Summary: Climate Data Operators
License: GNU GENERAL PUBLIC LICENSE Version 2, June 1991 License: GNU GENERAL PUBLIC LICENSE Version 2, June 1991
......
...@@ -37,7 +37,6 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename) ...@@ -37,7 +37,6 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
int gridID1, gridID2; int gridID1, gridID2;
int zaxisID1, zaxisID2; int zaxisID1, zaxisID2;
int varID1, varID2; int varID1, varID2;
int nvars1, nvars2;
int param1, param2; int param1, param2;
int ztype1, ztype2; int ztype1, ztype2;
int gtype1, gtype2; int gtype1, gtype2;
...@@ -46,8 +45,8 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename) ...@@ -46,8 +45,8 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
int mlev1 = 0, mlev2 = 0; int mlev1 = 0, mlev2 = 0;
double *lev1 = NULL, *lev2 = NULL; double *lev1 = NULL, *lev2 = NULL;
nvars1 = vlistNvars(vlistID1); int nvars1 = vlistNvars(vlistID1);
nvars2 = vlistNvars(vlistID2); int nvars2 = vlistNvars(vlistID2);
for ( varID1 = 0; varID1 < nvars1; ++varID1 ) for ( varID1 = 0; varID1 < nvars1; ++varID1 )
{ {
...@@ -115,31 +114,38 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename) ...@@ -115,31 +114,38 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
if ( lev2 ) free(lev2); if ( lev2 ) free(lev2);
} }
static
int vlistConstVars(int vlistID)
{
int nvars = vlistNvars(vlistID);
for ( int varID = 0; varID < nvars; ++varID )
if ( vlistInqVarTsteptype(vlistID, varID) != TSTEP_CONSTANT ) return (0);
return (1);
}
void *Merge(void *argument) void *Merge(void *argument)
{ {
int streamID1 = -1, streamID2 = -1; int streamID1 = -1, streamID2 = -1;
int varID, varID2; int varID, varID2;
int nrecs = 0; int nrecs = 0;
int tsID, recID, levelID, levelID2; int recID, levelID, levelID2;
int index; int index;
int streamCnt;
int *streamIDs;
int *vlistIDs;
int vlistID1 = -1, vlistID2; int vlistID1 = -1, vlistID2;
int recID2;
int nmerge;
int idum = -4711;
int lcopy = FALSE; int lcopy = FALSE;
int gridsize; int gridsize;
int nmiss; int nmiss;
int taxisID1, taxisID2; int taxisID1, taxisID2;
int skip_same_var = FALSE; //int skip_same_var = FALSE;
const char *ofilename;
double *array = NULL; double *array = NULL;
cdoInitialize(argument); cdoInitialize(argument);
if ( UNCHANGED_RECORD ) lcopy = TRUE;
/*
{ {
char *envstr; char *envstr;
envstr = getenv("SKIP_SAME_VAR"); envstr = getenv("SKIP_SAME_VAR");
...@@ -155,30 +161,27 @@ void *Merge(void *argument) ...@@ -155,30 +161,27 @@ void *Merge(void *argument)
} }
} }
} }
*/
if ( UNCHANGED_RECORD ) lcopy = TRUE; int streamCnt = cdoStreamCnt();
int nmerge = streamCnt - 1;
streamCnt = cdoStreamCnt();
nmerge = streamCnt - 1;
ofilename = cdoStreamName(streamCnt-1)->args; const char *ofilename = cdoStreamName(streamCnt-1)->args;
if ( !cdoSilentMode && !cdoOverwriteMode ) if ( !cdoSilentMode && !cdoOverwriteMode )
if ( fileExists(ofilename) ) if ( fileExists(ofilename) )
if ( !userFileOverwrite(ofilename) ) if ( !userFileOverwrite(ofilename) )
cdoAbort("Outputfile %s already exists!", ofilename); cdoAbort("Outputfile %s already exists!", ofilename);
streamIDs = (int*) malloc(nmerge*sizeof(int)); int *streamIDs = (int*) malloc(nmerge*sizeof(int));
vlistIDs = (int*) malloc(nmerge*sizeof(int)); int *vlistIDs = (int*) malloc(nmerge*sizeof(int));
int *numrecs = (int*) malloc(nmerge*sizeof(int));
for ( index = 0; index < nmerge; index++ ) for ( index = 0; index < nmerge; index++ )
{ {
streamID1 = streamOpenRead(cdoStreamName(index)); streamID1 = streamOpenRead(cdoStreamName(index));
streamIDs[index] = streamID1; streamIDs[index] = streamID1;
vlistIDs[index] = streamInqVlist(streamID1);
vlistID1 = streamInqVlist(streamID1);
vlistIDs[index] = vlistID1;
} }
vlistID1 = vlistIDs[0]; vlistID1 = vlistIDs[0];
...@@ -211,37 +214,68 @@ void *Merge(void *argument) ...@@ -211,37 +214,68 @@ void *Merge(void *argument)
array = (double*) malloc(gridsize*sizeof(double)); array = (double*) malloc(gridsize*sizeof(double));
} }
tsID = 0; int firstindex = 0;
int tsID = 0;
while ( tsID >= 0 ) while ( tsID >= 0 )
{ {
recID2 = 0;
for ( index = 0; index < nmerge; index++ ) for ( index = 0; index < nmerge; index++ )
{ {
streamID1 = streamIDs[index]; streamID1 = streamIDs[index];
vlistID1 = vlistIDs[index]; vlistID1 = vlistIDs[index];
if ( vlistID1 == -1 ) continue;
if ( vlistID1 == idum ) continue; numrecs[index] = streamInqTimestep(streamID1, tsID);
}
nrecs = streamInqTimestep(streamID1, tsID); for ( index = 0; index < nmerge; index++ ) if ( numrecs[index] != 0 ) break;
if ( index == nmerge ) break; // EOF on all input streams
if ( nrecs == 0 )
{
if ( tsID == 1 ) if ( tsID == 1 )
{ {
vlistIDs[index] = idum; for ( index = 0; index < nmerge; index++ )
continue; if ( numrecs[index] == 0 && vlistConstVars(vlistIDs[index]) ) vlistIDs[index] = -1;
/*
for ( index = 0; index < nmerge; index++ )
if ( vlistIDs[index] != -1 )
{
firstindex = index;
break;
}
*/
}
/*
for ( index = 0; index < nmerge; index++ )
printf("tsID %d %d sID %d vID %d nrecs %d\n", tsID, index, streamIDs[index], vlistIDs[index], numrecs[index]);
*/
if ( numrecs[firstindex] == 0 )
{
for ( index = 1; index < nmerge; index++ )
if ( vlistIDs[index] != -1 && numrecs[index] != 0 )
cdoWarning("Input stream %d has %d timestep%s. Stream %d has more timesteps, skipped!", firstindex+1, tsID, tsID==1?"":"s", index+1);
break;
} }
else else
{ {
tsID = idum; for ( index = 1; index < nmerge; index++ )
if ( vlistIDs[index] != -1 && numrecs[index] == 0 )
{
cdoWarning("Input stream %d has %d timestep%s. Stream %d has more timesteps, skipped!", index+1, tsID, tsID==1?"":"s", firstindex+1);
break; break;
} }
if ( index < nmerge ) break;
} }
if ( index == 0 ) for ( index = 0; index < nmerge; index++ )
{ {
taxisCopyTimestep(taxisID2, taxisID1); streamID1 = streamIDs[index];
vlistID1 = vlistIDs[index];
nrecs = numrecs[index];
if ( vlistID1 == -1 ) continue;
if ( index == firstindex )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID); streamDefTimestep(streamID2, tsID);
} }
...@@ -264,16 +298,10 @@ void *Merge(void *argument) ...@@ -264,16 +298,10 @@ void *Merge(void *argument)
streamReadRecord(streamID1, array, &nmiss); streamReadRecord(streamID1, array, &nmiss);
streamWriteRecord(streamID2, array, nmiss); streamWriteRecord(streamID2, array, nmiss);
} }
recID2++;
} }
} }
tsID++;
for ( index = 0; index < nmerge; index++ )
if ( vlistIDs[index] != idum ) break;
if ( index == nmerge ) tsID = idum; tsID++;
} }
for ( index = 0; index < nmerge; index++ ) for ( index = 0; index < nmerge; index++ )
...@@ -285,6 +313,7 @@ void *Merge(void *argument) ...@@ -285,6 +313,7 @@ void *Merge(void *argument)
if ( streamIDs ) free(streamIDs); if ( streamIDs ) free(streamIDs);
if ( vlistIDs ) free(vlistIDs); if ( vlistIDs ) free(vlistIDs);
if ( numrecs ) free(numrecs);
if ( ! lcopy ) if ( ! lcopy )
if ( array ) free(array); if ( array ) free(array);
......
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