Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Passing a subvector to a void function


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Passing a subvector to a void function
Date   Fri, 26 Jul 2013 16:12:55 +0000

A question for all you Mata programmers:

I am converting a Fortran 90 program to Mata and the Fortran program passes subarrays as arguments to subroutines like this:

	call idtang ( ndp, xd, yd, nt, iwk(jwipt), nl, iwk(jwipl),  iwk(jwiwl), iwk(jwiwp), wk )

where iwk is an array and iwk(jwipt) means "pass a subarray of iwk starting at element jwipt".  The subroutine modifies this subarray and passes it back.

I converted this to Mata as follows:

	idtang ( ndp, xd, yd, nt, iwk[|jwipt\.|], nl, iwk[|jwipl\.|], iwk[|jwiwl\.|], iwk[|jwiwp\.|], wk )

but iwk is empty upon return.

Is there a way to do this that will return the modified subvector and put it back in iwk at position jwipt?

I got it to work by creating a new vector ipt, setting it to iwk[|jwipt\.|] and passing it to the function, but I was hoping to avoid having to make so many substantive changes to the original code.

Thanks for your help!

Joe Canner
Johns Hopkins University School of Medicine

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index