array3.f
PROGRAM ARRAY3
c
c What if I don't know how much array space I will need when I first
c write my Fortran Program
c
c John Mahaffy 2/2/95
c
IMPLICIT NONE
INTEGER I,J,IERR,N,NDAT
c
c Declare A, B, and C to be arrays to be ALLOCATABLE
c
REAL, ALLOCATABLE :: A(:),B(:),C(:)
REAL CSUM,CMAX,CMIN,AVERAGE
c
c Decide on space needed for the arrays
c
NDAT=10
c
c Tell the computer to grab space for your arrays. You should have the
c "STAT=" portion of this statement to provide an error indicator. If
c you skip the optional STAT argument the code will terminate immediately
c on any allocation problem.
c
ALLOCATE (A(1:NDAT),B(NDAT),C(NDAT),STAT=IERR)
PRINT *, 'ERROR FLAG =', IERR
c
c Set values of A and B
c
A(1:NDAT) = (/( I, I=1,NDAT)/)
B(1:NDAT) = (/(I/3, I=1,NDAT)/)
c
c Process as before
c
C(1:NDAT)=A(1:NDAT)+B(1:NDAT)
CSUM=SUM(C(1:NDAT))
CMIN=MINVAL(C(1:NDAT))
CMAX=MAXVAL(C(1:NDAT))
C
AVERAGE=CSUM/NDAT
c
c Note modification of this write from array1.f and array2.f
c
WRITE(*,'(//,'' RESULTS FOR ELEMENTS 1 THROUGH '',I3,'' OF C'')')
& NDAT
WRITE(6,2002)AVERAGE,CMIN,CMAX
2002 FORMAT(' AVERAGE OF SELECTED ELEMENTS IN C = ', F8.3,/,
& ' MINIMUM OF SELECTED ELEMENTS IN C = ', F8.3,/,
& ' MAXIMUM OF SELECTED ELEMENTS IN C = ', F8.3)
WRITE(6,2003) C(1:NDAT)
2003 FORMAT(' C = ',/,(1P,8E10.2))
c
STOP
END