Difference between “character*10 :: a” and “character :: a(10)”

前端 未结 1 2002
时光说笑
时光说笑 2020-12-03 23:43

Trying to refresh my Fortran 90 knowledge for a project, I have run into some oddity when using internal files. Consider the example code:

! ---- internal_fi         


        
相关标签:
1条回答
  • 2020-12-03 23:58

    character*40 :: string is a character string of length 40

    character(len=40) :: string is also a character string of length 40

    character :: string(40) is an array of 40 character strings of length 1

    character*40 :: string(40) is an array of 40 character strings of length 40

    character(len=40) :: string(40) is an array of 40 character strings of length 40

    Your second internal writes fails, because it writes to the first string in the array string2. The first string string2(1) is just 1 character long and that is too short. For that reason you get the end of record error condition, the message is too long for the supplied string.

    Internal writes treat array elements as separate records (similar to separate lines). One can utilize arrays of string in internal writes if one has more records (lines) to write into the array.

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