An Introduction to Fortran

Size: px
Start display at page:

Download "An Introduction to Fortran"

Transcription

1 An Introduction to Fortran Sylvia Plöckinger March 10, 2011 Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

2 General Information Find this file on: Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

3 Outline 1 Literature 2 History 3 Fortran 90 4 Declaration Part 5 Execution Part 6 Modules 7 Back to F77 8 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

4 Literature Literature in the Astronomy Library: Fortran 90/95 for Scientists and Engineers, Stephen J. Chapman Introduction to Programming with Fortran, I. Chivers, J. Sleightholme Fortran for the 90s, Stacey L. Edgar Fortran 90 Programming,T. M. R. Ellis, I. R. Philips, T. M. Lahey Fortran 90 Language Guide, Wilhelm Gehrke Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

5 History The early days... Up tp 1954 Machine language (0,1 - binary) Assembler (mnemonics) Problem: Machine dependent + Higher-level language should be understandable by both humans and machines IBM team led by John Backus developed the first higher level language: Fortran (Formula Translator) very successful First standard Fortran Relatively machine independent Was widely available Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

6 History Next standard: Fortran 77 Column 1-6 1: Line is a comment if a c or a * is inserted 2-5: Labels for GOTO or FORMAT statements 6: Any symbol beside blank or 0 line continues Column 7-72 Actual Fortran statements Column Comments, not read by compiler, originally for sequence numbers of punched cards Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

7 History General Remarks: Your program should be: efficient (in both CPU time and memory) readable (documentation, variable names, indentation,...) portable (machine independent, compiler independent) modular (subroutines can be used otherwise) Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

8 Fortran 90 Fortran 90 Program A program consists of modules, like Program Subroutine Function Interface Module Fortran 90 Modules Every module consists of (Documentation) Header Declaration Part (variable declaration, use statements) Execution Part End Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

9 Declaration Part Declaration Part Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

10 Declaration Part Declaration Part - Variables and Constants Variable names are symbolic references for positions within the memory. They are reserved already by the compiler, but get their values assigned at runtime. The memory for constants is already filled with the value at compilation. Declare all variables and constants explicitly! (Implicit: I-N - Integer, A-H and O-Z - Real) Fortran 77 IMPLICIT NONE INTEGER c REAL ix,x,y,z CHARACTER*10 name LOGICAL a DOUBLE PRECISION b Fortran 90 IMPLICIT NONE INTEGER (kind=4) :: c REAL (kind=4) :: ix, x, y, z CHARACTER (len=10) :: name LOGICAL :: a REAL (kind=8) :: b Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

11 Declaration Part A quick side note on the binary system Integer values: 16 bit (2 byte): [ , ] up to bit (4 byte): [ , ] up to = = 3 Floating point values: = = Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

12 Declaration Part Floating Point numbers SINGLE PRECISION (32 bit or 4 byte) DOUBLE PRECISION (64 bit or 8 byte) Sign: Exponent: Significand: Size = 1 bit Size = 8 bit (single), 11 bit (double) Size = 23 bit (single), 52 bit (double) Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

13 Declaration Part Floating Point numbers Roundoff error Finite accuracy of number representation Decimal: π, 2, 1 3 Binary: 0.1 Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

14 Declaration Part Machine Accuracy ɛ m The smallest number that can be added to 1. and gives as a result a number that is different to 1. For a real number (4 byte) typically For example: 1.E = 1.E07 no matter how often you perform this calculation Error estimation For a randomly distributed error, after N operations: Nɛ m Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

15 Declaration Part KIND - A side mark to the topic of portability It is up to each compiler configuration to decide what kind numbers are associated with each type and kind variation kind value on its own should not be used across platforms! To make sure the accuracy of you program is machine independent use the intrinsic functions: INTEGER, PARAMETER :: intkind = SELECTED INT KIND (2) INTEGER, PARAMETER :: realkind = SELECTED REAL KIND(P=15,R=307)! P... Precision (f.e. 15 significant digits), R... Range (f.e. [10 307, ] ) INTEGER (KIND = intkind) :: i REAL (KIND = realkind) :: a, b, c Error / accuracy / range estimation: KIND(x) Returns the kind type HUGE(x) Returns the largest number PRECISION(x) Returns the decimal precision EPSILON(x) Smallest difference between two reals Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

