2018-08-02 10:27:39 +00:00
|
|
|
#! /usr/local/apps/perl/current/bin/perl
|
|
|
|
|
|
|
|
# old #!/usr/local/bin/perl56 -I/usr/local/lib/metaps/perl
|
2014-10-30 11:42:56 +00:00
|
|
|
|
|
|
|
use strict; use warnings;
|
|
|
|
|
|
|
|
# Generate the mars tables from paramDB
|
|
|
|
# stream.table
|
|
|
|
# type.table
|
|
|
|
# class.table
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
#use DBConfig;
|
|
|
|
#my %Config = DBConfig::get_config;
|
|
|
|
#my $db=$Config{DB};
|
|
|
|
#my $host=$Config{HOST};
|
|
|
|
#my $user=$Config{USER};
|
|
|
|
#my $pass=$Config{PASS};
|
|
|
|
|
|
|
|
my $db="param";
|
|
|
|
my $host="grib-param-db-prod.ecmwf.int";
|
2018-08-02 10:27:39 +00:00
|
|
|
my $user="ecmwf_ro"; # Read-only access to Param DB
|
|
|
|
my $pass="ecmwf_ro"; # Read-only access to Param DB
|
2014-10-30 11:42:56 +00:00
|
|
|
|
|
|
|
my $dbh = DBI->connect("dbi:mysql(RaiseError=>1):database=$db;host=$host","$user","$pass") or die $DBI::errstr;
|
|
|
|
|
|
|
|
my $mars_dir = "mars";
|
|
|
|
|
2018-08-02 10:27:39 +00:00
|
|
|
foreach my $att ('class', 'type', 'stream') {
|
2014-10-30 11:42:56 +00:00
|
|
|
my $sth = $dbh->prepare("select grib_code,mars_abbreviation,long_name from grib_$att order by grib_code");
|
|
|
|
$sth->execute();
|
|
|
|
|
|
|
|
my $mars_file = "${mars_dir}/${att}.table";
|
2018-08-02 10:27:39 +00:00
|
|
|
open OUT,">${mars_file}" or die "Failed to write \"$mars_file\": $!";
|
2014-10-30 11:42:56 +00:00
|
|
|
print OUT "0 0 Unknown\n";
|
|
|
|
|
|
|
|
while (my @row = $sth->fetchrow_array) {
|
|
|
|
#print Data::Dumper->Dump(\@row);
|
|
|
|
|
|
|
|
# NOTE:
|
|
|
|
# The parameter DB type table has extra entries which cannot fit into
|
|
|
|
# an octet (range of values of mars.type is 0->255) so we skip these
|
|
|
|
if ($att eq "type") {
|
|
|
|
my $type_code = $row[0];
|
|
|
|
next if ($type_code > 255);
|
|
|
|
}
|
|
|
|
print OUT join " ",@row;
|
|
|
|
print OUT "\n";
|
|
|
|
}
|
|
|
|
print "Wrote ${mars_file}\n";
|
|
|
|
|
|
|
|
close(OUT);
|
|
|
|
}
|