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 compute various norms of a vector ! INTEGER,PARAMETER :: NMAX = 6000 INTEGER :: i,n REAL(kind=dp) :: total REAL(kind=dp) :: x(NMAX) ! Value of n obtained from the short line counting program n = 5432 ! Read data from file (NOTE: This only needs to be done ! once since we are not changing any of the x values.) DO i = 1,n READ(*,*) x(i) ENDDO ! Get 1 norm total = 0 DO i = 1,n total = total + ABS(x(i)) ENDDO WRITE(*,*) '1 norm = ',total ! Compute the 1 norm using a subroutine instead CALL norm1(n,x,total) WRITE(*,*) '1 norm with subroutine = ',total ! Get 2 norm (Don't need ABS on x because x is a real ! number). total = 0 DO i = 1,n total = total + x(i)**2 ENDDO WRITE(*,*) '2 norm = ',SQRT(total) ! Get infinity norm total = ABS(x(1)) DO i = 2,n IF(ABS(x(i)) > total) THEN total = ABS(x(i)) ENDIF ENDDO WRITE(*,*) 'infinity norm = ',total END PROGRAM prog