From: Clint on
Hi Can someone please explain why this does not output two vectors to the matlab workspace?

I call the below file inside matlab with:

tempVec = ones(256,256,10,20).*573;
zbndryVec = ones(256,256,2,20).*0.75E-3;
zbndryVec(:,:,1,:)= -zbndryVec(:,:,1,:);

[field,q] = cmsl4Integrated(tempVec,zbndryVec);

--------------Start of mex File -----------------------------------------
#include "fintrf.h"
C======================================================================
#if 0
C
C cmsl4.F
C .F file needs to be preprocessed to generate .for equivalent
C
#endif
C
C cmsl4.f
C
C Computational function that takes temperature and displacement
C and returns optical field inside HEL resonator.

C This is a MEX-file for MATLAB.
C Copyright 1984-2009 The MathWorks, Inc.
C $Revision: 1.12.2.8 $
C======================================================================
C Gateway routine
subroutine mexFunction(nlhs, plhs, nrhs, prhs)

C Declarations
implicit none

C mexFunction arguments:
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs

C Function declarations:
mwPointer mxGetPr,mxGetPi
mwPointer mxCreateDoubleMatrix,mxCreateNumericArray
integer*4 mxClassIDFromClassName
integer mxIsNumeric
mwSize mxGetM, mxGetN

C Pointers to input/output mxArrays:
mwPointer x_ptr1,x_ptr2,x_ptr3,y_ptr1,y_ptr2,y_ptri1,y_ptri2

C Array information:
mwSize mrows1,mrows2,ncols1,ncols2,size1,size2,fieldSize

C Arguments for mxCreateNumericArray
integer*4 classid
integer*4 complexflag
mwSize ndim
mwSize dims(1)

C Arguments for computational routine:
real*8 temp,zbndry,q
dimension temp(256,256,10,20),zbndry(256,256,2,20)
dimension q(256,256,10,20,2)
complex*16 c(1024,1024)

C-----------------------------------------------------------------------
C Check for proper number of arguments.
if(nrhs .ne. 2) then
call mexErrMsgIdAndTxt ('MATLAB:cmsl4:nInput',
+ 'Two inputs required.')
elseif(nlhs .gt. 2) then
call mexErrMsgIdAndTxt ('MATLAB:cmsl4:nOutput',
+ 'Too many output arguments.')
endif

C Validate inputs
C Check that the 1st input is numeric array.
if(mxIsNumeric(prhs(1)) .eq. 0.) then
call mexErrMsgIdAndTxt ('MATLAB:cmsl4:NonNumeric',
+ 'Input1 must be numeric.')
endif

C Check that the 2nd input is numeric array.
if(mxIsNumeric(prhs(2)) .eq. 0.) then
call mexErrMsgIdAndTxt ('MATLAB:cmsl4:NonNumeric',
+ 'Input2 must be numeric.')
endif



C Get the size of the first input array.
mrows1 = mxGetM(prhs(1))
ncols1 = mxGetN(prhs(1))
size1 = mrows1*ncols1

C Get the size of the 2nd input array.
mrows2 = mxGetM(prhs(2))
ncols2 = mxGetN(prhs(2))
size2 = mrows2*ncols2


C Create Fortran array from the 1st input argument.
x_ptr1 = mxGetPr(prhs(1))
call mxCopyPtrToReal8(x_ptr1,temp,size1)

C Create Fortran array from the 2nd input argument.
x_ptr2 = mxGetPr(prhs(2))
call mxCopyPtrToReal8(x_ptr2,zbndry,size2)

C Create matrix for the return argument.
plhs(1) = mxCreateDoubleMatrix(1024,1024,1)
fieldSize = 1024*1024
y_ptr1 = mxGetPr(plhs(1))
y_ptri1 = mxGetPi(plhs(1))

C Create matrix for the return argument q.
classid = mxClassIDFromClassName('REAL*8')
complexflag = 0
ndim = 6
dims(1) = 256
dims(2) = 256
dims(3) = 10
dims(4) = 20
dims(5) = 2
plhs(2) = mxCreateNumericArray(ndim,dims,classid,complexflag)
y_ptr2 = mxGetPr(plhs(2))

C Load the data into y_ptr, which is the output to MATLAB.
call mxCopyComplex16ToPtr(c,y_ptr1,y_ptri1,fieldSize)
call mxCopyReal8ToPtr(q,y_ptr2,mxGetM(plhs(2))*mxGetN(plhs(2)))
call mxDestroyArray(plhs(2))
call mxDestroyArray(plhs(1))

return
end

C-----------------------------------------------------------------------
C Computational routine