#!/bin/bash
#By Samuel George; samuel@star.sr.bham.ac.uk
#Mod:	  19-10-09
#original 18-10-09
#########################################################################
#Purpose: To organise FITS files such that they all have the extension fit and reader the header to create
#         lists of bias, dark and target frames. Eventually this is to link into pyphot.
#         http://www.krioma.net/pyphot.php
#Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument.
#DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.  
#Notes:	  Might need to change the cut character values depending on different headers 
#         (this is for the Wast Hills Apogee camera data)
#Mod 19-10-09: added the loop instead of listing the output.
##########################################################################
for i in *.FIT; do mv "$i" "${i/FIT}fit" ; done
for i in *.FITS; do mv "$i" "${i/FITS}fit" ; done
for i in *.fits; do mv "$i" "${i/fits}fit" ; done

#ls *.fit | grep "Bias\|bias" > biasframes.lis
#ls *.fit | grep "Dark\|dark" > darkframes.lis
#ls *.fit | grep -v "Bias\|bias" | grep -v "Dark\|dark"> targetframes.lis

FILES='*.fit'
for word in $FILES
do
   output=$(cut -c 1532-1536 $word | head -n 1)
   if [ "$output" = "Bias " ]; then echo $word >> biasframes.lis; fi
   if [ "$output" = "Dark " ]; then echo $word >> darkframes.lis; fi
   if [ "$output" = "Light" ]; then echo $word >> targetframes.lis; fi  
done




