如何使用隐式DO循环调试Fortran READ / WRITE语句? [英] How can I debug a Fortran READ/WRITE statement with an implicit DO loop?

查看:1846
本文介绍了如何使用隐式DO循环调试Fortran READ / WRITE语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 在文件的第182行。 ./SOURCE_FILE.f90(unit = 1,file ='INPUT_FILE.1')
Fortran运行时错误:在整数读取期间出现错误值

展望182行,我看到一条带有隐含/隐含DO循环的READ语句:

  182:READ(IT4,310)((IPPRM2(IP,I),IP = 1,NP),I = 1,16)!读取6个整数
183:READ(IT4,320)((PPARM2(IP,I),IP = 1,NP),I = 1,14)!阅读5个reals

格式声明:

  310 FORMAT(1X,6I12)

在调试器中 NP 的值为2. I 的值为6, IP 的值为67.我认为 I IP 应该重新初始化循环。



我的问题是,当我尝试在调试器中逐步完成READ语句时,它似乎执行并抛出错误。我不确定如何按照它读取。我尝试着进入这个功能,但是由于我不熟悉gfortran库,似乎这可能是一条困难的路线。输入文件看起来不错,我认为它应该被读取得很好。这使得我认为这个READ语句没有像预期的那样循环。



我对Fortran和这种隐式DO循环完全陌生,但从我可以收集的第182行应根据格式字符串#310读取6个整数。但是,当我到达时,NP 的值为2,这让我认为它只会尝试读取16次2个整数。



如何调试此读取语句,以检查从文件中读取的读入 IPPARM 的值?我将不得不逐步通过Fortran库?



任何提示可以消除我对这些隐式循环的困惑,我们将不胜感激!



谢谢!

注意:我在Linux上使用gfortran / gcc和gdb。

解决方案

变量IP和I是循环索引,因此它们由循环重新初始化。在NP = 2的情况下,第一个语句将读取总共32个整数 - 它有助于确定要读取的项目列表。格式决定了他们如何阅读。使用1X,6I12,它们将被读取为输入文件的每行6个整数。当所请求的32个整数中的前6个从行/记录读取时,Fortran将认为该行/记录已完成并前进到下一个记录。



1X,6I12整数必须精确排列在文件中。应该有一个空白,然后整数应该在12列的字段中右对齐。如果它们失去对齐性,可能会读取错误的值或运行时错误。

The Fortran program I am working is encountering a runtime error when processing an input file.

At line 182 of file ../SOURCE_FILE.f90 (unit = 1, file = 'INPUT_FILE.1')
Fortran runtime error: Bad value during integer read

Looking to line 182 I see a READ statement with an implicit/implied DO loop:

182:    READ(IT4, 310 )((IPPRM2(IP,I),IP=1,NP),I=1,16)    ! read 6 integers
183:    READ(IT4, 320 )((PPARM2(IP,I),IP=1,NP),I=1,14)    ! read 5 reals

Format statement:

310 FORMAT(1X,6I12)

When I reach this code in the debugger NP has a value of 2. I has a value of 6, and IP has a value of 67. I think I and IP should be reinitialized in the loop.

My problem is that when I try to step through in the debugger once I get to the READ statement it seems to execute and then throw the error. I'm not sure how to follow it as it reads. I tried stepping into the function, but it seems like that may be a difficult route to take since I am unfamiliar with the gfortran library. The input file looks OK, I think it should be read just fine. This makes me think this READ statement isn't looping as intended.

I am completely new to Fortran and implicit DO loops like this, but from what I can gather line 182 should read in 6 integers according to the format string #310. However, when I arrive NP has a value of 2 which makes me think it will only try to read 2 integers 16 times.

How can I debug this read statement to examine the values read into IPPARM as they are read from the file? Will I have to step through the Fortran library?

Any tips that can clear up my confusion regarding these implicit loops would be appreciated!

Thanks!

NOTE: I'm using gfortran/gcc and gdb on Linux.

解决方案

The variables IP and I are loop indices and so they are reinitialized by the loop. With NP=2 the first statement is going to read a total of 32 integers -- it is contributing to the determination the list of items to read. The format determines how they are read. With "1X,6I12" they will be read as 6 integers per line of the input file. When the first 6 of the requested 32 integers is read fron a line/record, Fortran will consider that line/record completed and advance to the next record.

With a format of "1X,6I12" the integers must be precisely arranged in the file. There should be a single blank, then the integers should each be right-justified in fields of 12 columns. If they get out of alignment you could get the wrong value read or a runtime error.

这篇关于如何使用隐式DO循环调试Fortran READ / WRITE语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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