getting stared with HDF5 on Visual Studio 2013 with Visual C++ 2013 -
i having hard time getting hdf5 illustration working visual studio 2013 (c++). illustration at: http://www.hdfgroup.org/ftp/hdf5/examples/misc-examples/stratt.cpp , i've posted code below completeness.
my first question is: latest hdf5 (version 1.8.13) work visual c++ 2013? docs mention 2012 can see, i've had no problems using 2013 2012 mentioned.
i tried illustration programme both 32 bit , 64 bit app. ultimately, i'm interested in 64 bit. in project settings 32 bit, under vc++ settings, added include directories: c:\program files (x86)\hdf_group\hdf5\1.8.13\include library directories, added: c:\program files (x86)\hdf_group\hdf5\1.8.13\lib
to linker->input, added: hdf5.lib;hdf5_cpp.lib when ran, (not unexpectedly) got message, "the programme can't start because hdf5.dll missing computer..." debug directory, added, hdf5.dll , hdf5_cpp.dll directory: c:\program files (x86)\hdf_group\hdf5\1.8.13\bin
i runtime error:
the application unable start correctly (0xc000007b). click ok close application. ideas?
incidentally, when tried x64 bit version (using 64 bit setttings, directories , files), got different errors. programme runs end, no attribute written console, no file produced, , dreaded error @ end (after hitting f10 on lastly line):
unhandled exception @ 0x000007fef05e512d (msvcp120d.dll) in hdf5attributeexample2.exe: 0xc0000005: access violation reading location 0xffffffffffffffff.
in both cases (32 , 64 bit) gut tells me have sort of configuration problem (wrong lib, wrong setup, etc.) i'd appreciate help or suggestions folks can offer.
if there visual c++ hdf5 example, means please tell me!
thanks,
dave
#include <string> #include <iostream> #include "h5cpp.h" using std::cout; using std::endl; using namespace h5; const h5std_string file_name("string_test.h5"); const h5std_string ds_name("data set 1"); const h5std_string attr_name("string attribute"); int main(void) { // create named file h5file file = h5file(file_name, h5f_acc_trunc); // create new dataspace dataset const int rank = 3; const int dim1 = 2; const int dim2 = 2; const int dim3 = 2; hsize_t dims[rank] = { dim1, dim2, dim3 }; dataspace dataspace = dataspace(rank, dims); // create new datatype dataset floattype datatype(predtype::native_float); // create dataset dataset dataset = file.createdataset(ds_name, datatype, dataspace); // set write buffer 'matrix' int q, r, s; float value; float matrix[dim1][dim2][dim3]; (q = 0; q < dim1; q++) (r = 0; r < dim2; r++) (s = 0; s < dim3; s++) { value = 1.111 + (q * r * s); matrix[q][r][s] = value; } // write info dataset dataset.write(matrix, datatype); // create new dataspace attribute dataspace attr_dataspace = dataspace(h5s_scalar); // create new string datatype attribute strtype strdatatype(predtype::c_s1, 256); // of length 256 characters // set write buffer attribute const h5std_string strwritebuf("this attribute of type strtype"); // create attribute , write attribute myatt_in = dataset.createattribute(attr_name, strdatatype, attr_dataspace); myatt_in.write(strdatatype, strwritebuf); // set read buffer attribute h5std_string strreadbuf(""); // open attribute , read contents attribute myatt_out = dataset.openattribute(attr_name); myatt_out.read(strdatatype, strreadbuf); // display attribute contents cout << "attribute contents: " << strreadbuf << endl; homecoming 0; }
doesn't many people interested in hdf5 visual c++ judging number of views. perhaps should warning me! in case, posterity offer next answers original question.
first of all, 1 needs careful path variable right in environments settings , set correctly 32 bit or 64 bit depending on want. instead of: c:\program files (x86)\hdf_group\hdf5\1.8.13\bin have: c:\program files (x86)\hdf group\hdf5\1.8.13\bin (notice missing underscore)
additionally, 1 has pay attending want 32 bit (use programme file (x86)) or 64 bit (use programme files). if knows of easier way run 32 bit , 64 bit programs on same machine utilize hdf5, please allow me know.
the other major problem illustration code itself. in it's original form, did not work. after much trial , error, tracked problem downwards utilize of h5std_string. when replaced these char [], worked. example, instead of using: const h5std_string file_name("string_test.h5"); used: char filename[128] = "string_test.h5"; , used h5file constructor so: h5file file = h5file(filename, h5f_acc_trunc); it's annoying didn't compile time error. constructor claims take std::string (which h5std_string is) in constructor h5file. quite possibly, there visual studio setting somewhere makes things original code work. i'm not knowledgeable plenty visual c++ know.
anyhow luck all.
dave
visual-c++ visual-studio-2013 hdf5
No comments:
Post a Comment