%**************************************************************************
%This function writes phase information to the data file.
%
%Input:
%dat_file, data file for results
%param, parameter structure
%rad, structure containing the phase information
%
%Zachary Wolf, 12/27/05

function [] = phase_dat_phase(dat_file, param, rad)

%Write the results to the data file
fid = fopen(dat_file, 'a');
fprintf(fid, '\r\n');
fprintf(fid, 'Phases At The Poles:\r\n');
fprintf(fid, 'Phase = 0 at cell boundary.\r\n');
fprintf(fid, 'Pole Num  Z Position      Phase      Phase    Ph mod 360\r\n');
fprintf(fid, '              (m)         (deg)     num 360     (deg)   \r\n');
fprintf(fid, '--------  -----------  -----------  -------  -----------\r\n');
pole_num = 1:length(rad.z_peak);
z_pos = rad.z_peak;
phase_deg = rad.phase_peak * 360. / (2 * pi);
phase_num_360 = floor(phase_deg / 360.);
phase_mod_360 = mod(phase_deg, 360.);
for ii = 1 : length(z_pos)
    fprintf(fid, '%8i  %11.6f  %11.3f  %7i  %11.3f\r\n', pole_num(ii), z_pos(ii), phase_deg(ii), phase_num_360(ii), phase_mod_360(ii));
end
fclose(fid);

%Done
