Getting a variable format specification, and character strings
...
Quote:
> write( label, '(i4.4)') number
...
> here the 4 restricts length of 'label' to 4, instead of having
> a multitude of write statement for every conceivable size of
> label (using len to find the size of label) how can i write
> the format statement to use a variable ix.x ?
One non-standard syntax supported by some of DEC's compilers is:
write ( label, '(i<X>.<X>)' ) number
Where X is the name of a variable in your program.
You can get a similar effect by using an internal write into a
a format string and then doing the write you really care about:
write ( format-string, '( ''(i'', i2.2, ''.'', i2.2, '')'' )' ) x, x
write ( label, format-string ) number
(Tested and hopefully transcribed correctly. :-)
Quote:
> on the subject of character strings. how does a character string
> look in memory? is there a null character to mark the end?
No, there is no null character. You can put one there if you want.
Quote:
> (because len() seems to return the full length of it, rather
> than what's actually been written into).
Right. Fortran-77 strings are fixed length.
Quote:
> in C as compared to fortran (memory-wise)? i have assumed
> that a fortran string is just a byte-sized version of the
> integer array.
Yep. That's how I visualize them. I don't think the language standard
specifies a memory layout though. On some architectures the layout
might be more interesting than others.
With the compilers I use, a Fortran string can be passed as an argument
to a C subroutine as long as you manually insert the null terminator that
the C subroutine may be expecting and as long as you specify the
correct parameter passing mechanism.
FORTRAN_STRING(LAST_CHAR:LAST_CHAR) = CHAR(0)
CALL C_SUBROUTINE ( %REF(FORTRAN_STRING) )