Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
12 Views

Wrong result using len_trim in array constructor

Hi all,

the following code writes an incorrect result:

program p
 implicit none

 call fs((/"abc","d  "/))

contains

 subroutine fs(text)
  character(len=*), intent(in) :: text(:)
  integer :: i

   write(*,*) "size(text) = ", size(text)
   write(*,*) "len_trim   = ", (len_trim(text(i)) , i=1,size(text))
   write(*,*) "sum(...)   = ", sum((/(len_trim(text(i)) , i=1,size(text))/))

 end subroutine fs

end program p

Using "Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.181 Build 20160204" I get

 size(text) =            2
 len_trim   =            3           1
 sum(...)   =          259

where I would expect, for sum(...), 4.

This might also be related to this old post: https://software.intel.com/en-us/comment/1878150#comment-1878150 .

 

0 Kudos
3 Replies
Highlighted
Black Belt
12 Views

The error is present in the current Windows compiler, 17.0.109, as well. If you declare LT as an integer array of size 2, and set LT = (/(len_trim(text(i)) , i=1,size(text))/), and print LT, the two elements are displayed as 3 and 256.

0 Kudos
Highlighted
Employee
12 Views

Thank you for reporting this MR, and mecej4 for the additional analysis. I will route this to Development.

About the earlier cited thread, that internal error remains fixed in our PSXE 2017 initial release; however, I was never able to make a connection to any similar report of that internal error, so the change responsible for apparently fixing that case is unknown. I still plan to follow-up on that error w/Development.

(Internal tracking id: DPD200414471)

0 Kudos
Highlighted
Beginner
12 Views

mecej4, Kevin, thank you both for your feedback!

Marco

0 Kudos