      SUBROUTINE READRM10
    
      use winteracter
      USE BLKRM10

      USE RESID
      
      implicit none
      
      INTEGER K,L,IIN,LIMIT,KH,KQ,KE,J,NMAT1,JSAVE,KK,KWT,KF,ICTOT,JGT,KC,JJ,KSN,LO,LHI,IINITWS
      INTEGER ICLON,ITET,ITET2,IYINFO,JFYR,JDAY,JMON,FHR,IFYINFO
      INTEGER NCHARBL
      REAL FCOEF,EDD11
      REAL AA
      CHARACTER(LEN=255)  :: filter
      CHARACTER*8 LABELF(44),LABELC(31),LABELFL(21),LABELCE,LABELFE,ID,LABELCF,LABELCEL,LABELCD,LABELSP,LIMITL(9)
      CHARACTER*72 DLIN
      CHARACTER*72 DLININ
      DATA LIMITL/ 'MAXFRONT','BUFFSIZL','MAXLAY  ','MAXCROSS','MAXCPTS ','MAXQINPT','MAXHINPT','MAXEINPT','BUFFSIZ '/
!      DATA LABELF/'INBNGEO ','INBNRST ','INRM1   ','INELEV  ','INHYD   ','INELTFL ','OUTFIL  ','OUTBNRMA','OUTBNRST','TIMFIL  ','OUTSMS  ','OUTSPL  ','OUTCON  ','INCROS  ','INSRCORD','INSTRESS','INBNSTRS','INWGT   ','INBNWGT ','OUTWGT  ','OUTBNWGT','OUTBNSTR','WEIRDATA','AWINDIN ','BWINDIN ','OUTFLOW ','INHARM  ','OUTBN3GE'/

      DATA LABELF/&
      'INBNGEO ','INRM1   ','INBNRST ','INCROS  ','INHYD   ','INELEV  ','INELTFL ','INBNELF ','INHARM  ','INLAYDAT','METFIL  '&
     ,'OUTFIL  ','OUTBNRMA','OUTBNRST','OUTBN3GE','OUTCON  ','OUTMET  ','TIMFIL  ','BWINDIN ','AWINDIN ','OUTBNXTR'&
     ,'OUTASXTR','OUTBNELF','INSRCORD','INBNWGT ','INBNSTRS','OUTBNWGT','OUTWGT  ','GROUPNUM','STFLFIL ','INASTRAT'&
     ,'BCFIL   ','VOLFIL  ','OUTBNRES','VELBNFIL','IN3DBNGE','OUTBN2GE','INSMSGN ','OUTSMS  '&
     ,'OUTSMS1 ','OUTFLOW ','INBC    ','INBNBC  ','OUTBNICE'/
      
!      DATA LABELC/'STARTIM ','ENDTIM  ','PRTOPT  ','SSITN   ','TRITN   ','MARSHOPT','ELEV    ','OMEGA   ','CONV-VEL','CONV-DEP','MARSH-SH','MARSH-RG','MARSH-PR','MARSH-LM','EDDYTYPE','EDDY-MAT','MANN-MAT','MARSH-FR','TAB-END'/
      DATA LABELC/ 'STARTIM ','ENDTIM  ','PRTOPT  ','SSITN   ','TRITN   ','MARSHOPT','TIMPROJ ','ITERINTV','1DTYP   ','MESSRWND','TRSTEPS ','HALF-TIM','HALF-HOL','GRAVITY ','OVERLAYT','WRTINIT ','EDDYTYPE','DRYSW   ','HIGH-ORD','9-NODE  ','RSTOPT  ','STBIN   ','FRQBIN  ','FRQRST  ','NUMRST  ','SOLVER  ','EDDY-MAT','MANN-MAT','MARSH-FR','WEIR-DAT','TABEND  '/
      DATA LABELFL/'ELEV    ','OMEGA   ','CONV-VEL','CONV-DEP','MARSH-SH','MARSH-RG','MARSH-PR','MARSH-LM','TBFACT  ','TBMIN   ','HALF-TOL','X-SCALE ','Y-SCALE ','V-SCALE ','DSET    ','DSETD   ','UNOM    ','HMIN    ','        ','DPCUTOF1','DPCUTOF2'/
      DATA LABELCE/'ENDGEO  '/,LABELFE/'ENDFIL  '/,LABELCF/'CONT-FLW '/,LABELCEL/'CONT-ELV'/,LABELCD/'CONT-DEP'/,LABELSP/'SPR-NOD '/
      filter="r10 file *.r10|*.R10|"
      IIN=5
      KH=0
      KQ=0
      KE=0
      KF=0
      KSN=0
      NCFLOWS=0
      NCELEV=0
      NCDEP=0
      NSPRTN=0
      KWT=0
      ICTOTC=0
      NMARSTYP=0
      NHOLDC=0
      HLIN1=-9999.
      DO K=1,1000
        ITYP(K)=0
        ORT(K,1)=-0.0
        ORT(K,5)=0.00
        ORT(K,7)=0.
      ENDDO
      IQLIN=0
      QLIN=0.
      QDLIN=0.
      IHLIN=0
      HLIN=0.
      IELIN=0
      NQLIN=0
      NHLIN=0
      IETP=0
      JET=0
      L3DCNT=0
      IINITWS=0      
      NSND=0
      CALL WSelectFile(FILTER,PromptOn+DirChange,NAMEFL,'Load RMA-10 File')

	  IF (WInfoDialog(ExitButtonCommon).EQ.CommonOpen) THEN
		  go to 100
	  else
        RETURN
      endif

