function [error] = writeAsciiSample( hMainFig, filename) % % Function to write the SAMPLE data in an ASCII file % % Input % ----- % hMainFig ............ Handel to the main user interface % filename ........... Data filename % % Output % ------ % error .............. 1: OK - -1 : no ouput % % initialise % ---------- error = -1; PARA = { 'SSPS_SPL'; 'SSPS_SPL_QC'; 'SSPS_SPL_TYPE';... 'SSTP_SPL'; 'SSTP_SPL_QC'; 'SSTP_SPL_TYPE'}; % Choose parameters to export % --------------------------- [colParaNo, choice] = exportParameterChoice( PARA ); if choice % Open the file % ------------- fid = fopen( filename, 'wt' ); if fid ~= -1 % Display write file info on console % --------------------------------- fprintf('\nWRITE_TXT_FILE\n'); tic; % Display more info about write file on console % --------------------------------------------- fprintf('...writing %s : ', filename); % Get the data from the application GUI % ------------------------------------- tsg = getappdata( hMainFig, 'tsg_data'); tsgNames = fieldnames(tsg); nbRecords = length( tsg.DAYD_SPL ); if nbRecords ~= 0 [year, month, day, hour, min, sec] = datevec( tsg.DAYD_SPL ); tsg_data = [year month day hour min fix(sec) tsg.LATX_SPL tsg.LONX_SPL ]; header = 'YEAR MNTH DAYX hh mi ss LATX LONX'; format = '%04d %02d %02d %02d %02d %02d %12.7f %12.7f'; for i = 1 : length(colParaNo) para = PARA{colParaNo(i)}; if isempty(tsg.(para)) tsg.(para) = NaN * ones( size( tsg.DAYD_SPL ) ); end if findstr( '_QC', para) tsg_data = [tsg_data double(tsg.(para))]; format = [format ' %1d']; else findstr( '_TYPE', para) tsg_data = [tsg_data tsg.(para)]; format = [format ' %1d']; end header = [header ' ' para]; end % Write the file % -------------- if ~isempty( header ) fprintf( fid, '%%HEADER %s\n', header); end if ~isempty(tsg_data) fprintf(fid, [format '\n'], tsg_data'); end % Clear the Workspace % ------------------- clear tsgdata % Everything OK % ------------- error = 1; end % Close the file % -------------- fclose( fid ); % Display time to write file on console % ------------------------------------- t = toc; fprintf('...done (%6.2f sec).\n\n',t); end end