#!/usr/pkg/bin/perl -w

#
# dbrowcount.pm
# Copyright (C) 2007-2015 by John Heidemann <johnh@isi.edu>
# $Id: 83fba9f283f462ac2039ab283fe5e131f7390a09 $
#
# This program is distributed under terms of the GNU general
# public license, version 2.  See the file COPYING
# in $dblibdir for details.
#


=head1 NAME

dbrowcount - count the number of rows in an Fsdb stream

=head1 SYNOPSIS

dbrowcount

=head1 DESCRIPTION

Count the number of rows and write out a new fsdb file
with one column (n) and one value: the number of rows.
This program is a strict subset of L<dbcolstats>.

Although there are other ways to get a count of rows
(C<dbcolstats>, or C<dbrowaccumulate -C 1> and some processing),
counting is so common it warrants its own command.
(For example, consider how often C<wc -l> is used in regular shell
scripting.)
There are some gross and subtle differences, though, in that
C<dbrowcount> doesn't require one to specify a column to search,
and it also doesn't look for and skip null data items.

=head1 OPTIONS

No program-specific options.

=for comment
begin_standard_fsdb_options

This module also supports the standard fsdb options:

=over 4

=item B<-d>

Enable debugging output.

=item B<-i> or B<--input> InputSource

Read from InputSource, typically a file name, or C<-> for standard input,
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects.

=item B<-o> or B<--output> OutputDestination

Write to OutputDestination, typically a file name, or C<-> for standard output,
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects.

=item B<--autorun> or B<--noautorun>

By default, programs process automatically,
but Fsdb::Filter objects in Perl do not run until you invoke
the run() method.
The C<--(no)autorun> option controls that behavior within Perl.

=item B<--help>

Show help.

=item B<--man>

Show full manual.

=back

=for comment
end_standard_fsdb_options


=head1 SAMPLE USAGE

=head2 Input:

    #fsdb      absdiff
    0
    0.046953
    0.072074
    0.075413
    0.094088
    0.096602
    #  | /home/johnh/BIN/DB/dbrow 
    #  | /home/johnh/BIN/DB/dbcol event clock
    #  | dbrowdiff clock
    #  | /home/johnh/BIN/DB/dbcol absdiff

=head2 Command:

    cat data.fsdb | dbrowcount

=head2 Output:

    #fsdb n
    6
    #  | /home/johnh/BIN/DB/dbrow 
    #  | /home/johnh/BIN/DB/dbcol event clock
    #  | dbrowdiff clock
    #  | /home/johnh/BIN/DB/dbcol absdiff

=head2 Input 2:

As another example, this input produces the same output as above in
C<dbrowcount>, but different output in C<dbstats>:

    #fsdb      absdiff
    -
    -
    -
    -
    -
    -
    #  | /home/johnh/BIN/DB/dbrow 
    #  | /home/johnh/BIN/DB/dbcol event clock
    #  | dbrowdiff clock
    #  | /home/johnh/BIN/DB/dbcol absdiff


=head1 SEE ALSO

L<dbcolaccumulate(1)>,
L<dbcolstats(1)>,
L<Fsdb(3)>

=cut


# WARNING: This code is derived from dbrowcount.pm; that is the master copy.

use Fsdb::Filter::dbrowcount;
my $f = new Fsdb::Filter::dbrowcount(@ARGV);
$f->setup_run_finish;  # or could just --autorun
exit 0;


=head1 AUTHOR and COPYRIGHT

Copyright (C) 2007-2015 by John Heidemann <johnh@isi.edu>

This program is distributed under terms of the GNU general
public license, version 2.  See the file COPYING
with the distribution for details.

=cut

1;

