Introduction to Fortran 90 Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Fortran 90 Programming

Description:

Cygwin is a Linux-like environment for Windows that consists of two parts: ... How to start cygwin ... Compile by typing g95 hello.f90 (in the cygwin window) ... – PowerPoint PPT presentation

Number of Views:469
Avg rating:3.0/5.0
Slides: 24
Provided by: geoUni
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Fortran 90 Programming


1
Introduction to Fortran 90 Programming
André Paul
2
Reading
  • The following notes are based on
  • Ellis, T.M.R., Phillips, Ivor R., and Lahey,
    Thomas M. Fortran 90 Programming, Addison-Wesley
    Publishing Company.

3
Telling a Computer What To Do
  • To get a computer to perform a specific task it
    must be given a sequence of unambiguous
    instructions or a program.
  • Generating a program
  • Text file with instructions (Source Code
    Fortran 90)
  • Translation into computer-compatible form
    (Compiler)
  • Executable Program

4
The Linux look and feel
  • Cygwin is a Linux-like environment for Windows
    that consists of two parts
  • A DLL (Dynamic Link Library, cygwin1.dll)
  • A collection of tools, which provide Linux look
    and feel
  • Link http//www.cygwin.com

5
A few useful Linux commands
  • pwd print name of current/working directory
  • ls list directory contents
  • cd change directory
  • mkdir make directories
  • rm remove files or diretories
  • man format and display the on-line manual pages
    (e.g. man pwd)

6
How to start cygwin
  • Open cygwin window by double-clicking on the
    start_cygwin DOS batchfile provided with this
    exercise
  • If this does not work ...

7
How to start cygwin II
  • Double-click on the cygwin icon on the desktop
  • In the computer room, try typing cd "ceida"
  • If this does not work ...

8
How to get to your directory
  • Copy the file /dozent/public/Austausch/anma/.profi
    le to your cygwin home directory

9
How to get to your directory II
  • Try it the long way
  • cd c
  • cd Dokumente und Einstellungen
  • cd put your username here
  • cd Eigene Dateien
  • cd put your working directory here

10
Creating and Running a Program
  • Invoke the editor from the Start menu, or type

into the cygwin window to create a file called
hello.f90.
11
Creating and Running a Program
  • Use the editor to create a file called hello.f90,
    which contains the following source code
  • Compile by typing g95 hello.f90 (in the cygwin
    window)
  • Run the program by typing ./a.exe (g95 by default
    creates an executable called a.exe)

12
Basic Fortran 90 concepts
  • All words which have a special meaning in Fortran
    are known as keywords.
  • Every main program unit must start with a PROGRAM
    statement which consists of the word PROGRAM
    followed by the name of the program as given by
    the programmer.

13
Avoid implicit declaration
  • The special IMPLICIT NONE statement should always
    be placed immediately after the PROGRAM
    statement. It instructs the compiler that all
    variables must be declared before use.

14
Basic building blocks
  • A main program unit

15
REAL and INTEGER variables
  • Use the INTEGER name statement to declare a
    whole-number variable
  • Use the REAL name statement to declare a
    floating-point variable

16
Repeating parts of your program
17
Using files to preserve data
  • Connecting external files to your program
  • Connect a file to a unit by OPEN(UNITunit_number
    ,FILEfile_name), where unit_number is an integer
    number, variable or parameter and file_name is a
    character expression.

18
  • Write a record to a file by WRITE
    (UNITunit_number,FMT)
  • Disconnect a file from a unit by means of a CLOSE
    (UNITunit_number) statement

19
Introduction to arrays
20
Parameterized REAL variables
  • REAL variables (floating point numbers) are
    parameterized
  • The kind type parameter specifies minimum
    precision and exponent range requirements.

21
  • ! Parameter declarations
  • ! Symbolic name for a real kind type with at
    least
  • ! 15 decimal digits of precision and an exponent
    range
  • ! from 10300 to 10(-300) (double precision)
  • INTEGER, PARAMETER dpSELECTED_REAL_KIND(P15,R
    300)
  • ! Symbolic name for a real kind type with at
    least
  • ! 6 decimal digits of precision and an exponent
    range
  • ! from 1030 to 10(-30) (single precision)
  • INTEGER, PARAMETER spSELECTED_REAL_KIND(P6,R
    30)
  • ! Symbolic name for a default real kind type
  • INTEGER, PARAMETER qdp
  • ! Variable declarations
  • REAL(KINDq) dpress
  • REAL(KINDq), DIMENSION(1km) p

22
Functions and subroutines
REAL(KINDq) FUNCTION feuler(y,s,dx)
IMPLICIT NONE !-----------------------------
------------------------------------ ! This
function integrates one time step using the
forward Euler ! method for the ODE dy/dx
f(x,y(x)) ! ! Input arguments
! y temperature (K) ! s solar
radiation (W m(-2)) ! dx time step
(s) ! ! Result variable !
feuler dy ! ! Uses external
function rhs ! ! Based on code by M.
Yoshimori !---------------------------------
--------------------------------
REAL(KINDq), INTENT(IN) y,s,dx feuler
rhs(y,s)dx END FUNCTION feuler
23
The block IF construct
  • ! Variable declarations
  • ! tol criteria of convergence (K)
  • REAL(KINDq) tol
  • ..
  • ! Initializations
  • tol 1.0E-03_q
  • ..
  • ! Time loop
  • DO itt1,ittmax
  • ..
  • ! Test for convergence
  • IF (ABS(tf ti) lt tol) THEN
  • EXIT
  • END IF
  • END DO
Write a Comment
User Comments (0)
About PowerShow.com