#!/usr/bin/perl -w # # dbmultistats # Copyright (C) 1991-1998 by John Heidemann # $Id: dbmultistats,v 1.23 2003/05/23 04:17:45 johnh Exp $ # # This program is distributed under terms of the GNU general # public license, version 2. See the file COPYING # in $dblibdir for details. # sub usage { print STDERR <getopt) { $ch = $dbopts->opt; if ($ch eq 'c') { $conf_pct = $dbopts->optarg; } elsif ($ch eq 'f') { $format = $dbopts->optarg; } elsif ($ch eq 'd') { $debug = 1; } elsif ($ch eq 'm') { $median = 1; } elsif ($ch eq 'q') { $ntile = $dbopts->optarg; } else { &usage; }; }; &usage if ($#ARGV != 1); my($tagcol, $valcol) = @ARGV; &readprocess_header; die ("$prog: unknown column name ``$tagcol''.\n") if (!defined($colnametonum{$tagcol})); my($tagf) = $colnametonum{$tagcol}; my($tagname) = $colnames[$tagf]; die ("$prog: unknown column name ``$valcol''.\n") if (!defined($colnametonum{$valcol})); my($valf) = $colnametonum{$valcol}; my(%tag_files, %tag_counts, $tag, $path); # read data while () { &delayed_pass_comments() && next; &split_cols; $tag = $f[$tagf]; $val = $f[$valf]; if (defined($tag_files{$tag})) { $tag_counts{$tag}++; } else { # open a new file $path = $tag_files{$tag} = &db_tmpfile(TMP); close(TMP); open PATH, ">>$path"; print PATH "$col_headertag data\n"; $tag_counts{$tag} = 1; }; $path = $tag_files{$tag}; open PATH, ">>$path"; print PATH "$val\n"; }; @dbstats_args = ("$dbbindir/dbstats"); push(@dbstats_args, '-c', $conf_pct) if (defined($conf_pct)); push(@dbstats_args, '-q', $ntile) if (defined($ntile)); push(@dbstats_args, '-m') if (defined($median)); push(@dbstats_args, '0'); # send each tag to mean foreach $tag (sort keys %tag_files) { # close it $path = $tag_files{$tag}; close(PATH); open(FROMMEAN, join(" ", @dbstats_args) . " <$tag_files{$tag} |") || die "$prog: cannot run dbstats.\n"; @meanout = ; close(FROMMEAN); if (defined($meanoutheader)) { print "# $tag\n" if ($debug); die("$prog: dbstats header mismatch on tag ``$tag''.\n". join("\n", @meanout) . "\n") if ($meanout[0] ne $meanoutheader); } else { $meanoutheader = $meanout[0]; &process_header($meanoutheader); &col_create($tagname, 0); # create the tag column at the beginning &write_header(); print "# $tag\n" if ($debug); }; print "$tag$outfs$meanout[1]"; } # close up shop &delayed_flush_comments(); print "# | $prog ", join(" ", @orig_argv), "\n"; exit 0; if (0) { my($x); $x = $col_headertag; $x = $outfs; $x = $colnames; $x = ; $x = ; }