      SUBROUTINE SHOWTIMESTP(J)
!   SHOW CONTROL PAGE    

      USE WINTERACTER

      USE RESID
      
      USE BLKRM10
      call wdialogload(IDD_GETTIMSTP)
      ierr=infoerror(1)

      CALL WDialogSelect(IDD_GETTIMSTP)
      ierr=infoerror(1)
50    IF(J .EQ. 1) THEN
        call wdialogputRadioButton(idf_radio1)
      ELSE
        call wdialogputRadioButton(idf_radio2)
        CALL WDialogPutInteger(IDF_INTEGER1,J-1)
      ENDIF
      
      CALL WDialogShow(-1,-1,0,Modal)

      ierr=infoerror(1)
      do
      
        IF (WInfoDialog(ExitButton) .EQ. IDHELP) THEN
           IHSW=7
           CALL HELP10(IHSW)
           GO TO 50
         ELSEIF (WInfoDialog(ExitButton) .EQ. IDOK) THEN
            call wdialogGetRadioButton(idf_radio1,J)
            IF(J .GT. 1) THEN
              CALL WDialogGetInteger(IDF_INTEGER1,JJ)
              J=JJ+1
              IF(J .EQ. 1) J=2
            ENDIF
            
            if(j .gt. jt) jt=j
            go to 95
         ELSEIF (WInfoDialog(ExitButton) .EQ. IDCANCEL)THEN
           RETURN
         endif
      enddo
95    continue         
      
      call wdialogload(IDD_TIMESTEP)
      ierr=infoerror(1)
100   CONTINUE
      CALL WDialogSelect(IDD_TIMESTEP)
      ierr=infoerror(1)

      if(J .EQ. 1) THEN
        DELT(1)=0.
        DELTM(J)=0.
        DATENDST(J)='                '
        ISTATE=0
        CALL WDialogFieldState(IDF_REAL1,ISTATE)
        CALL WDialogFieldState(IDF_REAL2,ISTATE)
        CALL WDialogFieldState(IDF_STRING9,ISTATE)
      ELSE  
        ISTATE=1
        CALL WDialogFieldState(IDF_REAL1,ISTATE)
        CALL WDialogFieldState(IDF_REAL2,ISTATE)
        CALL WDialogFieldState(IDF_STRING9,ISTATE)
      ENDIF
      
      CALL WDialogPutReal(IDF_REAL1,DELT(J))
      CALL WDialogPutReal(IDF_REAL2,DELTM(J))

      CALL WDialogPutString(IDF_STRING9,DATENDST(J))
      CALL WDialogPutReal(IDF_REAL5,URLC(J))
      CALL WDialogPutInteger(IDF_INTEGER2,NRITR(J))
      
      DO K=1,20
        IF(IQLIN(K,J) .GT. 0) THEN
          CALL WGridPutCellInteger(IDF_GRID1,1,K,iqlin1(K,J))
          CALL WGridPutCellCheckbox(IDF_GRID1,2,K,qcklin(K,J))
          CALL WGridPutCellInteger(IDF_GRID1,3,K,iqlin(K,J))
          CALL WGridPutCellInteger(IDF_GRID1,4,K,LAYNUMQ(K,J))
          CALL WGridPutCellReal(IDF_GRID1,5,K,qlin(K,J))
          CALL WGridPutCellReal(IDF_GRID1,6,K,qdlin(K,J))
          CALL WGridPutCellReal(IDF_GRID1,7,K,QUALKQ(K,J,1))
          CALL WGridPutCellReal(IDF_GRID1,8,K,QUALKQ(K,J,2))
          CALL WGridPutCellReal(IDF_GRID1,9,K,QUALKQ(K,J,3))
        ENDIF
        IF(IHLIN(K,J) .GT. 0) THEN
          CALL WGridPutCellInteger(IDF_GRID2,1,K,ihlin(K,J))
          CALL WGridPutCellCheckbox(IDF_GRID2,2,K,hcklin(K,J))
          CALL WGridPutCellCheckbox(IDF_GRID2,3,K,hcklin1(K,J))
          CALL WGridPutCellReal(IDF_GRID2,4,K,hlin(K,J))
          IF(HLIN1(K,J) .GT. -9000.) CALL WGridPutCellReal(IDF_GRID2,5,K,hlin1(K,J))
          CALL WGridPutCellReal(IDF_GRID2,6,K,QUALKH(K,J,1))
          CALL WGridPutCellReal(IDF_GRID2,7,K,QUALKH(K,J,2))
          CALL WGridPutCellReal(IDF_GRID2,8,K,QUALKH(K,J,3))
        ENDIF
      ENDDO
      DO K=1,500
        IF(IETP(K,J) .GT. 0) THEN
          CALL WGridPutCellInteger(IDF_GRID3,1,K,ietp(K,J))
          CALL WGridPutCellCheckbox(IDF_GRID3,2,K,ecklin(K,J))
          CALL WGridPutCellInteger(IDF_GRID3,3,K,ielin(K,J))
          CALL WGridPutCellInteger(IDF_GRID3,4,K,LAYNUME(K,J))
          CALL WGridPutCellCheckbox(IDF_GRID3,5,K,ecklin1(K,J))
          CALL WGridPutCellReal(IDF_GRID3,6,K,elin(K,J))
          CALL WGridPutCellReal(IDF_GRID3,7,K,QUALKE(K,J,1))
          CALL WGridPutCellReal(IDF_GRID3,8,K,QUALKE(K,J,2))
          CALL WGridPutCellReal(IDF_GRID3,9,K,QUALKE(K,J,3))
