interpolation.f90 Source File


Files dependent on this one

sourcefile~~interpolation.f90~~AfferentGraph sourcefile~interpolation.f90 interpolation.f90 sourcefile~regr1_lint_m.f90 regr1_lint_m.f90 sourcefile~regr1_lint_m.f90->sourcefile~interpolation.f90 sourcefile~regr_horiz_time_climoz_m.f90~2 regr_horiz_time_climoz_m.f90 sourcefile~regr_horiz_time_climoz_m.f90~2->sourcefile~interpolation.f90 sourcefile~regr_lint_m.f90 regr_lint_m.f90 sourcefile~regr_horiz_time_climoz_m.f90~2->sourcefile~regr_lint_m.f90 sourcefile~regr_conserv_m.f90 regr_conserv_m.f90 sourcefile~regr_horiz_time_climoz_m.f90~2->sourcefile~regr_conserv_m.f90 sourcefile~regr_horiz_time_climoz_m.f90 regr_horiz_time_climoz_m.f90 sourcefile~regr_horiz_time_climoz_m.f90->sourcefile~interpolation.f90 sourcefile~regr_horiz_time_climoz_m.f90->sourcefile~regr_lint_m.f90 sourcefile~regr_horiz_time_climoz_m.f90->sourcefile~regr_conserv_m.f90 sourcefile~regr1_step_av_m.f90 regr1_step_av_m.f90 sourcefile~regr1_step_av_m.f90->sourcefile~interpolation.f90 sourcefile~regr_lint_m.f90->sourcefile~interpolation.f90 sourcefile~regr1_step_av_m.f90~2 regr1_step_av_m.f90 sourcefile~regr1_step_av_m.f90~2->sourcefile~interpolation.f90 sourcefile~regr_pr_time_av_m.f90 regr_pr_time_av_m.f90 sourcefile~regr_pr_time_av_m.f90->sourcefile~interpolation.f90 sourcefile~regr_pr_time_av_m.f90->sourcefile~regr_lint_m.f90 sourcefile~regr_pr_time_av_m.f90->sourcefile~regr_conserv_m.f90 sourcefile~regr_pr_time_av_m.f90~2 regr_pr_time_av_m.f90 sourcefile~regr_pr_time_av_m.f90~2->sourcefile~interpolation.f90 sourcefile~regr_pr_time_av_m.f90~2->sourcefile~regr_lint_m.f90 sourcefile~regr_pr_time_av_m.f90~2->sourcefile~regr_conserv_m.f90 sourcefile~regr1_conserv_m.f90 regr1_conserv_m.f90 sourcefile~regr1_conserv_m.f90->sourcefile~interpolation.f90 sourcefile~regr3_lint_m.f90 regr3_lint_m.f90 sourcefile~regr3_lint_m.f90->sourcefile~interpolation.f90 sourcefile~regr_conserv_m.f90->sourcefile~interpolation.f90 sourcefile~regr_lat_time_coefoz_m.f90~2 regr_lat_time_coefoz_m.f90 sourcefile~regr_lat_time_coefoz_m.f90~2->sourcefile~regr_lint_m.f90 sourcefile~regr_lat_time_coefoz_m.f90~2->sourcefile~regr_conserv_m.f90 sourcefile~regr_lat_time_coefoz_m.f90 regr_lat_time_coefoz_m.f90 sourcefile~regr_lat_time_coefoz_m.f90->sourcefile~regr_lint_m.f90 sourcefile~regr_lat_time_coefoz_m.f90->sourcefile~regr_conserv_m.f90 sourcefile~regr_pr_av_m.f90 regr_pr_av_m.f90 sourcefile~regr_pr_av_m.f90->sourcefile~regr1_conserv_m.f90 sourcefile~regr_pr_o3_m.f90 regr_pr_o3_m.f90 sourcefile~regr_pr_o3_m.f90->sourcefile~regr_conserv_m.f90 sourcefile~physiq_mod.f90 physiq_mod.F90 sourcefile~physiq_mod.f90->sourcefile~regr_horiz_time_climoz_m.f90 sourcefile~physiq_mod.f90->sourcefile~regr_pr_time_av_m.f90 sourcefile~phytrac_mod.f90 phytrac_mod.f90 sourcefile~physiq_mod.f90->sourcefile~phytrac_mod.f90 sourcefile~phyetat0_mod.f90 phyetat0_mod.F90 sourcefile~physiq_mod.f90->sourcefile~phyetat0_mod.f90 sourcefile~phys_output_write_mod.f90 phys_output_write_mod.F90 sourcefile~physiq_mod.f90->sourcefile~phys_output_write_mod.f90 sourcefile~physiqex_mod.f90 physiqex_mod.F90 sourcefile~physiq_mod.f90->sourcefile~physiqex_mod.f90 sourcefile~diag_slp.f90 diag_slp.f90 sourcefile~physiq_mod.f90->sourcefile~diag_slp.f90 sourcefile~phys_output_mod.f90 phys_output_mod.F90 sourcefile~physiq_mod.f90->sourcefile~phys_output_mod.f90 sourcefile~regr_pr_int_m.f90 regr_pr_int_m.f90 sourcefile~regr_pr_int_m.f90->sourcefile~regr_lint_m.f90 sourcefile~regr_pr_comb_coefoz_m.f90~2 regr_pr_comb_coefoz_m.f90 sourcefile~regr_pr_comb_coefoz_m.f90~2->sourcefile~regr_pr_time_av_m.f90 sourcefile~regr_pr_comb_coefoz_m.f90~2->sourcefile~regr_pr_int_m.f90 sourcefile~regr_pr_o3_m.f90~2 regr_pr_o3_m.f90 sourcefile~regr_pr_o3_m.f90~2->sourcefile~regr_conserv_m.f90 sourcefile~etat0phys_netcdf.f90 etat0phys_netcdf.f90 sourcefile~etat0phys_netcdf.f90->sourcefile~regr_horiz_time_climoz_m.f90 sourcefile~regr_pr_int_m.f90~2 regr_pr_int_m.f90 sourcefile~regr_pr_int_m.f90~2->sourcefile~regr_lint_m.f90 sourcefile~regr_pr_comb_coefoz_m.f90 regr_pr_comb_coefoz_m.f90 sourcefile~regr_pr_comb_coefoz_m.f90->sourcefile~regr_pr_time_av_m.f90 sourcefile~regr_pr_comb_coefoz_m.f90->sourcefile~regr_pr_int_m.f90 sourcefile~regr_lat_time_climoz_m.f90 regr_lat_time_climoz_m.f90 sourcefile~regr_lat_time_climoz_m.f90->sourcefile~regr1_conserv_m.f90 sourcefile~regr_lat_time_climoz_m.f90->sourcefile~regr3_lint_m.f90 sourcefile~physiq_mod.f90~2 physiq_mod.F90 sourcefile~physiq_mod.f90~2->sourcefile~regr_horiz_time_climoz_m.f90 sourcefile~physiq_mod.f90~2->sourcefile~regr_pr_time_av_m.f90 sourcefile~physiq_mod.f90~2->sourcefile~phytrac_mod.f90 sourcefile~physiq_mod.f90~2->sourcefile~phyetat0_mod.f90 sourcefile~physiq_mod.f90~2->sourcefile~phys_output_write_mod.f90 sourcefile~physiq_mod.f90~2->sourcefile~physiqex_mod.f90 sourcefile~physiq_mod.f90~2->sourcefile~diag_slp.f90 sourcefile~physiq_mod.f90~2->sourcefile~phys_output_mod.f90 sourcefile~old_lmdz1d.f90 old_lmdz1d.f90 sourcefile~old_lmdz1d.f90->sourcefile~physiq_mod.f90 sourcefile~traclmdz_mod.f90 traclmdz_mod.f90 sourcefile~traclmdz_mod.f90->sourcefile~regr_pr_comb_coefoz_m.f90 sourcefile~o3_chem_m.f90 o3_chem_m.f90 sourcefile~traclmdz_mod.f90->sourcefile~o3_chem_m.f90 sourcefile~traclmdz_mod.f90~2 traclmdz_mod.f90 sourcefile~traclmdz_mod.f90~2->sourcefile~regr_pr_comb_coefoz_m.f90 sourcefile~traclmdz_mod.f90~2->sourcefile~o3_chem_m.f90 sourcefile~etat0dyn_netcdf.f90 etat0dyn_netcdf.F90 sourcefile~etat0dyn_netcdf.f90->sourcefile~regr_lat_time_coefoz_m.f90 sourcefile~etat0dyn_netcdf.f90->sourcefile~regr_pr_o3_m.f90 sourcefile~ce0l.f90 ce0l.F90 sourcefile~ce0l.f90->sourcefile~etat0phys_netcdf.f90 sourcefile~ce0l.f90->sourcefile~etat0dyn_netcdf.f90 sourcefile~callphysiq_mod.f90~2 callphysiq_mod.f90 sourcefile~callphysiq_mod.f90~2->sourcefile~physiq_mod.f90 sourcefile~o3_chem_m.f90->sourcefile~regr_pr_comb_coefoz_m.f90 sourcefile~o3_chem_m.f90~2 o3_chem_m.f90 sourcefile~o3_chem_m.f90~2->sourcefile~regr_pr_comb_coefoz_m.f90 sourcefile~scm.f90 scm.f90 sourcefile~scm.f90->sourcefile~physiq_mod.f90 sourcefile~callphysiq_mod.f90 callphysiq_mod.f90 sourcefile~callphysiq_mod.f90->sourcefile~physiq_mod.f90 sourcefile~lsc_scav.f90 lsc_scav.f90 sourcefile~lsc_scav.f90->sourcefile~traclmdz_mod.f90 sourcefile~lsc_scav_orig.f90~2 lsc_scav_orig.f90 sourcefile~lsc_scav_orig.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~calfis.f90 calfis.f90 sourcefile~calfis.f90->sourcefile~callphysiq_mod.f90 sourcefile~phytrac_mod.f90->sourcefile~traclmdz_mod.f90 sourcefile~cltracrn.f90~2 cltracrn.f90 sourcefile~cltracrn.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~phyredem.f90 phyredem.F90 sourcefile~phyredem.f90->sourcefile~traclmdz_mod.f90 sourcefile~initrrnpb.f90 initrrnpb.f90 sourcefile~initrrnpb.f90->sourcefile~traclmdz_mod.f90 sourcefile~lsc_scav_orig.f90 lsc_scav_orig.f90 sourcefile~lsc_scav_orig.f90->sourcefile~traclmdz_mod.f90 sourcefile~phyetat0_mod.f90->sourcefile~traclmdz_mod.f90 sourcefile~radio_decay.f90 radio_decay.f90 sourcefile~radio_decay.f90->sourcefile~traclmdz_mod.f90 sourcefile~initrrnpb.f90~2 initrrnpb.f90 sourcefile~initrrnpb.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~lsc_scav_spl.f90 lsc_scav_spl.f90 sourcefile~lsc_scav_spl.f90->sourcefile~traclmdz_mod.f90 sourcefile~phytrac_mod.f90~2 phytrac_mod.f90 sourcefile~phytrac_mod.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~radio_decay.f90~2 radio_decay.f90 sourcefile~radio_decay.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~lsc_scav_spl.f90~2 lsc_scav_spl.f90 sourcefile~lsc_scav_spl.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~lsc_scav.f90~2 lsc_scav.f90 sourcefile~lsc_scav.f90~2->sourcefile~traclmdz_mod.f90 sourcefile~cltracrn.f90 cltracrn.f90 sourcefile~cltracrn.f90->sourcefile~traclmdz_mod.f90 sourcefile~phys_output_write_mod.f90->sourcefile~phytrac_mod.f90 sourcefile~physiqex_mod.f90~2 physiqex_mod.F90 sourcefile~physiqex_mod.f90~2->sourcefile~phyetat0_mod.f90 sourcefile~phys_output_write_mod.f90~2 phys_output_write_mod.F90 sourcefile~phys_output_write_mod.f90~2->sourcefile~phytrac_mod.f90 sourcefile~physiqex_mod.f90->sourcefile~phyetat0_mod.f90 sourcefile~diag_slp.f90->sourcefile~phys_output_write_mod.f90 sourcefile~phys_output_mod.f90->sourcefile~phys_output_write_mod.f90 sourcefile~phys_output_mod.f90~2 phys_output_mod.F90 sourcefile~phys_output_mod.f90~2->sourcefile~phys_output_write_mod.f90 sourcefile~diag_slp.f90~2 diag_slp.f90 sourcefile~diag_slp.f90~2->sourcefile~phys_output_write_mod.f90 sourcefile~recmwf_aero.f90 recmwf_aero.F90 sourcefile~recmwf_aero.f90->sourcefile~phys_output_mod.f90 sourcefile~recmwf_aero.f90~2 recmwf_aero.F90 sourcefile~recmwf_aero.f90~2->sourcefile~phys_output_mod.f90 sourcefile~sw_aeroar4.f90 sw_aeroAR4.f90 sourcefile~sw_aeroar4.f90->sourcefile~phys_output_mod.f90 sourcefile~sw_aeroar4.f90~2 sw_aeroAR4.f90 sourcefile~sw_aeroar4.f90~2->sourcefile~phys_output_mod.f90

