]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
add forked draw function to HPlot
authorhadaq <hadaq@hades33.gsi.de>
Fri, 26 Feb 2021 13:32:15 +0000 (14:32 +0100)
committerhadaq <hadaq@hades33.gsi.de>
Fri, 26 Feb 2021 13:32:15 +0000 (14:32 +0100)
tools/HPlot.pm

index 01565f17af2d4bf0f397e2dc49a8531ddabd00d0..3080cfefa7f6a418df924b418008cedef8205bf6 100755 (executable)
@@ -28,14 +28,14 @@ sub plot_write {
     }
   else {
     print $file $str."\n";
-     print $str."\n";
+ #     print $str."\n";
     }
   if(defined $save) {$plotstring->{$save} .= $str;}  
   }
 
 
 sub makeTimeString{
-  return strftime("set label 100 \"%H:%M:%S\" at screen 0.02,0.02 left tc rgb \"#000044\" font \"monospace,8\"\n", localtime())
+  return strftime("set label 100 \"%H:%M:%S\" at screen 0.99,0.02 right tc rgb \"#000044\" font \"monospace,8\"\n", localtime())
   }
 
 sub setranges { 
@@ -56,7 +56,8 @@ sub PlotInit {
 
   my $name      = $c->{name};
 
-  my $fn = "gnuplot 2>1";
+  my $fn = "gnuplot 2>&1";
+  #my $fn = "gnuplot";
   #my $fh = new FileHandle ("|$fn") or  die "error: no gnuplot";
   open my $fh, "|$fn" or  die "error: no gnuplot";
   $fh->autoflush(1);
@@ -236,9 +237,22 @@ sub PlotInit {
 
 }
 
+sub PlotDrawFork {
+  my($name) = @_;
+  waitpid($p->{$name}->{pid},0) if $p->{$name}->{pid};
+  my $pid = fork;
+  unless ($pid) {PlotDraw($name);exit;}
+  $p->{$name}->{pid} = $pid;
+  $p->{$name}->{run}++;
+}
+
 
 sub PlotDraw {
   my($name) = @_;
+  if(!defined $p->{$name}) {
+    print "PlotDraw called with non existing plot name: \"$name\", typo? Exiting!\n";
+    exit;
+  }
   if($p->{$name}->{buffer} && -e $p->{$name}->{file}."tmp.png") {  
     rename $p->{$name}->{file}."tmp.png", $p->{$name}->{file}.".png";
     }
@@ -270,10 +284,10 @@ sub PlotDraw {
     for(my $j=0; $j<$p->{$name}->{curves}; $j++) {
       for(my $i=$p->{$name}->{entries}-$realentries; $i< $p->{$name}->{entries}; $i++) {
         plot_write($p->{$name}->{fh},' '.(($p->{$name}->{value}->[$j]->[$i]||0)/($p->{$name}->{yscale}||1))); #?? maybe without ||0
-        }
-      plot_write($p->{$name}->{fh},"e");
       }
+      plot_write($p->{$name}->{fh},"e");
     }
+  }
 
     
   if($p->{$name}->{type} == TYPE_HEATMAP) {
@@ -315,7 +329,12 @@ sub PlotDraw {
 
 sub PlotAdd {
   my($name,$value,$curve) = @_;
+  if(!defined $p->{$name}) {
+    print "PlotAdd called with non existing plot name: \"$name\", typo? Exiting!\n";
+    exit;
+  }
   $curve = 0 unless $curve;
+  #print Dumper $p;
   push(@{$p->{$name}->{value}->[$curve]},$value||0);
   shift(@{$p->{$name}->{value}->[$curve]});
 
@@ -323,6 +342,11 @@ sub PlotAdd {
 
 sub PlotFill {
   my($name,$value,$slot,$curve,$add) = @_;
+  if(!defined $p->{$name}) {
+    print "PlotFill called with non existing plot name: \"$name\", typo? Exiting!\n";
+    exit;
+  }
+
   $curve = 0 unless $curve;
   if($add) {
     $p->{$name}->{value}->[$curve]->[$slot] += $value||0;