16 Declaration Part Other options in the declaration part PARAMETER INTEGER, PARAMETER :: imax = ! whats the difference to that: INTEGER:: imax = REAL, PARAMETER :: pi = 4. * ATAN (1.) Parameter cannot be changed within the program. Memory gets the value already at runtime. DIMENSION INTEGER :: i, j REAL, DIMENSION (100) :: x, y, temp1d REAL, DIMENSION(100,100) :: temp DO i = 1,100,1 x(i) = REAL(i) y(i) = REAL(i) DO j = 1,100,1 temp(i,j) = * & SIN(x(i)) * COS(x(i)*y(j)) ENDDO ENDDO! Not in F77 : temp1d = 0. temp1d = temp (50,:) Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

17 Declaration Part Other options in the declaration part ALLOCATABLE INTEGER :: i, j, nsteps REAL, DIMENSION (:), ALLOCATABLE :: x, y REAL, DIMENSION(:,:), ALLOCATABLE :: temp write (*,*) how many steps in x and y direction? read (*,*) nsteps allocate (x (nsteps) ) allocate (y (nsteps) ) allocate (temp (nsteps, nsteps) ) DO i = 1,100,1 x(i) = REAL(i) y(i) = REAL(i) DO j = 1,100,1 temp(i,j) = * & SIN(x(i)) * COS(x(i)*y(j)) ENDDO ENDDO deallocate (x) deallocate (y) deallocate (temp) OTHERS INTENT(IN) (OUT) (INOUT) PRIVATE PUBLIC SAVE EXTERNAL INTRINSIC OPTIONAL POINTER TARGET Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

18 Execution Part Execution Part Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

19 Execution Part IF Statement IF <logical expression> THEN... ENDIF Logical Expressions IF (a < b) THEN means: IF ( (a < b) ==.true.) THEN IF <logical expression> THEN... ELSE... ENDIF IF <logical expression> THEN... IF <logical expression> THEN... ELSE IF <logical expression> THEN... ELSE... ENDIF ENDIF (a < b): relational ( < <= > >= == /= ) (.LT..LE..GT..GE..EQ..NE. ) (a < b).and. (c > d): logical (.NOT..AND..OR..EQV..NEQV.) Relational expressions have a higher priority than logical expressions. Question!!What could that mean: IF (a) b=b+1!or that: IF (r < N ) EXIT Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

20 Execution Part CASE Construct... INTEGER (kind=1) :: month... SELECT CASE (month) CASE (12,1,2) write (*,*) Winter CASE (3:5) write (*,*) Spring CASE (6:8) write (*,*) Summer CASE (9:11) write (*,*) Autumn CASE DEFAULT write (*,*) Error: Something is wrong with your date END SELECT Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

21 Execution Part DO Loop INTEGER (kind = 1) :: x INTEGER (kind = 2) :: f x DO x = 1, 10, 2 f x = x*x + 10 write (*,*) x, f x ENDDO INTEGER (kind = 1) :: x INTEGER (kind = 2) :: f x x=1 DO f x = x*x write (*,*) x, f x IF (x > 10) EXIT x = x+2. ENDDO INTEGER (kind = 2) :: ix, iy REAL (kind = 4) :: x, y, f xy DO ix = -30, 30, 1 x = REAL(ix) / 10. DO iy = -30, 30, 1 y = REAL(iy) / 10. f xy = (x** *y**2-yy)*exp(1.-(x**2+y**2)) write (*,*) x, y, f x ENDDO ENDDO Be careful: What is the problem here? INTEGER (kind = 2) :: ix, iy REAL (kind = 4) :: x, y, f xy ix= -30; iy= -30 DO x = REAL(ix) / 10. DO y = REAL(iy) / 10. f xy = (x** *y**2-yy)*exp(1.-(x**2+y**2)) write (*,*) x, y, f x IF (iy.gt. 30) EXIT iy = iy + 1 ENDDO IF (ix.gt. 30) EXIT ix = ix + 1 ENDDO Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

22 Execution Part DO Loop INTEGER (kind = 1) :: x INTEGER (kind = 2) :: f x DO x = 1, 10, 2 f x = x*x + 10 write (*,*) x, f x ENDDO INTEGER (kind = 1) :: x INTEGER (kind = 2) :: f x x=1 DO f x = x*x write (*,*) x, f x IF (x > 10) EXIT x = x+2. ENDDO Loop Counter Avoid infinite loops : INTEGER (kind = 4), PARAMETER :: imax = INTEGER (kind = 4) :: i i = 0 DO IF (i > imax) EXIT i = i+1 ENDDO INTEGER (kind = 2) :: ix, iy REAL (kind = 4) :: x, y, f xy DO ix = -30, 30, 1 x = REAL(ix) / 10. DO iy = -30, 30, 1 y = REAL(iy) / 10. f xy = (x** *y**2-yy)*exp(1.-(x**2+y**2)) write (*,*) x, y, f x ENDDO ENDDO Corrected version INTEGER (kind = 2) :: ix, iy REAL (kind = 4) :: x, y, f xy ix= -30! ; iy= -30 DO iy= -30 x = REAL(ix) / 10. DO y = REAL(iy) / 10. f xy = (x** *y**2-yy)*exp(1.-(x**2+y**2)) write (*,*) x, y, f x IF (iy.gt. 30) EXIT iy = iy + 1 ENDDO IF (ix.gt. 30) EXIT ix = ix + 1 ENDDO Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

