Commits (34)
2019-10-29 Uwe Schulzweida
2021-01-25 Uwe Schulzweida
* using CGRIBEX library version 1.9.5
* Version 1.9.10 released
2021-01-07 Uwe Schulzweida
* gridDefParamRLL: set x/y units to degrees
2020-12-03 Uwe Schulzweida
* gridDefParamLCC: write latitude_of_projection_origin to lat_0 (bug fix)
2020-11-27 Uwe Schulzweida
* struct record_t: changed data type of levelID from short to int
2020-11-26 Uwe Schulzweida
* cdi.h: removed function gaussianLatitudes() from cdi interface
2020-10-09 Uwe Schulzweida
* using CGRIBEX library version 1.9.5
* Version 1.9.9 released
2020-09-25 Uwe Schulzweida
* cdi_generate_vars: set level to level1 if zaxis bounds are available (removed level = (level1 + level2) / 2)
2020-09-21 Uwe Schulzweida
* Ignore netCDF attribute _NCProperties
......
......@@ -4,10 +4,10 @@
# autoconf 2.69
# libtool 2.4.6
AC_PREREQ([2.69])
AC_PREREQ([2.70])
LT_PREREQ([2.4.6])
AC_INIT([cdi], [1.9.9rc5], [https://mpimet.mpg.de/cdi])
AC_INIT([cdi],[1.9.10],[https://mpimet.mpg.de/cdi])
AC_DEFINE_UNQUOTED(CDI, ["$PACKAGE_VERSION"], [CDI version])
......@@ -27,7 +27,7 @@ AC_CONFIG_HEADERS([src/config.h])
AM_MAINTAINER_MODE([disable])
# Check building environment
AC_PROG_CC_C99
AC_PROG_CC
dnl The check above forgets to delete the following directory
dnl generated by the MacOS linker, which results in multiple
dnl annoying messages from the rm utility:
......@@ -439,10 +439,11 @@ AC_CONFIG_FILES([tests/test_cksum_grib \
tables/gen_tableheaderfile \
util/serialrun],[chmod a+x "$ac_file"])
AC_OUTPUT([Makefile src/Makefile interfaces/Makefile app/Makefile \
AC_CONFIG_FILES([Makefile src/Makefile interfaces/Makefile app/Makefile \
tests/Makefile examples/Makefile cdi.settings \
examples/pio/Makefile src/pkgconfig/cdi.pc src/pkgconfig/cdipio.pc \
src/pkgconfig/cdi_f2003.pc])
AC_OUTPUT
# ----------------------------------------------------------------------
# Show configuration
......
......@@ -64,7 +64,7 @@ libcdi_la_SOURCES = \
extralib.c \
file.c \
file.h \
gaussgrid.c \
gaussian_latitudes.c \
gribapi.c \
gribapi.h \
gribapi_utilities.h \
......
......@@ -7,6 +7,7 @@
UINT32 get_UINT32(unsigned char *x)
{
// clang-format off
switch (HOST_ENDIANNESS)
{
case CDI_BIGENDIAN:
......@@ -17,11 +18,13 @@ UINT32 get_UINT32(unsigned char *x)
Error("Unhandled endianness %d", HOST_ENDIANNESS);
return UINT32_C(0xFFFFFFFF);
}
// clang-format on
}
UINT32 get_SUINT32(unsigned char *x)
{
// clang-format off
switch (HOST_ENDIANNESS)
{
case CDI_BIGENDIAN:
......@@ -32,11 +35,13 @@ UINT32 get_SUINT32(unsigned char *x)
Error("Unhandled endianness %d", HOST_ENDIANNESS);
return UINT32_C(0xFFFFFFFF);
}
// clang-format on
}
UINT64 get_UINT64(unsigned char *x)
{
// clang-format off
switch (HOST_ENDIANNESS)
{
case CDI_BIGENDIAN:
......@@ -49,11 +54,13 @@ UINT64 get_UINT64(unsigned char *x)
Error("Unhandled endianness %d", HOST_ENDIANNESS);
return UINT64_C(0xFFFFFFFFFFFFFFFF);
}
// clang-format on
}
UINT64 get_SUINT64(unsigned char *x)
{
// clang-format off
switch (HOST_ENDIANNESS)
{
case CDI_BIGENDIAN:
......@@ -66,6 +73,7 @@ UINT64 get_SUINT64(unsigned char *x)
Error("Unhandled endianness %d", HOST_ENDIANNESS);
return UINT64_C(0xFFFFFFFFFFFFFFFF);
}
// clang-format on
}
......@@ -85,8 +93,8 @@ size_t binReadF77Block(int fileID, int byteswap)
void binWriteF77Block(int fileID, int byteswap, size_t blocksize)
{
static unsigned int s[4] = {0, 8, 16, 24};
unsigned long ublocksize = (unsigned long) blocksize;
static const unsigned int s[4] = {0, 8, 16, 24};
const unsigned long ublocksize = (unsigned long) blocksize;
unsigned char f77block[4];
switch (HOST_ENDIANNESS)
......@@ -142,28 +150,6 @@ int binReadInt64(int fileID, int byteswap, size_t size, INT64 *ptr)
}
int binReadFlt32(int fileID, int byteswap, size_t size, FLT32 *ptr)
{
if ( sizeof(FLT32) != 4 ) Error("Not implemented for %d byte float!", sizeof(FLT32));
fileRead(fileID, (void *) ptr, 4*size);
if ( byteswap ) swap4byte(ptr, size);
return 0;
}
int binReadFlt64(int fileID, int byteswap, size_t size, FLT64 *ptr)
{
if ( sizeof(FLT64) != 8 ) Error("Not implemented for %d byte float!", sizeof(FLT64));
fileRead(fileID, (void *) ptr, 8*size);
if ( byteswap ) swap8byte(ptr, size);
return 0;
}
int binWriteInt32(int fileID, int byteswap, size_t size, INT32 *ptr)
{
if ( sizeof(INT32) != 4 ) Error("Not implemented for %d byte integer!", sizeof(INT32));
......
......@@ -2,7 +2,7 @@
#define BINARY_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <inttypes.h>
......@@ -34,9 +34,6 @@ int binReadInt64(int fileID, int byteswap, size_t size, INT64 *ptr);
int binWriteInt32(int fileID, int byteswap, size_t size, INT32 *ptr);
int binWriteInt64(int fileID, int byteswap, size_t size, INT64 *ptr);
int binReadFlt32(int fileID, int byteswap, size_t size, FLT32 *ptr);
int binReadFlt64(int fileID, int byteswap, size_t size, FLT64 *ptr);
int binWriteFlt32(int fileID, int byteswap, size_t size, FLT32 *ptr);
int binWriteFlt64(int fileID, int byteswap, size_t size, FLT64 *ptr);
......
......@@ -27,25 +27,12 @@ int days_per_month(int calendar, int year, int month)
{
int daysperyear = calendar_dpy(calendar);
const int *dpm;
if ( daysperyear == 360 ) dpm = month_360;
else if ( daysperyear == 365 ) dpm = month_365;
else dpm = month_366;
int dayspermonth = 0;
if ( month >= 1 && month <= 12 )
dayspermonth = dpm[month-1];
/*
else
fprintf(stderr, "days_per_month: month %d out of range\n", month);
*/
if ( daysperyear == 0 && month == 2 )
{
if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
dayspermonth = 29;
else
dayspermonth = 28;
}
const int *dpm = (daysperyear == 360) ? month_360 : ((daysperyear == 365) ? month_365 : month_366);
int dayspermonth = ( month >= 1 && month <= 12 ) ? dpm[month-1] : 0;
if (daysperyear == 0 && month == 2)
dayspermonth = ((year%4 == 0 && year%100 != 0) || year%400 == 0) ? 29 : 28;
return dayspermonth;
}
......@@ -55,11 +42,11 @@ int days_per_year(int calendar, int year)
{
int daysperyear = calendar_dpy(calendar);
if ( daysperyear == 0 )
if (daysperyear == 0)
{
if ( year == 1582 && (calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN) )
if (year == 1582 && (calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN))
daysperyear = 355;
else if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
else if ((year%4 == 0 && year%100 != 0) || year%400 == 0)
daysperyear = 366;
else
daysperyear = 365;
......@@ -71,8 +58,6 @@ int days_per_year(int calendar, int year)
static void decode_day(int dpy, int days, int *year, int *month, int *day)
{
int i = 0;
*year = (days-1) / dpy;
days -= (*year*dpy);
......@@ -81,6 +66,7 @@ static void decode_day(int dpy, int days, int *year, int *month, int *day)
else if ( dpy == 365 ) dpm = month_365;
else if ( dpy == 366 ) dpm = month_366;
int i = 0;
if ( dpm )
for ( i = 0; i < 12; i++ )
{
......@@ -112,7 +98,7 @@ static int64_t encode_day(int dpy, int year, int month, int day)
void encode_caldaysec(int calendar, int year, int month, int day, int hour, int minute, int second,
int64_t *julday, int *secofday)
{
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
if ( dpy == 360 || dpy == 365 || dpy == 366 )
*julday = encode_day(dpy, year, month, day);
......@@ -126,7 +112,7 @@ void encode_caldaysec(int calendar, int year, int month, int day, int hour, int
void decode_caldaysec(int calendar, int64_t julday, int secofday,
int *year, int *month, int *day, int *hour, int *minute, int *second)
{
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
if ( dpy == 360 || dpy == 365 || dpy == 366 )
decode_day(dpy, julday, year, month, day);
......@@ -142,7 +128,7 @@ void decode_caldaysec(int calendar, int64_t julday, int secofday,
#ifdef TEST
static int date_to_calday(int calendar, int date)
{
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
int year, month, day;
cdiDecodeDate(date, &year, &month, &day);
......@@ -160,14 +146,14 @@ static int date_to_calday(int calendar, int date)
static int calday_to_date(int calendar, int calday)
{
int year, month, day;
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
if ( dpy == 360 || dpy == 365 || dpy == 366 )
decode_day(dpy, calday, &year, &month, &day);
else
decode_julday(calendar, calday, &year, &month, &day);
int date = cdiEncodeDate(year, month, day);
const int date = cdiEncodeDate(year, month, day);
return date;
}
......
......@@ -103,7 +103,7 @@ static int cdfOpenFile(const char *filename, const char *mode, int *filetype)
{
case 'r':
{
int status = cdf_open(filename, readmode, &ncid);
const int status = cdf_open(filename, readmode, &ncid);
if ( status > 0 && ncid < 0 ) ncid = CDI_ESYSTEM;
#ifdef HAVE_NETCDF4
else
......
......@@ -28,7 +28,7 @@ void cdf_create(const char *path, int cmode, int *ncidp)
int status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d mode = %d chunksizehint = %zu file = %s", *ncidp, cmode, chunksizehint, path);
Message("ncid=%d mode=%d chunksizehint=%zu file=%s", *ncidp, cmode, chunksizehint, path);
if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
......@@ -75,7 +75,7 @@ int cdf_open(const char *path, int omode, int *ncidp)
}
if ( CDF_Debug )
Message("ncid = %d mode = %d file = %s", *ncidp, omode, path);
Message("ncid=%d mode=%d file=%s", *ncidp, omode, path);
if ( CDF_Debug && status != NC_NOERR ) Message("%s", nc_strerror(status));
......@@ -85,21 +85,21 @@ int cdf_open(const char *path, int omode, int *ncidp)
void cdf_close(int ncid)
{
int status = nc_close(ncid);
const int status = nc_close(ncid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
void cdf_redef(int ncid)
{
int status = nc_redef(ncid);
const int status = nc_redef(ncid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
void cdf_enddef(int ncid)
{
int status = nc_enddef(ncid);
const int status = nc_enddef(ncid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -111,24 +111,24 @@ void cdf__enddef(const int ncid, const size_t hdr_pad)
const size_t r_align = 4UL; // [B] Alignment of beginning of data section for record variables
// nc_enddef(ncid) is equivalent to nc__enddef(ncid, 0, 4, 0, 4)
int status = nc__enddef(ncid, hdr_pad, v_align, v_minfree, r_align);
const int status = nc__enddef(ncid, hdr_pad, v_align, v_minfree, r_align);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
void cdf_sync(int ncid)
{
int status = nc_sync(ncid);
const int status = nc_sync(ncid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
void cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp)
{
int status = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp);
const int status = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d",
Message("ncid=%d ndims=%d nvars=%d ngatts=%d unlimid=%d",
ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
......@@ -137,10 +137,10 @@ void cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp)
void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
{
int status = nc_def_dim(ncid, name, len, dimidp);
const int status = nc_def_dim(ncid, name, len, dimidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d name = %s len = %d", ncid, name, len);
Message("ncid=%d name=%s len=%d", ncid, name, len);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -148,10 +148,10 @@ void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
{
int status = nc_inq_dimid(ncid, name, dimidp);
const int status = nc_inq_dimid(ncid, name, dimidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d name = %s dimid= %d", ncid, name, *dimidp);
Message("ncid=%d name=%s dimid=%d", ncid, name, *dimidp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -159,10 +159,10 @@ void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
{
int status = nc_inq_dim(ncid, dimid, name, lengthp);
const int status = nc_inq_dim(ncid, dimid, name, lengthp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d dimid = %d length = %d name = %s", ncid, dimid, *lengthp, name);
Message("ncid=%d dimid=%d length=%d name=%s", ncid, dimid, *lengthp, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -170,10 +170,10 @@ void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
void cdf_inq_dimname(int ncid, int dimid, char *name)
{
int status = nc_inq_dimname(ncid, dimid, name);
const int status = nc_inq_dimname(ncid, dimid, name);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d dimid = %d name = %s", ncid, dimid, name);
Message("ncid=%d dimid=%d name=%s", ncid, dimid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -181,10 +181,10 @@ void cdf_inq_dimname(int ncid, int dimid, char *name)
void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
{
int status = nc_inq_dimlen(ncid, dimid, lengthp);
const int status = nc_inq_dimlen(ncid, dimid, lengthp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d dimid = %d length = %d", ncid, dimid, *lengthp);
Message("ncid=%d dimid=%d length=%d", ncid, dimid, *lengthp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -202,11 +202,10 @@ void
cdf_def_var_serial(int ncid, const char *name, nc_type xtype, int ndims,
const int dimids[], int *varidp)
{
int status = nc_def_var(ncid, name, xtype, ndims, dimids, varidp);
const int status = nc_def_var(ncid, name, xtype, ndims, dimids, varidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d name = %s xtype = %d ndims = %d varid = %d",
ncid, name, xtype, ndims, *varidp);
Message("ncid=%d name=%s xtype=%d ndims=%d varid=%d", ncid, name, xtype, ndims, *varidp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -215,10 +214,10 @@ cdf_def_var_serial(int ncid, const char *name, nc_type xtype, int ndims,
void cdf_inq_varid(int ncid, const char *name, int *varidp)
{
int status = nc_inq_varid(ncid, name, varidp);
const int status = nc_inq_varid(ncid, name, varidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d name = %s varid = %d ", ncid, name, *varidp);
Message("ncid=%d name=%s varid=%d", ncid, name, *varidp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -226,10 +225,10 @@ void cdf_inq_varid(int ncid, const char *name, int *varidp)
void cdf_inq_nvars(int ncid, int *nvarsp)
{
int status = nc_inq_nvars(ncid, nvarsp);
const int status = nc_inq_nvars(ncid, nvarsp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d nvars = %d", ncid, *nvarsp);
Message("ncid=%d nvars=%d", ncid, *nvarsp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -238,10 +237,10 @@ void cdf_inq_nvars(int ncid, int *nvarsp)
void cdf_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp,
int dimids[], int *nattsp)
{
int status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);
const int status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d ndims = %d xtype = %d natts = %d name = %s",
Message("ncid=%d varid=%d ndims=%d xtype=%d natts=%d name=%s",
ncid, varid, *ndimsp, *xtypep, *nattsp, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
......@@ -250,10 +249,10 @@ void cdf_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp,
void cdf_inq_varname(int ncid, int varid, char *name)
{
int status = nc_inq_varname(ncid, varid, name);
const int status = nc_inq_varname(ncid, varid, name);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Message("ncid=%d varid=%d name=%s", ncid, varid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -261,10 +260,10 @@ void cdf_inq_varname(int ncid, int varid, char *name)
void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
{
int status = nc_inq_vartype(ncid, varid, xtypep);
const int status = nc_inq_vartype(ncid, varid, xtypep);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d xtype = %s", ncid, varid, *xtypep);
Message("ncid=%d varid=%d xtype=%s", ncid, varid, *xtypep);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -272,10 +271,10 @@ void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
{
int status = nc_inq_varndims(ncid, varid, ndimsp);
const int status = nc_inq_varndims(ncid, varid, ndimsp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -283,10 +282,10 @@ void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
void cdf_inq_vardimid(int ncid, int varid, int dimids[])
{
int status = nc_inq_vardimid(ncid, varid, dimids);
const int status = nc_inq_vardimid(ncid, varid, dimids);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -294,10 +293,10 @@ void cdf_inq_vardimid(int ncid, int varid, int dimids[])
void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
{
int status = nc_inq_varnatts(ncid, varid, nattsp);
const int status = nc_inq_varnatts(ncid, varid, nattsp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d nattsp = %d", ncid, varid, *nattsp);
Message("ncid=%d varid=%d nattsp=%d", ncid, varid, *nattsp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -305,7 +304,7 @@ void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
void cdf_put_var_text(int ncid, int varid, const char *tp)
{
int status = nc_put_var_text(ncid, varid, tp);
const int status = nc_put_var_text(ncid, varid, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %s", ncid, varid, tp);
......@@ -316,7 +315,7 @@ void cdf_put_var_text(int ncid, int varid, const char *tp)
void cdf_put_var_short(int ncid, int varid, const short *sp)
{
int status = nc_put_var_short(ncid, varid, sp);
const int status = nc_put_var_short(ncid, varid, sp);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %hd", ncid, varid, *sp);
......@@ -327,7 +326,7 @@ void cdf_put_var_short(int ncid, int varid, const short *sp)
void cdf_put_var_int(int ncid, int varid, const int *ip)
{
int status = nc_put_var_int(ncid, varid, ip);
const int status = nc_put_var_int(ncid, varid, ip);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %d", ncid, varid, *ip);
......@@ -338,7 +337,7 @@ void cdf_put_var_int(int ncid, int varid, const int *ip)
void cdf_put_var_long(int ncid, int varid, const long *lp)
{
int status = nc_put_var_long(ncid, varid, lp);
const int status = nc_put_var_long(ncid, varid, lp);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %ld", ncid, varid, *lp);
......@@ -349,7 +348,7 @@ void cdf_put_var_long(int ncid, int varid, const long *lp)
void cdf_put_var_float(int ncid, int varid, const float *fp)
{
int status = nc_put_var_float(ncid, varid, fp);
const int status = nc_put_var_float(ncid, varid, fp);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %f", ncid, varid, *fp);
......@@ -407,7 +406,7 @@ void minmaxvalf(size_t nvals, const float *array, double *minval, double *maxval
void cdf_put_vara_double(int ncid, int varid, const size_t start[],
const size_t count[], const double *dp)
{
int status = nc_put_vara_double(ncid, varid, start, count, dp);
const int status = nc_put_vara_double(ncid, varid, start, count, dp);
if ( CDF_Debug || status != NC_NOERR )
{
......@@ -417,11 +416,11 @@ void cdf_put_vara_double(int ncid, int varid, const size_t start[],
nc_inq_vartype(ncid, varid, &xtype);
int ndims;
nc_inq_varndims(ncid, varid, &ndims);
double minval = 0, maxval = 0;
double minval = 0.0, maxval = 0.0;
size_t nvals = 1;
for ( int i = 0; i < ndims; ++i ) nvals *= count[i];
minmaxval(nvals, dp, &minval, &maxval);
// Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);
// Message("ncid=%d varid=%d val0=%f", ncid, varid, *dp);
Message("name=%s type=%s minval=%f maxval=%f", name, cdf_var_type(xtype), minval, maxval);
}
......@@ -432,7 +431,7 @@ void cdf_put_vara_double(int ncid, int varid, const size_t start[],
void cdf_put_vara_float(int ncid, int varid, const size_t start[],
const size_t count[], const float *fp)
{
int status = nc_put_vara_float(ncid, varid, start, count, fp);
const int status = nc_put_vara_float(ncid, varid, start, count, fp);
if ( CDF_Debug || status != NC_NOERR )
{
......@@ -442,11 +441,11 @@ void cdf_put_vara_float(int ncid, int varid, const size_t start[],
nc_inq_vartype(ncid, varid, &xtype);
int ndims;
nc_inq_varndims(ncid, varid, &ndims);
double minval = 0, maxval = 0;
double minval = 0.0, maxval = 0.0;
size_t nvals = 1;
for ( int i = 0; i < ndims; ++i ) nvals *= count[i];
minmaxvalf(nvals, fp, &minval, &maxval);
// Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);
// Message("ncid=%d varid=%d val0=%f", ncid, varid, *dp);
Message("name=%s type=%s minval=%f maxval=%f", name, cdf_var_type(xtype), minval, maxval);
}
......@@ -456,10 +455,10 @@ void cdf_put_vara_float(int ncid, int varid, const size_t start[],
void cdf_put_vara(int ncid, int varid, const size_t start[], const size_t count[], const void *cp)
{
int status = nc_put_vara(ncid, varid, start, count, cp);
const int status = nc_put_vara(ncid, varid, start, count, cp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -467,10 +466,10 @@ void cdf_put_vara(int ncid, int varid, const size_t start[], const size_t count[
void cdf_get_vara(int ncid, int varid, const size_t start[], const size_t count[], void *cp)
{
int status = nc_get_vara(ncid, varid, start, count, cp);
const int status = nc_get_vara(ncid, varid, start, count, cp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -478,10 +477,10 @@ void cdf_get_vara(int ncid, int varid, const size_t start[], const size_t count[
void cdf_get_vara_int(int ncid, int varid, const size_t start[], const size_t count[], int *dp)
{
int status = nc_get_vara_int(ncid, varid, start, count, dp);
const int status = nc_get_vara_int(ncid, varid, start, count, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -489,10 +488,10 @@ void cdf_get_vara_int(int ncid, int varid, const size_t start[], const size_t co
void cdf_get_vara_double(int ncid, int varid, const size_t start[], const size_t count[], double *dp)
{
int status = nc_get_vara_double(ncid, varid, start, count, dp);
const int status = nc_get_vara_double(ncid, varid, start, count, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d start[0]=%zu count[0]=%zu", ncid, varid, start[0], count[0]);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -500,10 +499,10 @@ void cdf_get_vara_double(int ncid, int varid, const size_t start[], const size_t
void cdf_get_vara_float(int ncid, int varid, const size_t start[], const size_t count[], float *fp)
{
int status = nc_get_vara_float(ncid, varid, start, count, fp);
const int status = nc_get_vara_float(ncid, varid, start, count, fp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d start[0]=%zu count[0]=%zu", ncid, varid, start[0], count[0]);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -511,10 +510,10 @@ void cdf_get_vara_float(int ncid, int varid, const size_t start[], const size_t
void cdf_get_vara_text(int ncid, int varid, const size_t start[], const size_t count[], char *tp)
{
int status = nc_get_vara_text(ncid, varid, start, count, tp);
const int status = nc_get_vara_text(ncid, varid, start, count, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -522,10 +521,10 @@ void cdf_get_vara_text(int ncid, int varid, const size_t start[], const size_t c
void cdf_get_vara_uchar(int ncid, int varid, const size_t start[], const size_t count[], unsigned char *tp)
{
int status = nc_get_vara_uchar(ncid, varid, start, count, tp);
const int status = nc_get_vara_uchar(ncid, varid, start, count, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -533,10 +532,10 @@ void cdf_get_vara_uchar(int ncid, int varid, const size_t start[], const size_t
void cdf_put_var_double(int ncid, int varid, const double *dp)
{
int status = nc_put_var_double(ncid, varid, dp);
const int status = nc_put_var_double(ncid, varid, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);
Message("ncid=%d varid=%d val0=%f", ncid, varid, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -544,10 +543,10 @@ void cdf_put_var_double(int ncid, int varid, const double *dp)
void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
{
int status = nc_get_var1_text(ncid, varid, index, tp);
const int status = nc_get_var1_text(ncid, varid, index, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -555,10 +554,10 @@ void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
{
int status = nc_get_var1_double(ncid, varid, index, dp);
const int status = nc_get_var1_double(ncid, varid, index, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -566,10 +565,10 @@ void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
{
int status = nc_put_var1_double(ncid, varid, index, dp);
const int status = nc_put_var1_double(ncid, varid, index, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d val = %f", ncid, varid, *dp);
Message("ncid=%d varid=%d val=%f", ncid, varid, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -577,10 +576,10 @@ void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double
void cdf_get_var_text(int ncid, int varid, char *tp)
{
int status = nc_get_var_text(ncid, varid, tp);
const int status = nc_get_var_text(ncid, varid, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -588,10 +587,10 @@ void cdf_get_var_text(int ncid, int varid, char *tp)
void cdf_get_var_short(int ncid, int varid, short *sp)
{
int status = nc_get_var_short(ncid, varid, sp);
const int status = nc_get_var_short(ncid, varid, sp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -599,10 +598,10 @@ void cdf_get_var_short(int ncid, int varid, short *sp)
void cdf_get_var_int(int ncid, int varid, int *ip)
{
int status = nc_get_var_int(ncid, varid, ip);
const int status = nc_get_var_int(ncid, varid, ip);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -610,10 +609,10 @@ void cdf_get_var_int(int ncid, int varid, int *ip)
void cdf_get_var_long(int ncid, int varid, long *lp)
{
int status = nc_get_var_long(ncid, varid, lp);
const int status = nc_get_var_long(ncid, varid, lp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -621,10 +620,10 @@ void cdf_get_var_long(int ncid, int varid, long *lp)
void cdf_get_var_float(int ncid, int varid, float *fp)
{
int status = nc_get_var_float(ncid, varid, fp);
const int status = nc_get_var_float(ncid, varid, fp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d", ncid, varid);
Message("ncid=%d varid=%d", ncid, varid);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -632,10 +631,10 @@ void cdf_get_var_float(int ncid, int varid, float *fp)
void cdf_get_var_double(int ncid, int varid, double *dp)
{
int status = nc_get_var_double(ncid, varid, dp);
const int status = nc_get_var_double(ncid, varid, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d val[0] = %f", ncid, varid, *dp);
Message("ncid=%d varid=%d val[0]=%f", ncid, varid, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -643,7 +642,7 @@ void cdf_get_var_double(int ncid, int varid, double *dp)
void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
{
int status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
const int status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %s %d %d", ncid_in, varid_out, name, ncid_out, varid_out);
......@@ -654,10 +653,10 @@ void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int
void cdf_put_att_text(int ncid, int varid, const char *name, size_t len, const char *tp)
{
int status = nc_put_att_text(ncid, varid, name, len, tp);
const int status = nc_put_att_text(ncid, varid, name, len, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s text = %.*s", ncid, varid, name, (int)len, tp);
Message("ncid=%d varid=%d att=%s text=%.*s", ncid, varid, name, (int)len, tp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -665,10 +664,10 @@ void cdf_put_att_text(int ncid, int varid, const char *name, size_t len, const c
void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype, size_t len, const int *ip)
{
int status = nc_put_att_int(ncid, varid, name, xtype, len, ip);
const int status = nc_put_att_int(ncid, varid, name, xtype, len, ip);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %d", ncid, varid, name, *ip);
Message("ncid=%d varid=%d att=%s val=%d", ncid, varid, name, *ip);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -676,10 +675,10 @@ void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype, size_
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype, size_t len, const float *dp)
{
int status = nc_put_att_float(ncid, varid, name, xtype, len, dp);
const int status = nc_put_att_float(ncid, varid, name, xtype, len, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);
Message("ncid=%d varid=%d att=%s val=%g", ncid, varid, name, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -687,10 +686,10 @@ void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype, siz
void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype, size_t len, const double *dp)
{
int status = nc_put_att_double(ncid, varid, name, xtype, len, dp);
const int status = nc_put_att_double(ncid, varid, name, xtype, len, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);
Message("ncid=%d varid=%d att=%s val=%g", ncid, varid, name, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -698,10 +697,10 @@ void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype, si
void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
{
int status = nc_get_att_text(ncid, varid, name, tp);
const int status = nc_get_att_text(ncid, varid, name, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Message("ncid=%d varid=%d name=%s", ncid, varid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -710,10 +709,10 @@ void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#ifdef HAVE_NETCDF4
int status = nc_get_att_string(ncid, varid, name, tp);
const int status = nc_get_att_string(ncid, varid, name, tp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Message("ncid=%d varid=%d name=%s", ncid, varid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
#endif
......@@ -722,10 +721,10 @@ void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
{
int status = nc_get_att_int(ncid, varid, name, ip);
const int status = nc_get_att_int(ncid, varid, name, ip);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %d", ncid, varid, name, *ip);
Message("ncid=%d varid=%d att=%s val=%d", ncid, varid, name, *ip);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -734,10 +733,10 @@ void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
void cdf_get_att_long(int ncid, int varid, const char *name, long *ip)
{
#ifdef HAVE_NETCDF4
int status = nc_get_att_long(ncid, varid, name, ip);
const int status = nc_get_att_long(ncid, varid, name, ip);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %ld", ncid, varid, name, *ip);
Message("ncid=%d varid=%d att=%s val=%ld", ncid, varid, name, *ip);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
#endif
......@@ -746,12 +745,10 @@ void cdf_get_att_long(int ncid, int varid, const char *name, long *ip)
void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
{
int status;
status = nc_get_att_double(ncid, varid, name, dp);
const int status = nc_get_att_double(ncid, varid, name, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %.9g", ncid, varid, name, *dp);
Message("ncid=%d varid=%d att=%s val=%.9g", ncid, varid, name, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -759,10 +756,10 @@ void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
{
int status = nc_inq_att(ncid, varid, name, xtypep, lenp);
const int status = nc_inq_att(ncid, varid, name, xtypep, lenp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s", ncid, varid, name);
Message("ncid=%d varid=%d att=%s", ncid, varid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -770,10 +767,10 @@ void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t
void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
{
int status = nc_inq_atttype(ncid, varid, name, xtypep);
const int status = nc_inq_atttype(ncid, varid, name, xtypep);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s", ncid, varid, name);
Message("ncid=%d varid=%d att=%s", ncid, varid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -781,10 +778,10 @@ void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
{
int status = nc_inq_attlen(ncid, varid, name, lenp);
const int status = nc_inq_attlen(ncid, varid, name, lenp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s len = %d", ncid, varid, name, *lenp);
Message("ncid=%d varid=%d att=%s len=%d", ncid, varid, name, *lenp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -792,10 +789,10 @@ void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
{
int status = nc_inq_attname(ncid, varid, attnum, name);
const int status = nc_inq_attname(ncid, varid, attnum, name);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d attnum = %d att = %s", ncid, varid, attnum, name);
Message("ncid=%d varid=%d attnum=%d att=%s", ncid, varid, attnum, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -803,10 +800,10 @@ void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
{
int status = nc_inq_attid(ncid, varid, name, attnump);
const int status = nc_inq_attid(ncid, varid, name, attnump);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s", ncid, varid, name);
Message("ncid=%d varid=%d att=%s", ncid, varid, name);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -815,7 +812,7 @@ void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
#ifdef HAVE_NETCDF4
void cdf_def_var_chunking(int ncid, int varid, int storage, const size_t *chunksizesp)
{
int status = nc_def_var_chunking(ncid, varid, storage, chunksizesp);
const int status = nc_def_var_chunking(ncid, varid, storage, chunksizesp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
#endif
......
......@@ -10,6 +10,7 @@
#include "dmemory.h"
#include "cdi.h"
#include "cdi_int.h"
#include "stream_grb.h"
#include "stream_cdf.h"
#include "cdf_int.h"
#include "vlist.h"
......@@ -83,13 +84,13 @@ void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], s
Message("dim = %d start = %d count = %d", idim, start[idim], count[idim]);
}
//Scans the data array for missVals, optionally applying first a scale factor and then an offset.
//Returns the number of missing + out-of-range values encountered.
// Scans the data array for missVals, optionally applying first a scale factor and then an offset.
// Returns the number of missing + out-of-range values encountered.
static
size_t cdfDoInputDataTransformationDP(int vlistID, int varID, size_t valueCount, double *data)
{
double missVal = vlistInqVarMissval(vlistID, varID);
const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
const int haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
double validRange[2];
if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
......@@ -98,20 +99,20 @@ size_t cdfDoInputDataTransformationDP(int vlistID, int varID, size_t valueCount,
double offset = vlistInqVarAddoffset(vlistID, varID);
double scaleFactor = vlistInqVarScalefactor(vlistID, varID);
const bool haveOffset = IS_NOT_EQUAL(offset, 0);
const bool haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1);
const bool missValIsNaN = DBL_IS_NAN(missVal);
const int haveOffset = IS_NOT_EQUAL(offset, 0.0);
const int haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1.0);
size_t missValCount = 0;
if ( IS_EQUAL(validMin, VALIDMISS) ) validMin = DBL_MIN;
if ( IS_EQUAL(validMax, VALIDMISS) ) validMax = DBL_MAX;
bool haveRangeCheck = (IS_NOT_EQUAL(validMax, DBL_MAX)) | (IS_NOT_EQUAL(validMin,DBL_MIN));
const int haveRangeCheck = (IS_NOT_EQUAL(validMax, DBL_MAX)) | (IS_NOT_EQUAL(validMin, DBL_MIN));
assert(!haveRangeCheck || haveMissVal);
switch ((int)haveMissVal | ((int)haveScaleFactor << 1)
| ((int)haveOffset << 2) | ((int)haveRangeCheck << 3))
switch (haveMissVal | (haveScaleFactor << 1) | (haveOffset << 2) | (haveRangeCheck << 3))
{
case 15: /* haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset */
case 15: // haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -121,7 +122,7 @@ size_t cdfDoInputDataTransformationDP(int vlistID, int varID, size_t valueCount,
: isMissVal ? data[i] : data[i] * scaleFactor + offset;
}
break;
case 13: /* haveRangeCheck & haveMissVal & haveOffset */
case 13: // haveRangeCheck & haveMissVal & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -131,7 +132,7 @@ size_t cdfDoInputDataTransformationDP(int vlistID, int varID, size_t valueCount,
: isMissVal ? data[i] : data[i] + offset;
}
break;
case 11: /* haveRangeCheck & haveMissVal & haveScaleFactor */
case 11: // haveRangeCheck & haveMissVal & haveScaleFactor
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -141,7 +142,7 @@ size_t cdfDoInputDataTransformationDP(int vlistID, int varID, size_t valueCount,
: isMissVal ? data[i] : data[i] * scaleFactor;
}
break;
case 9: /* haveRangeCheck & haveMissVal */
case 9: // haveRangeCheck & haveMissVal
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -150,42 +151,50 @@ size_t cdfDoInputDataTransformationDP(int vlistID, int varID, size_t valueCount,
data[i] = outOfRange ? missVal : data[i];
}
break;
case 7: /* haveMissVal & haveScaleFactor & haveOffset */
case 7: // haveMissVal & haveScaleFactor & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
if ( DBL_IS_EQUAL(data[i], missVal) )
missValCount++;
else
data[i] = data[i] * scaleFactor + offset;
break;
case 6: /* haveOffset & haveScaleFactor */
case 6: // haveOffset & haveScaleFactor
for ( size_t i = 0; i < valueCount; i++ )
data[i] = data[i] * scaleFactor + offset;
break;
case 5: /* haveMissVal & haveOffset */
case 5: // haveMissVal & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
if ( DBL_IS_EQUAL(data[i], missVal) )
missValCount++;
else
data[i] += offset;
break;
case 4: /* haveOffset */
case 4: // haveOffset
for ( size_t i = 0; i < valueCount; i++ )
data[i] += offset;
break;
case 3: /* haveMissVal & haveScaleFactor */
case 3: // haveMissVal & haveScaleFactor
for ( size_t i = 0; i < valueCount; i++ )
if ( DBL_IS_EQUAL(data[i], missVal) )
missValCount++;
else
data[i] *= scaleFactor;
break;
case 2: /* haveScaleFactor */
case 2: // haveScaleFactor
for ( size_t i = 0; i < valueCount; i++ )
data[i] *= scaleFactor;
break;
case 1: /* haveMissVal */
case 1: // haveMissVal
if (missValIsNaN)
{
for ( size_t i = 0; i < valueCount; i++ )
missValCount += (size_t)DBL_IS_NAN(data[i]);
}
else
{
for ( size_t i = 0; i < valueCount; i++ )
missValCount += (unsigned)DBL_IS_EQUAL(data[i], missVal);
missValCount += (size_t)IS_EQUAL(data[i], missVal);
}
break;
}
......@@ -196,7 +205,7 @@ static
size_t cdfDoInputDataTransformationSP(int vlistID, int varID, size_t valueCount, float *data)
{
double missVal = vlistInqVarMissval(vlistID, varID);
const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
const int haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
double validRange[2];
if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
......@@ -205,20 +214,20 @@ size_t cdfDoInputDataTransformationSP(int vlistID, int varID, size_t valueCount,
double offset = vlistInqVarAddoffset(vlistID, varID);
double scaleFactor = vlistInqVarScalefactor(vlistID, varID);
const bool haveOffset = IS_NOT_EQUAL(offset, 0);
const bool haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1);
const bool missValIsNaN = DBL_IS_NAN(missVal);
const int haveOffset = IS_NOT_EQUAL(offset, 0.0);
const int haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1.0);
size_t missValCount = 0;
if ( IS_EQUAL(validMin, VALIDMISS) ) validMin = DBL_MIN;
if ( IS_EQUAL(validMax, VALIDMISS) ) validMax = DBL_MAX;
bool haveRangeCheck = (IS_NOT_EQUAL(validMax, DBL_MAX)) | (IS_NOT_EQUAL(validMin,DBL_MIN));
const int haveRangeCheck = (IS_NOT_EQUAL(validMax, DBL_MAX)) | (IS_NOT_EQUAL(validMin, DBL_MIN));
assert(!haveRangeCheck || haveMissVal);
switch ((int)haveMissVal | ((int)haveScaleFactor << 1)
| ((int)haveOffset << 2) | ((int)haveRangeCheck << 3))
switch (haveMissVal | (haveScaleFactor << 1) | (haveOffset << 2) | (haveRangeCheck << 3))
{
case 15: /* haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset */
case 15: // haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -228,7 +237,7 @@ size_t cdfDoInputDataTransformationSP(int vlistID, int varID, size_t valueCount,
: isMissVal ? data[i] : (float)(data[i] * scaleFactor + offset);
}
break;
case 13: /* haveRangeCheck & haveMissVal & haveOffset */
case 13: // haveRangeCheck & haveMissVal & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -238,7 +247,7 @@ size_t cdfDoInputDataTransformationSP(int vlistID, int varID, size_t valueCount,
: isMissVal ? data[i] : (float)(data[i] + offset);
}
break;
case 11: /* haveRangeCheck & haveMissVal & haveScaleFactor */
case 11: // haveRangeCheck & haveMissVal & haveScaleFactor
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -248,7 +257,7 @@ size_t cdfDoInputDataTransformationSP(int vlistID, int varID, size_t valueCount,
: isMissVal ? data[i] : (float)(data[i] * scaleFactor);
}
break;
case 9: /* haveRangeCheck & haveMissVal */
case 9: // haveRangeCheck & haveMissVal
for ( size_t i = 0; i < valueCount; i++ )
{
int outOfRange = data[i] < validMin || data[i] > validMax;
......@@ -257,42 +266,50 @@ size_t cdfDoInputDataTransformationSP(int vlistID, int varID, size_t valueCount,
data[i] = outOfRange ? (float)missVal : data[i];
}
break;
case 7: /* haveMissVal & haveScaleFactor & haveOffset */
case 7: // haveMissVal & haveScaleFactor & haveOffset
for ( size_t i = 0; i < valueCount; i++ )
if ( DBL_IS_EQUAL(data[i], missVal) )