Commit 8181d16d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added compare.h

parent bea3b19d
......@@ -526,6 +526,7 @@ src/clipping/utils.h -text
src/color.c -text
src/color.h -text
src/commandline.c -text
src/compare.h -text
src/config.h.in -text
src/const.h -text
src/counter.h -text
......
......@@ -163,11 +163,8 @@ static
int getDate(const char *name)
{
int date = 0;
size_t len;
char *pname;
len = strlen(name);
pname = strchr(name, '_');
if ( pname ) date = atoi(pname+1);
......
......@@ -91,11 +91,8 @@ static
int getDate(const char *name)
{
int date = 0;
size_t len;
char *pname;
len = strlen(name);
pname = strchr(name, '_');
if ( pname ) date = atoi(pname+1);
......
......@@ -242,10 +242,7 @@ void printMap(int nlon, int nlat, double *array, double missval, double min, dou
void *Info(void *argument)
{
int INFO, INFOP, INFON, INFOC, MAP;
int operatorID;
int i;
int indf, indg;
int varID, recID;
int gridsize = 0;
int gridID, zaxisID;
......@@ -253,9 +250,6 @@ void *Info(void *argument)
int vdate, vtime;
int nrecs;
int levelID;
int tsID, taxisID;
int streamID = 0;
int vlistID;
int nmiss;
int number;
int ivals = 0, nvals = 0;
......@@ -264,36 +258,38 @@ void *Info(void *argument)
char paramstr[32];
char vdatestr[32], vtimestr[32];
double missval;
double *array = NULL;
double level;
double arrmin = 0, arrmax = 0, arrmean = 0, arrvar = 0;
cdoInitialize(argument);
INFO = cdoOperatorAdd("info", 0, 0, NULL);
INFOP = cdoOperatorAdd("infop", 0, 0, NULL);
INFON = cdoOperatorAdd("infon", 0, 0, NULL);
INFOC = cdoOperatorAdd("infoc", 0, 0, NULL);
MAP = cdoOperatorAdd("map", 0, 0, NULL);
int INFO = cdoOperatorAdd("info", 0, 0, NULL);
int INFOP = cdoOperatorAdd("infop", 0, 0, NULL);
int INFON = cdoOperatorAdd("infon", 0, 0, NULL);
int INFOC = cdoOperatorAdd("infoc", 0, 0, NULL);
int MAP = cdoOperatorAdd("map", 0, 0, NULL);
operatorID = cdoOperatorID();
UNUSED(INFO);
UNUSED(INFOP);
for ( indf = 0; indf < cdoStreamCnt(); indf++ )
int operatorID = cdoOperatorID();
for ( int indf = 0; indf < cdoStreamCnt(); indf++ )
{
streamID = streamOpenRead(cdoStreamName(indf));
int streamID = streamOpenRead(cdoStreamName(indf));
vlistID = streamInqVlist(streamID);
int vlistID = streamInqVlist(streamID);
int taxisID = vlistInqTaxis(vlistID);
if ( vlistNvars(vlistID) == 0 ) continue;
gridsize = vlistGridsizeMax(vlistID);
if ( vlistNumber(vlistID) != CDI_REAL ) gridsize *= 2;
array = (double*) malloc(gridsize*sizeof(double));
double *array = (double*) malloc(gridsize*sizeof(double));
indg = 0;
tsID = 0;
taxisID = vlistInqTaxis(vlistID);
int indg = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID, tsID)) )
{
vdate = taxisInqVdate(taxisID);
......@@ -487,6 +483,7 @@ void *Info(void *argument)
}
tsID++;
}
streamClose(streamID);
if ( array ) free(array);
......
......@@ -81,7 +81,7 @@ void *Input(void *argument)
int vlistID = -1;
int nmiss = 0;
int i;
int code = 0, code0 = 0, level = 0, date = 0, time = 0, nlon = 0, nlat = 0;
int code = 0, level = 0, date = 0, time = 0, nlon = 0, nlat = 0;
int output_filetype = FILETYPE_GRB;
int rval;
int ihead[8];
......@@ -157,7 +157,6 @@ void *Input(void *argument)
if ( nrecs == 0 )
{
code0 = code;
levels[0] = level;
gridsize0 = gridsize;
......@@ -204,7 +203,6 @@ void *Input(void *argument)
if ( nrecs == 0 )
{
code0 = code;
levels[0] = level;
gridsize0 = gridsize;
......
......@@ -189,6 +189,8 @@ void *Intlevel(void *argument)
int INTLEVEL = cdoOperatorAdd("intlevel", 0, 0, NULL);
int INTLEVELX = cdoOperatorAdd("intlevelx", 0, 0, NULL);
UNUSED(INTLEVEL);
int operatorID = cdoOperatorID();
if ( operatorID == INTLEVELX ) expol = TRUE;
......
......@@ -314,42 +314,31 @@ void invertLatData(double *array1, double *array2, int gridID1)
void *Invert(void *argument)
{
int INVERTLAT, INVERTLON, INVERTLATDES, INVERTLONDES, INVERTLATDATA, INVERTLONDATA;
int operatorID;
int operfunc1, operfunc2;
int streamID1, streamID2;
int nrecs;
int tsID, recID, varID, levelID;
int gridsize;
int vlistID1, vlistID2;
int recID, varID, levelID;
int gridID1;
int nmiss;
double *array1, *array2;
int taxisID1, taxisID2;
cdoInitialize(argument);
INVERTLAT = cdoOperatorAdd("invertlat", func_all, 0, NULL);
INVERTLON = cdoOperatorAdd("invertlon", func_all, 0, NULL);
INVERTLATDES = cdoOperatorAdd("invertlatdes", func_hrd, 0, NULL);
INVERTLONDES = cdoOperatorAdd("invertlondes", func_hrd, 0, NULL);
INVERTLATDATA = cdoOperatorAdd("invertlatdata", func_fld, 0, NULL);
INVERTLONDATA = cdoOperatorAdd("invertlondata", func_fld, 0, NULL);
operatorID = cdoOperatorID();
operfunc1 = cdoOperatorF1(operatorID);
if ( operatorID == INVERTLAT || operatorID == INVERTLATDES || operatorID == INVERTLATDATA )
operfunc2 = func_lat;
else
operfunc2 = func_lon;
cdoOperatorAdd("invertlat", func_all, func_lat, NULL);
cdoOperatorAdd("invertlon", func_all, func_lon, NULL);
cdoOperatorAdd("invertlatdes", func_hrd, func_lat, NULL);
cdoOperatorAdd("invertlondes", func_hrd, func_lon, NULL);
cdoOperatorAdd("invertlatdata", func_fld, func_lat, NULL);
cdoOperatorAdd("invertlondata", func_fld, func_lon, NULL);
int operatorID = cdoOperatorID();
int operfunc1 = cdoOperatorF1(operatorID);
int operfunc2 = cdoOperatorF2(operatorID);
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
if ( operfunc1 == func_all || operfunc1 == func_hrd )
......@@ -360,16 +349,16 @@ void *Invert(void *argument)
invertLonDes(vlistID2);
}
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
streamDefVlist(streamID2, vlistID2);
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
array1 = (double*) malloc(gridsize*sizeof(double));
array2 = (double*) malloc(gridsize*sizeof(double));
double *array1 = (double*) malloc(gridsize*sizeof(double));
double *array2 = (double*) malloc(gridsize*sizeof(double));
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
......
......@@ -90,59 +90,46 @@ void invertLevDes(int vlistID)
void *Invertlev(void *argument)
{
int INVERTLEV;
int operatorID;
int operfunc;
int streamID1, streamID2;
int nrecs, nvars;
int tsID, recID, varID, levelID;
int gridsize;
int vlistID1, vlistID2;
int nrecs;
int recID, varID, levelID;
int nmiss;
int **varnmiss;
double *array;
double **vardata;
int taxisID1, taxisID2;
int lcopy = FALSE;
int nlev, nlevel;
int gridID, zaxisID, zaxistype, offset;
int lcopy = FALSE;
int linvert = FALSE;
cdoInitialize(argument);
if ( UNCHANGED_RECORD ) lcopy = TRUE;
INVERTLEV = cdoOperatorAdd("invertlev", func_all, 0, NULL);
cdoOperatorAdd("invertlev", func_all, 0, NULL);
operatorID = cdoOperatorID();
operfunc = cdoOperatorF1(operatorID);
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
if ( operfunc == func_all || operfunc == func_hrd )
{
invertLevDes(vlistID2);
}
if ( operfunc == func_all || operfunc == func_hrd ) invertLevDes(vlistID2);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
streamDefVlist(streamID2, vlistID2);
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
array = (double*) malloc(gridsize*sizeof(double));
double *array = (double*) malloc(gridsize*sizeof(double));
nvars = vlistNvars(vlistID1);
int nvars = vlistNvars(vlistID1);
vardata = (double**) malloc(nvars*sizeof(double*));
varnmiss = (int**) malloc(nvars*sizeof(int*));
double **vardata = (double**) malloc(nvars*sizeof(double*));
int **varnmiss = (int**) malloc(nvars*sizeof(int*));
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -167,7 +154,7 @@ void *Invertlev(void *argument)
if ( linvert == FALSE ) cdoWarning("No variables with invertable levels found!");
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
......
......@@ -26,8 +26,7 @@ void dumplogo(const char *logfilename, int dumptype);
void *Log(void *argument)
{
int DUMPLOGS, DAYLOGS, MONLOGS, DUMPLOGO;
int SNAMELOGO, SCALLLOGO, SMEMLOGO, STIMELOGO, SPERCLOGO;
int DUMPLOGS, DAYLOGS, MONLOGS;
int operatorID, operfunc;
int dumptype;
......@@ -36,12 +35,12 @@ void *Log(void *argument)
DUMPLOGS = cdoOperatorAdd("dumplogs", 0, 0, NULL);
DAYLOGS = cdoOperatorAdd("daylogs", 0, 0, NULL);
MONLOGS = cdoOperatorAdd("monlogs", 0, 0, NULL);
DUMPLOGO = cdoOperatorAdd("dumplogo", 1, 0, NULL);
SNAMELOGO = cdoOperatorAdd("snamelogo", 1, 1, NULL);
SCALLLOGO = cdoOperatorAdd("scalllogo", 1, 2, NULL);
SMEMLOGO = cdoOperatorAdd("smemlogo", 1, 3, NULL);
STIMELOGO = cdoOperatorAdd("stimelogo", 1, 4, NULL);
SPERCLOGO = cdoOperatorAdd("sperclogo", 1, 5, NULL);
cdoOperatorAdd("dumplogo", 1, 0, NULL);
cdoOperatorAdd("snamelogo", 1, 1, NULL);
cdoOperatorAdd("scalllogo", 1, 2, NULL);
cdoOperatorAdd("smemlogo", 1, 3, NULL);
cdoOperatorAdd("stimelogo", 1, 4, NULL);
cdoOperatorAdd("sperclogo", 1, 5, NULL);
operatorID = cdoOperatorID();
operfunc = cdoOperatorF1(operatorID);
......
......@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libcdo.la
libcdo_la_SOURCES = \
cdo_int.h \
compare.h \
cdo_pthread.c \
cdo_vlist.c \
cdo_getopt.c \
......
......@@ -541,22 +541,23 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libcdo.la
libcdo_la_SOURCES = cdo_int.h cdo_pthread.c cdo_vlist.c cdo_getopt.c \
cdo_getopt.h color.c color.h commandline.c const.h counter.h \
datetime.c datetime.h dmemory.h dtypes.h ecacore.c ecacore.h \
ecautil.c ecautil.h error.h etopo.h temp.h mask.h exception.c \
expr.c expr.h expr_lex.c expr_yacc.c expr_yacc.h features.c \
field.c field.h field2.c fieldc.c fieldmem.c fieldmer.c \
fieldzon.c fouriertrans.c functs.h gradsdeslib.c gradsdeslib.h \
grid.c grid.h grid_area.c grid_gme.c grid_lcc.c grid_rot.c \
gridreference.c griddes.c griddes.h griddes_h5.c griddes_nc.c \
hetaeta.c hetaeta.h history.c institution.c interpol.c \
interpol.h job.c juldate.c kvlist.c kvlist.h legendre.c list.c \
list.h merge_sort2.c merge_sort2.h modules.c modules.h \
namelist.c namelist.h normal.c nth_element.c nth_element.h \
operator_help.h par_io.c par_io.h percentiles.c percentiles.h \
pipe.c pipe.h pragma_omp_atomic_update.h printinfo.h process.c \
process.h pstream.c pstream.h pstream_int.h pthread_debug.c \
libcdo_la_SOURCES = cdo_int.h compare.h cdo_pthread.c cdo_vlist.c \
cdo_getopt.c cdo_getopt.h color.c color.h commandline.c \
const.h counter.h datetime.c datetime.h dmemory.h dtypes.h \
ecacore.c ecacore.h ecautil.c ecautil.h error.h etopo.h temp.h \
mask.h exception.c expr.c expr.h expr_lex.c expr_yacc.c \
expr_yacc.h features.c field.c field.h field2.c fieldc.c \
fieldmem.c fieldmer.c fieldzon.c fouriertrans.c functs.h \
gradsdeslib.c gradsdeslib.h grid.c grid.h grid_area.c \
grid_gme.c grid_lcc.c grid_rot.c gridreference.c griddes.c \
griddes.h griddes_h5.c griddes_nc.c hetaeta.c hetaeta.h \
history.c institution.c interpol.c interpol.h job.c juldate.c \
kvlist.c kvlist.h legendre.c list.c list.h merge_sort2.c \
merge_sort2.h modules.c modules.h namelist.c namelist.h \
normal.c nth_element.c nth_element.h operator_help.h par_io.c \
par_io.h percentiles.c percentiles.h pipe.c pipe.h \
pragma_omp_atomic_update.h printinfo.h process.c process.h \
pstream.c pstream.h pstream_int.h pthread_debug.c \
pthread_debug.h readline.c realtime.c remap.h remaplib.c \
remapsort.c remap_scrip_io.c remap_search_reg2d.c \
remap_search_latbins.c remap_store_link.c remap_store_link.h \
......
......@@ -34,7 +34,7 @@ void gen_index(int gridID1, int gridID2, int *index)
int nlat1, nlon1;
int nlat2, nlon2;
int gridtype1, gridtype2;
int gridsize1, gridsize2;
int gridsize2;
int i, j, k, i1, i2;
int *xindex = NULL, *yindex = NULL;
double *xvals1 = NULL, *yvals1 = NULL;
......@@ -43,7 +43,6 @@ void gen_index(int gridID1, int gridID2, int *index)
gridtype1 = gridInqType(gridID1);
gridtype2 = gridInqType(gridID2);
gridsize1 = gridInqSize(gridID1);
gridsize2 = gridInqSize(gridID2);
if ( gridtype1 != gridtype2 )
......
......@@ -57,6 +57,8 @@ void *Pinfo(void *argument)
PINFO = cdoOperatorAdd("pinfo", 0, 0, NULL);
PINFOV = cdoOperatorAdd("pinfov", 0, 0, NULL);
UNUSED(PINFO);
operatorID = cdoOperatorID();
streamID1 = streamOpenRead(cdoStreamName(0));
......
......@@ -33,7 +33,7 @@
void *Seaspctl(void *argument)
{
int timestat_date = TIMESTAT_MEAN;
int vdate1 = 0, vtime1 = 0;
int vdate1 = 0;
int vdate2 = 0, vtime2 = 0;
int vdate3 = 0, vtime3 = 0;
int nrecs;
......@@ -162,7 +162,6 @@ void *Seaspctl(void *argument)
{
dtlist_taxisInqTimestep(dtlist, taxisID1, nsets);
vdate1 = dtlist_get_vdate(dtlist, nsets);
vtime1 = dtlist_get_vtime(dtlist, nsets);
cdiDecodeDate(vdate1, &year, &month, &day);
if ( month < 0 || month > 16 )
......
......@@ -28,6 +28,7 @@
#include <math.h>
#include <float.h>
#include "compare.h"
#include "timebase.h"
#include "field.h"
#include "functs.h"
......@@ -72,32 +73,6 @@ char *strdup(const char *s);
enum T_WEIGHT_MODE {WEIGHT_OFF, WEIGHT_ON};
enum T_EIGEN_MODE {JACOBI, DANIELSON_LANCZOS};
#if defined(__xlC__) /* performance problems on IBM */
#ifndef DBL_IS_NAN
# define DBL_IS_NAN(x) ((x) != (x))
#endif
#else
#ifndef DBL_IS_NAN
#if defined(HAVE_DECL_ISNAN)
# define DBL_IS_NAN(x) (isnan(x))
#elif defined(FP_NAN)
# define DBL_IS_NAN(x) (fpclassify(x) == FP_NAN)
#else
# define DBL_IS_NAN(x) ((x) != (x))
#endif
#endif
#endif
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#ifndef IS_EQUAL
# define IS_NOT_EQUAL(x,y) (x < y || y < x)
# define IS_EQUAL(x,y) (!IS_NOT_EQUAL(x,y))
#endif
#ifndef M_LN10
#define M_LN10 2.30258509299404568402 /* log_e 10 */
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2015 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef _COMPARE_H
#define _COMPARE_H
#if defined(HAVE_CONFIG_H)
# include "config.h"
#endif
#include <math.h>
#if defined(__xlC__) /* performance problems on IBM */
#ifndef DBL_IS_NAN
# define DBL_IS_NAN(x) ((x) != (x))
#endif
#else
#ifndef DBL_IS_NAN
#if defined(HAVE_DECL_ISNAN)
# define DBL_IS_NAN(x) (isnan(x))
#elif defined(FP_NAN)
# define DBL_IS_NAN(x) (fpclassify(x) == FP_NAN)
#else
# define DBL_IS_NAN(x) ((x) != (x))
#endif
#endif
#endif
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
# define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif
#ifndef IS_EQUAL
# define IS_NOT_EQUAL(x,y) (x < y || y < x)
# define IS_EQUAL(x,y) (!IS_NOT_EQUAL(x,y))
#endif
#endif /* _COMPARE_H */
......@@ -415,7 +415,7 @@ void eca2(const ECA_REQUEST_2 *request)
long nsets;
int i;
int istreamID1, istreamID2, ostreamID;
int ivlistID1, ivlistID2, ovlistID, itaxisID1, itaxisID2, otaxisID;
int ivlistID1, ivlistID2, ovlistID, itaxisID1, otaxisID;
int nlevels;
int *recVarID, *recLevelID;
double missval1, missval2;
......@@ -466,7 +466,6 @@ void eca2(const ECA_REQUEST_2 *request)
if ( cdoOperatorF2(operatorID) == 16 ) vlistDefNtsteps(ovlistID, 1);
itaxisID1 = vlistInqTaxis(ivlistID1);
itaxisID2 = vlistInqTaxis(ivlistID2);
otaxisID = taxisCreate(TAXIS_RELATIVE);
taxisDefTunit(otaxisID, TUNIT_MINUTE);
// taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC);
......
......@@ -3,11 +3,8 @@
#include <string.h>
#include <math.h>
#include "cdo_int.h" // IS_EQUAL
#ifndef _VINTERP_H
# include "vinterp.h"
#endif
#include "compare.h"
#include "vinterp.h"
#define SCALEHEIGHT (-7000.)
#define SCALESLP (101325.0)
......@@ -461,8 +458,8 @@ void vert_interp_lev3d(int gridsize, double missval, double *vardata1, double *v
*/
w1 = wgt1;
w2 = wgt2;
if ( DBL_IS_EQUAL(var1L1, missval) ) w1 = 0;
if ( DBL_IS_EQUAL(var1L2, missval) ) w2 = 0;
if ( DBL_IS_EQUAL(var1L1, missval) ) w1 = 0;
if ( DBL_IS_EQUAL(var1L2, missval) ) w2 = 0;
if ( IS_EQUAL(w1, 0) && IS_EQUAL(w2, 0) )
{
......@@ -490,6 +487,8 @@ void vert_interp_lev3d(int gridsize, double missval, double *vardata1, double *v
}
}
#if defined(CDO)
#include "util.h"
/*
* Create weights for the 3d vertical coordinate
*
......@@ -672,3 +671,4 @@ void vert_gen_weights3d1d(int expol, int nlev1, int gridsize, double *lev1, int
}
}
}
#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