Aerospace Engineering Problems - Main Programs | AER E 160, Study notes of Aerospace Engineering

Material Type: Notes; Professor: Haugli; Class: AEROSPAC ENG PROBLM; Subject: AEROSPACE ENGINEERING; University: Iowa State University; Term: Spring 2005;

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-8xa
koofers-user-8xa 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
D. Haugli Aer E 160 Aerospace Engineering
2/2/2005 Main Programs, Page 1 Iowa State University
Main Programs
The essential structure of a FORTRAN program with no explicit subroutines or functions is:
PROGRAM <insert name of program>
<Insert IMPLICIT NONE statement and declarations>
<Insert executable statements followed by STOP>
END PROGRAM <insert name of program>
Every program must begin with the PROGRAM line, and end with END PROGRAM. Program names
must begin with a letter, and may contain any combination of letters, numbers and underscore
characters after the first letter. No other characters are allowed.
(Programs are saved in text files. The text files must be named with the extension .f90, such as
main.f90. The name of the text file can be different from the name on the PROGRAM line.)
Variables are declared immediately after the PROGRAM line (including the line IMPLICIT NONE,
which must listed before data type declarations such as REAL, CHARACTER or INTEGER).
Executable statements follow the declarations, and end with the line STOP. (STOP tells the
program to stop running.)
Case (e.g., small or capital letters) does not matter in writing a FORTRAN program. Each
programmer develops their own style, and many use case to clarify their codes. For example,
this instructor uses capital letters for FORTRAN commands and lower case letters for program
and variable names.
Good programmers add comments to their codes that explain what the code is doing. Words and
sentences that follow an exclamation point are comments. The compiler ignores them.
Several examples of main programs follow.
Example 1. The Hello World program below is a traditional introduction to the form of a
main program.
PROGRAM hello
WRITE (*,*) "Hello World!"
STOP
END PROGRAM hello
This program has no declarations. The statement,
WRITE (*,*) "Hello World!"
is an executable statement and causes the words "Hello World!" to appear on the screen
when the program runs.
pf2

Partial preview of the text

Download Aerospace Engineering Problems - Main Programs | AER E 160 and more Study notes Aerospace Engineering in PDF only on Docsity!

D. Haugli Aer E 160 Aerospace Engineering

2/2/2005 Main Programs, Page 1 Iowa State University

Main Programs

The essential structure of a FORTRAN program with no explicit subroutines or functions is:

PROGRAM

END PROGRAM

Every program must begin with the PROGRAM line, and end with END PROGRAM. Program names

must begin with a letter, and may contain any combination of letters, numbers and underscore

characters after the first letter. No other characters are allowed.

(Programs are saved in text files. The text files must be named with the extension .f90, such as

main.f90. The name of the text file can be different from the name on the PROGRAM line.)

Variables are declared immediately after the PROGRAM line (including the line IMPLICIT NONE,

which must listed before data type declarations such as REAL, CHARACTER or INTEGER).

Executable statements follow the declarations, and end with the line STOP. (STOP tells the

program to stop running.)

Case (e.g., small or capital letters) does not matter in writing a FORTRAN program. Each

programmer develops their own style, and many use case to clarify their codes. For example,

this instructor uses capital letters for FORTRAN commands and lower case letters for program

and variable names.

Good programmers add comments to their codes that explain what the code is doing. Words and

sentences that follow an exclamation point are comments. The compiler ignores them.

Several examples of main programs follow.

Example 1. The Hello World program below is a traditional introduction to the form of a

main program.

PROGRAM hello WRITE (,) "Hello World!" STOP END PROGRAM hello

This program has no declarations. The statement,

WRITE (,) "Hello World!"

is an executable statement and causes the words "Hello World!" to appear on the screen

when the program runs.

D. Haugli Aer E 160 Aerospace Engineering

2/2/2005 Main Programs, Page 2 Iowa State University

Example 2. A program to add two numbers and save them in the variable "c" follows.

PROGRAM add

! Declarations IMPLICIT NONE INTEGER :: a, b, c

! Executable Statements a = 1 b = 2 c = a + b WRITE (,) a, " + ", b " = ", c

STOP

END PROGRAM add

The statements,

IMPLICIT NONE

INTEGER :: a, b, c

are examples of declarations. IMPLICIT NONE means that variables are "explicitly"

declared and the compiler must not assume a data type based on the name of a variable.

For more information on declaring variables, see the related documents under "Data

Storage" on the Aer E 160 homepage.

The executable statements first assign the value 1 to a, then 2 to b, then the sum a+b to c.

The value of c is 3 after this operation (and undefined before). The WRITE statement

produces the following output on the screen:

These operations and others are described in several different documents on the Aer E

160 homepage.

For the structure of a FORTRAN program with subroutines, functions and/or modules, see the

corresponding documents under "Program Structures" on the Aer E 160 webpage.