
use strict;
use POSIX qw(setsid);
use Getopt::Std;
use Time::HiRes qw(usleep);
use LinuxGpib;
use DateTime;
use n8ur qw(lower_case trim squash collapse round);
use n8ur_gpib qw( logline);

my $opt_string = 'a:hgc:t:f:z:';

sub usage() {
print STDERR << "EOF";

usage: $0 -c [-a samples] [-z a|b|ab] [-h] [t iso|mjd] -f logfile

-a	: samples to average (each sample is 100 gate time counter average)
-c	: counter number
-t	: timestamp format: iso or mjd (default is mjd)
-z	: 50 ohm termination for channel a, b, or ab
-g	: test for bad GPS values (50ns threshold)
-h	: this (help) message
-f	: logfile using full pathname;
	  for output to console, use "-f -"

EOF
}

# main loop
#----------

getopts( "$opt_string", \my %opt ) or usage() and exit;

#----------
# write header line
my $dt = DateTime->now;
my $current_iso = $dt->ymd('-') . 'T' . $dt->hms(':');
my $current_mjd = $dt->mjd;
printf LOG "# Run started at %s (MJD %11.6F).\n",$current_iso,$current_mjd;

print LOG logline($tag,9,$time_int);
