Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
matlab_airfoil_toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Pour rappel, le service sera inaccessible ce lundi 05/05/25 midi pour raison de mise à jour.
Show more breadcrumbs
Aerospace and Mechanical Engineering
matlab_airfoil_toolbox
Commits
9622fc96
Verified
Commit
9622fc96
authored
3 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
refactor(utils): improve cyclomatic complexity
parent
63645207
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
+af_tools/+utils/parsefileinputs.m
+48
-28
48 additions, 28 deletions
+af_tools/+utils/parsefileinputs.m
+af_tools/+utils/parsenacainputs.m
+30
-16
30 additions, 16 deletions
+af_tools/+utils/parsenacainputs.m
+af_tools/+utils/parsepolarinputs.m
+33
-25
33 additions, 25 deletions
+af_tools/+utils/parsepolarinputs.m
with
111 additions
and
69 deletions
+af_tools/+utils/parsefileinputs.m
+
48
−
28
View file @
9622fc96
function
[
filenames
,
filepath
s
,
idxOpts
]
=
parsefileinputs
(
optList
,
filetype
,
varargin
)
function
[
filenames
,
file
s
path
,
idxOpts
]
=
parsefileinputs
(
optList
,
filetype
,
varargin
)
% PARSEFILEINPUTS Parses the input and checks their validity.
% Returns the filenames and filepaths for the input files, as well as the index where the
% remaining options start.
...
...
@@ -37,7 +37,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va
if
hasNoInput
% Prompt user to select files
ext
=
[
'*'
,
filetype
];
[
filenames
,
filepath
s
]
=
uigetfile
(
ext
,
'Select all dat-files to aggregate'
,
...
[
filenames
,
file
s
path
]
=
uigetfile
(
ext
,
'Select all dat-files to aggregate'
,
...
'MultiSelect'
,
'on'
);
idxOpts
=
1
;
else
...
...
@@ -50,34 +50,14 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va
inputFiles
=
DEFAULT_INPUTFILES
;
end
% Validate inputDir
validateattributes
(
inputDir
,
{
'char'
,
'string'
},
{
'nonempty'
,
'vector'
},
...
mfilename
(),
'inputDir'
);
if
~
exist
(
inputDir
,
'dir'
)
error
(
'MATLAB:parsefileinputs:dirNotFound'
,
...
'The directory specified as inputDir (%s) can not be found!\n'
,
inputDir
);
end
% Validate inputFiles
validateattributes
(
inputFiles
,
{
'char'
,
'cell'
},
{
'nonempty'
,
'vector'
},
...
mfilename
(),
'inputFiles'
,
4
);
if
iscell
(
inputFiles
)
&&
~
iscellstr
(
inputFiles
)
error
(
'MATLAB:parsefileinputs:wrongInputFiles'
,
...
[
'If inpuFiles is given as a cell array, '
...
'it must contain only character vectors!\n'
]);
end
% Validate inputs
validateinputdir
(
inputDir
);
validateinputfiles
(
inputFiles
);
% ---------------------------------------
% Look for files
% Get absolute path
if
contains
(
inputDir
,
pwd
)
filepaths
=
inputDir
;
else
filepaths
=
fullfile
(
pwd
,
inputDir
);
end
filespath
=
absolutepath
(
inputDir
);
% Convert inputFiles to string for simpler handling
inputFiles
=
string
(
inputFiles
);
...
...
@@ -87,10 +67,10 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va
for
i
=
1
:
length
(
inputFiles
)
inputFiles
(
i
)
=
appendextension
(
inputFiles
(
i
),
filetype
);
% Add extension
dummy
=
dir
(
fullfile
(
filepath
s
,
inputFiles
(
i
)));
dummy
=
dir
(
fullfile
(
file
s
path
,
inputFiles
(
i
)));
if
isempty
(
dummy
)
warning
(
'MATLAB:parsefileinputs:FileNotFound'
,
...
'Could not find file %s.'
,
fullfile
(
filepath
s
,
inputFiles
(
i
)));
'Could not find file %s.'
,
fullfile
(
file
s
path
,
inputFiles
(
i
)));
end
AllFiles
=
[
AllFiles
;
dummy
];
end
...
...
@@ -119,3 +99,43 @@ function bool = isoption(optList, var)
bool
=
any
(
strcmpi
(
var
,
optList
));
end
end
% --------------------------------------------------------------------------------------------------
function
abspath
=
absolutepath
(
directory
)
% ABSOLUTEPATH Returns the absolute path to a directory
if
contains
(
directory
,
pwd
)
abspath
=
directory
;
else
abspath
=
fullfile
(
pwd
,
directory
);
end
end
% --------------------------------------------------------------------------------------------------
function
validateinputdir
(
inputDir
)
% VALIDATEDIR Validates inputDir input.
validateattributes
(
inputDir
,
{
'char'
,
'string'
},
{
'nonempty'
,
'vector'
},
...
mfilename
(),
'inputDir'
);
if
~
exist
(
inputDir
,
'dir'
)
error
(
'MATLAB:parsefileinputs:dirNotFound'
,
...
'The directory specified as inputDir (%s) can not be found!\n'
,
inputDir
);
end
end
% --------------------------------------------------------------------------------------------------
function
validateinputfiles
(
inputFiles
)
% VALIDATEDIR Validates inputDir input.
validateattributes
(
inputFiles
,
{
'char'
,
'cell'
},
{
'nonempty'
,
'vector'
},
...
mfilename
(),
'inputFiles'
,
4
);
if
iscell
(
inputFiles
)
&&
~
iscellstr
(
inputFiles
)
error
(
'MATLAB:parsefileinputs:wrongInputFiles'
,
...
[
'If inpuFiles is given as a cell array, '
...
'it must contain only character vectors!\n'
]);
end
end
This diff is collapsed.
Click to expand it.
+af_tools/+utils/parsenacainputs.m
+
30
−
16
View file @
9622fc96
...
...
@@ -51,16 +51,31 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
idxOpts
=
2
;
digits
=
varargin
{
1
};
if
length
(
varargin
)
>=
2
if
~
isoption
(
optList
,
varargin
{
2
})
idxOpts
=
3
;
nPoints
=
varargin
{
2
};
end
if
length
(
varargin
)
>=
2
&&
~
isoption
(
optList
,
varargin
{
2
})
idxOpts
=
3
;
nPoints
=
varargin
{
2
};
end
end
% Validate NACA digits input
% Validate inputs
validatedigits
(
digits
);
validatenpoints
(
nPoints
);
end
% --------------------------------------------------------------------------------------------------
function
bool
=
isoption
(
optList
,
var
)
% ISOPTION Returns true if var is contained in option list
bool
=
any
(
strcmpi
(
var
,
optList
));
end
% --------------------------------------------------------------------------------------------------
function
validatedigits
(
digits
)
% VALIDATEDIGITS Validates digit input.
% Correct type
validateattributes
(
digits
,
{
'char'
,
'string'
},
{
'scalartext'
},
mfilename
(),
'digits'
,
1
);
if
isstring
(
digits
)
digits
=
char
(
digits
);
...
...
@@ -69,13 +84,13 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
% Only accept NACA 4- or 5-digit
if
length
(
digits
)
<
4
||
length
(
digits
)
>
5
error
(
'MATLAB:parsenacainputs:wrongNumberOfDigits'
,
...
[
'nacacamber and nacaairfoil can only be used for NACA 4 or 5 digits airfoils.'
]
);
'nacacamber and nacaairfoil can only be used for NACA 4 or 5 digits airfoils.'
);
end
% Ensures the character vector only contains digits
if
~
all
(
isstrprop
(
digits
,
'digit'
))
error
(
'MATLAB:parsenacainputs:invalidDigits'
,
...
[
'The input (
''
%s
''
) does not correspond to a proper NACA airfoil.'
]
,
digits
);
'The input (
''
%s
''
) does not correspond to a proper NACA airfoil.'
,
digits
);
end
% Ensure the third number of a NACA-5 is either 0 or 1
...
...
@@ -87,9 +102,15 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
'(standard camber) or a 1 (reflex camber). Found %d'
],
q
);
end
end
end
% --------------------------------------------------------------------------------------------------
function
validatenpoints
(
nPoints
)
% VALIDATENPOINTS Validates nPoints input.
%
Validate nPoints input
%
Correct type
validateattributes
(
nPoints
,
{
'numeric'
},
{
'scalar'
,
'>='
,
2
},
mfilename
(),
'nPoints'
,
2
);
% Enough points to have a good result
if
nPoints
<=
10
warning
(
'MATLAB:parsenacainputs:lowNPoints'
,
...
[
'The number of points is very low (%d), '
...
...
...
@@ -97,10 +118,3 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
end
end
% --------------------------------------------------------------------------------------------------
function
bool
=
isoption
(
optList
,
var
)
% ISOPTION Returns true if var is contained in option list
bool
=
any
(
strcmpi
(
var
,
optList
));
end
This diff is collapsed.
Click to expand it.
+af_tools/+utils/parsepolarinputs.m
+
33
−
25
View file @
9622fc96
...
...
@@ -31,12 +31,6 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
% First ensures the option list is properly set
validateattributes
(
optList
,
{
'char'
,
'string'
,
'cell'
},
{},
mfilename
(),
'optList'
,
1
);
% Initialize outputs
alpha
=
[];
cl
=
[];
cd
=
[];
cm
=
[];
% Parse inputs
hasNoInput
=
isempty
(
varargin
)
||
isoption
(
optList
,
varargin
{
1
});
if
hasNoInput
...
...
@@ -54,19 +48,7 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
validateattributes
(
Polar
,
{
'struct'
},
{
'nonempty'
},
mfilename
(),
'Polar'
,
1
);
[
alpha
,
cl
,
cd
,
cm
]
=
extractpolar
(
varargin
{
1
});
else
% Parse user-provided arrays
if
length
(
varargin
)
>=
1
[
alpha
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
alpha
,
varargin
,
1
);
if
length
(
varargin
)
>=
2
&&
~
foundOpts
[
cl
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
cl
,
varargin
,
2
);
if
length
(
varargin
)
>=
3
&&
~
foundOpts
[
cd
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
cd
,
varargin
,
3
);
if
length
(
varargin
)
>=
4
&&
~
foundOpts
[
cm
,
idxOpts
,
~
]
=
assignvar
(
optList
,
cm
,
varargin
,
4
);
end
end
end
end
[
alpha
,
cl
,
cd
,
cm
,
idxOpts
]
=
parsearrays
(
optList
,
varargin
);
end
end
...
...
@@ -80,9 +62,9 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
validateattributes
(
alpha
,
{
'numeric'
},
{
'real'
,
'2d'
,
'nonempty'
,
'increasing'
},
...
mfilename
(),
'alpha'
,
1
);
check
array
(
cl
,
size
(
alpha
,
1
),
2
);
check
array
(
cd
,
size
(
alpha
,
1
),
3
);
check
array
(
cm
,
size
(
alpha
,
1
),
4
);
validate
array
(
cl
,
size
(
alpha
,
1
),
2
);
validate
array
(
cd
,
size
(
alpha
,
1
),
3
);
validate
array
(
cm
,
size
(
alpha
,
1
),
4
);
% Standardize alpha size so we have one column per Polar as well
if
size
(
alpha
,
2
)
==
1
&&
~
isempty
(
cl
)
...
...
@@ -109,9 +91,11 @@ function [alpha, cl, cd, cm] = extractpolar(Polar)
end
% --------------------------------------------------------------------------------------------------
function
[
var
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
var
,
data
,
idx
)
function
[
var
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
data
,
idx
)
% ASSIGNVAR Assign varargin value to a variable, ouptut corresponding idxOpts.
var
=
[];
foundOpts
=
false
;
if
~
isoption
(
optList
,
data
{
idx
})
idxOpts
=
idx
+
1
;
...
...
@@ -124,8 +108,32 @@ function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx)
end
% --------------------------------------------------------------------------------------------------
function
checkarray
(
array
,
nrows
,
idx
)
% CHECKARRAY Checks type and diemnsions of array.
function
[
alpha
,
cl
,
cd
,
cm
,
idxOpts
]
=
parsearrays
(
optList
,
data
)
% PARSEARRAYS Parse user-provided arrays.
alpha
=
[];
cl
=
[];
cd
=
[];
cm
=
[];
if
length
(
data
)
>=
1
[
alpha
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
data
,
1
);
if
length
(
data
)
>=
2
&&
~
foundOpts
[
cl
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
data
,
2
);
if
length
(
data
)
>=
3
&&
~
foundOpts
[
cd
,
idxOpts
,
foundOpts
]
=
assignvar
(
optList
,
data
,
3
);
if
length
(
data
)
>=
4
&&
~
foundOpts
[
cm
,
idxOpts
,
~
]
=
assignvar
(
optList
,
data
,
4
);
end
end
end
end
end
% --------------------------------------------------------------------------------------------------
function
validatearray
(
array
,
nrows
,
idx
)
% VALIDATEARRAY Checks type and diemnsions of array.
if
~
isempty
(
array
)
validateattributes
(
array
,
{
'numeric'
},
{
'real'
,
'nrows'
,
nrows
,
'nonempty'
},
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment