We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23
A tutorial Introduction
to Fortran
Siddhartha Ghosh sghosh@ucar.edu Consulting Services Group
Scientific Computing Division
Contents
Scientific Computing Division
References
Scientific Computing Division
Data types Any computer program in its most basic form: • Loads data from memory • does some operations using those data and • stores data again in same or different locations A simple example: c=a+b In Fortran, these memory locations have an associated type i.e. a predefined way to interpret the sequence of bits Scientific Computing Division Fortran Intrinsic Data types
Scientific Computing Division
Arithmetic Operators
Range and precision of basic datatypes
• integer : range +/- 2^31-1 • real : range +/- 10^38 with 7 digits • real(8) : range +/- 10^308 with 15 digits
Scientific Computing Division
Arithmetic relational operators
Scientific Computing Division
Conditional Statements
Scientific Computing Division
Logical operators
Scientific Computing Division
Loops • Most common is do loop where you have a counter to track the count • Loop till some condition is met i.e. while loop • There are other loops e.g. forall which we will not cover here.
Scientific Computing Division
Arrays
Scientific Computing Division
Arrays, smart operations
Scientific Computing Division
Functions and Subroutines
Scientific Computing Division
Modules
Scientific Computing Division
User defined data-types
Scientific Computing Division
Formatted I/O
Scientific Computing Division
Formatted I/O to files
Scientific Computing Division
Namelist
Scientific Computing Division
Binary I/O
Scientific Computing Division
I/O using netcdf files
Scientific Computing Division
netcdf • You may enquire structure of a netcdf file using ncdump • You will notice in the example program the typical sequence of writing a netcdf file is: (a) define a netcdf dataset (b) define dimensions needed for variables (c) define variables and finally (d) write the variables. • While reading you may enquire and find all the dimension (or metadata) information unlike in case of binary I/O. • Also notice the filesizes which is closer to corresponding binary file sizes. Scientific Computing Division 1d Shallow Water Eqn. (A toy problem) • The equations:
=0
=0
The rigid boundary at both ends. Refer to the appendix of