!        ELSE
!          CALL WGridPutCellInteger(IDF_GRID3,1,K,0)
!        ENDIF
!          CALL WGridPutCellCheckbox(IDF_GRID3,7,K,ecklin2(K,J))
        ENDIF
      ENDDO
      DO K=1,20
        IF(isflin(K,J) .GT. 0) THEN
          CALL WGridPutCellInteger(IDF_GRID4,1,K,isflin(K,J))
          CALL WGridPutCellReal(IDF_GRID4,2,K,sflin(K,J))
          CALL WGridPutCellReal(IDF_GRID4,3,K,sflin1(K,J))
          CALL WGridPutCellReal(IDF_GRID4,4,K,sflin2(K,J))
          CALL WGridPutCellReal(IDF_GRID4,5,K,sflin3(K,J))
          CALL WGridPutCellReal(IDF_GRID4,6,K,sflin4(K,J))
        ENDIF
      ENDDO
      CALL WDialogShow(-1,-1,0,Modal)

      ierr=infoerror(1)
      do
      
         IF (WInfoDialog(ExitButton) .EQ. IDHELP) THEN
           IHSW=5
           CALL HELP10(IHSW)
           GO TO 100
         ELSEIF (WInfoDialog(ExitButton) .EQ. IDOK  .OR.  WInfoDialog(ExitButton) .EQ. IDNEXT) THEN

           CALL WDialogGetReal(IDF_REAL1,DELT(J))
           CALL WDialogGetReal(IDF_REAL2,DELTM(J))
           CALL WDialogGetString(IDF_STRING9,DATENDST(J))
           CALL WDialogGetReal(IDF_REAL5,URLC(J))
           CALL WDialogGetInteger(IDF_INTEGER2,NRITR(J))

           DO K=1,20
             CALL WGridGetCellInteger(IDF_GRID1,1,K,iqlin1(K,J))
             IF(IQLIN1(K,J) .LT. 1) THEN
               NQLIN(J)=K-1
               EXIT
             ENDIF
          CALL WGridGetCellCheckbox(IDF_GRID1,2,K,qcklin(K,J))
          CALL WGridGetCellInteger(IDF_GRID1,3,K,iqlin(K,J))
          CALL WGridGetCellInteger(IDF_GRID1,4,K,LAYNUMQ(K,J))
          CALL WGridGetCellReal(IDF_GRID1,5,K,qlin(K,J))
          CALL WGridGetCellReal(IDF_GRID1,6,K,qdlin(K,J))
          CALL WGridGetCellReal(IDF_GRID1,7,K,QUALKQ(K,J,1))
          CALL WGridGetCellReal(IDF_GRID1,8,K,QUALKQ(K,J,2))
          CALL WGridGetCellReal(IDF_GRID1,9,K,QUALKQ(K,J,3))
           ENDDO
           DO K=1,20
             CALL WGridGetCellInteger(IDF_GRID2,1,K,ihlin(K,J))
             IF(IHLIN(K,J) .LT. 1) THEN
               NHLIN(J)=K-1
               EXIT
             ENDIF
             CALL WGridGetCellCheckbox(IDF_GRID2,2,K,hcklin(K,J))
             CALL WGridGetCellCheckbox(IDF_GRID2,3,K,hcklin1(K,J))
             CALL WGridGetCellReal(IDF_GRID2,4,K,hlin(K,J))
             CALL WGridGetCellReal(IDF_GRID2,5,K,HH)
             IF(HH .GT. -900) hlin1(K,J)=HH
             CALL WGridGetCellReal(IDF_GRID2,6,K,QUALKH(K,J,1))
             CALL WGridGetCellReal(IDF_GRID2,7,K,QUALKH(K,J,2))
             CALL WGridGetCellReal(IDF_GRID2,8,K,QUALKH(K,J,3))
           ENDDO
           DO K=1,500
             CALL WGridGetCellInteger(IDF_GRID3,1,K,ietp(K,J))
             if(ietp(k,j) .lt. 0) then
               NELIN(J)=K-1
               EXIT
             ENDIF
              
             CALL WGridGetCellCheckbox(IDF_GRID3,2,K,ecklin(K,J))
             CALL WGridGetCellInteger(IDF_GRID3,3,K,ielin(K,J))
             CALL WGridGetCellInteger(IDF_GRID3,4,K,LAYNUME(K,J))
             CALL WGridGetCellCheckbox(IDF_GRID3,5,K,ecklin1(K,J))
             CALL WGridGetCellReal(IDF_GRID3,6,K,elin(K,J))
             CALL WGridGetCellReal(IDF_GRID3,7,K,QUALKE(K,J,1))
             CALL WGridGetCellReal(IDF_GRID3,8,K,QUALKE(K,J,2))
             CALL WGridGetCellReal(IDF_GRID3,9,K,QUALKE(K,J,3))
             IF(IELIN(K,J) .LE. 0) IELIN(K,J)=0
          
           ENDDO  
        
           DO K=1,20
             CALL WGridGetCellInteger(IDF_GRID4,1,K,isflin(K,J))
             IF(isflin(K,J) .EQ. 0) THEN
               nsflin(j)=k-1
               exit
             endif
             CALL WGridGetCellReal(IDF_GRID4,2,K,sflin(K,J))
             CALL WGridGetCellReal(IDF_GRID4,3,K,sflin1(K,J))
             CALL WGridGetCellReal(IDF_GRID4,4,K,sflin2(K,J))
             CALL WGridGetCellReal(IDF_GRID4,5,K,sflin3(K,J))
             CALL WGridGetCellReal(IDF_GRID4,6,K,sflin4(K,J))
           ENDDO

           IERR=0
           DO K=1,20
               IF(IETP(K,J) .EQ. 0) EXIT
               !IF(ECKLIN2(K,J) .EQ. 1  .AND. IETP(K,J) .EQ. 0  .AND. IELIN(K,J) .GT. 0) THEN
               !  CALL WMessageBox(OKOnly,ExclamationIcon,CommonOK, &
               !  'Rain unit inflows cannot be applied to a single element',&
               !      'ERROR IN ELEMENT INFLOW BLOCK')
               !  IERR=1
               IF(ECKLIN2(K,J) .EQ. 1  .AND.  ECKLIN1(K,J) .EQ. 1) THEN
                 CALL WMessageBox(OKOnly,ExclamationIcon,CommonOK, &
                 'Total flow choice conflicts with rain unit',&
                      'ERROR IN ELEMENT INFLOW BLOCK')
                 IERR=1
               ENDIF
               IF(IETP(K,J) .EQ. 3  .AND.  ECKLIN2(K,J) .EQ. 0) THEN
                 CALL WMessageBox(OKOnly,ExclamationIcon,CommonOK, &
                 'Option for group inflow in standard units (metres/sec) not implemented in RMA2',&
                      'ERROR IN ELEMENT INFLOW BLOCK')
                 IERR=1
               ENDIF
           ENDDO
           IF(IERR .EQ. 1) GO TO 100
           call wdialogunload(IDD_TIMESTEP)
           IF(WInfoDialog(ExitButton) .EQ. IDNEXT) GO TO 500
           
           RETURN
