This file is indexed.

/usr/share/gtk-doc/html/libgwymodule/gwymodule-tutorial-minimal.html is in libgwyddion20-doc 2.34-3ubuntu1.

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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gwyddion Module Library Reference Manual: Minimal Module</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Gwyddion Module Library Reference Manual">
<link rel="up" href="ModuleTutorial.html" title="Gwyddion Module Tutorial">
<link rel="prev" href="gwymodule-tutorial-overview.html" title="Gwyddion Module Overview">
<link rel="next" href="gwymodule-tutorial-beyond.html" title="Beyond the Minimal Module">
<meta name="generator" content="GTK-Doc V1.19 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="10"><tr valign="middle">
<td width="100%" align="left"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="ModuleTutorial.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="gwymodule-tutorial-overview.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="gwymodule-tutorial-beyond.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="gwymodule-tutorial-minimal"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">Minimal Module</span></h2>
<p>Minimal Module — 
      Dissection of a minimal <span class="application">Gwyddion</span> data
      processing module
    </p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="id-1.3.3.3"></a><h2>Module Overview</h2>
<p>
      In this section we will describe a minimal
      <span class="application">Gwyddion</span> data-processing module.
      It provides a function to invert values in a channel about zero.
      The complete module code is:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>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</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libgwyddion/gwymacros.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libprocess/datafield.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libgwymodule/gwymodule-process.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libgwydgets/gwystock.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;app/gwyapp.h&gt;</span>

<span class="preproc">#define</span><span class="normal"> </span><span class="usertype">INVERT_VALUE_RUN_MODES</span><span class="normal"> <a href="libgwymodule-gwymoduleenums.html#GWY-RUN-IMMEDIATE:CAPS">GWY_RUN_IMMEDIATE</a></span>

<span class="keyword">static</span><span class="normal"> </span><span class="usertype">gboolean</span><span class="normal"> </span><span class="function">module_register</span><span class="symbol">(</span><span class="type">void</span><span class="symbol">);</span>
<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span><span class="normal">     </span><span class="function">my_invert_value</span><span class="symbol">(</span><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">data</span><span class="symbol">,</span>
<span class="normal">                                </span><span class="usertype">GwyRunType</span><span class="normal"> run</span><span class="symbol">);</span>

<span class="keyword">static</span><span class="normal"> </span><span class="usertype">GwyModuleInfo</span><span class="normal"> module_info </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">    <a href="libgwymodule-gwymoduleloader.html#GWY-MODULE-ABI-VERSION:CAPS">GWY_MODULE_ABI_VERSION</a></span><span class="symbol">,</span>
<span class="normal">    </span><span class="symbol">&amp;</span><span class="normal">module_register</span><span class="symbol">,</span>
<span class="normal">    </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"Inverts data value."</span><span class="symbol">),</span>
<span class="normal">    </span><span class="string">"J. Random Hacker &lt;hacker.jr@example.org&gt;"</span><span class="symbol">,</span>
<span class="normal">    </span><span class="string">"1.0"</span><span class="symbol">,</span>
<span class="normal">    </span><span class="string">"Bit Rot Inc."</span><span class="symbol">,</span>
<span class="normal">    </span><span class="string">"2006"</span><span class="symbol">,</span>
<span class="cbracket">}</span><span class="symbol">;</span>

<span class="function"><a href="libgwymodule-gwymoduleloader.html#GWY-MODULE-QUERY:CAPS">GWY_MODULE_QUERY</a></span><span class="symbol">(</span><span class="normal">module_info</span><span class="symbol">)</span>

