1#!/usr/local/bin/perl56 -I/usr/local/lib/metaps/perl 2 3use strict; use warnings; 4 5# Generate the mars tables from paramDB 6# stream.table 7# type.table 8# class.table 9 10use Data::Dumper; 11use DBI; 12 13#use DBConfig; 14#my %Config = DBConfig::get_config; 15#my $db=$Config{DB}; 16#my $host=$Config{HOST}; 17#my $user=$Config{USER}; 18#my $pass=$Config{PASS}; 19 20my $db="param"; 21my $host="grib-param-db-prod.ecmwf.int"; 22my $user="ecmwf_ro"; 23my $pass="ecmwf_ro"; 24 25my $dbh = DBI->connect("dbi:mysql(RaiseError=>1):database=$db;host=$host","$user","$pass") or die $DBI::errstr; 26 27my $mars_dir = "mars"; 28 29foreach my $att qw(class type stream) { 30 my $sth = $dbh->prepare("select grib_code,mars_abbreviation,long_name from grib_$att order by grib_code"); 31 $sth->execute(); 32 33 my $mars_file = "${mars_dir}/${att}.table"; 34 open OUT,">${mars_file}" or die $!; 35 print OUT "0 0 Unknown\n"; 36 37 while (my @row = $sth->fetchrow_array) { 38 #print Data::Dumper->Dump(\@row); 39 40 # NOTE: 41 # The parameter DB type table has extra entries which cannot fit into 42 # an octet (range of values of mars.type is 0->255) so we skip these 43 if ($att eq "type") { 44 my $type_code = $row[0]; 45 next if ($type_code > 255); 46 } 47 print OUT join " ",@row; 48 print OUT "\n"; 49 } 50 print "Wrote ${mars_file}\n"; 51 52 close(OUT); 53} 54