%**************************************************************************
%This function determines the shims required to adjust the K parameter to
%the desired value.
%
%Input:
%dat_file, data file
%plt_file, plot file
%param, parameter structure
%shim_param, shim parameter structure
%field, magnetic field structure
%traj, trajectory structure
%rad, structure containing radiation information
%
%Output:
%k_shim, structure containing shim information to get the proper K value
%   dbrel               %Required dB / B to get the proper K value
%   dgap                %Required gap change (m)
%   dxbeam              %Change in x of the beam required to give the proper K value
%
%Zachary Wolf
%12/28/05

function [k_shim] = pid_shim_k(dat_file, plt_file, param, shim_param, field, traj, rad)

%Calculate the relative change required in the field
k_shim_dbrel = k_shim_calc_dbrel(param.nom_k_value, rad.k_eff);

%Calculate the required gap change
k_shim_dgap = k_shim_calc_dgap(shim_param.phaserr_gap_shim_nom_gap, param.nom_lambda_u, k_shim_dbrel);

%Calculate the horizontal translation of the beam with canted poles to get the proper K value
k_shim_dxbeam = k_shim_calc_dx(shim_param.k_shim_cant_angle, k_shim_dgap);

%Save the results
k_shim.dbrel = k_shim_dbrel;
k_shim.dgap = k_shim_dgap;
k_shim.dxbeam = k_shim_dxbeam;

%Write the results to the data file
k_shim_dat_k_shim(dat_file, rad, param, shim_param, k_shim);

%Done
