Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Reshape a character array inside ASSOCIATE, LEN is lost

$
0
0

Consider the following code:

program test
 implicit none

 character(len=5) :: s(3), sr(3,1)

 s(1) = '12345'
 s(2) = 'ABCDE'
 s(3) = 'abcde'

 ! everything fine here
 sr = reshape(s,(/3,1/))
 write(*,*) 'len is   ',len(sr)
 write(*,*) 'shape is ',shape(sr)
 write(*,*) 'sr is    ',sr

 write(*,*) ''

 ! this should be the same as before, but len is lost
 associate( ar => reshape(s,(/3,1/)) )
 write(*,*) 'len is   ',len(ar)
 write(*,*) 'shape is ',shape(ar)
 write(*,*) 'ar is    ',ar
 end associate

end program test

The output of the WRITEs inside the ASSOCIATE construct should be the same as the previous one, however I get

$ ./test
 len is              5
 shape is            3           1
 sr is    12345ABCDEabcde
 
 len is              0
 shape is            3           1
 ar is    

i.e. the length of ar is zero, which I think is wrong.

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0 Build 20140723

Marco

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>