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,8 +16,10 @@
./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/javaFromMatlabCell.m
./usr/local/mdsplus/matlab/private/javaFromMatlabStruct.m
./usr/local/mdsplus/matlab/private/javaToMatlab.m
./usr/local/mdsplus/matlab/private/javaToMatlabCell.m
./usr/local/mdsplus/matlab/private/javaToMatlabStruct.m
./usr/local/mdsplus/matlab/private/pythonActivate.m
./usr/local/mdsplus/matlab/private/pythonConnect.m
Expand Down
2 changes: 1 addition & 1 deletion deploy/packaging/debian/python.noarch
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
./usr/local/mdsplus/python/MDSplus/mdsdcl.py
./usr/local/mdsplus/python/MDSplus/mdsscalar.py
./usr/local/mdsplus/python/MDSplus/modpython.py
./usr/local/mdsplus/python/MDSplus/pyproject.toml
./usr/local/mdsplus/python/MDSplus/scope.py
./usr/local/mdsplus/python/MDSplus/setup.py
./usr/local/mdsplus/python/MDSplus/pyproject.toml
./usr/local/mdsplus/python/MDSplus/tests/__init__.py
./usr/local/mdsplus/python/MDSplus/tests/_common.py
./usr/local/mdsplus/python/MDSplus/tests/connection_case.py
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,8 +18,10 @@
./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/javaFromMatlabCell.m
./usr/local/mdsplus/matlab/private/javaFromMatlabStruct.m
./usr/local/mdsplus/matlab/private/javaToMatlab.m
./usr/local/mdsplus/matlab/private/javaToMatlabCell.m
./usr/local/mdsplus/matlab/private/javaToMatlabStruct.m
./usr/local/mdsplus/matlab/private/pythonActivate.m
./usr/local/mdsplus/matlab/private/pythonConnect.m
Expand Down
2 changes: 1 addition & 1 deletion deploy/packaging/redhat/python.noarch
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
./usr/local/mdsplus/python/MDSplus/mdsdcl.py
./usr/local/mdsplus/python/MDSplus/mdsscalar.py
./usr/local/mdsplus/python/MDSplus/modpython.py
./usr/local/mdsplus/python/MDSplus/pyproject.toml
./usr/local/mdsplus/python/MDSplus/scope.py
./usr/local/mdsplus/python/MDSplus/setup.py
./usr/local/mdsplus/python/MDSplus/pyproject.toml
./usr/local/mdsplus/python/MDSplus/tests
./usr/local/mdsplus/python/MDSplus/tests/__init__.py
./usr/local/mdsplus/python/MDSplus/tests/_common.py
Expand Down
4 changes: 3 additions & 1 deletion java/mdsobjects/src/main/java/MDSplus/Apd.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public Data getDescAt(int idx)
{
return descs[idx];
}

public int[] getShape()
{
return new int[]{descs.length};
return new int[]{nDescs};
}

protected void resizeDescs(int newDim)
{
if (descs == null)
Expand Down
62 changes: 55 additions & 7 deletions java/mdsobjects/src/main/java/MDSplus/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,55 @@ public Data get(java.lang.String expr, Data args[]) throws MdsException
{
if (!checkArgs(args))
throw new MdsException(
"Invalid arguments: only scalars and arrays arguments can be passed to COnnection.get()");
return get(sockId, expr, args);
"Invalid arguments: only scalars and arrays arguments can be passed to Connection.get()");
java.lang.String expandedExpr;
if(expr.equals("$"))
{
expandedExpr = "serializeout(`("+expr+"))";
}
else
{
expandedExpr = "serializeout(`(data(("+expr+"))))";
}
Data serData = get(sockId, expandedExpr, args);
return Data.deserialize(serData.getByteArray());

}

public Data get(java.lang.String expr) throws MdsException
{
return get(expr, new Data[0]);
java.lang.String expandedExpr = "serializeout(`(data(("+expr+"))))";
Data serData = get(sockId, expandedExpr, new Data[0]);
if(serData instanceof Array)
return Data.deserialize(serData.getByteArray());
else //error code
return serData;
}

