#!/bin/sh
#
# Name: fitsverify_file_strict
#
# Description: Runs several FITS-format verifiers against a file
#              to ensure that no FITS errors
#              are present.  The opus_fitsverify tool is used
#              for this purpose, run in a mode to only flag most errors
#              (the "strict" version distinguishes this version from the more
#               lenient fitsverify mode) and
#              also the pyFITS "verify" function is used.
#
# Called by:   fitsverify
#
# Returns: 0 = if no errors were found in the FITS files
#          1 = if errors were found
#
#--------------------------------------------------------------------------
echo "starting fitsverify_file_strict for ${1}"
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 -e option flags most errors (the more lenient option is -s).
#
# NOTE: APPENDS to output file so that a multi-file run ends up with all
#       messages in the same place
#
opus_fitsverify -e ${1} >> 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"
   # stop right away
   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"
   # continue on
   #exit 0
 else
   echo "no errors or warnings reported by fitsverify"
   echo "created output file fitsverify.out"
   # continue on
   #exit 0
 fi
fi
#
# and now pyFITS verification, which has been proven to catch problems that
# opus_fitsverify does not
pyfits_verify.py ${1}
if test $? -ne 0
then
   echo "pyFITS verification FAILED."
   exit 1
else
   echo "pyFITS verification OK."
   exit 0
fi
