Commit 332fc8e6 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cgribexlib update

parent 7f2fa6e1
......@@ -223,12 +223,6 @@ void gribPrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
void gribCheck1(int nrec, long recpos, long recsize, unsigned char *gribbuffer);
void gribRepair1(int nrec, long recsize, unsigned char *gribbuffer);
int grib1Sections(unsigned char *gribbuffer, long recsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp);
int grib2Sections(unsigned char *gribbuffer, long recsize, unsigned char **idsp,
unsigned char **lusp, unsigned char **gdsp, unsigned char **pdsp,
unsigned char **drsp, unsigned char **bmsp, unsigned char **bdsp);
int gribGetZip(long recsize, unsigned char *gribbuffer, long *urecsize);
int gribBzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufsize);
......
/* Automatically generated by m214003 at 2014-09-29, do not edit */
/* Automatically generated by m214003 at 2014-09-30, do not edit */
/* CGRIBEXLIB_VERSION="1.7.0" */
......@@ -212,6 +212,13 @@ void grib_decode_float(int *isec0, int *isec1, int *isec2, float *fsec2, int *i
float *fsec3, int *isec4, float *fsec4, int klenp, int *kgrib,
int kleng, int *kword, int dfunc, int *kret);
int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp, long *gribrecsize);
int grib2Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **idsp,
unsigned char **lusp, unsigned char **gdsp, unsigned char **pdsp,
unsigned char **drsp, unsigned char **bmsp, unsigned char **bdsp);
#endif /* _GRIB_INT_H */
#ifndef _GRIBDECODE_H
#define _GRIBDECODE_H
......@@ -5569,8 +5576,8 @@ int correct_bdslen(int bdslen, long recsize, long gribpos)
}
int grib1Sections(unsigned char *gribbuffer, long bufsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp)
int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp, long *gribrecsize)
{
unsigned char *pds, *gds, *bms, *bds;
unsigned char *bufpointer, *is, *section;
......@@ -5578,11 +5585,17 @@ int grib1Sections(unsigned char *gribbuffer, long bufsize, unsigned char **pdsp,
long gribsize = 0, recsize;
int bdslen;
*gribrecsize = 0;
*pdsp = NULL;
*gdsp = NULL;
*bmsp = NULL;
*bdsp = NULL;
section = gribbuffer;
is = gribbuffer;
if ( ! GRIB_START(section) )
{
fprintf(stderr, "Wrong indicator section >%c%c%c%c<\n",
fprintf(stderr, "Wrong GRIB indicator section: found >%c%c%c%c<\n",
section[0], section[1], section[2], section[3]);
return (-1);
}
......@@ -5630,21 +5643,23 @@ int grib1Sections(unsigned char *gribbuffer, long bufsize, unsigned char **pdsp,
gribsize += bdslen;
gribsize += 4;
if ( gribsize > bufsize )
{
fprintf(stderr, "GRIB buffer size %ld too small! Min size = %ld\n", bufsize, gribsize);
return (1);
}
*pdsp = pds;
*gdsp = gds;
*bmsp = bms;
*bdsp = bds;
*gribrecsize = gribsize;
if ( gribbufsize < gribsize )
{
fprintf(stderr, "Length of GRIB message is inconsistent (grib_buffer_size=%ld < grib_record_size=%ld)!\n", gribbufsize, gribsize);
return (1);
}
/* end section - "7777" in ascii */
if ( !GRIB_FIN(bufpointer) )
{
fprintf(stderr, "Missing end section >%2x %2x %2x %2x<\n",
fprintf(stderr, "Missing GRIB end section: found >%c%c%c%c<\n",
bufpointer[0], bufpointer[1], bufpointer[2], bufpointer[3]);
return (-2);
}
......@@ -5653,7 +5668,7 @@ int grib1Sections(unsigned char *gribbuffer, long bufsize, unsigned char **pdsp,
}
int grib2Sections(unsigned char *gribbuffer, long bufsize, unsigned char **idsp,
int grib2Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **idsp,
unsigned char **lusp, unsigned char **gdsp, unsigned char **pdsp,
unsigned char **drsp, unsigned char **bmsp, unsigned char **bdsp)
{
......@@ -5665,7 +5680,7 @@ int grib2Sections(unsigned char *gribbuffer, long bufsize, unsigned char **idsp,
long gribsize;
long grib_len = 0;
UNUSED(bufsize);
UNUSED(gribbufsize);
*idsp = NULL;
*lusp = NULL;
......@@ -5962,10 +5977,11 @@ void grib1PrintALL(int nrec, long offset, long recpos, long recsize, unsigned ch
if ( gribrec_len(is[4], is[5], is[6]) > JP23SET ) llarge = 1;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d :%4ld %8ld %6ld : error\n", nrec, offset, recpos, recsize);
fprintf(stdout, "%5d :%4ld %8ld %6ld : GRIB message error\n", nrec, offset, recpos, recsize);
return;
}
......@@ -5994,10 +6010,13 @@ void grib1PrintALL(int nrec, long offset, long recpos, long recsize, unsigned ch
cr = ((double)s1)/s2;
}
fprintf(stdout, "%5d :%4ld %8ld %6ld :%2d%4d%5d %6d %6d : %3d %6d : %5d %5d %6.4g %c\n",
fprintf(stdout, "%5d :%4ld %8ld %6ld :%2d%4d%5d %6d %6d : %3d %6d : %5d %5d %6.4g %c",
nrec, offset, recpos, recsize, GRIB_EDITION(is),
PDS_Len, GDS_Len, BMS_Len, bdslen,
PDS_Parameter, level, PDS_LevelType, GridType, cr, llarge?'T':'F');
if ( nerr > 0 ) fprintf(stdout, " <-- GRIB data corrupted!");
fprintf(stdout, "\n");
}
......@@ -6103,10 +6122,11 @@ void grib1PrintPDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
is = gribbuffer;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d : error\n", nrec);
fprintf(stdout, "%5d : GRIB message error\n", nrec);
return;
}
......@@ -6145,11 +6165,14 @@ void grib1PrintPDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
date = year*10000+PDS_Month*100+PDS_Day;
}
fprintf(stdout, "%5d :%4d%4d%4d%4d%4d %4d %4d%4d%7d%7d %8d%6d%3d%3d%3d%3d%5d%6d%5d%4d\n", nrec,
fprintf(stdout, "%5d :%4d%4d%4d%4d%4d %4d %4d%4d%7d%7d %8d%6d%3d%3d%3d%3d%5d%6d%5d%4d", nrec,
PDS_Len, PDS_CodeTable, PDS_CenterID, subcenter, PDS_ModelID,
PDS_GridDefinition, PDS_Parameter, PDS_LevelType, PDS_Level1, PDS_Level2,
date, PDS_Time, PDS_TimePeriod1, PDS_TimePeriod2, PDS_TimeUnit, PDS_TimeRange,
PDS_AvgNum, decimalscale, fc_num, century);
if ( nerr > 0 ) fprintf(stdout, " <-- GRIB data corrupted!");
fprintf(stdout, "\n");
}
......@@ -6189,22 +6212,28 @@ void grib1PrintGDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
header = 0;
}
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d : error\n", nrec);
fprintf(stdout, "%5d : GRIB message error\n", nrec);
return;
}
fprintf(stdout, "%5d :", nrec);
if ( gds )
fprintf(stdout, "%5d :%4d%4d%4d %4d :%6d%6d%7d%7d%7d%7d%6d%6d\n", nrec,
fprintf(stdout, "%4d%4d%4d %4d :%6d%6d%7d%7d%7d%7d%6d%6d",
GDS_Len, GDS_NV, GDS_PVPL, GDS_GridType,
GDS_NumLon, GDS_NumLat,
GDS_FirstLat, GDS_FirstLon,
GDS_LastLat, GDS_LastLon,
GDS_LonIncr, GDS_LatIncr);
else
fprintf(stdout, "%5d : Grid Description Section not defined\n", nrec);
fprintf(stdout, " Grid Description Section not defined");
if ( nerr > 0 ) fprintf(stdout, " <-- GRIB data corrupted!");
fprintf(stdout, "\n");
}
......@@ -6244,10 +6273,11 @@ void grib1PrintBMS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
header = 0;
}
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d : error\n", nrec);
fprintf(stdout, "%5d : GRIB message error\n", nrec);
return;
}
......@@ -6258,13 +6288,17 @@ void grib1PrintBMS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
else
level = PDS_Level1;
fprintf(stdout, "%5d :", nrec);
if ( bms )
fprintf(stdout, "%5d :%4d%7d %7d %7d\n", nrec,
fprintf(stdout, "%4d%7d %7d %7d",
PDS_Parameter, level,
BMS_Len, BMS_BitmapSize);
else
fprintf(stdout, "%5d :%4d%7d Bit Map Section not defined\n", nrec,
PDS_Parameter, level);
fprintf(stdout, "%4d%7d Bit Map Section not defined", PDS_Parameter, level);
if ( nerr > 0 ) fprintf(stdout, " <-- GRIB data corrupted!");
fprintf(stdout, "\n");
}
......@@ -6306,10 +6340,11 @@ void grib1PrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
header = 0;
}
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d : error\n", nrec);
fprintf(stdout, "%5d : GRIB message error\n", nrec);
return;
}
......@@ -6343,9 +6378,17 @@ void grib1PrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffe
scale *= decscale;
}
fprintf(stdout, "%5d :%4d%7d %7d %4d %8.5g %11.5g%4d %6.4g\n", nrec,
PDS_Parameter, level,
BDS_Len, BDS_Flag, scale, refval, BDS_NumBits, cr);
fprintf(stdout, "%5d :", nrec);
if ( bds )
fprintf(stdout, "%4d%7d %7d %4d %8.5g %11.5g%4d %6.4g",
PDS_Parameter, level,
BDS_Len, BDS_Flag, scale, refval, BDS_NumBits, cr);
else
fprintf(stdout, " Binary Data Section not defined");
if ( nerr > 0 ) fprintf(stdout, " <-- GRIB data corrupted!");
fprintf(stdout, "\n");
}
......@@ -6377,10 +6420,17 @@ void gribCheck1(int nrec, long recpos, long recsize, unsigned char *gribbuffer)
UNUSED(recpos);
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d : error\n", nrec);
fprintf(stdout, "%5d : GRIB message error\n", nrec);
return;
}
if ( nerr > 0 )
{
fprintf(stdout, "%5d : <-- GRIB data corrupted!\n", nrec);
return;
}
......@@ -6421,10 +6471,18 @@ void repair1(unsigned char *gbuf, long gbufsize)
int datstart = 0;
/* int llarge = FALSE; */
nerr = grib1Sections(gbuf, gbufsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gbuf, gbufsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "grib1Sections error\n");
fprintf(stdout, "GRIB message error\n");
return;
}
if ( nerr > 0 )
{
fprintf(stdout, "GRIB data corrupted!\n");
return;
}
/* recLen = gribrec_len(gbuf[4], gbuf[5], gbuf[6]); */
......@@ -6483,10 +6541,17 @@ void gribRepair1(int nrec, long recsize, unsigned char *gribbuffer)
unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL;
double cr = 1;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "%5d : GRIB message error\n", nrec);
return;
}
if ( nerr > 0 )
{
fprintf(stdout, "%5d : error\n", nrec);
fprintf(stdout, "%5d : <-- GRIB data corrupted!\n", nrec);
return;
}
......@@ -6572,10 +6637,17 @@ int gribGetZip(long recsize, unsigned char *gribbuffer, long *urecsize)
if ( gribversion == 2 ) return (compress);
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(gribbuffer, recsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "GRIB message error\n");
return (compress);
}
if ( nerr > 0 )
{
fprintf(stdout, "grib1Sections error\n");
fprintf(stdout, "GRIB data corrupted!\n");
return (compress);
}
......@@ -6618,10 +6690,17 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
rec_len = gribLen;
nerr = grib1Sections(dbuf, dbufsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(dbuf, dbufsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "GRIB message error\n");
return (rec_len);
}
if ( nerr > 0 )
{
fprintf(stdout, "grib1Sections error!\n");
fprintf(stdout, "GRIB data corrupted!\n");
return (rec_len);
}
......@@ -6919,10 +6998,17 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
UNUSED(dbufsize);
nerr = grib1Sections(sbuf, sbufsize, &pds, &gds, &bms, &bds);
if ( nerr )
long gribrecsize;
nerr = grib1Sections(sbuf, sbufsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "GRIB message error\n");
return (0);
}
if ( nerr > 0 )
{
fprintf(stdout, "grib1Sections error\n");
fprintf(stdout, "GRIB data corrupted!\n");
return (0);
}
......@@ -6964,10 +7050,16 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
else
sourceLen = ((size_t) ((bds[20]<<16)+(bds[21]<<8)+bds[22]));
nerr = grib1Sections(dbuf, sbufsize, &pds, &gds, &bms, &bds);
if ( nerr )
nerr = grib1Sections(dbuf, sbufsize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( nerr < 0 )
{
fprintf(stdout, "GRIB message error\n");
return (0);
}
if ( nerr > 0 )
{
fprintf(stdout, "grib1Sections error\n");
fprintf(stdout, "GRIB data corrupted!\n");
return (0);
}
......@@ -10128,13 +10220,17 @@ int TEMPLATE(decodeBDS,T)(int decscale, unsigned char *bds, int *isec2, int *ise
if ( dfunc != 'J' )
for ( i = 0; i < ioff; i++ )
{
iexp = (bds[locnd+4*i ]);
imant =((bds[locnd+4*i+1]) << 16) +
((bds[locnd+4*i+2]) << 8) +
(bds[locnd+4*i+3]);
if ( imiss )
*fpdata++ = 0.0;
else
{
iexp = (bds[locnd+4*i ]);
imant =((bds[locnd+4*i+1]) << 16) +
((bds[locnd+4*i+2]) << 8) +
(bds[locnd+4*i+3]);
if ( imiss ) *fpdata++ = 0.0;
else *fpdata++ = decfp2(iexp,imant);
*fpdata++ = decfp2(iexp,imant);
}
}
locnd += 4*ioff; /* RealCoef */
......@@ -10606,10 +10702,8 @@ void TEMPLATE(grib_decode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
gribLen = isLen + pdsLen + gdsLen + bmsLen + bdsLen + esLen;
if ( ISEC0_GRIB_Len )
if ( gribLen > ISEC0_GRIB_Len )
{
Warning("grib1Len = %d gribLen = %d", ISEC0_GRIB_Len, gribLen);
}
if ( ISEC0_GRIB_Len < gribLen )
Warning("Length of GRIB message is inconsistent (grib_message_size=7867 < grib_record_size=9718)!", ISEC0_GRIB_Len, gribLen);
ISEC0_GRIB_Len = gribLen;
......@@ -11059,13 +11153,17 @@ int TEMPLATE(decodeBDS,T)(int decscale, unsigned char *bds, int *isec2, int *ise
if ( dfunc != 'J' )
for ( i = 0; i < ioff; i++ )
{
iexp = (bds[locnd+4*i ]);
imant =((bds[locnd+4*i+1]) << 16) +
((bds[locnd+4*i+2]) << 8) +
(bds[locnd+4*i+3]);
if ( imiss )
*fpdata++ = 0.0;
else
{
iexp = (bds[locnd+4*i ]);
imant =((bds[locnd+4*i+1]) << 16) +
((bds[locnd+4*i+2]) << 8) +
(bds[locnd+4*i+3]);
if ( imiss ) *fpdata++ = 0.0;
else *fpdata++ = decfp2(iexp,imant);
*fpdata++ = decfp2(iexp,imant);
}
}
locnd += 4*ioff; /* RealCoef */
......@@ -11537,10 +11635,8 @@ void TEMPLATE(grib_decode,T)(int *isec0, int *isec1, int *isec2, T *fsec2, int *
gribLen = isLen + pdsLen + gdsLen + bmsLen + bdsLen + esLen;
if ( ISEC0_GRIB_Len )
if ( gribLen > ISEC0_GRIB_Len )
{
Warning("grib1Len = %d gribLen = %d", ISEC0_GRIB_Len, gribLen);
}
if ( ISEC0_GRIB_Len < gribLen )
Warning("Length of GRIB message is inconsistent (grib_message_size=7867 < grib_record_size=9718)!", ISEC0_GRIB_Len, gribLen);
ISEC0_GRIB_Len = gribLen;
......@@ -14128,7 +14224,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.0" " of ""Sep 29 2014"" ""14:24:37";
static const char grb_libvers[] = "1.7.0" " of ""Sep 30 2014"" ""13:27:33";
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