Re: merge of character strings



In article <i1G4k.84350$SV4.74552@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Dick Hendrickson <dick.hendrickson@xxxxxxx> wrote:
John Harper wrote:
PROGRAM testmerge
* What happens in merge(string1,string2,mask) if lengths of strings
* are not known at compile time, but are in fact equal at run time?
INTEGER,PARAMETER:: maxlen=60
CHARACTER:: stuff*(maxlen-2),empty*(maxlen)='a blank string'
PRINT *,'Enter a character string (possibly empty or all blanks)'
READ "(A)",stuff
PRINT *, 'You entered '//merge(empty,
$ '"'//trim(stuff)//'"'//repeat(' ',maxlen-2-len_trim(stuff)),
$ len_trim(stuff)==0)
END PROGRAM testmerge
It looks OK to me. The rules for MERGE say that the two thingos
should have the same type parameters. But that doesn't mean they have
to be known at compile time.
I'd suggest trying a simpler example
PROGRAM testmerge
character*20 a,b
a = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
b = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
something = 12
do
READ(*,*) N,M
PRINT *, n,m, merge(a(1:n), b(1:m), n==something)
enddo
END PROGRAM testmerge

and see what happens with the 4 compilers for various n and m.

Dick's version compiled and ran with all 4 compilers. None complained
at run-time if n /= m, though I did get various results as is permitted
by the standard in that case. Bug reports are on their way to the
compilers that my version found internal errors in.

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 6780 fax (+64)(4)463 5045
.