diff --git a/autoMatricesProtub/mainAutoMatProtub.m b/autoMatricesProtub/mainAutoMatProtub.m index cf618b4339dd0c62d9bb01565a1b4bc87a2d5481..07e6db7ecabb3341c8768c08e0226fa1aec69001 100644 --- a/autoMatricesProtub/mainAutoMatProtub.m +++ b/autoMatricesProtub/mainAutoMatProtub.m @@ -1,4 +1,4 @@ -function [coeffsTot, coeffsTotHighAOA] = mainAutoMatProtub(rocket, environment, settings, options) +function [coeffsOut, coeffsOutHighAOA] = mainAutoMatProtub(rocket, environment, settings, options) arguments rocket = []; % Empty by default environment Environment = Environment.empty @@ -98,12 +98,13 @@ input = createDissileInput(rocket, autoMatSettings.vars); [coeffsTot, finsCN] = dissileMatcom(input); %% SAVE DATA -if options.saveVars - saveVars(autoMatSettings.varsHighAOA, rocket, mission, coeffsTotHighAOA, finsCNHighAOA, ... - chosenXcg, autoMatSettings.saveFinsCN, 'aeroCoefficientsHighAOA.mat'); - saveVars(autoMatSettings.vars, rocket, mission, coeffsTot, finsCN, ... - chosenXcg, autoMatSettings.saveFinsCN, 'aeroCoefficients.mat'); -end + +coeffsOut = exportVars( ... + autoMatSettings.varsHighAOA, rocket, mission, coeffsTotHighAOA, finsCNHighAOA, chosenXcg, ... + autoMatSettings.saveFinsCN, options.saveVars, 'aeroCoefficientsHighAOA.mat'); +coeffsOutHighAOA = exportVars( ... + autoMatSettings.vars, rocket, mission, coeffsTot, finsCN, chosenXcg, ... + autoMatSettings.saveFinsCN, options.saveVars, 'aeroCoefficients.mat'); AMtime = toc; fprintf('Aerodynamics Prediction completed \n') diff --git a/autoMatricesProtub/src/saveVars.m b/autoMatricesProtub/src/exportVars.m similarity index 69% rename from autoMatricesProtub/src/saveVars.m rename to autoMatricesProtub/src/exportVars.m index 3681975c383587d1ddd319e270e66315ff765d89..9a388e39af36eaa106709329b5b434d95291e60e 100644 --- a/autoMatricesProtub/src/saveVars.m +++ b/autoMatricesProtub/src/exportVars.m @@ -1,4 +1,5 @@ -function saveVars(vars, rocket, mission, total, finsCN, chosenXcg, saveFinsCN, outputName) +function coeffs = exportVars(vars, rocket, mission, total, finsCN, chosenXcg, ... + saveFinsCN, saveToFile, outputName) arguments vars @@ -8,6 +9,7 @@ arguments finsCN chosenXcg saveFinsCN + saveToFile outputName end @@ -40,36 +42,48 @@ if strcmp(rocket.parafoil.noseType,'MHAACK') geometry.cMod = rocket.parafoil.noseCMod; geometry.pMod = rocket.parafoil.nosePMod; else - error('parafoil.pMod and/or parafoil.cMod are not defined; check simulationsData') + error('parafoil.pMod and/or parafoil.cMod are not defined; check rocketConfig') end end geometry.xcg = chosenXcg; + %% CREATING OUTPUT outputPath = fullfile(mission.dataPath, outputName); -output = struct(); - -if ~isfile(outputPath) - save(outputPath, '-struct', 'output') -else - save(outputPath, '-struct', 'output', '-append') -end if rocket.dynamicDerivatives, fieldName = rocket.motor.name; else, fieldName = 'generic'; end -output.(fieldName) = struct(); -output.(fieldName).state = state; -output.(fieldName).total = total; -output.(fieldName).geometry = geometry; -output.(fieldName).finsCN = []; - if saveFinsCN finsCN = squeeze(finsCN(1, :, :, :, :, :)); % Consider only the first xcg bc fins CN is xcg-independent - output.(fieldName).finsCN = finsCN; +else + finsCN = []; end -save(outputPath, '-struct', 'output', '-append') +coeffs = Coefficient(); +coeffs.state = state; +coeffs.total = total; +coeffs.geometry = geometry; +coeffs.finsCN = finsCN; + +if saveToFile + % Save files as struct to allow exporting + output = struct(); + + if ~isfile(outputPath) + save(outputPath, '-struct', 'output') + else + save(outputPath, '-struct', 'output', '-append') + end + + output.(fieldName) = struct(); + output.(fieldName).state = state; + output.(fieldName).total = total; + output.(fieldName).geometry = geometry; + output.(fieldName).finsCN = finsCN; + + save(outputPath, '-struct', 'output', '-append'); +end end \ No newline at end of file