This file is indexed.

/usr/share/fityk/html/script.html is in fityk 1.3.0-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
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
<!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/html; charset=utf-8" />
    
    <title>Scripts &#8212; Fityk 1.3.0 manual</title>
    
    <link rel="stylesheet" href="_static/fityk.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.3.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/fityk.ico"/>
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Fityk 1.3.0 manual" href="fityk-manual.html" />
    <link rel="next" title="All the Rest" href="ref.html" />
    <link rel="prev" title="Curve Fitting" href="fit.html" />
 


  </head>
  <body role="document">
<div style="background-color: white; text-align: center; padding: 10px 10px 10px 10px">
 <a href="http://fityk.nieto.pl/"><img src="_static/fityk-banner.png" alt="" /></a>
</div>

      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h3><a href="fityk-manual.html">Table Of Contents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="intro.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="getstarted.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="lang.html">Mini-Language</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="model.html">Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="fit.html">Curve Fitting</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Scripts</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#working-with-scripts">Working with Scripts</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fityk-library-api">Fityk library API</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#input-output">Input / output</a></li>
<li class="toctree-l3"><a class="reference internal" href="#settings">Settings</a></li>
<li class="toctree-l3"><a class="reference internal" href="#data">Data</a></li>
<li class="toctree-l3"><a class="reference internal" href="#general-info">General Info</a></li>
<li class="toctree-l3"><a class="reference internal" href="#model-info">Model info</a></li>
<li class="toctree-l3"><a class="reference internal" href="#fit-statistics">Fit statistics</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#examples">Examples</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="ref.html">All the Rest</a></li>
</ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/script.txt"
           rel="nofollow">Show Source</a></li>
    <li><a href="https://github.com/wojdyr/fityk/blob/master/doc/script.rst"
           rel="nofollow">Edit on GitHub</a></li>
  </ul>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="scripts">
<h1>Scripts<a class="headerlink" href="#scripts" title="Permalink to this headline"></a></h1>
<div class="section" id="working-with-scripts">
<h2>Working with Scripts<a class="headerlink" href="#working-with-scripts" title="Permalink to this headline"></a></h2>
<p>Scripts can be executed using the command:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span>exec filename
</pre></div>
</div>
<p>The file can be either a fityk script (usually with extension <code class="docutils literal"><span class="pre">fit</span></code>),
or a Lua script (extension <code class="docutils literal"><span class="pre">lua</span></code>).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Fityk can save its state to a script (<code class="docutils literal"><span class="pre">info</span> <span class="pre">state</span> <span class="pre">&gt;</span> <span class="pre">file.fit</span></code>).
It can also save all commands executed (directly or via GUI) in the session
to a script (<code class="docutils literal"><span class="pre">info</span> <span class="pre">history</span> <span class="pre">&gt;</span> <span class="pre">file.fit</span></code>).</p>
</div>
<p>Since a Fityk script with all the data inside can be a large file,
the files may be stored compressed and it is possible to directly read
gzip-compressed fityk script (<code class="docutils literal"><span class="pre">.fit.gz</span></code>).</p>
<p>Embedded Lua interpreter can execute any program in Lua 5.1.
One-liners can be run with command <code class="docutils literal"><span class="pre">lua</span></code>:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>lua print(_VERSION)
Lua 5.1
<span class="gp">=-&gt; </span>lua print(os.date(&quot;Today is %A.&quot;))
Today is Thursday.
<span class="gp">=-&gt; </span>lua for n,f in F:all_functions() do print(n, f, f:get_template_name()) end
0       %_1     Constant
1       %_2     Cycle
</pre></div>
</div>
<p>(The Lua <code class="docutils literal"><span class="pre">print</span></code> function in fityk is redefined to show the output
in the GUI instead of writing to <code class="docutils literal"><span class="pre">stdout</span></code>).</p>
<p>Like in the Lua interpreter, <code class="docutils literal"><span class="pre">=</span></code> at the beginning of line can be used
to save some typing:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>= os.date(&quot;Today is %A.&quot;)
Today is Thursday.
</pre></div>
</div>
<p>Similarly, <code class="docutils literal"><span class="pre">exec=</span></code> also interprets the rest of line
as Lua expressions, but this time the resulting string is executed
as a fityk command:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>= string.format(&quot;fit @%d&quot;, math.random(0,5))
fit 17
<span class="gp">=-&gt; </span>exec= string.format(&quot;fit @%d&quot;, math.random(0,5))
<span class="c"># fitting random dataset (useless example)</span>
</pre></div>
</div>
<p>The Lua interpreter in Fityk has defined global object <code class="docutils literal"><span class="pre">F</span></code> which
enables interaction with the program:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>= F:get_info(&quot;version&quot;)
Fityk 1.2.1
</pre></div>
</div>
<p>Now the first example that can be useful. For each dataset write output
of the <code class="docutils literal"><span class="pre">info</span> <span class="pre">peaks</span></code> command to a file named after the data file,
with appended &#8221;.out&#8221;:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>@*: lua F:execute(&quot;info peaks &gt;<span class="s1">&#39;%s.out&#39;</span>&quot; % F:get_info(&quot;filename&quot;))
</pre></div>
</div>
<p>This and other methods of <code class="docutils literal"><span class="pre">F</span></code> are documented in the next section.</p>
<p>Here is an example of Lua-Fityk interactions:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="c1">-- load data from files file01.dat, file02.dat, ... file13.dat</span>
<span class="k">for</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="mi">13</span> <span class="k">do</span>
    <span class="n">F</span><span class="p">:</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">@+ &lt; file%02d.dat:0:1::&quot;</span> <span class="o">%</span> <span class="n">i</span><span class="p">)</span>
