Thread Subject: MEX EXAMPLE not working .. URGENT please

Subject: MEX EXAMPLE not working .. URGENT please

From: Charan

Date: 19 Feb, 2008 22:37:03

Message: 1 of 5

I am a newbie to MEX functions.
I got Fortran 9.1 and selected it using "mex -setup"

then i tried to compile the example in this link

http://www.mathworks.com/access/helpdesk/help/techdoc/index.
html?/access/helpdesk/help/techdoc/matlab_external/f21779.ht
ml&http://www.google.com/search?
hl=en&q=mex+fortran+sample+code

But I get an error. what should I do?

the error I get is as follows

>> mex timestwo.f
ifort: Command line warning: /fp:precise evaluates in
source precision with Fortran.
fortcom: Error: Illegal character in statement label field
[m]
fortcom: Error: Illegal character in statement label field
[e]
fortcom: Error: Illegal character in statement label field
[x]
fortcom: Error: Illegal character in statement label field
[t]
fortcom: Error: First statement in file must not be
continued
timestwo.f(1) : Error: Syntax error, found POUND_BASE ''
when expecting one of: => = / . ( :: , <END-OF-
STATEMENT> ; : ) %
mex timestwo.F#include "fintrf.h"
--------------^
timestwo.f(21) : Error: Syntax error, found ',' when
expecting one of: => = . ( %
      mwpointer plhs(*), prhs(*)
-----------------------^
timestwo.f(22) : Error: Syntax error, found ',' when
expecting one of: => = . ( : %
      mwpointer mxGetPr, mxCreateDoubleMatrix
-----------------------^
timestwo.f(23) : Error: Syntax error, found ',' when
expecting one of: => = . ( : %
      mwpointer x_pr, y_pr
--------------------^
timestwo.f(28) : Error: Syntax error, found ',' when
expecting one of: => = . ( : %
      mwsize mxGetM, mxGetN
-------------------^
timestwo.f(29) : Error: Syntax error, found ',' when
expecting one of: => = . ( : %
      mwsize m, n, size
--------------^
timestwo.f(27) : Error: A specification statement cannot
appear in the executable section.
      integer nlhs, nrhs, mxIsNumeric
------^
timestwo.f(29) : Error: A specification statement cannot
appear in the executable section.
      mwsize m, n, size
------^
timestwo.f(30) : Error: A specification statement cannot
appear in the executable section.
      real*8 x, y
------^
timestwo.f(21) : Error: Object is not a pointer object
[MWPOINTERPLHS]
      mwpointer plhs(*), prhs(*)
------^
timestwo.f(22) : Error: The POINTER attribute is required
[MWPOINTERMXGETPR]
      mwpointer mxGetPr, mxCreateDoubleMatrix
------^
timestwo.f(22) : Error: The variable must have the TARGET
attribute or be a subobject of an object with the TARGET
attribute, or it must have the POINTER attribute.
[MXCREATEDOUBLEMATRIX]
      mwpointer mxGetPr, mxCreateDoubleMatrix
-------------------------^
timestwo.f(23) : Error: The POINTER attribute is required
[MWPOINTERX_PR]
      mwpointer x_pr, y_pr
------^
timestwo.f(23) : Error: The variable must have the TARGET
attribute or be a subobject of an object with the TARGET
attribute, or it must have the POINTER attribute. [Y_PR]
      mwpointer x_pr, y_pr
----------------------^
timestwo.f(28) : Error: The POINTER attribute is required
[MWSIZEMXGETM]
      mwsize mxGetM, mxGetN
------^
timestwo.f(28) : Error: The variable must have the TARGET
attribute or be a subobject of an object with the TARGET
attribute, or it must have the POINTER attribute.
[MXGETN]
      mwsize mxGetM, mxGetN
---------------------^
timestwo.f(41) : Error: This name has not been declared as
an array or a function. [MXGETN]
      n = mxGetN(prhs(1))
----------^
timestwo.f(50) : Error: This name has not been declared as
an array or a function. [PLHS]
      plhs(1) = mxCreateDoubleMatrix(m,n,0)
------^
timestwo.f(50) : Error: This name has not been declared as
an array or a function. [MXCREATEDOUBLEMATRIX]
      plhs(1) = mxCreateDoubleMatrix(m,n,0)
----------------^
compilation aborted for timestwo.f (code 1)
 
  C:\PROGRA~1\MATLAB\R2007B\BIN\MEX.PL: Error: Compile
of 'timestwo.f' failed.

Subject: MEX EXAMPLE not working .. URGENT please

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 19 Feb, 2008 22:46:14

Message: 2 of 5

In article <fpflmf$6nl$1@fred.mathworks.com>,
Charan <boyacharan@gmail.com> wrote:
>I am a newbie to MEX functions.
>I got Fortran 9.1 and selected it using "mex -setup"

>then i tried to compile the example in this link

>http://www.mathworks.com/access/helpdesk/help/techdoc/index.
>html?/access/helpdesk/help/techdoc/matlab_external/f21779.ht
>ml&http://www.google.com/search?
>hl=en&q=mex+fortran+sample+code

>But I get an error. what should I do?

>the error I get is as follows

>>> mex timestwo.f

>timestwo.f(1) : Error: Syntax error, found POUND_BASE ''
>when expecting one of: => = / . ( :: , <END-OF-
>STATEMENT> ; : ) %
>mex timestwo.F#include "fintrf.h"

Please check the content of timestwo.f . Somehow the compiler
is seeing C code, not Fortran code.
--
  "I will not approve any plan which is based on the old principle
  of build now and repair later." -- Walter Hickle

Subject: MEX EXAMPLE not working .. URGENT please

From: James Tursa

Date: 20 Feb, 2008 00:33:07

Message: 3 of 5

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fpfm7m$24q$1@canopus.cc.umanitoba.ca>...
>
> Please check the content of timestwo.f . Somehow the
compiler
> is seeing C code, not Fortran code.

No. The mwpointer stuff is definitely Fortran, not C. I
will go check my version of timestwo.f and try compiling
it with Intel 9.1 ....

James Tursa

Subject: MEX EXAMPLE not working .. URGENT please

From: James Tursa

Date: 20 Feb, 2008 00:49:08

Message: 4 of 5


timestwo.F works fine for my R2007a and Intel 9.1. It may
be that you are using an older version of MATLAB where the
header file fintrf.h does not define mwpointer or mwsize
(they used to be just integer*4). So after the
#include "fintrf.h" line, add these lines:

#ifndef mwpointer
#define mwpointer integer*4
#endif

#ifndef mwsize
#define mwsize integer*4
#endif

That way, if they are not defined then your code will
define them before using them.

James Tursa

Subject: MEX EXAMPLE not working .. URGENT please

From: James Tursa

Date: 20 Feb, 2008 01:21:11

Message: 5 of 5

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fpfte4$a1j$1@fred.mathworks.com>...
>
> timestwo.F works fine for my R2007a and Intel 9.1. It
may
> be that you are using an older version of MATLAB where
the
> header file fintrf.h does not define mwpointer or mwsize
> (they used to be just integer*4). So after the
> #include "fintrf.h" line, add these lines:
>
> #ifndef mwpointer
> #define mwpointer integer*4
> #endif
>
> #ifndef mwsize
> #define mwsize integer*4
> #endif
>
> That way, if they are not defined then your code will
> define them before using them.
>
> James Tursa
>

Follow-up: The code works, but only if the input is a
scalar. The code has bugs for other sizes. In particular,
this line:

      call mxCopyPtrToReal8(x_pr,x,size)

will cause memory beyond x (which is only one element with
8 bytes) to be overwritten with whatever x_pr is pointing
to. Something is being clobbered here, and this will cause
unpredictable results.

Also, from a good practise standpoint, "size" should not
be used as a variable name since it is the name of a
Fortran intrinsic function.

James Tursa


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mex example Charan 19 Feb, 2008 17:40:23
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com