April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages Programming Languages (ICE 1341) (ICE 1341) Lecture #13 Lecture #13 April 14, 2004 In-Young Ko iko .AT. i cu . ac.kr Information and Communications University (ICU)
22
Embed
April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
April 14, 2004 1 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
April 14, 2004 2 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
AnnouncementsAnnouncements
The The solution of the midterm examsolution of the midterm exam is is now available on the class homepagenow available on the class homepage
April 14, 2004 3 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
FORTRAN FORTRAN ((ForFormula mula TranTranslating System)slating System)
Designed to efficiently translate mathematical Designed to efficiently translate mathematical formulas into formulas into IBM 704IBM 704 machine code machine code
IBM 704IBM 704 (1954) (1954)““The first mass-produced The first mass-produced
computer with computer with core core memorymemory and and floating-floating-
point arithmeticpoint arithmetic”” Photo: Lawrence Livermore National Laboratory
April 14, 2004 4 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
FORTRAN Coding FormatFORTRAN Coding Format
FORTRAN programs FORTRAN programs were written in a were written in a coding form with a coding form with a strict formatting rulestrict formatting rule
April 14, 2004 6 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
Early FORTRAN VersionsEarly FORTRAN Versions
FORTRAN I (1957)FORTRAN I (1957) NamesNames could have up to could have up to six characterssix characters (IBM 704 has (IBM 704 has
a 6-bit BCD character set and 36-bit word)a 6-bit BCD character set and 36-bit word) Post-test counting loopPost-test counting loop ( (DODO), ), Formatted I/OFormatted I/O, , User-User-
No data typing statements (No data typing statements (Implicit Type DeclarationImplicit Type Declaration –– Variables whose names begin with I, J, K, L, M, Variables whose names begin with I, J, K, L, M, and N are integer types, all others are floating point)and N are integer types, all others are floating point)
FORTRAN II (1958)FORTRAN II (1958) IndependIndependeent compilationnt compilation of subroutines of subroutines
* AW Lecture Notes
April 14, 2004 7 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
Later FORTRAN VersionsLater FORTRAN Versions
FORTRAN IV (1960-62) FORTRAN IV (1960-62) –– ANSI standard in 1966 ANSI standard in 1966 Explicit type declarationsExplicit type declarations Logical selection statementLogical selection statement Subprogram names could be parametersSubprogram names could be parameters
FORTRAN 77 (1978)FORTRAN 77 (1978) Character stringCharacter string handling handling Logical loop control statementLogical loop control statement IF-THEN-ELSEIF-THEN-ELSE statement statement
April 14, 2004 9 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
FORTRAN Data Types (1)FORTRAN Data Types (1)
IntegerInteger Implicit TypingImplicit Typing: Variables whose names begin with I~N: Variables whose names begin with I~N Explicit DeclarationExplicit Declaration
e.g., e.g., INTEGER A, TOTALINTEGER A, TOTAL Real Real –– Single precision floating point number Single precision floating point number
Implicit TypingImplicit Typing: Variables whose names begin with : Variables whose names begin with other than A~H or O-Zother than A~H or O-Z
Explicit DeclarationExplicit Declaration
e.g., e.g., REAL J, RREAL J, R Double precisionDouble precision floating point number floating point number
ee.g., .g., DOUBLE PRECISION A, XDOUBLE PRECISION A, X
April 14, 2004 10 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
FORTRAN Data Types (2)FORTRAN Data Types (2)
Complex Complex e.g., e.g., COMPLEX A, B, CCOMPLEX 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 + BC = A + B
REAL MATRIX(-6:4, 7, -5:10), KREAL MATRIX(-6:4, 7, -5:10), K
DIMENSION K(20)DIMENSION K(20)J.W. Perry Cole, ANSI FORTRAN IV, wcb
April 14, 2004 12 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
FORTRAN OperatorsFORTRAN Operators
Arithmetic Operators: Arithmetic Operators: ++, , --, , **, , //, , **** (exponentiation) (exponentiation) Mixed mode expressions – evaluated in integer mode Mixed mode expressions – evaluated in integer mode if all if all
operands are integeroperands are integer, evaluated in real mode otherwise, evaluated in real mode otherwisee.g., e.g., 86.3 * K + R / 16.5 ** J86.3 * K + R / 16.5 ** J All are evaluated in All are evaluated in
Multiple Assignment StatementsMultiple Assignment Statementse.g., e.g., A = I = V = W = .2 * R + XA = I = V = W = .2 * R + X A truncated value will be assigned to A and IA truncated value will be assigned to A and I
April 14, 2004 13 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
G77 Installation and Execution Instructions:G77 Installation and Execution Instructions:http://www.engineering.usu.edu/cee/faculty/gurro/http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Fortran_g77/GettingStartedGnuFortran.pdfSoftware_Calculators/Fortran_g77/GettingStartedGnuFortran.pdf
FORTRAN77 Language Reference:FORTRAN77 Language Reference:http://www.ictp.trieste.it/~manuals/programming/sun/fortran/f77rm/http://www.ictp.trieste.it/~manuals/programming/sun/fortran/f77rm/
April 14, 2004 20 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
Homework #4 Homework #4 –– A Weather Data A Weather Data Retrieval Program (1)Retrieval Program (1)
Install Install G77G77 on your computer and practice how on your computer and practice how to compile and run FORTRAN programsto compile and run FORTRAN programs
Download a Download a weather data fileweather data file that contains the that contains the latest week’s weather information from: latest week’s weather information from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/data.txtftp://ftp.ncdc.noaa.gov/pub/data/globalsod/data.txt
Download the Download the weather station listweather station list from: from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/stnlist-sorted.txtftp://ftp.ncdc.noaa.gov/pub/data/globalsod/stnlist-sorted.txt
Check the Check the weather data file formatweather data file format from: from: ftp://ftp.ncdc.noaa.gov/pub/data/globalsod/README.TXTftp://ftp.ncdc.noaa.gov/pub/data/globalsod/README.TXT
April 14, 2004 21 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
Homework #4 Homework #4 –– A Weather Data A Weather Data Retrieval Program (2)Retrieval Program (2)
Write a FORTRAN program that Write a FORTRAN program that accepts a city accepts a city namename (e.g., TAEJON, SEOUL, PARIS), and (e.g., TAEJON, SEOUL, PARIS), and prints the lowest and highest temperatures (in prints the lowest and highest temperatures (in Celsius), and sea-level pressure valuesCelsius), and sea-level pressure values for the for the latest week like:latest week like:
City: TAEJONCity: TAEJON
DateDate MINMIN MAXMAX SLPSLP
2004032820040328 9.59.5 15.215.2 1002.71002.7
2004032920040329 12.312.3 20.120.1 1005.11005.1
……
April 14, 2004 22 ICE 1341 – Programming Languages (Lecture #13) In-Young Ko
Homework #4 Homework #4 –– A Weather Data A Weather Data Retrieval Program (3)Retrieval Program (3)
To retrieve weather information for a city, use To retrieve weather information for a city, use the the weather station numberweather station number that is firstly that is firstly matched against the city name in the station listmatched against the city name in the station list
Use INDEX function to match a city name from Use INDEX function to match a city name from the station listthe station list
IF (IF (INDEXINDEX(NAME, ‘ICU’) .GT. 0)(NAME, ‘ICU’) .GT. 0)
PRINT *, ‘Matched!’PRINT *, ‘Matched!’ Submit the source program Submit the source program electronicallyelectronically by by
Midnight of Wednesday April 28, 2004Midnight of Wednesday April 28, 2004 Please do not collaborate with other students!Please do not collaborate with other students!