'Write; statement without a lot of spaces

前端 未结 2 596
春和景丽
春和景丽 2021-01-22 14:31

The write function does print the parameters with a lot of spaces between columms, this is giving me a very huge file in the end. so How do I trim the output, to li

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 14:47

    You need to take control of the output formatting using Fortran's edit descriptors. If you just want to write 3 integers on a line then you could use

    write(1,fmt='(3i2)',err=1001) 1, 2, 3
    

    which will write the integers into 2-character wide fields in the output file. There are many variations of the edit descriptors you should become familiar with. A couple of examples:

    fmt='(i4.2)'  ! 1 integer is written into a 4-character wide field, with at least 2 digits so a leading 0 is written if necessary
    fmt='(6f9.4)' ! 6 reals are written into 9-character fields, with 4 digits after the decimal point
    

    There's a lot more besides this, your compiler documentation will explain everything.

提交回复
热议问题