No Well Type Description Oil Rate Water Rate Gas Rate FBHP
(m3 /day) (m3 /day) (m3 /day) (kPa)
---------------------------------------------------------------------------------------------
No Well Type Description Oil Rate Water Rate Gas Rate FBHP
(m3 /day) (m3 /day) (m3 /day) (kPa)
---------------------------------------------------------------------------------------------
No Well Type Description Oil Rate Water Rate Gas Rate FBHP
(m3 /day) (m3 /day) (m3 /day) (kPa)
---------------------------------------------------------------------------------------------
No Well Type Description Oil Rate Water Rate Gas Rate FBHP
(m3 /day) (m3 /day) (m3 /day) (kPa)
---------------------------------------------------------------------------------------------
Time = 32.00000 days
1 P1 6 Liquid Production Rate Srf 14.81 15.19 0.000 0.000 1.026 50.63 1.1939E+04
Time = 32.00000 days
2 P2 6 Liquid Production Rate Srf 14.90 15.10 0.000 0.000 1.013 50.32 1.1984E+04
Time = 32.00000 days
3 P3 6 Liquid Production Rate Srf 14.86 15.14 0.000 0.000 1.019 50.47 1.1902E+04
Time = 32.00000 days
4 P4 6 Liquid Production Rate Srf 14.96 15.04 0.000 0.000 1.005 50.13 1.1943E+04
Time = 32.00000 days
5 P5 6 Liquid Production Rate Srf 14.65 15.35 0.000 0.000 1.048 51.18 1.2031E+04
No Well Type Description Oil Rate Water Rate Gas Rate FBHP
(m3 /day) (m3 /day) (m3 /day) (kPa)
---------------------------------------------------------------------------------------------
No Well Type Description Oil Rate Water Rate Gas Rate FBHP
(m3 /day) (m3 /day) (m3 /day) (kPa)
---------------------------------------------------------------------------------------------
Time = 32.00000 days
1 P1 6 Liquid Production Rate Srf 14.81 15.19 0.000 0.000 1.026 50.63 1.1939E+04
fcode 发表于 2015-4-14 17:16
Open 打开文件
循环 Read ,每次 read 读一行,如果不满足条件就继续下一次循环。
Backspace 回退一行。
fcode 发表于 2015-4-14 17:16
Open 打开文件
循环 Read ,每次 read 读一行,如果不满足条件就继续下一次循环。
Backspace 回退一行。
PROGRAM READPLOT
IMPLICIT NONE
INTEGER :: ERROR
CHARACTER(4) :: CTIME ! 检查是否为Time
DOUBLE PRECISION :: DTIME ! 临时存储Time后的值
INTEGER, PARAMETER :: MAXTN = 1000, MAXWN = 20 ! 最大存储1000个时间步,20口井的数据
DOUBLE PRECISION :: D(MAXTN) ! 存储Time后的所有值
CHARACTER(10) :: WELLNAME(MAXWN),WELL ! 存储井名,最大十个字符
INTEGER :: IT,IWELL ! 时间步数,井数
DOUBLE PRECISION :: OILRATE(MAXWN,MAXTN),WATERRATE(MAXWN,MAXTN) ! 油水产量
DOUBLE PRECISION :: GASRATE(MAXWN,MAXTN),GOR(MAXWN,MAXTN) ! 气产量,气油比
DOUBLE PRECISION :: WOR(MAXWN,MAXTN),WCUT(MAXWN,MAXTN),FBHP(MAXWN,MAXTN) ! 油水比,含水率,井底压力
DOUBLE PRECISION :: OR,WR,GR,G,WO,WC,FB ! 临时存储以上数据
INTEGER :: MXWN,MXTN ! 存入的最大数据个数
INTEGER :: I,J ! 循环变量
! 占位变量,不进行存储
CHARACTER(4) :: AA
INTEGER :: BB
CHARACTER(27) :: CC
! 初始化
IT = 1
D = 0.0
ERROR = 0
WELLNAME = ' '
! 读取数据
OPEN(UNIT = 415, FILE = 'plot.out')
DO WHILE(ERROR >= 0) ! 检查读取文件是否结束
READ(415,IOSTAT = ERROR) CTIME,AA,DTIME,AA,BB,AA,BB
IF(ERROR == 0) THEN ! 如果文件读取正常进行以下操作
IF(CTIME == 'Time') THEN
IF(IT == 1) THEN ! 如果是第一个时间步数据
D(IT) = DTIME
READ(415,IOSTAT = ERROR) IWELL,WELL,BB,CC,OR,WR,GR,G,WO,WC,FB
WELLNAME(IWELL) = WELL
OILRATE(IWELL,IT) = OR
WATERRATE(IWELL,IT) = WR
GASRATE(IWELL,IT) = GR
GOR(IWELL,IT) = G
WOR(IWELL,IT) = WO
WCUT(IWELL,IT) = WC
FBHP(IWELL,IT) = FB
ELSE
IF(D(IT) == DTIME) THEN ! 是否相同的时间步不同的井数据
READ(415,IOSTAT = ERROR) IWELL,WELL,BB,CC,OR,WR,GR,G,WO,WC,FB
WELLNAME(IWELL) = WELL
OILRATE(IWELL,IT) = OR
WATERRATE(IWELL,IT) = WR
GASRATE(IWELL,IT) = GR
GOR(IWELL,IT) = G
WOR(IWELL,IT) = WO
WCUT(IWELL,IT) = WC
FBHP(IWELL,IT) = FB
ELSE ! 下一个时间步第一口井数据
IT = IT + 1
D(IT) = DTIME
READ(415,IOSTAT = ERROR) IWELL,WELL,BB,CC,OR,WR,GR,G,WO,WC,FB
WELLNAME(IWELL) = WELL
OILRATE(IWELL,IT) = OR
WATERRATE(IWELL,IT) = WR
GASRATE(IWELL,IT) = GR
GOR(IWELL,IT) = G
WOR(IWELL,IT) = WO
WCUT(IWELL,IT) = WC
FBHP(IWELL,IT) = FB
END IF
END IF
END IF
END IF
END DO
CLOSE(415)
! 输出数据
OPEN(UNIT = 416, FILE = 'plot.dat')
MXWN = 1
MXTN = 1
DO I = 1,MAXTN
IF (D(MXTN) == 0) THEN
EXIT
ELSE
MXTN = MXTN + 1
END IF
END DO
DO I = 1, MAXWN
IF (WELLNAME(I) == ' ') THEN
EXIT
ELSE
MXWN = MXWN + 1
END IF
END DO
DO I = 1,MXWN
WRITE(416,1003) WELLNAME(I)
WRITE(416,1004)
DO J = 1, MXTN
WRITE(416,1005) D(J),OILRATE(I,J),WATERRATE(I,J),GASRATE(I,J), &
&GOR(I,J),WOR(I,J),WCUT(I,J),FBHP(I,J)
END DO
END DO
1003 FORMAT(A10)
1004 FORMAT('TIME',9X,'OILRATE',7X,'WATERRATE',5X,'GASRATE',7X,'GOR',11X, &
& 'WOR',11X,'WCUT',10X,'FBHP')
1005 FORMAT(F10.5,3X,6(G11.4,3X),G11.4)
CLOSE(416)
END PROGRAM
3.18 KB, 下载次数: 2
225 Bytes, 下载次数: 2
fcode 发表于 2015-4-14 17:16
Open 打开文件
循环 Read ,每次 read 读一行,如果不满足条件就继续下一次循环。
Backspace 回退一行。
! 读取数据
OPEN(UNIT = 415, FILE = 'plot.out')
Do !// 一直读
READ(415 ,IOSTAT = ERROR) cStr !// 先读入字符串
if ( Error /= 0 ) exit !// 如果读错,则退出循环(文件结束)
read( cStr , * ) cTime
if ( cTime == "Time" ) THEN
IF(IT == 1) THEN ! 如果是第一个时间步数据
D(IT) = DTIME
READ(415,IOSTAT = ERROR) IWELL,WELL,BB,CC,OR,WR,GR,G,WO,WC,FB
WELLNAME(IWELL) = WELL
OILRATE(IWELL,IT) = OR
WATERRATE(IWELL,IT) = WR
GASRATE(IWELL,IT) = GR
GOR(IWELL,IT) = G
WOR(IWELL,IT) = WO
WCUT(IWELL,IT) = WC
FBHP(IWELL,IT) = FB
ELSE
楚香饭 发表于 2015-4-15 19:26
我只修改一段代码,剩下的没动。
加了一个变量:
楚香饭 发表于 2015-4-15 19:26
我只修改一段代码,剩下的没动。
加了一个变量:
READ(415 ,IOSTAT = ERROR) cStr !// 先读入字符串
fcode 发表于 2015-4-17 12:33
读字符串有问题,一般就是文件结束了。通常没有其他问题。
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |