More on F90 Outline: I.Parameter statements II.Comments III.Program layout-- execution part IV.if/then/else V.Case statements VI.do loops VII.goto VIII.Intrinsic.

Slides:



Advertisements
Similar presentations
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Advertisements

Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
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.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Need for Arrays Exercise Read the IDs and the grades for all ICS 101 students. Compute and print the average of the students. Print the grades and IDs.
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
FORTRAN Short Course Week 2 Kate Thayer-Calder February 23, 2009.
Introduction to Fortran Fortran Evolution Drawbacks of FORTRAN 77 Fortran 90 New features Advantages of Additions.
Program Design and Development
Chapter 2 Basic Elements of Fortan
Fortran 9x HTML version. New F90 features Free source form Modules User-defined data types and operators Generic user-defined procedures Interface blocks.
Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Revision – A simple program How to start a program? How to end a program? How to declare variables? What are the mathematical operators? How to start a.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
Chapter 8 Arrays and Strings
VB .NET Programming Fundamentals
Building blocks No. 2 and GWBASIC PROGRAMMING. –For new comers,GWBASIC a good start- easy to learn, portable executable program with graphics capability,
ReAl :: x OK CHARACTER :: name OK, a 1 character name! CHARACTER(LEN=10) :: name OK, string length 10 REAL :: var-1 cannot have -1 in a declaration var_1.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Introduction to FORTRAN
Call-by-Value vs. Call-by-Reference Call-by-value parameters are used for passing information from the calling function to the called function (input parameters).
Beginning Fortran Fortran (77) Basics 22 October 2009 *Black text on white background provided for easy printing.
Tutorial : Fortran By Gopika Sood.
1 Week 12 Arrays, vectors, matrices and cubes. Introduction to Scientific & Engineering Computing 2 Array subscript expressions n Each subscript in an.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Multi-Dimensional Arrays
April 14, ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)
Chapter 8 Arrays and Strings
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Fortran: Expressions and Assignments Session Two ICoCSIS.
FORTRAN FORmula TRANslator -Anand Trivedi. HISTORY  Designed and written from scratch in by an IBM team lead by John W. Backus as the first.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CHAPTER 9 SUBPROGRAMS Subprograms are useful in the following cases: long complicated program  Subprograms make it readable and simple by dividing it.
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
Chapter 8: Arrays and Functions Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
I Power Higher Computing Software Development High Level Language Constructs.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 Lab 1. C Introduction  C: –Developed by Bell lab. in –a procedure-oriented programming language.  Developing environments: –Editing –Preprocessing.
Beginning Fortran Fortran (77) Advanced 29 October 2009 *Black text on white background provided for easy printing.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
FUNCTIONS IN FORTRAN For a complex program difficulties like writing it and debugging are encountered. These can be minimized by breaking main program.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
 2000 Prentice Hall, Inc. All rights reserved Program Components in C++ Function definitions –Only written once –These statements are hidden from.
COP 3275 – Finishing Loops and Beginning Arrays Instructor: Diego Rivera-Gutierrez.
CSE3302 Programming Languages (notes continued)
ALGORITHMS AND FLOWCHARTS
Fortran Tutorial Fortran spaces for code qqqqqqCODE
September 8th.
Haskell.
CSC113: Computer Programming (Theory = 03, Lab = 01)
User-Defined Functions
Chapter 4: Algorithm Design
Matlab review Matlab is a numerical analysis system
Midterm Review Programming in Fortran
Chapter 4: Algorithm Design
mdul-cntns-sub-cmmnts2.f90
The structure of programming
REPETITION Why Repetition?
Programming The ideal style of programming is Structured or
Presentation transcript:

More on F90 Outline: I.Parameter statements II.Comments III.Program layout-- execution part IV.if/then/else V.Case statements VI.do loops VII.goto VIII.Intrinsic functions IX.Input/output X.Calling subroutines: call rs example XI.Array assignment XII.For the first project…

I. Parameter statements Not really parameters, but instead constants Can be integer, real, etc. REAL, PARAMETER :: pi= INTEGER, PARAMETER :: MAX=100 Once set, parameters cannot be changed within your code!

