#!/usr/bin/ksh # # green_ascii2all_new.ksh # # This script generates lines for a IDL batch # file which creates gmag cdfs for Greenland data files. (New provider) # # Arguments: # # Author: Patrick Cruce # Created: May 14,2010 # # Based heavily of green_ascii2all.ksh by Tim Quinn # # ## 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/setup_themis.bourne # . $THMSOC/src/config/wget_green_gmag.config . /home/thmsoc/lphilpotts_stuff/greenland_test/wget_green_gmag_test.config IDL_PATH=$IDL_PATH':'+/home/thmsoc/lphilpotts_stuff/greenland_test/ ; export IDL_PATH processdate=$(date +%Y%m%d) #LOGDIR=/home/thmsoc/lphilpotts_stuff/greenland_test LOGFILE=${LOGDIR}/webdownloads/green_ascii2all_new_${processdate}_$$ IDLLOG=${LOGDIR}/webdownloads/green_ascii2all_new_idl_${processdate}_$$ # ## ## Begin Work ## # echo ":$$:green_ascii2all_new: " >> $LOGFILE echo ":$$:green_ascii2all_new: Starting green_ascii2all_new at $(date)" >> $LOGFILE echo ":$$:green_ascii2all_new: " >> $LOGFILE os=$(uname -s) # ## Find New Files files=$(ls -1 $GMAGWORKDIR) for f in $files do fullfilepath=${GMAGWORKDIR}/${f} #remove old junk rm -f ${TEMPDIR}/*.bm rm -f ${TEMPDIR}/*.txt rm -f ${TEMPDIR}/*.cdf #new script newscript=${TEMPDIR}/${f}.bm echo "!quiet=1" >> $newscript echo "thm_greenmag_l2gen_new2,\"${fullfilepath}\",mastercdf_dir=\"${GREENMASTERDIR}/\",out_dir=\"${TEMPDIR}/\"" >> $newscript echo "exit" >> $newscript idl $newscript >> $IDLLOG 2>> $IDLLOG # This check is redundant with following check for file creation # idlStatus=$? # if (( $idlStatus != 0 )) # then # echo ":$$:green_ascii2all_new: " >> $LOGFILE # echo ":$$:green_ascii2all_new: Failed CDF conversion for ${f}" >> $LOGFILE # echo ":$$:green_ascii2all_new: " >> $LOGFILE # fi outcdf=$(ls ${TEMPDIR}/thg*cdf) 2>/dev/null outtxt=$(ls ${TEMPDIR}/thg*txt) 2>/dev/null if [[ -z $outcdf || -z $outtxt ]] then echo ":$$:green_ascii2all_new:" >> $LOGFILE echo ":$$:green_ascii2all_new: ERROR: The IDL run failed to produce both the cdf and txt!!" >> $LOGFILE echo ":$$:green_ascii2all: ERROR file: ${f}" >> $LOGFILE else outname=$(echo $outcdf | awk -F/ '{print $NF}') month=$(echo $outname | awk -F_ '{print substr($5,5,2)}') day=$(echo $outname | awk -F_ '{print substr($5,7,2)}') year=$(echo $outname | awk -F_ '{print substr($5,1,4)}') site=$(echo $outname | awk -F_ '{print $4}') # if [[ $os = "SunOS" ]] # then # ucsite=$(echo $site | nawk '{print toupper($1)}') # else # ucsite=$(echo $site | awk '{print toupper($1)}') # fi cdf_archive_dir=${L2MAGDIR}/${site}/${year} ascii_archive_dir=${ASCIIMAGDIR}/${site}/${year}${month} mkdir -p $cdf_archive_dir mv $outcdf $cdf_archive_dir mkdir -p $ascii_archive_dir mv $outtxt $ascii_archive_dir echo ":$$:green_ascii2all_new:" >> $LOGFILE echo ":$$:green_ascii2all_new: Processing of $outcdf & $outtxt completed." >> $LOGFILE fi rm -f ${GMAGWORKDIR}/${f} done ## Cleanup # exit 0