Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!ogicse!unmvax!ariel.unm.edu!cie!scavo From: scavo@cie.uoregon.edu (Tom Scavo) Newsgroups: comp.lang.fortran Subject: Re: MS-FORTRAN bug in string concatenation Summary: how do I fix these? Keywords: Fortran, strings, substrings Message-ID: <1991Feb16.202213.10167@ariel.unm.edu> Date: 16 Feb 91 20:22:13 GMT References: <2PWGG2@MPLVAX.SRI.COM> <22078@hydra.gatech.EDU> Reply-To: scavo@cie.uoregon.edu (Tom Scavo) Organization: University of Oregon Campus Information Exchange Lines: 91 In article <22078@hydra.gatech.EDU> gt4512c@prism.gatech.EDU (BRADBERRY,JOHN L) writes: >In article <2PWGG2@MPLVAX.SRI.COM> HUESTIS@MPLVAX.SRI.COM (David L. Huestis) writes: >>Under Microsoft FORTRAN the following simple program >> >> character string*4/'abc'/ >> string = '*'//string >> write(*,*)string >> end >> >>produces the output '**bb' while LAHEY and VAX yield '*abc' > >...The only restriction >FORTRAN places on such usage is that overlapping substrings CANNOT appear >on both sides of the same assignment statement... So how do I fix these nonstandard routines without having to resort to local character variables (which would put an unnecessary limit on the length of each argument)? * length() computes the effective length of its argument (minus * trailing spaces); minLength() computes the length minus leading * AND trailing spaces. SUBROUTINE center(st) * IMPLICIT NONE CHARACTER*(*) st * Local variables: INTEGER i, j, k, m, n * Functions: INTEGER minLength, length n = length(st) IF ( n .GT. 0 ) THEN k = LEN(st) m = minLength(st) * i is the # of leading spaces in the uncentered string. * j is the # of leading spaces in the centered string. i = n - m j = (k - m)/2 IF ( i .NE. j ) THEN st(j+1:j+m) = st(i+1:n) IF ( i .LT. j) THEN CALL blank(st(i+1:j)) ELSE CALL blank(st(j+m+1:n)) END IF END IF END IF RETURN END SUBROUTINE leftJustify(st) * IMPLICIT NONE CHARACTER*(*) st * Local variables: INTEGER m, n * Functions: INTEGER minLength, length m = minLength(st) n = length(st) IF ( m .NE. n ) THEN * Shift the string n-m characters to the left. st = st(n-m+1:n) END IF RETURN END ------------------------------------------------------------------- Tom Scavo scavo@cie.uoregon.edu