-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakeSectionwise.m
More file actions
70 lines (58 loc) · 2.06 KB
/
makeSectionwise.m
File metadata and controls
70 lines (58 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function filepath = makeSectionwise(facedata, coilname, savepath)
% filepath = coilpath_to_sectionwise(facedata, coilname, savepath)
%
% Takes data in facedata cell structure and writes contours to a
% comsol-readable sectionwise text file. Models can then import this file
% directly to their geometry, rather than loading each curve individually.
%
% ARR 2020.04.15
if ~exist('coilname','var') || isempty(coilname)
coilname = 'autosection.txt';
end
if ~exist('savepath','var') || isempty(savepath)
savepath = pwd;
end
coordinates = [];
elements = [];
for i=1:length(facedata)
% facedata{i} = {x,y,Vm,M,contours};
M = facedata{i}{4};
contours = facedata{i}{5};
for j = 1:length(contours)
for k=1:length(contours{j})
twocurve = contours{j}{k};
threecurve = affineRestore(twocurve(1,:),twocurve(2,:),M);
if isempty(coordinates)
coordinates = threecurve';
nstart = 0;
else
[nstart, ~] = size(coordinates);
coordinates = cat(1,coordinates,threecurve');
end
nstart = nstart+1;
[~,n] = size(threecurve);
latest = cat(1,(nstart):(nstart+n-2),(nstart+1):(nstart+n-1))';
if isempty(elements)
elements = latest;
else
elements = cat(1,elements,latest);
end
end
end
end
filepath = fullfile(savepath, coilname);
fileID = fopen(filepath,'wt');
fprintf(fileID, '%% Autogenerated Sectionwise Coil Path\n%%\n');
fprintf(fileID, '%% makeSectionwise.m by Austin Reid 2020-04-15\n%%\n');
fprintf(fileID, '%% Coordinates\n');
for i=1:(nstart+n-1)
fprintf(fileID,'%f %f %f\n',coordinates(i,:));
end
fprintf(fileID, '%% Elements (lines)\n');
[n,~] = size(elements);
for i=1:n
fprintf(fileID,'%d %d\n',elements(i,:));
end
%Other common conversion specifiers include '%d' for integers or '%s' for characters. fprintf reapplies the conversion information to cycle through all values of the input arrays in column order.
fclose(fileID);
end