Fortran Coder

查看: 3310|回复: 1
打印 上一主题 下一主题

[求助] 可分配数组在迭代循环中的赋值问题

[复制链接]

9

帖子

4

主题

0

精华

入门

F 币
45 元
贡献
28 点
跳转到指定楼层
楼主
发表于 2022-3-17 16:02:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 richard7 于 2022-3-17 16:06 编辑

循环中和循坏外输出的x1的值并不一样,循环中的x1的值正常,但循环外的x1的值被最后一个值给覆盖了,想知道这是为什么

[Fortran] 纯文本查看 复制代码
program main1
 implicit  none
 real (kind=4) :: r,s,x,u,v,q,k,p
 integer , parameter :: L=5 
 integer :: t
 integer :: status=0
 integer :: pipe
 integer :: pip !用来赋值管道序号
 integer :: time
 real , allocatable :: qo(:,:)
 real , allocatable :: x1(:,:)
 real , allocatable :: u1(:,:)
 real , allocatable :: v1(:,:)
 real , allocatable :: qw(:,:)
 real , allocatable :: qmix(:,:)
 integer , allocatable :: timemax(:)


 real (kind=4) :: ansq
 real (kind=4) :: ansqo
 real (kind=4) :: ansqw
 real (kind=4) :: ww
 real (kind=4) :: ko
 real (kind=4) :: kw 
 real (kind=4) :: ansx
 real (kind=4) :: sw
logical alive
 write(*,*) "压差p(MPa)"
 read(*,*) p
 inquire(file="r.txt",exist=alive)
 if(.not.alive)then
     write(*,*) "文件不存在"
     stop
 end if
 open(unit=10,file="r.txt")

 pipe=0
 do while (.true.)
     read(10,"(F9.3)",iostat=status)r
     if(status/=0) exit
     pipe=pipe+1
 end do
 !此处读取管道个数的程序,即为pipe的大小
    
     allocate(qo(pip,t))
     allocate(qw(pip,t))
     allocate(qmix(pip,t))
     allocate(x1(pip,t))
     allocate(u1(pip,t))
     allocate(v1(pip,t))
     allocate(timemax(pipe))

   open (unit=10,file="r.txt")
   rewind(10)
   do pip = 1 , pipe  
   x=0
   t=0
   read(10,"(F9.3)",iostat=status)r
   s=3.14*(r*0.0001/2)**2
   write(*,*) r
    do while (x<=L)
     u=(5*(L-x)**2+0.75*x**2)/((L-x)**2+x**2)
     v=((r*0.000001/2))**2*p*1000000/(8*u*0.001*0.05*100)
     q=v*s
     x=x+v
     t=t+1
    
    qmix(pip,t)=q
     x1(pip,t)=x
     u1(pip,t)=u
     v1(pip,t)=v
     timemax(pip)=t

    end do
   end do
   write(*,*) x1(1,1)
   write(*,*)"请输入管道序号及时间"
   read(*,*)pip,t
  write(*,*) x1(pip,t)



分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

213

帖子

2

主题

0

精华

宗师

F 币
2126 元
贡献
875 点

规矩勋章

沙发
发表于 2022-3-18 00:07:15 | 只看该作者
allocate语句有错。变量pip, t在allocate语句前没有赋值,默认为0 。
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-4-27 03:27

Powered by Tencent X3.4

© 2013-2024 Tencent

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