The Fortran programming language is mainly used for scientific computing. Invented in 1954, it is the oldest high-level programming language, followed by Lisp (1958), Algol (1958) and COBOL (1959). The number of scientific libraries written in Fortran and the creation of special translator-compilers make it possible to use the language today. In addition, multiple calculators have been created for vectorization, coprocessors, parallelism, which intersperse this language for use in the industrial production of the modern world.
Milestones of Fortran
John Backus, an IBM radio engineer, published articles in 1954 under the headings Preliminary Report, Specifications for the IBM Matmal Transmula TRANslating System, which started the term FORTRAN. Then it took another two years of effort for the entire team he led to write the first Fortran programming language compiler (25,000 lines for IBM 704).
The language name was originally spelled out in FORTRAN uppercase letters and was used to indicate language versions up to Fortran 77, unlike the free syntax versions starting with Fortran 90. In the Fortran 77 standard, lowercase letters are not part of the language, but most compilers support them, in addition to standard.
Today, the Fortran programming language is the dominant programming language used in engineering applications. Therefore, it is important that graduate engineers can read and modify Fortran code. From time to time, the so-called experts predict that the language will lose its popularity and will soon cease to be used at all.
These predictions have always failed. Fortran is the most stable computer programming language in history. One of the main reasons Fortran programming language has survived and survives is the inertia of the software. After a company has spent a lot of resources and possibly millions of dollars on a software product, it is unlikely that it will translate the software into another language.
The main advantage of Fortran is that it is standardized by international ANSI and ISO bodies. Therefore, if the program is written in ANSI, then it will run on any computer with the Fortran 77 compiler. This is important information. Thus, Fortran object-oriented programming language programs exist on different software devices.
Differences in language versions
Stages of creating a language platform:
- In 1954-1957, the first compiler was developed from scratch. In those days there were no "high level languages" (= HLL), most operating systems were simple, and the memory was small, something around 16 Kb. The first compiler worked on IBM 704. This HLL language was much more efficient than assembly language and very popular at that time.
- FORTRAN II was published in 1958. In the same year, FORTRAN III was developed, but was never put into widespread production.
- In 1961, FORTRAN IV was created. It contained improvements, such as the implementation of the COMMON and EQUIVALENCE statements.
- In 1962, the ASA committee began developing a standard for the Fortran object-oriented programming language. This allowed the seller to use it in every new computer. And this fact made it even more popular HLL, the language became available on Apple and TRS80 systems.
- FORTRAN 66, the world's first HLL standard, was launched in 1967. The publication of the standard meant that the language became more widely implemented than any other. By the mid-1970s, almost every computer, mini or mainframe was equipped with the standard FORTRAN 66 language. The language used the statement if, goto-statement and spagethi programs. Such structured programming became popular in the 60s and 70s.
- Fortran existed on punch cards in particular with the FMS system, optimizing the location of its sources until Fortran 90 introduced a “free” syntax. In it, the code of the Fortran array begins with the 7th column and should not exceed 72 thousand characters.
It should also be noted that prior to Fortran 90, gaps did not matter between the 7th and 72nd columns. Thus, the cycle “DO I = 1.5” can also be written “DOI = 1.5”. On the other hand, “DO I = 1.5” is equivalent to “DOI = 1.5”.
Numerous industry codes have been written in the Nastran, NAG, and IMSL-Fortran library. The compatibility of new versions with previous ones is important. For this reason, Fortran 90 is fully compatible with Fortran 77. However, incompatibilities have already been introduced in future versions of the standard.
Soon followed by more advanced Fortran 90 and Fortran 95 languages, upgraded to the current Fortran 2003 standard. Despite the fact that modern compilers work unlimitedly in all current versions of Windows and even support 64-bit processors. Meanwhile, manufacturers have recognized the trend of the times and offer compilers for Linux in the form of an object-oriented programming language Actor Fortran.
Prerequisites for using a programming language
You need to understand that Fortran is still a widely used programming language and is mainly used in the field of discoveries. Classical applications, for example, in physics or technology, where extensive and complex mathematical calculations are performed. The extensive mathematical libraries that exist for different compilers are very useful in them. To summarize, it can be argued that today the Fortran language is still used for a number of reasons:
- The presence of numerous functional libraries developed over the years.
- The availability of software in Fortran, which requires very important resources for development, when switching to another language is considered too expensive.
- Powerful compilers with Fortran built-in functions that produce very fast executables.
- The language is more accessible to an inventor who did not have a specialized computer course.
Many scientific programs are now written in C and C ++, the compilers of which are available on most machines. Other compiled languages ​​are sometimes used for scientific computing, and especially for programs such as Scilab or Matlab. The latter also include the BLAS and LAPACK libraries developed by Fortran programming. Matlab was originally a Fortran program distributed at universities and research centers.
Modern compilers
Although Tom Lahey is now the "only" general compiler, Lahey Computer Systems continues to be used by many programmers. Lahey has been working with Fujitsu for several years, Lahey focuses on the Fortran parser, and Fujitsu focuses on the code generator. The current Compiler Suite for Windows is called Lahey Fujitsu Fortran 95 (LF95) and is available in various versions, some of which also integrate with Visual Studio .NET 2003.
There is also an inexpensive version of the LF95 Express without its own IDE. The current version is 7.1. on Linux is invoked by the Lahey / Fujitsu Fortran 95 v6.2 compiler for Linux and is available in two different versions. For example, the Pro version includes compatibility with OpenMP v2.0, the simple Winteracter Starter Kit graphics engine, the math library, and the Fujitsu 2 science routine library.
Another manufacturer is Absoft. Compilers and C ++ exist not only for Windows and Linux, but also for OS X on Macintosh. These compilers are interesting to developers who need or want to support all three platforms. Unfortunately, Absoft distinguishes between 32-bit and 64-bit versions under Linux; Fortran 95 version 10.0 for 64-bit Linux is currently used.
Relatively new to the market is the EKOPath Compiler Suite. It consists of C ++ compilers and the Fortran development environment for Linux, which are also available separately and are mainly intended for 64-bit AMDusers. It also runs on Intel EM64T. Also, Microsoft once tried to find a “cheap market” Fortran and brought to the market Microsoft Powerstation.
The market may have been too small for the software giant, but Digital took up some of the code in 1997 and used its experience with the Digital Unix and OpenVMS compilers. It was the birth of the still very successful Digital Visual Fortran. At some point, Digital then switched to Compaq, the compiler was updated to the current version of Compaq Visual Fortran (CVF) v6.6.
In addition to the “normal” 32-bit platforms, there are various 64-bit compilers, for example, for Intel Itanium and Intel EM64T. Although not “urgent” for scope of delivery, they are available for free download through Intel Premier's web-based support system.
After a one-time, somewhat cumbersome registration, you can use it for a year, taking into account new updates every few weeks. Even older versions will remain available.
Program Organizational Structures
Fortran is a sequence of lines of text. The text must follow certain syntax. For example: a circle of radius r, area c.
This program reads the real radius and determines the area of ​​a circle with radius r:
write (*, *);
'Radius r:' read (*, *) r;
area = 3.14159 * r * r;
write (*, *) 'Area =';
stop;
end.
Lines starting with “C” are comments and have no purpose but to make the program more readable for people. Initially, all Fortran programs were capitalized. Most programmers now write lowercase, as this is more legible.
A Fortran program usually consists of a main program or driver and several subprograms, procedures, or routines. The structure of the main program:
- the name of the program;
- declarations;
- statements;
- Stop;
- end.
Italics should not be taken as literal text, but rather, as a general description. The stop statement is optional and may seem redundant because the program will stop when it reaches the end anyway, but it is recommended that you always end the program with the stop statement to emphasize that the execution flow is stopping.
Column Position Rules
Fortran 77 is not a free-form language, but has a very strict set of rules for formatting source code. The most important rules are column layout rules:
- Col. 1: Blank or “c” or “*” for comments.
- Col. 2-5: operator label.
- Col. 6: continuation of the previous line.
- Col. 7-72: statement.
- Col. 73-80: Sequence number.
A Fortran line starting with the letter “c” or an asterisk in the first column is a comment. Comments can appear anywhere in the program. Well written, they are critical to the readability of a program. Fortran sales codes often contain about 50% of the comments. You can also come across programs that use an exclamation point (!). This is very unusual in Fortran 77, but is allowed in Fortran 90.
An exclamation mark may appear anywhere on the line. Sometimes the statement does not fit on one line, then you can split the statement into two or more lines and use the continuation sign in the position.
Example:
- C23456789 - This demonstrates the position of the column.
- “C” - the next operator goes through two areas of physical lines.
- Area = 3.14159265358979+ * r * r.
Blank spaces are ignored, starting with Fortran 77. Therefore, if you remove all spaces in Fortran 77, the program is still syntactically correct, although it is almost unreadable for operators.
Variables, Types, and Declarations
Variable names in Fortran consist of 1-6 characters, selected from the letters az and the numbers 0-9. The first character must be a letter. Fortran 90 allows variable names of arbitrary lengths. Fortran 77 does not distinguish between upper and lower case; in fact, it assumes that all input is upper case. However, almost all F 77 compilers will accept lowercase letters. Each variable must be defined in the declaration. This sets the type of variable. The most common variable lists are:
- integer;
- real;
- double precision;
- complex;
- logical;
- character.
The variable list should consist of names separated by commas. Each variable must be declared exactly once. If a variable is not declared, F 77 uses a set of implicit rules to establish the type. This means that all variables starting with the letters “in” are integers, and all others are real. Many older F 77 programs use these implicit rules, but programmers should not do this, since the probability of errors in a program increases dramatically if they inconsistently declare variables.
Fortran 77 has only one type for integer variables. Integers are usually stored as 32-bit (4 bytes) variables. Therefore, all integer variables must take values ​​in the range [-m, m], where m is approximately 2 * 10 9.
F 77 has two different types for floating point variables called real double precision. Some numerical calculations require very high accuracy, and double precision should be used. Usually the real one is a 4-byte variable, and the double precision is 8 bytes, but it depends on the machine.
Custom versions of Fortran use the real * 8 syntax to denote 8-byte floating point variables. Some constants appear many times in the program. Therefore, it is advisable to identify them only once, at the beginning of the program. To do this, use the parameter operator. It also makes programs more readable. For example, a circle area program should be written like this.
The syntax of the parameter operator (name = constant, ..., name = constant). Rules for the parameter operator:
- A “variable” defined in a parameter statement is not a variable, but a constant whose value can never change.
- A "variable" can display at most one parameter operator.
- The parameter operator must come before the first executable statement
Some good reasons to use the parameter - it helps to reduce the number of typos, it is easy to change the constant that appears many times in the program.
Logical expressions
Logical expressions can only have a value of .TRUE. or .FALSE. and can be formed by comparing arithmetic expressions using relational operators.
You cannot use characters such as "<" or "=" for comparison in F 77, but you can use the correct two-letter abbreviation enclosed by dots. However, such characters are permitted in Fortran 90.
Logical expressions can be combined by the logical operators "AND", "OR", "NOT", which have an obvious meaning. True values ​​can be stored in logical variables. Assignment is similar to arithmetic assignment.
Example: logical a, ba = .TRUE.b = a .AND. 3 .LT. 5/2
The order of priority is very important. The rule is that arithmetic expressions are calculated first, then relational operators, and finally logical operators. Therefore, b will be assigned to .FALSE. In the above example, logical variables are rarely used in Fortran, but they are often used in conditional statements, such as the if statement.
Constant and purpose
The simplest form of expression is a constant. There are 6 types of constants corresponding to 6 data types. Here are some integer constants: 10-10032767 + 15
Real constants: 1.0-0.252.0E63.333E-1.
E-notation means that you need to multiply the constant by 10, raised to the power following “E”. Therefore, 2.0E6 is two million, and 3.333E-1 is about one third for constants that are larger than the largest real allowable, or that require high precision, double precision should be used. The notation is the same as for real constants, except that “E” is replaced by “D”.
Example: 2.0D-11D99.
Here, 2.0D-1 represents double precision with one fifth, while 1D99 is one followed by 99 zeros.
The next type is complex constants. They are indicated by a pair of constants (integer or real), separated by a comma and enclosed in brackets.
Examples are: (2, -3) (1,9,9-1). The first number denotes the real part, and the second - the imaginary part.
The fifth type is logical constants. They can have only one of two values:
.TRUE.
.FALSE.
Note that points containing letters are mandatory.
The last type is character constants. They are most often used as an array of characters called a string. They consist of an arbitrary sequence of characters enclosed in apostrophes (single quotes):
'ABC'
'Anything goes!'
'It is a nice day'
String and character constants are case sensitive. The problem arises if you need to have a real apostrophe in the line itself. In this case, you need to double the apostrophe: 'It''sa nice day', which means 'What a wonderful day'
Conditional "if" statements
Important components of any programming language are conditional statements. The most common of these statements in Fortran is the if statement, which actually takes several forms.
The simplest is the if statement in the Fortran description: if (logical expression) executable statement.
This should be written on one line, for example, when determining the absolute value of x:
if (x .LT. 0) x = -x
If more than one statement is to be executed in an if, then the following syntax should be used: if (logical expression) thenstatementsendif.
Thread flow from top to bottom. Conditional expressions are evaluated sequentially until a true value is found. Then the corresponding code is executed, and the control proceeds to the next statement after end “if”.
If statements can be nested at several levels. To ensure readability, it is important to use the correct indentation. Here is an example:
if (x .GT. 0) thenif (x .GE. y) thenwrite (*, *) 'x is positive and x> = y'elsewrite (*, *)' x is positive but x <y'endifelseif (x .LT. 0) thenwrite (*, *) 'x is negative'elsewrite (*, *)' x is zero'endif
Programmers should avoid nesting many levels of “if” statements as it will be difficult to follow.
Use on Unix OS
You can use any Unix workstation with the F 77 compiler. Experienced programmers recommend using either Sun or Dec.
A Fortran program consists of plain text that follows certain syntax rules. This is called source code. Programmers use an editor to write source code. The most common editors on Unix are emacs and vi, but they can be a bit complicated for novice users. You can use a simpler editor, for example, xedit, which works under X-windows.
After the Fortran program is written, it is saved in a file with the extension “.f” or “.for” and the program is converted into machine-readable form. This is done using a special program called the compiler. The Fortran 77 compiler is commonly called f77. The compilation result is given the somewhat cryptic name “a.out” by default, but you can choose a different name if necessary. To start the program, simply enter the name of the executable file, for example, “a.out”. The compiler translates the source code into object code, and the linker or loader into the executable file. As you can see, this procedure is not complicated at all and is available to any user.
Production Modeling Methods
Modeling is one of the most commonly used production methods and other systems available in modern enterprises. Most simulation models are built using the Actor Fortran object-oriented programming language, or a modeling software package written in a traditional language. These tools have their limitations. Object-oriented technology has been increasingly used in many areas and promises a more flexible and efficient approach to modeling business systems.
Simula Fortran's object-oriented programming languages ​​are compared to a common scientific programming language called FORTRAN. A typical military simulation model is programmed in both SIMULA and FORTRAN. SIMULA turned out to be 24% shorter than the FORTRAN version.
The SIMULA version is also simpler and gives a better picture of the simulated model. On the other hand, the run-time for production runs is 64% longer with the object-oriented programming language Simula Fortran. Weighing the pros and cons shows that SIMULA will be more and more profitable software, with higher personnel costs and lower computer costs.
CUDA shows how high-end application developers can leverage the power of GPUs using Fortran, a familiar language for scientific computing and benchmarking supercomputers. The authors do not suggest any prior experience in parallel computing and cover only the basics, and also use best practices. GPU computing performance using Fortran CUDA is provided by the targeted GPU architecture.
CUDA Fortran for scientists and engineers will identify the intensive computational parts of the code and modify the code for data management, concurrency and performance optimization. All this is done in Fortran, without having to rewrite the program into another language. Each concept is illustrated by actual examples, so you can immediately evaluate the performance of the code.
Perhaps once the global corporation is “finally globalizing” and decides that Fortran is no longer needed, however, not now. Thanks to the current capabilities of the modern Fortran, many programmers and scientists see the future behind it. In addition, there are enough manufacturers in the world who live off the development of modern compilers and make good money on this process.