View previous topic :: View next topic |
Author |
Message |
Little-Acorn
Joined: 06 Jul 2008 Posts: 111 Location: San Diego
|
Posted: Fri May 27, 2011 11:54 pm Post subject: TRIM vs. TRIM@ |
|
|
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:
Notes . . . . The standard intrinsic function TRIM can be used instead.
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?') |
|
Back to top |
|
 |
Wilfried Linder
Joined: 14 Nov 2007 Posts: 314 Location: D�sseldorf, Germany
|
Posted: Sat May 28, 2011 6:57 am Post subject: |
|
|
To avoid confusions with trim, I prefer adjustl and adjustr which are standard Fortran functions.
Code: | string = ' abcd '
string2 = adjustl(string) ==> 'abcd '
string2 = adjustr(string) ==> ' abcd' |
Regards - Wilfried |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat May 28, 2011 5:43 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
Little-Acorn
Joined: 06 Jul 2008 Posts: 111 Location: San Diego
|
Posted: Sat May 28, 2011 6:08 pm Post subject: |
|
|
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.
CHARACTER*2000 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. |
|
Back to top |
|
 |
|