Skip to content

Commit

Permalink
DGOV-507: GRIB2: Add legacy parameters to paramdb
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Oct 25, 2024
1 parent 9b72c73 commit 57a47b8
Show file tree
Hide file tree
Showing 9 changed files with 7,323 additions and 7,259 deletions.
118 changes: 99 additions & 19 deletions definitions/create_def.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ sub create_cfName {
attribute.id=grib.attribute_id and
centre.id=grib_encoding.centre_id and
units.id=param.units_id and
param.id=cf.grib1_ecmwf order by
param.id=cf.grib1_ecmwf and
grib_encoding.is_legacy=0 order by
edition,centre_id,param.o,param.id,grib_encoding.param_version,attribute.o;
EOF

Expand Down Expand Up @@ -98,6 +99,83 @@ sub create_cfName {
close(TAR);
}

sub create_cfName_legacy {
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_encoding,grib,attribute,centre,units,cf where
param.hide_def=0 and
# param.retired=0 and
grib_encoding.id=grib.encoding_id and
param.id=grib_encoding.param_id and
attribute.id=grib.attribute_id and
centre.id=grib_encoding.centre_id and
units.id=param.units_id and
param.id=cf.grib1_ecmwf and
grib_encoding.is_legacy=1 order by
edition,centre_id,param.o,param.id,grib_encoding.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 "wmo" ) { $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.legacy.def\n";
#system("cp -f $filebase/$key.def $filebase/$key.def.orig");
open($out,"> $filebase/$key.legacy.def")
or die "unable to open $filebase/$key.legacy.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) =@_;
Expand All @@ -117,7 +195,8 @@ sub create_def {
param.id=grib_encoding.param_id and
attribute.id=grib.attribute_id and
centre.id=grib_encoding.centre_id and
units.id=param.units_id
units.id=param.units_id and
grib_encoding.is_legacy=0
order by edition,centre_id,param.o,param.id,grib_encoding.param_version,attribute.o;
EOF

Expand Down Expand Up @@ -183,29 +262,27 @@ sub create_def {
close(TAR);
}

# See ECC-1886
sub create_cfVarName {
sub create_def_legacy {
my $p; my %seen;
my ($key) =@_;
my $field=$key;

#if ($key =~ /paramId/) { $field="param.id"; }
#if ($key =~ /name/) { $field="param.name"; }
#if ($key =~ /units/) { $field="units.name"; }
if ($key =~ /cfVarName/) { $field="cfVarName"; }
if ($key =~ /paramId/) { $field="param.id"; }
if ($key =~ /name/) { $field="param.name"; }
if ($key =~ /units/) { $field="units.name"; }

my $query= <<"EOF";
select $field,force128,edition,
centre.abbreviation,param_id,attribute.name,attribute_value,param.name,param.shortName
from param,grib_encoding,grib,attribute,centre,units where
param.hide_def=0 and
param.retired=0 and
# param.retired=0 and
grib_encoding.id=grib.encoding_id and
param.id=grib_encoding.param_id and
attribute.id=grib.attribute_id and
centre.id=grib_encoding.centre_id and
units.id=param.units_id
and cfVarName IS NOT NULL
units.id=param.units_id and
grib_encoding.is_legacy=1
order by edition,centre_id,param.o,param.id,grib_encoding.param_version,attribute.o;
EOF

Expand Down Expand Up @@ -237,10 +314,10 @@ sub create_cfVarName {
#copy("$filebase/$key.def","$filebase/$key.def.bkp")
# or die ("unable to copy $filebase/$key.def");

print TAR "grib$edition$conceptDir/$key.def\n";
print TAR "grib$edition$conceptDir/$key.legacy.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";
open($out,"> $filebase/$key.legacy.def")
or die "unable to open $filebase/$key.legacy.def";
print $out "# Automatically generated by $0, do not edit\n";
$p=();
}
Expand Down Expand Up @@ -270,7 +347,7 @@ sub create_cfVarName {

close(TAR);
}

sub create_paramId_def {
my $p; my %seen;

Expand All @@ -281,7 +358,8 @@ sub create_paramId_def {
grib_encoding.id=grib.encoding_id and
param.id=grib_encoding.param_id and
attribute.id=grib.attribute_id and
centre.id=grib_encoding.centre_id
centre.id=grib_encoding.centre_id and
grib_encoding.is_legacy=0
order by edition,centre_id,param.o,param.id,attribute.o";
my $qh=$dbh->prepare($query);
$qh->execute();
Expand Down Expand Up @@ -355,13 +433,15 @@ sub create_def_old {
}

create_def("paramId");
create_def_legacy("paramId");
create_def("shortName");
create_def_legacy("shortName");
create_def("name");
create_def_legacy("name");
create_def("units");
# Note: The cfVarName.def files are smaller than the rest. We only store the
# minimum set necessary. See ECC-1886
create_cfVarName("cfVarName");
create_def_legacy("units");
create_cfName("cfName");
create_cfName_legacy("cfName");

# #create_paramId_def();

Expand Down
Loading

0 comments on commit 57a47b8

Please sign in to comment.