This file is indexed.

/usr/share/doc/libwreport-doc/apidocs/examples.html is in libwreport-doc 2.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>libwreport: Code examples</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">libwreport&#160;<span id="projectnumber">2.1</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">Code examples </div>  </div>
</div>
<div class="contents">
<div class="textblock"><h2><a class="anchor" id="examples_reading"></a>
Reading and decoding bulletins</h2>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * input - BUFR and CREX input examples</span>
<span class="comment"> *</span>
<span class="comment"> * Copyright (C) 2011  ARPA-SIM &lt;urpsim@smr.arpa.emr.it&gt;</span>
<span class="comment"> *</span>
<span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<span class="comment"> * the Free Software Foundation; either version 2 of the License.</span>
<span class="comment"> *</span>
<span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> * GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> * You should have received a copy of the GNU General Public License</span>
<span class="comment"> * along with this program; if not, write to the Free Software</span>
<span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA</span>
<span class="comment"> *</span>
<span class="comment"> * Author: Enrico Zini &lt;enrico@enricozini.com&gt;</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &lt;<a class="code" href="bulletin_8h.html" title="Intermediate representation of parsed values, ordered according to a BUFR or CREX message template...">wreport/bulletin.h</a>&gt;</span>
<span class="preprocessor">#include &quot;options.h&quot;</span>

<span class="keyword">using namespace </span>wreport;

<span class="comment">// Read all BUFR messages from a file</span>
<span class="keywordtype">void</span> read_bufr(<span class="keyword">const</span> Options&amp; opts, <span class="keyword">const</span> <span class="keywordtype">char</span>* fname, BulletinHandler&amp; handler)
{
    <span class="comment">// Open the input file</span>
    FILE* in = fopen(fname, <span class="stringliteral">&quot;rb&quot;</span>);
    <span class="keywordflow">if</span> (in == NULL)
        <a class="code" href="structwreport_1_1error__system.html#ae91b8d57c825a893e74599a1e2664844" title="Throw the exception, building the message printf-style.">error_system::throwf</a>(<span class="stringliteral">&quot;opening file %s&quot;</span>, fname);

    <span class="comment">// Use a generic try/catch block to ensure we always close the input file,</span>
    <span class="comment">// even in case of errors</span>
    <span class="keywordflow">try</span> {
        <span class="comment">// Create a BUFR bulletin</span>
        auto_ptr&lt;Bulletin&gt; bulletin(<a class="code" href="structwreport_1_1BufrBulletin.html#a41bfffb8be7da42495c4a4dade761960" title="To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...">BufrBulletin::create</a>());

        <span class="comment">// String used to hold raw data read from the input file</span>
        <span class="keywordtype">string</span> raw_data;

        <span class="comment">// (optional) offset of the start of the BUFR message read, which we</span>
        <span class="comment">// pass to the decoder to have nicer error messages</span>
        <span class="keywordtype">long</span> offset;

        <span class="comment">// Read all BUFR data in the input file, one message at a time. Extra</span>
        <span class="comment">// data before and after each BUFR message is skipped.</span>
        <span class="comment">// fname and offset are optional and we pass them just to have nicer</span>
        <span class="comment">// error messages.</span>
        <span class="keywordflow">while</span> (<a class="code" href="structwreport_1_1BufrBulletin.html#a1e16d73ba74fdb1f6d4aed545b3fa2d2" title="Read an encoded BUFR message from a stream.">BufrBulletin::read</a>(in, raw_data, fname, &amp;offset))
        {
            <span class="comment">// Decode the raw data. fname and offset are optional and we pass</span>
            <span class="comment">// them just to have nicer error messages</span>
            bulletin-&gt;decode(raw_data, fname, offset);

            <span class="comment">// Do something with the decoded information</span>
            handler.handle(*bulletin);
        }

        <span class="comment">// Cleanup</span>
        fclose(in);
    } <span class="keywordflow">catch</span> (...) {
        fclose(in);
        <span class="keywordflow">throw</span>;
    }
}

<span class="comment">// Read all CREX messages from a file</span>
<span class="keywordtype">void</span> read_crex(<span class="keyword">const</span> Options&amp; opts, <span class="keyword">const</span> <span class="keywordtype">char</span>* fname, BulletinHandler&amp; handler)
{
    <span class="comment">// Open the input file</span>
    FILE* in = fopen(fname, <span class="stringliteral">&quot;rt&quot;</span>);
    <span class="keywordflow">if</span> (in == NULL)
        <a class="code" href="structwreport_1_1error__system.html#ae91b8d57c825a893e74599a1e2664844" title="Throw the exception, building the message printf-style.">error_system::throwf</a>(<span class="stringliteral">&quot;opening file %s&quot;</span>, fname);

    <span class="comment">// Use a generic try/catch block to ensure we always close the input file,</span>
    <span class="comment">// even in case of errors</span>
    <span class="keywordflow">try</span> {
        <span class="comment">// Create a CREX bulletin</span>
        auto_ptr&lt;Bulletin&gt; bulletin(<a class="code" href="structwreport_1_1CrexBulletin.html#ad1657d6e0c314811c7424875327c7403" title="To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...">CrexBulletin::create</a>());

        <span class="comment">// String used to hold raw data read from the input file</span>
        <span class="keywordtype">string</span> raw_data;

        <span class="comment">// (optional) offset of the start of the CREX message read, which we</span>
        <span class="comment">// pass to the decoder to have nicer error messages</span>
        <span class="keywordtype">long</span> offset;

        <span class="comment">// Read all CREX data in the input file, one message at a time. Extra</span>
        <span class="comment">// data before and after each CREX message is skipped.</span>
        <span class="comment">// fname and offset are optional and we pass them just to have nicer</span>
        <span class="comment">// error messages.</span>
        <span class="keywordflow">while</span> (<a class="code" href="structwreport_1_1CrexBulletin.html#af77f692fa59515682e4366c1a3321845" title="Read an encoded BUFR message from a stream.">CrexBulletin::read</a>(in, raw_data, fname, &amp;offset))
        {
            <span class="comment">// Decode the raw data. fname and offset are optional and we pass</span>
            <span class="comment">// them just to have nicer error messages</span>
            bulletin-&gt;decode(raw_data, fname, offset);

            <span class="comment">// Do something with the decoded information</span>
            handler.handle(*bulletin);
        }

        <span class="comment">// Cleanup</span>
        fclose(in);
    } <span class="keywordflow">catch</span> (...) {
        fclose(in);
        <span class="keywordflow">throw</span>;
    }
}


</pre></div><h2><a class="anchor" id="examples_printing"></a>
Printing bulletin contents</h2>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * output - output bulletin contents</span>
<span class="comment"> *</span>
<span class="comment"> * Copyright (C) 2011  ARPA-SIM &lt;urpsim@smr.arpa.emr.it&gt;</span>
<span class="comment"> *</span>
<span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<span class="comment"> * the Free Software Foundation; either version 2 of the License.</span>
<span class="comment"> *</span>
<span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> * GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> * You should have received a copy of the GNU General Public License</span>
<span class="comment"> * along with this program; if not, write to the Free Software</span>
<span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA</span>
<span class="comment"> *</span>
<span class="comment"> * Author: Enrico Zini &lt;enrico@enricozini.com&gt;</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &lt;<a class="code" href="bulletin_8h.html" title="Intermediate representation of parsed values, ordered according to a BUFR or CREX message template...">wreport/bulletin.h</a>&gt;</span>
<span class="preprocessor">#include &quot;options.h&quot;</span>

<span class="keyword">struct </span>PrintContents : <span class="keyword">public</span> BulletinHandler
{
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> handle(<span class="keyword">const</span> <a class="code" href="structwreport_1_1Bulletin.html" title="Storage for the decoded data of a BUFR or CREX message.">wreport::Bulletin</a>&amp; b)
    {
        b.<a class="code" href="structwreport_1_1Bulletin.html#a45d7cfad201f1d56b60a0147a7f388aa" title="Dump the contents of this bulletin.">print</a>(stderr);
    }
};

<span class="keyword">struct </span>PrintStructure : <span class="keyword">public</span> BulletinHandler
{
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> handle(<span class="keyword">const</span> <a class="code" href="structwreport_1_1Bulletin.html" title="Storage for the decoded data of a BUFR or CREX message.">wreport::Bulletin</a>&amp; b)
    {
        b.<a class="code" href="structwreport_1_1Bulletin.html#a30b72bf1cb4a00feb8c5c1c2f259725e" title="Dump the contents of this bulletin, in a more structured way.">print_structured</a>(stderr);
    }
};

<span class="keyword">struct </span>PrintDDS : <span class="keyword">public</span> BulletinHandler
{
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> handle(<span class="keyword">const</span> <a class="code" href="structwreport_1_1Bulletin.html" title="Storage for the decoded data of a BUFR or CREX message.">wreport::Bulletin</a>&amp; b)
    {
        b.<a class="code" href="structwreport_1_1Bulletin.html#a6f1d1a8e450fb6d9cafb9b35453840e7" title="Pretty-print the data descriptor section.">print_datadesc</a>(stderr);
    }
};
</pre></div><h2><a class="anchor" id="examples_config"></a>
Printing library configuration</h2>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * info - print library configuration</span>
<span class="comment"> *</span>
<span class="comment"> * Copyright (C) 2011  ARPA-SIM &lt;urpsim@smr.arpa.emr.it&gt;</span>
<span class="comment"> *</span>
<span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<span class="comment"> * the Free Software Foundation; either version 2 of the License.</span>
<span class="comment"> *</span>
<span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> * GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> * You should have received a copy of the GNU General Public License</span>
<span class="comment"> * along with this program; if not, write to the Free Software</span>
<span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA</span>
<span class="comment"> *</span>
<span class="comment"> * Author: Enrico Zini &lt;enrico@enricozini.com&gt;</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &lt;cstdlib&gt;</span>

