[Fortran] 纯文本查看 复制代码
type mytype
sequence
integer,dimension(:),allocatable:: array_type
integer,dimension(10):: other_variables
end type
type(mytype),dimension(:),allocatable:: array_main
allocate(array_main%array_type(10))
allocate(array_type(10))
end
[Fortran] 纯文本查看 复制代码
program main
implicit none
type :: mytype
sequence
integer, dimension(:), allocatable :: array_type
integer, dimension(10) :: other_variables
end type mytype
type(mytype), dimension(:), allocatable :: array_main
integer :: i
allocate (mytype :: array_main(10))
do i = 1, size(array_main)
allocate (array_main(i)%array_type(10))
end do
end program main
[Fortran] 纯文本查看 复制代码
type T_mytype !类型名做个区分
sequence
integer,allocatable:: array_type(:) !非必要不写dimension
integer:: other_variables(10)
end type T_mytype
!必要写 dimension 的情况是,需要大量定义相同大小尺寸的多个数组
type(T_mytype),allocatable:: array_main(:)
integer :: j
allocate(array_main(3)) !先分配array_main
do j = 1 , size(array_main)
allocate(array_main(j)%array_type(10)) !再逐个分配array_type
end do
!allocate(array_type(10)) !这句多余,且无意义
end
[Fortran] 纯文本查看 复制代码
type trace
sequence
type(segy_trace_head):: header
real(4),dimension(:),allocatable:: idata
end type
type(segy_reel_head):: reel_head
type(trace),dimension(:),allocatable:: traces
integer:: fp,fid_segy,fid_traces
integer:: i
open(newunit=fid_segy,file='D:/Example.SEGY',form='unformatted',access='stream',convert='big_endian')
allocate(traces(500))
do i = 1,500
allocate(traces(i)%idata(6000))
end do
read(fid_segy) reel_head
do i = 1, 500
read(fid_segy) traces(i) ! 读取前500道
end do