100   CONTINUE
      OPEN(IIN,FILE=NAMEFL,FORM='FORMATTED')
      KH=0
      KQ=0
      KE=0
      KF=0
      NCFLOWS=0
      NCELEV=0
      NCDEP=0
      NSPRTN=0
      KWT=0
      NMARSTYP=0
      HLIN1=-9999.
      DO K=1,1000
        ITYP(K)=0
        ORT(K,1)=-0.0
        ORT(K,5)=0.00
        ORT(K,7)=0.
      ENDDO
      IQLIN=0
      QLIN=0.
      QDLIN=0.
      IHLIN=0
      HLIN=0.
      IELIN=0
      NQLIN=0
      NHLIN=0
      JT=0
      DO K=1,44
        DO L=1,72
          FNAME(K)(L:L)=' '
        ENDDO
      ENDDO
      DO K=1,1000
        DO J=1,3
          DO L=1,80
            LINSAVE(K,J)(L:L)=' '
          ENDDO
        ENDDO
      ENDDO
      LINSAVC=0
      J=1
      JSAVE=1
      DO  KC=1,5000
        CALL GINPT(IIN,ID,DLININ)
        CALL PARSELIN(DLININ,DLIN,ICLON,NCHARBL)
110     IF(ID .EQ. 'ENDFILE '  .OR.  ID .EQ. 'ENDFIL '  .OR.  ID .EQ. 'ENDLIMIT') THEN
          JSAVE=2
          GO TO 200
        ENDIF
        IF(ID .EQ. 'TABEND  '  .OR.  ID .EQ. 'TAB-END  ') THEN
          IF(IINITWS .EQ. 0) ELEV1=ELEV
          GO TO 200
        ENDIF
        IF(ID .EQ. 'ENDGEO  ') THEN
          JSAVE=3
          GO TO 200
        ENDIF
        IF(ID .EQ. 'ENDSTEP ') THEN
          NQLIN(J)=KQ
          NHLIN(J)=KH
          NELIN(J)=KE
          NFCLIN(J)=KF
          J=J+1
          KH=0
          KQ=0
          KE=0
          KF=0
          KSN=0
          GO TO 200
        ENDIF
        IF(ID .EQ. 'ENDDATA') THEN
          JT=J-1
          IF(NITN .EQ. 0) THEN
            DATEND='                '
          ENDIF
          close(iin)
          RETURN
        ENDIF
        DO L=1,43
          IF(ID .EQ. LABELF(L)) THEN
            FNAME(L)=DLININ
            GO TO 200
          ENDIF
        ENDDO
        DO L=1,9
          IF(ID .EQ. LIMITL(L)) THEN
            READ(DLIN,*) LIMITVAL(L)
            IF(L .EQ. 9) LIMITVAL(2)=LIMITVAL(9)
            GO TO 200
          ENDIF
        ENDDO
        IF(ID(1:2) .EQ. 'TI') THEN
          TITLEHEAD=DLIN
          GO TO 200
        ENDIF
        
      IF(ID(1:7) .EQ. 'STARTIM'  ) THEN
          DO L=1,72
            IF(DLIN(L:L) .NE. ' ') THEN
              LIMIT=L
              GO TO 120
            ENDIF
          ENDDO 
120       READ(DLININ(LIMIT:LIMIT+15),5010) DATEST
5010      FORMAT(A16)            
      ELSEIF(ID(1:6) .EQ. 'ENDTIM'  ) THEN
          DO L=1,72
            IF(DLININ(L:L) .EQ. '&') THEN
              LIMIT=1
              GO TO 130
            ELSEIF(DLININ(L:L) .NE. ' ') THEN
              LIMIT=L
              GO TO 130
            ENDIF
          ENDDO 
