LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hdf5 Problems using hdf5dll.dll directly

Hi,
I've some problems to implement hdf5 operations (like create an attribute, an dataset) in LabView 8.5.
 
For example, I want to create a hdf5 file and then I want to close it (very basic, I know). The c-example for this is this:
-------------------------------------------------------------------------------
/*
 *    Creating and closing a file.
 */
#include "hdf5.h"
#define FILE "file.h5"
int main() {
   hid_t       file_id;   /* file identifier */
   herr_t      status;
   /* Create a new file using default properties. */
   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
   /* Terminate access to the file. */
   status = H5Fclose(file_id);
}
-------------------------------------------------------------------------------
 
I understand this c code, but I don't know how to define an access mode "H5F_ACC_TRUNC", e.g., in Labview in the "Call Library Function Node"!?
I've attached an example hdf5Test.vi . You have to download the hdf5dll.dll file from http://hdfgroup.com/HDF5/release/obtain5.html -> HDF5-1.8.0 Software -> "windows" to make the VI runnable.
But maybe you can give me a hint.
The VI works but I don't understand how to set the hdf5 parameters right.
 
You can see the in the Function Node -> Configuration -> Parameters how I tried to set the parameters H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT , but I think that's wrong 😞
 
Please give me some ideas
Thanks
Hans
 
0 Kudos
Message 1 of 8
(5,989 Views)
Many of the HDF5 #defines are macros, not constants, which makes it difficult to use them from LabVIEW.  The standard way to deal with this issue is to write a C/C++ wrapper that translates the macro to a simple integer, export that subroutine, then call that from LabVIEW.  The C code would look something like
 
subroutine translateHDF5#define ( int inputNumber){
 
switch ( inputNumber){
  case: HDF5#define1
    return 0;
  case: HDF5#define2
    return 1;
.
.
.
}
 
The old HDF5 1.4.4 code on the NI website includes such a translator DLL.  Note that HDF5 1.6.x introduced a lot more macros, so the 1.4.4 wrapper will not work for 1.6.0 and above.
 
 
0 Kudos
Message 2 of 8
(5,984 Views)

Thank you very much for your reply!

I'll try to use the way with the C/C++ wrapper.

 

Best regards
Hans

0 Kudos
Message 3 of 8
(5,964 Views)

In looking back at my reply, I realize I swithed the HDF5 #define and input index numbers.  The subroutine should return the HDF5 #define and switch on the input index.

Good luck.  Let us know if you run into problems.  Note that at least two other people have done this.  Here are a couple of links.

http://forums.ni.com/ni/board/message?board.id=170&message.id=241522&query.id=117745#M241522

http://www.me.mtu.edu/researchAreas/isp/lvhdf5/

0 Kudos
Message 4 of 8
(5,954 Views)
I found out that these specific HDF5 variables (for example "H5F_ACC_TRUNC" for method "H5Fcreate") are only some numeric constants which are defined in the hdf5 c++ header files (for example "H5Fpublic.h"):
"
.....
#define H5F_ACC_RDONLY (H5CHECK 0x0000u) /*absence of rdwr => rd-only */
#define H5F_ACC_RDWR (H5CHECK 0x0001u) /*open for read and write */
#define H5F_ACC_TRUNC (H5CHECK 0x0002u) /*overwrite existing files */
#define H5F_ACC_EXCL (H5CHECK 0x0004u) /*fail if file already exists*/
#define H5F_ACC_DEBUG (H5CHECK 0x0008u) /*print debug info */
#define H5F_ACC_CREAT (H5CHECK 0x0010u) /*create non-existing files */
...
"
So I defined the according parameter as a normal labview numeric (unsigned hex 0x0002u as I32 value=2) in the "Call Function Library Node" and it works.

But I've some problems to create a hdf5 datatype (methods "H5Tcreate" or "H5Tcopy")! In the header file "H5Tpublic", for example, the standard datatype for I32 big endian is defined as follows:
"...
/*
* These are "standard" types. For instance, signed (2's complement) and
* unsigned integers of various sizes and byte orders.
*/
#define H5T_STD_I8BE (H5OPEN H5T_STD_I8BE_g)
#define H5T_STD_I8LE (H5OPEN H5T_STD_I8LE_g)
#define H5T_STD_I16BE (H5OPEN H5T_STD_I16BE_g)
#define H5T_STD_I16LE (H5OPEN H5T_STD_I16LE_g)
#define H5T_STD_I32BE (H5OPEN H5T_STD_I32BE_g)
#define H5T_STD_I32LE (H5OPEN H5T_STD_I32LE_g)
....
H5_DLLVAR hid_t H5T_STD_I32BE_g;
...
"

In Labview in the "Call Function Library Node" (hdf5dll.dll) I can select a H5T_STD_I32BE_g operation (method? variable?) but I don't know how to use this operation (input and output paramters?) with the H5Tcopy function, e.g. 😞
There is also a h5open function in the dll, maybe this also helps.

I also found an ADA example where a similar hdf5 standard variable was imported by this way:
"...
H5T_STD_I32BE_g : Hid_t;
pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");
..."
But how can I do this with the "Call Function Library Node" in Labview?

Can you give me a hint?
Thanks
Hans

0 Kudos
Message 5 of 8
(5,941 Views)

This is a clean example of needing the wrapper function I mentioned above.  The #defines for the Type are C macros, which cannot be accessed using the call Library node.  In this case, to get the integer Type specifier, you need to write something like this:

int getType ( int enumValue ) {
 
  case: 0
    return H5T_STD_I8BE;
  case: 1
    return H5T_STD_I8LE;
  case: 2
    return H5T_STD_I16BE;
  case: 3
    return H5T_STD_I16LE;
  case: 4
    return H5T_STD_I32BE;
  case: 5
    return  H5T_STD_I32LE;
 default:
   return 0;
}
 
Call this from the call library node.  The input should be an enum you design so the text values are something like the HDF5 specifiers (e.g. H5T_STD_I8BE).  Use the output as the input to any HDF5 function which requires a type specifier.
0 Kudos
Message 6 of 8
(5,934 Views)

Yes, but my problem is that I have only a Visual C++ 2005 Express Edition and this edition can't create a DLL project.

Or can you tell me how can I export this wrapper function from Visual c++ 2005 to Labview without a DLL project?

Thanks
Hans

0 Kudos
Message 7 of 8
(5,930 Views)
If you can't make a DLL, then it would be difficult to call a shared library from LabVIEW.  The easiest option is to use an open source compiler to create your wrapper library.  Since the wrapper is pretty simple, it shouldn't be too difficult to create it without the full development environment you get with Visual Studio.  gcc certainly supports this functionality.  You may be able to generate your object code with Visual Studio then convert it to a DLL with gcc, however, I have never tried this.  Check out this page for making DLLs with gcc.
0 Kudos
Message 8 of 8
(5,922 Views)