@@ -8,6 +8,8 @@ function calculate_piecewisefit( pn_float_dir, pn_float_name, po_system_configur
88
99%
1010% Cecile Cabanes, June 2013 : calculate off-diagonal terms for error estimate: add horizontal covariance to track changes: see "change config 129"
11+ % Delphine Dobler (DD), September 2024 :
12+ % 4 - save computed theta levels in a file
1113
1214% pn_float_dir='testfloats/';
1315% pn_float_name='robbins4900178';
@@ -156,10 +158,15 @@ function calculate_piecewisefit( pn_float_dir, pn_float_name, po_system_configur
156158 return
157159end
158160
161+ % DD (2024/09-4): initialisation of arrays to be saved in a file
162+ Theta_nseq= NaN * zeros(10 ,n_seq );
163+ Index= NaN * zeros(10 ,n );
164+ Plevels= NaN * zeros(10 ,n_seq );
165+
159166% loop through sequences of calseries, ie if time series is broken into segments --
160- for i = 1 : n_seq
167+ for iseq = 1 : n_seq
161168
162- calindex = find(calseries == unique_cal(i ));
169+ calindex = find(calseries == unique_cal(iseq ));
163170 k = length(calindex );
164171
165172 % choose 10 float theta levels to use in the piecewise linear fit --------
@@ -180,6 +187,31 @@ function calculate_piecewisefit( pn_float_dir, pn_float_name, po_system_configur
180187
181188 [Theta , P , index , var_s_th , th ] = ...
182189 find_10thetas( unique_SAL , unique_PTMP , unique_PRES , unique_la_ptmp , use_theta_gt , use_theta_lt , use_pres_gt , use_pres_lt , use_percent_gt );
190+
191+ % DD (2024/09-4): Save Theta-related information for plotting functions
192+ Index(: ,calindex )=index ;
193+ Plevels(: ,iseq )=P ;
194+ [mvth ,~ ]=size(var_s_th );
195+ Theta_nseq(: ,iseq )=Theta ;
196+ if iseq == 1
197+ Var_s_Thetas= NaN .* ones(mvth ,n_seq );
198+ Thetas= NaN .* ones(mvth ,n_seq );
199+ Var_s_Thetas(: ,iseq )=var_s_th ;
200+ Thetas(: ,iseq )=th ;
201+ else
202+ [mVth ,~ ]=size(Var_s_Thetas );
203+ tmp1= Var_s_Thetas ;
204+ tmp2= Thetas ;
205+ mm= max(mVth ,mvth );
206+ Var_s_Thetas= NaN .* ones(mm ,n_seq );
207+ Thetas= NaN .* ones(mm ,n_seq );
208+ Var_s_Thetas(1 : mVth ,: )=tmp1 ;
209+ Var_s_Thetas(1 : mvth ,iseq )=var_s_th ;
210+ Thetas(1 : mVth ,: )=tmp2 ;
211+ Thetas(1 : mvth ,iseq )=th ;
212+ end
213+ %
214+
183215
184216 pp= find(isnan(index )==0 );
185217 if (isempty(pp )==0 ) % only proceed when there are valid levels ----
@@ -229,18 +261,18 @@ function calculate_piecewisefit( pn_float_dir, pn_float_name, po_system_configur
229261 if isempty(breaks )
230262 [xfit(calindex ), pcond_factor(calindex ), pcond_factor_err(calindex ), time_deriv(calindex ), ...
231263 time_deriv_err(calindex ), sta_mean(calindex ), sta_rms(calindex ), NDF , fitcoef , fitbreaks ] = ...
232- fit_cond(x , y , err , covariance , ' max_no_breaks' , max_breaks(i ));
264+ fit_cond(x , y , err , covariance , ' max_no_breaks' , max_breaks(iseq ));
233265 else
234- breaks_in = breaks(i ,: );
266+ breaks_in = breaks(iseq ,: );
235267 breaks_in = breaks_in(find(isfinite(breaks_in )));
236- if isempty(max_breaks(i ))
268+ if isempty(max_breaks(iseq ))
237269 [xfit(calindex ), pcond_factor(calindex ), pcond_factor_err(calindex ), time_deriv(calindex ), ...
238270 time_deriv_err(calindex ), sta_mean(calindex ), sta_rms(calindex ), NDF , fitcoef , fitbreaks ] = ...
239271 fit_cond(x , y , err , covariance , ' breaks' , breaks_in );
240272 else
241273 [xfit(calindex ), pcond_factor(calindex ), pcond_factor_err(calindex ), time_deriv(calindex ), ...
242274 time_deriv_err(calindex ), sta_mean(calindex ), sta_rms(calindex ), NDF , fitcoef , fitbreaks ] = ...
243- fit_cond(x , y , err , covariance , ' breaks' , breaks_in , ' max_no_breaks' , max_breaks(i ));
275+ fit_cond(x , y , err , covariance , ' breaks' , breaks_in , ' max_no_breaks' , max_breaks(iseq ));
244276 end
245277 end
246278
@@ -266,16 +298,22 @@ function calculate_piecewisefit( pn_float_dir, pn_float_name, po_system_configur
266298 sta_SAL1(: ,calindex ) = sw_salt( (sta_COND(: ,calindex )+sta_COND_err(: ,calindex ))/sw_c3515 , unique_PTMP , 0 ) ;
267299 sta_SAL_err(: ,calindex ) = abs(sta_SAL(: ,calindex )-sta_SAL1(: ,calindex ));
268300
269- fcoef(i ,1 : length(fitcoef )) = fitcoef ;
301+ fcoef(iseq ,1 : length(fitcoef )) = fitcoef ;
270302 if ~isempty(fitbreaks )
271- fbreaks(i ,1 : length(fitbreaks )) = fitbreaks ;
303+ fbreaks(iseq ,1 : length(fitbreaks )) = fitbreaks ;
272304 end
273305
274306 end
275307
276308 end % if there are valid levels
277309end % for each unique_cal
278310
311+ % DD (2024/09-4) : save theta levels information inside a file.
312+ Theta= Theta_nseq ;
313+ ls_theta = strcat( po_system_configuration .FLOAT_CALIB_DIRECTORY , ...
314+ pn_float_dir , ' selected_theta_' , pn_float_name ,' .mat' );
315+ save(ls_theta , ' Theta' ,' Index' ,' Plevels' ,' Var_s_Thetas' ,' Thetas' )
316+ % end of DD (2024/09-4)
279317
280318% save calibration data --------------------------------
281319
0 commit comments