%find_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=[];

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

   ab_s=mean(Vab(1:150));
   cd_s=mean(Vcd(1:150));
   ef_s=mean(Vef(1:150));
   gh_s=mean(Vgh(1:150));

      Vab_mean_surf=[Vab_mean_surf ab_s];
      Vcd_mean_surf=[Vcd_mean_surf cd_s];
      Vef_mean_surf=[Vef_mean_surf ef_s];
      Vgh_mean_surf=[Vgh_mean_surf gh_s];


   ab_b=mean(Vab(end-150:end));
   cd_b=mean(Vcd(end-150:end));
   ef_b=mean(Vef(end-150:end));
   gh_b=mean(Vgh(end-150:end));

      Vab_mean_bot=[Vab_mean_bot ab_b];
      Vcd_mean_bot=[Vcd_mean_bot cd_b];
      Vef_mean_bot=[Vef_mean_bot ef_b];
      Vgh_mean_bot=[Vgh_mean_bot gh_b];




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

   ab_s=mean(Vab(end-150:end));
   cd_s=mean(Vcd(end-150:end));
   ef_s=mean(Vef(end-150:end));
   gh_s=mean(Vgh(end-150:end));

      Vab_mean_surf=[Vab_mean_surf ab_s];
      Vcd_mean_surf=[Vcd_mean_surf cd_s];
      Vef_mean_surf=[Vef_mean_surf ef_s];
      Vgh_mean_surf=[Vgh_mean_surf gh_s];


   ab_b=mean(Vab(1:150));
   cd_b=mean(Vcd(1:150));
   ef_b=mean(Vef(1:150));
   gh_b=mean(Vgh(1:150));

      Vab_mean_bot=[Vab_mean_bot ab_b];
      Vcd_mean_bot=[Vcd_mean_bot cd_b];
      Vef_mean_bot=[Vef_mean_bot ef_b];
      Vgh_mean_bot=[Vgh_mean_bot gh_b];

end

mean_abs=mean(Vab_mean_surf); median_abs=median(Vab_mean_surf);
mean_cds=mean(Vcd_mean_surf); median_cds=median(Vcd_mean_surf);
mean_efs=mean(Vef_mean_surf); median_efs=median(Vef_mean_surf);
mean_ghs=mean(Vgh_mean_surf); median_ghs=median(Vgh_mean_surf);
mean_abb=mean(Vab_mean_bot);  median_abb=median(Vab_mean_bot);
mean_cdb=mean(Vcd_mean_bot);  median_cdb=median(Vcd_mean_bot);
mean_efb=mean(Vef_mean_bot);  median_efb=median(Vef_mean_bot);
mean_ghb=mean(Vgh_mean_bot);  median_ghb=median(Vgh_mean_bot);


save hawaii_acm_bias Vab_mean_surf Vab_mean_bot Vcd_mean_surf Vcd_mean_bot Vef_mean_surf Vef_mean_bot Vgh_mean_surf Vgh_mean_bot mean_abs median_abs mean_abb median_abb mean_cds median_cds mean_cdb median_cdb mean_efs median_efs mean_efb median_efb mean_ghs median_ghs mean_ghb median_ghb

figure
plot(Vab_mean_bot,'r--');
hold on; grid on; zoom on;
plot(Vcd_mean_bot,'m--');plot(Vef_mean_bot,'b--');plot(Vgh_mean_bot,'g--');
plot(Vab_mean_surf,'r');,plot(Vcd_mean_surf,'m');,plot(Vef_mean_surf,'b');,plot(Vgh_mean_surf,'g');
plot(65,mean_abs,'r*','markersize',10)
plot(65,mean_abb,'r*')                
plot(65,mean_cds,'m*','markersize',10)
plot(65,mean_cdb,'m*');
plot(68,mean_efs,'b*','markersize',10)
plot(68,mean_efb,'b*')                
plot(68,mean_ghs,'g*','markersize',10)
plot(68,mean_ghb,'g*');



plot(70,median_abs,'r.','markersize',20);
plot(70,median_abb,'r.','markersize',10);
plot(70,median_cds,'m.','markersize',20);
plot(70,median_cdb,'m.','markersize',10);
plot(73,median_efs,'b.','markersize',20);
plot(73,median_efb,'b.','markersize',10);
plot(73,median_ghs,'g.','markersize',20);
plot(73,median_ghb,'g.','markersize',10);
 
plot(([stas(1),stas(end)]),([mean_abs,mean_abs]),'r','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_abb,mean_abb]),'r--','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_cds,mean_cds]),'m','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_cdb,mean_cdb]),'m--','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_efs,mean_efs]),'b','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_efb,mean_efb]),'b--','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_ghs,mean_ghs]),'g','linewidth',2); 
plot(([stas(1),stas(end)]),([mean_ghb,mean_ghb]),'g--','linewidth',2); 

title('Vab Vcd Vef Vgh = r m b g    HAWAII\_TEST  dashed=bottom solid=surf');
ylabel('mean 150 scans  w/ MEDIAN overplotted Vab Vcd Vef Vgh') 
xlabel('cast #   thick/thin = surf/bot ');

figure

plot(([stas(1),stas(end)]),([median_abs,median_abs]),'r'); 
hold on; grid on; zoom on;
plot(([stas(1),stas(end)]),([median_abb,median_abb]),'r--'); 
plot(([stas(1),stas(end)]),([median_cds,median_cds]),'m'); 
plot(([stas(1),stas(end)]),([median_cdb,median_cdb]),'m--'); 
plot(([stas(1),stas(end)]),([median_efs,median_efs]),'b'); 
plot(([stas(1),stas(end)]),([median_efb,median_efb]),'b--'); 
plot(([stas(1),stas(end)]),([median_ghs,median_ghs]),'g'); 
plot(([stas(1),stas(end)]),([median_ghb,median_ghb]),'g--'); 


title('Vab Vcd Vef Vgh = r m b g    HAWAII\_TEST  dashed=bottom solid=surf');
ylabel('MEDIAN OF mean 150 scans  Vab Vcd Vef Vgh') 
xlabel('cast #   thick/thin = surf/bot mean  ');
