📄 make_mc9s12orig.m
字号:
% arr1(1).a = 'a';
% arr1(1).b = 'b';
% arr1(1).c = 'c';
% arr1(2).a = 'a2';
% arr1(2).b = 'b2';
% arr1(2).c = 'c2';
%
% arr2(1).d = 'a2';
% arr2(1).e = 'e';
% arr2(1).f = 'f';
% arr2(2).d = 'a';
% arr2(2).e = 'e2';
% arr2(2).f = 'f2';
% RTWStuffArray(arr1, arr2, {'a', 'd'}, {'b', 'e'})
% would result in
% arr1(1).a,b,c = {'a', 'e2', 'c'}
% arr1(2).a,b,c = {'a2', 'e', 'c2'}
%
% This function extends RTWStuffArray in the following way:
% LocRTWStuffArray(array1, array2, {primary_key, secondary_key}, ...
% {field1, field1a, mapfcn1}, {field2, field2a, mapfcn2}, ...)
% results in the following:
% All cases where array1(i).primary_key == array2(j).secondary_key,
% array1(i).field1 <-- mapfcn1(array1(i), array2(j), array2(j).field1a)
% array1(i).field2 <-- mapfcn2(array1(i), array2(j), array2(j).field2a)
if nargin < 4
error(['Need at least three arguments: Primary Array, Secondary' ...
' Array, Key Fields, and Secondary Fields']);
end
array1 = varargin{1};
array2 = varargin{2};
% Not sure about the following behavior for empty arrays. May need to
% change it.
if (isempty(array1))
output = array1;
return;
elseif (isempty(array2))
output = array2;
return;
end
if (~(isstruct(array1) & isstruct(array2)))
error(['Both the primary and secondary arrays must be struct arrays']);
end
keyPair = varargin{3};
if (~(iscell(keyPair) & (length(keyPair) == 2)))
error(['The key fields must be a cell struct with two elements']);
end
primaryKey = keyPair{1};
secondaryKey = keyPair{2};
if (~isfield(array1, char(primaryKey)))
error('%s', [primaryKey ' is not a field in the primary array.']);
elseif (~isfield(array2, char(secondaryKey)))
error('%s', [secondaryKey ' is not a field in the secondary array.']);
end
% Do some more error checking.
for k = 4:length(varargin)
fieldPair = varargin{k};
if (isequal(fieldPair{1}, primaryKey))
error('%s', ['A field being replaced,' fieldPair{1}, ' has the same name', ...
' as the primary key field, ' primaryKey '.']);
elseif (isequal(fieldPair{2}, secondaryKey))
error('%s', ['A field being used for replacement,' fieldPair{2}, ' has', ...
' the same name as the primary key field, ' secondaryKey '.']);
end
end
for k = 1:length(array1)
key1val = getfield(array1(k), primaryKey);
for l = 1:length(array2)
key2val = getfield(array2(l), secondaryKey);
if ~(isequal(key1val, key2val)) continue; end
for j = 4:length(varargin)
fieldPair = varargin{j};
field1 = fieldPair{1};
field2 = fieldPair{2};
if ( ~isfield(array1(k), field1) | ~isfield(array2(l), field2) )
continue;
end
mapFcn = fieldPair{3};
value2 = getfield(array2(l), field2);
if isempty(mapFcn),
value1 = value2;
else
value1 = feval(mapFcn, array1(k), array2(l), char(value2));
end
array1(k) = setfield(array1(k), field1, value1);
end
array2(l) = '';
break;
end
end
output = array1;
%endfunction LocRTWStuffArray
% Function: LocMapFcn ==========================================================
%
function output = LocMapFcn(record1, record2, value)
% LocMapFcn - Maps the value of a record of type rtwoption to its
% equivalent for an optionarray. See beginning of this file for
% descriptions of "rtwoption" and "optionarray".
if (isfield(record1,'type') & ~isempty(record1.type))
switch(record1.type)
case 'Popup'
% Strip all quotation marks from the value fields (presumably inserted
% for a popup)
output = strrep(value, '"', '');
return;
case 'Checkbox'
if (isequal(value,'1'))
output = 'on';
else
output = 'off';
end
otherwise
output = value;
end
else
output = value;
end
%endfunction LocMapFcn
% Function: CleanupForExit =====================================================
% Abstract:
% - Restore state of the lock and dirty flags
% - Restore working directory
% - Leave the attic clean
function CleanupForExit(startDirToRestore, hMdl, origLockFlag,...
origDirtyFlag,origStartTime,rtwCodeReuseSetting)
if ~isempty(startDirToRestore)
cd(startDirToRestore);
end
CleanupDirtyFlag(hMdl,origDirtyFlag)
lockFlag = get_param(hMdl, 'Lock');
if ~strcmp(lockFlag, origLockFlag),
set_param(hMdl,'Lock',origLockFlag);
end
if ~strcmp(get_param(hMdl, 'StartTime'), origStartTime)
% restore original start time
set_param(hMdl, 'StartTime', origStartTime);
end
% restore RTWCodeReuse flag
feature('RTWCodeReuse',rtwCodeReuseSetting);
rtwattic('clean');
%endfunction CleanupForExit
% Function: CleanupDirtyFlag
% Abstract:
% Restore the state of the dirty flag
%
function CleanupDirtyFlag(hMdl,origDirtyFlag)
dirtyFlag = get_param(hMdl, 'Dirty');
if ~strcmp(dirtyFlag, origDirtyFlag),
set_param(hMdl,'Dirty',origDirtyFlag);
end
%endfunction CleanupDirtyFlag
% Function: LocGetTMF ========================================================
% Abstract:
% Get the template makefile to be used by the build process
%
function [templateMakefile,compilerEnvVal] = LocGetTMF(hModel,rtwroot,...
languageDir,adaEnvVar)
templateMakefile = deblank(get_param(hModel,'RTWTemplateMakefile'));
templateMakefile = fliplr(deblank(fliplr(templateMakefile)));
if isempty(templateMakefile)
error('No template makefile specified');
end
compilerEnvVal = ''; % assume
if ~any(find(templateMakefile=='.'))
if ~exist([templateMakefile,'.m'],'file')
error('Invalid template makefile specified');
end
% No extension, so assume MATLAB command which returns the template
% makefile
if nargout(templateMakefile) == 2
[templateMakefile,compilerEnvVal] = feval(templateMakefile);
else
templateMakefile = feval(templateMakefile);
end
end
if exist(templateMakefile) ~= 2
[file]=LocGetTMFFromRTWRoot(rtwroot, languageDir, templateMakefile);
if ~isempty(file)
templateMakefile = file;
else
error('%s', ['Unable to locate template makefile: ',templateMakefile]);
end
else
templateMakefile = which(templateMakefile);
end
if ~isempty(adaEnvVar)
%
% Over-ride compilerEnvVal if specified in buildArgs for Ada
%
compilerEnvVal = ['GNAT_VER=',adaEnvVar,';'];
end
%endfunction LocGetTMF
% Function: LocGetTMFFromRTWRoot ===============================================
% Abstract:
% Search in <rtwroot>/<langDir>/<targetDirs> for template makefile
%
function [fileOut,targetDirOut] = LocGetTMFFromRTWRoot(rtwroot,langDir, fileIn)
fileOut = [];
targetDirOut = [];
targetDirs = dir(fullfile(rtwroot, langDir));
for i=1:length(targetDirs)
if targetDirs(i).isdir
targetDir = targetDirs(i).name;
if ~strcmp(targetDir,'.') & ...
~strcmp(targetDir,'..') & ...
~strcmp(targetDir,'src') & ...
~strcmp(targetDir,'libsrc') & ...
~strcmp(targetDir,'lib') & ...
~strcmp(targetDir,'tlc')
file = fullfile(rtwroot, langDir, targetDir, fileIn);
if exist(file) == 2
fileOut = file;
targetDirOut = targetDir;
break;
end
end
end
end
%endfunction LocGetTMFFromRTWRoot
% Function: LocalFindStr =======================================================
% Abstract:
% Make findstr more robust by requiring that s1 >= s2 in length.
% This is because findstr find the smaller of the two. If s1 is
% a space ' ', findstr will return true, but this routine won't.
function found = LocalFindStr(s1,s2)
found = (length(s1) >= length(s2) & ~isempty(findstr(s1,s2)));
%endfunction LocalFindStr
% Function: ParseBuildArgs =====================================================
% Abstract:
% Parse the build arguments passed into make_rtw
%
function [modelName,initRTWOptsAndGenSettingsOnly, ...
languageDir,adaEnvVar,buildArgs] = ParseBuildArgs(buildArgs)
initRTWOptsAndGenSettingsOnly = 0;
% Get the model name and handle. Pluck:
% mdl:modelName => Build
% or
% ini:modelName => Initialize RTWOptions and RTWGenSettings, then exit.
%
if length(buildArgs) > 4 & ...
(all(buildArgs(1:4)=='mdl:') | all(buildArgs(1:4)=='ini:'))
if all(buildArgs(1:4)=='ini:')
initRTWOptsAndGenSettingsOnly = 1;
end
sp = findstr(buildArgs,' ');
if ~isempty(sp)
modelName = buildArgs(5:sp(1)-1);
buildArgs(1:sp(1)) = [];
else
modelName = buildArgs(5:end);
buildArgs = '';
end
else
modelName = bdroot;
end %if
if isempty(modelName)
error('Unable to obtain current model name.');
end %if
adaEnvVar = '';
% When needed, add Language to dialog box
% Check to see if Ada language was specified in make command (-ada switch)
if (~isempty(findstr(get_param(modelName,'RTWMakeCommand'), '-ada')))
adaRequested = 1;
% Identify form '-ada' or '-ada=gnat3.xx'
adaGnat = 0;
firstAda = findstr('-ada', buildArgs);
if length(buildArgs) > 4
firstAdaGnat = findstr('-ada=gnat',buildArgs);
if ~isempty(firstAdaGnat)
if firstAdaGnat == firstAda
adaGnat = 5;
end
end
end
% Strip out '-ada' or '-ada=gnat' from make command line
buildArgs(firstAda:firstAda+adaGnat+3) = '';
% If using the '-ada=gnat3.xx' form, strip out the GNAT version number
% from the make command line and store it in variable 'adaEnvVar'
if adaGnat
firstSpace = findstr(' ',buildArgs);
if isempty(firstSpace)
adaEnvVar=buildArgs;
buildArgs(1:length(buildArgs))='';
else
firstSpace=firstSpace-1;
adaEnvVar=buildArgs(1:firstSpace);
buildArgs(1:firstSpace)='';
end
end
if ~strcmp(get_param(0,'RTWAdaLicensed'),'on')
error('You are not licensed for the Real-Time Workshop Ada Target');
end
else
adaRequested = 0;
end %if
if adaRequested
languageDir = 'ada';
else
languageDir = 'c';
end %if
% Function: tdisplay_caller_info ===============================================
% Check the m-file's caller's name
%
function callerName = tdisplay_caller_info(headerStr)
[dbStackInfo,dbLineInfo] = dbstack;
if(length(dbStackInfo)>2)
callerName = strip_name(dbStackInfo(3).name);
else
callerName = ''; %make_rtw invoked from cmd line
end
function name = strip_name(name)
idx = find(name==filesep);
if(~isempty(idx))
name = name(max(idx)+1:end);
end
%[eof] make_rtw.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -