A Brief Introduction to Fortran of 15

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

6.1 Expression Evaluation. 1 of 21

Chapter 4. Fortran Arrays

Review More Arrays Modules Final Review

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

ARRAYS COMPUTER PROGRAMMING. By Zerihun Alemayehu

PACKAGE SPECIFICATION HSL 2013

Subroutines, Functions and Modules

Fortran 90 - A thumbnail sketch

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

Module 28.3: nag mv rotation Rotations. Contents

7. Procedures and Structured Programming

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

AMath 483/583 Lecture 8

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

ISO/IEC : TECHNICAL CORRIGENDUM 2

Subroutines and Functions

Chapter 3. Fortran Statements

Allocating Storage for 1-Dimensional Arrays

INTRODUCTION TO FORTRAN PART II

NO CALCULATOR ALLOWED!!

Information technology Programming languages Fortran Part 1: Base language

Introduction to Programming with Fortran 90

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

Bits, Bytes, and Precision

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

Module 19.1: nag ip Integer Programming. Contents

About 1. Chapter 1: Getting started with Fortran 2. Remarks 2. Versions 2. Examples 2. Installation or Setup 2. Hello, world 3. Quadratic equation 4

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

Goals for This Lecture:

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

Module 25.2: nag correl Correlation Analysis. Contents

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

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

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

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

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


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

Lecture V: Introduction to parallel programming with Fortran coarrays

SUBPROGRAMS AND MODULES

Technical Report on further interoperability with C

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

LF Fortran 95 Language Reference. Revision G.02

Report from WG5 convener

TS Further Interoperability of Fortran with C WG5/N1917

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

Quick Guide to Fortran

Array Processing { Part II. Multi-Dimensional Arrays. 1. What is a multi-dimensional array?

Technical Specification on further interoperability with C

Declaration and Initialization

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

dbx90: Fortran debugger March 9, 2009

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

UNIT 3

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

NAGWare f95 and reliable, portable programming.

Goals for This Lecture:

Goals for This Lecture:

Goals for This Lecture:

Introduction to FORTRAN 90

Introduction to FORTRAN 90

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

Equations. resid(3:jm2:2,2:jm1:2)=a(3:jm2:2,2:jm1:2)*u(4:jm1:2,2:jm1:2)+& b(3:jm2:2,2:jm1:2)*u(2:jm3:2,2:jm1:2)+&

Run-Time Data Structures

ISO/IEC JTC 1/SC 22/OWGV N 0220

Appendix D. Fortran quick reference

Module 25.1: nag lin reg Regression Analysis. Contents

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

International Standards Organisation. Parameterized Derived Types. Fortran

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

Module 7.2: nag sym fft Symmetric Discrete Fourier Transforms. Contents

NAG Library Routine Document F08LEF (DGBBRD)

Fortran Coding Standards and Style

Implementing Subprograms

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Introduction to Modern Fortran

PACKAGE SPECIFICATION HSL 2013

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

Index. classes, 47, 228 coarray examples, 163, 168 copystring, 122 csam, 125 csaxpy, 119 csaxpyval, 120 csyscall, 127 dfetrf,14 dfetrs, 14

The new features of Fortran 2003

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

Type Checking. Prof. James L. Frankel Harvard University

Informatica 3 Syntax and Semantics

Language Reference Manual

0. Overview of this standard Design entities and configurations... 5

2 Recommended books and a Web page

Personal SE. Functions & Arrays

Co-arrays to be included in the Fortran 2008 Standard

NAG Library Routine Document F07KDF (DPSTRF)

Computer Science & Engineering 150A Problem Solving Using Computers

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Fortran 90 Features. Science & Technology Support High Performance Computing. Ohio Supercomputer Center 1224 Kinnear Road Columbus, OH

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

Introduction to Fortran Programming. -External subprograms-

Programming Languages

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays

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

Short LAPACK User s Guide

1 Introduction to MATLAB

Transcription:

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 simply kind) An integer that further specifes intrinsic data types (REAL(4), REAL(8)) Literal constants (or simply literals) are psecified as to kind by appending an underscore (1.5_4, 1.5_8) Vary from machine to machine 2 of 15

IMPLICIT none 3 of 15

Examples INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9) INTEGER, PARAMETER :: SP = KIND(1.0) INTEGER, PARAMETER :: DP = KIND(1.0D0) INTEGER(I4B) i,j,k INTEGER m,n,p REAL(SP) x,y REAL w,z REAL(SP) :: t,u,v READ(SP), DIMENSION(100,200) :: barr REAL(SP) :: carr(500) 4 of 15

Array Shapes and Sizes The shape of an array refers to both its dimensionality (called its rank), and the lenght of each dimension (called the extents) The F90 intrinsic function shape returns a one dimensional array (a rank-one array) whose elements are the extents along each dimension. shape(barr) returns the vector (100,200) The size of an array is its total number of elements, The intrinsic size(barr) would return 20000. The extent of each dimension can also be computed by using additional parameters. size(barr,1) returns 100 size(barr,2) returns 200. 5 of 15

