Skip to content

Commit 007abb1

Browse files
committed
Code change to handle case of missing prof files
Normally, all floats have *_prof.nc files on the GDAC. BGC floats also have *_Sprof.nc files. In early February 2023, JMA was reprocessing some older float files, and temporarily, only Sprof files were present on the GDAC, not the corresponding prof files. This fix handles this case.
1 parent ee05d5a commit 007abb1

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

auxil/initialize_sprof.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function initialize_sprof(file_name)
3737
Sprof.lat = H{3};
3838
Sprof.lon = H{4};
3939
Sprof.ocean = H{5};
40-
% Sprof.profiler = H{6}; % profiler type; not yet used
40+
Sprof.profiler = H{6}; % profiler type
4141
% column 7: institution
4242
Sprof.sens = H{8};
4343
Sprof.split_sens = cellfun(@split, Sprof.sens, 'UniformOutput', false);

initialize_argo.m

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function initialize_argo()
164164

165165
% Extract unique BGC floats
166166
[uwmo_sprof,ia] = unique(Sprof.wmo,'stable'); % keep list order
167+
Sprof_wmo = Sprof.wmo; % needed later if sprof_only is not empty
167168
Sprof.wmo = str2double(Sprof.wmo);
168169
ia(end+1) = length(Sprof.urls) + 1;
169170
bgc_prof_idx1 = ia(1:end-1);
@@ -185,13 +186,50 @@ function initialize_argo()
185186
% Extract unique floats
186187
% note that older floats have 5-digit IDs
187188
[uwmo_prof,ia2] = unique(Prof.wmo,'stable'); % keep list order
189+
Prof_wmo = Prof.wmo; % needed later if sprof_only is not empty
188190
Prof.wmo = str2double(Prof.wmo);
189191
ulist = Prof.urls(ia2);
190-
dacs = regexp(ulist(:,1),'^\w+','once','match');
192+
dacs = regexp(ulist(:),'^\w+','once','match');
191193
prof_fnames = regexprep(uwmo_prof,'\d+','$0_prof.nc');
192-
tmp = regexprep(ulist(:,1),'profiles.+','');
194+
tmp = regexprep(ulist(:),'profiles.+','');
193195
prof_fp = strcat(tmp,prof_fnames);
194196

197+
% are there any floats that have only Sprof files, but not prof files?
198+
sprof_only = setdiff(uwmo_sprof, uwmo_prof);
199+
if ~isempty(sprof_only)
200+
n_sprof_only = length(sprof_only);
201+
fprintf('The following %d floats have only Sprof files, not prof files:\n', ...
202+
n_sprof_only)
203+
disp(cell2mat(sprof_only))
204+
disp('') % empty line in command window
205+
idx_sprof_only = cellfun(@(x) find(strcmp(Sprof_wmo, x), 1), sprof_only);
206+
add_dacs = regexp(Sprof.urls(idx_sprof_only),'^\w+','once','match');
207+
% since the float type is 'bgc', prof will be replaced by Sprof later
208+
add_fnames = regexprep(sprof_only,'\d+','$0_prof.nc');
209+
tmp = regexprep(Sprof.urls(idx_sprof_only),'profiles.+','');
210+
add_fp = strcat(tmp, add_fnames);
211+
% add them to other variables so Float structure will have them
212+
prof_fp = [prof_fp; add_fp];
213+
prof_fnames = [prof_fnames; add_fnames];
214+
dacs = [dacs; add_dacs];
215+
wmo_sprof_only = str2double(sprof_only);
216+
idx_in_sprof = cell2mat(arrayfun(@(x) find(Sprof.wmo == x), ...
217+
wmo_sprof_only, 'UniformOutput', false));
218+
% add all fields from the "special" floats into the Prof structure
219+
Prof.urls = [Prof.urls; Sprof.urls(idx_in_sprof)];
220+
Prof.date = [Prof.date; Sprof.date(idx_in_sprof)];
221+
Prof.lat = [Prof.lat; Sprof.lat(idx_in_sprof)];
222+
Prof.lon = [Prof.lon; Sprof.lon(idx_in_sprof)];
223+
Prof.ocean = [Prof.ocean; Sprof.ocean(idx_in_sprof)];
224+
Prof.profiler = [Prof.profiler; Sprof.profiler(idx_in_sprof)];
225+
Prof.update = [Prof.update; Sprof.update(idx_in_sprof)];
226+
Prof.split_sens = [Prof.split_sens; Sprof.split_sens(idx_in_sprof)];
227+
Prof.wmo = [Prof.wmo; Sprof.wmo(idx_in_sprof)];
228+
Prof_wmo = [Prof_wmo; Sprof_wmo(idx_in_sprof)];
229+
[uwmo_prof,ia2] = unique(Prof_wmo,'stable');
230+
end
231+
232+
195233
% need to find out which floats are phys (in Prof only) and bgc (in Sprof)
196234
is_uniq_bgc = ismember(uwmo_prof,uwmo_sprof);
197235
nbgc = sum(is_uniq_bgc); % # of bgc floats (this may be revised later)
@@ -271,6 +309,15 @@ function initialize_argo()
271309
bgc_prof_idx2 = bgc_prof_idx2(is_true_bgc == 1);
272310
Float.bgc_prof_idx1(strcmp(Float.type, 'bgc')) = bgc_prof_idx1;
273311
Float.bgc_prof_idx2(strcmp(Float.type, 'bgc')) = bgc_prof_idx2;
312+
% add this check in case that files without prof files do not have
313+
% any BGC sensors, so that they will be classified as 'phys' floats
314+
% but Sprof files need to be read anyway
315+
Float.has_prof_file = ones(length(Float.type), 1);
316+
if ~isempty(sprof_only)
317+
idx_in_float = cell2mat(arrayfun(@(x) find(Float.wmoid == x), ...
318+
wmo_sprof_only, 'UniformOutput', false));
319+
Float.has_prof_file(idx_in_float) = 0;
320+
end
274321

275322
% for all "true" BGC floats, i.e., those that are listed in the Sprof
276323
% index file and have more than pTS sensors, Sprof files will be used
@@ -279,12 +326,14 @@ function initialize_argo()
279326
fprintf('%d "true" BGC floats were found\n', sum(idx_bgc));
280327
idx_phys = strcmp(Float.type, 'phys');
281328
fprintf('%d core and deep floats were found\n', sum(idx_phys));
282-
Float.file_path(strcmp(Float.type, 'bgc')) = ...
329+
Float.file_path(strcmp(Float.type, 'bgc') | ~Float.has_prof_file) = ...
283330
cellfun(@(x) strrep(x, 'prof', 'Sprof'), ...
284-
Float.file_path(strcmp(Float.type, 'bgc')), 'UniformOutput', false);
285-
Float.file_name(strcmp(Float.type, 'bgc')) = ...
331+
Float.file_path(strcmp(Float.type, 'bgc') | ~Float.has_prof_file), ...
332+
'UniformOutput', false);
333+
Float.file_name(strcmp(Float.type, 'bgc') | ~Float.has_prof_file) = ...
286334
cellfun(@(x) strrep(x, 'prof', 'Sprof'), ...
287-
Float.file_name(strcmp(Float.type, 'bgc')), 'UniformOutput', false);
335+
Float.file_name(strcmp(Float.type, 'bgc') | ~Float.has_prof_file), ...
336+
'UniformOutput', false);
288337

289338
% use the update date of the last profile of each float
290339
Float.update(strcmp(Float.type, 'bgc')) = Sprof.update(bgc_prof_idx2);

0 commit comments

Comments
 (0)