C
C *** READ OF ONE CHANNNEL WAVE DATA FROM DISK FILE ***
C
      SUBROUTINE WVREAD(TITL,WV,NWV,MWV,DT)
C
C *** TITL : TITLE OF EACH CHANNEL WAVE
C *** WV   : WAVE AMPLITUDE DATA
C *** NWV  : WAVE DATA NUMBER
C *** MWV  : NWV IN MAIN PROGRAM DIMENSION
C          : IF MWV > 2**13(=8192), MWV CAN NOT USE !!!
C *** DT   : DELTA TIME ( SEC ) 
C
      CHARACTER FNAME*30, TITL*50
      DIMENSION WV(MWV)
      INTEGER*2 IWV(128)
C
C *** INPUT OF WAVE DATA NAME AND CHANNEL NUMBER ***
C
      WRITE(*,*)
      WRITE(*,1000)
   10 WRITE(*,1010)
      READ(*,'(A)') FNAME
      IF (FNAME(1:1).EQ.' ') GO TO 10
   12 WRITE(*,1020)
      READ(*,*)ICH
 1000 FORMAT(' FROM SUBROUTIME WVREAD')
 1010 FORMAT(/' Enter Wave File Name :',\)
 1020 FORMAT(/' Enter Output Channel :',\)
C
C *** INPUT OF WAVE DATA FROM FILE DATA ***
C
      OPEN (5,FILE=FNAME,FORM='UNFORMATTED',STATUS='OLD',
     &      ACCESS='DIRECT',RECL=256)
C
C   * READ OF CHANNEL-POINTER ( RECORD INFORMATION ) *
C
      READ(5,REC=1) IWV
C
C   * READ OF TITL *
C
      LREC = IWV(ICH)
      READ(5,REC=LREC,ERR=20) TITL
      WRITE(*,*)TITL
      WRITE(*,1100)
      READ(*,*)NYES
      IF(NYES.NE.0)THEN
        CLOSE(5)
        GOTO 12
      END IF
 1100 FORMAT(/' Is this ch. ok ? ( Enter yes = 0 ) :',\)
C
C   * READ OF DATA NUMBER, DELTA TIME AND AMPLITUDE FACTER *
C
      LREC = LREC+1
      READ(5,REC=LREC) IWV
      NWV=IWV(1)
      NDT=IWV(3)
      NAF=IWV(5)
      DT  = 1.0/FLOAT(NDT)
      AFAC= 2.0**NAF
C
C   * DATA ECHO END ENTER OF DELTA TIME SKIP *
C
      NWVO=NWV
      DTO=DT
      NSKIP=1
   13 WRITE(*,1200)NWV,DT
C
      WRITE(*,1210)
      READ(*,*)ISYS
      IF(ISYS.EQ.0)THEN
        WRITE(*,1220)
        READ(*,*)NSKIP
        NSKIP=NSKIP+1
        NWV=NWVO/NSKIP
        DT=DTO*FLOAT(NSKIP)
        GOTO 13
      END IF
 1200 FORMAT(/' TOTAL WAVE DATA NUM. =',I7,' ,DELTA TIME (SEC) =',F5.3)
 1210 FORMAT(' SKIP OF DELTA TIME ? ( YES = 0 ) : ',\)
 1220 FORMAT(' ENTER SKIP NUMBER : ',\)
C
C   * INPUT OF WAVE DURATION *
C
      DUR=FLOAT(NWV-1)*DT
      WRITE(*,1300)DUR
      WRITE(*,1310)
      READ(*,*)IYES
      IF(IYES.EQ.0)GOTO 16
   14 WRITE(*,1320)
      READ(*,*)DUR
      NWV=INT(DUR/DT)+1
      WRITE(*,1330)NWV
 1300 FORMAT(/' TOTAL DURATION (SEC) =',F10.5)
 1310 FORMAT(' TOTAL WAVE OUTPUT ? ( YES = 0 ) :',\)
 1320 FORMAT(' ENTER OUTPUT DURAION (SEC) :',\)
 1330 FORMAT(' NEW WAVE DATA NUM. =',I7)
C
C   * MWV CHECK ( PART 2 ) *
C
   16 IF(NWV.GE.32800)THEN
      WRITE(*,*)' NWV > 32800(MWV) !!!!, ENTER SHORTER DURATION !!!'
      GO TO 14
      END IF
C
C   * READ OF WAVE DATA WITHOUT SKIP *
C
      NN = 128
      NWVR=NWV*NSKIP
      NREC = NWVR/NN
      NRES = MOD(NWVR,NN)
      LREC = LREC+1
      DO 110 J = 1,NREC
        READ(5,REC=LREC) IWV
        LREC = LREC+1
        IS = NN*(J-1)
        DO 100 I = 1,NN
          IW=IWV(I)
          WV(IS+I) = FLOAT(IW)*AFAC
  100   CONTINUE
  110 CONTINUE
C
      IF (NRES.GE.1) THEN
        READ(5,REC=LREC) IWV
        LREC = LREC+1
        DO 200 I = 1,NRES
          IW=IWV(I)
          WV(NWVR-NRES+I) = FLOAT(IW)*AFAC
  200   CONTINUE
      END IF
C
      CLOSE(5)
C
C *** ARRENGE OF SKIP WAVE DATA ***
C
      ICT=1
      DO 300 I=1,NWVR,NSKIP
      WV1=WV(I)
      WV(ICT)=WV1
      ICT=ICT+1
  300 CONTINUE
C
      WRITE(*,*)
C
      RETURN
C
C *** ERROR ***
C
   20 WRITE(*,*) 'Channel access error.'
      STOP
C
      END

