program calculator
real :: x(10)
call random_init(.true., .true.)
call random_number(x)
x = x*1000.0
print "(f8.2)", x
end program
The printed values are right aligned. Can I switch to left aligned? GFortran 12.2.1 is used.
program calculator
real :: x(10)
call random_init(.true., .true.)
call random_number(x)
x = x*1000.0
print "(f8.2)", x
end program
The printed values are right aligned. Can I switch to left aligned? GFortran 12.2.1 is used.
Probably the simplest example (Fortran descriptions are a language unto themselves) is
program calculator
real :: x(20)
call random_init(.true., .true.)
call random_number(x)
x = x*1000.0
print "(f8.2)", x ! default right
print *
print "(f0.2)", x ! left
print *
write(*, "(f0.2,t10,f0.2,t20,f0.2,t30,f0.2,t40,f0.2)") x !every five values each left-justified
end program
635.99
696.17
996.33
228.91
294.63
403.02
982.48
166.99
174.31
935.52
635.99
696.17
996.33
228.91
294.63
403.02
982.48
166.99
174.31
935.52
635.99 696.17 996.33 228.91 294.63
403.02 982.48 166.99 174.31 935.52
What does the 0 mean in “(f0.2)”?
Briefly, it means to use as few characters as needed to represent the value, in your case modified by the “.2” field to present only two digits after the decimal.