%plots with mean values
clear
xbow_file = 'S:\VOCALS_2008\RHB\radar\wband\Raw\Motion\20083370000Crossbow.txt';
kong_file = 'S:\VOCALS_2008\RHB\radar\wband\Raw\Motion\20083370000Kongsberg.txt';
strhour = str2num(kong_file(50:51))
for run_hour=strhour:2;
    
    if run_hour<10
       kong_file(51) = num2str(run_hour) 
       xbow_file(51) = num2str(run_hour) 
    else
    kong_file(50:51) = num2str(run_hour)
    xbow_file(50:51) = num2str(run_hour)
    end
        
    k=importdata(kong_file, ' ',4);
    x=importdata(xbow_file, ' ',4);
    kdatadegrees=(180/pi)*(k.data(:,1:2));    %convert p&r from radians to degrees
    xdatadegrees=(.005493)*(x.data(:,1:2));    %convert p&r to degrees
    %%x = -2.9:0.1:5.9;   % horizontal bin sizes
    %x = -2.9:0.1:5.9;hist(kdatadegrees(:,1),x);   %pitch - auto plot
    %x = -4:0.1:4;hist(kdatadegrees(:,2),x);  %roll
    %x = -2.9:0.1:2.9;hist(data(:,3),x)          %vert velocity
    kmean_pitch_roll=mean(kdatadegrees), kstd_pitch_roll=std(kdatadegrees)%mean, %std p&r
    xmean_pitch_roll=mean(xdatadegrees), xstd_pitch_roll=std(xdatadegrees)%mean, %std p&r
    %mean_vert_vel=mean(data(:,3)), std_vert_vel=std(data(:,3))      %mean, std vert vel
    
    ksample_size = length(k.data);
    for i=1:ksample_size;
        kdatadegrees(i,3)= i/600;%convert to minutes
    end;
    
    xsample_size = length(x.data);
    for i=1:xsample_size;
        xdatadegrees(i,3)= i/1200;%convert to minutes
    end;

    subplot(4,1,1),plot (kdatadegrees(:,3),kdatadegrees(:,1),'r');axis ([0 60 -6 6]);ylabel('pitch (degrees)');
    text(5,5,['mean = ', num2str(kmean_pitch_roll(1)),'   std = ',num2str(kstd_pitch_roll(1))]);title (kong_file(43:62));
    xlabel('Minutes from the hour');
    subplot(4,1,2),plot (kdatadegrees(:,3),kdatadegrees(:,2),'b');axis ([0 60 -6 6]);ylabel('roll (degrees)');
    text(5,5,['mean = ', num2str(kmean_pitch_roll(2)),'   std = ',num2str(kstd_pitch_roll(2))]);title (kong_file(43:62));
    xlabel('Minutes from the hour');
    
    subplot(4,1,3),plot (xdatadegrees(:,3),xdatadegrees(:,1),'r');axis ([0 60 -6 6]);ylabel('pitch (degrees)');
    text(5,5,['mean = ', num2str(xmean_pitch_roll(1)),'   std = ',num2str(xstd_pitch_roll(1))]);title (xbow_file(43:61));
    xlabel('Minutes from the hour');
    subplot(4,1,4),plot (xdatadegrees(:,3),xdatadegrees(:,2),'b');axis ([0 60 -6 6]);ylabel('roll (degrees)');
    text(5,5,['mean = ', num2str(xmean_pitch_roll(2)),'   std = ',num2str(xstd_pitch_roll(2))]);title (xbow_file(43:61));
    xlabel('Minutes from the hour');
      
    
    jpgfile = 'W:\WBand\Vocals\Kongsberg\MC_Platform_Pitch_Roll_Plots\Leg2\YYYYDDDHHMMa.jpg';
    jpgfile(61:71)=kong_file(43:53);

    saveas(gcf, jpgfile);
end;
