From 21ddfd950ea681ac2edd8aadcebaf294d1f5c48a Mon Sep 17 00:00:00 2001 From: prasetya Date: Wed, 24 Nov 2021 17:11:41 +0100 Subject: [PATCH 1/2] remove precompiler directives --- src/mo_utils.F90 | 103 ++--------------------------------------------- 1 file changed, 4 insertions(+), 99 deletions(-) diff --git a/src/mo_utils.F90 b/src/mo_utils.F90 index 8e5a2e8..26754d7 100755 --- a/src/mo_utils.F90 +++ b/src/mo_utils.F90 @@ -206,6 +206,8 @@ MODULE mo_utils MODULE PROCEDURE is_finite_sp, is_finite_dp END INTERFACE is_finite + !> \param[in] "real(sp/dp) :: x" Number to check + INTERFACE is_nan MODULE PROCEDURE is_nan_sp, is_nan_dp END INTERFACE is_nan @@ -552,48 +554,35 @@ CONTAINS ELEMENTAL PURE FUNCTION is_finite_dp(a) -#ifndef GFORTRAN + use, intrinsic :: ieee_arithmetic, only : ieee_is_finite -#endif IMPLICIT NONE REAL(dp), INTENT(IN) :: a LOGICAL :: is_finite_dp -#ifndef GFORTRAN is_finite_dp = ieee_is_finite(a) -#else - is_finite_dp = (.not. ((a > huge(a)) .or. (a < -huge(a)))) .and. (.not. is_nan(a)) -#endif END FUNCTION is_finite_dp ELEMENTAL PURE FUNCTION is_finite_sp(a) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : ieee_is_finite -#endif IMPLICIT NONE REAL(sp), INTENT(IN) :: a LOGICAL :: is_finite_sp -#ifndef GFORTRAN is_finite_sp = ieee_is_finite(a) -#else - is_finite_sp = (.not. ((a > huge(a)) .or. (a < -huge(a)))) .and. (.not. is_nan(a)) -#endif END FUNCTION is_finite_sp ELEMENTAL PURE FUNCTION is_nan_dp(a) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : isnan => ieee_is_nan -#endif IMPLICIT NONE @@ -606,9 +595,7 @@ CONTAINS ELEMENTAL PURE FUNCTION is_nan_sp(a) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : isnan => ieee_is_nan -#endif IMPLICIT NONE @@ -622,39 +609,27 @@ CONTAINS ELEMENTAL PURE FUNCTION is_normal_dp(a) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : ieee_is_normal -#endif IMPLICIT NONE REAL(dp), INTENT(IN) :: a LOGICAL :: is_normal_dp -#ifndef GFORTRAN is_normal_dp = ieee_is_normal(a) -#else - is_normal_dp = is_finite(a) -#endif END FUNCTION is_normal_dp ELEMENTAL PURE FUNCTION is_normal_sp(a) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : ieee_is_normal -#endif IMPLICIT NONE REAL(sp), INTENT(IN) :: a LOGICAL :: is_normal_sp -#ifndef GFORTRAN is_normal_sp = ieee_is_normal(a) -#else - is_normal_sp = is_finite(a) -#endif END FUNCTION is_normal_sp @@ -834,7 +809,6 @@ CONTAINS function special_value_dp(x, ieee) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : ieee_value, & IEEE_SIGNALING_NAN, & IEEE_QUIET_NAN, & @@ -846,7 +820,6 @@ CONTAINS IEEE_POSITIVE_NORMAL, & IEEE_NEGATIVE_ZERO, & IEEE_POSITIVE_ZERO -#endif implicit none @@ -856,12 +829,9 @@ CONTAINS ! local character(len = 21) :: ieee_up -#ifdef GFORTRAN - real(dp) :: tmp -#endif + real(dp) :: tmp ieee_up = toupper(ieee) -#ifndef GFORTRAN select case(trim(ieee_up)) case('IEEE_SIGNALING_NAN') special_value_dp = ieee_value(x, IEEE_SIGNALING_NAN) @@ -886,42 +856,11 @@ CONTAINS case default special_value_dp = 0.0_dp end select -#else - select case(ieee_up) - case('IEEE_SIGNALING_NAN') - tmp = 0.0_dp - special_value_dp = tmp / tmp - case('IEEE_QUIET_NAN') - tmp = 0.0_dp - special_value_dp = tmp / tmp - case('IEEE_NEGATIVE_INF') - tmp = huge(x) - special_value_dp = -tmp * tmp - case('IEEE_POSITIVE_INF') - tmp = huge(x) - special_value_dp = tmp * tmp - case('IEEE_NEGATIVE_DENORMAL') - special_value_dp = -0.0_dp - case('IEEE_POSITIVE_DENORMAL') - special_value_dp = 0.0_dp - case('IEEE_NEGATIVE_NORMAL') - special_value_dp = -1.0_dp - case('IEEE_POSITIVE_NORMAL') - special_value_dp = 1.0_dp - case('IEEE_NEGATIVE_ZERO') - special_value_dp = -0.0_dp - case('IEEE_POSITIVE_ZERO') - special_value_dp = 0.0_dp - case default - special_value_dp = 0.0_dp - end select -#endif end function special_value_dp function special_value_sp(x, ieee) -#ifndef GFORTRAN use, intrinsic :: ieee_arithmetic, only : ieee_value, & IEEE_SIGNALING_NAN, & IEEE_QUIET_NAN, & @@ -933,7 +872,6 @@ CONTAINS IEEE_POSITIVE_NORMAL, & IEEE_NEGATIVE_ZERO, & IEEE_POSITIVE_ZERO -#endif implicit none @@ -943,12 +881,9 @@ CONTAINS ! local character(len = 21) :: ieee_up -#ifdef GFORTRAN real(sp) :: tmp -#endif ieee_up = toupper(ieee) -#ifndef GFORTRAN select case(trim(ieee_up)) case('IEEE_SIGNALING_NAN') special_value_sp = ieee_value(x, IEEE_SIGNALING_NAN) @@ -973,36 +908,6 @@ CONTAINS case default special_value_sp = 0.0_sp end select -#else - select case(ieee_up) - case('IEEE_SIGNALING_NAN') - tmp = 0.0_sp - special_value_sp = tmp / tmp - case('IEEE_QUIET_NAN') - tmp = 0.0_sp - special_value_sp = tmp / tmp - case('IEEE_NEGATIVE_INF') - tmp = huge(x) - special_value_sp = -tmp * tmp - case('IEEE_POSITIVE_INF') - tmp = huge(x) - special_value_sp = tmp * tmp - case('IEEE_NEGATIVE_DENORMAL') - special_value_sp = -0.0_sp - case('IEEE_POSITIVE_DENORMAL') - special_value_sp = 0.0_sp - case('IEEE_NEGATIVE_NORMAL') - special_value_sp = -1.0_sp - case('IEEE_POSITIVE_NORMAL') - special_value_sp = 1.0_sp - case('IEEE_NEGATIVE_ZERO') - special_value_sp = -0.0_sp - case('IEEE_POSITIVE_ZERO') - special_value_sp = 0.0_sp - case default - special_value_sp = 0.0_sp - end select -#endif end function special_value_sp -- GitLab From 49c891c18c10ecb8bbb3429138bd6fd69ae914a8 Mon Sep 17 00:00:00 2001 From: prasetya Date: Thu, 25 Nov 2021 00:47:42 +0100 Subject: [PATCH 2/2] docstring is_normal is_nan is_finite special_value --- src/mo_utils.F90 | 106 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 32 deletions(-) diff --git a/src/mo_utils.F90 b/src/mo_utils.F90 index 26754d7..e9c04f9 100755 --- a/src/mo_utils.F90 +++ b/src/mo_utils.F90 @@ -152,20 +152,19 @@ MODULE mo_utils ! ------------------------------------------------------------------ ! NAME - ! is_finite / is_nan / is_normal + ! is_finite ! PURPOSE ! Elemental inquiry functions returning .true. if the argument has a value ! implied by the name of the function. ! - !> \brief .true. if not IEEE Inf, IEEE NaN, nor IEEE Inf nor IEEE NaN, respectively. + !> \brief .true. if not IEEE Inf. ! - !> \details Checks for IEEE Inf and IEEE NaN, i.e. Infinity and Not-a-Number.\n - !> Wraps to functions of the intrinsic module ieee_arithmetic - !> but gives alternatives for gfortran, which does not provide ieee_arithmetic. + !> \details Checks for IEEE Inf, i.e. Infinity.\n + !> Wraps to functions of the intrinsic module ieee_arithmetic. ! ! INTENT(IN) - !> \param[in] "real(sp/dp) :: x" Number to check + !> \param[in] "real(sp/dp) :: a" Number to be evaluated. ! ! INTENT(INOUT) ! None @@ -183,8 +182,8 @@ MODULE mo_utils ! None ! ! RETURN - !> \return logical :: is_finite/is_nan/is_normal — \f$ a /= Inf, a == NaN, a /= Inf and a == NaN \f$, - !> logically true or false + !> \return logical :: is_finite — \f$ a \neq \infty \f$, + !> logically true or false. ! ! RESTRICTIONS ! None @@ -206,12 +205,38 @@ MODULE mo_utils MODULE PROCEDURE is_finite_sp, is_finite_dp END INTERFACE is_finite - !> \param[in] "real(sp/dp) :: x" Number to check + ! NAME + ! is_nan + ! + !> \brief .true. if IEEE NaN. + ! + !> \details Checks for IEEE NaN, i.e. Not-a-Number.\n + !> Wraps to functions of the intrinsic module ieee_arithmetic. + ! + ! INTENT(IN) + !> \param[in] "real(sp/dp) :: a" Number to be evaluated. + ! + ! RETURN + !> \return logical :: is_nan — \f$ a = NaN \f$, logically true or false. INTERFACE is_nan MODULE PROCEDURE is_nan_sp, is_nan_dp END INTERFACE is_nan + ! NAME + ! is_normal + ! + !> \brief .true. if nor IEEE Inf nor IEEE NaN. + ! + !> \details Checks if IEEE Inf and IEEE NaN, i.e. Infinity and Not-a-Number.\n + !> Wraps to functions of the intrinsic module ieee_arithmetic. + ! + ! INTENT(IN) + !> \param[in] "real(sp/dp) :: a" Number to be evaluated. + ! + ! RETURN + !> \return logical :: is_normal — \f$ a \neq \infty \land a = NaN \f$, logically true or false. + INTERFACE is_normal MODULE PROCEDURE is_normal_sp, is_normal_dp END INTERFACE is_normal @@ -353,10 +378,7 @@ MODULE mo_utils !> \brief Special IEEE values. ! !> \details Returns special IEEE values such as Infinity or Not-a-Number.\n - !> Wraps to function ieee_value of the intrinsic module ieee_arithmetic - !> but gives alternatives for gfortran, which does not provide ieee_arithmetic.\n - !> Quiet and signaling NaN are the same in case of gfortran;\n - !> also denormal values are the same as inf. + !> Wraps to function ieee_value of the intrinsic module ieee_arithmetic. !> !> Current special values are:\n !> IEEE_SIGNALING_NAN\n @@ -372,7 +394,7 @@ MODULE mo_utils ! ! INTENT(IN) !> \param[in] "real(sp/dp) :: x" dummy for kind of output - !> \param[in] "character(le=*) :: name ieee signal nanme + !> \param[in] "character(le=*) :: ieee" ieee signal nanme ! ! INTENT(INOUT) ! None @@ -559,8 +581,8 @@ CONTAINS IMPLICIT NONE - REAL(dp), INTENT(IN) :: a - LOGICAL :: is_finite_dp + REAL(dp), INTENT(IN) :: a !< Number to be evaluated. + LOGICAL :: is_finite_dp !< logical :: is_finite — \f$ a \neq \infty \f$, logically true or false. is_finite_dp = ieee_is_finite(a) @@ -572,8 +594,8 @@ CONTAINS IMPLICIT NONE - REAL(sp), INTENT(IN) :: a - LOGICAL :: is_finite_sp + REAL(sp), INTENT(IN) :: a !< Number to be evaluated. + LOGICAL :: is_finite_sp !< logical :: is_finite — \f$ a \neq \infty \f$, logically true or false. is_finite_sp = ieee_is_finite(a) @@ -586,8 +608,8 @@ CONTAINS IMPLICIT NONE - REAL(dp), INTENT(IN) :: a - LOGICAL :: is_nan_dp + REAL(dp), INTENT(IN) :: a !< Number to be evaluated. + LOGICAL :: is_nan_dp !< logical :: is_nan — \f$ a = NaN \f$, logically true or false. is_nan_dp = isnan(a) @@ -599,8 +621,8 @@ CONTAINS IMPLICIT NONE - REAL(sp), INTENT(IN) :: a - LOGICAL :: is_nan_sp + REAL(sp), INTENT(IN) :: a !< Number to be evaluated. + LOGICAL :: is_nan_sp !< logical :: is_nan — \f$ a = NaN \f$, logically true or false. is_nan_sp = isnan(a) @@ -613,8 +635,8 @@ CONTAINS IMPLICIT NONE - REAL(dp), INTENT(IN) :: a - LOGICAL :: is_normal_dp + REAL(dp), INTENT(IN) :: a !< Number to be evaluated. + LOGICAL :: is_normal_dp !< logical :: is_normal — \f$ a \neq \infty \land a = NaN \f$, logically true or false. is_normal_dp = ieee_is_normal(a) @@ -626,8 +648,8 @@ CONTAINS IMPLICIT NONE - REAL(sp), INTENT(IN) :: a - LOGICAL :: is_normal_sp + REAL(sp), INTENT(IN) :: a !< Number to be evaluated. + LOGICAL :: is_normal_sp !< logical :: is_normal — \f$ a \neq \infty \land a = NaN \f$, logically true or false. is_normal_sp = ieee_is_normal(a) @@ -823,9 +845,19 @@ CONTAINS implicit none - real(dp), intent(in) :: x - character(len = *), intent(in) :: ieee - real(dp) :: special_value_dp + real(dp), intent(in) :: x !< dummy for kind of output. + character(len = *), intent(in) :: ieee !< ieee signal name. + real(dp) :: special_value_dp !< real(dp) :: special_value — IEEE special value\n + !< IEEE_SIGNALING_NAN\n + !< IEEE_QUIET_NAN\n + !< IEEE_NEGATIVE_INF\n + !< IEEE_POSITIVE_INF\n + !< IEEE_NEGATIVE_DENORMAL\n + !< IEEE_POSITIVE_DENORMAL\n + !< IEEE_NEGATIVE_NORMAL\n + !< IEEE_POSITIVE_NORMAL\n + !< IEEE_NEGATIVE_ZERO\n + !< IEEE_POSITIVE_ZERO\n ! local character(len = 21) :: ieee_up @@ -875,9 +907,19 @@ CONTAINS implicit none - real(sp), intent(in) :: x - character(len = *), intent(in) :: ieee - real(sp) :: special_value_sp + real(sp), intent(in) :: x !< dummy for kind of output. + character(len = *), intent(in) :: ieee !< ieee signal name. + real(sp) :: special_value_sp !< real(sp) :: special_value — IEEE special value\n + !< IEEE_SIGNALING_NAN\n + !< IEEE_QUIET_NAN\n + !< IEEE_NEGATIVE_INF\n + !< IEEE_POSITIVE_INF\n + !< IEEE_NEGATIVE_DENORMAL\n + !< IEEE_POSITIVE_DENORMAL\n + !< IEEE_NEGATIVE_NORMAL\n + !< IEEE_POSITIVE_NORMAL\n + !< IEEE_NEGATIVE_ZERO\n + !< IEEE_POSITIVE_ZERO\n ! local character(len = 21) :: ieee_up -- GitLab