%**************************************************************************
%This function calculates the integral of y dx.
%It used a cubic spline interpolation to get a dense set of points between
%the measured data points. It then
%does a trapezoidal integration on the denser set of interpolated points.
%The x values are assumed to increase monotonically.
%
%Input:
%x, independent variable
%y, dependent variable
%
%Output:
%int_y_dx, integral of y dx
%
%Zack Wolf  2/5/04

function int_y_dx = int_calc_int(x, y)

%Parameter
INTERP_FACTOR = 4;
  
%Check
if length(x) ~= length(y)
    msgbox('idanal_calc_integral: x and y have different lengths', 'Error');
    return;
end
if length(x) < 10 | length(y) < 10
    msgbox('idanal_calc_integral: problem with array sizes', 'Error');
    return;
end

%Make a dense set of x values for the cubic spline interpolation
xx = x(1) : (x(2) - x(1)) / INTERP_FACTOR : x(length(x));

%Cubic spline interpolation between the measured points
yy = spline(x, y, xx);

%Trapezoidal integration of the interpolated points
int_yy_dxx = cumtrapz(xx, yy);

%Return the value of the integral at the input x values
int_y_dx = spline(xx, int_yy_dxx, x);
    
%Done