130       READ(DLININ(LIMIT:LIMIT+15),5010) DATEND
        
      ELSEIF(ID(1:8) .EQ. 'OVERLAYT') THEN
        IOV=1
      ELSEIF(ID(1:6) .EQ. 'YEAR  '  ) THEN
        READ(DLIN,*) IYRR
        IYINFO=2
      ELSEIF(ID(1:6) .EQ. 'MONTH '  ) THEN
        READ(DLIN,*) ITMM
      ELSEIF(ID(1:6) .EQ. 'DAY   '  ) THEN
        READ(DLIN,*) ITMD
      ELSEIF(ID(1:6) .EQ. 'HOUR  '  ) THEN
        READ(DLIN,*) TET
      ELSEIF(ID(1:8) .EQ. 'VERTTURB') THEN
        READ(DLIN,*) IOPTZD
      ELSEIF(ID(1:8) .EQ. 'MARSHOPT'  ) THEN
        READ(DLIN,*) IDNOPT
      ELSEIF(ID(1:8) .EQ. 'EDDYTYPE'  ) THEN
        READ(DLIN,*) IEDSW
      ELSEIF(ID(1:6) .EQ. 'TBFACT'  ) THEN
        READ(DLIN,*) TBFACT
      ELSEIF(ID(1:5) .EQ. 'TBMIN'  ) THEN
        READ(DLIN,*) TBMIN
      ELSEIF(ID(1:7) .EQ. 'TIMPROJ'  ) THEN
        READ(DLIN,*) IPROJ
      ELSEIF(ID(1:7) .EQ. '2DMODEL'  ) THEN
        NDP=0
        NLAYTYP=0
      ELSEIF(ID(1:8) .EQ. '3DFIXLAY'  ) THEN
        READ(DLIN,*) NDP
        NDP=-NDP-1
        NLAYTYP=1
      ELSEIF(ID(1:8) .EQ. '3DTYPLD1') THEN
        NDP=1
        NLAYTYP=2
      ELSEIF(ID(1:8) .EQ. '3DTYPLD2') THEN
        NDP=-1
        NLAYTYP=3
      ELSEIF(ID(1:8) .EQ. '3DTYPLD3') THEN
        NDP=2
        NLAYTYP=4
      ELSEIF(ID(1:7) .EQ. 'GRAVITY'  ) THEN
        READ(DLIN,*) IGRV
	  IF(IGRV .EQ. 0) GRAV=32.2
  	  IF(IGRV .EQ. 1) GRAV=9.81
        IF(GRAV .LT. 10.) THEN
          FCOEF=GRAV
        ELSE
          FCOEF=GRAV/2.208
        ENDIF
      ELSEIF(ID(1:7) .EQ. 'ZEROBED') THEN
        READ(DLIN,*) IZB
      ELSEIF(ID(1:7) .EQ. 'PASSSAL') THEN
        READ(DLIN,*) IPASS1
      ELSEIF(ID(1:7) .EQ. 'PASSTMP') THEN
        READ(DLIN,*) IPASS2
      ELSEIF(ID(1:7) .EQ. 'PASSSED') THEN
        READ(DLIN,*) IPASS3
      ELSEIF(ID(1:8) .EQ. 'ZEROSURF') THEN
        READ(DLIN,*) IZERS
      ELSEIF(ID(1:8) .EQ. 'ZERBELLV') THEN
        READ(DLIN,*) ZERBED
      ELSEIF(ID(1:6) .EQ. 'SAVITR'  ) THEN
        READ(DLIN,*) ISAVITR
      ELSEIF(ID(1:8) .EQ. 'REVRTDEN'  ) THEN
        READ(DLIN,*) IVERTDEN
      ELSEIF(ID(1:5) .EQ. 'OMEGA'  ) THEN
        READ(DLIN,*) OMEGA1
      ELSEIF(ID(1:4) .EQ. 'ELEV'  ) THEN
        READ(DLIN,*) ELEV
      ELSEIF(ID(1:7) .EQ. 'X-SCALE' ) THEN
        READ(DLIN,*) XSCALE
        IF(XSCALE .EQ. 0.) XSCALE=1.0
      ELSEIF(ID(1:7) .EQ. 'Y-SCALE' ) THEN
        READ(DLIN,*) YSCALE
        IF(YSCALE .EQ. 0.) YSCALE=1.0
      ELSEIF(ID(1:7) .EQ. 'Z-SCALE' ) THEN
        READ(DLIN,*) ZSCALE
        IF(ZSCALE .EQ. 0.) ZSCALE=1.0
      ELSEIF(ID(1:8) .EQ. 'BOUNDCMN') THEN
        READ(DLIN,*) CMIN
        IF(CMIN .EQ. 0.) CMIN=1.0
      ELSEIF(ID(1:8) .EQ. 'BOUNDCPW' ) THEN
        READ(DLIN,*) CPR
        IF(CPR .EQ. 0.) CPR=1.0
      ELSEIF(ID(1:4) .EQ. 'UNOM'  ) THEN
        READ(DLIN,*) UNOM
      ELSEIF(ID(1:4) .EQ. 'UDIR'  ) THEN
        READ(DLIN,*) UDIR
      ELSEIF(ID(1:4) .EQ. 'HMIN'  ) THEN
        READ(DLIN,*) HMIN
      ELSEIF(ID(1:5) .EQ. 'DSET ') THEN
        READ(DLIN,*) DSET
      ELSEIF(ID(1:5) .EQ. 'DSETD'  ) THEN
        READ(DLIN,*) DSETD
      ELSEIF(ID(1:5) .EQ. 'FIXBC'  ) THEN
        READ(DLIN,*) IFXBC
      ELSEIF(ID(1:8) .EQ. 'VERTEQSW'  ) THEN
        READ(DLIN,*) IEQSWT
        IF(IEQSWT .EQ. 0) IEQSWT=20000

      ELSEIF(ID(1:8) .EQ. 'INITSAL '  ) THEN
        READ(DLIN,*) SALI
      ELSEIF(ID(1:8) .EQ. 'INITTEMP'  ) THEN
        READ(DLIN,*) TEMPI
      ELSEIF(ID(1:8) .EQ. 'INITSED '  ) THEN
        READ(DLIN,*) SEDI
      ELSEIF(ID(1:8) .EQ. 'INITUBED'  ) THEN
        READ(DLIN,*) UINP
      ELSEIF(ID(1:8) .EQ. 'INITVBED'  ) THEN
        READ(DLIN,*) VINP
      ELSEIF(ID(1:8) .EQ. 'RETRNPCT'  ) THEN
        READ(DLIN,*) PRCNT
      ELSEIF(ID(1:7) .EQ. 'SURFMIX'  ) THEN
        READ(DLIN,*) DMIX
		
      ELSEIF(ID(1:5) .EQ. 'SSITN'  ) THEN
       READ(DLIN,*) NITI
      ELSEIF(ID(1:5) .EQ. 'TRITN'  ) THEN
        READ(DLIN,*) NITN
        IF(NITN .EQ. 0) NCYC=0
      ELSEIF(ID(1:7) .EQ. 'TRSTEPS' ) THEN
        READ(DLIN,*) NCYC
        IF(NCYC .EQ. 0) DATEND='                '
      ELSEIF(ID(1:8) .EQ. 'ECHSVALL'  ) THEN
        IPRT=1
      ELSEIF(ID(1:8) .EQ. 'ECHSVNON'  ) THEN
        IPRT=0
      ELSEIF(ID(1:8) .EQ. 'ECHPTINI'  ) THEN
        IPRT=2
      ELSEIF(ID(1:8) .EQ. 'ITERINTV'  ) THEN
        READ(DLIN,*) NPRTI
      ELSEIF(ID(1:8) .EQ. 'ASCSVFRQ'  ) THEN
        READ(DLIN,*) NPRTF
      ELSEIF(ID(1:5) .EQ. 'STBIN'  ) THEN
        READ(DLIN,*) IRSAV
        IF(IRSAV .EQ. 0) IRSAV=1 
      ELSEIF(ID(1:5) .EQ. 'DRYSW' ) THEN
        READ(DLIN,*) IDSWT
      ELSEIF(ID(1:6) .EQ. 'FRQBIN'  ) THEN
        READ(DLIN,*) IOUTFREQ
        IF(IOUTFREQ .EQ. 0) IOUTFREQ=1
      ELSEIF(ID(1:6) .EQ. 'FRQRST' ) THEN
        READ(DLIN,*) IOUTRST 
        IF(IOUTRST .EQ. 0) IOUTRST=10        
      ELSEIF(ID(1:8) .EQ. 'RWDASFRQ'  ) THEN
        READ(DLIN,*) IREWOUT 
        IF(IREWOUT .EQ. 0) IREWOUT=999999
      ELSEIF(ID(1:5) .EQ. '1DTYP'  ) THEN
        READ(DLIN,*) ID1DND
      ELSEIF(ID(1:6) .EQ. 'SOLVER') THEN
        READ(DLIN,*) ICPU
      ELSEIF(ID(1:8) .EQ. 'SLVERDSK') THEN
        READ(DLIN,*) IOOC
      ELSEIF(ID(1:8) .EQ. 'MESSRWND'  ) THEN
        READ(DLIN,*) IREWMES 
        IF(IREWMES .EQ. 0) IREWMES=999999
      ELSEIF(ID(1:8) .EQ. 'INITWSRF'  ) THEN
        IINITWS=1
        READ(DLIN,*) ELEV1         
      ELSEIF(ID(1:8) .EQ. 'CONV-VEL'  ) THEN
        READ(DLIN,*) CONV(1)
        CONV(2)=CONV(1)
      ELSEIF(ID(1:8) .EQ. 'CONV-DEP'  ) THEN
        READ(DLIN,*) CONV(3)
      ELSEIF(ID(1:8) .EQ. 'CONV-SAL'  ) THEN
        READ(DLIN,*) CONV(4)
      ELSEIF(ID(1:8) .EQ. 'CONV-TMP'  ) THEN
        READ(DLIN,*) CONV(5)
      ELSEIF(ID(1:8) .EQ. 'CONV-SED'  ) THEN
        READ(DLIN,*) CONV(6)
      ELSEIF(ID(1:8) .EQ. 'TRANSIT '  ) THEN
        READ(DLIN,*) TRANSIT
        ITRANSIT=1

     ELSEIF(ID(1:8) .EQ. 'CCLINOUT'  ) THEN
       READ(DLIN,*) (NCSPLPT(JJ),JJ=JCSPLPT+1,NCHARBL+JCSPLPT)
       JCSPLPT=JCSPLPT+NCHARBL
     ELSEIF(ID(1:8) .EQ. 'CONT-FLW'  ) THEN
       ICTOTC=ICTOTC+1
       ICCOMP(ICTOTC)=1
       ACSPLPT(ICTOTC)=  'FLOW     '
     ELSEIF(ID(1:8) .EQ. 'CONT-DEP'  ) THEN
       ICTOTC=ICTOTC+1
       ICCOMP(ICTOTC)=2
       ACSPLPT(ICTOTC)=  'DEPTH    '
     ELSEIF(ID(1:8) .EQ. 'CONT-ELV'  ) THEN
       ICTOTC=ICTOTC+1
       ICCOMP(ICTOTC)=3
       ACSPLPT(ICTOTC)=  'WS-ELEV  '
     ELSEIF(ID(1:8) .EQ. 'CONT-SAL'  ) THEN
       ICTOTC=ICTOTC+1
       ICCOMP(ICTOTC)=4
       ACSPLPT(ICTOTC)=  'SALINITY'
     ELSEIF(ID(1:8) .EQ. 'CONT-TMP'  ) THEN
       ICTOTC=ICTOTC+1
       ICCOMP(ICTOTC)=5
       ACSPLPT(ICTOTC)=  'TEMPERAT'
     ELSEIF(ID(1:8) .EQ. 'CONT-SED'  ) THEN
       ICTOTC=ICTOTC+1
       ICCOMP(ICTOTC)=6
       ACSPLPT(ICTOTC)=  'SEDIMENT'
      
        
      ELSEIF(ID(1:8) .EQ. 'EDDY-MAT'  ) THEN
        READ(DLIN,*) K,EDD11
        ORT(K,1)=EDD11
        ORT(K,2)=EDD11
        ORT(K,3)=EDD11
        ORT(K,4)=EDD11
        IF(NMAT .LT. K) NMAT=K
      ELSEIF(ID(1:8) .EQ. 'EDDY-VRT'  ) THEN
        READ(DLIN,*) K,EDD11
        ORT(K,6)=EDD11
        ORT(K,7)=EDD11
        IF(NMAT .LT. K) NMAT=K
      ELSEIF(ID(1:8) .EQ. 'DIFF-MAT'  ) THEN
        READ(DLIN,*) K,EDD11
        ORT(K,8)=EDD11
        ORT(K,9)=EDD11
        IF(NMAT .LT. K) NMAT=K
      ELSEIF(ID(1:8) .EQ. 'DIFF-VRT'  ) THEN
        READ(DLIN,*) K,EDD11
        ORT(K,10)=EDD11
        IF(NMAT .LT. K) NMAT=K
      ELSEIF(ID(1:8) .EQ. 'MANN-MAT'  ) THEN
        READ(DLIN,*) K,ORT(K,5)
      ELSEIF(ID(1:8) .EQ. 'MANN-BNK'  ) THEN
        READ(DLIN,*) K,ORT(K,11)
      ELSEIF(ID(1:8) .EQ. 'MARSH-FR'  ) THEN
        READ(DLIN,*) K,ORT(K,12)
      ELSEIF(ID(1:8) .EQ. 'MANN-SRF'  ) THEN
        READ(DLIN,*) K,ORT(K,13)
      ELSEIF(ID(1:8) .EQ. 'BN-V-MIN'  ) THEN
        READ(DLIN,*) VMIN
      ELSEIF(ID(1:8) .EQ. 'BN-V-PWR'  ) THEN
        READ(DLIN,*) POWER
      ELSEIF(ID(1:8) .EQ. 'TR-V-MIN'  ) THEN
        READ(DLIN,*) UMIN
      ELSEIF(ID(1:8) .EQ. 'TR-V-PWR'  ) THEN
        READ(DLIN,*) PWERIN
      ELSEIF(ID(1:8) .EQ. 'ED-VTVAR'  ) THEN
        READ(DLIN,*) K,EDD1(K),EDD2(K),EDD3(K)
      ELSEIF(ID(1:8) .EQ. 'MARSH-SH'  ) THEN
        READ(DLIN,*) ACT1
      ELSEIF(ID(1:8) .EQ. 'MARSH-RG'  ) THEN
        READ(DLIN,*) ACT2
      ELSEIF(ID(1:8) .EQ. 'MARSH-PR'  ) THEN
        READ(DLIN,*) ACT3
      ELSEIF(ID(1:8) .EQ. 'MARSH-LM'  ) THEN
        READ(DLIN,*) ACT4
      ELSEIF(ID(1:4) .EQ. 'LD3 '  ) THEN
        L3DCNT=L3DCNT+1  
        L3DTYP=3
        READ(DLIN,*) JND(L3DCNT),KKLAY(L3DCNT),(L3DDAT(L3DCNT,K),K=1,KKLAY(L3DCNT))
      ELSEIF(ID(1:4) .EQ. 'LD2 '  ) THEN
        L3DCNT=L3DCNT+1  
        L3DTYP=2
        READ(DLIN,*) JND(L3DCNT),KKLAY(L3DCNT),(L3DDAT(L3DCNT,K),K=1,KKLAY(L3DCNT))
      ELSEIF(ID(1:8) .EQ. 'SPR-NOD '  ) THEN
        READ(DLIN,*) (NSPLPT(J),J=JSPLPT+1,NCHARBL+JSPLPT)
        JSPLPT=JSPLPT+NCHARBL
        
