Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: mex fortran confusion with deallocate
Replies: 7   Last Post: Nov 19, 2013 7:09 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Octopode

Posts: 16
Registered: 7/31/13
mex fortran confusion with deallocate
Posted: Oct 7, 2013 10:19 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,

So far i was coding mex fortran with only fortran 77 standards.
Now i'm trying the 90/95 features, with allocatable arrays. I'm confused with the deallocation, when i'm supposed to do it, and not to.

Say I declare within my subroutine (not the gateway) an output variable B (plhs(1)), and input A (prhs(1)):


SUBROUTINE MYFUN(B,A)

DOUBLE PRECISION :: A
DOUBLE PRECISION, dimension(:), allocatable :: B
mwSize :: M

later on i get to know its size, M.

allocate(B(M))

then do some stuff on B which lead to A as a result.

RETURN
END

When/where/how am i supposed to deallocate A ?

Should i do this in the gateway with "mxDestroyArray" like below ?

Ap = MXGETPR(PRHS(1))
PLHS(1) = MXCREATEDOUBLEMATRIX(M,1,0)
Bp = MXGETPR(PLHS(1))

CALL MYFUN(%val(Ap),%val(Bp))

CALL mxDestroyArray(Ap)

RETURN
END

or should i use "deallocate" somewhere else ?

Thanks




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.