Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print out fomat for real number 1

Status
Not open for further replies.

BlueSky666

Programmer
Jul 15, 2005
2
0
0
US

Hi, how should I output real varibles Var/12.3,9999/ as 12.3 9999 by using F4.1 rather than 12.3 9999.9 by using F6.1. I am using Microsoft Visual Fortran.

Thanks
 
Try G12.4. It will give 12.30 and 9999. with 4 leading and 4 trailing spaces. Maybe your implementation of G is different from GNUs and will give you what you want. Also check if it has B and Z descriptors. They do some extras on some implementations.
 
you have a real number and a integer number, so you have to use diferent FORMAT for them
example_1

- if you want scientific format try
E15.7,1x,I8
----> output 0.1230000E+02 9999
- or
F15.7,1x,I8
----> output 12.3000002 9999

example_2
x=12.3 ; n=9999
write(*,100)x,n
100 format(E15.7,1x,I8)
end

you could read the help of your compiler for more examples...
I recomand the scientific notation (not F4.1) for real numbers...your choice.
 

Thank xwb and RenardPaul.

Since the length of the values can change, here is the code I tried. Little bit tedius but it seems to work.

__________________________________________
ws(1)=18.9
ws(2)=9999
ws(3)=1.3
n=3

do i=1,n
if (int(mod(ws(i),1.0)*10000).lt.0.0001) then
write (var(i), '(I8)') int(ws(i))
else
write (var(i), '(f8.2)') ws(i)
end if
end do

do i=1,n
var(i)=adjustl(var(i))
kk(i)=len_trim(var(i))
end do

write(*,'(<n>(A<kk(i)>,A1))') ((Var(i),','),i=1,n)
________________________________________
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top