| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | module athena__normalisation | ||
| 2 | !! Module containing procedures for normalising input and output data | ||
| 3 | use coreutils, only: real32 | ||
| 4 | implicit none | ||
| 5 | |||
| 6 | |||
| 7 | private | ||
| 8 | |||
| 9 | public :: linear_renormalise | ||
| 10 | public :: renormalise_norm | ||
| 11 | public :: renormalise_sum | ||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | contains | ||
| 16 | |||
| 17 | !############################################################################### | ||
| 18 | − | subroutine linear_renormalise(input, min, max) | |
| 19 | !! Renormalise input data to a specified range | ||
| 20 | implicit none | ||
| 21 | |||
| 22 | ! Arguments | ||
| 23 | real(real32), dimension(:), intent(inout) :: input | ||
| 24 | !! Input data to be renormalised | ||
| 25 | real(real32), optional, intent(in) :: min, max | ||
| 26 | !! Minimum and maximum values for renormalisation | ||
| 27 | |||
| 28 | ! Local variables | ||
| 29 | real(real32) :: lower, width | ||
| 30 | !! Lower bound and width of the range | ||
| 31 | real(real32) :: min_val, max_val | ||
| 32 | !! Minimum and maximum values of the input data | ||
| 33 | |||
| 34 | − | min_val = minval(input) | |
| 35 | − | max_val = maxval(input) | |
| 36 | |||
| 37 | − | if(present(min))then | |
| 38 | − | lower = min | |
| 39 | else | ||
| 40 | − | lower = -1._real32 | |
| 41 | end if | ||
| 42 | − | if(present(max))then | |
| 43 | − | width = max - min | |
| 44 | else | ||
| 45 | − | width = 2._real32 | |
| 46 | end if | ||
| 47 | |||
| 48 | − | input = lower + width * (input - min_val)/(max_val - min_val) | |
| 49 | − | end subroutine linear_renormalise | |
| 50 | !############################################################################### | ||
| 51 | |||
| 52 | |||
| 53 | !############################################################################### | ||
| 54 | − | subroutine renormalise_norm(input, norm, mirror) | |
| 55 | !! Renormalise input data to a unit norm | ||
| 56 | implicit none | ||
| 57 | |||
| 58 | ! Arguments | ||
| 59 | real(real32), dimension(:), intent(inout) :: input | ||
| 60 | !! Input data to be renormalised | ||
| 61 | real(real32), optional, intent(in) :: norm | ||
| 62 | !! Desired norm value | ||
| 63 | logical, optional, intent(in) :: mirror | ||
| 64 | !! Boolean whether the data should be mirrored | ||
| 65 | |||
| 66 | ! Local variables | ||
| 67 | real(real32) :: scale | ||
| 68 | !! Scaling factor | ||
| 69 | |||
| 70 | − | if(present(norm))then | |
| 71 | − | scale = norm | |
| 72 | else | ||
| 73 | − | scale = 1._real32 | |
| 74 | end if | ||
| 75 | |||
| 76 | − | if(present(mirror))then | |
| 77 | − | if(mirror) call linear_renormalise(input) | |
| 78 | end if | ||
| 79 | − | input = input * scale/sqrt(dot_product(input,input)) | |
| 80 | − | end subroutine renormalise_norm | |
| 81 | !############################################################################### | ||
| 82 | |||
| 83 | |||
| 84 | !############################################################################### | ||
| 85 | − | subroutine renormalise_sum(input, norm, mirror, magnitude) | |
| 86 | !! Renormalise input data to a unit sum | ||
| 87 | implicit none | ||
| 88 | |||
| 89 | ! Arguments | ||
| 90 | real(real32), dimension(:), intent(inout) :: input | ||
| 91 | !! Input data to be renormalised | ||
| 92 | real(real32), optional, intent(in) :: norm | ||
| 93 | !! Desired sum value | ||
| 94 | logical, optional, intent(in) :: mirror, magnitude | ||
| 95 | !! Booleans whether the data should be mirrored or use magnitude | ||
| 96 | |||
| 97 | ! Local variables | ||
| 98 | logical :: magnitude_ | ||
| 99 | !! Flag to indicate if magnitude should be used | ||
| 100 | real(real32) :: scale | ||
| 101 | !! Scaling factor | ||
| 102 | |||
| 103 | − | if(present(norm))then | |
| 104 | − | scale = norm | |
| 105 | else | ||
| 106 | − | scale = 1._real32 | |
| 107 | end if | ||
| 108 | |||
| 109 | − | if(present(mirror))then | |
| 110 | − | if(mirror) call linear_renormalise(input) | |
| 111 | end if | ||
| 112 | |||
| 113 | − | if(present(magnitude)) magnitude_ = magnitude | |
| 114 | − | if(present(magnitude))then | |
| 115 | − | scale = scale/sum(abs(input)) | |
| 116 | else | ||
| 117 | − | scale = scale/sum(input) | |
| 118 | end if | ||
| 119 | − | input = input * scale | |
| 120 | − | end subroutine renormalise_sum | |
| 121 | !############################################################################### | ||
| 122 | |||
| 123 | end module athena__normalisation | ||
| 124 |