From 7f63665b0c8f98aba06ea786aaaf3b4bb6e78e75 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <Olivier.Sauter@epfl.ch>
Date: Wed, 6 May 2020 17:57:59 +0200
Subject: [PATCH 1/3] add new ids available, thomson_scattering and summary, in
 various global functions

---
 matlab/TCV_IMAS/README             | 3 ++-
 matlab/TCV_IMAS/ids2database.m     | 3 ++-
 matlab/TCV_IMAS/tcv2ids.m          | 3 ++-
 matlab/TCV_IMAS/tcv2ids2database.m | 7 +++++--
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/matlab/TCV_IMAS/README b/matlab/TCV_IMAS/README
index 0c737364..bb3df11b 100644
--- a/matlab/TCV_IMAS/README
+++ b/matlab/TCV_IMAS/README
@@ -4,7 +4,8 @@
 %
 ids_list_all=ids_list;
 
-%ids_list_to_generate = {'core_profiles', 'core_sources', 'equilibrium', 'magnetics', 'pf_active', 'pf_passive', 'tf','wall'};
+% ids_list_to_generate = {'core_profiles', 'core_sources', 'equilibrium', 'magnetics', 'pf_active', 'pf_passive', 'tf','wall', ...
+% 'thomson_scattering', 'summary'};
 ids_list_to_generate = ids_list_all;
 
 for i=1:length(ids_list_to_generate)
diff --git a/matlab/TCV_IMAS/ids2database.m b/matlab/TCV_IMAS/ids2database.m
index abbbfaec..596f0102 100644
--- a/matlab/TCV_IMAS/ids2database.m
+++ b/matlab/TCV_IMAS/ids2database.m
@@ -88,7 +88,8 @@ try
     ids_full_list = IDS_list;
   end
 catch
-  ids_full_list = {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi','pf_passive'};
+  ids_full_list = {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi','pf_passive', ...
+                  'thomson_scattering', 'summary'};
   warning(['IDS_list not available, quick fix introducing list of ids ready for TCV: ' fprintf('%s ',ids_full_list{:}) char(10)]);
 end
 ids_names_notok = setdiff(ids_names,ids_full_list);
diff --git a/matlab/TCV_IMAS/tcv2ids.m b/matlab/TCV_IMAS/tcv2ids.m
index d6e2ecc9..477885f9 100644
--- a/matlab/TCV_IMAS/tcv2ids.m
+++ b/matlab/TCV_IMAS/tcv2ids.m
@@ -32,7 +32,8 @@ function [ids_from_tcv,varargout] = tcv2ids(shot,varargin);
 p = inputParser;
 % no required inputs here so one can call with empty args and get defaults parameters
 % effectively required inputs should have defaults as empty
-ids_names = {'equilibrium', 'magnetics', 'pf_active','wall', 'tf','core_profiles','ec_launchers','nbi', 'thomson_scattering'};
+ids_names = {'equilibrium', 'magnetics', 'pf_active','wall', 'tf','core_profiles','ec_launchers','nbi', 'thomson_scattering', ...
+            'summary'};
 p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
 p.addOptional('ids_names', ids_names, @(x) isempty(x) || iscell(x) ); % char or cell array
 p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or cell array
diff --git a/matlab/TCV_IMAS/tcv2ids2database.m b/matlab/TCV_IMAS/tcv2ids2database.m
index 99b52f12..7a9081f9 100644
--- a/matlab/TCV_IMAS/tcv2ids2database.m
+++ b/matlab/TCV_IMAS/tcv2ids2database.m
@@ -9,7 +9,8 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin);
 %
 % varargin: 'occurence': occurence value
 % varargin: 'ids_names': cell, ids to load, by default all defined so far (if empty or empty string or not given)
