Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICE1341 Programming Languages Spring 2005 Lecture #15 Lecture #15 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.

Similar presentations


Presentation on theme: "ICE1341 Programming Languages Spring 2005 Lecture #15 Lecture #15 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University."— Presentation transcript:

1 ICE1341 Programming Languages Spring 2005 Lecture #15 Lecture #15 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University (ICU)

2 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Chapter 8 – Statement-Level Control Structures Chapter 8 – Statement-Level Control Structures Unconditional Branching Unconditional Branching Guarded Commands Guarded Commands FORTRAN Programming FORTRAN Programming Data Types Data Types Operators Operators Last Lecture

3 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University This Lecture FORTRAN Programming – cont. FORTRAN Programming – cont. Control Statements Control Statements Input/Output Statements Input/Output Statements Subprograms Subprograms Homework #5 – FORTRAN Programming Exercises Homework #5 – FORTRAN Programming Exercises

4 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Program Flow Control GotoGOTO (10, 20, 30) KCOUNT GotoGOTO (10, 20, 30) KCOUNT Logical IFIF (K.LT. 1) K = K + 1 Logical IFIF (K.LT. 1) K = K + 1 Arithmetic IFIF (A / T – S) 10, 20, 30 Arithmetic IFIF (A / T – S) 10, 20, 30 Block IFIF (M.GT. 15) THEN M = M / 3 Block IFIF (M.GT. 15) THEN M = M / 3 ELSE M = M * 3 ENDIF Do loopsDO 10 I = 1, N, 2 Do loopsDO 10 I = 1, N, 2 SUM = SUM + I SUM = SUM + I 10 CONTINUE 10 CONTINUE

5 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Data Input Standard I/O Units: stdin (5), stdout (6) Standard I/O Units: stdin (5), stdout (6) READ (5, 99) NUM, VAL, STR 99FORMAT (I3, 2X, F5.2, 1X, A20) READ (5, 98) N1, N2, N3, STR1, STR2 98FORMAT (3I5, //2A15) READ (5, *) L, SUM, NAME OPEN (UNIT=10, FILE=‘data.txt’, * STATUS=‘OLD’) * STATUS=‘OLD’) READ (10, *) N, A, X, S

6 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Input Format Example / I6orA62X 4I 2I2I F5.1 2X 5X F5.1 5X F6.1

7 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Data Output Carriage Control Codes: 1H1 (new page), 1H0 (double space), 1Hb (single space)… Carriage Control Codes: 1H1 (new page), 1H0 (double space), 1Hb (single space)… WRITE (6, 97) A, B, C 97FORMAT (1H1,//3F8.2) WRITE (6, 96) X, Y, SUM 96FORMAT (1H0, 4HX =, F4.1, 3X, 4HY =, * F4.1, 4X, 6HSUM =, F5.1, 20(1H*)) * F4.1, 4X, 6HSUM =, F5.1, 20(1H*)) PRINT *, ‘X = ’, X, ‘Y = ’, Y, ‘SUM = ’, SUM OPEN (UNIT=11, FILE=‘data.txt’, * STATUS=‘NEW’) * STATUS=‘NEW’) WRITE (11, *) ‘Result = ’, SUM

8 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Subprograms - Subroutines SUBROUTINE SUMMARY(X, N, TOT) DIMENSION X(20) TOT = 0.0 DO 10 I = 1, N TOT = TOT + X(I) TOT = TOT + X(I) 10CONTINUE RETURNEND J.W. Perry Cole, ANSI FORTRAN IV, wcb All parameters are bidirectional

9 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Subprograms - Functions FUNCTION TOTAL(X, N) DIMENSION X(20) TOTAL = 0.0 DO 10 I = 1, N TOTAL = TOTAL + X(I) TOTAL = TOTAL + X(I) 10CONTINUE RETURNEND

10 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Subprogram Calls PROGRAM SAMPLE2 DIMENSION A(10), B(20) READ (5, 99) A 99FORMAT (10F4.2) CALL SUMMARY(A, 10, SUM) WRITE (6, 98) A, SUM 98FORMAT (1, H0, 10F7.2/, 6HSUM =, F7.2) READ (5, 99) B WRITE (6, 98) B, TOTAL(SUM, 10) STOPEND

11 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University GNU FORTRAN77 Compiler Download G77 from: Download G77 from: G77 Installation and Execution Instructions: G77 Installation and Execution Instructions: ators/Fortran_g77/GettingStartedGnuFortran.pdf ators/Fortran_g77/GettingStartedGnuFortran.pdf FORTRAN77 Tutorial: FORTRAN77 Tutorial: FORTRAN77 Language Reference: FORTRAN77 Language Reference:

12 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Homework #5 – A Weather Data Retrieval Program (1) Install G77 on your computer and practice how to compile and run FORTRAN programs Install G77 on your computer and practice how to compile and run FORTRAN programs Download a weather data file that contains the latest week’s weather information from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/data.txt Download a weather data file that contains the latest week’s weather information from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/data.txt ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/data.txt Download the weather station list from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/stnlist-sorted.txt Download the weather station list from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/stnlist-sorted.txt ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/stnlist-sorted.txt Check the weather data file format from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/README.TXT Check the weather data file format from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/README.TXT ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/README.TXT

13 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Homework #5 – A Weather Data Retrieval Program (2) Weather Data File Weather Data File Format

14 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Homework #5 – A Weather Data Retrieval Program (3) Weather Station List RKTF DAEJEON KO

15 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Homework #5 – A Weather Data Retrieval Program (4) Programming Exercise #1: Programming Exercise #1: Write a FORTRAN program that accepts a city name (e.g., DAEJEON, SEOUL, PARIS), and prints the lowest and highest temperatures (in Celsius), and sea-level pressure values for the latest week like: City: DAEJEON DateMINMAXSLP …

16 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Homework #5 – A Weather Data Retrieval Program (5) Programming Exercise #2 (Extra-credit): Programming Exercise #2 (Extra-credit): Assume that you are traveling with a PDA with a GPS device. Please write a FORTRAN program that finds a city name base on the lat/long data received from the GPS device (keyboard inputs for this exercise), and prints the latest weather information of the place: Lat: , Long: City: DAEJEON DateMINMAXSLP

17 Spring ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Homework #5 – A Weather Data Retrieval Program (6) To retrieve weather information for a city, use the weather station number that is firstly matched against the city name in the station list To retrieve weather information for a city, use the weather station number that is firstly matched against the city name in the station list Use INDEX function to match a city name from the station list Use INDEX function to match a city name from the station list IF (INDEX(NAME, ‘ICU’).GT. 0) PRINT *, ‘Matched!’ PRINT *, ‘Matched!’ Submit the source program electronically (to TA) by Midnight of Wednesday May 4, 2005 Submit the source program electronically (to TA) by Midnight of Wednesday May 4, 2005 Please do not collaborate with other students! Please do not collaborate with other students!


Download ppt "ICE1341 Programming Languages Spring 2005 Lecture #15 Lecture #15 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University."

Similar presentations


Ads by Google