#!/bin/tcsh -f 

if ($#argv != 1) then
  echo "" 
  echo "Usage: $0 <section name>"
  echo ""
  echo "Example:  $0 return"
  echo "Example:  $0 b2"
  echo ""
  echo "Run this program from within the 'date' directory"
  echo "that contains the observations for the mesh."
  echo "Example: cd /mnt/raid/user/images/021215"
  echo ""
  echo "When the process is complete, copy the resulting file"
  echo "which is named 'telescoped.mesh' to the $TELHOME/archive/config"
  echo "directory of the telescope"
  echo ""
  echo "Example (1/2 meter): cp telescoped.mesh $TELHOME/archive/config"
  echo "Example (1 meter): rcp telescoped.mesh onem:$TELHOME/archive/config"
  echo ""
  echo "Important: Remember to remove the telescoped.mesh file BEFORE running mesh scan"
  echo "and make sure that only images taken without the mesh in effect exist in the directory"
  echo "when you run the program"
  echo ""
  exit 1
endif  
set ptf = "telescoped.mesh"
rm -f $ptf

foreach f (*/X_*_$1.fts)
 set t = "`fitshdr $f | grep CRVAL1`"
 if("$t" == "") then
	wcs -vw $f 
 endif 
 set r = "`fitshdr $f | grep AMDX0`"
 if("$r" == "") then 
 else 
    echo -n $f 
    echo -n " " 
    pterrors $f >> $ptf
    tail -1 $ptf
 endif

end