23 Modules F90 Modules Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

24 Modules Subroutines Example: PROGRAM test IMPLICIT NONE INTEGER :: type REAL :: r, p, d, g... call equation of state (type, t, p, d, g)... END PROGRAM test SUBROUTINE equation of state (type, temp, pres, & dens, gamma) IMPLICIT NONE INTEGER :: type REAL :: temp, pres, dens, gamma... END SUBROUTINE equation of state Advantages: Keeps the code structured Test each code segments separately Include already existing segments Numerical Recipes!!! Use a given segment frequently in a code Use a self-written subroutine in different programs Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

25 Modules Functions A function itself needs a variable declaration and gives back a value. Syntax PROGRAM main IMPLICIT NONE REAL :: plummer dens, edge dens, totalmass, & plummer rad, cutoff rad... edge dens = plummer dens(totalmass, plummer rad, cutoff rad) END PROGRAM main FUNCTION plummer dens (totalmass, plummer rad, cutoff rad) IMPLICIT NONE REAL :: plummer dens, edge dens, totalmass, plummer rad, cutoff rad plummer dens =... END FUNCTION plummer dens Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

26 Modules Modules Sharing variables between different routines: Syntax MODULE constants IMPLICIT NONE REAL, PARAMETER :: pi = 4.*ATAN(1.) REAL, PARAMETER :: Msol = E33 REAL, PARAMETER :: parsec = E18 END MODULE constants PROGRAM main USE constants, ONLY: pi WRITE (*,*) Pi =, pi END Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

27 Modules Main program of the powerful FLASH3.2 code program Flash use Driver interface implicit none call Driver initflash() call Driver evolveflash() call Driver finalizeflash() end program Flash Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

28 Back to F77 Back to Fortran 77 Common Block - Syntax PROGRAM main IMPLICIT NONE REAL a, b COMMON /coeff/ a, b CALL solve END PROGRAM main SUBROUTINE solve IMPLICIT NONE REAL a, b COMMON /coeff/ a, b... END SUBROUTINE solve Common Block + Include PROGRAM main INCLUDE main.inc CALL solve END PROGRAM main SUBROUTINE solve INCLUDE main.inc... END SUBROUTINE solve! file main.inc : IMPLICIT NONE REAL a,b COMMON /coeff/ a, b Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

29 Back to F77 Compiler and Linker We use: gfortran <options> <infile 1> <infile 2>... To find out about the options:> man gfortran Some helpful options: -fdefault-integer-8 : Set the default integer and logical types to the 8 byte wide type -fdefault-real-8 : Set the default real type to the 8 byte wide type -fimplicit-none : Equivalent of adding implicit none to the start of every procedure -o <output>: Output file not default (a.out) but <output> The compiler is treating every routine separately no error message when the declarations of values which are exchanged do not fit together! Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

30 Gnuplot Gnuplot Homepage: Freely distributed Command line driven Available for a lot of different platforms Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

31 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

32 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

33 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

34 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

35 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

36 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

37 Gnuplot Try out the following with the 3D data from last week: set pm3d at b set contour base set surface set view 70,60,1.0,1.5 set dgrid3d 50, 50 set hidden3d show contour splot "data3d.dat" u 1:2:3 w line palette Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

38 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

39 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

40 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

41 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

42 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

43 Gnuplot Sylvia Plöckinger () An Introduction to Fortran March 10, / 43

Review More Arrays Modules Final Review

Review More Arrays Modules Final Review OUTLINE 1 REVIEW 2 MORE ARRAYS Using Arrays Why do we need dynamic arrays? Using Dynamic Arrays 3 MODULES Global Variables Interface Blocks Modular Programming 4 FINAL REVIEW THE STORY SO FAR... Create

More information

AMath 483/583 Lecture 7

AMath 483/583 Lecture 7 AMath 483/583 Lecture 7 This lecture: Python debugging demo Compiled langauges Introduction to Fortran 90 syntax Declaring variables, loops, booleans Reading: class notes: Python debugging class notes:

More information

