[Fortran] 纯文本查看 复制代码
type :: L2R2
!===============================================================================
! a1*L1^CL1 + a2*L2^CL2 + e*E^(-1) <---> b1*R1^CR1 + b2*R2^CR2 , p = XXX V
!
! for example:
!
! No = 1
! idn= 'L2R2_001'
! Rx = 'O3 + 2 H^(+) + 2 e^(-) <---> O2 + H2O' Pot = +2.075 V
!
! a1 = 1 ; L1 = 'O3' ; CL1 = 0
! a2 = 2 ; L2 = 'H' ; CL1 = 1
! e = 2 ;
! b1 = 1 ; R1 = 'O2' ; CR1 = 0
! b2 = 1 ; R1 = 'H2O' ; CL1 = 0
! p = 2.075
!==============================================================================
integer :: No
character(10) :: idn
character(100) :: Rx
integer :: a1
character(20) :: L1
integer :: CL1
integer :: a2
character(20) :: L2
integer :: CL2
integer :: e
integer :: b1
character(20) :: R1
integer :: CR1
integer :: b2
character(20) :: R2
integer :: CR2
real :: p
end type L2R2
[Fortran] 纯文本查看 复制代码
type (L2R2) :: L2R2_003
!==============================================================================
! No = 3 Rx = 'ZnO2^(2-) + 2 H2O + 2 e^(-) <---> Zn + 4 OH^(-)' Pot = -1.285 V
!==============================================================================
L2R2_003%No = 3
L2R2_003%idn = 'L2R2_003'
L2R2_003%Rx = 'ZnO2^(2-) + 2 H2O + 2 e^(-) <---> Zn + 4 OH^(-)'
L2R2_003%a1 = 1
L2R2_003%L1 = 'ZnO2'
L2R2_003%CL1 = -2
L2R2_003%a2 = 2
L2R2_003%L2 = 'H2O'
L2R2_003%CL2 = 0
L2R2_003%e = 2
L2R2_003%b1 = 1
L2R2_003%R1 = 'Zn'
L2R2_003%CR1 = 0
L2R2_003%b2 = 4
L2R2_003%R2 = 'OH'
L2R2_003%CR2 = -1
L2R2_003%p = -1.285
[Fortran] 纯文本查看 复制代码
L2R2_003 = (/ 3 , "L2R2_003" , "ZnO2^(2-) + 2 H2O + 2 e^(-) <---> Zn + 4 OH^(-)" , &
1 , "ZnO2" , -2 , 2 , "H2O" , 0 , 2 , 1 , "Zn" , 0 , 4 , "OH" , -1 , -1.285 /)
[Fortran] 纯文本查看 复制代码
module example
implicit none
type:: base
integer:: nlen=2
real, allocatable:: array(:)
end type
interface base
module procedure new_base
module procedure new_base_list
end interface
contains
function new_base(nlen)
implicit none
integer, intent(in), optional:: nlen
type(base):: new_base
write(*, "('Call constructor: new_base(nlen)')")
if (present(nlen)) then
if (0 < nlen) then
new_base%nlen = nlen
write(*, '(2x, "User defined length:", 1x, i4)') nlen
else
write(*, '(2x, "Negetive input and use default value 2")')
endif
else
write(*, '(2x, "Default length: 2")')
end if
allocate(new_base%array(new_base%nlen))
end function
function new_base_list(array) result(new_base)
implicit none
real, intent(in):: array(:)
type(base):: new_base
write(*, "('Call constructor: new_base_list(array)')")
new_base%nlen = size(array)
allocate(new_base%array(new_base%nlen))
new_base%array = array
write(*, "(2x, 'Array:', *(f7.2))")new_base%array
end function
end module
program oop
use example
implicit none
type(base):: a1, a2, a3, a4
a1 = base()
a2 = base(nlen=6)
a3 = base(-2)
a4 = base([1E1, 3E2, 5E0, 7E0, 9E1])
end program