Getting data from a Fortran code into a VDC can be tricky business. At present an API for writing output directly from a Fortran program to a VDC is not supported. Hence, data must first be written out to an intermediary file, and subsequently translated to a VDC using either command line tools or another interface. The tricky part is in generating an intermediary file that the conversion utilities can understand. Two issues that arise are:
Two machine representations for binary floating point numbers are commonly found today: Little-endian (used by Intel processors) and Big-endian (used by most everybody else). If the raw data file generated by your simulation code was produced on a machine different from the one you are creating your VDC on, there may be an endian mismatch. Fortunately, this is easily resolved by using either the –swapbyte switch, if using the raw2vdf command line utility, or using the /SWAP_ENDIAN, /SWAP_IF_LITTLE_ENDIAN, or SWAP_IF_BIG_ENDIAN open procedure keywords, if using the IDL language extensions, provided by VAPOR, to translate your data.
Creating a raw data file from Fortran - one containing binary data with no header or trailer – requires more effort than it should. Common practice among many Fortran programmers is to write binary data as an unformatted, sequential file. Unfortunately, on UNIX systems this results in the inclusion of a data header and/or trailer. Care must be taken if the header is to be avoided. The code snippet below demonstrates how to write a contiguous volume of data (3d array) as a raw file:
program computeraw
implicit none
integer :: nx, ny, nz
integer(kind=8) :: rec_len
integer :: i,j,k
parameter(nx = 100, ny = 20, nz = 50)
real, dimension(nx,ny,nz) :: array
do i=1,nx
do j=1,ny
do k=1,nz
array(i,j,k) = (i+j+k)
end do
end do
end do
inquire (IOLENGTH=rec_len) array
open(1,file='myarray.raw',status = 'unknown',
form='unformatted', access='direct',recl=rec_len)
write(1,rec=1) array
close(1)
The resulting file, myarray.raw, may now be translated using, for example, the command line utility raw2vdf.