Skip to content
Snippets Groups Projects
tsg_readBucketData.m 1.55 KiB
Newer Older
function [error] = tsg_readBucketData( hTsgGUI, filename)
Yves Gouriou's avatar
Yves Gouriou committed
% Function to read Bucket data in ASCII format. 
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
% filename ........... Data filename
%
% Output
% ------
% error .............. 1: OK - -1 : an error occured
%
Yves Gouriou's avatar
Yves Gouriou committed
% The data are store using setappdata - Variable name : 'bucketASCII'
%
% 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
    % -------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    bucketASCII.TIME      = datenum(bucketData(:,1), bucketData(:,2), ...
                                    bucketData(:,3), bucketData(:,4), ...
                                    bucketData(:,5), bucketData(:,6));
    bucketASCII.LATITUDE  = bucketData(:,7);
    bucketASCII.LONGITUDE = bucketData(:,8);
    bucketASCII.PSAL      = bucketData(:,9);
    bucketASCII.PSAL_QC   = zeros(size(bucketASCII.PSAL));

    % Save the data in the application GUI
    % ------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    setappdata( hTsgGUI, 'bucketASCII', bucketASCII );
    
    % Clear the Workspace
    % -------------------
    clear bucketData
    
    % Close the file
    % --------------
    fclose( fid );
    
    % Everything OK
    % -------------
    error = 1;
end