#! /bin/bash # shell script file to extract single column of individual year data # from hydrobal.out file # At the command prompt type # falloweff hydrobal.out # or to run multiple files, type # find . -depth -name hydrobal.out -exec falloweff {} \; # In both cases, the results are placed in falloweff.txt in the directory # from which the command is run. # columns of interest in hydrobal.out are: # 4 - start day of hydrobalance period # 5 - starting soil water content (mm) # 6 - starting snow water content (mm) # 8 - end day of hydrobalance period # 9 - ending soil water content (mm) # 10 - ending snow water content (mm) # 12 - rainfall for period (mm) # 13 - runoff for period (mm) # 14 - evaporation for period (mm) # 15 - transpiration for period (mm) # 16 - drainage for period (mm) # 17 - check for period (mm) # 18 - fallow efficiency (delta swc / precip) # get columns 15 and 18 from hydrobal.out (transpiration and fallow efficiency) hydrobalcols $1 temp 15 18 # maximum number of "trigger" operations = maxoper + 1 maxoper=`sed -n '1p' < temp | dm N` let maxoper=maxoper/2 #echo "maxoper = $maxoper" # create dm script file to select only the fallow efficiency for non crop growing periods # by checking for transpiration and skipping those with it. numcol=2 chkcol=1 # transpiration check column, divide between growth and non growth periods effcol=2 # fallow efficiency column maxcolp=`expr $maxoper \* $numcol + $numcol + 1` echo "if \(x$chkcol=0\) then x$effcol else x$maxcolp" >screen.dm for mult in $(seq $maxoper) do totcol=`expr $mult \* $numcol` tchkcol=`expr $totcol + $chkcol` # total columns to reach check column on multiple operations teffcol=`expr $totcol + $effcol` echo if \(x$tchkcol=0\) AND \(x$teffcol\>0\) then x$teffcol else x$maxcolp >>screen.dm done # # calculate fallow efficiency for each fallow period echo $1 > temp1 dm Escreen.dm < temp > temp0 # summary statistics for each fallow efficiency column count=`expr $maxoper + 1` for mult in $(seq $count) do colex $mult < temp0 | stats mean >> temp1 done # remove zero lines from results file grep "[.]" < temp1 # remove excess files rm screen.dm rm temp rm temp0 rm temp1