II. Comments Comments start with c or ! No function other than notes for programmer Still important! ! Program to compute eigenfunctions and eigenvalues ! for a particle in a one-dimensional potential Comments are especially important for anyone else who inherits your code!

III. Program layout-- execution part PROGRAM program-name IMPLICIT NONE [specification part] [execution part] [subprogram part] END PROGRAM program-name The execution part is control statements, subroutine calls, functions, and intrinsic functions

IV. If/then/else Control statement Can nest as many as one needs if (x<0) x=0 Just a single if statement… no then or else: Or, when several conditions are desired: if (x<0) then x=0 else if (x>100) x=100 endif Notice indentation! Terminate with “endif”

V. Select Case construct Essentially an alternative to if/then/else Another example of control statements INTEGER :: option select case(option) case(1) x=0 case(2) x=100 case default x=1 end select

VI. Do loops… Another control statement Useful for repeated calculations INTEGER :: n REAL :: x,y do n=1,100 x=pi*n y=cos(x) enddo Integer n takes on Values 1,2,3,…,100 Again indentation

VII. Goto statements Often best to avoid as much as possible Very often used in conjunction with “if” statements REAL :: x if (x<0) goto 100 … 100 x=0 Statements that Are only done if x>0 Line number 100 (just a tag or label)

VIII. Intrinsic functions Mathematical functions Intrinsic to f90 compiler REAL :: x,y y=cos(x) y=exp(x) y=atan(x) Cosine of argument x y=e x y=tan -1 (x) Links to intrinsic function list given in my webpage

IX. Input/output Input data usually from “read” statement… Input file Output results from “write” statement… screen or output file Everything needs a unit number Format statements… useful, sometimes needed, can be a pain REAL :: x,y y=cos(x) y=exp(x) y=atan(x)

IX. Input/output Input data usually from “read” statement… Input file Output results from “write” statement… screen or output file Everything needs a unit number Format statements… useful, sometimes needed, can be a pain INTEGER :: n,i,j,k REAL :: x,y,z open(unit=10,file=‘input.dat’) open(unit=11,file=‘output.dat’) read(10,*) i,j,k,x,y n=I+j+k z=x+y write(11,*) n,z write(6,*) n,z Unformatted input and output unit=6 reserved for output to screen

X. Calling a subroutine Subroutines for frequently-used applications… portable Example: rs….. Diagonalize a real-symmetric matrix Arguments represent common variables subroutine rs(nm,n,a,w,matz,z,fv1,fv2,ierr) Arguments of the subroutine Arguments need to be of same type/dimension as in subroutine

subroutine rs(nm,n,a,w,matz,z,fv1,fv2,ierr) integer n,nm,ierr,matz double precision a(nm,n),w(n),z(nm,n),fv1(n),fv2(n) Real variable arrays but of higher precision Example: calling rs from the execution part Input matrix Output eigenvalues Output eigenvectors First look at subroutine itself… comments and declaration part show us what to do…

subroutine rs(nm,n,a,w,matz,z,fv1,fv2,ierr) integer n,nm,ierr,matz double precision a(nm,n),w(n),z(nm,n),fv1(n),fv2(n) Call statement in your code for project #1 First look at subroutine itself… comments and declaration part show us what to do… INTEGER, PARAMETER:: ndim=10 INTEGER :: ierr REAL*8, DIMENSION(ndim) :: w,fv1,fv2 REAL*8, DIMENSION(ndim,ndim) :: hami,z … call rs(ndim,ndim,hamil,w,z,fv1,fv2,ierr) Input H matrix Output

XI: Array assignment REAL, DIMENSION(10,10) :: a,b,c REAL :: d INTEGER :: i,j a=2.0 d=2.0 Assigns the value 2.0 to each element of a Assigns 2.0 to the real scalar variable d do i=1,10 do j=1,10 b(i,j) = real(i+j) enddo c=a+b The real value of i+j, since both i and j are integers Assigns all elements of c

XII: For the first project… Define elements of hamil(nmax,nmax) using nested do loops Call rs subroutine to diagonalize hamil Analyze the eigenvalues w returned from hamil Analyze and plot the five lowest eigenfunctions… gnuplot Compare to estimates obtained from perturbation theory for the eigenvalues Requires intrinsic functions dexp and dcos… (double-precisio exponential and cosine functions…