<?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 I don't understand what it is in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947218#M91406</link>
    <description>I don't understand what it is that you are trying to achieve.  

Wrapping an integer component in a derived type with appropriate set and test (operator(==)) procedures is certainly one way to implement a strongly typed enumeration in Fortran.  There are some disadvantages - for example you can't use such an enumeration directly in a SELECT CASE construct.

(Your invoke procedure in your example code has a dummy argument (nnn2) that is a pointer - an explicit interface is required.)</description>
    <pubDate>Tue, 13 Nov 2012 19:44:30 GMT</pubDate>
    <dc:creator>IanH</dc:creator>
    <dc:date>2012-11-13T19:44:30Z</dc:date>
    <item>
      <title>Tagging in Fortran (like enum)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947214#M91402</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I would like to tag some pointers to some values, such a definition reminds me the enumeration type of C, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[cpp]&amp;nbsp;enum ctype { out, cut, in, sp};&amp;nbsp;[/cpp]&lt;/P&gt;
&lt;P&gt;and we have a&amp;nbsp;pointer (named as type_) that will be allocated for the values above:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[cpp]&amp;nbsp;ctype *type_;&amp;nbsp;&amp;nbsp;[/cpp]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;in a subroutine I try to tag a pointer such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[cpp]&lt;/P&gt;
&lt;P&gt;if(*nnn-&amp;gt;type_==out)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if(*nnn-&amp;gt;type_==cut)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if(*nnn-&amp;gt;type_==in)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if(*nnn-&amp;gt;type_==sp)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[/cpp]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;How can I rewrite the above tagging in Fortran, should I use &amp;nbsp;[fortran]&amp;nbsp;integer(selected_int_kind) &amp;nbsp;[/fortran]&amp;nbsp;or [fortran]&amp;nbsp;enum, bind(c) ctype&amp;nbsp;[/fortran] ? I try both of them but cannot figure out what is wrong... I will appreciate any contribution, suggestion about the problem. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2012 09:13:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947214#M91402</guid>
      <dc:creator>emreka82</dc:creator>
      <dc:date>2012-11-12T09:13:14Z</dc:date>
    </item>
    <item>
      <title>Are you interacting with C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947215#M91403</link>
      <description>Are you interacting with C code, or are you rewriting something in Fortran exclusively?

If you want an enumeration that lines up exactly with the values and storage that you get in C, then the syntax is:

[fortran]
ENUM, BIND(C)
  ENUMERATOR :: out, cut, in, sp
END ENUM
[/fortran]

Note that you don't name the enumeration, just the enumerators.  If you want the kind used for the enumerators, then you can just use KIND(out), or similar.

If you are just working in the Fortran world, then you could just declare the integer constants that are the enumerators directly.  Perhaps something like:

[fortran]
  INTEGER, PARAMETER :: ctype_kind = KIND(1)
  INTEGER(ctype_kind), PARAMETER :: out = 1
  INTEGER(ctype_kind), PARAMETER :: cut = 2
  INTEGER(ctype_kind), PARAMETER :: in = 3
  INTEGER(ctype_kind), PARAMETER :: sp = 4
[/fortran]

In the above, the kind for the enumeration is just default kind you could change that depending on your requirements.

Practically the two forms are often equivalent - the kind of a enumeration that interoperates with C may well be default kind.</description>
      <pubDate>Mon, 12 Nov 2012 23:09:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947215#M91403</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-11-12T23:09:00Z</dc:date>
    </item>
    <item>
      <title>Quote:IanH wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947216#M91404</link>
      <description>&lt;BLOCKQUOTE&gt;IanH wrote:&lt;BR /&gt;&lt;P&gt;
&lt;/P&gt;&lt;P&gt;If you are just working in the Fortran world, then you could just declare the integer constants that are the enumerators directly.  Perhaps something like:&lt;/P&gt;
&lt;P&gt;&lt;PRE class="brush: fortran"&gt;

  INTEGER, PARAMETER :: ctype_kind = KIND(1)

  INTEGER(ctype_kind), PARAMETER :: out = 1

  INTEGER(ctype_kind), PARAMETER :: cut = 2

  INTEGER(ctype_kind), PARAMETER :: in = 3

  INTEGER(ctype_kind), PARAMETER :: sp = 4

