#!/bin/ksh # plottemps - creates graphs of temperature readings from Hot Little Therm # $Id: plottemps,v 1.16 2002/10/15 01:07:56 johan Exp $ #################### # (C) 2002 Johan van Zanten # johan@giantfoo.org # http://www.giantfoo.org/~johan # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # The GPL can be found at http://www.fsf.org/copyleft/gpl.html # Unlimited License to use this shell script is granted to anyone who # wants it. #################### # requires: thermal data, Ploticus graphing software ("pl") unset noclobber HOST=`uname -n` ME=`basename $0` OS=`uname` OSwV=${OS}-`uname -r` PATH=/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin:/local/bin:/usr/local/share/bin LD_LIBRARY_PATH=/usr/pkg/lib:/usr/lib:/usr/X11R6/lib export PATH LD_LIBRARY_PATH umask 002 # Echo our args to standard error. function errecho { echo $* >&2 } # The infamous usage function. function usage { errecho "usage: ${ME} [ -1 input.file1 ] [ -2 input.file2 ] [ -whxdFC ] [ -s num_samples ] " exit 1 } therm_data_dir=/var/thermlogs f1=$therm_data_dir/inside-N-1 f2=$therm_data_dir/outside-N-1 #allfiles="$therm_data_dir/inside-N-1 $therm_data_dir/outside-N-1" #allfiles="$therm_data_dir/inside-N-1" # tmpdir=~/tmp/$ME # Default input file #infile=$therm_data_dir/Coloco-MR-F.log # temp_template=/local/lib/therm-template.html # Default output is not X11, but a file. unset xoutput plot_diff # output_dir=$tmpdir get_new_data=true plots="0 1" # Default pl options and command-line switches. pl_opts=" -stdin -inches -png " while getopts FCwhxds:1:2: opt do case $opt in # Look for signs for help... h) cat < $tmpdir/$tmpfile & fi done cd $tmpdir wait datestamp=`tail -1 $t1 | nawk '{print $1}'` join $t1 $t2 > $j_fn # Identify current temps. echo "Getting current temps..." cur_line="Current Temperatures at `date` : " # # get current conditions (last lint of data file) cur_cond=`therm inside-N-1 outside-N-1 \ | nawk '{printf "
%s %.1f %.1f\n", $1, $3, $3*1.8+32}'` cur_line=`echo $cur_line $cur_cond '
'` cd $tmpdir ## get highest and lowest temps, we use these in the graphing. ## echo "determining max and mins for all data ..." cat $tmpfiles \ | nawk 'BEGIN { C_max=-999.9 C_min=999.9 } { if ($2 > C_max) C_max = int($2) +1 if ($2 < C_min) C_min = int($2) } END { F_max = ((C_max*1.8)+32) F_min = ((C_min*1.8)+32) printf "%.0f %.0f %.0f %.0f\n", C_max, C_min, F_max, F_min }' > hilos.tmp read C_max C_min F_max F_min < hilos.tmp # Array elements with subscript "0" are for plotting with degrees C # Array elements with subscript "1" are for plotting with degrees F output_file[0]=$output_dir/temperature-C-${num_samples}.png output_file[1]=$output_dir/temperature-F-${num_samples}.png max[0]=$C_max min[0]=$C_min max[1]=$F_max min[1]=$F_min echo "Min/Max: F: $F_max/$F_min C: $C_max/$C_min" temp_scale[0]=Celsius temp_scale[1]=Fahrenheit grid_color[0]=skyblue grid_color[1]=lavender y_fld[0]=2 y_fld[1]=3 # Defaults for graphs title="Local temparatures at TEW HQ" scale=1 if [[ $num_samples -eq 288 ]] then scale=.7 title="Local temparatures at TEW HQ, last 24 hours" output_file[0]=$output_dir/temperature-24h-C.png output_file[1]=$output_dir/temperature-24h-F.png fi ############################## # # The plotting # We have a 2-loop for statement to produce both Celsius and Fahrenheit # graphs, but wiuthout having to maintain two seperate sets of plotting # instructions. # Beware, there are ksh variables embedded in the plotting # instruction, which will (hopefully) be replaced with the correct values # before "pl" actually runs. for i in $plots do if [[ -n $xoutput ]] then output="-x11" else output="-o ${output_file[i]}" fi echo "Running ploticus. Output will be sent to ${output} ." pl ${pl_opts} ${output} < 2399 && @NRECORDS < 105120 xautorange: datafield=1 nearest=day #endif #if @NRECORDS > 105119 xautorange: datafield=1 nearest=month #endif //////////////////// // This is the "primary" axis usually hours, unless we have more than a #proc xaxis #if @NRECORDS < 2400 stubformat: hh:mm #endif //////// #if @NRECORDS < 2400 stubs: inc 12 hours minorticinc: 6 hours #endif #if @NRECORDS < 1600 stubs: inc 8 hours minorticinc: 4 hours #endif #if @NRECORDS < 800 stubs: inc 4 hour minorticinc: 2 hour #endif // 24 hours or less #if @NRECORDS < 289 stubs: inc 2 hour minorticinc: 1 hour #endif ////////// #if @NRECORDS > 2399 stubformat: Mmm-dd stubs: inc 1 day minorticinc: .5 day #endif #if @NRECORDS > 4801 stubformat: Mmm-dd stubs: inc 2 days minorticinc: 1 day #endif #if @NRECORDS > 11519 stubformat: Mmm-dd stubs: inc 4 days #endif // 90 days or more of data #if @NRECORDS > 25919 stubformat: Mmm-dd stubs: inc 8 days #endif // 180 days or more of data #if @NRECORDS > 51839 stubformat: Mmm-dd stubs: inc 16 days minorticinc: 4 days #endif // a year or more of data #if @NRECORDS > 105119 stubformat: Mmm-dd stubs: inc 1 month minorticinc: .5 month autoyears: yyyy #endif ////////// label: Time axisline: yes grid: color=${grid_color[i]} minortics: yes //////////////////// /// X Axis number 2 #proc xaxis // #if @NRECORDS > 500 && @NRECORDS < 2400 stubs: increment 1 day stubformat: Mmm-dd location: min-0.22 axisline: none stubdetails: none #endif //////////////////// /// Y Axis number 1 #proc yaxis stubs: inc 1 degree label: ${temp_scale[i]} labeldetails: adjust=-0.5,0 axisline: yes grid: color=${grid_color[i]} minortics: yes minorticinc: .5 #proc lineplot xfield: 1 yfield: ${y_fld[i]} linedetails: width=1.5 color=red legendlabel: Indoor, air entering machine rack #proc lineplot xfield: 1 yfield: $((${y_fld[i]}+2)) linedetails: width=1.5 color=green legendlabel: Outdoor, north side of house //////////////////// /// Y Axis number 2 #proc yaxis stubs: inc 1 degree location: max stubdetails: adjust=0.6,0 ticlen: -0.1 axisline: yes grid: color=${grid_color[i]} minortics: yes minorticlen: -0.05 minorticinc: .5 #proc legend location: min+0.2 min-0.3 EOF done wait sed "s?^Current Temperatures.*\$?${cur_line}?" $temp_template > $temp_doc # If we are sending output to webdir, try to generate a xbm-type file to # give to xlockmore. if [ $webout = "true" ] && [ $num_samples -eq 288 ] then if type pngtopnm >/dev/null 2>&1; then xpmfile=`echo ${output_file[0]} | sed 's/png$/xpm/'` echo "Creating $xpmfile ..." pngtopnm ${output_file[0]} | ppmtoxpm > $xpmfile 2>/dev/null fi fi if [[ $debug != "true" ]] then rm -f $tmpfiles fi exit