<span class="comment">// Print information about the library</span>
<span class="keywordtype">void</span> do_info()
{
    printf(<span class="stringliteral">&quot;Tables search paths (tried in order):\n&quot;</span>);
    printf(<span class="stringliteral">&quot;Extra tables directory: %s (env var WREPORT_EXTRA_TABLES)\n&quot;</span>, getenv(<span class="stringliteral">&quot;WREPORT_EXTRA_TABLES&quot;</span>));
    printf(<span class="stringliteral">&quot;System tables directory: %s (env var WREPORT_TABLES)\n&quot;</span>, getenv(<span class="stringliteral">&quot;WREPORT_TABLES&quot;</span>));
    printf(<span class="stringliteral">&quot;Compiled-in default tables directory: %s\n&quot;</span>, TABLE_DIR);
}
</pre></div><h2><a class="anchor" id="examples_iterate"></a>
Iterating bulletin contents</h2>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * iterate - iterate bulletin contents</span>
<span class="comment"> *</span>
<span class="comment"> * Copyright (C) 2011  ARPA-SIM &lt;urpsim@smr.arpa.emr.it&gt;</span>
<span class="comment"> *</span>
<span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<span class="comment"> * the Free Software Foundation; either version 2 of the License.</span>
<span class="comment"> *</span>
<span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> * GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> * You should have received a copy of the GNU General Public License</span>
<span class="comment"> * along with this program; if not, write to the Free Software</span>
<span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA</span>
<span class="comment"> *</span>
<span class="comment"> * Author: Enrico Zini &lt;enrico@enricozini.com&gt;</span>
<span class="comment"> */</span>

<span class="keyword">struct </span>PrintVars : <span class="keyword">public</span> BulletinHandler
{
    <span class="keyword">const</span> std::vector&lt;wreport::Varcode&gt;&amp; codes;

    PrintVars(<span class="keyword">const</span> std::vector&lt;wreport::Varcode&gt;&amp; codes)
        : codes(codes) {}

    <span class="keyword">const</span> Var* find_varcode(<span class="keyword">const</span> <a class="code" href="structwreport_1_1Subset.html" title="Represent a BUFR/CREX data subset as a list of decoded variables.">wreport::Subset</a>&amp; subset, <a class="code" href="namespacewreport.html#a056668f68a3ab6bf5f2c1e9ce5205b8b" title="Holds the WMO variable code of a variable.">Varcode</a> code)
    {
        <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; subset.size(); ++i)
            <span class="keywordflow">if</span> (subset[i].code() == code)
                <span class="keywordflow">return</span> &amp;subset[i];
        <span class="keywordflow">return</span> NULL;
    }

    <span class="keyword">virtual</span> <span class="keywordtype">void</span> handle(<span class="keyword">const</span> <a class="code" href="structwreport_1_1Bulletin.html" title="Storage for the decoded data of a BUFR or CREX message.">wreport::Bulletin</a>&amp; b)
    {
        <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> sset = 0; sset &lt; b.<a class="code" href="structwreport_1_1Bulletin.html#a544f248fc72a7c75e48ed6835bb22e62" title="Decoded variables.">subsets</a>.size(); ++sset)
        {
            printf(<span class="stringliteral">&quot;%s:%zd:&quot;</span>, b.<a class="code" href="structwreport_1_1Bulletin.html#af4496066edc2d2c23a09d507630d6f6f" title="Input file name (optional).">fname</a>, sset + 1);
            <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; codes.size(); ++i)
            {
                <span class="keyword">const</span> Var* var = find_varcode(b.<a class="code" href="structwreport_1_1Bulletin.html#a544f248fc72a7c75e48ed6835bb22e62" title="Decoded variables.">subsets</a>[sset], codes[i]);
                <span class="keywordflow">if</span> (var)
                {
                    <span class="keywordtype">string</span> formatted = var-&gt;format();
                    printf(<span class="stringliteral">&quot;\t%s&quot;</span>, formatted.c_str());
                }
            }
            putc(<span class="charliteral">&#39;\n&#39;</span>, stdout);
        }
    }
};
</pre></div> </div></div>
<hr class="footer"/><address class="footer"><small>Generated on Thu Jul 28 2011 00:13:15 for libwreport by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>