<?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 Thank you Steve, it works! in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984409#M100388</link>
    <description>Thank you Steve, it works!

but only w/o variable names ;-)
type(mytype) :: typeScalar = mytype('Name1', 1, .true.)

Dieter</description>
    <pubDate>Fri, 04 Jan 2013 16:15:59 GMT</pubDate>
    <dc:creator>dnoack</dc:creator>
    <dc:date>2013-01-04T16:15:59Z</dc:date>
    <item>
      <title>Initialize derived data types</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984407#M100386</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to initialize an array of derived data types with constant values. Since the routines should run in parallel I have to prevent access conflicts and want a static initialization of the constant values only once in a module. Below is a code example:&lt;/P&gt;
&lt;P&gt;module myModule&lt;/P&gt;
&lt;P&gt;type myType&lt;/P&gt;
&lt;P&gt;&amp;nbsp; character(len=10) :: name&lt;/P&gt;
&lt;P&gt;&amp;nbsp; double precision :: value&lt;/P&gt;
&lt;P&gt;&amp;nbsp; logical :: exist&lt;/P&gt;
&lt;P&gt;end type myType&lt;/P&gt;
&lt;P&gt;type(myType), dimension(100) ::&lt;/P&gt;
&lt;P&gt;&amp;nbsp; typeArray(1)%name = 'name1',&lt;/P&gt;
&lt;P&gt;&amp;nbsp; typeArray(1)%value = '1',&lt;/P&gt;
&lt;P&gt;&amp;nbsp; typeArray(2)%name = 'name2',&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;end module myModule&lt;/P&gt;
&lt;P&gt;Subroutine mySub&lt;/P&gt;
&lt;P&gt;use myModule&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;The compiler complains with the error message:&lt;/P&gt;
&lt;P&gt;Syntax error, found '%' when expecting one of: * , &amp;lt;END-OF-STATEMENT&amp;gt; ; [ / = =&amp;gt;&lt;/P&gt;
&lt;P&gt;Please can anyone point me to another way to initialize an array of derived data types.&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;
&lt;P&gt;dieter&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2013 12:05:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984407#M100386</guid>
      <dc:creator>dnoack</dc:creator>
      <dc:date>2013-01-04T12:05:11Z</dc:date>
    </item>
    <item>
      <title>You have to use "constructors</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984408#M100387</link>
      <description>You have to use "constructors" for the initialization value.  For example:

[fortran]
type(mytype) :: typeScalar = mytype(name='Name1', value=1, exist=.true.)
[/fortran]

For components that don't have default values in the type declaration, you must specify them in the constructor.

However, doing this for an array of 100 is rather awkward - you'd have an array constructor of type constructors. Might you instead use an initialization routine that is called only once at program start?

Note that you can specify default values in the type declaration, but every object of that type will be initialized to those values.</description>
      <pubDate>Fri, 04 Jan 2013 15:06:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984408#M100387</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-01-04T15:06:35Z</dc:date>
    </item>
    <item>
      <title>Thank you Steve, it works!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984409#M100388</link>
      <description>Thank you Steve, it works!

but only w/o variable names ;-)
type(mytype) :: typeScalar = mytype('Name1', 1, .true.)

Dieter</description>
      <pubDate>Fri, 04 Jan 2013 16:15:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984409#M100388</guid>
      <dc:creator>dnoack</dc:creator>
      <dc:date>2013-01-04T16:15:59Z</dc:date>
    </item>
    <item>
      <title>Works fine for me with the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984410#M100389</link>
      <description>Works fine for me with the names.  You need to make sure the component names in the constructor match those in your actual type declaration.</description>
      <pubDate>Fri, 04 Jan 2013 16:32:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984410#M100389</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-01-04T16:32:38Z</dc:date>
    </item>
    <item>
      <title>type(myType), dimension(100)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984411#M100390</link>
      <description>[fortran]
   type(myType), dimension(100) :: typeArray = [(myType('Name'// &amp;amp;
      trim(merge(achar(48+mod(i,1000)/100),' ',i&amp;gt;=100))// &amp;amp;
      trim(merge(achar(48+mod(i,100)/10),' ',i&amp;gt;=10))// &amp;amp;
      achar(48+mod(i,10)),i,.TRUE.),i=1,size(typeArray))]
[/fortran]</description>
      <pubDate>Fri, 04 Jan 2013 16:40:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984411#M100390</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2013-01-04T16:40:50Z</dc:date>
    </item>
    <item>
      <title>Hello Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984412#M100391</link>
      <description>Hello Steve,
if I compile the following example program with ifort 10.1 I receive the error:

fortcom: Error: initType.f, line 25: An equals sign (=) is invalid in this context.   [NAME]
      typeScalar(5) = myType(name='Name5', value=5.d0, exist=.false.)
-----------------------------^
fortcom: Error: initType.f, line 25: An equals sign (=) is invalid in this context.   [VALUE]
      typeScalar(5) = myType(name='Name5', value=5.d0, exist=.false.)
-------------------------------------------^
fortcom: Error: initType.f, line 25: An equals sign (=) is invalid in this context.   [EXIST]
      typeScalar(5) = myType(name='Name5', value=5.d0, exist=.false.)
-------------------------------------------------------^
compilation aborted for initType.f (code 1)


program:
      module myMod

      implicit none

      type myType
        character(len=5) :: name
        double precision :: value = 1.d0
        logical :: exist = .false.
      end type myType

      end module myMod

      program initType

      use myMod

      implicit none

      type(myType), dimension(5) :: typeScalar

      typeScalar(1) = myType('Name1', 1.d0, .false.)
      typeScalar(2) = myType('Name2', 2.d0, .true.)
      typeScalar(3) = myType('Name3', 3.d0, .false.)
      typeScalar(4) = myType('Name4', 4.d0, .true.)
      typeScalar(5) = myType(name='Name5', value=5.d0, exist=.false.)

      write(*,'(a,e12.5,l)') typeScalar

      end</description>
      <pubDate>Fri, 04 Jan 2013 16:51:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984412#M100391</guid>
      <dc:creator>dnoack</dc:creator>
      <dc:date>2013-01-04T16:51:40Z</dc:date>
    </item>
    <item>
      <title>Wow - 10.1.  That's old. The</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984413#M100392</link>
      <description>Wow - 10.1.  That's old. The use of component names was added in Fortran 2003 and has been accepted by the compiler for several releases now.</description>
      <pubDate>Fri, 04 Jan 2013 19:34:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984413#M100392</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-01-04T19:34:48Z</dc:date>
    </item>
    <item>
      <title>Some other compilers seem to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984414#M100393</link>
      <description>Some other compilers seem to experience difficulties with the following program:
[fortran]
program init_data
   implicit none
   type myType
      character(10) name
      double precision value
      logical exist
   end type myType
   integer i, j
   type(myType), dimension(100) :: typeArray = [(myType('Name'// &amp;amp;
      transfer(achar(48+mod(i/[(10**j,j=int(log10(i+0.5d0)),0,-1)],10)), &amp;amp;
      repeat('A',int(log10(i+0.5d0))+1)), &amp;amp;
      i,.TRUE.),i=1,size(typeArray))]
   write(*,'(a,1x,f5.1,1x,L1)') typeArray
end program init_data
[/fortran]
Is ifort OK with this?</description>
      <pubDate>Fri, 04 Jan 2013 20:33:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984414#M100393</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2013-01-04T20:33:15Z</dc:date>
    </item>
    <item>
      <title>No - our support for</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984415#M100394</link>
      <description>No - our support for transformational intrinsics in constant expressions is incomplete, so we don't allow TRANSFER and REPEAT there. It's probably the third biggest F03 feature we're missing.</description>
      <pubDate>Fri, 04 Jan 2013 21:39:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984415#M100394</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-01-04T21:39:23Z</dc:date>
    </item>
    <item>
      <title>Are you sure that's the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984416#M100395</link>
      <description>Are you sure that's the correct diagnosis? TRANSFER and REPEAT are specifically called out in F95 as allowed in initialization expressions. It seem more probable that int(log10(i+0.5d0)), which is new to F03 initialization expressions, is the culprit. We can work around this, however. What about:
[fortran]
program init_data
   implicit none
   type myType
      character(10) name
      double precision value
      logical exist
   end type myType
   integer i, j
   type(myType), dimension(100) :: typeArray = [(myType('Name'// &amp;amp;
      transfer(achar(48+mod(i/[(10**j,j= &amp;amp;
      (1-sign(1,-i/1000))/2+ (1-sign(1,-i/100))/2+ &amp;amp;
      (1-sign(1,-i/10))/2,0,-1)],10)), &amp;amp;
      repeat('A', &amp;amp;
      (1-sign(1,-i/1000))/2+ (1-sign(1,-i/100))/2+ &amp;amp;
      (1-sign(1,-i/10))/2+ 1)), &amp;amp;
      i,.TRUE.),i=1,size(typeArray))]
   write(*,'(a,1x,f5.1,1x,L1)') typeArray
end program init_data
[/fortran]</description>
      <pubDate>Fri, 04 Jan 2013 23:06:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984416#M100395</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2013-01-04T23:06:00Z</dc:date>
    </item>
    <item>
      <title>A little more experimentation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984417#M100396</link>
      <description>A little more experimentation and I found two examples which are F95-conforming and work in LF95 but not in gfortran, g95, and ftn95. First example:
[fortran]
program init_data
   implicit none
   type myType
      character(10) name
      double precision value
      logical exist
   end type myType
   integer i, j
   type(myType), dimension(100) :: typeArray
   typeArray = (/(myType('Name'//transfer(achar(48+mod(i/(/(10**j, &amp;amp;
      j=int(log10(i+0.5d0)),0,-1)/),10)),repeat('A', &amp;amp;
      int(log10(i+0.5d0))+1)),i,.TRUE.),i=1,size(typeArray))/)
   write(*,'(a,1x,f5.1,1x,L1)') typeArray
end program init_data
[/fortran]
Second example:
[fortran]
program init_data
   implicit none
   type myType
      character(10) name
      double precision value
      logical exist
   end type myType
   integer i, j
   type(myType), dimension(100) :: typeArray = (/(myType('Name'// &amp;amp;
      adjustl(transfer(achar(32+(/((1-sign(1,-i/10**j))/2* &amp;amp;
      (16+mod(i/10**j,10)),j=range(i),0,-1)/)), repeat('A', &amp;amp;
      range(i)+1))),i,.TRUE.),i=1,size(typeArray))/)
   write(*,'(a,1x,f5.1,1x,L1)') typeArray
end program init_data
[/fortran]
How does ifort fare with these examples?</description>
      <pubDate>Sat, 05 Jan 2013 18:04:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984417#M100396</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2013-01-05T18:04:07Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984418#M100397</link>
      <description>Hello,
thank you very much for your hints. For my purpose I use Steves suggestion without variable names.

I have to program only in strict fortran standard and using clear and easy code, so that everybody can understand the logic of the program. In the past I have several problems using nested intrinsic functions, because often there is no fortran standard defined. In addition some extensions to compilers are also without fortran standard. Therefore if they change or I change the compiler, it breaks my code.

BTW: The variable names in my real code are not in ascendig order, but rather arbitrary. The consecutive names I have only used for demonstration in my example program.</description>
      <pubDate>Sun, 06 Jan 2013 01:56:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialize-derived-data-types/m-p/984418#M100397</guid>
      <dc:creator>dnoack</dc:creator>
      <dc:date>2013-01-06T01:56:40Z</dc:date>
    </item>
  </channel>
</rss>

