#!/bin/bash # shell script file to extract single column of individual year data # from harvest.out type of file # # At the command prompt type # harvfilter harvest.out # # columns of interest in harvest.out are: # 4 - yield (lbs/acre or kg/m^2) # 5 - residue (lbs/acre or kg/m^2) # 6 - harvest index # 7 - yield (bu/acre or other user units) # # create file to use dm to screen harvest.out file # in files with multiple columns, grab only the second year # the x100 term limits this to 12 (8*12=96 columns)harvest events # in a harvest.out file, since the x100 is placed to give a zero result # only 8 harvest events are processed below harvcol=$2 echo "if N=8 then x$harvcol else x100" > screen.dm echo if \(N\>8\) AND \(x3=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 8 + $2` echo if \(N\>8\) AND \(x11=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 16 + $2` echo if \(N\>8\) AND \(x19=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 24 + $2` echo if \(N\>8\) AND \(x27=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 32 + $2` echo if \(N\>8\) AND \(x35=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 40 + $2` echo if \(N\>8\) AND \(x43=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 48 + $2` echo if \(N\>8\) AND \(x51=2\) then x$harvcol else x100 >> screen.dm harvcol=`expr 56 + $2` echo if \(N\>8\) AND \(x59=2\) then x$harvcol else x100 >> screen.dm # # remove text from harvest.out and put spaces in place of / so column count is correct # in this original script, the text was enclosed in quotes # sed s/\"[^\".]*\"//g "$*" | sed 's/\// /g' | dm \"if INLINE\>1 then INPUT else NEXT\" >temp # in this script, the text is enclosed in |, but only because text and numbers # alternate, and by chance, we start in the right pattern and alternate text # and numbers. (whew) Changes in WEPS.FOR eliminated initialization from harvest.out # so removed the INLINE>1 editing echo "$*" sed s/\|[^\|.]*\|//g "$1" | sed 's/\// /g' > temp # # seldir=`echo -r $1 | sed 's/harvest_en.out//g'` filerep=$seldir'yield.rep' # # calculate annual average yield (maximum 8 harvests maximum 2 years) dm Escreen.dm temp0 dm x1+x2+x3+x4+x5+x6+x7+x8+x9 temp1 # # copy temporary file into original directory cp temp1 $filerep # # remove excess files rm screen.dm rm temp rm temp0 rm temp1