Problems when comparing mwSize and mwIndex variables
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ed Mendes
am 6 Apr. 2019
Kommentiert: Ed Mendes
am 3 Mai 2019
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 Kommentare
James Tursa
am 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.
Akzeptierte Antwort
James Tursa
am 30 Apr. 2019
Bearbeitet: James Tursa
am 30 Apr. 2019
A couple of observations:
>> typecast(uint64(1),'uint8')
ans =
1 0 0 0 0 0 0 0
>> typecast(uint64(4294967297),'uint8')
ans =
1 0 0 0 1 0 0 0
So now I am thinking it may be a function signature problem. If a function is returning a value of 1 as an int (4-bytes), but you told the compiler it is returning an 8-byte integer, then an extra garbage 4-bytes may be picked up by the compiler and stuffed into nyt, accounting for that extra 1 in the bit pattern. This is just speculation, but I have seen this behavior before when prototypes/signatures are not correct.
I next would like to see the exact code where nyt is being set. And if your functions are involved, the prototypes/signatures of those functions.
Are you getting any compiler warnings about mismatched pointer types?
Do you have compiled C mex code calling compiled Fortran code? If so, then I would need to see the Fortran function/subroutine signature also. E.g., if it is the Fortran signature you show above, then I would expect all of the integers on the Fortran side to be 4-bytes. And if you are passing in pointers to 8-byte integers from the C-mex side then yes that would be a problem.
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!