program array practice c c John Mahaffy, Penn State University, CmpSc 201 Example c 1/26/96 c * We will try to utilize MAX, MIN, Implied Do-Loops, Data statements, * and FORTRAN 90 constructs fortest preparation IMPLICIT NONE INTEGER I,J,K REAL, DIMENSION(10) :: A,B,C=(/(I,I=1,10)/),GSUM,GM,GX c Associating a dimension with gmult treats it as an array containing c numbers, not a function that must be evaluated. INTERFACE GMULT FUNCTION GMULT (A,B) REAL A(:),B(:) REAL GMULT(SIZE(A)) END FUNCTION GMULT END INTERFACE EXTERNAL GMULT DATA A/3*2.5,4*2.,7.,9.,11./ DATA B/4*3.,2*5.,2.,9.,1.4,3./ OPEN (12,FILE='ARRAY.DATA') DO 100 J=1,10 WRITE (12,20) A(J),B(J),C(J) 20 FORMAT ('A= ',f5.2,' B= ',f5.2,' C= ',f5.2) 100 CONTINUE CALL XSUM (A,B,GSUM) GX=GMULT(A,B) DO 110 K=1,10 WRITE (12,200) A(K),B(K),GSUM(K),GX(K) 200 FORMAT ('A= ',f5.2,' B=',f5.2,' GSUM=',f5.2,' GX=',f5.2) 110 CONTINUE STOP END SUBROUTINE XSUM (E,F,GSUM) IMPLICIT NONE REAL, DIMENSION (10) :: E,F,GSUM,G G(1:10) = E(1:10) + F(1:10) c SUM returns a single number. No need to load it into an array. c the array just gets the same number in all elements. GSUM=SUM(G(1:10)) RETURN END FUNCTION GMULT(E,F) IMPLICIT NONE INTEGER I REAL E(:),F(:) REAL GMULT(SIZE(E)) DO 120 I=1,10 GMULT(I)=E(I)*F(I) 120 CONTINUE END