Memory Mangement Within subprograms (that is, subroutines and functions), one can have automatic arrays that come into existence each time the subprogram is entered (and disappear when the program is exited). Example SUBROUTINE domething(,j,k) REAL, DIMENSION(2*j,k**2) :: carr 6 of 15

Fortran 90 Intrinsic Procedures aint(a,kind) Truncate to integer value, return as a real kind anint(a,kind) Nearest whole number, return as a real kind. real(a,kind) Convert to rea real kind ceiling(a) floor(a) Convert to integer, truncating towards more positive all(mask,dim) any(mask,dim) count(mask,dim) returns true if all elements of mask are true Returns true if any of the elements of mask are true counts the true elemtns in mask minval(array,dim,mask)minimum value of the array elements maxval(array,dim,mask) 7 of 15

product(array,dim,mask) sum(array,dim,mask) myarray = 1 2 3 4 5 6 7 8 910112 sum(myarray,dim=1)=(15,18,21,24) sum(myarray,dim=2)=(10,26,42) size(array,dim) maxloc(array,mask) minloc(array,mask) dot_prduct(vecta,vectb) matmul(mata,matb) 8 of 15

Finer control on when an array is created or destroyed can be achieved by declaring allocatable arrays REAL, DIMENSION(:,:), ALLOCATABLE :: darr allocate(darr(10,20)) deallocate(darr) allocate(darr(100,200)) deallocate(darr) 9 of 15

Yet finer control is achieved by the use of pointers. Like an allocatable array, a pointer can be allocated. However, it an also be pointer associated with a target that already exists under another name. REAL, DIMENSION(:), POINTER :: parr REAL, DIMENSION(100), TARGET :: earr parr => earr nullify(parr) allocate(parr(500)) deallocate(parr) 10 of 15

Procedure Interfaces When a procedure is referenced (called) from within a program or subprogram, the program unit must be told the procedure s interface, that is, its calling sequence. INTERFACE SUBROUTINE caldat(julian,mm,id,iyyy) INTEGER, INTENT(IN) :: julian INTEGER, INTENT(OUT) :: MM,ID,IYYY END SUBROUTINE caldat END INTERFACE 11 of 15

Triplet notation Sections of arrays are identified in Fortran 90 using triplets of the form l:u:s. A triplet represent the sequence of subscripts l, l+s, l+2*s,,l+m*s where m is the smallest number such that l+(m+1)s > u (if s l) or l+(m+1)s < u (if s l) For example, the section A(3:5,2,1:2) of an array A is the array of shape (3,2): A(3,2,1) A(3,2,2) A(4,2,1) A(4,2,2) A(5,2,1) A(5,2,2) If l is omitted, the lober bound for the array is assumed. If u is omitted, the upper bound is assumed. If s is omitted, 1 is assumed. The stride s cannot be 0 12 of 15

Expressions in Fortran 90 may contain array sections, specified using triplets, or complete arrays identified by the name of the array without any subscripts. For example, consider the arrays a, b and c declared as follows: dimension a(100,100) b(100,100),c(100,100) The statement c = a + b assigns to matrix c the element-by-element sum of matrices a and b. Also, a(1:100, 2) = 0 assigns 0 to the second column of a. An identical function is performed by the following three statements. a(:100,2) = 0 a(1:,2) = 0 a(:,2) = 0 Another example is a(51:100,4) = b(1:50,4) * c(30,31:80) a(51:100,4) = a(50:99,4) + 1 The rank of an array is the number of dimensions. 13 of 15

The shape of an array is determined by its rank and its extent in each dimension. All the objects in an expression or assignment statement must be conformable. Two arrays are conformable if they have the same shape. A scalar is conformable with any array. Any intrinsic operation defined for scalar objects may be applied to conformable objects. Such operations are performed elementby-element to produce a resultant array conformable with the array operands. The masked array assignment is used to perform selective assignment to arrays. For example, in the statement where(temp>0)temp = temp - reduce_temp only those elements in the array temp which are > 0 will be decreased by the value reduce_temp. In the following compound statement, where(pressure<=0) pressure = pressure + inc_pressure 14 of 15

temp = temp - 5.0 elsewhere raining =.true. end where the array pressure in modified only where it is <= 1. Also, the array temp is modified in the corresponding locations (i.e. in the same locations as pressure). Finally, the array raining is assigned.true. only in the locations that correspond to those element of pressure which are > 1. The mask of the where statement is like another operator on the right-hand side of all the assignment statements in the body of the where statement and therefore has to be conformable to the righthand side expression and to the array on the left-hand side. There are a collection of intrinsic functions designed to operate on arrays. These will be described as needed. 15 of 15