#!/opt/local/bin/perl
#
# UNFINISHED (use IDL)
#
while (@ARGV) {
  $_ = shift;
  if (/^-/) { 	# is an option
    if (/^-h/) {
      &usage;
    } else {
      die "\nUnrecognized switch: $_\n\n";
    }
  } else {		# is not an option -- just list given files
    push(@infiles,$_);
  }
}
if (! @infiles) {
  print "$0: Need input files.\n";
  &usage;
  exit;
}
foreach $infile (@infiles) {
  open(INFILE,"< $infile") || die "\n$0: Cannot open input file $input\n";
  print "\nInput file: $infile\n\n";
#
# Read 1st 4 80-char header lines:
  $hdr1 = <INFILE>; $hdr2 = <INFILE>; $hdr3 = <INFILE>; $hdr4 = <INFILE>;
  chop $hdr1; chop $hdr2; chop $hdr3; chop $hdr4;
  print "$hdr1"; print "$hdr2"; print "$hdr3"; print "$hdr4"; 
#
# Read x spec:
  $xspec = <INFILE>; 
  $xspec =~ /nx=\s*(\d+)/ ; $nx = $1; 
  print "xspec=$xspec\n";
  print "nx=$nx\n"; 
  while (<INFILE>) {
    if ($_ =~ /^ny/) { last; }
    chop;
    @x = split(/\s+/,$_);
    foreach $number (@x) {
      push(@xx,$number)
    }
  }
  print "@xx\n";
#
# Read y spec:
  $yspec = $_ ; $yspec =~ /ny=\s*(\d+)/ ; $ny = $1; 
  print "ny=$ny\n"; 

  close(INFILE);
} 

exit 0;
#-------------------------------------------------------------------------
sub usage {
  print "\n","-" x 72,"\n";
  print "Usage: $0 [infiles]\n\n";
  print "-" x 72,"\n\n";
  exit 1;
}
