Clicky

Fortran Wiki
Posix90 (changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #3 to #4: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

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\ (削除ここまで)(追記) printf (追記ここまで)(追記) (" (追記ここまで)(追記) integer (追記ここまで)(追記) , (追記ここまで)(追記)  (追記ここまで)(追記) parameter (追記ここまで)(追記)  (追記ここまで)(追記) :: (追記ここまで)(追記)  (追記ここまで)(追記) dir_kind (追記ここまで)(追記)  (追記ここまで)(追記) = (追記ここまで)(追記)  (追記ここまで)(追記) %d\ (追記ここまで)(追記) 
 (追記ここまで)(追記) ", (追記ここまで)(追記)  (追記ここまで)(追記) sizeof (追記ここまで)(追記) (DIR (追記ここまで)(追記)  (追記ここまで)(追記) *)); (追記ここまで)
(削除) (削除ここまで)(削除)

", 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)

Revised on March 3, 2023 11:19:47 by vmagnin (86.67.213.99) (2793 characters / 1.0 pages)
Edit | Back in time (3 revisions) | Hide changes | History | Views: Print | TeX | Source | Linked from: Libraries

AltStyle によって変換されたページ (->オリジナル) /