From da02a787f1d089796476d9a0063ee8738bc0c5b4 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Thu, 12 Sep 2024 13:19:54 +0200
Subject: [PATCH] add new array of gas traces and add source for rtc request

---
 matlab/TCV/gdat_tcv.m             | 40 ++++++++++++++++++++++++-------
 matlab/TCV/tcv_requests_mapping.m |  2 +-
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m
index f528917d..a0e28176 100644
--- a/matlab/TCV/gdat_tcv.m
+++ b/matlab/TCV/gdat_tcv.m
@@ -1278,9 +1278,13 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
                     'plot_eqdsk, write_eqdsk, read_eqdsk can be used'];
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-   case {'gas', 'gas_flux', 'gas_request', 'gas_feedforward','gas_valve'}
+   case {'gas', 'gas_flux', 'gas_request', 'gas_feedforward','gas_valve', 'gas_fluxes'}
     params_eff = gdat_data.gdat_params;
-    params_eff.data_request = '\diagz::flux_gaz:piezo_1:flux';
+    if shot <= 82186
+      params_eff.data_request = '\diagz::flux_gaz:piezo_1:flux';
+    else
+      params_eff.data_request = '\atlas::top.system.gas.valve_001:flow'
+    end
     gasflux = gdat_tcv(gdat_data.shot,params_eff);
     gdat_data.gas_flux = gasflux;
     params_eff.data_request = '\hybrid::mat_m_signals:output_019';
@@ -1353,6 +1357,22 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
           end
         end
       end
+     case {'gas_fluxes'}
+       for i=1:20
+         if shot < 78667
+           params_eff.data_request = sprintf('\\draw_feedfor_gas:alim_0%.2d',i);
+         else
+           params_eff.data_request = sprintf('\\draw_refs_gas:ref_0%.2d',i)
+         end
+         gasrequest_ref = gdat_tcv(gdat_data.shot,params_eff); gasrequest_ref.units = 'V';
+         gdat_data_data{i} = gasrequest_ref.data;
+         if ~isempty(gasrequest_ref.t)
+           gdat_data.units = gasrequest_ref.units;
+           gdat_data.t = gasrequest_ref.t;
+           gdat_data.data_fullpath = gasrequest_ref.data_fullpath;
+         end
+       end
+       gdat_data.data = gdat_data_data;
      otherwise
       error('gas option not defined')
     end
@@ -3321,13 +3341,17 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     if isempty(aaa)
       error('no path for get_scd_mems')
     end
-
-    aa = get_scd_mems(shot,gdat_data.gdat_params.source);
-    if isstruct(aa)
-      scd_names = fieldnames(aa);
-      for i=1:length(scd_names)
-        gdat_data.scd_mems.(scd_names{i}) = aa.(scd_names{i});
+    try
+      aa = get_scd_mems(shot,gdat_data.gdat_params.source);
+      if isstruct(aa)
+        scd_names = fieldnames(aa);
+        for i=1:length(scd_names)
+          gdat_data.scd_mems.(scd_names{i}) = aa.(scd_names{i});
+        end
       end
+      gdat_data.data_fullpath = sprintf('used %s with patterns specified in source gdat_params',aaa);
+    catch
+      % to make sure close and disconnect even if error, since connects to scd
     end
     mdsclose;
     mdsdisconnect;
diff --git a/matlab/TCV/tcv_requests_mapping.m b/matlab/TCV/tcv_requests_mapping.m
index 7ac36f74..bb06a26e 100644
--- a/matlab/TCV/tcv_requests_mapping.m
+++ b/matlab/TCV/tcv_requests_mapping.m
@@ -144,7 +144,7 @@ switch lower(data_request)
                    'gdat_tmp=gdat_tcv([],params_eff);aa_data(1,:)=min(gdat_tmp.data,[],1)-0.624;aa_data(1,[aa_data(1,:)<0]) = 0.;' ...
                     'aa_data(2,:)=1.1376-max(gdat_tmp.data,[],1);aa_data(2,[aa_data(2,:)<0]) = 0.;gdat_tmp.data=aa_data;gdat_tmp.x=[1:2];gdat_tmp.dim{1}=gdat_tmp.x;' ...
                    'gdat_tmp.dimunits{1}={''HFS'',''LFS''};gdat_tmp.units=''m'';'];
- case {'gas', 'gas_flux', 'gas_request', 'gas_feedforward','gas_valve'}
+ case {'gas', 'gas_flux', 'gas_request', 'gas_feedforward','gas_valve', 'gas_fluxes'}
   mapping.timedim = 1;
   mapping.label = 'gas flux';
   mapping.method = 'switchcase';
-- 
GitLab