Skip to content
Closed
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
18 changes: 11 additions & 7 deletions deploy/packaging/debian/matlab.noarch
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
./usr/local/mdsplus/matlab/matlab2python.m
./usr/local/mdsplus/matlab/MDSarg.m
./usr/local/mdsplus/matlab/MDSplusAPI.m
./usr/local/mdsplus/matlab/NATIVEvalue.m
./usr/local/mdsplus/matlab/mdsFromMatlab.m
./usr/local/mdsplus/matlab/mdsInfo.m
./usr/local/mdsplus/matlab/mdsToMatlab.m
./usr/local/mdsplus/matlab/mdsUseLegacy.m
./usr/local/mdsplus/matlab/mdsUsePython.m
./usr/local/mdsplus/matlab/mdsclose.m
./usr/local/mdsplus/matlab/mdsconnect.m
./usr/local/mdsplus/matlab/mdsdisconnect.m
./usr/local/mdsplus/matlab/mdsFromMatlab.m
./usr/local/mdsplus/matlab/mdsgetmsg.m
./usr/local/mdsplus/matlab/mdsInfo.m
./usr/local/mdsplus/matlab/mdsopen.m
./usr/local/mdsplus/matlab/MDSplusAPI.m
./usr/local/mdsplus/matlab/mdsput.m
./usr/local/mdsplus/matlab/mdstcl.m
./usr/local/mdsplus/matlab/mdstest.m
./usr/local/mdsplus/matlab/mdsToMatlab.m
./usr/local/mdsplus/matlab/mdsUseLegacy.m
./usr/local/mdsplus/matlab/mdsUsePython.m
./usr/local/mdsplus/matlab/mdsvalue.m
./usr/local/mdsplus/matlab/NATIVEvalue.m
./usr/local/mdsplus/matlab/PyExecute.m
./usr/local/mdsplus/matlab/python2matlab.m
./usr/local/mdsplus/matlab/setPython.m
19 changes: 11 additions & 8 deletions deploy/packaging/redhat/matlab.noarch
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
./usr/local/mdsplus/matlab
./usr/local/mdsplus/matlab/matlab2python.m
./usr/local/mdsplus/matlab/MDSarg.m
./usr/local/mdsplus/matlab/MDSplusAPI.m
./usr/local/mdsplus/matlab/NATIVEvalue.m
./usr/local/mdsplus/matlab/mdsFromMatlab.m
./usr/local/mdsplus/matlab/mdsInfo.m
./usr/local/mdsplus/matlab/mdsToMatlab.m
./usr/local/mdsplus/matlab/mdsUseLegacy.m
./usr/local/mdsplus/matlab/mdsUsePython.m
./usr/local/mdsplus/matlab/mdsclose.m
./usr/local/mdsplus/matlab/mdsconnect.m
./usr/local/mdsplus/matlab/mdsdisconnect.m
./usr/local/mdsplus/matlab/mdsFromMatlab.m
./usr/local/mdsplus/matlab/mdsgetmsg.m
./usr/local/mdsplus/matlab/mdsInfo.m
./usr/local/mdsplus/matlab/mdsopen.m
./usr/local/mdsplus/matlab/MDSplusAPI.m
./usr/local/mdsplus/matlab/mdsput.m
./usr/local/mdsplus/matlab/mdstcl.m
./usr/local/mdsplus/matlab/mdstest.m
./usr/local/mdsplus/matlab/mdsToMatlab.m
./usr/local/mdsplus/matlab/mdsUseLegacy.m
./usr/local/mdsplus/matlab/mdsUsePython.m
./usr/local/mdsplus/matlab/mdsvalue.m
./usr/local/mdsplus/matlab/NATIVEvalue.m
./usr/local/mdsplus/matlab/PyExecute.m
./usr/local/mdsplus/matlab/python2matlab.m
./usr/local/mdsplus/matlab/setPython.m
10 changes: 10 additions & 0 deletions matlab/PyExecute.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function [ result] = PyExecute( expression, varargin)
% PyExecute evaluate an expression
% [ result, status ] = mdsvalue( expression, varargin)
info = mdsInfo();
n = nargin-1;
args=cell(n,1);
result = py.MDSplus.EXECUTE(expression,args{:});
result.evaluate();
result=mdsToMatlab(result);
end
34 changes: 34 additions & 0 deletions matlab/matlab2python.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function result = matlab2python(value, info)
dtype=class(value);
switch dtype
case 'char'
result = value;
otherwise
switch dtype
case 'single'
dtype='float32';
case 'double'
dtype='float64';
case 'cell'
dtype='str';
end
if info.ispy2 && contains(dtype,'int64')
warning('MDSplus:python2_int64','%s\n',...
'Loss of precision: python2 does not support int64 properly. Try python3 instead.',...
'You can disable this warning with "warning(''off'', ''MDSplus:python2_int64'')"')
value = double(value);
end
if isscalar(value)
f=str2func(strcat('py.numpy.',dtype));
result=f(value);
else
sz = size(value);
result = py.numpy.array(reshape(value,int32(1),prod(int32(sz))),dtype);
if not(numel(sz) == 2 && sz(2) == 1)
result = py.numpy.resize(result, flip(int32(sz)));
result = py.numpy.ascontiguousarray(result);
end
end
end
end

34 changes: 0 additions & 34 deletions matlab/mdsFromMatlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,6 @@
end
end

