https://www.cdslab.org/paramonte/fortran/2
Current view: top level - main - pm_arraySearch@routines.inc.F90 (source / functions) Hit Total Coverage
Test: ParaMonte 2.0.0 :: Serial Fortran - Code Coverage Report Lines: 11 11 100.0 %
Date: 2024-04-08 03:18:57 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!                                                                                                                            !!!!
       4             : !!!!    ParaMonte: Parallel Monte Carlo and Machine Learning Library.                                                           !!!!
       5             : !!!!                                                                                                                            !!!!
       6             : !!!!    Copyright (C) 2012-present, The Computational Data Science Lab                                                          !!!!
       7             : !!!!                                                                                                                            !!!!
       8             : !!!!    This file is part of the ParaMonte library.                                                                             !!!!
       9             : !!!!                                                                                                                            !!!!
      10             : !!!!    LICENSE                                                                                                                 !!!!
      11             : !!!!                                                                                                                            !!!!
      12             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md                                                          !!!!
      13             : !!!!                                                                                                                            !!!!
      14             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      15             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      16             : 
      17             : !>  \brief
      18             : !>  This file contains the implementation details of the routines under the generic interfaces in [pm_arraySearch](@ref pm_arraySearch).
      19             : !>
      20             : !>  \author
      21             : !>  \AmirShahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin
      22             : 
      23             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      24             : 
      25             :         ! Define the array indexing rules.
      26             : #if     D0_D0_ENABLED && SK_ENABLED
      27             : #define GET_INDEX(i) i:i+lenValueMinusOne
      28             : #define GET_SIZE len
      29             : #elif   D1_D0_ENABLED
      30             : #define GET_INDEX(i) i
      31             : #define GET_SIZE size
      32             : #else
      33             : #error  "Unrecognized interface."
      34             : #endif
      35             :         ! Define the comparison rules.
      36             : #if     CusCom_ENABLED
      37             : #define IS_LESS(a,b) isLess(a,b)
      38             : #elif   DefCom_ENABLED && CK_ENABLED
      39             : #define IS_LESS(a,b) a%re < b%re
      40             : #else
      41             : #define IS_LESS(a,b) a < b
      42             : #endif
      43             :         integer(IK) :: minbin, maxbin
      44             : #if     D0_D0_ENABLED && SK_ENABLED
      45             : #define MAXBIN GET_SIZE(array, kind = IK) - lenValueMinusOne
      46             :         integer(IK) :: lenValueMinusOne
      47          23 :         lenValueMinusOne = len(value, kind = IK) - 1_IK
      48             : #elif   D1_D0_ENABLED
      49             : #define MAXBIN GET_SIZE(array, kind = IK)
      50             : #else
      51             : #error  "Unrecognized interface."
      52             : #endif
      53       55764 :         CHECK_ASSERTION(__LINE__, 0_IK < MAXBIN, SK_"@getBin(): The length of the input array must be non-zero: lenArray = "//getStr(MAXBIN))
      54       55764 :         if (IS_LESS(value, array(GET_INDEX(1)))) then
      55             :             bin = 0_IK
      56             :         else
      57             : #if         D0_D0_ENABLED && SK_ENABLED
      58             :             maxbin = GET_SIZE(array, kind = IK) - lenValueMinusOne
      59             : #elif       D1_D0_ENABLED
      60             :             maxbin = GET_SIZE(array, kind = IK)
      61             : #else
      62             : #error      "Unrecognized interface."
      63             : #endif
      64       55731 :             if (IS_LESS(value, array(GET_INDEX(maxbin)))) then
      65             :                 minbin = 1_IK
      66             :                 do
      67       98725 :                     bin = minbin + (maxbin - minbin) / 2_IK
      68       98725 :                     if (IS_LESS(value, array(GET_INDEX(bin)))) then
      69       43588 :                         if (bin - minbin > 1_IK) then
      70             :                             maxbin = bin
      71             :                             cycle
      72             :                         end if
      73       21985 :                         bin = bin - 1_IK
      74       21985 :                         return
      75             :                     else
      76             :                         minbin = bin
      77       55137 :                         if (maxbin - bin > 1_IK) then
      78             :                             minbin = bin
      79             :                             cycle
      80             :                         end if
      81       20918 :                         return
      82             :                     end if
      83             :                 end do
      84             :             else
      85             :                 bin = GET_SIZE(array, kind = IK)
      86             :             end if
      87             :         end if
      88             : 
      89             : #undef  COMPONENT
      90             : #undef  GET_INDEX
      91             : #undef  GET_SIZE
      92             : #undef  IS_LESS
      93             : #undef  MAXBIN

ParaMonte: Parallel Monte Carlo and Machine Learning Library 
The Computational Data Science Lab
© Copyright 2012 - 2024