View Single Post
  #1 (permalink)  
Old 09-18-2006, 02:38 PM
Ben Hetland
Guest
 
Posts: n/a
Default Array range assignments and characters

Given the following declarations and code fragment

-----
character(1), dimension(8) :: t
character(1), dimension(5) :: p
real, dimension(6) :: r1
real, dimension(4) :: r2
data r1/1.0, 2.0, 3.0, 4.0, 5.0, 6.0/
data r2/41.0, 42.0, 43.0, 44.0/
t = 'ABCDEFGH'
p = 'abcde'
[...]
t(1:5) = p(1:5)
t(2:6) = p
t(2:6) = p(

r1(1:4) = r2(1:4)
r1(3:6) = r2
-----

Is is just my compiler being weird, or is there a rationale that
explains why these assignments should behave differently for the
character array than they do for the corresponding real array assigments?

I observe that the "character" assigments always copy only the first
character element from the source into _every_ given element of the
target array, while in the real variable case multiple values are copied
instead (not just the first value).

In other words, after the above t contains 'Aaaaaa' and not [maybe] the
expected 'Aabcde', while r1 does contain (as expected)
/41,42,41,42,43,44/ and NOT the character array equivalent of
/41,41,41,41,41,41/.

FWIW, it doesn't seem to matter whether I change the declaration to some
other style like one of

character(1) p*5
character(1), dimension(5) :: p
character(5) :: p


--
-+-Ben-+-
Reply With Quote