Using version control keyword substitution in Simulink mdl files

2 views (last 30 days)
Many version control systems contain features that automatically populate the checked out file with information such as revision history, file name, file revision number etc.
I am looking for a way of incorporating this information into a simulink mdl file.
The version control system will be looking for a particular string pattern which it will overwrite with the rev history etc on a checkout.
How can I incorporate these special strings into the mdl file that makes them visible in the Simulink GUI?
I have tried editing the description of a subsystem and adding the keywords but Simulink ended up encoding this into the mdl file as follows:
Block {
BlockType SubSystem
Name "Atomic Subsystem"
SID "1"
Description "Copywrite stuff.... \n \n%PCMS_HEADER_SUBSTITUTION"
"_START%\nName: \n%PID% \n%PCMS_HEADER_SUBSTITUTION_END% "
The version control software wants it to be formatted something like this:
%PCMS_HEADER_SUBSTITUTION% Name: %PID% %PCMS_HEADER_SUBSTITUTION_END%
Any ideas?

Answers (1)

Daniel Shub
Daniel Shub on 14 Dec 2011

I don't use simulink and I am not familiar with the formatting of your version control system's keyword... In regular MATLAB with unexpanded keywords looking like $unexpanded keyword$" and expanded keywords looking like $expanded keyword: value$, you could define a function like:

function [keyword, value] = rckeyword(str)
  if ~isempty(strfind(str, ': '))
    keyword = str(2:(strfind(str, ': ')-1));
    value = str((strfind(str, ': ')+2):(end-1));
	else
    keyword = str(2:(end-1));
    value = '';
  end
end

Then in your version controlled m files include:

[keyword1, value1] = rckeyword('$Expanded Keyword: hello world$')
[keyword2, value2] = rckeyword('$Unexpanded Keyword$')

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!