From 28c4e950ded91c5f40082d7d3f53a15c3100d709 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <Olivier.Sauter@epfl.ch>
Date: Fri, 17 Mar 2023 13:02:58 +0100
Subject: [PATCH] simplify/fix extra_sf2sig from toki02 with sf2sig, add
 edition in output, need to check with tunnel and mdsplus

---
 matlab/AUG/gdat_aug.m   | 67 +++++++++++++++++++++++++----------------
 matlab/AUG/rdaAUG_eff.m | 50 +++++++++++++++++++++---------
 2 files changed, 76 insertions(+), 41 deletions(-)

diff --git a/matlab/AUG/gdat_aug.m b/matlab/AUG/gdat_aug.m
index 13f5b288..f908886c 100644
--- a/matlab/AUG/gdat_aug.m
+++ b/matlab/AUG/gdat_aug.m
@@ -203,7 +203,7 @@ if (nargin>=ivarargin_first_char)
         varargin_eff{i} = lower(varargin_eff{i});
         % enforce lower case for any character driven input (only for 1st part of pair...)
 % $$$         if ischar(varargin_eff{i+1})
-          gdat_params.(varargin_eff{i}) = varargin_eff{i+1};
+        gdat_params.(varargin_eff{i}) = varargin_eff{i+1};
 % $$$         else
 % $$$           gdat_params.(lower(varargin_eff{i})) = varargin_eff{i+1};
 % $$$         end
@@ -347,6 +347,7 @@ if strcmp(mapping_for_aug.method,'signal')
   if isfield(aatmp,'x'); gdat_data.x = aatmp.x; end
   if isfield(aatmp,'dim'); gdat_data.dim = aatmp.dim; end
   if isfield(aatmp,'dimunits'); gdat_data.dimunits = aatmp.dimunits; end
+  if isfield(aatmp,'edition'); gdat_data.edition = aatmp.edition; end
   gdat_data.data_fullpath=mapping_for_aug.expression;
   if isempty(aatmp.data) || (isempty(gdat_data.t) && isempty(gdat_data.x))
     return
@@ -569,10 +570,6 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       end
       gdat_data.gdat_params.source = sources_in;
     end
-    extra_arg_sf2sig_eff_string = '';
-    if ~strcmp(gdat_data.gdat_params.extra_arg_sf2sig,'[]')
-      extra_arg_sf2sig_eff_string = [',' gdat_data.gdat_params.extra_arg_sf2sig];
-    end
     % set starting source
     i_count = 1;
     diag_name = gdat_data.gdat_params.source{i_count};
@@ -586,9 +583,9 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       z_node = z_node_available{i_source};
       % R, Z positions of measurements
       try
-        % eval(['[r_time]=sf2ab(diag_name,shot,r_node,''-exp'',exp_name_eff' extra_arg_sf2sig_eff_string ');']);
+        % eval(['[r_time]=sf2ab(diag_name,shot,r_node,''-exp'',exp_name_eff' gdat_data.gdat_params.extra_arg_sf2sig ');']);
         % both for CEZ and CMZ, and.. Ti:1 is ok, otherwise introduce string above
-        [r_time,err]=rdaAUG_eff(shot,diag_name,'Ti',exp_name_eff,[],extra_arg_sf2sig_eff_string,['area-base:' r_node ':1']);
+        [r_time,err]=rdaAUG_eff(shot,diag_name,'Ti',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig,['area-base:' r_node ':1']);
       catch ME_R_time
         % assume no shotfile
         disp(getReport(ME_R_time))
@@ -600,9 +597,9 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
         gdat_data.r(inotok) = NaN;
         try
           if [exist('sf2sig')==3]
-            [z_time,err]=rdaAUG_eff(shot,diag_name,'z_time',exp_name_eff,[],extra_arg_sf2sig_eff_string,['area-base:' z_node ':1']);
+            [z_time,err]=rdaAUG_eff(shot,diag_name,'z_time',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig,['area-base:' z_node ':1']);
           else
