Problems when comparing mwSize and mwIndex variables
Mostrar comentarios más antiguos
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 comentarios
James Tursa
el 8 de Abr. de 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
el 27 de Abr. de 2019
James Tursa
el 29 de Abr. de 2019
Editada: James Tursa
el 29 de Abr. de 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
el 30 de Abr. de 2019
James Tursa
el 30 de Abr. de 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
el 30 de Abr. de 2019
Editada: James Tursa
el 30 de Abr. de 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
el 30 de Abr. de 2019
James Tursa
el 30 de Abr. de 2019
Editada: James Tursa
el 30 de Abr. de 2019
So, how to explain that 4294967297 output?
(Now that we know it is unsigned, change that %lld to %llu)
Ed Mendes
el 30 de Abr. de 2019
James Tursa
el 30 de Abr. de 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Fortran with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!