Presentation is loading. Please wait.

Presentation is loading. Please wait.

April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)

Similar presentations


Presentation on theme: "April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)"— Presentation transcript:

1 April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341) Lecture #13 April 14, 2004 In-Young Ko iko.AT. icu.ac.kr Information and Communications University (ICU) iko.AT. icu.ac.kr

2 April 14, 2004 2 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Announcements The solution of the midterm exam is now available on the class homepage The solution of the midterm exam is now available on the class homepage

3 April 14, 2004 3 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko FORTRAN (Formula Translating System) Designed to efficiently translate mathematical formulas into IBM 704 machine code Designed to efficiently translate mathematical formulas into IBM 704 machine code IBM 704 (1954) “The first mass-produced computer with core memory and floating- point arithmetic” Photo: Lawrence Livermore National Laboratory

4 April 14, 2004 4 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko FORTRAN Coding Format FORTRAN programs were written in a coding form with a strict formatting rule Continuation (6) FORTRAN Statement (7-72) Identification Sequence (73-80) Statement Number (1-5) J.W. Perry Cole, ANSI FORTRAN IV, wcb

5 April 14, 2004 5 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Punched Cards Coded FORTRAN programs were converted onto punched cards for loading Photos: http://www.tno.nl/instit/fel/museum/computer/en/punchcards.html

6 April 14, 2004 6 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Early FORTRAN Versions FORTRAN I (1957) FORTRAN I (1957) Names could have up to six characters (IBM 704 has a 6-bit BCD character set and 36-bit word) Names could have up to six characters (IBM 704 has a 6-bit BCD character set and 36-bit word) Post-test counting loop ( DO ), Formatted I/O, User- defined subprograms, Three-way selection statement (arithmetic IF ) Post-test counting loop ( DO ), Formatted I/O, User- defined subprograms, Three-way selection statement (arithmetic IF ) No data typing statements (Implicit Type Declaration – Variables whose names begin with I, J, K, L, M, and N are integer types, all others are floating point) No data typing statements (Implicit Type Declaration – Variables whose names begin with I, J, K, L, M, and N are integer types, all others are floating point) FORTRAN II (1958) FORTRAN II (1958) Independent compilation of subroutines Independent compilation of subroutines * AW Lecture Notes

7 April 14, 2004 7 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Later FORTRAN Versions FORTRAN IV (1960-62) – ANSI standard in 1966 FORTRAN IV (1960-62) – ANSI standard in 1966 Explicit type declarations Explicit type declarations Logical selection statement Logical selection statement Subprogram names could be parameters Subprogram names could be parameters FORTRAN 77 (1978) FORTRAN 77 (1978) Character string handling Character string handling Logical loop control statement Logical loop control statement IF-THEN-ELSE statement IF-THEN-ELSE statement FORTRAN 90 (1990) FORTRAN 90 (1990) Free coding format Free coding format Modules, Dynamic arrays, Pointers, Recursion, CASE statement Modules, Dynamic arrays, Pointers, Recursion, CASE statement * AW Lecture Notes

8 April 14, 2004 8 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko A Sample FORTRAN Program C *** This is a sample FORTRAN IV program PROGRAM SAMPLE READ (5, 990) A, B 990FORMAT (F5.2, F5.2) SUM = A + B WRITE (6, 81) A, B, SUM 81FORMAT (1X, F5.2, 3X, F5.2, 3X, F6.2) STOPEND J.W. Perry Cole, ANSI FORTRAN IV, wcb

9 April 14, 2004 9 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko FORTRAN Data Types (1) Integer Integer Implicit Typing: Variables whose names begin with I~N Implicit Typing: Variables whose names begin with I~N Explicit Declaration Explicit Declaration e.g., INTEGER A, TOTAL Real – Single precision floating point number Real – Single precision floating point number Implicit Typing: Variables whose names begin with other than A~H or O-Z Implicit Typing: Variables whose names begin with other than A~H or O-Z Explicit Declaration Explicit Declaration e.g., REAL J, R Double precision floating point number Double precision floating point number e.g., DOUBLE PRECISION A, X

