Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove the empty space in the output columns in Fortran?

I am writing some data in a text file using Fortran code.
The output data I want to have should look like the following.

ITEM: ATOMS id type xs ys zs
1 1 0.004775 0.074550 0.697303
2 1 0.017240 0.107659 0.721766
3 1 0.015886 0.123553 0.652037
.
.
.
10 1 0.014177 0.208595 0.748898
11 1 0.036628 0.185849 0.723589
12 1 0.055109 0.218853 0.706833
.
.
.
100 1 0.854597 0.087217 0.713019
101 1 0.861486 0.076430 0.637017
102 1 0.900569 0.109375 0.747426

To print the output data as shown before I am using the following code.

write(21,'(g0)') "ITEM: ATOMS id type xs ys zs"
write(21,'(i3,i2,3f9.6)') ll, i_type, r(:,i)

However, the output from this code I am getting is shown below. As you can see there are blank spaces at the beginning of the columns.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ITEM: ATOMS id type xs ys zs
  1 1 0.004775 0.074550 0.697303
  2 1 0.017240 0.107659 0.721766
  3 1 0.015886 0.123553 0.652037
.
.
.
 10 1 0.014177 0.208595 0.748898
 11 1 0.036628 0.185849 0.723589
 12 1 0.055109 0.218853 0.706833
.
.
.
100 1 0.854597 0.087217 0.713019
101 1 0.861486 0.076430 0.637017
102 1 0.900569 0.109375 0.747426

How do I eliminate these blank spaces at the beginning and the output maybe looks more left-justified?

>Solution :

The i3 makes the first number to always use ghree columns (characters). To use only the necessary number of columns use i0 or the generic g0.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading