Fortran 95 Download

Fortran 95, and further updated in 2004 to Fortran 2003, and in 2010 to Fortran 2008. The forthcoming Fortran 2015 standard is intended to be a minor revision. At each update some obsolescent features were removed, some mistakes corrected and a limited number of new facilities were added. Fortran is now an ISO/IEC and ANSI standard.

  1. Fortran 95 Download
  2. Fortran 90/95 Download
Home » Programming » Introduction to programming with Fortran 95

Introduction to programming with Fortran 95. This tutorial aim to provide an introduction to programming with Fortran 95. Fortran is particularly suitable for science and engineering.

  1. G95 is a stable, production Fortran 95 compiler available for multiple cpu architectures and operating systems. Innovations and optimizations continue to be worked on. Parts of the F2003 and F2008 standards have been implemented in g95.
  2. Fortran for Macs How to install g95 on a Mac by Neill Warrington. Another compiler, gfortran, is available for Macs and Linux: gfortran binaries. Fortran for Windows 8 and later Windows users who are unable to install the g95 compiler can alternatively use gfortran or the free (there is a 5-second nag screen) version of the FRN95 compiler.

Fortran is a programming language designed in the 1950s for scientific computing. It continues to be widely used in the field of scientific research for intensive computing. Unlike more advanced languages, the flow of individual machine operations remains relatively controllable in the language, which makes it possible to write codes that are relatively efficient in terms of calculation. Fortran has evolved a lot in recent years with the appearance of the Fortran 90 standard.

The recent norms (Fortran 95) are much richer but also much more difficult to understand than the Fortran 77 norm. We thus present here the fundamental bases of Fortran based mainly on Fortran 77 but using (implicitly or explicitly) some progress significant from the 90-95 standard.

Table of contents

  • The basics
  • Install Fortran 95
  • Your first program
  • A programming environment
  • Running your first Fortran 95 program
  • Program structure
  • Intrinsic Functions
  • Macking decision
  • Multiple conditions
  • Loops
  • Using files and extending decision
  • Arrays and formatted I/O
  • Subroutines and Functions
  • Advanced topics
  • Array Functions
  • Table extensions
  • Definitions (rank, profile, range, ...)
  • Manipulations of tables (conformance, constructor, section, size, ...)
  • Argument table of a procedure (size and profile implicit)
  • Non-contiguous array section as an argument to a procedure
  • Intrinsic functions tables
  • Query (maxloc, lbound, shape, ..)
  • Reduction (all, any, count, sum, ...)
  • Multiplication (matmul, dot_product, ...)

Functions on tables

COUNT: Returns the number of TRUE elements in the mask: count (A> 0.)
ALL (MASK): Returns TRUE if all the elements of the mask are true: ALL (A <10.)
ANY (MASK): Returns TRUE if at least one element of the mask is true: ALL (A = 1.)
MAXVAL (A, MASK): Returns the maximum value of A hidden.
MINVAL (A, MASK): Returns the minimum value of A hidden.
PRODUCT (A, MASK): Returns the product of the elements of masked A.
SUM (A, MASK): Returns the sum of the elements of A masked.
MERGE (A, B, MASK): Returns an array containing A where the mask is TRUE

Paperback :
eBook : 420.993 Kb
Downloads: 157
Submitted On: 2018-05-21
License:
Author(s):

Take advantage of this course called Introduction to programming with Fortran 95 to improve your Programming skills and better understand Fortran.

This course is adapted to your level as well as all Fortran pdf courses to better enrich your knowledge.

All you need to do is download the training document, open it and start learning Fortran for free.

This tutorial has been prepared for the beginners to help them understand basic Fortran Programming. After completing this tutorial you will find yourself at a moderate level of expertise in Fortran from where you can take yourself to next levels.

This tutorial is designed for Fortran students who are completely unaware of Fortran concepts but they have basic understanding on Programming training.