!      ENDIF
      
      
      
        ELSEIF(ID .EQ. 'DELTA-HR') THEN
          READ(DLIN,*) DELT(J)
          KH=0
          KQ=0
          KE=0
          KF=0
        ELSEIF(ID .EQ. 'DELTA-MN') THEN
          READ(DLIN,*) DELTM(J)
          KH=0
          KQ=0
          KE=0
          KF=0
        ELSEIF(ID .EQ. 'DATE-END') THEN
          DO L=1,72
            IF(DLIN(L:L) .NE. ' ') THEN
              LIMIT=L
              GO TO 140
            ENDIF
          ENDDO 
140       READ(DLININ(LIMIT:LIMIT+15),5010) DATENDST(J)
!        ELSEIF(ID .EQ. 'UNDERRLX') THEN
!          READ(DLIN,*) URLC(J), NRITR(J)  
!        ELSEIF(ID .EQ. 'WINDSW  ') THEN
!          READ(DLIN,*) IWIND(J)
!        ELSEIF(ID .EQ. 'WINDUNIT') THEN
!          READ(DLIN,*) IWUNITS(J)
!        ELSEIF(ID .EQ. 'WINDVEL ') THEN
!          READ(DLIN,*) WVEL(J)
!        ELSEIF(ID .EQ. 'WINDDIR ') THEN
!          READ(DLIN,*) WDIR(J)
        ELSEIF(ID .EQ. 'Q-ITR   ') THEN
          IITYPE(J)=1  
        ELSEIF(ID .EQ. 'QSL-ITR ') THEN
          IITYPE(J)=2  
        ELSEIF(ID .EQ. 'QTM-ITR ') THEN
          IITYPE(J)=3  
        ELSEIF(ID .EQ. 'QSD-ITR ') THEN
          IITYPE(J)=4  
        ELSEIF(ID .EQ. 'QST-ITR ') THEN
          IITYPE(J)=5
          
          
          
        ELSEIF(ID .EQ. 'FL-ELEVC') THEN
          KH=KH+1
          READ(DLIN,*) IHLIN(KH,J),LAYNUMH(KH,J),HLIN(KH,J),(QUALKH(KH,J,K),K=1,3)
          HCKLIN(KH,J)=1
          LO=1
        ELSEIF(ID .EQ. 'CN-ELEVC') THEN
          KH=KH+1
          READ(DLIN,*) IHLIN(KH,J),LAYNUMH(KH,J),HLIN(KH,J),(QUALKH(KH,J,K),K=1,3)
          HCKLIN(KH,J)=0
          LO=1
        ELSEIF(ID(1:3) .EQ. 'HCN') THEN