!         ELSEIF(WInfoDialog(ExitButton) .EQ. IDNEXT) THEN
!           J=J+1
!           GO TO 100
         else
           return
         endif
      enddo
      
      RETURN
      
500   CONTINUE        
      call wdialogload(IDD_TIMESTEP2)
      ierr=infoerror(1)
 
      CALL WDialogSelect(IDD_TIMESTEP2)
      ierr=infoerror(1)
      CALL WDialogPutReal(IDF_REAL3,WVEL(J))
      CALL WDialogPutReal(IDF_REAL4,WDIR(J))

      IF(KHCN(J) .GT. 0) THEN
        DO K=1,KHCN(J)
          DO L=1,IHCN(K,J)
            CALL WGridPutCellReal(IDF_GRID1,L,K,FHCN(K,J,L))
          ENDDO
        ENDDO
      ENDIF
      IF(NSND(J) .GT. 0) THEN
        DO K=1,NSND(J)
          IF(NODSND(K,J) .GT. 0) THEN  
            CALL WGridPutCellInteger(IDF_GRID2,1,K,NODSND(K,J))
          ENDIF
          CALL WGridPutCellInteger(IDF_GRID2,2,K,NCODE(K,J))
          DO L=1,6
            CALL WGridPutCellReal(IDF_GRID2,L+2,K,BCSND(K,J,L))
          ENDDO
        ENDDO  
      ENDIF    
      CALL WDialogShow(-1,-1,0,Modal)

      ierr=infoerror(1)
      do

         IF (WInfoDialog(ExitButton) .EQ. IDHELP) THEN
           IHSW=6
           CALL HELP10(IHSW)
           GO TO 500
         ELSEIF (WInfoDialog(ExitButton) .EQ. IDOK) THEN

           CALL WDialogGetReal(IDF_REAL3,WVEL(J))
           CALL WDialogGetReal(IDF_REAL4,WDIR(J))

           DO K=1,20
             CALL WGridGetCellReal(IDF_GRID1,1,K,fhcn(K,J,1))
             IF(FHCN(K,J,1) .LT. 0.) THEN
               KHCN(J)=K-1 
               EXIT
             ENDIF
             DO L=1,36  
               CALL WGridGetCellReal(IDF_GRID1,L,K,fhcn(K,J,L))
               IF(FHCN(K,J,L) .LT. 0.) THEN
                 IHCN(K,J)=L-1 
                 EXIT
               ENDIF
             ENDDO
           ENDDO

           DO K=1,500
             IF(NCODE(K,J) .LE. 0) THEN
               NSND(J)=K-1
               EXIT
             ENDIF
             
             CALL WGridGetCellInteger(IDF_GRID2,1,K,NODSND(K,J))
             IF(NODSND(K,J) .LE. 0) NODSND(K,J)=0
             CALL WGridGetCellInteger(IDF_GRID2,2,K,NCODE(K,J))
             DO L=1,6
               CALL WGridGetCellReal(IDF_GRID2,L+2,K,BCSND(K,J,L))
             ENDDO
           ENDDO       
           
           call wdialogUNload(IDD_TIMESTEP2)
           RETURN
         ELSE
           call wdialogUNload(IDD_TIMESTEP2)
           RETURN
         ENDIF
      ENDDO
      END 
