Problems when comparing mwSize and mwIndex variables
이전 댓글 표시
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
James Tursa
2019년 4월 8일
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
2019년 4월 27일
James Tursa
2019년 4월 29일
편집: James Tursa
2019년 4월 29일
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
2019년 4월 30일
James Tursa
2019년 4월 30일
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
2019년 4월 30일
편집: James Tursa
2019년 4월 30일
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
2019년 4월 30일
James Tursa
2019년 4월 30일
편집: James Tursa
2019년 4월 30일
So, how to explain that 4294967297 output?
(Now that we know it is unsigned, change that %lld to %llu)
Ed Mendes
2019년 4월 30일
James Tursa
2019년 4월 30일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!