]> jspc29.x-matter.uni-frankfurt.de Git - hadesdaq.git/commitdiff
Merged HPlot -AW
authorHadaq Hades <jan@lxhadeb07>
Mon, 8 Oct 2018 13:12:01 +0000 (15:12 +0200)
committerHadaq Hades <jan@lxhadeb07>
Mon, 8 Oct 2018 13:12:01 +0000 (15:12 +0200)
hmon/HPlot.pm

index b01c41bf3a48d7beff9063c808788be619aac22c..96e2c34b015ea8542af3ab1eef9595b2f7b5645f 100755 (executable)
@@ -8,6 +8,7 @@ use Storable qw(lock_store lock_retrieve);
 
 my $p;
 my $storefile;
+my $plotstring;
 
 use constant {TYPE_HISTORY => 1, TYPE_BARGRAPH => 2, TYPE_HEATMAP => 3};
 
@@ -15,19 +16,21 @@ use constant {OUT_PNG    => 1,
               OUT_SVG    => 2,  #n/a
               OUT_SCREEN => 3}; #n/a
 
-my @color= ('#2222dd','#dd2222','#22dd22','#dd8822','#dd22dd','#22dddd','#dddd22','#8888dd','#8822bb','#444444','#2222dd','#dd2222','#22dd22','#dd8822','#dd22dd','#22dddd','#dddd22','#8888dd','#8822bb','#444444',);
+my @color= ('#2222dd','#dd2222','#22dd22','#dd8822','#dd22dd','#22dddd','#dddd22','#8888dd','#8822bb','#444444',
+ '#2222dd','#dd2222','#22dd22','#dd8822','#dd22dd','#22dddd','#dddd22','#8888dd','#8822bb','#444444');
 
 sub plot_write {
-  my ($file,$str,$no) = @_;
+  my ($file,$str,$no,$save) = @_;
   return unless $str;
   if($no || 0) {
     print $file $str;
-#     print $str;
+#      print $str;
     }
   else {
     print $file $str."\n";
-#     print $str."\n";
+#      print $str."\n";
     }
+  if(defined $save) {$plotstring->{$save} .= $str;}  
   }
 
 
@@ -48,8 +51,6 @@ sub setranges {
     }
   }
 
