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

EXSE library update to 1.4.1

parent 12c81616
2018-11-08 Uwe Schulzweida
* using EXSE library version 1.4.1
* Version 1.9.6 released
2018-09-13 Uwe Schulzweida
......
......@@ -26,7 +26,7 @@ static int extDefaultNumber = EXT_REAL;
* A version string.
*/
#undef LIBVERSION
#define LIBVERSION 1.4.0
#define LIBVERSION 1.4.1
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
static const char ext_libvers[] = STRING(LIBVERSION);
......@@ -43,9 +43,7 @@ static int EXT_Debug = 0; /* If set to 1, debugging */
void extDebug(int debug)
{
EXT_Debug = debug;
if ( EXT_Debug )
Message("debug level %d", debug);
if (EXT_Debug) Message("debug level %d", debug);
}
......@@ -141,10 +139,9 @@ int extCheckFiletype(int fileID, int *swap)
size_t fact = 0;
size_t data = 0;
size_t dimxy = 0;
int found = 0;
unsigned char buffer[40], *pbuf;
if ( fileRead(fileID, buffer, 4) != 4 ) return found;
if ( fileRead(fileID, buffer, 4) != 4 ) return 0;
size_t blocklen = (size_t) get_UINT32(buffer);
size_t sblocklen = (size_t) get_SUINT32(buffer);
......@@ -156,7 +153,7 @@ int extCheckFiletype(int fileID, int *swap)
{
*swap = 0;
fact = blocklen/4;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return found;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return 0;
pbuf = buffer+3*fact; dimxy = (size_t) get_UINT32(pbuf);
pbuf = buffer+blocklen+4; data = (size_t) get_UINT32(pbuf);
}
......@@ -164,7 +161,7 @@ int extCheckFiletype(int fileID, int *swap)
{
*swap = 0;
fact = blocklen/4;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return found;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return 0;
pbuf = buffer+3*fact; dimxy = (size_t) get_UINT64(pbuf);
pbuf = buffer+blocklen+4; data = (size_t) get_UINT32(pbuf);
}
......@@ -172,7 +169,7 @@ int extCheckFiletype(int fileID, int *swap)
{
*swap = 1;
fact = sblocklen/4;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return found;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return 0;
pbuf = buffer+3*fact; dimxy = (size_t) get_SUINT32(pbuf);
pbuf = buffer+sblocklen+4; data = (size_t) get_SUINT32(pbuf);
}
......@@ -180,22 +177,20 @@ int extCheckFiletype(int fileID, int *swap)
{
*swap = 1;
fact = sblocklen/4;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return found;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return 0;
pbuf = buffer+3*fact; dimxy = (size_t) get_SUINT64(pbuf);
pbuf = buffer+sblocklen+4; data = (size_t) get_SUINT32(pbuf);
}
fileRewind(fileID);
if ( data && dimxy*fact == data ) found = 1;
else if ( data && dimxy*fact*2 == data ) found = 1;
if ( EXT_Debug )
{
Message("swap = %d fact = %d", *swap, fact);
Message("dimxy = %lu data = %lu", dimxy, data);
}
int found = data && (dimxy*fact == data || dimxy*fact*2 == data);
return found;
}
......@@ -204,8 +199,7 @@ int extInqHeader(void *ext, int *header)
{
extrec_t *extp = (extrec_t *) ext;
for ( size_t i = 0; i < EXT_HEADER_LEN; i++ )
header[i] = extp->header[i];
for (size_t i = 0; i < EXT_HEADER_LEN; i++) header[i] = extp->header[i];
if ( EXT_Debug ) Message("datasize = %lu", extp->datasize);
......@@ -217,13 +211,12 @@ int extDefHeader(void *ext, const int *header)
{
extrec_t *extp = (extrec_t *) ext;
for ( size_t i = 0; i < EXT_HEADER_LEN; i++ )
extp->header[i] = header[i];
for (size_t i = 0; i < EXT_HEADER_LEN; i++) extp->header[i] = header[i];
extp->datasize = (size_t)header[3];
if ( extp->number == EXT_COMP ) extp->datasize *= 2;
if ( EXT_Debug ) Message("datasize = %lu", extp->datasize);
if (EXT_Debug) Message("datasize = %lu", extp->datasize);
return 0;
}
......@@ -231,7 +224,6 @@ int extDefHeader(void *ext, const int *header)
static
int extInqData(extrec_t *extp, int prec, void *data)
{
size_t i;
int ierr = 0;
int byteswap = extp->byteswap;
size_t datasize = extp->datasize;
......@@ -249,7 +241,7 @@ int extInqData(extrec_t *extp, int prec, void *data)
if ( rprec == prec )
memcpy(data, buffer, datasize*sizeof(FLT32));
else
for ( i = 0; i < datasize; ++i )
for (size_t i = 0; i < datasize; ++i)
((double *) data)[i] = (double) ((float *) buffer)[i];
}
else
......@@ -266,7 +258,7 @@ int extInqData(extrec_t *extp, int prec, void *data)
if ( rprec == prec )
memcpy(data, buffer, datasize*sizeof(FLT64));
else
for ( i = 0; i < datasize; ++i )
for (size_t i = 0; i < datasize; ++i)
((float *) data)[i] = (float) ((double *) buffer)[i];
}
else
......@@ -300,16 +292,9 @@ int extInqDataDP(void *ext, double *data)
static int extDefData(void *ext, int prec, const void *data)
{
extrec_t *extp = (extrec_t *) ext;
size_t i;
int rprec;
void *buffer;
if ( extDefaultPrec ) rprec = extDefaultPrec;
else rprec = extp->prec;
if ( ! rprec ) rprec = prec;
extp->prec = rprec;
int rprec = extDefaultPrec ? extDefaultPrec : extp->prec;
extp->prec = rprec ? rprec : prec;
int *header = extp->header;
......@@ -319,18 +304,16 @@ static int extDefData(void *ext, int prec, const void *data)
extp->datasize = datasize;
void *buffer = extp->buffer;
size_t buffersize = extp->buffersize;
if ( buffersize != blocklen )
{
buffersize = blocklen;
buffer = extp->buffer;
buffer = Realloc(buffer, buffersize);
extp->buffer = buffer;
extp->buffersize = buffersize;
}
else
buffer = extp->buffer;
switch ( rprec )
{
......@@ -339,7 +322,7 @@ static int extDefData(void *ext, int prec, const void *data)
if ( rprec == prec )
memcpy(buffer, data, datasize*sizeof(FLT32));
else
for ( i = 0; i < datasize; i++ )
for (size_t i = 0; i < datasize; i++)
((float *) buffer)[i] = (float) ((double *) data)[i];
break;
......@@ -349,7 +332,7 @@ static int extDefData(void *ext, int prec, const void *data)
if ( rprec == prec )
memcpy(buffer, data, datasize*sizeof(FLT64));
else
for ( i = 0; i < datasize; i++ )
for (size_t i = 0; i < datasize; i++)
((double *) buffer)[i] = (double) ((float *) data)[i];
break;
......@@ -380,8 +363,6 @@ int extDefDataDP(void *ext, const double *data)
int extRead(int fileID, void *ext)
{
extrec_t *extp = (extrec_t *) ext;
size_t i;
void *buffer;
int status;
if ( ! extp->checked )
......@@ -398,8 +379,7 @@ int extRead(int fileID, void *ext)
if ( fileEOF(fileID) ) return -1;
if ( EXT_Debug )
Message("blocklen = %lu", blocklen);
if ( EXT_Debug ) Message("blocklen = %lu", blocklen);
size_t hprec = blocklen / EXT_HEADER_LEN;
......@@ -412,7 +392,7 @@ int extRead(int fileID, void *ext)
INT32 tempheader[4];
binReadInt32(fileID, byteswap, EXT_HEADER_LEN, tempheader);
for ( i = 0; i < EXT_HEADER_LEN; i++ )
for (size_t i = 0; i < EXT_HEADER_LEN; i++)
extp->header[i] = (int)tempheader[i];
break;
......@@ -422,7 +402,7 @@ int extRead(int fileID, void *ext)
INT64 tempheader[4];
binReadInt64(fileID, byteswap, EXT_HEADER_LEN, tempheader);
for ( i = 0; i < EXT_HEADER_LEN; i++ )
for (size_t i = 0; i < EXT_HEADER_LEN; i++)
extp->header[i] = (int)tempheader[i];
break;
......@@ -448,18 +428,16 @@ int extRead(int fileID, void *ext)
blocklen = binReadF77Block(fileID, byteswap);
void *buffer = extp->buffer;
size_t buffersize = (size_t)extp->buffersize;
if ( buffersize < blocklen )
{
buffersize = blocklen;
buffer = extp->buffer;
buffer = Realloc(buffer, buffersize);
extp->buffer = buffer;
extp->buffersize = buffersize;
}
else
buffer = extp->buffer;
size_t dprec = blocklen / extp->datasize;
......@@ -497,7 +475,6 @@ int extRead(int fileID, void *ext)
int extWrite(int fileID, void *ext)
{
extrec_t *extp = (extrec_t *) ext;
size_t i;
union { INT32 i32[EXT_HEADER_LEN]; INT64 i64[EXT_HEADER_LEN]; } tempheader;
int byteswap = extp->byteswap;
int rprec = extp->prec;
......@@ -513,7 +490,7 @@ int extWrite(int fileID, void *ext)
{
case EXSE_SINGLE_PRECISION:
{
for ( i = 0; i < EXT_HEADER_LEN; i++ )
for (size_t i = 0; i < EXT_HEADER_LEN; i++)
tempheader.i32[i] = (INT32) header[i];
binWriteInt32(fileID, byteswap, EXT_HEADER_LEN, tempheader.i32);
......@@ -522,7 +499,7 @@ int extWrite(int fileID, void *ext)
}
case EXSE_DOUBLE_PRECISION:
{
for ( i = 0; i < EXT_HEADER_LEN; i++ )
for (size_t i = 0; i < EXT_HEADER_LEN; i++)
tempheader.i64[i] = (INT64) header[i];
binWriteInt64(fileID, byteswap, EXT_HEADER_LEN, tempheader.i64);
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -24,7 +20,7 @@ static int iegDefaultDprec = 0;
* A version string.
*/
#undef LIBVERSION
#define LIBVERSION 1.4.0
#define LIBVERSION 1.4.1
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
static const char ieg_libvers[] = STRING(LIBVERSION);
......@@ -80,9 +76,7 @@ void iegLibInit(void)
void iegDebug(int debug)
{
IEG_Debug = debug;
if ( IEG_Debug )
Message("debug level %d", debug);
if (IEG_Debug) Message("debug level %d", debug);
}
static
......@@ -145,8 +139,7 @@ int iegCheckFiletype(int fileID, int *swap)
size_t blocklen = get_UINT32(buffer);
size_t sblocklen = get_SUINT32(buffer);
if ( IEG_Debug )
Message("blocklen = %d sblocklen = %d", blocklen, sblocklen);
if ( IEG_Debug ) Message("blocklen = %d sblocklen = %d", blocklen, sblocklen);
if ( blocklen == 636 || blocklen == 640 )
{
......@@ -187,14 +180,13 @@ int iegCheckFiletype(int fileID, int *swap)
fileRewind(fileID);
int found = data && (dimx*dimy*fact == data || dimx*dimy*8 == data);
if ( IEG_Debug )
{
Message("swap = %d fact = %d", *swap, fact);
Message("dimx = %lu dimy = %lu data = %lu", dimx, dimy, data);
}
int found = data && (dimx*dimy*fact == data || dimx*dimy*8 == data);
return found;
}
......@@ -237,8 +229,7 @@ int iegInqData(void *ieg, int prec, void *data)
{
const float *restrict p = (float *)buffer;
double *restrict q = (double *)data;
for ( size_t i = 0; i < datasize; i++)
q[i] = p[i];
for (size_t i = 0; i < datasize; i++) q[i] = p[i];
}
}
else
......@@ -258,8 +249,7 @@ int iegInqData(void *ieg, int prec, void *data)
{
const double *restrict p = (double *)buffer;
float *restrict q = (float *)data;
for ( size_t i = 0; i < datasize; i++)
q[i] = (float)p[i];
for (size_t i = 0; i < datasize; i++) q[i] = (float)p[i];
}
}
else
......@@ -294,17 +284,15 @@ static int
iegDefData(iegrec_t *iegp, int prec, const void *data)
{
int dprec = iegDefaultDprec ? iegDefaultDprec : iegp->dprec;
iegp->dprec = dprec = dprec ? dprec : prec;
iegp->dprec = dprec ? dprec : prec;
size_t datasize = (size_t)IEG_G_NumLon(iegp->igdb) * (size_t)IEG_G_NumLat(iegp->igdb);
size_t blocklen = datasize * (size_t)dprec;
iegp->datasize = datasize;
size_t buffersize = iegp->buffersize;
void *buffer = iegp->buffer;
size_t buffersize = iegp->buffersize;
if ( buffersize != blocklen )
{
buffersize = blocklen;
......@@ -323,8 +311,7 @@ iegDefData(iegrec_t *iegp, int prec, const void *data)
{
const double *restrict p = (const double *)data;
float *restrict q = (float *)buffer;
for (size_t i = 0; i < datasize; i++)
q[i] = (float)p[i];
for (size_t i = 0; i < datasize; i++) q[i] = (float)p[i];
}
break;
}
......@@ -336,8 +323,7 @@ iegDefData(iegrec_t *iegp, int prec, const void *data)
{
const float *restrict p = (const float *)data;
double *restrict q = (double *)buffer;
for ( size_t i = 0; i < datasize; i++)
q[i] = p[i];
for ( size_t i = 0; i < datasize; i++) q[i] = p[i];
}
break;
}
......@@ -436,20 +422,6 @@ int iegRead(int fileID, void *ieg)
iegp->vct[i] = buf.d[i];
}
/*
fprintf(stderr, "refval %g\n", iegp->refval);
for ( size_t i = 0; i < 100; i++ )
fprintf(stderr, "%3d %g\n", i, iegp->vct[i]);
{
int i;
for ( size_t i = 0; i < 37; i++ )
fprintf(stderr, "pdb: %d %d\n", i, iegp->ipdb[i]);
for ( size_t i = 0; i < 22; i++ )
fprintf(stderr, "gdb: %d %d\n", i, iegp->igdb[i]);
}
*/
size_t blocklen2 = binReadF77Block(fileID, byteswap);
if ( blocklen2 != blocklen )
......@@ -461,12 +433,10 @@ int iegRead(int fileID, void *ieg)
size_t datasize = iegp->datasize
= (size_t)IEG_G_NumLon(iegp->igdb) * (size_t)IEG_G_NumLat(iegp->igdb);
if ( IEG_Debug )
Message("datasize = %lu", iegp->datasize);
if ( IEG_Debug ) Message("datasize = %lu", iegp->datasize);
blocklen = binReadF77Block(fileID, byteswap);
void *buffer = iegp->buffer;
if ( iegp->buffersize < blocklen )
{
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
......@@ -31,7 +27,7 @@ static int srvDefaultDprec = 0;
* A version string.
*/
#undef LIBVERSION
#define LIBVERSION 1.4.0
#define LIBVERSION 1.4.1
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
static const char srv_libvers[] = STRING(LIBVERSION);
......@@ -48,9 +44,7 @@ static int SRV_Debug = 0; /* If set to 1, debugging */
void srvDebug(int debug)
{
SRV_Debug = debug;
if ( SRV_Debug )
Message("debug level %d", debug);
if (SRV_Debug) Message("debug level %d", debug);
}
static
......@@ -145,10 +139,9 @@ int srvCheckFiletype(int fileID, int *swap)
size_t data = 0;
size_t dimx = 0, dimy = 0;
size_t fact = 0;
int found = 0;
unsigned char buffer[72], *pbuf;
if ( fileRead(fileID, buffer, 4) != 4 ) return found;
if ( fileRead(fileID, buffer, 4) != 4 ) return 0;
size_t blocklen = (size_t) get_UINT32(buffer);
size_t sblocklen = (size_t) get_SUINT32(buffer);
......@@ -160,7 +153,7 @@ int srvCheckFiletype(int fileID, int *swap)
{
*swap = 0;
fact = blocklen>>3;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return found;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return 0;
pbuf = buffer+4*fact; dimx = (size_t) get_UINT32(pbuf);
pbuf = buffer+5*fact; dimy = (size_t) get_UINT32(pbuf);
pbuf = buffer+blocklen+4; data = (size_t) get_UINT32(pbuf);
......@@ -169,7 +162,7 @@ int srvCheckFiletype(int fileID, int *swap)
{
*swap = 0;
fact = blocklen>>3;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return found;
if ( fileRead(fileID, buffer, blocklen+8) != blocklen+8 ) return 0;
pbuf = buffer+4*fact; dimx = (size_t) get_UINT64(pbuf);
pbuf = buffer+5*fact; dimy = (size_t) get_UINT64(pbuf);
pbuf = buffer+blocklen+4; data = (size_t) get_UINT32(pbuf);
......@@ -178,7 +171,7 @@ int srvCheckFiletype(int fileID, int *swap)
{
*swap = 1;
fact = sblocklen>>3;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return found;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return 0;
pbuf = buffer+4*fact; dimx = (size_t) get_SUINT32(pbuf);
pbuf = buffer+5*fact; dimy = (size_t) get_SUINT32(pbuf);
pbuf = buffer+sblocklen+4; data = (size_t) get_SUINT32(pbuf);
......@@ -187,7 +180,7 @@ int srvCheckFiletype(int fileID, int *swap)
{
*swap = 1;
fact = sblocklen>>3;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return found;
if ( fileRead(fileID, buffer, sblocklen+8) != sblocklen+8 ) return 0;
pbuf = buffer+4*fact; dimx = (size_t) get_SUINT64(pbuf);
pbuf = buffer+5*fact; dimy = (size_t) get_SUINT64(pbuf);
pbuf = buffer+sblocklen+4; data = (size_t) get_SUINT32(pbuf);
......@@ -195,15 +188,13 @@ int srvCheckFiletype(int fileID, int *swap)
fileRewind(fileID);
if ( data && dimx*dimy*fact == data ) found = 1;
else if ( data && dimx*dimy*8 == data ) found = 1;
if ( SRV_Debug )
{
Message("swap = %d fact = %d", *swap, fact);
Message("dimx = %lu dimy = %lu data = %lu", dimx, dimy, data);
}
int found = data && (dimx*dimy*fact == data || dimx*dimy*8 == data);
return found;
}
......@@ -212,11 +203,9 @@ int srvInqHeader(void *srv, int *header)
{
srvrec_t *srvp = (srvrec_t *) srv;
for ( size_t i = 0; i < SRV_HEADER_LEN; i++ )
header[i] = srvp->header[i];
for (size_t i = 0; i < SRV_HEADER_LEN; i++) header[i] = srvp->header[i];
if ( SRV_Debug )
Message("datasize = %lu", srvp->datasize);
if (SRV_Debug) Message("datasize = %lu", srvp->datasize);
return 0;
}
......@@ -226,13 +215,11 @@ int srvDefHeader(void *srv, const int *header)
{
srvrec_t *srvp = (srvrec_t *) srv;
for ( size_t i = 0; i < SRV_HEADER_LEN; i++ )
srvp->header[i] = header[i];
for (size_t i = 0; i < SRV_HEADER_LEN; i++) srvp->header[i] = header[i];
srvp->datasize = (size_t)(header[4] * header[5]);
if ( SRV_Debug )
Message("datasize = %lu", srvp->datasize);
if (SRV_Debug) Message("datasize = %lu", srvp->datasize);
return 0;
}
......@@ -240,7 +227,6 @@ int srvDefHeader(void *srv, const int *header)
static
int srvInqData(srvrec_t *srvp, int prec, void *data)
{
size_t i;
int ierr = 0;
int byteswap = srvp->byteswap;
size_t datasize = srvp->datasize;
......@@ -258,7 +244,7 @@ int srvInqData(srvrec_t *srvp, int prec, void *data)
if ( dprec == prec )
memcpy(data, buffer, datasize*sizeof(FLT32));
else
for ( i = 0; i < datasize; i++ )
for (size_t i = 0; i < datasize; i++)
((double *) data)[i] = (double) ((float *) buffer)[i];
}
else
......@@ -275,7 +261,7 @@ int srvInqData(srvrec_t *srvp, int prec, void *data)
if ( dprec == prec )
memcpy(data, buffer, datasize*sizeof(FLT64));
else
for ( i = 0; i < datasize; i++ )
for (size_t i = 0; i < datasize; i++)
((float *) data)[i] = (float) ((double *) buffer)[i];
}
else
......@@ -310,23 +296,12 @@ static int
srvDefData(void *srv, int prec, const void *data)
{
srvrec_t *srvp = (srvrec_t *) srv;
size_t i;
int dprec, hprec;
void *buffer;
if ( srvDefaultDprec ) dprec = srvDefaultDprec;
else dprec = srvp->dprec;
if ( ! dprec ) dprec = prec;
srvp->dprec = dprec;
int dprec = srvDefaultDprec ? srvDefaultDprec : srvp->dprec;
srvp->dprec = dprec ? dprec : prec;
if ( srvDefaultHprec ) hprec = srvDefaultHprec;
else hprec = srvp->hprec;
if ( ! hprec ) hprec = dprec;
srvp->hprec = hprec;
int hprec = srvDefaultHprec ? srvDefaultHprec : srvp->hprec;
srvp->hprec = hprec ? hprec : dprec;
int *header = srvp->header;
......@@ -335,18 +310,15 @@ srvDefData(void *srv, int prec, const void *data)
srvp->datasize = datasize;
void *buffer = srvp->buffer;
size_t buffersize = srvp->buffersize;
if ( buffersize != blocklen )
{
buffersize = blocklen;
buffer = srvp->buffer;
buffer = Realloc(buffer, buffersize);
srvp->buffer = buffer;
srvp->buffersize = buffersize;
}
else
buffer = srvp->buffer;
switch ( dprec )
{
......@@ -355,7 +327,7 @@ srvDefData(void *srv, int prec, const void *data)
if ( dprec == prec )
memcpy(buffer, data, datasize*sizeof(FLT32));
else
for ( i = 0; i < datasize; i++ )
for (size_t i = 0; i < datasize; i++)
((float *) buffer)[i] = (float) ((double *) data)[i];
break;
......@@ -365,7 +337,7 @@ srvDefData(void *srv, int prec, const void *data)
if ( dprec == prec )
memcpy(buffer, data, datasize*sizeof(FLT64));
else
for ( i = 0; i < datasize; i++ )
for (size_t i = 0; i < datasize; i++)
((double *) buffer)[i] = (double) ((float *) data)[i];
break;
......@@ -396,12 +368,10 @@ int srvDefDataDP(void *srv, const double *data)
int srvRead(int fileID, void *srv)
{
srvrec_t *srvp = (srvrec_t *) srv;
size_t i;
union {
INT32 i32[SRV_HEADER_LEN];
INT64 i64[SRV_HEADER_LEN];