#!/usr/local/bin/perl -w # ###################################################################################### # # file_growth_monitor.pl - Monitors growth of Molray output files. MRH 14-Mar-2000/6-Feb-2002 # ###################################################################################### # # Call as : % file_growth_monitor.pl?file=$file&psize=$size - # &url=$url&exe=$exe&start=$start&end=$end # ###################################################################################### # Monitor window sizes $win_width = 800; $win_height = 200; #$min_width = 10; #$min_height = 10; # Sleep lengths $short_sleep = 1; $long_sleep = 1; # Other initialisations $movie_prog_string =""; # Default params $def_file = ""; $def_pred_size = 1000; $def_url = "Unknown"; $def_exe = "Online"; $def_start = 0; $def_end = 0; $def_id = ""; $def_term = ""; #$def_netscape = "Yes"; # pick up form input %input_data = &User_Data() ; # interpret flags $infile = val_def("file",$def_file); $pred_size = val_def("psize",$def_pred_size); $url = val_def("url",$def_url); $url_copy = $url; $exe = val_def("exe",$def_exe); $start = val_def("start",$def_start); $end = val_def("end",$def_end); $id = val_def("id",$def_id); $idk = val_def("term",$def_term); $netscape_flag = val_def("netscape_flag",$def_term); $| =1; $this_script = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}"; # Job killing code #------------ if ("$idk" ne "") { # Kill instruction issued print "Content-TYPE: text/html\n\n"; print ""; print "Tidy

\n"; print "Killing current POV-Ray job ($idk) ...

\n"; print "This message will self destruct in 3 seconds....

\n"; $scratch = $infile; $scratch =~ s/\/([^\/]*$)//; $kill_cshfile = "$scratch/tmppd$idk.csh"; $cmd = "/bin/csh -f $kill_cshfile"; # print "Cmd : $cmd"; system("$cmd"); # execute file containing povray-process kill commands print "\n"; print ""; print ""; exit; } # End of job killing code # print HTML header # ------------- if ($netscape_flag eq 'Yes') { print "Content-TYPE: multipart/x-mixed-replace;boundary=--Next_file\n\n"; print "--Next_file\n"; } print "Content-TYPE: text/html\n"; print "Pragma: nocache\n"; print "\n"; #print ""; print "File Growth Monitor

\n"; print "Monitoring image file creation ($exe)

\n"; #print ""; # Check browser version and size the window print << "FGM"; FGM # ---------------------- if ($end == $start && $start == 0) {goto STILL}; # Skip movie stuff if still # Calculate movie frames # ---------------------- $padlen = 1; if ($end > 9) {$padlen = 2}; if ($end > 99) {$padlen = 3}; if ($end > 999) {$padlen = 4}; $pov_movroot = $infile; $pov_movroot =~ s/.tga//; $rm_string = "rm -f "; for ($istep=$start-1;$istep<$end;$istep++) { $padstep = sprintf "%0".$padlen."d", $istep+1; $frame_files[$istep] = "$pov_movroot".($padstep).".tga"; # if ($istep == $end-1) {$pov_movone = "$pov_movroot".($padstep).".tga"}; $rm_string = $rm_string.$frame_files[$istep]; } # system("$rm_string"); # Why ????????? for ($istep=$start-1;$istep<$end;$istep++) { # Movie loop $padstep = sprintf "%0".$padlen."d", $istep+1; $frame_files[$istep] = "$pov_movroot".($padstep).".tga"; $infile = $frame_files[$istep]; $trunfile = $infile; $trunfile =~ s/^.*\/tmp\///; $url = "$url_copy\/$trunfile"; $n = $istep-$start+2; $m = $end-$start+1; $movie_prog_string = "(File $n of $m)"; STILL: # back to stills and movies # ------------------------ $local_time = localtime(time); # Print header # print "File : $url $movie_prog_string
\n"; # print "Start time : $local_time CET
\n"; # print "Predicted final file size : $pred_size
\n"; print << "FGM";
FGM sleep($short_sleep); $old_percent = 0; $percent = 0.0; $then = time(); $old_gone = 0; $diff_gone = 0; $old_size = 0; # Loop around aimlessly $icount = 0; while ($percent < 99.0) { $icount++; # Calculate file size if (-e $infile) { $size = `cat $infile | /usr/bin/wc -c`; } else { $size = 0; }; $percent = 100*$size/$pred_size; # Calculate times $now = time(); $gone = $now-$then + 1; $diff_gone = $gone - $old_gone; if ($size > 1) { $pred_time = $gone*$pred_size/$size; $remain_time = $pred_time - $gone + 1; } else { $remain_time = 1000000; } # $date = sprintf("%02d",$fulltime[4]); ($day, $month, $dom, $time, $year) = split(/\s+/,localtime(time),5); ($hour, $min, $sec) = split(/:/,$time,3); $short_time = sprintf("%d:%02d:%02d",$hour,$min,$sec); $dom=$dom; $month=$month; $day=$day; $year=$year; # Stop if finished if ($percent > 99) { # print "Finished

