Introduction to Fortran95 Programming Part II. By Deniz Savas, CiCS, Shef. Univ., 2018

Size: px
Start display at page:

Download "Introduction to Fortran95 Programming Part II. By Deniz Savas, CiCS, Shef. Univ., 2018"

Transcription

1 Introduction to Fortran95 Programming Part II By Deniz Savas, CiCS, Shef. Univ., 2018

2 Summary of topics covered Logical Expressions, IF and CASE statements Data Declarations and Specifications ARRAYS and Array Handling Where & Forall statements

3 Logical and Relational Expressions Logical variables can only take one of two values.true. or.false. Logical Operators are;.or..and..not..eqv..neqv. Example: LOGICAL :: A, B, C A =.TRUE. ; B =.NOT. A ; C= A.AND..NOT.B

4 Relational expressions Relational expressions are used for comparing the value of one variable with another variable of the same type. The result of a relational operation is a LOGICAL value of either.true. or.false. Relational expressions are classed as logical expressions and can be mixed with other logical expressions RELATIONAL OPERATORS:.LT..LE..EQ..GE..GT..NE. < <= == >= > /=

5 Logical and Relational expressions EXAMPLES: LOGICAL :: FIRED, LOCKED REAL :: A, B, C INTEGER :: I, J CHARACTER*10 :: NAME1, NAME2 : LOCKED = NAME1.EQ.NAME2.AND. I.LT.J FIRED = A.GE.B.AND. LOCKED

6 Taking Decisions If Statements IF (logical_expression) executable_statement or IF (logical_expression) THEN block ENDIF or IF ( logical_expression) THEN...block... ELSE block ENDIF [ name]

7 IF statement: The full syntax label: IF ( logical_expression) THEN...block... ELSE IF ( logic. expr. ) THEN... block... ELSE... block... ENDIF [ name]

8 Exercises 5 Modify the program you have written earlier about the area of a triangle to make sure that the calculations are performed for only realistic triangles. Hint: For a valid triangle the sum of its two sides must be greater then the length of the remaining side. The answers are given as ex3b, ex3c and ex3d (.f95) files in the answers directory.

9 CASE constructs Use this construct when options for action fall into a fixed set of choices Syntax SELECT CASE ( expression) CASE ( selector) block CASE ( selector) block : END SELECT

10 Example Case Statement CHARACTER (LEN=20) :: MONITOR SELECT CASE ( MONITOR) CASE ( E, EGA ) XRES =320 CASE ( V, VG, VGA ) XRES = 480 CASE ( SVGA, SUPERVGA ) XRES =600 CASE DEFAULT! Note that this means anything else XRES = 480 END SELECT

11 Few usefull compiler flags -c ( compile but not link) -o exefile ( give a name to executable otherwise it is a.out ) -Mfree -Mfixed declare source to be free or fixed form. -Mdclchk Require all variables to be declared. -Mdefaultunit Mnodefaultunit ( Default units behaviour) -Msave -Mnosave : save all local variables -Mbounds Check array bounds during execution -g Produce debugging information -fast Try to optimise the code. -fastsse is even faster on iceberg -r8 Promote reals to Double Precision -g77libs must use this option to link in.o files generated by the g77 compiler (GNU) -lnag -lacml use the NAG library

12 Exercises 6 Perform Exercises 5 & 6 from the exercise sheet

13 Data Specifications & Declarations Type declarations ( built in and user-defined) IMPLICIT statement PARAMETER statement DIMENSION statement DATA statements SAVE statement USE statement

14 Type Declarations type [,attribute] :: list TYPE can be one of ; INTEGER ( KIND= n) - REAL ( KIND=n) COMPLEX( KIND= n ) - LOGICAL(KIND=n) CHARACTER ( LEN=m,KIND=n) where (KIND=n) is OPTIONAL TYPE ( type-name) ATTRIBUTE can be a combination of; PARAMETER - PUBLIC - PRIVATE POINTER - TARGET - ALLOCATABLE DIMENSION - INTENT(inout) - OPTIONAL SAVE - EXTERNAL - INTRINSIC

15 Example Type Declarations Old style, i.e. pre Fortran90 INTEGER N, M PARAMETER ( N = 20, M=30) REAL X, Y, Z, PI DIMENSION X(N), Y(N), Z(N) DATA PI / / New (Fortran90 and above) style INTEGER, PARAMETER :: N =20, M = 30 REAL, DIMENSION(N) :: X, Y, Z REAL :: PI = Note: The above two segments of code are identical in effect.

