Fortran splats my output to asterisks - why?

前端 未结 1 452
余生分开走
余生分开走 2021-01-17 13:26

I\'m having a hard time wrapping my head around formatting statements in Fortran.

Without formatting my output, this is what I do (inside a loop, so this happens a f

相关标签:
1条回答
  • 2021-01-17 13:52

    Fortran format statements are defined as:

    Fw.d, where w is the number of characters to be used in total, and d is the number of characters after the decimal point. Here you are telling it that you need a float, that is 1 character wide in total, and 2 characters after the decimal point, something that is obviously not correct. So to get, for example, a float that is 4 characters in total, with 3 decimal places, you'd write:

    write(*, '(F4.3)') t*1E9
    

    See http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html

    Also, I should mention that the asterisks are indicative that the number cannot be displayed in the format stated.

    EDIT:

    Adding in the comment from george below:

    "For E format the fieldwidth has to be at least 7 more than the number of decimals, eg E15.8. Four for the exponent, two for the lead 0. one for a possible '-'. I usually add one more extra space so numbers don't run together, E16.8"

    0 讨论(0)
提交回复
热议问题