Home > marsbar > mars_uifile.m

mars_uifile

PURPOSE ^

wrapper for matlab uiputfile/getfile; to resolve version differences

SYNOPSIS ^

function [fn,pn,fi] = mars_uifile(action, filter_spec, prompt, filename, varargin)

DESCRIPTION ^

 wrapper for matlab uiputfile/getfile; to resolve version differences
 FORMAT [fn,pn,fi] = mars_uifile(action, filter_spec, prompt, filename, varargin)

 uigetfile and uiputfile in matlab 5.3 does not support the use of multiple
 filters, in the filter_spec array.
 Matlab < 6.5 does not allow the passing of a seperate filename default
 as a third argument. 
 Matlab < 6.5 does not return a third argument (file index)

 mars_uifile acts as a wrapper for calls to uiputfile and uigetfile, so
 that 6.5 format calls will be translated to something useful to 5.3,
 6.1 if 5.3 or 6.1 is running.

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fn,pn,fi] = mars_uifile(action, filter_spec, prompt, filename, varargin)
0002 % wrapper for matlab uiputfile/getfile; to resolve version differences
0003 % FORMAT [fn,pn,fi] = mars_uifile(action, filter_spec, prompt, filename, varargin)
0004 %
0005 % uigetfile and uiputfile in matlab 5.3 does not support the use of multiple
0006 % filters, in the filter_spec array.
0007 % Matlab < 6.5 does not allow the passing of a seperate filename default
0008 % as a third argument.
0009 % Matlab < 6.5 does not return a third argument (file index)
0010 %
0011 % mars_uifile acts as a wrapper for calls to uiputfile and uigetfile, so
0012 % that 6.5 format calls will be translated to something useful to 5.3,
0013 % 6.1 if 5.3 or 6.1 is running.
0014 %
0015 % $Id$
0016   
0017 if nargin < 1
0018   error('Need action');
0019 end
0020 if nargin < 2
0021   filter_spec = '';
0022 end
0023 if nargin < 3
0024   prompt = '';
0025 end
0026 if nargin < 4
0027   filename = '';
0028 end
0029 if isnumeric(filename)
0030   varargin = [{filename} varargin];
0031   filename = '';
0032 end
0033   
0034 mlv = version; mlv = str2num(mlv(1:3));
0035 if mlv < 6.5 
0036   % If we have a default filename, we cannot use it with the filterspec,
0037   % so use filename instead of filterspec
0038   if ~isempty(filename) 
0039     filter_spec = filename;
0040   elseif mlv < 6 % only allowed string filterspec
0041     if iscell(filter_spec)
0042       filter_spec = filter_spec{1};
0043     end
0044     semic = find(filter_spec == ';');
0045     if ~isempty(semic)
0046       filter_spec(semic(1):end) = [];
0047     end
0048   end
0049   arglist = {filter_spec, prompt, varargin{:}};
0050 else % (so matlab >= 6.5)
0051   % It seems that, in the following setup:
0052   % matlab 7; Java interface; linux; cell array filterspec
0053   % - all uigetfile filters need to be of form '*.<ext>', where <ext> is
0054   % the file extension.  This is not so for the one version of matlab 7
0055   % on windows that I tested (matlab 7.1.0.253 or something).  I'm
0056   % guessing that other Unices may have the same problem though.
0057   if mlv >= 7 & usejava('jvm') & isunix
0058     for fsn = 1:size(filter_spec, 1)
0059       [pn fn ext] = fileparts(filter_spec{fsn, 1});
0060       filter_spec{fsn, 1} = ['*' ext];
0061     end
0062   end
0063     
0064   if isempty(filename) % matlab 7 does not tolerate empty filenames
0065     arglist = {filter_spec, prompt, varargin{:}};
0066   else
0067     arglist = {filter_spec, prompt, filename, varargin{:}};
0068   end
0069 end  
0070 
0071 fi = [];
0072 switch lower(action)
0073  case 'get'
0074   if mlv < 6.5
0075     [fn pn] = uigetfile(arglist{:});
0076   else
0077     [fn pn fi] = uigetfile(arglist{:});
0078   end
0079  case 'put'
0080   if mlv < 6.5
0081     [fn pn] = uiputfile(arglist{:});
0082   else
0083     [fn pn fi] = uiputfile(arglist{:});
0084   end
0085  otherwise 
0086    error(['Strange desire for ' action]);
0087 end

Generated on Thu 17-Mar-2016 01:14:46 by m2html © 2005