Fortran Coder

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

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

[复制链接]

9

帖子

4

主题

0

精华

入门

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

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

[Fortran] 纯文本查看 复制代码
01program main1
02 implicit  none
03 real (kind=4) :: r,s,x,u,v,q,k,p
04 integer , parameter :: L=5
05 integer :: t
06 integer :: status=0
07 integer :: pipe
08 integer :: pip !用来赋值管道序号
09 integer :: time
10 real , allocatable :: qo(:,:)
11 real , allocatable :: x1(:,:)
12 real , allocatable :: u1(:,:)
13 real , allocatable :: v1(:,:)
14 real , allocatable :: qw(:,:)
15 real , allocatable :: qmix(:,:)
16 integer , allocatable :: timemax(:)
17 
18 
19 real (kind=4) :: ansq
20 real (kind=4) :: ansqo
21 real (kind=4) :: ansqw
22 real (kind=4) :: ww
23 real (kind=4) :: ko
24 real (kind=4) :: kw
25 real (kind=4) :: ansx
26 real (kind=4) :: sw
27logical alive
28 write(*,*) "压差p(MPa)"
29 read(*,*) p
30 inquire(file="r.txt",exist=alive)
31 if(.not.alive)then
32     write(*,*) "文件不存在"
33     stop
34 end if
35 open(unit=10,file="r.txt")
36 
37 pipe=0
38 do while (.true.)
39     read(10,"(F9.3)",iostat=status)r
40     if(status/=0) exit
41     pipe=pipe+1
42 end do
43 !此处读取管道个数的程序,即为pipe的大小
44     
45     allocate(qo(pip,t))
46     allocate(qw(pip,t))
47     allocate(qmix(pip,t))
48     allocate(x1(pip,t))
49     allocate(u1(pip,t))
50     allocate(v1(pip,t))
51     allocate(timemax(pipe))
52 
53   open (unit=10,file="r.txt")
54   rewind(10)
55   do pip = 1 , pipe 
56   x=0
57   t=0
58   read(10,"(F9.3)",iostat=status)r
59   s=3.14*(r*0.0001/2)**2
60   write(*,*) r
61    do while (x<=L)
62     u=(5*(L-x)**2+0.75*x**2)/((L-x)**2+x**2)
63     v=((r*0.000001/2))**2*p*1000000/(8*u*0.001*0.05*100)
64     q=v*s
65     x=x+v
66     t=t+1
67     
68    qmix(pip,t)=q
69     x1(pip,t)=x
70     u1(pip,t)=u
71     v1(pip,t)=v
72     timemax(pip)=t
73 
74    end do
75   end do
76   write(*,*) x1(1,1)
77   write(*,*)"请输入管道序号及时间"
78   read(*,*)pip,t
79  write(*,*) x1(pip,t)



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

213

帖子

2

主题

0

精华

宗师

F 币
2142 元
贡献
875 点

规矩勋章

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

本版积分规则

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

GMT+8, 2025-3-15 06:58

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

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