Computers in Engineering WWW Site - Example 7.1

# Example 7.1

#### FORTRAN Version

!
PROGRAM P71
!
IMPLICIT NONE
CHARACTER (LEN=3) :: SEASON(4,3)
INTEGER :: J,KS,M
!
!
PRINT *, 'This is Program >> P71  - Matrix input/ouput'
!
!     Tell program where data for  READ   is coming from
OPEN(UNIT=5, FILE='P71.DAT')      ! UNIT=5 is the default input
!
!
!     ONE PER CARD
!
L1:   DO KS=1,4
L2:         DO M=1,3
END DO L2
END DO L1
27   FORMAT (A3)
!
!     PRINT MATRIX
!     METHOD 1
!
PRINT 100
PRINT 101, SEASON
101   FORMAT (4('  ',A3))
100   FORMAT(/' MATRIX OUTPUT 1'/)
!
!     METHOD 2
!
PRINT 200
200   FORMAT(/' MATRIX OUTPUT 2'/)
L3:      DO KS=1,4
PRINT 202, (SEASON(KS,J),J=1,3)
END DO L3
202   FORMAT(3('  ',A3))
!
STOP
END PROGRAM P71
DATA:
Jan    672 3.4
Feb    609 3.2
Mar    715 3.7
Apr    803 4.2
May    810 4.8
Jun    831 5.1
Jul    829 5.1
Aug    727 5.1
Sep    780 4.3
Oct    703 3.9
Nov    791 4.2
Dec    783 3.6
OUTPUT:

+--------------------------------------------------+
|     32-bit Power for Lahey Computer Systems      |
|   Phar Lap's 386|DOS-Extender(tm) Version 7.0    |
|  Copyright (C) 1986-94 Phar Lap Software, Inc.   |
|           Available Memory = 14880 Kb            |
+--------------------------------------------------+

This is Program >> P71  - Matrix input/ouput

MATRIX OUTPUT 1

Jan  Apr  Jul  Oct
Feb  May  Aug  Nov
Mar  Jun  Sep  Dec

MATRIX OUTPUT 2

Jan  Feb  Mar
Apr  May  Jun
Jul  Aug  Sep
Oct  Nov  Dec

#### Pascal Version

{\$G256}
{\$P512}
{\$D+}
PROGRAM p71 (input, output);
VAR
season : ARRAY [ 1..4, 1..3 ] OF string[3];
row, column, j : INTEGER;
BEGIN
writeln ( ^l );
{
Read in month code, one per line
}
FOR row := 1 TO 4 DO
FOR column := 1 TO 3 DO
readln ( season [ row, column ] );
{
Print matrix method 1
}
FOR column := 1 TO 3 DO
BEGIN
FOR row := 1 TO 4 DO
write ( season [ row, column ], ' ':2 );
writeln
END; { end for }
{
Print matrix method 2
}
writeln;
FOR row := 1 TO 4 DO
BEGIN
FOR column := 1 TO 3 DO
write ( season [ row, column ], ' ':2 );
writeln
END { end for }
END.
DATA:
jan    672 3.4
feb    609 3.2
mar    715 3.7
apr    803 4.2
may    810 4.8
jun    831 5.1
jul    829 5.1
aug    727 5.1
sep    780 4.3
oct    703 3.9
nov    791 4.2
dec    783 3.6