1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Patch from Kenn to speed up matlab parsing by preallocating arrays

This commit is contained in:
James Cotton 2011-12-16 15:26:56 -06:00
parent b56c11d1d9
commit 99201d152a
3 changed files with 27 additions and 1 deletions

View File

@ -3,6 +3,17 @@ function [] = OPLogConvert(logfile)
% THIS FILE IS AUTOMATICALLY GENERATED.
$(ALLOCATIONCODE)
if nargin==0
%%
if (exist('uigetfile'))
[FileName, PathName]=uigetfile;
logfile=fullfile(PathName, FileName);
else
error('Your technical computing program does not support file choosers. Please input the file name in the argument. ')
end
end
fid = fopen(logfile);
% Parse log file, entry by entry
@ -46,6 +57,9 @@ end
%% Clean Up and Save mat file
fclose(fid);
% Trim output structs
$(CLEANUPCODE)
matfile = strrep(logfile,'opl','mat');
save(matfile $(SAVEOBJECTSCODE));

View File

@ -51,6 +51,7 @@ bool UAVObjectGeneratorMatlab::generate(UAVObjectParser* parser,QString template
matlabCodeTemplate.replace( QString("$(ALLOCATIONCODE)"), matlabAllocationCode);
matlabCodeTemplate.replace( QString("$(SWITCHCODE)"), matlabSwitchCode);
matlabCodeTemplate.replace( QString("$(CLEANUPCODE)"), matlabCleanupCode);
matlabCodeTemplate.replace( QString("$(SAVEOBJECTSCODE)"), matlabSaveObjectsCode);
matlabCodeTemplate.replace( QString("$(FUNCTIONSCODE)"), matlabFunctionsCode);
@ -127,6 +128,16 @@ bool UAVObjectGeneratorMatlab::process_object(ObjectInfo* info)
matlabSwitchCode.append("\t\tcase " + objectTableName.toUpper() + "_OBJID\n");
matlabSwitchCode.append("\t\t\t" + objectTableName + "(" + tableIdxName +") = " + functionCall + ";\n");
matlabSwitchCode.append("\t\t\t" + tableIdxName + " = " + tableIdxName +" + 1;\n");
matlabSwitchCode.append("\t\t\tif " + tableIdxName + " > length(" + objectTableName +")\n");
matlabSwitchCode.append("\t\t\t\t" + objectTableName + "(" + tableIdxName + "+100+1) = " + objectTableName +"(end);\n");
matlabSwitchCode.append("\t\t\t\t" + objectTableName +"(end)=[];\n");
matlabSwitchCode.append("\t\t\tend\n");
//=============================================================//
// Generate 'Cleanup:' code (will replace the $(CLEANUP) tag) //
//=============================================================//
matlabCleanupCode.append(objectTableName + "(" + tableIdxName +":end) = [];\n");
//=============================================================================//

View File

@ -38,6 +38,7 @@ private:
bool process_object(ObjectInfo* info);
QString matlabAllocationCode;
QString matlabSwitchCode;
QString matlabCleanupCode;
QString matlabSaveObjectsCode;
QString matlabFunctionsCode;
QStringList fieldTypeStrMatlab;