AMath 483/583 Lecture 7. Notes: Notes: Changes in uwhpsc repository. AMath 483/583 Lecture 7. Notes:

AMath 483/583 Lecture 7. Notes: Notes: Changes in uwhpsc repository. AMath 483/583 Lecture 7. Notes: AMath 483/583 Lecture 7 This lecture: Python debugging demo Compiled langauges Introduction to Fortran 90 syntax Declaring variables, loops, booleans Reading: class notes: Python debugging class notes:

More information

AN INTRODUCTION TO FORTRAN 90 LECTURE 2. Consider the following system of linear equations: a x + a x + a x = b

AN INTRODUCTION TO FORTRAN 90 LECTURE 2. Consider the following system of linear equations: a x + a x + a x = b AN INTRODUCTION TO FORTRAN 90 LECTURE 2 1. Fortran 90. Arrays, functions and subroutines. 2. Scientific plotting. Gnuplot 1 Each coefficient and variable is a scalar. Lengthy and cumbersome! Program Scalar

More information

Evolution of Fortran. Presented by: Tauqeer Ahmad. Seminar on Languages for Scientific Computing

Evolution of Fortran. Presented by: Tauqeer Ahmad. Seminar on Languages for Scientific Computing Evolution of Fortran Presented by: Seminar on Languages for Scientific Computing Outline (1) History of Fortran Versions FORTRAN I FORTRAN II FORTRAN III FORTRAN IV FORTRAN 66 FORTRAN 77 Evolution of FORTRAN

More information

A quick guide to Fortran

A quick guide to Fortran A quick guide to Fortran Sergiy Bubin Department of Physics Nazarbayev University History of Fortran One of the oldest general purpose high-level computer languages First developed in 1957 at IBM in the

More information

Fortran. (FORmula TRANslator) History

Fortran. (FORmula TRANslator) History Fortran (FORmula TRANslator) History FORTRAN vs. Fortran 1954 FORTRAN first successful high level language John Backus (IBM) 1958 FORTRAN II (Logical IF, subroutines, functions) 1961 FORTRAN IV 1966 FORTRAN

More information

Reflection Seismology (SCPY 482) An Introduction to Fortran 90 Programming

Reflection Seismology (SCPY 482) An Introduction to Fortran 90 Programming Reflection Seismology (SCPY 482) An Introduction to Fortran 90 Programming Chaiwoot Boonyasiriwat September 18, 2014 Outline Why Fortran 90? Hello World Compilation and Execution Recommended Program Structure

More information

IEEE 754 Floating-Point Format

IEEE 754 Floating-Point Format PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 IEEE 754 Floating-Point Format PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Floating-Point Decimal Number 123456. 10 1 = 12345.6 10 0 = 1234.56 10

More information

Table 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind

Table 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind Chapter 2 Data Types Any computer program is going to have to operate on the available data. The valid data types that are available will vary from one language to another. Here we will examine the intrinsic

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Introduction to Modern Fortran

Introduction to Modern Fortran Introduction to Modern Fortran p. 1/?? Introduction to Modern Fortran See next foil for copyright information Nick Maclaren nmm1@cam.ac.uk March 2014 Introduction to Modern Fortran p. 2/?? Acknowledgement

More information

AMath 483/583 Lecture 8

AMath 483/583 Lecture 8 AMath 483/583 Lecture 8 This lecture: Fortran subroutines and functions Arrays Dynamic memory Reading: class notes: Fortran Arrays class notes: Fortran Subroutines and Functions class notes: gfortran flags

More information

Review Functions Subroutines Flow Control Summary

Review Functions Subroutines Flow Control Summary OUTLINE 1 REVIEW 2 FUNCTIONS Why use functions How do they work 3 SUBROUTINES Why use subroutines? How do they work 4 FLOW CONTROL Logical Control Looping 5 SUMMARY OUTLINE 1 REVIEW 2 FUNCTIONS Why use

More information

2. Basic Elements of Fortran

2. Basic Elements of Fortran 2. Basic Elements of Fortran Structure of a Fortran Program 31 characters must be in the 1st line if present declaration section program my_first_program! Declare variables integer :: i, j, k! i, j, k

More information

An introduction to Fortran. Daniel Price School of Physics and Astronomy Monash University Melbourne, Australia

An introduction to Fortran. Daniel Price School of Physics and Astronomy Monash University Melbourne, Australia An introduction to Fortran Daniel Price School of Physics and Astronomy Monash University Melbourne, Australia Part I: Introduction to FORTRAN A brief history of Fortran (and FORTRAN) developed in the

More information

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 Name :. Roll No. :..... Invigilator s Signature :.. 2011 INTRODUCTION TO PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give

