Problems when comparing mwSize and mwIndex variables
Show older comments
Hello
I am slowly changing my old fortran-c codes to the new matlab standard. When changing one of the gateway funtions, I encounter the following
....
mwIndex nyt, nsuby;
mwSize YDA_COLS;
....
then nyt and YDA_COLS = nsuby = mxGetN(YDA_IN) take value 1, that is nyt=1 and YDA_COLS=1. When I issue the following comand
if (YDA_COLS < nyt)
{
mexErrMsgTxt("Number of Columns of Y is incompatible. ");
}
The number os Columns of Y is incompatible! I have no idea of what is wrong. If I change to mwSize nyt, nsuby, the same thing happens. It only works if I change to int nyt, nsuby.
Many thanks
Ed
10 Comments
James Tursa
on 8 Apr 2019
It is hard to advise without seeing more of your code. At the very least, I would print out the values of YDA_COLS and nyt before you call mexErrMsgTxt.
Ed Mendes
on 27 Apr 2019
James Tursa
on 29 Apr 2019
Edited: James Tursa
on 29 Apr 2019
What is sizeof(mwSize) and sizeof(mwIndex)? Is mwSize unsigned (e.g., size_t)? Can you post the actual code where YDA_COLS and nyt are assigned values? I am thinking it could possibly be a signed/unsigned conversion issue.
Ed Mendes
on 30 Apr 2019
James Tursa
on 30 Apr 2019
Let's back up a step. What do you get when you run this code:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mwIndex nyt = 1, Itest = -1;
mwSize YDA_COLS = 1, Stest = -1;
mexPrintf("YDA_COLS = %llu , %zu bytes , is signed? %d\n",YDA_COLS,sizeof(YDA_COLS),Stest<0);
mexPrintf("nyt = %lld , %zu bytes , is signed? %d\n",nyt,sizeof(nyt),Itest<0);
if (YDA_COLS < nyt) {
mexErrMsgTxt("Number of Columns of Y is incompatible. ");
} else {
mexPrintf("Everything OK\n");
}
}
James Tursa
on 30 Apr 2019
Edited: James Tursa
on 30 Apr 2019
Also, not sure what difference this will make to you (if any), but the default INTEGER type in Fortran is typically 4-bytes, even with a 64-bit compiler. In your translation the integers you are using are apparently 8-bytes.
Ed Mendes
on 30 Apr 2019
James Tursa
on 30 Apr 2019
Edited: James Tursa
on 30 Apr 2019
So, how to explain that 4294967297 output?
(Now that we know it is unsigned, change that %lld to %llu)
Ed Mendes
on 30 Apr 2019
James Tursa
on 30 Apr 2019
Can you clarify? Are you linking compiled C-mex code to compiled Fortran code? How does changing integer to integer*8 on the Fortran side affect the "signed" output on the C side? I am confused about what you are actually doing.
Accepted Answer
More Answers (0)
Categories
Find more on Fortran with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!