From: Etienne on
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hlergg$n4h$1(a)fred.mathworks.com>...
> "Etienne" <etienne.coetzee(a)airbus.com> wrote in message <hleh0q$1sa$1(a)fred.mathworks.com>...
> > Hi James
> >
> > I am now trying to assign an array to the Ndim variable, so when it comes in, it is empty, the array is resized to 90 elemnts, and I would like to send this back out as the Ndim variable.
> >
> > I have tried to reallocate memory to the pointer, but I am not quite sure what I am doing wrong.
> >
> > Any help would be appreciated.
> >
> > Regards
> >
> > Etienne
>
> Not exactly sure how to advise without seeing your code. If you are simply trying to create a new 90 element Ndim variable to use, then you can just create one using the ptrNDIM variable, point to it with a 1-D NDIM pointer using the fpGetPr1 routine, and then use it. e.g.,
>
> #include <fintrf.h>
>
> SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
> use MatlabAPImex
> use MatlabAPImx
> IMPLICIT NONE
> !-ARG
> MWPOINTER PLHS(*), PRHS(*)
> INTEGER*4 NLHS, NRHS
> !-LOC
> Real*8, pointer :: NDIM(:)
> mwPointer ptrNDIM
> mwIndex :: i = 1
> mwSize :: m = 90
> mwSize :: n = 1
> !-----
> !\
> ! Argument checks
> !/
> if( nrhs /= 1 ) then
> call mexErrMsgTxt("Need exactly one auto input")
> endif
> if( mxGetClassName(prhs(1)) /= "auto" ) then
> call mexErrMsgTxt("Need exactly one auto input")
> endif
> if( nlhs > 1 ) then
> call mexErrMsgTxt("Too many outputs")
> endif
> !\
> ! Create a new Ndim property mxArray, 90 x 1 double
> !/
> ptrNDIM = mxCreateDoubleMatrix(m, n, mxREAL)
> NDIM => fpGetPr1(ptrNDIM) ! NDIM points directly at data area of ptrNDIM
> if( .not.associated(NDIM) ) then
> call mexErrMsgTxt("Internal error pointing to ptrNDIM data")
> endif
> !\
> ! Fill the Ndim property values
> !/
> NDIM = 5.d0 ! Your actual values would go here
> !\
> ! Create the output array
> !/
> PLHS(1) = mxDuplicateArray(PRHS(1))
> !\
> ! Set the new Ndim property value on the returned mxArray variable
> !/
> CALL mxSetProperty(PLHS(1),i,'Ndim',ptrNDIM)
> CALL mxDestroyArray(ptrNDIM)
> !-----
> RETURN
> END
>
>
> James Tursa

Thanks
From: Etienne on
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hlergg$n4h$1(a)fred.mathworks.com>...
> "Etienne" <etienne.coetzee(a)airbus.com> wrote in message <hleh0q$1sa$1(a)fred.mathworks.com>...
> > Hi James
> >
> > I am now trying to assign an array to the Ndim variable, so when it comes in, it is empty, the array is resized to 90 elemnts, and I would like to send this back out as the Ndim variable.
> >
> > I have tried to reallocate memory to the pointer, but I am not quite sure what I am doing wrong.
> >
> > Any help would be appreciated.
> >
> > Regards
> >
> > Etienne
>
> Not exactly sure how to advise without seeing your code. If you are simply trying to create a new 90 element Ndim variable to use, then you can just create one using the ptrNDIM variable, point to it with a 1-D NDIM pointer using the fpGetPr1 routine, and then use it. e.g.,
>
> #include <fintrf.h>
>
> SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
> use MatlabAPImex
> use MatlabAPImx
> IMPLICIT NONE
> !-ARG
> MWPOINTER PLHS(*), PRHS(*)
> INTEGER*4 NLHS, NRHS
> !-LOC
> Real*8, pointer :: NDIM(:)
> mwPointer ptrNDIM
> mwIndex :: i = 1
> mwSize :: m = 90
> mwSize :: n = 1
> !-----
> !\
> ! Argument checks
> !/
> if( nrhs /= 1 ) then
> call mexErrMsgTxt("Need exactly one auto input")
> endif
> if( mxGetClassName(prhs(1)) /= "auto" ) then
> call mexErrMsgTxt("Need exactly one auto input")
> endif
> if( nlhs > 1 ) then
> call mexErrMsgTxt("Too many outputs")
> endif
> !\
> ! Create a new Ndim property mxArray, 90 x 1 double
> !/
> ptrNDIM = mxCreateDoubleMatrix(m, n, mxREAL)
> NDIM => fpGetPr1(ptrNDIM) ! NDIM points directly at data area of ptrNDIM
> if( .not.associated(NDIM) ) then
> call mexErrMsgTxt("Internal error pointing to ptrNDIM data")
> endif
> !\
> ! Fill the Ndim property values
> !/
> NDIM = 5.d0 ! Your actual values would go here
> !\
> ! Create the output array
> !/
> PLHS(1) = mxDuplicateArray(PRHS(1))
> !\
> ! Set the new Ndim property value on the returned mxArray variable
> !/
> CALL mxSetProperty(PLHS(1),i,'Ndim',ptrNDIM)
> CALL mxDestroyArray(ptrNDIM)
> !-----
> RETURN
> END
>
>
> James Tursa

