Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
libcdi
Commits
f437d67c
Commit
f437d67c
authored
1 year ago
by
Uwe Schulzweida
Committed by
Sergey Kosukhin
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
grb_encode(): add parameter datatype
parent
178d4608
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!71
Develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/grb_read.c
+4
-2
4 additions, 2 deletions
src/grb_read.c
src/grb_write.c
+16
-8
16 additions, 8 deletions
src/grb_write.c
with
20 additions
and
10 deletions
src/grb_read.c
+
4
−
2
View file @
f437d67c
...
...
@@ -37,15 +37,17 @@ grb_decode(int filetype, int memType, int datatype, void *cgribexp, void *gribbu
#endif
#ifdef HAVE_LIBGRIB_API
{
void
*
datap
=
data
;
bool
useFloatInterface
=
(
have_gribapi_float_interface
()
&&
datatype
!=
CDI_DATATYPE_FLT32
&&
datatype
!=
CDI_DATATYPE_FLT64
);
int
memTypeX
=
useFloatInterface
?
memType
:
MEMTYPE_DOUBLE
;
if
(
!
useFloatInterface
&&
memType
==
MEMTYPE_FLOAT
)
datap
=
Malloc
(
datasize
*
sizeof
(
double
));
void
*
datap
=
(
!
useFloatInterface
&&
memType
==
MEMTYPE_FLOAT
)
?
Malloc
(
datasize
*
sizeof
(
double
))
:
data
;
// if (useFloatInterface) printf("gribapi read: useFloatInterface\n");
status
=
gribapiDecode
(
memTypeX
,
gribbuffer
,
gribsize
,
datap
,
datasize
,
unreduced
,
nmiss
,
missval
);
if
(
!
useFloatInterface
&&
memType
==
MEMTYPE_FLOAT
)
{
// printf("gribapi read: convert double to float\n");
float
*
dataf
=
(
float
*
)
data
;
double
*
datad
=
(
double
*
)
datap
;
for
(
size_t
i
=
0
;
i
<
datasize
;
++
i
)
dataf
[
i
]
=
(
float
)
datad
[
i
];
...
...
This diff is collapsed.
Click to expand it.
src/grb_write.c
+
16
−
8
View file @
f437d67c
...
...
@@ -24,9 +24,9 @@
#include
"namespace.h"
static
size_t
grb_encode
(
int
filetype
,
int
memType
,
int
varID
,
int
levelID
,
int
vlistID
,
int
gridID
,
int
zaxisID
,
CdiDateTime
vDateTime
,
int
tsteptype
,
int
numavg
,
size_t
datasize
,
const
void
*
data
,
size_t
nmiss
,
void
**
gribbuffer
,
int
comptype
,
void
*
gribContainers
)
grb_encode
(
int
filetype
,
int
memType
,
int
datatype
,
int
varID
,
int
levelID
,
int
vlistID
,
int
gridID
,
int
zaxisID
,
CdiDateTime
vDateTime
,
int
tsteptype
,
int
numavg
,
size_t
datasize
,
const
void
*
data
,
size_t
nmiss
,
void
**
gribbuffer
,
int
comptype
,
void
*
gribContainers
)
{
size_t
nbytes
=
0
;
...
...
@@ -48,10 +48,17 @@ grb_encode(int filetype, int memType, int varID, int levelID, int vlistID, int g
#else
void
*
gribContainer
=
(
void
*
)
&
((
gribContainer_t
*
)
gribContainers
)[
varID
];
#endif
// bool useFloatInterface = (have_gribapi_float_interface() && datatype != CDI_DATATYPE_FLT32 && datatype !=
// CDI_DATATYPE_FLT64);
bool
useFloatInterface
=
false
;
int
memTypeX
=
useFloatInterface
?
memType
:
MEMTYPE_DOUBLE
;
const
void
*
datap
=
data
;
int
memTypeX
=
/*have_gribapi_float_interface() ? memType :*/
MEMTYPE_DOUBLE
;
if
(
/*!have_gribapi_float_interface() &&*/
memType
==
MEMTYPE_FLOAT
)
// if (useFloatInterface) printf("gribapi write: useFloatInterface\n");
if
(
!
useFloatInterface
&&
memType
==
MEMTYPE_FLOAT
)
{
// printf("gribapi write: convert float to double\n");
const
float
*
dataf
=
(
const
float
*
)
data
;
double
*
datad
=
(
double
*
)
Malloc
(
datasize
*
sizeof
(
double
));
for
(
size_t
i
=
0
;
i
<
datasize
;
++
i
)
datad
[
i
]
=
(
double
)
dataf
[
i
];
...
...
@@ -62,7 +69,7 @@ grb_encode(int filetype, int memType, int varID, int levelID, int vlistID, int g
nbytes
=
gribapiEncode
(
memTypeX
,
varID
,
levelID
,
vlistID
,
gridID
,
zaxisID
,
vDateTime
,
tsteptype
,
numavg
,
(
long
)
datasize
,
datap
,
nmiss
,
gribbuffer
,
&
gribbuffersize
,
comptype
,
gribContainer
);
if
(
/*!have_gribapi_f
loat
_i
nterface
()
&&
*/
memType
==
MEMTYPE_FLOAT
)
Free
((
void
*
)
datap
);
if
(
!
useF
loat
I
nterface
&&
memType
==
MEMTYPE_FLOAT
)
Free
((
void
*
)
datap
);
}
#else
{
...
...
@@ -379,6 +386,7 @@ grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, co
CdiDateTime
vDateTime
=
streamptr
->
tsteps
[
tsID
].
taxis
.
vDateTime
;
int
numavg
=
(
tsteptype
==
TSTEP_AVG
)
?
streamptr
->
tsteps
[
tsID
].
taxis
.
numavg
:
0
;
int
comptype
=
streamptr
->
comptype
;
int
datatype
=
vlistInqVarDatatype
(
vlistID
,
varID
);
if
(
CDI_Debug
)
Message
(
"gridID = %d zaxisID = %d"
,
gridID
,
zaxisID
);
...
...
@@ -394,8 +402,8 @@ grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, co
}
void
*
gribbuffer
=
NULL
;
size_t
nbytes
=
grb_encode
(
filetype
,
memtype
,
varID
,
levelID
,
vlistID
,
gridID
,
zaxisID
,
vDateTime
,
tsteptype
,
numavg
,
datasize
,
data
,
nmiss
,
&
gribbuffer
,
comptype
,
streamptr
->
gribContainers
);
size_t
nbytes
=
grb_encode
(
filetype
,
memtype
,
datatype
,
varID
,
levelID
,
vlistID
,
gridID
,
zaxisID
,
vDateTime
,
tsteptype
,
numavg
,
datasize
,
data
,
nmiss
,
&
gribbuffer
,
comptype
,
streamptr
->
gribContainers
);
if
(
filetype
==
CDI_FILETYPE_GRB
&&
(
comptype
==
CDI_COMPRESS_SZIP
||
comptype
==
CDI_COMPRESS_AEC
))
nbytes
=
grbSzip
(
filetype
,
gribbuffer
,
nbytes
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment