简体   繁体   English

Fortran 90错误:输入需要太多数据

[英]Fortran 90 Error: input requires too much data

I have the following code: 我有以下代码:

if (complex) then
read(unitvector) (CoefC(jl),jl=1,NV)
endif

Where a user indicates if the data is a collection of complex numbers. 用户指示数据是否为复数的集合。 Now, if the user indicates that it is, but it actually isn't, i get error 67 (input requires too much data). 现在,如果用户指示它是,但实际上不是,我会收到错误67(输入需要太多数据)。 How can i trap that, so i can write that perhaps a user made a mistake. 我该如何捕获该错误,以便我可以写一个用户可能出错的信息。 I was thinking it would look something like: 我以为它看起来像:

read(unitvector, ioStat=iocplx) (CoefC(jl),jl=1,NV) 

but where would i put the "if" to check for the error? 但是我应该在哪里放置“ if”检查错误?

That depends on the overall logic of the program, we cannot tell you the best way for you from such small code snippet. 这取决于程序的整体逻辑,我们无法从如此小的代码片段中告诉您最佳的方法。 You can try something like (not tested): 您可以尝试类似(未经测试)的方法:

if (complex) then
  read(unitvector, ioStat=iocplx) (CoefC(jl),jl=1,NV) 
  if (iocplx/=0) stop "Error reading the complex data."
end if

or 要么

if (complex) then
  read(unitvector, ioStat=iocplx) (CoefC(jl),jl=1,NV) 
  if (iocplx/=0) then
     write(*,*) "Error reading the complex data, triung real."
     complex = .false.
     backspace(unitvector)
     read(unitvector, ioStat=ioreal) (CoefR(jl),jl=1,NV)
     if (ioreal/=0) then
       stop "Error reading real data."
     end if
  end if
end if

But you really did not specify what you want, stop the program and write a meaningful message? 但是您确实没有指定所需的内容,停止程序并编写有意义的消息吗? Read data some other way? 以其他方式读取数据? Everything is possible and we do not have a crystal ball. 一切皆有可能,我们没有水晶球。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM