Lecture 4 - September 6, 2007
Topics discussed
Programs discussed in detail and modified in class
Things to remember when writing FORTRAN code
don't embed function calls in a output statement
functions ALWAYS return a value (always exactly 1 value)
when you pass an array into a subprogram, you need to dimension it in the subprogram
the actual parameters you use in a function or subroutine call should be variables not literals
variable names used as formal parameters should match the data type they expect to hold
CHARACTER S(5) declares a five element array
CHARACTER S*5 declares a five character string
<ctrl>z is the end of file character in command mode on a PC
List of some built-in functions in FORTRAN
1) MOD (numerator, denominator) – returns the remainder when numerator is divided by denominator takes real or integer arguments
2) ACHAR(num1) - gives the numth character in the ASCII collating sequence
3) ABS (number) – the number can be REAL or INTEGER, returns the absolute value of the number
4) MAX (num1, num2) – finds the maximum value in a ______
5) IFIX (REALnumber) – returns a
6) SQRT (integer) – finds the square root – returns a ____
7) LOG (anyTypeNumber) – returns the natural log of x
8)
9) COS (realNumber) – returns the cosine as a realNumber – the parameter is in radians
10) SIN (realNumber) – returns the sine as a realNumber – the parameter is in radians
11) TAN (realNumber) – returns the tangent as a realNumber – the parameter is in radians
12)
13) FLOOR (realNumber) – returns as integer which is the truncated real
14) MIN(listOfNumbers) – fins the minimum value in a list of homogeneous type numbers
15) ATAN (realNumber) – returns the inverse of tangent -- returns value in radians
16) CEILING(realNumber) – returns an integer
17)
SRAND(integerNumber) – sets the seed for the
18) EXP (realNumber) – returns e to the real number power
19) ASIN (realNumber) – returns the inverse of sine -- returns value in radians
20) LEN (string) - length of string
CANDY BAR Questions
If there is a way using Force to have your subroutine or function in a file separate from the main program, what is it? (submit your answer to the Blackboard drop box before next class).