public void put(java.lang.String path, java.lang.String expr, Data args[]) throws MdsException
public void put(java.lang.String path, java.lang.String expr, Data inArgs[]) throws MdsException
{
Data args[] = new Data[inArgs.length];
//Check if any passed argument is Apd
boolean serialized = false;
for(int i = 0; i < inArgs.length; i++)
{
if(inArgs[i] instanceof Apd)
{
serialized = true;
}
}

for(int i = 0; i < inArgs.length; i++)
{
if(serialized)
args[i] = new Uint8Array(inArgs[i].serialize());
else
args[i] = inArgs[i];
}
if (!checkArgs(args))
throw new MdsException(
"Invalid arguments: only scalars and arrays arguments can be passed to COnnection.put()");
put(sockId, path, expr, args);
put(sockId, path, expr, args, serialized);
}

public void put(java.lang.String path, java.lang.String expr) throws MdsException
Expand All @@ -136,7 +170,7 @@ public void put(java.lang.String path, Data data) throws MdsException

public native Data get(int sockId, java.lang.String expr, Data args[]) throws MdsException;

public native void put(int sockId, java.lang.String path, java.lang.String expr, Data args[]) throws MdsException;
public native void put(int sockId, java.lang.String path, java.lang.String expr, Data args[], boolean serialized) throws MdsException;

public GetMany getMany()
{ return new GetManyInConnection(); }
Expand All @@ -145,7 +179,19 @@ public PutMany putMany()
{
return new PutManyInConnection();
}

public static void main(java.lang.String args[])
{
try {

MDSplus.Connection c = new MDSplus.Connection("localhost:8001");
c.openTree("test", -1);
System.out.println(c.get("anyapd"));
}catch(Exception exc)
{
System.out.println(exc);
}
}

////////// GetMany
class GetManyInConnection extends List implements GetMany
{
Expand Down Expand Up @@ -288,5 +334,7 @@ public void checkStatus(java.lang.String path) throws MdsException
throw new MdsException(retMsg.getString());
}
}



}
8 changes: 5 additions & 3 deletions java/mdsobjects/src/main/java/MDSplus/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,12 @@ public java.lang.String[] getStringArray() throws MdsException
return data.getStringArray();
}

public int getSize()
public int getSize() throws MdsException
{
final Data data = data();
return data.getSize();
final Data data = executeWithContext("SIZE($1)", this);
if (!(data instanceof Int32))
throw new MdsException("Cannot get data size");
return data.getInt();
}

public int getSizeInBytes()
Expand Down
1 change: 1 addition & 0 deletions java/mdsobjects/src/main/java/MDSplus/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public List()
public List(Data[] descs)
{
super(descs, null, null, null, null);
dtype = DTYPE_LIST;
}

