	PRO archive_ck, path, range=range, xbd_path=xbd_path, $
		filename=filename, filesize=filesize, output=output
;	------------------------------------------------------------------
;+							5-May-94
;	NAME: archive_ck
;	Purpose: Check an archive copy for completeness.  It checks the 
;		file names to ensure that all files were copied and it 
;		ensures that the file sizes are correct.
;		Default is to do both checks.
;	Calling Sequence:
;		badfiles = archive_ck(path, [filename=filename,
;			filesize=filesize, output=output, xbd_path=xbd_path]
;
;	where: 
;		badfiles 	is a list of files missing files or
;				files with incorrect sizes.
;               ''		null string indicates NO bad files found!
;		'-1'		-1 string indicates possible error in that
;				there were NO file found in the given path.
;	INPUT:
;		path		full path of archive to check.  eg.
;				path='/yd1/feb93/'
;		range		first and last valid fileid to check
;				for a range of archive files. eg.
;				range=['930208.1324','930212.1856']
;	option not available yet...
;		weeks		list of archive weeks to check found
;				in the path. eg. weeks=['93_07','93_08']
;	Optional Inputs:
;		DEFAULTS to checks of filenames and filesizes:
;		filename	Only check that all files were copied.
;		filesize	Only check files sizes of copied files.
;	The following options not available yet:	
;               output		Write the names of the missing or bad
;				files to a file.
;		xbd_path	specify the path to the "xbd" files if 
;				they are located in a non-standard dir.
;	History:
;		written 5-May-94, gal.
;-
; 	-----------------------------------------------------------------
	
	if (n_elements(filename) eq 0) and (n_elements(filesize) eq 0) then begin
	  filename = 1 & filesize = 1	  
        endif else begin
	  if (n_elements(filesize) eq 0) then filesize=0
	  if (n_elements(filename) eq 0) then filename=0
	endelse

	  cd, '', current= olddir	;save current dir

	  afiles = findfile(path)	;check path and get list of filenames
	  if (afiles(0) eq '') then begin
	    print, "No files found on Archive directory: ", path
	  endif else begin
	    cd, path
	  if (n_elements(range) ne 0) then begin
	    files = gen_file_id(range=range,/filename,/nocba)
	  endif

	  asizes = file_stat(files,/size)		;get online sizes
	  if (filename) then begin
;	    if an ele. of asizes is 0 then empty file
;	    if an ele. of asizes is -1 then the file was not found.
            fn_not = where(asizes eq -1, nnot)
	    if (nnot gt 0) then begin	;found some missing files
	      Print, "List of missing files:"
	      print, files(fn_not)
;	      clean this with say 10 per line... w/mod
	    endif
	  endif

	  if (filesize) then begin
	    files_sizes = get_afile_size(files)	;get predicted sizes
	    size_prob = where( abs(files_sizes - asizes), nprob )	
						;list of non-matching
						;file sizes
	    if (nprob gt 0) then begin
	      print, "List of files with an incorrect size:"
	      print, files(size_prob)
	    endif
	  endif
          cd, olddir			;return to olddir
	endelse

	END
