#!/usr/bin/ksh # # ucla_rmd2all_test.ksh # # Based on ucla_rmd2all.ksh this takes site and date arguments rather than reading # files to reprocess from a list (lphilpott, Sep 2011) # # When UCLA Ground Magnetometer (GMAG) raw data (RMD) have been # rsync-mirrored from the UCLA or UCalgary server, this script # will initiate the sequence of file format conversions: # # RMD->FF->Merged_FF->CDF->ASCII # # Author: Tim Quinn # Created: September 2006 # # Notes: This scipt calls code written by UCLA which will # only comile on SunOS. # # Updates: # # 11/28/06 Removed stack plot production, which will run # independently. # ## Set the environment variables # if [[ -z $THMSOC ]] then THMSOC=/disks/socware/thmsoc_dp_current export THMSOC fi . $THMSOC/src/config/soc_it_to_me.config . $THMSOC/src/config/ucla_rmd2all.config #LOGFILE=/home/thmsoc/lphilpotts_stuff/bmls_reprocess_log echo ":$$:ucla_rmd2all_test:" >> $LOGFILE echo ":$$:ucla_rmd2all_test:Starting ucla_rmd2all_test at $(date)" >> $LOGFILE # ## Script MUST run on SunOS. Check and quit otherwise # os=$(uname -s) if [[ $os != "SunOS" ]] then echo Script MUST run on SunOS. Quitting...... exit 0 fi loopsite=$1 startdate=$2 enddate=$3 ucsite=$(echo $loopsite | nawk '{print toupper($1)}') chk_site=$(grep $loopsite $CONFIGDIR/lc_site_list_ucla_epo.txt) if [[ -n $chk_site ]] then gbo_or_epo=EPO else if [[ $ucsite = "LETH" || $ucsite = "ROTH" || $ucsite = "REDR" || $ucsite = "LARG" || $ucsite = "VLDR" ]]; then gbo_or_epo=ATH else gbo_or_epo=GBO fi fi # ## Process any RMD directories that were produced as part of the ## rsync-mirror process # ## First: Check if calibration file exists # if [[ ! -e ${TABLE_FILES_DIR}/${ucsite}.txt ]] then # Calibration file does not exist. Go to next dir echo ":$$:ucla_rmd2all_test:" >> $LOGFILE echo ":$$:ucla_rmd2all_test:WARNING: Cal file ${ucsite}.txt does not exist." >> $LOGFILE echo ":$$:ucla_rmd2all_test:.........trying next directory." >> $LOGFILE continue fi for date in $(cat $CONFIGDIR/date_list.txt 2>/dev/null) do if [[ $date = $enddate ]] then exit 0 fi if [[ $date < $startdate ]] then continue fi year=$(echo $date | awk '{print substr($1,1,4)}') month=$(echo $date | awk '{print substr($1,5,2)}') day=$(echo $date | awk '{print substr($1,7,2)}') ## create a directory name that includes siteyyyymmdd_rmd in ## garage subdir of epo ff storage dir # tmpdir=${ucsite}${date}_rmd mkdir -p ${UCB_FLAT_HOME}/process_rmd2ff/${tmpdir} ## Copy all rmd files from RMD dir to temp dir # if [[ $gbo_or_epo = "EPO" ]] then sitename=$(grep $loopsite ${EPO_MIRROR_HOME}/site_list.txt |awk -F_ '{print $1}') path=${EPO_MIRROR_HOME}/${sitename}/${year}/${month}/${day} if [[ -d $path ]] then cp -r ${path}/*RMD ${UCB_FLAT_HOME}/process_rmd2ff/${tmpdir} else echo Does Not Exist - $path continue fi elif [[ $gbo_or_epo = "ATH" ]] then path=${ATHA_MIRROR_HOME}/${ucsite}/${year}/${month}/${day} if [[ -d $path ]] then cp -r ${path}/*RMD ${UCB_FLAT_HOME}/process_rmd2ff/${tmpdir} else echo Does Not Exist - $path continue fi else path=${GBO_MIRROR_HOME}/${year}/${month}/${day} if [[ -d $path ]] then cp -r ${path}/${ucsite}*RMD ${UCB_FLAT_HOME}/process_rmd2ff/${tmpdir} else continue fi fi ## Change directories to temp dir and run rmd2ff on each RMD file # cd ${UCB_FLAT_HOME}/process_rmd2ff/${tmpdir} echo ":$$:ucla_rmd2all_test:" >> $LOGFILE echo ":$$:ucla_rmd2all_test: Running rmd2ff on files in $(pwd)......." >> $LOGFILE for file in $(ls *RMD) do fileroot=$(echo $file | awk -F. '{print $1}') site=$(echo $fileroot |awk '{print substr($1,1,4)}') rm -f $LOGDIR/rmd2ff_${fileroot}.log ${RMD2FFPATH}/RMD2FF -ctime -batch -in_file $file -table ${TABLE_FILES_DIR}/${site}.txt -outfile $fileroot 1>/dev/null 2>${LOGDIR}/RMD2FF_BAD$$ if [[ -s ${LOGDIR}/RMD2FF_BAD$$ ]] then echo ":$$:ucla_rmd2all_test:">> $LOGFILE echo ":$$:ucla_rmd2all_test: Problem in RMD2FF run. Check ${LOGDIR}/RMD2FF_BAD$$">> $LOGFILE else rm -f ${LOGDIR}/RMD2FF_BAD$$ fi done echo ":$$:ucla_rmd2all_test: rmd2ff complete. ">> $LOGFILE ## Now merge the flat files into one 24 hour file # for file in $(ls *ffd) do fileroot=$(echo $file | awk -F. '{print $1}') echo $fileroot >> filelist.txt done newfilename=$(echo $fileroot |awk '{print substr($1,1,10)}') echo filelist.txt >> ffmerge.input echo "2 3 4" >> ffmerge.input echo x >> ffmerge.input echo first >> ffmerge.input echo last >> ffmerge.input echo $newfilename >> ffmerge.input echo n >> ffmerge.input echo y >> ffmerge.input rm -f $LOGDIR/ffmerge_${newfilename} echo ":$$:ucla_rmd2all_test:" >> $LOGFILE echo ":$$:ucla_rmd2all_test: Running ffmerge on files ......" >> $LOGFILE ${FFMERGEPATH}/ffmergesungnucmp < ffmerge.input 1> /dev/null echo ":$$:ucla_rmd2all_test: ffmerge complete. ">> $LOGFILE # Now a single flat file exists for that day in the form # schlyymmdd.ffd, schlyymmdd.ffh and must be changed to # Byydoy_schl fullyear=$(echo $newfilename |awk '{print "20" substr($1,5,2)}') partyear=$(echo $newfilename |awk '{print substr($1,5,2)}') month=$(echo $newfilename |awk '{print substr($1,7,2)}') day=$(echo $newfilename |awk '{print substr($1,9,2)}') sitedir=$(echo $site | nawk '{print tolower($1)}') doy=$(${KSHSCRIPTS}/date2doy ${fullyear}-${month}-${day} | awk '{printf("%03d",$1)}') finalfileroot=B${partyear}${doy}_${site} cdftxtgifroot=thg_l2_mag_${sitedir}_${fullyear}${month}${day}_v01 echo ":$$:ucla_rmd2all_test: New files: ${newfilename}.ffd and ${newfilename}.ffh." >> $LOGFILE mkdir -p ${UCB_FLAT_HOME}/${sitedir}/${fullyear} #mkdir -p /home/thmsoc/lphilpotts_stuff/${sitedir}/${fullyear} mv ${newfilename}.ffd ${UCB_FLAT_HOME}/${sitedir}/${fullyear}/${finalfileroot}.ffd #mv ${newfilename}.ffd /home/thmsoc/lphilpotts_stuff/${sitedir}/${fullyear}/${finalfileroot}.ffd mv ${newfilename}.ffh ${UCB_FLAT_HOME}/${sitedir}/${fullyear}/${finalfileroot}.ffh #mv ${newfilename}.ffh /home/thmsoc/lphilpotts_stuff/${sitedir}/${fullyear}/${finalfileroot}.ffh echo ":$$:ucla_rmd2all_test: New 24 hour flat file = ${finalfileroot}" >> $LOGFILE ## Make CDF file #ksh /home/thmsoc/lphilpotts_stuff/ucla_flat2cdf_test.ksh $finalfileroot $gbo_or_epo 1>> $LOGFILE 2>/dev/null ucla_flat2cdf.ksh $finalfileroot $gbo_or_epo 1>> $LOGFILE 2>/dev/null ## Make ASCII file #ksh /home/thmsoc/lphilpotts_stuff/ucla_flat2ascii_test.ksh $finalfileroot $gbo_or_epo 1>> $LOGFILE 2>/dev/null ucla_flat2ascii.ksh $finalfileroot $gbo_or_epo 1>> $LOGFILE 2>/dev/null ## Delete temp dir # cd ${UCB_FLAT_HOME} rm -rf ${UCB_FLAT_HOME}/process_rmd2ff/${tmpdir} done # ## Cleanup # exit 0