      PROGRAM EXACT
C=======================================================================
C           2-DIM FEM PROGRAM FOR SOLVING EIGENVALUE PROBLEM IN
C                                        HELMHOLZ EQUATION
C                        EXACT EIGEN VALUES
C=======================================================================
      IMPLICIT REAL*8 ( A-H , O-Z )
      PARAMETER ( MXX=50,MXY=50,MXN=(MXX+1)*(MXY+1) )
      DIMENSION MODEX(MXN), MODEY(MXN), EIGENV(MXN)
      CHARACTER INPFILE*12, OUTFILE*12, EXFILE*3
      LOGICAL YES
      WRITE (*,*)' EXACTEIGN.FOR SOLVER'
C=======================================================================
      OUTFILE ='EXACTEI.GEN'
      EXFILE ='NEW'
      IW = 1
      INQUIRE ( FILE=OUTFILE, EXIST=YES )
      IF ( YES ) EXFILE='OLD'
      OPEN ( IW, FILE=OUTFILE, STATUS=EXFILE,FORM='FORMATTED' )
C=======================================================================
      RX = 2.3
      RY = 1.2
      MX = 40
      MY = 20
C=======================================================================
      PI = 4.D0*DATAN(1.D0)
      PI2 = PI*PI
      N = 0
      DO I = 0 , MX
      DO J = 0 , MY
      N = N + 1
      MODEX(N) = I
      MODEY(N) = J
      EIGENV(N) = PI2*( (I/RX)**2 + (J/RY)**2)
      WRITE(*,*) MODEX(N), MODEY(N), EIGENV(N)
      END DO
      END DO
      CALL SORTING ( MXN,N,MODEX,MODEY,EIGENV)
      WRITE(IW,*) 'SEQUENCE MODE-X MODE-Y EIGEN-VALUE'
      DO I = 1 , N
      WRITE(IW,*) I, MODEX(I), MODEY(I), EIGENV(I)
      END DO
C=======================================================================
      CLOSE (IW)
      STOP
      END
C
C
      SUBROUTINE SORTING ( MXN,N,MODEX,MODEY,EIGENV)
      IMPLICIT REAL*8 ( A-H , O-Z )
      DIMENSION MODEX(MXN), MODEY(MXN), EIGENV(MXN)
      ICHECK = 1
      DO WHILE ( ICHECK .NE. 0 )
      ICHECK = 0
      DO I = 2, N
      J = I-1
      IF ( EIGENV(I) .LT. EIGENV(J) ) THEN
      ICHECK = ICHECK + 1
      MX = MODEX(I)
      MY = MODEY(I)
      EI = EIGENV(I)
      MODEX(I) = MODEX(J)
      MODEY(I) = MODEY(J)
      EIGENV(I) = EIGENV(J)
      MODEX(J) = MX
      MODEY(J) = MY
      EIGENV(J) = EI
      END IF
      END DO
      END DO
      RETURN
      END






