Applying Object-Oriented Concepts
to Traditional Languages
Object-Based Fortran Program
This is an object-based Fortran program for the sample task of reading
two scalars, combining them into a vector, and printing the vector.
C---------------------------------------------
C
C CLASS SCALAR
C Data and operations that model a scalar
C
SUBROUTINE SCALAR_READ (A)
C Read scalar value
READ (5,100) A
100 FORMAT (F7.3)
END
C END CLASS SCALAR
C
C---------------------------------------------
C
C CLASS VECTOR
C Data and operations that model a vector
C
SUBROUTINE VECTOR_CREATE (A,B)
C Create vector
COMMON /VECTOR/ V(2)
V(1) = A
V(2) = B
END
C
SUBROUTINE VECTOR_PRINT
C Write vector
COMMON /VECTOR/ V(2)
WRITE (6,100) V
100 FORMAT (1X,F7.3,'i +',F7.3,'j')
END
C END CLASS VECTOR
C
C---------------------------------------------
C
C CLASS TASK
C Read two scalar components of a vector
C and print vector
C
CALL SCALAR_READ (A)
CALL SCALAR_READ (B)
CALL VECTOR_CREATE (A,B)
CALL VECTOR_PRINT
END
C END CLASS TASK
C
C---------------------------------------------
[home]
[OO]
[Java]
[memorial ships]
[humor]
[income tax repeal]
Copyright (C) 1998 LDJ Trust