      SUBROUTINE FNORM (NA,N,M,A,ANORM)
      INTEGER NA,N,M
      DOUBLE PRECISION A(NA,M),ANORM
C
C     ***** PURPOSE:
C     THIS DOUBLE PRECISION SUBROUTINE COMPUTES THE FROBENIUS OR
C     EUCLIDEAN MATRIX NORM OF A REAL N X M MATRIX A, NAMELY
C     A SCALAR 'ANORM' IS RETURNED WHICH IS THE SQUARE ROOT OF
C     THE SUM OF THE SQUARES OF THE ELEMENTS OF A.
C
C     ON ENTRY:
C
C        NA     INTEGER
C               ROW DIMENSION OF THE ARRAY CONTAINING A AS DECLARED
C               IN THE MAIN CALLING PROGRAM.
C
C        N      INTEGER
C               THE ROW DIMENSION OF THE MATRIX A.
C
C        M      INTEGER
C               THE COLUMN DIMENSION OF THE MATRIX A.
C
C        A      DOUBLE PRECISION(NA,M)
C               ARRAY CONTAINING A REAL N X M MATRIX WHOSE FROBENIUS
C               NORM IS DESIRED.  THE CONTENTS OF THE ARRAY ARE LEFT
C               UNCHANGED BY THIS PROGRAM.
C
C     ON RETURN:
C
C        ANORM  DOUBLE PRECISION
C               THE FROBENIUS NORM OF THE MATRIX A.
C
C     PROGRAM WRITTEN BY ALAN J. LAUB, DEP'T. OF ELEC. ENGRG. - SYSTEMS,
C     UNIVERSITY OF SOUTHERN CALIFORNIA, LOS ANGELES, CA 90007,
C     PH.: (213) 743-5535
C     JANUARY 1982.
C
C     INTERNAL VARIABLES
C
      INTEGER I,J
      DOUBLE PRECISION AMAX
C
C     FORTRAN FUNCTIONS CALLED:
C
      DOUBLE PRECISION DABS,DSQRT
C
C     SUBROUTINES AND FUNCTIONS CALLED:  NONE
C
C     ------------------------------------------------------------------
C
C     COMPUTE MAXIMUM MAGNITUDE ELEMENT OF A AS A SCALING FACTOR
C
      ANORM = 0.0D0
      DO 20 J = 1,M
         DO 10 I = 1,N
            AMAX = DABS(A(I,J))
            IF (AMAX .GT. ANORM) ANORM = AMAX
   10    CONTINUE
   20 CONTINUE
      IF (ANORM .EQ. 0.0D0) RETURN
C
C     SCALE ELEMENTS OF A BY SCALING FACTOR AND SUM THE SCALED SQUARES
C
      ANORM = 1.0D0/ANORM
      AMAX = 0.0D0
      DO 40 J = 1,M
         DO 30 I = 1,N
            A(I,J) = ANORM*A(I,J)
            AMAX = AMAX+(A(I,J)**2)
   30    CONTINUE
   40 CONTINUE
C
C     RESCALE ELEMENTS OF A SO THAT THE ORIGINAL A MATRIX IS
C     RETURNED IN THE ARRAY A
C
      ANORM = 1.0D0/ANORM
      DO 60 J = 1,M
         DO 50 I = 1,N
            A(I,J) = ANORM*A(I,J)
   50    CONTINUE
   60 CONTINUE
C
C     COMPUTE SQUARE ROOT OF SCALED SUM OF SQUARES THEN MULTIPLY
C     BACK THE SCALING FACTOR
C
      ANORM = ANORM*DSQRT(AMAX)
      RETURN
      END
