Silverfrost Forums

Welcome to our forums

TRIM vs. TRIM@

27 May 2011 10:54 #8324

I have used the function TRIM many times to get rid of trailing blanks, and have found that it works as advertised.

I note a different command TRIM@, which is a subroutine instead of a function. The 'Help' file for FTN95 says that TRIM@ will remove the LEADING blanks (not trailing blanks) from a string. Says that in two different places in the 'Help' file entry. I'm convinced.

But at the bottom of the 'Help' file entry for the subroutine TRIM@ is the sentence:

[color=blue:50d757eb15]Notes . . . . The standard intrinsic function TRIM can be used instead.[/color:50d757eb15]

I thought the function TRIM removed TRAILING blanks, not leading blanks. In fact, I know it does. Why does this part of the 'Help' file say it can be used in place of the subroutine TRIM@ which removes LEADING blanks? Typo in the 'Help' file?')

28 May 2011 5:57 #8326

To avoid confusions with trim, I prefer adjustl and adjustr which are standard Fortran functions.

string = '   abcd   '
string2 = adjustl(string) ==> 'abcd      '
string2 = adjustr(string) ==> '      abcd'

Regards - Wilfried

28 May 2011 4:43 #8328

You're correct, TRIM removes trailing blanks, TRIM@ removes leading blanks.

Its a mistake in the help file.

TRIM@ is really an alternative to the standard intrinsic ADJUSTL so the HELP file should say that ADJUSTL can be used instead of TRIM@.

Using T = TRIM(S) is not as useful as you might think, since there will still be trailing blanks unless the length of the character variable is LEN_TRIM(S). Unfortunately you cannot allocate character arrays to be a particular length at run time (well, not in Fortran 95). About the only place I find TRIM helpful is to remove trailing blanks on output.

28 May 2011 5:08 #8330

Thank you, Wilfried and david! I thought that was the case.

I seldom use TRIM into a storage location, for the reasons you cite. But it is useful directly.

[color=blue:57b8679a99] CHARACTER2000 CNAME READ(5) CNAME I=INDEX('David and Goliath', TRIM(CNAME)) IF(TRIM(CNAME).EQ.'David') NNAMES=NNAMES+1 PRINT,TRIM(CNAME),' is my friend's name.'

  etc. [/color:57b8679a99]
Please login to reply.