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

Size: px
Start display at page:

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

Transcription

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

2 Subprograms Subprograms are used to split the program into separate smaller units. Internal subprogram is not an independent part of a program. Fortran 90 has two types of subprograms: functions and subroutines. Once each piece is working correctly, we can put the pieces together to build the program. 1

3 Program unit It is a physically complete sequence of program lines with end statement. Main program: The main program unit containing the first statement of the actual program. External subprogram: User-defined subprogram which is an independent program unit. Module (since Fortran90): A program unit which contains only declarations and external subprograms. 2

4 Internal subprogram Internal subprogram: Internal subprograms are routines that are defined within the main program. Internal subprograms are not an independent part of a main program. Let s reduce bugs using subprograms. 3

5 Program units Main program (program-name) Internal functions Internal subroutines External Subprograms Today s topic!! Fortran s program units are the main program, external subprograms, and modules. Module 4

6 Internal functions syntax program program_name [Specification part] [Execution part] stop contains function function_name (arg1,arg2, ) end function function_name end program program_name 5

7 Internal functions syntax function function_name (arg1, ) [Specification part] [Execution part] end function function_name Or function function_name (arg1, ) result (out) [Specification part] [Execution part] end function function_name 6

8 Internal functions syntax function function_name (arg1, ) [Specification part] [Execution part] end function function_name Specification part includes formal arguments. The name of the return variable is function_name. Specification part is used to define the type of the return value function_name. 7

9 Internal functions syntax function function_name (arg1, ) result (out) [Specification part] [Execution part] end function function_name Specification part includes formal arguments. The name of the return variable is out. Specification part is used to define the type of the return value out. 8

10 Example 1 1. Declaration - Declare the variable i and j as integers. - Substitute specific value for i. 2. Make an internal function addone - Return the value i Call the internal function addone and substitute the return value for j. 9

11 Example 1 program test1 implicit none integer :: i, j i = 1 write(*,*) i j = addone(i) write(*,*) j stop contains function addone(i) integer :: i integer :: addone addone = i + 1 end function addone end program test1 A dummy argument for initialization. However, variable needs to be defined. Specification part: declare the variable i. Specification part: declare the variable addone. Substitute i+1 for addone. 10

12 Example 1 program test1 implicit none integer :: i, j i = 1 write(*,*) i j = addone(i) write(*,*) j stop contains function addone(fff) integer :: fff integer :: addone addone = fff + 1 end function addone end program test1 For example, we set a dummy argument fff. Specification part: declare the variable fff. Substitute fff+1 for addone. 11

13 Example 1 program test1 implicit none integer :: i, j i = 1 write(*,*) i j = addone(i) write(*,*) j stop contains function addone(fff) result(ggg) integer :: fff integer :: ggg ggg = fff + 1 end function addone end program test1 For example, we set the variable of return value ggg. Specification part: declare the variable ggg. Substitute fff+1 for ggg. 12

14 Call by reference If this code is executed, how do we output the result? program test1 implicit none integer :: i, j i = 1 write(*,*) i=, i j = addone(i) write(*,*) i=, i, j=, j Display i and j. stop contains function addone(fff) result(ggg) integer :: fff integer :: ggg ggg = fff + 1 fff = fff + 10 Substitute fff+10 for fff. end function addone end program test1 We try to change the value of dummy argument. 13

15 Call by reference If this code is executed, how do we output the result? program test1 implicit none integer :: i, j i = 1 write(*,*) i=, i j = addone(i) write(*,*) i=, i, j=, j stop contains function addone(fff) result(ggg) integer :: fff integer :: ggg ggg = fff + 1 fff = fff + 10 end function addone end program test1 Output of i and j i = 1 i = 11 j = 2 The value i is changed from 1 to 11 Fortran passes arguments by reference. (No copy is made!!) 14

16 Intent attribute data_type, intent (attribute) :: variable_name When declaring variables that need to be passed in or out or inout, intent may be added to the declaration. Intent attribute is not necessary for the return value. Intent: in : the variable value can enter, but not be changed. out : the variable is set inside the procedure and sent back to the main program. inout : the variable comes in with a value and leaves with a value. To optimize your code, you need to use the intent attribute. 15

17 Example 2 1. Declaration - Declare the variable i and j as integers. - Substitute specific value for i. 2. Make an internal function addone - Return the value i+1. - Declare the argument with intent(in). 3. Call the internal function addone and substitute the return value for j. 16

18 Example 2 program test1 implicit none integer :: i, j i = 1 write(*,*) i j = addone(i) write(*,*) j stop contains function addone(i) integer, intent(in) :: i integer :: addone addone = i + 1 end function addone end program test1 A dummy argument with the intent(in) can enter, but not be changed. For example, if we set i = i+10 in function addone, then an error occurs. 17

Introduction to Fortran Programming. -External subprograms-

Introduction to Fortran Programming. -External subprograms- Introduction to Fortran Programming -External subprograms- Subprograms Subprograms are used to split a program into separate smaller units. Internal subprograms are dependent parts of a program. Fortran

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

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

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

Reusing this material

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

More information

Introduction to Fortran Programming. - Module -

Introduction to Fortran Programming. - Module - Introduction to Fortran Programming - Module - Subprograms Subprograms are used to split program into separate smaller units. Internal subprograms are dependent parts of program. Fortran 90 has two types

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

SUBROUTINE subroutine-name (arg1, arg2,..., argn)

SUBROUTINE subroutine-name (arg1, arg2,..., argn) FORTRAN Subroutines Syntax Form 1 SUBROUTINE subroutine-name (arg1, arg2,..., argn) [specification part] [execution part] [subprogram part] subroutine-name Form 2 SUBROUTINE subroutine-name () [specification

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

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

Computers in Engineering. Subroutines Michael A. Hawker

Computers in Engineering. Subroutines Michael A. Hawker Computers in Engineering COMP 208 Subroutines Michael A. Hawker Subprograms Functions are one type of subprogram in FORTRAN Another type of subprogram FORTRAN allows is called a subroutine There are many

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

Extrinsic Procedures. Section 6

Extrinsic Procedures. Section 6 Section Extrinsic Procedures 1 1 1 1 1 1 1 1 0 1 This chapter defines the mechanism by which HPF programs may call non-hpf subprograms as extrinsic procedures. It provides the information needed to write

More information

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7) Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants

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

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

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

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

Fortran 95/2003 Course

Fortran 95/2003 Course Fortran 95/2003 Course Procedures and Modules by Hartmut Häfner March 25, 2015 STEINBUCH CENTRE FOR COMPUTING - SCC KIT University of the State of Baden-Württemberg and National Laboratory of the Helmholtz

More information

Merge Sort. Run time typically depends on: Insertion sort can be faster than merge sort. Fast, able to handle any data

Merge Sort. Run time typically depends on: Insertion sort can be faster than merge sort. Fast, able to handle any data Run time typically depends on: How long things take to set up How many operations there are in each step How many steps there are Insertion sort can be faster than merge sort One array, one operation per

More information

Chapter 7 - Notes User-Defined Functions II

