#!/usr/bin/perl -w
{
  $version = $0;

  require ("cgi-lib.pl");
  require "wjs_web_perl_utilities.pl";

if ($ENV{'PATH_INFO'}) {
  &printheader();

#   Set up environment.  Assume .pl routine is in our directory 
  $build_opt_env = "./build-opt-env.pl";
  &check_r_access($build_opt_env);
  require $build_opt_env;

 #   Check that build-opt-env set up things as expected
  defined ($ENV{'OBJECT'}) ||
        &quit ("Internal problem.  ",
                "Did not get defined env var OBJECT from $build_opt_env");
  ($object = $ENV{'OBJECT'}) ||
        &quit ("Internal problem.  ",
                "Did not get non-empty env var OBJECT from $build_opt_env");
  defined ($ENV{'SUBSELS'}) ||
        &quit ("Internal problem.  ",
                "Did not get defined envar SUBSELS from $build_opt_env");
  ($subsels = $ENV{'SUBSELS'}) ||
        &quit ("Did not get required projection");
#   Next test inferior because it does not distinguish sel from proj
  ($subsels,$dummy) = split /\,/,$subsels;
  $dummy && &quit("Must have only one projected variable","Got sel/proj string $ENV{'SUBSELS'}");
  $objspec = qq|$object($ENV{'SUBSELS'})|;
  print "<pre>\n";
  $open_pre_tag = 1;
} else {
  $open_pre_tag = 0;
  $objspec = $ARGV[0];
}

  $command = qq|../bin/list -b  -c "$objspec" |;
  $! = $? = 0;
  open IN,"$command |" || &quit ("Could not pipe from $command","$!=$!; \$?=$?");


  $nrec = 0;
  $ngood = 0; 
  while (defined ($rec = <IN>))  {
    $nrec++;
    chomp $rec;
    $rec || ((print "[Value for $subsels empty]\n") && next);
   ($rec) = ($rec =~ /^\s*(.*?)\s*$/);
    ($rec  eq "") && (print "[Value for $subsels all whitespace]\n") && next;
    ($rec eq "nd") && next;
    (&valid_number($rec)) || ((print "$rec\n") && next);
    $ngood++;
  }
  print "\nSummary:\n\t$nrec records processed\n\t$ngood were numeric\n";
  undef $version;
  exit(0);
}
