Commit 70ceb220 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Optimized error handling.

parent 316f8d14
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
Ensstat enspctl Ensemble percentiles Ensstat enspctl Ensemble percentiles
*/ */
#include <cdi.h> #include <cdi.h>
#include "cdo.h" #include "cdo.h"
#include "cdo_int.h" #include "cdo_int.h"
...@@ -41,7 +40,6 @@ ...@@ -41,7 +40,6 @@
void *Ensstat(void *argument) void *Ensstat(void *argument)
{ {
int nrecs0; int nrecs0;
int nmiss;
typedef struct typedef struct
{ {
int streamID; int streamID;
...@@ -78,10 +76,10 @@ void *Ensstat(void *argument) ...@@ -78,10 +76,10 @@ void *Ensstat(void *argument)
argc--; argc--;
} }
int count_data = FALSE; bool count_data = false;
if ( argc == 1 ) if ( argc == 1 )
{ {
if ( strcmp("count", operatorArgv()[nargc-1]) == 0 ) count_data = TRUE; if ( strcmp("count", operatorArgv()[nargc-1]) == 0 ) count_data = true;
else cdoAbort("Unknown parameter: >%s<", operatorArgv()[nargc-1]); else cdoAbort("Unknown parameter: >%s<", operatorArgv()[nargc-1]);
} }
...@@ -153,6 +151,8 @@ void *Ensstat(void *argument) ...@@ -153,6 +151,8 @@ void *Ensstat(void *argument)
streamDefVlist(streamID2, vlistID2); streamDefVlist(streamID2, vlistID2);
bool lwarning = false;
bool lerror = false;
int tsID = 0; int tsID = 0;
do do
{ {
...@@ -164,10 +164,22 @@ void *Ensstat(void *argument) ...@@ -164,10 +164,22 @@ void *Ensstat(void *argument)
if ( nrecs != nrecs0 ) if ( nrecs != nrecs0 )
{ {
if ( nrecs == 0 ) if ( nrecs == 0 )
cdoAbort("Inconsistent ensemble file, too few time steps in %s!", cdoStreamName(fileID)->args); {
lwarning = true;
cdoWarning("Inconsistent ensemble file, too few time steps in %s!", cdoStreamName(fileID)->args);
}
else if ( nrecs0 == 0 )
{
lwarning = true;
cdoWarning("Inconsistent ensemble file, too few time steps in %s!", cdoStreamName(0)->args);
}
else else
cdoAbort("Inconsistent ensemble file, number of records at time step %d of %s and %s differ!", {
tsID+1, cdoStreamName(0)->args, cdoStreamName(fileID)->args); lerror = true;
cdoWarning("Inconsistent ensemble file, number of records at time step %d of %s and %s differ!",
tsID+1, cdoStreamName(0)->args, cdoStreamName(fileID)->args);
}
goto CLEANUP;
} }
} }
...@@ -194,9 +206,9 @@ void *Ensstat(void *argument) ...@@ -194,9 +206,9 @@ void *Ensstat(void *argument)
int gridID = vlistInqVarGrid(vlistID1, varID); int gridID = vlistInqVarGrid(vlistID1, varID);
gridsize = gridInqSize(gridID); gridsize = gridInqSize(gridID);
double missval = vlistInqVarMissval(vlistID1, varID); double missval = vlistInqVarMissval(vlistID1, varID);
nmiss = 0; int nmiss = 0;
#if defined(_OPENMP) #if defined(_OPENMP)
#pragma omp parallel for default(shared) #pragma omp parallel for default(shared)
#endif #endif
...@@ -246,6 +258,11 @@ void *Ensstat(void *argument) ...@@ -246,6 +258,11 @@ void *Ensstat(void *argument)
} }
while ( nrecs0 > 0 ); while ( nrecs0 > 0 );
CLEANUP:
if ( lwarning ) cdoWarning("Inconsistent ensemble, processed only the first %d timesteps!", tsID);
if ( lerror ) cdoAbort("Inconsistent ensemble, processed only the first %d timesteps!", tsID);
for ( int fileID = 0; fileID < nfiles; fileID++ ) for ( int fileID = 0; fileID < nfiles; fileID++ )
streamClose(ef[fileID].streamID); streamClose(ef[fileID].streamID);
......
Supports Markdown
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