Commit 10bb0003 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cgribexlib.c update.

parent c803868f
/* Automatically generated by m214003 at 2017-06-06, do not edit */
/* Automatically generated by m214003 at 2017-07-12, do not edit */
/* CGRIBEXLIB_VERSION="1.8.1" */
......@@ -12500,11 +12500,9 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
{
long z = *gribLen;
int exponent, mantissa;
long i;
int ival;
int pvoffset = 0xFF;
int gdslen = 32;
unsigned lonIncr, latIncr;
if ( ISEC2_GridType == GRIB1_GTYPE_LCC ) gdslen += 10;
......@@ -12566,12 +12564,7 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
ISEC2_GridType == GRIB1_GTYPE_GAUSSIAN ||
ISEC2_GridType == GRIB1_GTYPE_LATLON_ROT )
{
int numlon;
if ( ISEC2_Reduced )
numlon = 0xFFFF;
else
numlon = ISEC2_NumLon;
int numlon = ISEC2_Reduced ? 0xFFFF : ISEC2_NumLon;
Put2Byte(numlon); /* 6- 7 Number of Longitudes */
Put2Byte(ISEC2_NumLat); /* 8- 9 Number of Latitudes */
......@@ -12580,16 +12573,8 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
Put1Byte(ISEC2_ResFlag); /* 16 Resolution flag */
Put3Int(ISEC2_LastLat);
Put3Int(ISEC2_LastLon);
if ( ISEC2_ResFlag == 0 )
{
lonIncr = 0xFFFF;
latIncr = 0xFFFF;
}
else
{
lonIncr = (unsigned)ISEC2_LonIncr;
latIncr = (unsigned)ISEC2_LatIncr;
}
unsigned lonIncr = (ISEC2_ResFlag == 0) ? 0xFFFF : (unsigned)ISEC2_LonIncr;
unsigned latIncr = (ISEC2_ResFlag == 0) ? 0xFFFF : (unsigned)ISEC2_LatIncr;
Put2Byte(lonIncr); /* 23-24 i - direction increment */
if ( ISEC2_GridType == GRIB1_GTYPE_GAUSSIAN )
Put2Byte(ISEC2_NumPar); /* 25-26 Latitudes Pole->Equator */
......@@ -12614,13 +12599,13 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
#if defined (SX)
#pragma vdir novector /* vectorization gives wrong results on NEC */
#endif
for ( i = 0; i < ISEC2_NumVCP; ++i )
for ( long i = 0; i < ISEC2_NumVCP; ++i )
{
Put1Real((double)(fsec2[10+i]));
}
if ( ISEC2_Reduced )
for ( i = 0; i < ISEC2_NumLat; i++ ) Put2Byte(ISEC2_RowLon(i));
for ( long i = 0; i < ISEC2_NumLat; i++ ) Put2Byte(ISEC2_RowLon(i));
*gribLen = z;
}
......@@ -12629,32 +12614,23 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
static
void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4, T *data, long *datasize)
{
GRIBPACK *bitmap;
long bitmapSize;
long imaskSize;
long i;
long bmsLen, bmsUnusedBits;
long fsec4size;
long z = *gribLen;
#if defined (VECTORCODE)
unsigned int *imask;
#endif
static int lmissvalinfo = 1;
/* unsigned int c, imask; */
static bool lmissvalinfo = true;
// unsigned int c, imask;
if ( DBL_IS_NAN(FSEC3_MissVal) && lmissvalinfo)
{
lmissvalinfo = 0;
lmissvalinfo = false;
Message("Missing value = NaN is unsupported!");
}
bitmapSize = ISEC4_NumValues;
imaskSize = ((bitmapSize+7)>>3)<<3;
bitmap = &lGrib[z+6];
fsec4size = 0;
long bitmapSize = ISEC4_NumValues;
long imaskSize = ((bitmapSize+7)>>3)<<3;
GRIBPACK *bitmap = &lGrib[z+6];
long fsec4size = 0;
#if defined (VECTORCODE)
imask = (unsigned int*) Malloc(imaskSize*sizeof(unsigned int));
unsigned int *imask = (unsigned int*) Malloc(imaskSize*sizeof(unsigned int));
memset(imask, 0, imaskSize*sizeof(int));
#if defined (CRAY)
......@@ -12666,7 +12642,7 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
#ifdef __uxpch__
#pragma loop novrec
#endif
for ( i = 0; i < bitmapSize; i++ )
for ( long i = 0; i < bitmapSize; i++ )
{
if ( IS_NOT_EQUAL(data[i], FSEC3_MissVal) )
{
......@@ -12684,7 +12660,7 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
#ifdef __uxpch__
#pragma loop novrec
#endif
for ( i = 0; i < imaskSize/8; i++ )
for ( long i = 0; i < imaskSize/8; i++ )
{
bitmap[i] = (imask[i*8+0] << 7) | (imask[i*8+1] << 6) |
(imask[i*8+2] << 5) | (imask[i*8+3] << 4) |
......@@ -12694,9 +12670,9 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
Free(imask);
#else
for ( i = 0; i < imaskSize/8; i++ ) bitmap[i] = 0;
for ( long i = 0; i < imaskSize/8; i++ ) bitmap[i] = 0;
for ( i = 0; i < bitmapSize; i++ )
for ( long i = 0; i < bitmapSize; i++ )
{
if ( IS_NOT_EQUAL(data[i], FSEC3_MissVal) )
{
......@@ -12706,8 +12682,8 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
}
#endif
bmsLen = imaskSize/8 + 6;
bmsUnusedBits = imaskSize - bitmapSize;
long bmsLen = imaskSize/8 + 6;
long bmsUnusedBits = imaskSize - bitmapSize;
Put3Byte(bmsLen); /* 0- 2 Length of Block 3 Byte 0 */
Put1Byte(bmsUnusedBits);
......@@ -12974,7 +12950,7 @@ int TEMPLATE(encodeBDS,T)(GRIBPACK *lGrib, long *gribLen, int decscale, int *ise
*gribLen = (long)z;
return (0);
return 0;
}
......@@ -12982,47 +12958,42 @@ void TEMPLATE(grib_encode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
T *fsec3, int *isec4, T *fsec4, int klenp, int *kgrib,
int kleng, int *kword, int efunc, int *kret)
{
long gribLen = 0; /* Counter of GRIB length for output */
long isLen, pdsLen;
GRIBPACK *lpds;
unsigned char *CGrib;
long gribLen = 0; // Counter of GRIB length for output
long fsec4size = 0;
int bmsIncluded;
GRIBPACK *lGrib;
long datstart, datsize, bdsstart;
int status = 0;
long datstart, datsize;
UNUSED(isec3);
UNUSED(efunc);
grsdef();
CGrib = (unsigned char *) kgrib;
unsigned char *CGrib = (unsigned char *) kgrib;
bmsIncluded = ISEC1_Sec2Or3Flag & 64;
bool gdsIncluded = ISEC1_Sec2Or3Flag & 128;
bool bmsIncluded = ISEC1_Sec2Or3Flag & 64;
/* set max header len */
// set max header len
size_t len = 16384;
/* add data len */
// add data len
size_t numBytes = (size_t)((ISEC4_NumBits+7)>>3);
len += numBytes*(size_t)klenp;
/* add bitmap len */
// add bitmap len
if ( bmsIncluded ) len += (size_t)((klenp+7)>>3);
#if defined (VECTORCODE)
lGrib = (GRIBPACK*) Malloc(len*sizeof(GRIBPACK));
GRIBPACK *lGrib = (GRIBPACK*) Malloc(len*sizeof(GRIBPACK));
if ( lGrib == NULL ) SysError("No Memory!");
#else
lGrib = CGrib;
GRIBPACK *lGrib = CGrib;
#endif
isLen = 8;
long isLen = 8;
encodeIS(lGrib, &gribLen);
lpds = &lGrib[isLen];
pdsLen = getPdsLen(isec1);
GRIBPACK *lpds = &lGrib[isLen];
long pdsLen = getPdsLen(isec1);
encodePDS(lpds, pdsLen, isec1);
gribLen += pdsLen;
......@@ -13040,7 +13011,7 @@ void TEMPLATE(grib_encode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
lwarn_cplx = false;
}
*/
TEMPLATE(encodeGDS,T)(lGrib, &gribLen, isec2, fsec2);
if ( gdsIncluded ) TEMPLATE(encodeGDS,T)(lGrib, &gribLen, isec2, fsec2);
/*
----------------------------------------------------------------
BMS Bit-Map Section Section (Section 3)
......@@ -13055,9 +13026,9 @@ void TEMPLATE(grib_encode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
fsec4size = ISEC4_NumValues;
}
bdsstart = gribLen;
status = TEMPLATE(encodeBDS,T)(lGrib, &gribLen, ISEC1_DecScaleFactor, isec2,
isec4, fsec4size, fsec4, &datstart, &datsize, ISEC1_Parameter);
long bdsstart = gribLen;
int status = TEMPLATE(encodeBDS,T)(lGrib, &gribLen, ISEC1_DecScaleFactor, isec2,
isec4, fsec4size, fsec4, &datstart, &datsize, ISEC1_Parameter);
if ( status )
{
*kret = status;
......@@ -13106,11 +13077,9 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
{
long z = *gribLen;
int exponent, mantissa;
long i;
int ival;
int pvoffset = 0xFF;
int gdslen = 32;
unsigned lonIncr, latIncr;
if ( ISEC2_GridType == GRIB1_GTYPE_LCC ) gdslen += 10;
......@@ -13172,12 +13141,7 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
ISEC2_GridType == GRIB1_GTYPE_GAUSSIAN ||
ISEC2_GridType == GRIB1_GTYPE_LATLON_ROT )
{
int numlon;
if ( ISEC2_Reduced )
numlon = 0xFFFF;
else
numlon = ISEC2_NumLon;
int numlon = ISEC2_Reduced ? 0xFFFF : ISEC2_NumLon;
Put2Byte(numlon); /* 6- 7 Number of Longitudes */
Put2Byte(ISEC2_NumLat); /* 8- 9 Number of Latitudes */
......@@ -13186,16 +13150,8 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
Put1Byte(ISEC2_ResFlag); /* 16 Resolution flag */
Put3Int(ISEC2_LastLat);
Put3Int(ISEC2_LastLon);
if ( ISEC2_ResFlag == 0 )
{
lonIncr = 0xFFFF;
latIncr = 0xFFFF;
}
else
{
lonIncr = (unsigned)ISEC2_LonIncr;
latIncr = (unsigned)ISEC2_LatIncr;
}
unsigned lonIncr = (ISEC2_ResFlag == 0) ? 0xFFFF : (unsigned)ISEC2_LonIncr;
unsigned latIncr = (ISEC2_ResFlag == 0) ? 0xFFFF : (unsigned)ISEC2_LatIncr;
Put2Byte(lonIncr); /* 23-24 i - direction increment */
if ( ISEC2_GridType == GRIB1_GTYPE_GAUSSIAN )
Put2Byte(ISEC2_NumPar); /* 25-26 Latitudes Pole->Equator */
......@@ -13220,13 +13176,13 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
#if defined (SX)
#pragma vdir novector /* vectorization gives wrong results on NEC */
#endif
for ( i = 0; i < ISEC2_NumVCP; ++i )
for ( long i = 0; i < ISEC2_NumVCP; ++i )
{
Put1Real((double)(fsec2[10+i]));
}
if ( ISEC2_Reduced )
for ( i = 0; i < ISEC2_NumLat; i++ ) Put2Byte(ISEC2_RowLon(i));
for ( long i = 0; i < ISEC2_NumLat; i++ ) Put2Byte(ISEC2_RowLon(i));
*gribLen = z;
}
......@@ -13235,32 +13191,23 @@ void TEMPLATE(encodeGDS,T)(GRIBPACK *lGrib, long *gribLen, int *isec2, T *fsec2)
static
void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4, T *data, long *datasize)
{
GRIBPACK *bitmap;
long bitmapSize;
long imaskSize;
long i;
long bmsLen, bmsUnusedBits;
long fsec4size;
long z = *gribLen;
#if defined (VECTORCODE)
unsigned int *imask;
#endif
static int lmissvalinfo = 1;
/* unsigned int c, imask; */
static bool lmissvalinfo = true;
// unsigned int c, imask;
if ( DBL_IS_NAN(FSEC3_MissVal) && lmissvalinfo)
{
lmissvalinfo = 0;
lmissvalinfo = false;
Message("Missing value = NaN is unsupported!");
}
bitmapSize = ISEC4_NumValues;
imaskSize = ((bitmapSize+7)>>3)<<3;
bitmap = &lGrib[z+6];
fsec4size = 0;
long bitmapSize = ISEC4_NumValues;
long imaskSize = ((bitmapSize+7)>>3)<<3;
GRIBPACK *bitmap = &lGrib[z+6];
long fsec4size = 0;
#if defined (VECTORCODE)
imask = (unsigned int*) Malloc(imaskSize*sizeof(unsigned int));
unsigned int *imask = (unsigned int*) Malloc(imaskSize*sizeof(unsigned int));
memset(imask, 0, imaskSize*sizeof(int));
#if defined (CRAY)
......@@ -13272,7 +13219,7 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
#ifdef __uxpch__
#pragma loop novrec
#endif
for ( i = 0; i < bitmapSize; i++ )
for ( long i = 0; i < bitmapSize; i++ )
{
if ( IS_NOT_EQUAL(data[i], FSEC3_MissVal) )
{
......@@ -13290,7 +13237,7 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
#ifdef __uxpch__
#pragma loop novrec
#endif
for ( i = 0; i < imaskSize/8; i++ )
for ( long i = 0; i < imaskSize/8; i++ )
{
bitmap[i] = (imask[i*8+0] << 7) | (imask[i*8+1] << 6) |
(imask[i*8+2] << 5) | (imask[i*8+3] << 4) |
......@@ -13300,9 +13247,9 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
Free(imask);
#else
for ( i = 0; i < imaskSize/8; i++ ) bitmap[i] = 0;
for ( long i = 0; i < imaskSize/8; i++ ) bitmap[i] = 0;
for ( i = 0; i < bitmapSize; i++ )
for ( long i = 0; i < bitmapSize; i++ )
{
if ( IS_NOT_EQUAL(data[i], FSEC3_MissVal) )
{
......@@ -13312,8 +13259,8 @@ void TEMPLATE(encodeBMS,T)(GRIBPACK *lGrib, long *gribLen, T *fsec3, int *isec4,
}
#endif
bmsLen = imaskSize/8 + 6;
bmsUnusedBits = imaskSize - bitmapSize;
long bmsLen = imaskSize/8 + 6;
long bmsUnusedBits = imaskSize - bitmapSize;
Put3Byte(bmsLen); /* 0- 2 Length of Block 3 Byte 0 */
Put1Byte(bmsUnusedBits);
......@@ -13580,7 +13527,7 @@ int TEMPLATE(encodeBDS,T)(GRIBPACK *lGrib, long *gribLen, int decscale, int *ise
*gribLen = (long)z;
return (0);
return 0;
}
......@@ -13588,47 +13535,42 @@ void TEMPLATE(grib_encode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
T *fsec3, int *isec4, T *fsec4, int klenp, int *kgrib,
int kleng, int *kword, int efunc, int *kret)
{
long gribLen = 0; /* Counter of GRIB length for output */
long isLen, pdsLen;
GRIBPACK *lpds;
unsigned char *CGrib;
long gribLen = 0; // Counter of GRIB length for output
long fsec4size = 0;
int bmsIncluded;
GRIBPACK *lGrib;
long datstart, datsize, bdsstart;
int status = 0;
long datstart, datsize;
UNUSED(isec3);
UNUSED(efunc);
grsdef();
CGrib = (unsigned char *) kgrib;
unsigned char *CGrib = (unsigned char *) kgrib;
bmsIncluded = ISEC1_Sec2Or3Flag & 64;
bool gdsIncluded = ISEC1_Sec2Or3Flag & 128;
bool bmsIncluded = ISEC1_Sec2Or3Flag & 64;
/* set max header len */
// set max header len
size_t len = 16384;
/* add data len */
// add data len
size_t numBytes = (size_t)((ISEC4_NumBits+7)>>3);
len += numBytes*(size_t)klenp;
/* add bitmap len */
// add bitmap len
if ( bmsIncluded ) len += (size_t)((klenp+7)>>3);
#if defined (VECTORCODE)
lGrib = (GRIBPACK*) Malloc(len*sizeof(GRIBPACK));
GRIBPACK *lGrib = (GRIBPACK*) Malloc(len*sizeof(GRIBPACK));
if ( lGrib == NULL ) SysError("No Memory!");
#else
lGrib = CGrib;
GRIBPACK *lGrib = CGrib;
#endif
isLen = 8;
long isLen = 8;
encodeIS(lGrib, &gribLen);
lpds = &lGrib[isLen];
pdsLen = getPdsLen(isec1);
GRIBPACK *lpds = &lGrib[isLen];
long pdsLen = getPdsLen(isec1);
encodePDS(lpds, pdsLen, isec1);
gribLen += pdsLen;
......@@ -13646,7 +13588,7 @@ void TEMPLATE(grib_encode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
lwarn_cplx = false;
}
*/
TEMPLATE(encodeGDS,T)(lGrib, &gribLen, isec2, fsec2);
if ( gdsIncluded ) TEMPLATE(encodeGDS,T)(lGrib, &gribLen, isec2, fsec2);
/*
----------------------------------------------------------------
BMS Bit-Map Section Section (Section 3)
......@@ -13661,9 +13603,9 @@ void TEMPLATE(grib_encode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
fsec4size = ISEC4_NumValues;
}
bdsstart = gribLen;
status = TEMPLATE(encodeBDS,T)(lGrib, &gribLen, ISEC1_DecScaleFactor, isec2,
isec4, fsec4size, fsec4, &datstart, &datsize, ISEC1_Parameter);
long bdsstart = gribLen;
int status = TEMPLATE(encodeBDS,T)(lGrib, &gribLen, ISEC1_DecScaleFactor, isec2,
isec4, fsec4size, fsec4, &datstart, &datsize, ISEC1_Parameter);
if ( status )
{
*kret = status;
......@@ -13705,7 +13647,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.8.1" " of ""Jun 6 2017"" ""11:54:18";
static const char grb_libvers[] = "1.8.1" " of ""Jul 12 2017"" ""18:11:37";
const char *
cgribexLibraryVersion(void)
{
......
......@@ -518,11 +518,12 @@ void cgribexDecodeHeader(int *isec0, int *isec1, int *isec2, double *fsec2,
memset(isec1, 0, 256*sizeof(int));
memset(isec2, 0, 32*sizeof(int));
isec2[0] = -1; // default generic grid
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4,
ipunp, (int *) gribbuffer, recsize, &iword, "J", iret);
if ( !(ISEC1_Sec2Or3Flag & 128) ) isec2[0] = -1; // default generic grid
*lmv = 0;
if ( ISEC1_CenterID == 215 && (isec1[34] != 0 && isec1[34] != 255) )
......@@ -1343,10 +1344,7 @@ int cgribexDecode(int memtype, void *gribbuffer, int gribsize, void *data, long
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, (double*) data,
(int) datasize, (int*) gribbuffer, gribsize, &iword, hoper, &iret);
if ( ISEC1_Sec2Or3Flag & 64 )
*nmiss = ISEC4_NumValues - ISEC4_NumNonMissValues;
else
*nmiss = 0;
*nmiss = (ISEC1_Sec2Or3Flag & 64) ? ISEC4_NumValues - ISEC4_NumNonMissValues : 0;
if ( ISEC1_CenterID == 215 && (isec1[34] != 0 && isec1[34] != 255) )
{
......@@ -1857,10 +1855,15 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
ISEC2_GME_BFlag = 0;
break;
}
case GRID_GENERIC:
{
ISEC1_Sec2Or3Flag = 0;
break;
}
default:
{
Warning("The CGRIBEX library can not store fields on the used grid!");
Error("Unsupported grid type: %s", gridNamePtr(gridtype));
ISEC1_Sec2Or3Flag = 0;
Warning("CGRIBEX library doesn't support %s grids, grid information will be lost!", gridNamePtr(gridtype));
break;
}
}
......
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