110 likes | 217 Views
MET 50. A bit more on… Repetitive EXECUTION. The “IF” statement. In Meteorology, it is common to use the letters I,J,K to denote counters . “I” is the counter to tell us where we are west east “J” is the counter to tell us where we are north south
E N D
MET 50 A bit more on… Repetitive EXECUTION
The “IF” statement In Meteorology, it is common to use the letters I,J,K to denote counters. “I” is the counter to tell us where we are west east “J” is the counter to tell us where we are north south “K” is the counter to tell us where we are up down MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement I=1 could be Greenwich I=2 would be east of Greenwich (say 100 km east) I=3 would be 100 km further east etc. I=IMAX would be west of Greenwich (say 100 km west) J=1 could be the south pole J=2 would be north of the south pole (say 100 km north) J=3 would be 100 km further north etc. J=JMAX would be the north pole K=1 could be the ground K=2 would be above that (say 1 km above) K=3 would be 1 km further up etc. K=KMAX could be the top of atmosphere MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement And then, you would see loops like this: DO I = 1, IMAX DO J = 1, JMAX DO K = 1, KMAX (important meteorological calculations) ENDDO ENDDO ENDDO MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement How does this look in “old” Fortran 77 code??? DO 10 I = 1, IMAX (important meteorological calculations) 10 CONTINUE MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement How does this look in “old” Fortran 77 code??? DO 10 I = 1, IMAX (important meteorological calculations) 10 CONTINUE Here, “10” is a statement label – something which has mostly vanished in Fortran 90. A statement label can have any integer value from 1 to 9999. MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement Statement label goes in columns 2-5. Why??? Because we used to use cards, and columns 1-6 on the cards were special! MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement History lesson…cards… MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement DO 10 I = 1, IMAX (important meteorological calculations) 10 CONTINUE So this says: Starting @ 1st line, and going until I = IMAX (same as Fortran 90) Perform the computations inside the loop. Once I = IMAX, don’t loop back – instead, “continue” on from statement # 10. MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement In 3D? DO 10 I = 1, IMAX DO 20 J = 1, JMAX DO 30 K = 1, KMAX (important meteorological calculations) 30 CONTINUE 20 CONTINUE 10 CONTINUE MET 50, FALL 2011, CHAPTER 4 PART 2
The “IF” statement Where… DO 10 I = 1, IMAX DO 20 J = 1, JMAX DO 30 K = 1, KMAX (important meteorological calculations) 30 CONTINUE 20 CONTINUE 10 CONTINUE column 7+ etc. etc. MET 50, FALL 2011, CHAPTER 4 PART 2