Need help w/sprintf-like internal file use.
Quote:
> I need sprintf functionality in an F77 program.
> As far as my understanding goes, the way to do this is to use internal
files.
> My problem is illustrated by the following code :
> program bob
> character foo*80
> write (UNIT=foo, FMT=10)
> C In the real world, I'd like to do something more
> C than just printing foo here, of course.
> write (*,*) foo
> 10 format ('First line',/,'Second line')
> end
> I'd like foo to contain - in C terms - "First line\nSecond line", and to
be
> printed, accordingly, in two lines. In stead, I get a run time error ;
> *** FORTRAN I/O ERROR 974: RECORD ACCESSED PAST END OF INTERNAL FILE
(VARIABLE)
A Fortran internal file (a character variable) consists of one
an only one record. Why don't you just put the newline into
the string the old fashioned way? If you know what character
your system interprets as the newline character, just build
a string with that character in it:
foo = 'First line' // char(10) // 'Second line'
This assumes that you're on a system (like unix) which
uses the linefeed character as the newline (actual
conformance to the intent of the ASCII standard would
use RS - the record separator - which is char(30), but
few systems ever have).
Internal I/O is mostly for conversion of numeric data
to and/or from character representations under format
control. For general purpose building and manipulation
of strings, you should use character assignment,
concatenation, and character functions. That's what
they're for.
--
J. Giles
Ricercar Software