#!/usr/bin/perl #Converts a text file into postcript file describing a kite-diagram #Usage: kitediagram.pl #The input file format is CSV. The first line is a list of labels for the x-axis #Subsequent lines consist of a label for that kite, and a list of measurements use POSIX qw(ceil floor); #Get the name of the input file, and open it $file=$ARGV[0]; if(!$file){$file="data.txt"}; open(INPUT, "<$file") or die "Could not open $file for reading"; #Form the name of the output file, and open it ($outputName, $trash)=split('\.', $file); $outputName .= ".ps"; open(MYOUTPUTFILE, ">$outputName") or die "Could not open $outputName for writing"; #Read the input file, splitting out the x-axis labels, and putting the others straight into an array $rowNumber=-1; while() { $rowNumber++; $line=$_; if ($rowNumber==0){ @xAxisLabels = split(',', $line); }else{ push(@lines, $line); } } #Work out the scale factor, before we start decremating $rowNumber $vSpaceNeeded= 130 + 120*($rowNumber-1); $vScaleFactor= 792 /$vSpaceNeeded; #form the postscript needed to graph each line while($rowNumber > 0){ ($label, @data)=split(',', $lines[$rowNumber-1]); $spaceLeft = 20; $width = floor( (612-$spaceLeft) / (scalar @data) ); #horizonatal space between data-points $rightCoord = $width * (scalar @data - 1) + $spaceLeft; $centerHeight = 60 + 120*($rowNumber-1); #$centerHeight = 792 - $centerHeight; #$centerHeight = 742 - 120*($rowNumber-1); $topHeight = $centerHeight+50; $bottomHeight = $centerHeight-50; $tickLeft = $spaceLeft - 4; #4 is the length of the tick $labelTop=$topHeight-4; $labelMiddle=$centerHeight-4; $labelBottom=$bottomHeight-4; $output .= topCurve(); $output .= bottomCurve(); $output .= xAxis(); $output .= yAxis(); $output .= xAxisLabels(@xAxisLabels); $output .= title(); $rowNumber -= 1; } #output the postscript and close the file print MYOUTPUTFILE "1 $vScaleFactor scale\n"; print MYOUTPUTFILE $output; close MYOUTPUTFILE; sub xAxis { #The axis: $xAxis .= <