A preliminary study of Fortran compilation

Source: Internet
Author: User
Keywords nbsp compiling Preliminary preprocessing source code
Tags aliyun archive code comment compiling file html http

Related file suffixes in Fortran programming

. A static library (archive). F,. For,. For
ftn*,. f90*,. f95*,. f03*http://www.aliyun.com/zixun/aggregation/29818.html ">fortran Source code (no compilation preprocessing required). F. FPP. FPP
. ftn*,. f90*,. f95*,. F03*fortran Source code (requires compilation preprocessing). Rfortran source code (requires ratfor compilation preprocessing). O Object file. S assembly language code. So dynamic Library

Among them, the suffix name of the mark * is Gfortran file suffix, G77 cannot recognize.

A single source file generates an executable program

The traditional Fortran program (that is, Fortran 77) can only be written in uppercase characters, and the first six characters per line are reserved for specific purposes. The first column is reserved by the character C or *, which is used to characterize the entire line as a comment. The second column to the sixth column is reserved for marking. The code starts at column seventh and ends at column 72 (73 columns and later will be ignored directly for comment). The following is the traditional Fortran format used by the sample program:

C HELLOWORLD.F
C
program Hello
WRITE (*,10)
FORMAT (' Hello, World ')
End Program Hello

Compiler Gfortran does not require all of the code to be capitalized--any keyword in the program can be in lowercase letters. The following command compiles the program into an executable file:

$ Gfortran Helloworld.f-o Hello

Note: Gfortran by default will. F,. For,. FPP,. FTN,. F. For,. FPP and. The FTN end of the file is processed as a fixed format, and the. F90, f95,. f03. F90,. F95 and. The F03 end of the file is processed as a free-form format. If we rename the above program file to Helloworld.f90, we must manually specify it as a fixed format:

$ mv HELLOWORLD.F Helloworld.f90
$ Gfortran Helloworld.f90-ffixed-form-o Hello

Fortran 90 and later standards allow and encourage the writing of Fortran code in a free-form format. Comment with an exclamation point (! Starts at the end of the line. The previous program is rewritten as follows in free-form format, where statements and labels can start from any column:

! Helloworldff.f90
!
program Hello
Write (*,10)
Format (' Hello, World ')
End Program Hello

Suffix named. F90, so gfortran to treat it as a free form

$ Gfortran Helloworldff.f90-o HELLOWORLDFF

Similarly, if you rename a program to a traditional suffix name, you compile it by adding the option-ffree-form to the command line, as follows:

$ mv Helloworldff.f90 helloworldff.for
$ gfortran-ffree-form Helloworldff.for-o HELLOWORLDFF

Because of the great difference between the two formats, program writing is only one of the formats that can be written. Note: It is important to adhere to the suffix conventions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.