> Are you running 32-bit or 64-bit?
> What version of MATLAB are you using?
>
> I see potential problems with your use of "integer" as a pointer (will need to be integer*8 on 64-bit systems ... i.e. should use mwPointer instead).
>
> Also the mxCreateFull function is deprecated, and has been for quite some time, so this must be very old code.
>
> Is it your intent to simply call the pr_equil function with MATLAB inputs & outputs? If so, this can probably be done much simpler.
>
> James Tursa
Hi James,
Thanks a lot for such a quick turnaround :) I am using Windows 7 32 bit, MATLAB R2011b 32 bit, Visual Studio 2010 Professional and Intel Visual Fortran Composer XE 2011. Yes the code is pretty old, written in 2001 and modified in 2006.
I have replaced mxCreateFull function with mxCreateDoubleMatrix. Also i used mwPointer wherever appropriate. However, MATLAB still crashes.
I guess i should learn about MEX files properly to get out of this. Anyway, if you think minor corrections could make the code work, would you please let me know?
The modified code is pasted below for your reference,
#include "fintrf.h"
C --------------------------------------------------------------------------
C MEX File Gateway implementation for Plant_Subroutines
C Date : 08-05-2001 by U?ur YILDIZ
C --------------------------------------------------------------------------
C Modified for gama-fi approach by ALMILA BAHAR Date:01/05/2006
C --------------------------------------------------------------------------
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
include 'thermo_LIBRARY.h'
include 'parameter.h'
mwPointer plhs(*), prhs(*)! pointer to left-hand and right-hand side variables
integer nlhs, nrhs ! # of variables in plhs, prhs
mwPointer mxCreateDoubleMatrix, mxGetString, mxGetM, mxGetN ! mx Functions declarations
integer mxIsNumeric, mxIsChar, status, alloc_err ! mx Functions declarations
mwPointer m, n ! Dummy variables
mwSize size
mwPointer Func_name_ptr ! Function name fortran pointers
character*100 Func_name ! Function name for fortran use
c ---------------------------------------------------Input fortran pointers
mwPointer Input1_pr, Input2_pr, Input3_pr, Input4_pr, Input5_pr
mwPointer Input6_pr, x_pr, y_pr, z_pr
c -------------------------------------------------- Output fortran pointers
mwPointer Output1_pr, Output2_pr, Output3_pr, Output4_pr
mwPointer Output5_pr, Output6_pr
plhs(1) = mxCreateDoubleMatrix(1,1,0)
plhs(2) = mxCreateDoubleMatrix(1,1,0)
call mexErrMsgTxt('Two outputs (T and vapor comp) are required. (eq
&uilibrium) [thermo_LIBRARY.dll]')
endif
if (mxIsNumeric(prhs(2)) .ne. 1) call mexErrMsgTxt('Input #1 is not
&a numeric. - (equilibrium) [thermo_LIBRARY.dll]')
if (mxIsNumeric(prhs(3)) .ne. 1) call mexErrMsgTxt('Input #2 is not
&a numeric. - (equilibrium) [thermo_LIBRARY.dll]')
if (mxIsNumeric(prhs(4)) .ne. 1) call mexErrMsgTxt('Input #3 is not
&a numeric. - (equilibrium) [thermo_LIBRARY.dll]')
m = mxGetM(prhs(2))
n = mxGetN(prhs(2))
Input1_sz = m*n;
if (n .ne. 1 .or. m .ne. 1) call mexErrMsgTxt('Input #1 is not a sc
&alar. - &(equilibrium) [thermo_LIBRARY.dll]')
m = mxGetM(prhs(3))
n = mxGetN(prhs(3))
Input2_sz = m*n;
if (n .ne. 1 .or. m .ne. 1) call mexErrMsgTxt('Input #2 is not a sc
&alar. - (equilibrium) [thermo_LIBRARY.dll]')
m = mxGetM(prhs(4))
n = mxGetN(prhs(4))
Input3_sz = m*n;
if (n .ne. 1 .or. m .ne. 1) call mexErrMsgTxt('Input #3 is not a NC
&Element row vector. - (equilibrium) &[thermo_LIBRARY.dll]')
Input1_pr = mxGetPr(prhs(2))
Input2_pr = mxGetPr(prhs(3))
Input3_pr = mxGetPr(prhs(4))
plhs(1) = mxCreateDoubleMatrix(1,1,0)
plhs(2) = mxCreateDoubleMatrix(1,nj,0)
Output1_pr = mxGetPr(plhs(1))
Output2_pr = mxGetPr(plhs(2))
status = 0
allocate (real_Input1(1),STAT = alloc_err)
status = status + alloc_err
allocate (real_Input2(1),STAT = alloc_err)
status = status + alloc_err
allocate (real_Input3(nj),STAT = alloc_err)
status = status + alloc_err
allocate (real_Output1(1),STAT = alloc_err)
status = status + alloc_err
allocate (real_Output2(nj),STAT = alloc_err)
status = status + alloc_err
if (status .ne. 0) then
if (allocated(real_Input1)) deallocate(real_Input1)
if (allocated(real_Input2)) deallocate(real_Input2)
if (allocated(real_Input3)) deallocate(real_Input3)
if (allocated(real_Output1)) deallocate(real_Output1)
if (allocated(real_Output2)) deallocate(real_Output2)
call mexErrMsgTxt('Memory allocation error. - (equilibrium) [thermo