Fortran 77 Tutorial: Hsiu-Pin Chen January 4, 2007
Fortran 77 Tutorial: Hsiu-Pin Chen January 4, 2007
Fortran 77 Tutorial: Hsiu-Pin Chen January 4, 2007
Hsiu-Pin Chen
January 4th, 2007
Concepts
computers
•Col. 7 - 72 : codes.
•Col. 1 : comment symbol
•Col. 6 : continuation
Case Insensitivity
Program test
Declarations of variable
Input statements
Calculations
Output statements
End
Operators & intrinsic functions
•Mathematical operators: +, -, *, /, ( ), **
•Logical operators:
.GT., .GE., .EQ., .NE., .LT., .LE., .AND.,
.OR., .NOT. (Results would be logical values:
.TRUE. or .FALSE.)
•Intrinsic functions:
abs, min, max, sqrt, sin, cos, tan, atan, exp,
log, mod(modulus, usage: mod(a, b))
Pay attention to the priority level of these operators
Arrays
real a,b(5,6),c(12)
•Data_type_name variable_name
variable_name = value
Type
Example
Integer 10
Real 10.1
do i = 1, 100
if (mod(i, 10) .NE. 0) then
current_square = i * i
sum = sum + current_square
endif
enddo
Subprograms
1) subroutine increment(ans, i)
integer i, ans
ans = ans + i*i
end
program test
integer sum, i
sum = 0
do i = 1, 100
call increment(sum, i)
enddo
print *, sum
end
Subprograms
end
program test
integer sum, i
sum = 0
do i = 1, 1000
sum = sum + increment(i)
enddo
print *, sum
end
Methods to pass data between
subprograms
subprograms
subroutine increment(i)
integer i, sum
end
I/O format
,STATUS=‘UNKNOWN’)
open (16, FILE=’output’, FORM=’FORMATTED’
,STATUS=‘UNKNOWN’)
close (15)
close (16)