For Programmers: Free Programming Magazines  


Home > Archive > Fortran > June 2004 > fortran 77 formatted output for floating-point









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author fortran 77 formatted output for floating-point
Bastian

2004-06-25, 7:44 pm

hello,

my problem is:

code output

write(*,*) 0.25 0.25
write(*,'(f5.2)') 0.25 .25

i dont have an idea how to get a leading zero, when using a format.
can anybody help me?
im working on an ibm aix 3.4

thx bastian
beliavsky@aol.com

2004-06-25, 7:44 pm


acilelaure@hotmail.com (Bastian) wrote:
>hello,
>
>my problem is:
>
> code output
>
>write(*,*) 0.25 0.25
>write(*,'(f5.2)') 0.25 .25
>
>i dont have an idea how to get a leading zero, when using a format.
>can anybody help me?
>im working on an ibm aix 3.4
>
>thx bastian


The format '(f5.2)' applied to 0.25 gives a leading zero with the g77, Compaq
Visual Fortran, and Lahey/Fujitsu Fortran 95 compilers. I don't know why
it does not do so with IBM, but if you try a larger width with something
like '(f8.2)' maybe you will get a leading '0'. Experiment.



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Richard Maine

2004-06-25, 7:44 pm

"beliavsky@aol.com" <beliavsky@127.0.0.1:7501> writes:

> The format '(f5.2)' applied to 0.25 gives a leading zero with the g77, Compaq
> Visual Fortran, and Lahey/Fujitsu Fortran 95 compilers. I don't know why
> it does not do so with IBM, but if you try a larger width with something
> like '(f8.2)' maybe you will get a leading '0'. Experiment.


I wouldn't count on that working. The zero is optional to the compiler.
To my recollection (which might be faulty) there is no way for the user
to force the zero to be there.

There is a somewhat tricky way to force the zero to be omitted, but I know
of no trick to force it to be there. (To force omission, lower the field
width down enough so that there isn't room for it; the compiler is not
allowed to use such optional characters as an "excuse" say that the value
won't fit in the field. Of course, this can give you problems if the value
might be greater than 1; this trick workd better with E format).

The only way I know to force the zero is to do it "manually" by some
means other than the edit descriptor in the format. Something like
writing to an internal character string and then manipulating that
string. That's sort of a PITA though; I'd save that as a last
resport. Or for that matter, I think I may have heard of people
running output through external filters like the unix sed for such things.

I'm not sure why there isn't an option to control that. Seems like
the small kind of thing that wouldn't have been hard to add to the
standard over the years. I might have seen a proposal to add such an
option, but it's a small enough thing not to have stuck in my mind.

(Of course, now someone will point out that such an option got added
while I wasn't looking. :-)).

--
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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com