#! /bin/bash # create input file to drive creation of a single file # containing all layer values for all simulation years # from an UNSAT-H run using DOUT301.EXE # USE: dout_theta [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 infilepre="${1}${minyear}" # 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 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 rm temp1.in rm temp1.out