Scientific Computing Division A tutorial Introduction to Fortran Siddhartha Ghosh Consulting Services Group.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
The Assembly Language Level
Some computer fundamentals and jargon Memory: Basic element is a bit – value = 0 or 1 Collection of “n” bits is a “byte” Collection of several bytes is.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Fortran 9x HTML version. New F90 features Free source form Modules User-defined data types and operators Generic user-defined procedures Interface blocks.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
FORTRAN.  Fortran or FORmula TRANslation was developed in the 1950's by IBM as an alternative to Assembly Language. First successfull high level language.
Guide To UNIX Using Linux Third Edition
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Chapter 12 Pointers and linked structures. 2 Introduction  The data structures that expand or contract as required during the program execution is called.
C++ fundamentals.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Introduction to Advanced UNIX March Kevin Keay.
Programmer's view on Computer Architecture by Istvan Haller.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CPS120: Introduction to Computer Science Decision Making in Programs.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
I Power Higher Computing Software Development High Level Language Constructs.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Web Database Programming Using PHP
The Machine Model Memory
Chapter 7 User-Defined Methods.
Web Database Programming Using PHP
Lecture: MATLAB Chapter 1 Introduction
Introduction to Scripting
Other Kinds of Arrays Chapter 11
MATLAB: Structures and File I/O
Computational Methods of Scientific Programming
Topics Introduction to File Input and Output
Midterm Review Programming in Fortran
Programming Funamental slides
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to Advanced UNIX
Topics Introduction to File Input and Output
Presentation transcript:

Scientific Computing Division A tutorial Introduction to Fortran Siddhartha Ghosh Consulting Services Group

Scientific Computing Division Contents Basic datatypes Operators for arithmetic and logical variables Condition statements Loops Formatted and Unformatted I/O The netcdf interface Brief description of a toy Model and output

Scientific Computing Division References On-line book: Metcalf and Reid Fortran90 Handbook – Jeanne Adams et. al. Online man pages and documentation G95 project page: http// Fortran news group Numerous news groups, tutorials etc from Google!

Scientific Computing Division 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 In Fortran, these memory locations have an associated type i.e. a predefined way to interpret the sequence of bits A simple example: c = a + b Data types

Scientific Computing Division Fortran Intrinsic Data types integer (by default 4-bytes or 32 bits) real (by default 4-bytes or 32 bits) complex (two reals, by default each 4-bytes) logical (by default 4-byte) character etc. (by default 1-byte)

Scientific Computing Division Arithmetic Operators Common operators +, -, *, / and ** (for power) These can be overloaded or modified to do something different than default 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.LT. for <.LE. for <=.GT. for >.GE. for >=.EQ. for =

Scientific Computing Division Conditional Statements Typical structure of conditional statements are if ( x.ge. y ) statements If (z.lt. p) then statements else statements endif

Scientific Computing Division Logical operators Logical locations can have values.TRUE. And.FALSE. only The operations are AND, OR, NOT, EQV and NEQV Compound conditions may be created using 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 Array is one, two, three.. till seven dimensional rectangular distribution of data defined (or declared) as a(100) e.g. or a(100,10,93) a three dimensional array The elements are accessed through indices Fortran supports very rich array semantics which we will not get into the detail here

Scientific Computing Division Arrays, smart operations Fortran90/95 allows smart operations over arrays: A + B will sum-up corresponding array elements, sizes of A and B will have to be equal Note that this is element by element operations, So often you may not get what you would expect

Scientific Computing Division Functions and Subroutines Function is a block of statements which executes and return a value against a call. Subroutine is exactly the same entity except it does not return a value. Note: In Fortran in function or subroutine call statement the address locations of arguments are passes, so any modifications of argument variables are available to caller after it returns.

Scientific Computing Division Modules The data-structure that are defined within function or subroutine and are not passed through arguments are called automatic variables. These are created during each invocation i.e. it doesn’t remember values of previous invocation. Modules allow sharing of data between different subprogram unit. Also, It allows protection of data, exposing only that is needed.

Scientific Computing Division User defined data-types We have seen intrinsic data types and collection of those in terms of array It may often be convenient to group few data items together The code composite.f90 illustrates such structure.

Scientific Computing Division Formatted I/O We have already used free-formatted write statements. Usually it is convenient to read in free-format i.e. system defined format The syntax for output is: write(unit-no,format-st)variables

Scientific Computing Division Formatted I/O to files Files are associated with unit numbers through a call to open The unit numbers are used in read and write statement to input or output data into files. Often input from a file may be directed to stdin using < sign in Unix. Similarly > filename may be used to dump stdout to a file.

Scientific Computing Division Namelist Namelists are for grouping I/O operations Most often parameter values as well as the name of the startup and output files are read using namelist Often parametric output are dumped to namelist files for subsequent runs.

Scientific Computing Division Binary I/O Most often model statefile containing all the values of physical variables in 3-d grid are rather large It is also required to save the intermediate states for further analysis as well as continuing the integration The above requirement is conveniently met by binary I/O

Scientific Computing Division I/O using netcdf files This is not part of Fortran but in NCAR this exposure would be useful The binary I/O though very efficient has several shortcomings e.g. it is somewhat platform dependent, it does not store sufficient header or metadata information for enquiring the content etc. All these shortcomings are addressed in netcdf and also they added few more goodies

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 The rigid boundary at both ends. Refer to the appendix of This presentation for detail.

Scientific Computing Division