Hi Cecilia
I am not sure about dynamically building a data type, but often the best
solution for a problem is the simplest.
I seems the user will choose an option for a data type to have his data , in
some input,
for example
in standard input by pressing a key 1 for integer or key 2 for float
in pseudo code
if key == 1 then
export_mydata_as_integer()
else if key == 2 then
export_mydata_as_float()
In H5NX, to define these 2 functions , you would use the following 2 vector
declarations
for integers
std::vector<int32_t> vec_data;
for floats
std::vector<float> vec_data;
then in each function call to save your vectorif
(h5nx.H5NXmake_dataset_vector("/", "dset", vec_data, vec_dim) < 0) { };
A complete example is here
http://www.space-research.org/nexus/h5nx_user.html
You can also ask in this forum , since this is not really a HDF5 issue, here's
a search for this issue
http://stackoverflow.com/questions/2834139/declaring-a-data-type-dynamically-in-c
------
Pedro Vicente, Earth System Science
University of California, Irvine
http://www.ess.uci.edu/
----- Original Message -----
From: Cecilia Herrera
To: [email protected]
Cc: 'Pedro Vicente'
Sent: Wednesday, April 17, 2013 1:11 AM
Subject: RE: [Hdf-forum] Different data types --- H5NX
Hello Pedro,
Thanks for your response.
I have a program where the user can choose one or more variables with
different data types to export. For example, name and age, which have string
and integer datatypes can be chosen. I do not know beforehand which variables,
what data types, and how many variables will be chosen. I have looked at
possibilities in HDF5 to do this, and think that the use of compound data type
is appropriate. The examples I found defined the structure of the data (e.g.
whether to have int or string in the first column, etc.) using "struct". For
example, in http://www.hdfgroup.org/ftp/HDF5/examples/misc-examples/cmpclass.c,
the "struct" is predefined at the start of the program (from line 15.).
However, for my application, I cannot predefine the structure, because it
depends on which variable the user will choose (can be a combination of
different types). Another option is to use strings for all variables (eg in my
example transforming the integer data type for age in a string), but the data
will take longer to export, and I would like to make the export speed as fast
as possible.
Would you know how I can attain what I want using compound data type or any
other way?
Thanks,
Cecilia
From: Pedro Vicente [mailto:[email protected]]
Sent: Wednesday, April 17, 2013 6:43 AM
To: HDF Users Discussion List
Cc: Cecilia Herrera
Subject: Re: [Hdf-forum] Different data types --- H5NX
Hello, Cecilia
>I would like to export large amounts of data in one file. The data variables
can be of different types; but it is not known beforehand what they are. I saw
examples where the Compound data type was used with a pre-defined "struct". In
this case, I cannot >pre-define my struct. I can ofcourse make everything
string, but I want to take advantage of the faster speed of writing other
types. How should I approach the problem? Do you have available examples? It
would also be nice to make use of the H5NX library >of Pedro Vicente for faster
speed, but I deal with 2D matrices and different data types.
It's not clear to me, from your description, the nature of the problem you're
trying to solve.
If you send further details I'll be glad to help.
Regarding the use of H5NX, this page
http://www.space-research.org/nexus/h5nx.html
has both links for
H5NX User's Guide
Detailed guide covering critical H5NX features
H5NX Reference Manual
Detailed C++ interface descriptions
>> but I deal with 2D matrices and different data types.
The H5NX function H5NXmake_dataset_vector deals with any rank, that is, you
can use it to define a 1D array, a 2D array, etc.
Just put your data values into a std::vector of any type and define the
dimensions in a std::vector<hsize_t>
If the size of this dimension vector is, say 2, then you have a matrix, or a
2D array.
Since this is C++, there is no need for an extra parameter to the function
with the size of the dimension vector (the rank)
int H5NXmake_dataset_vector(const std::string &group_path,
const std::string &dataset_name,
const std::vector<NumT> &vec,
const std::vector<hsize_t> &dim_vec);
The only function that currently deals exclusively with a 1D array is
H5NXappend_slab
Regarding the types, I am currently defining it for other types, I'll upload
a new version when done.
H5NX uses the HDF5 native types corresponding to the C99 fixed width integer
types plus the HDF5 string type, used in the "string" functions
int8_t
uint8_t
int16_t
uint16_t
int32_t
uint32_t
int64_t
uint64_t
float
double
but not all API functions have templates for all types.
What are your needs regarding these types and functions ?
Pedro
------
Pedro Vicente, Earth System Science
University of California, Irvine
http://www.ess.uci.edu/
----- Original Message -----
From: Cecilia Herrera
To: '[email protected]'
Sent: Monday, March 11, 2013 2:26 AM
Subject: [Hdf-forum] Different data types
I would like to export large amounts of data in one file. The data
variables can be of different types; but it is not known beforehand what they
are. I saw examples where the Compound data type was used with a pre-defined
"struct". In this case, I cannot pre-define my struct. I can ofcourse make
everything string, but I want to take advantage of the faster speed of writing
other types. How should I approach the problem? Do you have available
examples? It would also be nice to make use of the H5NX library of Pedro
Vicente for faster speed, but I deal with 2D matrices and different data types.
Thanks for the help!
----------------------------------------------------------------------------
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org