How to encode replicated descriptors

Asked by Charlie Martin

I've been exploring libECBUFR, to use for encoding upsonde and dropsonde soundings. This will be added to an existing radiosonde processing program. I'm working with templates 309052 and 309054.

I can't figure out the procedure for inserting replicated descriptors into a template. Perhaps there is an example that shows this, but I haven't been able to find it.

My idea is that I sequence through the template until I find the delayed replication descriptor, and then use some api call to insert the replicated descriptors. But I'm not seeing a way to do this.

Any guidance on the general approach with libECBUFR would be appreciated.

Thanks,
Charlie

Question information

Language:
English Edit question
Status:
Solved
For:
libECBUFR Edit question
Assignee:
No assignee Edit question
Solved by:
Charlie Martin
Solved:
Last query:
Last reply:
Revision history for this message
Yves Pelletier (yves-pelletier) said :
#1

Hello Charlie,

Thank you for your question and for your interest in libECBUFR. At this point I am going to give you a very hasty answer, mainly to acknowledge that we have seen your question and that we will not leave you in the dark.

I certainly acknowledge we could do better in terms of documentation. You sound like you are able to browse through code to look for examples, and for now, this close to the holidays, I can only suggest you look into the code for function bufr_genmsgs_from_dump and see if anything there helps clear things up for you.

We will be in touch again in January.

Regards and best wishes of the season

Yves

Revision history for this message
Charlie Martin (martinc-e) said :
#2

Thanks Yves.

I took a look at bufr_genmsgs_from_dump(), but it quickly descended into very low level activities, and I really have no idea what is going on in there. I look forward to returning to this in January, when I'm sure you'll be able to lead me out of the woods!

Regards,
Charlie

Revision history for this message
cpb (chris-beauregard) said :
#3

I don't believe there's a C example, but my perl bindings have a test case here:

  http://bazaar.launchpad.net/~chris-beauregard/libecbufr/libecbufr-perl/view/head:/t/encode_delayed_template.t

Roughly speaking, the approach is:

1. create the template
2. create the dataset from the template
3. create a datasubset from the dataset
4. expand the datasubset (if necessary, such as the replication descriptor being buried in a Table C)
5. find the delayed replication descriptor in the datasubset
6. set the value of the replication descriptor to your replication $count
7. expand the datasubset (again). Note that if you didn't mess with anything else, the result of the previous
find will still be valid, and now there will be $count blank and expanded replicated elements just after that
position.
8. set the values for the replicated descriptors.

I could certainly add a proper example or test case if that's not clear enough. The key is that after setting the delayed replication value, then expanding the datasubset expands out the replicated elements into a bunch of missing values and that's where you do your leg work.

Revision history for this message
cpb (chris-beauregard) said :
#4

r321 adds a complete example of encoding delayed replication from the C API:

http://bazaar.launchpad.net/~libecbufr-dev/libecbufr/trunk/view/head:/Examples/encode_delayed_repl.c

Revision history for this message
Charlie Martin (martinc-e) said :
#5

Thanks, that helps a lot..

 delayed_repl.c showed me the procedure for inserting delayed replication descriptors. It also showed how to create a template without having to provide a file with the template specification in it, which was very useful.

After adding the replicated descriptors, I find that I can't set their values. bufr_descriptor_set_ivalue() returns -1. When I trace through the library, I find that the encoding type (bc->encoding.type) doesn't seem to be set for the descriptor., causing bufr_mkval_for_descriptor() to return null.

(note : I wonder if there might be a typo in delayed_repl.c, at line 53? Shouldn't bufr_get_datasubset() be requesting subset 0, rather than subset n?)

Revision history for this message
cpb (chris-beauregard) said :
#6

> When I trace through the library, I find that the encoding type (bc->encoding.type) doesn't seem to be set for the descriptor.

I'd probably have to see the code, but... that might actually be a table issue. It might be advisable to enable debug output, as the bufr_merge.c example does. If there's problems with tables (i.e. missing descriptors) that should tell you about them.

> Shouldn't bufr_get_datasubset() be requesting subset 0, rather than subset n?

In this case, either works. n is initialized on line 45 with:

    n = bufr_create_datasubset(dts);

... but n==0 since we're only creating one datasubset. Using a variable like n is just a better habit to get into as your code will handle multiple datasubsets without (as much) pain.

Revision history for this message
Charlie Martin (martinc-e) said :
#7

Ok, I mistook n as the number of datasubsets, rather than the index. That makes sense.

With this help, I've been able to get encoding of delayed replicators to work. Thanks.

Revision history for this message
cpb (chris-beauregard) said :
#8

Glad we could help.