#! /bin/bash # create input file to drive creation of a single file # containing all layer values in WEPS hlayer.out format # from an UNSAT-H run using DOUT301.EXE # USE: dout_hlayer [file name preface (not including year.res part)] # get number of years from file names minyear=`find . -name "$1*.res" -print | \ sed -e "s/\.\/$1//" -e "s/\.res//" | \ stats min` maxyear=`find . -name "$1*.res" -print | \ sed -e "s/\.\/$1//" -e "s/\.res//" | \ stats max` echo "minyear = $minyear" echo "maxyear = $maxyear" # file name for yearly file without extension if [ ${minyear} -eq 0 ] then infilepre="${1}" else infilepre="${1}${minyear}" fi # get number of layers # create input file to extract number of layers from DOUT301.EXE echo "$infilepre" > temp1.in echo "4" >> temp1.in echo "2" >> temp1.in echo "0" >> temp1.in echo "1 1" >> temp1.in echo "" >> temp1.in echo "0" >> temp1.in echo "0" >> temp1.in # extract number of layers numlay=`./dout301.exe //' | \ dm x3` echo "numlay = $numlay" # create multiyear base file totalfile=${1}_theta.out echo "# unsat-h theta file numlay = $numlay" > $totalfile echo "" >> $totalfile echo "" >> $totalfile # loop through all files by year if [ ${minyear} -eq 0 ] then # file name for yearly file without extension infilepre="${1}" # get valid number of days # put commands into input pipe file # file name prefixes echo "$infilepre" > temp1.in echo "5" >> temp1.in echo "2" >> temp1.in echo "1 0" >> temp1.in echo "0" >> temp1.in echo "0" >> temp1.in echo "0" >> temp1.in dayrange=`dout301 < temp1.in | grep days | grep through | sed "s/days//" | sed "s/through//"` startday=`echo ${dayrange} | sed "s/\ .*//"` endday=`echo ${dayrange} | sed "s/.*\ //"` # echo $startday $endday # loop through days for nday in $(seq $startday $endday) do # put commands into input pipe file echo "$infilepre" > temp1.in echo "5" >> temp1.in echo "2" >> temp1.in echo "1 $nday" >> temp1.in echo "1" >> temp1.in echo "temp1.out" >> temp1.in echo "0" >> temp1.in echo "0" >> temp1.in # create output file echo "compositing output for day $nday" dout301 < temp1.in > NULL # reformat output file and add to end of total output file dm "if INLINE > 11 then INPUT else SKIP" < temp1.out | dm $nday $nday 1 x1 "x2*10" x3 >> $totalfile echo "" >> $totalfile done else let year=minyear-1 while [ "$year" != "$maxyear" ] do let year=year+1 # file name for yearly file without extension infilepre="${1}${year}" # single year all layers out file name yearfile="theta_${year}.out" # create input file to extract info for layer groups for # this year using DOUT301.EXE # name prefixes echo "$infilepre" > temp1.in #loop through layers let lay=0 while [ "$lay" != "$numlay" ] do let lay=lay+1 echo "4" >> temp1.in echo "2" >> temp1.in echo "1" >> temp1.in echo "theta_${year}_${lay}.out" >> temp1.in echo "1 $lay" >> temp1.in done echo "0" >> temp1.in # extract each layer into individual file ./dout301.exe < temp1.in > /dev/null # condense single year, single layer files into one single year file let lay=1 # strip top 11 lines, and put day, year and first layer columns # into yearly base file dm "if INLINE > 11 then INPUT else SKIP" < \ theta_${year}_${lay}.out | \ dm x1 "$year" x2 > $yearfile # remove layer file rm theta_${year}_${lay}.out while [ "$lay" != "$numlay" ] do let lay=lay+1 # strip top 11 lines, and put theta column into temp file dm "if INLINE > 11 then INPUT else SKIP" < \ theta_${year}_${lay}.out | \ dm x2 > temp1.out # remove layer file rm theta_${year}_${lay}.out # place temp file column into base file abut $yearfile temp1.out > temp2.out mv temp2.out $yearfile done # add two blank lines to end of yearly file (for GNUPLOT) # and cat file to end of base file echo "" >> $yearfile echo "" >> $yearfile cat $yearfile >> $totalfile # remove yearly file rm $yearfile echo "finished adding ${infilepre}.out to ${1}_theta.out" done fi #rm temp1.in #rm temp1.out