#!/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 "
\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 "
\n"; print "Monitoring image file creation ($exe)
\n";
#print " \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";
} # end if netscape
} # end if movie
} # end movie loop
#print "
\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
";
}
}
return %user_data;
}