Problems when comparing mwSize and mwIndex variables
Afficher commentaires plus anciens
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 commentaires
James Tursa
le 8 Avr 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
le 27 Avr 2019
James Tursa
le 29 Avr 2019
Modifié(e) : James Tursa
le 29 Avr 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
le 30 Avr 2019
James Tursa
le 30 Avr 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
le 30 Avr 2019
Modifié(e) : James Tursa
le 30 Avr 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
le 30 Avr 2019
James Tursa
le 30 Avr 2019
Modifié(e) : James Tursa
le 30 Avr 2019
So, how to explain that 4294967297 output?
(Now that we know it is unsigned, change that %lld to %llu)
Ed Mendes
le 30 Avr 2019
James Tursa
le 30 Avr 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Fortran with MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!