Fortran Wiki
Posix90

Posix90 provides a very complete Fortran 90 POSIX interface.

The documentation will be built automatically upon running make, which builds the library and produces and HTML and PDF documentation in the /doc subdirectory.


Examples

Directory Listing

Routines for reading the contents of directories f90_unix_dirent module (opendir, closedir, readdir, etc.). Here is a simple example:

program ls_posix90
  use f90_unix_dirent
  implicit none

  type(DIR) :: dirp
  integer :: errno, name_len
  character(LEN=128) :: name

  call opendir('/home/jrblevin', dirp)
  do
     call readdir(dirp, name, name_len)
     if (name_len > 0) then
        print *, name(1:name_len)
     else
        exit
     end if
  end do
  call closedir(dirp)
end program ls_posix90

To compile and link the program with GFortran (after building Posix90 in directory $POSIX90):

$ gfortran -I$POSIX90 -o ls_posix90 ls_posix90.f90 -L$POSIX90 -lposix90

Discussion

This libraries always assumes that fortran characters are equivalent to a non-null terminated C string array plus an default integer containing the length of the array. It also assumes that this hidden interger is the last argument to be passed (by reference) in function calls. This is unfortunately not true in general, although it holds for gfortran from 2006. Using this library with any other compiler can give unexpected results.

Furthermore, it is mostly obsolete nowadays since the iso_c_binding intrinsic module is support by all decent fortran compilers, rendering all kind compatibility problems easily resolved.

Finally, the library is completely abandoned and does not even compile without some (minor) modification.

Some features of the library can still be useful, like the signal handling, as they provide a more familiar interface for fortran programmers.


Unfortunately the kind parameters for the Fortran interface are defined in a non-portable way (across compilers) through setting the kind numbers directly, rather than using the kind inquiry intrinsics. For example, dir_kind is obtained through a C program which produces a kind number:

printf("integer, parameter :: dir_kind = %d\
       ", sizeof(DIR *));

This is later used in the Fortran 90 interface as

type DIR
   integer(dir_kind):: dir
end type DIR

It would be nice to rewrite these to use the kind inquiry intrinsic functions such as selected_int_kind. (Jason Blevins, April 4, 2010 11:43 EDT)