150       LHI=LO-1+NCHARBL
          READ(DLIN,*) (FHCN(KH,J,K), K=LO,LHI)
          KHCN(J)=KH
          IHCN(KH,J)=LHI
          LO=LO+NCHARBL
          CALL GINPT(IIN,ID,DLININ)
          CALL PARSELIN(DLININ,DLIN,ICLON,NCHARBL)
          IF(ID(1:3) .NE. 'HCN') GO TO 110

          GO TO 150
          
        ELSEIF(ID .EQ. 'FL-ELEVI') THEN
          KH=KH+1
          READ(DLIN,*) IHLIN(KH,J),LAYNUMH(KH,J),HLIN(KH,J),HLIN1(KH,J),(QUALKH(KH,J,K),K=1,3)
          HCKLIN(KH,J)=1
        ELSEIF(ID .EQ. 'CN-ELEVI') THEN
          KH=KH+1
          READ(DLIN,*) IHLIN(KH,J),LAYNUMH(KH,J),HLIN(KH,J),HLIN1(KH,J),(QUALKH(KH,J,K),K=1,3)
          HCKLIN(KH,J)=0
 
        ELSEIF(ID .EQ. 'GBWIND  ') THEN
          READ(DLIN,*) WVEL(J),WDIR(J)
        
          
        ELSEIF(ID(1:4) .EQ. 'CN-Q') THEN
          KQ=KQ+1
          READ(DLIN,*) IQLIN(KQ,J),LAYNUMQ(KQ,J),QLIN(KQ,J),QDLIN(KQ,J),(QUALKQ(KQ,J,K),K=1,3)
          QCKLIN(KQ,J)=0
          IF(ID(5:5) .EQ. 'C') THEN
            IQLIN1(KQ,J)=1  
          ELSEIF(ID(5:5) .EQ. 'F') THEN
            IQLIN1(KQ,J)=2  
          ELSEIF(ID(5:5) .EQ. 'H') THEN
            IQLIN1(KQ,J)=3  
          ENDIF
        ELSEIF(ID(1:4) .EQ. 'FL-Q') THEN
          KQ=KQ+1
          READ(DLIN,*) IQLIN(KQ,J),LAYNUMQ(KQ,J),QLIN(KQ,J),QDLIN(KQ,J),(QUALKQ(KQ,J,K),K=1,3)
          QCKLIN(KQ,J)=1
          IF(ID(5:5) .EQ. 'C') THEN
            IQLIN1(KQ,J)=1  
          ELSEIF(ID(5:5) .EQ. 'F') THEN
            IQLIN1(KQ,J)=2  
          ELSEIF(ID(5:5) .EQ. 'H') THEN
            IQLIN1(KQ,J)=3  
          ENDIF

        ELSEIF(ID .EQ. 'CN-RAIN ') THEN
          KE=KE+1
          IETP(KE,J)=4
          READ(DLIN,*) ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=0
          ECKLIN1(KE,J)=0
