%**************************************************************************
%This function models the shimmed trajectory giving the expected results of
%the shimming.
%
%Input:
%plt_file, plot file
%param, parameter structure
%field, magnetic field structure
%traj_shim, structure containing the trajectory shim information
%   x_shim              %Structure containing the x trajectory shim information
%   y_shim              %Structure containing the y trajectory shim information
%
%Zachary Wolf
%1/2/06

function [] = pid_shim_model_traj(plt_file, param, field, traj_shim)

%Extract the required field information
z = field.z;
bx = field.bx;
by = field.by;
nom_lambda_u = param.nom_lambda_u;
gamma = param.gamma;

%Extract the shim information
x_shim = traj_shim.x_shim;
y_shim = traj_shim.y_shim;

%Add the shim fields to the measured fields
by_m = model_traj_shim_x_traj_shim(nom_lambda_u, x_shim, z, by);
bx_m = model_traj_shim_y_traj_shim(nom_lambda_u, y_shim, z, bx);

%Calculate the field integrals
int_bx_dz_m = int_calc_int(z, bx_m);
int_by_dz_m = int_calc_int(z, by_m);
int_int_bx_dz_dz_m = int_calc_int(z, int_bx_dz_m);
int_int_by_dz_dz_m = int_calc_int(z, int_by_dz_m);

%Apply lambda filter
bx_filt_m = filt_apply_lambda_filt(nom_lambda_u, z, bx_m);
by_filt_m = filt_apply_lambda_filt(nom_lambda_u, z, by_m);
int_bx_dz_filt_m = filt_apply_lambda_filt(nom_lambda_u, z, int_bx_dz_m);
int_by_dz_filt_m = filt_apply_lambda_filt(nom_lambda_u, z, int_by_dz_m);
int_int_bx_dz_dz_filt_m = filt_apply_lambda_filt(nom_lambda_u, z, int_int_bx_dz_dz_m);
int_int_by_dz_dz_filt_m = filt_apply_lambda_filt(nom_lambda_u, z, int_int_by_dz_dz_m);

%Calculate trajectories
[x_m, x_p_m, x_pp_m] = traj_calc_x_traj(gamma, by_m, int_by_dz_m, int_int_by_dz_dz_m);
[y_m, y_p_m, y_pp_m] = traj_calc_y_traj(gamma, bx_m, int_bx_dz_m, int_int_bx_dz_dz_m);

%Calculate filtered trajectories
[x_filt_m, x_p_filt_m, x_pp_filt_m] = traj_calc_x_traj(gamma, by_filt_m, int_by_dz_filt_m, int_int_by_dz_dz_filt_m);
[y_filt_m, y_p_filt_m, y_pp_filt_m] = traj_calc_y_traj(gamma, bx_filt_m, int_bx_dz_filt_m, int_int_bx_dz_dz_filt_m);

%Plot the expected trajectories with the added shims
model_traj_shim_plot_x_traj(plt_file, param, z, x_m, x_filt_m);
model_traj_shim_plot_y_traj(plt_file, param, z, y_m, y_filt_m);

%Done
