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