EBF I/O in Fortran (95/2003)
A brief description of the subroutines and functions of Fortran API are given below. Additionally, an example program making use of them is given in the end. For further details one can refer to the link on the top of this page or click on the routines themselves.
Following each routine the input, output paramaters are given. Optional parameters, along with their default values are shown as paramater=value. Here, x refers to a variable which is being read or written. It can be
- an integer of kind=1, 2, 3 and 4
- a real of kind=4 and 8
- of shape (:), (:, :) or (:, :, :), i.e., one, two or three dimensional array.
A worked out example is given here ebf_demo.f90 . (click to see source code)
The code has been tested on 64 bit ubuntu machine using gfortran(4.4.3) compiler. For other platforms it is strongle advised to run the test module before using ebf. The tests check for compatibility of data types. A file named test_master1.ebf containing pre defined values in various data types is also used by the test module to check if the data can be read correctly.
For I/O ebf uses file access mode "stream" which is probably not available for all fortran compilers. Other fortran features which the code uses are elemental functions and allocatable arrays. Note, for endian conversion ebf makes use of a module named Endian_Utility written by Paul van Delst.
The module ebf is the gateway for the user to the ebf library. All routines that the user needs are made availble through this module and are listed below. Note, internally some routines might be in different module but they are still exported through module ebf.
- subroutine ebf::ebf_info (filename)
Get a summary of contents of an ebf file
- character, intent(in) :: filename*(*)
- subroutine ebf::ebf_write (filename, dataname, x, mode="w", dataunit="")
Write an array or a scalar variable to an ebf file
- character, intent(in) :: filename*(*), dataname*(*)
- dtype, dimension(dshape), intent( in ) :: x
- character, intent(in), optional :: mode*(*), dataunit*(*)
- subroutine ebf::ebf_read (filename, dataname, x, dinfo=)
Read data from an ebf file into an allocatable array or a scalar variable
- character , intent(in) :: filename*(*), dataname*(*)
- dtype, dimenion(dshape),intent(inout) :: x
- type(ebfdatainfo), intent(inout), optional :: dinfo
- function ebf::ebf_containskey (filename,dataname)
Check if a data object with a given name is present in an ebf file
- character ,intent(in) :: filename*(*),dataname*(*)
- logical containsKey
- function ebf::ebf_containskey (filename,dataname,dinfo)
Check if a data object with a given name is present in an ebf file returns true if item is present or false if there is an error in locating item dinfo can queried for information about data, like data units, elements and so on.
- character ,intent(in) :: filename*(*),dataname*(*)
- type(ebfdatainfo), intent(inout), optional :: dinfo
- subroutine ebf::ebffile_open (efile, filename, dataname, mode="r", datatype=0, dataunit="", dims=ALLOCATE(dims(1)))
Open and ebf-file to perform read write operations mode could be "w" , "a" or "r" corresponding to write append and read modes.
- type(ebffile), intent(inout) :: efile
- character , intent(in) :: filename*(*), dataname*(*)
- character , intent(in), optional :: mode*(*)
- integer , intent(in), optional :: datatype
- character , intent(in), optional :: dataunit*(*)
- integer (kind=8), dimension(:), intent(in), optional :: dims
- integer(kind=8) function ebfbase::ebfheader_elements ( ebfh )
get the total number of elements from an ebfheader of the data object Usage, elements(ebfh) or elements(efileebfh)
- type(ebfheader),intent(in):: ebfh
- integer i
- subroutine ebf::ebffile_read (efile, x, loc)
Read into array x ,elements loc to loc+size(x), from an ebf-file opened with efile_open. The file pointer is advanced to then end of last read element and can be used sequentially to read the next items
- dtype, dimension(dshape), intent( inout) :: x
- type(ebffile),intent(inout):: efile
- integer (kind=8),optional,intent(in):: loc
- subroutine ebf::ebffile_write (efile, x)
Write size(x) elements of array x to an ebf-file opened with efile_open.
- dtype, dimension(dshape), intent( inout) :: x
- type(ebffile),intent(inout):: efile
- subroutine ebf::ebffile_close (efile)
Close an ebf-file after a read or write operation. The first dimension in ebf file (for fortran it is last dim) is adjusted to match the number of items written.
- type(ebffile),intent(inout):: efile
- integer(kind=4) function ebf::ebf_typev (x)
gives the EBF integer type code of the data type of x
- integer(kind=4) function ebf::ebf_types (name)
gives the EBF integer type code of the data type as specified by a named string Caution! do not use ebf_typev(name) by mistake as it would be wrong and would give type code 1, implying a character type
- name a string specifying the data type could be either of the following char, int4 , int16, int32, int64, real32, real64
- type ebf::ebffile A structure used for partial I/O It contains an ebfheader field named ebfh which among other things can be queried for
- dataunit efile%ebfhdataunit
- rank efile%ebfhrank
- dims efile%ebfhdims(i)
- type ebfbase::ebfheader a structure conataining header of the data object which among other things can be quiried for
- dataunit efile%ebfhdataunit
- rank efile%ebfhrank
- dims efile%ebfhdims(i)
- type ebf::ebfdatainfo a structure conataining information about the data object.This can be quiried for character(len=ebf_keyname_maxsize)dataunit integer (kind=4):: ecode,datatype, datasize, rank integer (kind=8):: headerpos,elements integer (kind=8):: dims(8) end type ebfdatainfo