Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deploy/packaging/debian/matlab.noarch
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
./usr/local/mdsplus/matlab/private/javaConnect.m
./usr/local/mdsplus/matlab/private/javaExecute.m
./usr/local/mdsplus/matlab/private/javaFromMatlab.m
./usr/local/mdsplus/matlab/private/javaFromMatlabStruct.m
./usr/local/mdsplus/matlab/private/javaToMatlab.m
./usr/local/mdsplus/matlab/private/javaToMatlabStruct.m
./usr/local/mdsplus/matlab/private/pythonActivate.m
./usr/local/mdsplus/matlab/private/pythonConnect.m
./usr/local/mdsplus/matlab/private/pythonExecute.m
Expand Down
2 changes: 2 additions & 0 deletions deploy/packaging/redhat/matlab.noarch
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
./usr/local/mdsplus/matlab/private/javaConnect.m
./usr/local/mdsplus/matlab/private/javaExecute.m
./usr/local/mdsplus/matlab/private/javaFromMatlab.m
./usr/local/mdsplus/matlab/private/javaFromMatlabStruct.m
./usr/local/mdsplus/matlab/private/javaToMatlab.m
./usr/local/mdsplus/matlab/private/javaToMatlabStruct.m
./usr/local/mdsplus/matlab/private/pythonActivate.m
./usr/local/mdsplus/matlab/private/pythonConnect.m
./usr/local/mdsplus/matlab/private/pythonExecute.m
Expand Down
5 changes: 4 additions & 1 deletion java/mdsobjects/src/main/java/MDSplus/Apd.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public Data getDescAt(int idx)
{
return descs[idx];
}

public int[] getShape()
{
return new int[]{descs.length};
}
protected void resizeDescs(int newDim)
{
if (descs == null)
Expand Down
4 changes: 4 additions & 0 deletions java/mdsobjects/src/main/java/MDSplus/Dictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public Dictionary(Data[] descs, Data help, Data units, Data error, Data validati
super(descs, help, units, error, validation);
dtype = DTYPE_DICTIONARY;
}
public int[] getShape()
{
return new int[]{descs.length/2};
}

public static Data getData(Data[] descs, Data help, Data units, Data error, Data validation)
{
Expand Down
5 changes: 5 additions & 0 deletions matlab/private/javaFromMatlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
javaclass = 'MDSplus.Uint8';
case 'cell'
javaclass = 'MDSplus.String';
case 'struct'
result = javaFromMatlabStruct(value);
return
case 'string'
javaclass = 'MDSplus.String';
case 'char'
result = javaObject('MDSplus.String', value);
return
Expand Down
24 changes: 24 additions & 0 deletions matlab/private/javaFromMatlabStruct.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function result = javaFromMatlabStruct(value)
if ~strcmp(class(value), 'struct')
throw(MException('MDSplus:javaFromMatlabStruct', 'only struct allowed'));
end

if isscalar(value)
fields = fieldnames(value);
result = MDSplus.Dictionary();
for fieldIdx = 1:length(fields)
fieldName = fields{fieldIdx};
fieldValue = value.(fieldName);
javaFromMatlab(fieldValue)
result.setItem(MDSplus.String(fieldName), javaFromMatlab(fieldValue));
end
else
result = MDSplus.Apd();
numItems = length(value);
for itemIdx = 1:numItems
result.setDescAt(itemIdx - 1, javaFromMatlab(value(itemIdx)));
end

end

end
8 changes: 6 additions & 2 deletions matlab/private/javaToMatlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
case 'MDSplus.Float32Array'
result = reshape(mdsthing.getFloatArray, shape);
case 'MDSplus.StringArray'
result = reshape(cellstr(char(mdsthing.getStringArray)), shape);
result = reshape(cellstr(string(mdsthing.getStringArray)), shape);
case 'MDSplus.Dictionary'
result = javaToMatlabStruct(mdsthing);
case 'MDSplus.Apd'
result = javaToMatlabStruct(mdsthing);
otherwise
throw(MException('MDSplus:mdsToMatlab', 'class %s not supported by mdsToMatlab function\n', class(mdsthing)));
end
Expand All @@ -58,7 +62,7 @@
case 'MDSplus.Float32'
result = mdsthing.getFloatArray();
case 'MDSplus.String'
result = char(mdsthing.getString());
result = string(mdsthing.getString());
otherwise
throw(MException('MDSplus:mdsToMatlab', 'class %s not supported by mdsToMatlab function\n', class(mdsthing)));
end
Expand Down
21 changes: 21 additions & 0 deletions matlab/private/javaToMatlabStruct.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function result = javaToMatlabStruct(value)
if ~strcmp(class(value), 'MDSplus.Dictionary') && ~strcmp(class(value), 'MDSplus.Apd')
throw(MException('MDSplus:javaToMatlabStruct', 'only MDSplus.Dictionary or MDSplus.Apd allowed'));
end
fields = value.getDescs();
if strcmp(class(value), 'MDSplus.Dictionary')
numItems = length(fields)/2;
for itemIdx = 1:numItems
fieldName = javaToMatlab(fields(itemIdx * 2 - 1));
fieldValue = javaToMatlab(fields(itemIdx * 2));
result.(fieldName) = fieldValue;
end
else
numItems = length(fields);
for itemIdx = 1:numItems
result(itemIdx) = javaToMatlab(fields(itemIdx));
end

end

end
4 changes: 3 additions & 1 deletion python/MDSplus/apd.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def fromDescriptor(cls, d):
def __init__(self, value=None, dtype=0):
"""Initializes a Apd instance
"""
self.dtype_id = Apd.dtype_id
if value is self:
return
self.dtype_id = dtype
self._descs = []
if value is not None:
if isinstance(value, _ver.listlike):
Expand Down Expand Up @@ -130,6 +130,7 @@ def tolist(self):
dtype_id = 216

def __init__(self, value=None):
self.dtype_id = Dictionary.dtype_id
if value is self:
return
if value is not None:
Expand Down Expand Up @@ -206,6 +207,7 @@ class List(list, Apd):
dtype_id = 214

def __init__(self, value=None):
self.dtype_id = List.dtype_id
if value is self:
return
if value is not None:
Expand Down