Ignore:
Timestamp:
Jul 24, 2024, 2:54:37 PM (2 months ago)
Author:
abarral
Message:

rename modules properly lmdz_*
move ismin, ismax, minmax into new lmdz_libmath.f90
(lint) uppercase fortran keywords

File:
1 moved

Legend:

Unmodified
Added
Removed
  • LMDZ6/branches/Amaury_dev/libf/misc/lmdz_interpolation.f90

    r5115 r5116  
    11! $Id$
    2 module interpolation
     2module lmdz_interpolation
    33
    44  ! From Press et al., 1996, version 2.10a
    55  ! B3 Interpolation and Extrapolation
    66
    7   IMPLICIT NONE
     7  IMPLICIT NONE; PRIVATE
     8  PUBLIC locate, hunt
    89
    910contains
    1011
    11   pure FUNCTION locate(xx,x)
     12  pure FUNCTION locate(xx, x)
    1213
    1314    REAL, DIMENSION(:), INTENT(IN) :: xx
     
    2223    ! See notes.
    2324
    24     INTEGER  n,jl,jm,ju
     25    INTEGER  n, jl, jm, ju
    2526    LOGICAL  ascnd
    2627
    2728    !----------------------------
    2829
    29     n=size(xx)
     30    n = size(xx)
    3031    ascnd = (xx(n) >= xx(1))
    3132    ! (True if ascending order of table, false otherwise.)
    3233    ! Initialize lower and upper limits:
    33     jl=0
    34     ju=n+1
    35     do while (ju-jl > 1)
    36        jm=(ju+jl)/2 ! Compute a midpoint,
    37        if (ascnd .eqv. (x >= xx(jm))) then
    38           jl=jm ! and replace either the lower limit
    39        else
    40           ju=jm ! or the upper limit, as appropriate.
    41        end if
     34    jl = 0
     35    ju = n + 1
     36    do while (ju - jl > 1)
     37      jm = (ju + jl) / 2 ! Compute a midpoint,
     38      if (ascnd .eqv. (x >= xx(jm))) THEN
     39        jl = jm ! and replace either the lower limit
     40      else
     41        ju = jm ! or the upper limit, as appropriate.
     42      end if
    4243    END DO
    4344    ! {ju == jl + 1}
     
    4849
    4950    ! Then set the output, being careful with the endpoints:
    50     if (x == xx(1)) then
    51        locate=1
    52     else if (x == xx(n)) then
    53        locate=n-1
     51    if (x == xx(1)) THEN
     52      locate = 1
     53    else if (x == xx(n)) THEN
     54      locate = n - 1
    5455    else
    55        locate=jl
     56      locate = jl
    5657    end if
    5758
     
    6061  !***************************
    6162
    62   pure SUBROUTINE hunt(xx,x,jlo)
     63  pure SUBROUTINE hunt(xx, x, jlo)
    6364
    6465    ! Given an array xx(1:N ), and given a value x, returns a value
     
    7273    REAL, INTENT(IN) :: x
    7374    REAL, DIMENSION(:), INTENT(IN) :: xx
    74     INTEGER  n,inc,jhi,jm
     75    INTEGER  n, inc, jhi, jm
    7576    LOGICAL  ascnd, hunt_up
    7677
    7778    !-----------------------------------------------------
    7879
    79     n=size(xx)
     80    n = size(xx)
    8081    ascnd = (xx(n) >= xx(1))
    8182    ! (True if ascending order of table, false otherwise.)
    82     if (jlo < 0 .or. jlo > n) then
    83        ! Input guess not useful. Go immediately to bisection.
    84        jlo=0
    85        jhi=n+1
     83    if (jlo < 0 .or. jlo > n) THEN
     84      ! Input guess not useful. Go immediately to bisection.
     85      jlo = 0
     86      jhi = n + 1
    8687    else
    87        inc=1 ! Set the hunting increment.
    88        if (jlo == 0) then
    89           hunt_up = .TRUE.
    90        else
    91           hunt_up = x >= xx(jlo) .eqv. ascnd
    92        end if
    93        if (hunt_up) then ! Hunt up:
    94           do
    95              jhi=jlo+inc
    96              if (jhi > n) then ! Done hunting, since off end of table.
    97                 jhi=n+1
    98                 exit
    99              else
    100                 if (x < xx(jhi) .eqv. ascnd) exit
    101                 jlo=jhi ! Not done hunting,
    102                 inc=inc+inc ! so double the increment
    103              end if
    104           END DO ! and try again.
    105        else ! Hunt down:
    106           jhi=jlo
    107           do
    108              jlo=jhi-inc
    109              if (jlo < 1) then ! Done hunting, since off end of table.
    110                 jlo=0
    111                 exit
    112              else
    113                 if (x >= xx(jlo) .eqv. ascnd) exit
    114                 jhi=jlo ! Not done hunting,
    115                 inc=inc+inc ! so double the increment
    116              end if
    117           END DO ! and try again.
    118        end if
     88      inc = 1 ! Set the hunting increment.
     89      if (jlo == 0) THEN
     90        hunt_up = .TRUE.
     91      else
     92        hunt_up = x >= xx(jlo) .eqv. ascnd
     93      end if
     94      if (hunt_up) then ! Hunt up:
     95        do
     96          jhi = jlo + inc
     97          if (jhi > n) then ! Done hunting, since off end of table.
     98            jhi = n + 1
     99            exit
     100          else
     101            if (x < xx(jhi) .eqv. ascnd) exit
     102            jlo = jhi ! Not done hunting,
     103            inc = inc + inc ! so double the increment
     104          end if
     105        END DO ! and try again.
     106      else ! Hunt down:
     107        jhi = jlo
     108        do
     109          jlo = jhi - inc
     110          if (jlo < 1) then ! Done hunting, since off end of table.
     111            jlo = 0
     112            exit
     113          else
     114            if (x >= xx(jlo) .eqv. ascnd) exit
     115            jhi = jlo ! Not done hunting,
     116            inc = inc + inc ! so double the increment
     117          end if
     118        END DO ! and try again.
     119      end if
    119120    end if ! Done hunting, value bracketed.
    120121
    121122    do ! Hunt is done, so begin the final bisection phase:
    122        if (jhi-jlo <= 1) then
    123           if (x == xx(n)) jlo=n-1
    124           if (x == xx(1)) jlo=1
    125           exit
    126        else
    127           jm=(jhi+jlo)/2
    128           if (x >= xx(jm) .eqv. ascnd) then
    129              jlo=jm
    130           else
    131              jhi=jm
    132           end if
    133        end if
     123      if (jhi - jlo <= 1) THEN
     124        if (x == xx(n)) jlo = n - 1
     125        if (x == xx(1)) jlo = 1
     126        exit
     127      else
     128        jm = (jhi + jlo) / 2
     129        if (x >= xx(jm) .eqv. ascnd) THEN
     130          jlo = jm
     131        else
     132          jhi = jm
     133        end if
     134      end if
    134135    END DO
    135136
    136137  END SUBROUTINE hunt
    137138
    138 end module interpolation
     139end module lmdz_interpolation
Note: See TracChangeset for help on using the changeset viewer.