【问题标题】:Solve error: Fortran runtime error: Bad integer for item 0 in list input解决错误:Fortran 运行时错误:列表输入中第 0 项的整数错误
【发布时间】:2015-02-22 12:04:13
【问题描述】:

我最近将我的 f90 编辑器更改为 Mac OS X 的 CodeBlocks,当我尝试打开位于项目文件夹中的文件以读取数据时,运行代码时屏幕上会出现下一条错误消息:

Fortran 运行时错误:列表输入中第 0 项的整数错误

我介绍了我在 Windows 7 中使用 fortran 和 Visual Studio 的英特尔编译器编写的相同代码。

代码本身是:

subroutine read_input_data

use input_data

implicit none

integer i,j

open(UNIT=5, FILE='lifting_line_input_data.txt', STATUS='old', FORM='formatted', ACCESS='sequential')

    read(5,*) C
    read(5,*) U
    read(5,*) alpha
    read(5,*) rho
    read(5,*) wake_length
    read(5,*) wake_eps
    read(5,*) n_chord
    read(5,*) n_twist

    if (n_chord .GE. n_twist ) then
        i = n_chord
    else
        i = n_twist
    end if

    allocate(chord_twist(5,i))

    do j = 1, i
        read(5,*) chord_twist(:,j)
    end do

close(5)

end subroutine read_input_data

你能帮我解决这个问题吗?非常感谢。

PD。数据文件是从保存为.txt 的 Excel 工作表中获取的,由制表符分隔

! LIFTING-LINE WING             
! Number of panels              
6               
! Free stream speed [m/s]               
50              
! Angle of attack [rad]             
0.15                
! Air density [kg/m^3]              
1.225               
! Wake length [m]               
100             
! Convergence parameter             
0.01                
! Number of data points given for the chord distribution                
2               
! Number of data points given for the twist distribution                
2               
! Y coord [m]   ! X_LE [m]  ! X_TE [m]  ! Y coord [m]   ! Twist [rad]

0   0   2   0   0

10  0   0.5 10  0.052359878

PD2。我更改了 .txt 文件的格式,使其与我在 Visual Studio 中使用的输入文件相同。现在文件是:

6   ! Number of panels                              
50  ! Free stream speed [m/s]                               
0.15    ! Angle of attack [rad]                             
1.225   ! Air density [kg/m^3]                              
100 ! Wake length [m]                               
0.01    ! Convergence parameter                             
2   ! Number of data points given for the chord distribution                                
2   ! Number of data points given for the twist distribution                                
0   0   2   0   0   ! Y coord [m]   ! X_LE [m]  ! X_TE [m]  ! Y coord [m]   !Twist [rad]
10  0   0.5 10  0.052359878 

现在终端给出的错误是找不到文件。由于我是 CodeBlocks 的初学者,所以我将逐步解释我所做的事情,因为我没有发现我错在哪里,我开始感到绝望:

  1. 新建项目 -> Fortran 应用程序 -> 我指明要在哪里创建项目文件。
  2. 我删除了 main.f95 文件并添加了带有代码的 .f90 文件。
  3. 我写代码。
  4. 我将 .txt 文件保存在与项目的所有文件相同的文件夹中。

当我运行代码时,会出现找不到文件的错误消息。 代码是:

!************************************************

subroutine read_input_data

use input_data
implicit none
integer i,j

open(UNIT=10, FILE='lifting_line_wing_input.txt', STATUS='old',     ACCESS='sequential')

    read(10,*) C
    read(10,*) U
    read(10,*) alpha
    read(10,*) rho
    read(10,*) wake_length
    read(10,*) wake_eps
    read(10,*) n_chord
    read(10,*) n_twist

    if (n_chord .GE. n_twist ) then
        i = n_chord
    else
        i = n_twist
    end if

    allocate(chord_twist(5,i))

    do j = 1, i
        read(10,*) chord_twist(:,j)
    end do

close(10)

end subroutine read_input_data

!************************************************

非常感谢您的宝贵时间和帮助

【问题讨论】:

  • 您的数据文件是什么样的? CodeBlocks 我不是编译器,它是一个编辑器。
  • 另外,不要使用单元号 5,它通常在其他地方预先连接。使用大于 10 的数字。
  • 首先非常感谢您回答问题。我已经证明了更大的数字(15 和 50)并且出现了相同的错误。数据文件是从 excel 获得的 .txt 文件,将其保存为带有表格的 .txt 文件。我是这个网站的新手,不知道如何在评论中粘贴格式正确的 .txt 文件的文本,所以我将编辑问题并将其粘贴到那里。
  • 编辑问题是正确的。不要使用 cmets 获取重要信息。
  • 文件是否在正确的目录中?文件名的大小写是否正确?如果您从程序中创建一个文件,它最终会在您的文件所在的目录中吗?

标签: fortran codeblocks


【解决方案1】:

这看起来像您的旧系统在列表导向输入上使用感叹号做了一些非标准的操作。

尝试重新格式化您的输入数据,例如

6 / number of panels

(斜线将终止 READ)。

【讨论】:

  • 首先非常感谢您的帮助。我做了一些和你说的类似的事情,实际上是我在其他项目中用Visual Studio使用过的那种文件,但是知道,正如我在PD2中解释的那样,代码找不到文件,你知道吗为什么?我已将它保存在与其余项目文件相同的文件夹中。非常感谢
【解决方案2】:

我不相信任何 fortran 编译器会自动处理这些 cmets。 如果您想按原样读取此文件,一种方法是让每次读取都处理错误,例如,

 integer ios
 ios = 1  
 do while(ios.ne.0)
  read(unit,*,iostat=ios)c
 end do
 ios=1
 do while(ios.ne.0)
  read(unit,*,iostat=ios)u
 end do

等等。 如果它是一次性的,您可以只编辑文件并删除所有 cmets。

【讨论】:

  • 首先非常感谢您的帮助,但是我试过了,还是不行。虽然我已经做出了我在 PD2 中解释过的更改,但现在错误是找不到文件……你知道为什么吗?我已将 .txt 保存在与所有项目文件相同的文件夹中...非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多