<?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 Look into &amp;quot;SELECT TYPE&amp;quot; in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999453#M103282</link>
    <description>&lt;P&gt;Look into "SELECT TYPE" construct: you need it to unmask the polymorphic object and invoke the methods associated with it.&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jul 2015 21:24:02 GMT</pubDate>
    <dc:creator>FortranFan</dc:creator>
    <dc:date>2015-07-05T21:24:02Z</dc:date>
    <item>
      <title>Polymorphic Pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999452#M103281</link>
      <description>&lt;P style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"&gt;I am trying to use pointers to create links between objects. Using Fortran and here is the code piece:&lt;/P&gt;

&lt;PRE style="margin-top: 0px; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; word-wrap: normal; color: rgb(34, 34, 34);"&gt;&lt;CODE style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"&gt; module base_pars_module
   type,abstract,public :: base_pars
   end type
 end module 
 module test_parameters_module
   use base_pars_module
   type, extends(base_pars) :: test_pars
     contains 
     procedure :: whoami
   end type
   contains
   function whoami(this) result(iostat)
     class( test_pars) :: this
     write(*,*) 'i am a derived type child of base_pars'
   end type
 end module
 module base_mask_module
   use base_pars module
     type, abstract , public :: base_mask
     class(base_pars),pointer :: parameters
   end type
end module
module test_mask_module
  use base_mask_module
  implicit none
  type, extends(base_mask) :: test_mask
  end type
end module
program driver
type(test_pars) , target :: par_Test
type(test_mask) :: mask_test
  iostat= par_test%whoami()
  mask_test%parameters=&amp;gt;par_test
  iostat=mask_test%parameters%whoami()
end program
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"&gt;&lt;CODE style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; background-color: rgb(238, 238, 238); white-space: pre-wrap;"&gt;parameters&lt;/CODE&gt;&amp;nbsp;at&amp;nbsp;&lt;CODE style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; background-color: rgb(238, 238, 238); white-space: pre-wrap;"&gt;base_mask_module&lt;/CODE&gt;&amp;nbsp;is a pointer with&amp;nbsp;&lt;CODE style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; background-color: rgb(238, 238, 238); white-space: pre-wrap;"&gt;base_pars&lt;/CODE&gt;&amp;nbsp;class. I would like to use this pointer to refer&amp;nbsp;&lt;CODE style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; background-color: rgb(238, 238, 238); white-space: pre-wrap;"&gt;par_test&lt;/CODE&gt;&amp;nbsp;object which is&amp;nbsp;&lt;CODE style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; background-color: rgb(238, 238, 238); white-space: pre-wrap;"&gt;test_pars&lt;/CODE&gt;&amp;nbsp;type that extends&amp;nbsp;&lt;CODE style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; background-color: rgb(238, 238, 238); white-space: pre-wrap;"&gt;base_pars&lt;/CODE&gt;&amp;nbsp;type. So the pointer and the target has the same class. But when I compile this it gives an error:&lt;/P&gt;

&lt;PRE style="margin-top: 0px; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; word-wrap: normal; color: rgb(34, 34, 34);"&gt;&lt;CODE style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"&gt; driver.f90:17.37:

iostat=mask_test%parameters%whoami()
                                  1
Error: 'whoami' at (1) is not a member of the 'base_pars' structure
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"&gt;Is it a bug or am i doing something wrong?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 20:41:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999452#M103281</guid>
      <dc:creator>dundar11</dc:creator>
      <dc:date>2015-07-05T20:41:14Z</dc:date>
    </item>
    <item>
      <title>Look into "SELECT TYPE"</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999453#M103282</link>
      <description>&lt;P&gt;Look into "SELECT TYPE" construct: you need it to unmask the polymorphic object and invoke the methods associated with it.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 21:24:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999453#M103282</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2015-07-05T21:24:02Z</dc:date>
    </item>
    <item>
      <title>Your question has already</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999454#M103283</link>
      <description>&lt;P&gt;Your question has already been answered by others at &lt;A href="http://stackoverflow.com/questions/31220961/fortran-polymorphism-in-pointers" target="_blank"&gt;http://stackoverflow.com/questions/31220961/fortran-polymorphism-in-pointers&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The error message is valid and a reasonable summary of the problem with the code.&amp;nbsp; `mask_test%parameters` is of type `base_pars`, and that type does not have a binding `whoami`.&amp;nbsp; The presence of a binding of that name in types that are extensions of `base_pars` is not relevant - in a statically typed language, such as Fortran (and many others), the available set of bindings and components are determined by the declared type of an object, not its dynamic type.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 21:31:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999454#M103283</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2015-07-05T21:31:32Z</dc:date>
    </item>
    <item>
      <title>I know that answers in the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999455#M103284</link>
      <description>&lt;P&gt;I know that answers in the StackoverFlow but wanted to port the discussion here.&lt;/P&gt;

&lt;P&gt;My problem in fact is this. I want to create objects from two different abstract classes.&lt;/P&gt;

&lt;P&gt;Lets say base_a and base_b&lt;/P&gt;

&lt;P&gt;And I want to create objects from classes &amp;nbsp;class_a which is child of base_a and class_b child of base_b.&lt;/P&gt;

&lt;P&gt;And , I want to establish a connection between child_a and child_b in terms of pointers at the abstract type definition while I am defining base_a and base_b. I want a pointer which points from base_a to any objects which inherits base_b.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I think this is not possible with fortran. If it is I don't know how. I discussed this with a computer engineer, expert in Java. He says it is quite possible to do this with java. As far as I understand, pointers in Fortran are not as polymorphic as pointers of other languages.&lt;/P&gt;

&lt;P&gt;So is there any work-around for this?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 23:34:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999455#M103284</guid>
      <dc:creator>dundar11</dc:creator>
      <dc:date>2015-07-05T23:34:28Z</dc:date>
    </item>
    <item>
      <title>In Fortran, a polymorphic</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999456#M103285</link>
      <description>&lt;P&gt;In Fortran, a polymorphic pointer can point at any object that is of a type that is an extension of the type of the pointer (i.e. the type of the pointer and any types that ultimate EXTEND the type of the pointer).&amp;nbsp; This is exactly what you do in the line before the line that incurs an error message from the compiler.&lt;/P&gt;

&lt;P&gt;The error above does not arise because you cannot point the polymorphic pointer at an object - it arises because the type of the pointer is that of the abstract parent type, and that abstract parent type does not have the member that you request.&lt;/P&gt;

&lt;P&gt;I am not a java programmer (which is an understatement), but here is the naive transliteration of your example into java.&amp;nbsp; It fails with a similar error to the Fortran program, for similar reasons.&amp;nbsp; If I change the type of the member reference to be that of the `test_pars` extension - the error message goes away - as it would if you did the same in Fortran.&lt;/P&gt;

&lt;P&gt;Perhaps you can discuss this example with your java expert.&amp;nbsp; If their response involves using a type cast, to downcast the `mask_test.parameters` reference to a base_pars object to be a reference to a test_pars object, then that is equivalent to using SELECT TYPE in Fortran, as others have suggested.&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:java;"&gt;
class ExampleApp
{
  class base_pars
  {
  }
  
  class test_pars extends base_pars
  {
    public int WhoAmI() {
      System.out.println("I am a test_pars - a subclass of base_pars");
      return 0;
    }
  }
  
  class base_mask
  {
     public base_pars parameters;
    /* public test_pars parameters;   */
  }
  