10 April 14, 2004 10 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko FORTRAN Data Types (2) Complex e.g., COMPLEX A, B, C Complex e.g., COMPLEX A, B, C A = (3.5, -7.24) A = (3.5, -7.24) B = (-8.21, 5.67) B = (-8.21, 5.67) C = A + B C = A + B Character Character e.g., CHARACTER C, NAME*20, ADDR*30 CHARACTER*20 STR1, STR2 CHARACTER*20 STR1, STR2 Character constants: e.g., ‘C’, ‘Go ICU’ Character constants: e.g., ‘C’, ‘Go ICU’ Hollerith Strings: e.g., 1HC, 5HGoICU Hollerith Strings: e.g., 1HC, 5HGoICU Logical (Boolean) Logical (Boolean) e.g., LOGICAL X, Y, FLAG Logical constants:.TRUE. or.FALSE. Logical constants:.TRUE. or.FALSE.

11 April 14, 2004 11 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Variable Initializations and Arrays Variable Initializations Variable Initializations e.g., DATA A/1.0/, L/2/, B,C/4.0, 5.0/ DATA ARYX(3)/1.333/, T(1),T(2),T(3)/3*0.0/ DATA ARYX(3)/1.333/, T(1),T(2),T(3)/3*0.0/ DATA C(1)/1HS/, C(2)/1HD/, TAG/3HYes DATA C(1)/1HS/, C(2)/1HD/, TAG/3HYes Arrays Arrays e.g., DIMENSION A(5), B(10,7), N(3,5,20) INTEGER X(7,5) INTEGER X(7,5) REAL MATRIX(-6:4, 7, -5:10), K REAL MATRIX(-6:4, 7, -5:10), K DIMENSION K(20) DIMENSION K(20) J.W. Perry Cole, ANSI FORTRAN IV, wcb

12 April 14, 2004 12 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko FORTRAN Operators Arithmetic Operators: +, -, *, /, ** (exponentiation) Arithmetic Operators: +, -, *, /, ** (exponentiation) Mixed mode expressions – evaluated in integer mode if all operands are integer, evaluated in real mode otherwise Mixed mode expressions – evaluated in integer mode if all operands are integer, evaluated in real mode otherwise e.g., 86.3 * K + R / 16.5 ** J  All are evaluated in real Relational Operators:.LT.,.LE.,.GT.,.GE.,.EQ.,.NE. Relational Operators:.LT.,.LE.,.GT.,.GE.,.EQ.,.NE. e.g., IF (RESULT.LT. 0.0) STOP Logical Operators:.AND.,.OR.,.NOT. Logical Operators:.AND.,.OR.,.NOT. e.g., IF (N.EQ. 1.OR..NOT. R.LT. 0.0) GOTO 75 Multiple Assignment Statements Multiple Assignment Statements e.g., A = I = V = W =.2 * R + X  A truncated value will be assigned to A and I  A truncated value will be assigned to A and I

13 April 14, 2004 13 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko 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

14 April 14, 2004 14 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko 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

15 April 14, 2004 15 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko 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

16 April 14, 2004 16 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko 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

17 April 14, 2004 17 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko 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

18 April 14, 2004 18 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko 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

19 April 14, 2004 19 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko GNU FORTRAN77 Compiler Download G77 from: Download G77 from: http://www.geocities.com/Athens/Olympus/5564/g77.htm G77 Installation and Execution Instructions: G77 Installation and Execution Instructions: http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calcul ators/Fortran_g77/GettingStartedGnuFortran.pdf http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calcul ators/Fortran_g77/GettingStartedGnuFortran.pdf FORTRAN77 Tutorial: FORTRAN77 Tutorial: http://www.stanford.edu/class/me200c/tutorial_77/ FORTRAN77 Language Reference: FORTRAN77 Language Reference: http://www.ictp.trieste.it/~manuals/programming/sun/fortran/f77rm/

20 April 14, 2004 20 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Homework #4 – 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

21 April 14, 2004 21 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Homework #4 – A Weather Data Retrieval Program (2) Write a FORTRAN program that accepts a city name (e.g., TAEJON, SEOUL, PARIS), and prints the lowest and highest temperatures (in Celsius), and sea-level pressure values for the latest week like: Write a FORTRAN program that accepts a city name (e.g., TAEJON, SEOUL, PARIS), and prints the lowest and highest temperatures (in Celsius), and sea-level pressure values for the latest week like: City: TAEJON DateMINMAXSLP 200403289.515.21002.7 2004032912.320.11005.1 …

22 April 14, 2004 22 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Homework #4 – A Weather Data Retrieval Program (3) 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 by Midnight of Wednesday April 28, 2004 Submit the source program electronically by Midnight of Wednesday April 28, 2004 Please do not collaborate with other students! Please do not collaborate with other students!


Download ppt "April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)"

Similar presentations


Ads by Google