Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
alta
alta
Commits
5219ee9d
Commit
5219ee9d
authored
May 12, 2015
by
Ludovic Courtès
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
data: Add 'save_data_as_binary'.
parent
b3d65baf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
sources/core/data_storage.cpp
sources/core/data_storage.cpp
+37
-0
sources/core/data_storage.h
sources/core/data_storage.h
+3
-0
No files found.
sources/core/data_storage.cpp
View file @
5219ee9d
...
...
@@ -15,6 +15,10 @@
#include <iostream>
#include <limits>
#ifdef __GLIBC__
# include <endian.h>
#endif
void
vertical_segment
::
load_data_from_text
(
std
::
istream
&
input
,
vertical_segment
&
result
,
const
arguments
&
args
)
...
...
@@ -241,3 +245,36 @@ void save_data_as_text(std::ostream& out, const data &data)
out
<<
std
::
endl
;
}
}
void
save_data_as_binary
(
std
::
ostream
&
out
,
const
data
&
data
)
{
out
<<
"#DIM "
<<
data
.
dimX
()
<<
" "
<<
data
.
dimY
()
<<
std
::
endl
;
out
<<
"#PARAM_IN "
<<
params
::
get_name
(
data
.
input_parametrization
())
<<
std
::
endl
;
out
<<
"#PARAM_OUT "
<<
params
::
get_name
(
data
.
output_parametrization
())
<<
std
::
endl
;
out
<<
"#FORMAT binary"
<<
std
::
endl
;
out
<<
"#VERSION 0"
<<
std
::
endl
;
out
<<
"#PRECISION ieee754-double"
<<
std
::
endl
;
out
<<
"#SAMPLE_COUNT "
<<
data
.
size
()
<<
std
::
endl
;
// FIXME: Note: on non-glibc systems, both macros may be undefined, so
// the conditional is equivalent to "#if 0 == 0", which is usually what
// we want.
#if __BYTE_ORDER == __LITTLE_ENDIAN
out
<<
"#ENDIAN little"
<<
std
::
endl
;
#else
out
<<
"#ENDIAN big"
<<
std
::
endl
;
#endif
out
<<
"#BEGIN_STREAM"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
data
.
size
();
++
i
)
{
vec
sample
=
data
.
get
(
i
);
const
double
*
numbers
=
sample
.
data
();
assert
(
sample
.
size
()
==
data
.
dimX
()
+
data
.
dimY
());
out
.
write
((
const
char
*
)
numbers
,
sample
.
size
()
*
sizeof
(
*
numbers
));
}
out
<<
std
::
endl
<<
"#END_STREAM"
<<
std
::
endl
;
}
sources/core/data_storage.h
View file @
5219ee9d
...
...
@@ -15,3 +15,6 @@
// Write DATA to OUT in ALTA's text format.
void
save_data_as_text
(
std
::
ostream
&
out
,
const
data
&
data
);
// Write DATA to OUT in a compact binary format.
void
save_data_as_binary
(
std
::
ostream
&
out
,
const
data
&
data
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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