"*************************************************************************"
"macroupdatepars(directory,macro) - runs a user macro to fix desired      "
"                      parameters of all parameter sets and data in the   "
"                      specified directory. Argument 2 is the macro name. "
"                      example  macroupdatepars('/vnmr/parlib','mymacro') "
"*************************************************************************"
if ($# > 1) then 
   exists($2,'maclib'):$e
   if ($e < 0.5) then
      write('error','Update macro %s does not exist',$2)
      abort
   endif
else 
   write('error','Please supply update macro as argument #2')
   abort
endif
exists($1,'directory'):$e
if ($e < 0.5) then
   write('error','Directory %s does not exist',$1)
   abort
endif
getfile($1):$entrys
write('alpha','directory %s has %d entries',$1,$entrys)
$inode = 0
$filename = ''
$ext = ''
while ($inode < $entrys) do
   $inode = $inode + 1
   getfile($1,$inode):$filename,$ext
   if (($ext = 'fid') or ($ext = 'par')) then
      $path = $1 + '/' + $filename + '.' + $ext + '/procpar'
      exists($path,'file'):$e
   else
      $e = 0
   endif
   if ($e > 0.5) then
      write('alpha','  Entry %d: Update %s.%s',$inode,$filename,$ext)
      fread($path) 
      prune($path)  
      exec($2)
      fsave($path)
   else
      $notpar = $filename
      if ($ext <> '') then
         $notpar = $filename + '.' + $ext
      endif
      write('alpha','  Entry %d:  %s is not a parameter file',$inode,$notpar)
   endif
endwhile
