Skip to content
Snippets Groups Projects
tsg_readBucketData.m 1.59 KiB
Newer Older
function [error] = tsg_readTsgData( hTsgGUI, filename)
% Function to read the Bucket data. Should be in a NetCDF file
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
% filename ........... Data filename
%
% Output
% ------
% error .............. 1: OK - -1 : an error occured
%
% The data are store using setappdata - Variable name : 'bucket_data'
%
% Function to be rewritten when the NetCDF format will be in use
% Caution : replace the fill-value with NaN
%

% Open the file
% -------------
fid = fopen( filename, 'r' );

error = -1;
if fid ~= -1

    % Read the file - skip 2 lines
    % ----------------------------
    fgetl( fid ); fgetl( fid );
    bucketData = fscanf(fid,'%d %d %d %d %d %d %f %f %f', [9 Inf])';
    
    % Every variable are put in a structure
    % -------------------------------------
    bucket.TIME_WS       = datenum(bucketData(:,1), bucketData(:,2), ...
                           bucketData(:,3), bucketData(:,4), ...
                           bucketData(:,5), bucketData(:,6));
    bucket.LATITUDE_WS   = bucketData(:,7);
    bucket.LONGITUDE_WS  = bucketData(:,8);
    bucket.PSAL_WS       = bucketData(:,9);
    bucket.PSAL_QC_WS    = size(bucket.PSAL_WS);

    % Save the data in the application GUI
    % ------------------------------------
    setappdata( hTsgGUI, 'bucket_data', bucket );
    
    % Clear the Workspace
    % -------------------
    clear bucketData
    
    % Close the file
    % --------------
    fclose( fid );
    
    % Everything OK
    % -------------
    error = 1;
end