  1.  NAME

  next_hdg - Get nearest heading value

  2.  SYNOPSIS

  rel = next_hdg(ref, hdg )

  3.  DESCRIPTION

  This Matlab function calculates nearest heading value relative to the
  reference heading value ref. This function is required when
  calculating statistics of heading values that cross the boundary
  {360,0}. Its vailidity depends on the fact that the difference between
  both heading values is less than +-180, since the relative heading is
  given by the reference heading plus the heading change in the
  direction of the shortest angle difference.

  Input parameters may be vectors of the same length to convert several
  heading values at once.

  If heading values are stored in an array, one dimension must be of the
  same length as the reference values. The other dimension is assumed to
  be a list off successive heading values. Each of them is recalculated
  relatively to the previous value, the first value being calculated
  relatively to its corresponding reference element.

  4.  PARAMETERS

     ref
        Value for reference heading.

     hdg
        Value of current heading.

  5.  RETURNS

     new
        The heading calculated relatively to the reference.

  6.  AUTHORS

  Pierre Jaccard, Geophysical Institute, University of Bergen, 1999

