/usr/share/gtk-doc/html/libgwyddion/libgwyddion-GwyExpr.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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | <!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 Library Reference Manual: GwyExpr</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Gwyddion Library Reference Manual">
<link rel="up" href="index.html" title="Gwyddion Library Reference Manual">
<link rel="prev" href="GwyFDCurvePreset.html" title="GwyFDCurvePreset">
<link rel="next" href="GwySIUnit.html" title="GwySIUnit">
<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">
<a href="#" class="shortcut">Top</a>
|
<a href="#libgwyddion-GwyExpr.description" class="shortcut">Description</a>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
<td><a accesskey="p" href="GwyFDCurvePreset.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="GwySIUnit.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="libgwyddion-GwyExpr"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="libgwyddion-GwyExpr.top_of_page"></a>GwyExpr</span></h2>
<p>GwyExpr — Arithmetic expression parser and evaluator</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="libgwyddion-GwyExpr.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include <libgwyddion/gwyddion.h>
#define <a class="link" href="libgwyddion-GwyExpr.html#GWY-EXPR-ERROR:CAPS" title="GWY_EXPR_ERROR">GWY_EXPR_ERROR</a>
enum <a class="link" href="libgwyddion-GwyExpr.html#GwyExprError" title="enum GwyExprError">GwyExprError</a>;
<a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Quarks.html#GQuark"><span class="returnvalue">GQuark</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-error-quark" title="gwy_expr_error_quark ()">gwy_expr_error_quark</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
<a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="returnvalue">GwyExpr</span></a> * <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-new" title="gwy_expr_new ()">gwy_expr_new</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
<span class="returnvalue">void</span> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-free" title="gwy_expr_free ()">gwy_expr_free</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>);
<a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-evaluate" title="gwy_expr_evaluate ()">gwy_expr_evaluate</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *text</code></em>,
<em class="parameter"><code><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> *result</code></em>,
<em class="parameter"><code><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **err</code></em>);
<a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-compile" title="gwy_expr_compile ()">gwy_expr_compile</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *text</code></em>,
<em class="parameter"><code><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **err</code></em>);
<a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-resolve-variables" title="gwy_expr_resolve_variables ()">gwy_expr_resolve_variables</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> n</code></em>,
<em class="parameter"><code>const <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> * const *names</code></em>,
<em class="parameter"><code><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> *indices</code></em>);
<a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-get-variables" title="gwy_expr_get_variables ()">gwy_expr_get_variables</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> ***names</code></em>);
<a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gdouble"><span class="returnvalue">gdouble</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-execute" title="gwy_expr_execute ()">gwy_expr_execute</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> *values</code></em>);
<span class="returnvalue">void</span> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-vector-execute" title="gwy_expr_vector_execute ()">gwy_expr_vector_execute</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> n</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> **data</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> *result</code></em>);
<a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-define-constant" title="gwy_expr_define_constant ()">gwy_expr_define_constant</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> value</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **err</code></em>);
<a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-undefine-constant" title="gwy_expr_undefine_constant ()">gwy_expr_undefine_constant</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>);
const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-get-expression" title="gwy_expr_get_expression ()">gwy_expr_get_expression</a> (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>);
<a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr">GwyExpr</a>;
</pre>
</div>
<div class="refsect1">
<a name="libgwyddion-GwyExpr.description"></a><h2>Description</h2>
<p>
<a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> is an expression evaluator, more precisely parser, compiler, and
evaluator. A new <a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> can be created with <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-new" title="gwy_expr_new ()"><code class="function">gwy_expr_new()</code></a>, then it can be
used to evaluate any number of expressions; when it's no longer needed, it
should be destroyed with <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-free" title="gwy_expr_free ()"><code class="function">gwy_expr_free()</code></a>.
</p>
<p>
Expression syntax is described in
<a class="ulink" href="http://gwyddion.net/documentation/user-guide/expression-syntax.html" target="_top">Gwyddion user guide</a>.
</p>
<p>
Simple arithmetic expressions without variables can be directly evaluated
with <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-evaluate" title="gwy_expr_evaluate ()"><code class="function">gwy_expr_evaluate()</code></a>.
</p>
<p>
Expression with variables have to be compiled first with <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-compile" title="gwy_expr_compile ()"><code class="function">gwy_expr_compile()</code></a>.
Then either <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-resolve-variables" title="gwy_expr_resolve_variables ()"><code class="function">gwy_expr_resolve_variables()</code></a> or <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-get-variables" title="gwy_expr_get_variables ()"><code class="function">gwy_expr_get_variables()</code></a> can be
used to obtain information what variables are present in the expression and
at which positions (variables are referenced by position, not name during
final evaluation because of effieiency reasons). Subsequent evaluation with
variable substitution is performed by <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-execute" title="gwy_expr_execute ()"><code class="function">gwy_expr_execute()</code></a>. It is also
possible to evaluate expression on each item of value arrays with
<a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-vector-execute" title="gwy_expr_vector_execute ()"><code class="function">gwy_expr_vector_execute()</code></a>.
</p>
<p>
One-shot evaluation of expressions without variables is easy:
</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</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="usertype">GwyExpr</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">expr</span><span class="symbol">;</span>
<span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">=</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
<span class="usertype">gdouble</span><span class="normal"> result</span><span class="symbol">;</span>
<span class="normal">expr </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="#gwy-expr-new">gwy_expr_new</a></span><span class="symbol">();</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(!</span><span class="function"><a href="#gwy-expr-evaluate">gwy_expr_evaluate</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"1+2"</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&</span><span class="normal">result</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&</span><span class="normal">err</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="comment">/* Handle compilation error */</span>
<span class="cbracket">}</span>
<span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Warnings-and-Assertions.html#g-print">g_print</a></span><span class="symbol">(</span><span class="string">"The result: %g</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> result</span><span class="symbol">);</span>
<span class="function"><a href="#gwy-expr-free">gwy_expr_free</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<p>
One-shot evaluation of expressions with known variables can be performed by
defining them as constants beforehand:
</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</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="usertype">GwyExpr</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">expr</span><span class="symbol">;</span>
<span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">=</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
<span class="usertype">gdouble</span><span class="normal"> result</span><span class="symbol">;</span>
<span class="comment">/* Create expression and define variables as constants */</span>
<span class="normal">expr </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="#gwy-expr-new">gwy_expr_new</a></span><span class="symbol">();</span>
<span class="function"><a href="#gwy-expr-define-constant">gwy_expr_define_constant</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"x"</span><span class="symbol">,</span><span class="normal"> </span><span class="number">3.0</span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="function"><a href="#gwy-expr-define-constant">gwy_expr_define_constant</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"y"</span><span class="symbol">,</span><span class="normal"> </span><span class="number">4.0</span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="comment">/* Evaluate expression */</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(!</span><span class="function"><a href="#gwy-expr-evaluate">gwy_expr_evaluate</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"hypot x,y"</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&</span><span class="normal">result</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&</span><span class="normal">err</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="comment">/* Handle compilation error */</span>
<span class="cbracket">}</span>
<span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Warnings-and-Assertions.html#g-print">g_print</a></span><span class="symbol">(</span><span class="string">"The result: %g</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> result</span><span class="symbol">);</span>
<span class="function"><a href="#gwy-expr-free">gwy_expr_free</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<p>
When the same expression is evaluated multiple times with different
variable values and the variables are again from some known set, the
<a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-resolve-variables" title="gwy_expr_resolve_variables ()"><code class="function">gwy_expr_resolve_variables()</code></a> should be used (if the repeated evaluation
happens over items of some arrays, <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-vector-execute" title="gwy_expr_vector_execute ()"><code class="function">gwy_expr_vector_execute()</code></a> is more
efficient and usually simplier to use too):
</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</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="usertype">GwyExpr</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">expr</span><span class="symbol">;</span>
<span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">=</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
<span class="keyword">const</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar">gchar</a> </span><span class="symbol">*</span><span class="keyword">const</span><span class="normal"> var_names</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span><span class="string">"lambda"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"theta"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"psi"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"d"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"k"</span><span class="normal"> </span><span class="cbracket">}</span><span class="symbol">;</span>
<span class="keyword">const</span><span class="normal"> </span><span class="usertype">gdouble</span><span class="normal"> var_values1</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span><span class="number">300.0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0.09</span><span class="symbol">,</span><span class="normal"> </span><span class="number">2.0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">52.3</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1.43</span><span class="normal"> </span><span class="cbracket">}</span><span class="symbol">;</span>
<span class="keyword">const</span><span class="normal"> </span><span class="usertype">gdouble</span><span class="normal"> var_values2</span><span class="symbol">[]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span><span class="number">400.0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0.12</span><span class="symbol">,</span><span class="normal"> </span><span class="number">2.0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">54.1</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1.44</span><span class="normal"> </span><span class="cbracket">}</span><span class="symbol">;</span>
<span class="usertype">guint</span><span class="normal"> var_positions</span><span class="symbol">[</span><span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-N-ELEMENTS:CAPS">G_N_ELEMENTS</a></span><span class="symbol">(</span><span class="normal">var_names</span><span class="symbol">)];</span>
<span class="usertype">gdouble</span><span class="normal"> vars</span><span class="symbol">[</span><span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-N-ELEMENTS:CAPS">G_N_ELEMENTS</a></span><span class="symbol">(</span><span class="normal">var_names</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> </span><span class="number">1</span><span class="symbol">];</span>
<span class="usertype">guint</span><span class="normal"> i</span><span class="symbol">;</span>
<span class="comment">/* Create expression and define constant pi */</span>
<span class="normal">expr </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="#gwy-expr-new">gwy_expr_new</a></span><span class="symbol">();</span>
<span class="function"><a href="#gwy-expr-define-constant">gwy_expr_define_constant</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"pi"</span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Numerical-Definitions.html#G-PI:CAPS">G_PI</a></span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="comment">/* Compile expression */</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(!</span><span class="function"><a href="#gwy-expr-compile">gwy_expr_compile</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"2*pi/lambda*d*sin theta"</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&</span><span class="normal">err</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="comment">/* Handle compilation error */</span>
<span class="cbracket">}</span>
<span class="comment">/* Resolve variables */</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="#gwy-expr-resolve-variables">gwy_expr_resolve_variables</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-N-ELEMENTS:CAPS">G_N_ELEMENTS</a></span><span class="symbol">(</span><span class="normal">var_names</span><span class="symbol">),</span>
<span class="normal"> var_names</span><span class="symbol">,</span><span class="normal"> var_positions</span><span class="symbol">))</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="comment">/* Expression contains unknown variables */</span>
<span class="cbracket">}</span>
<span class="comment">/* Evaluate first set */</span>
<span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol"><</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-N-ELEMENTS:CAPS">G_N_ELEMENTS</a></span><span class="symbol">(</span><span class="normal">var_names</span><span class="symbol">);</span><span class="normal"> i</span><span class="symbol">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> vars</span><span class="symbol">[</span><span class="normal">var_positions</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">]]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> var_values1</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">];</span>
<span class="cbracket">}</span>
<span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Warnings-and-Assertions.html#g-print">g_print</a></span><span class="symbol">(</span><span class="string">"First result: %g</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="#gwy-expr-execute">gwy_expr_execute</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> vars</span><span class="symbol">));</span>
<span class="comment">/* Evaluate second set */</span>
<span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol"><</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-N-ELEMENTS:CAPS">G_N_ELEMENTS</a></span><span class="symbol">(</span><span class="normal">var_names</span><span class="symbol">);</span><span class="normal"> i</span><span class="symbol">++)</span>
<span class="normal"> vars</span><span class="symbol">[</span><span class="normal">var_positions</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">]]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> var_values2</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">];</span>
<span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Warnings-and-Assertions.html#g-print">g_print</a></span><span class="symbol">(</span><span class="string">"Second result: %g</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="#gwy-expr-execute">gwy_expr_execute</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">,</span><span class="normal"> vars</span><span class="symbol">));</span>
<span class="function"><a href="#gwy-expr-free">gwy_expr_free</a></span><span class="symbol">(</span><span class="normal">expr</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<p>
The most general case is when the variables are from a large set (or
completely arbitrary). Then it is best to get the list of variables with
<a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-get-variables" title="gwy_expr_get_variables ()"><code class="function">gwy_expr_get_variables()</code></a> and supply only values of variables that
are actually present in the expression.
</p>
</div>
<div class="refsect1">
<a name="libgwyddion-GwyExpr.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GWY-EXPR-ERROR:CAPS"></a><h3>GWY_EXPR_ERROR</h3>
<pre class="programlisting">#define GWY_EXPR_ERROR gwy_expr_error_quark()
</pre>
<p>
Error domain for expression parsing and evaluation. Errors in this domain
will be from the <a class="link" href="libgwyddion-GwyExpr.html#GwyExprError" title="enum GwyExprError"><span class="type">GwyExprError</span></a> enumeration. See <a href="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information on
error domains.
</p>
</div>
<hr>
<div class="refsect2">
<a name="GwyExprError"></a><h3>enum GwyExprError</h3>
<pre class="programlisting">typedef enum {
GWY_EXPR_ERROR_CLOSING_PARENTHESIS,
GWY_EXPR_ERROR_EMPTY,
GWY_EXPR_ERROR_EMPTY_PARENTHESES,
GWY_EXPR_ERROR_GARBAGE,
GWY_EXPR_ERROR_INVALID_ARGUMENT,
GWY_EXPR_ERROR_INVALID_TOKEN,
GWY_EXPR_ERROR_MISSING_ARGUMENT,
GWY_EXPR_ERROR_NOT_EXECUTABLE,
GWY_EXPR_ERROR_OPENING_PARENTHESIS,
GWY_EXPR_ERROR_STRAY_COMMA,
GWY_EXPR_ERROR_UNRESOLVED_IDENTIFIERS,
GWY_EXPR_ERROR_CONSTANT_NAME
} GwyExprError;
</pre>
<p>
Error codes returned by expression parsing and execution.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><a name="GWY-EXPR-ERROR-CLOSING-PARENTHESIS:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_CLOSING_PARENTHESIS</code></span></p></td>
<td>A closing parenthesis is missing.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-EMPTY:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_EMPTY</code></span></p></td>
<td>Expression is empty.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-EMPTY-PARENTHESES:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_EMPTY_PARENTHESES</code></span></p></td>
<td>A parentheses pair contain nothing
inside.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-GARBAGE:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_GARBAGE</code></span></p></td>
<td>An symbol unexpectedly managed to survive.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-INVALID-ARGUMENT:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_INVALID_ARGUMENT</code></span></p></td>
<td>Function or operator argument is not a
value.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-INVALID-TOKEN:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_INVALID_TOKEN</code></span></p></td>
<td>Expression contains an invalid token.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-MISSING-ARGUMENT:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_MISSING_ARGUMENT</code></span></p></td>
<td>Function or operator arguments is missing.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-NOT-EXECUTABLE:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_NOT_EXECUTABLE</code></span></p></td>
<td>Compiled stack is not executable.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-OPENING-PARENTHESIS:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_OPENING_PARENTHESIS</code></span></p></td>
<td>An opening parenthesis is missing.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-STRAY-COMMA:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_STRAY_COMMA</code></span></p></td>
<td>A comma at the start or end of list.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-UNRESOLVED-IDENTIFIERS:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_UNRESOLVED_IDENTIFIERS</code></span></p></td>
<td>Expression contains unresolved
identifiers.
</td>
</tr>
<tr>
<td><p><a name="GWY-EXPR-ERROR-CONSTANT-NAME:CAPS"></a><span class="term"><code class="literal">GWY_EXPR_ERROR_CONSTANT_NAME</code></span></p></td>
<td>Constant name is invalid.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-error-quark"></a><h3>gwy_expr_error_quark ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Quarks.html#GQuark"><span class="returnvalue">GQuark</span></a> gwy_expr_error_quark (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Returns error domain for expression parsin and evaluation.
</p>
<p>
See and use <a class="link" href="libgwyddion-GwyExpr.html#GWY-EXPR-ERROR:CAPS" title="GWY_EXPR_ERROR"><code class="literal">GWY_EXPR_ERROR</code></a>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The error domain.</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-new"></a><h3>gwy_expr_new ()</h3>
<pre class="programlisting"><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="returnvalue">GwyExpr</span></a> * gwy_expr_new (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new expression evaluator.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>A newly created expression evaluator.</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-free"></a><h3>gwy_expr_free ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> gwy_expr_free (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>);</pre>
<p>
Frees all memory used by an expression evaluator.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-evaluate"></a><h3>gwy_expr_evaluate ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> gwy_expr_evaluate (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *text</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> *result</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **err</code></em>);</pre>
<p>
Evaulates an arithmetic expression.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>text</code></em> :</span></p></td>
<td>String containing the expression to evaluate.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>result</code></em> :</span></p></td>
<td>Location to store result to.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>err</code></em> :</span></p></td>
<td>Location to store compilation or evaluation error to, or <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
Errors from <a class="link" href="libgwyddion-GwyExpr.html#GwyExprError" title="enum GwyExprError"><span class="type">GwyExprError</span></a> domain can occur.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if evaluation failed.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-compile"></a><h3>gwy_expr_compile ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> gwy_expr_compile (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *text</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **err</code></em>);</pre>
<p>
Compiles an expression for later execution.
</p>
<p>
This function is useful for expressions with variables. For normal
arithmetic expressions it's easier to use <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-evaluate" title="gwy_expr_evaluate ()"><code class="function">gwy_expr_evaluate()</code></a>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>text</code></em> :</span></p></td>
<td>String containing the expression to compile.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>err</code></em> :</span></p></td>
<td>Location to store compilation or evaluation error to, or <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
Errors from <a class="link" href="libgwyddion-GwyExpr.html#GwyExprError" title="enum GwyExprError"><span class="type">GwyExprError</span></a> domain can occur.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if compilation failed.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-resolve-variables"></a><h3>gwy_expr_resolve_variables ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a> gwy_expr_resolve_variables (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> n</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> * const *names</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> *indices</code></em>);</pre>
<p>
Finds positions of variables in an expression.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n</code></em> :</span></p></td>
<td>The length of <em class="parameter"><code>names</code></em> and <em class="parameter"><code>indices</code></em> arrays.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>names</code></em> :</span></p></td>
<td>List of variable names to get positions of.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>indices</code></em> :</span></p></td>
<td>Array to store variable positions to. The positions are the same
as in <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-execute" title="gwy_expr_execute ()"><code class="function">gwy_expr_execute()</code></a>. Variables not present in the expression
are assigned (reserved) position 0. This allows to safely
substitute values of all variables before execution wthout caring
which variables are actually present.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The number of remaining, unresolved variables in <em class="parameter"><code>expr</code></em>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-get-variables"></a><h3>gwy_expr_get_variables ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a> gwy_expr_get_variables (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> ***names</code></em>);</pre>
<p>
Get the number, names, and indices of unresolved identifiers in <em class="parameter"><code>expr</code></em>.
</p>
<p>
It is an error to call this function after an unsuccessful compilation.
</p>
<p>
If you only care about variables from a prefedined set, that is if any
unknown variable is an error, it's easier to use
<a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-resolve-variables" title="gwy_expr_resolve_variables ()"><code class="function">gwy_expr_resolve_variables()</code></a>.
</p>
<p>
The position of each variable in <em class="parameter"><code>names</code></em> corresponds to the position of its
value in <em class="parameter"><code>values</code></em> array in <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-execute" title="gwy_expr_execute ()"><code class="function">gwy_expr_execute()</code></a> call. Namely, the first item
in the array is always reserved and do not correspond to any variable.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>names</code></em> :</span></p></td>
<td>Location to store pointer to array of variable names to (may be
<a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to get just number of variables). The string array returned
in this argument in owned by <em class="parameter"><code>expr</code></em> and is valid only until next
<a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-compile" title="gwy_expr_compile ()"><code class="function">gwy_expr_compile()</code></a>, <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-evaluate" title="gwy_expr_evaluate ()"><code class="function">gwy_expr_evaluate()</code></a>, or <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-free" title="gwy_expr_free ()"><code class="function">gwy_expr_free()</code></a>
call.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The length of array stored to <em class="parameter"><code>names</code></em>. This is the number of
variables plus one (for the first reserved item).
On failure, 0 is returned.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-execute"></a><h3>gwy_expr_execute ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="returnvalue">gdouble</span></a> gwy_expr_execute (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> *values</code></em>);</pre>
<p>
Executes a compiled expression with variables, substituting given values.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>values</code></em> :</span></p></td>
<td>Array with variable values. Its zeroth item is always unused.
Variable list can be obtained by <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-get-variables" title="gwy_expr_get_variables ()"><code class="function">gwy_expr_get_variables()</code></a>.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The result.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-vector-execute"></a><h3>gwy_expr_vector_execute ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> gwy_expr_vector_execute (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> n</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> **data</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> *result</code></em>);</pre>
<p>
Executes a compiled expression on each item of data arrays.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n</code></em> :</span></p></td>
<td>The lenght of <em class="parameter"><code>result</code></em> and of <em class="parameter"><code>data</code></em> member arrays, that is vector length.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
<td>An array of arrays of length <em class="parameter"><code>n</code></em>. The arrays correspond to expression
variables in <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-execute" title="gwy_expr_execute ()"><code class="function">gwy_expr_execute()</code></a>. Zeroth array can be <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>result</code></em> :</span></p></td>
<td>An array of length <em class="parameter"><code>n</code></em> to store computation results to. It may be
one of those in <em class="parameter"><code>data</code></em>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-define-constant"></a><h3>gwy_expr_define_constant ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> gwy_expr_define_constant (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> value</code></em>,
<em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **err</code></em>);</pre>
<p>
Defines a symbolic constant.
</p>
<p>
Note the definition does not affect already compiled expression, you have
to recompile it (and eventually re-resolve variables).
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>name</code></em> :</span></p></td>
<td>Name of constant to define.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>value</code></em> :</span></p></td>
<td>Constant numeric value.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>err</code></em> :</span></p></td>
<td>Location to store error to, or <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
Only <a class="link" href="libgwyddion-GwyExpr.html#GWY-EXPR-ERROR-CONSTANT-NAME:CAPS"><code class="literal">GWY_EXPR_ERROR_CONSTANT_NAME</code></a> error from <a class="link" href="libgwyddion-GwyExpr.html#GwyExprError" title="enum GwyExprError"><span class="type">GwyExprError</span></a> domain can
occur.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if definition failed.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-undefine-constant"></a><h3>gwy_expr_undefine_constant ()</h3>
<pre class="programlisting"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> gwy_expr_undefine_constant (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>,
<em class="parameter"><code>const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>);</pre>
<p>
Undefines a symbolic constant.
</p>
<p>
Note the definition removal does not affect already compiled expression,
you have to recompile it (and eventually re-resolve variables).
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>name</code></em> :</span></p></td>
<td>Name of constant to undefine.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if there was such a constant and was removed, <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>
otherwise.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gwy-expr-get-expression"></a><h3>gwy_expr_get_expression ()</h3>
<pre class="programlisting">const <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * gwy_expr_get_expression (<em class="parameter"><code><a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> *expr</code></em>);</pre>
<p>
Gets the expression string.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
<td>An expression evaluator.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The last string passed to <a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-evaluate" title="gwy_expr_evaluate ()"><code class="function">gwy_expr_evaluate()</code></a> or
<a class="link" href="libgwyddion-GwyExpr.html#gwy-expr-compile" title="gwy_expr_compile ()"><code class="function">gwy_expr_compile()</code></a>. It is owned by <em class="parameter"><code>expr</code></em> and must not be modified
or freed.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="GwyExpr"></a><h3>GwyExpr</h3>
<pre class="programlisting">typedef struct _GwyExpr GwyExpr;</pre>
<p>
<a class="link" href="libgwyddion-GwyExpr.html#GwyExpr" title="GwyExpr"><span class="type">GwyExpr</span></a> is an opaque data structure and should be only manipulated with the
functions below.
</p>
</div>
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.19</div>
</body>
</html>
|