0001 function cond_cal = make_cond_sumfile(cruiseid)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 flag_conv1=0;
0041 flag_conv2=0;
0042 flag_message1=0;
0043 flag_message2=0;
0044
0045
0046
0047 group = group_name(cruiseid);
0048
0049
0050 if ispref(group,'cal_data_dir')
0051 cruise_dir=getpref(group,'cal_data_dir');
0052 else
0053 error(['The cal_data_dir preference was not set for cruise: ' cruiseid '. Run register_cruise.m']);
0054 end
0055
0056
0057 db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
0058 if exist(db_file)==2
0059 load(db_file);
0060 else
0061 error(['The cruise data base file was not found on the path. ' db_file]);
0062 end
0063
0064
0065 n=who('btl');
0066 if isempty(n)==1
0067 error(['btl variable not found in the cruise database. Run load_btl.m ']);
0068 return;
0069 end
0070 n=who('bl');
0071 if isempty(n)==1
0072 error(['bl variable not found in the cruise database. Run load_bl.m ']);
0073 return;
0074 end
0075 n=who('cnv');
0076 if isempty(n)==1
0077 error(['cnv variable not found in the cruise database. Run load_cnv.m ']);
0078 return;
0079 end
0080 n=who('cond');
0081 if isempty(n)==1
0082 error(['cond variable not found in the cruise database. Run load_salts.m ']);
0083 return;
0084 end
0085
0086
0087 cond_cal = sample_struct;
0088 cond_cal.cruiseid=cruiseid;
0089
0090
0091
0092
0093
0094 stations= unique(vertcat(cond.station));
0095 cond_cal.stnnbr=vertcat(cond.station);
0096 cond_cal.castnbr=vertcat(cond.station);
0097 cond_cal.sampnbr=vertcat(cond.sample_bottle);
0098 cond_cal.btlnbr=vertcat(cond.niskin_bottle);
0099 cond_cal.niskinbtlpos=vertcat(cond.niskin_bottle);
0100 cond_cal.btlsal=vertcat(cond.salinity);
0101
0102
0103 for i=1:1:length(cond_cal.btlnbr)
0104 if (cond_cal.stnnbr(i)==0)
0105 cond_cal.fireorder(i,1)=NaN;
0106 else
0107 fire_index=find(bl(cond_cal.stnnbr(i)).niskinnumber==cond_cal.btlnbr(i));
0108 if isempty(fire_index)
0109 warning('No matching bl entry for the current sample. Likely, no confirmation bit.')
0110 else
0111
0112 cond_cal.fireorder(i,1)=bl(cond_cal.stnnbr(i)).fireorder(fire_index);
0113 end
0114 end
0115 end
0116
0117
0118 jj_nan=find(isnan(cond_cal.fireorder)==0);
0119 cond_cal.fireorder=cond_cal.fireorder(jj_nan);
0120 cond_cal.stnnbr=cond_cal.stnnbr(jj_nan);
0121 cond_cal.castnbr=cond_cal.castnbr(jj_nan);
0122 cond_cal.sampnbr=cond_cal.sampnbr(jj_nan);
0123 cond_cal.btlnbr=cond_cal.btlnbr(jj_nan);
0124 cond_cal.niskinbtlpos=cond_cal.niskinbtlpos(jj_nan);
0125 cond_cal.btlsal=cond_cal.btlsal(jj_nan);
0126
0127
0128 for i=1:length(cond_cal.btlsal)
0129 sta_idx=cond_cal.stnnbr(i);
0130 fire_idx=cond_cal.fireorder(i);
0131
0132 for j=1:length(btl(sta_idx).names);
0133 if strncmp(btl(sta_idx).names(j),'pressure',8);
0134 pr_idx=j;
0135 end
0136 if strncmp(btl(sta_idx).names(j),'con_pri',7);
0137 ctd_c1_idx=j;
0138 end
0139 if strncmp(btl(sta_idx).names(j),'con_sec',7);
0140 ctd_c2_idx=j;
0141 end
0142 if strncmp(btl(sta_idx).names(j),'t68_pri',7);
0143 ctd_t1_idx=j;
0144 end
0145 if strncmp(btl(sta_idx).names(j),'t68_sec',7);
0146 ctd_t2_idx=j;
0147 end
0148 if strncmp(btl(sta_idx).names(j),'sal_pri_pri',11);
0149 ctd_sal1_idx=j;
0150 end
0151 if strncmp(btl(sta_idx).names(j),'sal_sec_sec',11);
0152 ctd_sal2_idx=j;
0153 end
0154 if strncmp(btl(sta_idx).names(j),'t90_pri',7);
0155 ctd_t1_idx=j;
0156 flag_conv1=1;
0157 if flag_message1==0
0158 disp('Primary temperatures are given in T90.')
0159 disp('This program will convert to T68 to make the necessary calculations')
0160 flag_message1=1;
0161 end
0162 end
0163 if strncmp(btl(sta_idx).names(j),'t90_sec',7);
0164 ctd_t2_idx=j;
0165 flag_conv2=1;
0166 if flag_message2==0
0167 disp('Secondary temperatures are given in T90.')
0168 disp('This program will convert to T68 to make the necessary calculations')
0169 flag_message2=1;
0170 end
0171 end
0172 end
0173 cond_cal.ctdprs(i,1)=btl(sta_idx).data(fire_idx,pr_idx);
0174 cond_cal.ctdcon1(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c1_idx);
0175 cond_cal.ctdcon2(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c2_idx);
0176 cond_cal.ctdsal1(i,1)=btl(sta_idx).data(fire_idx,ctd_sal1_idx);
0177 cond_cal.ctdsal2(i,1)=btl(sta_idx).data(fire_idx,ctd_sal2_idx);
0178 cond_cal.ctdtmp1(i,1)=btl(sta_idx).data(fire_idx,ctd_t1_idx);
0179 if flag_conv1==1;
0180 cond_cal.ctdtmp1(i,1)=t90tot68(cond_cal.ctdtmp1(i,1));
0181 end
0182 cond_cal.ctdtmp2(i,1)=btl(sta_idx).data(fire_idx,ctd_t2_idx);
0183 if flag_conv2==1;
0184 cond_cal.ctdtmp2(i,1)=t90tot68(cond_cal.ctdtmp2(i,1));
0185 end
0186
0187
0188
0189 for j=1:length(cnv(sta_idx).names);
0190 if strncmp(cnv(sta_idx).names(j),'pr',2)
0191 cnv_pr_idx=j;
0192 end
0193 if strncmp(cnv(sta_idx).names(j),'c0S/m',5);
0194 cnv_c1_idx=j;
0195 end
0196 if strncmp(cnv(sta_idx).names(j),'c1S/m',5);
0197 cnv_c2_idx=j;
0198 end
0199 end
0200 pressure=cnv(sta_idx).data(:,cnv_pr_idx);
0201 max_pressure_idx=find(pressure(:)==max(pressure));
0202
0203
0204
0205 conductivity1=10*cnv(sta_idx).data(:,cnv_c1_idx);
0206 conductivity2=10*cnv(sta_idx).data(:,cnv_c2_idx);
0207 pressure=pressure(1:max_pressure_idx);
0208 conductivity1=conductivity1(1:max_pressure_idx);
0209 conductivity2=conductivity2(1:max_pressure_idx);
0210 aux_dcdp1=weim(21,'hann',gradient(conductivity1))';
0211 aux_dcdp2=weim(21,'hann',gradient(conductivity2))';
0212 new_dcdp1=interp1(pressure,aux_dcdp1,cond_cal.ctdprs(i),'spline',NaN);
0213 new_dcdp2=interp1(pressure,aux_dcdp2,cond_cal.ctdprs(i),'spline',NaN);
0214 if isnan(new_dcdp1)==1
0215 cond_cal.dcdp1(i,1)=mean(aux_dcdp1);
0216 else
0217 cond_cal.dcdp1(i,1)=new_dcdp1;
0218 end
0219 if isnan(new_dcdp2)==1
0220 cond_cal.dcdp2(i,1)=mean(aux_dcdp2);
0221 else
0222 cond_cal.dcdp2(i,1)=new_dcdp2;
0223 end
0224 end
0225 cond_cal.btlcon1=sw_C3515*sw_cndr(cond_cal.btlsal,cond_cal.ctdtmp1,cond_cal.ctdprs);
0226 cond_cal.btlcon2=sw_C3515*sw_cndr(cond_cal.btlsal,cond_cal.ctdtmp2,cond_cal.ctdprs);
0227
0228
0229 save(db_file,'cond_cal','-append');
0230
0231 if nargout==0
0232 assignin('caller','ans',cond_cal);
0233 return
0234 else
0235 varargout{1}=cond_cal;
0236 return
0237 end
0238
0239 return