@osauter@vallar I continue the discussion here. Also tagging @amerle who may have opinions about this.
tdi is a class that returns data objects constructed from various mdsvalue calls.
The status flag is the status flag of mdsvalue that tdi returns. This makes sense and constitutes expected behaviour of the tdi class. I think it is not unreasonable that assume this behaviour stays true. We can add a test if we want to ensure this.
I merely advocate using this existing error handling mechanosm of MDSplus, which is correctly propagated thorugh tdi, to check whether a request for data from MDS fails.
Furthermore we can add of course a further output/error flag to gdat if you want, but that is beyond the scope of this issue. The issue here is how to check, within gdat (or elsewhere for that matter) whether an mds call gave what you expected, to replace things like
d = tdi('expression')if ~ischar(d.data) && ~isempty(d.data) warning('problem')end
with
[d] = tdi('expression')if ~rem(d.status,2) % unambigious way to check for problems warning('problem')end
It can be better to use tdi/status but the check will be different from a mdsvalue return. Same for gdat. At some point the data may not come from mds anymore, hence no reason to keep this old convention (not much known actually), but may be 0 for ok and non-zero for not ok would be better...
tdi is very intimately linked to mdsvalue, since it is basically a wrapper that calls it. What I'm proposing is already completely within the mdsplus data retrieval/handling scope of the program.
The fact that the convention is not well known is our fault (for not advertising and documenting it enough within SPC) but that is not a reason not to use it.
The issue is whether we should use rem(d.status,2) to check errors in the future in gdat. I think yes.
If you think no, and the above reasoning did not convince you, I will drop it and you can close the issue.
I don't know enough about mds to know whether mdsdata (which is called in tdi) always returns 1 if correct, but I know that checking odd/even should always work.
No, as you can readily see by inspecting the tdi class definition, tdi returns the mds status as-is, except if it catches a further error (it looks for some specific strings in the returned text) in which case it substitutes another error flag -2.
I don't know if checking the shot from mdsopen is always sufficient, I think I remember finding some cases where it was not sufficient. Checking the status flag always works.
While this fix could readily work for calls to the MATLAB tdi class. It wouldn't work in all cases for mdsvalue calls due to some of the error handling by our IT group explicitely replacing the return value with a string without triggering an MDSplus error and thus having an odd status (this is linked to spc/tcv/tbx/mds#8).