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)',ERR=10)FNAME
      IF (FNAME(1:1).EQ.' ') GO TO 10
   12 WRITE(*,1020)
      READ(*,*,ERR=10)ICH
 1000 FORMAT(' FROM SUBROUTIME WVRDN :')
 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,ERR=10)
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 ? (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)
      NDTFLG=IWV(8)
      NOD=IWV(10)
      IOD=IWV(12)
      XNOD=FLOAT(NOD)
      IF(NDTFLG.NE.1) THEN
        DT = 1.0/FLOAT(NDT)
        WRITE(*,*) 'NDTFLG=',NDTFLG
      ELSE
        DT=XNOD*(10.0**IOD)
      ENDIF
      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
   14 WRITE(*,1210)
      READ(*,*)ISYS
      IF(ISYS.EQ.0)THEN
        WRITE(*,1220)
        READ(*,*)NSKIP
        NSKIP=NSKIP+1
        NWV=NWVO/NSKIP
        DT=DTO*FLOAT(NSKIP)
        WRITE(*,1200)NWV,DT
        WRITE(*,1230)
        READ(*,*)NSY
        IF(NSY.NE.0)GOTO 14
      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 : ',\)
 1230 FORMAT(/' Is this data OK ? (yes=0) : ',\)
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
      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 duration (sec) :',\)
 1330 FORMAT(' New wave data num. =',I7)
C
C *** DATA NUMBER CHECK ***
C
   16 IF(NWV.GT.MWV)THEN
        WRITE(*,*)
        WRITE(*,*)' NWV > MWV, thus you need data skip !!!'
        WRITE(*,*)' NWV, MWV =',NWV,MWV
        WRITE(*,*)
        GOTO 13
      END IF
C
C   * READ OF WAVE DATA *
C
      NN = 128
      NREC = NWVO/NN+1
      LREC = LREC+1
      NC=0
      DO 110 J = 1,NREC
        READ(5,REC=LREC) IWV
        NUM0= NN*(J-1)
        NUM1= NUM0+NSKIP-1
        DO 100 I = 1,NN
          IF(NUM0+I.GT.NWVO)GOTO 120
          IF(MOD(NUM1+I,NSKIP).NE.0)GOTO 100
          NC=NC+1
          WV(NC) = FLOAT(IWV(I))*AFAC
  100   CONTINUE
        LREC = LREC+1
  110 CONTINUE
C
  120 CLOSE(5)
C
      WRITE(*,1400)
      READ(*,*)NOK
      IF(NOK.NE.0)GOTO 10
      WRITE(*,*)
 1400 FORMAT(/' All data OK ? (yes=0) : ',\)
C
      RETURN
C
C *** ERROR ***
C
   20 WRITE(*,*) 'Channel access error.'
      STOP
C
      END

