Clicky

Fortran Wiki
FAQ (Rev #13, changes)

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

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

Contents


Which Fortran compiler should I use?

GFortran, G95, Open Watcom, and Silverfrost are free Fortran compilers, while Absoft, IBM, Intel, Lahey, NAG, Pathscale, PGI, and Sun produce commercial Fortran compilers. Polyhedron Software provides compiler comparisons at http://www.polyhedron.com/compare0html. See Compilers for more information.

What are good books on Fortran?

See the Books page.

How should one capitalize "Fortran?"

Standard capitalization is now the preferred way to write Fortran for several reasons, most notably because that is how recent versions of the standard write it. Another reason is due to an effort to standardize the capitalization of the names of programming languages. To quote Walt Brainerd (originally from the 1997年01月03日 version of Keith Bierman’s Fortran FAQ):

The rule: if you say the letters, it is all caps (APL); if you pronounce it as a word, it is not (Cobol, Fortran, Ada).

Some choose to write FORTRAN when referring to older versions of the language (prior to Fortran 90) to distinguish them from newer versions.

How do I produce a library?

To build a static library libfoo.a containing all modules and procedures in the .f90 files in the current directory on Linux:

% gfortran -c *.f90
% ar cr libfoo.a *.o

The first command builds the object files and the second archives the object files into a static archive.

To build a shared library libfoo.so:

% gfortran -shared *.f90 -o libfoo.so -fPIC

In both cases, other compiler flags such as -O2 can be used.

Why doesn’t u == 1.4D0 work?

See Floating point arithmetic.

How do I read until the end of a file (EOF)?

A common Fortran 95 idiom for reading lines until the end of file is

integer :: stat
character(len=100) :: buf
open(15, file='foo.txt')
do
 read(fh, iostat=stat) buf
 if (stat /= 0) exit
 ! process buf
end do
close(15)

This example catches all conditions, not just the end of file. To specifically catch the EOF in Fortran 2003 one can use the iso_fortran_env module and replace the if condition above with

if (stat == iostat_end) exit

See also: EOF idiom? on comp.lang.fortran.

How do I read a character without having to press enter?

There isn’t a portable way to do this either in Fortran or C, in short, because the terminal controls when the input is sent to your program and by default it is buffered. You must request that the terminal send each key and the method for doing so is platform-dependent.

Clive Page’s Fortran Resources has a section on "Reading single keystrokes from Fortran" which provides a couple of short C functions (sys_keyin.c) which can be called from Fortran to achive the desired behavior on most Unix systems.

John Urban also provides a getkey function, written in C and callable from Fortran.

See also: Get Key Function? on comp.lang.fortran.

How do I set the precision of real variables in Fortran 90?

See Real precision.

How do I convert a numeric variable to a string, or vice-versa?

There is no intrinsic procedure for converting character strings to numerical values, or vice-versa. However, this can be accomplished using internal file IO. To obtain a string representation of a numeric variable, one can perform a formatted write to a string, just as one does to a file. Similarly, a formatted read from a string can extract a numeric value. See the strnum program for an example.

How do I read command-line arguments?

See Command-line arguments.

(追記) (追記ここまで)(追記)

How can I create a temporary file?

(追記ここまで)
(追記) (追記ここまで)(追記)
open(7, access='direct', status='scratch')
(追記ここまで)
(追記) (追記ここまで)(追記)

This will create a temporary file that only lives until it is closed. It doesn’t need a filename as it will not be permanently saved to disk (although it could be stored somewhere as a temporary file). In this example, the unit number is 7.

(追記ここまで)
(追記) (追記ここまで)(追記)

The file may not be deleted if the program terminates abnormally. To prevent deletion, call close with status='keep'.

(追記ここまで)

Revision from March 13, 2010 00:23:33 by Jason Blevins
Forward in time (29 more) | Back in time (12 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: HomePage, sidebar, 2009, Stats, Contributing

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