module curveModule
type point !定义一个点
integer x,y,z
end type
type curve !定义一个曲线,有很多点构成
type(point),dimension(:),allocatable::points
character(:),allocatable::name
contains
procedure,pass,public::initCurve
end type
contains
subroutine initCurve(self,psNum,ps,theName)
class(curve)::self
integer::psNum
type(point),dimension(psNum)::ps
character(len=*)::theName
allocate(self.points(psNum))
self.points=ps
self.name=theName
end subroutine
end module
module figureModule
type figure !定义图表,有几条曲线构成
type(curve)::c1,c2,c3
contains
procedure,pass::init
end type
contains
subroutine init(self,inputFile)
character(:),allocatable::inputFile
class(figure)::self
type(point)::p1=point(1,2,3),p2=point(2,3,4),p3=point(3,4,5),p4=point(4,5,6)
type(point)::ps1(4),ps2(4)
ps1=(\p1,p2,p3,p4\)
ps2=(\p2,p3,p4,p1\)
self.c1.init(size(ps1),ps1,'curve-1')
self.c2.init(size(ps2),ps2,'curve-2') !若是只有才c1一个变量可执行,两个就不可,会覆盖第一个
write(*,*) self.c1.name,self.c2.name
end subroutine
end module
program main
type(figure)::f
call f.init('a.txt') !读入一个数据文件,将数据文件格式化的存成一个图表对象
end program
module curveModule
type point !定义一个点
integer x,y,z
end type
type curve !定义一个曲线,有很多点构成
type(point),dimension(:),allocatable::points
character(:),allocatable::name
contains
procedure,pass,public::initCurve
end type
contains
subroutine initCurve(self,psNum,ps,theName)
class(curve)::self
integer::psNum
type(point),dimension(psNum)::ps
character(len=*)::theName
allocate(self.points(psNum))
self.points=ps
self.name=theName
end subroutine
end module
module figureModule
use curveModule
type figure !!定义图表,有几条曲线构成
type(curve)::c1,c2,c3
contains
procedure,pass::init
end type
contains
subroutine init(self,inputFile)
character(*) inputFile
class(figure)::self
type(point)::p1=point(1,2,3),p2=point(2,3,4),p3=point(3,4,5),p4=point(4,5,6)
type(point)::ps1(4),ps2(4)
ps1=(/p1,p2,p3,p4/)
ps2=(/p2,p3,p4,p1/)
call self.c1.initCurve(size(ps1),ps1,'curve-1')
call self.c2.initCurve(size(ps2),ps2,'curve-2') !!若是只有才c1一个变量可执行,两个就不可,会覆盖第一个
write(*,*) self.c1.name,self.c2.name
end subroutine
end module
program main
use figureModule
type(figure)::f
call f.init('a.txt') !!读入一个数据文件,将数据文件格式化的存成一个图表对象
end program
IMG_20151202_101649.jpg (54.54 KB, 下载次数: 275)
IMG_20151202_101955.jpg (66.24 KB, 下载次数: 300)
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |