*FILE MEMBER=TITLES_LINEAR_INTERPOLATE LIBRARY=SNOMAN LANGUAGE=FORTRAN77 DATE=07:Dec:2006
     
 <<<      SUBROUTINE TITLES_LINEAR_INTERPOLATE(LINK_BANK,
         +                                  X,
         +                                  INTERPOLATED_VALUE)
     
    *     SNOMAN: Simple linear interpolation.
     
    *     Contact:  N. Oblath, UW
     
    *     Parameters:-
    *     ==========
    *     LINK_BANK             in    Link to the bank (the ld-link; see bank format below)
    *     X                     in    Position on the abscissa at which the value of the function will be found
    *     INTERPOLATED_VALUE    out   Value of the function to be returned
     
    *     Common Block Access:-
    *     ===================
     
    *     Specification:-
    *     =============
     
    *     Linear interpolation for titles banks with the following format:
     
    *     Data Word   Type    Description
    *     ----------------------------------------
    *         1       I       Number of data points
    *         2       F       Position (on the abscissa) of the first entry
    *         3       F       Position (on the abscissa) of the last entry
    *         4       F       Step size (along the abscissa)
    *         5       F       First data point
    *         6       F       Second data point
    *         7 ...
     
    *     Program Notes:-
    *     =============
     
    *     If X is between words 2 and 3 of the bank, linear interpolation
    *     between the appropriate data points is used
     
    *     If X is less than word 2 [greater than word 3], the first [last]
    *     two data points are used for interpolation
     
     
    *     Revision History:-
    *     ================
    *      5.03  N. Oblath    First version.
     
          IMPLICIT NONE
     
          INCLUDE 'mt.inc'
     
    *     Argument Declarations:-
    *     =====================
     
          INTEGER LINK_BANK
          REAL  INTERPOLATED_VALUE, X
     
    *ENDHEADER
     
    *     Local Variable Declarations:-
    *     ============================
          REAL DX, START_VALUE
          INTEGER DATA_OFFSET_LINK, START_INDEX
     
          data_offset_link = link_bank + 4
          dx = rcons(link_bank + 4)
     
          if (x.lt.rcons(link_bank + 2)) then
             start_index = 1
          elseif (x.gt.rcons(link_bank + 3)) then
             start_index = icons(link_bank + 1) - 1
          else
             start_index = int((x-rcons(link_bank+2))/dx) + 1
          endif
     
          start_value = rcons(data_offset_link+start_index)
     
          interpolated_value = (x/dx-real(start_index)) *
         +     (rcons(data_offset_link+start_index+1) - start_value) +
         +     start_value
     
          RETURN
          END
     
    *ENDFILE MEMBER=TITLES_LINEAR_INTERPOLATE