-            [z_time,err]=rdaAUG_eff(shot,diag_name,'z_time',exp_name_eff,[],extra_arg_sf2sig_eff_string);
+            [z_time,err]=rdaAUG_eff(shot,diag_name,'z_time',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig);
           end
           gdat_data.z = z_time.data;
           inotok=find(gdat_data.z<=0);
@@ -617,9 +614,9 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       end
       if ishotfile_ok == 1
         try
-          % eval(['[time]=sf2tb(diag_name,shot,''time'',''-exp'',exp_name_eff' extra_arg_sf2sig_eff_string ');']);
+          % eval(['[time]=sf2tb(diag_name,shot,''time'',''-exp'',exp_name_eff' gdat_data.gdat_params.extra_arg_sf2sig ');']);
           if [exist('sf2sig')==3]
-            [time,err] = rdaAUG_eff(shot,diag_name,'time',exp_name_eff,[],extra_arg_sf2sig_eff_string,'time-base:time:0');
+            [time,err] = rdaAUG_eff(shot,diag_name,'time',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig,'time-base:time:0');
           else
             time.data = r_time.t;
           end
@@ -660,6 +657,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       a.name = 'vrot';
       if any(strcmp(fieldnames(a),'units')); gdat_data.vrot.units=a.units; end
       if any(strcmp(fieldnames(a),'name')); gdat_data.vrot.name=a.name; end
+      if isfield(a,'edition'); gdat_data.vrot.edition = a.edition; end
       gdat_data.vrot.label = 'vrot_tor';
       % Ti
       %     [a,e]=rdaAUG_eff(shot,diag_name,'Ti',exp_name_eff);
@@ -682,6 +680,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       if any(strcmp(fieldnames(a),'units')); gdat_data.ti.units=a.units; end
       if any(strcmp(fieldnames(gdat_data.ti),'units')); gdat_data.units=gdat_data.ti.units; end
       if any(strcmp(fieldnames(a),'name')); gdat_data.ti.name=a.name; end
+      if isfield(a,'edition'); gdat_data.ti.edition = a.edition; end
       gdat_data.ti.label = 'Ti_c';
       % main node ti a this stage
       gdat_data.data = gdat_data.ti.data;
@@ -926,6 +925,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     gdat_data.x = gdat_data.dim{1};
     gdat_data.t = gdat_data.dim{2};
     gdat_data.dimunits=[{'channels'} ; {'time [s]'}];
+    if isfield(a,'edition'); gdat_data.edition = a.edition; end
     if any(strcmp(fieldnames(a),'units')); gdat_data.units=a.units; end
     try
       [aR,e]=rdaAUG_eff(shot,diag_name,'R-A',exp_name_eff,time_interval,gdat_data.gdat_params.extra_arg_sf2sig);
@@ -1298,6 +1298,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     gdat_data.dim{2} = gdat_data.t;
     gdat_data.dimunits{1} = 'rhopolnorm';
     gdat_data.dimunits{2} = 'time [s]';
+    if isfield(qpsi,'edition'); gdat_data.edition = qpsi.edition; end
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    case {'gas', 'gas_valve', 'gas_valves'}
@@ -1453,6 +1454,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     gdat_data.(lower(node_child_nameeff)).z = repmat(a.data',1,size(gdat_data.(lower(node_child_nameeff)).data,2));
     gdat_data.dimunits=[{'Z [m]'} ; {'time [s]'}];
     gdat_data.data_fullpath=[data_request_eff ' from VTA/' upper(data_request_eff(1)) 'e_c and ' upper(data_request_eff(1)) 'e_e'];
+    if isfield(a,'edition'); gdat_data.edition = a.edition; end
     nb_core = size(gdat_data.(lower(node_child_nameeff)).z,1);
     gdat_data.data = [];
     gdat_data.data(1:nb_core,:) = gdat_data.(lower(node_child_nameeff)).data(1:nb_core,:);
@@ -1467,6 +1469,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     ij_edge_notok = find(a.data>5e21);
     gdat_data.(lower(node_child_nameeff_e)).data(ij_edge_notok) = NaN;
     gdat_data.(lower(node_child_nameeff_e)).t = a.t;
+    if isfield(a,'edition'); gdat_data.(lower(node_child_nameeff_e)).edition = a.edition; end
     if ~isempty(a.data)
       [a,error_status]=rdaAUG_eff(shot,'VTA','R_edge',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig);
       gdat_data.(lower(node_child_nameeff_e)).r = repmat(a.data,size(gdat_data.(lower(node_child_nameeff_e)).data,1),1);
@@ -1911,7 +1914,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       try
         [a,e]=rdaAUG_eff(shot,'ECS',[sys1_source num2str(i)],gdat_data.gdat_params.exp_name,[], ...
           gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'gyr_freq']);
