Report a list of the DPR.CATG
, DPR.TECH
and DPR.TYPE
keywords from FITS frames.
Just copy the script into the directory of frames and run:
sh report_fits_keywords_for_directory.sh .
#!/bin/bash | |
# SET PATH | |
PATH=:/usr/local/bin/:/usr/bin/:/Library/Frameworks/Python.framework/Versions/2.7/bin/:/bin/ | |
VERSION=0.1 | |
display_usage() { | |
echo "Usage: | |
${0##*/} [options] <directory> | |
-k|--keep keep original files (copy instead of rename files) | |
-h|--help show this message | |
-v|--version show version number" | |
} | |
## DEFAULT OPTIONS & VARIABLES | |
keep=0 # KEEP ALL BYPRODUCT FILES (USE FOR DEBUGGING) | |
numberArguments=1 # MINIMUM NUMBER OF COMMAND-LINE ARGUMENTS REQUIRED | |
# COLLECT CL-ARGUMENTS & PARSE OPTIONS | |
args=( "$@" ) | |
while [[ $# > 0 ]] | |
do | |
key="$1" | |
case $key in | |
-h|--help) | |
display_usage | |
exit 0 | |
shift | |
;; | |
-v|--version) | |
echo "${0##*/} version $VERSION" | |
exit 0 | |
;; | |
-k|--keep) | |
keep=1 | |
delete=($key) | |
args=( ${args[@]/$delete/} ) | |
shift | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
shift | |
done | |
# IF LESS THAN THE REQUIRED ARGUMENTS SUPPLIED, DISPLAY USAGE | |
if [ ${#args[@]} -lt $numberArguments ] | |
then | |
display_usage | |
exit 1 | |
fi | |
## assign cl-arguments to varibale names | |
directory=${args[0]} | |
echo "| FILENAME | DPR.CATG | DPR.TECH | DPR.TYPE |" | |
find $directory/*.fits | while read fitsfile; do | |
filename=$(echo $fitsfile | perl -pe "s/.*\///g") | |
table="" | |
# PARSE ORIGINAL NAME FROM FITS FILE HEADERS | |
nameas=$(fitshdr $fitsfile | grep "HIERARCH ESO DPR CATG") | |
nameas=$(echo $nameas | perl -pe "s/'\s*\/ Observation category//g") | |
nameas=$(echo $nameas | perl -pe "s/HIERARCH ESO DPR CATG = '//g") | |
table="$table| $nameas " | |
nameas=$(fitshdr $fitsfile | grep "HIERARCH ESO DPR TECH") | |
nameas=$(echo $nameas | perl -pe "s/'\s*\/ Observation technique//g") | |
nameas=$(echo $nameas | perl -pe "s/HIERARCH ESO DPR TECH = '//g") | |
table="$table| $nameas " | |
nameas=$(fitshdr $fitsfile | grep "HIERARCH ESO DPR TYPE") | |
nameas=$(echo $nameas | perl -pe "s/'\s*\/ Observation type//g") | |
nameas=$(echo $nameas | perl -pe "s/HIERARCH ESO DPR TYPE = '//g") | |
table="| $filename $table| $nameas |" | |
echo $table | |
done |