More information

PROBLEM SOLVING WITH FORTRAN 90

PROBLEM SOLVING WITH FORTRAN 90 David R. Brooks PROBLEM SOLVING WITH FORTRAN 90 FOR SCIENTISTS AND ENGINEERS Springer Contents Preface v 1.1 Overview for Instructors v 1.1.1 The Case for Fortran 90 vi 1.1.2 Structure of the Text vii

More information

41391 High performance computing: Miscellaneous parallel programmes in Fortran

41391 High performance computing: Miscellaneous parallel programmes in Fortran 1391 High performance computing: Miscellaneous parallel programmes in Fortran Nilas Mandrup Hansen, Ask Hjorth Larsen January 19, 0 1 Introduction This document concerns the implementation of a Fortran

More information

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill 12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring Chris Hill Review of last lecture Start examining the FORTRAN language Development of the language Philosophy of language:

More information

Introduction to Fortran Programming. -Internal subprograms (1)-

Introduction to Fortran Programming. -Internal subprograms (1)- Introduction to Fortran Programming -Internal subprograms (1)- Subprograms Subprograms are used to split the program into separate smaller units. Internal subprogram is not an independent part of a program.

More information

Walt Brainerd s Fortran 90 programming tips

Walt Brainerd s Fortran 90 programming tips Walt Brainerd s Fortran 90 programming tips I WORKETA - March, 2004 Summary by Margarete Domingues (www.cleanscape.net/products/fortranlint/fortran-programming tips.html) Fortran tips WORKETA - 2004 p.1/??

More information

Goals for This Lecture:

Goals for This Lecture: Goals for This Lecture: Understand what modules are Understand what module procedures are and how to use them Understand explicit and implicit interfaces Understand what automatic arrays are and how to

More information

Our Strategy for Learning Fortran 90

Our Strategy for Learning Fortran 90 Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

Python: Functions. Thomas Schwarz, SJ Marquette University

Python: Functions. Thomas Schwarz, SJ Marquette University Python: Functions Thomas Schwarz, SJ Marquette University History Early computer programming was difficult Not only because interacting with the computer was difficult Data was entered by setting switches,

More information

REGCM 4.3 Developer Guide

REGCM 4.3 Developer Guide REGCM 4.3 Developer Guide Stefano Cozzini CNR/IOM Democritos, Trieste, Italy and Graziano Giuliani ICTP Earth System Physics Section, Trieste, Italy Contents 1 Introduction ii 1.1 About Fortran90 in REGCM

More information

Summer 2003 Lecture 14 07/02/03

Summer 2003 Lecture 14 07/02/03 Summer 2003 Lecture 14 07/02/03 LAB 6 Lab 6 involves interfacing to the IBM PC parallel port Use the material on wwwbeyondlogicorg for reference This lab requires the use of a Digilab board Everyone should

More information

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017 FORTRAN 90: Functions, Modules, and Subroutines Meteorology 227 Fall 2017 Purpose First step in modular program design Cannot always anticipate all of the steps that will be needed to solve a problem Easier

More information

Computational Astrophysics AS 3013

Computational Astrophysics AS 3013 Computational Astrophysics AS 3013 Lecture 2: 1) F90 variable types 2) variable declaration 3) good programming style AS3013: F90 lecture2 1 Fortran 90 variable types integer whole numbers: 3, 244, -10,

More information

Introduction to FORTRAN

Introduction to FORTRAN Introduction to by Dr. Ibrahim A. Assakkaf Spring 2000 Department of Civil and Environmental Engineering University of Maryland Slide No. 1 Introduction = FORmula TRANslation Developed for the IBM 704

More information

Goals for This Lecture:

Goals for This Lecture: Goals for This Lecture: Learn about multi-dimensional (rank > 1) arrays Learn about multi-dimensional array storage Learn about the RESHAPE function Learn about allocatable arrays & the ALLOCATE and DEALLOCATE

More information

1996 ILLINOIS JETS TEAMS DISTRICT COMPUTER FUNDAMENTALS TEST. 1. A computer program is:

1996 ILLINOIS JETS TEAMS DISTRICT COMPUTER FUNDAMENTALS TEST. 1. A computer program is: 1996 ILLINOIS JETS TEAMS DISTRICT COMPUTER FUNDAMENTALS TEST 1. A computer program is: a. a sequence of binary machine instructions b. a sequence of operations to carry out a defined task c. a set of computer

More information

Welcome. Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at BST

