Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TurTLE
TurTLE
Commits
395528bd
Commit
395528bd
authored
Nov 05, 2019
by
Cristian Lalescu
Browse files
adds hdf5 single value write method
parent
630e7e8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
cpp/hdf5_tools.cpp
View file @
395528bd
...
...
@@ -169,6 +169,36 @@ number hdf5_tools::read_value(
return
result
;
}
template
<
typename
number
>
int
hdf5_tools
::
write_value_with_single_rank
(
const
hid_t
group
,
const
std
::
string
dset_name
,
const
number
value
)
{
hid_t
dset
,
mem_dtype
;
if
(
typeid
(
number
)
==
typeid
(
int
))
mem_dtype
=
H5Tcopy
(
H5T_NATIVE_INT
);
else
if
(
typeid
(
number
)
==
typeid
(
double
))
mem_dtype
=
H5Tcopy
(
H5T_NATIVE_DOUBLE
);
if
(
H5Lexists
(
group
,
dset_name
.
c_str
(),
H5P_DEFAULT
))
{
dset
=
H5Dopen
(
group
,
dset_name
.
c_str
(),
H5P_DEFAULT
);
}
else
{
hid_t
fspace
;
hsize_t
count
[
1
];
count
[
0
]
=
1
;
fspace
=
H5Screate_simple
(
1
,
count
,
NULL
);
dset
=
H5Dcreate
(
group
,
dset_name
.
c_str
(),
mem_dtype
,
fspace
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
H5Sclose
(
fspace
);
}
H5Dwrite
(
dset
,
mem_dtype
,
H5S_ALL
,
H5S_ALL
,
H5P_DEFAULT
,
&
value
);
H5Dclose
(
dset
);
H5Tclose
(
mem_dtype
);
return
EXIT_SUCCESS
;
}
template
<
typename
dtype
>
std
::
vector
<
dtype
>
hdf5_tools
::
read_vector_with_single_rank
(
const
int
myrank
,
...
...
@@ -269,3 +299,15 @@ double hdf5_tools::read_value<double>(
const
hid_t
,
const
std
::
string
);
template
int
hdf5_tools
::
write_value_with_single_rank
<
int
>(
const
hid_t
group
,
const
std
::
string
dset_name
,
const
int
value
);
template
int
hdf5_tools
::
write_value_with_single_rank
<
double
>(
const
hid_t
group
,
const
std
::
string
dset_name
,
const
double
value
);
cpp/hdf5_tools.hpp
View file @
395528bd
...
...
@@ -84,6 +84,12 @@ namespace hdf5_tools
number
read_value
(
const
hid_t
group
,
const
std
::
string
dset_name
);
template
<
typename
number
>
int
write_value_with_single_rank
(
const
hid_t
group
,
const
std
::
string
dset_name
,
const
number
value
);
}
#endif//HDF5_TOOLS_HPP
...
...
Write
Preview
Supports
Markdown
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