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

cgribexlib update

parent 0405a790
/* Automatically generated by m214003 at 2015-02-22, do not edit */
/* Automatically generated by m214003 at 2015-03-04, do not edit */
/* CGRIBEXLIB_VERSION="1.7.1" */
......@@ -133,7 +133,7 @@
double intpow2(int x);
int gribrec_len(int b1, int b2, int b3);
int gribrec_len(unsigned b1, unsigned b2, unsigned b3);
int correct_bdslen(int bdslen, long recsize, long gribpos);
/* CDI converter routines */
......@@ -678,12 +678,22 @@ gcc -g -Wall -O3 -march=native -std=c99 -DTEST_MINMAXVAL -fopenmp -DOMP_SIMD min
simd : fmin: -500000 fmax: 499999 time: 3.10s # omp simd in gcc 4.9
avx : fmin: -500000 fmax: 499999 time: 2.84s
icc -g -Wall -O3 -march=native -std=c99 -vec-report=1 -DTEST_MINMAXVAL -openmp -DOMP_SIMD minmax_val.c
icc -g -Wall -O3 -march=native -std=c99 -qopt-report=5 -DTEST_MINMAXVAL -openmp -DOMP_SIMD minmax_val.c
result on thunder5 (icc 14.0.2):
orig : fmin: -500000 fmax: 499999 time: 2.83s
simd : fmin: -500000 fmax: 499999 time: 2.83s
avx : fmin: -500000 fmax: 499999 time: 2.92s
icc -g -Wall -O3 -march=native -std=c99 -qopt-report=5 -DTEST_MINMAXVAL -openmp -DOMP_SIMD minmax_val.c
result on hama (icc 15.0.1):
float:
minmax_val: fmin: -500000 fmax: 499999 time: 0.60s
double:
minmax_val: fmin: -500000 fmax: 499999 time: 3.06s
orig : fmin: -500000 fmax: 499999 time: 2.66s
simd : fmin: -500000 fmax: 499999 time: 6.65s
avx : fmin: -500000 fmax: 499999 time: 3.11s
xlc_r -g -O3 -qhot -q64 -qarch=auto -qtune=auto -qreport -DTEST_MINMAXVAL minmax_val.c
result on blizzard (xlc 12):
orig : fmin: -500000 fmax: 499999 time: 7.26s
......@@ -977,6 +987,8 @@ void pwr6_minmax_val_double_unrolled6(const double *restrict data, long idatasiz
#if defined(TEST_MINMAXVAL) && defined(__GNUC__)
static
void minmax_val_double_orig(const double *restrict data, long idatasize, double *fmin, double *fmax) __attribute__ ((noinline));
static
void minmax_val_double_simd(const double *restrict data, long idatasize, double *fmin, double *fmax) __attribute__ ((noinline));
#endif
#if defined(GNUC_PUSH_POP)
......@@ -1041,10 +1053,8 @@ void minmax_val_float(const float *restrict data, long idatasize, float *fmin, f
// TEST
#if defined(OMP_SIMD)
//#pragma omp declare reduction(xmin : double : omp_out = omp:in > omp_out ? omp_out : omp_in)
// initializer( omp_priv = { largenumber })
//#pragma omp declare reduction(xmax : double : omp_out = omp:in < omp_out ? omp_out : omp_in)
// initializer( omp_priv = { -largenumber })
//#pragma omp declare reduction(xmin : double : omp_out = omp_in > omp_out ? omp_out : omp_in) initializer( omp_priv = { 1.e300 })
//#pragma omp declare reduction(xmax : double : omp_out = omp_in < omp_out ? omp_out : omp_in) initializer( omp_priv = { -1.e300 })
#if defined(GNUC_PUSH_POP)
#pragma GCC push_options
......@@ -1254,7 +1264,7 @@ int main(void)
for ( int i = 0; i < NRUN; ++i )
{
fmin = fmax = data_dp[0];
avx_minmax_double_val(data_dp, datasize, &fmin, &fmax);
avx_minmax_val_double(data_dp, datasize, &fmin, &fmax);
}
t_end = dtime();
printf("avx : fmin: %ld fmax: %ld time: %6.2fs\n", (long)fmin, (long) fmax, t_end-t_begin);
......@@ -4244,9 +4254,7 @@ void gribPrintSec4Wave(int *isec4)
int gribOpen(const char *filename, const char *mode)
{
int fileID;
fileID = fileOpen(filename, mode);
int fileID = fileOpen(filename, mode);
#if defined (__sun)
if ( fileID != FILE_UNDEFID && tolower(*mode) == 'r' )
......@@ -4255,7 +4263,7 @@ int gribOpen(const char *filename, const char *mode)
}
#endif
return (fileID);
return fileID;
}
......@@ -4267,17 +4275,16 @@ void gribClose(int fileID)
off_t gribGetPos(int fileID)
{
return (fileGetPos(fileID));
return fileGetPos(fileID);
}
int gribCheckFiletype(int fileID)
{
int ierr;
int found = 0;
char buffer[4];
if ( fileRead(fileID, buffer, 4) != 4 ) return(found);
if ( fileRead(fileID, buffer, 4) != 4 ) return found;
if ( memcmp(buffer, "GRIB", 4) == 0 )
{
......@@ -4287,8 +4294,7 @@ int gribCheckFiletype(int fileID)
else
{
long offset;
ierr = gribFileSeek(fileID, &offset);
int ierr = gribFileSeek(fileID, &offset);
fileRewind(fileID);
if ( !ierr )
{
......@@ -4297,25 +4303,23 @@ int gribCheckFiletype(int fileID)
}
}
return (found);
return found;
}
int gribCheckSeek(int fileID, long *offset, int *version)
{
int ierr;
char buffer[4];
ierr = gribFileSeek(fileID, offset);
int ierr = gribFileSeek(fileID, offset);
*version = -1;
if ( !ierr )
{
if ( fileRead(fileID, buffer, 4) == 4 )
char buffer[4];
if ( fileRead(fileID, buffer, 4) == 4 )
*version = buffer[3];
}
return (ierr);
return ierr;
}
......@@ -4327,11 +4331,10 @@ int gribFileSeekOld(int fileID, long *offset)
unsigned char buffer[4096];
int retry = 4096;
int i;
void *fileptr;
*offset = 0;
fileptr = filePtr(fileID);
void *fileptr = filePtr(fileID);
ch = filePtrGetc(fileptr); if ( ch == EOF ) return (-1); buffer[0] = ch;
ch = filePtrGetc(fileptr); if ( ch == EOF ) return (-1); buffer[1] = ch;
......@@ -4366,10 +4369,9 @@ int gribFileSeekOld(int fileID, long *offset)
buffer[3] = buffer[i+3];
}
if ( CGRIBEX_Debug )
Message("record offset = %d", (int) *offset);
if ( CGRIBEX_Debug ) Message("record offset = %d", (int) *offset);
return (1);
return 1;
}
......@@ -4380,11 +4382,10 @@ int gribFileSeek(int fileID, long *offset)
long code = 0;
int ch;
int retry = 4096*4096;
void *fileptr;
*offset = 0;
fileptr = filePtr(fileID);
void *fileptr = filePtr(fileID);
while ( retry-- )
{
......@@ -4403,10 +4404,9 @@ int gribFileSeek(int fileID, long *offset)
(*offset)++;
}
if ( CGRIBEX_Debug )
Message("record offset = %d", (int) *offset);
if ( CGRIBEX_Debug ) Message("record offset = %d", (int) *offset);
return (1);
return 1;
}
......@@ -4420,12 +4420,11 @@ int gribFileSeekTest(int fileID, long *offset)
const int buffersize = 8;
unsigned char buffer[8];
int retry = 4096*4096;
void *fileptr;
int nread = 0;
*offset = 0;
fileptr = filePtr(fileID);
void *fileptr = filePtr(fileID);
while ( retry-- )
{
......@@ -4453,43 +4452,24 @@ int gribFileSeekTest(int fileID, long *offset)
(*offset)++;
}
if ( CGRIBEX_Debug )
Message("record offset = %d", (int) *offset);
if ( CGRIBEX_Debug ) Message("record offset = %d", (int) *offset);
return (1);
return 1;
}
int gribReadSize(int fileID)
{
int gribversion, gribsize;
int b1, b2, b3;
off_t pos;
void *fileptr;
/*
const int buffersize = 4;
unsigned char buffer[4];
*/
fileptr = filePtr(fileID);
void *fileptr = filePtr(fileID);
off_t pos = fileGetPos(fileID);
pos = fileGetPos(fileID);
/* bug: order of functions calls!
gribsize = (filePtrGetc(fileptr) << 16) + (filePtrGetc(fileptr) << 8) + filePtrGetc(fileptr);
*/
b1 = filePtrGetc(fileptr);
b2 = filePtrGetc(fileptr);
b3 = filePtrGetc(fileptr);
// gribsize = (b1 << 16) + (b2 << 8) + b3;
gribsize = gribrec_len(b1, b2, b3);
gribversion = filePtrGetc(fileptr);
/*
filePtrRead(fileptr, buffer, buffersize);
unsigned b1 = (unsigned) filePtrGetc(fileptr);
unsigned b2 = (unsigned) filePtrGetc(fileptr);
unsigned b3 = (unsigned) filePtrGetc(fileptr);
gribsize = (buffer[0] << 16) + (buffer[1] << 8) + buffer[2];
int gribsize = gribrec_len(b1, b2, b3);
int gribversion = filePtrGetc(fileptr);
gribversion = buffer[3];
*/
if ( gribsize == 24 )
{
if ( gribversion != 1 && gribversion != 2 ) gribversion = 0;
......@@ -4597,84 +4577,70 @@ int gribReadSize(int fileID)
fileSetPos(fileID, pos, SEEK_SET);
return (gribsize);
return gribsize;
}
int gribGetSize(int fileID)
{
int recsize;
long offset;
int ierr;
ierr = gribFileSeek(fileID, &offset); /* position file pointer after GRIB */
int ierr = gribFileSeek(fileID, &offset); /* position file pointer after GRIB */
if ( ierr > 0 )
{
Warning("GRIB record not found!");
return (0);
}
if ( ierr == -1 )
return (0);
else if ( ierr == 1 )
return (0);
if ( ierr == -1 ) return 0;
else if ( ierr == 1 ) return 0;
recsize = gribReadSize(fileID);
int recSize = gribReadSize(fileID);
if ( CGRIBEX_Debug ) Message("recsize = %d", recsize);
if ( CGRIBEX_Debug ) Message("recsize = %d", recSize);
fileSetPos(fileID, (off_t) -4, SEEK_CUR);
return (recsize);
return recSize;
}
int gribRead(int fileID, unsigned char *buffer, size_t *buffersize)
{
long offset;
int ierr = 0;
size_t nread, recsize, recsize0;
ierr = gribFileSeek(fileID, &offset); /* position file pointer after GRIB */
int ierr = gribFileSeek(fileID, &offset); /* position file pointer after GRIB */
if ( ierr > 0 )
{
Warning("GRIB record not found!");
return (-2);
}
if ( ierr == -1 )
{
*buffersize = 0;
return (-1);
}
else if ( ierr == 1 )
if ( ierr == -1 ) { *buffersize = 0; return -1; }
else if ( ierr == 1 ) { *buffersize = 0; return -2; }
size_t recSize = gribReadSize(fileID);
size_t readSize = recSize;
if ( readSize > *buffersize )
{
*buffersize = 0;
return (-2);
readSize = *buffersize;
ierr = -3; // Tell the caller that the buffer was insufficient.
}
recsize = gribReadSize(fileID);
*buffersize = recSize; // Inform the caller about the record size.
// Write the stuff to the buffer that has already been read in gribFileSeek().
buffer[0] = 'G';
buffer[1] = 'R';
buffer[2] = 'I';
buffer[3] = 'B';
recsize0 = recsize;
if ( recsize > *buffersize )
{
recsize = *buffersize;
ierr = -3;
}
*buffersize = recsize0;
readSize -= 4;
// Read the rest of the record into the buffer.
size_t nread = fileRead(fileID, &buffer[4], readSize);
nread = fileRead(fileID, &buffer[4], recsize-4);
if ( nread != readSize ) ierr = 1;
if ( nread != recsize-4 ) ierr = 1;
return (ierr);
return ierr;
}
......@@ -4682,30 +4648,31 @@ int gribWrite(int fileID, unsigned char *buffer, size_t buffersize)
{
int nwrite = 0;
if( (nwrite = fileWrite(fileID, buffer, buffersize)) != (int) buffersize )
if ( (nwrite = fileWrite(fileID, buffer, buffersize)) != (int) buffersize )
{
perror(__func__);
nwrite = -1;
}
return ((int) nwrite);
return nwrite;
}
int gribrec_len(int b1, int b2, int b3)
int gribrec_len(unsigned b1, unsigned b2, unsigned b3)
{
int gribsize;
gribsize = (1-(int) ((unsigned) (b1&128) >> 6)) * (int) (((b1&127) << 16)+(b2<<8) + b3);
/*
If count is negative, have to rescale by factor of -120.
If bit 7 of b1 is set, we have to rescale by factor of 120.
This is a fixup to get round the restriction on product lengths
due to the count being only 24 bits. It is only possible because
the (default) rounding for GRIB products is 120 bytes.
*/
if ( gribsize < 0 ) gribsize *= (-120);
int needRescaling = b1 & (1 << 7);
int gribsize = (((b1&127) << 16)+(b2<<8) + b3);
return (gribsize);
if ( needRescaling ) gribsize *= 120;
return gribsize;
}
#include <stdlib.h>
......@@ -6969,6 +6936,10 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
}
#else
UNUSED(sbuf);
UNUSED(sbufsize);
if ( libszwarn )
{
Warning("Compression disabled, szlib or libaec not available!");
......@@ -7238,6 +7209,12 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
*/
}
#else
UNUSED(bds_nbits);
UNUSED(sourceLen);
UNUSED(source);
UNUSED(bdsLen);
UNUSED(dest);
if ( libszwarn )
{
Warning("Decompression disabled, szlib or libaec not available!");
......@@ -14220,7 +14197,7 @@ void encode_dummy(void)
(void) encode_array_unrolled_double(0, 0, 0, NULL, NULL, 0, 0, NULL);
(void) encode_array_unrolled_float(0, 0, 0, NULL, NULL, 0, 0, NULL);
}
static const char grb_libvers[] = "1.7.1" " of ""Feb 22 2015"" ""11:10:55";
static const char grb_libvers[] = "1.7.1" " of ""Mar 4 2015"" ""13:33:34";
const char *
cgribexLibraryVersion(void)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment