From a75c8f0ec46fea5bcec3a9dc46b3540510f14be1 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Tue, 18 Jun 2024 13:45:29 +0200
Subject: [PATCH] fix when no EC and ec_inputs=0, fix params and add help

---
 matlab/TCV/gdat_tcv.m            | 9 ++++++---
 matlab/TCV/tcv_help_parameters.m | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m
index 6651cda8..087cc655 100644
--- a/matlab/TCV/gdat_tcv.m
+++ b/matlab/TCV/gdat_tcv.m
@@ -83,6 +83,7 @@ varargout{1}=cell(1,1);
 error_status=1;
 
 % construct main default parameters structure
+% parameters and defaults related to a specific request should be defined in the relevant switch case section
 gdat_params.data_request = '';
 default_machine = 'tcv';
 
@@ -91,7 +92,6 @@ gdat_params.doplot = 0;
 gdat_params.liuqe = 1;
 gdat_params.nverbose = 1;
 gdat_params.trialindx = [];
-gdat_params.ec_inputs = 0;
 
 % construct list of keywords from global set of keywords and specific TCV set
 % get data_request names from centralized table
@@ -1512,7 +1512,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     if ~isempty(gdat_data.gdat_params.trialindx) && gdat_data.gdat_params.trialindx < 0
       gdat_data.gdat_params.trialindx = [];
     end
-
+    % specific parameters check and default settings
     if ~isfield(gdat_data.gdat_params,'source') || isempty(gdat_data.gdat_params.source)
       switch data_request_eff
        case 'ec_data'
@@ -1549,6 +1549,9 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
         end
       end
     end
+    if ~isfield(gdat_data.gdat_params,'ec_inputs') || isempty(gdat_data.gdat_params.ec_inputs) || ~isnumeric(gdat_data.gdat_params.ec_inputs)
+      gdat_data.gdat_params.ec_inputs = 0;
+    end
 
     % create structure for icd sources from params and complete with defaults
     source_icd.ec = 'toray';
@@ -1754,7 +1757,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
           getReport(ME) % without ; to get output
           % try to identify cause of the error
           if ~check_nodes_filled(shot,'toray')
-            if ~any(ec_inputs.launchers_active.data,1)
+            if ~isempty(ec_inputs.launchers_active) && ~any(ec_inputs.launchers_active.data,1)
               msg = 'write_pyro(shot) found NO active launchers, maybe there was no EC in this shot?';
             else
               msg = 'write_pyro(shot) found active launchers, but TORAY nodes are no filled, check hldsi(shot), and (ask to) relaunch TORAY.';
diff --git a/matlab/TCV/tcv_help_parameters.m b/matlab/TCV/tcv_help_parameters.m
index 15de8984..2248c26d 100644
--- a/matlab/TCV/tcv_help_parameters.m
+++ b/matlab/TCV/tcv_help_parameters.m
@@ -39,6 +39,7 @@ help_struct_all.cocos = ['cocos value desired in output, uses eqdsk_cocos_transf
                     'is wanted. See O. Sauter et al Comput. Phys. Commun. 184 (2013) 293'];
 help_struct_all.nrz_out = 'Nb of radial and vertical points in output eqdsk, default is [129,129], set to [-1,-1] to get original meshes';
 help_struct_all.edge = '0 (default), 1 to get edge Thomson values';
+help_struct_all.ec_inputs = '0 (default), 1 to get all characterics ofgyrotrons with specific launchers like freq';
 help_struct_all.fit = '0, no fit profiles, 1 (default) if fit profiles desired as well, relevant for _rho profiles. See also fit_type';
 help_struct_all.fit_type = 'provenance of fitted profiles ''conf'' (default) from conf nodes, ''avg'' or ''local'' for resp. proffit: nodes';
 help_struct_all.trialindx = 'value of trialindx desired to get a specific one when relevant, otherwise gets ok_trialindx, that is 1 usually';
-- 
GitLab