#!/bin/csh
#
#Program for processing IMEXAMINE logs.
#Generates "imex.pars" with average sky, sigma
#and fwhm for each image, and files containing
#the coordinates of the examined stars
#Note: The file should only contain output
#from the "m" and "a" keys. You can't cicle the
#the keys in the same image, ie. aaammm or mma
#are valid sequences but aama or mama are not.
#
#Usage:  processimex.csh <imexaminelog>
#Author: Andre' Moitinho
# 
awk '{						\
if ($0 ~/M67/) 		{		\
   if (n > 0) 					\
   printf("%6s %5.1f %4.1f %4.1f\n", 		\
   nam, sky/nm, sig/nm, fwhm/na) > "imex.pars";	\
   nam=substr($3,1,10); n++; next} 		\
if ($0 ~/STDDEV/){m=1; nm=0;a=0; sky=0; 	\
		  sig=0; next}			\
if ($0 ~/DIRECT/){m=0; na=0; a=1; fwhm=0; next}	\
 if (m!=0) {sky+=$3; sig+=$5; nm++; next}	\
 if (a!=0) {fwhm+=$15; na++; 			\
	    print $1, $2 > nam ".coords"}	\
} END { printf("%6s %5.1f %4.1f %4.1f\n", 	\
nam, sky/nm, sig/nm, fwhm/na) > "imex.pars"}' $1
