Skip to content

Commit

Permalink
add a method to get the qualifiers from the RTMD for a descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Beauregard committed Aug 30, 2016
1 parent fd27edb commit 3313912
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
44 changes: 44 additions & 0 deletions EC.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,50 @@ descriptor(d)
OUTPUT:
RETVAL

=head2 $desc->qualifiers([qualdescs])

Returns the list of active (uncancelled) L<Geo::BUFR::EC::Descriptor>
qualifiers for the given descriptor. If a specific list of C<qualdescs>
descriptors are requested, only those will be returned (where available).

Note that the descriptor needs to be part of an expanded datasubset in order
for qualifiers to be available.

=cut

void qualifiers(d,...)
Geo::BUFR::EC::Descriptor d
PREINIT:
SV* relatedsv = ST(0);
int r = 0, i;
PPCODE:
if( d->meta == NULL ) XSRETURN_EMPTY;
if( d->meta->nb_qualifiers==0 ) XSRETURN_EMPTY;
if( items > 1 ) {
for( i = 1; i < items; i ++ ) {
BufrDescriptor* qual = bufr_fetch_rtmd_qualifier(
SvIV(ST(i)), d->meta);
if( qual ) {
ST(r) = sv_newmortal();
sv_setref_pv(ST(r), "Geo::BUFR::EC::Descriptor", (void*)qual);
hold_related(ST(r), relatedsv);
r ++;
}
}
} else {
EXTEND(SP,d->meta->nb_qualifiers);
for( i = 0; i < d->meta->nb_qualifiers; i ++ ) {
if( d->meta->qualifiers[i]==NULL ) continue;
ST(r) = sv_newmortal();
sv_setref_pv(ST(r), "Geo::BUFR::EC::Descriptor",
(void*)d->meta->qualifiers[i]);
hold_related(ST(r), relatedsv);
r ++;
}
r ++;
}
XSRETURN(r);

=head2 $desc->value()

Returns the L<Geo::BUFR::EC::Value> value for C<$desc>.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ t/encode_delayed_template.t
t/encode_tablec.t
t/class_method.t
t/lookup.t
t/quals.t
56 changes: 56 additions & 0 deletions t/quals.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Geo-BUFR-EC.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use Test::More qw/no_plan/;
BEGIN { use_ok('Geo::BUFR::EC') };

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

$ENV{BUFR_TABLES} = '/usr/share/libecbufr/';

my $bulletin = '';
open(my $f, '<', 't/sample.bufr') || die $!;
$bulletin .= $_ while(<$f>);
close $f;

my $msg = Geo::BUFR::EC::Message->fromString($bulletin);
ok( defined $msg );

$tables = Geo::BUFR::EC::Tables->new();
ok( defined $tables );

ok( not defined $tables->master_version() );
ok( not defined $tables->local_version() );

$tables->cmc();

my $dts = $msg->decode($tables);
ok( defined $dts );

my $nds = $dts->count_datasubset();
print "$nds data subsets\n";
for( my $sno = 0; $sno < $nds; $sno ++ ) {
$dts->expand_datasubset($sno);
my $ds = $dts->get_datasubset($sno);
ok( defined $ds );

my $dno = 0;
while( defined($dno = $ds->find_descriptor(20054, $dno+1) ) ) {
my $d = $ds->get_descriptor($dno);
my @quals = $d->qualifiers();
ok( @quals > 0 );
my @quals = $d->qualifiers(8002);
ok( @quals == 1 );
print "qualifier ",$quals[0]->descriptor(), " => ",
$quals[0]->get(), "\n";
}
}

exit 0;

0 comments on commit 3313912

Please sign in to comment.