Commit f09cc342 authored by David Tosolini's avatar David Tosolini
Browse files

Update checkfits.sh

E' stato aggiunto del codice per usare uno script di astropy-pyfits chimato fitscheck.
La modifica scrive in tutti i nuovi files.fits le keywords CHECKSUM e DATASUM
parent ce6b597a
Loading
Loading
Loading
Loading
+361 −216
Original line number Diff line number Diff line
@@ -2,24 +2,35 @@

#: Title	: checkfits.sh
#: Date		: 2014/10/28
#: Author	: "Marco De Marco" <demarco@oats.inaf.it>
#: Version	: 1.0
#: Author	:"David Tosolini" david.tosolini@inaf.it /"Marco De Marco"
#: Version	: 2.0
#: Description	: Fits verification and proccessing script

# ===========================================================================

#Tools paths

# --------------------------------------------------------------------------

VERIFY_TOOL="/usr/local/bin/fitsverify"
LISTHEAD_TOOL="/usr/local/bin/listhead"
MODHEAD_TOOL="/usr/local/bin/modhead"
FITSCHECK_TOOL="/usr/bin/fitscheck"

# ===========================================================================

if [ "$1" == "CHECK" ]; then

# --------------------------------------------------------------------------
        #: Section	: CHECK
        #: Parameter	: none
        #: Response	: CHECK OK
        #: 		: CHECK FATAL
        #: Description	: Check availability of script tools
# ===========================================================================

        # 1. Check fitsverify tools

	#Check fitsverify tools
        CHECK_STRING="conform to the FITS format"

        res=$($VERIFY_TOOL 2>&1)
@@ -30,7 +41,9 @@ if [ "$1" == "CHECK" ]; then
                exit 0
        fi

	#Check listhead tools

        # 2. Check listhead tools

        CHECK_STRING="Usage: listhead filename"

        res=$($LISTHEAD_TOOL 2>&1)
@@ -41,7 +54,9 @@ if [ "$1" == "CHECK" ]; then
                exit 0
        fi

	#Check modhead tools

        # 3. Check modhead tools

        CHECK_STRING="Usage: modhead filename"

        res=$($MODHEAD_TOOL 2>&1)
@@ -52,16 +67,35 @@ if [ "$1" == "CHECK" ]; then
                exit 0
        fi


        # 4. Check fitscheck tools
        CHECK_STRING="Usage: fitscheck"

        res=$($FITSCHECK_TOOL 2>&1)

        check=$(echo $res | grep "$CHECK_STRING" | wc | awk '{print $1}')
        if [ "$check" -lt "1" ]; then
             echo "CHECK FATAL"
             exit 0
        fi

        # if 1.2.3.4. are ok then the Section CHECK gives "CHECK OK" output

        echo "CHECK OK"
        exit 0

# ===========================================================================

elif [ "$1" == "VALID" ]; then

# ---------------------------------------------------------------------------
        #: Section	: VALID
        #: Parameter	: file path
        #: Response	: VALID OK
        #: 		: VALID IGNORE
        #: Description	: Check file name compliance
