An Introduction to Fortran 90 2.1 About Fortran in General

An Introduction to Fortran 90 2.1 About Fortran in General

2 An Introduction to Fortran 90 This chapter aims at giving a short introduction to Fortran 90. As describing all features of the Fortran language would probably fill some hundred pages, we will concentrate on the basic features that will be needed to follow the rest of this textbook. Nevertheless, there are various Fortran tutorials out in the internet that could be used as complementary literature. 2.1 About Fortran in general 2.1.1 The history of Fortran Fortran is pretty old. Actually it is considered the first realized higher programming lan- guage. It goes back to a proposal by John W. Backus, an IBM programmer, in 1953. The term Fortran is derived from The IBM Formula Translation System. Before the release of the first Fortran compiler in April 1957, people used to use assembly languages. The intro- duction of a higher programming language compiler reduced the number of code lines needed to write a program tremendously and therefore FORTRAN, the first release of the Fortran programming language, grew pretty fast in popularity. From 1957 on several versions followed the initial FORTRAN version, namely FORTRAN II and FORTRAN III in 1958 and FORTRAN IV in 1961. In 1966, the American Standards Association (now known as the ANSI) approved a standardized American Standard Fortran.Theprogram- ming language defined on this standard was called FORTRAN 66. Approving an updated standard in 1977, the ANSI paved the way for a new Fortran version known as FORTRAN 77. This version became pretty popular in computational economics during the 80ies and beginning 90ies. More than 13 years later, the Fortran 90 standard was released by both ISO and ANSI in consecutive years. With FORTRAN 90, the fixed format standard was exchanged by a free format standard. In addition, many new features like modules, recur- sive procedures, derived data types and dynamic memory allocation made the language much more flexible. From Fortran 90 on, there has only been one major revision which basically introduced object-oriented programming features into the Fortran language in 2003. However, as object-oriented programming will not be needed and Fortran 90 is by far the more popular language, we will focus on the 1990 version in this book. 4 Chapter 2 – An Introduction to Fortran 90 2.1.2 Why to use Fortran Fortran is a general purpose, procedural, imperative, high-level programming language. In detail this means that (a) Fortran was not created for a special purpose like e.g. Matlab, Mathematica or Gauss were for efficiently dealing with matrices or solving mathematical problems, (b) Fortran code that will be used severaltimescanbestoredinfunctionsand subroutines that can be called from other program parts, (c) a Fortran program consists of statements that will be executed one after the other (i.e. a Fortran program starts with the first line and ends with the last), and (d) Fortran abstracts from the details of a computer, i.e. having the right compiler, Fortran code could be run on every computer independent of its hardware configuration and operating system. At this point our students usually ask "So, why to use Fortran? Why not a special pur- pose language or something more "fashionable" like Java?". Let us come up with some justifying points. First, special purpose languages might be relatively efficient in the spe- cific purpose they were created for, however, slow in other areas. Matlab, for example, is very good in working with matrices of regularorsparsenature.However,ifyouhave ever tried to run some do-loops in Matlab, you will know what we mean. Second, when it comes to the more "fashionable" languages like Java or C++, one has to always keep in mind that those languages are usually object-oriented and abundant. They are very good for creating software with Graphical User Interfaces, but not for running numerical maths code quickly and efficiently. As computational economics usually consists of at least 80% numerical methods, we need a programming language that is efficient in exe- cuting do-loops and if-statements, calling functions and subroutines and allows to per- manently store general code that is frequently used. Fortran is a language that matches all those features and not much more. The only real alternative we know would be C. There is no real reason why not to use C instead of Fortran, it’s just a matter of preference. Last but not least, Fortran has been used a lot by engineers, numerical mathematicians and computational economists during the 80ies and 90ies where a lot of optimizers and interpolation techniques were written. Fortunately, Fortran 90 is backward compatible with FORTRAN 77, i.e. all the code that is out there can be easily included in our Fortran programs. All in all, it seems reasonable for us to have chosen a language that matches all the fea- tures we need but does not come with any unnecessary extras that just make execution less efficient. 2.1.3 The way high-level programming languages work Low-level assembly languages that are basically used to program computers, micropro- cessors, etc. do not abstract from the computer’s instruction set architecture. Therefore, the syntax of assembly languages depends on the specific physical or virtual computer used. In addition, assembly languages are quite complicated and even a small programm 2.1. About Fortran in general 5 requires many lines of computer code. In opposite to that, high-level programming languages abstract from the system architec- ture and are therefore portable between different systems. As in all other languages, one has to learn the vocabulary, grammar, and punctuation called syntax of that language. However, compared to real languages, the syntax of a high-level language can be learned within some hours. In addition, the semantics, i.e. the meaning or interpretation of the different symbols you use, usually follows principles that can be comprehended by using pure logic. As high-level languages abstract from the computer’s instruction set architecture, one needs a compiler, sometimes also called interpreter, that interprets the statements given in the program and translates them into a computer’s native language, i.e. binary code. The way high-level programming works can be seen from Figure 2.1. First, the programmer Source Code Programmer Compilation Other Libraries Object Code Compiler Linkage Operating Executable (binary) System/ Hardware Figure 2.1: The way high-level compilers work has to write his source code in the respective high-level language and hand it over to the compiler. The compiler now proceeds in two steps. In the compilation step he interprets the source code and creates a so called object code file which consists of binary code. Binary code files usually have the suffix .obj. During this step, the compiler usually performs a syntax validation scan. If there are any syntactical errors, it produces error messages and stops the compilation process. In order to create an executable file, which has the suffix .exe in Microsoft® Windows, the compiler now links theobjectcodewithall other libraries that are needed to run the program, e.g. external numerical routines. The resulting executable can now be sent to the operating system which advises the hardware to do what exactly the programmer wants. 6 Chapter 2 – An Introduction to Fortran 90 2.1.4 Fortran Compilers for Windows® and Linux For beginners, we suggest to use the SilverFrost FTN95 compiler. You can download a free Personal Edition from http://www.silverfrost.com and install it on you com- puter by double-clicking on the downloaded file. The setup agent will guide you through the installation process. SilverFrost’s FTN95 compiler comes with a graphical user inter- face called Plato. You can open this program by double-clicking "Plato 3 IDE" in the "Start -> Programs -> Salford Software" menu. The user interface can be seen in Figure 2.2. Figure 2.2: The Plato user interface for the FTN95 compiler Below the main menu there are two lines of shortcut symbols, the first of which is nearly self-explanatory. The only thing that needs some explanation is the drop-down menu with the three possible execution modes for FTN95. The standard entry thereby is Check- Mate Win 32. CheckMate is a graphical debugger, the Debug mode is a simple console debugging mode. Using CheckMate or Debug and running into an error, the compiler will 2.1. About Fortran in general 7 give us detailed information about what happened and where exactly it occurred. In op- posite to that, Release minimizes the debug information in our programm which makes it run pretty quick. Note, however, that the Release mode should only be used, if the pro- gram is fully developed and free of bugs. Please only use the Win32 modes, as the .NET modes are only conceived for users that want to integrate the FTN95 compiler into a Mi- crosoft® .NET Framework. Using the .NET mode without having the compiler properly integrated into the framework can produce weird results.1 The text field and the three buttons on the right of the execution mode choice menu are used to search within a pro- gram or a file. The next two buttons increase and decrease the intent of code, respectively. The two buttons on the right of the intent buttons comment or uncomment some code lines. The last four buttons finally can be used to toggle bookmarks. In order to demonstrate the usage of the second line of shortcut symbols, we first have to write a small program. You can start a new program by creating a Free Format Fortran Source File via using the "File -> New" button and typing some program code.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    32 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us