"SS_AutoCal_aph0 - Applies aph0 to the current element of an array.      "
"      If a first argument exists and it is 'array', aph0 is applied     "
"      at celem=1, and if celem>1 aph0 is applied to the element with the"
"      largest previously-phased peak,  measured in av mode.              "

$mode=''
if ($#>0) then 
   $mode=$1
endif 

$ok=0
if ($mode='array') then 
   select(celem) av peak:$ht
   if (celem=1) then r2=0 endif 
   if (($ht>r2)or(celem=1)) then 
      r1=celem 
      r2=$ht
   endif
   select(r1) 
   ph aph0:$ok
else 
   select(celem)
   aph0:$ok 
endif
return($ok)
