* Final Version

	Program MRERAY

* This program reconfigures the data produced by Yoshiaki Hisada's
* BEM output into a file of REAL response and IMAG response.

	IMPLICIT REAL*8(A-H,O-Z)
	PARAMETER (ND1=100)
	COMPLEX*16 SP(ND1),CC(ND1)
	CHARACTER*20 INFILE,OUTFILE

c    Prompt for input/output files

	WRITE(5,*)
	WRITE(5,*) 'PROGRAM RECONFIGURE -- To create a BEM file of a sin
     +gle element containing'
	WRITE(5,*) '                       Real, Imag data'
	WRITE(5,*) '****************************************************
     +**********************'
	WRITE(5,*) 'Enter name of BEM file: '
	READ(5,1000) INFILE
	OPEN(10,FILE=INFILE,STATUS='OLD',FORM='FORMATTED')
	WRITE(5,*) 'Enter name for reconfigured output file: '
	READ(5,1000) OUTFILE
	OPEN(11,FILE=OUTFILE,STATUS='NEW',FORM='FORMATTED')
1000	FORMAT(A20)

c    Read header information from the input file

	READ(10,1100) FT,NOM,DT,NT,NFLT
1100	FORMAT(1X,F15.7,I15,F15.7,2I15)
	READ(10,1300)
	READ(10,1300)
	READ(10,1300)
	READ(10,1300)
1300	FORMAT()

        WRITE(5,*)'ENTER ELEM OF OUTPUT ELEM :'
        READ(5,*)NELEM

        DO 100 I=1,NELEM
          IF(I.EQ.NELEM)THEN
            DO 110 J=1,NOM,5
              READ(10,1400) (SP(J+K),K=0,4)
              WRITE(*,1400) (SP(J+K),K=0,4)
110         CONTINUE   
          ELSE
            DO 120 J=1,NOM,5
              READ(10,1400) (CC(J+K),K=0,4)
120         CONTINUE   
          END IF
100     CONTINUE   
1400    FORMAT(1X,10F8.5)

c
c Output to data file
c
        DO 200 I=1,NOM
        WRITE(11,1500)SP(I)
200     CONTINUE
1500	FORMAT(1X,F8.5,1X,F8.5)

c    Write out some information about output file to terminal

	WRITE(5,*) 
	WRITE(5,*) 'OUTPUT INFORMATION'
        WRITE(5,1700)
	WRITE(5,1600) OUTFILE,NCOMP,NF,NREGION,NELEM
1600    FORMAT(1X,'Output file: ',A20,/1X,'Component (0=SH,1=U,2=W): ',
     + I1,/1X,'Fault #: ',I1,/1X,'Region #: ',I1,/1X,'Element #: ',I5)
        WRITE(5,1700) 
1700	FORMAT(1X,'***************************************************')
	close(10)
	close(11)
	end
