Page 18 - Demo
P. 18
Interface to C/C++%uf09f%uf09fRCPConsult2023-2025Page 1810.Built-in Accessto binary data containerTheC/C++interfaceprovides a set of built-in procedures for binding of external data, usually abinary container with a specific organisation. The most popular is MAT-filecreated by Matlab. Files with the %u201c. mat%u201d extension are files in the binary data container format that Matlabuses. The extension was developed by Mathworksand MAT files are categorized as data files that include variables, functions, arrays and other information.Also,the HDF5-filecreated by The HDF Group gets more popular now. The HDF5 technology is designed to organize, store, discover, access, analyse, share, and preserve diverse, complex data in continuously evolving heterogeneous computing and storage environments. The basic organisation of both binary formats is a directory of symbolic names given for a specific kind of corresponding linked data.The list of accessible functions/subroutines for binding of binary datalong long OpenBinaryDataFileInit(datafile)Open a MAT/HDF5 binary file and read all data fromdatafile (char*) %u2013filename having extension *.mat or *.h5Returns identifier (long long) ofopened data fileor 0 if error.void *GetBinaryDataFileVariable(fid, variable, m1, m2, bytes)Returns identifierofvariable data, dimensions and bytesof typefid (long long)%u2013identifier of data filevariable (char*)name of variable in directory of data filem1, m2 (longs)%u2013dimension of variable data arraybytes(long)%u2013size in bytes of variable data elementvoid CloseBinaryDataFile(fid)Closea MAT/HDF5 binary filefid (long long)%u2013identifier of data fileThe invoking of binary data file in the source file is very straightforward. First the data file must be opened and becomes an unique identifier.For examplelonglongfid=OpenBinaryDataFile(\orlonglongfid=OpenBinaryDataFile(\Next apointertodata array and corresponding dimensions and size in bytes for a variable of interest should be defined.longm1,m2,nb;double*mc=(double*)GetBinaryDataFileVariable(fid,\Now it is possible to reshape an array of variable to a real shape as is stored in data filedouble(&ar)[m2][m1]=*reinterpret cast(mc);%uf046The clcompiler does not allow usage of variablesinreinterpret_caststatement. Therefore it is necessary to get these values first using Data File Viewerof STRUREL. For example, m1=25 and m2=9.After it is possible to reshape an array of variable to a real shape as is stored in data filedouble(&ar)[9][25]=*reinterpret_cast(mc);Finally, after loadingdata from binary file it must be closed byCloseBinaryDataFile(fid);