Re: WRITE, FORMAT problem



<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
.



Relevant Pages

  • Re: Using VBA need to add a text box to a form
    ... The loop will be created with: ... Since you already have a reference to txt, you can assign the format ... Allen Browne - Microsoft MVP. ... I am not even sure you are doing this in design view. ...
    (microsoft.public.access.formscoding)
  • Re: is it effective/better
    ... i dont know whether what i have written is an effective solution. ... do (loop ... initially (format t "~%~VA" ... (defun pascal-triangle (n) ...
    (comp.lang.lisp)
  • Re: whats the best way to do this?
    ... "t then nil" thing is a little cutesy, ... so I'd go with the LOOP version. ... Hey, this was supposed to be LOOP weekend, not FORMAT. ... You are a newbie and you haven't answered my: ...
    (comp.lang.lisp)
  • Re: string formatting with mapping & *... is this a bug?
    ... Pierre Fortin wrote: ... Ah, sorry, my favourite idiom to avoid the boilerplate of ... reference loop) so I should remember to 'del self.self' after it... ... you SHOULD hoist the "real format" out of the ...
    (comp.lang.python)
  • My first macro
    ... (loop for item in expr collecting (cond ((eql (car item) ... 'case) `((eql,var,(cadr item)),)) )))))) ... (format t "3")) ... Before I happened upon "loop", I was struggling to manually add ...
    (comp.lang.lisp)