      SUBROUTINE MASTERLOCK(jp,maxprobe,npro,iaccesstype,
     * actionrec,ilocknum,iverb,ilockup)

C     MASTERLOCK CHECKS PRESENT LOCK STATUS FOR
C     GIVEN PROGRAM, INFORMS USER IF THEY DO NOT
C     HAVE ACCESS, OR NEED TO UPGRADE A LOCK, THEN
C     CHANGES THE LOCK INFORMATION ACCORDINGLY

      character*(*) actionrec
      character*11 ctype
      character*15 whoisit,printrec

      dimension jp(0:maxprobe)

      if ( iaccesstype .eq. 4 ) return
      call setlockowner(whoisit,15)
      if ( whoisit(1:4) .eq. 'root' ) return

      if ( ilocknum .gt. 0 .and. ilocknum .lt. npro ) then
       iloopx=ilocknum
      else
       iloopx=npro
      endif

      ilockstat=iaccesstype
      if ( ilockstat .eq. 3 ) ilockstat=0
      do 50 nn=1,iloopx

       call clearstring(ctype,11)
       call getprobename(jp(nn),ctype)

       call lockcheck(ctype,ilockstat,istatus,ilockup,iverb)

       if ( istatus .eq. -1 ) goto 50
       if ( istatus .eq. 9.and. ilockstat .gt. -1 ) then
        write(6,*)' '
        write(6,*)' Access to main database(s) is denied!'
        write(6,*) 'Good-bye'
        write(6,*)' '
        stop
       endif

       if ( ilockstat .gt. -1 ) then
        printrec=actionrec
       else
        call clearstring(printrec,15)
        istatus=-1
       endif

       call lockexec(ctype,istatus,printrec)

50    continue

      return
      end
