Page 21 - Demo
P. 21


                                    Interface to FORTRAN%uf09f %uf09f RCP Consult 2023-2025 Page 2110.Built-in Access to binary data containerThe FORTRAN interface provides a set of built-in procedures for binding of external data, usually a binary container with a specific organisation. The most popular is MAT-file created by Matlab. Files with the %u201c. mat%u201d extension are files in the binary data container format that Matlab uses. The extension was developed by Mathworks and 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 dataOpenBinaryDataFileInit(datafile)Open a MAT/HDF5 binary file and read all data fromdatafile (character) %u2013 filename having extension *.mat or *.h5Returns identifier (integer*8) of opened data file or 0 if error.GetBinaryDataFileVariable(fid, variable, m1, m2, bytes)Returns identifier of variable data, dimensions and bytes of typefid (integer*8) %u2013 identifier of data filevariable (character) %u2013 name of variable in directory of data filem1, m2 (integers) %u2013 dimension of variable data arraybytes (integer) %u2013 size in bytes of variable data elementCloseBinaryDataFile(fid)Close a MAT/HDF5 binary filefid (integer*8) %u2013 identifier of data fileThe invoking of binary data file in the source file is very straightforward. First you need prepare all required variables and their types in declarative part of function or subroutine. For example, if you process double precision data from a data file it looks like integer*8 fid ! identifier of data file real*8 ar(1) ! array of interest to be used integer*8 id ! identifier of array for variable integer m1,m2,nb ! dimensions and size of array element pointer(id,ar) ! binding of variable data with array real*8, allocatable::cr(:,:) ! declaration of array for reshapingIn the executable part of function or subroutine the data file must be opened and becomes an unique identifier. For example fid=OpenBinaryDataFile(\! filename must be null terminatedor fid=OpenBinaryDataFile(\! filename must be null terminatedNext an identifier of data array and corresponding dimensions and size in bytes for a variable of interest should be defined. id=GetBinaryDataFileVariable(fid,\! varname must be null terminatedNow it is possible to reshape an array of variable to a real shape as is stored in data file cr=reshape(ar, (/m1, m2/)) ! cr array will now be declared as cr(m1,m2)Finally, after loading data from binary file it must be closed by call CloseBinaryDataFile(fid)
                                
   15   16   17   18   19   20   21