Catherine,
>Now another question about character strings and formats:
>
>I have to construct a character string that spans multiple lines.
>(In order to provide file annotation in HDF version 4, I have
>to write out the entire multi-line annotation as a single character
>string). Is there some way to embed a new-line (as in "C") within
>a character string without having it mark the end of the string?
Yes you can, but note that the \n equivalent is part of the format
descriptor not the string itself
(This is since the special character that marks the end of a line is not
ubiquitous - the Mac, Windows and Unix all do it differently. The \n is a
flag to the printf statment, that it interprets as a format modifier - just
like tabs and other things.)
Erik Schnetter suggested embedding the ASCII newline symbol in your string
which he admits may not be portable. I assume that you will write this
multiline string yourself rather than pass it to a subroutine in an HDF
library?
You can do what you want in a portable way by using Fortran's '/' edit
descriptor. The trick is to build up your output line as a format descriptor
string and *not* as the target of an '(a)' edit descriptor.
eg.
program multiline
! This demonstrates how to have multiline outputs
character :: mystring*79
write (mystring,'(3a)') &
& '("this is on one line"',',/,','"and this on the next")'
print*,mystring
write (*,mystring)
end
Yours,
Daniel.
ps. This should work in old F77 syntax too by replicating any embedded
quotes.
--------------------------------------------------------------
Dr. Dan Kidger, Quadrics Ltd. [log in to unmask]
One Bridewell St., Bristol, BS1 2AA, UK 0117 915 5505
----------------------- www.quadrics.com --------------------
|