Welcome. Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at BST Welcome Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at 15.00 BST Modern Fortran: F77 to F90 and beyond Adrian Jackson adrianj@epcc.ed.ac.uk @adrianjhpc Fortran Ancient History (1967)

More information

Computer Systems C S Cynthia Lee

Computer Systems C S Cynthia Lee Computer Systems C S 1 0 7 Cynthia Lee 2 Today s Topics LECTURE: Floating point! Real Numbers and Approximation MATH TIME! Some preliminary observations on approximation We know that some non-integer numbers

More information

Goals for This Lecture:

Goals for This Lecture: Goals for This Lecture: Understand what function subprograms are Understand how to use function subprograms Understand the various kinds of REAL types Understand how to select precision in a processor

More information

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia Floating Point CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/899/

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

CS16 Exam #1 7/17/ Minutes 100 Points total

CS16 Exam #1 7/17/ Minutes 100 Points total CS16 Exam #1 7/17/2012 75 Minutes 100 Points total Name: 1. (10 pts) Write the definition of a C function that takes two integers `a` and `b` as input parameters. The function returns an integer holding

More information

C interfaces to HSL routines. J. D. Hogg. Version 1.0 5th December Numerical Analysis Group Internal Report

C interfaces to HSL routines. J. D. Hogg. Version 1.0 5th December Numerical Analysis Group Internal Report 2011-1 Numerical Analysis Group Internal Report C interfaces to HSL routines J. D. Hogg Version 1.0 5th December 2011 Copyright (c) 2011 Science and Technology Facilities Council C interfaces to HSL routines

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

NAGWare f95 and reliable, portable programming.

NAGWare f95 and reliable, portable programming. NAGWare f95 and reliable, portable programming. Malcolm Cohen The Numerical Algorithms Group Ltd., Oxford How to detect errors using NAGWare f95, and how to write portable, reliable programs. Support for

More information

Exercises Lecture III: Random numbers with non uniform distributions; simulations of simple random processes

Exercises Lecture III: Random numbers with non uniform distributions; simulations of simple random processes Exercises Lecture III: Random numbers with non uniform distributions; simulations of simple random processes 1. Random numbers with non uniform distributions: Inverse Transformation Method (a) With the

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

ParaFEM Coding Standard for Fortran 90. Contents. 1.0 Introduction. 2.0 Documentation. 2.1 External Documentation

ParaFEM Coding Standard for Fortran 90. Contents. 1.0 Introduction. 2.0 Documentation. 2.1 External Documentation ParaFEM Coding Standard for Fortran 90 This standard has been prepared by Lee Margetts, Francisco Calvo and Vendel Szeremi at the University of Manchester. It is based on Version 1.1 of the European Standards

More information

2.1.1 Fixed-Point (or Integer) Arithmetic

2.1.1 Fixed-Point (or Integer) Arithmetic x = approximation to true value x error = x x, relative error = x x. x 2.1.1 Fixed-Point (or Integer) Arithmetic A base 2 (base 10) fixed-point number has a fixed number of binary (decimal) places. 1.

More information

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken

More information

ME1107 Computing Y Yan.

ME1107 Computing Y Yan. ME1107 Computing 1 2008-2009 Y Yan http://www.staff.city.ac.uk/~ensyy About Fortran Fortran Formula Translation High level computer language Basic, Fortran, C, C++, Java, C#, (Matlab) What do we learn?

More information

Fortran Coding Standards and Style

Fortran Coding Standards and Style Fortran Coding Standards and Style The Fortran Company Version 20160112 Copyright 2015-2016, The Fortran Company All rights reserved. Redistribution, with or without modification, is permitted provided

More information

Fortran 90 - A thumbnail sketch

Fortran 90 - A thumbnail sketch Fortran 90 - A thumbnail sketch Michael Metcalf CERN, Geneva, Switzerland. Abstract The main new features of Fortran 90 are presented. Keywords Fortran 1 New features In this brief paper, we describe in

More information

Data Representation in Computer Memory

Data Representation in Computer Memory Data Representation in Computer Memory Data Representation in Computer Memory Digital computer stores the data in the form of binary bit sequences. Binary number system has two symbols: 0 and 1, called

More information

Lecture V: Introduction to parallel programming with Fortran coarrays

Lecture V: Introduction to parallel programming with Fortran coarrays Lecture V: Introduction to parallel programming with Fortran coarrays What is parallel computing? Serial computing Single processing unit (core) is used for solving a problem One task processed at a time

More information

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types Data Types Declarations and Initializations Larry Caretto Computer Science 16 Computing in Engineering and Science February 7, 25 Outline Review last week Meaning of data types Integer data types have

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

