pro valid_check, badfiles, len=len, size=size, name=name , $
	recover=recover	, logfile=logfile
;+
;   Name:valid_check
;
;   Purpose: validity checks - information/actions for mktap_prep
;
;   Input Parameters:
;      badfiles - caller defined list of bad files to signal
;
;   Keyword Parameters:
;      len, size, name - determine (index) action/message
;      recover - if set, auto action is taken and return to caller
;
;   History: slf, 4-mar-92
;
logging=keyword_set(logfile)
;
item=['len','size','name']
badname='_bad' + item + '_'				; for rename
;
warnings=['Illegal Name Length',	$	;len
	  'Pointer/Size Mismatch',	$	;size
	  'Illegal Name/Prefix',	$	;name
	  ''				]


case 1 of
   keyword_set(len): type=0
   keyword_set(size):type=1
   keyword_set(name):type=2
   else:message,/info,"Need at least one keyword switch"
endcase
;
if n_elements(type) eq 0 then type = n_elements(warnings)-1
;
messageopt=[	$
      'message,"Fatal Error: Correct probelem and restart "', $
      'message,/info,"Warning: Proceding with auto-recovery"']

messexe=messageopt(keyword_set(recover)) ; which action depends on cont

; signal error and recovery plan
if n_elements(badfiles) gt 0 then begin 
   print 
   warns='>> ' + badfiles + ' <<' + warnings(type) 
   prstr,warns
   if logging then src=mk_script(warns,name=logfile,/append)
   exestat=execute(messexe)
endif

;
;perform automatic action if you get this far  
message,/info,"Automatic Rename Started"
newnames=strcompress( $
	str_replace(badfiles,'.',badname(type)),/remove)
cmds='mv -f ' + badfiles + ' ' + newnames
for i=0, n_elements(cmds)-1 do begin     
   print,cmds(i)
   spawn,cmds(i)
endfor
if logging then src=mk_script(cmds,name=logfile,/append)
; 
return
end
