{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Basic_comphy_ch2

# Basic_comphy_ch2 - Ch 2 Fortran 90 Basic References 1 T.M.R...

This preview shows pages 1–9. Sign up to view the full content.

1 Ch. 2 Fortran 90: Basic References: 1. T.M.R. Ellis et al., “ Fortran 90 programming ” , Chs. 2, 3, 8, 10 2. L. Nyhoff & S. Leestma, “ Introduction to FORTRAN 90 ” , Chs. 2, 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Outline 2.1 Your first Fortran 90 code (Ch.2 of Ellis et al.) 2.2 Data types & basic operations (Ch.2 of Nyhoff & Leestma; Ch.3 of Ellis et al.) 2.3 Fortran intrinsic functions (Sec. 2.2 and Appendix A of Nyhoff & Leestma) 2.4 Parameterized REAL variables (Sec. 10.2 of Ellis et al.) 2.5 Input/Output (Ch. 5 of Nyhoff & Leestma; Ch. 8 of Ellis et al.)
3 2.1 Your first Fortran 90 code 1D motion under constant acceleration v t = u at x t = ut 1 2 at 2 Aim: write a Fortran program to calculate v & x (for given a ,  u ,  t ) * Login to your Unix account, use pico ” to edit & save a file called Try1 .f90 Note: The file's name must end with .f90 ” so that the compiler recongzies that it is a Fortran 90 program.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 PROGRAM Try1 IMPLICIT NONE REAL :: x, v, u, a, t a = 1.0 ! acceleration u = 2.0 ! initial velocity t = 1.0 ! time v = u + a*t x = u*t + a*t**2/2 PRINT *, "Velocity = ", v WRITE(*,*) "Displacement = ", x WRITE(10,*) "Velocity = ", v WRITE(10,*) "Displacement = ", x END PROGRAM Try1 Program heading The file Try1.f90 ” contains: Note: we use upper case for Fortran keywords eg: PROGRAM, IMPLICIT NONE, REAL, PRINT ...etc To cancel implicit naming convention (so that all variables must be declared) End of the program (this statement terminates execution of the program)
5 Declaration of variables REAL :: x, v, u, a, t a = 1.0 ! acceleration u = 2.0 ! initial velocity t = 1.0 ! time v = u + a*t x = u*t + a*t**2/2 Variable initalization Manipulation An exclamation mark ! ” indicates the beginning of a comment (read by human only) * Arithmetic operators in Fortran: Operator Meaning Priority + Addition Low - Subtraction Low * Multiplication Medium / Division Medium ** Exponentiation High * Within the same level of priority, (+, -, *, /) will proceed from left to right . However, exponentiation will proceed from right to left (eg: 2**3**2 = 2**9 = 512 ) 2 3 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 PRINT *, "Velocity = ", v WRITE(*,*) "Displacement = ", x WRITE( 10 ,*) "Velocity = ", v WRITE( 10 ,*) "Displacement = ", x 2 different ways to output the results to the screen ( List-directed output statement ) Write to a file (“ fort. 10 ” ) in free FORMAT (more later .... ) * We shall discuss input/output (IO) in more detail later.
7 How to compile the code? On our department's linux machines: ifort Try1.f90 -o Try1 Fortran compiler command (depends on the compiler) Fortran code Compilation command Executable file * The above command will compile the code “ Try1.f90 ” and create an executable file Try1 (the name is arbitrary) * You can also use the command: ifort Try1.f90 This will create an executable file called “ a.out Remark: Our department's machines have 2 different Fortran compilers ifort ” = Intel Fortran compiler f95 ” = NAGWare Fortran 95 compiler

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 How to run?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 43

Basic_comphy_ch2 - Ch 2 Fortran 90 Basic References 1 T.M.R...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online