Fortran: Specification Statements Session Six ICoCSIS.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Introduction to arrays
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Chapter 7: User-Defined Functions II
Kernighan/Ritchie: Kelley/Pohl:
The new features of Fortran 2003 David Muxworthy BSI Fortran Convenor.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Fortran: Array Features Session Five ICoCSIS. Outline 1.Zero-sized Array 2.Assumed-shaped Array 3.Automatic Objects 4.Allocation of Data 5.Elemental Operations.
Application of Fortran 90 to ocean model codes Mark Hadfield National Institute of Water and Atmospheric Research New Zealand.
VBA Modules, Functions, Variables, and Constants
Arrays Array Terminology Declarations Visualisation of Arrays Array Conformance Array Element Ordering Array Syntax Whole Array Expressions Array Sections.
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 6 Programming with Functions. FUNCTIONS Intrinsic Functions (or called library functions) Function Subprograms: programmer-defined functions.
Program Units Main Program Syntax Program Example Introduction to Procedures Subroutines Functions Argument Association Local Objects Argument Intent Scoping.
Functions & Subroutines HTML version DFMain.chm. Types of subprograms Internal External Module Pure Elemental Recursive Optional arguments Generic Defined.
Introduction to Fortran Fortran Evolution Drawbacks of FORTRAN 77 Fortran 90 New features Advantages of Additions.
Fortran 9x HTML version. New F90 features Free source form Modules User-defined data types and operators Generic user-defined procedures Interface blocks.
6 April, 2000 CS1001 Lecture 15 EXAM1 - results SUBPROGRAM - - revisit FUNCTION.
27 March, 2000 CS1001 Lecture 16 FUNCTIONS SUBROUTINES SCOPE MODULES EXTERNAL SUBPROGRAMS.
Chapter 10 Modules and programming with subroutines.
Chapter 9 Modules and Programming with Functions.
FORTRAN.  Fortran or FORmula TRANslation was developed in the 1950's by IBM as an alternative to Assembly Language. First successfull high level language.
6 April, 2000 CS1001 Lecture 13 PRACTICE EXAM - revisit SUBPROGRAM FUNCTION.
Chapter 9 Introduction to Procedures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul -
Chapter 12 Pointers and linked structures. 2 Introduction  The data structures that expand or contract as required during the program execution is called.
ISBN Chapter 9 Subprograms and Functions –Design Issues –Local Referencing Environments –Parameter-Passing Methods –Parameters that are Subprogram.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Introduction to FORTRAN
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
1 Week 12 Arrays, vectors, matrices and cubes. Introduction to Scientific & Engineering Computing 2 Array subscript expressions n Each subscript in an.
Fortran: Program Units and Procedures Session Four ICoCSIS.
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Week 8. Today’s program n New stuff: –Recursion in F –Procedures as arguments –User-defined data types n Quiz #3.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Week 8 Improving on building blocks Recursive procedures.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Functions. Type of Subprograms Fortran 90/95 allows for two types of subprograms: –Functions, and –Subroutines. In general, there are two forms of subprograms:
Module and Data Sharing. Programming in the Large Software, in general, is large having multiple units Multiple units designed and developed independently.
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
1 Serial Run-time Error Detection and the Fortran Standard Glenn Luecke Professor of Mathematics, and Director, High Performance Computing Group Iowa State.
Week 3 Let's review! Fundamental data types List-directed input/output.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Procedures and Modular Programming Part # 2. Interface Block ► Functions do not have to be internal to main program ► They can be stand-alone ► In this.
An introduction to arrays WEEK 7 Introduction In scientific and engineering computing, it is very common to need to manipulate ordered sets of values,
Arrays Introduction In scientific and engineering computing, it is very common to need to manipulate ordered sets of values, such as vectors and matrices.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Compilation Technology SCINET compiler workshop | February 17-18, 2009 © 2009 IBM Corporation Software Group Fortran 2003 Jim Xia IBM Toronto Lab
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
FORTRAN 90+ Yetmen Wang Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT.
Fortran MATTHEW CARSON. History of FORTRAN FORTRAN ; First High Level Language FORTRAN I 1957; First Compiled Language FORTRAN II ; Independent.
19 - 2/25/2000AME 150L1 Solving Systems of Linear Equations.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Fortran: Control Structures Session Three ICoCSIS.
Introduction to Fortran95 Programming Part II By Deniz Savas, CiCS, 2007
Information and Computer Sciences University of Hawaii, Manoa
Procedures and Modular Programming
Programming For Nuclear Engineers Lecture 6 Arrays
Array processing and Matrix manipulation
11/10/2018.
Midterm Review Programming in Fortran
By Deniz Savas, CiCS, Shef. Univ., 2015
7 Arrays.
mdul-cntns-sub-cmmnts2.f90
Array processing and Matrix manipulation
Presentation transcript:

Fortran: Specification Statements Session Six ICoCSIS

Outline 1.Implicit Typing 2.Declaring Entities of Different Shapes 3.Named Constants and Constants Expressions 4.Initial Values for Variables 5.Public and Private Attributes 6.The Pointer, Target, and Allocatable Statement 7.The intent and Optional Statement 8.The save Attribute 9.The use Statement 10.Derived-type Definition 11.The Type Declaration Statement 12.Type and Type Parameter Specification 13.Specification Expression 14.The Namelist Statement

