For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2004 > print a floating point number without a period









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 print a floating point number without a period
Lynn McGuire

2004-03-27, 12:18 am

Is there a way to print a floating point number without a period in
F77 ? For instance:

double precision x
x = 12345678
write (6,101) x
101 format (1x, 'x = ', F9.0)

prints: x = 12345678.

I would rather have: x = 12345678

Thanks,
Lynn McGuire


Richard Maine

2004-03-27, 12:18 am

"Lynn McGuire" <NOSPAM.winsim@NOSPAM.winsim.com> writes:

> Is there a way to print a floating point number without a period in
> F77 ? For instance: [elided]


There is no direct way, but there are two relatively simple indirect
ways that occur to me. (And there are probably others.) The
simplest way is to copy the real into a temporary integer and
then write the integer with an I format as in

write (lun,'(1x,i9)') int(x)

Do not, by the way, try to directly write the real with an I format.
That is not allowed by the standard and gives different results on
different compilers. On some compilers it might do what you want.
On others, it might have the effect of a transfer/equivalence, which
is not at all what you want. On yet other compilers it will fail
with an error message.

Another posssibility is slightly more complicated, but might happen
to be more convenient in some special cases. Use an internal
write to write the real with a decimal point to a character string.
Then get rid of the decimal point in the character string, either
by changing it to a blank or by just using the substring prior to
it. Write out that character string with an "A" edit descriptor.

--
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
James Van Buskirk

2004-03-27, 12:18 am

"Lynn McGuire" <NOSPAM.winsim@NOSPAM.winsim.com> wrote in message
news:4061b05f$0$17095$811e409b@news.mylinuxisp.com...

> Is there a way to print a floating point number without a period in
> F77 ? For instance:


> double precision x
> x = 12345678
> C write (6,101) x
> C101 format (1x, 'x = ', F9.0)

write(6,101) nint(x)
101 format(1x, 'x = ', i9)


--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Sponsored Links







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

Copyright 2008 codecomments.com