Tutorials in the same categorie :
  • Restful Web Services (Type: PDF, Size: HTML, PDF, ePub, Mobi (Kindle), Daisy, etc, Downloads: 3)
  • VB.NET Quick Guide (Type: PDF, Size: 346.60 Kb, Downloads: 174)
  • Python for Everybody: Exploring Data in Python 3 (Type: PDF, Size: PDF, ePub, etc., Downloads: 17)
  • React JS tutorial (Type: PDF, Size: 1.01 MB, Downloads: 874)
  • Using Perl 6 (Type: PDF, Size: : Online, PDF files, Downloads: 3)
  • Introduction to Programming using Fortran 95/2003/2008 (Type: PDF, Size: PDF (237 pages), Downloads: 7)
  • Programming in Fortran 95 (Type: PDF, Size: 326.145 Kb, Downloads: 206)
  • Beginner Fortran 90 tutorial (Type: PDF, Size: 134.745 Kb, Downloads: 117)
  • Fortran 90/95 Programming Manual (Type: PDF, Size: 279.259 Kb, Downloads: 180)
  • Getting started with Fortran language (Type: PDF, Size: 1.09MB, Downloads: 140)

This worksheet is also available in PDF format.

This worksheet makes use of several examples programs that are all available for download from this website.

Aims

By the end of this worksheet, you will be able to:

  • Create and run a FORTRAN 95 program
  • Understand basic program structure
  • Start to deal with programming errors
  • Start to understand real, integer and character variable types.
  • Save a copy of your output in Word.

Install FTN95 Personal Edition

  • Search for Silverfrost FTN5 personal edition or click this link http://www.silverfrost.com/32/ftn95/ftn95_personal_edition.aspx.
  • Download and install the software accepting all the defaults.

Your first programming session

  • Locate and double click the Plato icon
  • Click File, New
  • Select Free Format Fortran File
  • Click File, Save As
  • Create a directory called fortranprograms and open it
  • Type first.f95

Plato is a 'programming environment'. Within Plato, you can create and edit programs and get them to run. Plato's editor is special – it understands the syntax of various programming languages. We tell Plato which language we are using when we create our empty file and save it with a .f95 (FORTRAN 95) extension. Provided you have given your file the appropriate extension, Plato's editor will be able to check the syntax of the program, highlighting the various keywords that it knows about using a colour code to distinguish between the various elements of the language.

Always ensure that your program files have a .f95 extension

Running your first FORTRAN 95 Program

