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

Wrong result using len_trim in array constructor

MR
Beginner
258 Views

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
mecej4
Honored Contributor III
258 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
Kevin_D_Intel
Employee
258 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
MR
Beginner
258 Views

mecej4, Kevin, thank you both for your feedback!

Marco

0 Kudos
Reply