<span class="k">end</span>

<span class="c1">-- print some statistics about the loaded data</span>
<span class="n">n</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">get_dataset_count</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">n</span> <span class="o">..</span> <span class="s2">&quot;</span><span class="s"> datasets loaded.&quot;</span><span class="p">)</span>

<span class="n">total_max_y</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="o">-</span><span class="mi">1</span> <span class="k">do</span>
    <span class="n">max_y</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">calculate_expr</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">max(y)&quot;</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">max_y</span> <span class="o">&gt;</span> <span class="n">total_max_y</span> <span class="k">then</span>
        <span class="n">total_max_y</span> <span class="o">=</span> <span class="n">max_y</span>
    <span class="k">end</span>
<span class="k">end</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">The largest y: &quot;</span> <span class="o">..</span> <span class="n">total_max_y</span><span class="p">)</span>
</pre></div>
</div>
<p>If a fityk command executed from Lua script fails, the whole script is
stopped, unless you catch the error:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="c1">-- wrap F:execute() in pcall to handle possible errors</span>
<span class="n">status</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="nb">pcall</span><span class="p">(</span><span class="k">function</span><span class="p">()</span> <span class="n">F</span><span class="p">:</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">fit&quot;</span><span class="p">)</span> <span class="k">end</span><span class="p">)</span>
<span class="k">if</span> <span class="n">status</span> <span class="o">==</span> <span class="kc">false</span> <span class="k">then</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">Error: &quot;</span> <span class="o">..</span> <span class="n">err</span><span class="p">)</span>
<span class="k">end</span>
</pre></div>
</div>
<p>The Lua interpreter was added in ver. 1.0.3. If you have any questions
about it, feel free to ask.</p>
<p>Older, but still supported way to automate Fityk is to prepare
a stand-alone program that writes a valid fityk script to the standard output.
To run such program and execute the output use command:</p>
<div class="highlight-fityk"><div class="highlight"><pre><span></span>exec ! program [args...]
</pre></div>
</div>
</div>
<div class="section" id="fityk-library-api">
<h2>Fityk library API<a class="headerlink" href="#fityk-library-api" title="Permalink to this headline"></a></h2>
<p>Fityk comes with embedded Lua interpreter and this language
is used in this section. The API for other supported languages is similar.
Lua communicates with Fityk using object <code class="docutils literal"><span class="pre">F</span></code> of type <code class="docutils literal"><span class="pre">Fityk</span></code>.
To call the methods listed below use <code class="docutils literal"><span class="pre">F:method()</span></code>, for example
<code class="docutils literal"><span class="pre">F:get_dof()</span></code> (not <code class="docutils literal"><span class="pre">Fityk.get_dof()</span></code>).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Other supported languages include C++, C, Python, Perl, Ruby and Java.
Except for C, all APIs are similar.</p>
<p>Unlike in built-in Lua, in other cases it is necessary to create
an instance of the Fityk class first. Then you use this object
in the same way as <code class="docutils literal"><span class="pre">F</span></code> is used below.</p>
<p>The <a class="reference external" href="https://github.com/wojdyr/fityk/blob/master/src/fityk.h">fityk.h</a> header file is the best reference.
Additionally, C++ and Python have access to functions from
the <a class="reference external" href="https://github.com/wojdyr/fityk/blob/master/src/ui_api.h">ui_api.h</a> header. These functions are used in command line
versions of fityk (<code class="docutils literal"><span class="pre">cfityk</span></code> or its equivalent &#8211; <code class="docutils literal"><span class="pre">samples/cfityk.py</span></code>).</p>
<p class="last">Examples of scripts in all the listed languages and in the <a class="reference external" href="https://github.com/wojdyr/fityk/blob/master/samples/">samples</a>
directory.</p>
</div>
<p>Here is the most general function:</p>
<dl class="method">
<dt id="Fityk.execute">
<code class="descclassname">Fityk.</code><code class="descname">execute</code><span class="sig-paren">(</span><em>cmd</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.execute" title="Permalink to this definition"></a></dt>
<dd><p>Executes a fityk command. Example: <code class="docutils literal"><span class="pre">F:execute(&quot;fit&quot;)</span></code>.</p>
</dd></dl>

<p>The <code class="docutils literal"><span class="pre">%</span></code> operator for the string type is pre-set to support Python-like
formatting:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="o">=</span> <span class="s2">&quot;</span><span class="s">%d pigs&quot;</span> <span class="o">%</span> <span class="mi">3</span>
<span class="o">=</span> <span class="s2">&quot;</span><span class="s">%d %s&quot;</span> <span class="o">%</span> <span class="p">{</span><span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">pigs&quot;</span><span class="p">}</span>
</pre></div>
</div>
<div class="section" id="input-output">
<h3>Input / output<a class="headerlink" href="#input-output" title="Permalink to this headline"></a></h3>
<dl class="method">
<dt id="Fityk.input">
<code class="descclassname">Fityk.</code><code class="descname">input</code><span class="sig-paren">(</span><em>prompt</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.input" title="Permalink to this definition"></a></dt>
<dd><p>Query user. In the CLI user is asked for input in the command line,
and in the GUI in a pop-up box. As a special case,
if the prompt contains string &#8220;[y/n]&#8221; the GUI shows Yes/No buttons
instead of text entry.</p>
<p>Example: TODO</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.out">
<code class="descclassname">Fityk.</code><code class="descname">out</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.out" title="Permalink to this definition"></a></dt>
<dd><p>Print string in the output area. The <code class="docutils literal"><span class="pre">print()</span></code> function in built-in Lua
is redefined to do the same.</p>
</dd></dl>

</div>
<div class="section" id="settings">
<h3>Settings<a class="headerlink" href="#settings" title="Permalink to this headline"></a></h3>
<dl class="method">
<dt id="Fityk.set_option_as_string">
<code class="descclassname">Fityk.</code><code class="descname">set_option_as_string</code><span class="sig-paren">(</span><em>opt</em>, <em>val</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.set_option_as_string" title="Permalink to this definition"></a></dt>
<dd><p>Set option <em>opt</em> to value <em>val</em>.
Equivalent of fityk command <code class="docutils literal"><span class="pre">set</span> <span class="pre">opt=val</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.set_option_as_number">
<code class="descclassname">Fityk.</code><code class="descname">set_option_as_number</code><span class="sig-paren">(</span><em>opt</em>, <em>val</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.set_option_as_number" title="Permalink to this definition"></a></dt>
<dd><p>Set option <em>opt</em> to numeric value <em>val</em>.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_option_as_string">
<code class="descclassname">Fityk.</code><code class="descname">get_option_as_string</code><span class="sig-paren">(</span><em>opt</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_option_as_string" title="Permalink to this definition"></a></dt>
<dd><p>Returns value of <em>opt</em> (string).</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_option_as_number">
<code class="descclassname">Fityk.</code><code class="descname">get_option_as_number</code><span class="sig-paren">(</span><em>opt</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_option_as_number" title="Permalink to this definition"></a></dt>
<dd><p>Returns value of <em>opt</em> (real number).</p>
</dd></dl>

</div>
<div class="section" id="data">
<h3>Data<a class="headerlink" href="#data" title="Permalink to this headline"></a></h3>
<dl class="method">
<dt id="Fityk.load">
<code class="descclassname">Fityk.</code><code class="descname">load</code><span class="sig-paren">(</span><em>spec</em><span class="optional">[</span>, <em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.load" title="Permalink to this definition"></a></dt>
<dd><p>Load data to &#64;*d* slot. The first argument is either a string with path
or LoadSpec struct that apart from the <code class="docutils literal"><span class="pre">path</span></code> has also the following
optional members: <code class="docutils literal"><span class="pre">x_col</span></code>, <code class="docutils literal"><span class="pre">y_col</span></code>, <code class="docutils literal"><span class="pre">sig_col</span></code>, <code class="docutils literal"><span class="pre">blocks</span></code>,
<code class="docutils literal"><span class="pre">format</span></code>, <code class="docutils literal"><span class="pre">options</span></code>. The meaning of these parameters is the same
as described in <a class="reference internal" href="data.html#dataload"><span class="std std-ref">Loading Data</span></a>.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.load_data">
<code class="descclassname">Fityk.</code><code class="descname">load_data</code><span class="sig-paren">(</span><em>d</em>, <em>xx</em>, <em>yy</em>, <em>sigmas</em><span class="optional">[</span>, <em>title</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.load_data" title="Permalink to this definition"></a></dt>
<dd><p>Load data to &#64;*d* slot. <em>xx</em> and <em>yy</em> must be numeric arrays
of the same size, <em>sigmas</em> must either be empty or have the same size.
<em>title</em> is an optional data title (string).</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.add_point">
<code class="descclassname">Fityk.</code><code class="descname">add_point</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>sigma</em><span class="optional">[</span>, <em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.add_point" title="Permalink to this definition"></a></dt>
<dd><p>Add one data point ((<em>x</em>, <em>y</em>) with std. dev. set to <em>sigma</em>)
to an existing dataset <em>d</em>.
If <em>d</em> is not specified, the default dataset is used.</p>
<p>Example: <code class="docutils literal"><span class="pre">F:add_point(30,</span> <span class="pre">7.5,</span> <span class="pre">1)</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_dataset_count">
<code class="descclassname">Fityk.</code><code class="descname">get_dataset_count</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_dataset_count" title="Permalink to this definition"></a></dt>
<dd><p>Returns number of datasets (n &gt;= 1).</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_default_dataset">
<code class="descclassname">Fityk.</code><code class="descname">get_default_dataset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_default_dataset" title="Permalink to this definition"></a></dt>
<dd><p>Returns default dataset. Default dataset is set by the &#8220;use &#64;n&#8221; command.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_data">
<code class="descclassname">Fityk.</code><code class="descname">get_data</code><span class="sig-paren">(</span><span class="optional">[</span><em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_data" title="Permalink to this definition"></a></dt>
<dd><p>Returns points for dataset <em>d</em>.</p>
<ul class="simple">
<li>in C++ &#8211; returns vector&lt;Point&gt;</li>
<li>in Lua &#8211; userdata with array-like methods, indexed from 0.</li>
</ul>
<p>Each point has 4 properties:
<code class="docutils literal"><span class="pre">x</span></code>, <code class="docutils literal"><span class="pre">y</span></code>, <code class="docutils literal"><span class="pre">sigma</span></code> (real numbers) and <code class="docutils literal"><span class="pre">is_active</span></code> (bool).</p>
<p>Example:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">points</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">get_data</span><span class="p">()</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="o">#</span><span class="n">points</span><span class="o">-</span><span class="mi">1</span> <span class="k">do</span>
    <span class="n">p</span> <span class="o">=</span> <span class="n">points</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    <span class="k">if</span> <span class="n">p</span><span class="p">.</span><span class="n">is_active</span> <span class="k">then</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">p</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="p">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="p">.</span><span class="n">sigma</span><span class="p">)</span>
    <span class="k">end</span>
<span class="k">end</span>

<span class="mi">1</span>       <span class="mf">4.24</span>    <span class="mf">1.06</span>    <span class="mi">1</span>
<span class="mi">2</span>       <span class="mf">6.73</span>    <span class="mf">1.39</span>    <span class="mi">1</span>
<span class="mi">3</span>       <span class="mf">8.8</span>     <span class="mf">1.61</span>    <span class="mi">1</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="general-info">
<h3>General Info<a class="headerlink" href="#general-info" title="Permalink to this headline"></a></h3>
<dl class="method">
<dt id="Fityk.get_info">
<code class="descclassname">Fityk.</code><code class="descname">get_info</code><span class="sig-paren">(</span><em>s</em><span class="optional">[</span>, <em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_info" title="Permalink to this definition"></a></dt>
<dd><p>Returns output of the fityk <code class="docutils literal"><span class="pre">info</span></code> command as a string.
If <em>d</em> is not specified, the default dataset is used (the dataset
is relevant for few arguments of the <code class="docutils literal"><span class="pre">info</span></code> command).</p>
<p>Example: <code class="docutils literal"><span class="pre">F:get_info(&quot;history&quot;)</span></code> &#8211; returns a multiline string
containing all fityk commands issued in this session.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.calculate_expr">
<code class="descclassname">Fityk.</code><code class="descname">calculate_expr</code><span class="sig-paren">(</span><em>s</em><span class="optional">[</span>, <em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.calculate_expr" title="Permalink to this definition"></a></dt>
<dd><p>Returns output of the fityk <code class="docutils literal"><span class="pre">print</span></code> command as a number.
If <em>d</em> is not specified, the default dataset is used.</p>
<p>Example: <code class="docutils literal"><span class="pre">F:calculate_expr(&quot;argmax(y)&quot;,</span> <span class="pre">0)</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_view_boundary">
<code class="descclassname">Fityk.</code><code class="descname">get_view_boundary</code><span class="sig-paren">(</span><em>side</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_view_boundary" title="Permalink to this definition"></a></dt>
<dd><p>Get coordinates of the plotted rectangle,
which is set by the <code class="docutils literal"><span class="pre">plot</span></code> command.
Return numeric value corresponding to given <em>side</em>, which should be
a letter <code class="docutils literal"><span class="pre">L</span></code>(eft), <code class="docutils literal"><span class="pre">R</span></code>(ight), <code class="docutils literal"><span class="pre">T</span></code>(op) or <code class="docutils literal"><span class="pre">B</span></code>(ottom).</p>
</dd></dl>

</div>
<div class="section" id="model-info">
<h3>Model info<a class="headerlink" href="#model-info" title="Permalink to this headline"></a></h3>
<dl class="method">
<dt id="Fityk.get_parameter_count">
<code class="descclassname">Fityk.</code><code class="descname">get_parameter_count</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_parameter_count" title="Permalink to this definition"></a></dt>
<dd><p>Returns number of simple-variables (parameters that can be fitted)</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.all_parameters">
<code class="descclassname">Fityk.</code><code class="descname">all_parameters</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.all_parameters" title="Permalink to this definition"></a></dt>
<dd><p>Returns array of simple-variables.</p>
<ul class="simple">
<li>in C++ &#8211; vector&lt;double&gt;</li>
<li>in Lua &#8211; userdata with array-like methods, indexed from 0.</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="Fityk.all_variables">
<code class="descclassname">Fityk.</code><code class="descname">all_variables</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.all_variables" title="Permalink to this definition"></a></dt>
<dd><blockquote>
<div><p>Returns array of all defined variables.</p>
<ul class="simple">
<li>in C++ &#8211; vector&lt;Var*&gt;</li>
<li>in Lua &#8211; userdata with array-like methods, indexed from 0.</li>
</ul>
</div></blockquote>
<p>Example:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">variables</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">all_variables</span><span class="p">()</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="o">#</span><span class="n">variables</span><span class="o">-</span><span class="mi">1</span> <span class="k">do</span>
    <span class="n">v</span> <span class="o">=</span> <span class="n">variables</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">v</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">v</span><span class="p">:</span><span class="n">value</span><span class="p">(),</span> <span class="n">v</span><span class="p">.</span><span class="n">domain</span><span class="p">.</span><span class="n">lo</span><span class="p">,</span> <span class="n">v</span><span class="p">.</span><span class="n">domain</span><span class="p">.</span><span class="n">hi</span><span class="p">,</span>
          <span class="n">v</span><span class="p">:</span><span class="n">gpos</span><span class="p">(),</span> <span class="n">v</span><span class="p">:</span><span class="n">is_simple</span><span class="p">())</span>
<span class="k">end</span>
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">Var.is_simple()</span></code> returns true for simple-variables.</p>
<p><code class="docutils literal"><span class="pre">Var.gpos()</span></code> returns position of the variable in the global array
of parameters (Fityk.all_parameters()), or -1 for compound variables.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_variable">
<code class="descclassname">Fityk.</code><code class="descname">get_variable</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_variable" title="Permalink to this definition"></a></dt>
<dd><p>Returns variable <em>$name</em>.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.all_functions">
<code class="descclassname">Fityk.</code><code class="descname">all_functions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.all_functions" title="Permalink to this definition"></a></dt>
<dd><p>Returns array of functions.</p>
<ul class="simple">
<li>in C++ &#8211; vector&lt;Func*&gt;</li>
<li>in Lua &#8211; userdata with array-like methods, indexed from 0.</li>
</ul>
<p>Example:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">f</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">all_functions</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="c1">-- first functions</span>
<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">f</span><span class="p">:</span><span class="n">get_template_name</span><span class="p">())</span>          <span class="c1">-- _1        Gaussian</span>
<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">:</span><span class="n">get_param</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">f</span><span class="p">:</span><span class="n">get_param</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>         <span class="c1">-- height  center</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">$&quot;</span> <span class="o">..</span> <span class="n">f</span><span class="p">:</span><span class="n">var_name</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">height&quot;</span><span class="p">))</span>            <span class="c1">-- $_4</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">center:&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">:</span><span class="n">get_param_value</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">center&quot;</span><span class="p">))</span> <span class="c1">-- center: 24.72235945525</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">f(25)=&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">:</span><span class="n">value_at</span><span class="p">(</span><span class="mi">25</span><span class="p">))</span>               <span class="c1">-- f(25)=  4386.95533969</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_function">
<code class="descclassname">Fityk.</code><code class="descname">get_function</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_function" title="Permalink to this definition"></a></dt>
<dd><p>Return the function with given <em>name</em>, or NULL if there is no such
function.</p>
<p>Example:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">f</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">get_function</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">_1&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">f(25)=&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">:</span><span class="n">value_at</span><span class="p">(</span><span class="mi">25</span><span class="p">))</span>               <span class="c1">-- f(25)=  4386.95533969</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_components">
<code class="descclassname">Fityk.</code><code class="descname">get_components</code><span class="sig-paren">(</span><em>d</em><span class="optional">[</span>, <em>fz</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_components" title="Permalink to this definition"></a></dt>
<dd><p>Returns %functions used in dataset <em>d</em>. If <em>fz</em> is <code class="docutils literal"><span class="pre">Z</span></code>, returns
zero-shift functions.</p>
<p>Example:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">func</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">get_components</span><span class="p">(</span><span class="mi">1</span><span class="p">)[</span><span class="mi">3</span><span class="p">]</span> <span class="c1">-- get 4th (index 3) function in @1</span>
<span class="nb">print</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>                   <span class="c1">-- &lt;Func %_6&gt;</span>
<span class="n">vname</span> <span class="o">=</span> <span class="n">func</span><span class="p">:</span><span class="n">var_name</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">hwhm&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">vname</span><span class="p">)</span>                  <span class="c1">-- _21</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">get_variable</span><span class="p">(</span><span class="n">vname</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">v</span><span class="p">:</span><span class="n">value</span><span class="p">())</span>           <span class="c1">-- &lt;Var $_21&gt;       0.1406587</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_model_value">
<code class="descclassname">Fityk.</code><code class="descname">get_model_value</code><span class="sig-paren">(</span><em>x</em><span class="optional">[</span>, <em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_model_value" title="Permalink to this definition"></a></dt>
<dd><p>Returns the value of the model for dataset <code class="docutils literal"><span class="pre">&#64;</span></code><em>d</em> at <em>x</em>.</p>
</dd></dl>

</div>
<div class="section" id="fit-statistics">
<h3>Fit statistics<a class="headerlink" href="#fit-statistics" title="Permalink to this headline"></a></h3>
<dl class="method">
<dt id="Fityk.get_wssr">
<code class="descclassname">Fityk.</code><code class="descname">get_wssr</code><span class="sig-paren">(</span><span class="optional">[</span><em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_wssr" title="Permalink to this definition"></a></dt>
<dd><p>Returns WSSR (weighted sum of squared residuals).</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_ssr">
<code class="descclassname">Fityk.</code><code class="descname">get_ssr</code><span class="sig-paren">(</span><span class="optional">[</span><em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_ssr" title="Permalink to this definition"></a></dt>
<dd><p>Returns SSR (sum of squared residuals).</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_rsquared">
<code class="descclassname">Fityk.</code><code class="descname">get_rsquared</code><span class="sig-paren">(</span><span class="optional">[</span><em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_rsquared" title="Permalink to this definition"></a></dt>
<dd><p>Returns R-squared.</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_dof">
<code class="descclassname">Fityk.</code><code class="descname">get_dof</code><span class="sig-paren">(</span><span class="optional">[</span><em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_dof" title="Permalink to this definition"></a></dt>
<dd><p>Returns the number of degrees of freedom (#points - #parameters).</p>
</dd></dl>

<dl class="method">
<dt id="Fityk.get_covariance_matrix">
<code class="descclassname">Fityk.</code><code class="descname">get_covariance_matrix</code><span class="sig-paren">(</span><span class="optional">[</span><em>d</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Fityk.get_covariance_matrix" title="Permalink to this definition"></a></dt>
<dd><p>Returns covariance matrix.</p>
</dd></dl>

</div>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<p>List peak center of series of data:</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="c1">-- file list-max.lua</span>
<span class="n">prev_x</span> <span class="o">=</span> <span class="kc">nil</span>
<span class="k">for</span> <span class="n">n</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">F</span><span class="p">:</span><span class="n">get_dataset_count</span><span class="p">()</span><span class="o">-</span><span class="mi">1</span> <span class="k">do</span>
    <span class="kd">local</span> <span class="n">path</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">get_info</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">filename&quot;</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
    <span class="kd">local</span> <span class="n">filename</span> <span class="o">=</span> <span class="nb">string.match</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">[^/</span><span class="se">\\</span><span class="s">]+$&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">&quot;</span><span class="s">&quot;</span>
    <span class="c1">-- local x = F:calculate_expr(&quot;argmax(y)&quot;, n)</span>
    <span class="kd">local</span> <span class="n">x</span> <span class="o">=</span> <span class="n">F</span><span class="p">:</span><span class="n">calculate_expr</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">F[0].center&quot;</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
    <span class="n">s</span> <span class="o">=</span> <span class="nb">string.format</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">%s: max at x=%.4f&quot;</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">prev_x</span> <span class="o">~=</span> <span class="kc">nil</span> <span class="k">then</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">s</span> <span class="o">..</span> <span class="nb">string.format</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">  (%+.4f)&quot;</span><span class="p">,</span> <span class="n">x</span><span class="o">-</span><span class="n">prev_x</span><span class="p">)</span>
    <span class="k">end</span>
    <span class="n">prev_x</span> <span class="o">=</span> <span class="n">x</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="k">end</span>
</pre></div>
</div>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>exec list-max.lua
frame-000.dat: max at x=-0.0197
frame-001.dat: max at x=-0.0209  (-0.0012)
frame-002.dat: max at x=-0.0216  (-0.0007)
frame-003.dat: max at x=-0.0224  (-0.0008)
</pre></div>
</div>
<p>Write to file values of the model F(x) at chosen x&#8217;s
(in this example x = 0, 1.5, 3, ... 150):</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="c1">-- file tabular-f.lua</span>
<span class="n">file</span> <span class="o">=</span> <span class="nb">io.open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">output.dat&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">w&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">150</span><span class="p">,</span> <span class="mf">1.5</span> <span class="k">do</span>
    <span class="n">file</span><span class="p">:</span><span class="n">write</span><span class="p">(</span><span class="nb">string.format</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">%g</span><span class="se">\t</span><span class="s">%g</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">F</span><span class="p">:</span><span class="n">get_model_value</span><span class="p">(</span><span class="n">x</span><span class="p">)))</span>
<span class="k">end</span>
<span class="n">file</span><span class="p">:</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-fityk"><div class="highlight"><pre><span></span><span class="gp">=-&gt; </span>exec tabular-f.lua
<span class="gp">=-&gt; </span>!head -5 output.dat
0       12.1761
1.5     12.3004
3       10.9096
4.5     9.12635
6       8.27044
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="ref.html" title="All the Rest"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="fit.html" title="Curve Fitting"
             accesskey="P">previous</a> &nbsp; </li>
  <li><a href="http://fityk.nieto.pl/">Home</a>&nbsp;&nbsp;&nbsp;</li>
  <li><a href="https://github.com/wojdyr/fityk/wiki">Wiki</a>&nbsp;&nbsp;&nbsp;</li>
  
        <li class="nav-item nav-item-0"><a href="fityk-manual.html">Manual</a> </li>
 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
      Last updated on 2016-11-06.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8.
    </div>
  </body>
</html>