Hi James

I tried to use your toolbox before, but I ran into problems when I needed to write a matrix that was of integer type. I couldn't see any function that seemed to be able to cope with this. Is this contained in your toolbox somewhere. This relates to my previous question. How would I create an array of integer type and then pass it back to the object.

Thanks in advance.

Etienne
From: Etienne on
"Etienne" <etienne.coetzee(a)airbus.com> wrote in message <hlf7b5$rdd$1(a)fred.mathworks.com>...
> "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hlergg$n4h$1(a)fred.mathworks.com>...
> > "Etienne" <etienne.coetzee(a)airbus.com> wrote in message <hleh0q$1sa$1(a)fred.mathworks.com>...
> > > Hi James
> > >
> > > I am now trying to assign an array to the Ndim variable, so when it comes in, it is empty, the array is resized to 90 elemnts, and I would like to send this back out as the Ndim variable.
> > >
> > > I have tried to reallocate memory to the pointer, but I am not quite sure what I am doing wrong.
> > >
> > > Any help would be appreciated.
> > >
> > > Regards
> > >
> > > Etienne
> >
> > Not exactly sure how to advise without seeing your code. If you are simply trying to create a new 90 element Ndim variable to use, then you can just create one using the ptrNDIM variable, point to it with a 1-D NDIM pointer using the fpGetPr1 routine, and then use it. e.g.,
> >
> > #include <fintrf.h>
> >
> > SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
> > use MatlabAPImex
> > use MatlabAPImx
> > IMPLICIT NONE
> > !-ARG
> > MWPOINTER PLHS(*), PRHS(*)
> > INTEGER*4 NLHS, NRHS
> > !-LOC
> > Real*8, pointer :: NDIM(:)
> > mwPointer ptrNDIM
> > mwIndex :: i = 1
> > mwSize :: m = 90
> > mwSize :: n = 1
> > !-----
> > !\
> > ! Argument checks
> > !/
> > if( nrhs /= 1 ) then
> > call mexErrMsgTxt("Need exactly one auto input")
> > endif
> > if( mxGetClassName(prhs(1)) /= "auto" ) then
> > call mexErrMsgTxt("Need exactly one auto input")
> > endif
> > if( nlhs > 1 ) then
> > call mexErrMsgTxt("Too many outputs")
> > endif
> > !\
> > ! Create a new Ndim property mxArray, 90 x 1 double
> > !/
> > ptrNDIM = mxCreateDoubleMatrix(m, n, mxREAL)
> > NDIM => fpGetPr1(ptrNDIM) ! NDIM points directly at data area of ptrNDIM
> > if( .not.associated(NDIM) ) then
> > call mexErrMsgTxt("Internal error pointing to ptrNDIM data")
> > endif
> > !\
> > ! Fill the Ndim property values
> > !/
> > NDIM = 5.d0 ! Your actual values would go here
> > !\
> > ! Create the output array
> > !/
> > PLHS(1) = mxDuplicateArray(PRHS(1))
> > !\
> > ! Set the new Ndim property value on the returned mxArray variable
> > !/
> > CALL mxSetProperty(PLHS(1),i,'Ndim',ptrNDIM)
> > CALL mxDestroyArray(ptrNDIM)
> > !-----
> > RETURN
> > END
> >
> >
> > James Tursa
>
> Hi James
>
> I tried to use your toolbox before, but I ran into problems when I needed to write a matrix that was of integer type. I couldn't see any function that seemed to be able to cope with this. Is this contained in your toolbox somewhere. This relates to my previous question. How would I create an array of integer type and then pass it back to the object.
>
> Thanks in advance.
>
> Etienne

Hi James

It seems to be working. I am still not sure how you can create an integer matrix, but this does not seem to be neccessary.

Regards

Etienne
From: James Tursa on
"Etienne" <etienne.coetzee(a)airbus.com> wrote in message <hlgdle$nls$1(a)fred.mathworks.com>...
>
> It seems to be working. I am still not sure how you can create an integer matrix, but this does not seem to be neccessary.

My package only works for double types. For other types you have to use the MATLAB API routines directly.

James Tursa