Contents

Source Code


Source Code

! $Id$
module interpolation

  ! From Press et al., 1996, version 2.10a
  ! B3 Interpolation and Extrapolation

  IMPLICIT NONE 

contains

  pure FUNCTION locate(xx,x)

    REAL, DIMENSION(:), INTENT(IN) :: xx
    REAL, INTENT(IN) :: x
    INTEGER  locate

    ! Given an array xx(1:N), and given a value x, returns a value j,
    ! between 0 and N, such that x is between xx(j) and xx(j + 1). xx
    ! must be monotonic, either increasing or decreasing. j = 0 or j =
    ! N is returned to indicate that x is out of range. This
    ! procedure should not be called with a zero-sized array argument.
    ! See notes.

    INTEGER  n,jl,jm,ju
    LOGICAL  ascnd

    !----------------------------

    n=size(xx)
    ascnd = (xx(n) >= xx(1))
    ! (True if ascending order of table, false otherwise.)
    ! Initialize lower and upper limits:
    jl=0
    ju=n+1
    do while (ju-jl > 1)
       jm=(ju+jl)/2 ! Compute a midpoint,
       if (ascnd .eqv. (x >= xx(jm))) then
          jl=jm ! and replace either the lower limit
       else
          ju=jm ! or the upper limit, as appropriate.
       end if
    end do
    ! {ju == jl + 1}

    ! {(ascnd .and. xx(jl) <= x < xx(jl+1)) 
    !  .neqv. 
    !  (.not. ascnd .and. xx(jl+1) <= x < xx(jl))}

    ! Then set the output, being careful with the endpoints:
    if (x == xx(1)) then
       locate=1
    else if (x == xx(n)) then
       locate=n-1
    else
       locate=jl
    end if

  END FUNCTION locate

  !***************************

  pure SUBROUTINE hunt(xx,x,jlo)

    ! Given an array xx(1:N ), and given a value x, returns a value
    ! jlo such that x is between xx(jlo) and xx(jlo+1). xx must be
    ! monotonic, either increasing or decreasing. jlo = 0 or jlo = N is
    ! returned to indicate that x is out of range. jlo on input is taken as
    ! the initial guess for jlo on output.
    ! Modified so that it uses the information "jlo = 0" on input.

    INTEGER, INTENT(INOUT) :: jlo
    REAL, INTENT(IN) :: x
    REAL, DIMENSION(:), INTENT(IN) :: xx
    INTEGER  n,inc,jhi,jm
    LOGICAL  ascnd, hunt_up

    !-----------------------------------------------------

    n=size(xx)
    ascnd = (xx(n) >= xx(1))
    ! (True if ascending order of table, false otherwise.)
    if (jlo < 0 .or. jlo > n) then
       ! Input guess not useful. Go immediately to bisection.
       jlo=0
       jhi=n+1
    else
       inc=1 ! Set the hunting increment.
       if (jlo == 0) then
          hunt_up = .true.
       else
          hunt_up = x >= xx(jlo) .eqv. ascnd
       end if
       if (hunt_up) then ! Hunt up:
          do
             jhi=jlo+inc
             if (jhi > n) then ! Done hunting, since off end of table.
                jhi=n+1
                exit
             else
                if (x < xx(jhi) .eqv. ascnd) exit
                jlo=jhi ! Not done hunting,
                inc=inc+inc ! so double the increment
             end if
          end do ! and try again.
       else ! Hunt down:
          jhi=jlo
          do
             jlo=jhi-inc
             if (jlo < 1) then ! Done hunting, since off end of table.
                jlo=0
                exit
             else
                if (x >= xx(jlo) .eqv. ascnd) exit
                jhi=jlo ! Not done hunting,
                inc=inc+inc ! so double the increment
             end if
          end do ! and try again.
       end if
    end if ! Done hunting, value bracketed.

    do ! Hunt is done, so begin the final bisection phase:
       if (jhi-jlo <= 1) then
          if (x == xx(n)) jlo=n-1
          if (x == xx(1)) jlo=1
          exit
       else
          jm=(jhi+jlo)/2
          if (x >= xx(jm) .eqv. ascnd) then
             jlo=jm
          else
             jhi=jm
          end if
       end if
    end do

  END SUBROUTINE hunt

end module interpolation