\n"; next; # Don't write out if less than 5% progress, or server is about to timeout } elsif ( (($percent - $old_percent) < 5) && ($diff_gone < 300) ) { sleep($long_sleep); next; } $old_percent = $percent; $old_size = $size; # Make messages $percsign="%"; $msg = sprintf(" %s Progress : %6.1f%s",$short_time,$percent,$percsign); $msg1 = sprintf(" %s Progress : %6.1f%s",$short_time,$percent,$percsign); # print "$msg"; $old_gone = $gone; print << "PRG1"; PRG1 if ($remain_time < 60){ $msg = sprintf("Estimated time left : %3.0fs",$remain_time); $msg2 = sprintf("Estimated time left : %3.0fs",$remain_time); } elsif ($remain_time < 3600) { $min = int($remain_time/60); $sec = $remain_time - $min*60; $msg = sprintf("Estimated time left : %3.0fm %3.0fs",$min,$sec); $msg2 = sprintf("Estimated time left : %3.0fm %3.0fs",$min,$sec); } elsif ($remain_time > 10000) { $msg = sprintf("Estimated time left : Ages"); $msg2 = sprintf("Estimated time left : Ages"); } else { $hours = int($remain_time/3600); $min = int(($remain_time-3600*$hours)/60); $sec = $remain_time - $min*60 - 3600*$hours; $msg = sprintf("Estimated time left : %3.0fm %3.0fs",$min, $sec); $msg2 = sprintf("Estimated time left : %3.0fm %3.0fs",$min, $sec); } #print $gone; #print " : "; #print int($pred_time); #print " : "; #print int($remain_time); #print " : \n"; # print "$msg"; print << "SCRL"; SCRL } # Write finish message print << "FIN"; FIN # Scroll window (or ideally clear and rewrite) #print "\n"; print << "SCRL"; SCRL print "\n"; sleep($short_sleep); #print ""; if ($start != $end) { # movie if ($netscape_flag eq "Yes") { # netscape server push print ""; print "\n"; print "--Next_file\n"; print "Content-TYPE: text/html\n"; print "Pragma: nocache\n\n"; #print "\n"; #print ""; print "\n"; print "File Growth Monitor

\n"; } # end if netscape } # end if movie } # end movie loop #print ""; # Close the window sleep($short_sleep); print << "FNSH"; FNSH print ""; print "\n"; ############################################################# sub val_def { local ($aa, $bb, $cc) ; ($aa, $bb) = @_ ; if (defined($input_data{$aa})) { $cc = $input_data{$aa} } else { $cc = $bb } return $cc } ###################################################################### # Subroutine User_Data sorts out form data-pairs. ###################################################################### ## Use as follows : ## %data_received = &User_Data(); ## $value = $data_received{item_name}; sub User_Data { local (%user_data, $user_string, $name_value_pair, @name_value_pairs, $name, $value); if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $user_string, $ENV{'CONTENT_LENGTH'}); } else { $user_string = $ENV{'QUERY_STRING'}; } $user_string =~ s/\+/ /g; @name_value_pairs = split(/&/, $user_string); foreach $name_value_pair (@name_value_pairs) { ($name, $value) = split(/=/, $name_value_pair); $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge; if (defined($user_data{$name})) { $user_data{$name} .= " : " . $value; } else { $user_data{$name} = $value; # print "UU :$user_data{$name} : $value
"; } } return %user_data; }