&lt;/PRE&gt;&lt;/P&gt;
&lt;P&gt;In the above, the kind for the enumeration is just default kind you could change that depending on your requirements.&lt;/P&gt;
&lt;P&gt;Practically the two forms are often equivalent - the kind of a enumeration that interoperates with C may well be default kind.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;

I think, second one is my choice, my code will be in Fortran. The most important part of my problem is the "CALL" part. I want to call the ctype_kind and tag it, such as:

[fortran]
if(nnn%type_==out) then
!...statements
end if

if(nnn%type_==cut) then
!...statements
end if

if(nnn%type_==in) then
!...statements
end if

if(nnn%type_==sp) then
!...statements
end if

[/fortran]

, where nnn is a pointer which points to a next pointer type_ and type_ has the enumerated values in, out, cut and sp.</description>
      <pubDate>Tue, 13 Nov 2012 07:14:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947216#M91404</guid>
      <dc:creator>emreka82</dc:creator>
      <dc:date>2012-11-13T07:14:00Z</dc:date>
    </item>
    <item>
      <title>Quote:emreka82 wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947217#M91405</link>
      <description>&lt;BLOCKQUOTE&gt;emreka82 wrote:&lt;BR /&gt;&lt;P&gt;&lt;STRONG&gt;Quote:&lt;/STRONG&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;EM&gt;IanH&lt;/EM&gt; wrote:
&lt;P&gt;If you are just working in the Fortran world, then you could just declare the integer constants that are the enumerators directly.  Perhaps something like:&lt;/P&gt;
&lt;P&gt;

  INTEGER, PARAMETER :: ctype_kind = KIND(1)

  INTEGER(ctype_kind), PARAMETER :: out = 1

  INTEGER(ctype_kind), PARAMETER :: cut = 2

  INTEGER(ctype_kind), PARAMETER :: in = 3

  INTEGER(ctype_kind), PARAMETER :: sp = 4

&lt;/P&gt;
&lt;P&gt;In the above, the kind for the enumeration is just default kind you could change that depending on your requirements.&lt;/P&gt;
&lt;P&gt;Practically the two forms are often equivalent - the kind of a enumeration that interoperates with C may well be default kind.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think, second one is my choice, my code will be in Fortran. The most important part of my problem is the "CALL" part. I want to call the ctype_kind and tag it, such as:&lt;/P&gt;
&lt;P&gt;&lt;PRE class="brush: fortran"&gt;

if(nnn%type_==out) then

!...statements

end if
if(nnn%type_==cut) then

!...statements

end if
if(nnn%type_==in) then

!...statements

end if
if(nnn%type_==sp) then

!...statements

end if
&lt;/PRE&gt;&lt;/P&gt;
&lt;P&gt;, where nnn is a pointer which points to a next pointer type_ and type_ has the enumerated values in, out, cut and sp.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;




I have written a module, a main program and two subroutines to clearly understand the problem, then I think I figure it out, can you check it ?

Module:

 [fortran]

module param_mod

type c_type
        integer :: val
end type c_type
    
    type(c_type), parameter   :: out=c_type(0), cut=c_type(1), sp=c_type(2), in=c_type(3)

type c

type(c_type), pointer  :: type_

end type c

interface operator(==) 
    module procedure operate
end interface

contains

logical function operate(a,b) 
      type(c_type), intent(in) :: a,b 
      operate = a%val.eq.b%val 
end function operate

end module param_mod

[/fortran]

Main program:

 [fortran]

    program param
    
    use param_mod
    
    call example
    
    call system('pause')  
    
    end program param

[/fortran]

Invoking subroutine:

 [fortran]
subroutine invoke(nnn2)
    use param_mod
    
    type(c), pointer    :: nnn2

    allocate(nnn2)

    allocate(nnn2%type_)
    
       
    nnn2%type_=cut
    
    
