#! /bin/bash # shell script to wrap wind data in a year,month, day, hour format # into a line with 24 values for each day. # if hourly temperature and precipitation are present, they are also # processed into cligen formatted columns of # precip, duration, 0.5, intensity of peak, tmax, tmin # to run on the command line: # hourwind [input file name] > [output file name] # create arrays of hour column and wind vel column years=( `dm x1 < $1` ) months=( `dm x2 < $1` ) days=( `dm x3 < $1` ) hours=( `dm x4 < $1` ) allwindvel=( `dm x5 < $1` ) alldir=( `dm x6 < $1` ) alltemp=( `dm x7 < $1` ) allprecip=( `dm x8 < $1` ) # initialize data arrays let index=0 pi=3.14159 evect=0 nvect=0 daywindvel=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ) mintemp=999 maxtemp=-999 precip=0 maxprecip=-999 raindur=0 for wval in ${allwindvel[@]} do # when at end of day: let indexminus=index-1 if [[ $index -gt 0 ]] then if [[ ${hours[indexminus]} -gt ${hours[index]} ]] then # finalize daily vector direction windir=`echo "$evect $nvect $pi" | dm 'atan(x1/x2)*180/x3' | dm 'if x1<0 then x1+360 else x1'` # echo out the whole line echo "${days[indexminus]} ${months[indexminus]} ${years[indexminus]} $windir ${daywindvel[@]} $precip $raindur 0.5 $maxprecip $mintemp $maxtemp" # zero out day wind velocity array evect=0 nvect=0 daywindvel=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ) mintemp=999 maxtemp=-999 precip=0 maxprecip=-999 raindur=0 fi fi # sum or place each hourly value in position evect=`echo "$evect ${wval} ${alldir[index]} $pi" | dm 'x1+x2*sin(x3*x4/180)'` nvect=`echo "$nvect ${wval} ${alldir[index]} $pi" | dm 'x1+x2*cos(x3*x4/180)'` daywindvel[${hours[index]}]=${wval} mintemp=`echo "$mintemp ${alltemp[index]}" | stats min` maxtemp=`echo "$maxtemp ${alltemp[index]}" | stats max` precip=`echo "$precip ${allprecip[index]}" | dm x1+x2` maxprecip=`echo "$maxprecip ${allprecip[index]}" | stats max` raindur=`echo "$raindur ${allprecip[index]}" | dm 'if x2>0 then x1+1 else x1'` # increment index to next value let index=index+1 done # upon termination, echo out the last whole line echo "${years[indexminus]} ${months[indexminus]} ${days[indexminus]} $daywindvel[@]"