Hi Luis-

I'm not an expert PP coder but I'm sure someone
with more experience can correct my mistakes.
My thoughts are in-line below...

--Chris

On 2/4/2017 11:22, Luis Mochan wrote:
> I want to define a PP routine that calls a fortran routine that takes
> a 2D array and returns its result in the same array.
>
> I don't fully understand the PDL::PP manual.
>
> If I plan to always modify the pdl containing the array, should I use
>     PARS => '[o] b(n,m);'
> as the array b is modified by the routine, or should I use
>     PARS => 'b(n,m);'
> as the array b contains the input data. How should I manage the double
> role of being both an input and output array.

I think the approach you want is a signature like 'a(n,m); [o]b(n,m);',
set Inplace => 1 and then condition the Code section by checking
if (a == b) as in the example below the description of the Inplace key
options.

If the input and output PDLs are the same, which they will be if the
user calls your routine with the inplace flag set on the input arg,
then a==b and you can skip the copy.

Otherwise, make the copy with the loops:

    loop(n) %{ loop(m) %{ $b() = $a(); %} %}

and I believe you can leave out the arguments for the
assignment operation.  This is definitely something that
could use a specific example in the docs.

I hope this helps and is correct!  :-)

Cheers,
Chris


> If I prefer not to change the input data, I guess my pars parameter
> should be something like
>     PARS => 'a(n,m), [o] b(n,m)';
> where a is the input and b is the output. Then I would need to
> initialize b with a, before calling the fortran
> routine with $P(b). What is the best way to do it? I could have two nested for
> loops, but I wonder if it can be done with the loop contruct, as
>     loop(n) %{ loop(m) %{ ... %} %}
> For a one dimensional array I would use
>     $b()=$a();
> within the innermost braces. But I couldn't find in the PDL::PP manual
> how to do it in the 2D (or higher dimensional) case.
>
> Finally, I guess I could let the user determine if he wants his input
> array to be modified or not, by using 'inplace'. I understand I would
> have to use a line with Inplace=>... in my pp_def, but I don't
> understand how to avoid then the explicit copy in the loop above. Is
> there a way of making the copy implicitly, depending on the use of
> inplace?
>
> Thanks for your advice,
> Luis
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to