When reading files created by a Fortran program, you need to be aware of the exact datatypes that were used to write the data. It is essential to specify the correct corresponding Julia datatype when using the
read function provided by this package. Especially, note that the default Fortran
INTEGER datatype on most systems corresponds to Julia's
Int32 datatype, which differs from Julia's default
Int datatype on 64-bit systems.
Likewise, when using this package to write Julia data into files which should be readable by a Fortran program, you need to define your data with the correct datatypes, or convert them appropriately before using them in the
The following table lists the Julia types which correspond to the standard Fortran types:
The first column lists the datatypes using the kind parameters according to the Fortran2008 standard. Most Fortran programs will likely use type declarations as in the second column, although these don't conform to the Fortran standard. If the Fortran program doesn't specify the kind, then the exact Fortran datatype also depends on the compiler options (which can influence the default kind of integers and reals).
This package currently only supports one kind of
CHARACTER data, namely ASCII characters with one byte of storage per character.
Fortran character strings possess an inherent length property. To support reading and writing such data, this package defines an
FString datatype which takes the length as a type parameter:
Datatype for reading and writing character strings from
FortranFiles. The type parameter
L signifies the length of the string. This is the equivalent to the Fortran datatype
Convert the Julia
s to an
s must contain only ASCII characters. As in Fortran, the string will be padded with spaces or truncated in order to reach the desired length.
There is not much you can do with
writeing them back to a
FortranFile. For conversion to a Julia
String, use the following:
s into a Julia
String, where trailing spaces are removed. Use
String(s) to keep the spaces.
To make it easier to convert Fortran code into Julia, the following functions are provided for convenience:
Returns the length of the
s with trailing spaces ignored.
Returns a truncated copy of the
s where all trailing spaces are removed.
It is currently undecided how best to support I/O of Fortran
LOGICAL data, pending some design decisions.
For the moment, such data can be read or written by treating them as integer data, where 0 corresponds to
false and 1 or -1 corresponds to
true (depending on the Fortran system). According to the Fortran standard, the storage size for the default
LOGICAL kind must be the same as for the default
INTEGER kind, therefore you probably want to use Int32 data in Julia.