#!/usr/bin/perl -w
######################################################################
# This program creates disk matrices from rstats files. If you
# have questions or comments, email me at ejrawdon@stthomas.edu.
# This program was downloaded from
# http:george.math.stthomas.edu/~rawdon
#
# Copyright (C) 2017 Eric J. Rawdon
#
# 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 3 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.
# For a copy of the GNU General Public License, see
#
######################################################################
use Math::Trig;
use Getopt::Std;
######################################################################
# CHANGE THE $bindir FOR YOUR SYSTEM UNLESS YOU HAVE EVERYTHING IN THE
# DIRECTORY FROM WHICH YOU ARE RUNNING THIS PROGRAM
######################################################################
$bindir = "./";
######################################################################
# parse the command line
# usage: roundv4.prl
# -f rstatsfile
# -o svgoutfile
# -v vertices
# [-s] # make the non-swirly graph
# [-h] # have hovering capability for seeing arc numbers
# [-w cutoff] # white the under cutoff
# [-a] # autofill shorties
# [-c] # use fixed colors
# [-n] # normalizes value to maximum of 1
######################################################################
$program = "roundv4.prl: ";
$usage = "usage for $program\n -f rstatsfile\n -o svgoutputfile \n -v vertices \n [-s] \# make a non-swirly graph\n [-w cutoff] \# white the under cutoff\n [-h] \# add hovering feature\n [-a] autofill shorties\n [-c] \# use fixed colors\n [-n] \# normalizes values to a maximum of 1";
my %Options;
# : means it takes input
getopts('f:o:v:w:shadcn', \%Options);
$ok = (defined($Options{'f'}) && defined($Options{'o'}) && defined($Options{'v'}));
($ok) || die("$usage\n");
######################################################################
# required flags -v -f -o, and optional -w
######################################################################
$vertices = $Options{'v'};
$file = $Options{'f'};
$outfile = $Options{'o'};
$cutoff = 0.0;
if(defined($Options{'w'})){
$cutoff = $Options{'w'};
}
######################################################################
# Read in colors
######################################################################
if(defined($Options{'c'})){
(-e "$bindir/keyfixed.colors") || die("Can't find $bindir/keyfixed.colors\n");
open(IN,"$bindir/keyfixed.colors") || die("Can't open $bindir/keyfixed.colors\n");
while(defined($line = )){
chomp($line);
@fields = split(/\s+/,$line);
$knottype = $fields[0];
$color = $fields[1];
$knottypetocolorhash{$knottype} = $color;
}
close(IN);
}
else{
(-e "$bindir/key.colors") || die("Can't find $bindir/key.colors\n");
open(IN,"$bindir/key.colors") || die("Can't open $bindir/key.colors\n");
$k = 0;
while(defined($line = )){
chomp($line);
$color[$k] = $line;
$k++;
}
close(IN);
}
######################################################################
# set up constants
######################################################################
$height = 1000; # height of actual matrix
$width = 1000; # width of the actual matrix
if(defined($Options{'h'})){
$topybuffer = 70; # buffer zone at the top, clean space now
}
else{
$topybuffer = 10; # buffer zone at the top, clean space now
}
$bottomybuffer = 10;
$leftxbuffer = 10;
$rightxbuffer = 370; # need space for knot types and key
$midx = $leftxbuffer + $width/2;
$midy = $topybuffer + $height/2;
$dx = $width/(2*($vertices-1));
$theta = 360.0/$vertices;
$radianstheta = 2.0*pi/$vertices;
$fontsize = 48; # how big the numbers are in the x and y axes, was 32
$knottypefontsize = 48; # for key on right
$knottypefontshift = $knottypefontsize/3; # for key on right
$rectwidth = 50; # width of key band of colors on the right
$rectshiftright = 20; # distance from right of matrix to start of key
$textrightshift = 5; # distance from right edge of key rectangle to have middle of knot type text
$realwidth = $width + $leftxbuffer + $rightxbuffer;
$realheight = $height + $topybuffer + $bottomybuffer;
######################################################################
# if we need to normalize, then normalize
# in such a case $max holds the number
######################################################################
(-e $file) || die("Can't find $file\n");
if(defined($Options{'n'})){
$max = -1.0;
open(IN,"$file") || die("Can't open $file\n");
while(defined($line = )){
chomp($line);
@fields = split(/\s+/,$line);
if($max < abs($fields[3])){
$max = abs($fields[3]);
}
}
close(IN);
}
######################################################################
# read in file and go at it
######################################################################
open(IN,"$file") || die("Can't open $file\n");
open(OUT,">$outfile") || die("Can't open $outfile\n");
print OUT ("\n");
print OUT ("\n");
print OUT ("\n");
close(OUT);
close(IN);