本文介绍了之间&QUOT差异;字符* 10 :: A"和"字符::一(10)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试刷新我的Fortran 90的知识的一个项目,我使用内部文件时遇到了一些怪胎。考虑例如code:

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_file_confusion.f90 ----
program internal_file_confusion
  implicit none

  character*40 :: string1
  character :: string2(40)

  write(string1, *) "Hello World 1"
  write(*,*) "string1 = ", string1

  write(string2, *) "Hello World 2"
  write(*,*) "string2 = ", string2

end program

当与 gfortran 编译崩溃,写入STDOUT

which when compiled with gfortran crashes, writing to STDOUT

 string1 =  Hello World 1
At line 10 of file e:/Daten/tmp/fortran-training/internal_file_confusion.f90
Fortran runtime error: End of record

在与 *长度符号声明的字符数组,可用于内部写,但不能与名称(长)宣布当符号。此外,我注意到 *长度符号似乎只对字符数组被允许,而这是一个错误消息像禁止

When declared with the *length notation the character array can be used for internal write, but not when declared with the name(length) notation. Furthermore I noticed that the *length notation seems to be allowed only for character arrays, while it is forbidden with an error message like

Error: Old-style type declaration INTEGER*40 not supported at (1)

有其它数据类型。

什么是这些符号之间的差异,为什么它会影响使用的内部文件?

What is the difference between these notations and why does it affect use as internal files?

推荐答案

字符* 40 ::字符串是一个长度为40的字符串

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

字符(LEN = 40)::字符串也是长度40的字符串

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

字符:: string的(40)是长度为1的40字符串数组

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

字符* 40 ::串(40)是长度40 40字符串数组

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

字符(LEN = 40)::串(40)是长度40 40字符串数组

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

您第二内部写入失败,因为其写入到第一串数组中字符串2 。第一个字符串字符串2(1)仅为1个字符长太短。出于这个原因,你得到的记录的结尾的错误情况,该消息是所提供的字符串太长。

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.

这篇关于之间&QUOT差异;字符* 10 :: A"和"字符::一(10)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 02:01