Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

ubuntu - How to use gfortran for Fortran 90 with .for file extension?

After I installed Gfortran in Ubuntu (16.04) is pointing to f95. I see in gfortran manual that -std option can be given for f95 and forward. The default -std option value I see from manual is "gnu". I am not sure of implications of internals of compiling if I use f95 for f90 code.

How do I use gfortran for Fortran 90 files with .for extension? I do not want to use Fortran 95 compiler for Fortran 90 code though Fortran 95 might be able to (not sure) compile Fortran 90.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In a nutshell, the common conventions are: .f or .for for fixed-form source code, .f90 for free-form source code, .F, .F90 (on UNIX/Linux) for fixed-form or free-form source code that must be preprocessed in a C/C++ like style using Macros, e.g., #define BLAH_BLAH = 42.

Now, while the notion of a "file extension" is ubiquitous on Windows platforms, other platforms such as UNIX/Linux/Mac OS do not attach any special meaning to the last bit of a file name. In fact, Mac OS doesn't even distinguish between main.f or MAIN.F, they are in fact equivalent.

Second, unlike Java, C/C++, Python, etc, there is no concept of a file as an organizational unit for the source code in FORTRAN/Fortran. More specifically, there can be no code outside the program, subroutine, function, or (sub)module, whence; the ISO Fortran standard itself does not define any extension, it does not even prescribe the use of files on disk to represent the source code. This may seem odd at first, but there are good reasons for this: an operating system might use a database of some sort to store all information in, so if the standard prescribed files on disk as the medium, it would exclude such (pre-command line/terminal) systems.

Generally speaking, the extensions .f90, .f95, .f03, and .f08 are used for modern, free-form source code conforming to the Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 standards, respectively. For older, fixed-form code, such as FORTRAN 77, the .f or .for extensions are typically used.

I highly advise against using the .f95, .f03, .f08 file extensions (not to mention .f15). Not only are these extension not recognized by all compilers, but Fortran 2008 code can be still be written as fixed-form source; it’s still part of that standard.

Therefore, always use *.f90 to indicate free-form source code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...