Skip to content

Commit

Permalink
streamlined subsref methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgri committed Nov 7, 2016
1 parent 019ab4c commit 93eacb0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
22 changes: 5 additions & 17 deletions Basic/@gds_library/subsref.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@

% convert cs-lists --> cell arrays
itype = {ins.type};
isubs = flatten({ins.subs});
isubs = {ins.subs};

% first indexing operator
switch itype{1}

case '()'

idx = isubs{1};
if iscell(idx)
idx = idx{1};
end

if ischar(idx) && idx == ':'
gstrs = glib.st(1:end);
gstrs = glib.st;
elseif length(idx) == 1 % return one structure
gstrs = glib.st{idx};
else
Expand Down Expand Up @@ -55,20 +58,5 @@
gstrs = subsref(gstrs, sins);
end
end

% flatten a cell array
function fca = flatten(ca)

fca = cell(size(ca));

for k = 1:length(ca)
if iscell(ca{k})
ct = ca{k};
fca{k} = ct{1};
else
fca(k) = ca(k);
end
end
end

end
2 changes: 1 addition & 1 deletion Basic/@gds_structure/layerinfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
for s=1:numel(gstruc.el)
el = gstruc.el{s};
if ~is_ref(el) % sref and aref have no layer information
numl = el.layer + 1; % gds layer numbers start with 0
numl = layer(el) + 1; % gds layer numbers start with 0
Li(numl) = Li(numl) + 1;
Si(numl).(etype(el)) = Si(numl).(etype(el)) + 1;
end
Expand Down
22 changes: 5 additions & 17 deletions Basic/@gds_structure/subsref.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@

% convert cs-lists --> cell arrays
itype = {ins.type};
isubs = flatten({ins.subs});
isubs = {ins.subs};

% first indexing operator
switch itype{1}

case '()'

idx = isubs{1};
if iscell(idx)
idx = idx{1};
end

if ischar(idx) && idx == ':'
gelp = gstruct.el(1:end);
gelp = gstruct.el;
elseif length(idx) == 1
gelp = gstruct.el{idx}; % return element
else
Expand Down Expand Up @@ -55,19 +58,4 @@
end
end

% flatten a cell array
function fca = flatten(ca)

fca = cell(size(ca));

for k = 1:length(ca)
if iscell(ca{k})
ct = ca{k};
fca{k} = ct{1};
else
fca(k) = ca(k);
end
end
end

end

0 comments on commit 93eacb0

Please sign in to comment.