]> git.mxchange.org Git - flightgear.git/commitdiff
Add a function to do plots with any channel being X and any other channel
authorcurt <curt>
Fri, 27 Feb 2004 23:28:23 +0000 (23:28 +0000)
committercurt <curt>
Fri, 27 Feb 2004 23:28:23 +0000 (23:28 +0000)
being "Y".

scripts/perl/examples/logging.pl

index b951b3a28ed4e8821cb3ba3f9be5bb272c3784d9..5aeda6586cff2cc72a9785a276d8c14d85d1eb40 100755 (executable)
@@ -134,7 +134,7 @@ sub stop_logging {
 }
 
 
-sub quick_plot {
+sub quick_plot_vs_time {
     my( $data_file ) = shift;
     my( $plot_file ) = shift;
     my( $title ) = shift;
@@ -169,4 +169,41 @@ sub quick_plot {
 }
 
 
+sub quick_plot {
+    my( $data_file ) = shift;
+    my( $plot_file ) = shift;
+    my( $xtitle ) = shift;
+    my( $ytitle ) = shift;
+    my( $xcolumn ) = shift;
+    my( $ycolumn ) = shift;
+
+    print "quick plot -> $plot_file\n";
+
+    my( $tmpcmd ) = "$tmp_dir/plot_cmd_tmp.$$";
+    my( $tmpdata ) = "$tmp_dir/plot_data_tmp.$$";
+    my( $png_image ) = "$plot_file.png";
+
+    # strip the leading header off the file so gnuplot doesn't squawk
+    system( "tail +2 $data_file | sed -e \"s/,/ /g\" > $tmpdata" );
+
+    # create the gnuplot command file
+    open( CMD, ">$tmpcmd" );
+    print CMD "set terminal png color\n";
+    print "png_image = $png_image\n";
+    print CMD "set output \"$png_image\"\n";
+    print CMD "set xlabel \"$xtitle\"\n";
+    print CMD "set ylabel \"$ytitle\"\n";
+    print CMD "plot \"$tmpdata\" using $xcolumn:$ycolumn title \"$xtitle vs. $ytitle\" with lines\n";
+    print CMD "quit\n";
+    close( CMD );
+
+    # plot the graph
+    system( "gnuplot $tmpcmd" );
+
+    # clean up all our droppings
+    unlink( $tmpcmd );
+    unlink( $tmpdata );
+}
+
+
 return 1;                    # make perl happy