Re: Is there any explanation for function block?
Ethan A Merritt <[email protected]> Sat, 15 Oct 2022 10:06:00 -0700
| Newsgroups | gmane.comp.graphics.gnuplot.devel |
|---|---|
| Message-ID | <CALUAmEv_G2kPJJaVhXzvh96iuqOoLeQ8OZu1zhoHuagCFoCK6g@mail.gmail.com> |
Function blocks are implemented in a new branch that I have not yet
committed. The "local" property for variables was part of that branch but
is useful already by itself, so I added it first. The idea of function
blocks is similar to datablocks, except that the text in the block is
executed as a function rather than used as data. See earlier discussion
attached to Bug #2547 https://sourceforge.net/p/gnuplot/bugs/2547/ and
Feature Request 521 https://sourceforge.net/p/gnuplot/feature-requests/521/
Here is a draft section of the documentation for the new branch. It still
has a few rough edges, but I expect to merge it in the next week or so.
The `function` command signals the definition of a here-document containing
a named block of gnuplot code that can be called as a function.
As with data blocks, the name of a function block must begin with a '$'.
Up to nine named parameters may be specified as part of the definition.
These names may be used inside the function block as local variables.
See `local` and `scope`.
Once the function block is defined, you can invoke it by name anywhere
that a normal function could be used.
Example:
function $sinc(arg) << EOF
if (arg == 0) { return 1.0 }
return sin(arg) / arg
EOF
gnuplot> plot $sinc(x) with lines title "sinc(x) as a function block"
It is not necessary to specify a list of named arguments to a function
block
at the time it is declared. Arguments to the function passed from the
command
line can be accessed inside the function block as ARGV[1] etc, as would be
the
case for a `call` command. See `ARGV`. This allows defining a function
block that can operate on a variable number of arguments.
The primary motivation for function block support is to allow definition of
complicated functions directly in gnuplot. Execution is of course slower
than if the same function were coded directly in C or Fortran, but this is
acceptable for many purposes. If execution speed matters then the function
can be implemented later as a plugin instead (see `plugins`).
A non-trivial example of using function blocks to implement and plot
a 15-term Lancosz approximation for the complex lngamma function is
provided in the demo collection as
^ <a href="http://www.gnuplot.info/demo_5.5/function_block.html">
function_block.dem
^ </a>
The function block implementation is slower by a factor of roughly 25
compared
to the built-in lnGamma function using the same algorithm coded directly in
C.
Nevertheless it is still fast enough for 3D interactive rotation.
On Fri, Oct 14, 2022 at 11:40 PM Tatsuro MATSUOKA via gnuplot-beta <
[email protected]> wrote:
> I found the option --enable-function-blocks is implemented to the
> development branch.
>
> Is there any explanation for the function block?
>
> Tatsuro
>
>
>
> _______________________________________________
> gnuplot-beta mailing list
> [email protected]
> Membership management via:
> https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/gnuplot-beta__;!!K-Hz7m0Vt54!i-6R1LQEUOPOg9GRf_E7o8MGHFaWf_cXfyDWcdAF0zC6EGVNvS-Yx-0U-vtqT0DdmY1ubirVqocHtClLZsrDvB2_cxG8J_Z9dvdW$
>
>
--
Ethan A Merritt
Biomolecular Structure Center, K-428 Health Sciences Bldg
MS 357742, University of Washington, Seattle 98195-7742
_______________________________________________
gnuplot-beta mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta