Although I heartily endorse Chris's recommended reading, I will also
answer your first question, as that seems to be of greatest relevance.

If the C-function "mysub_" modifies its arguments in-place (because it
works with pointers), it will also modify the piddles in-place. This
will work even if the incoming piddles are slices: modifications
correctly flow back to the parent piddles. This fact is incredibly
useful when it comes to writing wrappers around C functions that work
universally for all piddles.

To your second question, I discuss this a bit in the PDL::PP chapter
of the PDL book. In short, you can modify incoming piddle arguments
in-place. One thing I don't cover in the chapter is the Inplace
argument to pp_def:
http://pdl.perl.org/PDLdocs/PP.html#other_useful_pp_keys_in_data_operation_definitions

Finally, returning values that are not a piddle is possible but not
simply supported. This is best handled by using OtherPars, passing in
the SV* that you modify in you PP code. Unfortunately, this means that
you must be familiar with Perl's C-API for manipulating scalars with C
code. It's not hard, but it has a learning curve. Once you have that
working, you should write a wrapper that handles this in a Perlish
(i.e. graceful) manner. (The PMCode key is supposed to be your friend
or such wrappers, but the PMCode chapter has yet to be written.)

Hope that helps, and do consult the reading that Chris recommended. It
took lots of effort to write and answers many of your questions, I
hope.

David

On Tue, Sep 4, 2012 at 12:07 AM, Luis Mochan <[email protected]> wrote:
> I'm learning to use Inline::Pdlpp and I have several questions. Many fortran
> subroutines modify their arguments, which are passed by reference. If I
> call such a function with code such as
>
> PDL::myfun($a, $b);
> use Inline Pdlpp =><<'ENDPP'
>     pp_def('myfun',
>            Pars=>'a(); 'b(n);',
>            Code=>'mysub_($P(a), $P(b), $SIZE(n));'
>           );
> ENDPP
>
> can I be sure that the pdl's $a and $b (on the perl side) will be
> modified if 'mysub_' modifies its first two arguments, or that they will
> not be modified even if mysub_ does modify its arguments?
>
> On the other hand, if the subroutine has many arguments and modifies
> several of them, what is the best way to send back the modifications to
> perl (easiest but not too inefficient)? I guess I could copy the
> variables to output variables using something like
>
>            Pars=>'...b(n);... [o] c(n);...',
>            Code=>'
>                   mysub_($P(a), $P(b), $SIZE(n));
>                   ...
>                   loop(n) %{ $c()=$b(); %}
>                   ...
>                   '
> Would this work? This is related to the previous question: will $b()
> (on the PP side) contain the changed values after returning from the
> Fortran subroutine? In case this works, wouldn't it involve too much
> copying? Is there a better/recommended way of sending the changes back
> to the perl side?
>
> One last question. Is there a simple way of sending back values that
> are not in a pdl?
>
> (Maybe all the questions could be answered with a pointer to the
> relevant documentation.)
>
> Thanks and best regards,
> Luis
>
> --
>
>                                                                   o
> W. Luis Mochán,                      | tel:(52)(777)329-1734     /<(*)
> Instituto de Ciencias Físicas, UNAM  | fax:(52)(777)317-5388     `>/   /\
> Apdo. Postal 48-3, 62251             |                           (*)/\/  \
> Cuernavaca, Morelos, México          | [email protected]   /\_/\__/
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl



-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to