From 99201d152a69da24bf585426af79ee0b96d342f3 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Fri, 16 Dec 2011 15:26:56 -0600 Subject: [PATCH] Patch from Kenn to speed up matlab parsing by preallocating arrays --- .../src/plugins/uavobjects/uavobjecttemplate.m | 14 ++++++++++++++ .../generators/matlab/uavobjectgeneratormatlab.cpp | 13 ++++++++++++- .../generators/matlab/uavobjectgeneratormatlab.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjecttemplate.m b/ground/openpilotgcs/src/plugins/uavobjects/uavobjecttemplate.m index f9a9e5dd3..5cfcb6068 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjecttemplate.m +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjecttemplate.m @@ -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)); diff --git a/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.cpp b/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.cpp index 5b45f482e..a7479cc77 100644 --- a/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.cpp +++ b/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.cpp @@ -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,7 +128,17 @@ 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"); + //=============================================================================// // Generate objects saving code code (will replace the $(SAVEOBJECTSCODE) tag) // diff --git a/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.h b/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.h index 9a060bf41..b86b001a5 100644 --- a/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.h +++ b/ground/uavobjgenerator/generators/matlab/uavobjectgeneratormatlab.h @@ -38,6 +38,7 @@ private: bool process_object(ObjectInfo* info); QString matlabAllocationCode; QString matlabSwitchCode; + QString matlabCleanupCode; QString matlabSaveObjectsCode; QString matlabFunctionsCode; QStringList fieldTypeStrMatlab;