Re: Write A, left justified, howto?
- From: "Arjen Markus" <arjen.markus@xxxxxxxxxx>
- Date: 27 Dec 2006 23:36:55 -0800
Jeremy schreef:
How can I make the following print ID, Code and Name left justified not
right? I found that if I pad ID, Code and Name to be longer than the
desired output then it becomes left justified.
write(*, '(A4,1X,A10,1X,A10)') 'ID', 'Code', 'Name'
prints:
ID Code Name
---- ---------- ----------
(-'s added for clarity)
write(*, '(A4,1X,A10,1X,A10)') 'ID ', 'Code ', &
'Name '
will print:
ID Code Name
---- ---------- ----------
which is what I want but I'm sure there has to be a better way of doing
it.
Thanks for any input,
Jeremy
The A edit descriptor is explicitly designed to do it that way, but how
about
a small helper function?
program padding
write(*, '(A4,1X,A10,1X,A10)') 'ID', 'Code', 'Name'
write(*, '(A,1X,A,1X,A)') adj('ID',4), adj('Code',10),
adj('Name',10)
contains
function adj(string,length) result(r)
character(len=*) :: string
integer :: length
character(len=length) :: r
r = adjustl(string)
end function adj
end program
This little program uses an (almost) trivial function adj() to do the
job of creating a string padded with spaces of the right length.
No need to use the width field with the A descriptor then either.
Regards,
Arjen
.
- Follow-Ups:
- Re: Write A, left justified, howto?
- From: *** Russell
- Re: Write A, left justified, howto?
- References:
- Write A, left justified, howto?
- From: Jeremy
- Write A, left justified, howto?
- Prev by Date: Write A, left justified, howto?
- Next by Date: Re: Dimension attribute based on host-associated variable - bug in Intel Fortran
- Previous by thread: Write A, left justified, howto?
- Next by thread: Re: Write A, left justified, howto?
- Index(es):