EFTCAMB  Reference documentation for version 3.0
02_utilities.f90
Go to the documentation of this file.
1 !----------------------------------------------------------------------------------------
2 !
3 ! This file is part of EFTCAMB.
4 !
5 ! Copyright (C) 2013-2016 by the EFTCAMB authors
6 !
7 ! The EFTCAMB code is free software;
8 ! You can use it, redistribute it, and/or modify it under the terms
9 ! of the GNU General Public License as published by the Free Software Foundation;
10 ! either version 3 of the License, or (at your option) any later version.
11 ! The full text of the license can be found in the file eftcamb/LICENSE at
12 ! the top level of the EFTCAMB distribution.
13 !
14 !----------------------------------------------------------------------------------------
15 
18 
19 
20 !----------------------------------------------------------------------------------------
22 
24 
26 
27  use precision
28 
29  implicit none
30 
31  private
32 
33  public hunt, integer_to_string, string
34 
35  !----------------------------------------------------------------------------------------
38  type :: string
39  character(len=:), allocatable :: string
40  end type string
41 
42 contains
43 
44  ! ---------------------------------------------------------------------------------------------
47  subroutine hunt(xx,n,x,jlo)
48 
49  implicit none
50 
51  integer :: n
52  real(dl) :: xx(n)
53  real(dl) :: x
54  integer :: jlo
55 
56  integer inc,jhi,jm
57  logical ascnd
58  ascnd=xx(n).ge.xx(1)
59  if(jlo.le.0.or.jlo.gt.n)then
60  jlo=0
61  jhi=n+1
62  goto 3
63  endif
64  inc=1
65  if(x.ge.xx(jlo).eqv.ascnd)then
66 1 jhi=jlo+inc
67  if(jhi.gt.n)then
68  jhi=n+1
69  else if(x.ge.xx(jhi).eqv.ascnd)then
70  jlo=jhi
71  inc=inc+inc
72  goto 1
73  endif
74  else
75  jhi=jlo
76 2 jlo=jhi-inc
77  if(jlo.lt.1)then
78  jlo=0
79  else if(x.lt.xx(jlo).eqv.ascnd)then
80  jhi=jlo
81  inc=inc+inc
82  goto 2
83  endif
84  endif
85 3 if(jhi-jlo.eq.1)then
86  if(x.eq.xx(n))jlo=n-1
87  if(x.eq.xx(1))jlo=1
88  return
89  endif
90  jm=(jhi+jlo)/2
91  if(x.ge.xx(jm).eqv.ascnd)then
92  jlo=jm
93  else
94  jhi=jm
95  endif
96  goto 3
97 
98  end subroutine hunt
99 
100  ! ---------------------------------------------------------------------------------------------
102  function integer_to_string( number )
104  implicit none
105 
106  integer, intent(in) :: number
107  character(10) :: integer_to_string
108 
109  write( integer_to_string, '(i10)' ) number
110 
111  integer_to_string = trim(adjustl( integer_to_string ))
112 
113  end function integer_to_string
114 
115  !----------------------------------------------------------------------------------------
116 
117 end module eftcamb_mixed_algorithms
118 
119 !----------------------------------------------------------------------------------------
This module contains various generic algorithms that are useful to EFTCAMB.
character(10) function, public integer_to_string(number)
This function converts an integer to a string. Usefull for numbered files output. ...
subroutine, public hunt(xx, n, x, jlo)
Hunting algorithm: This is used to efficiently search an ordered table by means of a hunting and a bi...