From d9cc849612997105d80ca58328d42f56e09b258e Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Sat, 12 Oct 2024 11:18:07 +0200
Subject: [PATCH] update source loaded in neint_ts

---
 matlab/D3D/gdat_d3d.m | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/matlab/D3D/gdat_d3d.m b/matlab/D3D/gdat_d3d.m
index b4b2d29e..83e1daa7 100644
--- a/matlab/D3D/gdat_d3d.m
+++ b/matlab/D3D/gdat_d3d.m
@@ -715,6 +715,12 @@ elseif strcmp(mapping_for_d3d.method,'switchcase')
 
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     case {'equil'}
+      if isfield(gdat_data.gdat_params,'source') && ~isempty(gdat_data.gdat_params.source) && ischar(gdat_data.gdat_params.source) && strcmp(lower(gdat_data.gdat_params.equil),'efit01')
+        % assume source provided instead of equil for choice of equil, since equil=default and source provided
+        warning('choice of equil should be provided in ''equil'' not in ''source'', moved entry')
+        gdat_data.gdat_params.equil = gdat_data.gdat_params.source;
+        gdat_data.gdat_params = rmfield(gdat_data.gdat_params,'source');
+      end
       if ~isfield(gdat_data.gdat_params,'equil') || isempty(gdat_data.gdat_params.equil) || ~ischar(gdat_data.gdat_params.equil)
         gdat_data.gdat_params.equil = 'efit03';
       else
@@ -1052,11 +1058,16 @@ elseif strcmp(mapping_for_d3d.method,'switchcase')
         return
       end
       % add rho coordinates
-      params_eff.data_request='equil';
-      [equil,params_equil,error_status]=gdat_d3d(shot,params_eff);
-      if error_status>0
-        if gdat_params.nverbose>=3; disp(['problems with ' params_eff.data_request]); end
-        return
+      if ~isfield(gdat_data.gdat_params,'equil') || isempty(gdat_data.gdat_params.equil) || ~isstruct(gdat_data.gdat_params.equil)
+        params_eff.data_request='equil';
+        [equil,params_equil,error_status]=gdat_d3d(shot,params_eff);
+        if error_status>0
+          if gdat_params.nverbose>=3; disp(['problems with ' params_eff.data_request]); end
+          return
+        end
+      else
+        params_equil.equil = gdat_data.gdat_params.equil.gdat_params.equil;
+        equil = gdat_data.gdat_params.equil;
       end
       gdat_data.gdat_params.equil = params_equil.equil;
       gdat_data.equil = equil;
@@ -1090,9 +1101,9 @@ elseif strcmp(mapping_for_d3d.method,'switchcase')
                 rhopolnorm_out_core(:,it_core_inequil) = sqrt((psi_out_core(:,it_core_inequil)-equil.psi_axis(itequil))./(equil.psi_lcfs(itequil)-equil.psi_axis(itequil)));
                 for it_cx=1:length(it_core_inequil)
                   rhotornorm_out_core(:,it_core_inequil(it_cx)) = ...
-                    interpos(equil.rhopolnorm(:,itequil),equil.rhotornorm(:,itequil),rhopolnorm_out_core(:,it_core_inequil(it_cx)),-3,[2 2],[0 1]);
+                      interpos(equil.rhopolnorm(:,itequil),equil.rhotornorm(:,itequil),rhopolnorm_out_core(:,it_core_inequil(it_cx)),-3,[2 2],[0 1]);
                   rhovolnorm_out_core(:,it_core_inequil(it_cx)) = ...
-                    interpos(equil.rhopolnorm(:,itequil),equil.rhovolnorm(:,itequil),rhopolnorm_out_core(:,it_core_inequil(it_cx)),-3,[2 2],[0 1]);
+                      interpos(equil.rhopolnorm(:,itequil),equil.rhovolnorm(:,itequil),rhopolnorm_out_core(:,it_core_inequil(it_cx)),-3,[2 2],[0 1]);
                 end
               end
             end
-- 
GitLab