<span class="keyword">static</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">module_register</span><span class="symbol">(</span><span class="type">void</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">    </span><span class="function"><a href="libgwymodule-gwymodule-process.html#gwy-process-func-register">gwy_process_func_register</a></span><span class="symbol">(</span><span class="string">"my_invert_value"</span><span class="symbol">,</span>
<span class="normal">                              </span><span class="symbol">(</span><span class="normal"><a href="libgwymodule-gwymodule-process.html#GwyProcessFunc">GwyProcessFunc</a></span><span class="symbol">)&amp;</span><span class="normal">my_invert_value</span><span class="symbol">,</span>
<span class="normal">                              </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"/_Test/_Invert Value"</span><span class="symbol">),</span>
<span class="normal">                              <a href="../libgwydgets/libgwydgets-gwystock.html#GWY-STOCK-VALUE-INVERT:CAPS">GWY_STOCK_VALUE_INVERT</a></span><span class="symbol">,</span>
<span class="normal">                              INVERT_VALUE_RUN_MODES</span><span class="symbol">,</span>
<span class="normal">                              <a href="../libgwyapp/libgwyapp-menu.html#GWY-MENU-FLAG-DATA:CAPS">GWY_MENU_FLAG_DATA</a></span><span class="symbol">,</span>
<span class="normal">                              </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"Invert data value about origin"</span><span class="symbol">));</span>

<span class="normal">    </span><span class="keyword">return</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">;</span>
<span class="cbracket">}</span>

<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_invert_value</span><span class="symbol">(</span><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">data</span><span class="symbol">,</span>
<span class="normal">                </span><span class="usertype">GwyRunType</span><span class="normal"> run</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">    </span><span class="usertype">GwyDataField</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">dfield</span><span class="symbol">;</span>
<span class="normal">    </span><span class="usertype">GQuark</span><span class="normal"> quark</span><span class="symbol">;</span>

<span class="normal">    </span><span class="function"><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Warnings-and-Assertions.html#g-return-if-fail">g_return_if_fail</a></span><span class="symbol">(</span><span class="normal">run </span><span class="symbol">&amp;</span><span class="normal"> INVERT_VALUE_RUN_MODES</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-get-current">gwy_app_data_browser_get_current</a></span><span class="symbol">(</span><span class="normal"><a href="../libgwyapp/libgwyapp-data-browser.html#GWY-APP-DATA-FIELD:CAPS">GWY_APP_DATA_FIELD</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">dfield</span><span class="symbol">,</span>
<span class="normal">                                     <a href="../libgwyapp/libgwyapp-data-browser.html#GWY-APP-DATA-FIELD-KEY:CAPS">GWY_APP_DATA_FIELD_KEY</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">quark</span><span class="symbol">,</span>
<span class="normal">                                     </span><span class="number">0</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyapp/libgwyapp-undo.html#gwy-app-undo-qcheckpointv">gwy_app_undo_qcheckpointv</a></span><span class="symbol">(</span><span class="normal">data</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">quark</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyprocess/GwyDataField.html#gwy-data-field-multiply">gwy_data_field_multiply</a></span><span class="symbol">(</span><span class="normal">dfield</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">-</span><span class="number">1.0</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyprocess/GwyDataField.html#gwy-data-field-data-changed">gwy_data_field_data_changed</a></span><span class="symbol">(</span><span class="normal">dfield</span><span class="symbol">);</span>
<span class="cbracket">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    Though the above example is minimal it still constis of quite a bit of
    code.  We will analyse it piece-by-piece in the following paragraphs.
  </p>
</div>
<div class="refsect1">
<a name="id-1.3.3.4"></a><h2>Boilerplate</h2>
<p>
      First of all, of course, some header files.
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libgwyddion/gwymacros.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libprocess/datafield.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libgwymodule/gwymodule-process.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;libgwydgets/gwystock.h&gt;</span>
<span class="preproc">#include</span><span class="normal"> </span><span class="string">&lt;app/gwyapp.h&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      These four are essential, for a complex modules you may need additional
      headers.
      <code class="filename"><a href="../libgwyddion/libgwyddion-gwymacros.html">gwymacros.h</a></code>
      contains some basic macros,
      <code class="filename"><a href="../libgwyprocess/GwyDataField.html">datafield.h</a></code>
      declares basic <a href="../libgwyprocess/GwyDataField.html"><span class="type">GwyDataField</span></a> methods,
      <code class="filename"><a href="../libgwydgets/libgwydgets-gwystock.html">gwystock.h</a></code>
      contains stock icon definitions,
      <code class="filename">gwymodule-process.h</code>
      declares functions essential for registering the module and its data processing functions,
      and <code class="filename">gwyapp.h</code>
      includes everything necessary for interfacing with the application.
    </p>
</div>
<div class="refsect1">
<a name="id-1.3.3.5"></a><h2>Function Prototypes</h2>
<p>
      Function prototypes of our functions.
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> </span><span class="usertype">gboolean</span><span class="normal"> </span><span class="function">module_register</span><span class="symbol">(</span><span class="type">void</span><span class="symbol">);</span>
<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span><span class="normal">     </span><span class="function">my_invert_value</span><span class="symbol">(</span><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">data</span><span class="symbol">,</span>
<span class="normal">                                </span><span class="usertype">GwyRunType</span><span class="normal"> run</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      Note <span class="emphasis"><em>all</em></span> functions and global variables should be
      declared <code class="literal">static</code>, the module should export no symbol
      except <a class="link" href="libgwymodule-gwymoduleloader.html#GWY-MODULE-QUERY:CAPS" title="GWY_MODULE_QUERY()"><code class="literal">GWY_MODULE_QUERY</code></a> described below.
    </p>
<p>
      An attentive reader has probably noticed we omitted the line
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="preproc">#define</span><span class="normal"> </span><span class="usertype">INVERT_VALUE_RUN_MODES</span><span class="normal"> <a href="libgwymodule-gwymoduleenums.html#GWY-RUN-IMMEDIATE:CAPS">GWY_RUN_IMMEDIATE</a></span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      where so-called run mode is defined.  We will describe run modes in
      detail in the <a class="link" href="gwymodule-tutorial-process.html" title="Data Processing Modules">section about
      data processing modules</a>.  At this point it suffices to say
      <a class="link" href="libgwymodule-gwymoduleenums.html#GWY-RUN-IMMEDIATE:CAPS"><code class="literal">GWY_RUN_IMMEDIATE</code></a> means the function is non-interactive, executed
      immediately.
    </p>
</div>
<div class="refsect1">
<a name="id-1.3.3.6"></a><h2>The Module Info Structure</h2>
<p>
      Here the interesting part starts.  The <a class="link" href="libgwymodule-gwymoduleloader.html#GwyModuleInfo" title="struct GwyModuleInfo"><span class="type">GwyModuleInfo</span></a> structure contains
      overall information about the module, most of it is presented in
      a more-or-less human-readable form in <span class="application">Gwyddion</span>
      in the module browser.
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> </span><span class="usertype">GwyModuleInfo</span><span class="normal"> module_info </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">    <a href="libgwymodule-gwymoduleloader.html#GWY-MODULE-ABI-VERSION:CAPS">GWY_MODULE_ABI_VERSION</a></span><span class="symbol">,</span>
<span class="normal">    </span><span class="symbol">&amp;</span><span class="normal">module_register</span><span class="symbol">,</span>
<span class="normal">    </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"Inverts data value."</span><span class="symbol">),</span>
<span class="normal">    </span><span class="string">"J. Random Hacker &lt;hacker.jr@example.org&gt;"</span><span class="symbol">,</span>
<span class="normal">    </span><span class="string">"1.0"</span><span class="symbol">,</span>
<span class="normal">    </span><span class="string">"Bit Rot Inc."</span><span class="symbol">,</span>
<span class="normal">    </span><span class="string">"2006"</span><span class="symbol">,</span>
<span class="cbracket">}</span><span class="symbol">;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      The first item is always <a class="link" href="libgwymodule-gwymoduleloader.html#GWY-MODULE-ABI-VERSION:CAPS" title="GWY_MODULE_ABI_VERSION"><code class="literal">GWY_MODULE_ABI_VERSION</code></a>.  The ABI version
      compiled to the module is checked by the loader on load-time and
      modules with wrong ABI version are rejected.
    </p>
<p>
      The second item is a pointer to module registration function, by
      convention called <code class="function">module_register</code>.  It is described
      in details below.
    </p>
<p>
      The fourth item is module description.  It will appear as Description
      in the module browser.  This is a short text (up to a paragraph or two)
      informing curious humans what the module contains and/or does.
    </p>
<p>
      The next item is the module author(s).  Under normal circumstances this
      should be a name of a person (or more people).  Including a contact
      e-mail address here it's a good idea because it will appear in the
      browser as Authors, so people don't need to look to the module sources
      to find out how to contact you.
    </p>
<p>
      The next item is the module version, a free-form string that will
      appear as Version in the browser.  Though it is free-form, using a
      versioning scheme with alorithmically comparable versions is
      preferable.
    </p>
<p>
      The last but one and last items are the module copyright and date.
      The copyright field may be the same as authors field (except without
      the e-mail address), it may be an organization, or whoever owns the
      copyright.
    </p>
</div>
<div class="refsect1">
<a name="id-1.3.3.7"></a><h2>The Module Query Function</h2>
<p>
      A <span class="application">Gwyddion</span> module is loaded in two stages.
      First, it is queried, the module responds with its module info,
      <span class="application">Gwyddion</span> then performs some basic sanity
      checks (e.g., whether module ABI version matches).  If it looks all
      right, <span class="application">Gwyddion</span> continues with the
      registration of particular module features.
    </p>
<p>
      The query function should be always constructed using the
      <a class="link" href="libgwymodule-gwymoduleloader.html#GWY-MODULE-QUERY:CAPS" title="GWY_MODULE_QUERY()"><code class="literal">GWY_MODULE_QUERY</code></a> macro as follows (note there is <span class="emphasis"><em>no</em></span>
      semicolon after the right parenthesis):
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="function"><a href="libgwymodule-gwymoduleloader.html#GWY-MODULE-QUERY:CAPS">GWY_MODULE_QUERY</a></span><span class="symbol">(</span><span class="normal">module_info</span><span class="symbol">)</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      The <em class="parameter"><code>module_info</code></em> parameter is the module info
      described above.  If you change its name for any reason, change it here
      too.
    </p>
</div>
<div class="refsect1">
<a name="id-1.3.3.8"></a><h2>Module Feature Registration</h2>
<p>
      The module registration function is called in the second registration
      stage and is responsible for registering particular module functions,
      each in one turn.  Our sample module registeres only a one function,
      <code class="function">my_invert_value</code>.
    </p>
<p>
      Each function type has its own registration function, our function
      is a data processing one, so it's registered with
      <a class="link" href="libgwymodule-gwymodule-process.html#gwy-process-func-register" title="gwy_process_func_register ()"><code class="function">gwy_process_func_register()</code></a>.
      File loading and/or saving functions are registered with
      <a class="link" href="libgwymodule-gwymodule-file.html#gwy-file-func-register" title="gwy_file_func_register ()"><code class="function">gwy_file_func_register()</code></a>, etc.
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">module_register</span><span class="symbol">(</span><span class="type">void</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">    </span><span class="function"><a href="libgwymodule-gwymodule-process.html#gwy-process-func-register">gwy_process_func_register</a></span><span class="symbol">(</span><span class="string">"my_invert_value"</span><span class="symbol">,</span>
<span class="normal">                              </span><span class="symbol">(</span><span class="normal"><a href="libgwymodule-gwymodule-process.html#GwyProcessFunc">GwyProcessFunc</a></span><span class="symbol">)&amp;</span><span class="normal">my_invert_value</span><span class="symbol">,</span>
<span class="normal">                              </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"/_Test/_Invert Value"</span><span class="symbol">),</span>
<span class="normal">                              <a href="../libgwydgets/libgwydgets-gwystock.html#GWY-STOCK-VALUE-INVERT:CAPS">GWY_STOCK_VALUE_INVERT</a></span><span class="symbol">,</span>
<span class="normal">                              INVERT_VALUE_RUN_MODES</span><span class="symbol">,</span>
<span class="normal">                              <a href="../libgwyapp/libgwyapp-menu.html#GWY-MENU-FLAG-DATA:CAPS">GWY_MENU_FLAG_DATA</a></span><span class="symbol">,</span>
<span class="normal">                              </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"Invert data value about origin"</span><span class="symbol">));</span>

