From fe06b174a0c5d241086757ed53ba0ca3866bcd47 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <Olivier.Sauter@epfl.ch>
Date: Wed, 28 Apr 2021 13:56:13 +0200
Subject: [PATCH] add consistent r_thomson, z_thomson with edge for old shots

---
 matlab/TCV/gdat_tcv.m | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m
index 8cbfda73..ea381317 100644
--- a/matlab/TCV/gdat_tcv.m
+++ b/matlab/TCV/gdat_tcv.m
@@ -2098,8 +2098,6 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     % Add the results to the output of gdat
     gdat_data.psiscatvol = psiscatvol;
     gdat_data.psi_max = psi_max;
-    r_thomson = gdat_tcv(gdat_data.shot,'\DIAGZ::THOMSON_SET_UP:RADIAL_POS');
-    gdat_data.r_thomson = r_thomson;
 
     if ~isempty(psiscatvol.data) && ~ischar(psiscatvol.data) && ~isempty(psi_max.data) && ~ischar(psi_max.data)
       psi_norm = 1.-psiscatvol.data./repmat(psi_max.data(:).',[size(psiscatvol.data,1),1]);
@@ -2116,11 +2114,11 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
       r_edge = gdat(gdat_data.shot,params_eff);
       params_eff.data_request='z_contour_edge';
       z_edge = gdat(gdat_data.shot,params_eff);
-      z_thomson = psiscatvol.dim{1};
+      gdat_data.z_thomson = gdat_data.dim{1};
       psinorm_max = max(max(psi_norm));
       for it=1:numel(psiscatvol.dim{2})
         iteq=iround_os(r_edge.t,psiscatvol.dim{2}(it));
-        inpol=inpolygon(r_thomson.data,z_thomson,r_edge.data(:,iteq),z_edge.data(:,iteq));
+        inpol=inpolygon(gdat_data.r_thomson,gdat_data.z_thomson,r_edge.data(:,iteq),z_edge.data(:,iteq));
         is_private_flux = [psi_norm(:,it) < 1] & ~inpol;
         % at this stage set private flux "rho" to max, could use 1.3^2
         psi_norm(is_private_flux,it) = psinorm_max;
@@ -3541,6 +3539,7 @@ for is = 1:nsys
   tracestd=tdi(['\results::thomson'  edge_str ':' data_request_eff(1:2) ':error_bar']);
   data_tmp(is).error_bar=tracestd.data';
   data_tmp(is).data_fullpath=nodenameeff;
+  data_tmp(is).r_thomson = mdsdata(['\diagz::thomson_set_up' edge_str ':radial_pos']);
   z=mdsdata(['\diagz::thomson_set_up' edge_str ':vertical_pos']);
   data_tmp(is).dim={z,time};
   data_tmp(is).units=tracetdi.units;
@@ -3563,6 +3562,8 @@ gdat_data.x = gdat_data.dim{1};
 gdat_data.t = time;
 gdat_data.system=vertcat(data_tmp.system);
 if status_any,gdat_data.units = data_tmp(isys_ref).units;end
+r_thomson = arrayfun(@(x) x.r_thomson, data_tmp, 'UniformOutput', false);
+gdat_data.r_thomson = vertcat(r_thomson{:});
 
 % add fir if ne requested
 if strcmp(data_request_eff(1:2),'ne')
-- 
GitLab