Definitions: Fix script to do cfVarNames too

This commit is contained in:
Shahram Najm 2024-11-12 14:36:01 +00:00
parent b41872cf23
commit 6d5501536f
4 changed files with 212 additions and 68 deletions

View File

@ -350,6 +350,92 @@ EOF
close(TAR);
}
sub create_cfVarName {
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"; }
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
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
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 ($key =~ /paramId/ && $force128==1 && $keyval >1000) {
# $keyval= $keyval % 1000;
#}
if ($filebase ne "$basedir/grib$edition$conceptDir") {
if ($filebase) {
print $out "}\n";
close $out;
}
$filebase="$basedir/grib$edition$conceptDir";
mkpath($filebase);
#copy("$filebase/$key.def","$filebase/$key.def.bkp")
# or die ("unable to copy $filebase/$key.def");
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_paramId_def {
my $p; my %seen;
@ -443,6 +529,7 @@ create_def("name");
create_def_legacy("name");
create_def("units");
create_def_legacy("units");
create_cfVarName("cfVarName");
create_cfName("cfName");
create_cfName_legacy("cfName");

View File

@ -189,6 +189,11 @@
table2Version = 171 ;
indicatorOfParameter = 7 ;
}
#100 metre wind speed anomaly
'sia100' = {
table2Version = 171 ;
indicatorOfParameter = 8 ;
}
#2 metre specific humidity
'sh2' = {
table2Version = 174 ;

View File

@ -119,34 +119,6 @@
scaleFactorOfLowerLimit = 0 ;
probabilityType = 3 ;
}
#Time-mean 2D wave spectra (single)
'avg_2dfd' = {
discipline = 10 ;
parameterCategory = 0 ;
parameterNumber = 86 ;
typeOfStatisticalProcessing = 0 ;
}
#Time-maximum 2D wave spectra (single)
'max_2dfd' = {
discipline = 10 ;
parameterCategory = 0 ;
parameterNumber = 86 ;
typeOfStatisticalProcessing = 2 ;
}
#Time-minimum 2D wave spectra (single)
'min_2dfd' = {
discipline = 10 ;
parameterCategory = 0 ;
parameterNumber = 86 ;
typeOfStatisticalProcessing = 3 ;
}
#Time-standard-deviation 2D wave spectra (single)
'std_2dfd' = {
discipline = 10 ;
parameterCategory = 0 ;
parameterNumber = 86 ;
typeOfStatisticalProcessing = 6 ;
}
#2 metre specific humidity
'sh2' = {
discipline = 0 ;
@ -214,6 +186,26 @@
scaledValueOfFirstFixedSurface = 100 ;
scaleFactorOfFirstFixedSurface = 0 ;
}
#Time-maximum 2 metre relative humidity
'mx2r' = {
discipline = 0 ;
parameterCategory = 1 ;
parameterNumber = 1 ;
typeOfFirstFixedSurface = 103 ;
scaledValueOfFirstFixedSurface = 2 ;
scaleFactorOfFirstFixedSurface = 0 ;
typeOfStatisticalProcessing = 2 ;
}
#Time-minimum 2 metre relative humidity
'mn2r' = {
discipline = 0 ;
parameterCategory = 1 ;
parameterNumber = 1 ;
typeOfFirstFixedSurface = 103 ;
scaledValueOfFirstFixedSurface = 2 ;
scaleFactorOfFirstFixedSurface = 0 ;
typeOfStatisticalProcessing = 3 ;
}
#Time-mean sea ice area fraction
'avg_ci' = {
discipline = 10 ;

View File

@ -1,4 +1,10 @@
# Automatically generated by ./create_def.pl, do not edit
#Sea ice area fraction
'siconc' = {
discipline = 192 ;
parameterCategory = 128 ;
parameterNumber = 31 ;
}
#Maximum temperature at 2 metres in the last 24 hours
'mx2t24' = {
discipline = 0 ;
@ -95,6 +101,18 @@
typeOfStatisticalProcessing = 3 ;
lengthOfTimeRange = 3 ;
}
#Maximum 10 metre wind gust in the last 3 hours
'fg310' = {
discipline = 192 ;
parameterCategory = 228 ;
parameterNumber = 28 ;
}
#100 metre wind speed
'si100' = {
discipline = 192 ;
parameterCategory = 228 ;
parameterNumber = 249 ;
}
#10 metre wind gust gradient
'fggrd10' = {
discipline = 192 ;
@ -343,6 +361,24 @@
parameterCategory = 140 ;
parameterNumber = 250 ;
}
#2D wave spectra (single)
'd2fd' = {
discipline = 192 ;
parameterCategory = 140 ;
parameterNumber = 251 ;
}
#Eastward surface sea water velocity
'uoe' = {
discipline = 192 ;
parameterCategory = 151 ;
parameterNumber = 131 ;
}
#Northward surface sea water velocity
'von' = {
discipline = 192 ;
parameterCategory = 151 ;
parameterNumber = 132 ;
}
#10 metre wind gust during averaging time
'fgrea10' = {
discipline = 192 ;
@ -397,9 +433,33 @@
parameterCategory = 200 ;
parameterNumber = 168 ;
}
#Time-mean 2 metre temperature
'avg_2t' = {
discipline = 192 ;
parameterCategory = 228 ;
parameterNumber = 4 ;
}
#Time-mean 10 metre wind speed
'avg_10ws' = {
discipline = 192 ;
parameterCategory = 228 ;
parameterNumber = 5 ;
}
#2 metre temperature significance
't2s' = {
discipline = 192 ;
parameterCategory = 234 ;
parameterNumber = 167 ;
}
#100 metre U wind component
'u100' = {
discipline = 192 ;
parameterCategory = 228 ;
parameterNumber = 246 ;
}
#100 metre V wind component
'v100' = {
discipline = 192 ;
parameterCategory = 228 ;
parameterNumber = 247 ;
}