Malcolm Cohen writes:
> Catherine Moroney said:
> > write(10,'(ndataI10)') (xarray(idata),idata=1,ndata)
> > close(10)
> >
> > What I want to do is to write out each of the elements in the array
> > as an I10. The size of the array is subject to change so I want
> > to somehow include the length of the array in the format statement.
>
> Apart from the more complicated suggestions, you could just pick a big
> number. It will stop when it is finished.
>
> e.g. WRITE(10,'(9999999I10)') xarray(1:ndata)
Indeed, this is usually the *FIRST* thing I suggest when people ask
this question. (I don't know why it so often seems to be the last
option mentioned). It is not adequate for all situations, but it is
fine for many (quite possibly including yours). A lot of people
don't realize that it is fine for the format to specify more fields
than are used. When the simple solution works, prefer it.
My recommendations are, in order of preference,
1. The above (just use a sufficiently large number in the format).
2. Use internal writes to generate a format, as shown in some other replies.
3. Use non-advancing I/O. That is simillar to the $ edit descriptor
that you mentioned, but it is standard. (The $ edit descriptor is
not and will not work with all compilers). I realize you said that
you preferred to avoid this style. I'm agreeing by listing it as
my last option.
Non-standard VFEs, mentioned by one other poster, aren't on my list at
all. I do not recommend them (and your compiler may well not support
them anyway).
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|