-        % eval(['a = sf2par(''ECS'',shot,''gyr_freq'','sys1_source num2str(i) '''' extra_arg_sf2sig_eff_string ');']);
+        % eval(['a = sf2par(''ECS'',shot,''gyr_freq'','sys1_source num2str(i) '''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
       catch
         % gyr_freq not present (old shots for example)
         a=[];
@@ -1924,7 +1927,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       try
         [a,e]=rdaAUG_eff(shot,'ECS',[sys1_source num2str(i)],gdat_data.gdat_params.exp_name,[], ...
           gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'GPolPos']);
-        % eval(['a = sf2par(''ECS'',shot,''GPolPos'','sys1_source num2str(i) '''' extra_arg_sf2sig_eff_string ');']);
+        % eval(['a = sf2par(''ECS'',shot,''GPolPos'','sys1_source num2str(i) '''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
       catch
         % GPolPos not present
         a=[];
@@ -1937,7 +1940,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       try
         [a,e]=rdaAUG_eff(shot,'ECS',[sys1_source num2str(i)],gdat_data.gdat_params.exp_name,[], ...
           gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'GTorPos']);
-        % eval(['a = sf2par(''ECS'',shot,''GTorPos'','sys1_source num2str(i) '''' extra_arg_sf2sig_eff_string ');']);
+        % eval(['a = sf2par(''ECS'',shot,''GTorPos'','sys1_source num2str(i) '''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
       catch
         a=[];
       end
@@ -1957,11 +1960,17 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
         if max(gdat_data_i.data) > 0.
           labels{i+4} = ['EC_' num2str(i+4)];
         end
+        % add where related to gdat_data.data
+        if isfield(gdat_data_i,'edition')
+          gdat_data.edition = gdat_data_i.edition;
+        elseif isfield(a,'edition')
+          gdat_data.edition = a.edition;
+        end
       end
       try
         [a,e]=rdaAUG_eff(shot,'ECS',['P_sy2_g' num2str(i)],gdat_data.gdat_params.exp_name,[], ...
           gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'gyr_freq']);
-        % eval(['a = sf2par(''ECS'',shot,''gyr_freq'',''P_sy2_g' num2str(i) '''' extra_arg_sf2sig_eff_string ');']);
+        % eval(['a = sf2par(''ECS'',shot,''gyr_freq'',''P_sy2_g' num2str(i) '''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
       catch
         a=[];
       end
@@ -1973,7 +1982,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       try
         [a,e]=rdaAUG_eff(shot,'ECS',['P_sy2_g' num2str(i)],gdat_data.gdat_params.exp_name,[], ...
           gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'GPolPos']);
-        % eval(['a = sf2par(''ECS'',shot,''GPolPos'',''P_sy2_g' num2str(i) '''' extra_arg_sf2sig_eff_string ');']);
+        % eval(['a = sf2par(''ECS'',shot,''GPolPos'',''P_sy2_g' num2str(i) '''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
       catch
         a=[];
       end
@@ -1985,7 +1994,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       try
         [a,e]=rdaAUG_eff(shot,'ECS',['P_sy2_g' num2str(i)],gdat_data.gdat_params.exp_name,[], ...
           gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'GTorPos']);
-        % eval(['a = sf2par(''ECS'',shot,''GTorPos'',''P_sy2_g' num2str(i) '''' extra_arg_sf2sig_eff_string ');']);
+        % eval(['a = sf2par(''ECS'',shot,''GTorPos'',''P_sy2_g' num2str(i) '''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
       catch
         a=[];
       end
@@ -2317,6 +2326,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     gdat_data.dim{2} = gdat_data.t;
     gdat_data.dimunits{1} = 'rhopolnorm';
     gdat_data.dimunits{2} = 'time [s]';
+    if isfield(qpsi,'edition'); gdat_data.edition = qpsi.edition; end
     % add grids_1d to have rhotor, etc
     gdat_data = get_grids_1d(gdat_data,2,1,gdat_params.nverbose);
 
@@ -2358,6 +2368,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       end
       gdat_data.units = psi_tree.units;
       gdat_data.data_fullpath = [DIAG '/PFL extract ' data_request_eff];
+      if isfield(psi_tree,'edition'); gdat_data.edition = psi_tree.edition; end
     end
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -2558,6 +2569,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       end
     end
     gdat_data.data_fullpath = [DIAG '/PFL extract in .data: ' data_request_eff];
+    if isfield(psi_tree,'edition'); gdat_data.edition = psi_tree.edition; end
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    case {'sxr'}
@@ -2680,6 +2692,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     if length(gdat_data.dim)>=1
       gdat_data.x = gdat_data.dim{1};
     end
+    if isfield(a,'edition'); gdat_data.edition = a.edition; end
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    case {'transp'}
@@ -2699,13 +2712,14 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
           abcd = rdaAUG_eff(shot,diagname,transp_sig{i,1},shotfile_exp_eff,[],gdat_data.gdat_params.extra_arg_sf2sig);
           eval(['gdat_data.' transp_sig{i,1} '= abcd;']);
           % eval(['[gdat_data.' transp_sig{i,1} ',e]=rdaAUG_eff(shot,diagname,''' transp_sig{i,1} ''',shotfile_exp_eff);']);
+          if isfield(abcd,'edition'); gdat_data.edition = abcd.edition; end
         catch
           eval(['gdat_data.' transp_sig{i,1} '=[];']);
         end
       elseif strcmp(lower(transp_sig{i,2}),'area-base')
         clear adata_area
         try
-          eval(['[adata_area]=sf2ab(diagname,shot,transp_sig{i,1},''-exp'',shotfile_exp_eff' extra_arg_sf2sig_eff_string  ');']);
+          eval(['[adata_area]=sf2ab(diagname,shot,transp_sig{i,1},''-exp'',shotfile_exp_eff' gdat_data.gdat_params.extra_arg_sf2sig  ');']);
           adata_area.data = adata_area.value{1};
         catch
           adata_area.value = cell(0);
@@ -2714,7 +2728,7 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
       elseif strcmp(lower(transp_sig{i,2}),'time-base')
         clear adata_time
         try
-          eval(['[adata_time]=sf2tb(diagname,shot,transp_sig{i,1},''-exp'',shotfile_exp_eff,shotfile_exp_eff' extra_arg_sf2sig_eff_string ');']);
+          eval(['[adata_time]=sf2tb(diagname,shot,transp_sig{i,1},''-exp'',shotfile_exp_eff,shotfile_exp_eff' gdat_data.gdat_params.extra_arg_sf2sig ');']);
           adata_time.data = adata_time.value;
         catch
           adata_time.value = [];
@@ -2891,24 +2905,24 @@ M_Rmesh = [];
 N_Zmesh = [];
 
 extra_arg_sf2sig_eff_string = '';
-if ~strcmp(gdat_data.gdat_params.extra_arg_sf2sig,'[]')
+if ~strcmp(gdat_data.gdat_params.extra_arg_sf2sig,'[]') && ~strcmp(gdat_data.gdat_params.extra_arg_sf2sig(1),',')
   extra_arg_sf2sig_eff_string = [',' gdat_data.gdat_params.extra_arg_sf2sig];
 end
 shot=gdat_data.shot;
 exp_name_eff = gdat_data.gdat_params.exp_name;
 gdat_data.gdat_params.equil = upper(gdat_data.gdat_params.equil);
 DIAG = gdat_data.gdat_params.equil; % 'EQI' by default at this stage, should become EQH?
-% eval(['M_Rmesh_par = sf2par(DIAG,shot,''M'',''PARMV''' extra_arg_sf2sig_eff_string ');']);
+% eval(['M_Rmesh_par = sf2par(DIAG,shot,''M'',''PARMV''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
 [M_Rmesh_par,e]=rdaAUG_eff(shot,DIAG,'PARMV',gdat_data.gdat_params.exp_name,[], ...
-          extra_arg_sf2sig_eff_string,['param:' 'M']);
+          gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'M']);
 M_Rmesh = M_Rmesh_par.value + 1; % nb of points
-% eval(['N_Zmesh_par = sf2par(DIAG,shot,''N'',''PARMV''' extra_arg_sf2sig_eff_string ');']);
+% eval(['N_Zmesh_par = sf2par(DIAG,shot,''N'',''PARMV''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
 [N_Zmesh_par,e]=rdaAUG_eff(shot,DIAG,'PARMV',gdat_data.gdat_params.exp_name,[], ...
-          extra_arg_sf2sig_eff_string,['param:' 'N']);
+          gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'N']);
 N_Zmesh = N_Zmesh_par.value + 1; % nb of points
-% eval(['NTIME_par = sf2par(DIAG,shot,''NTIME'',''PARMV''' extra_arg_sf2sig_eff_string ');']);
+% eval(['NTIME_par = sf2par(DIAG,shot,''NTIME'',''PARMV''' gdat_data.gdat_params.extra_arg_sf2sig ');']);
 [NTIME_par,e]=rdaAUG_eff(shot,DIAG,'PARMV',gdat_data.gdat_params.exp_name,[], ...
-          extra_arg_sf2sig_eff_string,['param:' 'NTIME']);
+          gdat_data.gdat_params.extra_arg_sf2sig,['param:' 'NTIME']);
 NTIME = NTIME_par.value; % nb of points
 Lpf_par = rdaAUG_eff(shot,DIAG,'Lpf',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig);
 % since June, nb of time points in EQ results is not consistent with NTIME and time
@@ -2941,3 +2955,4 @@ end
 
 [equil_time,e]=rdaAUG_eff(shot,DIAG,'time',exp_name_eff,[],gdat_data.gdat_params.extra_arg_sf2sig);
 gdat_data.t = equil_time.value(1:NTIME);
+if isfield(equil_time,'edition'); gdat_data.edition = equil_time.edition; end
diff --git a/matlab/AUG/rdaAUG_eff.m b/matlab/AUG/rdaAUG_eff.m
index d4df013d..22656480 100644
--- a/matlab/AUG/rdaAUG_eff.m
+++ b/matlab/AUG/rdaAUG_eff.m
@@ -40,6 +40,9 @@ function [adata,error]=rdaAUG_eff(shot,diagname,sigtype,shotfile_exp,varargin);
 %         2D array transposed (assumed were changed from C origin, this way gets usually time as 2nd)
 %
 %global usemdsplus
+
+nverbose = 1;
+
 usemdsplus = ~[exist('sf2sig')==3];
 if ~exist('usemdsplus') || isempty(usemdsplus); usemdsplus=0; end
 error=999;
@@ -56,8 +59,8 @@ adata_area = [];
 adata.time_aug = adata_time;
 adata.area = adata_area;
 adata.exp = shotfile_exp;
-adata.edition_in = [];
-adata.edition_out = [];
+edition_in = []; % for debugging or adding warning if effective edition is different from input
+adata.edition = [];
 
 varargin_eff = varargin;
 nargin_eff = nargin;
@@ -117,6 +120,16 @@ if nargin_eff>=7 && ~isempty(varargin_eff{3}) && ischar(varargin_eff{3}) ...
   end
 end
 did_transpose = 0;
+% extract edition number if provided as '-ed',value in extra_arg_sf2sig
+ij=strfind(extra_arg_sf2sig,'-ed');
+ed_number = '';
+if ~isempty(ij)
+  ed_number = num2str(sscanf(extra_arg_sf2sig(ij+5:end),'%d'));
+end
+if exist('ed_number')
+  edition_in = str2num(ed_number);
+end
+
 if usemdsplus
   % a_remote=mdsremotelist; does not seem sufficient if connection broken, test with 1+2
   is3 = mdsvalue('1+2');
@@ -142,12 +155,6 @@ if usemdsplus
   if ~isempty(ij)
     ask_raw = '"raw"';
   end
-  % extract edition number if provided as '-ed',value in extra_arg_sf2sig
-  ij=strfind(extra_arg_sf2sig,'-ed');
-  ed_number = '';
-  if ~isempty(ij)
-    ed_number = num2str(sscanf(extra_arg_sf2sig(ij+5:end),'%d'));
-  end
   if isempty(time_int)
     tstart = '';
     tend = '';
@@ -203,10 +210,10 @@ if usemdsplus
 
   end
   adata.data=data;
-  if exist('ed_number')
-    adata.edition_in = str2num(ed_number);
+  adata.edition = mdsvalue(['_oed' user diagname]);
+  if nverbose>=1 && adata.edition~=edition_in
+    warning(sprintf('\nedition in = %d is different from output edition: %d\n\n',edition_in,adata.edition));
   end
-  adata.edition_out = mdsvalue(['_oed' user diagname]);
   if mod(error,2)==2; disp(['error even for ' diagname ' ; ' sigtype]); end
   % begin some fix %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   % fix some problems (seems not needed anymore with lxmdsplus.aug.ipp.mpg.de, but do with mdsplus.aug.ipp.mpg.de (so leave for some timing tests)
@@ -265,8 +272,8 @@ if usemdsplus
     eval(['time=mdsvalue(''dim_of(_rdaeff' user diagname ',' num2str(idim_t) ')'');']);
     time = reshape(time,1,length(time));
     adata.dim = {x, time};
-    eval(['xunits=mdsvalue(''units_of(dim_of(_rdaeff' user diagname ',' num2str(idim_x) '))'');']);
-    eval(['tunits=mdsvalue(''units_of(dim_of(_rdaeff' user diagname ',' num2str(idim_t) '))'');']);
+    eval(['xunits=deblank(mdsvalue(''units_of(dim_of(_rdaeff' user diagname ',' num2str(idim_x) '))''));']);
+    eval(['tunits=deblank(mdsvalue(''units_of(dim_of(_rdaeff' user diagname ',' num2str(idim_t) '))''));']);
     adata.dimunits = {xunits, tunits};
 
 % $$$    case 3
@@ -354,6 +361,19 @@ else
       end
     end
 
+    if ~isempty(extra_arg_sf2sig) && ~strcmp(extra_arg_sf2sig,'[]')
+      eval(['[adata_info]=sfinfo(diagname,shot,''-exp'',shotfile_exp,' extra_arg_sf2sig ');']);
+    else
+      [adata_info]=sfinfo(diagname,shot,'-exp',shotfile_exp);
+    end
+    if isfield(adata_info,'id')
+      islash=findstr(adata_info.id,'/');
+      if ~isempty(islash) adata.edition = str2double(adata_info.id(islash(end)+1:end)); end
+      if nverbose>=1 && (~isempty(edition_in) && adata.edition~=edition_in)
+        warning(sprintf('\nedition in = %d is different from output edition: %d\n\n',edition_in,adata.edition));
+      end
+    end
+
     if isempty(adata.data)
       return
     end
@@ -421,7 +441,7 @@ else
       end
     end
     adata.units = adata.unit;
-  elseif isempty(param_set_name) && ~area_base && ~time_base
+elseif isempty(param_set_name) && ~area_base && ~time_base
     % use sf2par
     try
       if ~isempty(extra_arg_sf2sig) && ~strcmp(extra_arg_sf2sig,'[]')
@@ -486,7 +506,7 @@ if isfield(adata,'x') && ~isempty(adata.x) && sum([size(adata.x)>1]) == 2 && sum
     end
   end
 end
-  
+
 if strcmp(upper(sigtype),'PNIQ')
   % transform 4x2 PINIs in 1:8 PINIs and total in index=9
   if (prod(size(adata.data))/length(adata.t) == 8)
-- 
GitLab