       SUBROUTINE wbox(itim,lbox,sline,icount)                                 
C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    wbox        Plot watch boxes               
C   PRGMMR: LARRY SAGER      ORG: NP12       DATE: 00-05-26
C
C ABSTRACT: Plot labels on the radar chart                   
C
C PROGRAM HISTORY LOG:
C   00-05-26  LARRY SAGER
C
C USAGE:    CALL labelr                                          
C   INPUT ARGUMENT LIST:
C
C   OUTPUT ARGUMENT LIST:      (INCLUDING WORK ARRAYS)
C
C REMARKS: LIST CAVEATS, OTHER HELPFUL HINTS OR INFORMATION
C
C ATTRIBUTES:
C   LANGUAGE: IBM FORTRAN 90     
C   MACHINE:  IBM   
C
C$$$

      EXTERNAL JAFOSTXT
      INTEGER JAFOSTXT
      EXTERNAL JAFZPLOT
      INTEGER JAFZPLOT 

      INTEGER       itim(5)
      INTEGER       idat(8)
      INTEGER       jdat(8)
      INTEGER       iclat(7)
      INTEGER       iclon(7)
      INTEGER       krotpr(2)
      
      REAL          rinc(5)
      REAL*8        sline(500,4)

      LOGICAL       lbox(113,89)
      LOGICAL       stnval(113,89)
    
      CHARACTER*19  msg
      CHARACTER*6   cwork
      CHARACTER*6   cboxn
      CHARACTER*6   cbox(20)
      CHARACTER*6   cnum  
      CHARACTER*4   cendt 
      CHARACTER*4   ccurt
      CHARACTER*1   cfile(4000)
      CHARACTER*4000 cfil 

      EQUIVALENCE(cfile,cfil)
      

      DATA          msg      /'                   '/
      DATA          ird      /18/
      DATA          rinc     /1.,4*0./
      DATA          rioff    /3.25/
      DATA          rjoff    /-6.25/
      DATA          xmesh    /47.625/
      DATA          krotpr   /2*0/ 
      DATA          impt     /700/
      DATA          jmpt     /162/
      DATA          icb      /0/ 

      SAVE

      keil = 15   
      T1 = 37.5
      inx = 0
C
C     Start by calculating the Julian minute of
C       the current time
C
      print *,' number of count is ',icount
      ijdn = iw3jdn(itim(1),itim(2),itim(3))
      PRINT *,' JULIAN DAY:',IJDN
      ijminc = ijdn*1440 + itim(4)*60 + 35      
      PRINT *,' current Julian minute is ',ijminc
C
C
C     Put watch boxes on the radar chart
C       Begin by reading in the field
C
      rewind ird
      READ(ird,END=10) cfile
 10   CONTINUE
C     print *,' watch boxes'
C     print *,(cfile(kk),kk=1,300)
C
C     Locate the end of file
C
      DO k = 1,3996
       IF((cfile(k) .eq. 'E') .and. (cfile(k+1) .eq. 'N') .and.
     1 (cfile(k+2) .eq. 'D') ) THEN
C           print *,' END found at ',k
            goto 11
       END IF
      END DO
      print *,' No END OF FILE found in watch box file'
      print *,' Watch box file dropped'
      print *,' **************************************'
      
      RETURN

 11   kend = k
C
C     Now process the watch boxes
C
C     print *,' Number of bytes in WB array ',kend
C     print *,' Watch box array '
C     print *,(cfile(k),k=1,kend)
C     print *,' ' 
C
C     Locate a severe weather box
C
      DO 20  k = 1,kend
         IF((cfile(k) .eq. 'S') .and. (cfile(k+1) .eq. 'E') .and.
     1      (cfile(k+2) .eq. 'V') .and. (cfile(k+3) .eq. 'R')) THEN
            print *,' SEVR found at ',k 
C
C        Decode the year month and day for this box  
C
            j = k+5
            DO i =0,5
               IF((cfile(j+i).lt.'0').or.(cfile(j+i).gt.'9'))THEN 
                 print *,' bad character found  drop SEVR box'
                 goto 20
               END IF
            END DO
            
            READ(cfil(j:j+5),'(3i2)') iywb,imwb,idwb
            iywb = iywb + 2000
