       program eriinput
c
c      fname? : Input compressed data
c
       character*80  fname1, fname2, inp, cdate
       character*7  dname1
       character*4   code
c
       integer nmon(13)/0,31,59,90,120,151,181,212,243,273,304,334,365/ 
       integer lmon(13)/0,31,60,91,121,152,182,213,244,274,304,335,366/ 
       integer jmon(13), oneday
c
        jfiles = 1
        write(0,*) ' Enter Station name '
        read(5,*) code
 1      write(0,*) ' Enter Start date & time '
        write(0,*) ' Enter yy, mm, dd, hh, mm, ss '
c-------
        read(5,*) iyr1, imon1, iday1, ihour1, imin1, isec1
c-------
        oneday = 60*60*24
        maxdur = 60*60*2
        fname1 = ' '
        fname2 = ' '
c    **************
        call chk(iyr1,imon1,iday1,ihour1,imin1,isec1,ill)
c    **************
        if(ill.ne.0) goto 1
c
        do 30 i = 1, 13
           jmon(i) = nmon(i)
 30        if(mod(iyr1,4).eq.0) jmon(i) = lmon(i)
c
        idate1 = iday1+100*imon1+10000*iyr1
        is1  = isec1 + imin1*60 + ihour1* 3600
c
        write(0,'(5X,A,6I4)') 
     1   ' From:yymmddhhmmss ', iyr1, imon1, iday1, ihour1, imin1, isec1
c
c 2      write(0,*) ' Enter duration time (sec) '
  2      write(0,*) ' Enter End date & time '
         write(0,*) ' Enter yy, mm, dd, hh, mm, ss '
c-------
c        read(5,*) idur
c        call addt(iyr1,imon1,iday1,ihour1,imin1,isec1,idur,
c     1            iyr2,imon2,iday2,ihour2,imin2,isec2)
        read(5,*) iyr2, imon2, iday2, ihour2, imin2, isec2
c-------
        call chk(iyr2,imon2,iday2,ihour2,imin2,isec2,ill)
c-------
        if(ill.ne.0) goto 2
c
        write(0,'(5X,A,6I3)') 
     1   ' End :yymmddhhmmss', iyr2, imon2, iday2, ihour2, imin2, isec2
        idate2 = iday2+100*imon2+10000*iyr2
        is2  = isec2 + imin2*60 + ihour2 * 3600
c
        if(idate2.lt.idate1.or.idate2.ge.idate1+2.or.
     1    (idate1.eq.idate2.and.is2.gt.is1+2*60*60).or.
     2    (idate1.eq.idate2-1.and.is2.gt.is1+maxdur-oneday) ) then
           write(0,*) '  range over '
           write(0,*) '  duration must be shorter than 2 hours '
           write(0,*) '      default 60 min '
           isec2  = isec1
           imin2  = imin1 
           ihour2 = ihour1 + 1
           iday2  = iday1
           imon2  = imon1
           iyr2   = iyr1
c
c          if(imin2.ge.60) then
c            imin2 = imin2 - 60
c            ihour2 = ihour2 + 1
c
             if(ihour2.ge.24) then
                ihour2 = ihour2 - 24
                iday2  = iday2 + 1
                jdate  = iday2 + jmon(imon2)
c
                do 20 i = 2, 13
c
                   if(jdate.le.jmon(i)) then
                      iday2 = jdate - jmon(i-1)
                      imon2  = i - 1 
                      goto 22
                   endif
  20            continue
                   imon2 = 1
                   iday2 = 1
                   iyr2  = iyr2 + 1
c
  22            continue
                idate2 = iday2+100*imon2+10000*iyr2
                is2  = isec2 + imin2*60 + ihour2 * 3600
                 write(0,'(5X,A,6I3)') 
     1             ' End :yymmddhhmmss',
     2             iyr2, imon2, iday2, ihour2, imin2, isec2
             endif 
c
           endif 
c
c       endif   
c
c       write(0,*) ' Enter file name '
c-------
        if (code(1:3) .eq. 'TSK') then
           dname1 = './TSK.F'
        else if (code(1:3) .eq. 'SHK') then
           dname1 = './SHK.F'
        else if (code(1:3) .eq. 'OGS') then
           dname1 = './OGS.F'
        else if (code(1:3) .eq. 'OKI') then
           dname1 = './OKI.F'
        else if (code(1:3) .eq. 'HCH') then
           dname1 = './HCH.F'
        else if (code(1:3) .eq. 'KKJ') then
           dname1 = './KKJ.F'
        else if (code(1:3) .eq. 'SYO') then
           dname1 = './SYO.F'
        else 
           write(0,*) 'Input station name error : ',code
        end if
c
        write(cdate,'(3I2.2)') iyr1, imon1, iday1
        fname1 = dname1//cdate
c-------
        if(idate2.ne.idate1) then
           jfiles = 2
c          write(0,*) ' Enter one more file name '
c-------
c          read(5,'(A)') fname2
           write(cdate,'(3I2.2)') iyr2, imon2, iday2
           fname2 = dname1//cdate
c-------
        endif 
c
        write(0,'(1X,A,6I3)') ' Start yymmddhhmmss:',
     +          iyr1, imon1, iday1, ihour1, imin1, isec1
        write(0,'(1X,A,6I3)') '  End  yymmddhhmmss:',
     +          iyr2, imon2, iday2, ihour2, imin2, isec2
        write(0,'(1X,A,A,A)') '   file name : ', fname1, fname2
        write(0,'(1X,A)')   ' OK ? (y/n) '      
        read(5,*) inp
        if(inp.eq.'n'.or.inp.eq.'N') goto 1
        write(0,'(A)') '  ....... wait ...... '
c
        write(6,*) code
        write(6,*) iyr1, imon1, iday1, ihour1, imin1, isec1
        write(6,*) iyr2, imon2, iday2, ihour2, imin2, isec2
        write(6,*) jfiles
        write(6,*) fname1
        write(6,*) fname2
c
        stop
        end
c*******************************
        subroutine chk(iyr,imon,iday,ihour,imin,isec,ill)
c*******************************
        ill = 0
        if(iyr.le.80.or.iyr.ge.99) then
             write(0,*) ' Input Error '
             write(0,*) '    year - 1900 ( 2 digits )'
             write(0,'(3X,A,I5)') ' year = ', iyear    
             ill = 999
         endif 
        if(imon.le.0.or.imon.ge.13) then
             write(0,*) ' Input Error '
             write(0,'(3X,A,I5)') ' month = ', imon    
             ill = 999
         endif 
         if(ihour.lt.0.or.ihour.ge.24) then
             write(0,*) ' Input Error '
             write(0,'(3X,A,I5)') ' hour = ', ihour   
             ill = 999
         endif 
         if(imin.lt.0.or.imin.ge.60) then
             write(0,*) ' Input Error '
             write(0,'(3X,A,I5)') ' min = ', imin
             ill = 999
         endif 
         if(isec.lt.0.or.isec.ge.60) then
             write(0,*) ' Input Error '
             write(0,'(3X,A,I5)') ' sec = ', isec
             ill = 999
         endif 
         return
         end
