Commit 768fba80 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

EXSE lib update

parent 23f64cf5
2009-12-29 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using EXSE library version 1.2.0
2009-12-15 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* fileRead: check result of fread
......
......@@ -112,7 +112,7 @@ void usage(void)
static
void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
int datasize, int nmiss, double missval, const double *data, int vardis)
int datasize, int number, int nmiss, double missval, const double *data, int vardis)
{
static int rec = 0;
int i, ivals = 0, imiss = 0;
......@@ -124,11 +124,11 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
if ( vardis )
fprintf(stdout,
" Rec : Date Time Varname Level Size Miss : Minimum Mean Maximum\n");
/* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+ */
/* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+ */
else
fprintf(stdout,
" Rec : Date Time Param Level Size Miss : Minimum Mean Maximum\n");
/* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+ */
/* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+ */
}
date2str(vdate, vdatestr, sizeof(vdatestr));
......@@ -139,6 +139,7 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
fprintf(stdout, "%7d ", datasize);
fprintf(stdout, "%7d :", nmiss);
/*
if ( gridtype == GRID_SPECTRAL )
{
......@@ -146,6 +147,7 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
}
else
*/
if ( number == CDI_REAL )
{
if ( nmiss > 0 )
{
......@@ -185,6 +187,31 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
if ( imiss != nmiss && nmiss > 0 )
fprintf(stdout, "Found %d of %d missing values!\n", imiss, nmiss);
}
else
{
int nvals_r = 0, nvals_i = 0;
double arrsum_r, arrsum_i, arrmean_r = 0, arrmean_i = 0;
arrsum_r = 0;
arrsum_i = 0;
for ( i = 0; i < datasize; i++ )
{
if ( !DBL_IS_EQUAL(data[i*2], missval) )
{
arrsum_r += data[i*2];
nvals_r++;
}
if ( !DBL_IS_EQUAL(data[i*2+1], missval) )
{
arrsum_i += data[i*2+1];
nvals_i++;
}
}
if ( nvals_r > 0 ) arrmean_r = arrsum_r / nvals_r;
if ( nvals_i > 0 ) arrmean_i = arrsum_i / nvals_i;
fprintf(stdout, " - (%#12.5g,%#12.5g) -\n", arrmean_r, arrmean_i);
}
}
......@@ -207,7 +234,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
char units[128];
double level;
char *modelptr, *instptr;
int prec;
int prec, number;
int year, month, day, hour, minute, second;
char pstr[4];
char paramstr[32];
......@@ -265,17 +292,27 @@ void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, "var ");
prec = vlistInqVarDatatype(vlistID, varID);
if ( prec == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( prec > 0 && prec <= 32 ) sprintf(pstr, "P%d", prec);
else if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "F32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "F64");
else if ( prec == DATATYPE_INT8 ) strcpy(pstr, "I8");
else if ( prec == DATATYPE_INT16 ) strcpy(pstr, "I16");
else if ( prec == DATATYPE_INT32 ) strcpy(pstr, "I32");
else if ( prec == DATATYPE_UINT8 ) strcpy(pstr, "U8");
else if ( prec == DATATYPE_UINT16 ) strcpy(pstr, "U16");
else if ( prec == DATATYPE_UINT32 ) strcpy(pstr, "U32");
else strcpy(pstr, "-1");
number = vlistInqVarNumber(vlistID, varID);
if ( number == CDI_REAL )
{
if ( prec == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( prec > 0 && prec <= 32 ) sprintf(pstr, "P%d", prec);
else if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "F32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "F64");
else if ( prec == DATATYPE_INT8 ) strcpy(pstr, "I8");
else if ( prec == DATATYPE_INT16 ) strcpy(pstr, "I16");
else if ( prec == DATATYPE_INT32 ) strcpy(pstr, "I32");
else if ( prec == DATATYPE_UINT8 ) strcpy(pstr, "U8");
else if ( prec == DATATYPE_UINT16 ) strcpy(pstr, "U16");
else if ( prec == DATATYPE_UINT32 ) strcpy(pstr, "U32");
else strcpy(pstr, "-1");
}
else
{
if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "C32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "C64");
else strcpy(pstr, "-2");
}
fprintf(stdout, " %-3s", pstr);
......@@ -746,7 +783,7 @@ int main(int argc, char *argv[])
int nrecs, nvars;
int levelID, levelsize;
int nts = 0;
int gridsize = 0;
int gridsize = 0, number;
int recID;
int tsID;
int ntsteps = 0;
......@@ -816,7 +853,8 @@ int main(int argc, char *argv[])
if ( otableID == CDI_UNDEFID ) otableID = itableID;
}
if ( vlistNumber(vlistID1) != CDI_REAL ) datasize *= 2;
data = (double *) malloc(datasize*sizeof(double));
/*
......@@ -873,9 +911,10 @@ int main(int argc, char *argv[])
gridsize = gridInqSize(gridID);
level = zaxisInqLevel(zaxisID, levelID);
missval = vlistInqVarMissval(vlistID1, varID);
number = vlistInqVarNumber(vlistID1, varID);
if ( Info )
printInfo(gridtype, vdate, vtime, varname, level, gridsize, nmiss, missval, data, Vardis);
printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
if ( fname2 )
{
......@@ -912,6 +951,7 @@ int main(int argc, char *argv[])
gridtype = gridInqType(gridID);
gridsize = gridInqSize(gridID);
missval = vlistInqVarMissval(vlistID1, varID);
number = vlistInqVarNumber(vlistID1, varID);
levelsize = zaxisInqSize(zaxisID);
for ( levelID = 0; levelID < levelsize; levelID++ )
......@@ -920,7 +960,7 @@ int main(int argc, char *argv[])
streamReadVarSlice(streamID1, varID, levelID, data, &nmiss);
if ( Info )
printInfo(gridtype, vdate, vtime, varname, level, gridsize, nmiss, missval, data, Vardis);
printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
if ( fname2 )
streamWriteVarSlice(streamID2, varID, levelID, data, nmiss);
......
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for cdi 1.4.1.
# Generated by GNU Autoconf 2.61 for cdi 1.4.2.
#
# Report bugs to <Uwe.Schulzweida@zmaw.de>.
#
......@@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='cdi'
PACKAGE_TARNAME='cdi'
PACKAGE_VERSION='1.4.1'
PACKAGE_STRING='cdi 1.4.1'
PACKAGE_VERSION='1.4.2'
PACKAGE_STRING='cdi 1.4.2'
PACKAGE_BUGREPORT='Uwe.Schulzweida@zmaw.de'
# Factoring default headers for most tests.
......@@ -1258,7 +1258,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures cdi 1.4.1 to adapt to many kinds of systems.
\`configure' configures cdi 1.4.2 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
......@@ -1329,7 +1329,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of cdi 1.4.1:";;
short | recursive ) echo "Configuration of cdi 1.4.2:";;
esac
cat <<\_ACEOF
......@@ -1462,7 +1462,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
cdi configure 1.4.1
cdi configure 1.4.2
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
......@@ -1476,7 +1476,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by cdi $as_me 1.4.1, which was
It was created by cdi $as_me 1.4.2, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
......@@ -2303,7 +2303,7 @@ fi
# Define the identity of the package.
PACKAGE='cdi'
VERSION='1.4.1'
VERSION='1.4.2'
cat >>confdefs.h <<_ACEOF
......@@ -9031,7 +9031,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by cdi $as_me 1.4.1, which was
This file was extended by cdi $as_me 1.4.2, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
......@@ -9084,7 +9084,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
cdi config.status 1.4.1
cdi config.status 1.4.2
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
......
# Process this file with autoconf to produce a configure script.
AC_INIT(cdi, 1.4.1, Uwe.Schulzweida@zmaw.de)
AC_INIT(cdi, 1.4.2, Uwe.Schulzweida@zmaw.de)
echo "configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}"
......
......@@ -16,6 +16,10 @@ extern "C" {
#define CDI_BIGENDIAN 0 /* Byte order BIGENDIAN */
#define CDI_LITTLEENDIAN 1 /* Byte order LITTLEENDIAN */
#define CDI_REAL 1 /* Real numbers */
#define CDI_COMP 2 /* Complex numbers */
#define CDI_BOTH 3 /* Both numbers */
/* Error identifier */
#define CDI_NOERR 0 /* No Error */
......@@ -297,6 +301,9 @@ void vlistMerge(int vlistID2, int vlistID1);
void vlistPrint(int vlistID);
/* vlistNumber: Number type in a variable list */
int vlistNumber(int vlistID);
/* vlistNvars: Number of variables in a variable list */
int vlistNvars(int vlistID);
......@@ -369,6 +376,12 @@ void vlistDefVarDatatype(int vlistID, int varID, int datatype);
/* vlistInqVarDatatype: Get the data type of a Variable */
int vlistInqVarDatatype(int vlistID, int varID);
/* vlistDefVarNumber: Define the number type of a Variable */
void vlistDefVarNumber(int vlistID, int varID, int number);
/* vlistInqVarNumber: Get the number type of a Variable */
int vlistInqVarNumber(int vlistID, int varID);
void vlistDefVarInstitut(int vlistID, int varID, int instID);
int vlistInqVarInstitut(int vlistID, int varID);
void vlistDefVarModel(int vlistID, int varID, int modelID);
......
#ifndef _EXTRA_H
#define _EXTRA_H
#define EXT_REAL 1
#define EXT_COMP 2
typedef struct {
int checked;
int byteswap;
int header[4];
int hprec; /* header precision */
int dprec; /* data precision */
int prec; /* single or double precison */
int number; /* real or complex */
size_t datasize;
size_t buffersize;
void *buffer;
}
EXTREC;
extrec_t;
const char *extLibraryVersion(void);
......@@ -21,18 +24,18 @@ void extDebug(int debug);
int extCheckFiletype(int fileID, int *swap);
EXTREC *extNew(void);
void extDelete(EXTREC *extp);
void *extNew(void);
void extDelete(void *ext);
int extRead(int fileID, EXTREC *extp);
int extWrite(int fileID, EXTREC *extp);
int extRead(int fileID, void *ext);
int extWrite(int fileID, void *ext);
int extInqHeader(EXTREC *extp, int *header);
int extInqDataSP(EXTREC *extp, float *data);
int extInqDataDP(EXTREC *extp, double *data);
int extInqHeader(void *ext, int *header);
int extInqDataSP(void *ext, float *data);
int extInqDataDP(void *ext, double *data);
int extDefHeader(EXTREC *extp, const int *header);
int extDefDataSP(EXTREC *extp, const float *data);
int extDefDataDP(EXTREC *extp, const double *data);
int extDefHeader(void *ext, const int *header);
int extDefDataSP(void *ext, const float *data);
int extDefDataDP(void *ext, const double *data);
#endif /* _EXTRA_H */
......@@ -16,15 +16,15 @@
#include "swap.h"
#define SINGLE_PRECISION 4
#define DOUBLE_PRECISION 8
#define SINGLE_PRECISION 4
#define DOUBLE_PRECISION 8
#define EXT_HEADER_LEN 4
#define EXT_HEADER_LEN 4
static int initExtLib = 0;
static int extDefaultHprec = 0;
static int extDefaultDprec = 0;
static int initExtLib = 0;
static int extDefaultPrec = 0;
static int extDefaultNumber = EXT_REAL;
/*
......@@ -32,7 +32,7 @@ static int extDefaultDprec = 0;
*/
#undef LIBVERSION
#define LIBVERSION 1.0.2
#define LIBVERSION 1.2.0
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
static const char ext_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__;
......@@ -67,33 +67,31 @@ void extLibInit()
envString = getenv(envName);
if ( envString )
{
int pos;
int nrun;
if ( strlen(envString) == 2 ) nrun = 1;
else nrun = 2;
int pos = 0;
pos = 0;
while ( nrun-- )
if ( strlen(envString) == 2 )
{
switch ( tolower((int) envString[pos]) )
{
case 'i':
case 'r':
{
extDefaultNumber = EXT_REAL;
switch ( (int) envString[pos+1] )
{
case '4': extDefaultHprec = SINGLE_PRECISION; break;
case '8': extDefaultHprec = DOUBLE_PRECISION; break;
case '4': extDefaultPrec = SINGLE_PRECISION; break;
case '8': extDefaultPrec = DOUBLE_PRECISION; break;
default:
Message(func, "Invalid digit in %s: %s", envName, envString);
}
break;
break;
}
case 'r':
case 'c':
{
extDefaultNumber = EXT_COMP;
switch ( (int) envString[pos+1] )
{
case '4': extDefaultDprec = SINGLE_PRECISION; break;
case '8': extDefaultDprec = DOUBLE_PRECISION; break;
case '4': extDefaultPrec = SINGLE_PRECISION; break;
case '8': extDefaultPrec = DOUBLE_PRECISION; break;
default:
Message(func, "Invalid digit in %s: %s", envName, envString);
}
......@@ -102,44 +100,44 @@ void extLibInit()
default:
Message(func, "Invalid character in %s: %s", envName, envString);
}
pos += 2;
}
}
initExtLib = 1;
}
void extInit(EXTREC *extp)
static
void extInit(extrec_t *extp)
{
extp->checked = 0;
extp->byteswap = 0;
extp->hprec = 0;
extp->dprec = 0;
extp->prec = 0;
extp->number = extDefaultNumber;
extp->datasize = 0;
extp->buffersize = 0;
extp->buffer = NULL;
}
EXTREC *extNew(void)
void *extNew(void)
{
static char func[] = "extNew";
EXTREC *extp;
extrec_t *extp;
if ( ! initExtLib ) extLibInit();
extp = (EXTREC *) malloc(sizeof(EXTREC));
extp = (extrec_t *) malloc(sizeof(extrec_t));
extInit(extp);
return (extp);
return ((void*)extp);
}
void extDelete(EXTREC *extp)
void extDelete(void *ext)
{
static char func[] = "extDelete";
extrec_t *extp = (extrec_t *) ext;
if ( extp )
{
......@@ -202,8 +200,8 @@ int extCheckFiletype(int fileID, int *swap)
fileRewind(fileID);
if ( data && dimxy*fact == data ) found = 1;
else if ( data && dimxy*8 == data ) found = 1;
if ( data && dimxy*fact == data ) found = 1;
else if ( data && dimxy*fact*2 == data ) found = 1;
if ( EXT_Debug )
{
......@@ -215,58 +213,56 @@ int extCheckFiletype(int fileID, int *swap)
}
int extInqHeader(EXTREC *extp, int *header)
int extInqHeader(void *ext, int *header)
{
static char func[] = "extInqHeader";
extrec_t *extp = (extrec_t *) ext;
size_t i;
for ( i = 0; i < EXT_HEADER_LEN; i++ )
header[i] = extp->header[i];
if ( EXT_Debug )
Message(func, "datasize = %lu", extp->datasize);
if ( EXT_Debug ) Message(func, "datasize = %lu", extp->datasize);
return (0);
}
int extDefHeader(EXTREC *extp, const int *header)
int extDefHeader(void *ext, const int *header)
{
static char func[] = "extDefHeader";
extrec_t *extp = (extrec_t *) ext;
size_t i;
for ( i = 0; i < EXT_HEADER_LEN; i++ )
extp->header[i] = header[i];
extp->datasize = header[3];
if ( extp->number == EXT_COMP ) extp->datasize *= 2;
if ( EXT_Debug )
Message(func, "datasize = %lu", extp->datasize);
if ( EXT_Debug ) Message(func, "datasize = %lu", extp->datasize);
return (0);
}
int extInqData(EXTREC *extp, int prec, void *data)
int extInqData(void *ext, int prec, void *data)
{
static char func[] = "extInqData";
extrec_t *extp = (extrec_t *) ext;
size_t datasize;
size_t i;
int ierr = 0;
int dprec;
int rprec, number;
void *buffer;
int byteswap = extp->byteswap;
datasize = extp->datasize;
buffer = extp->buffer;
rprec = extp->prec;
number = extp->number;
buffer = extp->buffer;
dprec = extp->dprec;
switch ( dprec )
switch ( rprec )
{
case SINGLE_PRECISION:
{
......@@ -274,10 +270,10 @@ int extInqData(EXTREC *extp, int prec, void *data)
{
if ( byteswap ) swap4byte(buffer, datasize);
if ( dprec == prec )
if ( rprec == prec )
memcpy(data, buffer, datasize*sizeof(FLT32));
else
for (i = 0; i < datasize; i++)
for ( i = 0; i < datasize; ++i )
((double *) data)[i] = (double) ((float *) buffer)[i];
}
else
......@@ -291,10 +287,10 @@ int extInqData(EXTREC *extp, int prec, void *data)
{
if ( byteswap ) swap8byte(buffer, datasize);
if ( dprec == prec )
if ( rprec == prec )
memcpy(data, buffer, datasize*sizeof(FLT64));
else
for (i = 0; i < datasize; i++)
for ( i = 0; i < datasize; ++i )
((float *) data)[i] = (float) ((double *) buffer)[i];
}
else
......@@ -304,7 +300,7 @@ int extInqData(EXTREC *extp, int prec, void *data)
break;
default:
{
Error(func, "unexpected data precision %d", dprec);
Error(func, "unexpected data precision %d", rprec);
}
}
......@@ -312,48 +308,42 @@ int extInqData(EXTREC *extp, int prec, void *data)
}
int extInqDataSP(EXTREC *extp, float *data)
int extInqDataSP(void *ext, float *data)
{
return (extInqData(extp, SINGLE_PRECISION, (void *) data));
return (extInqData(ext, SINGLE_PRECISION, (void *) data));
}
int extInqDataDP(EXTREC *extp, double *data)
int extInqDataDP(void *ext, double *data)
{
return (extInqData(extp, DOUBLE_PRECISION, (void *) data));
return (extInqData(ext, DOUBLE_PRECISION, (void *) data));
}
int extDefData(EXTREC *extp, int prec, const void *data)
int extDefData(void *ext, int prec, const void *data)
{
static char func[] = "extDefData";
extrec_t *extp = (extrec_t *) ext;
size_t datasize;
size_t blocklen;
size_t buffersize;
size_t i;
int dprec, hprec;
int rprec;
int *header;
void *buffer;
if ( extDefaultPrec ) rprec = extDefaultPrec;
else rprec = extp->prec;