-
-
 sub PlotInit {
   my ($c) = @_;
 
@@ -58,7 +59,6 @@ sub PlotInit {
   my $fn = "gnuplot";
   #my $fh = new FileHandle ("|$fn") or  die "error: no gnuplot";
   open my $fh, "|$fn" or  die "error: no gnuplot";
-  #open my $fh, ">delme_$name" or  die "error: no gnuplot";
   $fh->autoflush(1);
 
 
@@ -77,11 +77,14 @@ sub PlotInit {
   $p->{$name}->{showvalues} = $p->{$name}->{showvalues} || 0;
   $p->{$name}->{storable} = $p->{$name}->{storable} || 0;
   $p->{$name}->{plot_string} = ""; # to store the plot command
+  $p->{$name}->{xticks} = $p->{$name}->{xticks} || 0;
   $p->{$name}{additional} = $p->{$name}{additional} || '';
 
   my $filename = $p->{$name}->{file};
   $filename =~ s%/%%;
-  $storefile->{$name} = "/dev/shm/".$name.'-'.$p->{$name}->{curves}.'-'.$p->{$name}->{entries}.'-'.$filename.'.store';
+  $storefile->{$name} = $name.'-'.$p->{$name}->{curves}.'-'.$p->{$name}->{entries}.'-'.$filename.'.store';
+  $storefile->{$name} =~ s%/%%g;
+  $storefile->{$name} = "/dev/shm/".$storefile->{$name};
 
   unless ($p->{$name}{noinit}) {
     foreach my $i (0..($c->{entries}-1)) {
@@ -100,7 +103,7 @@ sub PlotInit {
 
   if($p->{$name}->{output} == OUT_PNG) {
     $p->{$name}->{file} or die "No filename specified";
-    plot_write($fh,"set term png size ".$p->{$name}->{sizex}.",".$p->{$name}->{sizey}." font \"monospace,8\"");
+    plot_write($fh,"set term png size ".$p->{$name}->{sizex}.",".$p->{$name}->{sizey}." truecolor font \"monospace,8\"");
     plot_write($fh,"set out \"".$p->{$name}->{file}.($p->{$name}->{buffer}?"tmp":"").".png\"");
     }
   elsif($p->{$name}->{output} == OUT_SCREEN) {
@@ -127,6 +130,10 @@ sub PlotInit {
   setranges($fh,'zrange',$p->{$name}->{zmin},$p->{$name}->{zmax});
   setranges($fh,'cbrange',$p->{$name}->{cbmin},$p->{$name}->{cbmax});
 
+  if($p->{$name}->{addCmd} && $p->{$name}->{addCmd} ne "") {  
+    plot_write($fh,$p->{$name}->{addCmd});
+    }  
+  
   if ($p->{$name}->{type} == TYPE_HISTORY) {
     if ($p->{$name}->{fill}) {
       plot_write($fh,"set style fill solid 1.00");
@@ -164,10 +171,16 @@ sub PlotInit {
   }
   elsif ($p->{$name}->{type} == TYPE_BARGRAPH) {
     my $stacked = $p->{$name}{stacked}?'rowstacked':'';
+    #print $stacked;
     plot_write($fh,"set style fill   solid 1.00 ");
     plot_write($fh,"set grid noxtics ytics");
     plot_write($fh,"set boxwidth ".($p->{$name}->{curvewidth}||4)." absolute");
     plot_write($fh,"set style histogram ".$stacked." gap ".($p->{$name}->{bargap}||1));
+    
+    if($p->{$name}->{xticks}) {
+      plot_write("set xtics rotate by 90 offset .7,-1.7 scale .7 ");
+    }
+    
     if (defined $p->{$name}->{bartitle} && scalar @{$p->{$name}->{bartitle}}) {
       plot_write($fh,"set xtics (",1);
       for (my $j=0; $j<scalar @{$p->{$name}->{bartitle}};$j++) {
@@ -182,10 +195,14 @@ sub PlotInit {
     #plot_write($fh,"plot ",1);
     $p->{$name}->{plot_string} .= "plot ";
     for (my $j=0; $j<$p->{$name}->{curves};$j++) {
-      #plot_write($fh,', ',1) if $j;
+      ##plot_write($fh,', ',1) if $j;
       $p->{$name}->{plot_string} .= ', ' if $j;
-      #plot_write($fh,"'-' lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1);
-      $p->{$name}->{plot_string} .= "'-' lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ";
+      ##plot_write($fh,"'-' lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1);
+      #$p->{$name}->{plot_string} .= "'-' lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ";
+      
+      $p->{$name}->{plot_string} .= "'-' with histograms ";
+      $p->{$name}->{plot_string} .= "using 2:xticlabels(1) " if ($p->{$name}->{xticks});
+      $p->{$name}->{plot_string} .= "lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ";
     }
     #plot_write($fh," ");
     $p->{$name}->{plot_string} .= " \n";
@@ -193,7 +210,12 @@ sub PlotInit {
   }
   elsif ($p->{$name}->{type} == TYPE_HEATMAP) {
     plot_write($fh,"set view map");
-    plot_write($fh,"set palette rgbformulae 22,13,-31");
+    if(defined $p->{$name}->{palette}) {
+      plot_write($fh,"set palette ".$p->{$name}->{palette});
+      }
+    else {
+      plot_write($fh,"set palette rgbformulae 22,13,-31");
+    }
     plot_write($fh,$p->{$name}{additional});
     if ($p->{$name}->{showvalues} == 0) {
       #plot_write($fh,"splot '-' matrix with image");
@@ -221,10 +243,11 @@ sub PlotDraw {
   if($p->{$name}->{run}>=1) {
     plot_write($p->{$name}->{fh},"set out \"".$p->{$name}->{file}.($p->{$name}->{buffer}?"tmp":"").".png\"");
     plot_write($p->{$name}->{fh},makeTimeString());
-    #plot_write($p->{$name}->{fh},"replot");
     plot_write($p->{$name}->{fh}, $p->{$name}->{plot_string});
     }
 
+    
+    
   if($p->{$name}->{type} == TYPE_HISTORY) {  
     my $realentries = $p->{$name}{limitentries} || $p->{$name}->{entries};
     for(my $j=0; $j<$p->{$name}->{curves}; $j++) {
@@ -233,7 +256,7 @@ sub PlotDraw {
           plot_write($p->{$name}->{fh},(($i-($p->{$name}->{entries}-$realentries))/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]);
           }
         else {
-          plot_write($p->{$name}->{fh},(($i-$realentries)/$p->{$name}->{xscale})." ".($p->{$name}->{value}->[$j]->[$i]||0));
+          plot_write($p->{$name}->{fh},(($i-$realentries)/($p->{$name}->{xscale}||1))." ".($p->{$name}->{value}->[$j]->[$i]||0));
           }
         }
       plot_write($p->{$name}->{fh},"e");
@@ -241,17 +264,18 @@ sub PlotDraw {
     }
 
   if($p->{$name}->{type} == TYPE_BARGRAPH) {
-    my $realentries = $p->{$name}{limitentries} || $p->{$name}{entries};
-    #plot_write($p->{$name}->{fh}, $p->{$name}->{plot_string});
-    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);
+    my $realentries = $p->{$name}{limitentries} || $p->{$name}->{entries};
+    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); #?? maybe without ||0
         }
-      plot_write($p->{$name}{fh},"e");
+      plot_write($p->{$name}->{fh},"e");
       }
     }
 
+    
   if($p->{$name}->{type} == TYPE_HEATMAP) {
+  #  if($p->{$name}->{showvalues}) { 
       for(my $j=0; $j<$p->{$name}->{curves}; $j++) {
         for(my $i=0; $i< $p->{$name}->{entries}; $i++) {
           plot_write($p->{$name}->{fh},($p->{$name}->{value}->[$j]->[$i]//'NaN')." ",1);#"NaN"
@@ -261,6 +285,8 @@ sub PlotDraw {
         }
       plot_write($p->{$name}->{fh},"e");
       plot_write($p->{$name}->{fh},"e");
+   #   }
+    
       if ($p->{$name}{showvalues}) {
         for(my $j=0; $j<$p->{$name}->{curves}; $j++) {
           for(my $i=0; $i< $p->{$name}->{entries}; $i++) {
@@ -304,4 +330,5 @@ sub PlotLimitEntries {
   $p->{$name}{limitentries} = $entries;
   }
 
+  
 1;