c           print *,' wb yr mt day are ',iywb,imwb,idwb
            j = j + 7
C           print *,' decode next*',cfil(j:j+3)
            DO i =0,3
               IF((cfile(j+i).lt.'0').or.(cfile(j+i).gt.'9'))THEN
                 print *,' bad character found  drop SEVR box'
                 goto 20
               END IF
            END DO
            ccurt = cfil(j:j+3)
            READ(cfil(j:j+3),'(i4)') icurt             
C           print *,' curt time is ',ccurt
C           print *,' curt time is ',icurt
C
C           Store the box number
C
            j = j + 5
            cboxn = cfil(j:j+5)

C
C           Check for duplicates
C
            IF(inx .gt. 0) THEN
              DO kk = 1,inx
                IF(cbox(kk) .eq. cboxn) THEN
                  print *,' duplicate warning box found'
                  print *,' drop box ',cboxn
                  print *,'   '
                  go to 20
                END IF
              END DO
            END IF
            inx = inx + 1
            IF(inx .le. 20) cbox(inx) = cboxn
          
C
C           Store end time
C

            j = j + 7
            print *,' decode next*',cfil(j:j+3)
            DO i =0,3
               IF((cfile(j+i).lt.'0').or.(cfile(j+i).gt.'9'))THEN
                 print *,' bad character found  drop SEVR box'
                 goto 20
               END IF
            END DO
            cendt = cfil(j:j+3)
            READ(cfil(j:j+3),'(i4)') iendt
            print *,' end  time is ',cendt
            print *,' end  time is ',iendt
C
C           Next find the Julian times for the start and stop
C             times
C  
            ijdn = iw3jdn(iywb,imwb,idwb)
            PRINT *,' JULIAN DAY start:',ijdn
            icurh = icurt/100
            icurm = icurt - icurh*100
            ijmins = ijdn*1440 + 60*icurh + icurm
            PRINT *,' JULIAN minute for start ',ijmins
C
C           Check to see if we need to update the
C              hour
C

            IF(icurt .gt. iendt) THEN
              idat(1) = iywb  
              idat(2) = imwb  
              idat(3) = idwb  
              idat(4) = iywb  
              idat(5) = ihwb  
              idat(6) = 0
              idat(7) = 0
              idat(8) = 0
              CALL w3movdat(rinc,idat,jdat)
              idwb = jdat(3)
              imwb = jdat(2)
              iywb = jdat(1)
               
              print *,' updated date is ',idwb,imwb,iywb
            ENDIF

            ijdn = iw3jdn(iywb,imwb,idwb)
            PRINT *,' JULIAN DAY start:',ijdn
            iendh = iendt/100
            iendm = iendt - iendh*100
            print *,' endh m t are ',iendh,iendm,iendt
            ijmine = ijdn*1440 + 60*iendh + iendm
            PRINT *,' JULIAN minute for end   ',ijmine
C 
C           Make sure this box is within the start and  
C             end times.
C
            print *,' compare ijminc ijmins ijmine ',ijminc,
     1         ijmins,ijmine
            IF((ijminc .ge. ijmins) .and. (ijminc .le. ijmine)) THEN
              print *,' process this box'
C
C             Get the corner points of the box
C
              j = j + 7
              DO ii = 1,6
              print *, ' corner # ',ii
              print *,' decode next*',cfil(j:j+4)
              DO i =0,4
                 IF((cfile(j+i).lt.'0').or.(cfile(j+i).gt.'9'))THEN
                   print *,' bad character found  drop SEVR box'
                   goto 20
                 END IF
              END DO
              READ(cfil(j:j+4),'(i5)') iclat(ii)
              print *,' corner lat ',iclat(ii)

              j = j + 6
              print *,' decode next*',cfil(j:j+4)
              DO i =0,4
                 IF((cfile(j+i).lt.'0').or.(cfile(j+i).gt.'9'))THEN
                   print *,' bad character found  drop SEVR box'
                   goto 20
                 END IF
              END DO
              READ(cfil(j:j+4),'(i5)') iclon(ii)

              j = j + 6
              IF(cfil(j-1:j-1) .eq. ';') goto 18
              END DO