<span class="normal">    </span><span class="keyword">return</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">;</span>
<span class="cbracket">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
     The registration function normally returns <code class="literal">TRUE</code>.
     Returning <code class="literal">FALSE</code> means the registration failed, and
     <span class="application">Gwyddion</span> then attempts to unregister all its
     already registered functions, unload the module and proceed as if it
     didn't exist.
   </p>
</div>
<div class="refsect1">
<a name="id-1.3.3.9"></a><h2>Executive</h2>
<p>
      Now let's do some actuall data processing:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">my_invert_value</span><span class="symbol">(</span><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">data</span><span class="symbol">,</span>
<span class="normal">                </span><span class="usertype">GwyRunType</span><span class="normal"> run</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">    </span><span class="usertype">GwyDataField</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">dfield</span><span class="symbol">;</span>
<span class="normal">    </span><span class="usertype">GQuark</span><span class="normal"> quark</span><span class="symbol">;</span>

<span class="normal">    </span><span class="function"><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Warnings-and-Assertions.html#g-return-if-fail">g_return_if_fail</a></span><span class="symbol">(</span><span class="normal">run </span><span class="symbol">&amp;</span><span class="normal"> INVERT_VALUE_RUN_MODES</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-get-current">gwy_app_data_browser_get_current</a></span><span class="symbol">(</span><span class="normal"><a href="../libgwyapp/libgwyapp-data-browser.html#GWY-APP-DATA-FIELD:CAPS">GWY_APP_DATA_FIELD</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">dfield</span><span class="symbol">,</span>
<span class="normal">                                     <a href="../libgwyapp/libgwyapp-data-browser.html#GWY-APP-DATA-FIELD-KEY:CAPS">GWY_APP_DATA_FIELD_KEY</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">quark</span><span class="symbol">,</span>
<span class="normal">                                     </span><span class="number">0</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyapp/libgwyapp-undo.html#gwy-app-undo-qcheckpointv">gwy_app_undo_qcheckpointv</a></span><span class="symbol">(</span><span class="normal">data</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">quark</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyprocess/GwyDataField.html#gwy-data-field-multiply">gwy_data_field_multiply</a></span><span class="symbol">(</span><span class="normal">dfield</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">-</span><span class="number">1.0</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="../libgwyprocess/GwyDataField.html#gwy-data-field-data-changed">gwy_data_field_data_changed</a></span><span class="symbol">(</span><span class="normal">dfield</span><span class="symbol">);</span>
<span class="cbracket">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
     A few things can be seen here.  First, we check the run mode we were
     executed in.  More sofisticated modules can in principle do different
     things based on the run mode, but we just check whether it looks sane.
   </p>
<p>
     Next, we get the data field to operate on.  The notion of current object
     is maintained by the application
     <a href="../libgwyapp/libgwyapp-data-browser.html">data browser</a> therefore we us
     a data browser method (beside the current data field, we also ask for its
     key that will be useful for undo later).
   </p>
<p>
     <a href="../libgwyprocess/GwyDataField.html"><span class="type">GwyDataField</span></a> is the basic data object representing a two-dimensional
     array of values (typically a height field).  Quite a few datafield
     manipulating functions already exist in libprocess, we will use one of them
     to perform the value inversion.
   </p>
<p>
     Function <a href="../libgwyapp/libgwyapp-undo.html#gwy-app-undo-qcheckpointv"><code class="function">gwy_app_undo_qcheckpointv()</code></a> creates a point in the undo history
     we can return to later.  It is necessary to call it before we start
     modifying the data.  Its first argument is the
     <a href="../libgwyddion/GwyContainer.html">data container</a> the objects we will
     change reside in.  Then we pass the number of changed items (1) and
     an array of their indentifiers in the data container.
   </p>
<p>
     Then we finally invert the value with <a href="../libgwyprocess/GwyDataField.html#gwy-data-field-multiply"><code class="function">gwy_data_field_multiply()</code></a> and we are
     done – almost.  To notify views displaying our data field that its data
     has changed we call <a href="../libgwyprocess/GwyDataField.html#gwy-data-field-data-changed"><code class="function">gwy_data_field_data_changed()</code></a>.  This function should
     be called once on each changed data field after all processing is done.
   </p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.19</div>
</body>
</html>