Skip to content

Commit

Permalink
documentation, enable dateline crossing
Browse files Browse the repository at this point in the history
  • Loading branch information
lnferris committed Sep 11, 2020
1 parent 4f10ef6 commit 4f56901
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion demos/demos.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
start_date = '01-Nov-2015 00:00:00';
end_date = '01-Jan-2017 00:00:00';
variable_list = {'TEMP_ADJUSTED','PSAL_ADJUSTED'}; % Variables to read (besides id, lon, lat, date, z).
[argo,~] = argo_build(argo_dir,region,start_date,end_date,variable_list);
[argo,matching_profiles] = argo_build(argo_dir,region,start_date,end_date,variable_list);

% argo_platform_subset

Expand Down
55 changes: 46 additions & 9 deletions ocean_data_tools/argo_build.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,29 @@
% [argo,matching_files] = argo_build(argo_dir,region,start_date,end_date,variable_list)
% searches pathway argo_dir for profiles meeting the search criteria
% region, start_date, and end_date. Profiles are loaded into the struct
% array argo with all variables specified in variable_list. Variables PLATFORM_NUMBER,
% LONGITUDE, LATITUDE, JULD, and PRES_ADJUSTED are included automatically.
% array argo with all variables specified in variable_list.
% Files containing matching profiles are listed in matching_files.
%
%
% argo_dir is a character array search path with wildcards. The search path
% should be the path to the netcdf files themselves, not their directory.
%
% region is a vector containing the bounds [S N W E] of the search region,
% with limits [-90 90 -180 180]. Limits may cross the dateline e.g. [35 45
% 170 -130].
%
% start_date and end_date are date strings in format 'dd-mmm-yyyy HH:MM:SS'.
%
% argo is a uniform struct containing data from the profiles matching the
% region and date criteria. Some data is included automatically while some
% must be specificed. The variables PLATFORM_NUMBER, LONGITUDE, LATITUDE, JULD,
% and PRES_ADJUSTED are included automatically. Additional variables must
% be specified in variable_list, a cell array where each element is the
% string name of a variable.
%
% matching_files is a string array where each string is the full path to a
% file which contained a profile matching the region and date criteria.
%
%
%% Example 1
% Load Argo data from west of New Zealand:
%
Expand All @@ -28,19 +47,27 @@
%
%% Citation Info
% github.com/lnferris/ocean_data_tools
% Jun 2020; Last revision: 08-Sep-2020
% Jun 2020; Last revision: 11-Sep-2020
%
% See also argo_platform_subset and general_region_subset.

% deal with inputs other than [-90 90 -180 180] e.g [-90 90 20 200]
% deal with inputs other than [-90 90 -180 180] e.g [-90 90 20 200]
region(region>180) = region(region>180)- 360;
region(region<-180) = region(region<-180)+360;

FillValue = 99999; % From Argo manual.
start_date = datenum(start_date,'dd-mmm-yyyy HH:MM:SS');
end_date = datenum(end_date,'dd-mmm-yyyy HH:MM:SS');
slim = region(1); nlim = region(2); % Unpack SearchLimits.
wlim = region(3); elim = region(4);
slim = region(1);
nlim = region(2);
wlim = region(3);
elim = region(4);
if wlim > elim
[wlim_left] = wlim;
[elim_left] = 180;
[wlim_right] = -180;
[elim_right] = elim;
end

base_list = {'PLATFORM_NUMBER','LONGITUDE','LATITUDE','JULD','PRES_ADJUSTED'}; % Variables automatically included.
variable_list(ismember(variable_list, base_list )) = []; % remove redundant vars
Expand All @@ -51,6 +78,10 @@
matching_files = []; % Make an empty list to hold filenames.
argo_cell = cell(0,nvar); % Make an empty table to hold profile data.
full_path = dir(argo_dir);
if isempty(full_path)
disp([newline, 'No matching Argo files in path ',argo_dir, newline])
return
end

for i = 1:length(full_path) % For each file in full_path...
filename = [full_path(i).folder '/' full_path(i).name];
Expand All @@ -66,8 +97,14 @@
VAR5 = netcdf.getVar(nc,netcdf.inqVarID(nc,'PRES_ADJUSTED'));

% See which profiles have the correct lat,lon,date.
good_inds = find(VAR3 >= slim & VAR3 <= nlim & VAR2 >= wlim & VAR2 <= elim & VAR4 >= start_date & VAR4 < (end_date +1));

if wlim > elim
inds_left = find(VAR3 >= slim & VAR3 <= nlim & VAR2 >= wlim_left & VAR2 <= elim_left & VAR4 >= start_date & VAR4 < (end_date +1));
inds_right = find(VAR3 >= slim & VAR3 <= nlim & VAR2 >= wlim_right & VAR2 <= elim_right & VAR4 >= start_date & VAR4 < (end_date +1));
good_inds = union(inds_left,inds_right);
else
good_inds = find(VAR3 >= slim & VAR3 <= nlim & VAR2 >= wlim & VAR2 <= elim & VAR4 >= start_date & VAR4 < (end_date +1));
end

if any(good_inds) % If there is at least one good profile in this file...
for cast = 1:length(good_inds) % Write each good profile into temporary cell array...

Expand Down

0 comments on commit 4f56901

Please sign in to comment.