	function prep_dat, dpath, cdmax, archdir, mvfiles, logdiscna, $
		dest=dest, select=select
;	--------------------------------------------------------------
;+							24-May-95
;	Name: prep_dat
;
;	Purpose: prep. weekly log file data (eg sfd) for CD rom writes.
;
;	Parameters:
;
;		dpath		path to data
;		cdmax		total space available on CD for data
;		archdir		returned archive dir. for ydb files.
;		mvfiles		list of files to move to /cdr_base
;		logdiscna	String with disc name, etc. for logging
;		dest		destination for CD
;		select		not used yet.
;
;       History: 26-May-95, GAL, written
;                26-Mar-96, GAL, mod for modvolume_inf.
;                12-Jan-97, PGS, changed value used for 'MB' to: 1048576.  
;-
;	----------------------------------------------------------------


;	-------------------------------------------
;	Setup Parameters:
;	-------------------------------------------
	volfn = '/sxt8data0/cdr_ydb/volume.inf'
	cd, current=default
	nos = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o']

; ***** 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, pre=pre)


;	--------------------------------------------------
;	Use prefix to find the files to be archive
;	--------------------------------------------------
;	determine type of weekly file?: assume sfd for now.
	if (n_elements(pre) eq 0) then pre = 'sfd'
	prep = pre+'*'

;	Check the dpath and get full filenames:
	if (n_elements(dpath) ne 0) then begin	; check dpath
	  fn = concat_dir(dpath,prep)
	endif else fn = prep

	nfiles = file_info(fn, finfo)
	fullnames = findfile(fn)		; get the fullnames for mv

	
	if (nfiles eq 0 ) then begin		; Check for No files
	  print, 'No files found!'
	  print, 'looked in dir: ', fn
	  return, 0			; return failure
	endif

;	---------------------------------------------
;	Compute total size of data to be CD-archived
;	---------------------------------------------
	iyr = strmid(finfo(0).filename,0,5)	; init yr check
	j = 0					; real counter

	for i=0, nfiles-1 do begin		; loop thur all files
	  if ( (total(finfo(0:i).size/1048576.) le cdmax) AND $
		(strmid(finfo(i).filename,0,5) eq iyr) ) then begin
	    tot = total(finfo(0:i).size/1048576.)
	    print, finfo(i).filename, tot
	    if (j eq 0) then begin
	      mvfiles = fullnames(i)
	      logstnams = strmid(finfo(i).filename,3,5)	; init log of names
	      savtot = tot
	      j = j+1
	    endif else begin
	      mvfiles = [mvfiles, fullnames(i)]
	      logstnams = [logstnams, strmid(finfo(i).filename,6,2)]
	      j = j+1
	      savtot = tot
	    endelse
	  endif
	endfor

	ilast = j			; save last file index


;	Test for free space and Adding another file:
	if (pre eq 'sfd') then begin	; test special cases
	  if ((savtot le (cdmax-100.)) AND (nfiles eq j) ) then begin
	    print, 'There maybe enough free space on the CD for ONE more file.'
	    ans = 'y'
	    input, 'Do you wish to continue?', ans, ans
	    if (strupcase(ans) ne 'Y') then return, 0
	  endif
	endif


	return, 1			; success

	END
