<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DEFINED OPERATORS/INTERFACE in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930974#M14788</link>
    <description>Hi Paul, &lt;BR /&gt; &lt;BR /&gt;INTERFACE block is function &lt;I&gt;declaration&lt;/I&gt;, i.e. the place where you tell compiler how the specific function is called; the same holds for INTERFACE OPERATOR - you tell compiler to "replace" operator .BAR. in the current procedure with a specific function. The &lt;I&gt;definition&lt;/I&gt;, i.e. the body of the function is somewhere else.  &lt;BR /&gt; &lt;BR /&gt;So, in non-MODULE style of programming, INTERFACE OPERATOR should be placed in the declaration part of the routine that uses the operator .BAR. &lt;BR /&gt;If it's needed in several places, you can put it in an INCLUDE (.fi) file. &lt;BR /&gt;FUNCTION BAR itself can be placed in any source file of the project. &lt;BR /&gt; &lt;BR /&gt;Otherwise, if you put function BAR in a module, the INTERFACE OPERATOR should be placed in declaration part of the module (above CONTAINS statement). The full description in the INTERFACE is not needed; use MODULE PROCEDURE instead: &lt;BR /&gt; &lt;BR /&gt;&lt;PRE&gt; 
 
MODULE FOO 
 
INTERFACE OPERATOR (.BAR.) 
MODULE PROCEDURE BAR 
END INTERFACE 
 
CONTAINS 
 
FUNCTION BAR(A_1) 
...(do something) 
END FUNCTION BAR 
 
END MODULE FOO 
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;HTH  &lt;BR /&gt;Jugoslav</description>
    <pubDate>Mon, 11 Dec 2000 19:49:30 GMT</pubDate>
    <dc:creator>Jugoslav_Dujic</dc:creator>
    <dc:date>2000-12-11T19:49:30Z</dc:date>
    <item>
      <title>DEFINED OPERATORS/INTERFACE</title>
      <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930973#M14787</link>
      <description>The examples of how to define your own binary operator in the &lt;BR /&gt;language reference (example operators .BAR. and  "+") omit to show &lt;BR /&gt;where you put the executable lines of code that perform the &lt;BR /&gt;function (section 8.9.4). I have tried placing the executable lines of &lt;BR /&gt;code in every conceivable place &lt;BR /&gt; &lt;BR /&gt; (e.g. between "FUNCTION MYFUNC(A,B)"    &lt;BR /&gt;               and  "END FUNCTION MYFUNC" ,  which seems logical) &lt;BR /&gt; &lt;BR /&gt;but the compiler kicks it out or says I haven't defined the operator. &lt;BR /&gt; &lt;BR /&gt;Lets look at the .BAR. example provided: &lt;BR /&gt; &lt;BR /&gt;     INTERFACE OPERATOR(.BAR.) &lt;BR /&gt;     FUNCTION BAR(A_1) &lt;BR /&gt;     INTEGER, INTENT(IN) :: A_1 &lt;BR /&gt;     INTEGER :: BAR &lt;BR /&gt;     END FUNCTION BAR &lt;BR /&gt;     END INTERFACE &lt;BR /&gt; &lt;BR /&gt;Then it is said you invoke the function when you write &lt;BR /&gt; &lt;BR /&gt;     I=4 + (.BAR.B) &lt;BR /&gt; &lt;BR /&gt;But nowhere is it defined what .BAR. does! &lt;BR /&gt; &lt;BR /&gt;Does it square B? Does it do a 1's complement of B? &lt;BR /&gt; &lt;BR /&gt;There has a place to put the executable code that defines what it &lt;BR /&gt;does, but the compiler will not accept executable code in an &lt;BR /&gt;INTERFACE block, only declarations. &lt;BR /&gt; &lt;BR /&gt;Can anyone provide a clue? &lt;BR /&gt; &lt;BR /&gt;Thanks, &lt;BR /&gt;             Paul Dent</description>
      <pubDate>Sun, 10 Dec 2000 01:19:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930973#M14787</guid>
      <dc:creator>paulw</dc:creator>
      <dc:date>2000-12-10T01:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: DEFINED OPERATORS/INTERFACE</title>
      <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930974#M14788</link>
      <description>Hi Paul, &lt;BR /&gt; &lt;BR /&gt;INTERFACE block is function &lt;I&gt;declaration&lt;/I&gt;, i.e. the place where you tell compiler how the specific function is called; the same holds for INTERFACE OPERATOR - you tell compiler to "replace" operator .BAR. in the current procedure with a specific function. The &lt;I&gt;definition&lt;/I&gt;, i.e. the body of the function is somewhere else.  &lt;BR /&gt; &lt;BR /&gt;So, in non-MODULE style of programming, INTERFACE OPERATOR should be placed in the declaration part of the routine that uses the operator .BAR. &lt;BR /&gt;If it's needed in several places, you can put it in an INCLUDE (.fi) file. &lt;BR /&gt;FUNCTION BAR itself can be placed in any source file of the project. &lt;BR /&gt; &lt;BR /&gt;Otherwise, if you put function BAR in a module, the INTERFACE OPERATOR should be placed in declaration part of the module (above CONTAINS statement). The full description in the INTERFACE is not needed; use MODULE PROCEDURE instead: &lt;BR /&gt; &lt;BR /&gt;&lt;PRE&gt; 
 
MODULE FOO 
 
INTERFACE OPERATOR (.BAR.) 
MODULE PROCEDURE BAR 
END INTERFACE 
 
CONTAINS 
 
FUNCTION BAR(A_1) 
...(do something) 
END FUNCTION BAR 
 
END MODULE FOO 
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;HTH  &lt;BR /&gt;Jugoslav</description>
      <pubDate>Mon, 11 Dec 2000 19:49:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930974#M14788</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2000-12-11T19:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: DEFINED OPERATORS/INTERFACE</title>
      <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930975#M14789</link>
      <description>Thanks for your input Jugoslav. What you suggest does work, but only &lt;BR /&gt;when the function and the operator are defined to operate on standard &lt;BR /&gt;variable types, and does not work for user-defined variable type. &lt;BR /&gt;I e-mailed you the following example, where all I did was change the &lt;BR /&gt; variable type from REAL A(2) to  &lt;BR /&gt; &lt;BR /&gt;  TYPE ARRAY2 &lt;BR /&gt;  REAL C(2) &lt;BR /&gt;  END TYPE ARRAY2 &lt;BR /&gt;  TYPE(ARRAY2) A,B &lt;BR /&gt; &lt;BR /&gt;Here is the programme that works: &lt;BR /&gt; &lt;BR /&gt;C*************MAIN PROGRAM******************** &lt;BR /&gt;C****DEFINE OPERATOR INTERFACE***** &lt;BR /&gt;	INTERFACE OPERATOR(.MULT.) &lt;BR /&gt;	FUNCTION MUL(A,B) &lt;BR /&gt;	REAL,INTENT(IN) :: A(2),B(2) &lt;BR /&gt;                REAL MUL(2) &lt;BR /&gt;	END FUNCTION MUL &lt;BR /&gt;	END INTERFACE &lt;BR /&gt;                REAL A(2),B(2),X(2) &lt;BR /&gt;                A(1)=1.0 &lt;BR /&gt;	A(2)=0.5 &lt;BR /&gt;	B(1)=2.0 &lt;BR /&gt;	B(2)=0.6 &lt;BR /&gt;C USE THE OPERATOR &lt;BR /&gt;	X=A.MULT.B &lt;BR /&gt;C AND PRINT THE RESULT WHICH SHOULD BE 2.0, -0.3 &lt;BR /&gt;	WRITE(*,*)X &lt;BR /&gt;	STOP &lt;BR /&gt;	END &lt;BR /&gt;C**CODE THAT IMPLEMENTS THE OPERATOR .MULT.*** &lt;BR /&gt;                FUNCTION MUL(A,B) &lt;BR /&gt;	REAL A(2),B(2),MUL(2),X(2) &lt;BR /&gt;                X(1)=A(1)*B(1) &lt;BR /&gt;	X(2)=-A(2)*B(2) &lt;BR /&gt;	MUL=X &lt;BR /&gt;	END FUNCTION MUL &lt;BR /&gt; &lt;BR /&gt;and here is the version that does not compile: &lt;BR /&gt; &lt;BR /&gt;C*******************MAIN PROGRAM******************** &lt;BR /&gt;C**DECLARE SOME VARIABLES OF A USER-DEFINED TYPE** &lt;BR /&gt;	TYPE ARRAY2 &lt;BR /&gt;	REAL C(2) &lt;BR /&gt;	END TYPE ARRAY2 &lt;BR /&gt;                TYPE(ARRAY2) A,B,X &lt;BR /&gt;C**DECLARE THE INTERFACE FOR THE OEPRATOR .MULT.*** &lt;BR /&gt;	INTERFACE OPERATOR(.MULT.) &lt;BR /&gt;	FUNCTION MUL(A,B) &lt;BR /&gt;	TYPE ARRAY2 &lt;BR /&gt;	REAL C(2) &lt;BR /&gt;	END TYPE ARRAY2 &lt;BR /&gt;	TYPE(ARRAY2),INTENT(IN) :: A,B &lt;BR /&gt;	TYPE(ARRAY2) MUL &lt;BR /&gt;	END FUNCTION MUL &lt;BR /&gt;	END INTERFACE &lt;BR /&gt;C***NOW TRY TO USE THE DEFINED OPERATOR*** &lt;BR /&gt;                A.C(1)=1.0 &lt;BR /&gt;	A.C(2)=0.5 &lt;BR /&gt;	B.C(1)=2.0 &lt;BR /&gt;	B.C(2)=0.6 &lt;BR /&gt;	X=A.MULT.B &lt;BR /&gt;	WRITE(*,*)X &lt;BR /&gt;	STOP &lt;BR /&gt;	END &lt;BR /&gt;C**CODE THAT IMPLEMENTS THE OPERATOR .MULT.*** &lt;BR /&gt;                FUNCTION MUL(A,B) &lt;BR /&gt;	TYPE ARRAY2 &lt;BR /&gt;	REAL C(2) &lt;BR /&gt;	END TYPE ARRAY2 &lt;BR /&gt;	TYPE(ARRAY2) A,B,MUL,X &lt;BR /&gt;                X.C(1)=A.C(1)*B.C(1) &lt;BR /&gt;	X.C(2)=-A.C(2)*B.C(2) &lt;BR /&gt;	MUL=X &lt;BR /&gt;	END FUNCTION MUL &lt;BR /&gt; &lt;BR /&gt;Surely the compiler lets us define operators for operating on user &lt;BR /&gt;defined types? That's the whole point! What am I missing? &lt;BR /&gt; &lt;BR /&gt;Paul</description>
      <pubDate>Tue, 12 Dec 2000 14:36:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930975#M14789</guid>
      <dc:creator>paulw</dc:creator>
      <dc:date>2000-12-12T14:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: DEFINED OPERATORS/INTERFACE</title>
      <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930976#M14790</link>
      <description>Hi Paul, &lt;BR /&gt;The source you posted is &lt;I&gt;almost&lt;/I&gt; good; I thought it would have worked, but it didn't. The problem is in the scope of declaration of type ARRAY2; it isn't "seen" the same within PROGRAM and INTERFACE. Here's the correct code that works (it looks as if the MODULEs have to be involved; but then, generic operators are also Fortran-90 stuff). Perhaps someone more versed in standards issues might explain why the code you posted does not work: &lt;BR /&gt; &lt;BR /&gt;&lt;PRE&gt; 
