fortio
A Fortran library intended to simplify read/write operations on unformatted binary files and text files.
Status
Example 1
The following example illustrates the writing and reading of an unformatted binary file.
program example
use, intrinsic :: iso_fortran_env
use fortio_binary
implicit none
! Define a few things to stuff into a file
character(len = :), parameter :: fname = "example_1.bin"
character(len = :), parameter :: txt1 = "Example 1"
real(real64), parameter :: d1= 0.5d0
real(real32), parameter :: s1 = -1.23
complex(real64), parameter :: c1 = (0.25d0, -0.75d0)
! Local Variables
integer(int32) :: i, n
character(len = :), allocatable :: txt
real(real64) :: d_in
real(real32) :: s_in
complex(real64) :: c_in
! Define the writer and reader objects
type(binary_writer) :: writer
type(binary_reader) :: reader
! Write the file
call writer%open(fname)
call writer%write(len(txt1)) ! Define the length of the string (TXT1)
call writer%write(txt1)
call writer%write(d1)
call writer%write(s1)
call writer%write(c1)
! Close the file
call writer%close()
! Read the file
call reader%open(fname)
n = reader%read_int32()
allocate(character(len = n) :: txt)
do i = 1, n
txt(i:i) = reader%read_char()
end do
print '(A)', "Read in string: " // txt // ", Expected: " // txt1
d_in = reader%read_real64()
print '(AF5.3AF5.3)', "Read in value: ", d_in, ", Expected: ", d1
s_in = reader%read_real32()
print '(AF6.3AF6.3)', "Read in value: ", s_in, ", Expected: ", s1
c_in = reader%read_complex64()
print '(AF5.3AF6.3AF5.3AF6.3A)', "Read in value: (", real(c_in, real64), &
", ", aimag(c_in), "), Expected: (", real(c1, real64), ", ", &
aimag(c1), ")"
! Close the file
call reader%close()
end programThe above program produces the following output.
Read in string: Example 1, Expected: Example 1
Read in value: 0.500, Expected: 0.500
Read in value: -1.230, Expected: -1.230
Read in value: (0.250, -0.750), Expected: (0.250, -0.750)
Documentation
Documentation can be found here.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
