Re: WRITE, FORMAT problem
- From: nospam@xxxxxxxxxxxxx (Richard E Maine)
- Date: Fri, 30 Jun 2006 07:57:00 -0700
<aborel@xxxxxxxxxxxxxxxxxxxx> wrote:
I tried (n_rows and n_columns are input):
do i=1,n_rows,1
do j=1, n_columns,1
write(unit=201,fmt="(<2*n_columns>a)"), &
trim(adjustl(arr_data(i,j))), char(59)
end do
end do
Note a few things.
1. The <2*n_columns> construct that you used is nonstandard. You can get
the same effect in a standard-conforming way by generating the format in
a character variable as Ian mentioned, though I happen to think that is
overkill for this case (see below).
2. In any case, the <2*n_columns> doesn't override the fact that you
have a separate write statement for each element. That's why they appear
on separate lines. Each write statement starts a new line unless you are
using advance="no", as Ian also mentioned.
But what I want as a result is
[Loadcase ID];Time Step;XTP;YTP;ZTP;XTS;YTS;ZTS;XBP;YBP;...
Several solutions
1. Use advance="no". That requires at least Fortran 90, but you have
several other Fortran 90 constructs in your code. Note that the "\" edit
descriptor that R MacDOnald mentioned is nonstandard, and not supported
by a particularly wide variety of compilers. If you are stuck with F77,
there are several nonstandard variants; that's one of them, though not
the most common. But it doesn't look like you are stuck with f77.
2. Build the format in a character variable as a substitute for the
nonstandard <> construct. But in order to make this work, you need to
put everything in a single write statement, as illustrated below. Don't
put the write statement in a loop. Instead, use an implied DO loop
*INSIDE* of teh write statement.
3. The simplest solution. People always seem to forget to mention this
one, even though it is what I consider the best option in the large
majority of the cases. Just use a large fixed number in the format.
There is no harm in having a number in the format bigger than needed.
Combine this with putting it all in one write statement, giving somethng
like (rushed and unchecked; I have to go right away)
write (20,"(999(a,:,';')") (trim(adjustl(arr_data(i,j))),j=1,n_columns)
Put your i loop around that, as I guess you want each row on a separate
line. The colon (:) in teh format is a "trick" to keep from putting a
semicolon at the end of the line; if you actually want one at the end of
the line, get rid of that. I've no time to explain how it works.
P.S. Second post in 2 days where I have seen people use obscure char()
"magic numbers" instead os simple character literals. Any reason why you
write char(59) instead of just ";"? (I assume that's ";". I have no time
to look it up, which just illustrates the problem). The ";" is standard
and guaranteed to wrok in all compilers. The ";" actually is not
guaranteed to work (it depends on ASCII, which isn't guaranteed), and is
just cryptic. Why?
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.
- References:
- WRITE, FORMAT problem
- From: aborel
- WRITE, FORMAT problem
- Prev by Date: Re: Random Numbers
- Next by Date: Re: removing blanks from a file
- Previous by thread: Re: WRITE, FORMAT problem
- Next by thread: the hot key in CVF 6.6
- Index(es):
Relevant Pages
|
|