Viewing contents of file '../idllib/iuedac/iuelib/pro/cpychk.pro'
;****************************************************************************
;+
;*NAME:
;
;     cpychk
;
;*PURPOSE:
;
;     To check for existence of a file to be written.
;
;*CALLING SEQUENCE:
;
;     cpychk,file,cpy,/update,/qsupersede
;
;*PARAMETERS:
;
;     file (req) (i/o) (0,1) (s)
;          File(s) to check for.  The user may enter new file name(s) if
;          the update keyword is set.
;
;     cpy  (req) (i/o) (0,1) (i)
;          Flag(s):  0=the user does not wish to proceed with creating file.
;                    1=the user wishes to create the file regardless of the
;                      existence of file(s) of the same name(s).
;          CPY can be set ahead of time to indicate the default value of CPY.
;
;     update (key) (i) (0) (i)
;            If set, the user may enter new filenames.
;
;     qsupersede (key) (i) (0) (i)
;            If set, the program will query the user even if the current
;            operating system merely creates a new version number rather
;            than overwriting existing files.
;
;
;*SUBROUTINES CALLED:
;
;     platform (to get proper term for current operating system)
;
;*FILES USED:
;
;     This procedure does not open any files.
;
;*SYSTEM VARIABLES USED:
;
;     none
;
;*PROCEDURE:
;
;     For each file, a FINDFILE is done to check for pre-existing file with 
;     the same name.  If any are found, the user is asked if the new file
;     should be created anyway.  If the update keyword is set, the user can
;     enter a new name for each file.
;
;*MODIFICATION HISTORY:
;
;      6 Feb 95 LLT wrote.
;-
;*****************************************************************************
pro cpychk,file,cpy,update=update,qsupersede=qsupersede

npar=n_params(0)
if npar eq 0 then begin
   print,'CPYCHK,FILE,CPY,/update,/qsupersede'
   return
endif ;npar eq 0

parcheck,npar,2,'cpychk'

nfiles=n_elements(file)
ncpy=n_elements(cpy)

if ncpy lt nfiles then begin
   if ncpy eq 1 then cpy=replicate(cpy,nfiles) else cpy=replicate(1,nfiles)
endif ;ncpy ne nfiles

platform,0,copymes=copymes
if (not keyword_set(qsupersede)) and (copymes.present eq ' supersede ') $
   then return

for i=0,nfiles-1 do begin
    temp=findfile(file(i),count=nf)
    if (nf gt 0) then begin
       a=''
       print,temp(0)+' exists;'+copymes.present+'it?'
       if cpy(i) then options= '0=no, 1=yes (def): ' else $
                      options= '0=no (def), 1=yes: '
       if keyword_set(update) then options = $
          options + ' or enter new name (no quotes, with extension): '
       read,prompt=options,a
       a=strtrim(a,2)
       if (strpos(a,'.') lt 0) then begin
             if (a ne '') then begin
                yesno,a 
                cpy(i) = a
             endif
       endif else begin
             cpy(i) = 1
             file(i) = a
       endelse
    endif ; pre-existing file found
endfor ;i=0,nfiles-1

return
end ;cpychk.pro