Home > classes > @ssm > ssmFromBuiltinSystem.m

ssmFromBuiltinSystem

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function varargout = ssmFromBuiltinSystem(pli)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FUNCTION:    ssmFromBuiltinSystem

 DESCRIPTION: Construct a statespace model from one of the built-in
              systems.

 CALL:        see ssm

 PARAMETER:

 VERSION:     $Id: ssmFromBuiltinSystem.m,v 1.41 2008/09/04 13:37:15 ingo Exp $

 HISTORY:     15-04-2008 Hewitson
              Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0002 %
0003 % FUNCTION:    ssmFromBuiltinSystem
0004 %
0005 % DESCRIPTION: Construct a statespace model from one of the built-in
0006 %              systems.
0007 %
0008 % CALL:        see ssm
0009 %
0010 % PARAMETER:
0011 %
0012 % VERSION:     $Id: ssmFromBuiltinSystem.m,v 1.41 2008/09/04 13:37:15 ingo Exp $
0013 %
0014 % HISTORY:     15-04-2008 Hewitson
0015 %              Creation
0016 %
0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0018 function varargout = ssmFromBuiltinSystem(pli)
0019   
0020   VERSION = '$Id: ssmFromBuiltinSystem.m,v 1.41 2008/09/04 13:37:15 ingo Exp $';
0021   
0022   utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
0023 
0024   % get AO info
0025   ii = ssm.getInfo('ssm', 'From Built-in Model');
0026 
0027   % Set the method version string in the minfo object
0028   ii.setMversion([VERSION '-->' ii.mversion]);
0029 
0030   % Get default params
0031   pl = combine(pli, ii.plists);
0032 
0033   % Get the name of the model the user wants
0034   bsys = find(pl, 'Built-in');
0035   
0036   % Get a list of user model directories
0037   paths = getappdata(0, 'ltpda_ssm_model_paths');
0038   if ischar(paths)
0039     paths = {paths};
0040   end
0041   
0042   % Always look in the system directory
0043   loc = mfilename('fullpath');
0044   idx = strfind(loc, filesep);
0045   loc = loc(1:idx(end));
0046   loc = fullfile(loc, '../../m/ssm_models');
0047   paths = [paths {loc}];
0048   
0049   for jj=1:numel(paths)
0050     utils.helper.msg(utils.const.msg.PROC1, 'looking for models in %s', paths{jj});
0051   end
0052   
0053   % list files in here
0054   models = {};
0055   for pp = 1:numel(paths)
0056     files = utils.prog.filescan(paths{pp}, '.m');
0057     for ff = 1:numel(files)
0058       [path, mname, ext, vers] = fileparts(files{ff});
0059       if strncmp(mname, 'ssm_model_', 10)
0060         models = [models {strrep(mname, 'ssm_model_', '')}];
0061       end
0062     end
0063   end
0064   
0065   % Give a list and an error if bsys is empty
0066   if isempty(bsys)
0067     for k=1:numel(models)
0068       disp(sprintf('%03d: %s', k, models{k}));
0069     end
0070     error('### No model specified. Please choose one from the list above.');
0071   end
0072   
0073   % Find the matching model
0074   sys = [];
0075   if any(strcmp(models, bsys)) || (isnumeric(bsys) && bsys <= numel(models))
0076     if isnumeric(bsys)
0077       fcnname = ['ssm_model_' models{bsys}];
0078     else
0079       fcnname = ['ssm_model_' bsys];
0080     end
0081     [sys pl_dim_red] = feval(fcnname, pl);
0082     sys.version = ii.mversion;
0083     sys.created = time(0);
0084     sys.creator = provenance();
0085     sys.hist    = history(time().utc_epoch_milli, ii, pl, [], []);
0086     
0087     % Convert to SSM object
0088     sys = ssm(sys);
0089     sys.reduce_model(pl_dim_red)
0090     
0091   else
0092     for k=1:numel(models)
0093       disp(sprintf('%03d: %s', k, models{k}));
0094     end
0095     error('### Model not found. Please choose one from the above list.');
0096   end
0097     
0098   % Set output
0099   varargout{1} = sys;
0100   
0101 end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003