What is the purpose of * in Fortran input/output

后端 未结 2 674
孤街浪徒
孤街浪徒 2020-12-12 05:11

I am learning Fortran because well, yeah, thought I\'d learn it. However, I\'ve found utterly no information on what the purpose of * is in print, read, etc:



        
2条回答
  •  抹茶落季
    2020-12-12 05:59

    You are correct in that it is a format specifier.

    There's a page on Wikibooks to do with IO and that states:

    The second * specifies the format the user wants the number read with

    when talking about the read statement. This applies to the write and print statements too.

    For fixed point reals: Fw.d; w is the total number of spaces alloted for the number, and d is the number of decimal places.

    And the example they give is

    REAL :: A
    READ(*,'(F5.2)') A
    

    which reads a real number with 2 digits before and after the decimal point. So if you were printing a real number you'd use:

    PRINT '(F5.2)', A
    

    to get the rounded output.

    In your example you're just printing text so there's no special formatting to do. Also if you leave the format specifier as * it will apply the default formatting to reals etc.

提交回复
热议问题