#!/usr/bin/ksh # # usgs_ascii2all.ksh # # This script generates lines for a IDL batch # file which creates gmag cdfs for data files obtained from USGS. # # # Arguments: # # Author: Lydia Philpott # Created: November 18, 2011 # # Based heavily on intermagnet_ascii2all.ksh # # ## 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_usgs_gmag.config processdate=$(date +%Y%m%d) LOGFILE=${LOGDIR}/webdownloads/usgs_ascii2all_${processdate}_$$ IDLLOG=${LOGDIR}/webdownloads/usgs_ascii2all_idl_${processdate}_$$ # ## ## Begin Work ## # echo ":$$:usgs_ascii2all: " >> $LOGFILE echo ":$$:usgs_ascii2all: Starting usgs_ascii2all at $(date)" >> $LOGFILE echo ":$$:usgs_ascii2all: " >> $LOGFILE os=$(uname -s) # ## Find New Files files=$(ls -1 $GMAGWORKDIR) for f in $files do filename=$f fullfilepath=${GMAGWORKDIR}/${f} echo ":$$:usgs_ascii2all:" >> $LOGFILE echo ":$$:usgs_ascii2all: Processing $fullfilepath." >> $LOGFILE processTime=$(date -u '+%Y-%m-%d %T') tmpsubdir=tmp_$filename processDir=${TMPDIR}/${tmpsubdir} mkdir -p $processDir cd $processDir #copy file to temporary directory cp $fullfilepath . ## Copy CDF master to processing directory # site=$(echo $filename | awk '{print substr($1,1,3)}') mkdir -p mastercdf cp ${CDFMASTERS}/*${site}* ./mastercdf #new script newscript=$filename.bm echo "!quiet=1" >> $newscript echo "thm_usgsmag_l2gen,\"${filename}\",out_dir=\"${processDir}/\"" >> $newscript echo "exit" >> $newscript idl $newscript >> $IDLLOG 2>> $IDLLOG outcdf=$(ls ${processDir}/thg*cdf) 2>/dev/null outtxt=$(ls ${processDir}/thg*txt) 2>/dev/null if [[ -z $outcdf || -z $outtxt ]] then echo ":$$:usgs_ascii2all:" >> $LOGFILE echo ":$$:usgs_ascii2all: ERROR: The IDL run failed to produce both the cdf and txt!!" >> $LOGFILE echo ":$$:usgs_ascii2all: ERROR file: ${filename}" >> $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 ## Database update # cdffile=$(basename $outcdf) txtfile=$(basename $outtxt) ## Update checksum file # ${KSH_SCRIPTS}/fileChkSum.ksh ${cdf_archive_dir}/${cdffile} ## Update checksum file # ${KSH_SCRIPTS}/fileChkSum.ksh ${ascii_archive_dir}/${txtfile} dataTime=$(echo $year $month $day | awk '{printf("%s-%02s-%02s 00:00:00",$1,$2,$3)}') mysql_cdftable_name=gbo_${ucsite}_cdffiles mysql_asciitable_name=gbo_${ucsite}_asciifiles cdffileSize=$(ls -l ${cdf_archive_dir}/${cdffile} |awk '{print $5}') txtfileSize=$(ls -l ${ascii_archive_dir}/${txtfile} |awk '{print $5}') gmag_cdf.php $mysql_cdftable_name $dataTime $cdffile $processTime $cdffileSize gmag_ascii.php $mysql_asciitable_name $dataTime $txtfile $processTime $txtfileSize echo ":$$:usgs_ascii2all:" >> $LOGFILE echo ":$$:usgs_ascii2all: Processing of $outcdf & $outtxt completed." >> $LOGFILE fi cd rm -rf $processDir rm -f ${GMAGWORKDIR}/${f} done ## Cleanup # exit 0