Fortran environment construction on Mac

Introduction

Here is how to build a Fortran environment on Mac 10.14 Mejave. Other versions should be the same.

Using Fortran can be said to be compelling, because many ancient (decades ago) programs, especially in some pattern analysis fields, many programs were written in Fortran. Now you need to use these patterns, and you have to learn what was once brilliant, but now it’s declining. Fortran. There are many more introductions about it on the Internet.
The following is an explanation from the encyclopedia.
ORTRAN language is the abbreviation of Formula Translation, which means "formula translation". It is designed for science, engineering problems or those problems in enterprise management that can be expressed by mathematical formulas, and its numerical calculation function is strong.
FORTRAN language is the world's first high-level language to be officially promoted. It was proposed in 1954 and officially used in 1956. It has a history of sixty years until 2014, but it is still enduring. It has always been the main language used in the field of numerical computing.

Installation of the compiler GFortran

There are multiple Fortran compilers to choose from, here is still in the process of exploring, first use the relatively popular G Fortran. The download of GFortran can be found on the
Wiki . Because you want to install on MacOS, select the corresponding version.
Insert picture description here

There are several installation methods, and you can see incomplete introductions compared to online searches. Here I choose to download the dmg installation package and install it manually without using brew or macport.
Insert picture description here
Download the version of the corresponding system on github and install it.
Insert picture description here

Conventional software installation method.
Insert picture description here

test

Successful installation:
Insert picture description here

MacVIM installation

This text editor software does not have to be installed, it does not need to be installed.
What is VIM: Vim is a well-known powerful and highly customizable text editor similar to Vi. It has improved and added many features on the basis of Vi.
What is Mac VIM : MacVim is a complete Cocoa user interface based on Vim. MacVim supports many native interface features of Mac OS X, such as toolbars, scroll bars, full-screen display, and binding of Mac menu shortcuts.

Download MacVim and install it manually.
Insert picture description here
Insert picture description here

The first Fortran program

Write down our first Fortran program and name the suffix f.

program hello
print *, "Hello World"
end program hello

Insert picture description here
Prepare to run in the terminal.
Specify the execution directory, otherwise it will be generated to other paths.
Open the terminal input, the syntax:

cd 输入路径回车(可以把自己想设置的路径文件直接拖拽到cd 后面,注意有空格)

Continue to enter commands in the terminal to generate the executable file nihao:

fortran hello.f90 -o nihao

Continue typing, or open nihao directly in the folder, you can see the following effects:

./nihao

effect:
Insert picture description here

Fortran basic grammar notes

Related file suffixes in Fortran programming
Insert picture description here

Generate executable program

Traditional Fortran programs (represented by Fortran 77) can only be written in uppercase characters, and the first six characters of each line are reserved for specific purposes. The first column is reserved for the character C or * to indicate that the entire line is a comment. The second to sixth columns are reserved for labels. The code starts in the seventh column and ends in the 72 column (the 73 column and later will be ignored directly and can be commented). For more information, please refer to: https://www.cnblogs.com/djcsch2001/archive/2012/01/12/2321062.html
The following is a sample program that uses the traditional Fortran format:

PROGRAM HELLOWORLD
WRITE(*,10)
FORMAT('hello, world')
END PROGRAM HELLOWORLD
      

The gortran compiler does not require all 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 helloworld

Note: gfortran treats .f, .for, .fpp, .ftn, .F, .FOR, .FPP and .FTN files as fixed formats by default, and treats .f90, .f95, .f03,. Files ending in F90, .F95 and .F03 are handled as free format.
If we rename the above program file to helloworld.f90, then we must manually specify it as a fixed format:

$ mv helloworld.f helloworld.f90
$ gfortran helloworld.f90 -o helloworld

Fortran 90 and later standards allow and encourage writing Fortran code in a free format. Comments start with an exclamation mark (!) and go to the end of the line. The previous program is rewritten in free format as follows, where the statement and label can start from any column.

At this point, the installation and testing of GFortran is complete, and if there is new content, I will continue to share it with you.

Guess you like

Origin blog.csdn.net/wokaowokaowokao12345/article/details/107943771