Chapter 7 - Notes User-Defined Functions II Chapter 7 - Notes User-Defined Functions II I. VOID Functions ( The use of a void function is done as a stand alone statement.) A. Void Functions without Parameters 1. Syntax: void functionname ( void

More information

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu 1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized

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

Goals for This Lecture:

Goals for This Lecture: Goals for This Lecture: Learn a simple sorting algorithm Understand how compilation & linking of separate main program and subprogram files are accomplished. Understand how to use subprograms to create

More information

Computers in Engineering COMP 208. Subprograms. Subroutines. Subroutines Michael A. Hawker

Computers in Engineering COMP 208. Subprograms. Subroutines. Subroutines Michael A. Hawker Computers in Engineering COMP 208 Subroutines Michael A. Hawker Subprograms Functions are one type of subprogram in FORTRAN Another type of subprogram FORTRAN allows is called a subroutine There are many

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

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

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

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

Lab # 5. Subprograms. Introduction

Lab # 5. Subprograms. Introduction Lab # 5 Subprograms Introduction Subprograms consist of procedures and functions. A procedure can return more than one argument; a function always returns just one. In a function, all parameters are input

More information

PGI Accelerator Programming Model for Fortran & C

PGI Accelerator Programming Model for Fortran & C PGI Accelerator Programming Model for Fortran & C The Portland Group Published: v1.3 November 2010 Contents 1. Introduction... 5 1.1 Scope... 5 1.2 Glossary... 5 1.3 Execution Model... 7 1.4 Memory Model...

More information

Storage and Sequence Association

Storage and Sequence Association 2 Section Storage and Sequence Association 1 1 HPF allows the mapping of variables across multiple processors in order to improve parallel 1 performance. FORTRAN and Fortran 0 both specify relationships

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

1. User-Defined Functions & Subroutines Part 1 Outline

1. User-Defined Functions & Subroutines Part 1 Outline User-Defined Functions Subroutines Part 1 Outline 1. User-Defined Functions Subroutines Part 1 Outline 2. Intrinsic Functions Are Not Enough 3. User-Defined Functions 4. A User-Defined Function for Mean

More information

SPECIFICATION 2 STATEMENTS

SPECIFICATION 2 STATEMENTS SPEIFIATION 2 STATEMENTS hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Objectives: You will learn: Type specification. Type declarations other than HARATER. Statements: HARATER, IMPLIIT, DIMENSION, PARAMETER,

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

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

Subprograms. FORTRAN 77 Chapter 5. Subprograms. Subprograms. Subprograms. Function Subprograms 1/5/2014. Satish Chandra.

Subprograms. FORTRAN 77 Chapter 5. Subprograms. Subprograms. Subprograms. Function Subprograms 1/5/2014. Satish Chandra. FORTRAN 77 Chapter 5 Satish Chandra satish0402@gmail.com When a programs is more than a few hundred lines long, it gets hard to follow. Fortran codes that solve real research problems often have tens of

More information

Procedural programs are ones in which instructions are executed in the order defined by the programmer.

Procedural programs are ones in which instructions are executed in the order defined by the programmer. Procedural programs are ones in which instructions are executed in the order defined by the programmer. Procedural languages are often referred to as third generation languages and include FORTRAN, ALGOL,

More information

NAG Library Routine Document D02MWF.1

NAG Library Routine Document D02MWF.1 D02 Ordinary Differential Equations NAG Library Routine Document Note: before using this routine, please read the Users Note for your implementation to check the interpretation of bold italicised terms

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

Fortran Bill Long, Cray Inc. 21-May Cray Proprietary

Fortran Bill Long, Cray Inc. 21-May Cray Proprietary Fortran 2003 Bill Long, Cray Inc. 21-May-2004 Cray Proprietary Fortran 2003 Specification for Fortran 2003 (f03) is finished Standard should be official in September 569 pages including Appendices and

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

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

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

Programmation in Fortran

Programmation in Fortran Programmation in Fortran Adrien Poteaux CRIStAL, Université Lille Year 2017-2018 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. http://creativecommons.org/licenses/by-nc-sa/3.0/

More information

(Refer Slide Time 01:41 min)

(Refer Slide Time 01:41 min) Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 03 C Programming - II We shall continue our study of

More information

NAG Library Routine Document E04GYF.1

NAG Library Routine Document E04GYF.1 NAG Library Routine Document Note: before using this routine, please read the Users Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent

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

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley. CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia

More information

Programming Tips for Plugins

Programming Tips for Plugins Programming Tips for Plugins Chad Neufeld Centre for Computational Geostatistics Department of Civil & Environmental Engineering University of Alberta Working in a university based research environment

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

Chapter 10. Implementing Subprograms

Chapter 10. Implementing Subprograms Chapter 10 Implementing Subprograms Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms

More information

KGEN: Fortran Kernel Generator. National Center for Atmospheric Research (NCAR) Youngsung Kim, John Dennis, Raghu R. Kumar, and Amogh Simha

KGEN: Fortran Kernel Generator. National Center for Atmospheric Research (NCAR) Youngsung Kim, John Dennis, Raghu R. Kumar, and Amogh Simha KGEN: Fortran Kernel Generator Youngsung Kim, John Dennis, Raghu R. Kumar, and Amogh Simha National Center for Atmospheric Research (NCAR) Contents Introduction A kernel generation example Kernel generation

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

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

More information

UNIVERSITY OF OSLO Department of Geosciences. GEO4060: Intro to Fortran 2003 programming. Gunnar Wollan

UNIVERSITY OF OSLO Department of Geosciences. GEO4060: Intro to Fortran 2003 programming. Gunnar Wollan UNIVERSITY OF OSLO Department of Geosciences GEO4060: Intro to Fortran 2003 programming Gunnar Wollan Spring 2014 Contents 1 Introduction 2 1.1 Why use Fortran?.................................... 2 1.2

More information

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

0. Overview of this standard Design entities and configurations... 5 Contents 0. Overview of this standard... 1 0.1 Intent and scope of this standard... 1 0.2 Structure and terminology of this standard... 1 0.2.1 Syntactic description... 2 0.2.2 Semantic description...

More information

Language Fundamentals

Language Fundamentals Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

More information

PROCEDURES, METHODS AND FUNCTIONS

PROCEDURES, METHODS AND FUNCTIONS Cosc 2P90 PROCEDURES, METHODS AND FUNCTIONS (c) S. Thompson, M. Winters 1 Procedures, Functions & Methods The are varied and complex rules for declaring, defining and calling procedures, methods and functions

More information

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a.

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a. UNIT IV 1. Appropriately comment on the following declaration int a[20]; a. Array declaration b. array initialization c. pointer array declaration d. integer array of size 20 2. Appropriately comment on

More information

Special Topics: Programming Languages

Special Topics: Programming Languages Lecture #17 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 17 Lecture #17 1 Slide 1 Runtime Representations Variable Names Environment L-values Scope, Extent

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

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

Numerical Modelling in Fortran: day 3. Paul Tackley, 2017 Numerical Modelling in Fortran: day 3 Paul Tackley, 2017 Today s Goals 1. Review subroutines/functions and finitedifference approximation from last week 2. Review points from reading homework Select case,

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

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE AIS Cube LANGUAGE REFERENCE [THE BLAZINGCORE SERIES] With superior number crunching abilities and peripheral handling on our custom embedded OS, Rapid prototyping is now easy... and blazing fast. Sonata

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 03: Program Development Life Cycle Readings: Not Covered in Textbook Program Development

More information

Assignment no. 5 Implementing the Parallel Quick-sort algorithm in parallel distributed memory environment

Assignment no. 5 Implementing the Parallel Quick-sort algorithm in parallel distributed memory environment Assignment no. 5 Implementing the Parallel Quick-sort algorithm in parallel distributed memory environment DCAMM PhD Course Scientific Computing DTU January 2008 1 Problem setting Given a sequence of n

More information

Chapter 9 Subprograms

Chapter 9 Subprograms Chapter 9 Subprograms We now explore the design of subprograms, including parameter-passing methods, local referencing environment, overloaded subprograms, generic subprograms, and the aliasing and problematic

More information

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE AIS Cube LANGUAGE REFERENCE [THE BLAZINGCORE SERIES] With superior number crunching abilities and peripheral handling on our custom embedded OS, Rapid prototyping is now easy... and blazing fast. Sonata

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

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

INF 212 ANALYSIS OF PROG. LANGS PROCEDURES & FUNCTIONS. Instructors: Kaj Dreef Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS PROCEDURES & FUNCTIONS. Instructors: Kaj Dreef Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS PROCEDURES & FUNCTIONS Instructors: Kaj Dreef Copyright Instructors. Subroutines aka Procedures Historically: blocks of instructions executed several times during program

More information

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design What is a Function? C Programming Lecture 8-1 : Function (Basic) A small program(subroutine) that performs a particular task Input : parameter / argument Perform what? : function body Output t : return

More information

Fortran functions: some examples

Fortran functions: some examples Laboratorio di Calcolo di Aerodinamica a.a. 2016/17 DIMA, Sapienza University of Rome, Italy April 4, 2017 Definite DO statement fattoriale.f90 code 1!file: fattoriale.f90 2!This program reads a number

More information

Goals for This Lecture:

Goals for This Lecture: Goals for This Lecture: Understand the various kinds of REAL types Understand how to select precision in a processor independent manner Introduction to Makefiles Kinds of REAL variables The default REAL

More information

UNIT II PL / SQL AND TRIGGERS

UNIT II PL / SQL AND TRIGGERS UNIT II PL / SQL AND 1 TRIGGERS TOPIC TO BE COVERED.. 2.1 Basics of PL / SQL 2.2 Datatypes 2.3 Advantages 2.4 Control Structures : Conditional, Iterative, Sequential 2.5 Exceptions: Predefined Exceptions,User

More information

Functions. A function is a subprogram that performs a specific task. Functions you know: cout << Hi ; cin >> number;

Functions. A function is a subprogram that performs a specific task. Functions you know: cout << Hi ; cin >> number; Function Topic 4 A function is a subprogram that performs a specific task. you know: cout > number; Pre-defined and User-defined Pre-defined Function Is a function that is already defined

More information

An OpenACC construct is an OpenACC directive and, if applicable, the immediately following statement, loop or structured block.

An OpenACC construct is an OpenACC directive and, if applicable, the immediately following statement, loop or structured block. API 2.6 R EF ER ENC E G U I D E The OpenACC API 2.6 The OpenACC Application Program Interface describes a collection of compiler directives to specify loops and regions of code in standard C, C++ and Fortran

More information

Information technology Programming languages Fortran Part 1: Base language

Information technology Programming languages Fortran Part 1: Base language INTERNATIONAL STANDARD ISO/IEC 1539-1:2010 TECHNICAL CORRIGENDUM 2 Published 2013-06-01 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE

More information

Programming Languages: Lecture 11

Programming Languages: Lecture 11 1 Programming Languages: Lecture 11 Chapter 9: Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 9 Topics 2 Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Chapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point

Chapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point Fundamental Characteristics of Subprograms 1. A subprogram has a single entry point 2. The caller is suspended during execution of the called subprogram 3. Control always returns to the caller when the

More information

Chapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram?

Chapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram? Control Abstraction Chapter 8 (81 84) Control Abstraction: Subroutines and parameters Programmer defined control structures Subprograms Procedures Functions Coroutines Exception handlers Processes Subprograms

More information

1. User-Defined Functions & Subroutines Part 2 Outline

1. User-Defined Functions & Subroutines Part 2 Outline User-Defined Functions Subroutines Part 2 Outline 1. User-Defined Functions Subroutines Part 2 Outline 2. Argument Order When Passing Arrays 3. Code Reuse Is GOOD GOOD GOOD 4. Reusing User-Defined Functions

More information

C for Engineers and Scientists

C for Engineers and Scientists C for Engineers and Scientists An Interpretive Approach Harry H. Cheng University of California, Davis 0.8 0.6 j0(t) j1(t) j2(t) j3(t) 0.4 Bessel functions 0.2 0-0.2-0.4-0.6 1 2 3 4 5 6 7 8 9 10 t Copyright

More information

9. Subprograms. 9.2 Fundamentals of Subprograms

9. Subprograms. 9.2 Fundamentals of Subprograms 9. Subprograms 9.2 Fundamentals of Subprograms General characteristics of subprograms A subprogram has a single entry point The caller is suspended during execution of the called subprogram Control always

More information

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

Array Processing { Part II. Multi-Dimensional Arrays. 1. What is a multi-dimensional array? Array Processing { Part II Multi-Dimensional Arrays 1. What is a multi-dimensional array? A multi-dimensional array is simply a table (2-dimensional) or a group of tables. The following is a 2-dimensional

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

Static Members. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Static Members. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Static Members OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Static Data Members Static data members hold global data that is common to all objects of the class. Ex: count of objects currently present,

More information

NAG Library Routine Document C05RBF.1

NAG Library Routine Document C05RBF.1 C05 Roots of One or More Transcendental Equations NAG Library Routine Document Note: before using this routine, please read the Users Note for your implementation to check the interpretation of bold italicised

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

CS61C Machine Structures. Lecture 5 C Structs & Memory Mangement. 1/27/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 5 C Structs & Memory Mangement. 1/27/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 5 C Structs & Memory Mangement 1/27/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L05 C Structs (1) C String Standard Functions

More information

Protection Levels and Constructors The 'const' Keyword

Protection Levels and Constructors The 'const' Keyword Protection Levels and Constructors The 'const' Keyword Review: const Keyword Generally, the keyword const is applied to an identifier (variable) by a programmer to express an intent that the identifier

More information

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration IT441 Network Services Administration Subroutines DRAFT (a.k.a., Functions, Methods, etc.) Organizing Code We have recently discussed the topic of organizing data (i.e., arrays and hashes) in order to

More information

Fortran Introduction

Fortran Introduction 26/10/2015 1 Background 2 Creating an Executable 3 Variables 4 Program Flow 5 Procedures 6 Input and Output 7 Deprecated Background In this opening section, I will talk briefly about The History of Fortran

More information

Intro to C: Pointers and Arrays

Intro to C: Pointers and Arrays Lecture 4 Computer Science 61C Spring 2017 January 25th, 2017 Intro to C: Pointers and Arrays 1 Administrivia Teaching Assistants: Let s try that again. Lectures are recorded. Waitlist/Concurrent Enrollment

More information

Paul F. Dubois. X-Division.

Paul F. Dubois. X-Division. Large-scale simulations with Fortran 95: An object-based approach Lesson 3 Types and objects X-Division 1 of 29 In our first two lessons, we have concentrated on arrays, modules, and derived types. It

More information

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

Advanced Features. SC10 Tutorial, November 15 th Parallel Programming with Coarray Fortran Advanced Features SC10 Tutorial, November 15 th 2010 Parallel Programming with Coarray Fortran Advanced Features: Overview Execution segments and Synchronisation Non-global Synchronisation Critical Sections

More information

11/29/17. Outline. Subprograms. Subroutine. Subroutine. Parameters. Characteristics of Subroutines/ Subprograms

11/29/17. Outline. Subprograms. Subroutine. Subroutine. Parameters. Characteristics of Subroutines/ Subprograms Outline Subprograms In Text: Chapter 9 Definitions Design issues for subroutines Parameter passing modes and mechanisms Advanced subroutine issues N. Meng, S. Arthur 2 Subroutine A sequence of program

More information