Prev: plotregion
Next: how to send keyboard event
From: James Tursa on 28 Dec 2009 15:00 "HIEU " <nguyenhuyhieu(a)gmail.com> wrote in message <hhb04a$5uh$1(a)fred.mathworks.com>... > @ James Tursa > I tried the code and got the following errors. Any idea? > > >> options = [matlabroot '\bin\win32\mexopts\intelf11msvs2005engmatopts.bat'] > > options = > > C:\Program Files\MATLAB\R2008a\bin\win32\mexopts\intelf11msvs2005engmatopts.bat > > >> mex('-f', options,'readinput.f90','MatlabAPImex.obj','MatlabAPImx.obj','MatlabAPImat.obj') > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXCALLMATLAB referenced in function _MATLABAPIMEX_mp_MEXCREATESPARSELOGICALMATRIX > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXPRINTF referenced in function _MATLABAPIMEX_mp_MEXPRINT > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXSETTRAPFLAG referenced in function _MATLABAPIMEX_mp_MEXGET > readinput.exe : fatal error LNK1120: 3 unresolved externals > > C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: Link of 'readinput.exe' failed. > > ??? Error using ==> mex at 207 > Unable to complete successfully. > > > As you mentioned before, is this possible to build a mexFunction routine instead in order to do the work? I have no idea how to do that and I would love to be advised. > > Thanks, > Hieu Hi. My bad. I should have been more explicit. For a PROGRAM (also known as an engine application as far as the build process is concerned) you cannot have *any* mex routines in the build. So do not include the 'MatlabAPImex.obj' file in your build. I had that included in my earlier post because I mistakenly assumed you were building a mexFunction routine, which you were not. The mex command should be: mex('-f', options,'readinput.f90','MatlabAPImx.obj','MatlabAPImat.obj') See if that works. For large arrays, the mexFunction approach is the most efficient since no disk writing is involved, and in some cases no data copying either. An example would be: #include "fintrf.h" subroutine mexFunction(nlhs, plhs, nrhs, prhs) use MatlabAPImex use MatlabAPImx implicit none !-ARG mwPointer plhs(*), prhs(*) integer*4 nlhs, nrhs !-LOC real(8), pointer :: fp(:,:,:) !----- !\ ! Check the input !/ if( nrhs /= 1 ) then call mexErrMsgTxt("This function needs exactly one input") endif if( nlhs /= 0 ) then call mexErrMsgTxt("This function does not return outputs") endif !\ ! Get a pointer to the input data !/ fp => fpGetPr3(prhs(1)) ! Assumes that fp will be used as input only if( .not.associated(fp) ) then call mexErrMsgTxt("Unable to associate pointer fp") endif !\ ! Use the fp array here !/ call DisplayMatrixExplicit3(fp) !\ ! Done !/ return !\ ! All of the contained routines have explicit interfaces and can use ! assumed shape arguments. !/ contains !---------------------------------------------------------------------- subroutine DisplayMatrixExplicit3(A) use MatlabAPImex implicit none !-ARG real(8), intent(in) :: A(:,:,:) ! Assumed shape A !-LOC mwSize M, N, P character(len=1000) line integer(4) i, j, k mwPointer address !----- k = mexPrint("Explicit Interface 3D Matrix Print") M = size(A,1) N = size(A,2) P = size(A,3) if( M*N*P == 0 ) return address = %loc(A) write(line,'(1X,A,Z8)') 'Address of data = ',address k = mexPrint(line) do j=1,p write(line,*) 'Sub-Matrix',j k = mexPrint(line) do i=1,M write(line,*) 'Row',i,' = ',int(A(i,:,j),1) k = mexPrint(line) enddo enddo return end subroutine DisplayMatrixExplicit3 !---------------------------------------------------------------------- end subroutine mexFunction To compile the mexFunction do this (assumes the above file is named passtest.f): mex passtest.f MatlabAPImex.obj MatlabAPImx.obj This is just a demonstration routine meant to work with small 3D arrays with integral values (so the printing is reasonable). No checking is done on the printing so if you pass it an array that is too large it will bomb. To run it you can do this: A = floor(rand(3,3,3)*99) % <-- small size, integral values !! passtest(A) Note particularly in this mexFunction example that I do not call fpDeallocate(fp). That is because fp is pointing directly at the input data area, not a copy. That is, fp is pointing directly at the data area of a variable that exists in the MATLAB workspace. So the fp memory must not be freed, and the fp target must be used as read-only in all downstream code. If you wish to modify the fp target then you will need to use fpGetPrCopy3 instead of fpGetPr3, and then at the end you would call fpDeallocate(fp). James Tursa
From: HIEU on 28 Dec 2009 16:00 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hhb2ol$lb8$1(a)fred.mathworks.com>... > "HIEU " <nguyenhuyhieu(a)gmail.com> wrote in message <hhb04a$5uh$1(a)fred.mathworks.com>... > > @ James Tursa > > I tried the code and got the following errors. Any idea? > > > > >> options = [matlabroot '\bin\win32\mexopts\intelf11msvs2005engmatopts.bat'] > > > > options = > > > > C:\Program Files\MATLAB\R2008a\bin\win32\mexopts\intelf11msvs2005engmatopts.bat > > > > >> mex('-f', options,'readinput.f90','MatlabAPImex.obj','MatlabAPImx.obj','MatlabAPImat.obj') > > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXCALLMATLAB referenced in function _MATLABAPIMEX_mp_MEXCREATESPARSELOGICALMATRIX > > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXPRINTF referenced in function _MATLABAPIMEX_mp_MEXPRINT > > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXSETTRAPFLAG referenced in function _MATLABAPIMEX_mp_MEXGET > > readinput.exe : fatal error LNK1120: 3 unresolved externals > > > > C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: Link of 'readinput.exe' failed. > > > > ??? Error using ==> mex at 207 > > Unable to complete successfully. > > > > > > As you mentioned before, is this possible to build a mexFunction routine instead in order to do the work? I have no idea how to do that and I would love to be advised. > > > > Thanks, > > Hieu > > Hi. My bad. I should have been more explicit. For a PROGRAM (also known as an engine application as far as the build process is concerned) you cannot have *any* mex routines in the build. So do not include the 'MatlabAPImex.obj' file in your build. I had that included in my earlier post because I mistakenly assumed you were building a mexFunction routine, which you were not. The mex command should be: > > mex('-f', options,'readinput.f90','MatlabAPImx.obj','MatlabAPImat.obj') > > See if that works. > @ James Tursa: Thank you. I also tried that mex command before (i.e without matlabAPImex.obj). It does compile but when I run the exe with the bang operator !readinput.exe nothing happens. when I tried to run the exe at a windows command prompt it returns the following runtime error: Severe: MATLAB:I18n:MissingICUdata - ICU data not found. The program '...' has excited with code 2 (0x2) Have you ever encountered this error? I am running XP pro 32bit. The input file test.mat (holding a simple 3d array) is in the same folder. Hieu
From: James Tursa on 28 Dec 2009 16:28 "HIEU " <nguyenhuyhieu(a)gmail.com> wrote in message <hhb697$46h$1(a)fred.mathworks.com>... > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hhb2ol$lb8$1(a)fred.mathworks.com>... > > "HIEU " <nguyenhuyhieu(a)gmail.com> wrote in message <hhb04a$5uh$1(a)fred.mathworks.com>... > > > @ James Tursa > > > I tried the code and got the following errors. Any idea? > > > > > > >> options = [matlabroot '\bin\win32\mexopts\intelf11msvs2005engmatopts.bat'] > > > > > > options = > > > > > > C:\Program Files\MATLAB\R2008a\bin\win32\mexopts\intelf11msvs2005engmatopts.bat > > > > > > >> mex('-f', options,'readinput.f90','MatlabAPImex.obj','MatlabAPImx.obj','MatlabAPImat.obj') > > > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXCALLMATLAB referenced in function _MATLABAPIMEX_mp_MEXCREATESPARSELOGICALMATRIX > > > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXPRINTF referenced in function _MATLABAPIMEX_mp_MEXPRINT > > > MatlabAPImex.obj : error LNK2019: unresolved external symbol _MEXSETTRAPFLAG referenced in function _MATLABAPIMEX_mp_MEXGET > > > readinput.exe : fatal error LNK1120: 3 unresolved externals > > > > > > C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: Link of 'readinput.exe' failed. > > > > > > ??? Error using ==> mex at 207 > > > Unable to complete successfully. > > > > > > > > > As you mentioned before, is this possible to build a mexFunction routine instead in order to do the work? I have no idea how to do that and I would love to be advised. > > > > > > Thanks, > > > Hieu > > > > Hi. My bad. I should have been more explicit. For a PROGRAM (also known as an engine application as far as the build process is concerned) you cannot have *any* mex routines in the build. So do not include the 'MatlabAPImex.obj' file in your build. I had that included in my earlier post because I mistakenly assumed you were building a mexFunction routine, which you were not. The mex command should be: > > > > mex('-f', options,'readinput.f90','MatlabAPImx.obj','MatlabAPImat.obj') > > > > See if that works. > > > > @ James Tursa: Thank you. I also tried that mex command before (i.e without matlabAPImex.obj). It does compile but when I run the exe with the bang operator > !readinput.exe > nothing happens. > when I tried to run the exe at a windows command prompt it returns the following runtime error: > Severe: > MATLAB:I18n:MissingICUdata - ICU data not found. > The program '...' has excited with code 2 (0x2) > > Have you ever encountered this error? I am running XP pro 32bit. The input file test.mat (holding a simple 3d array) is in the same folder. > Hieu Hmmm ... both files I posted work fine with Intel 10.0 WinXP 32-bit. I ran them before posting them. I am not sure what could be different with Intel 11.0. I don't have that compiler to test with. The only thing I could guess at is that not all of the necessary libraries have been linked in. Maybe you could compare the opts.bat files for Intel 10.0 and Intel 11.0 to see what might be missing. Have you tried the mexFunction file yet? James Tursa
From: HIEU on 28 Dec 2009 19:49 > Hmmm ... both files I posted work fine with Intel 10.0 WinXP 32-bit. I ran them before posting them. I am not sure what could be different with Intel 11.0. I don't have that compiler to test with. The only thing I could guess at is that not all of the necessary libraries have been linked in. Maybe you could compare the opts.bat files for Intel 10.0 and Intel 11.0 to see what might be missing. Have you tried the mexFunction file yet? > > James Tursa Dear James, I tried the mex file, it compiled but when I ran it with: >> A = floor(rand(3,3,3)*99); >> passtest(A) I got: ??? Invalid MEX-file 'C:\Fortran\passtest.mexw32': The specified procedure could not be found. I will older Matlab version and see if the readinput program works. Thanks, Hieu
From: James Tursa on 29 Dec 2009 02:44
"HIEU " <nguyenhuyhieu(a)gmail.com> wrote in message <hhbjm1$r6o$1(a)fred.mathworks.com>... > > I tried the mex file, it compiled but when I ran it with: > >> A = floor(rand(3,3,3)*99); > >> passtest(A) > > I got: > ??? Invalid MEX-file 'C:\Fortran\passtest.mexw32': The specified procedure could not be found. That message is typical when you compile a mex routine with one version of MATLAB and try to run it under another version, indicating some type of mismatch in the interface. Are you compiling and running with the same version? James Tursa |