#!/usr/bin/ksh # # ucla_flat2ascii.ksh - convert UCLA flat files to ascii # format # # Usage: ucla_flat2ascii.ksh [filename] # # Arguments: # $1 = filename (extensions have to be added) # $2 = EPO/GBO # # Creation Date: # # 09 August 2006 TimQuinn # # 10/23/06 new path for archiving cdf: # {root}/thg/[l0|l1|l2]/mag/yyyy/mm/dd # ## Set the environment variables # . $THMSOC/src/config/setup_themis_UCLA.bourne . $THMSOC/src/config/ucla_rmd2all.config . $THMSOC/src/config/soc_it_to_me.config 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)}') ## Where is the flat file located # schdir=${UCB_FLAT_HOME}/${lcschool}/${year} echo :$$:ucla_flat2ascii: echo :$$:ucla_flat2ascii: Using Flat File: echo :$$:ucla_flat2ascii: ${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/uff2asc.bm $processDir line="uff2asc,'$ucschool','$yydoy'" echo $line >> ${processDir}/uff2asc.bm echo exit >> ${processDir}/uff2asc.bm ## Now run idl with batch file # echo :$$:ucla_flat2ascii: echo :$$:ucla_flat2ascii: Starting FLAT to ASCII conversion for $fileroot at $(date) cd ${TMPDIR} #idl ${processDir}/uff2asc.bm 1>> $LOGDIR/IDLOUT_FF2ASCII_${fileroot} 2>/dev/null idl ${processDir}/uff2asc.bm if (( $? != 0 )) then echo :$$:ucla_flat2ascii: ERROR in IDL Process echo :$$:ucla_flat2ascii: 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 ascii 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=${ASCIIMAGDIR}/${lcschool}/${year} mkdir -p $archive_dir idlasciifile=thg_l2_mag_${lcschool}_${year}${month}${day}_v01.txt echo :$$:ucla_flat2ascii: ascii file $idlasciifile created at $(date) echo :$$:ucla_flat2ascii: moved file to $archive_dir mv ${TMPDIR}/${idlasciifile} ${archive_dir}/${idlasciifile} rm -r $processDir ## Update checksum file # ${KSH_SCRIPTS}/fileChkSum.ksh ${archive_dir}/${idlasciifile} ## Process information into database # mysql_table_name=${grdnet}_${ucschool}_asciifiles dataTime=$(echo $year $month $day | awk '{printf("%s-%02s-%02s 00:00:00",$1,$2,$3)}') fileSize=$(ls -l ${archive_dir}/${idlasciifile} |awk '{print $5}') echo "$$:ucla_flat2ascii: Updating MySQL database table $mysql_table_name......." echo "$$:ucla_flat2ascii: gmag_ascii.php $mysql_table_name $dataTime $idlasciifile $processTime $fileSize" >> $LOGFILE gmag_ascii.php $mysql_table_name $dataTime $idlasciifile $processTime $fileSize exit 0