function result = matlab2python(value, info)
dtype=class(value);
switch dtype
case 'char'
result = value;
otherwise
switch dtype
case 'single'
dtype='float32';
case 'double'
dtype='float64';
case 'cell'
dtype='str';
end
if info.ispy2 && contains(dtype,'int64')
warning('MDSplus:python2_int64','%s\n',...
'Loss of precision: python2 does not support int64 properly. Try python3 instead.',...
'You can disable this warning with "warning(''off'', ''MDSplus:python2_int64'')"')
value = double(value);
end
if isscalar(value)
f=str2func(strcat('py.numpy.',dtype));
result=f(value);
else
sz = size(value);
result = py.numpy.array(reshape(value,int32(1),prod(int32(sz))),dtype);
if not(numel(sz) == 2 && sz(2) == 1)
result = py.numpy.resize(result, flip(int32(sz)));
result = py.numpy.ascontiguousarray(result);
end
end
end
end

function result = matlab2java(value, ~)
switch class(value)
case 'double'
Expand Down
17 changes: 1 addition & 16 deletions matlab/mdsInfo.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,6 @@
end
end

function err = setPython()
global MDSINFO
persistent cache
if ~isempty(cache)
err = cache;
else
try
MDSINFO.ispy2 = logical(py.MDSplus.version.ispy2);
err = false;
cache = err;
catch err
end
end
end

function err = setJavaMds()
persistent cache
if ~isempty(cache)
Expand Down Expand Up @@ -108,4 +93,4 @@
catch err
end
end
end
end
57 changes: 0 additions & 57 deletions matlab/mdsToMatlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,6 @@
end
end

function result = python2matlab(value, info)
if strncmp(class(value),'py.MDSplus', 10)
value = value.data();
end
if ~strncmp(class(value),'py.numpy', 8)
result = value;
else
dtype = char(value.dtype.name);
if contains(dtype,'str') || contains(dtype,'bytes')
if value.ndim == 0
result = char(value);
else
strs = value.flatten.tolist();
result{length(strs)} = '';
for idx = 1 : length(strs)
result{idx} = char(py.MDSplus.version.tostr(strs{idx}));
end
shape = flip(int64(py.array.array('i', value.shape)));
if numel(shape) == 1
shape = [shape, int64(1)];
end
result = reshape(result, shape);
end
else
switch dtype
case 'float32'
dtype='single';
case 'float64'
dtype='double';
end
f=str2func(dtype);
dtype = value.dtype.char;
if info.ispy2 && contains('Qq',char(dtype))
warning('MDSplus:python2_int64','%s\n',...
'Loss of precision: python2 does not support int64 properly. Try python3 instead.',...
'You can disable this warning with "warning(''off'', ''MDSplus:python2_int64'')"')
dtype='d';
end
if value.ndim > 1
shape = int64(py.array.array('i',value.shape));
if ~py.numpy.isfortran(value)
shape = flip(shape);
end
value = py.numpy.asfortranarray(value);
value = py.array.array(dtype,value.flat);
result = reshape(f(value),shape);
else
if value.ndim > 0
result=reshape(f(py.array.array(dtype,value)),[int64(value.shape{1}),1]);
else
result=f(py.array.array(dtype,{value}));
end
end
end
end
end

function result = java2matlab(mdsthing, info)
if ~strncmp(class(mdsthing),'MDSplus',7)
result = mdsthing;
Expand Down
3 changes: 1 addition & 2 deletions matlab/mdsvalue.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
end
else
if info.usePython
result = py.MDSplus.EXECUTE(expression,args{:});
result.evaluate();
result = PyExecute(expression, args{:})
else
dobj=javaObject('MDSplus.Data');
result = dobj.execute(expression, args);
Expand Down
57 changes: 57 additions & 0 deletions matlab/python2matlab.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function result = python2matlab(value, info)
if strncmp(class(value),'py.MDSplus', 10)
value = value.data();
end
if ~strncmp(class(value),'py.numpy', 8)
result = value;
else
dtype = char(value.dtype.name);
if contains(dtype,'str') || contains(dtype,'bytes')
if value.ndim == 0
result = char(value);
else
strs = value.flatten.tolist();
result{length(strs)} = '';
for idx = 1 : length(strs)
result{idx} = char(py.MDSplus.version.tostr(strs{idx}));
end
shape = flip(int64(py.array.array('i', value.shape)));
if numel(shape) == 1
shape = [shape, int64(1)];
end
result = reshape(result, shape);
end
else
switch dtype
case 'float32'
dtype='single';
case 'float64'
dtype='double';
end
f=str2func(dtype);
dtype = value.dtype.char;
if info.ispy2 && contains('Qq',char(dtype))
warning('MDSplus:python2_int64','%s\n',...
'Loss of precision: python2 does not support int64 properly. Try python3 instead.',...
'You can disable this warning with "warning(''off'', ''MDSplus:python2_int64'')"')
dtype='d';
end
if value.ndim > 1
shape = int64(py.array.array('i',value.shape));
if ~py.numpy.isfortran(value)
shape = flip(shape);
end
value = py.numpy.asfortranarray(value);
value = py.array.array(dtype,value.flat);
result = reshape(f(value),shape);
else
if value.ndim > 0
result=reshape(f(py.array.array(dtype,value)),[int64(value.shape{1}),1]);
else
result=f(py.array.array(dtype,{value}));
end
end
end
end
end

15 changes: 15 additions & 0 deletions matlab/setPython.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function err = setPython()
global MDSINFO
persistent cache
if ~isempty(cache)
err = cache;
else
try
MDSINFO.ispy2 = logical(py.MDSplus.version.ispy2);
err = false;
cache = err;
catch err
end
end
end