#!/usr/bin/ksh # # epo_magfile_append.ksh - Combine the XYZ and BDH magnetometer measurement # plots from the EPO GMAGS # ## Set the environment variables # . $HOME/software_dev/config/thmsoc_epo.config ## Function Definitions # function no_merge # Print warning if file merge cannot occur { echo "$$:" >> $LOGFILE echo "$$: WARNING: One or more of the following files were not found:" >> $LOGFILE echo "$$: $1" >> $LOGFILE echo "$$: $2" >> $LOGFILE if [[ -z $4 ]] then echo "$$: Cannot create file = $3" >> $LOGFILE else echo "$$: $3" >> $LOGFILE echo "$$: Cannot create file = $4" >> $LOGFILE fi } ## Move to the directory containg the EPO data # cd $EPO_HOME ## Set a counter (n) and then set a variable to the ## first school name in the SCHOOL array which was ## defined in the config file above # n=0 school=${SCHOOL[$n]} echo "$$:" >> $LOGFILE echo "$$:----------- Starting epo_magfile_append at $(date) ---------" >> $LOGFILE ## Check for lock file # if [[ -a $LOCKFILE ]] ; then echo "$$:" >> $LOGFILE echo "$$: A Append Process is currently active " >> $LOGFILE echo "$$: Quittin..................." >> $LOGFILE exit 0 fi echo $$ > $LOCKFILE # Now lets start looping through the schools # while [[ -n $school ]] do echo "$$: Starting processing for school = $school" >> $LOGFILE school_dir=$(echo $school | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/') chkStatus="" ############################################## ## Search for x, y, and z time series plots ## ############################################## # find ./${school_dir} -name ${school}_TS1_\* -mtime ${FIND_MTIME} > /tmp/ts1_files xyzTSstatus="" if [[ ! -s /tmp/ts1_files ]] then xyzTSstatus=1 chkStatus=1 fi ## .....and merge plots # echo "$$:" >> $LOGFILE echo "$$:......processing XYZ Time Series plots" >> $LOGFILE while [[ -s /tmp/ts1_files ]] do xmag_file_name=$(head -1 /tmp/ts1_files) date_string=$(echo $xmag_file_name | awk -F_ '{print $3 "_" $4}') path_string=$(echo $xmag_file_name | awk -F_ '{print $1}') ymag_file_name=$(echo "${path_string}_TS2_${date_string}") zmag_file_name=$(echo "${path_string}_TS3_${date_string}") b_file_name=$(echo "${path_string}_TStamp_${date_string}") xyzmag_file_name=$(echo $xmag_file_name |awk -F_ '{print $1 "_TS123_" $3 "_" $4}') if [[ ! -a $ymag_file_name || ! -a $zmag_file_name || ! -a $b_file_name ]] then no_merge $ymag_file_name $zmag_file_name $b_file_name $xyzmag_file_name else echo "$$:" >> $LOGFILE echo "$$: Merging files:" >> $LOGFILE echo "$$: $xmag_file_name" >> $LOGFILE echo "$$: $ymag_file_name" >> $LOGFILE echo "$$: $zmag_file_name" >> $LOGFILE echo "$$: $b_file_name" >> $LOGFILE echo "$$: New filename = $xyzmag_file_name" >> $LOGFILE /usr/local/bin/convert $xmag_file_name $ymag_file_name $zmag_file_name $b_file_name -append $xyzmag_file_name mysql_table=${school}_TS123 mysql_date=$(echo $date_string | awk -F_ '{print substr($1,5,4) "-" substr($1,1,2) "-" substr($1,3,2)}') mysql_time=$(echo $date_string | awk -F_ '{print substr($2,1,2) ":" substr($2,3,2) ":" substr($2,5,2)}') echo "$$: Updating MySQL database table $mysql_table......." >> $LOGFILE /home/thmsoc/software_dev/php/epo_cmdline_input.php $mysql_table $mysql_date $mysql_time $xyzmag_file_name echo "$$: ...........update complete. " >> $LOGFILE fi sed '1d' /tmp/ts1_files > /tmp/TS1_FILES mv /tmp/TS1_FILES /tmp/ts1_files done rm /tmp/ts1_files ############################################## ## Search for B, D, and H time series plots ## ############################################## # find ./${school_dir} -name ${school}_TSB_\* -mtime ${FIND_MTIME} > /tmp/tsb_files bdhTSstatus="" if [[ ! -s /tmp/tsb_files ]] then bdhTSstatus=1 chkStatus=1 fi ## .....and merge plots # echo "$$:" >> $LOGFILE echo "$$:......processing BDH Time Series plots" >> $LOGFILE while [[ -s /tmp/tsb_files ]] do bmag_file_name=$(head -1 /tmp/tsb_files) date_string=$(echo $bmag_file_name | awk -F_ '{print $3 "_" $4}') path_string=$(echo $bmag_file_name | awk -F_ '{print $1}') dmag_file_name=$(echo "${path_string}_TSD_${date_string}") hmag_file_name=$(echo "${path_string}_TSH_${date_string}") b_file_name=$(echo "${path_string}_TStamp_${date_string}") bdhmag_file_name=$(echo $bmag_file_name |awk -F_ '{print $1 "_TSBDH_" $3 "_" $4}') if [[ ! -a $dmag_file_name || ! -a $hmag_file_name || ! -a $b_file_name ]] then no_merge $dmag_file_name $hmag_file_name $b_file_name $bdhmag_file_name else echo "$$:" >> $LOGFILE echo "$$: Merging files:" >> $LOGFILE echo "$$: $bmag_file_name" >> $LOGFILE echo "$$: $dmag_file_name" >> $LOGFILE echo "$$: $hmag_file_name" >> $LOGFILE echo "$$: $b_file_name" >> $LOGFILE echo "$$: New filename = $bdhmag_file_name" >> $LOGFILE /usr/local/bin/convert $bmag_file_name $dmag_file_name $hmag_file_name $b_file_name -append $bdhmag_file_name mysql_table=${school}_TSBDH mysql_date=$(echo $date_string | awk -F_ '{print substr($1,5,4) "-" substr($1,1,2) "-" substr($1,3,2)}') mysql_time=$(echo $date_string | awk -F_ '{print substr($2,1,2) ":" substr($2,3,2) ":" substr($2,5,2)}') echo "$$: Updating MySQL database table $mysql_table......." >> $LOGFILE /home/thmsoc/software_dev/php/epo_cmdline_input.php $mysql_table $mysql_date $mysql_time $bdhmag_file_name echo "$$: ...........update complete. " >> $LOGFILE fi sed '1d' /tmp/tsb_files > /tmp/TSB_FILES mv /tmp/TSB_FILES /tmp/tsb_files done rm /tmp/tsb_files ############################################# ## Search for x, y, and z day series plots ## ############################################# # find ./${school_dir} -name ${school}_DS1_\* -mtime ${FIND_MTIME} > /tmp/ds1_files xyzDSstatus="" if [[ ! -s /tmp/ds1_files ]] then xyzDSstatus=1 chkStatus=1 fi ## .....and merge plots # echo "$$:" >> $LOGFILE echo "$$:......processing XYZ Day Series plots" >> $LOGFILE while [[ -s /tmp/ds1_files ]] do xmag_file_name=$(head -1 /tmp/ds1_files) date_string=$(echo $xmag_file_name | awk -F_ '{print $3 "_" $4}') path_string=$(echo $xmag_file_name | awk -F_ '{print $1}') ymag_file_name=$(echo "${path_string}_DS2_${date_string}") zmag_file_name=$(echo "${path_string}_DS3_${date_string}") tstamp_search=$(echo ${path_string}_TStamp_$(echo $date_string |awk -F_ '{print $1}')) b_file_name=$(ls -1 ${tstamp_search}* |tail -1) xyzmag_file_name=$(echo $xmag_file_name |awk -F_ '{print $1 "_DS123_" $3 "_" $4}') if [[ ! -a $ymag_file_name || ! -a $zmag_file_name || ! -a $b_file_name ]] then no_merge $ymag_file_name $zmag_file_name $b_file_name $xyzmag_file_name else echo "$$:" >> $LOGFILE echo "$$: Merging files:" >> $LOGFILE echo "$$: $xmag_file_name" >> $LOGFILE echo "$$: $ymag_file_name" >> $LOGFILE echo "$$: $zmag_file_name" >> $LOGFILE echo "$$: $b_file_name" >> $LOGFILE echo "$$: New filename = $xyzmag_file_name" >> $LOGFILE /usr/local/bin/convert $xmag_file_name $ymag_file_name $zmag_file_name $b_file_name -append $xyzmag_file_name mysql_table=${school}_DS123 mysql_date=$(echo $date_string | awk -F_ '{print substr($1,5,4) "-" substr($1,1,2) "-" substr($1,3,2)}') mysql_time=$(echo $date_string | awk -F_ '{print substr($2,1,2) ":" substr($2,3,2) ":00" }') echo "$$: Updating MySQL database table $mysql_table......." >> $LOGFILE /home/thmsoc/software_dev/php/epo_cmdline_input.php $mysql_table $mysql_date $mysql_time $xyzmag_file_name echo "$$: ...........update complete. " >> $LOGFILE fi sed '1d' /tmp/ds1_files > /tmp/DS1_FILES mv /tmp/DS1_FILES /tmp/ds1_files done rm /tmp/ds1_files ############################################# ## Search for B, D, and H day series plots ## ############################################# # find ./${school_dir} -name ${school}_DSB_\* -mtime ${FIND_MTIME} > /tmp/dsb_files bdhDSstatus="" if [[ ! -s /tmp/dsb_files ]] then bdhDSstatus=1 chkStatus=1 fi ## .....and merge plots # echo "$$:" >> $LOGFILE echo "$$:......processing BDH Day Series plots" >> $LOGFILE while [[ -s /tmp/dsb_files ]] do bmag_file_name=$(head -1 /tmp/dsb_files) date_string=$(echo $bmag_file_name | awk -F_ '{print $3 "_" $4}') path_string=$(echo $bmag_file_name | awk -F_ '{print $1}') dmag_file_name=$(echo "${path_string}_DSD_${date_string}") hmag_file_name=$(echo "${path_string}_DSH_${date_string}") tstamp_search=$(echo ${path_string}_TStamp_$(echo $date_string |awk -F_ '{print $1}')) b_file_name=$(ls -1 ${tstamp_search}* |tail -1) bdhmag_file_name=$(echo $bmag_file_name |awk -F_ '{print $1 "_DSBDH_" $3 "_" $4}') if [[ ! -a $dmag_file_name || ! -a $hmag_file_name || ! -a $b_file_name ]] then no_merge $dmag_file_name $hmag_file_name $b_file_name $bdhmag_file_name else echo "$$:" >> $LOGFILE echo "$$: Merging files:" >> $LOGFILE echo "$$: $bmag_file_name" >> $LOGFILE echo "$$: $dmag_file_name" >> $LOGFILE echo "$$: $hmag_file_name" >> $LOGFILE echo "$$: $b_file_name" >> $LOGFILE echo "$$: New filename = $bdhmag_file_name" >> $LOGFILE /usr/local/bin/convert $bmag_file_name $dmag_file_name $hmag_file_name $b_file_name -append $bdhmag_file_name echo "$$:" >> $LOGFILE echo "$$: Updating MySQL database................" >> $LOGFILE mysql_table=${school}_DSBDH mysql_date=$(echo $date_string | awk -F_ '{print substr($1,5,4) "-" substr($1,1,2) "-" substr($1,3,2)}') mysql_time=$(echo $date_string | awk -F_ '{print substr($2,1,2) ":" substr($2,3,2) ":00" }') echo "$$: Updating MySQL database table $mysql_table......." >> $LOGFILE /home/thmsoc/software_dev/php/epo_cmdline_input.php $mysql_table $mysql_date $mysql_time $bdhmag_file_name echo "$$: ...........update complete. " >> $LOGFILE fi sed '1d' /tmp/dsb_files > /tmp/DSB_FILES mv /tmp/DSB_FILES /tmp/dsb_files done rm /tmp/dsb_files #################################### ## Search for Time Series Spectra ## #################################### # find ./${school_dir} -name ${school}_TSpectra_\* -mtime ${FIND_MTIME} > /tmp/ts1_files specTSstatus="" if [[ ! -s /tmp/ts1_files ]] then specTSstatus=1 chkStatus=1 fi echo "$$:" >> $LOGFILE echo "$$:......processing Spectra Time Series plots" >> $LOGFILE while [[ -s /tmp/ts1_files ]] do tspectra_file_name=$(head -1 /tmp/ts1_files) date_string=$(echo $tspectra_file_name | awk -F_ '{print $3 "_" $4}') echo "$$:" >> $LOGFILE echo "$$:" >> $LOGFILE echo "$$: Found file: $tspectra_file_name" >> $LOGFILE mysql_table=${school}_TSpectra mysql_date=$(echo $date_string | awk -F_ '{print substr($1,5,4) "-" substr($1,1,2) "-" substr($1,3,2)}') mysql_time=$(echo $date_string | awk -F_ '{print substr($2,1,2) ":" substr($2,3,2) ":" substr($2,5,2)}') echo "$$: Updating MySQL database table $mysql_table......." >> $LOGFILE /home/thmsoc/software_dev/php/epo_cmdline_input.php $mysql_table $mysql_date $mysql_time $tspectra_file_name echo "$$: ...........update complete. " >> $LOGFILE sed '1d' /tmp/ts1_files > /tmp/TS1_FILES mv /tmp/TS1_FILES /tmp/ts1_files done rm /tmp/ts1_files #################################### ## Search for Day Series Spectra ## #################################### # find ./${school_dir} -name ${school}_DSpectra_\* -mtime ${FIND_MTIME} > /tmp/ds1_files specDSstatus="" if [[ ! -s /tmp/ds1_files ]] then specDSstatus=1 chkStatus=1 fi echo "$$:" >> $LOGFILE echo "$$:......processing Spectra Time Series plots" >> $LOGFILE while [[ -s /tmp/ds1_files ]] do dspectra_file_name=$(head -1 /tmp/ds1_files) date_string=$(echo $dspectra_file_name | awk -F_ '{print $3 "_" $4}') echo "$$:" >> $LOGFILE echo "$$:" >> $LOGFILE echo "$$: Found file: $dspectra_file_name" >> $LOGFILE mysql_table=${school}_DSpectra mysql_date=$(echo $date_string | awk -F_ '{print substr($1,5,4) "-" substr($1,1,2) "-" substr($1,3,2)}') mysql_time=$(echo $date_string | awk -F_ '{print substr($2,1,2) ":" substr($2,3,2) ":00" }') echo "$$: Updating MySQL database table $mysql_table......." >> $LOGFILE /home/thmsoc/software_dev/php/epo_cmdline_input.php $mysql_table $mysql_date $mysql_time $dspectra_file_name echo "$$: ...........update complete. " >> $LOGFILE sed '1d' /tmp/ds1_files > /tmp/DS1_FILES mv /tmp/DS1_FILES /tmp/ds1_files done rm /tmp/ds1_files if [[ -n $chkStatus ]] then printf "%s\n%s\n" "THEMIS EPO-GMAG Recovery Warning" \ "Files not received for $FIND_MTIME days. " \ "Check the following:" \ "School = $school" \ "xyzTSstatus = $xyzTSstatus" \ "bdhTSstatus = $bdhTSstatus" \ "xyzDSstatus = $xyzDSstatus" \ "bdhDSstatus = $bdhDSstatus" \ "specTSstatus = $specTSstatus" \ "specDSstatus = $specDSstatus" | mail $CONTACT_LIST fi n=$(( n + 1 )) school=${SCHOOL[$n]} done rm $LOCKFILE echo "$$:" >> $LOGFILE echo "$$:----------- Ending epo_magfile_append at $(date) ---------" >> $LOGFILE