% apply_ref_calshift.m
% 20 Aug 2000
%
% this mfile to apply cal shift to weddell_9900 data
% this cal shift based upon Weddell Sea CTD casts from LDEO
% which John had from work on MP ballasting
%
% applying this cal shift to data which has already been 
% adjusted to it's own internal reference station 218
% using get_new_cond_slopes.m
% input = /j2/data/mvp/weddell_9900/new_grdfmt/grd*.mat
% output = /j2/data/mvp/weddell_9900/cal_grdfmt/grd*.mat

 %apply new slopes to all data files

  all_stations=[1:154 156:369];
  for nn=1:length(all_stations)
    infile=(['/j2/data/mvp/weddell_9900/grdfmt_3_internal_ccal/grd',sprintf('%4.4i',all_stations(nn)),'.mat']);
    outfile=(['/j2/data/mvp/weddell_9900/grdfmt_4_LDEO_ccal/grd',sprintf('%4.4i',all_stations(nn)),'.mat']);
    eval(['load ',infile]);
    disp(['loading file: ',infile]);

    potc=sw_cndr(s_ave',thetave',0)'*sw_c3515;
    potc=.213598+potc*.9920475;
    s_ave=sw_salt(potc/sw_c3515,thetave,0);
    thetave=sw_ptmp(s_ave,tave,pave,0);
    sigthave=sw_pden(s_ave,tave,pave,0)-1000.;

    eval(['save ', outfile, ...
    ' pgrid pave tave cave s_ave thetave sigthave uave vave wave dpdtave'...
    ' cscan1 cscan2 ascan1 ascan2 startdaytime stopdaytime psdate pstart' ...
    ' pedate pstop file'])

  end