!          ECKLIN2(KE,J)=1
        ELSEIF(ID .EQ. 'FL-RAIN ') THEN
          KE=KE+1
          IETP(KE,J)=4
          READ(DLIN,*) ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=1
          ECKLIN1(KE,J)=0
          
!          ECKLIN2(KE,J)=1
        ELSEIF(ID .EQ. 'CN-ELMGT') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          IELIN(KE,J)=0
          ECKLIN(KE,J)=0
          ECKLIN1(KE,J)=1
        ELSEIF(ID .EQ. 'FL-ELMGT') THEN
          KE=KE+1
          IETP(KE,J)=1        
          READ(DLIN,*) LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          IELIN(KE,J)=0
          ECKLIN(KE,J)=1
          ECKLIN1(KE,J)=1
          
         ELSEIF(ID .EQ. 'CN-ELMGD') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          IELIN(KE,J)=0
          ECKLIN(KE,J)=0
          ECKLIN1(KE,J)=0
         ELSEIF(ID .EQ. 'FL-ELMGD') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          IELIN(KE,J)=0
          ECKLIN(KE,J)=1
          ECKLIN1(KE,J)=0
          
        ELSEIF(ID .EQ. 'CN-ELMET') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) IELIN(KE,J),LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=0
          ECKLIN1(KE,J)=1
        ELSEIF(ID .EQ. 'FL-ELMET') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) IELIN(KE,J),LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=1
          ECKLIN1(KE,J)=1  

        ELSEIF(ID .EQ. 'CN-ELMED') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) IELIN(KE,J),LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=0
          ECKLIN1(KE,J)=0
        ELSEIF(ID .EQ. 'FL-ELMED') THEN
          KE=KE+1
          IETP(KE,J)=1
          READ(DLIN,*) IELIN(KE,J),LAYNUME(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=1
          ECKLIN1(KE,J)=0

        ELSEIF(ID .EQ. 'CN-GRAIN') THEN
          KE=KE+1
          IETP(KE,J)=6
          READ(DLIN,*) IELIN(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=0
          ECKLIN1(KE,J)=0
        ELSEIF(ID .EQ. 'FL-GRAIN') THEN
          KE=KE+1
          IETP(KE,J)=6
          READ(DLIN,*) IELIN(KE,J),ELIN(KE,J),(QUALKE(KE,J,K),K=1,3)
          ECKLIN(KE,J)=1
          ECKLIN1(KE,J)=0
        ELSEIF(ID(1:3) .EQ. 'SN ') THEN
          NSND(J)=NSND(J)+1
          READ(DLIN,*) NODSND(NSND(J),J),NCODE(NSND(J),J),(BCSND(NSND(J),J,K),K=1,6)
        ELSEIF(ID(1:8) .EQ. 'SD      ') THEN
          NSND(J)=NSND(J)+1
          READ(DLIN,*) NCODE(NSND(J),J),(BCSND(NSND(J),J,K),K=1,6)
          NODSND(NSND(J),J)=0
          
!        ELSEIF(ID .EQ. 'FLWCNTRL') THEN
!          KF=KF+1
!          READ(DLIN,*) IFCLIN(KF,J),IFCLIN1(KF,J),FCLIN1(KF,J),FCLIN2(KF,J),FCLIN3(KF,J),FCLIN4(KF,J),FCLIN5(KF,J)
        ELSE
          NHOLDC=NHOLDC+1
          WRITE(HOLDC(NHOLDC),'(A8,A72)') ID,DLIN
        ENDIF
200     CONTINUE          
      ENDDO
      IF(INTG(5) .EQ. 0) THEN
        DATEND='                '
        INTG(10)=0
      ENDIF
      NQLIN(J)=KQ
      NHLIN(J)=KH
      NELIN(J)=KE
      NFCLIN(J)=KF
      NSND(J)=KSN
      RETURN
    END
    
        
      SUBROUTINE GINPT(IIN,ID,DLIN)
      INTEGER ICROS(73)
      CHARACTER ID*8,DLIN*72,EMES(10)*23
      CHARACTER*8 DLINEXTRA
      COMMON /DLINF/ DLINEXTRA
      DATA ICROS/0,7,8*0,4,8*0,1,3,0,6,7,0,2,43*0,10,0,0,5/
     ! DATA EMES/
     !+'CROSS SECTION DATA FILE',
     !+'GROUP DATA FILE        ',
     !+'PUMP DATA FILE         ',
     !+'BOUNDARY FLOW DATA FILE',
     !+'STAGE FLOW DATA FILE   ',
     !+'CONTROL STRUCTURE FILE ',
     !+'INPUT RM2 CONTROL FILE ',
     !+'ALTERNATE INPUT FILE   ',
     !+'INPUT TIME CONTROL FILE',
     !+'WIND DATA FILE         '/
  100 CONTINUE
!IPK  OCT 14 ADD TEST FOR ERROR OR END OF FILE
      READ(IIN,7000,END=800,ERR=900) ID,DLIN,DLINEXTRA
      write(75,7000) id,dlin,DLINEXTRA
!ipk jul03
      call to_upper(id)
 7000 FORMAT(A8,A72,A8)
      do i=1,8
          if(id(i:i) .eq. char(9)) go to 200
      enddo
      do i=1,72
        if(dlin(i:i) .eq. char(9)) go to 200
      enddo
!ipk jan03
      do i=1,8
	    if(dlinextra(i:i) .eq. char(9)) go to 200
      enddo
      IF(ID(1:1) .EQ. ':') GO TO 100
      IF(ID(1:1) .EQ. ';') GO TO 100
      IF(ID(1:3) .EQ. 'com') GO TO 100
      IF(ID(1:3) .EQ. 'COM') GO TO 100
      IF(ID(1:3) .EQ. 'Com') GO TO 100
      IF(ID(1:8) .EQ. '        ') GO TO 100
      RETURN
  200 continue
        write(*,*) 'Error Tab character found in the following line'
        write(75,*) 'Error Tab character found in the following line'
      write(75,7000) id,dlin
      write(*,7000) id,dlin
      stop
      
  800 CLOSE(75)
      OPEN(75,file='ERROR.OUT')
 6005 FORMAT(' ERROR -- END OF FILE READING ',A23)      
      STOP
 
  900 CLOSE(75)
      OPEN(75,file='ERROR.OUT')
      WRITE(*,6006) EMES(ICROS(IIN))
      WRITE(*,6006) EMES(ICROS(IIN))
      WRITE(75,6006) EMES(ICROS(IIN))
 6006 FORMAT(' ERROR -- ILLEGAL CHARACTER READING ',A23)      
      STOP
 
      END

! *****************************************************************************************

      SUBROUTINE TO_UPPER(STR)

      CHARACTER*(*) STR
      CHARACTER*1 CH

      L = LEN(STR)

      DO I=1,L
         CH = STR(I:I)
         IF ( ICHAR(CH) .GT. 96 .AND. ICHAR(CH) .LE. 122)  THEN
            STR(I:I) = CHAR(ICHAR(CH)-32)
         ENDIF
      ENDDO

      END
 
      SUBROUTINE PARSELIN(DLININ,DLIN,ICLON,NCHARBL)
	  CHARACTER*72 DLIN,DLININ
	  CHARACTER*1 CTYPE(6)
        INTEGER ICLON
	  DATA CTYPE/' ',',','\',':','/','&'/
	  IBAS=0
        IPREV=1
        ICLON=0
        NCHARBL=0
	  DO K=1,72
	    DLIN(K:K)=CTYPE(1)
	  ENDDO
	  DO K=1,72
            
	    IF(DLININ(K:K) .EQ. CTYPE(6)) THEN
            IF(IBAS .EQ. 0) THEN
              NCHARBL=0
              RETURN
            ENDIF
            IF(DLIN(IBAS:IBAS) .EQ. CTYPE(2)) THEN
              DLIN(IBAS:IBAS)= CTYPE(1) 
            ELSE
              IBAS=IBAS+1  
              DLIN(IBAS:IBAS) =CTYPE(1)
              NCHARBL=NCHARBL+1
            ENDIF
            
            RETURN
          ENDIF
          
		IF(DLININ(K:K) .EQ. CTYPE(1)) THEN
              
!         TEST FOR PREVIOUS BLANK IF SO MOVE ON                    
              
		  IF(IPREV .EQ. 1) GO TO 200 

!           IF NO PREVIOUS THEN WE HAVE AN END OF CHARACTER STREAM ADD A COMMA TO DLIN
		  IPREV=1
            IF(DLIN(IBAS:IBAS) .NE. CTYPE(2)) THEN
		    IBAS=IBAS+1
		    DLIN(IBAS:IBAS)=CTYPE(2)
              NCHARBL=NCHARBL+1
            ENDIF
          ELSE
              
!           WE HAVE NUMBER OR A COMMA OR \ OR / CHARACTER              
              
		  DO J=2,5
		    IF(DLININ(K:K) .EQ. CTYPE(J)) THEN

!           FOUND SOMETHING ADD A COMMA
                  
                IPREV=0
			  IBAS=IBAS+1
                IF(J .EQ. 4) THEN
                  ICLON=1
                ENDIF
                DLIN(IBAS:IBAS)=CTYPE(2)
                NCHARBL=NCHARBL+1
			  GO TO 100
			ENDIF
            ENDDO

!             NOTHING FOUND MUST BE LETTER OR NUMBER COPY IT OVER
            
            IPREV=0
		  IBAS=IBAS+1
		  DLIN(IBAS:IBAS)=DLININ(K:K)
!           MOVE ON TO NEXT CHARACTER
            
  100     CONTINUE
		ENDIF
  200 ENDDO
      RETURN
      END
    
    
        