Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
1002e14c
Commit
1002e14c
authored
Jan 27, 2012
by
Uwe Schulzweida
Browse files
added support for GRIB2 packing type grid_ieee
parent
e1d58c6b
Changes
7
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
1002e14c
2012-01-
??
Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
2012-01-
30
Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* Version 1.5.4 released
201
2-01-06
Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
201
1-12-27
Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added support for GRIB gaussian grid parameter NumPar on non global grids [Bug #1711]
* added interface functions gridDefNP/gridInqNP (number of parallels between a pole and the equator)
* added support for GRIB2 packing type grid_ieee
2011-12-19 Luis Kornblueh <Luis.Kornblueh@zmaw.de>
...
...
@@ -19,6 +18,11 @@
* added support for netCDF attributes scale_factor and add_offset for lon/lat coordinates
2012-01-06 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added support for GRIB gaussian grid parameter NumPar on non global grids [Bug #1711]
* added interface functions gridDefNP/gridInqNP (number of parallels between a pole and the equator)
2011-11-04 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added support for GRIB1_LTYPE_SIGMA_LAYER
...
...
NEWS
View file @
1002e14c
CDI NEWS
--------
Version 1.5.4 (30 January 2012):
New features:
* Added support for GRIB2 packing type grid_ieee
* Added suppport for GRIB2 level type 150
Version 1.5.3 (17 October 2011):
New features:
...
...
app/cdi.c
View file @
1002e14c
...
...
@@ -756,10 +756,13 @@ int main(int argc, char *argv[])
if
(
Progname
==
0
)
Progname
=
argv
[
0
];
else
Progname
++
;
while
(
(
c
=
getopt
(
argc
,
argv
,
"f:t:w:z:cdhlMmqRrsvVZ"
))
!=
EOF
)
while
(
(
c
=
getopt
(
argc
,
argv
,
"
b:
f:t:w:z:cdhlMmqRrsvVZ"
))
!=
EOF
)
{
switch
(
c
)
{
case
'b'
:
setDefaultDataType
(
optarg
);
break
;
case
'd'
:
Debug
=
1
;
break
;
...
...
src/gribapi.c
View file @
1002e14c
...
...
@@ -39,7 +39,7 @@ const char *gribapiLibraryVersion(void)
void
gribContainersNew
(
int
streamID
)
{
stream_t
*
streamptr
;
streamptr
=
stream_to_pointer
(
streamID
);
#if defined (HAVE_LIBCGRIBEX)
...
...
@@ -69,7 +69,7 @@ void gribContainersNew(int streamID)
void
gribContainersDelete
(
int
streamID
)
{
stream_t
*
streamptr
;
streamptr
=
stream_to_pointer
(
streamID
);
if
(
streamptr
->
gribContainers
)
...
...
@@ -85,12 +85,3 @@ void gribContainersDelete(int streamID)
streamptr
->
gribContainers
=
NULL
;
}
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
src/stream_grb.c
View file @
1002e14c
...
...
@@ -444,24 +444,28 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *
static
size_t
grbEncode
(
int
filetype
,
int
varID
,
int
levelID
,
int
vlistID
,
int
gridID
,
int
zaxisID
,
int
date
,
int
time
,
int
tsteptype
,
int
numavg
,
long
datasize
,
const
double
*
data
,
int
nmiss
,
unsigned
char
*
gribbuffer
,
size_t
gribbuffer
size
,
long
datasize
,
const
double
*
data
,
int
nmiss
,
unsigned
char
*
*
gribbuffer
,
int
ljpeg
,
void
*
gribContainer
)
{
size_t
nbytes
;
size_t
gribbuffersize
;
#if defined (HAVE_LIBCGRIBEX)
if
(
filetype
==
FILETYPE_GRB
)
{
gribbuffersize
=
datasize
*
4
+
3000
;
*
gribbuffer
=
(
unsigned
char
*
)
malloc
(
gribbuffersize
);
nbytes
=
cgribexEncode
(
varID
,
levelID
,
vlistID
,
gridID
,
zaxisID
,
date
,
time
,
tsteptype
,
numavg
,
datasize
,
data
,
nmiss
,
gribbuffer
,
gribbuffersize
);
datasize
,
data
,
nmiss
,
*
gribbuffer
,
gribbuffersize
);
}
else
#endif
{
nbytes
=
gribapiEncode
(
varID
,
levelID
,
vlistID
,
gridID
,
zaxisID
,
date
,
time
,
tsteptype
,
numavg
,
datasize
,
data
,
nmiss
,
gribbuffer
,
gribbuffersize
,
datasize
,
data
,
nmiss
,
gribbuffer
,
&
gribbuffersize
,
ljpeg
,
gribContainer
);
}
...
...
@@ -505,7 +509,6 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
int
gridID
;
int
zaxisID
;
unsigned
char
*
gribbuffer
=
NULL
;
size_t
gribbuffersize
=
0
;
long
datasize
;
int
tsID
;
int
vlistID
;
...
...
@@ -541,10 +544,10 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
Message
(
"gridID = %d zaxisID = %d"
,
gridID
,
zaxisID
);
datasize
=
gridInqSize
(
gridID
);
/*
gribbuffersize = datasize*4+3000;
gribbuffer = (unsigned char *) malloc(gribbuffersize);
*/
#if defined (HAVE_LIBCGRIBEX)
if
(
filetype
==
FILETYPE_GRB
)
{
...
...
@@ -570,7 +573,7 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
}
nbytes
=
grbEncode
(
filetype
,
varID
,
levelID
,
vlistID
,
gridID
,
zaxisID
,
date
,
time
,
tsteptype
,
numavg
,
datasize
,
data
,
nmiss
,
gribbuffer
,
gribbuffersize
,
ljpeg
,
gc
);
datasize
,
data
,
nmiss
,
&
gribbuffer
,
ljpeg
,
gc
);
if
(
streamptr
->
comptype
==
COMPRESS_SZIP
)
nbytes
=
grbSzip
(
filetype
,
gribbuffer
,
nbytes
);
...
...
src/stream_gribapi.c
View file @
1002e14c
...
...
@@ -681,7 +681,7 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh,
//lbounds = cgribexGetZaxisHasBounds(ISEC1_LevelType);
if
(
datatype
>
32
)
datatype
=
DATATYPE_PACK32
;
//
if ( datatype > 32 ) datatype = DATATYPE_PACK32;
if
(
datatype
<
0
)
datatype
=
DATATYPE_PACK
;
name
[
0
]
=
0
;
...
...
@@ -804,6 +804,7 @@ int gribapiScanTimestep1(int streamID)
long
editionNumber
;
long
lpar
;
int
bitsPerValue
;
int
lieee
=
FALSE
;
double
dlevel
=
0
;
streamptr
=
stream_to_pointer
(
streamID
);
...
...
@@ -841,6 +842,8 @@ int gribapiScanTimestep1(int streamID)
rstatus
=
gribRead
(
fileID
,
gribbuffer
,
&
readsize
);
if
(
rstatus
)
break
;
lieee
=
FALSE
;
comptype
=
COMPRESS_NONE
;
if
(
gribGetZip
(
recsize
,
gribbuffer
,
&
unzipsize
)
>
0
)
{
...
...
@@ -889,7 +892,8 @@ int gribapiScanTimestep1(int streamID)
if
(
status
==
0
)
{
// fprintf(stderr, "packingType %d %s\n", len, typeOfPacking);
if
(
strncmp
(
typeOfPacking
,
"grid_jpeg"
,
len
)
==
0
)
comptype
=
COMPRESS_JPEG
;
if
(
strncmp
(
typeOfPacking
,
"grid_jpeg"
,
len
)
==
0
)
comptype
=
COMPRESS_JPEG
;
else
if
(
strncmp
(
typeOfPacking
,
"grid_ieee"
,
len
)
==
0
)
lieee
=
TRUE
;
}
GRIB_CHECK
(
grib_get_long
(
gh
,
"discipline"
,
&
lpar
),
0
);
...
...
@@ -924,14 +928,23 @@ int gribapiScanTimestep1(int streamID)
/*
printf("%d %d %d.%d.%d %d %g\n", vdate, vtime, pnum, pcat, pdis, leveltype, dlevel);
*/
datatype
=
DATATYPE_PACK
;
status
=
grib_get_long
(
gh
,
"bitsPerValue"
,
&
lpar
);
if
(
status
==
0
)
{
bitsPerValue
=
(
int
)
lpar
;
if
(
bitsPerValue
>
0
&&
bitsPerValue
<=
32
)
datatype
=
bitsPerValue
;
}
if
(
lieee
)
{
datatype
=
DATATYPE_FLT64
;
status
=
grib_get_long
(
gh
,
"precision"
,
&
lpar
);
if
(
status
==
0
&&
lpar
==
1
)
datatype
=
DATATYPE_FLT32
;
}
else
{
datatype
=
DATATYPE_PACK
;
status
=
grib_get_long
(
gh
,
"bitsPerValue"
,
&
lpar
);
if
(
status
==
0
)
{
bitsPerValue
=
(
int
)
lpar
;
if
(
bitsPerValue
>
0
&&
bitsPerValue
<=
32
)
datatype
=
bitsPerValue
;
}
}
if
(
nrecs
==
0
)
{
...
...
@@ -1137,7 +1150,7 @@ int gribapiScanTimestep2(int streamID)
gribbuffer
=
(
unsigned
char
*
)
streamptr
->
record
->
buffer
;
buffersize
=
streamptr
->
record
->
buffersize
;
tsID
=
streamptr
->
rtsteps
;
if
(
tsID
!=
1
)
Error
(
"Internal problem! unexpeceted timestep %d"
,
tsID
+
1
);
...
...
@@ -1153,7 +1166,7 @@ int gribapiScanTimestep2(int streamID)
streamptr
->
tsteps
[
1
].
nrecs
=
0
;
for
(
recID
=
0
;
recID
<
nrecords
;
recID
++
)
streamptr
->
tsteps
[
1
].
recIDs
[
recID
]
=
-
1
;
for
(
recID
=
0
;
recID
<
nrecords
;
recID
++
)
{
varID
=
streamptr
->
tsteps
[
0
].
records
[
recID
].
varID
;
...
...
@@ -2008,7 +2021,7 @@ void gribapiDefTime(grib_handle *gh , int vdate, int vtime, int tsteptype, int n
int
rdate
,
rtime
;
int
ip
=
0
;
int
calendar
;
calendar
=
taxisInqCalendar
(
taxisID
);
rdate
=
taxisInqRdate
(
taxisID
);
rtime
=
taxisInqRtime
(
taxisID
);
...
...
@@ -2038,7 +2051,7 @@ void gribapiDefTime(grib_handle *gh , int vdate, int vtime, int tsteptype, int n
#if defined (HAVE_LIBGRIB_API)
static
void
gribapiDefGrid
(
grib_handle
*
gh
,
int
gridID
,
int
ljpeg
)
void
gribapiDefGrid
(
grib_handle
*
gh
,
int
gridID
,
int
ljpeg
,
int
*
lieee
)
{
int
gridtype
;
int
status
;
...
...
@@ -2236,7 +2249,12 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
/* South -> North */
//if ( ISEC2_LastLat > ISEC2_FirstLat ) ISEC2_ScanFlag += 64;
if
(
ljpeg
&&
editionNumber
==
2
)
if
(
*
lieee
)
{
mesg
=
"grid_ieee"
;
len
=
strlen
(
mesg
);
GRIB_CHECK
(
grib_set_string
(
gh
,
"packingType"
,
mesg
,
&
len
),
0
);
}
else
if
(
ljpeg
&&
editionNumber
==
2
)
{
mesg
=
"grid_jpeg"
;
len
=
strlen
(
mesg
);
GRIB_CHECK
(
grib_set_string
(
gh
,
"packingType"
,
mesg
,
&
len
),
0
);
...
...
@@ -2246,13 +2264,7 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
mesg
=
"grid_simple"
;
len
=
strlen
(
mesg
);
GRIB_CHECK
(
grib_set_string
(
gh
,
"packingType"
,
mesg
,
&
len
),
0
);
}
/*
{
mesg = "grid_ieee"; len = strlen(mesg);
GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0);
GRIB_CHECK(grib_set_long(gh, "precision", 2), 0);
}
*/
break
;
}
/*
...
...
@@ -2299,7 +2311,16 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
// GRIB_CHECK(grib_set_long(gh, "numberOfDataPoints", gridInqSize(gridID)), 0);
if
(
gridInqComplexPacking
(
gridID
)
)
if
(
*
lieee
)
*
lieee
=
FALSE
;
/*
if ( lieee )
{
printf("spectral_ieee\n");
if ( editionNumber == 2 ) GRIB_CHECK(grib_set_long(gh, "numberOfValues", gridInqSize(gridID)), 0);
mesg = "spectral_ieee"; len = strlen(mesg);
GRIB_CHECK(grib_set_string(gh, "packingType", mesg, &len), 0);
}
else */
if
(
gridInqComplexPacking
(
gridID
)
)
{
if
(
editionNumber
==
2
)
GRIB_CHECK
(
grib_set_long
(
gh
,
"numberOfValues"
,
gridInqSize
(
gridID
)),
0
);
mesg
=
"spectral_complex"
;
len
=
strlen
(
mesg
);
...
...
@@ -2320,6 +2341,8 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
}
case
GRID_GME
:
{
if
(
*
lieee
)
*
lieee
=
FALSE
;
GRIB_CHECK
(
grib_set_long
(
gh
,
"gridDefinitionTemplateNumber"
,
GRIB2_GTYPE_GME
),
0
);
GRIB_CHECK
(
grib_set_long
(
gh
,
"nd"
,
gridInqGMEnd
(
gridID
)),
0
);
...
...
@@ -2336,6 +2359,8 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
}
case
GRID_REFERENCE
:
{
if
(
*
lieee
)
*
lieee
=
FALSE
;
static
int
warning
=
1
;
status
=
grib_set_long
(
gh
,
"gridDefinitionTemplateNumber"
,
GRIB2_GTYPE_NUMBER
);
if
(
status
!=
0
&&
warning
)
...
...
@@ -2351,7 +2376,6 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
GRIB_CHECK
(
grib_set_long
(
gh
,
"numberOfGridInReference"
,
gridInqPosition
(
gridID
)),
0
);
len
=
16
;
GRIB_CHECK
(
grib_set_string
(
gh
,
"uuidOfHGrid"
,
gridInqUUID
(
gridID
,
uuid
),
&
len
),
0
);
}
break
;
...
...
@@ -2664,7 +2688,7 @@ void gribHandleDelete(void *gh)
size_t
gribapiEncode
(
int
varID
,
int
levelID
,
int
vlistID
,
int
gridID
,
int
zaxisID
,
int
vdate
,
int
vtime
,
int
tsteptype
,
int
numavg
,
long
datasize
,
const
double
*
data
,
int
nmiss
,
unsigned
char
*
gribbuffer
,
size_t
gribbuffersize
,
long
datasize
,
const
double
*
data
,
int
nmiss
,
unsigned
char
*
*
gribbuffer
,
size_t
*
gribbuffersize
,
int
ljpeg
,
void
*
gribContainer
)
{
size_t
nbytes
=
0
;
...
...
@@ -2673,7 +2697,9 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
void
*
dummy
=
NULL
;
int
datatype
;
int
param
;
int
lieee
=
FALSE
;
long
bitsPerValue
;
long
editionNumber
;
char
name
[
256
];
grib_handle
*
gh
=
NULL
;
gribContainer_t
*
gc
=
(
gribContainer_t
*
)
gribContainer
;
...
...
@@ -2689,17 +2715,33 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
gh
=
gc
->
gribHandle
;
#endif
GRIB_CHECK
(
grib_get_long
(
gh
,
"editionNumber"
,
&
editionNumber
),
0
);
if
(
!
gc
->
init
)
gribapiDefInstitut
(
gh
,
vlistID
,
varID
);
if
(
!
gc
->
init
)
gribapiDefModel
(
gh
,
vlistID
,
varID
);
if
(
!
gc
->
init
)
gribapiDefParam
(
gh
,
param
,
name
);
gribapiDefTime
(
gh
,
vdate
,
vtime
,
tsteptype
,
numavg
,
vlistInqTaxis
(
vlistID
));
/* bitsPerValue have to be defined befor call to DefGrid (complex packing) */
bitsPerValue
=
grbBitsPerValue
(
datatype
);
GRIB_CHECK
(
grib_set_long
(
gh
,
"bitsPerValue"
,
bitsPerValue
),
0
);
if
(
editionNumber
==
2
&&
(
datatype
==
DATATYPE_FLT32
||
datatype
==
DATATYPE_FLT64
)
)
lieee
=
TRUE
;
/* bitsPerValue have to be defined before call to DefGrid (complex packing) */
// if ( lieee == FALSE )
{
bitsPerValue
=
grbBitsPerValue
(
datatype
);
GRIB_CHECK
(
grib_set_long
(
gh
,
"bitsPerValue"
,
bitsPerValue
),
0
);
}
if
(
!
gc
->
init
)
gribapiDefGrid
(
gh
,
gridID
,
ljpeg
,
&
lieee
);
if
(
lieee
==
TRUE
)
{
if
(
datatype
==
DATATYPE_FLT64
)
GRIB_CHECK
(
grib_set_long
(
gh
,
"precision"
,
2
),
0
);
else
GRIB_CHECK
(
grib_set_long
(
gh
,
"precision"
,
1
),
0
);
}
if
(
!
gc
->
init
)
gribapiDefGrid
(
gh
,
gridID
,
ljpeg
);
gribapiDefLevel
(
gh
,
param
,
zaxisID
,
levelID
);
if
(
nmiss
>
0
)
...
...
@@ -2712,13 +2754,12 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
/* get the size of coded message */
GRIB_CHECK
(
grib_get_message
(
gh
,
(
const
void
**
)
&
dummy
,
&
recsize
),
0
);
//recsize += 512; /* add some space for possible filling */
if
(
recsize
>
gribbuffersize
)
Error
(
"Internal problem: GRIB buffer too small (size = %ld, needed = %ld"
,
gribbuffersize
,
recsize
);
recsize
+=
512
;
/* add some space for possible filling */
*
gribbuffersize
=
recsize
;
*
gribbuffer
=
(
unsigned
char
*
)
malloc
(
*
gribbuffersize
);
/* get a copy of the coded message */
GRIB_CHECK
(
grib_get_message_copy
(
gh
,
gribbuffer
,
&
recsize
),
0
);
GRIB_CHECK
(
grib_get_message_copy
(
gh
,
*
gribbuffer
,
&
recsize
),
0
);
#if defined(GRIBAPIENCODETEST)
gribHandleDelete
(
gh
);
...
...
@@ -2733,12 +2774,3 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
return
(
nbytes
);
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
src/stream_gribapi.h
View file @
1002e14c
...
...
@@ -10,16 +10,7 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
size_t
gribapiEncode
(
int
varID
,
int
levelID
,
int
vlistID
,
int
gridID
,
int
zaxisID
,
int
vdate
,
int
vtime
,
int
tsteptype
,
int
numavg
,
long
datasize
,
const
double
*
data
,
int
nmiss
,
unsigned
char
*
gribbuffer
,
size_t
gribbuffersize
,
long
datasize
,
const
double
*
data
,
int
nmiss
,
unsigned
char
*
*
gribbuffer
,
size_t
*
gribbuffersize
,
int
ljpeg
,
void
*
gribContainer
);
#endif
/* _STREAM_GRIBAPI_H */
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment