sub GenerateGraph { #$ppmtogif = "/usr/local/bin/ppmtogif"; #print "GenerateGraph: @_, changed: $changed, region: $region, "; #print "parameter: $parameter, Order: $orderforplot Range: $start to $end."; if ($parameter eq '1'){ $title = "Nitrogen_Concentration_mg/L"; } elsif ($parameter eq '2'){ $title = "Phosphorus_mg/L"; } elsif ($parameter eq '3'){ $title = "Sediments_mg/L"; } elsif ($parameter eq '4'){ $title = "Heavy_Metal_mg/L"; } elsif ($parameter eq '5'){ $title = "Toxins_mg/L"; } elsif ($parameter eq '6'){ $title = "Water_Temperature_Degrees_Celsius"; } elsif ($parameter eq '11'){ $title = "Air_Temperature_Degrees_Celsius"; } elsif ($parameter eq '12'){ $title = "Precipitation_Inches"; } elsif ($parameter eq '7'){ $title = "pH"; } elsif ($parameter eq '8'){ $title = "Dissolved_Oxygen_mg/L"; } elsif ($parameter eq '9'){ $title = "BOD_mg/L"; } elsif ($parameter eq '10'){ $title = "Saturated_DO_mg/L"; } elsif ($parameter eq '13'){ $title = "Runoff_Meters_Cubed"; } elsif ($parameter eq '14'){ $title = "Total_Flow_Meters_Cubed"; } elsif ($parameter eq '15'){ $title = "Groundwater_Meters_Cubed"; } else { $title = "No_Title_Available"; } # If the indicator is precipitation we can skip some stuff if ($parameter == "12"){ # Set variables: # we deal with precipitation seperately because the # data doesn't change (yet) # preci is the location of precip data. # precipit will be the pre management data file # precipit2 will be the post management data file # we use 2 files to stay consistent with the program $preci = "/var/www/html/ncsa/riverweb/version5/precip2.txt"; $precipit = "/tmp/riverout$pid"; $precipit2 = "/tmp/riverbout$pid"; # read in precip data file to @precipit # open (PRECIPDAT, "<$preci") || print " couldn't open file $preci: $!"; # while (){ # chop; # push @numbers, $_; # } # close (PRECIPDAT); #$ku = '0'; # figure out the durations # open file in tmp and print array #open (PRECIP, ">$precipit") || print "couldn't open riverout file in if loop $precipit: $!"; #open (PRECIP2, ">$precipit2") || print "couldn't open riveroutb file in if loop $precipit2: $!"; system ("cp $preci $precipit"); system ("cp $preci $precipit2"); # while looping through the array, print same data to # both files #while ($ku <= $#numbers){ #print PRECIP "$numbers[$ku]\n"; #print PRECIP2 "$numbers[$ku]\n"; #$ku++; #} #close (PRECIP); #close (PRECIP2); # then skip all this other stuff and post process.... } # else we are a normal indicator that needs the full treatment # this is the section that calls the fortran program to make a pbm file # we call this whole subroutine twice while making the dual display else { ##### # what we really want to say is: # if top, pid, if bottom, pid+=1 # this line clears the files before we write to them, # therefore can't be causing the station 7 bug. system ("rm /tmp/riverdata$pid"); system ("rm /tmp/riverout$pid"); # if we are making a single plot # call the fortran program after writing the file it reads if ($region == '0'){$changed = 0;} ############################## # O.K the problem I am having with this set of code is that # when I split a munber into an array, if the number is 0 # it leaves the array empty at the location it's either that # or the book is wrong. # what this is doing is reading the order to plot and testing region 7 # to see whether to display one line or two lines. Obselete since # ordercontrol.pl::HasImprovementBeenMade # open (LOG, ">logdata") || print " couldn't open log file in else loop $data: $!"; $go = '1'; @letters = split(//, $orderforplot); $il = 0; # print LOG "orderforplot == $orderforplot\n"; while ($il < $#letters){ # print LOG "$letter[$il]\n"; if (!$letter[$il]){ $increment += 1; } $il++; } # print LOG "$increment == 5\n"; if ($increment == 5){ $go = '2'; } $increment = 0; @letters = ''; # print LOG "$region && $go\n"; # if (($region == '7') && (there are some improvements)){$changed = 1;} if (($region == '7') && ($go == '2')){ $changed = 1; # print LOG "$region && $go\n"; } # close (LOG); #if (($region == '7') && ($improved_7 = "print_two_lines")){ #$changed = 1; #} ############################## if ($changed == 0){ $data = ("/tmp/riverdata" . $pid); open (TEMP, ">$data") || print " couldn't open riverout file in else loop $data: $!"; #open (LOG, ">>logdata") || print " couldn't open log file in else loop $data: $!"; print TEMP "$region\n"; #print "166\n$region\n"; print TEMP "$parameter\n"; #print "$parameter\n"; print TEMP "$changed\n"; #print "$changed\n"; print TEMP "$orderforplot\n"; #print "$orderforplot\n"; #close (LOG); close (TEMP); if (-e $data){ system("/var/www/html/ncsa/riverweb/version5/perl/callriverout.cgi -d $pid"); #print "Data exitsts!"; open (TEMP, "<$data") || print "N-a-a-a-a-het -> $data: $!
\n"; while (){ chop; ### #print "Data: $_
\n"; } close (TEMP); } else { print "$data does not exist!"; } } # elsif we are making a multiplot # call the fortran program after writing the two files it reads elsif ($changed == 1){ # the fortran program is using the same file, it writes # a "file a" if changed is 0 or "file b" if changed is 1. # since $changed is 1, first we'll create the best management data $data = ("/tmp/riverdata" . $pid); open (TEMP, ">$data") || print "couldn't open riveroutb file in elsif loop $data: $!"; #open (LOG, ">>logdata") || print " couldn't open log file in else loop $data: $!"; print TEMP "$region\n"; #print "\n218\nRegion: $region\n"; print TEMP "$parameter\n"; #print "Paramater: $parameter\n"; print TEMP "$changed\n"; #print "BMP: $changed\n"; print TEMP "$orderforplot\n"; #print "Order: $orderforplot\n"; #close (LOG); close (TEMP); if (-e $data){ system("/var/www/html/ncsa/riverweb/version5/perl/callriverout.cgi -d $pid"); #print "Data exitsts!"; open (TEMP, "<$data") || print "N-a-a-a-a-het -> $data: $!
\n"; while (){ chop; ### #print "Data: $_
\n"; } close (TEMP); } else { print "$data does not exist!"; } ### #if ($region == '7'){ # move the post file out of the way # system ("mv /tmp/riverbout$pid /tmp/rivercout$pid"); #} # now we've created the best management output, # we can erase the data file system ("rm $data"); # make changed 0, $changed = 0; # and compose the second unmanaged data file $data = ("/tmp/riverdata" . $pid); open (TEMP, ">$data") || print "couldn't open riveroutb file in elsif loop $data: $!"; #open (LOG, ">>logdata") || print " couldn't open log file in else loop $data: $!"; $logcount += 1; #print LOG "\nlogcount: $logcount\n"; print TEMP "$region\n"; #print "\n272\nRegion: $region\n"; print TEMP "$parameter\n"; #print "Parameter: $parameter\n"; print TEMP "$changed\n"; #print "Changed: $changed\n"; print TEMP "$orderforplot\n"; #print "Order: $orderforplot\n"; #close (LOG); close (TEMP); # call fortran program if (-e $data){ system("/var/www/html/ncsa/riverweb/version5/callriverout.cgi -d $pid"); #print "Data exitsts!"; open (TEMP, "<$data") || print "N-a-a-a-a-het -> $data: $!
\n"; while (){ chop; ### #print "Data: $_
\n"; } close (TEMP); } else { print "$data does not exist!"; } ### #if ($region == '7'){ # move the pre file to the right place # system ("mv /tmp/riverbout$pid /tmp/riverout$pid"); # move the post file back # system ("mv /tmp/rivercout$pid /tmp/riverbout$pid"); #} # remove the second data file we created since we # now have our riverout file # system ("rm $data"); # then make changed 1 to keep the faith $changed = 1; } } # So, after that we now have up to two data files for this graph: # River Out is unmanaged data $data1 = "/tmp/riverout" . $pid; # RiverBOut is managed data $data2 = "/tmp/riverbout" . $pid; &PrepareDataFiles; # well, the fortran program doesnt make these files completely # compatible with gnuplot (our next goal) so in order to get # them ready we will have to parse them: # O.K. so we know we at least have to process river.out # and maybe river b.out. Lets go for the obvious first... # Lets read river out, ditch the spaces and add it to an array $_ = ''; @numbers = ''; $tt = ''; #open (RIVEROUT, "<$data1") || print "callprogs A Reading data: couldn't open file $data1: $!"; # while (){ # chop; # # $_ =~ s/ //g; # if ($_){ # push @numbers, $_; # } # } #close (RIVEROUT); # Now we'll take that array and print the lines that make # sense back to the same file #open (RIVEROUT, ">$data1") || print "B Reading data: couldn't open file $data1: $!"; # open (DEBUG, ">debug") || print "couldn't open file Debug: $!"; # print DEBUG "New Session: $pid\n"; #while ($tt <= $#numbers){ # if ($numbers[$tt] =~ "&"){ # ; # } # else { # print RIVEROUT "$numbers[$tt]\n"; #print DEBUG "$numbers[$tt]\n"; # } # $tt++; #} #close (RIVEROUT); #close (DEBUG); # callgnuplot is set up for single unimproved plots #print "Debug: region: $region, changed: $changed, improved_7: $improved_7 \n"; if ($region ne 7){ if ($changed == 0){ system("/var/www/html/ncsa/riverweb/version5/perl/callgnuplot.pl -f $pid -s $start -e $end -g $range -n $rangeto -r $title"); } # callgnuplotb is set up for best management practice elsif ($changed == 1){ system("/var/www/html/ncsa/riverweb/version5/perl/callgnuplotb.pl -f $pid -s $start -e $end -g $range -n $rangeto -r $title"); } } if ($region eq 7){ if ($improved_7 eq "print_one_line"){ system("/var/www/html/ncsa/riverweb/version5/perl/callgnuplot.pl -f $pid -s $start -e $end -g $range -n $rangeto -r $title"); } # callgnuplotb is set up for best management practice elsif ($improved_7 eq "print_two_lines"){ system("/var/www/html/ncsa/riverweb/version5/perl/callgnuplotb.pl -f $pid -s $start -e $end -g $range -n $rangeto -r $title"); } } # system ("$ppmtogif < /tmp/river$pid.pbm > /tmp/river$pid.gif"); #print "Here 1: pid $pid"; system ("mv /tmp/river$pid.png /var/www/html/tmpgif/"); system ("chmod 444 /tmp/riverout$pid"); system ("chmod 444 /tmp/riverbout$pid"); system ("mv /tmp/riverout$pid /var/www/html/tmpgif/riverout$pid.dat"); # system ("mv /tmp/riverout.html$pid /var/www/html/tmpgif/riverout$pid.html"); # system ("mv /tmp/riverbout.html$pid /var/www/html/tmpgif/riverbout$pid.html"); system ("mv /tmp/riverbout$pid /var/www/html/tmpgif/riverbout$pid.dat"); system ("rm /tmp/riverdata$pid"); # system ("rm /tmp/river$pid.pbm"); $png = ("river" . $pid . ".png"); return($png); } sub NewGenerateGraph { # Hard wire variables for New Code $fortranprogram = ''; # $ppmtogif = "/usr/local/bin/ppmtogif"; $gnuplot = ''; $riverout = ''; $precip = ''; $call{'station_1'} = $call{'topstation'}; $call{'parameter_1'} = $parameter; $call{'day_beginning_1'} = $call{'topfrom'}; $call{'day_end_1'} = $call{'topto'}; $call{'range_beginning_1'} = $call{'topyrange'}; $call{'range_end_1'} = $call{'topyrangeto'}; $improved_1 = ''; $order_1 = ''; $process_1 = ''; $title_1 = ''; $call{'station_2'} = $call{'bottomstation'}; $call{'parameter_2'} = $parameter_2; $call{'day_beginning_2'} = $call{'botfrom'}; $call{'day_end_2'} = $call{'botto'}; $call{'range_beginning_2'} = $call{'botyrange'}; $call{'range_end_2'} = $call{'botyrangeto'}; $improved_2 = ''; $order_2 = ''; $process_2 = ''; $title_2 = ''; # write file for fortran program $data = ("/tmp/riverdata" . $process_1); open (TEMP, ">$data") || print "couldn't write file $data: $!"; print TEMP "$call{'station_1'}\n"; print TEMP "$call{'parameter_1'}\n"; print TEMP "$improved_1\n"; print TEMP "$order_1\n"; close (TEMP); # call fortran program $riverout = '/tmp/riverout' . $process_1; # This line is a simple answer to a really irritating # complex problem: echo the process ID to the fortran program, # and print the output of the fortran program to file in tmp system("echo $process_1|$fortranprogram|$riverout"); # Now if the management is in effect, generate second data set # that is not improved if ($improved_1 eq 1){ open (TEMP, ">$data") || print "couldn't write file $data: $!"; print TEMP "$call{'station_1'}\n"; print TEMP "$call{'parameter_1'}\n"; print TEMP "0\n"; print TEMP "$order_1\n"; close (TEMP); $riverbout = '/tmp/riverbout' . $process_1; } # if the parameter is precip the fortran program didn't work. Use our own datafile if ($call{'parameter_1'} eq 12){ system ("cp $precip $riverout"); if ($improved_1 eq 1){ system ("cp $precip $riverbout"); } } # call gnuplot $session = ("/tmp/riversession" . $process_1); open (SESSION_1, ">$session") || print "couldn't write file $data: $!"; print SESSION_1 "set terminal png small xffffff x000000 xaa0000 x000066\n"; print SESSION_1 "set output \"/tmp/river$process_1.png\"\n"; print SESSION_1 "set size 0.7,0.5\n"; print SESSION_1 "set xlabel \"Days in Year\"\n"; print SESSION_1 "set timestamp top rotate\n"; print SESSION_1 "set xrange [$call{'day_beginning_1'}:$call{'day_end_1'}]\n"; if ($call{'range_beginning_1'} || $call{'range_end_1'}){ print WRITEME "set yrange [$call{'range_beginning_1'}:$call{'range_end_1'}]\n"; } print SESSION_1 "set title \"$title_1\"\n"; print SESSION_1 "set nokey\n"; print SESSION_1 "plot \"$riverout\" title \"River Data\" with l lt 0"; if ($improved_1 eq 1){ print SESSION_1 ", \"$riverbout\" title \"Best_Management\" w l lt 1\n"; } else { print SESSION_1 "\n"; } print SESSION_1 "quit\n"; close (SESSION_1); $data_1 = '/var/www/html/tmpgif/riverout$process_1.dat'; $data_1b = '/var/www/html/tmpgif/riverbout$process_1.dat'; $png_1 = '/var/www/html/tmpgif/river$process_1.png'; system ("$gnuplot $session"); # system ("$ppmtogif < /tmp/river$process_1.pbm > /tmp/river$process_1.gif"); system ("rm $session $data"); #print "Here 2"; system ("mv /tmp/river$process_1.png /var/www/html/tmpgif/"); system ("mv $riverout $data_1"); if ($improved_1 eq 1){ system ("mv $riverbout $data_1b"); } # Begin creating second graphic # write file for fortran program. $data = ("/tmp/riverdata" . $process_2); open (TEMP, ">$data") || print "couldn't write file $data: $!"; print TEMP "$call{'station_2'}\n"; print TEMP "$call{'parameter_2'}\n"; print TEMP "$improved_2\n"; print TEMP "$order_2\n"; close (TEMP); # call fortran program $riverout = '/tmp/riverout' . $process_2; # This line is a simple answer to a really irritating # complex problem: echo the process ID to the fortran program, # and print the output of the fortran program to file in tmp system("echo $process_2|$fortranprogram|$riverout"); # Now if the management is in effect, generate second data set # that is not improved if ($improved_2 eq 1){ open (TEMP, ">$data") || print "couldn't write file $data: $!"; print TEMP "$call{'station_2'}\n"; print TEMP "$call{'parameter_2'}\n"; print TEMP "0\n"; print TEMP "$order_2\n"; close (TEMP); $riverbout = '/tmp/riverbout' . $process_2; } # if the parameter is precip the fortran program didn't work. Use our own datafile if ($call{'parameter_2'} eq 12){ system ("cp $precip $riverout"); if ($improved_2 eq 1){ system ("cp $precip $riverbout"); } } # call gnuplot $session = ("/tmp/riversession" . $process_2); open (SESSION_2, ">$session") || print "couldn't write file $data: $!"; print SESSION_2 "set terminal png small xffffff x000000 xaa0000 x000066\n"; print SESSION_2 "set output \"/tmp/river$process_2.png\"\n"; print SESSION_2 "set size 0.7,0.5\n"; print SESSION_2 "set xlabel \"Days in Year\"\n"; print SESSION_2 "set timestamp top rotate\n"; print SESSION_2 "set xrange [$call{'day_beginning_2'}:$call{'day_end_2'}]\n"; if ($call{'range_beginning_2'} || $call{'range_end_2'}){ print WRITEME "set yrange [$call{'range_beginning_2'}:$call{'range_end_2'}]\n"; } print SESSION_2 "set title \"$title_2\"\n"; print SESSION_2 "set nokey\n"; print SESSION_2 "plot \"$riverout\" title \"River Data\" with l lt 0"; if ($improved_2 eq 1){ print SESSION_2 ", \"$riverbout\" title \"Best_Management\" w l lt 1\n"; } else { print SESSION_2 "\n"; } print SESSION_2 "quit\n"; close (SESSION_2); $data_2 = '/var/www/html/tmpgif/riverout$process_2.dat'; $data_2b = '/var/www/html/tmpgif/riverbout$process_2.dat'; $png_2 = '/var/www/html/tmpgif/river$process_2.png'; system ("$gnuplot $session"); # system ("$ppmtogif < /tmp/river$process_2. > /tmp/river$process_2.gif"); system ("rm $session $data"); #print "Here 3"; system ("mv /tmp/river$process_2.png /var/www/html/tmpgif/"); system ("mv $riverout $data_2"); if ($improved_2 eq 1){ system ("mv $riverbout $data_2b"); } } 1;