mirror of https://github.com/ecmwf/eccodes.git
Definitions: cfName update from parameter DB
This commit is contained in:
parent
0f6893685f
commit
1bb5b4c28f
|
@ -20,6 +20,75 @@ my $dbh = DBI->connect("dbi:mysql(RaiseError=>1):database=$db;host=$host",$user
|
|||
# I have written to it already or not
|
||||
my $tarfilesflag = 0;
|
||||
|
||||
sub create_cfName {
|
||||
my $p; my %seen;
|
||||
my ($key) = "cfName";
|
||||
my $field = "cf.name";
|
||||
|
||||
my $query= <<"EOF";
|
||||
select $field,force128,edition,
|
||||
centre.abbreviation,param_id,attribute.name,attribute_value,param.name,param.shortName
|
||||
from param,grib,attribute,centre,units,cf where param.hide_def=0 and param.id=grib.param_id
|
||||
and attribute.id=grib.attribute_id and centre.id=grib.centre and units.id=param.units_id and param.id=cf.grib1_ecmwf
|
||||
order by edition,centre,param.o,param.id,grib.param_version,attribute.o;
|
||||
EOF
|
||||
|
||||
my $qh=$dbh->prepare($query);
|
||||
$qh->execute();
|
||||
|
||||
# file containing the list of grib api parameters files we want to tar and
|
||||
# distribute to users for them to download and update their list of parameter
|
||||
# to the latest
|
||||
open(TAR,$tarfilesflag ? ">>" : ">","tarfiles.txt") or die "Count not open file tarfiles.txt: $!";
|
||||
$tarfilesflag=1;
|
||||
|
||||
while (my ($keyval,$force128,$edition,$centre,$paramId,$attribute,$value,$name,$shortName)=$qh->fetchrow_array )
|
||||
{
|
||||
if ($centre eq "all" ) { $conceptDir=""; }
|
||||
else { $conceptDir="/localConcepts/$centre"; }
|
||||
|
||||
if ($filebase ne "$basedir/grib$edition$conceptDir") {
|
||||
if ($filebase) {
|
||||
print $out "}\n";
|
||||
close $out;
|
||||
}
|
||||
$filebase="$basedir/grib$edition$conceptDir";
|
||||
mkpath($filebase);
|
||||
|
||||
print TAR "grib$edition$conceptDir/$key.def\n";
|
||||
system("cp -f $filebase/$key.def $filebase/$key.def.orig");
|
||||
open($out,"> $filebase/$key.def")
|
||||
or die "unable to open $filebase/$key.def";
|
||||
print $out "# Automatically generated by $0, do not edit\n";
|
||||
$p=();
|
||||
}
|
||||
if ($p ne $paramId || exists($seen{$attribute}) ) {
|
||||
if ($p) { print $out "\t}\n"; }
|
||||
print $out "#$name\n" ;
|
||||
print $out "\'".$keyval."\' = {\n" ;
|
||||
$p=$paramId;
|
||||
%seen=();
|
||||
}
|
||||
$seen{$attribute}=1;
|
||||
print "($key=$keyval) $edition,$centre,$shortName,$paramId,$name,$attribute,$value\n";
|
||||
# we need to allow strings in the attribute_value field
|
||||
# for the moment we apply a patch here
|
||||
if ($attribute =~ /stepType/ ) {
|
||||
$value="\"accum\"";
|
||||
}
|
||||
if ($value eq '') {
|
||||
$value="missing()";
|
||||
}
|
||||
print $out "\t $attribute = $value ;\n" ;
|
||||
}
|
||||
if ($filebase) {
|
||||
print $out "}\n";
|
||||
close $out;
|
||||
}
|
||||
|
||||
close(TAR);
|
||||
}
|
||||
|
||||
sub create_def {
|
||||
my $p; my %seen;
|
||||
my ($key) =@_;
|
||||
|
@ -185,7 +254,7 @@ create_def("paramId");
|
|||
create_def("shortName");
|
||||
create_def("name");
|
||||
create_def("units");
|
||||
|
||||
create_cfName("cfName");
|
||||
|
||||
#create_paramId_def();
|
||||
|
||||
|
|
Loading…
Reference in New Issue