


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















How can we do these repetitive computations (e.g., a thousand times) in Fortran? A. Cut and paste the code a thousand times?
meaning… DO NUM = 1, 4 (insert code you’re here, e.g., calculations) END DO means:
DO NUM = 1, 4 PRINT*, ‘value is’,NUM END DO Would produce: (since NUM =1) value is 1 (since NUM =2) value is 2 (since NUM =3) value is 3 (since NUM =4) value is 4 8
DO NUM = 1,10 implies DO NUM = 1,10,1 (^10)
11
DO “from west coast to east coast” DO “from Mexican border to Canadian border ” DO “from ground level to tropopause” (fancy meteorological calculations) ENDDO ENDDO ENDDO 13
DO “ from west coast to east coast ” – set at 1 st value DO “ from Mexican border to Canadian border ” – set at 1 st value DO “ from ground level to tropopause ” – do for ALL values (fancy meteorological calculations) ENDDO ENDDO ENDDO 14
DO “ from west coast to east coast ” – do for rest of values DO “ from Mexican border to Canadian border ” – again do for ALL values DO “ from ground level to tropopause ” – again do for ALL values (fancy meteorological calculations) ENDDO ENDDO ENDDO 16
DO I=1,1000 I= DO J=1, 2000 J= DO K=1,50 K=1 TO 50 (fancy meteorological calculations) ENDDO ENDDO ENDDO Then… DO I=1,1000 I= DO J=1, 2000 J= DO K=1,50 K=1 TO 50 (fancy meteorological calculations) ENDDO ENDDO ENDDO Etc. 17
IF (something) EXIT! Which means jump out of loop! (insert code you’re here, e.g., calculations) END DO (C) DO (insert code you’re here, e.g., calculations) IF (something) EXIT! Which means jump out of loop! END DO 19
Example: IMPLICIT … REAL … ! DO READ*, input some MET data IF (we’re at the end of the data) EXIT! (calculations e.g., averaging, finding max values etc.) END DO (next set of statements) 20