%  function:  open_file_GUI
%
%  takes in:
%    1.  title for the GUI box
%    2.  extension with which to seed the "open types" box
%    3.  permission (ex. 'r' for read-only, 'w' for write-only
%
%  returns in "data" structure:
%    1.  data.filename              name of the data file (ex.  junk.txt)
%    2.  data.pathname              path of the data file (ex.  c:\temp\)
%    3.  data.full_path_and_file    full path and name (ex.  c:\temp\junk.txt)
%    4.  data.file_rootname         root name of the data file (ex. junk)
function [data] = open_file_GUI (title, extension, permission)

wildcard = '*.';
%full_wildcard = strcat(wildcard, extension);

%[data.filename, data.pathname]=uigetfile(full_wildcard, title );

% [data.filename, data.pathname] = uigetfile( ...
% {'*.nmea;*.bin','Data Files (*.nmea,*.bin)';
%     '*.nmea',  'ASCII (*.nmea)'; ...
%     '*.bin','GSOF or RT17 (*.bin)'}, ...
%     'Pick a data file');
[data.filename, data.pathname] = uigetfile(extension, title);



warning off;
data.full_path_and_file = strcat(data.pathname, data.filename);             % concatinate strings for filename
data.file_rootname = strtok(data.filename,'.');

warning on;
%if ((isempty(data.file)==1)|(exist(data.file)==0))
if ((isempty(data.full_path_and_file)==1)|(exist(data.full_path_and_file)==0))
    fprintf('->  No file (%s) to load!\n', data.full_path_and_file);
%    fprintf('->  Exiting!\n');
    fprintf(1,'|\n');
%    fprintf(1,'=====================================================================================\n');
    return;
end;

data.fid = fopen(data.full_path_and_file,permission);
%fprintf('->  Option File Handle: %s\n', data.fid);
%fprintf('->  Option File Name:   %s\n', data.filename);
%fprintf('->  Option Path:        %s\n', data.pathname);

return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
