Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29246 Discussions

How to initialize a derived type within DATA statement

Robinson__Donald
Beginner
752 Views
Hi all -

Using XP(SP3), VS2010 +IVF 12.0.1.127 [IA-32]...

I think it should be possible to compile this test program, butone form of array intialization works while the other one doesn't work. This is a demo example. In my real program the derived data structure MD_STR has integer arrays, character-string arrays and real scalars;and the variable ZNKONST is itself an array of the MD_STR derived type.

The same issue is present in 12.0.0.x (whatever came with the original DVD)
This problem does not occur under VS2010 + IVF 11.0.061

===================

program Console1

implicit none

TYPE MD_STR
INTEGER :: SPP(4)
INTEGER :: OBSERV
END TYPE

TYPE (MD_STR) ZNKONST

DATA ZNKONST /
> MD_STR (
> (/1, 0,0,0 /), ! This is OK
! > (/1, 3*0 /), ! This is bad
> 200
> ) /

print *, 'Hello World'
end program Console1

===================

Is my initialization somehow flawed? Any suggestions would be welcome.
0 Kudos
1 Solution
Steven_L_Intel1
Employee
752 Views
The 3*0 syntax is not valid in an array constructor. What you actually did with that is have an array constructor with only two elements, the second of which was 0. You want this instead:

DATA ZNKONST / MD_STR ((/1, (0,I=1,3) /), 200 ) /

View solution in original post

0 Kudos
2 Replies
Steven_L_Intel1
Employee
753 Views
The 3*0 syntax is not valid in an array constructor. What you actually did with that is have an array constructor with only two elements, the second of which was 0. You want this instead:

DATA ZNKONST / MD_STR ((/1, (0,I=1,3) /), 200 ) /
0 Kudos
Robinson__Donald
Beginner
752 Views
Bang on, Steve -

I changed the syntax as you suggested (both integers and character strings) and the compiler is happy. Just a few dozen more edits to go.

Interesting that this is trapped in XE2011 but not IVF 11. A case of 'per ardua ad astra' no doubt.

Thanks again for your help.
0 Kudos
Reply