public List(Data[] descs, Data help, Data units, Data error, Data validation)
Expand Down
2 changes: 1 addition & 1 deletion javamds/MDSplus_Connection.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion javamds/mdsobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@ Java_MDSplus_Connection_get(JNIEnv *env, jobject obj __attribute__((unused)),
*/
JNIEXPORT void JNICALL Java_MDSplus_Connection_put(
JNIEnv *env, jobject obj __attribute__((unused)), jint sockId,
jstring jPath, jstring jExpr, jobjectArray jArgs)
jstring jPath, jstring jExpr, jobjectArray jArgs, jboolean serialized)
{
const char *expr = (*env)->GetStringUTFChars(env, jExpr, 0);
const char *inPath = (*env)->GetStringUTFChars(env, jPath, 0);
Expand All @@ -3936,12 +3936,25 @@ JNIEXPORT void JNICALL Java_MDSplus_Connection_put(
else
strcpy(path, inPath);

if(serialized)
{
putExpr = malloc(strlen("TreePutDeserialized(") + strlen(expr) + strlen(path) + 5 +
nArgs * 2 + 2);
if (nArgs > 0)
sprintf(putExpr, "TreePutDeserialized(\'%s\',\'%s\',", path, expr);
else
sprintf(putExpr, "TreePutDeserialized(\'%s\',\'%s\'", path, expr);
}
else
{
putExpr = malloc(strlen("TreePut(") + strlen(expr) + strlen(path) + 5 +
nArgs * 2 + 2);
if (nArgs > 0)
sprintf(putExpr, "TreePut(\'%s\',\'%s\',", path, expr);
else
sprintf(putExpr, "TreePut(\'%s\',\'%s\'", path, expr);

}
for (varIdx = 0; varIdx < nArgs; varIdx++)
{
if (varIdx < nArgs - 1)
Expand Down
50 changes: 48 additions & 2 deletions matlab/mdsput.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
function [ status ] = mdsput( node, expression, varargin)
% MDSPUT put data into MDSplus tree node
% This routine invokes treeput(node, expression, ...)
status = mdsvalue(sprintf('treeput($, $%s)', repmat(', $', 1, nargin - 2)), node, expression, varargin{:});
% This routine uses the java or python interface
info = mdsInfo();
n = nargin - 2;
if info.usePython
args = cell(n, 1);
else
if info.isConnected
extra = 0;
else
extra = 1;
end
args = javaArray('MDSplus.Data', max(1, n + extra));
end
for k = 1 : n
argin = varargin(k);
if iscell(argin{1})
argout = mdsFromMatlab(argin{1});
else
argout = mdsFromMatlab(cell2mat(argin));
end
if info.usePython
args{k} = argout;
else
args(k) = argout;
end
end

try
if info.isConnected
if n > 0
if info.usePython
info.connection.put(node, expression, args{:});
else
info.connection.put(node, expression, args);
end
else
info.connection.put(node, expression);
end
else
[mdsres, mdsok] = mdsvalue(sprintf('treeput($, $%s)', repmat(', $', 1, nargin - 2)), node, expression, varargin{:});
if mdsok==0 || ~isnumeric(mdsres) || rem(mdsres,2)==0
throw(MException('MDSplus:treeput', 'treeput error %d: %s', mdsok, string(mdsres)));
end
end
status = 1;
catch err
status = 0;
error(err.message);
end
8 changes: 4 additions & 4 deletions matlab/private/javaFromMatlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
case 'uint8'
javaclass = 'MDSplus.Uint8';
case 'cell'
javaclass = 'MDSplus.String';
result = javaFromMatlabCell(value);
return
case 'struct'
result = javaFromMatlabStruct(value);
return
Expand All @@ -31,11 +32,10 @@
result = javaObject('MDSplus.String', value);
return
otherwise
result = value;
return
throw(MException('MDSplus:javaFromMatlab', 'Unsupported type'))
end
sz = size(value);
if isequal(sz, [1, 1])
if isscalar(value)
result = javaObject(javaclass, value);
else
result = javaObject(strcat(javaclass, 'Array'), reshape(value, [], 1), sz);
Expand Down
33 changes: 33 additions & 0 deletions matlab/private/javaFromMatlabCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function result = javaFromMatlabCell(value)
if ~iscell(value)
throw(MException('MDSplus:javaFromMatlabCell', 'only cell allowed'));
end
result = MDSplus.Apd();
if isscalar(value)
result.setDescAt(0, javaFromMatlab(value{:}));
elseif isvector(value)
numItems = length(value);
for itemIdx = 1:numItems
if isrow(value)
result.setDescAt(itemIdx - 1, javaFromMatlab(value{itemIdx}));
else
result.setDescAt(itemIdx - 1, javaFromMatlab({value{itemIdx}}));
end
end
elseif ismatrix(value)
elemSize = size(value);
for rowIdx = 1:elemSize(1)
result.setDescAt(rowIdx - 1, javaFromMatlab(value(rowIdx,:)));
end
else
elemSize = size(value);
n = ndims(value);
idx = cell(1,n);
idx(:) = {':'};
for currDim = 1:elemSize(end)
idx{end} = currDim;
result.setDescAt(currDim - 1, javaFromMatlab(value(idx{:})));
end
end

end
32 changes: 26 additions & 6 deletions matlab/private/javaFromMatlabStruct.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function result = javaFromMatlabStruct(value)
if ~strcmp(class(value), 'struct')
if ~isstruct(value)
throw(MException('MDSplus:javaFromMatlabStruct', 'only struct allowed'));
end

Expand All @@ -9,16 +9,36 @@
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();
elseif isvector(value)
result = MDSplus.List();
numItems = length(value);
for itemIdx = 1:numItems
result.setDescAt(itemIdx - 1, javaFromMatlab(value(itemIdx)));
if isrow(value)
result.append(javaFromMatlabStruct(value(itemIdx)));
else
temp = MDSplus.List();
temp.append(javaFromMatlabStruct(value(itemIdx)));
result.append(temp);
end
end
elseif ismatrix(value)
result = MDSplus.List();
elemSize = size(value);
for rowIdx = 1:elemSize(1)
result.append(javaFromMatlabStruct(value(rowIdx,:)));
end
else
result = MDSplus.List();
elemSize = size(value);
n = ndims(value);
idx = cell(1,n);
idx(:) = {':'};
for currDim = 1:elemSize(end)
idx{end} = currDim;
result.append(javaFromMatlab(value(idx{:})));
end

end

end
Loading