Fortran90 Bindings for Charm++

Fortran90 Bindings for Charm++ Fortran90 Bindings for Charm++ January 20, 2018 Charm++ is a parallel object language based on C++. The f90charm module is to provide Fortran90 programs a f90 interface to Charm++. Using the F90Charm interface,

More information

10. Additional Intrinsic Data Types

10. Additional Intrinsic Data Types 10. Additional Intrinsic Data Types Example: You have written a test driver for SGESV in LAPACK consists of the following steps: 1. Generate the elements of the matrix [A] and the vector {x_exact} using

More information

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100 GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,

More information

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II Basics of Computation Basics of Computation Computers store information and allow us to operate on it. That's basically it. Computers have finite memory, so it is not possible to store the infinite range

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

Principles of Programming Languages. Lecture Outline

Principles of Programming Languages. Lecture Outline Principles of Programming Languages CS 492 Lecture 1 Based on Notes by William Albritton 1 Lecture Outline Reasons for studying concepts of programming languages Programming domains Language evaluation

More information

ASP4100 Introduction to honours computing

ASP4100 Introduction to honours computing School of Physics and Astronomy ASP4100 ASP4100 Introduction to honours computing Version control with git + advanced Fortran 1 Version control with git It begins with I broke the code, what if I could

More information

1. In COMAL language programs, parameters after name of procedure must be put in A. brackets B. back-slash C. insecure data D.

1. In COMAL language programs, parameters after name of procedure must be put in A. brackets B. back-slash C. insecure data D. 1. In COMAL language programs, parameters after name of procedure must be put in A. brackets B. back-slash C. insecure data D. punctuation marks 2. Programming language COBOL works best if used for A.

More information

NO CALCULATOR ALLOWED!!

NO CALCULATOR ALLOWED!! CPSC 203 500 EXAM TWO Fall 2005 NO CALCULATOR ALLOWED!! Full Name (Please Print): UIN: Score Possible Points Prog Points Part One 33 pts Part Two 30 pts Part Three 20 pts Part Four 25 pts Total 108 pts

More information

Run time environment of a MIPS program

Run time environment of a MIPS program Run time environment of a MIPS program Stack pointer Frame pointer Temporary local variables Return address Saved argument registers beyond a0-a3 Low address Growth of stack High address A translation

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

IEEE-754 floating-point

IEEE-754 floating-point IEEE-754 floating-point Real and floating-point numbers Real numbers R form a continuum - Rational numbers are a subset of the reals - Some numbers are irrational, e.g. π Floating-point numbers are an

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1 BIL 104E Introduction to Scientific and Engineering Computing Lecture 1 Introduction As engineers and scientists why do we need computers? We use computers to solve a variety of problems ranging from evaluation

More information

eccodes BUFR decoding

eccodes BUFR decoding eccodes BUFR decoding Fortran 90 and Python API part 1 Marijana Crepulja Marijana.Crepulja@ecmwf.int ECMWF March 7, 2017 Introduction: Fortran 90 subroutines to decode BUFR data Python subroutines to decode

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Data Types and Basic Calculation

Data Types and Basic Calculation Data Types and Basic Calculation Intrinsic Data Types Fortran supports five intrinsic data types: 1. INTEGER for exact whole numbers e.g., 1, 100, 534, -18, -654321, etc. 2. REAL for approximate, fractional

More information

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction Chapter 1: An Overview of Computers and Programming Languages Objectives Objectives (cont d.) In this chapter, you will: Learn about different types of computers Explore hardware and software Learn about

More information

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia Floating Point CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/571/

More information

Why Study Assembly Language?

Why Study Assembly Language? Why Study Assembly Language? This depends on the decade in which you studied assembly language. 1940 s You cannot study assembly language. It does not exist yet. 1950 s You study assembly language because,

More information

Fixed-Point Math and Other Optimizations

Fixed-Point Math and Other Optimizations Fixed-Point Math and Other Optimizations Embedded Systems 8-1 Fixed Point Math Why and How Floating point is too slow and integers truncate the data Floating point subroutines: slower than native, overhead

More information

Introduction to Fortran

Introduction to Fortran Introduction to Fortran Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_us

More information

C++ Tutorial AM 225. Dan Fortunato

C++ Tutorial AM 225. Dan Fortunato C++ Tutorial AM 225 Dan Fortunato Anatomy of a C++ program A program begins execution in the main() function, which is called automatically when the program is run. Code from external libraries can be

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

FORTRAN Block data subprograms 2. Common blocks 3. Entry points 4. Function subprograms 5. Main program 6. Subroutines