MODULE OVRMOD 
 
TYPE ARRAY2  
REAL C(2)  
END TYPE ARRAY2  
 
END MODULE OVRMOD 
!=============================== 
PROGRAM OVERLOAD 
USE OVRMOD 
 
TYPE(ARRAY2) A,B,X  
 
!**DECLARE THE INTERFACE FOR THE OEPRATOR .MULT.***  
INTERFACE OPERATOR (.MULT.)  
   FUNCTION MUL(A,B) RESULT(F)  
   USE OVRMOD 
   TYPE(ARRAY2),INTENT(IN) :: A,B  
   TYPE(ARRAY2) F  
   END FUNCTION MUL  
END INTERFACE  
!***NOW TRY TO USE THE DEFINED OPERATOR***  
A.C(1)=1.0  
A.C(2)=0.5  
B.C(1)=2.0  
B.C(2)=0.6  
X=A.MULT.B 
  
WRITE(*,*)X  
STOP  
END  
!=============================== 
FUNCTION MUL(A,B) RESULT(F)  
USE OVRMOD 
 
TYPE(ARRAY2),INTENT(IN) :: A,B  
TYPE(ARRAY2) F 
 
DO I=1,2 
   F.C(I)=A.C(I)*B.C(I) 
END DO 
 
END FUNCTION MUL  
 
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;Regards &lt;BR /&gt; &lt;BR /&gt;Jugoslav</description>
      <pubDate>Wed, 13 Dec 2000 01:30:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930976#M14790</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2000-12-13T01:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: DEFINED OPERATORS/INTERFACE</title>
      <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930977#M14791</link>
      <description>Thanks for your help, Jugoslav.  It works now - why it is essential to use &lt;BR /&gt;the MODULE construction is a puzzle, and it is very fussy about the order &lt;BR /&gt;of things.  &lt;BR /&gt; &lt;BR /&gt;My next problem is that I can write user defined operators for doing &lt;BR /&gt;arithmetic on user defined types that work one a time, i.e I can write &lt;BR /&gt; &lt;BR /&gt;    F=A*B &lt;BR /&gt;    F=A+B &lt;BR /&gt;    F=A-B &lt;BR /&gt;    F=F+A   etc &lt;BR /&gt;and they all work according to the function definitions I have provided &lt;BR /&gt; &lt;BR /&gt;However, if I write &lt;BR /&gt; &lt;BR /&gt;   F=A*B+C &lt;BR /&gt; &lt;BR /&gt;which I hoped to do, or even &lt;BR /&gt; &lt;BR /&gt;  F = (A*B)+C &lt;BR /&gt; &lt;BR /&gt;I get garbage, and the reason seems to be that the compiler is not &lt;BR /&gt;allocating the right "shape"  of storage for the intermediate result of A*B &lt;BR /&gt; &lt;BR /&gt;Do you know if one is supposed to be able to write expressions of &lt;BR /&gt;any complexity, with nested parentheses etc with user-defined &lt;BR /&gt;operators, or not? &lt;BR /&gt; &lt;BR /&gt;Thanks, &lt;BR /&gt;             Paul</description>
      <pubDate>Wed, 13 Dec 2000 11:50:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930977#M14791</guid>
      <dc:creator>paulw</dc:creator>
      <dc:date>2000-12-13T11:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: DEFINED OPERATORS/INTERFACE</title>
      <link>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930978#M14792</link>
      <description>Derived type definitions have to either come from the same source (USE or host association) or be SEQUENCE derived types and be otherwise identical.  It seems to me much simpler to define the type in a module and use the module where the type is required; you don't have to maintain several identical derived type definitions throughout your code.  Look in the online docs under Derived type statement, Rules and Behavior.  The problem you may be having with statements like F = A*B+C is that the output of your binary multiplication operator isn't the same as the left input to your addition operator.  This should give you errors at compile time rather than garbage, however.  Now, if the object in question are arrays rather than derived types, you could have a problem if the lengths aren't conformable.  You could check this possibility by making the inputs assumed shape arrays and then comparing their lengths within the function.</description>
      <pubDate>Fri, 15 Dec 2000 19:51:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/DEFINED-OPERATORS-INTERFACE/m-p/930978#M14792</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2000-12-15T19:51:39Z</dc:date>
    </item>
  </channel>
</rss>

