


xxsimOpenModel - Opens a 20-sim model.
sets the opened 20-sim model as active model and assigns it unique identifier.
Syntax:
identifier = xxsimOpenModel(fileName, boolean)
Inputs:
fileName = directory path of the model to be opened .
Note: entering an empty string opens an empty 20-sim editor.
boolean = (optional) indicates if a new 20-sim editor should be opened.
true - opens model with a new editor.
false - opens model with an existing editor (Default).
Outputs:
identifier = opened 20-sim editors are assigned identifier value (1-based).
in case of error, 0 is returned.
Examples:
identifier = xxsimOpenModel('C:\temp\test.emx',true)
- opens model 'test.emx' with a new 20-sim editor.
See also: xxsimCloseModel
Author: Controllab Products B.V.
email: info@controllab.nl
Website: http://www.controllab.nl
September 2013

0001 function [identifier] = xxsimOpenModel(varargin) 0002 % xxsimOpenModel - Opens a 20-sim model. 0003 % sets the opened 20-sim model as active model and assigns it unique identifier. 0004 % 0005 % Syntax: 0006 % identifier = xxsimOpenModel(fileName, boolean) 0007 % 0008 % Inputs: 0009 % fileName = directory path of the model to be opened . 0010 % Note: entering an empty string opens an empty 20-sim editor. 0011 % 0012 % boolean = (optional) indicates if a new 20-sim editor should be opened. 0013 % true - opens model with a new editor. 0014 % false - opens model with an existing editor (Default). 0015 % 0016 % Outputs: 0017 % identifier = opened 20-sim editors are assigned identifier value (1-based). 0018 % in case of error, 0 is returned. 0019 % 0020 % Examples: 0021 % identifier = xxsimOpenModel('C:\temp\test.emx',true) 0022 % 0023 % - opens model 'test.emx' with a new 20-sim editor. 0024 % 0025 % See also: xxsimCloseModel 0026 % 0027 % Author: Controllab Products B.V. 0028 % email: info@controllab.nl 0029 % Website: http://www.controllab.nl 0030 % September 2013 0031 0032 %------------- BEGIN CODE -------------- 0033 %check input arguments 0034 if isempty(varargin) 0035 error('Not enough input arguments.'); 0036 elseif length(varargin)>2 0037 error('Too many input arguments.'); 0038 end 0039 0040 if ~ischar(varargin{1}) 0041 error('Input argument 1 should be a file name.'); 0042 else 0043 modelFilename = varargin{1}; 0044 end 0045 0046 if length(varargin) == 2 0047 if ~islogical(varargin{2}) 0048 error('Input argument 2 should be a boolean.'); 0049 end 0050 0051 newinstance = varargin{2}; 0052 else 0053 newinstance = false; 0054 end 0055 0056 % first set on 0 indicating wrong identifier 0057 identifier = 0; 0058 0059 % check if we already have a connection 0060 global xxsim; 0061 if (~exist('xrlisconnected','var')) || xrlisconnected() == 0 || isempty(xxsim) || isempty(xxsim.connections) 0062 xxsimConnect(); 0063 0064 % now a connection must have been made 0065 if xrlisconnected() == 0 0066 error('no connection to 20-sim could be made.'); 0067 end 0068 end 0069 0070 %check if the model file exists 0071 0072 if ~isempty(modelFilename) 0073 [status, result, msgid] = fileattrib(modelFilename); 0074 if status == 1 0075 % use the full resolved name, and we're done 0076 useFilename = fullfile(result.Name, ''); 0077 else 0078 % check if the user provided a full name 0079 [directory, name, extension] = fileparts(modelFilename); 0080 0081 % is an extension given? 0082 if isempty(extension) 0083 extension = '.emx'; 0084 end 0085 0086 % is a directory given? 0087 if isempty(directory) 0088 % use the current directory 0089 directory = pwd; 0090 end 0091 0092 useFilename = fullfile(directory, [name, extension]); 0093 end 0094 0095 0096 % again check if we have a valid name now 0097 if exist(useFilename, 'file') == 0 0098 error('%s does not exist.', modelFilename); 0099 end 0100 0101 if xxsim.verbose 0102 % do some verbose output 0103 fprintf('Opening file: %s\n', useFilename); 0104 end 0105 else 0106 useFilename = ''; 0107 end 0108 0109 try 0110 reply = xrlinvoke('xxsim.openModel', struct('name', useFilename, 'newinstance', newinstance )); 0111 if (isempty(reply) ) 0112 error('Could not load the model'); 0113 end 0114 if ~isempty(useFilename) 0115 if xxsim.verbose 0116 0117 % do some verbose output 0118 fprintf('Successfully opened file: %s\n', useFilename); 0119 0120 end 0121 end 0122 0123 % return the identifier 0124 identifier = reply.identifier; 0125 catch 0126 error('Could not load the model'); 0127 end 0128 0129 end 0130 %------------- END OF CODE --------------