#!/usr/bin/perl # file: plot_rr.pm G. Moody 13 March 2009 # Last revised: 31 March 2012 # _____________________________________________________________________________ # plot_rr module for PhysioBank's Automated Teller Machine # Copyright (C) 2009-2012 George B. Moody sub mod_plot_rr { # Return immediately if no output is possible. if (!$annotator) { show_html("no-rr"); return; } # Set defaults. $tend = $tstart + 10; # Adjust options based on user's choices of length and time format. if ($dt > 10) { $tend = $tstart + 60; } if ($dt > 60) { $tend = $tstart + 3600; } if ($dt > 3600) { $tend = $tstart + 43200; } if ($dt == 0) { $tend = "e"; } # Set the path, URL, and final output filenames and URLs for this request. $wd = "plots/rr"; $wu = "$baseurl/$wd"; $wp = "$basepath/$wd"; $ps = "$wp/rr.ps"; $png = "$wp/rr.png"; # If results for this request are already in the cache, return them. if (-s $png) { mod_plot_rr_out(); return; } # Create the working directory for this request. mkpath($wp); # Make temporary filenames. $tplt = "$wp/$$.plt"; $tps = "$wp/$$.ps"; $tpng = "$wp/$$.png"; # Create and save the plot. unless (fork) { open(STDOUT, ">$tplt"); exec($RRPLOT, "-r", "$database/$record", "-a", "$annotator", "-f", "$tstart", "-t", "$tend", "-T", "lw"); } # Wait for rrplot to finish writing the plot file. wait; # Convert the plot to PostScript. unless (fork) { open(STDOUT, ">$tps"); exec($LWCAT, "-t", "-eps", "$tplt"); } # Wait for lwcat to finish writing the PostScript file. wait; # Convert the PostScript to PNG. unless (fork) { exec($CONVERT, "-density", "100x100", $tps, $tpng); } # Wait for convert to finish writing the PNG file. wait; if (-s $png) { # there was a race, and this process lost! unlink($tps); unlink($tpng); } else { # save the PNG and PS files for the cache rename($tpng, $png); rename($tps, $ps); } unlink($tplt); # discard the temporary plt file mod_plot_rr_out(); } sub mod_plot_rr_out { # Show the commands and the plot. if (-s $png) { print 'The output below was prepared using these', ' commands:
rrplot -r' .
	    " $database/$record -a $annotator -f $tstart -t $tend -T lw |" .
	    " lwcat -ps'.
	    " >rr.ps
"; print '' . 'convert -density 100x100 rr.ps', " rr.png" . "

"; print ""; } else { show_html("no-rr"); } } 1;