%**************************************************************************
%This function performs a phase analysis of a device.
%The slippage, the distance between the light and the electrons, is calculated.
%The phase is analyzed, including the total phase through the device.
%
%Input:
%param, parameter structure
%dat_file, output data file name
%plt_file, output plot file name
%field, field structure
%traj, trajectory structure
%
%Output:
%phas, structure containing phase information
%	z                   %Translated Z, from traj structure (m)
%	slip                %Slippage, slip = 0 at z = 0 (m)
%	nom_lambda_r        %Wavelength of nominal radiation wave (m)
%	phase_nom           %Phase relative to nominal radiation wave, phase = 0 at cell boundary (rad)
%
%Zachary Wolf
%7/25/11

function [phas] = traj_anal_phase(param, dat_file, plt_file, field, traj)

%Extract required information
nom_lambda_r = param.nom_lambda_r;
z = field.z;
vz = traj.vz;

%Slippage -----

%Calculate the slippage as a function of z
slip = slip_calc_slip_vz(z, vz);

%Plot the slippage
slip_plot_slip(plt_file, z, slip);

%Phase To Nominal Wave -----

%Calculate the phase relative to the nominal radiation wave as a function of z, phase(z(1)) = 0 ref
phase_nom = phase_calc_phase(nom_lambda_r, slip);

%Plot the phase
phase_plot_phase_nom_rad_wave(plt_file, z, phase_nom);

%Results -----

%Save values in the phas structure
phas.z = z;
phas.slip = slip;
phas.nom_lambda_r = nom_lambda_r;
phas.phase_nom = phase_nom;

%Done