Introduction The compiler requires information about the entities involved. This information is provided at the beginning of each program unit or subprogram by specification statements.

Implicit Typing strong typing Vs. implicit typing In FORTRAN implcit type is assigned according to the initial letter of its name: Entities whose names begin with one of the letters i, j,..., n are of type default integer, and variables beginning with the letters a, b,..., h or o, p,..., z are of type default real. For no implicit typing the statement implicit none is available.

Declaring entities of differing shapes integer :: a, b integer, dimension(10) :: c, d integer, dimension(8,7) :: e Fortran permits using a single statement. Whether or not there is a dimension attribute present, arrays may be declared by placing the shape information after the name of the array: integer :: a, b, c(10), d(10), e(8, 7) or (with dimension for default shape) integer, dimension(10) :: c, d, e(8, 7)

Named constants and constant expressions Inside a program, we often need to define a constant for multiple usage pi = or to use a constant in declarations and executions, which later need to change. named constants: real, parameter :: pi =

Initial values for variables Initialization in type declaration statements real :: a = 0.0 real, dimension(3) :: b = (/ 0.0, 1.2, 4.5 /) The data statement data object-list /value-list/ [[,] object-list /value-list/]... real :: a, b, c integer :: i, j, k data a,b,c/1.,2.,3./, i,j,k/1,2,3/ Pointer initialization and the function null real, pointer, dimension(:) :: vector => null() Default initialization of components: any object of a derived type is given a default initial value for a component type entry real :: value = 2.0 integer :: index type(entry), pointer :: next => null() end type entry

The public and private attributes If the entities in a module are to be accessible elsewhere, thay have the public attribute. If access is limited to only the procedures of the module, there is no possibility of an accidental corruption of these data by another procedure and design changes can be made within the module without affecting the rest of the program. In cases where entities are not to be accessible outside their own module, they may be given the private attribute. real, public :: x, y, z integer, private :: u, v, w or public :: x, y, z, operator(.add.) private :: u, v, w, assignment(=), operator(*)

The pointer, target, and allocatable statements There are statements for specifying the pointer, target, and allocatable attributes of entities. They take the forms: pointer [::] object-name[(array-spec)] [,object-name [(array-spec)]]... target [::] object-name[(array-spec)] [,object-name [(array-spec)]]... and allocatable [::] array-name[(array-spec)] [,array-name [(array-spec)]]... as in real :: a, son, y allocatable :: a(:,:) pointer :: son target :: a, y(10)

The intent and optional statements The intent attribute for a dummy argument that is not a dummy procedure or pointer may be specified in a type declaration statement or in an intent statement of the form intent( inout ) [::] dummy-argument-name-list subroutine solve (a, b, c, x, y, z) real :: a, b, c, x, y, z intent(in) :: a, b, c intent(out) :: x, y, z optional [::] dummy-argument-name-list

The save attribute To retain the value of a local variable in a subprogram, for example to count the number of times the subprogram is entered. real, save :: a A similar situation arises with the use of variables in modules. In theory, on return from a subprogram that accesses a variable whose scope is a module, the variable becomes undefined unless the main program accesses the module, another subprogram in execution accesses the module, or the variable has the save attribute. In practice, compilers treat module variables as having the save attribute. save [ [::] variable-name-list ] A save statement with no list is equivalent to a list containing all possible names.

The use statement use module-name provides access to all the public named data objects, derived types, interface blocks, procedures, generic identifiers, and namelist groups in the module named. Any use statements must precede other specification statements in a scoping unit. The only attribute of an accessed entity that may be specified afresh is public or private (and this only in a module), but the entity may be included in one or more namelist groups.

Derived-type definitions type [[,access]:: ] type-name [ private ] component-def-stmt [component-def-stmt]... end type [ type-name ] Each component-def-stmt has the form type [ [,component-attr-list] :: ]component-decl-list where type specifies the type and type parameters. Each component-attr is allocatable, pointer, or dimension(bounds-list). Each component-decl is component-name [ (bounds-list)][ *char-len ] or component-name [ (bounds-list)][ *char-len ] [ comp-int ] type, public :: lock private integer, pointer :: key(:) logical :: state end type lock

The type declaration statement Simple examples of the declarations of named entities by integer, real, complex, logical, character, and type(type-name) statements. The general form is type [ [, attribute]... :: ] entity-list

Specification expressions subroutine sample(arr, n, string) use definitions ! Contains the real a and the integer datasetsize integer, intent(in) :: n real, dimension(n), intent(out) :: arr ! Explicit-shape array character(len=*), intent(in) :: string ! Assumed length real, dimension(datasetsize+5) :: x ! Automatic array character(len=n+len(string)) :: cc ! Automatic object integer, parameter :: pa2 = selected_real_kind(2*precision(a)) real(kind=pa2) :: z ! Precision of z is at least twice ! the precision of a

The namelist statement It is sometimes convenient to gather a set of variables into a single group, in order to facilitate input/output (I/O) operations on the group as a whole. The method by which a group is declared is via the namelist statement namelist namelist-spec where namelist-spec is /namelist-group-name/ variable-name-list The namelist-group-name is the name given to the group for subsequent use in the I/O statements.