	PRO cp_fns, list, fdir, tdir, mv=mv, mach=mach, acc_sw=acc_sw, $
			qdebug=qdebug
;	----------------------------------------------------------
;+							14-May-93
;	NAME: cp_fns
;
;	PURPOSE: copy files given in the input list from "fdir" to
;		"tdir" after setting default to the "to directory".
;	
;	Calling Sequence:
;		cp_fns, file_list, fdir, tdir, 
;			[mv=mv, mach=mach, acc_sw=acc_sw ]
;
;	Input: 
;		list		file_list: list of file(s) to copy
;				passing *930513.1200 is ok.
;		fdir		from_dir: One of the "week_on" directories
;				(eg. '93_12' or '93_14a' are ok)
;		tdir		to_dir: target directory for copy.
;				(eg. '/yd13/mo_a' or '/yd13/mo_b')
;	Optional Input: 
;		mv 		To copy via MV command instead of cp.
;		mach		To copy from another mach via "rsh"
;		acc_sw		account to use on other mach.
;
;	History: written 6-May-93.
;		added options for "rsh" copy
;		 2-Jun-93 (MDM) - Added command to remove the CBA files after
;				  a copy is done (for cases where copy is done 
;				  from the REFA catchup week directory)
;		 2-Feb-94 (SLF) - different rsh for ultrix and others
;                                 file_delete replace spawn rm
;		 4-Feb-94 (SLF) - use rsh.pro
;               25-Jun-94 (SLF) - call yo_file_check to verify copies
;	--------------------------------------------------------
;-
	if (strpos(fdir, '_', 0) ne -1) then begin	;valid online dir
	  from_path = wk_online(fdir) 		;path to on-line dir.	
	endif else begin
	  print, 'Error: invalid input directory name: ', fdir
	  return
	endelse

	tpath = concat_dir(tdir, '.')

        copy = 'cp '
	IF keyword_set(mv) then copy = 'mv '

;       slf - verify integrity of source (mag) and destination files (mo)
        sfiles=file_list(from_path,strtrim(list,2))
        dfiles=file_list(tpath,strtrim(list,2))

        message,/info,"Checking integrity of input files...
        ys_file_check,sfiles, badfiles, all=all, status=status

        if not all then begin
           mess="Problem with one or more input files, aborting..."
           message,/info,mess
           prstr, badfiles
           mail,/self,[mess,'',badfiles],subj="mk_mo - bad soure files"
           return
        endif

	IF KEYWORD_SET(mach) THEN BEGIN		;do copy via "rsh"
	  for i=0, n_elements(list)-1 do begin
	    cp_cmd = copy+from_path+strtrim(list(i),2)+' '+tpath
	    print, 'Copying Files on '+strtrim(mach,2)+': ', $
			from_path+strtrim(list(i),2)
	    if i eq 0 then print, 'cp_cmd(0): ', cp_cmd	    
            if (not keyword_set(qdebug)) then $
	       rsh,mach,cp_cmd,user='mocreate',/null
            file_delete,concat_dir(tdir, 'cba*')
	  endfor
	ENDIF ELSE BEGIN
	  for i=0, n_elements(list)-1 do begin
	    cp_cmd = copy+from_path+strtrim(list(i),2)+' '+tpath

	    print, 'Copying Files: ', from_path+strtrim(list(i),2)
	    if i eq 0 then print, 'cp_cmd(0): ', cp_cmd
	    if (not keyword_set(qdebug)) then spawn, cp_cmd
	  endfor
	ENDELSE

        message,/info,"Checking integrity of destination files...
        ys_file_check,dfiles, badfiles, all=all, status=status
        if not all then begin
           mess="Problem with one or more files during mo write"
           message,/info,mess
           prstr,badfiles
           mail,[mess,'',badfiles],/self,subj="mk_mo - bad mo creation"
        endif

        return
	END

	
