Silverfrost Forums

Welcome to our forums

Problem with TRIM

23 Oct 2012 3:37 #10892

I didn't have this problem in 2009 but now -

CHARACTER*8 STRINGS(3) STRINGS=(/'Longer ','Short ','Longest '/) STRINGS=TRIM(STRINGS) PRINT '(/(A8))',STRINGS END

doesn't work properly. OK if longest first, otherwise not. Truncation is determined by the first string.

23 Oct 2012 4:45 #10893

This should fail to compile because TRIM is not 'elemental'.

You could use...

CHARACTER*8 STRINGS(3) 
STRINGS=(/'Longer  ','Short   ','Longest '/) 
do i=1,3
  STRINGS(i)=TRIM(STRINGS(i))
enddo  
PRINT '(/(A8))',STRINGS 
END
23 Oct 2012 6:25 #10894

PRINT *,TRIM(STRINGS) fails to compile

but STRINGS=TRIM(STRINGS) compiles OK

23 Oct 2012 10:13 #10895

Quoted from skeptic ... STRINGS=TRIM(STRINGS) compiles OK

It may compile, but the assignment, as well as the assignment STRINGS(i)=TRIM(STRINGS(i)) in a DO loop, does nothing useful. The expression on the right of the assignment is a trimmed string. However, when a string expression is assigned to a variable, the expression is truncated or padded up with blanks to match the length of the CHARACTER variable.

Try PRINT '(/(1h|,A,1h|))',(TRIM(STRINGS(i)),i=1,3)

24 Oct 2012 7:07 #10897

Good point.

The original code does indeed compile under FTN95 but this reflects a bug in FTN95. It should produce a compilation error report.

27 Mar 2013 5:07 #11894

I have fixed this bug for the next release (after 6.35).

Please login to reply.