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
8477be05
Commit
8477be05
authored
Nov 18, 2015
by
Uwe Schulzweida
Browse files
streamWriteRecordF: added fall back to double precision writing
parent
446684ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/stream_fcommon.c
View file @
8477be05
...
...
@@ -5,10 +5,9 @@
#include
"file.h"
#include
"stream_fcommon.h"
void
streamFCopyRecord
(
stream_t
*
streamptr2
,
stream_t
*
streamptr1
,
const
char
*
container_name
)
{
void
streamFCopyRecord
(
stream_t
*
streamptr2
,
stream_t
*
streamptr1
,
const
char
*
container_name
)
{
int
fileID1
=
streamptr1
->
fileID
;
int
fileID2
=
streamptr2
->
fileID
;
...
...
src/stream_write.c
View file @
8477be05
#if
def
ined (
HAVE_CONFIG_H
)
#
include "config.h"
#ifdef
HAVE_CONFIG_H
#include
"config.h"
#endif
#include
"cdi.h"
...
...
@@ -9,6 +9,7 @@
#include
"stream_srv.h"
#include
"stream_ext.h"
#include
"stream_ieg.h"
#include
"dmemory.h"
#include
"namespace.h"
...
...
@@ -304,8 +305,12 @@ cdiStreamWriteVarChunk_(int streamID, int varID, int memtype,
}
static
void
stream_write_record
(
int
streamID
,
int
memtype
,
const
void
*
data
,
int
nmiss
)
int
stream_write_record
(
int
streamID
,
int
memtype
,
const
void
*
data
,
int
nmiss
)
{
// May fail if memtype == MEMTYPE_FLOAT and the file format does not support single precision writing.
// A value > 0 is returned in this case, otherwise it returns zero.
int
status
=
0
;
check_parg
(
data
);
stream_t
*
streamptr
=
stream_to_pointer
(
streamID
);
...
...
@@ -320,19 +325,19 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss)
#endif
#if defined (HAVE_LIBSERVICE)
case
FILETYPE_SRV
:
if
(
memtype
==
MEMTYPE_FLOAT
)
Error
(
"srvWriteRecord not implemented for memtype float!"
)
;
if
(
memtype
==
MEMTYPE_FLOAT
)
return
1
;
srvWriteRecord
(
streamptr
,
(
const
double
*
)
data
);
break
;
#endif
#if defined (HAVE_LIBEXTRA)
case
FILETYPE_EXT
:
if
(
memtype
==
MEMTYPE_FLOAT
)
Error
(
"extWriteRecord not implemented for memtype float!"
)
;
if
(
memtype
==
MEMTYPE_FLOAT
)
return
1
;
extWriteRecord
(
streamptr
,
(
const
double
*
)
data
);
break
;
#endif
#if defined (HAVE_LIBIEG)
case
FILETYPE_IEG
:
if
(
memtype
==
MEMTYPE_FLOAT
)
Error
(
"iegWriteRecord not implemented for memtype float!"
)
;
if
(
memtype
==
MEMTYPE_FLOAT
)
return
1
;
iegWriteRecord
(
streamptr
,
(
const
double
*
)
data
);
break
;
#endif
...
...
@@ -352,6 +357,8 @@ void stream_write_record(int streamID, int memtype, const void *data, int nmiss)
break
;
}
}
return
status
;
}
/*
...
...
@@ -374,8 +381,23 @@ void streamWriteRecord(int streamID, const double *data, int nmiss)
stream_write_record
(
streamID
,
MEMTYPE_DOUBLE
,
(
const
void
*
)
data
,
nmiss
);
}
void
streamWriteRecordF
(
int
streamID
,
const
float
*
data
,
int
nmiss
)
{
stream_write_record
(
streamID
,
MEMTYPE_FLOAT
,
(
const
void
*
)
data
,
nmiss
);
if
(
stream_write_record
(
streamID
,
MEMTYPE_FLOAT
,
(
const
void
*
)
data
,
nmiss
)
)
{
// In case the file format does not support single precision reading,
// we fall back to double precision writing, converting the data on the fly.
stream_t
*
streamptr
=
stream_to_pointer
(
streamID
);
int
tsID
=
streamptr
->
curTsID
;
int
vrecID
=
streamptr
->
tsteps
[
tsID
].
curRecID
;
int
recID
=
streamptr
->
tsteps
[
tsID
].
recIDs
[
vrecID
];
int
varID
=
streamptr
->
tsteps
[
tsID
].
records
[
recID
].
varID
;
size_t
elementCount
=
(
size_t
)
gridInqSize
(
vlistInqVarGrid
(
streamInqVlist
(
streamID
),
varID
));
double
*
conversionBuffer
=
(
double
*
)
Malloc
(
elementCount
*
sizeof
(
*
conversionBuffer
));
for
(
size_t
i
=
elementCount
;
i
--
;
)
conversionBuffer
[
i
]
=
(
double
)
data
[
i
];
stream_write_record
(
streamID
,
MEMTYPE_DOUBLE
,
(
const
void
*
)
conversionBuffer
,
nmiss
);
Free
(
conversionBuffer
);
}
}
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