Re: Fortran





Rich Townsend wrote:
robin wrote:

Rich Townsend wrote in message ...

robin wrote:

Rich Townsend wrote in message ...

robin wrote:

Rich Townsend wrote in message ...

robin wrote:

Both true. However, it doesn't change the fact that, in the last protracted
exchange I had with you, *every* piece of code you posted (to implement TRIM()
in Fortran 77, IIRC) was broken.


And how many "pieces of code" were that?
Two, the first one of which I corrected shortly after and without prompting,
as it contained a transcription error.


In other words, one swallow doesn't make a summer.
Or, in other words, you exaggerated, didn't you.

The second one contained an anachronism for F77
(namely, a /= for .NE. ) but was otherwise correct for F90+.


But the code never worked, did it?


It works fine.


No, it didn't implement a working TRIM() in F77.



It does. Let me refresh your memory.
FUNCTION TRIM (S)
CHARACTER*(*) S, TRIM
INTEGER J
DO J = LEN(S), 2, -1
IF (S(J:J) .NE. ' ') GOTO 2
END DO
TRIM=S(1:1)
RETURN
2 TRIM = S(1:J)
RETURN
END


As Giles has pointed out, this is impossible.



It is?
print *, len(s), trim(s) // '|'

80hello|
80a|
80two words|
80alongword|


I'm not going to debate this further. You were wrong then, and since the F77
standard hasn't changed in the interim, you are still wrong.



No, you're the one who is wrong.
You can figure how it's done. I've given you the clues.


Please compile and run this program on your compiler:

But, this is obviously(?) the wrong test program!!!!!!!!!


PROGRAM ATEST
CHARACTER*80 STRING
CHARACTER*10 MYTRIM
EXTERNAL MYTRIM
STRING = 'hello'
!!! PRINT *, LEN(STRING), MYTRIM(STRING)//'|'
!!!!replace with
call leng5(string)
STRING = 'a'
!!! PRINT *, LEN(STRING), MYTRIM(STRING)//'|'
call leng1(string) ! etc
STRING = 'two words'
PRINT *, LEN(STRING), MYTRIM(STRING)//'|'
STRING = 'alongword'
PRINT *, LEN(STRING), MYTRIM(STRING)//'|'
STOP
END
subroutine leng5(string)
CHARACTER*(*) STRING
CHARACTER*5 MYTRIM
EXTERNAL MYTRIM
PRINT *, LEN(STRING), MYTRIM(STRING)//'|'
end
! similar for leng1, etc.

Will work like a charm, and you don't need no trim
function!!!!!!!

True, it's not particularly general. But it's easy to adapt
to any string Robin can come up with. ;)

*** Hendrickson

FUNCTION MYTRIM (S)
CHARACTER*(*) S, MYTRIM
INTEGER J
DO J = LEN(S), 2, -1
IF (S(J:J) .NE. ' ') GOTO 2
END DO
MYTRIM=S(1:1)
RETURN
2 MYTRIM = S(1:J)
RETURN
END

Notes:

1) I have renamed TRIM() to MYTRIM(), to avoid any possible compiler confusion with built-in TRIM(). However, apart from this modification, I have copied your function *verbatim*.

2) I have declared MYTRIM in the main program as having length 10, in the absence of other information. The main program is based on that posted by James Giles.

3) I have used the specific strings that you posted in your example.

4) Test results:

Intel ifort 9.0.026 (Linux):
80 hello |
80 a |
80 two words |
80 alongword |

GNU g77 3.4.5 (Linux):
80hello |
80a |
80two words |
80alongword |

Lahey lf95 6.20c (Linux):
80 hello |
80 a |
80 two words |
80 alongword |

Compaq f95 5.5 (Tru64):
80 hello |
80 a |
80 two words |
80 alongword |

NAG f95 5.0 (Linux):
80 hello |
80 a |
80 two words |
80 alongword |

Sun f95 7.1 (SunOS 5.9)
80 hello |
80 a |
80 two words |
80 alongword |

Clearly, I cannot achieve your "result" of a working trim-like function [which I believe to be bogus] on a single one of the compilers available to me. Yet, I have copied the contents of your function verbatim, amending only its name.

Thus, I suggest you

a) Post edits to my program above that (i) remain within the F77 standard, and (ii) create a functioning MYTRIM() function with *exactly* the same behaviour as the F9X intrinsic TRIM(), such that the program will produce the results you claim.

or

b) Post full details of your compiler, version and platform, plus output from the above program that produces the results you claim.

or

c) Undertake a combination of (a) and (b).

In the absence of either of these prerequisites, I will deem you to have withdrawn your specious claim.

Good luck!

cheers,

Rich

.


Loading