  class test_mask extends base_mask
  {
  }
  
  
  
  
  public static void main(String[] args)
  {
    try {
      ExampleApp obj = new ExampleApp();
      obj.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  
  void run(String[] args)
  {
    test_pars par_Test = new test_pars();
    test_mask mask_test = new test_mask();
    
    mask_test.parameters = par_Test;
    int iostat = mask_test.parameters.WhoAmI();
  }
}
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2015 02:00:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999456#M103285</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2015-07-06T02:00:30Z</dc:date>
    </item>
    <item>
      <title>Quote:dundar11 wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999457#M103286</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;dundar11 wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;.. &lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;. I discussed this with a computer engineer, expert in Java. He says it is quite possible to do this with java. As far as I understand, pointers in Fortran are not as polymorphic as pointers of other languages. ..&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;So why don't you ask this Java expert to give you a minimal working example of what you want to do in Java without using type casting? &amp;nbsp;And why don't you post the Java example here? &amp;nbsp;We can then offer comments on what is possible with Fortran. &amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;But I'm willing to bet the "expert in Java" has type casting in mind which, as IanH pointed out, is the same as using SELECT TYPE in Fortran. &amp;nbsp;One may argue there is "syntactic sugar" available in Java with type casting that allows a coder to accomplish the same task in fewer keystrokes compared to, say, Fortran. &amp;nbsp;But that would be a separate discussion altogether. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2015 04:18:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999457#M103286</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2015-07-06T04:18:40Z</dc:date>
    </item>
    <item>
      <title>That java part was a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999458#M103287</link>
      <description>&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;That java part was a misunderstanding between me and my friend. However is it possible to "cast" type of the pointer?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;In the initial example&lt;/P&gt;

&lt;PRE style="font-size: 13px; color: rgb(96, 96, 96);"&gt;     class(base_pars),pointer :: parameters
&lt;/PRE&gt;

&lt;P&gt;Pointer parameters belongs to base_pars class. What if I allocate this pointer at the body of the program:&lt;/P&gt;

&lt;P&gt;allocate(test_pars::mask_test%parameters)&lt;/P&gt;

&lt;P&gt;and point this to par_Test?&lt;/P&gt;

&lt;P&gt;mask_test%parameters=&amp;gt;par_test&lt;/P&gt;

&lt;P&gt;and call the function whoami later:&lt;/P&gt;

&lt;P&gt;iostat=mask_test%parameters%whoami()&lt;/P&gt;

&lt;P&gt;It still gives the compiler error. says whoami does not belong to base_pars class. However I should be able to cast this pointer with test_pars type. If not what is the point of using classes?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2015 10:41:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999458#M103287</guid>
      <dc:creator>dundar11</dc:creator>
      <dc:date>2015-07-06T10:41:59Z</dc:date>
    </item>
    <item>
      <title>Quote:dundar11 wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999459#M103288</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;dundar11 wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;That java part was a misunderstanding between me and my friend. However is it possible to "cast" type of the pointer?&lt;/P&gt;

&lt;P&gt;In the initial example&lt;/P&gt;

&lt;PRE&gt;     class(base_pars),pointer :: parameters
&lt;/PRE&gt;

&lt;P&gt;Pointer parameters belongs to base_pars class. What if I allocate this pointer at the body of the program:&lt;/P&gt;

&lt;P&gt;allocate(test_pars::mask_test%parameters)&lt;/P&gt;

&lt;P&gt;and point this to par_Test?&lt;/P&gt;

&lt;P&gt;mask_test%parameters=&amp;gt;par_test&lt;/P&gt;

&lt;P&gt;and call the function whoami later:&lt;/P&gt;

&lt;P&gt;iostat=mask_test%parameters%whoami()&lt;/P&gt;

&lt;P&gt;It still gives the compiler error. says whoami does not belong to base_pars class. However I should be able to cast this pointer with test_pars type. If not what is the point of using classes?&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;No, you would still need to use "SELECT TYPE" construct to unmask the polymorphic object. &amp;nbsp;Or if the base_pars class design is something you have control over, you can redesign it as suggested to you on the StackOverflow forum.&lt;/P&gt;

&lt;P&gt;Re: "&lt;SPAN style="font-size: 13.0080003738403px; line-height: 19.5120010375977px;"&gt;what is the point of using classes?&lt;/SPAN&gt;", you can best answer this question for yourself by (re)reading the books/articles on object-oriented programming applications in Fortran e.g., &lt;A href="https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world" target="_blank"&gt;https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world&lt;/A&gt; and&amp;nbsp;http://www.hindawi.com/journals/sp/2015/942059/&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2015 15:37:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Polymorphic-Pointers/m-p/999459#M103288</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2015-07-06T15:37:35Z</dc:date>
    </item>
  </channel>
</rss>

