#!/usr/local/ug/bin/perl5.003 #new perl engine is on owl (above) #old perl engine is on chico (below) #/users/research/students/chow/perl5/bin/perl ####################################################################### # file: ~lstein/public_html/cgi-bin/NetRes.pl # date: 4/10/96 # original: plot.pl 4/10/96 # purpose: generates a graphical plot of network data from files # # revision: created from plot.pl 9/3/96 for grad project # cleanup for release # # data flow: This program is called from the # ~lstein/NetRes/perl/NetRes.html form # After a person fills in what network and 2 nodes they # want and submit the form, this program is called # This program # 1. creates a web page for results of this program via # print statements you will find in this program # 2. reads two input data files under network directory # ./$net(nj or us)/rreact/$node1.$node2.cutl # ./$net(nj or us)/twoprong/$node1.$node2.cutl # 3. writes to 5 output files in ./plotdemo directory # ./plotdemo/$rreact_data # ./plotdemo/$twoprong_data # ./plotdemo/$gnuplot_cmd); # ./plotdemo/netres.ppm # ./plotdemo/netres.gif # 4. runs gnuplot program passing gnuplot_cmd file # 5. runs the ppmtogif program passing netres.ppm file # and redirecting output to netnres.gif # 6. exit program which returns web page generated on fly # showing graph generated by this program # ####################################################################### use CGI; # will use perl object library # extract params from web page environment passing $query = new CGI; # create a new query object $net = $query->param(net); # extract $net value from web page arguement $node1 = $query->param(node1); # extract $node1 value from web page $node2 = $query->param(node2); # extract $node2 value from web page # define the algorithms we want to do @algorithm = ("rreact","twoprong"); #define array with both alg names # start the web page print "Content-type: text/html\n\n"; print "~lstein/cgi-bin/owl/NetRes.pl\n"; print "\nNetRes web page created by NetRes.pl program\n\n"; print "

@algorithm Simulation Plot on $net net
\n"; print "with break between $node1 and $node2

\n"; # quality control check user asked for two nodes if ($node1 eq $node2) { print "

Error! node1=$node1 can not be the same as node2=$node2\n"; exit; } if ($net eq "nj") { if ($node1 gt "N10") { print "

Error! NJ net only has 11 nodes retry \n"; print "
To return and try again click here
\n"; print "\n"; print "click here


\n"; exit; } elsif ($node2 gt "N10") { print "

Error! NJ net only has 11 nodes retry \n"; print "
To return and try again click here
\n"; print "\n"; print "click here


\n"; exit; } # end elsif } # end if $net eq nj # for the gnuplot program we have 3 files, 2 data files and a # command file (which is the instructions to gnuplot) # here we define the name of our data files $rreact_data = "plotdemo/rreact_data"; $twoprong_data = "plotdemo/twoprong_data"; $gnuplot_cmd = "plotdemo/gnuplot_cmd"; # remove any old data & command files lying around # note the command file name is a literal system("rm -f $rreact_data"); system("rm -f $twoprong_data"); system("rm -f $gnuplot_cmd"); system "rm -f plotdemo/netres.ppm"; # system "rm -f plotdemo/netres.gif"; # get rid of any old one open(GNUPLOTRREACT, "> $rreact_data"); # open data file for write open(GNUPLOTTWOPRONG, "> $twoprong_data"); # open data file open(GNUPLOTCMD, "> $gnuplot_cmd"); # open command file # we will start plotting from coords x=0,0 y=0,0 print GNUPLOTRREACT "0.0 0.0\n"; # start writing data print GNUPLOTTWOPRONG "0.0 0.0\n"; # start writing data # for each of the algorithm names (rreact & twoprong # do the following foreach $astring(@algorithm) { $algorithm = $astring; # extract this algorithm name # define where we will find the data file on disk $net_data_file = "$net/$algorithm/$node1-". $node2 . "cut.l"; # start body section of web page print "net_data_file=$net_data_file
\n"; open(INPUT, "$net_data_file"); # open the data file to INPUT while () # read all the lines in the input file { # now for each line s/\)/ /; # get rid of (; s/\(/ /; # get rid of ); @words = split(/\s+/); # use white spaces as separators if ( $words[0] eq "Path") # here is the data line to plot { parse(); # call the subroutine to get data } } # end while } # end foreach close(INPUT); # okay, all done with data input file close(GNUPLOTRREACT); # done writing our data to data file close(GNUPLOTTWOPRONG); # done writing our data to data file # start printing instructions for the gnuplot program print GNUPLOTCMD "set term pbm small color\n"; print GNUPLOTCMD "set size 0.72, 0.54\n"; print GNUPLOTCMD "set output \"plotdemo/netres.ppm\" \n"; print GNUPLOTCMD "set title \"$algorithm simulation on $net". ", $node1-$node2 break\" \n"; print GNUPLOTCMD "set grid\n"; print GNUPLOTCMD "set xlabel \'Time (sec)\' \n"; print GNUPLOTCMD "set ylabel \'Restoration Level\' \n"; print GNUPLOTCMD "set yrange [0:100] \n"; print GNUPLOTCMD "plot \"$rreact_data\" with linesp 1, ". " \"$twoprong_data\" with linesp 2 \n"; close GNUPLOTCMD; # done with gnuplot instructions # now execute the gnuplot program, passing gnuplot_cmd instructions system "/usr/local/ug/bin/gnuplot plotdemo/gnuplot_cmd"; # run it ! # run the ppmtogif program passing in netres.ppm data # and redirecting output to netres.gif system "/usr/local/ug/bin/ppmtogif plotdemo/netres.ppm > plotdemo/netres.gif"; # ad the picture (gif graph) to the web results page print "\n"; exit; # all done ######################################################################### sub parse { $local_alg = $astring; # extract algorithm name we want to do $percent = $words[4]; # percent value is in location 4 @percent = split(//, $words[4]); $percent =~ s/%//; if ($percent[$#percent] ne "%") { # format error exit(); } if ($local_alg eq "rreact") # if we are doing rrect { # then time is in location 5 $time = $words[5]; $time =~ s/rstrd\@//; $time =~ s/msec//; print GNUPLOTRREACT "$time $percent\n"; } elsif ($local_alg eq "twoprong") { $time = $words[7]; print GNUPLOTTWOPRONG "$time $percent\n"; } else { print "Help I don't know what kind of algorithm to do\n"; print "It should have been rreact or twoprong\n"; exit(); } # end else print "\$time=$time, \$percent=$percent
\n"; } # end of subroutine parse ######################################################################### # end of file NetRes.pl