      SUBROUTINE LOCKCHECK(proberec,iaccesstype,istatus,
     * ilockup,iverb)

c*****************************************************************
c    
c     INPUT:
c       proberec - probe of interest
c       iaccesstype -  0 = read-only program (e.g. proflook, overlap)
c                      1 = low risk read/write
c                          (READ-ONLY lock required)
c                      2 = high risk read/write
c                          (EXCL-LOCK required)
c                      8 = Dangerous - do not run on main probe
c
c     RETURN: (istatus)
c        -1  - local probe, no accession permission required
c     .  "0" = read-only access okay / don't own READ-ONLY lock, if present
c     .  "1" = read-write (low risk) access okay (READ-ONLY)
c     .  "2" = read-write (high risk) access okay (EXCL-LOCK)
c     .  "9" = ACCESS DENIED
c    
c*****************************************************************

      parameter (iwhofile = 77, ilockfile = 78)
      parameter (maxprobe=25)
      parameter (ip=11,it=8,il=15,iw=15,iw2=25)

      character*11 proberec,probelockrec(maxprobe)
      character*8 timerec(maxprobe)
      character*15 wholockrec(maxprobe)
      character*15 lockstat(maxprobe)
      character*25 whatrec(maxprobe)

      dimension iLOCK(maxprobe)

      call readlockfile(icounter,maxprobe,
     * probelockrec,ip,lockstat,il,wholockrec,iw,
     * timerec,it,whatrec,iw2,iLOCK,ilockfile)

      call matchlockprobe(icounter,probelockrec,ip,proberec,
     * iprobe,maxprobe)

      if ( iprobe .gt. 0 ) then
       call lockown(wholockrec(iprobe),iw,iown)

       if ( iaccesstype .gt. -1 ) then 
        write(6,*)' '
        write(6,*)'Probe: ',proberec
        write(6,*) 'present user:',wholockrec(iprobe)
        write(6,*) 'lock status:',lockstat(iprobe)
        write(6,*) 'running:',whatrec(iprobe)
       endif

       call lockstatus(iaccesstype,iLOCK(iprobe),iown,
     *  iprobe,istatus,ilockup,iverb)

c     Allow for overnight locks (3 & 4)
       if ( iLOCK(iprobe) .eq. 4 ) then
        istatus=4
       elseif ( istatus .lt. iLOCK(iprobe) .and.
     *  iLOCK(iprobe) .lt. 3 ) then
        istatus=iLOCK(iprobe)
       elseif ( istatus . lt. 2 .and. iLOCK(iprobe) .eq. 3 ) then
        istatus=3
       endif
      else
       istatus=-1
      endif

      return
      end

