#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

# get the file name
$filename = $ARGV[0];
if (!$filename) {
    die 'error: xml file name must be supplied as first argument';
}
# slurp in the xml file noisily
$ref = XMLin($filename, KeyAttr => []);
# dump it to the screen for debugging only
#print Dumper($ref);

$name = $ref->{name};
@token = split($name, $filename);
$dirname = $token[0];
print "ccdbcmd mktbl /calib/$dirname$ref->{name}";
print " -r $ref->{nrow}";
$ncol = $ref->{ncol};
for ($ic = 0; $ic < $ncol; $ic++) {
    if ($ref->{column}[$ic]->{number} != $ic + 1) {
	die "column number does not match expectation";
    }
    print " $ref->{column}[$ic]->{name}";
}
print " #$ref->{comment}";
print "\n";

exit;

print "name = $ref->{name}\n";
print "comment = $ref->{comment}\n";
$ncol = $ref->{ncol};
for ($ic = 0; $ic < $ncol; $ic++) {
    print "index = $ic\n";
    print "column number = $ref->{column}[$ic]->{number}\n";
    print "column name = $ref->{column}[$ic]->{name}\n";
}

