Viewing contents of file '../idllib/ssw/allpro/apply_lock.pro'
;+
; Project     : SOHO - CDS     
;                   
; Name        : APPLY_LOCK
;               
; Purpose     : create a LOCK file 
;               
; Category    : Planning
;               
; Explanation : creates a LOCK file with the creation date saved in file.
;               
; Syntax      : IDL> apply_lock,lock_file
;    
; Examples    : 
;
; Inputs      : LOCK_FILE = lock file name (with path)
;               
; Opt. Inputs : None
;               
; Outputs     : None
;
; Opt. Outputs: None
;               
; Keywords    : ERR - message string
;               QUIET - turn off printing
;               EXPIRE - seconds after which LOCK file expires
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None.
;               
; History     : Version 1,  17-July-1996,  D M Zarro.  Written
;
; Contact     : DZARRO@SOLAR.STANFORD.EDU
;-            

pro apply_lock,lock_file,err=err,quiet=quiet,expire=expire,status=status

err='' & status=1
noisy=(1-keyword_set(quiet))

;-- valid input string filename?

if datatype(lock_file) ne 'STR' then begin
 err='Invalid input LOCK filename'
 goto,quit
endif

;-- create lock file

openw,lun,lock_file,/get_lun,err=error
if error then begin
 err='Write permission denied. No LOCK file created'
 goto,quit
endif

;-- insert creation time 

get_utc,utc,/ecs
user_id=get_user_id()
user_pid=get_pid('/idl',tty=user_tty,count=count)
if exist(expire) then expiration=float(expire) else expiration=0.
printf,lun,utc
printf,lun,expiration
printf,lun,user_id
printf,lun,user_pid
printf,lun,user_tty
close,lun & free_lun,lun

;-- allow GROUP write access to LOCK file

espawn,'chmod g+w '+lock_file,out

if noisy then message,'Created LOCK file - '+lock_file,/cont
status=1

quit:
if trim(err) ne '' then begin
 status=0 
 if noisy then message,err,/cont
endif

return & end