f



Matlab crashes while calling Mex file

Hi,

My problem is as follows:

I created a mex file called getCg(), in order to use some functions
of the c-files I have in my matlab model. Problem is, after calling
the mex file 'getCg()' several times matlab crashes. That is, when I
write
>>for i=1:28, a(i) = getCgOnGas(50*i); end
command several times matlab crashes immediately.

Do you have any idea what could be the reason?

Here is the mex file I have:

#include<mex.h>
#include"gas.h"
#include"gasdb.h"
#include"global.h"
#include"heat.h"
#include"hss.h"
#include"readfile.h"
#include"utils.h"
#include"brickdb.h"
#include "callInit.h"

void mexFunction(int nlhs,mxArray *plhs[], int nrhs, mxArray *prhs[])
{
	double x1, tmp;
	double *y;
	int i;
	Gas coldBlast; // 'Gas' structure is defined in the header files

	callingInit();

	//buildGasDB();

	for (i = 0; i < NUM_GASCOMPONENT; i++) {
           coldBlast.Ratio[i]=0;
    }

	coldBlast.Ratio[N2] = 0.76867;	
	coldBlast.Ratio[O2] = 0.20433;
	coldBlast.Ratio[H2O] = 0.02700;

	plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
	x1 = mxGetScalar(prhs[0]);
	
	y = (double *) mxGetPr(plhs[0]);

	tmp = getGasTrueHeatCapacity(coldBlast,x1);
	//printf("%f\n",tmp);
    y[0] = tmp;
}
0
1/15/2006 5:54:30 PM
comp.soft-sys.matlab 211266 articles. 24 followers. lunamoonmoon (257) is leader. Post Follow

1 Replies
473 Views

Similar Articles

[PageSpeed] 32

Akin Sahin wrote:
> Hi,
> 
> My problem is as follows:
> 
> I created a mex file called getCg(), in order to use some functions
> of the c-files I have in my matlab model. Problem is, after calling
> the mex file 'getCg()' several times matlab crashes. That is, when I
> write
>>> for i=1:28, a(i) = getCgOnGas(50*i); end
> command several times matlab crashes immediately.
> 
> Do you have any idea what could be the reason?
> 
> Here is the mex file I have:
> 
> #include<mex.h>
> #include"gas.h"
> #include"gasdb.h"
> #include"global.h"
> #include"heat.h"
> #include"hss.h"
> #include"readfile.h"
> #include"utils.h"
> #include"brickdb.h"
> #include "callInit.h"
> 
> void mexFunction(int nlhs,mxArray *plhs[], int nrhs, mxArray *prhs[])
> {
> 	double x1, tmp;
> 	double *y;
> 	int i;
> 	Gas coldBlast; // 'Gas' structure is defined in the header files
> 
> 	callingInit();
> 
> 	//buildGasDB();
> 
> 	for (i = 0; i < NUM_GASCOMPONENT; i++) {
>            coldBlast.Ratio[i]=0;
>     }
> 
> 	coldBlast.Ratio[N2] = 0.76867;	
> 	coldBlast.Ratio[O2] = 0.20433;
> 	coldBlast.Ratio[H2O] = 0.02700;
> 
> 	plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
> 	x1 = mxGetScalar(prhs[0]);
> 	
> 	y = (double *) mxGetPr(plhs[0]);
> 
> 	tmp = getGasTrueHeatCapacity(coldBlast,x1);
> 	//printf("%f\n",tmp);
>     y[0] = tmp;
> }

I can't see anything terribly wrong with the code you
have provided us. My mex crashes are usually due to some
subtle mistakes in C and/Fortran subroutines. Put some
printf's to locate the problem and then see the code carefully
(or post here).

markus
0
no438 (1037)
1/16/2006 5:56:34 AM
Reply: