#! /bin/csh -f
#------------------------------------------------------
#This is a csh script for making median bias frames
#------------------------------------------------------
#
#       Created by Masami Ouchi
#               July 6, 1999
#       Revised by Masami Ouchi
#               March 15, 2000
#       Revised by Masami Ouchi
#               July 7, 2000
#------------------------------------------------------
#

# necessary files & programs
#
# bias.lis : list of bias images (OVERSCAN SUBTRACTED NAME!!)
# expmatchmcomb* : program for making a median frame of images
#

# parameters

#aquire a name of a list and a name of output image 

if ( $#argv != 2 ) then
    echo "Usage:" $0 " [bias.lis] [bias header name eg. H000601]" 
    exit 1
endif

if ( !(-r $1) ) then
    echo "mkbias.csh: Cannot open "$1": No such file or directory"
    exit 1
endif

set biaslist = $1
set header = $2

# make lists of each bias frame
awk '$1 ~/(si001s)+/ {print $0}' $biaslist > tmp1
awk '$1 ~/(si002s)+/ {print $0}' $biaslist > tmp2
awk '$1 ~/(si005s)+/ {print $0}' $biaslist > tmp3
awk '$1 ~/(si006s)+/ {print $0}' $biaslist > tmp4
awk '$1 ~/(w67c1)+/ {print $0}' $biaslist > tmp5
awk '$1 ~/(w6c1)+/ {print $0}' $biaslist > tmp6
awk '$1 ~/(w93c2)+/ {print $0}' $biaslist > tmp7
awk '$1 ~/(w9c2)+/ {print $0}' $biaslist > tmp8

# take the median of bias frames
expmatchmcomb tmp1 ${2}_mbias_si001s.fits
expmatchmcomb tmp2 ${2}_mbias_si002s.fits
expmatchmcomb tmp3 ${2}_mbias_si005s.fits
expmatchmcomb tmp4 ${2}_mbias_si006s.fits
expmatchmcomb tmp5 ${2}_mbias_w67c1.fits
expmatchmcomb tmp6 ${2}_mbias_w6c1.fits
expmatchmcomb tmp7 ${2}_mbias_w93c2.fits
expmatchmcomb tmp8 ${2}_mbias_w9c2.fits







