[ITEM]
26.12.2018

Fortran Program For Area Of Circle

46

/ / / / Fortran Programming Basics Fortran Programming Basics Contents • • • • • • • • Introduction Fortran Programming Language Fortran (FORmula TRANslation) is a high level language aimed at numerical calculations. Evolved over 30-40 years. All compilers should conform to the Fortran standard so that code is completely portable. Recommended textbooks: • Fortran 90 Explained, Metcalf and Reid, Oxford Science Publications • Fortran 90/95 Explained, Metcalf and Reid, Oxford University Press • Fortran 95/2003 Explained, Metcalf, Reid and Cohen, Oxford University Press Internet resources are • contains a FAQ and lots of other information.

• news://comp.lang.fortran to speak directly to those who develop Fortran Free compilers There are a number of free compilers available • Fortran 77 – F77 part of the GNU GCC project • Fortran 95 – based on the GNU GCC project • Fortran 95 – part of the GNU GCC 4.0 project • Fortran 95 – Intel Fortran compilers for linux Fortran Program Structure Here is an example Fortran code. Program circle real:: r, area!This program reads a real number r and prints!the area of a circle with radius r read (*,*) r area = 3.14159*r*r write (*,*)' Area = ',area stop end program circle Note that all variables are declared at the beginning of the program and before they are used. Fortran77 Formalities • Fortran77 requires that all lines except comment or continuation lines start in the 7th column (convention left over from Fortran coding sheets) and are restricted to 72 columns as follows: • Col 1: Blank or c, C or * for comments • Col 1-5: Statement label (optional) • Col 6: Continuation of previous line (optional) • Col 7-72: Statements • Fortran is not case specific. • Comments can appear anywhere in a program – use them. • Any symbol can be used in the 6th column for continuation but the general practice is to use +, & or numbers. Download sixaxis pair tool 32 bit. • Implicit typing depending on first letter of variable name, i-n are integers. This easily leads to mistakes so don’t rely on it.

Fixed or Free Format The standard Fortran77 layout (i.c. Columns 7-72) is called fixed format but with compiler options can be extended to a line width of 132. Some compilers accept the non-standard tab source form where tab automatically skips to the 7th column.

Then line continuations can be a number in the 8th column. Free source form is generally used for Fortran90. Continuation lines are marked by an ampersand & at the end of the line that is to be continued.

Fortran77 or Fortran90 Fortran90 compilers are backward compatible so will interpret Fortran77 code. In fact, Fortan77 is a subset of Fortran90. If you are modifying existing Fortran77 code you will have to continue to use the fixed format layout in any program that is already in fixed format. Compilers decide whether code is fixed or free format depending on the extension of the file name e.g. Prog.f or prog.f90 From now on we will present Fortran90 but mention any Fortran77 constructs that are now deprecated and replaced by Fortran90 constructs. Declaration Declaration of Variables Start every program with the statement implicit none This tells the compiler that all variables are to be declared and the compiler will report an error if any variable is not declared. This is good programming practice.

Do not rely on the compiler to decide if variables are integers or real. This is different from e.g.

Write a program to compute volume of metal in hollow steel cylinder, given data values for the inner radius,outer radius and length. Use formula Volume= (area of outer-area of inner circle)*length.

[/ITEM]
[/MAIN]
26.12.2018

Fortran Program For Area Of Circle

58

/ / / / Fortran Programming Basics Fortran Programming Basics Contents • • • • • • • • Introduction Fortran Programming Language Fortran (FORmula TRANslation) is a high level language aimed at numerical calculations. Evolved over 30-40 years. All compilers should conform to the Fortran standard so that code is completely portable. Recommended textbooks: • Fortran 90 Explained, Metcalf and Reid, Oxford Science Publications • Fortran 90/95 Explained, Metcalf and Reid, Oxford University Press • Fortran 95/2003 Explained, Metcalf, Reid and Cohen, Oxford University Press Internet resources are • contains a FAQ and lots of other information.

• news://comp.lang.fortran to speak directly to those who develop Fortran Free compilers There are a number of free compilers available • Fortran 77 – F77 part of the GNU GCC project • Fortran 95 – based on the GNU GCC project • Fortran 95 – part of the GNU GCC 4.0 project • Fortran 95 – Intel Fortran compilers for linux Fortran Program Structure Here is an example Fortran code. Program circle real:: r, area!This program reads a real number r and prints!the area of a circle with radius r read (*,*) r area = 3.14159*r*r write (*,*)' Area = ',area stop end program circle Note that all variables are declared at the beginning of the program and before they are used. Fortran77 Formalities • Fortran77 requires that all lines except comment or continuation lines start in the 7th column (convention left over from Fortran coding sheets) and are restricted to 72 columns as follows: • Col 1: Blank or c, C or * for comments • Col 1-5: Statement label (optional) • Col 6: Continuation of previous line (optional) • Col 7-72: Statements • Fortran is not case specific. • Comments can appear anywhere in a program – use them. • Any symbol can be used in the 6th column for continuation but the general practice is to use +, & or numbers. Download sixaxis pair tool 32 bit. • Implicit typing depending on first letter of variable name, i-n are integers. This easily leads to mistakes so don’t rely on it.

Fixed or Free Format The standard Fortran77 layout (i.c. Columns 7-72) is called fixed format but with compiler options can be extended to a line width of 132. Some compilers accept the non-standard tab source form where tab automatically skips to the 7th column.

Then line continuations can be a number in the 8th column. Free source form is generally used for Fortran90. Continuation lines are marked by an ampersand & at the end of the line that is to be continued.

Fortran77 or Fortran90 Fortran90 compilers are backward compatible so will interpret Fortran77 code. In fact, Fortan77 is a subset of Fortran90. If you are modifying existing Fortran77 code you will have to continue to use the fixed format layout in any program that is already in fixed format. Compilers decide whether code is fixed or free format depending on the extension of the file name e.g. Prog.f or prog.f90 From now on we will present Fortran90 but mention any Fortran77 constructs that are now deprecated and replaced by Fortran90 constructs. Declaration Declaration of Variables Start every program with the statement implicit none This tells the compiler that all variables are to be declared and the compiler will report an error if any variable is not declared. This is good programming practice.

Do not rely on the compiler to decide if variables are integers or real. This is different from e.g.

Write a program to compute volume of metal in hollow steel cylinder, given data values for the inner radius,outer radius and length. Use formula Volume= (area of outer-area of inner circle)*length.