Lab-Measurement-Legacy

 view release on metacpan or  search on metacpan

examples/Legacy/DAQ/Plot_WR640  view on Meta::CPAN

#!/usr/bin/perl -I ../../blib/lib

# use gnuplot to show trace data

use Lab::Data::Analysis;
use Getopt::Long qw(:config bundling auto_version no_ignore_case);
use Carp;
use Chart::Gnuplot;
use Data::Dumper;

sub usage {
    print "usage $0: [options] datafile\n";
    print "  options:\n";
    print "        --t0='start time' [def: earliest]\n";
    print "        --t1='end time'   [def: latest]\n";
    print "        -o --output=file  output file for non-interactive plot\n";
    print "        -f --force        force otuput file overwriting\n";
    print "        -n --nevents=N    number of events to plot [def: all]\n";
    print "        -s --start=N      first event to plot [def: 1]\n";
    print "        -r --run=N        run number [def: first in file]\n";
    print "        -c --chan=chans   channels to plot [def: all]\n";
    print "        -I --ID           include trace ID on plot title\n";
    print "        -T --Tag          tag plots with processing info\n";
    print "        -d --debug        debug printouts\n";
    print "        -v --verbose      verbose\n";
    print "        -h -? --help      print this help\n";

    print "The following are substituted when generating output filenames:\n";
    print "   %R -> run number \n";
    print "   %E -> event number\n";
    print "   %P -> plot number\n";
    print "   %D -> event date, in YYYYMMDD format\n";
    print "   %T -> event time, in HHMMDD format\n";
    print "The default 'output file format' is postscript, but other types\n";
    print "can be specified using the filetype '.gif', '.png' etc. See the\n";
    print "documentation on Chart::Gnuplot for details. \n";
    print "If more than one plot will be generated, and there are no '%x' \n";
    print "substitutions in the output file name, a '_R%RE%E' will be \n";
    print "appended to the 'base' output filename.\n";
    print "Example: -o 'myplot_R%03R_E%03E.ps'\n";
    print "           ---> myplot_R001_E001.ps \n";
    print "           ---> myplot_R001_E002.ps ...etc\n";
}

our $DEBUG   = $Lab::Generic::CLOptions::DEBUG;
our $VERSION = '3.544';
our $VERBOSE = 1;

#our $GNUPLOT = `which gnuplot`;
#croak("unable to find gnuplot") unless $GNUPLOT !~ /^\s*$/;

my $user = getlogin || getpwuid($<) || '?';
our $TAGINIT = join( ' ', $0, @ARGV, "($user @", scalar localtime, ")" );

main();

sub main {
    my $nev = 0;
    my $chans;
    my (@acqch);
    my $t0;
    my $t1;
    my $start = 1;
    my $outfile;
    my $force = 0;
    my $help  = 0;
    my $tag   = 0;
    my $run;
    my $id = 0;

    Getopt::Long::GetOptions(
        "nevents|n=i" => \$nev,
        "start|s=i"   => \$start,
        "chan|c=s"    => \$chans,
        "debug|d+"    => \$DEBUG,
        "verbose|v+"  => \$VERBOSE,
        "help|h|?"    => \$help,
        "output|o=s"  => \$outfile,
        "force|f"     => \$force,
        "ID|I"        => \$id,
        "t0=s"        => \$t0,
        "t1=s"        => \$t1,
        "run|r=i"     => \$run,
        "Tag|T"       => \$tag,
    );

    if ($help) {
        usage();
        exit(0);
    }

    my $infile = shift(@ARGV);
    croak("no input file given") unless defined $infile;
    croak("unable to find input file") unless -e $infile;

    $nev = 0 if $nev < 0;
    if ( defined($first) && $first <= 0 ) {
        carp("starting at first event (event=1)");
        $first = 1;
    }

    if ( defined($outfile) ) {

        # $nev == 1, only one file, use the given one
        if ( $nev != 1 && $outfile =~ /\.(\w+)$/i ) {

            # split into basename and filetype
            my $ftype = $1;
            my $fbase = substr(
                $outfile, 0,
                length($outfile) - length($ftype) - 1
            );



( run in 2.127 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )