#!/usr/bin/ksh # # ucla_flat2cdf.ksh - convert UCLA flat files to CDF # format # # Usage: ucla_flat2cdf.ksh [filename] # # Arguments: # $1 = filename (extensions have to be added) # $2 = EPO/GBO # # Creation Date: # # 09 August 2006 TimQuinn # # Updates: # # 10/09/06 updated to all new IDL procedures # 10/23/06 new path for archiving cdf: # {root}/thg/[l0|l1|l2]/mag/yyyy/mm/dd # 11/29/06 Added line to put cdf date in file for stack plot # creation process to use # ## Set the environment variables # . $THMSOC/src/config/setup_themis_UCLA.bourne . $THMSOC/src/config/soc_it_to_me.config . $THMSOC/src/config/ucla_rmd2all.config ## Create variables derived from the input arguments # os=$(uname -s) fileroot=$1 year=$(echo $fileroot |awk '{print "20" substr($1,2,2)}') ucschool=$(echo $fileroot | awk '{print substr($1,8,4)}') if [[ $os = "SunOS" ]] then lcschool=$(echo $ucschool | nawk '{print tolower($1)}') grdnet=$(echo $2 | nawk '{print tolower($1)}') else lcschool=$(echo $ucschool | awk '{print tolower($1)}') grdnet=$(echo $2 | awk '{print tolower($1)}') fi yydoy=$(echo $fileroot | awk '{print substr($1,2,5)}') msg=Flat2CDFFileyear echo $msg echo $fileroot echo $year echo $yydoy ## Where is the flat file located # schdir=${UCB_FLAT_HOME}/${lcschool}/${year} echo :$$:ucla_flat2cdf: echo :$$:ucla_flat2cdf: Using Flat File: echo :$$:ucla_flat2cdf: ${UCB_FLAT_HOME}/${lcschool}/${year}/$fileroot ## Create a directory where processing will occur # processDir=${TMPDIR}/tmp_${yydoy} mkdir -p $processDir ## Now copy all of the necessary files to the processing directory # cp ${schdir}/${fileroot}.ffd ${processDir}/${fileroot}.DAT cp ${schdir}/${fileroot}.ffh ${processDir}/${fileroot}.ABS cp $THMSOC/src/config/default.DES ${processDir}/${fileroot}.DES ## Create HED file used by IDL routine # HEDstring=0123456789012345678901234567890123456789012345678901234567890123456789012345678901 HEDint1=4 filesize=$(ls -l $processDir/${fileroot}.DAT |awk '{print $5}') HEDint2=$(( $filesize/20 )) printf "%82s%10i%10i" $HEDstring $HEDint1 $HEDint2 > ${processDir}/${fileroot}.HED ## Build IDL batch file # cp $THMSOC/idl/thmsoc/ucla_ff/uff2cdf.bm $processDir line="uff2cdf,'$ucschool','$yydoy'" echo $line >> ${processDir}/uff2cdf.bm echo exit >> ${processDir}/uff2cdf.bm ## Now run idl with batch file # echo :$$:ucla_flat2cdf: echo :$$:ucla_flat2cdf: Starting FLAT to CDF conversion for $fileroot at $(date) cd ${TMPDIR} mkdir mastercdfs cp ${CDFMASTERS}/thg_l2_mag_${lcschool}* mastercdfs #idl ${processDir}/uff2cdf.bm 1>> $LOGDIR/IDLOUT_FF2CDF_${fileroot} 2>/dev/null idl ${processDir}/uff2cdf.bm if (( $? != 0 )) then echo :$$:ucla_flat2cdf: ERROR in IDL Process echo :$$:ucla_flat2cdf: Notifying OPS Personnel thmsoc_dblog.php $(basename $0) 3 "WARNING: IDL problem - check $LOGFILE" fi processTime=$(date -u '+%Y-%m-%d %T') ## Create subdirectory for archiving the cdf file # year=$(echo $yydoy | awk '{print "20"substr($1,1,2)}') doy=$(echo $yydoy | awk '{print substr($1,3,3)}') #date=$(/home/thmsoc/software_dev/ksh/doy2date $year $doy) date=$(${KSH_SCRIPTS}/doy2date $year $doy) month=$(echo $date |awk -F/ '{printf("%02d",$2)}') day=$(echo $date |awk -F/ '{printf("%02d",$3)}') archive_dir=${L2MAGDIR}/${lcschool}/${year} mkdir -p $archive_dir ## Create cdf file name and move to archive directory # idlcdffile=thg_l2_mag_${lcschool}_${year}${month}${day}_v01.cdf echo :$$:ucla_flat2cdf: cdf file $idlcdffile created at $(date) echo :$$:ucla_flat2cdf: moved file to $archive_dir mv ${TMPDIR}/${idlcdffile} $archive_dir rm -rf $processDir rm -rf ${TMPDIR}/mastercdfs ## Update checksum file # ${KSH_SCRIPTS}/fileChkSum.ksh ${archive_dir}/${idlcdffile} ## Create file for stack plot production # echo ${year}-${month}-${day} > ${WORKMAGSTACKS}/stack_${year}${month}${day}_$$ ## Process information into database # mysql_table_name=${grdnet}_${ucschool}_cdffiles dataTime=$(echo $year $month $day | awk '{printf("%s-%02s-%02s 00:00:00",$1,$2,$3)}') fileSize=$(ls -l ${archive_dir}/${idlcdffile} |awk '{print $5}') echo :$$:ucla_flat2cdf: echo :$$:ucla_flat2cdf: gmag_cdf.php $mysql_table_name $dataTime $idlcdffile $processTime $fileSize gmag_cdf.php $mysql_table_name $dataTime $idlcdffile $processTime $fileSize exit 0