From 4bce16295e25cfe317be1a625630f5edf36d0524 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <Olivier.Sauter@epfl.ch>
Date: Tue, 20 Apr 2021 14:52:06 +0200
Subject: [PATCH] add nel from fit when fir missing, gas_get for N2

add shot numbers in legend automatically with doplot=-1
---
 matlab/TCV/gdat_tcv.m             | 32 +++++++++++++++++++++++++++++++
 matlab/TCV/tcv_help_parameters.m  |  3 ++-
 matlab/TCV/tcv_requests_mapping.m |  2 +-
 matlab/gdat_plot.m                |  2 +-
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m
index 2d06b8db..06b3bf04 100644
--- a/matlab/TCV/gdat_tcv.m
+++ b/matlab/TCV/gdat_tcv.m
@@ -2018,6 +2018,38 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
       gdat_data.gdat_params.time_out = [];
     end
 
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+   case {'nel'}
+    % line-averaged density
+    sources_avail = {'fir','fit'};
+    if ~isfield(gdat_data.gdat_params,'source') || isempty(gdat_data.gdat_params.source)
+      gdat_data.gdat_params.source = 'fir';
+    end
+    gdat_data.gdat_params.source = lower(gdat_data.gdat_params.source);
+    if ~any(strmatch(gdat_data.gdat_params.source,sources_avail,'exact'))
+      error([gdat_data.gdat_params.source ' not defined, sources_avail = ' sources_avail]);
+    end
+    switch gdat_data.gdat_params.source
+     case 'fit'
+      psitbx01=psitbxtcv(gdat_data.shot,'01',psitbx_str);
+      neft = gdat_tcv(gdat_data.shot,'ne_rho','fit',1);
+      gdat_data.t = neft.fit.t;
+      gdat_data.dim{1} = gdat_data.t;
+      gdat_data.dimunits{1} = 's';
+      gdat_data.units = 'particles/m^3';
+      nel.dim{1} = neft.fit.t';
+      nel.data = ones(size(nel.dim{1}));
+      gdat_data.r_center_chord = 0.903;
+      [ratio,fir_times,z_lineint]=fir_ratio_from_fits(neft.fit.data,neft.fit.x,psitbx01,nel,gdat_data.r_center_chord,gdat_data.t',1,1e3);
+      gdat_data.data = reshape(1./ratio./z_lineint,numel(ratio),1);
+      gdat_data.data_fullpath = ['line-averaged density from fit using ' neft.fit.data_fullpath];
+     otherwise
+      gdat_data.gdat_params.data_request = '\results::fir:n_average';
+      gdat_data = gdat_tcv(gdat_data.shot,gdat_data.gdat_params);
+      ab_index = gdat_tcv(gdat_data.shot,'\diagz::fir_array:center_chord');
+      ab_r = gdat_tcv(gdat_data.shot,'\diagz::fir_array:radii');
+      gdat_data.r_center_chord = ab_r.data(ab_index.data+1);
+    end
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    case {'ne_rho', 'te_rho', 'nete_rho'}
     % if nete_rho, do first ne, then Te later (so fir stuff already done)
diff --git a/matlab/TCV/tcv_help_parameters.m b/matlab/TCV/tcv_help_parameters.m
index e25c436b..2c6c74c0 100644
--- a/matlab/TCV/tcv_help_parameters.m
+++ b/matlab/TCV/tcv_help_parameters.m
@@ -48,7 +48,8 @@ help_struct_all.source = sprintf('%s\n','cxrs: [1 2 3] (default systems);', ...
           'rtc: defined, all, adcs', ...
           'transp: source provides the netcdf file', ...
           'icds: ''ec'', ''nbi'' ', ...
-          'ids_names for request ''ids'' like magnetics, equilibrium, etc');
+          'ids_names: for request ''ids'' like magnetics, equilibrium, etc', ...
+          'nel: ''fir'' (default) or ''fit'' to compute nel from fit');
 help_struct_all.source_ec = sprintf('%s\n','toray (for toray nodes), no other source for eccd yet implemented');
 help_struct_all.source_nbi = sprintf('%s\n','nbi_output_matfilename containing out structure, to be added astra nodes');
 help_struct_all.error_bar = sprintf('%s\n','for ids: choice of nodes fill in and how:', ...
diff --git a/matlab/TCV/tcv_requests_mapping.m b/matlab/TCV/tcv_requests_mapping.m
index c850da91..80f32a3c 100644
--- a/matlab/TCV/tcv_requests_mapping.m
+++ b/matlab/TCV/tcv_requests_mapping.m
@@ -228,7 +228,7 @@ switch lower(data_request)
  case 'nel'
   mapping.timedim = 1;
   mapping.label = 'line-averaged el. density';
-  mapping.method = 'tdi';
+  mapping.method = 'switchcase';
   mapping.expression = '\results::fir:n_average';
  case 'ne_rho'
   mapping.timedim = 2;
diff --git a/matlab/gdat_plot.m b/matlab/gdat_plot.m
index 464fd6c8..ada21523 100644
--- a/matlab/gdat_plot.m
+++ b/matlab/gdat_plot.m
@@ -84,7 +84,7 @@ if all(isfield(gdat_data,{'data','t'})) && ~isempty(gdat_data.data) && ~isempty(
       return
     end
     if ~isfield(gdat_data,'shot'); return; end % allows to plot if just .t and .data exist
-    if strcmp(get(gcf,'nextplot'),'add')
+    if doplot < 0
       title([gdat_data.gdat_params.machine]);
     else
       title([gdat_data.gdat_params.machine ' #' num2str(gdat_data.shot)]);
-- 
GitLab