Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
Takin
core
Commits
5c638781
Verified
Commit
5c638781
authored
Nov 12, 2021
by
Tobias WEBER
Browse files
hdf5 test
parent
ea56e9fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
tools/test/tst_hdf.cpp
View file @
5c638781
...
...
@@ -3,8 +3,8 @@
* @author Tobias Weber <tobias.weber@tum.de>
* @date 9-apr-17
* @license GPLv2
*
* gcc
-lstdc++
-o tst_hdf tst_hdf.cpp -lstdc++ -lhdf5
*
* gcc -o tst_hdf tst_hdf.cpp -lstdc++ -lhdf5
*
* ----------------------------------------------------------------------------
* Takin (inelastic neutron scattering software package)
...
...
@@ -76,7 +76,7 @@ int main()
hid_t
file2
=
::
H5Fopen
(
"tst.hdf"
,
H5F_ACC_RDONLY
,
H5P_DEFAULT
);
if
(
file
1
<
0
)
if
(
file
2
<
0
)
{
std
::
cerr
<<
"Cannot open file."
<<
std
::
endl
;
return
-
1
;
...
...
tools/test/tst_hdf2.cpp
0 → 100644
View file @
5c638781
/**
* hdf test
* @author Tobias Weber <tweber@ill.fr>
* @date 12-nov-21
* @license GPLv2
*
* Reference: https://support.hdfgroup.org/HDF5/doc1.6/UG/11_Datatypes.html
*
* g++ -o tst_hdf2 tst_hdf2.cpp -lhdf5_serial
*
* ----------------------------------------------------------------------------
* Takin (inelastic neutron scattering software package)
* Copyright (C) 2017-2021 Tobias WEBER (Institut Laue-Langevin (ILL),
* Grenoble, France).
* Copyright (C) 2013-2017 Tobias WEBER (Technische Universitaet Muenchen
* (TUM), Garching, Germany).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* ----------------------------------------------------------------------------
*/
#include
<hdf5/serial/hdf5.h>
#include
<iostream>
#include
<vector>
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<=
1
)
{
std
::
cerr
<<
"Please specify a nexus/hdf5 file."
<<
std
::
endl
;
return
-
1
;
}
hid_t
file
=
::
H5Fopen
(
argv
[
1
],
H5F_ACC_RDONLY
,
H5P_DEFAULT
);
if
(
file
<
0
)
{
std
::
cerr
<<
"Cannot open file
\"
"
<<
argv
[
1
]
<<
"
\"
."
<<
std
::
endl
;
return
-
1
;
}
hid_t
data
=
::
H5Dopen
(
file
,
"/entry0/data_scan/scanned_variables/variables_names/name"
,
H5P_DEFAULT
);
if
(
data
<
0
)
{
std
::
cerr
<<
"Cannot open data."
<<
std
::
endl
;
return
-
1
;
}
hid_t
set
=
::
H5Dget_space
(
data
);
if
(
set
<
0
)
{
std
::
cerr
<<
"Cannot create data set."
<<
std
::
endl
;
return
-
1
;
}
int
iRank
=
::
H5Sget_simple_extent_ndims
(
set
);
std
::
vector
<
hsize_t
>
vecDim
(
iRank
);
::
H5Sget_simple_extent_dims
(
set
,
vecDim
.
data
(),
0
);
::
H5Sclose
(
set
);
std
::
cout
<<
"Rank: "
<<
iRank
<<
", dims: "
;
for
(
hsize_t
iDim
:
vecDim
)
std
::
cout
<<
iDim
<<
", "
;
std
::
cout
<<
std
::
endl
;
hid_t
type_id
=
::
H5Tcopy
(
H5T_C_S1
);
::
H5Tset_size
(
type_id
,
H5T_VARIABLE
);
hsize_t
num_strings
=
vecDim
[
0
];
//hvl_t *str = new hvl_t[num_strings];
const
char
**
str
=
new
const
char
*
[
num_strings
];
if
(
::
H5Dread
(
data
,
type_id
,
H5S_ALL
,
H5S_ALL
,
H5P_DEFAULT
,
str
)
<
0
)
{
std
::
cerr
<<
"Cannot read data."
<<
std
::
endl
;
return
-
1
;
}
for
(
hsize_t
i
=
0
;
i
<
num_strings
;
++
i
)
{
std
::
cout
<<
"String "
<<
i
<<
": "
<<
str
[
i
]
<<
std
::
endl
;
}
delete
[]
str
;
::
H5Dclose
(
data
);
::
H5Fclose
(
file
);
::
H5close
();
return
0
;
}
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