16 Example use of KIND values in variable declarations INTEGER, PARAMETER :: SMLINT=SELECTED_INT_KIND(2) INTEGER, PARAMETER :: BIGINT=SELECTED_INT_KIND(7) INTEGER,PARAMETER :: BIG=SELECTED_REAL_KIND(7,40) INTEGER(KIND=SMLINT) :: I, J, K INTEGER(KIND=BIGINT) :: ISUM, JSUM REAL ( KIND=BIG) :: A, B,C The Intrinsic function KIND( ) returns the kind value of its argument. EXAMPLE: IKIND = KIND(1.0E60)

17 User Defined Types Also referred to as Derived_Data_Types or Structures EXAMPLE:! First define the type structure TYPE VERTEX REAL X, Y, Z END TYPE VERTEX! Next declare variables of this type. TYPE ( VERTEX ) :: CORNER1, CORNER2! Now we can initialise and use them CORNER2%Y = 2.5 ; CORNER1=( 1.0,1.0,0.2)

18 Derived Types ( Examples) TYPE VERTEX REAL :: X, Y, Z END TYPE VERTEX TYPE PATCH TYPE ( VERTEX ) :: CORNER(4) END TYPE PATCH TYPE (VERTEX) :: P1, P2, P3, P4 TYPE (PATCH) :: MYPATCH, YOURPATCH P1 = ( 0.0, 0.0, 0.0 ) ; P3 = ( 1.0, 1.0, 0.0 ) P2 = ( 1.0, 0.0, 0.0 ) ; P4 = ( 0.0, 1.0, 0.0 ) MYPATCH = ( P1, P2, P3,P4 ) YOURPATCH = MYPATCH YOURPATCH%CORNER(1) = MYPATCH%CORNER(4) - & (1.0,1.0,1.0)

19 Derived Types ( More Examples) TYPE USERNAME CHARACTER*2 :: DEPARTMENT INTEGER :: STATUS CHARACTER*4 :: INITIALS TYPE ( USERNAME ), POINTER :: NEIGHBOUR END TYPE USERNAME TYPE ( USERNAME ), DIMENSION(1000) :: USERS USERS(1) = ( CS, 1, DS ) USERS(12) = ( CS, 1, PF ) USERS(1)%NEIGHBOUR => USERS(12) NULLIFY( USERS(12)%NEIGHBOUR )

20 ARRAYS: Declarations SIMPLE INTEGER, PARAMETER :: N = 36 REAL :: A( 20), B(-1:5), C(4,N,N), D(0:N,0:4) INTEGER, DIMENSION(10,10) :: MX,NX,OX Note that up to 7 dimensional arrays are allowed. ALLOCATABLE ( Dynamic global memory allocation) REAL, ALLOCATABLE :: A(:), B(:,:,:) AUTOMATIC ( Dynamic local memory allocation) REAL, DIMENSION SIZE(A) :: work ASSUMED SHAPE ( Used for declaring arrays passed to procedures ) REAL A(* )! Fortran77 syntax REAL :: A(:)! or A(:,:) so on! Fortran90 syntax

