%estimate_acm_bias.m
stas=input('input the range of profiles starting w/ downcast :   ');
direct=input('input the directory where these files sit  :  ','s');

Vab_mean_surf=[];
Vcd_mean_surf=[];
Vef_mean_surf=[];
Vgh_mean_surf=[];


Vab_mean_bot=[];
Vcd_mean_bot=[];
Vef_mean_bot=[];
Vgh_mean_bot=[];

Vab_median_surf=[];
Vcd_median_surf=[];
Vef_median_surf=[];
Vgh_median_surf=[];


Vab_median_bot=[];
Vcd_median_bot=[];
Vef_median_bot=[];
Vgh_median_bot=[];


Vab_std_surf=[];
Vcd_std_surf=[];
Vef_std_surf=[];
Vgh_std_surf=[];


Vab_std_bot=[];
Vcd_std_bot=[];
Vef_std_bot=[];
Vgh_std_bot=[];


for mm=1:length(stas)   %downcasts
   fil=['raw',sprintf('%4.4i',(stas(mm)))];
   eval(['load ',direct,'/',fil,'.mat']);
   disp([sprintf('\n'),'working on file  :   ',fil]);

%first edit the ACM vel data 
[Vab]=mvp_edit_3(-50,50,11,Vab);
[Vcd]=mvp_edit_3(-50,50,11,Vcd);
[Vef]=mvp_edit_3(-50,50,11,Vef);
[Vgh]=mvp_edit_3(-50,50,11,Vgh);

%next specify the scan numbers for the top and bottom rest periods
if(cpres(1)>cpres(end));
%this is an up profile
nbot=[1:150];
ntop=[length(Vab)-150:length(Vab)];

else
%this is a down profile
nbot=[length(Vab)-150:length(Vab)];
ntop=[1:150];

end

      Vab_mean_surf(mm)=mean(Vab(ntop));
      Vcd_mean_surf(mm)=mean(Vcd(ntop));
      Vef_mean_surf(mm)=mean(Vef(ntop));
      Vgh_mean_surf(mm)=mean(Vgh(ntop));

      Vab_mean_bot(mm)=mean(Vab(nbot));
      Vcd_mean_bot(mm)=mean(Vcd(nbot));
      Vef_mean_bot(mm)=mean(Vef(nbot));
      Vgh_mean_bot(mm)=mean(Vgh(nbot));

      Vab_median_surf(mm)=median(Vab(ntop));
      Vcd_median_surf(mm)=median(Vcd(ntop));
      Vef_median_surf(mm)=median(Vef(ntop));
      Vgh_median_surf(mm)=median(Vgh(ntop));

      Vab_median_bot(mm)=median(Vab(nbot));
      Vcd_median_bot(mm)=median(Vcd(nbot));
      Vef_median_bot(mm)=median(Vef(nbot));
      Vgh_median_bot(mm)=median(Vgh(nbot));

      Vab_std_surf(mm)=std(Vab(ntop));
      Vcd_std_surf(mm)=std(Vcd(ntop));
      Vef_std_surf(mm)=std(Vef(ntop));
      Vgh_std_surf(mm)=std(Vgh(ntop));

      Vab_std_bot(mm)=std(Vab(nbot));
      Vcd_std_bot(mm)=std(Vcd(nbot));
      Vef_std_bot(mm)=std(Vef(nbot));
      Vgh_std_bot(mm)=std(Vgh(nbot));


end


save acm_bias_statistics stas Vab_mean_surf Vab_mean_bot Vcd_mean_surf Vcd_mean_bot ...
Vef_mean_surf Vef_mean_bot Vgh_mean_surf Vgh_mean_bot Vab_median_surf Vab_median_bot ... 
Vcd_median_surf Vcd_median_bot Vef_median_surf Vef_median_bot Vgh_median_surf Vgh_median_bot ...
Vab_std_surf Vab_std_bot Vcd_std_surf Vcd_std_bot ...
Vef_std_surf Vef_std_bot Vgh_std_surf Vgh_std_bot