# ===========================================================================


        file=$2
        file_name=${file##*/}
@@ -81,14 +115,19 @@ elif [ "$1" == "VALID" ]; then
        echo "VALID OK"
        exit 0

# ===========================================================================

elif [ "$1" == "VERIFY" ]; then

# ---------------------------------------------------------------------------
        #: Section	: VERIFY
        #: Parameter	: file path
        #: Response	: VERIFY OK
        #: 		: VERIFY WAIT
        #: 		: VERIFY FATAL
        #: Description	: Check file compliance to fits format
# ===========================================================================


        file=$2

@@ -131,8 +170,12 @@ elif [ "$1" == "VERIFY" ]; then
        echo "VERIFY OK"
        exit 0

# ===========================================================================

elif [ "$1" == "PREPROCESS" ]; then

# ---------------------------------------------------------------------------

        #: Section	: PREPROCESS
        #: Parameter	: file path
        #: 		: ingestion result [OK, WAIT, FATAL]
@@ -140,25 +183,42 @@ elif [ "$1" == "PREPROCESS" ]; then
        #: 		: PREPROCESS FATAL
        #: Description	: Apply preprocessing before ingestion


# ===========================================================================

        file=$2
        file_name=${file##*/}

        verified=$3



# ---------------------------------------------------------------------------



        #Check verified parameter value

        if [ "$verified" != "OK" -a "$verified" != "WAIT" -a "$verified" != "FATAL" ]; then
                echo "PREPROCESS FATAL"
                exit 0
        fi


# ---------------------------------------------------------------------------

        #Pre processing for verified OK files

        if [ "$verified" == "OK" ]; then

                #Change file ownership
                /usr/bin/sudo -n /bin/chown controls:controls $file

                #Change file and permission before processing
                /usr/bin/sudo -n /bin/chmod u+rw $file

# ---------------------------------------------------------------------------

                #Check regular expression for luci files
                if [[ "${file_name,,}" =~ ^.*luci.*\.(fits|fit|fts).*$ ]]; then

@@ -174,6 +234,7 @@ elif [ "$1" == "PREPROCESS" ]; then
                                exit 0
                        fi


                        #if fits file not exists -> fatal
                        if [ ! -f $file ]; then
                                echo "PREPROCESS FATAL : file not exists"
@@ -191,8 +252,11 @@ elif [ "$1" == "PREPROCESS" ]; then
                        if [[ $gratorde =~ "'not used'/" ]]; then
                                $MODHEAD_TOOL $file GRATORDE 0.0 &>/dev/null
                        fi

                fi #luci files

# ---------------------------------------------------------------------------

                #Check regular expression for irt files
                if [[ "${file_name,,}" =~ ^.*irt.*\.(fits|fit|fts).*$ ]]; then

@@ -208,6 +272,7 @@ elif [ "$1" == "PREPROCESS" ]; then
                                exit 0
                        fi


                        #if fits file not exists -> fatal
                        if [ ! -f $file ]; then
                                echo "PREPROCESS FATAL : file not exists"
@@ -226,15 +291,80 @@ elif [ "$1" == "PREPROCESS" ]; then
                                        $MODHEAD_TOOL $file DATE_OBS "'$date_obs'" &>/dev/null
                                fi
                        fi



                fi #irt files


# ---------------------------------------------------------------------------


        fi #verified ok files


# ---------------------------------------------------------------------------

        #: Sub Section	: PREPROCESS - Wright CHECKSUM and DATASUM
        #: Parameter	: file path
        #: Response	: PREPROCESS OK
        #: 		: PREPROCESS FATAL
        #: Description	: Wrighting CHECKSUM and DATASUM in $file before moving it


# ===========================================================================


        file=$2
        file_name=${file##*/}


        #if fitscheck tools exists -> fatal
            if [ ! -x $FITSCHECK_TOOL ]; then
                echo "PREPROCESS FATAL : fitscheck tools not exists"
                exit 0
            fi


        #if listhead tools exists -> fatal
            if [ ! -x $LISTHEAD_TOOL ]; then
                echo "PREPROCESS FATAL : listhead tools not exists"
                exit 0
            fi


        #if fits file not exists -> fatal
            if [ ! -f $file ]; then
                echo "PREPROCESS FATAL : file not exists"
                exit 0
            fi


         new_file=$($FITSCHECK_TOOL -vf  $file )
         datasum=$($LISTHEAD_TOOL $file| grep DATASUM)
         datasum_value=$($LISTHEAD_TOOL $file| grep DATASUM|awk '{print $3}')
         checkdatasum=$(echo $datasum | grep DATASUM | wc | awk '{print $1}')



   if [ "$checkdatasum" -lt "1" ]; then
           echo "DATASUM is NOT recorded in $file"
           exit 0 ; else
           echo "DATASUM is recorded: $datasum_value"
    fi

# ---------------------------------------------------------------------------

        echo "PREPROCESS OK"
        exit 0


# ===========================================================================

elif [ "$1" == "POSTPROCESS" ]; then

# ---------------------------------------------------------------------------

        #: Section	: POSTPROCESS
        #: Parameter	: file path
        #: 		: ingestion result [OK, WAIT, FATAL]
@@ -242,37 +372,52 @@ elif [ "$1" == "POSTPROCESS" ]; then
        #: 		: POSTPROCESS FATAL
        #: Description	: Apply postprocessing after ingestion

# ===========================================================================

        file=$2
        file_name=${file##*/}

        verified=$3

        #Check verified parameter value

        if [ "$verified" != "OK" -a "$verified" != "WAIT" -a "$verified" != "FATAL" ]; then
                echo "POSTPROCESS FATAL"
                exit 0
        fi

# ---------------------------------------------------------------------------

        #Post process verified WAIT files
        if [ "$verified" == "WAIT" ]; then
                echo "Warning file: $file_name" | mutt -s "Pre process log" -- demarco@oats.inaf.it
        fi

# ---------------------------------------------------------------------------

        #Post process verified FATAL files
        if [ "$verified" == "FATAL" ]; then
                echo "Fatal file: $file_name" | mutt -s "Pre process log" -- demarco@oats.inaf.it
        fi


        echo "POSTPROCESS OK"
        exit 0

# ===========================================================================

else

# ---------------------------------------------------------------------------

        #: Section	: DEFAULT
        #: Parameter	: none
        #: Response	: UNKNOWN

# ===========================================================================

        echo "UNKNOWN"
        exit 0


fi