pro add_pro, module, doc=doc, adderr=adderr,	$
	clobber=clobber,			$
	update=update,				$
        cat=cat,				$
	bcs=bcs, hxt=hxt, sxt=sxt, wbs=wbs, gen=gen, ucon=ucon
;
;+
;   Name: add_pro
;
;   Purpose: perform rudimentary checks on input idl module(s) and place it
;	     online if everything copecetic
;
;   Input Parameters
;      module - name of module(s) (including path) or directory containing
;	 	multiple modules to check
;
;   Calling Sequence:
;      add_pro, module [,/doc]
;
;-
tquiet=!quiet
case n_elements(module) of
   0: message,'No module name supplied!'
   1: begin
         mods=findfile(module + '*')
      endcase
   else: mods=module
endcase
pros=where(strpos(mods,'.pro') ne -1,count)
if count eq 0 then $
   message,'No pro files found' $
else mods=mods(pros)

; locate path to new software and backup versions
newdir=getenv('DIR_ATEST_NEWSW')
backdir=getenv('DIR_ATEST_BACK')


; define error words
namerr = 1 and 1 - (keyword_set(update))	; not error if update set
docerr = 2

adderr=lonarr(n_elements(mods))
plural=['is','s are']
for i=0, n_elements(mods)-1 do begin

   message,/info,'Processing Module: ' + mods(i)

;  ---------------- Name Conflict Check ----------------------------------
;  message,/info,'Checking for name conflict...'
   !quiet=1
   chk=path_sw(mods(i),/exact,/multi)
   !quiet=0
   if chk(0) eq '' then begin
;     message,/info,'No name conflict exists for module: ' + mods(i)
   endif else begin
      plur=plural(n_elements(chk) ge 1)
      if keyword_set(update) then $
         message,/info,'Update set - ignoring conflicts...' $
      else begin      
         message,/info,'Warning, name conflict for module: ' + mods(i)
         message,/info,'Conflicting online module' + plur + ':'
         prstr,chk
      endelse
      adderr(i) = adderr(i) or namerr
   endelse
;  -----------------------------------------------------------------------
;
;  ----------------- IDL Documentation Header Checks ---------------------
   message,/info,'Checking documentation header...'
   !quiet=1
   head=get1doc(mods(i))
   !quiet=0
   shead=size(head)
;  build error message
   headerr=''					; initialize 
   case shead(0) of
      0:headerr=[headerr,'No Header ']
      1: begin
	 if head.name    eq '' then headerr=[headerr,'No Name ']
	 if head.purpose eq '' then headerr=[headerr,'No Purpose ']
	 if head.bad_start     then headerr=[headerr,'Bad start delimitor ']
	 if head.bad_stop      then headerr=[headerr,'Bad stop  delimtor ']
      endcase
   endcase
;
   if n_elements(headerr) gt 1 then begin
      headerr=headerr(1:*) + 'Found'
      message,/info,'Problem with idl header'
      prstr,headerr
      adderr(i) = adderr(i) or docerr
   endif else begin
;      message,/info,'IDL header ok'
   endelse	

;  -----------------------------------------------------------------------

;  ----------------- All checks passed - place on line -------------------
   if newdir eq '' then message,'New Software Path not defined'
   if adderr(i) eq 0 then begin
      message,/info,'Verification checks completed, placing module online'
      ; 
      outmod=concat_dir(newdir,mods(i))
      if file_exist(outmod) then $
         newv=new_version(outmod,move=getenv('DIR_ATEST_BACK'))
      cpcmd='cp -p ' + mods(i) + ' ' + outmod
      spawn,cpcmd
   endif else begin
      message,/info,'Problem with module: ' + mods(i) + $
	 ', not placing on-line'
   endelse  
      
;  -----------------------------------------------------------------------

   print
endfor
;
!quiet=tquiet
return
end
