diff --git a/algos/template/duplicate_template.m b/algos/template/duplicate_template.m new file mode 100644 index 0000000000000000000000000000000000000000..7b021c85148b8ec2b2f8872b76c9f9816d48b23c --- /dev/null +++ b/algos/template/duplicate_template.m @@ -0,0 +1,70 @@ +function [] = duplicate_template(name) + +startpath=pwd; +fcnpath=fileparts(mfilename('fullpath')); +algopath=strcat(fcnpath,'/../',name); + +fprintf('Creating folder %s\n',algopath); +system(sprintf('mkdir -p %s',algopath)); + +fprintf('Copying files ...\n'); +filelist={... + 'algo_template.slx',... + 'algo_template_harness.slx',... + 'algo_template_harness_run.m',... + 'algo_template_test.m',... + 'algo_template_loadtp.m',... + 'algo_template_loadfp.m',... + 'algo_template_signal_buses.m',... + 'algo_template_outBus_def.m',... + 'algo_template_inBus_def.m',... + 'algoobj_template.m',... + }; +for i=1:numel(filelist) + cpcmd=sprintf('cp -vf %s/%s %s/%s',fcnpath,filelist{i},algopath,strrep(filelist{i},'template',name)); + system(cpcmd); +end + +eval(sprintf('cd %s',algopath)); + +fprintf('Changing models data dictionary ...\n'); +modellist={... + 'algo_template',... + 'algo_template_harness',... + }; +ddname=sprintf('algo_%s.sldd',name); +for i=1:numel(modellist) + modelname=strrep(modellist{i},'template',name); + load_system(modelname); + set_param(modelname, 'DataDictionary', ddname); + save_system(modelname); + close_system(modelname); +end + +fprintf('Changing block diagrams properties ...\n'); +list={{'algo_template/realtime' ,'SampleTime'}, ... + {'algo_template/signal_in' ,'OutDataTypeStr'}, ... + {'algo_template/signal_out' ,'OutDataTypeStr'}, ... + {'algo_template/Gain' ,'Gain'}, ... + }; +load_system(['algo_' name]); +for i=1:numel(list) + parobj=strrep(list{i}{1},'template',name); + oldvalue = get_param(parobj,list{i}{2}); + newvalue = strrep(oldvalue,'template',name); + fprintf('changing %s,%s %s->%s\n', parobj,list{i}{2},oldvalue,newvalue); + set_param(parobj,list{i}{2},newvalue); +end +save_system(['algo_' name]); + +fprintf('Renaming ''template'' to ''%s'' inside .m files ...\n',name); +rncmd=sprintf('cd %s; sed -i ''s/template/%s/g'' *.m', algopath, name); +system(rncmd); + + +eval(sprintf('cd %s',startpath)); + + + + +end