fortran2003

Using scientific notation and underscore kind specifier at the same time for real literals in Fortran

强颜欢笑 提交于 2019-11-28 14:18:30
Using scientific notation for floating point literals is easy enough in Fortran: 1.5d-10 would mean a double precision (whatever that means under current Fortran compiler settings) floating point value that approximates 1.5*10^-15 . However, the fusion of the exponent notation and the floating point kind specifier is a bit of an issue. How would one declare this floating point literal when one wants it to have a type of C_DOUBLE ? I know that this is a bit of a nitpicking issue, but there can be circumstances when double precision will not be the same as C_DOUBLE . A real literal may be

Does the finalization routine need to be elemental in order to be called on the elements of allocatable array that goes out of scope?

空扰寡人 提交于 2019-11-28 08:52:35
问题 If I have an allocatable array of a finalizable derived type, will the finalizer be called on every individual element when the array goes out of scope? Here is a small code example that illustrates the question: module LeakyTypeModule implicit none private type, public :: LeakyType real, pointer :: dontLeakMe(:) => null() contains procedure :: New final :: Finalizer end type contains subroutine New(self, n) class(LeakyType), intent(out) :: self integer , intent(in) :: n allocate(self

Using scientific notation and underscore kind specifier at the same time for real literals in Fortran

二次信任 提交于 2019-11-27 19:33:59
问题 Using scientific notation for floating point literals is easy enough in Fortran: 1.5d-10 would mean a double precision (whatever that means under current Fortran compiler settings) floating point value that approximates 1.5*10^-15 . However, the fusion of the exponent notation and the floating point kind specifier is a bit of an issue. How would one declare this floating point literal when one wants it to have a type of C_DOUBLE ? I know that this is a bit of a nitpicking issue, but there can

Passing type bound procedures as arguments

拜拜、爱过 提交于 2019-11-27 09:46:38
I am trying to pass a type bound procedure as an argument to another subroutine. I want to know if this is possible in Fortran. Here is a code snippet that shows what I am trying to do . module type_definitions type test_type integer :: i1, i2,i3 contains procedure :: add_integers_up end type test_type contains subroutine add_integers_up(this,i4,ans) class(test_type) :: this integer :: i4,ans ans = this%i1+this%i2+this%i3+i4 end subroutine add_integers_up subroutine print_result_of_subroutine(i4,random_subroutine) integer :: i4,ans interface subroutine random_subroutine(i1,i2) integer:: i1,i2

Passing type bound procedures as arguments

雨燕双飞 提交于 2019-11-26 14:53:54
问题 I am trying to pass a type bound procedure as an argument to another subroutine. I want to know if this is possible in Fortran. Here is a code snippet that shows what I am trying to do . module type_definitions type test_type integer :: i1, i2,i3 contains procedure :: add_integers_up end type test_type contains subroutine add_integers_up(this,i4,ans) class(test_type) :: this integer :: i4,ans ans = this%i1+this%i2+this%i3+i4 end subroutine add_integers_up subroutine print_result_of_subroutine