> Date: Thu, 18 Jul 2002 12:03:25 -0500
> From: Aleksandar Donev <[log in to unmask]>
> Hello,
>
> Another dumb IO question. If I am writing a long character array to a
> file and want to avoid the starting extra blank that would appear with a
> list-directed * formatting, what should I use for the format (I do not
> know the size of the array). I mean, I could make a format string "XA"
> where X=size(character_array), but this seems like it's a lot of work.
It's only a few statements.
> Is there an easier way?
write (*, '(2147483647A)' ) CharacterArray
> I've often used large numbers for X when I don't
> want to count or don't know exactly how many elements there are.
There are alternatives (you mentioned one already):
WRITE (*, '(A)' ) TRANSFER (Z, REPEAT(' ', SIZE(Z)))
and
PROGRAM X
IMPLICIT NONE
CHARACTER (LEN=1) :: Z(5)
Z = (/ 'a', 'b', 'c', 'd', 'e' /)
WRITE (*, VFORMAT('A', SIZE(Z))) Z
STOP
CONTAINS
FUNCTION VFORMAT (F, L)
IMPLICIT NONE
CHARACTER (LEN=*), INTENT (IN) :: F
INTEGER, INTENT (IN) :: L
CHARACTER (LEN=12+LEN(F)) :: VFORMAT
WRITE (VFORMAT, '(A, I10, 2A)') '(', L, F, ')'
RETURN
END FUNCTION VFORMAT
END PROGRAM X
> Thanks,
> Aleksandar
|