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

Changed boolean vars to bool.

parent 26fbd95c
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#if defined(HAVE_CONFIG_H) #if defined(HAVE_CONFIG_H)
# include "config.h" #include "config.h"
#endif #endif
#ifndef _XOPEN_SOURCE #ifndef _XOPEN_SOURCE
...@@ -78,7 +78,7 @@ void pipe_init(pipe_t *pipe) ...@@ -78,7 +78,7 @@ void pipe_init(pipe_t *pipe)
Message("_POSIX_THREAD_PROCESS_SHARED undefined"); Message("_POSIX_THREAD_PROCESS_SHARED undefined");
#endif #endif
*/ */
pipe->EOP = 0; pipe->EOP = false;
pipe->recIDr = -1; pipe->recIDr = -1;
pipe->recIDw = -1; pipe->recIDw = -1;
...@@ -89,7 +89,7 @@ void pipe_init(pipe_t *pipe) ...@@ -89,7 +89,7 @@ void pipe_init(pipe_t *pipe)
pipe->nmiss = 0; pipe->nmiss = 0;
pipe->data = NULL; pipe->data = NULL;
pipe->hasdata = 0; pipe->hasdata = 0;
pipe->usedata = TRUE; pipe->usedata = true;
pipe->pstreamptr_in = 0; pipe->pstreamptr_in = 0;
pipe->mutex = (pthread_mutex_t*) Malloc(sizeof(pthread_mutex_t)); pipe->mutex = (pthread_mutex_t*) Malloc(sizeof(pthread_mutex_t));
...@@ -223,7 +223,7 @@ int pipeInqTimestep(pstream_t *pstreamptr, int tsID) ...@@ -223,7 +223,7 @@ int pipeInqTimestep(pstream_t *pstreamptr, int tsID)
// LOCK // LOCK
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
pipe->usedata = FALSE; pipe->usedata = false;
pipe->recIDr = -1; pipe->recIDr = -1;
if ( tsID != pipe->tsIDr+1 ) if ( tsID != pipe->tsIDr+1 )
{ {
...@@ -299,7 +299,7 @@ void pipeDefTimestep(pstream_t *pstreamptr, int tsID) ...@@ -299,7 +299,7 @@ void pipeDefTimestep(pstream_t *pstreamptr, int tsID)
pipe->nrecs = nrecs; pipe->nrecs = nrecs;
if ( PipeDebug ) Message("%s nrecs %d tsID %d %d %d", pname, nrecs, tsID, pipe->tsIDw, pipe->tsIDr); if ( PipeDebug ) Message("%s nrecs %d tsID %d %d %d", pname, nrecs, tsID, pipe->tsIDw, pipe->tsIDr);
if ( nrecs == 0 ) pipe->EOP = TRUE; if ( nrecs == 0 ) pipe->EOP = true;
pthread_mutex_unlock(pipe->mutex); pthread_mutex_unlock(pipe->mutex);
// UNLOCK // UNLOCK
...@@ -327,7 +327,7 @@ int pipeInqRecord(pstream_t *pstreamptr, int *varID, int *levelID) ...@@ -327,7 +327,7 @@ int pipeInqRecord(pstream_t *pstreamptr, int *varID, int *levelID)
{ {
char *pname = pstreamptr->name; char *pname = pstreamptr->name;
pipe_t *pipe = pstreamptr->pipe; pipe_t *pipe = pstreamptr->pipe;
int condSignal = FALSE; bool condSignal = false;
if ( PipeDebug ) Message("%s pstreamID %d", pname, pstreamptr->self); if ( PipeDebug ) Message("%s pstreamID %d", pname, pstreamptr->self);
...@@ -338,8 +338,8 @@ int pipeInqRecord(pstream_t *pstreamptr, int *varID, int *levelID) ...@@ -338,8 +338,8 @@ int pipeInqRecord(pstream_t *pstreamptr, int *varID, int *levelID)
{ {
pipe->hasdata = 0; pipe->hasdata = 0;
pipe->data = NULL; pipe->data = NULL;
pipe->usedata = FALSE; pipe->usedata = false;
condSignal = TRUE; condSignal = true;
} }
pthread_mutex_unlock(pipe->mutex); pthread_mutex_unlock(pipe->mutex);
// UNLOCK // UNLOCK
...@@ -348,7 +348,7 @@ int pipeInqRecord(pstream_t *pstreamptr, int *varID, int *levelID) ...@@ -348,7 +348,7 @@ int pipeInqRecord(pstream_t *pstreamptr, int *varID, int *levelID)
// LOCK // LOCK
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
pipe->usedata = TRUE; pipe->usedata = true;
pipe->recIDr++; pipe->recIDr++;
if ( PipeDebug ) Message("%s recID %d %d", pname, pipe->recIDr, pipe->recIDw); if ( PipeDebug ) Message("%s recID %d %d", pname, pipe->recIDr, pipe->recIDw);
...@@ -388,7 +388,7 @@ void pipeDefRecord(pstream_t *pstreamptr, int varID, int levelID) ...@@ -388,7 +388,7 @@ void pipeDefRecord(pstream_t *pstreamptr, int varID, int levelID)
{ {
char *pname = pstreamptr->name; char *pname = pstreamptr->name;
pipe_t *pipe = pstreamptr->pipe; pipe_t *pipe = pstreamptr->pipe;
int condSignal = FALSE; bool condSignal = false;
if ( PipeDebug ) Message("%s pstreamID %d", pname, pstreamptr->self); if ( PipeDebug ) Message("%s pstreamID %d", pname, pstreamptr->self);
...@@ -399,7 +399,7 @@ void pipeDefRecord(pstream_t *pstreamptr, int varID, int levelID) ...@@ -399,7 +399,7 @@ void pipeDefRecord(pstream_t *pstreamptr, int varID, int levelID)
{ {
pipe->hasdata = 0; pipe->hasdata = 0;
pipe->data = NULL; pipe->data = NULL;
condSignal = TRUE; condSignal = true;
} }
pthread_mutex_unlock(pipe->mutex); pthread_mutex_unlock(pipe->mutex);
// UNLOCK // UNLOCK
...@@ -408,7 +408,7 @@ void pipeDefRecord(pstream_t *pstreamptr, int varID, int levelID) ...@@ -408,7 +408,7 @@ void pipeDefRecord(pstream_t *pstreamptr, int varID, int levelID)
// LOCK // LOCK
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
pipe->usedata = TRUE; pipe->usedata = true;
pipe->recIDw++; pipe->recIDw++;
pipe->varID = varID; pipe->varID = varID;
pipe->levelID = levelID; pipe->levelID = levelID;
...@@ -454,7 +454,7 @@ void pipeCopyRecord(pstream_t *pstreamptr_out, pstream_t *pstreamptr_in) ...@@ -454,7 +454,7 @@ void pipeCopyRecord(pstream_t *pstreamptr_out, pstream_t *pstreamptr_in)
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
while ( pipe->hasdata ) while ( pipe->hasdata )
{ {
if ( pipe->usedata == FALSE ) break; if ( ! pipe->usedata ) break;
if ( pipe->recIDw != pipe->recIDr ) break; if ( pipe->recIDw != pipe->recIDr ) break;
...@@ -591,7 +591,7 @@ void pipeWriteRecord(pstream_t *pstreamptr, double *data, int nmiss) ...@@ -591,7 +591,7 @@ void pipeWriteRecord(pstream_t *pstreamptr, double *data, int nmiss)
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
while ( pipe->hasdata ) while ( pipe->hasdata )
{ {
if ( pipe->usedata == FALSE ) break; if ( ! pipe->usedata ) break;
/* /*
printf("ts ids %d %d\n", pipe->tsIDw, pipe->tsIDr); printf("ts ids %d %d\n", pipe->tsIDw, pipe->tsIDr);
printf("rec ids %d %d\n", pipe->recIDw, pipe->recIDr); printf("rec ids %d %d\n", pipe->recIDw, pipe->recIDr);
......
...@@ -15,13 +15,14 @@ ...@@ -15,13 +15,14 @@
GNU General Public License for more details. GNU General Public License for more details.
*/ */
#ifndef _PIPE_H #ifndef PIPE_H
#define _PIPE_H #define PIPE_H
#if defined(HAVE_CONFIG_H) #if defined(HAVE_CONFIG_H)
# include "config.h" #include "config.h"
#endif #endif
#include <stdbool.h>
#include <sys/types.h> #include <sys/types.h>
#if defined(HAVE_LIBPTHREAD) #if defined(HAVE_LIBPTHREAD)
...@@ -32,7 +33,7 @@ ...@@ -32,7 +33,7 @@
#endif #endif
typedef struct { typedef struct {
short check_datarange; bool check_datarange;
int gridsize; int gridsize;
int datatype; int datatype;
double missval; double missval;
...@@ -48,12 +49,12 @@ typedef struct { ...@@ -48,12 +49,12 @@ typedef struct {
int vlistID; int vlistID;
int tsID; int tsID;
int filetype; int filetype;
int ispipe;
int isopen;
int tsID0; int tsID0;
int mfiles; int mfiles;
int nfiles; int nfiles;
int varID; /* next varID defined with streamDefVar */ int varID; /* next varID defined with streamDefVar */
bool ispipe;
bool isopen;
char *name; char *name;
char **mfnames; char **mfnames;
varlist_t *varlist; varlist_t *varlist;
...@@ -69,10 +70,12 @@ typedef struct { ...@@ -69,10 +70,12 @@ typedef struct {
#if defined(HAVE_LIBPTHREAD) #if defined(HAVE_LIBPTHREAD)
struct pipe_s { struct pipe_s {
int nrecs, EOP; bool EOP;
bool usedata;
short hasdata;
int nrecs;
int varID, levelID; int varID, levelID;
int recIDr, recIDw, tsIDr, tsIDw; int recIDr, recIDw, tsIDr, tsIDw;
int hasdata, usedata;
int nmiss; int nmiss;
double *data; double *data;
pstream_t *pstreamptr_in; pstream_t *pstreamptr_in;
...@@ -105,4 +108,4 @@ void pipeCopyRecord(pstream_t *pstreamptr_dest, pstream_t *pstreamptr_src); ...@@ -105,4 +108,4 @@ void pipeCopyRecord(pstream_t *pstreamptr_dest, pstream_t *pstreamptr_src);
#endif #endif
#endif /* _PIPE_H */ #endif /* PIPE_H */
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
*/ */
#if defined(HAVE_CONFIG_H) #if defined(HAVE_CONFIG_H)
# include "config.h" #include "config.h"
#endif #endif
#if defined(_OPENMP) #if defined(_OPENMP)
# include <omp.h> #include <omp.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
...@@ -52,7 +52,7 @@ static int _pstream_max = MAX_PSTREAMS; ...@@ -52,7 +52,7 @@ static int _pstream_max = MAX_PSTREAMS;
static void pstream_initialize(void); static void pstream_initialize(void);
static int _pstream_init = FALSE; static bool _pstream_init = false;
#if defined(HAVE_LIBPTHREAD) #if defined(HAVE_LIBPTHREAD)
#include <pthread.h> #include <pthread.h>
...@@ -71,14 +71,14 @@ static pthread_mutex_t _pstream_mutex; ...@@ -71,14 +71,14 @@ static pthread_mutex_t _pstream_mutex;
# define PSTREAM_LOCK() pthread_mutex_lock(&_pstream_mutex) # define PSTREAM_LOCK() pthread_mutex_lock(&_pstream_mutex)
# define PSTREAM_UNLOCK() pthread_mutex_unlock(&_pstream_mutex) # define PSTREAM_UNLOCK() pthread_mutex_unlock(&_pstream_mutex)
# define PSTREAM_INIT() \ # define PSTREAM_INIT() \
if ( _pstream_init == FALSE ) pthread_once(&_pstream_init_thread, pstream_initialize) if ( !_pstream_init ) pthread_once(&_pstream_init_thread, pstream_initialize)
#else #else
# define PSTREAM_LOCK() # define PSTREAM_LOCK()
# define PSTREAM_UNLOCK() # define PSTREAM_UNLOCK()
# define PSTREAM_INIT() \ # define PSTREAM_INIT() \
if ( _pstream_init == FALSE ) pstream_initialize() if ( !_pstream_init ) pstream_initialize()
#endif #endif
...@@ -181,8 +181,8 @@ void pstream_init_entry(pstream_t *pstreamptr) ...@@ -181,8 +181,8 @@ void pstream_init_entry(pstream_t *pstreamptr)
{ {
pstreamptr->self = pstream_from_pointer(pstreamptr); pstreamptr->self = pstream_from_pointer(pstreamptr);
pstreamptr->isopen = TRUE; pstreamptr->isopen = true;
pstreamptr->ispipe = FALSE; pstreamptr->ispipe = false;
pstreamptr->fileID = -1; pstreamptr->fileID = -1;
pstreamptr->vlistID = -1; pstreamptr->vlistID = -1;
pstreamptr->tsID = -1; pstreamptr->tsID = -1;
...@@ -254,7 +254,7 @@ void pstream_initialize(void) ...@@ -254,7 +254,7 @@ void pstream_initialize(void)
pstream_init_pointer(); pstream_init_pointer();
_pstream_init = TRUE; _pstream_init = true;
} }
static static
...@@ -361,7 +361,7 @@ void pstreamOpenReadPipe(const argument_t *argument, pstream_t *pstreamptr) ...@@ -361,7 +361,7 @@ void pstreamOpenReadPipe(const argument_t *argument, pstream_t *pstreamptr)
for ( int i = 0; i < newargument->argc; ++i ) for ( int i = 0; i < newargument->argc; ++i )
printf("pstreamOpenRead: new arg %d >%s<\n", i, newargument->argv[i]); printf("pstreamOpenRead: new arg %d >%s<\n", i, newargument->argv[i]);
*/ */
pstreamptr->ispipe = TRUE; pstreamptr->ispipe = true;
pstreamptr->name = pipename; pstreamptr->name = pipename;
pstreamptr->rthreadID = pthread_self(); pstreamptr->rthreadID = pthread_self();
pstreamptr->pipe = pipeNew(); pstreamptr->pipe = pipeNew();
...@@ -507,19 +507,18 @@ void pstreamOpenReadFile(const argument_t *argument, pstream_t *pstreamptr) ...@@ -507,19 +507,18 @@ void pstreamOpenReadFile(const argument_t *argument, pstream_t *pstreamptr)
{ {
pstreamCreateFilelist(argument, pstreamptr); pstreamCreateFilelist(argument, pstreamptr);
size_t len;
char *filename = NULL; char *filename = NULL;
if ( pstreamptr->mfiles ) if ( pstreamptr->mfiles )
{ {
len = strlen(pstreamptr->mfnames[0]); size_t len = strlen(pstreamptr->mfnames[0]);
filename = (char*) Malloc(len+1); filename = (char*) Malloc(len+1);
strcpy(filename, pstreamptr->mfnames[0]); strcpy(filename, pstreamptr->mfnames[0]);
pstreamptr->nfiles = 1; pstreamptr->nfiles = 1;
} }
else else
{ {
len = strlen(argument->args); size_t len = strlen(argument->args);
filename = (char*) Malloc(len+1); filename = (char*) Malloc(len+1);
strcpy(filename, argument->args); strcpy(filename, argument->args);
} }
...@@ -535,7 +534,7 @@ void pstreamOpenReadFile(const argument_t *argument, pstream_t *pstreamptr) ...@@ -535,7 +534,7 @@ void pstreamOpenReadFile(const argument_t *argument, pstream_t *pstreamptr)
int fileID = streamOpenRead(filename); int fileID = streamOpenRead(filename);
if ( fileID < 0 ) if ( fileID < 0 )
{ {
pstreamptr->isopen = FALSE; pstreamptr->isopen = false;
cdiOpenError(fileID, "Open failed on >%s<", filename); cdiOpenError(fileID, "Open failed on >%s<", filename);
} }
...@@ -855,18 +854,18 @@ void pstreamClose(int pstreamID) ...@@ -855,18 +854,18 @@ void pstreamClose(int pstreamID)
{ {
#if defined(HAVE_LIBPTHREAD) #if defined(HAVE_LIBPTHREAD)
pipe_t *pipe; pipe_t *pipe;
int lread = FALSE, lwrite = FALSE; bool lread = false, lwrite = false;
pthread_t threadID = pthread_self(); pthread_t threadID = pthread_self();
if ( pthread_equal(threadID, pstreamptr->rthreadID) ) lread = TRUE; if ( pthread_equal(threadID, pstreamptr->rthreadID) ) lread = true;
else if ( pthread_equal(threadID, pstreamptr->wthreadID) ) lwrite = TRUE; else if ( pthread_equal(threadID, pstreamptr->wthreadID) ) lwrite = true;
else Error("Internal problem! Close pipe %s", pstreamptr->name); else Error("Internal problem! Close pipe %s", pstreamptr->name);
if ( lread ) if ( lread )
{ {
pipe = pstreamptr->pipe; pipe = pstreamptr->pipe;
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
pipe->EOP = TRUE; pipe->EOP = true;
if ( PSTREAM_Debug ) Message("%s read closed", pstreamptr->name); if ( PSTREAM_Debug ) Message("%s read closed", pstreamptr->name);
pthread_mutex_unlock(pipe->mutex); pthread_mutex_unlock(pipe->mutex);
pthread_cond_signal(pipe->tsDef); pthread_cond_signal(pipe->tsDef);
...@@ -875,7 +874,7 @@ void pstreamClose(int pstreamID) ...@@ -875,7 +874,7 @@ void pstreamClose(int pstreamID)
pthread_cond_signal(pipe->recInq); pthread_cond_signal(pipe->recInq);
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
pstreamptr->isopen = FALSE; pstreamptr->isopen = false;
pthread_mutex_unlock(pipe->mutex); pthread_mutex_unlock(pipe->mutex);
pthread_cond_signal(pipe->isclosed); pthread_cond_signal(pipe->isclosed);
...@@ -902,7 +901,7 @@ void pstreamClose(int pstreamID) ...@@ -902,7 +901,7 @@ void pstreamClose(int pstreamID)
{ {
pipe = pstreamptr->pipe; pipe = pstreamptr->pipe;
pthread_mutex_lock(pipe->mutex); pthread_mutex_lock(pipe->mutex);
pipe->EOP = TRUE; pipe->EOP = true;
if ( PSTREAM_Debug ) Message("%s write closed", pstreamptr->name); if ( PSTREAM_Debug ) Message("%s write closed", pstreamptr->name);
pthread_mutex_unlock(pipe->mutex); pthread_mutex_unlock(pipe->mutex);
pthread_cond_signal(pipe->tsDef); pthread_cond_signal(pipe->tsDef);
...@@ -1039,7 +1038,7 @@ void pstreamDefVarlist(pstream_t *pstreamptr, int vlistID) ...@@ -1039,7 +1038,7 @@ void pstreamDefVarlist(pstream_t *pstreamptr, int vlistID)
varlist[varID].addoffset = vlistInqVarAddoffset(vlistID, varID); varlist[varID].addoffset = vlistInqVarAddoffset(vlistID, varID);
varlist[varID].scalefactor = vlistInqVarScalefactor(vlistID, varID); varlist[varID].scalefactor = vlistInqVarScalefactor(vlistID, varID);
varlist[varID].check_datarange = FALSE; varlist[varID].check_datarange = false;
int laddoffset = IS_NOT_EQUAL(varlist[varID].addoffset, 0); int laddoffset = IS_NOT_EQUAL(varlist[varID].addoffset, 0);
int lscalefactor = IS_NOT_EQUAL(varlist[varID].scalefactor, 1); int lscalefactor = IS_NOT_EQUAL(varlist[varID].scalefactor, 1);
...@@ -1066,11 +1065,11 @@ void pstreamDefVarlist(pstream_t *pstreamptr, int vlistID) ...@@ -1066,11 +1065,11 @@ void pstreamDefVarlist(pstream_t *pstreamptr, int vlistID)
datatype == CDI_DATATYPE_UINT8 || datatype == CDI_DATATYPE_UINT8 ||
datatype == CDI_DATATYPE_INT16 || datatype == CDI_DATATYPE_INT16 ||
datatype == CDI_DATATYPE_UINT16 ) datatype == CDI_DATATYPE_UINT16 )
varlist[varID].check_datarange = TRUE; varlist[varID].check_datarange = true;
} }
else if ( cdoCheckDatarange ) else if ( cdoCheckDatarange )
{ {
varlist[varID].check_datarange = TRUE; varlist[varID].check_datarange = true;
} }
} }
} }
...@@ -1304,6 +1303,7 @@ void pstreamCheckDatarange(pstream_t *pstreamptr, int varID, double *array, int ...@@ -1304,6 +1303,7 @@ void pstreamCheckDatarange(pstream_t *pstreamptr, int varID, double *array, int
double vmin = 0, vmax = 0; double vmin = 0, vmax = 0;
// clang-format off
if ( datatype == CDI_DATATYPE_INT8 ) { vmin = -128.; vmax = 127.; } if ( datatype == CDI_DATATYPE_INT8 ) { vmin = -128.; vmax = 127.; }
else if ( datatype == CDI_DATATYPE_UINT8 ) { vmin = 0.; vmax = 255.; } else if ( datatype == CDI_DATATYPE_UINT8 ) { vmin = 0.; vmax = 255.; }
else if ( datatype == CDI_DATATYPE_INT16 ) { vmin = -32768.; vmax = 32767.; } else if ( datatype == CDI_DATATYPE_INT16 ) { vmin = -32768.; vmax = 32767.; }
...@@ -1311,7 +1311,8 @@ void pstreamCheckDatarange(pstream_t *pstreamptr, int varID, double *array, int ...@@ -1311,7 +1311,8 @@ void pstreamCheckDatarange(pstream_t *pstreamptr, int varID, double *array, int
else if ( datatype == CDI_DATATYPE_INT32 ) { vmin = -2147483648.; vmax = 2147483647.; } else if ( datatype == CDI_DATATYPE_INT32 ) { vmin = -2147483648.; vmax = 2147483647.; }
else if ( datatype == CDI_DATATYPE_UINT32 ) { vmin = 0.; vmax = 4294967295.; } else if ( datatype == CDI_DATATYPE_UINT32 ) { vmin = 0.; vmax = 4294967295.; }
else if ( datatype == CDI_DATATYPE_FLT32 ) { vmin = -3.40282e+38; vmax = 3.40282e+38; } else if ( datatype == CDI_DATATYPE_FLT32 ) { vmin = -3.40282e+38; vmax = 3.40282e+38; }
else { vmin = -1.e+300; vmax = 1.e+300; } else { vmin = -1.e+300; vmax = 1.e+300; }
// clang-format on
if ( smin < vmin || smax > vmax ) if ( smin < vmin || smax > vmax )
cdoWarning("Some data values (min=%g max=%g) are outside the\n" cdoWarning("Some data values (min=%g max=%g) are outside the\n"
......
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