% This script runs through the Sprof .nc files from the GDAC to check if
% there is DOXY_ADJUSTED available
% Directory containing the files
dirPath = 'Canadian_ARGO';

% Get all .nc files in the directory
ncFiles = dir(fullfile(dirPath, '*.nc'));

% Check if directory exists and has files
if isempty(ncFiles)
    fprintf('No .nc files found in %s\n', dirPath);
    return;
end

% Loop through each file
fprintf('Checking %d files...\n\n', length(ncFiles));

for i = 1:length(ncFiles)
    % Get full file path
    filePath = fullfile(ncFiles(i).folder, ncFiles(i).name);
    
    try
        % Try to read the DOXY_ADJUSTED variable
        doxyData = ncread(filePath, 'DOXY_ADJUSTED');
        
        % Check if all values are NaN
        hasDoxyAdjusted = ~all(isnan(doxyData(:)));
        
        % Output result
        fprintf('%s, hasdoxy_adjusted: %s\n', ncFiles(i).name, mat2str(hasDoxyAdjusted));
        
    catch ME
        % If variable doesn't exist or other error
        fprintf('%s, hasdoxy_adjusted: F (Error: %s)\n', ncFiles(i).name, ME.message);
    end
end

fprintf('\nProcessing complete.\n');
% ```
% 
% This script:
% 1. Gets all `.nc` files from the `Canadian_ARGO` directory
% 2. Loops through each file
% 3. Attempts to read the `DOXY_ADJUSTED` variable
% 4. Checks if all values are NaN (returns `F` if all NaN, `T` if any non-NaN values exist)
% 5. Outputs the filename and whether it has valid DOXY_ADJUSTED data
% 6. Handles errors gracefully if the variable doesn't exist
% 
% The output format will be:
% ```
% filename.nc, hasdoxy_adjusted: 1
% filename2.nc, hasdoxy_adjusted: 0