% FIGURE 5.3.3b
      function HERM = HERM(HORS,K,IDER,X)
      global N XPTS
%                              EVALUATE AT X THE IDER-TH DERIVATIVE OF
%                              THE CUBIC HERMITE "H" OR "S" FUNCTION
%                              CENTERED AT XPTS(K+1).
      XK = XPTS(K+1);
      HH = XPTS(N+1)-XPTS(1);
      if (K > 0)
         XKM1 = XPTS(K);
      else
         XKM1 = XPTS(1)-HH;
      end
      if (K < N)
         XKP1 = XPTS(K+2);
      else
         XKP1 = XPTS(N+1)+HH;
      end
      HERM = 0.0;
      if (X < XKM1)
         return
      end
      if (X > XKP1)
         return
      end
      if (X <= XK)
         H = XK-XKM1;
         S = (X-XKM1)/H;
         if (HORS == 'H')
            if (IDER == 0)
               HERM = 3.0*S^2 - 2.0*S^3;
            elseif (IDER == 1)
               HERM = 6.0*S/H - 6.0*S^2/H;
            else
               HERM = 6.0/H^2 - 12.0*S/H^2;
            end
         else
            if (IDER == 0)
               HERM = -H*S^2 + H*S^3;
            elseif (IDER == 1)
               HERM = -2.0*S + 3.0*S^2;
            else
               HERM = -2.0/H + 6.0*S/H;
            end
         end
      else
         H = XKP1-XK;
         S = (XKP1-X)/H;
         if (HORS == 'H')
            if (IDER == 0)
               HERM = 3.0*S^2 - 2.0*S^3;
            elseif (IDER == 1)
               HERM = -6.0*S/H + 6.0*S^2/H;
            else
               HERM = 6.0/H^2 - 12.0*S/H^2;
            end
         else
            if (IDER == 0)
               HERM = H*S^2 - H*S^3;
            elseif (IDER == 1)
               HERM = -2.0*S + 3.0*S^2;
            else
               HERM = 2.0/H - 6.0*S/H;
            end
         end
      end
