%**************************************************************************
%This function calculates the required magnetic effect of the K adjustment
%shim.
%
%Input:
%ideal_k_value, K value we want to shim to
%k_value, measured K value
%
%Output:
%k_shim_dbrel, delta B / B for the k adjust shim
%
%Zachary Wolf, 1/14/06

function [k_shim_dbrel] = k_shim_calc_dbrel(ideal_k_value, k_value)

%Method
%The K value is adjusted by uniformly changing the magnetic field in the
%undulator by a factor.
%
%Change K by changing the field strength:
%K := - q B0 lambda_u / m vz 2 pi
%d_K / K = d_B0 / B0
%dbrel = d_K / K

%Perform the calculation
dbrel = (k_value - ideal_k_value) / ideal_k_value;

%The shim needs to correct this
k_shim_dbrel = - dbrel;
    
%Done
