<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164128</link>
    <title>MATLAB Central Newsreader - MEX EXAMPLE not working .. URGENT please</title>
    <description>Feed for thread: MEX EXAMPLE not working .. URGENT please</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 19 Feb 2008 22:37:03 -0500</pubDate>
      <title>MEX EXAMPLE not working .. URGENT please</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164128#416186</link>
      <author>Charan </author>
      <description>I am a newbie to MEX functions. &lt;br&gt;
I got Fortran 9.1 and selected it using &quot;mex -setup&quot;&lt;br&gt;
&lt;br&gt;
then i tried to compile the example in this link &lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/index.&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/index.&lt;/a&gt;&lt;br&gt;
html?/access/helpdesk/help/techdoc/matlab_external/f21779.ht&lt;br&gt;
ml&amp;&lt;a href=&quot;http://www.google.com/search?&quot;&gt;http://www.google.com/search?&lt;/a&gt;&lt;br&gt;
hl=en&amp;q=mex+fortran+sample+code&lt;br&gt;
&lt;br&gt;
But I get an error. what should I do?&lt;br&gt;
&lt;br&gt;
the error I get is as follows&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; mex timestwo.f&lt;br&gt;
ifort: Command line warning: /fp:precise evaluates in &lt;br&gt;
source precision with Fortran. &lt;br&gt;
fortcom: Error: Illegal character in statement label field  &lt;br&gt;
[m] &lt;br&gt;
fortcom: Error: Illegal character in statement label field  &lt;br&gt;
[e] &lt;br&gt;
fortcom: Error: Illegal character in statement label field  &lt;br&gt;
[x] &lt;br&gt;
fortcom: Error: Illegal character in statement label field  &lt;br&gt;
[t] &lt;br&gt;
fortcom: Error: First statement in file must not be &lt;br&gt;
continued &lt;br&gt;
timestwo.f(1) : Error: Syntax error, found POUND_BASE '' &lt;br&gt;
when expecting one of: =&amp;gt; = / . ( :: , &amp;lt;END-OF-&lt;br&gt;
STATEMENT&amp;gt; ; : ) % &lt;br&gt;
mex timestwo.F#include &quot;fintrf.h&quot; &lt;br&gt;
--------------^ &lt;br&gt;
timestwo.f(21) : Error: Syntax error, found ',' when &lt;br&gt;
expecting one of: =&amp;gt; = . ( % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer plhs(*), prhs(*) &lt;br&gt;
-----------------------^ &lt;br&gt;
timestwo.f(22) : Error: Syntax error, found ',' when &lt;br&gt;
expecting one of: =&amp;gt; = . ( : % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer mxGetPr, mxCreateDoubleMatrix &lt;br&gt;
-----------------------^ &lt;br&gt;
timestwo.f(23) : Error: Syntax error, found ',' when &lt;br&gt;
expecting one of: =&amp;gt; = . ( : % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer x_pr, y_pr &lt;br&gt;
--------------------^ &lt;br&gt;
timestwo.f(28) : Error: Syntax error, found ',' when &lt;br&gt;
expecting one of: =&amp;gt; = . ( : % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwsize mxGetM, mxGetN &lt;br&gt;
-------------------^ &lt;br&gt;
timestwo.f(29) : Error: Syntax error, found ',' when &lt;br&gt;
expecting one of: =&amp;gt; = . ( : % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwsize m, n, size &lt;br&gt;
--------------^ &lt;br&gt;
timestwo.f(27) : Error: A specification statement cannot &lt;br&gt;
appear in the executable section. &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;integer nlhs, nrhs, mxIsNumeric &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(29) : Error: A specification statement cannot &lt;br&gt;
appear in the executable section. &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwsize m, n, size &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(30) : Error: A specification statement cannot &lt;br&gt;
appear in the executable section. &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;real*8  x, y &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(21) : Error: Object is not a pointer object   &lt;br&gt;
[MWPOINTERPLHS] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer plhs(*), prhs(*) &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(22) : Error: The POINTER attribute is required   &lt;br&gt;
[MWPOINTERMXGETPR] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer mxGetPr, mxCreateDoubleMatrix &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(22) : Error: The variable must have the TARGET &lt;br&gt;
attribute or be a subobject of an object with the TARGET &lt;br&gt;
attribute, or it must have the POINTER attribute.   &lt;br&gt;
[MXCREATEDOUBLEMATRIX] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer mxGetPr, mxCreateDoubleMatrix &lt;br&gt;
-------------------------^ &lt;br&gt;
timestwo.f(23) : Error: The POINTER attribute is required   &lt;br&gt;
[MWPOINTERX_PR] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer x_pr, y_pr &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(23) : Error: The variable must have the TARGET &lt;br&gt;
attribute or be a subobject of an object with the TARGET &lt;br&gt;
attribute, or it must have the POINTER attribute.   [Y_PR] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwpointer x_pr, y_pr &lt;br&gt;
----------------------^ &lt;br&gt;
timestwo.f(28) : Error: The POINTER attribute is required   &lt;br&gt;
[MWSIZEMXGETM] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwsize mxGetM, mxGetN &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(28) : Error: The variable must have the TARGET &lt;br&gt;
attribute or be a subobject of an object with the TARGET &lt;br&gt;
attribute, or it must have the POINTER attribute.   &lt;br&gt;
[MXGETN] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mwsize mxGetM, mxGetN &lt;br&gt;
---------------------^ &lt;br&gt;
timestwo.f(41) : Error: This name has not been declared as &lt;br&gt;
an array or a function.   [MXGETN] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n = mxGetN(prhs(1)) &lt;br&gt;
----------^ &lt;br&gt;
timestwo.f(50) : Error: This name has not been declared as &lt;br&gt;
an array or a function.   [PLHS] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;plhs(1) = mxCreateDoubleMatrix(m,n,0) &lt;br&gt;
------^ &lt;br&gt;
timestwo.f(50) : Error: This name has not been declared as &lt;br&gt;
an array or a function.   [MXCREATEDOUBLEMATRIX] &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;plhs(1) = mxCreateDoubleMatrix(m,n,0) &lt;br&gt;
----------------^ &lt;br&gt;
compilation aborted for timestwo.f (code 1) &lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;C:\PROGRA~1\MATLAB\R2007B\BIN\MEX.PL: Error: Compile &lt;br&gt;
of 'timestwo.f' failed. </description>
    </item>
    <item>
      <pubDate>Tue, 19 Feb 2008 22:46:14 -0500</pubDate>
      <title>Re: MEX EXAMPLE not working .. URGENT please</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164128#416189</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;fpflmf$6nl$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
Charan  &amp;lt;boyacharan@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;I am a newbie to MEX functions. &lt;br&gt;
&amp;gt;I got Fortran 9.1 and selected it using &quot;mex -setup&quot;&lt;br&gt;
&lt;br&gt;
&amp;gt;then i tried to compile the example in this link &lt;br&gt;
&lt;br&gt;
&amp;gt;&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/index.&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/index.&lt;/a&gt;&lt;br&gt;
&amp;gt;html?/access/helpdesk/help/techdoc/matlab_external/f21779.ht&lt;br&gt;
&amp;gt;ml&amp;&lt;a href=&quot;http://www.google.com/search?&quot;&gt;http://www.google.com/search?&lt;/a&gt;&lt;br&gt;
&amp;gt;hl=en&amp;q=mex+fortran+sample+code&lt;br&gt;
&lt;br&gt;
&amp;gt;But I get an error. what should I do?&lt;br&gt;
&lt;br&gt;
&amp;gt;the error I get is as follows&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; mex timestwo.f&lt;br&gt;
&lt;br&gt;
&amp;gt;timestwo.f(1) : Error: Syntax error, found POUND_BASE '' &lt;br&gt;
&amp;gt;when expecting one of: =&amp;gt; = / . ( :: , &amp;lt;END-OF-&lt;br&gt;
&amp;gt;STATEMENT&amp;gt; ; : ) % &lt;br&gt;
&amp;gt;mex timestwo.F#include &quot;fintrf.h&quot; &lt;br&gt;
&lt;br&gt;
Please check the content of timestwo.f . Somehow the compiler&lt;br&gt;
is seeing C code, not Fortran code.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&quot;I will not approve any plan which is based on the old principle&lt;br&gt;
&amp;nbsp;&amp;nbsp;of build now and repair later.&quot;                   -- Walter Hickle</description>
    </item>
    <item>
      <pubDate>Wed, 20 Feb 2008 00:33:07 -0500</pubDate>
      <title>Re: MEX EXAMPLE not working .. URGENT please</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164128#416203</link>
      <author>James Tursa</author>
      <description>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in &lt;br&gt;
message &amp;lt;fpfm7m$24q$1@canopus.cc.umanitoba.ca&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please check the content of timestwo.f . Somehow the &lt;br&gt;
compiler&lt;br&gt;
&amp;gt; is seeing C code, not Fortran code.&lt;br&gt;
&lt;br&gt;
No. The mwpointer stuff is definitely Fortran, not C. I &lt;br&gt;
will go check my version of timestwo.f and try compiling &lt;br&gt;
it with Intel 9.1 ....&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Wed, 20 Feb 2008 00:49:08 -0500</pubDate>
      <title>Re: MEX EXAMPLE not working .. URGENT please</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164128#416206</link>
      <author>James Tursa</author>
      <description>&lt;br&gt;
timestwo.F works fine for my R2007a and Intel 9.1. It may &lt;br&gt;
be that you are using an older version of MATLAB where the &lt;br&gt;
header file fintrf.h does not define mwpointer or mwsize &lt;br&gt;
(they used to be just integer*4). So after the &lt;br&gt;
#include &quot;fintrf.h&quot; line, add these lines:&lt;br&gt;
&lt;br&gt;
#ifndef mwpointer&lt;br&gt;
#define mwpointer integer*4&lt;br&gt;
#endif&lt;br&gt;
&lt;br&gt;
#ifndef mwsize&lt;br&gt;
#define mwsize integer*4&lt;br&gt;
#endif&lt;br&gt;
&lt;br&gt;
That way, if they are not defined then your code will &lt;br&gt;
define them before using them.&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Wed, 20 Feb 2008 01:21:11 -0500</pubDate>
      <title>Re: MEX EXAMPLE not working .. URGENT please</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164128#416210</link>
      <author>James Tursa</author>
      <description>&quot;James Tursa&quot; &amp;lt;aclassyguywithaknotac@hotmail.com&amp;gt; wrote in &lt;br&gt;
message &amp;lt;fpfte4$a1j$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; timestwo.F works fine for my R2007a and Intel 9.1. It &lt;br&gt;
may &lt;br&gt;
&amp;gt; be that you are using an older version of MATLAB where &lt;br&gt;
the &lt;br&gt;
&amp;gt; header file fintrf.h does not define mwpointer or mwsize &lt;br&gt;
&amp;gt; (they used to be just integer*4). So after the &lt;br&gt;
&amp;gt; #include &quot;fintrf.h&quot; line, add these lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; #ifndef mwpointer&lt;br&gt;
&amp;gt; #define mwpointer integer*4&lt;br&gt;
&amp;gt; #endif&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; #ifndef mwsize&lt;br&gt;
&amp;gt; #define mwsize integer*4&lt;br&gt;
&amp;gt; #endif&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; That way, if they are not defined then your code will &lt;br&gt;
&amp;gt; define them before using them.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; James Tursa&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Follow-up:  The code works, but only if the input is a &lt;br&gt;
scalar. The code has bugs for other sizes. In particular, &lt;br&gt;
this line:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;call mxCopyPtrToReal8(x_pr,x,size)&lt;br&gt;
&lt;br&gt;
will cause memory beyond x (which is only one element with &lt;br&gt;
8 bytes) to be overwritten with whatever x_pr is pointing &lt;br&gt;
to. Something is being clobbered here, and this will cause &lt;br&gt;
unpredictable results.&lt;br&gt;
&lt;br&gt;
Also, from a good practise standpoint, &quot;size&quot; should not &lt;br&gt;
be used as a variable name since it is the name of a &lt;br&gt;
Fortran intrinsic function.&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
  </channel>
</rss>

