mdsplus icon indicating copy to clipboard operation
mdsplus copied to clipboard

mdsvalue can't handle MDSplus.List class

Open walkerml opened this issue 5 months ago • 4 comments

Affiliation What University / Laboratory / Company are you from, if any? GA

Version(s) Affected The MDSplus Version(s) affected, if any. e.g. Client Version: Alpha 7.142.80, Server Version: Stable 7.79.0 You can use mdstcl show version to get the client version. You can use mdsvalue('Tcl("show version", _ver); _ver') to get the server version over thin client, or ask your site administrator.

MDSplus version: 7.139.59

Release: HEAD_release_7.139.59 Browse: https://github.com/MDSplus/mdsplus/tree/HEAD_release_7.139.59 Download: https://github.com/MDSplus/mdsplus/archive/HEAD_release_7.139.59.tar.gz

Platform(s) The Operating System(s) you're running on.

Linux

Installation Method(s) The method(s) used to install MDSplus. e.g. mdsplus.org repository, compiled from source, kits downloaded from GitHub Release

Unknown. Installed by system admins.

Describe the bug A clear and concise description of what the bug is.

The current version of mdsvalue simply punts when asked to read MDSplus.List class data:

237 dat = mdsvalue(fullnam); % Actual value of data K>> K>> K>> Error using javaToMatlab class MDSplus.List not supported by mdsToMatlab function

Error in mdsToMatlab (line 13) result = javaToMatlab(mdsthing);

Error in mdsvalue (line 53) result = mdsToMatlab(result);

Error in get_mds_tree (line 237) dat = mdsvalue(fullnam); % Actual value of data

To Reproduce Steps to reproduce the behavior:

(1) Connect to and open D3D mdsplus server and MSE tree in matlab. status = mdsconnect('atlas.gat.com'); [shoto, status] = mdsopen('MSE', 203000); (2) Set fullnam = '\MSE::TOP.CALIB:BT_SCALE' (3) type dat = mdsvalue(fullnam);

This problem is easily connected using code like this:

if(isa(result,'MDSplus.List')) % handle List class isdata = 1; k=0; clear data; while isdata temp = result.getElementAt(k) if(isempty(temp)), break; end k=k+1 data(k) = temp; end result = double(data); else result = mdsToMatlab(result); end

(which is what I'm doing on a temporary basis, but this needs a permanent fix.)

walkerml avatar Aug 15 '25 15:08 walkerml

Hi @walkerml,

Thanks for the note and suggested fix.

Note that the alpha-7-139-59 is almost two years old (6-Nov-2023). Several issues with the MDSplus API for MATLAB have been fixed since that version was released.

Today, I will see if this problem is fixed in the current release. If so, I will post an alternate solution that you can evaluate.

However, if I am able to reproduce the problem in the current release, then I will convert your suggested fix into a GitHub PR.

mwinkel-dev avatar Aug 18 '25 16:08 mwinkel-dev

Hi @walkerml,

This issue has just been reproduced with the alpha-7-153-6 release (22-Jul-2025) running on GA's Omega cluster.

We will now work on a fix for this issue.

mwinkel-dev avatar Aug 18 '25 19:08 mwinkel-dev

The alpha-7-153-6 version does have code to handle MDSplus.List, so does not generate the error described in the bug report: class MDSplus.List not supported by mdsToMatlab function.

However, the code for handling MDSplus.List is failing in alpha-7-153-6 as shown below.

$ matlab -nodisplay

                                                  < M A T L A B (R) >
                                        Copyright 1984-2024 The MathWorks, Inc.
                                   R2024b Update 6 (24.2.0.2923080) 64-bit (glnxa64)
                                                    March 28, 2025

 
To get started, type doc.
For product information, visit www.mathworks.com.
 
>> mdsconnect('atlas');
>> mdsopen('MSE', 203000);
>> dat = mdsvalue('\MSE::TOP.CALIB:BT_SCALE')
Error using javaToMatlabStruct (line 41)
incompatible types

Error in javaToMatlab (line 38)
                result = javaToMatlabStruct(mdsthing);
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in mdsToMatlab (line 13)
        result = javaToMatlab(mdsthing);
                 ^^^^^^^^^^^^^^^^^^^^^^
Error in mdsvalue (line 53)
result = mdsToMatlab(result);
         ^^^^^^^^^^^^^^^^^^^
 
>> 

The MDSplus.List in the above example is a 69-element vector of MDSplus.Float64 values. However, the code in javaToMatlabStruct.m appears to be expecting just a list that contains dictionaries or other lists. Thus, the all(string(itemClasses)=='MDSplus.List') comparison fails, thereby causing it to throw the incompatible types exception.

The bug report's proposed solution works with the ~2 year-old alpha-7-139-59 release of MDSplus. However, it might not be the optimal solution for the current alpha.

mwinkel-dev avatar Aug 18 '25 21:08 mwinkel-dev

Hi @walkerml,

The issue with the MDSplus.List data type is that a list can contain members of many different data types, including nested sublists and dictionaries. The analogous concept in MATLAB is nested "cell arrays". A general purpose method for converting MDSplus.List into "cell arrays" would involve recursive code. It is a complex task to ensure that all possible MDSplus.List structures will be correctly converted to nested "cell arrays".

In the example provided in the bug report, the list is a vector of numeric data -- all of the same type. MDSplus has ~12 numeric data types. So, for that tiny subset of the universe of all possible lists, it is straightforward to convert it to a MATLAB array. The conversion could either be done on the MDSplus side with a custom TDI function, or on the MATLAB side by adding a few more cases to the javaToMatlabStruct.m script.

Regardless, the code in the current "alpha" version does not gracefully handle your example input.

We are presently discussing the various options and have not yet decided on the optimal solution.

mwinkel-dev avatar Aug 21 '25 20:08 mwinkel-dev