Fortran 90-尝试读取文件末尾 [英] Fortran 90 - Attempt to read past end of file

查看:260
本文介绍了Fortran 90-尝试读取文件末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Fortran 90中遇到读取问题.我正在尝试读取31488行数据.我正在使用Portland Group Fortran 90编译器.

I am having a read issue in Fortran 90. I am attempting to read 31488 rows of data. I am using the Portland Group Fortran 90 compiler.

我的错误消息是这样的:

My error message is this:

PGFIO-F-217/list-directed read/unit = 14/尝试读取文件末尾.文件名=/import/c/w/username/WRFV3/SKILLSETS/Overestimations.txt格式,可顺序访问记录= 31489

PGFIO-F-217/list-directed read/unit=14/attempt to read past end of file. File name = /import/c/w/username/WRFV3/SKILLSETS/Overestimations.txt formatted, sequential access record = 31489

Fortran程序认为我还有多余的一行.我不知道代码中的指示位置.

The Fortran program thinks that I have an extra row. I do not know where that is indicated in the code.

我已经附加了代码的相关部分...在这部分代码中搜索了高低,我调查了文本文件以查看行数是否匹配.我绝对看不出问题出在哪里.

I have attached the relevant part of the code... I have searched high and low through this part of the code, I have investigated the text file to see if the number of rows match. I absolutely do not see where the problem lies.

编译器指出错误位于do语句内的那行代码read(14,*)的read语句中.

The compiler states that the error is located in the read statement... at read(14,*), that line of the code, within the do statements.

请帮助.非常感谢你.

Program skillruss
! Purpose: to calculate skill scores

implicit none
integer :: i,j,nsite,ntime,iref,jj,csite

! nsite = number of observation sites, csites = number of chemical sites, ntime = number of hours

parameter(nsite=32,csite=1,ntime=984)

real :: Tob(nsite,ntime),RHo(nsite,ntime),diro(nsite,ntime)
real :: raino(nsite,ntime),swo(nsite,ntime),po(nsite,ntime)
real :: Tdo(nsite,ntime),vo(nsite,ntime)
real :: Ts(nsite,ntime),RHs(nsite,ntime),dirs(nsite,ntime)
real :: rains(nsite,ntime),sws(nsite,ntime),ps(nsite,ntime)
real :: Tds(nsite,ntime),vs(nsite,ntime)
real :: PMo(csite,ntime),PMs(csite,ntime)

real :: pers(csite,ntime)
real :: bias,rmse,sde,r,x,y,sx,sy,dw,isig
real :: countn
real :: nrmse,fac2,nstdev,mg,fb,nmse
real :: biast(ntime),rmset(ntime),sdet(ntime)
real :: rt(ntime),xt(ntime),yt(ntime)
real :: sxt(ntime),syt(ntime),isigt(ntime),countt(ntime),dt(ntime)


! Open file to read the observational data

open(14,file=&
"/import/c/w/username/WRFV3/SKILLSETS/Overestimations.txt",&
   form="formatted",status="old")

Tob= -999.
RHo= -999.
vo= -999.
diro= -999.
raino= -999.
swo= -999.
po= -999.
Tdo= -999.

do i=1,nsite
do j=1,ntime
read(14,*) Tob(i,j),RHo(i,j),vo(i,j),diro(i,j),raino(i,j),swo(i,j),&
    po(i,j),Tdo(i,j)
if(vo(i,j) <=0.)diro(i,j)=-999.
end do
end do
close(14)

推荐答案

通常,我们需要查看数据文件以确定您为什么得到此错误.列表导向的输入很容易受到错误的影响,这些错误距离检测到错误的位置很远.例如,该错误在记录31489中报告,但也许记录7233的行上的值太少-以列表为导向,它将自动读取下一条记录以获取丢失的值,然后丢弃其余的新值线.然后,当到达最后一条记录时,它又需要一个..错误!

Generally, we would need to see the data file in order to determine why you get the error. List-directed input is very susceptible to mistakes made a long ways away from where the error is detected. For example, the error is reported at record 31489, but maybe record 7233 had one too few values on the line - with list-directed, it would automatically read the next record to pick up the missing value and then discard the rest of that new line. Then when it gets to the last record, it wants one more and.. error!

我非常有信心,问题出在数据文件中,而不是程序源中.您应该添加一些验证,以确保它确实在读取所需的值.根据数据文件的格式,我可能建议使用G格式而不是列表定向的格式化输入.我已经看到太多的程序员对列表导向的输入(和输出)误入歧途.

I am fairly confident that the problem is in the data file, not the program source. You should add some verification to make sure it is actually reading the values you want. Depending on how your data file is formatted, I might recommend using formatted input with G format rather than list-directed. I have seen far too many programmers led astray by list-directed input (and output).

这篇关于Fortran 90-尝试读取文件末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