#!/bin/ksh # 200711 7 311 16:40:38UT : # - added radius of earth to fitone.inp # - then sed into fasc.tmplt # 10 March 2005 # - big re-edit diffed with current scripts on yampa and pave # 6 Jan2002 # edit for SFIT2 change name to fit2.k # 14 November 2000 # Added filename_line to input # rearrange (rewrite) short file for header on plot # 11 Oct 2000 # updates to solve changes # new sed patterns # add linepos to inp file # 03 May 1999 # Some changes to work only in one directory # input files # fitone.inp # fasc0 # fasc1 # fasc0.prf # binput # temp.bnr # This is a modified version of the fitscript script used to process the SESAME # data along with DOLIST # This script automates many (but unfortunately, not all) of # the operations necessary to run sfit, once the files have # been set up for the initial case. # Uses input file: fitone.inp # USAGE: fitone umask 111 exec 7 0 # fastcode_sw - 0-don't run fastcode, 1- run fastcode # result_fname - an output file to put results for an entire run into # not used yet # linepos - wavenumber of line to fitted, used for refractive index calc # in fastcode. Sed(ed) into input file # 1. FASTCODE # Use stream editor to put zenith angle and obs alt into the fastcode input # files in $fastdir. # Check fastcode_sw, if we are fitting a new region of the previously fitted # spectrum we don't have to run fastcode again. # 2 Aug 2000 made changes to accommmodate new fastcode - now only one input file # these typeset cmds don't work in linux as they did in AIX # alt is set to 9 char in fitbatch (OPUS) & ?? for OTA OTM # sza is set to 9 char in o2bq set -A Asza integer iscan=0 set $sza while (( ${iscan} < ${nscan} )) do Asza[iscan]=$1 #print ${Asza[iscan]} shift let iscan=${iscan}+1 done #print $alt $sza if [[ ${#alt} != 9 ]] then typeset -Z9 alt=$alt fi #if [[ ${#sza} != 9 ]] #then # typeset -Z9 sza=$sza #fi #print $alt $sza #exit typeset -Z9 lnp=$linepos.0 ((ln1=$linepos+1)) typeset -Z9 ln1=$ln1.0 if ((fastcode_sw == 1)) then # now we are going to read and write fasc.inp # each block will be written nscan times set -A fscline let nfln=0 exec 7< ${ftmplt} while read -u7 fscline[nfln] do ((nfln=${nfln}+1)) done exec 7<&- #print " Lines in fasc.tmplt : " $nfln # now that we have the lines change to fastdir to do the work cd ${fastdir} # print out the header block print -R "${fscline[0]}" > fasc.0 print -R "${fscline[1]}" >> fasc.0 # change the nscan variable add 1 for 0 zenith angle calculation typeset -Z2 nsc ((nsc=${nscan}+1)) sed -e s/NN/${nsc}/g fasc.0 >fasc.inp # now print out a block for each of nscan sza's / 49 layers in FH TAB let iscan=0 while (( ${iscan} <= ${nscan} )) do i=2 rm -f fasc.inp.tmp while (( $i < $nfln )) do print -R "${fscline[$i]}" >> fasc.inp.tmp ((i=$i+1)) #print $i done SZA=${Asza[iscan]} if (( ${iscan} == ${nscan} )) then SZA=0000000.0 fi #print $SZA sed -e s/FIRSTLAYR/$alt/g \ -e s/SOLARZENA/${SZA}/g \ -e s/LOREFRACI/$lnp/g \ -e s/HIREFRACI/$ln1/g \ -e s/RADISEARTH/$radofearth/g \ fasc.inp.tmp >>fasc.inp ((iscan=${iscan}+1)) done cp ../fasc41.prf fasc.prf if [[ $? -ne 0 ]] then print "!!! cp fas41.prf returned not ok !!!" exit 7 fi # now run the fastcode program print " fitn.k : Running fastc.k..." #${bin}fastc.k fasc 1 ${bin}fast2.k -ffasc -v${Sver} fOK=$? if [ $fOK -ne 0 ] then print "!!! fastc.k returned not ok !!!" exit 7 fi # copy the output files back here cd $autodir cp $fastdir/fasc\.* ${sfitdir} else print -R " Skipping FASTCODE..." >>$result_fname print -R "" >>$result_fname fi # 2. SFIT # setup the spectra cd $sfitdir print -R $ratiodir >ratio.dir print "" print " fitn.k : Setting up spectra..." integer iscan=0 while (( ${iscan} < ${nscan} )) do typeset -Z2 isc=${iscan} cp ../temp.bnr.${isc} temp.bnr.${isc} let iscan=${iscan}+1 done # now create the fitting parameter file cinput # get the id number for this scan from the z file print " fitn.k : Editing cinput..." set -A id exec 7 ${sfitdir}/cinput.tmp # now add the 0 at the end of the file or the snr regions to be # updated we are only allowing 1 region!!! # note in bbedit an extra blank line is needed at end of file lline=$(tail -1 cinput.tmp) count=$(wc -l cinput.tmp) integer Nlln="${count% *}" #print "" #print " Fixing up tail end of cinput..." #print " lastline in cinput.tmp : " $lline #print " # of lines in cinput.tmp : " $Nlln #print " first part of last line : " "${lline%%.*}" #print "" #print " testing for end of file <0> or snr lines on : " "${lline%.*}" if [ "${lline%.*}" != 0 ] then # has snr lines # grab the last 2 lines or N lines later... #l2line=$(tail -2 cinput.tmp) let svln=${Nlln}-2 #print " # lines - snr region lines : " $svln #print " last 1 lines ${lline}" head -${svln} cinput.tmp > cinput else let svln=${Nlln}-1 #print " # lines - <0 line> " $svln head -${svln} cinput.tmp > cinput fi #print "first part of last line: " "${lline%%.*}" #print "" #print " Adding in spectrum code and bnr lines..." # tack on the last lines containing bnr zenith angle code: # 1 block for each scan # add filter to temp.bnr filename to get it into specasc5 from cinput integer iscan=0 while (( ${iscan} < ${nscan} )) do print -R "${id[iscan]} 1" >>cinput # used to be Z2 but this ksh goes to 2 w/ just -Z !!! #typeset -Z2 isc=${iscan} # on acd typeset -Z isc=${iscan} # on mac #print 1 $isc 2 $iscan 3 temp.bnr.${isc} #print $isc $iscan fprefix=${thisfltr} if [ ${ratioflag} == 0 ] then fprefix=0 fi print " fitn.k : filter = ${thisfltr}, prefix = ${fprefix}" print -R "${fprefix}temp.bnr.${isc}" >>cinput let iscan=${iscan}+1 done #print "first part of last line: " "${lline%%.*}" #print "" #print " replace 0 or snr lines..." if [ "${lline%%.*}" != 0 ] then # only accounting for changing the snr in one region for now!!! print 1 >>cinput #print " added line : " "${lline}" print "${lline}" >>cinput else # this says no update of snr by region print 0 >>cinput fi #exit # now we are ready to call the fitting program # note sfitinpx is not run from sfit.k binput assumed to be correct # use argument "nointerp" to call specasc4 # use argument "interp" or nothing to call specasc5 print " fitn.k : Running sfit.k... ${Sver}" ${bin}sfit2.k -s 6 -v ${Sver} if [[ $? -ne 0 ]] then print "!!! sfit2.k returned not ok !!!" exit 7 fi # fi # 3. RESULTS # get the data from the short output for the results file set -A sline short="summary.st" if [[ -s ${short} ]] then count=$(wc -l ${short}) integer nlines="${count% *}" integer n=0 exec 7< ${short} while ((n < nlines)) do read -u7 sline[n] if [[ ${sline[n]} == "Itr"* ]] then itrline=${sline[n]} #print $itrline set $itrline #print $1 #itr="${1%%:??}" q=${1#*:} #print $q itr=${q%/*} #print 'itr : ' $itr fi let n=${n}+1 done exec 7<&- else integer nlines=1 sline[0]="!short output file: empty" fi #print $nlines # put the short output file to the results file # add filename_line print -R "$filename_line" >> ${result_fname} soutfile='specasc.out' if [[ -s ${soutfile} ]] then exec 7<${soutfile} read -u7 tag zro junk exec 7<&- else zro=0.00000 fi # Make list file set ${sline[1]} #this is 80char bnr header dte=$1 tme="${2%%UT*}" #print $dte $tme let n=${nlines}-1 set ${sline[n]} # this line looks like: #pcol CHF2CL 0.394 1.150 4.2 77.5 2.3294E+15 9.2688E+14 7.4581E+13 3.5740E+15 1.9749E+25 mymol=$2 pcol="$zro $3 $4 $5 $6 ${10} ${11}" # params + partial columns pc2="$3 $4 $5 $6 ${10}" # params and total column, air column #print $9 ${10} #print $pcol #print $pc2 aircol=${11} print -R "${outputpath} ${savedir} ${daydir} ${tme} ${dur} ${sza} ${azm} ${radofearth} ${itr} ${thisfltr} ${pcol}" >> ${result_fname}.l # make profile listing from PRFS.out file pline='' pclin='' click=0 while read line do #print ${line} set ${line} if [ $click == 0 ] then click=1 else pline="$4 ${pline}" pclin="$7 ${pclin}" fi done > ${result_fname}.q print "${mymol} ${daydir} ${tme} ${sza} ${azm} ${thisfltr} $pc2 ${pclin}" >> ${result_fname}.qc # rearrange the short output file for plotting in IDL sfitplt.pro # save as zsum # print -R "[filenames]" > zsum # print -R "rdrv.ctl" >> zsum # print -R "[titles]" >> zsum # print -R "${sline[0]}" >> zsum # print -R "$filename_line" >> zsum # also print run summary info to screen print " " print "Run summary:" print -R "${sline[0]}" print -R "$filename_line" print -R "$filename_line" >>summary.st # one loop does it all let n=1 while(( ${n} < ${nlines} )) do print -R "${sline[n]}" >> ${result_fname} # print -R "${sline[n]}" >> zsum print -R "${sline[n]}" let n=${n}+1 done # let n=1 # while(( ${n} < ${nlines} )) # do # if [[ ${sline[n]} == "Itr"* ]] # then # print -R "${sline[n]}" >> zsum # let n=${nlines}-1 # else # print -R "${sline[n]}" >> zsum # let n=${n}+1 # fi # done print " " >> $result_fname print "*****************************************************************************************" # we are all done (if everything worked!) exit 0