MODULE const INTEGER, PARAMETER :: dp = KIND(1.0d0), sp = KIND(1.0e0) REAL(KIND=dp), PARAMETER :: dpi = 3.141592653589793d0 END MODULE const ! PROGRAM prog USE const IMPLICIT NONE ! Program to add 2 integer vectors ! ! NOTE: The sum of 2 vectors is another vector INTEGER, PARAMETER :: NMAX = 50 INTEGER :: n,i INTEGER :: x(NMAX),y(NMAX),z(NMAX) ! n = number of lines in file from line counting program n = 10 ! Read data from file (using input redirection here; you can ! also use an OPEN statement instead). DO i = 1,n READ(*,*) x(i),y(i) ENDDO ! Call subroutine CALL addvecs(n,x,y,z) ! Write out the sum of the vectors DO i = 1,n WRITE(*,*) i,z(i) ENDDO END PROGRAM prog SUBROUTINE addvecs(n,v1,v2,v3) USE const IMPLICIT NONE ! Subroutine to add 2 vectors. ! ! Dummy declarations INTEGER,INTENT(IN) :: n INTEGER,INTENT(IN) :: v1(n),v2(n) INTEGER,INTENT(OUT) :: v3(n) ! Local declarations INTEGER :: i ! Each element of v3 is the sum of the corresponding elements ! of v1 and v2 DO i = 1,n v3(i) = v1(i) + v2(i) ENDDO RETURN END SUBROUTINE addvecs ! ! 1 4 ! 2 4 ! 3 -7 ! 4 -6 ! 5 13 ! 6 1 ! 7 -4 ! 8 1 ! 9 12 ! 10 10