end subroutine invoke
 [/fortran]

Example subroutine:

 [fortran]

subroutine example
    
use param_mod

integer, target :: new

type(c), pointer :: nnn

allocate(nnn)

allocate(nnn%type_)

call invoke(nnn) ! here I tag the "nnn%type_" as "cut".

print*, nnn%type_ ! shows the value of the pointer

if(nnn%type_==out) then ! if nnn%type_= out, values are both 0

print*, "out"
!...statements

else if(nnn%type_==cut) then ! if nnn%type_= cut, values are both 1

print*, "cut"
!...statements

else if(nnn%type_==sp) then ! if nnn%type_= sp, values are both 2

print*, "sp"
!...statements


else  ! if nnn%type_= in, values are both 3

print*, "in"
!...statements

end if

    deallocate(nnn%type_)
    deallocate(nnn)

end subroutine example

 [/fortran]

As you can see above, I overload the operator ==, could the overloading result in any problem ? And do you have any suggestions for more clever and direct solution for the problem other than that above ? Thanks.</description>
      <pubDate>Tue, 13 Nov 2012 13:13:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947217#M91405</guid>
      <dc:creator>emreka82</dc:creator>
      <dc:date>2012-11-13T13:13:00Z</dc:date>
    </item>
    <item>
      <title>I don't understand what it is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947218#M91406</link>
      <description>I don't understand what it is that you are trying to achieve.  

Wrapping an integer component in a derived type with appropriate set and test (operator(==)) procedures is certainly one way to implement a strongly typed enumeration in Fortran.  There are some disadvantages - for example you can't use such an enumeration directly in a SELECT CASE construct.

(Your invoke procedure in your example code has a dummy argument (nnn2) that is a pointer - an explicit interface is required.)</description>
      <pubDate>Tue, 13 Nov 2012 19:44:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947218#M91406</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-11-13T19:44:30Z</dc:date>
    </item>
    <item>
      <title>Firstly, thanks for the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947219#M91407</link>
      <description>Firstly, thanks for the contribution Ian, you have been very helpful. I have some questions in my mind about your comments:

&lt;BLOCKQUOTE&gt;IanH wrote:&lt;BR /&gt;&lt;P&gt;I don't understand what it is that you are trying to achieve.  &lt;/P&gt;
&lt;P&gt;Wrapping an integer component in a derived type with appropriate set and test (operator(==)) procedures is certainly one way to implement a strongly typed enumeration in Fortran.  There are some disadvantages - for example you can't use such an enumeration directly in a SELECT CASE construct.&lt;/P&gt;
&lt;P&gt;(Your invoke procedure in your example code has a dummy argument (nnn2) that is a pointer - an explicit interface is required.)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;

I am trying to tag a pointer(type_) as out, cut, sp or in. This pointer (type_)  is a component of  another pointer (nnn or nnn2). 

&lt;BLOCKQUOTE&gt;IanH wrote:&lt;BR /&gt;
&lt;P&gt;Wrapping an integer component in a derived type with appropriate set and test (operator(==)) procedures is certainly one way to implement a strongly typed enumeration in Fortran.  There are some disadvantages - for example you can't use such an enumeration directly in a SELECT CASE construct.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;


Then, my solution is correct, right ? Where would I need "SELECT CASE construct" ?

&lt;BLOCKQUOTE&gt;IanH wrote:&lt;BR /&gt;
&lt;P&gt;(Your invoke procedure in your example code has a dummy argument (nnn2) that is a pointer - an explicit interface is required.)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;

"explicit interface is required", then should I write an interface in the param_mod module, right ? Such as:

[fortran]

module param_mod
!......................

interface

subroutine invoke(nnn2)

    type(c), pointer    :: nnn2

end subroutine invoke

end interface


[/fortran]</description>
      <pubDate>Wed, 14 Nov 2012 08:06:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Tagging-in-Fortran-like-enum/m-p/947219#M91407</guid>
      <dc:creator>emreka82</dc:creator>
      <dc:date>2012-11-14T08:06:54Z</dc:date>
    </item>
  </channel>
</rss>

