f90读取.txt文件返回NaN [英] f90 read .txt file return NaN

查看:202
本文介绍了f90读取.txt文件返回NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用fortran程序读取具有多个数组的.txt文件.

程序似乎正在查找文件,但只返回NaN值...

 !
INTEGER                              :: T, RH, i, j, ierror
!
REAL, DIMENSION(3,3)                 :: AFILE
!
LOGICAL                              :: dir_e

inquire(file='PSR_FAB.txt', exist=dir_e)

if ( dir_e ) then
 print*, "dir exists!"
else
 print*, 'nope'
end if

OPEN (UNIT = 1234 , FILE = 'PSR_FAB.txt', STATUS = 'OLD', ACTION = 'READ')

   DO i=1,3
      READ(1234,*, IOSTAT=ierror) (AFILE(i,j),j=1,3)
       print*, (AFILE(i,j),j=1,3)
!      if (ierror>0) then
!        stop 'Error while reading from file. '
!      elseif (ierror<0) then
!        print* ,PSR_FILE
!        stop 'Reached end of file. '
!      endif
   ENDDO
  CLOSE(UNIT=1234)
!
T=2
RH=3
print*,AFILE(T,RH)
!    

为了测试程序,我使用以下.txt文件:

1 2 3
4 5 6
7 8 9

此外,当我使用"ierror if test"时,会弹出到达文件末尾",这意味着ierror <0,这意味着到达文件末尾.

起初我以为是因为找不到文件,但是当我查询文件时,找到它没有问题...

正如我之前所说,读取文件后,AFILE仅包含NaN值.

我想知道问题是否出在.txt文件或代码中.也许这是READ语句,但是代码对我来说似乎没问题.

此刻我陷入困境,没有想法...有什么想法吗?

谢谢

解决方案

在Windows 2000上运行程序时,我遇到了类似的问题,但在Windows 7上运行良好.

在我的情况下,该应用程序是使用Intel Fortran V11在Win7机器上构建的.该应用程序可以在Win7机器上运行,但是在Win2000机器上运行时,它无法读取前2个条目.

尝试使用/arch:IA32选项进行编译.这将使用X87指令集而不是SSE2增强指令.这将产生一个在两个平台上均可使用的应用程序.

I am trying to read a .txt file with multiple arrays with a fortran program.

It looks like the program is finding the file but it only returns NaN value...

 !
INTEGER                              :: T, RH, i, j, ierror
!
REAL, DIMENSION(3,3)                 :: AFILE
!
LOGICAL                              :: dir_e

inquire(file='PSR_FAB.txt', exist=dir_e)

if ( dir_e ) then
 print*, "dir exists!"
else
 print*, 'nope'
end if

OPEN (UNIT = 1234 , FILE = 'PSR_FAB.txt', STATUS = 'OLD', ACTION = 'READ')

   DO i=1,3
      READ(1234,*, IOSTAT=ierror) (AFILE(i,j),j=1,3)
       print*, (AFILE(i,j),j=1,3)
!      if (ierror>0) then
!        stop 'Error while reading from file. '
!      elseif (ierror<0) then
!        print* ,PSR_FILE
!        stop 'Reached end of file. '
!      endif
   ENDDO
  CLOSE(UNIT=1234)
!
T=2
RH=3
print*,AFILE(T,RH)
!    

In order to test the program, I'm using the following .txt file:

1 2 3
4 5 6
7 8 9

Also, when I am using the "ierror if test", the "Reaching end of file" pops out, which mean ierror<0, which mean the end of file is reach.

At first I thought it was because it could not find the file, but when I inquire it, it has no problem finding it...

And as I said earlier, the AFILE contains only NaN value after the file has been read.

I am wondering if the problem lies in the .txt file or in the code. Maybe it is the READ statement, but the code seems ok to me.

I am kind of stuck at the moment and out of ideas... Any thoughts?

Thank you

解决方案

I experienced a similar problem when I ran a program on a Windows 2000, but it worked fine on a Windows 7 box.

In my situation, the application was built on a Win7 box using Intel Fortran V11. This application worked on a Win7 box, but when run on a Win2000 box it failed to read the first 2 entries.

Try compiling with the /arch:IA32 option. This will use the X87 instruction set instead of the SSE2 enhanced instructions. This produces an application that works on both platforms.

这篇关于f90读取.txt文件返回NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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