Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

max length of * format write

0 views
Skip to first unread message

jfh

unread,
Jan 5, 2010, 4:30:03 PM1/5/10
to
Recently I found myself wishing there was an intrinsic inquiry
function (let's call it maxlistdir(x) ) that would return the maximum
length needed to write a list-directed value of the same kind as x,
where x is of any integer, real or complex kind allowed by the
compiler. I was trying to write something that would work the same way
with various compilers (which of course use different formats for list-
directed writing of the same value), so that if string were a scalar
character variable of length maxlistdir(x) then

write (string,*) x

would never cause a run-time error, and for at least one value of x,
string would have no trailing blanks. Does anyone else think this
would improve the next version of the Fortran standard?

John Harper

robin

unread,
Jan 5, 2010, 5:58:41 PM1/5/10
to
"jfh" <john....@vuw.ac.nz> wrote in message news:a9a03503-11cd-4f7c...@f5g2000yqh.googlegroups.com...

| Recently I found myself wishing there was an intrinsic inquiry
| function (let's call it maxlistdir(x) ) that would return the maximum
| length needed to write a list-directed value of the same kind as x,

Of what use would that be?

jfh

unread,
Jan 6, 2010, 4:25:56 PM1/6/10
to
On Jan 6, 11:58 am, "robin" <robi...@bigpond.com> wrote:
> "jfh" <john.har...@vuw.ac.nz> wrote in messagenews:a9a03503-11cd-4f7c...@f5g2000yqh.googlegroups.com...

>
> | Recently I found myself wishing there was an intrinsic inquiry
> | function (let's call it maxlistdir(x) ) that would return the maximum
> | length needed to write a list-directed value of the same kind as x,
>
> Of what use would that be?
>
I wrote a module to permit keeping units with variables by defining
type var with components value (real(kind(1d0)) numerical value,
powers (an array of 6 elements giving the powers of
m,kg,s,amp,mol,kelvin) and badch (one character, '.' if no error was
detected, '+' if addition attempted of things with different powers,
similarly '-', and 'L' if log of something that wasn't dimensionless
was attempted). Then I wrote a subroutine with an optional format for
the value, to write such a var to a character variable (string, say),
giving value, powers and an appropriate warning if badch/='.'. If the
format wasn't present the value would be list-directed, and the
problem my suggestion was intended to solve is finding the appropriate
length to declare string with.

John Harper

!
! Type var is (value,powers,badch) where:
! value is a double precision real scalar,
! powers is a single precision array of 6 elements
(m,kg,sec,amp,mol,K),
! badch is one character, not '.' if and only if an error has been
found
! or suspected.

0 new messages