#!/bin/sh
#
# Name: fitsverify_delivery
#
# Description: Runs a FITS-format verifier against all the *.fits files in
#              the current directory, to ensure that no serious FITS errors
#              are present in the files.  The opus_fitsverify tool is used
#              for this purpose, run in a mode to only flag SEVERE errors.
#
# Called by:   deliver_cdbs.s
#
# Returns: 0 = if no errors were found in the FITS files
#          1 = if errors were found
#
#--------------------------------------------------------------------------
echo "starting fitsverify_delivery"
date
#
# Have to use OPUS FITS verifier on Linux (Farris version does not exist)
# (the OPUS version is a slight-modified version of the CFITSIO verifier).
# The -s option only flags SEVERE errors, which makes it more compatible
# with the results from the Farris version.
#
opus_fitsverify -s *.fits > fitsverify.out
if [ `grep -i 'ERRORS were encountered' fitsverify.out | wc -l` -gt 0 ]
then
   echo "errors in fitsverify"
   echo "see output file fitsverify.out"
   exit 1
else
 if [ `grep -i 'WARNINGS were encountered' fitsverify.out | wc -l` -gt 0 ]
 then
   echo "warnings in fitsverify"
   echo "see output file fitsverify.out"
   exit 0
 else
   echo "no errors or warnings reported by fitsverify"
   echo "created output file fitsverify.out"
   exit 0
 fi
fi
