[Fortran] 纯文本查看 复制代码
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