12.07.2015 Views

Contents

Contents

Contents

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12 2 MotivationREAL, PARAMETER :: G = 9.81 ! acceleration due to gravityREAL, PARAMETER :: RHOREF = 1028.0 ! reference densityREAL, PARAMETER :: PI = 3.14159265359 ! piText after a pronunciation mark is treated as a comment and ignored by the compiler.Although not required, comments are very useful aids to highlight the structureof the program and as reminders for future uses. Parameters that are allowed tochange values during the program’s execution are declared with:REAL :: wspeed ! wind speedINTEGER :: k ! grid indexCHARACTER(3) :: txtIn this example, “txt” is a character with three letters. One-dimensional and twodimensionalarrays are declared with:REAL :: eta(0:nx+1) ! sea-level elevationREAL :: w(0:nz+1,0:nx+1) ! vertical velocityWith nx=11 and nz = 5, for instance, “eta” obtains 11+2=13 so-far unassignedelements: eta(0), eta(1), ··· ..., eta(11), eta(12), and “w” is a two-dimensional arrayof 13 columns and 7 rows. After the declaration section, values can be assigned tothese arrays using DO loops such as:DO k = 0,nx+1IF(k > 50) THENeta(k) = 1.0ELSEeta(k) = 0.0END IFEND DOThis DO-loop repeats certain calculations for the index “k” running from 0 atsteps of 1 to nx+1. If the reader wants to do it the other way around, the solution is:DO k = nx+1,0,−1IF(k > 50) THENeta(k) = 1.0ELSEeta(k) = 0.0END IFEND DOThis example also includes an IF statement. Options are “>” (greater than), “=” (greater or equal), “

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!