% Download the three files on the main page
% URL containing the list of .nc files
url = 'https://data-argo.ifremer.fr/aux/coriolis/1902578/';

% Read the content of the webpage
webContent = webread(url);

% Define a regular expression pattern to extract URLs ending with .nc
pattern = 'href="([^"]*\.nc)"';

% Find all matches of the pattern in the webpage content
matches = regexp(webContent, pattern, 'tokens');

% Loop through each match and download the corresponding .nc file
for i = 1:length(matches)
    nc_url = matches{i}{1}; % Extract the URL
    full_url = fullfile(url, nc_url); % Create the full URL
    [~, filename, ext] = fileparts(nc_url); % Extract the filename and extension
    output_file = fullfile('C:\Users\bwerb\Documents\MATLAB', [filename, ext]); % Define the output file path
    websave(output_file, full_url); % Download the file
    disp(['Downloaded: ', output_file]); % Display a message
end

%

% Download each profile
% URL containing the list of .nc files
url = 'https://data-argo.ifremer.fr/aux/coriolis/1902578/profiles/';

% Read the content of the webpage
webContent = webread(url);

% Define a regular expression pattern to extract URLs ending with .nc
pattern = 'href="([^"]*\.nc)"';

% Find all matches of the pattern in the webpage content
matches = regexp(webContent, pattern, 'tokens');

% Loop through each match and download the corresponding .nc file
for i = 1:length(matches)
    nc_url = matches{i}{1}; % Extract the URL
    full_url = fullfile(url, nc_url); % Create the full URL
    [~, filename, ext] = fileparts(nc_url); % Extract the filename and extension
    output_file = fullfile('C:\Users\bwerb\Documents\MATLAB', [filename, ext]); % Define the output file path
    websave(output_file, full_url); % Download the file
    disp(['Downloaded: ', output_file]); % Display a message
end