data is printed in a second row, fortran

前端 未结 1 1503
醉梦人生
醉梦人生 2021-01-26 17:52

I have the following write statement in a fortran code:

    write(4,\'(7f20.4)\'),x(i,1), x(i,2),x(i,3),x(i,4),x(i,5),x(i,6),x(i,7),x(i,8),x(i,9)
相关标签:
1条回答
  • 2021-01-26 18:43

    Fortran 2008 introduced the unlimited-format-item, which is *(format-items) (in other words, '*' is like a repeat count).

    Your compiler (you didn't say which you are using) may support this.

    In the (621-page) Working Document, Note 10.7 explains further:

    "The effect of an unlimited-format-item is as if its enclosed list were preceded by a very large repeat count. There is no file positioning implied by unlimited-format-item reversion. This may be used to write what is commonly called a comma separated value record.

    For example,

    WRITE( 10, ’( "IARRAY =", *( I0, :, ","))’) IARRAY
    

    produces a single record with a header and a comma separated list of integer values."

    Here's another example - a full program - using the line you gave us above

    Program test
      Implicit None
      Integer, Parameter :: i = 1
      Real, Parameter :: x(i, 9) = reshape( [1,2,3,4,5,6,7,8,9], [1,9] )
      Write (4, '(*(f20.4))') x(i, 1), x(i, 2), x(i, 3), x(i, 4), x(i, 5), &
        x(i, 6), x(i, 7), x(i, 8), x(i, 9)
    End Program
    
    0 讨论(0)
提交回复
热议问题