xxsimGenerateXMLCode

PURPOSE ^

xxsimGenerateXMLCode - Generate XML for the active model using the specified XML target template

SYNOPSIS ^

function [result, warnings, errors] = xxsimGenerateXMLCode(varargin)

DESCRIPTION ^

 xxsimGenerateXMLCode - Generate XML for the active model using the specified XML target template

 Syntax: 
   [result, warnings, errors] = xxsimGenerateXMLCode(targetName, outputDirectory, submodelName, templateDirectory)
   result = xxsimGenerateXMLCode(targetName, outputDirectory)

 Inputs:
   targetName   = the name of the target to generate XML for
   outputDirectory = the output directory for the generated XML
   submodelName = (optional) the name of the submodel to generate XML for.
                   Only necessary for targets that need a submodel selection
   templateDirectory = (optional) the directory where the code generation template is stored
                       When omitted, 20-sim used the default 'Documentation' folder instead.

 Output:
   result  = returns true if the XML generation was successful
   warnings = warning(s) during XML generation if any
   errors  = error(s) during XML generation if any

 See also: xxsimGenerateCCode, xxsimGenerateMatlabCode

 Author: Controllab Products B.V
 email: info@controllab.nl
 Website: http://www.controllab.nl
 October 2014

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [result, warnings, errors] = xxsimGenerateXMLCode(varargin)
0002 % xxsimGenerateXMLCode - Generate XML for the active model using the specified XML target template
0003 %
0004 % Syntax:
0005 %   [result, warnings, errors] = xxsimGenerateXMLCode(targetName, outputDirectory, submodelName, templateDirectory)
0006 %   result = xxsimGenerateXMLCode(targetName, outputDirectory)
0007 %
0008 % Inputs:
0009 %   targetName   = the name of the target to generate XML for
0010 %   outputDirectory = the output directory for the generated XML
0011 %   submodelName = (optional) the name of the submodel to generate XML for.
0012 %                   Only necessary for targets that need a submodel selection
0013 %   templateDirectory = (optional) the directory where the code generation template is stored
0014 %                       When omitted, 20-sim used the default 'Documentation' folder instead.
0015 %
0016 % Output:
0017 %   result  = returns true if the XML generation was successful
0018 %   warnings = warning(s) during XML generation if any
0019 %   errors  = error(s) during XML generation if any
0020 %
0021 % See also: xxsimGenerateCCode, xxsimGenerateMatlabCode
0022 %
0023 % Author: Controllab Products B.V
0024 % email: info@controllab.nl
0025 % Website: http://www.controllab.nl
0026 % October 2014
0027 
0028 %------------- BEGIN CODE --------------
0029     global xxsim;
0030     xxsimVerbose = 0;
0031     if exist('xxsim')
0032         xxsimVerbose = xxsim.verbose;
0033     end
0034 
0035     submodelName = '';
0036     if length(varargin)> 4
0037         error('Too many input arguments.');
0038     end
0039     if length(varargin)< 2
0040         error('Too few input arguments.');
0041     end
0042     
0043     % first argument must hold target information
0044     if ~ischar(varargin{1})
0045     
0046         if isnumeric(varargin{1})
0047             targetIndex = varargin{1};
0048             
0049             % get a list of XML targets, to determine the index
0050             targets = xxsimGetCCodeTargets();
0051             
0052             if length(targets) < targetIndex 
0053                 error('Wrong target index given');
0054             end
0055             
0056             % and set the name of this target
0057             targetName = targets(targetIndex).name;
0058 
0059         else
0060             error('target name must be a string');
0061         end
0062     else
0063         targetName = varargin{1};
0064     end
0065 
0066     if length(varargin)>=2
0067         if ~ischar(varargin{2})
0068             error('output directory must be a string');
0069         end
0070         outputDirectory = varargin{2};
0071     end
0072 
0073     if length(varargin)>=3
0074         if ~ischar(varargin{3})
0075             error('submodel name must be a string');
0076         end
0077         submodelName = varargin{3};
0078     else
0079         submodelName = '';
0080     end
0081     
0082     if length(varargin)>=4
0083         if ~ischar(varargin{4})
0084             error('templateDirectory must be a string');
0085         end
0086         templateDirectory = varargin{4};
0087     else
0088         templateDirectory = '';
0089     end
0090 
0091     if( xxsimVerbose )
0092         fprintf('Generating XML for : ');
0093     end
0094 
0095   args = struct('targetName', targetName, 'outputDirectory', outputDirectory, 'submodelName', submodelName, 'templateDirectory', templateDirectory);
0096     codeGenResult = xrlinvoke('xxsim.simulator.generateXMLCode', args);
0097     if( isfield(codeGenResult, 'errors') && length(codeGenResult.errors) ~= 0 )
0098         result = 0;
0099     else
0100         result = 1;
0101     end
0102     
0103     % check if the code generation itself returned an error
0104     if result ~= 0
0105         if isfield(codeGenResult, 'result')
0106             result = codeGenResult.result;
0107         else
0108             result = false;
0109         end
0110     end
0111     
0112     %optionally return the outputs as the third variable
0113     if isfield(codeGenResult, 'warnings')
0114         warnings = codeGenResult.warnings;
0115     else
0116         warnings = [];
0117     end
0118     
0119     if isfield(codeGenResult, 'errors')
0120         errors = codeGenResult.errors;
0121     else
0122         errors = [];
0123     end
0124     
0125     if( xxsimVerbose )
0126         if( result )
0127             fprintf('Success\n');
0128         else
0129             fprintf('Failure\n');
0130         end
0131 
0132         % print the errors and warnings
0133         for i = 1:length(codeGenResult.errors)
0134             fprintf('\tError: %s\n',codeGenResult.errors{i});
0135         end
0136         for i = 1:length(codeGenResult.warnings)
0137             fprintf('\tWarning: %s\n', codeGenResult.warnings{i});
0138         end
0139         fprintf('\Code generation: %d error(s), %d warning(s)\n', length(codeGenResult.errors), length(codeGenResult.warnings));
0140     end
0141 end
0142 %------------- END CODE --------------

Generated on Sun 10-Dec-2017 19:24:51