fast4fix (version 1.1)
You can also look at:
#! /usr/bin/ksh
##############################################################################
#
# SYNTAX: fast4fix event_file
#
# DESCRIPTION: Occasionally ASCA will be switched to FAST mode before it
# DESCRIPTION: is switched out of 4CCD mode,
# DESCRIPTION: this results in a funny state where the spacecraft
# DESCRIPTION: thinks it is using 4CCDs when it is really using two.
# DESCRIPTION: This script fixes this problem by taking an event file
# DESCRIPTION: and changing
# DESCRIPTION: certain keywords to reflect the true state of the instrument.
# DESCRIPTION: <P>
# DESCRIPTION: This was originally an STOOL, but it was converted to
# DESCRIPTION: a processing utility script after the switch to FTOOLS 4.0
# DESCRIPTION: on 7/7/97 in order to cope with the new meaning of the FTOOLS
# DESCRIPTION: environment variable.
# DESCRIPTION: <P>
# DESCRIPTION: The original STOOL was written by
# DESCRIPTION: Edward A. Pier 2/2/96 (following the suggestions of Koji Mukai)
#
# VERSION: 1.1
#
# HISTORY: 0.0 -> 1.0 7/21/97
# HISTORY: Supplied a missing close parenthesis.
# HISTORY:
# HISTORY: 1.0 -> 1.1 12/22/97
# HISTORY: Fixed a problem when the file to be fixed was unreadable.
# HISTORY: That part of the code had not been "util"-ized.
# HISTORY: Explicitly specifies extension in dum_table call,
# HISTORY: plus a number of other modifications to make this actually work.
# HISTORY: The previous version was not fully tested.
#
###########################################################################
#DEBUG=1
###########################################################################
###########################################################################
##
## Main Script
##
###########################################################################
###########################################################################
file=$1
if [ ! -r "$file" ]; then
##################
# File unreadable
##################
$UTIL/exception $0 2 "Can't open $file"
exit 0
fi
#################################################
# Check for DATAMODE = FAST and S[0/1]CCDMOD = 1
#################################################
datamode=$($UTIL/read_fits_keyword $file[0] DATAMODE )
inst=$($UTIL/read_fits_keyword $file[0] INSTRUME )
inst=${inst##SIS}
ccdmod=$($UTIL/read_fits_keyword $file[0] S${inst}CCDMOD )
#####################
# Check for validity
#####################
if [ "$datamode" != "FAST" -o "$ccdmod" == "1" ]; then
#####################################################
# Not FAST mode or in 1 CCD mode, exit with status 0
#####################################################
exit 0
fi
############################################################################
# If the code gets to here, the file is in a messed up 2 or 4 CCD FAST mode
# and must be fixed
############################################################################
$UTIL/log_entry "Fixing FAST mode file $file"
ccd=$($UTIL/dump_table $file[1] CCDID |uniq )
ccd=$(echo $ccd )
count=$(echo $ccd |wc -w )
if [ $count -ne 1 ]; then
$UTIL/exception $0 2 "Not all events in $file are on the same chip"
exit 0
fi
###################
# Fix the keywords
###################
###############
# S[0/1]CCDMOD
###############
$UTIL/add_fits_keyword $file[0] S${inst}CCDMOD 1
###############
# S[0/1]CCDPOW
###############
keyword="S${inst}CCDPOW"
case "$ccd" in
0) value="'1000'" ;;
1) value="'0100'" ;;
2) value="'0010'" ;;
3) value="'0001'" ;;
*) $UTIL/exception $0 2 "$ccd invalid CCD chip"
exit 0
;;
esac
###################
# Debugging output
###################
if [ -n "$DEBUG" ]; then
echo ${0##*/}: ccd=$ccd
echo ${0##*/}: keyword=$keyword
echo ${0##*/}: value=$value
fi
$UTIL/add_fits_keyword $file[0] $keyword $value
###############
# S[0/1]CCDLST
###############
keyword="S${inst}CCDLST"
value="${ccd} ${ccd} ${ccd} ${ccd}"
###################
# Debugging output
###################
if [ -n "$DEBUG" ]; then
echo ${0##*/}: keyword=$keyword
echo ${0##*/}: value=$value
fi
$UTIL/add_fits_keyword $file[0] $keyword "$value"
################################
# TIMEDEL in extensions 0 and 1
################################
$UTIL/add_fits_keyword $file[0] TIMEDEL 4.0
$UTIL/add_fits_keyword $file[1] TIMEDEL 4.0
####################################################
# Add a HISTORY comment to record what has happened
####################################################
echo "HISTORY ASCA was switched to FAST mode before it was switched to 1" \
"CCD mode." >comment.tmp
echo "HISTORY This left the spacecraft in a funny state." >>comment.tmp
echo "HISTORY Data was taken in FAST mode with one CCD chip per SIS," \
>> comment.tmp
echo "HISTORY but there there is no guarantee that it is the chip you want." \
>> comment.tmp
echo "HISTORY To recover the data, the following keywords have been" \
>> comment.tmp
echo "HISTORY updated in processing:" >>comment.tmp
echo "HISTORY S${inst}CCDMOD, S${inst}CCDPOW, S${inst}CCDLST," \
"and TIMEDEL" >>comment.tmp
$UTIL/setup_parfile $FTOOL/fmodhead.par infile=${file}[0] \
tmpfil=comment.tmp
$FTOOL/fmodhead >stdout.log 2>stderr.log
$UTIL/ftool_test fmodhead $? $0 2 stdout.log stderr.log
rm -f comment.tmp
exit 0