FORTRAN Block data subprograms 2. Common blocks 3. Entry points 4. Function subprograms 5. Main program 6. Subroutines FORTRAN77 The first FORTRAN compiler was a milestone in the history of computing, at that time computers had very small memories (on the order of 15KB, it was common then to count memory capacities in

More information

Practical Numerical Methods in Physics and Astronomy. Lecture 1 Intro & IEEE Variable Types and Arithmetic

Practical Numerical Methods in Physics and Astronomy. Lecture 1 Intro & IEEE Variable Types and Arithmetic Practical Numerical Methods in Physics and Astronomy Lecture 1 Intro & IEEE Variable Types and Arithmetic Pat Scott Department of Physics, McGill University January 16, 2013 Slides available from http://www.physics.mcgill.ca/

More information

CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II

CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II Example: Simple variables Handout written by Julie Zelenski and Nick Parlante A variable is a location in memory. When a variable

More information

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 1 Edgardo Molina Fall 2013 City College of New York 1 Introduction to Computing Lectures: Tuesday and Thursday s (2-2:50 pm) Location: NAC 1/202 Recitation:

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Advanced Fortran Programming

Advanced Fortran Programming Sami Ilvonen Pekka Manninen Advanced Fortran Programming March 20-22, 2017 PRACE Advanced Training Centre CSC IT Center for Science Ltd, Finland type revector(rk) integer, kind :: rk real(kind=rk), allocatable

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

A Prototype Finite Difference Model. Timothy H. Kaiser, Ph.D.

A Prototype Finite Difference Model. Timothy H. Kaiser, Ph.D. A Prototype Finite Difference Model Timothy H. Kaiser, Ph.D. tkaiser@mines.edu 1 Examples at http://hpc.mines.edu/examples or enter the commands: mkdir examples cd examples wget http://hpc.mines.edu/examples/examples.tgz

More information

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017 Numerical Modelling in Fortran: day 2 Paul Tackley, 2017 Goals for today Review main points in online materials you read for homework http://www.cs.mtu.edu/%7eshene/courses/cs201/notes/intro.html More

More information

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] Content in [] is optional. Example:- PROGRAM FIRST_PROGRAM IMPLICIT NONE PRINT*,

More information

Variable A variable is a value that can change during the execution of a program.

Variable A variable is a value that can change during the execution of a program. Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does

More information

IEEE Standard for Floating-Point Arithmetic: 754

IEEE Standard for Floating-Point Arithmetic: 754 IEEE Standard for Floating-Point Arithmetic: 754 G.E. Antoniou G.E. Antoniou () IEEE Standard for Floating-Point Arithmetic: 754 1 / 34 Floating Point Standard: IEEE 754 1985/2008 Established in 1985 (2008)

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

Peter Crouch. Chairman Fortran Specialist Group. BCS Birmingham Branch meeting 19 May 2008

Peter Crouch. Chairman Fortran Specialist Group. BCS Birmingham Branch meeting 19 May 2008 Fortran 1957 2008 : A Language with a Past, Present and Future Peter Crouch pccrouch@bcs.org.uk Chairman Fortran Specialist Group www.fortran.bcs.org BCS Birmingham Branch meeting 19 May 2008 My Background

More information

Computational Techniques I

Computational Techniques I Computational Techniques I Course Zero 2017-2018 Madrid Alicia Palacios, alicia.palacios@uam.es Cristina Sanz Sanz, cristina.sanz@uam.es Outline 1. Introduction: how to run, input 2. Data types 3. Declaration

More information

NAGWare f95 Recent and Future Developments

NAGWare f95 Recent and Future Developments NAGWare f95 Recent and Future Developments Malcolm Cohen The Numerical Algorithms Group Ltd., Oxford Nihon Numerical Algorithms Group KK, Tokyo Contents 1. Standard Fortran 2. High Performance 3. NAGWare

More information

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164) Introduction to Programming Languages and Compilers CS164 11:00-12:30 TT 10 Evans 1 ICOM 4036 - Outline Prontuario Course Outline Brief History of PLs Programming Language Design Criteria Programming Language

More information

LECTURE 1. Overview and History

LECTURE 1. Overview and History LECTURE 1 Overview and History COURSE OBJECTIVE Our ultimate objective in this course is to provide you with the knowledge and skills necessary to create a new programming language (at least theoretically).

More information

8. Floating-point Numbers II

8. Floating-point Numbers II Floating-point Number Systems A Floating-point number system is defined by the four natural numbers: 8. Floating-point Numbers II Floating-point Number Systems; IEEE Standard; Limits of Floating-point

More information