#!/bin/bash # Takes file with day, month, year, precip, precip, duration, time_peak and intensity # this was written to set duration, time_peak and intensity for the first precip # location from the parameters for a precipitation event at another location. # auto set number of values on the line linelen=`head -1 <$1 | dm N` # get line and place line values in variable array allval=( `cat $1` ) # set up initial nextval array values np=0 for singval in ${lineval[@]} do let np=np+1 if [ $np -le $linelen ] then nextval[np]=$singval # echo "nextval($np) = ${nextval[np]}" fi done nline=0 for singval in ${allval[@]} do let nline=nline+1 lastval[nline]=${nextval[nline]} nextval[nline]=$singval if [ $nline -eq $linelen ] then # echo "lastval(1-$linelen) = ${lastval[@]}" # echo "nextval(1-$linelen) = ${nextval[@]}" # check for match of rainfall amounts at both locations if [ `echo "${nextval[4]} ${nextval[5]}" | dm "if x1>0 and x2>0 then 1 else 0"` -gt 0 ] then # rainfall at both locations outval[1]=${nextval[1]} outval[2]=${nextval[2]} outval[3]=${nextval[3]} outval[4]=${nextval[4]} outval[5]=`echo "${nextval[4]} ${nextval[5]} ${nextval[6]}" | dm "(x3*x1)/x2" "21*sin(0.028*x1)+4*sin(0.056*x1)" | stats min` outval[6]=${nextval[7]} outval[7]=${nextval[8]} elif [ `echo "${nextval[4]} ${lastval[5]}" | dm "if x1>0 and x2>0 then 1 else 0"` -gt 0 ] then # rainfall at other location on previous day outval[1]=${nextval[1]} outval[2]=${nextval[2]} outval[3]=${nextval[3]} outval[4]=${nextval[4]} outval[5]=`echo "${nextval[4]} ${lastval[5]} ${lastval[6]}" | dm "(x3*x1)/x2" "21*sin(0.028*x1)+4*sin(0.056*x1)" | stats min` outval[6]=${lastval[7]} outval[7]=${lastval[8]} elif [ `echo "${nextval[4]}" | dm "if x1>0 then 1 else 0"` -gt 0 ] then # rain day at location only outval[1]=${nextval[1]} outval[2]=${nextval[2]} outval[3]=${nextval[3]} outval[4]=${nextval[4]} outval[5]=`echo "${nextval[4]}" | dm "0.358*x1"` outval[6]=0.5 outval[7]=5.58 else # rain day at location only outval[1]=${nextval[1]} outval[2]=${nextval[2]} outval[3]=${nextval[3]} outval[4]=${nextval[4]} outval[5]=0 outval[6]=0 outval[7]=0 fi echo "${outval[@]}" nline=0 fi done