	function prep_week, dpath, cdmax, archdir, mvfiles, logdiscna, $
		dest=dest, rdtap_script = rdtap_script, $
		weekid = weekid
;	----------------------------------------------------------------
;+							14-June-95
;	Name: prep_week
;	
;	PURPOSE: prep Yohkoh archive tape data for a CD archive.
;	
;		dpath 	if data is already on disk this is the path to it.
;		cdmax	max. size of archive
;		archdir	Returned archive dir. name for weekly files.
;		mvfiles	Returned list of files to mv to /cdr_base and archive
;			when tape is used this list comes from xbd files.
;		logdiscna	Ret: String with disc name, for logging.
;		dest	Input: destination for CD, used to build logging string
;		rdtap_script	String-array with commands for dumping tape
;		weekid	Input: tape Archive week to dump.
;		
;	History: written, Sep 95, GAL
;		26-Mar-96, GAL, mod for modvolume_inf.
;
;-
;	----------------------------------------------------------------

;       -------------------------------------------
;       Setup Parameters:
;       -------------------------------------------
        volfn = '/sxt8data0/cdr_week/volume.inf'
	stage_disk = '/sxt8data4/stage_a1'	; stage area 1

; ***** need to move info updat up for finding files and new move...
;       ----------------------------------------------------
;       update the volume.inf file and define archive dir.
;       ----------------------------------------------------

	volstat = modvolume_inf( volfn, dest, logdiscna, archdir) 

;	----------------------------------------------------------
;	Is this a big week with an archive size of > 650Mb?
;	----------------------------------------------------------
	if (n_elements(weekid) eq 0) then weekid = archdir
	if (yo_arch_size(weekid) gt cdmax) then big_week =1	; yup


;	----------------------------------------------------------
;	Has the data been staged to disk (are dpath or flist defined)?
;	Determine Archive name or input tape name, ...
;	----------------------------------------------------------
	if (n_elements(dpath) eq 0) then begin
	  tape = 1			; Yes, dump from tape 1st
	endif else tape =0  		; data is online
;					; assume its on stage_disk?????

;	If not, dump data from tape?
	if (tape) then begin		; Need to Dump Archive Tape
;	  enter device number
	  dev=3
	  print, "Place tape into tape device"
	  input, "Enter the tape device # ",dev,dev
	  ans = ''
	  input, "Hit return when ready to read tape", ans, ans
	  rdtap,def_tapd(dev), prefix=['ada','bda','hda','sfr','spr','wda'], $
	 	dpath = stage_disk, /alpha, /noexe, rdtap_script=rdtap_script
	  clean = 'rm -fr '+ stage_disk+'/*'
;	stop,'ck rdtap_script:'
	  rdtap_script = [clean, rdtap_script]	; clean area 1st


;	  Determine tape name if not given:
	  if (keyword_set(weekid) ne 1) then begin
	    weekid = archdir		; use archdir from modvolume
	  endif
	  if (strlen(weekid) eq 5) then weekid = weekid+'a'

;	  Determine size of dataset from xbd file and check against cdmax,
;	  weekfiles(/xbd,/high)	;list of latest files
	  xbdlist = weekfiles(/xbd,/high)	; Get list of highest
	  break_file,xbdlist,bdisk,bdir,bfn
	  ixbd = where(strmid(bfn,3,6) eq weekid)
	  xbd = xbdlist(ixbd)			; the most recent file
;	  xbd = '$DIR_GEN_XBD/xbd'+weekid+'.01'	; help sam software to
						; ret. last vers.
	  rd_tapdir, xbd(0), hdr, drecs		; get tape info
	  tapename = string(hdr.tapename)	; Full name for logging
	  
	  	  
;	  Generate file list
	  prefix = PrefixCk(/noobs)       	; ck & ensure standard    
	  prefix = prefix(where(prefix ne 'cba')); no cba
	  npf= N_ELEMENTS(prefix)        	; number of file prefixes
          nid= N_ELEMENTS(drecs)-1       	; number of file ids-obs

          files = STRARR(npf*nid)
          FOR i=0, npf-1 DO BEGIN
            files(i*nid) = prefix(i) + STRING(drecs(1:nid).fileid)
          ENDFOR
	  good = ck(files, drecs)	; get rid of 0 byte files
	  files = files(good)
	  mvfiles = stage_disk +'/'+ files	; list of files to move

	  fn_sz = get_afile_size(files,hdr=hdr,drecs=drecs)
	  mb = 1.024e6
	  tarch_sz = total(fn_sz)/mb		; in Mb
	  if (tarch_sz gt cdmax) then begin	; Problem, user picked
						; wrong tape for now...
;	    check the size of data and compress if necessary and recheck
	    print, 'Size of archive exceeds CD max! Archive size = ', tarch_sz
	    print, 'Need to call SFR Compression Routine'
; must dump tape 1st
	    sfr = files(where(strmid(files,0,3) eq sfr)	)
	    comp_sfr_arch, sfr, tarch_sz, cdmax, success
	    if (success) then begin
		stop,'chk sizes of new archive'
	    endif else begin
		print,'unable to compress enough'
		return, 0		; failed compress
  	    endelse
	  endif else begin
	    print,'-----------------------------------------'
	    print,'  CD Archive size is ', strtrim(tarch_sz,2),'Mb'
	    print,'-----------------------------------------'
	  endelse
	endif 

	return, 1			; success
	END


