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

ifthen: bug fix for datasets with different missing values

parent 16c218b8
......@@ -3,6 +3,7 @@
* using CDI library version 1.2.1
* New operator: gengrid - generate grid [request: Michael Boettinger]
* Module Timstat: use taxis with bounds from input [request: Beate Geyer]
* ifthen: bug fix for datasets with different missing values [report: Beate Geyer]
* runmean: bug fix for datasets with missing values [report: Carmen Ulmen]
* Version 1.2.1 released
......
......@@ -48,6 +48,7 @@ void *Cond(void *argument)
int nmiss1, nmiss2, nmiss3;
int i;
double missval1 = -9.E33;
double missval2 = -9.E33;
double *array1, *array2, *array3;
int **varnmiss1 = NULL;
double **vardata1 = NULL;
......@@ -167,7 +168,7 @@ void *Cond(void *argument)
}
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
missval2 = vlistInqVarMissval(vlistID2, varID);
if ( recID == 0 || filltype != FILL_REC )
{
missval1 = vlistInqVarMissval(vlistID1, varID);
......@@ -176,12 +177,12 @@ void *Cond(void *argument)
if ( operatorID == IFTHEN )
{
for ( i = 0; i < gridsize; i++ )
array3[i] = !DBL_IS_EQUAL(array1[i], missval1) && !DBL_IS_EQUAL(array1[i], 0) ? array2[i] : missval1;
array3[i] = !DBL_IS_EQUAL(array1[i], missval1) && !DBL_IS_EQUAL(array1[i], 0) ? array2[i] : missval2;
}
else if ( operatorID == IFNOTTHEN )
{
for ( i = 0; i < gridsize; i++ )
array3[i] = !DBL_IS_EQUAL(array1[i], missval1) && DBL_IS_EQUAL(array1[i], 0) ? array2[i] : missval1;
array3[i] = !DBL_IS_EQUAL(array1[i], missval1) && DBL_IS_EQUAL(array1[i], 0) ? array2[i] : missval2;
}
else
{
......@@ -190,7 +191,7 @@ void *Cond(void *argument)
nmiss3 = 0;
for ( i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(array3[i], missval1) ) nmiss3++;
if ( DBL_IS_EQUAL(array3[i], missval2) ) nmiss3++;
streamDefRecord(streamID3, varID, levelID);
streamWriteRecord(streamID3, array3, nmiss3);
......
......@@ -47,6 +47,7 @@ void *Cond2(void *argument)
int nmiss1, nmiss2, nmiss3, nmiss4;
int i;
double missval1 = -9.E33;
double missval2 = -9.E33;
double *array1, *array2, *array3, *array4;
int **varnmiss1 = NULL;
double **vardata1 = NULL;
......@@ -179,6 +180,7 @@ void *Cond2(void *argument)
}
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
missval2 = vlistInqVarMissval(vlistID2, varID);
if ( recID == 0 || filltype != FILL_REC )
{
......@@ -189,7 +191,7 @@ void *Cond2(void *argument)
{
for ( i = 0; i < gridsize; i++ )
array4[i] = DBL_IS_EQUAL(array1[i], missval1) ?
missval1 : !DBL_IS_EQUAL(array1[i], 0) ? array2[i] : array3[i];
missval2 : !DBL_IS_EQUAL(array1[i], 0) ? array2[i] : array3[i];
}
else
{
......@@ -198,7 +200,7 @@ void *Cond2(void *argument)
nmiss4 = 0;
for ( i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(array4[i], missval1) ) nmiss4++;
if ( DBL_IS_EQUAL(array4[i], missval2) ) nmiss4++;
streamDefRecord(streamID4, varID, levelID);
streamWriteRecord(streamID4, array4, nmiss4);
......
......@@ -86,6 +86,7 @@ int cdoTimer = FALSE;
int cdoVerbose = FALSE;
int cdoDebug = 0;
int cdoCompress = FALSE;
int cdoInteractive = FALSE;
int cdoExpMode = -1;
char *cdoExpName = NULL;
......@@ -578,7 +579,7 @@ int main(int argc, char *argv[])
if ( noff ) setDefaultFileType(Progname+noff, 0);
while ( (c = cdoGetopt(argc, argv, "f:b:e:p:g:i:l:m:t:D:z:aBdhRrsTVvZ")) != -1 )
while ( (c = cdoGetopt(argc, argv, "f:b:e:p:g:i:l:m:t:D:z:aBdhRrsTuVvZ")) != -1 )
{
switch (c)
{
......@@ -652,6 +653,9 @@ int main(int argc, char *argv[])
case 't':
cdoDefaultTableID = defineTable(cdoOptarg);
break;
case 'u':
cdoInteractive = TRUE;
break;
case 'V':
Version = 1;
break;
......
......@@ -58,6 +58,7 @@ extern int cdoTimer;
extern int cdoVerbose;
extern int cdoDebug;
extern int cdoCompress;
extern int cdoInteractive;
extern int cdoZtype;
extern int cdoZlevel;
......
......@@ -23,6 +23,7 @@
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <sys/stat.h> /* stat */
FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);
......@@ -597,6 +598,19 @@ int pstreamOpenWrite(const char *argument, int filetype)
if ( filetype == CDI_UNDEFID ) filetype = FILETYPE_GRB;
if ( cdoInteractive )
{
int rstatus;
struct stat stbuf;
rstatus = stat(argument, &stbuf);
/* If permanent file already exists, query user whether to overwrite or exit */
if ( rstatus != -1 )
{
fprintf(stderr, "%s exists ---`e'xit, `o'verwrite (delete existing file) (e/o)?", argument);
}
}
#if defined (HAVE_LIBPTHREAD)
pthread_mutex_lock(&streamOpenWriteMutex);
#endif
......
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