-%             {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi'} or a subset
+%             {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi', 'thomson_scattering', ...
+%              'summary'} or a subset
 % varargin: 'error_bar': type (string)
 %                'delta' or empty (default): meaning difference in upper is set (standard error_bar
 %                'added': errorbar is added: upper=data+delta and lower=data-delta
@@ -48,7 +49,9 @@ p = inputParser;
 p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
 p.addOptional('run_out', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
 p.addOptional('occurence', 0, @(x) isempty(x) || (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
-p.addOptional('ids_names', {'equilibrium', 'magnetics', 'pf_active','wall', 'tf','core_profiles','ec_launchers','nbi'}, @(x) isempty(x) || iscell(x)); % char or cell array
+ids_names = {'equilibrium', 'magnetics', 'pf_active','wall', 'tf','core_profiles','ec_launchers','nbi', 'thomson_scattering', ...
+            'summary'};
+p.addOptional('ids_names', ids_names, @(x) isempty(x) || iscell(x)); % char or cell array
 p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or cell array
 p.addOptional('tree_user', getenv('USER'), @(x) isempty(x) || ischar(x) ); % char
 p.addOptional('tree_tokamak', 'tcv', @(x) isempty(x) || ischar(x) ); % char
-- 
GitLab


From 9622b295d0b831fc1008cc574e4213a6a46eb9f4 Mon Sep 17 00:00:00 2001
From: Antoine Merle <antoine.merle@epfl.ch>
Date: Fri, 8 May 2020 14:23:51 +0200
Subject: [PATCH 2/3] Single function to have list of available IDSs on TCV.

---
 matlab/TCV_IMAS/README              | 3 +--
 matlab/TCV_IMAS/ids2database.m      | 5 ++---
 matlab/TCV_IMAS/tcv2ids.m           | 9 ++++-----
 matlab/TCV_IMAS/tcv2ids2database.m  | 6 ++----
 matlab/TCV_IMAS/tcv_available_ids.m | 6 ++++++
 5 files changed, 15 insertions(+), 14 deletions(-)
 create mode 100644 matlab/TCV_IMAS/tcv_available_ids.m

diff --git a/matlab/TCV_IMAS/README b/matlab/TCV_IMAS/README
index bb3df11b..9dd6086c 100644
--- a/matlab/TCV_IMAS/README
+++ b/matlab/TCV_IMAS/README
@@ -4,8 +4,7 @@
 %
 ids_list_all=ids_list;
 
-% ids_list_to_generate = {'core_profiles', 'core_sources', 'equilibrium', 'magnetics', 'pf_active', 'pf_passive', 'tf','wall', ...
-% 'thomson_scattering', 'summary'};
+% ids_list_to_generate = tcv_available_ids;
 ids_list_to_generate = ids_list_all;
 
 for i=1:length(ids_list_to_generate)
diff --git a/matlab/TCV_IMAS/ids2database.m b/matlab/TCV_IMAS/ids2database.m
index 596f0102..f2b887ba 100644
--- a/matlab/TCV_IMAS/ids2database.m
+++ b/matlab/TCV_IMAS/ids2database.m
@@ -88,9 +88,8 @@ try
     ids_full_list = IDS_list;
   end
 catch
-  ids_full_list = {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi','pf_passive', ...
-                  'thomson_scattering', 'summary'};
-  warning(['IDS_list not available, quick fix introducing list of ids ready for TCV: ' fprintf('%s ',ids_full_list{:}) char(10)]);
+  ids_full_list = tcv_available_ids;
+  warning(['IDS_list not available, quick fix introducing list of ids available for TCV: ' fprintf('%s ',ids_full_list{:}) char(10)]);
 end
 ids_names_notok = setdiff(ids_names,ids_full_list);
 if ~isempty(ids_names_notok)
diff --git a/matlab/TCV_IMAS/tcv2ids.m b/matlab/TCV_IMAS/tcv2ids.m
index 477885f9..da618f38 100644
--- a/matlab/TCV_IMAS/tcv2ids.m
+++ b/matlab/TCV_IMAS/tcv2ids.m
@@ -11,7 +11,7 @@ function [ids_from_tcv,varargout] = tcv2ids(shot,varargin);
 % mdsconnect('localhost:5555')
 %
 % varargin: 'ids_names': cell, idss to load, by default all defined so far (if empty or empty string or not given)
-%             {'equilibrium', 'magnetics', 'pf_active','wall','core_profiles','ec_launchers','nbi'} or a subset
+%             see tcv_available_ids for the list of IDSs available for TCV
 %           'error_bar': type (string)
 %                empty or 'delta' (default): meaning difference in upper is set (standard error_bar
 %                'added': errorbar is added: upper=data+delta and lower=data-delta
@@ -32,14 +32,13 @@ function [ids_from_tcv,varargout] = tcv2ids(shot,varargin);
 p = inputParser;
 % no required inputs here so one can call with empty args and get defaults parameters
 % effectively required inputs should have defaults as empty
-ids_names = {'equilibrium', 'magnetics', 'pf_active','wall', 'tf','core_profiles','ec_launchers','nbi', 'thomson_scattering', ...
-            'summary'};
+ids_names = tcv_available_ids;
 p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
 p.addOptional('ids_names', ids_names, @(x) isempty(x) || iscell(x) ); % char or cell array
 p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or cell array
 p.addOptional('cocos_out', 11, @(x) isempty(x) || isnumeric(x) ); % char
-p.addOptional('ipsign_out', 0, @(x) isempty(x) || (x==0 | x==-1 | x==+1) ); % char
-p.addOptional('b0sign_out', 0, @(x) isempty(x) || (x==0 | x==-1 | x==+1) ); % char
+p.addOptional('ipsign_out', 0, @(x) isempty(x) || (isscalar(x) && (x==0 || x==-1 || x==+1)) );
+p.addOptional('b0sign_out', 0, @(x) isempty(x) || (isscalar(x) && (x==0 || x==-1 || x==+1)) );
 p.addOptional('nverbose', 1, @(x) isempty(x) || isnumeric(x) );
 p.addOptional('time_out', [], @(x) isempty(x) || isnumeric(x) );
 p.addOptional('trialindx', [], @(x) isempty(x) || isnumeric(x) );
diff --git a/matlab/TCV_IMAS/tcv2ids2database.m b/matlab/TCV_IMAS/tcv2ids2database.m
index 7a9081f9..09337c16 100644
--- a/matlab/TCV_IMAS/tcv2ids2database.m
+++ b/matlab/TCV_IMAS/tcv2ids2database.m
@@ -9,8 +9,7 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin);
 %
 % varargin: 'occurence': occurence value
 % varargin: 'ids_names': cell, ids to load, by default all defined so far (if empty or empty string or not given)
-%             {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi', 'thomson_scattering', ...
-%              'summary'} or a subset
+%             see tcv_available_ids for the list of IDSs available for TCV
 % varargin: 'error_bar': type (string)
 %                'delta' or empty (default): meaning difference in upper is set (standard error_bar
 %                'added': errorbar is added: upper=data+delta and lower=data-delta
@@ -49,8 +48,7 @@ p = inputParser;
 p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
 p.addOptional('run_out', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
 p.addOptional('occurence', 0, @(x) isempty(x) || (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
-ids_names = {'equilibrium', 'magnetics', 'pf_active','wall', 'tf','core_profiles','ec_launchers','nbi', 'thomson_scattering', ...
-            'summary'};
+ids_names = tcv_available_ids;
 p.addOptional('ids_names', ids_names, @(x) isempty(x) || iscell(x)); % char or cell array
 p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or cell array
 p.addOptional('tree_user', getenv('USER'), @(x) isempty(x) || ischar(x) ); % char
diff --git a/matlab/TCV_IMAS/tcv_available_ids.m b/matlab/TCV_IMAS/tcv_available_ids.m
new file mode 100644
index 00000000..a98cf4f1
--- /dev/null
+++ b/matlab/TCV_IMAS/tcv_available_ids.m
@@ -0,0 +1,6 @@
+function list = tcv_available_ids()
+
+list = {'equilibrium', 'magnetics', 'tf', 'pf_active','wall','core_profiles','ec_launchers','nbi','pf_passive', ...
+        'thomson_scattering', 'summary'};
+
+end
\ No newline at end of file
-- 
GitLab


From c3dffdd395d78c0d9167f179fd4a4a4e1409daf8 Mon Sep 17 00:00:00 2001
From: Antoine Merle <antoine.merle@epfl.ch>
Date: Fri, 8 May 2020 14:23:51 +0200
Subject: [PATCH 3/3] Polish some argument parsing.

---
 matlab/TCV_IMAS/tcv2ids2database.m | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv2ids2database.m b/matlab/TCV_IMAS/tcv2ids2database.m
index 09337c16..9166d42d 100644
--- a/matlab/TCV_IMAS/tcv2ids2database.m
+++ b/matlab/TCV_IMAS/tcv2ids2database.m
@@ -54,9 +54,9 @@ p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or ce
 p.addOptional('tree_user', getenv('USER'), @(x) isempty(x) || ischar(x) ); % char
 p.addOptional('tree_tokamak', 'tcv', @(x) isempty(x) || ischar(x) ); % char
 p.addOptional('tree_majorversion', '3', @(x) isempty(x) || ischar(x) ); % char
-p.addOptional('cocos_out', 11, @(x) isempty(x) || isnumeric(x) ); % char
-p.addOptional('ipsign_out', 0, @(x) isempty(x) || (x==0 | x==-1 | x==+1) ); % char
-p.addOptional('b0sign_out', 0, @(x) isempty(x) || (x==0 | x==-1 | x==+1) ); % char
+p.addOptional('cocos_out', 11, @(x) isempty(x) || isnumeric(x) );
+p.addOptional('ipsign_out', 0, @(x) isempty(x) || (isscalar(x) && (x==0 || x==-1 || x==+1)) );
+p.addOptional('b0sign_out', 0, @(x) isempty(x) || (isscalar(x) && (x==0 || x==-1 || x==+1)) );
 p.addOptional('nverbose', 1, @(x) isempty(x) || isnumeric(x) );
 p.addOptional('time_out', [], @(x) isempty(x) || isnumeric(x) );
 p.addOptional('trialindx', [], @(x) isempty(x) || isnumeric(x) );
-- 
GitLab