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

Data Initialization

bbeyer
Novice
468 Views
I am in the process of upgrading some legacy Fortran code to be more compliant with the 2003 requirements based on using the /stand:f03 setting, and have a simple question. I am encountering many data initializations such as :
CHARACTER(6) CFORCE(6)/3*' FORCE',3*'MOMENT'/
and receive warning message #6915 concerning data values on a type statement.
I tried the following and received error #6952 concerning storing numeric data in type character:
CHARACTER(6) :: CFORCE(6) = [3*' FORCE',3*'MOMENT']

I assume that the "[]" brackets may be used to replace the "//";is there a way to replace the "3*" to maintainthe samefunctionality as the old statement? Is there a good book available that might show examples for these types of questions? Thanks for any help.
0 Kudos
3 Replies
mecej4
Honored Contributor III
468 Views
You are almost there. Try implied loops, as in

CHARACTER(6) :: CFORCE(6) = [('FORCE',i=1,3),('MOMENT',i=1,3)]

where the counter i has been declared as integer earlier.

If you prefer the old style, split the declaration and the initialization into separate statements.

CHARACTER(len=6) :: CFORCE(6)
data CFORCE/3*'FORCE',3*'MOMENT'/
0 Kudos
IanH
Honored Contributor II
468 Views
When F2003 support is complete you could use the SPREAD intrinsic too.

[fortran]CHARACTER(6) :: var(6) = [SPREAD('FORCE ', 1, 3), SPREAD('MOMENT', 1, 3)][/fortran]
(Currently the intel compiler complains about it being in the initializer for a variable, which is a bit disappointing. The error message conflates terminology from different standards too.)
0 Kudos
bbeyer
Novice
468 Views
Thank you both for these suggestions!
0 Kudos
Reply