C
C           Now draw the watch box
C 
  18        CONTINUE
            iclat(ii+1) = iclat(1)
            iclon(ii+1) = iclon(1)
            ii = ii + 1
            
            keil = 15   
            T1 = 37.5
            ipen = 3
            DO ki = 1,2

            IF(ki .eq. 2) THEN
               DO kk = 1,ii
                   iclat(kk) = iclat(kk) + 3
                   iclon(kk) = iclon(kk) + 3
               END DO
            END IF            
            DO ij = 1,ii
               alat = iclat(ij)
               alat = alat*.01
               alon = iclon(ij)
               alon = alon*.01
               CALL TRUIJX(alat,alon,ri,rj,KEIL,IRET)
               YYA = (T1 * (rj - 1.0)) / 100.0
               XXA = (T1 * (ri - 1.0)) / 100.0
               iret = jafzplot(xxa,yya,ipen)          
               ipen = 2
            END DO
            END DO
C
C         Put the watch box number on the chart
C           Start by getting the i j location of
C           this box on the chart.
C
          ilat = 0      
          ilon = 99999
          DO kk = 1,ii
             IF(iclat(kk) .gt. ilat) THEN
               ilat = iclat(kk)
               ilon = iclon(kk)
             END IF
          END DO 
C
          IF(ilon .ne. 99999) THEN
          alat = ilat
          alat = alat*.01
          alon = ilon
          alon = alon*.01
C
C          Calculate the position on the 113x89 grid
C
          CALL w3fb00(alat,alon-25.,xmesh,zi,zj)
          zi = zi + 40. + 1. + rioff
          zj = zj + 160. + 1. + rjoff
C         print *,' i j   113X89 ',zi,zj
          ini = nint(zi)
          inj = nint(zj)
c  
C         print *,' '

C         do kkk =ini-10,ini+10
C            print *,(stnval(kkk,iii),iii=inj-10,inj+10)
C         END DO
C         print *,' ' 
          CALL watcell(lbox,ini,inj,io,jo,iswit)

          xi = float(io)-40.-1.-rioff
          xj = float(jo)-160.-1.-rjoff

          CALL w3fb01(xi,xj,xmesh,alat,alon)
          alon = alon + 25.
C
C         Calculate the i,j position from the lat/lon
C             using ijarea.
C
          ich = 5
          iflags = 0 
          CALL locat(alat,alon,ix,iy)
          iflags = 0
C         ireta= jafostxt(cboxn,ich,ix,iy,0,0,0,iflags)


          ENDIF
C
C         Print the start time/end time message 
C           for this watch box
C

C         print *,' ccurt cendt = ',ccurt,cendt
          msg(1:6) = cboxn
          msg(8:11) = ccurt(1:4)
          msg(12:12)= 'Z'
          msg(15:18) = cendt(1:4)
          msg(19:19) = 'Z'
          icb = icb + 1


            
          END IF
C
 
         END IF
 20   CONTINUE

       IF(icount .le. 0) RETURN
       IF(icount .ge. 500) icount = 500
       xcorr = -0.25
       ycorr = -1.55
       xchg = 0.35
       ychg = 0.35  
       DO k = 1,icount
         alat = sline(k,1)
         alon = sline(k,2)
         CALL TRUIJX(alat,alon,ri,rj,KEIL,IRET)
         ri = ri + xcorr
         rj = rj + ycorr
         YYA = (T1 * (rj - 1.0)) / 100.0
         XXA = (T1 * (ri - 1.0)) / 100.0
         yya = yya + ychg
         xxa = xxa + xchg
         ipen = 3
         iret = jafzplot(xxa,yya,ipen)
         alat = sline(k,3)
         alon = sline(k,4)
         CALL TRUIJX(alat,alon,ri,rj,KEIL,IRET)
         ri = ri + xcorr
         rj = rj + ycorr
         YYA = (T1 * (rj - 1.0)) / 100.0
         XXA = (T1 * (ri - 1.0)) / 100.0
         yya = yya + ychg
         xxa = xxa + xchg
         ipen = 2
         iret = jafzplot(xxa,yya,ipen)
       END DO
      RETURN 
      END
