Basic_comphy_ch2

Basic_comphy_ch2 - Ch. 2 Fortran 90: Basic References: 1....

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
    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
Background image of page 1

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

View Full DocumentRight Arrow Icon
    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 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.)
Background image of page 2
    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 Try1 .f90 Note: The file's name must end with “ .f90 ” so that the compiler recongzies that it is a Fortran 90 program.
Background image of page 3

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

View Full DocumentRight Arrow Icon
    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)
Background image of page 4
    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
Background image of page 5

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

View Full DocumentRight Arrow Icon
    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.
Background image of page 6
    7 How to compile the code? On our department's linux machines:
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/21/2010 for the course PHYSICS 2351 taught by Professor Drlinlapming during the Spring '10 term at CUHK.

Page1 / 43

Basic_comphy_ch2 - Ch. 2 Fortran 90: Basic References: 1....

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online