Fortran/FAQ

This article contains some frequently-asked questions (FAQs) regarding Fortran and their answers.

Q. Should I learn Fortran? Is it obsolete?
A: Fortran is not obsolete and it will not be any time soon. Fortran is a general purpose programming language and is suitable for many applications. However, it excells at numerical computation and high performance computing. It is fast, portable and it has seamless handling of arrays. Because of this, there are many high-quality Fortran libraries for numerical algorithms and it is widespread in scientific communities (e.g. numerical weather predicion). The language itself is still maintained and regularly updated with modern features; the latest version is Fortran 2018.

Q: What Fortran compiler should I use?
A: Oracle Solaris Studio, GNU Fortran, G95, and Silverfrost (Windows only) are free software Fortran 95 compilers, and Absoft, IBM, Intel, Lahey, NAG, Pathscale and PGI sell Fortran compilers. Comparative information on Fortran compilers is available at Wikipedia.

Q: How do I create numbered file names such as out_01.txt, out_02.txt etc.?
A: Use an "internal write" to create the file names, for example

A: A neater way to do this would be:

This way the formatting is clear and you are writing the correct string to the variable. I assume you wanted an integer as the number. 'I' format statement requires an Integer length, or zero in some cases. You are probably thinking of F where the decimal point denotes the number of decimals to consider.

Q: What does the open statement look like using this technique? OPEN(UNIT = __, FILE = ???, STATUS='NEW')?
A: Gfortran does not accept this block

Gives, ERROR, file tag must be of type CHARACTER

Can someone else help with this?

A: See the answer above. Basically the way you have written the variable file_name is incorrect.

Assuming that ITN has been declared as an integer and given a value.

Q: How can I convert a string to an integer and other types? What about the reverse?
A: Use an "internal read" or "internal write". In effect, you use a character variable as the file name and read or write the I/O list. You write things like

to convert a string to another type and

to convert to a string from another type, as demonstrated by the following program:

This answer is based on messages in comp.lang.fortran by Paul van Delst and Dick Hendrickson.

Q. How do I issue a command to the operating system within a Fortran program?
A. The Fortran 2008 standard provides the  intrinsic procedure to make system calls. Prior versions have no standard way to make system calls, but many compilers have an extension named "system" or something similar. Please consult the documentation of your compiler. In Fortran 2003, one can call C code, and it is possible to call the operating system from C.