#! /bin/bash # shell script to extract the precip column from a hydro.out # format file, divide it out into single year segments, # wrap it into a 8 line UNSAT-H format, placing it into # separate files for each year with the year + 1900 in # the file name for all the years in the hydro.out format # file. # find maximum year value in file and set to variable maxyears=`dm "if N>1 then INPUT else SKIP" <$1 | dm x3 | stats max` # set first year let year=0 while [ "$year" != "$maxyears" ] do let year=year+1 # shift into 1900 year range let outyear=year+1900 # find number of days with rain in file for this year nwater=`dm "if N>1 then INPUT else SKIP" <$1 | \ dm "if x3=$year AND x12>0 then x12 else SKIP" | \ stats n` echo "$nwater," > "rain$outyear.dat" # first line, skips lines without full columns # second line, selects desired year # third line, pulls eight values unto one line # '$!N' stops getting lines at the last line # fourth line, adds comma to end of each line except the last dm "if N>1 then INPUT else SKIP" <$1 | \ dm "if x3=$year AND x12>0 then INPUT else SKIP" | \ dm x2 x12/10 | \ sed -e 's/\t/,1,2,1.0,\n1.0,/' -e 's/.*/&,\n2.0,0.0,/' >> \ "rain$outyear.dat" echo "created rain$outyear.dat breakpoint rainfall file" done