Exercise 1.1

  • Type in the following exactly as shown:
  • Click the black ► , (the Execute button).
  • Plato will get FTN95 to check your program for errors. If it finds any problems, it will give you the details. If you have typed in the program exactly as shown above, an executable file will be generated (first.exe). Plato will then automatically get the program to start executing.
  • A banner will appear for a couple of seconds and will then disappear (that's the price we have to pay for using the free software)
  • A black console window will appear.
  • Press Return to close the window. Do not click the X at the top right of the window.

Plato can get upset if you do not press Return to close the window, try this…

  • Save your program first!
  • Run the program again (click ►)
  • This time click the X at the top right of the window to close it.
  • Make up your own mind about which is the better way to close this window in future!

Program Structure

Fortran

Examine the following short program:

Fortran 95 DownloadFortran

There are a number of general points here:

  1. The program is made up of a number of lines. Each line is called a statement.
  2. Each statement is made up of
  3. variable names e.g. answer, x, y
  4. operators e.g. +,= etc
  5. keywords e.g. read, print
  6. The statements are executed sequentially.

Let's break the program down, line by line:

  1. The name of the program. Keep it reasonably short and meaningful.
  2. A comment explaining the purpose of the program. Comments are indicated by an exclamation mark. All text to the right of an exclamation mark is ignored by the compiler. Programmers use comments to help them remember how a program works. Use of appropriate comments in programs aids understanding and is good practice.
  3. Variables - answer, x and y are used to store floating point numbers – we indicate this by declaring them as real.
  4. print *, outputs to the screen – the asterisk means use the default number of decimal places when the number is written to the screen.
  5. We read information from the keyboard and store the values in x and y.
  6. Do some arithmetic and store the answer in answer.
  7. Output the result to the screen
  8. Conclude the program

More on Input and Output

Exercise 1.2

  • Open a new file and call it io.f95.
  • Type in the following program:
  • Execute it by pressing ►
  • You can enter the numbers one at a time and press the Enter key each time.
  • Execute the program again
  • This time type all three numbers on one line separated by commas.

Look at the print statement

In this statement, we are outputting four separate things, a literal string of characters,

and the variables z, y, and x. We may output several items at one time, provided they are separated by commas.

Exercise 1.3

The following program has a number of errors. The purpose of this exercise is to show you the various kinds of errors you may encounter when programming. You will come across errors many times as a programmer, and it is helpful to have a strategy for how to deal with them.

  • Create a new file called bug.f95 and then type in the following program exactly as shown.
  • You can also download this file from Example programs page.

The compiler will report two error messages when it attempts to compile. Click on the details button. Each error generates a message.

Double clicking on the message will
take you to the line in the program where the fault occurs

  • Correct the two errors.
  • Click Execute ►
  • There is now one further error, Plato will provide a yellow warning alert. Watch the screen carefully! The window will close and then the program will start to execute. Something is not correct, however... the program will 'hang'. It is actually waiting for you to input a value, because of the line To the user of the program, this is not at all obvious – they may have thought that the program has crashed!
  • Type in a number then press enter
  • The program returns an strange value. This is an 'execution time' error.
  • We need to find out what the warning message was. Click the 'compile' button (to the left of the ►). Then click the 'details' button. Plato will tell you that the variable b has not been given a value.
  • Correct the program to give b a value, and then execute the program again.
  • There is still a problem. This time, it is a problem with the program's logic.

Need a Hint?

The program statements are executed sequentially.

The statement

doesn't make sense, as at this stage of the program, we haven't yet given a value to c.

Important points to note

  • There are two types of errors associated with this program: compiler errors and run-time errors.
  • The program is also user-unfriendly. The program waits for input without telling the user what is needed.

Fix the run time error by:

  • read in a value for b
  • correct the order of the statements
  • make the program more user-friendly,

then compare your program with the one called bugfixed.f95 in the downloads directory.

More Data types – integer and character

So far, we have only used real (floating point numbers) in our programs. We can also specify that numbers are integer and character. Program convert, below, demonstrates their use.

Within a given range, integers are always represented exactly whereas the precision of realnumbers is limited by the architecture of the machine. The real variable type gives us 6 figure decimal precision. (If this doesn't seem enough – don't worry we'll come back later on when we examine how to increase the number of digits of precision in Worksheet 5).

Character variables hold strings of characters like

When the character variable is declared, we show the maximum length that the string can occupy by following the name by a * then its maximum length. The example below has a maximum length of 10 characters allowed for a person's name – this might not always be enough! You have to make a judgement here.

By including it in your program, FORTRAN will check that you have properly declared all your variable types. In the bad old days of programming, declaration of variables was thought to be unnecessary and the old FORTRAN compilers used an implicit convention that integers have names starting with the letters in the range i – n, all the others being real. FORTRAN still allows you to do this if we don't include the line, implicit none. Time has shown that one of the commonest reasons for error in a program is the incorrect use of variables.

Always use implicit none at the start of every program.

Fortran 95 Download

Exercise 1.4

With the program convert in section 1.5 as a guide, write a program to test out everything you've learned so far. You might include different types of variables, for example real, integer, and character. Include input and output using read and print. An example might be a program that asks people questions, including things like their age and name and so on. It could, for example, print out their year of birth with a suitable message. It's up to you, just use your imagination.

Saving the contents of Output Window

Run your last program again. When the black output window opens right click on the Plato icon in the top left corner

  • Click on edit
  • Click Select all
  • Click copy
  • Open a new document in Word or Notepad and click paste.

Fortran 90/95 Download


Fortran Tutorial by Janet A Nicholson is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.