View previous topic :: View next topic |
Author |
Message |
skeptic
Joined: 22 Mar 2009 Posts: 14
|
Posted: Tue Oct 23, 2012 4:37 pm Post subject: Problem with TRIM |
|
|
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. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8209 Location: Salford, UK
|
Posted: Tue Oct 23, 2012 5:45 pm Post subject: |
|
|
This should fail to compile because TRIM is not "elemental".
You could use...
Code: | CHARACTER*8 STRINGS(3)
STRINGS=(/'Longer ','Short ','Longest '/)
do i=1,3
STRINGS(i)=TRIM(STRINGS(i))
enddo
PRINT '(/(A8))',STRINGS
END |
|
|
Back to top |
|
 |
skeptic
Joined: 22 Mar 2009 Posts: 14
|
Posted: Tue Oct 23, 2012 7:25 pm Post subject: Problem with TRIM |
|
|
PRINT *,TRIM(STRINGS) fails to compile
but STRINGS=TRIM(STRINGS) compiles OK |
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Tue Oct 23, 2012 11:13 pm Post subject: Re: Problem with TRIM |
|
|
skeptic wrote: | ... 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 Code: | PRINT '(/(1h|,A,1h|))',(TRIM(STRINGS(i)),i=1,3) |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8209 Location: Salford, UK
|
Posted: Wed Oct 24, 2012 8:07 am Post subject: |
|
|
Good point.
The original code does indeed compile under FTN95 but this reflects a bug in FTN95. It should produce a compilation error report. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8209 Location: Salford, UK
|
Posted: Wed Mar 27, 2013 6:07 pm Post subject: |
|
|
I have fixed this bug for the next release (after 6.35). |
|
Back to top |
|
 |
|