#!/usr/bin/env ruby ### wxWindCompass --- Generate data for a wind compass graph. ## Copyright 2006 by Dave Pearson ## $Revision: 1.1 $ ## ## wxWindCompass is free software distributed under the terms of the GNU ## General Public Licence, version 2. For details see the file COPYING. # If we've been passsed the line count. if ARGV[ 0 ] then # Get the line count. linecount = ARGV[ 0 ].to_f # Line counter. n = 0 # For each line. $stdin.each do |line| # Split the data data = line.chomp.split( " " ) # Extract the speed and direction. speed = data[ 0 ].to_f direction = data[ 1 ].to_f # If there was wind. if speed > 0 then # Figure out where to plot. x = ( direction / 360.0 ) * ( Math::PI * 2 ) y = n / linecount # Emit the line. puts "#{ Math.sin( x ) * y }, #{ Math.cos( x ) * y }" end # Increment the line counter. n += 1 end else puts "Syntax:" puts " wxWindCompass " end