function ph = erik_fixphase(ph_temp, E_pp)
%
%
%

% unwrap the phase before interpolating
ph_temp(:, 2) = unwrap(ph_temp(:, 2)*pi/180)*180/pi;


% Interpolate the phase data to the E_para data
ph_temp = [E_pp(:,1) interp1(ph_temp(:,1), ph_temp(:,[2]), E_pp(:,1), 'linear', 'extrap')];


% Wrap back

for i = 1:length(ph_temp)
  if (ph_temp(i, 2)) > 360
    ph_temp(i, 2) = ph_temp(i, 2) - 360*floor(ph_temp(i, 2)/360);    
  end
  if (ph_temp(i, 2)) < 0
    ph_temp(i, 2) = ph_temp(i, 2) + 360*(-floor(ph_temp(i, 2)/360));    
  end
end

ph = ph_temp;
