Fortran Coder

查看: 10447|回复: 3
打印 上一主题 下一主题

[求助] 用include来读取一个数组的时候碰到的问题

[复制链接]

60

帖子

17

主题

0

精华

专家

F 币
454 元
贡献
266 点
跳转到指定楼层
楼主
发表于 2014-10-17 16:24:08 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
在debug一个程序的时候发现了这样的一个bug:
有个头文件output_step.h的内容大致如下:


!====2D output
    nt2d(1)=1 ; nt2d(2)=243
!    nt2d(1)=3286 ; nt2d(2)=3650
!====time-series output(nts分記入,stepは重複しないようにする)
    nnts(1,1)=    1 ; nnts(1,2)=  243
    nnts(2,1)=  366 ; nnts(2,2)=  730
    nnts(3,1)=  731 ; nnts(3,2)= 1095
    nnts(4,1)= 1096 ; nnts(4,2)= 1460
    nnts(5,1)= 1461 ; nnts(5,2)= 1825
    nnts(6,1)= 1826 ; nnts(6,2)= 2190
    nnts(7,1)= 2191 ; nnts(7,2)= 2555
    nnts(8,1)= 2556 ; nnts(8,2)= 2920
    nnts(9,1)= 2921 ; nnts(9,2)= 3285
    nnts(10,1)= 3286 ; nnts(10,2)= 3650

主程序中用include来读取一个头文件,大概内容如下
implicit none
(省略部分)
    include "output_step.h"
!====debug==
    write(*,*)nnts(1,1)
    write(*,*)nnts(1,2)
    write(*,*)nnts(2,1)
    write(*,*)nnts(2,2)

(省略部分)

end

电脑是64位,windows7,编译器是Microsoft Visual Studio Fortran2008
用ifort 编译,结果是:
1
366
366
731

也就是说读入了数据以后马上就输出,没有经过任何数值计算,结果竟然错了。一开始以为Fortran数据储存的方式是先循环前面的,然后出现了这个bug,可是看这组数据貌似不是那么简单了。

我瞬间就凌乱了,难道我电脑也是醉了吗?
这让我以后还敢用include吗?

求各位大神指点到底是什么原因``


Image 1.png (1005 Bytes, 下载次数: 251)

Image 1.png
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

712

帖子

4

主题

0

精华

大师

农村外出务工人员

F 币
608 元
贡献
311 点

新人勋章爱心勋章水王勋章元老勋章热心勋章

沙发
发表于 2014-10-17 17:14:40 | 只看该作者
传所有代码吧

60

帖子

17

主题

0

精华

专家

F 币
454 元
贡献
266 点
板凳
 楼主| 发表于 2014-10-17 17:36:55 | 只看该作者
由于write 后面的部分没有参与所以省略不计
程序如下
[Fortran] 纯文本查看 复制代码
program xx
    implicit none
    include "param.h"
    include "TECIO_mod.f90"
    real(8) :: X(ngi,ngj),Y(ngi,ngj),T(ni,nj),SS(ni,nj),TURB(ni,nj),U(ni,nj),V(ni,nj),yvd(ngj),dx(ni)
    real(8),allocatable :: XT(:,:),YT(:,:),TT(:,:),SST(:,:),TURBT(:,:),UT(:,:),VT(:,:)
    real(8) :: dys,ytmp1,ytmp2
    integer :: i,j,ii,jj,tloop,io
    integer :: dts,dto,tts1,tts2
    integer :: iyr,imon,iday,ihour,niu,njs
    integer :: js(ni)
!====Variables for Tecplot-Binary Output
    integer(4) :: ti,tiii,imax,jmax,kmax,debug,disdouble,visdouble
    integer(4) :: strandid,parentzn
    integer(4) :: pvl(7),valloc(7),sharingzone(7)
    real(8) :: soltime1,soltime2
    character(len=1) :: nulchar
    character(len=15) :: timchar1,timchar2
    include "output_step.h"
    
!====debug==
    write(*,*)nnts(1,1)
    write(*,*)nnts(1,2)
    write(*,*)nnts(2,1)
    write(*,*)nnts(2,2)

end

output_step.h 文件的内容已经完整传上来了。可以看到前面的代码都只是定义变量的部分,跟这部分应该没有关系。

712

帖子

4

主题

0

精华

大师

农村外出务工人员

F 币
608 元
贡献
311 点

新人勋章爱心勋章水王勋章元老勋章热心勋章

地板
发表于 2014-10-17 17:41:48 | 只看该作者
本帖最后由 楚香饭 于 2014-10-17 17:44 编辑

根据你已有的代码来看,不会出错,实际上在我这里也是正常的。

建议你无省略的上传所有代码(可打包,上传附件)
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-16 17:26

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表