#!/bin/sh # try_hw4: create single data file of temperatures for tucson for year 1995 # Assume filename format of: jan00-f6.txt if [ -f year.dat ]; then /usr/bin/rm year.dat; echo "removing year.dat"; fi printf "\nEnter year to plot (95, 96, etc.)\n" read yr for i in jan feb mar apr may jun jul aug sep oct nov dec do cat $i$yr*.txt >> year.dat echo processing month: $i done printf "\nEnter starting day for year '$yr (Mon, Tue, Wed, Thu, Fri, Sat, or Sun)\n" read daystart printf "\nPlot: average (1); max (2); min (3)\n" read plot case $plot in 1) field=4;; 2) field=2;; 3) field=3;; esac cat year.dat | nawk '/Dy Max/,/Sm/ { if ($0 ~ /^[ ]?[0-9]+/) print }' | nawk ' BEGIN{ if ("'$daystart'" == "Tue") split("1 2 3 4 5 6 7", days) else if ("'$daystart'" == "Wed") split("2 3 4 5 6 7 1", days) else if ("'$daystart'" == "Thu") split("3 4 5 6 7 1 2", days) else if ("'$daystart'" == "Fri") split("4 5 6 7 1 2 3", days) else if ("'$daystart'" == "Sat") split("5 6 7 1 2 3 4", days) else if ("'$daystart'" == "Sun") split("6 7 1 2 3 4 5", days) else if ("'$daystart'" == "Mon") split("7 1 2 3 4 5 6", days) } { print days[(NR % 7) + 1], $'$field' }' > final.out printf "\nPlot data? (y/n)\n" read answer if [ $answer = y ]; then cat final.out | nawk ' $1 == 1 { sum1 += $2; count1++; } $1 == 2 { sum2 += $2; count2++ } $1 == 3 { sum3 += $2; count3++ } $1 == 4 { sum4 += $2; count4++ } $1 == 5 { sum5 += $2; count5++ } $1 == 6 { sum6 += $2; count6++ } $1 == 7 { sum7 += $2; count7++ } END { print 1, sum1/count1 print 2, sum2/count2 print 3, sum3/count3 print 4, sum4/count4 print 5, sum5/count5 print 6, sum6/count6 print 7, sum7/count7 }' > plot.out xmgr -geometry 694x483-49+7 -autoscale xy -p temp.par plot.out printf "\nfinal data stored as: final.out\n" printf "plot data stored as: plot.out\n" fi