21 Allocatable Array Examples Used for declaring arrays whose size will be determined during run-time. REAL, ALLOCATABLE :: X(:), Y(:,:), Z(:) : READ(*,*) N ALLOCATE( X(N) ) ALLOCATE ( Y(-N:N,0:N ), STAT=status) ALLOCATE ( Z(SIZE(X) ) : DEALLOCATE ( X,Y,Z) END Note: status is an integer variable that will contain 0 if allocation has been successful or a non-zero value to indicate error.

22 Assumed Shape Array Examples Used for declaring the dummy array arguments dimensions to procedures when these vary from call to call. PROGRAM TEST REAL :: AX1(20), AX2(30), AY(10,10), BX1(80), BX2(90),BY(20,30) : Call spline( AX1, AX2, AY) Call spline (BX1, BX2, BY) : END SUBROUTINE SPLINE( X1, X2, Y ) REAL, DIMENSION(:) :: X1, X2 REAL, DIMENSION(:,:) :: Y : RETURN END

23 Automatic Array Examples Use this method when you need short term storage for intermediate results. WORK arrays in NAG library are good examples! SUBROUTINE INTERMIT( X1, X2, Y,M) REAL, DIMENSION(:) :: X1, X2, Y INTEGER :: M REAL, DIMENSION(SIZE(Y) ) :: WORK COMPLEX, DIMENSION(M) :: CWORK : RETURN END

24 Array Terminology RANK, EXTENT, SHAPE and SIZE Determines the conformance CONFORMANCE REAL A( 4,10), B( 0:3,10), C( 4,5,2), D(0:2, -1:4, 6 ) A & B are: rank=2, extents=4 and 10 shape=4,10, size=40 C is rank=3, extents=4,5and 2 - shape=4,5,2 - size=40 D is rank=3 - extents=3, 6 and 6 - shape=3,6,6 - size= 108 For two arrays to be conformable their rank, shape and size must match up. Above only A and B are conformable with each other.

25 Whole Array Operations Whole array operations can be performed on conformable arrays. This avoids using DO loops. REAL :: A(10,3,4), B( 0:9,3,2:5), C(0:9,0:2,0:3) : C = A + B ; C = A*B ; B= C/A ; C =sqrt(a) All the above array expressions are valid.

26 WHERE Statement This feature is a way of implementing vector operation masks. It can be seen as the vector equivalent of the IF statement WHERE (logical_array_expr ) array_var=array_expr WHERE (logical_array_expr ) array_assignments ELSE WHERE array_assignments END WHERE Note: ELSE WHERE clause is optional.

27 REAL :: A(300), B(300) WHERE ( A > 1.0 ) A = 1.0/A WHERE ( A > B) A = B END WHERE Examples WHERE ( A > 0.0.AND. A>B ) A = LOG10( A ) ELSEWHERE A = 0.0 END WHERE

28 FORALL statement This is a new Fortran95 feature. Extending the ability of Fortran Array Processing that was introduced by the WHERE statement. Syntax: FORALL (index=subscript_triplet, scalar_mask_expression) block of executable statements END FORALL

29 FORALL statement example FORALL ( II=1:100,A(II)>0 ) X(II)=X(II)+Y(II) Y(II)= Y(II) * X(II) END FORALL Mask is elements of A between 1 and 100 whose values are positive

30 Referencing Array Elements REAL A (10), X(10,20,30), value INTEGER I, K(10) value = A( 8) OK VALUE = A(12) WRONG!!!! I = 2; value = A( I ) OK J = 3 ; I = 4 ; VALUE = X ( J, 10, I ) Value = X (1.5 ) WRONG!!! OK X(:,1,1) = A(K)! OK assuming K has values within the range 1 to 10

31 Referencing Array Sections REAL :: A(10), B(4,8), C(4,5,6) I = 2 ; J=3 ; K=4 Referencing the array elements: A(2) B(3,4) C( 3,1,1) A(K) B(I,4) C(I,J,K) Referencing the array section: A(2:5) B(1,1:6) C( 1:1,3:4, 1:6 ) A(I:K) B( I:J,K) C(1:I,1:J,5 )

32 Referencing Array Sections (cont.) It is also possible to use a stride index when referring to array sections. The rule is : array(start-index:stop-index:stride,.) Stride can be a negative integer. If start-index is omitted it is assumed to be the lower_bound If stop-index is omitted it is assumed to be the upper_bound For example if array A is declared with DIMENSION(10,20) we can reference a subsections that contains only the even colums as; A(2:10:2,: ) The following are some other examples: A(1:9:3,1:20:2) this is the same as A(1:9:3,::2) A(10:1:-1,: ) this reverses the ordering of first dimension

33 Array Intrinsics Many of the elemental numeric functions such as those listed below can be called with array arguments to return array results ( of same shape and size). abs, sin, acos, exp, log, int, sqrt... There are also additional Vector/Matrix algebra functions designed to perform vector/matrix operations: dot_product, matmul, transpose, minval, sum, size, lbound, ubound, merge, maxloc, pack

34 Array Assignments REAL A(10,10), B(10), C(0:9), D(0:30) A = 1.0 ; B=0.55 B = (/ 3., 5.,6.,1., 22.,8.,16., 4.,9., 12.0 /) I = 3 C = A( I,1:10) D(11:20) = A(I+1,1:10) D(1:10) = D(11:20) D(3:10) = D(5:12) A(2,:) = SIN( B )

35 Exercises Perform exercises 8.1a and 8.1b from the exercises sheet

36 Acknowledgement &References: Thanks to Manchester and North High Performance Computing, Training & Education Centre for the Student Notes. See APPENDIX A of the above notes for a list of useful reference books Fortran 90 for Scientists and Engineers, Brian D Hahn, ISBN Fortran 90 Explained by Metcalf & Reid is available from Blackwells St Georges Lib. Oxford Science Publications, ISBN

37 END OF PART 2

Introduction to Fortran95 Programming Part I. By Deniz Savas, CiCS, Shef. Univ., 2018

Introduction to Fortran95 Programming Part I. By Deniz Savas, CiCS, Shef. Univ., 2018 Introduction to Fortran95 Programming Part I By Deniz Savas, CiCS, Shef. Univ., 2018 D.Savas@sheffield.ac.uk Fortran Standards Fortran 2 Fortran 4 Fortran 66 Fortran 77 : Character variables, File I/O

More information

2 3. Syllabus Time Event 9:00{10:00 morning lecture 10:00{10:30 morning break 10:30{12:30 morning practical session 12:30{1:30 lunch break 1:30{2:00 a

2 3. Syllabus Time Event 9:00{10:00 morning lecture 10:00{10:30 morning break 10:30{12:30 morning practical session 12:30{1:30 lunch break 1:30{2:00 a 1 Syllabus for the Advanced 3 Day Fortran 90 Course AC Marshall cuniversity of Liverpool, 1997 Abstract The course is scheduled for 3 days. The timetable allows for two sessions a day each with a one hour

More information

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

Chapter 4. Fortran Arrays

Chapter 4. Fortran Arrays Chapter 4. Fortran Arrays Fortran arrays are any object with the dimension attribute. In Fortran 90/95, and in HPF, arrays may be very different from arrays in older versions of Fortran. Arrays can have

More information

Subroutines, Functions and Modules

Subroutines, Functions and Modules Subroutines, Functions and Modules Subdividing the Problem Most problems are thousands of lines of code. Few people can grasp all of the details. Good design principle: Exhibit the overall structure in

More information

Introduction to Programming with Fortran 90

Introduction to Programming with Fortran 90 Introduction to Programming with Fortran 90 p. 1/?? Introduction to Programming with Fortran 90 Array Concepts Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 November 2007 Introduction to Programming

More information

High Performance Fortran http://www-jics.cs.utk.edu jics@cs.utk.edu Kwai Lam Wong 1 Overview HPF : High Performance FORTRAN A language specification standard by High Performance FORTRAN Forum (HPFF), a

More information

Fortran Coarrays John Reid, ISO Fortran Convener, JKR Associates and Rutherford Appleton Laboratory

Fortran Coarrays John Reid, ISO Fortran Convener, JKR Associates and Rutherford Appleton Laboratory Fortran Coarrays John Reid, ISO Fortran Convener, JKR Associates and Rutherford Appleton Laboratory This talk will explain the objectives of coarrays, give a quick summary of their history, describe the

More information

Introduction to Modern Fortran

Introduction to Modern Fortran Introduction to Modern Fortran p. 1/?? Introduction to Modern Fortran Advanced Use Of Procedures Nick Maclaren nmm1@cam.ac.uk March 2014 Introduction to Modern Fortran p. 2/?? Summary We have omitted some

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

dbx90: Fortran debugger March 9, 2009

dbx90: Fortran debugger March 9, 2009 dbx90: Fortran debugger March 9, 2009 1 Name dbx90 a Fortran 90/95 debugger for use with the NAG Fortran compiler. 2 Usage dbx90 [option]... executable-file 3 Description dbx90 is a Fortran 90/95 debugger

More information

Bits, Bytes, and Precision

Bits, Bytes, and Precision Bits, Bytes, and Precision Bit: Smallest amount of information in a computer. Binary: A bit holds either a 0 or 1. Series of bits make up a number. Byte: 8 bits. Single precision variable: 4 bytes (32

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

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

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 FORTRAN PART II

INTRODUCTION TO FORTRAN PART II INTRODUCTION TO FORTRAN PART II Prasenjit Ghosh An example: The Fibonacci Sequence The Fibonacci sequence consists of an infinite set of integer nos. which satisfy the following recurrence relation x n

More information

TS Further Interoperability of Fortran with C WG5/N1917

TS Further Interoperability of Fortran with C WG5/N1917 TS 29113 Further Interoperability of Fortran with C WG5/N1917 7th May 2012 12:21 Draft document for DTS Ballot (Blank page) 2012/5/7 TS 29113 Further Interoperability of Fortran with C WG5/N1917 Contents

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

The Fortran Basics. Handout Two February 10, 2006

The Fortran Basics. Handout Two February 10, 2006 The Fortran Basics Handout Two February 10, 2006 A Fortran program consists of a sequential list of Fortran statements and constructs. A statement can be seen a continuous line of code, like b=a*a*a or

More information

2 Recommended books and a Web page

2 Recommended books and a Web page Fortran 95 for Fortran 77 users J.F.Harper School of Mathematics, Statistics and Computer Science Victoria University of Wellington First ed. 5 Apr 2006, latest amendments 23 May 2007 1 Introduction With

More information

HPF commands specify which processor gets which part of the data. Concurrency is defined by HPF commands based on Fortran90

HPF commands specify which processor gets which part of the data. Concurrency is defined by HPF commands based on Fortran90 149 Fortran and HPF 6.2 Concept High Performance Fortran 6.2 Concept Fortran90 extension SPMD (Single Program Multiple Data) model each process operates with its own part of data HPF commands specify which

More information

Technical Report on further interoperability with C

Technical Report on further interoperability with C Technical Report on further interoperability with C John Reid, ISO Fortran Convener, JKR Associates and Rutherford Appleton Laboratory Fortran 2003 (or 2008) provides for interoperability of procedures

More information

Basic Fortran Programming. National Computational Infrastructure

Basic Fortran Programming. National Computational Infrastructure Basic Fortran Programming National Computational Infrastructure Outline Introduction Declaration Arithmetic Do Loops Conditionals Functions I/O Libraries End 2 / 56 Fortran Programming Language Fortran

More information

FORTRAN - ARRAYS. For example, to declare a one-dimensional array named number, of real numbers containing 5 elements, you write,

FORTRAN - ARRAYS. For example, to declare a one-dimensional array named number, of real numbers containing 5 elements, you write, http://www.tutorialspoint.com/fortran/fortran_arrays.htm FORTRAN - ARRAYS Copyright tutorialspoint.com Arrays can store a fixed-size sequential collection of elements of the same type. An array is used

More information

Technical Specification on further interoperability with C

Technical Specification on further interoperability with C Technical Specification on further interoperability with C John Reid, ISO Fortran Convener Fortran 2003 (or 2008) provides for interoperability of procedures with nonoptional arguments that are scalars,

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

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

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

Chapter 3. Fortran Statements

Chapter 3. Fortran Statements Chapter 3 Fortran Statements This chapter describes each of the Fortran statements supported by the PGI Fortran compilers Each description includes a brief summary of the statement, a syntax description,

More information

ARRAYS COMPUTER PROGRAMMING. By Zerihun Alemayehu

ARRAYS COMPUTER PROGRAMMING. By Zerihun Alemayehu ARRAYS COMPUTER PROGRAMMING By Zerihun Alemayehu AAiT.CED Rm. E119B BASIC RULES AND NOTATION An array is a group of variables or constants, all of the same type, that are referred to by a single name.

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

Parallel Programming in Fortran with Coarrays

Parallel Programming in Fortran with Coarrays Parallel Programming in Fortran with Coarrays John Reid, ISO Fortran Convener, JKR Associates and Rutherford Appleton Laboratory Fortran 2008 is now in FDIS ballot: only typos permitted at this stage.

More information

7. Procedures and Structured Programming

7. Procedures and Structured Programming 7. Procedures and Structured Programming ONE BIG PROGRAM external procedure: separated small and reusable program units to conduct individual subtasks smaller main program Each program unit can be debugged

More information

A Brief Introduction to Fortran of 15

A Brief Introduction to Fortran of 15 A Brief Introduction to Fortran 90 1 of 15 Data Types and Kinds Data types Intrisic data types (INTEGER, REAL,LOGICAL) derived data types ( structures or records in other languages) kind parameter (or

More information

Practical Exercise 1 Question 1: The Hello World Program Write a Fortran 95 program to write out Hello World on the screen.

Practical Exercise 1 Question 1: The Hello World Program Write a Fortran 95 program to write out Hello World on the screen. Practical Exercise Question : The Hello World Program Write a Fortran 95 program to write out Hello World on the screen. Question : Some Division One Results A particular number can be expressed as the

More information

Chapter 6. A Brief Introduction to Fortran David A. Padua

Chapter 6. A Brief Introduction to Fortran David A. Padua Chapter 6. A Brief Introduction to Fortran 90 1998 David A. Padua 1 of 15 6.1 Data Types and Kinds Data types Intrisic data types (INTEGER, REAL,LOGICAL) derived data types ( structures or records in other

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

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

Allocating Storage for 1-Dimensional Arrays

Allocating Storage for 1-Dimensional Arrays Allocating Storage for 1-Dimensional Arrays Recall that if we know beforehand what size we want an array to be, then we allocate storage in the declaration statement, e.g., real, dimension (100 ) :: temperatures

More information

More Coarray Features. SC10 Tutorial, November 15 th 2010 Parallel Programming with Coarray Fortran

More Coarray Features. SC10 Tutorial, November 15 th 2010 Parallel Programming with Coarray Fortran More Coarray Features SC10 Tutorial, November 15 th 2010 Parallel Programming with Coarray Fortran Overview Multiple Dimensions and Codimensions Allocatable Coarrays and Components of Coarray Structures

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

Fortran 2003 Part 1. École normale supérieure L3 geosciences 2018/2019. Lionel GUEZ Laboratoire de météorologie dynamique Office E324

Fortran 2003 Part 1. École normale supérieure L3 geosciences 2018/2019. Lionel GUEZ Laboratoire de météorologie dynamique Office E324 Fortran 2003 Part 1 École normale supérieure L3 geosciences 2018/2019 Lionel GUEZ guez@lmd.ens.fr Laboratoire de météorologie dynamique Office E324 Modification date: Apr 1, 2019 Contents (1/2) Introduction

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

Visual basic tutorial problems, developed by Dr. Clement,

Visual basic tutorial problems, developed by Dr. Clement, EXCEL Visual Basic Tutorial Problems (Version January 20, 2009) Dr. Prabhakar Clement Arthur H. Feagin Distinguished Chair Professor Department of Civil Engineering, Auburn University Home page: http://www.eng.auburn.edu/users/clemept/

More information

Appendix D. Fortran quick reference

Appendix D. Fortran quick reference Appendix D Fortran quick reference D.1 Fortran syntax... 315 D.2 Coarrays... 318 D.3 Fortran intrisic functions... D.4 History... 322 323 D.5 Further information... 324 Fortran 1 is the oldest high-level

More information

Declaration and Initialization

Declaration and Initialization 6. Arrays Declaration and Initialization a1 = sqrt(a1) a2 = sqrt(a2) a100 = sqrt(a100) real :: a(100) do i = 1, 100 a(i) = sqrt(a(i)) Declaring arrays real, dimension(100) :: a real :: a(100) real :: a(1:100)!

More information

Co-arrays to be included in the Fortran 2008 Standard

Co-arrays to be included in the Fortran 2008 Standard Co-arrays to be included in the Fortran 2008 Standard John Reid, ISO Fortran Convener The ISO Fortran Committee has decided to include co-arrays in the next revision of the Standard. Aim of this talk:

More information

SHAPE Returns the number of elements in each direction in an integer vector.

SHAPE Returns the number of elements in each direction in an integer vector. Chapter 5: Arrays An advantage fortran has over other programming languages is the ease with which it handles arrays. Because arrays are so easy to handle, fortran is an ideal choice when writing code

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

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

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

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

Page 1 of 7. Date: 1998/05/31 To: WG5 From: J3/interop Subject: Interoperability syntax (Part 1) References: J3/98-132r1, J3/98-139

Page 1 of 7. Date: 1998/05/31 To: WG5 From: J3/interop Subject: Interoperability syntax (Part 1) References: J3/98-132r1, J3/98-139 (J3/98-165r1) Date: 1998/05/31 To: WG5 From: J3/interop Subject: Interoperability syntax (Part 1) References: J3/98-132r1, J3/98-139 ISO/IEC JTC1/SC22/WG5 N1321 Page 1 of 7 Describing pre-defined C data

More information

Verification of Fortran Codes

Verification of Fortran Codes Verification of Fortran Codes Wadud Miah (wadud.miah@nag.co.uk) Numerical Algorithms Group http://www.nag.co.uk/content/fortran-modernization-workshop Fortran Compilers Compilers seem to be either high

More information

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving CS 199 Computer Programming Spring 2018 Lecture 2 Problem Solving ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence

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

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Array Many applications require multiple data items that have common

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

Fortran 2008: what s in it for high-performance computing

Fortran 2008: what s in it for high-performance computing Fortran 2008: what s in it for high-performance computing John Reid, ISO Fortran Convener, JKR Associates and Rutherford Appleton Laboratory Fortran 2008 has been completed and is about to be published.

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

Old Questions Name: a. if b. open c. output d. write e. do f. exit

Old Questions Name: a. if b. open c. output d. write e. do f. exit Old Questions Name: Part I. Multiple choice. One point each. 1. Which of the following is not a Fortran keyword? a. if b. open c. output d. write e. do f. exit 2. How many times will the code inside the

More information

C introduction: part 1

C introduction: part 1 What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation

More information

6.1 Expression Evaluation. 1 of 21

6.1 Expression Evaluation. 1 of 21 6.1 Expression Evaluation 1 of 21 The world of expressions In the absence of side effects, expressions are relatively simple and nice objects. Functional programming languages rely on expressions as their

More information

Maltepe University Computer Engineering Department. BİL 133 Algorithms and Programming. Chapter 8: Arrays

Maltepe University Computer Engineering Department. BİL 133 Algorithms and Programming. Chapter 8: Arrays Maltepe University Computer Engineering Department BİL 133 Algorithms and Programming Chapter 8: Arrays What is an Array? Scalar data types use a single memory cell to store a single value. For many problems

More information

Intrinsic Numeric Operations

Intrinsic Numeric Operations Intrinsic Numeric Operations The following operators are valid for numeric expressions: ** exponentiation (e.g., 10**2) evaluated right to left: 2**3**4 is evaluated as 2**(3**4) * and / multiply and divide

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

CSE 262 Spring Scott B. Baden. Lecture 4 Data parallel programming

CSE 262 Spring Scott B. Baden. Lecture 4 Data parallel programming CSE 262 Spring 2007 Scott B. Baden Lecture 4 Data parallel programming Announcements Projects Project proposal - Weds 4/25 - extra class 4/17/07 Scott B. Baden/CSE 262/Spring 2007 2 Data Parallel Programming

More information

Parallel Programming Languages. HPC Fall 2010 Prof. Robert van Engelen

Parallel Programming Languages. HPC Fall 2010 Prof. Robert van Engelen Parallel Programming Languages HPC Fall 2010 Prof. Robert van Engelen Overview Partitioned Global Address Space (PGAS) A selection of PGAS parallel programming languages CAF UPC Further reading HPC Fall

More information

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur 1 Array Many applications require multiple data items that have common

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

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

ISO/IEC : TECHNICAL CORRIGENDUM 2

ISO/IEC : TECHNICAL CORRIGENDUM 2 ISO/IEC 1539-1:2010 - TECHNICAL CORRIGENDUM 2 ISO/IEC/JTC1/SC22/WG5-N1957 Notes for WG5: Edits included in this document from the interpretations in N1932 as amended by 12-193 and 12-194 and in N1949 as

More information

PACKAGE SPECIFICATION HSL 2013

PACKAGE SPECIFICATION HSL 2013 PACKAGE SPECIFICATION HSL 2013 1 SUMMARY Given a rank-one or rank-two allocatable array, reallocates the array to have a different size, and can copy all or part of the original array into the new array.

More information

CSc 372. Comparative Programming Languages. 15 : Haskell List Comprehension. Department of Computer Science University of Arizona

CSc 372. Comparative Programming Languages. 15 : Haskell List Comprehension. Department of Computer Science University of Arizona 1/20 CSc 372 Comparative Programming Languages 15 : Haskell List Comprehension Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/20 List Comprehensions

More information

Scientific Programming in C VI. Common errors

Scientific Programming in C VI. Common errors Scientific Programming in C VI. Common errors Susi Lehtola 6 November 2012 Beginner errors If you re a beginning C programmer, you might often make off-by one errors when you use arrays: #i n c l u de

More information

International Standards Organisation. Parameterized Derived Types. Fortran

International Standards Organisation. Parameterized Derived Types. Fortran International Standards Organisation Parameterized Derived Types in Fortran Technical Report defining extension to ISO/IEC 1539-1 : 1996 {Produced 4-Jul-96} THIS PAGE TO BE REPLACED BY ISO CS ISO/IEC 1

More information

Implementation and Evaluation of Coarray Fortran Translator Based on OMNI XcalableMP. October 29, 2015 Hidetoshi Iwashita, RIKEN AICS

Implementation and Evaluation of Coarray Fortran Translator Based on OMNI XcalableMP. October 29, 2015 Hidetoshi Iwashita, RIKEN AICS Implementation and Evaluation of Coarray Fortran Translator Based on OMNI XcalableMP October 29, 2015 Hidetoshi Iwashita, RIKEN AICS Background XMP Contains Coarray Features XcalableMP (XMP) A PGAS language,

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

Subroutines and Functions

Subroutines and Functions Subroutines and Functions Procedures: Subroutines and Functions There are two types of procedures: SUBROUTINE: a parameterized named sequence of code which performs a specific task and can be invoked from

More information

Programming for High Performance Computing in Modern Fortran. Bill Long, Cray Inc. 17-May-2005

Programming for High Performance Computing in Modern Fortran. Bill Long, Cray Inc. 17-May-2005 Programming for High Performance Computing in Modern Fortran Bill Long, Cray Inc. 17-May-2005 Concepts in HPC Efficient and structured layout of local data - modules and allocatable arrays Efficient operations

More information

Introduction to Object-Oriented Concepts in Fortran95

Introduction to Object-Oriented Concepts in Fortran95 Introduction to Object-Oriented Concepts in Fortran95 Object-Oriented Programming (OOP) is a design philosophy for writing complex software. Its main tool is the abstract data type, which allows one to

More information

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering. C Tutorial: Part 1 Dr. Charalampos C. Tsimenidis Newcastle University School of Electrical and Electronic Engineering September 2013 Why C? Small (32 keywords) Stable Existing code base Fast Low-level

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

VBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type >

VBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type > VBA Handout References, tutorials, books Excel and VBA tutorials Excel VBA Made Easy (Book) Excel 2013 Power Programming with VBA (online library reference) VBA for Modelers (Book on Amazon) Code basics

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

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

C for Engineers and Scientists: An Interpretive Approach. Chapter 10: Arrays

C for Engineers and Scientists: An Interpretive Approach. Chapter 10: Arrays Chapter 10: Arrays 10.1 Declaration of Arrays 10.2 How arrays are stored in memory One dimensional (1D) array type name[expr]; type is a data type, e.g. int, char, float name is a valid identifier (cannot

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

Lab #10 Multi-dimensional Arrays

Lab #10 Multi-dimensional Arrays Multi-dimensional Arrays Sheet s Owner Student ID Name Signature Group partner 1. Two-Dimensional Arrays Arrays that we have seen and used so far are one dimensional arrays, where each element is indexed

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

An Introduction to Fortran

An Introduction to Fortran An Introduction to Fortran Sylvia Plöckinger March 10, 2011 Sylvia Plöckinger () An Introduction to Fortran March 10, 2011 1 / 43 General Information Find this file on: http://homepage.univie.ac.at/nigel.mitchell/numprac/

More information

Arrays in C C Programming and Software Tools. N.C. State Department of Computer Science

Arrays in C C Programming and Software Tools. N.C. State Department of Computer Science Arrays in C C Programming and Software Tools N.C. State Department of Computer Science Contents Declaration Memory and Bounds Operations Variable Length Arrays Multidimensional Arrays Character Strings

More information

Arrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept

Arrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept Arrays in C Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur 1 Basic Concept Many applications require multiple data items that have common characteristics.

More information

CSE 230 Intermediate Programming in C and C++ Arrays and Pointers

CSE 230 Intermediate Programming in C and C++ Arrays and Pointers CSE 230 Intermediate Programming in C and C++ Arrays and Pointers Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Definition: Arrays A collection of elements

More information

CS 161 Exam II Winter 2018 FORM 1

CS 161 Exam II Winter 2018 FORM 1 CS 161 Exam II Winter 2018 FORM 1 Please put your name and form number on the scantron. True (A)/False (B) (28 pts, 2 pts each) 1. The following array declaration is legal double scores[]={0.1,0.2,0.3;

More information

LF Fortran 95 Language Reference. Revision G.02

LF Fortran 95 Language Reference. Revision G.02 LF Fortran 95 Language Reference Revision G.02 Copyright Copyright 1994-2004 by Lahey Computer Systems, Inc. All rights reserved worldwide. This manual is protected by federal copyright law. No part of

More information

SUBPROGRAMS AND MODULES

SUBPROGRAMS AND MODULES SUBPROGRAMS AND MODULES FORTRAN PROGRAMING Zerihun Alemayehu AAiT.CED Program structure Advantages of subprograms Program units can be written and tested independently A program unit that has a well defined

More information

Functions. Arash Rafiey. September 26, 2017

Functions. Arash Rafiey. September 26, 2017 September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic

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

Module 5.5: nag sym bnd lin sys Symmetric Banded Systems of Linear Equations. Contents

Module 5.5: nag sym bnd lin sys Symmetric Banded Systems of Linear Equations. Contents Module Contents Module 5.5: nag sym bnd lin sys Symmetric Banded Systems of nag sym bnd lin sys provides a procedure for solving real symmetric or complex Hermitian banded systems of linear equations with

More information