Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler errors 为什么我的代码没有';你不能用fortran语言编译吗?_Compiler Errors_Fortran - Fatal编程技术网

Compiler errors 为什么我的代码没有';你不能用fortran语言编译吗?

Compiler errors 为什么我的代码没有';你不能用fortran语言编译吗?,compiler-errors,fortran,Compiler Errors,Fortran,这是我的代码,无法编译 输出结果如下所示: 1>Error: The operation could not be completed ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 我正在使用Microsoft visual studio 2019和英特尔并行studio 2020 for fortran program Truss implicit none integer

这是我的代码,无法编译 输出结果如下所示:

1>Error: The operation could not be completed 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我正在使用Microsoft visual studio 2019和英特尔并行studio 2020 for fortran

program Truss
 implicit none
 integer :: Nnodes
 open(unit=1,file='data.txt')
 open(unit=2,file='output.txt')
 read(1,2) Nnodes
 write(2,3) Nnodes
 2  format(7x)
 3  format("Number of nodes:",1I)


end program Truss
data.txt文件包含以下内容:

npoint 3
0 0
2 0
1 1

我想在npoint之后阅读'3',这就是我忽略7个字符的原因。

这只是一个纯粹的猜测,但在您的情况下,
7x
应该后跟类型规范(例如,
I1

program Truss

  implicit none
  integer :: Nnodes

  open (unit=10, file='data.txt')
  open (unit=20, file='output.txt')

  read (10, 2) Nnodes
  write(20, 3) Nnodes

2 format(7X,I1)
3 format("Number of nodes: ", I1)

end program Truss
但是,正如我所说的,这仅仅是猜测你想要实现什么

我假设您的输入文件如下所示:

> cat data.txt
       1
  2 FORMAT(7X, I4)  

这只是一个纯粹的猜测,但在您的案例中,
7x
后面应该跟着类型规范(例如,
I1

program Truss

  implicit none
  integer :: Nnodes

  open (unit=10, file='data.txt')
  open (unit=20, file='output.txt')

  read (10, 2) Nnodes
  write(20, 3) Nnodes

2 format(7X,I1)
3 format("Number of nodes: ", I1)

end program Truss
但是,正如我所说的,这仅仅是猜测你想要实现什么

我假设您的输入文件如下所示:

> cat data.txt
       1
  2 FORMAT(7X, I4)  

当您想知道错误发生的原因时,通常最好包含错误消息。如果它没有打印在屏幕上,那么它应该在一些日志中

也就是说,我注意到了三件事,@evets和@Oo.Oo也注意到了其中两件事:

  • 请勿使用低于10的单元编号。其中一些可能是为标准输入和输出、错误输出或类似的东西保留的

  • 您试图读取一个整数,但您给出的格式不包含任何整数描述符
    7X
    仅表示“忽略7个字符”,但忽略不读取值。现在我不知道输入文件是什么样子,也不知道为什么需要忽略前7个字符。一般来说,最好只使用

      read(unit, *) Nnodes
    
    但是,如果确实需要声明格式,那么该格式说明符必须包含实际整数的某些组件,如下所示:

    > cat data.txt
           1
    
      2 FORMAT(7X, I4)  
    
    这假设输入行中的第8到第11个字符只包含数字,并且包含所有数字。
    I
    之后的
    4
    表示要读取的数字包含多少个字符

  • 最后是print语句的格式。您有
    1I
    ——在
    I
    前面的数字表示要读取多少个整数<代码>1在这种情况下是多余的。但是我可以合理地确定,
    I
    需要在
    I
    后面加一个数字来表示整数应该使用多少位数

    现在有些编译器似乎接受了I0,意思是“你需要多少就有多少”,但我不知道这是哪个标准,也不知道你的编译器是否接受它。有些编译器也可能只接受
    I
    ,但我认为这不是标准。(我相信有人会在下面的评论中纠正我的回答;))


干杯

当您想知道错误发生的原因时,通常最好包含错误消息。如果它没有打印在屏幕上,那么它应该在一些日志中

也就是说,我注意到了三件事,@evets和@Oo.Oo也注意到了其中两件事:

  • 请勿使用低于10的单元编号。其中一些可能是为标准输入和输出、错误输出或类似的东西保留的

  • 您试图读取一个整数,但您给出的格式不包含任何整数描述符
    7X
    仅表示“忽略7个字符”,但忽略不读取值。现在我不知道输入文件是什么样子,也不知道为什么需要忽略前7个字符。一般来说,最好只使用

      read(unit, *) Nnodes
    
    但是,如果确实需要声明格式,那么该格式说明符必须包含实际整数的某些组件,如下所示:

    > cat data.txt
           1
    
      2 FORMAT(7X, I4)  
    
    这假设输入行中的第8到第11个字符只包含数字,并且包含所有数字。
    I
    之后的
    4
    表示要读取的数字包含多少个字符

  • 最后是print语句的格式。您有
    1I
    ——在
    I
    前面的数字表示要读取多少个整数<代码>1在这种情况下是多余的。但是我可以合理地确定,
    I
    需要在
    I
    后面加一个数字来表示整数应该使用多少位数

    现在有些编译器似乎接受了I0,意思是“你需要多少就有多少”,但我不知道这是哪个标准,也不知道你的编译器是否接受它。有些编译器也可能只接受
    I
    ,但我认为这不是标准。(我相信有人会在下面的评论中纠正我的回答;))

干杯谢谢你的帮助。 现在,根据您的建议,我将代码更改为:

program Truss
implicit none
integer :: Nnodes
open(unit=11,file='data.txt')
open(unit=22,file='output.txt')
read(11,20) Nnodes
write(22,30) Nnodes
20  format(7x,I3)
30  format("Number of nodes:",2I)


end program Truss
现在,我希望有两行被忽略,并根据格式30将数据写入output.txt,但它是这样做的:

Number of nodes:           3
谢谢你的帮助。 现在,根据您的建议,我将代码更改为:

program Truss
implicit none
integer :: Nnodes
open(unit=11,file='data.txt')
open(unit=22,file='output.txt')
read(11,20) Nnodes
write(22,30) Nnodes
20  format(7x,I3)
30  format("Number of nodes:",2I)


end program Truss
现在,我希望有两行被忽略,并根据格式30将数据写入output.txt,但它是这样做的:

Number of nodes:           3

Stackover不会接受我的编辑以正确格式化您的代码。哦,好吧!有几件事。1.不要将
unit=1
2
用于IO,有些编译器将其用作预连接的单元号。2.您的格式语句可能是错误的。使用列表方向IO。也就是说,使用
read(1,*)
write(2,*)
。Stackover不会接受我的编辑来正确格式化代码。哦,好吧!有几件事。1.不要将
unit=1
2
用于IO,有些编译器将其用作预连接的单元号。2.您的格式语句可能是错误的。使用列表方向IO。也就是说,使用
read(1,*)
write(2,*)