From cc236eb295ed625af2e6acf02d5e956a24cb75f1 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Thu, 18 Feb 2016 18:08:04 +0000
Subject: [PATCH] clean list of data_requests now automatic from
 gdat_machine.m, add volume_rho, rhotor, etc in gdat_aug, improve CEZ gui

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5488 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/AUG/CEZ_CMZ_fit.m                     |   2 +-
 crpptbx/AUG/CEZ_CMZ_guiplot.m                 |  10 +-
 crpptbx/AUG/aug_requests_mapping.m            |   6 +-
 crpptbx/AUG/gdat_aug.m                        | 106 +++++++++++++-----
 crpptbx/JET/gdat_jet.m                        |   3 +-
 crpptbx/TCV/gdat_tcv.m                        |   3 +-
 .../get_data_request_names_from_gdat_xxx.m    |  42 +++++++
 7 files changed, 139 insertions(+), 33 deletions(-)
 create mode 100644 crpptbx/get_data_request_names_from_gdat_xxx.m

diff --git a/crpptbx/AUG/CEZ_CMZ_fit.m b/crpptbx/AUG/CEZ_CMZ_fit.m
index 847b64e4..43b7814f 100644
--- a/crpptbx/AUG/CEZ_CMZ_fit.m
+++ b/crpptbx/AUG/CEZ_CMZ_fit.m
@@ -10,7 +10,7 @@ if exist(filename_data,'file')
 else
   cxrs=gdat(shot,'cxrs_rho','doplot',1);
   cmz=gdat(shot,'cxrs_rho','doplot',1,'source','cmz');
-  eval(['save ' filename_data])
+  eval(['save ' filename_data ' cxrs cmz'])
 end
 cez_cmz_data = [];
 cez_cmz_fit = [];
diff --git a/crpptbx/AUG/CEZ_CMZ_guiplot.m b/crpptbx/AUG/CEZ_CMZ_guiplot.m
index 3066c2d4..e43c8590 100644
--- a/crpptbx/AUG/CEZ_CMZ_guiplot.m
+++ b/crpptbx/AUG/CEZ_CMZ_guiplot.m
@@ -55,6 +55,11 @@ function CEZ_CMZ_guiplot_OpeningFcn(hObject, eventdata, handles, varargin)
 % Choose default command line output for CEZ_CMZ_guiplot
 handles.output = hObject;
 
+% change defaults here to avoid changing .fig too much:
+tension_ti_def = str2double(get(handles.set_tension_ti,'string'));
+tension_ti_def_eff = -1;
+set(handles.set_tension_ti,'string',num2str(tension_ti_def_eff));
+
 handles = init_CEZ_gui(handles);
 
 % Update handles structure
@@ -253,7 +258,8 @@ try
   else
     time = str2num(time_prev);
     handles.it_index = iround_os(handles.data.time,time);
-    time_slide = (time-handles.data.time(1))./(handles.data.time(end)-handles.data.time(1)).*diff(handles.slider_range) + handles.slider_range(1);
+    time_slide = abs((time-handles.data.time(1))./(handles.data.time(end)-handles.data.time(1)).*diff(handles.slider_range) + handles.slider_range(1));
+    if time_slide>1; time_slide=1; end
     set(handles.time_set_slider,'Value',time_slide);
   end
   
@@ -280,6 +286,7 @@ function set_tension_ti_Callback(hObject, eventdata, handles)
 % Hints: get(hObject,'String') returns contents of set_tension_ti as text
 %        str2double(get(hObject,'String')) returns contents of set_tension_ti as a double
 
+set_shot_Callback(hObject, eventdata, handles);
 
 % --- Executes during object creation, after setting all properties.
 function set_tension_ti_CreateFcn(hObject, eventdata, handles)
@@ -303,6 +310,7 @@ function set_tension_vrot_Callback(hObject, eventdata, handles)
 % Hints: get(hObject,'String') returns contents of set_tension_vrot as text
 %        str2double(get(hObject,'String')) returns contents of set_tension_vrot as a double
 
+set_shot_Callback(hObject, eventdata, handles);
 
 % --- Executes during object creation, after setting all properties.
 function set_tension_vrot_CreateFcn(hObject, eventdata, handles)
diff --git a/crpptbx/AUG/aug_requests_mapping.m b/crpptbx/AUG/aug_requests_mapping.m
index 796d2926..6a723708 100644
--- a/crpptbx/AUG/aug_requests_mapping.m
+++ b/crpptbx/AUG/aug_requests_mapping.m
@@ -238,11 +238,15 @@ switch lower(data_request)
  case 'rhotor'
   mapping.timedim = 2;
   mapping.method = 'switchcase';
-  mapping.label = 'rhotor\_norm';
+  mapping.label = 'rhotor';
  case 'rhotor_edge'
   mapping.timedim = 1;
   mapping.method = 'switchcase';
   mapping.label = 'rhotor\_edge';
+ case 'rhotor_norm'
+  mapping.timedim = 1;
+  mapping.method = 'switchcase';
+  mapping.label = 'rhotor\_norm';
  case 'rhovol'
   mapping.timedim = 2;
   mapping.label = 'rhovol\_norm';
diff --git a/crpptbx/AUG/gdat_aug.m b/crpptbx/AUG/gdat_aug.m
index 3b77c8a0..86f28092 100644
--- a/crpptbx/AUG/gdat_aug.m
+++ b/crpptbx/AUG/gdat_aug.m
@@ -73,7 +73,8 @@ gdat_params.nverbose = 1;
 
 % construct list of keywords from global set of keywords and specific AUG set
 % get data_request names from centralized table
-data_request_names = get_data_request_names;
+%%% data_request_names = get_data_request_names; % do not use xlsx anymore but scan respective machine_requests_mapping.m files
+data_request_names = get_data_request_names_from_gdat_xxx(default_machine);
 % add AUG specific to all:
 if ~isempty(data_request_names.aug)
   aug_names = fieldnames(data_request_names.aug);
@@ -1619,44 +1620,93 @@ elseif strcmp(mapping_for_aug.method,'switchcase')
     end
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-   case {'rho_tor', 'rhotor_edge', 'rhovol', 'volume_rho'}
+   case {'rhotor', 'rhotor_edge', 'rhotor_norm', 'rhovol', 'volume_rho'}
     if strcmp(upper(gdat_data.gdat_params.equil),'FPG')
       gdat_params_prev = gdat_data.gdat_params; gdat_params_eff = gdat_params_prev;
-      gdat_params_eff.data_request = [{'FPG'},{'fax-bnd'},{'AUGD'}];
+      gdat_params_eff.data_request = [{'FPG'},{'Vol'},{'AUGD'}];
       gdat_data = gdat_aug(gdat_data.shot,gdat_params_eff);
       gdat_data.gdat_params = gdat_params_prev;
-      gdat_data.label = 'psi\_axis-psi\_edge';
-      gdat_data.data_fullpath = [gdat_data.data_fullpath ' yields only psi\_axis-psi\_edge from FPG/fax-bnd'];
+      gdat_data.label = 'Vol';
+      gdat_data.data_fullpath = [gdat_data.data_fullpath ' yields only edge Volume from FPG/Vol'];
+      return
+    end
+    [gdat_data,exp_name_eff,DIAG,NTIME_Lpf,NTIME,Lpf1_t,Lpf_SOL] = get_EQ_params(gdat_data);
+    % since Lpf depends on time, need to load all first and then loop over time for easier mapping
+    [phi_tree,e]=rdaAUG_eff(shot,DIAG,'TFLx',exp_name_eff);
+    ndimrho = size(phi_tree.data,2);
+    if ndimrho==NTIME_Lpf
+      % data seems to be transposed
+      ndimrho = size(phi_tree.data,1);
+      itotransposeback = 1; % seems x,time inverted so transpose and exchange .x and .t
     else
-      [gdat_data,exp_name_eff,DIAG,NTIME_Lpf,NTIME,Lpf1_t,Lpf_SOL] = get_EQ_params(gdat_data);
-      % since Lpf depends on time, need to load all first and then loop over time for easier mapping
-      [psi_tree,e]=rdaAUG_eff(shot,DIAG,'PFL',exp_name_eff);
-      ndimrho = size(psi_tree.data,2);
-      if ndimrho==NTIME_Lpf
-	% data seems to be transposed
-	ndimrho = size(psi_tree.data,1);
-	itotransposeback = 1; % seems x,time inverted so transpose and exchange .x and .t
-      else
-	itotransposeback = 0;
+      itotransposeback = 0;
+    end
+    phi_tree=adapt_rda(phi_tree,NTIME,ndimrho,itotransposeback);
+    ijnan=find(isnan(phi_tree.value));
+    phi_tree.value(ijnan)=0;
+    [Vol,e]=rdaAUG_eff(shot,DIAG,'Vol',exp_name_eff);
+    Vol=adapt_rda(Vol,NTIME,2*ndimrho,itotransposeback);
+    [psi_tree,e]=rdaAUG_eff(shot,DIAG,'PFL',exp_name_eff);
+    psi_tree=adapt_rda(psi_tree,NTIME,ndimrho,itotransposeback);
+    %
+    switch data_request_eff
+     case {'volume_rho', 'rhovol'}
+      for it=1:NTIME
+	Lpf1 = Lpf1_t(it);
+	psi_it=psi_tree.value(it,Lpf1:-1:1)';
+	psi_axis(it)= psi_it(1);
+	psi_lcfs(it)= psi_it(end);
+	gdat_data.x(:,it) = sqrt(abs((psi_it-psi_axis(it)) ./(psi_lcfs(it)-psi_axis(it))));
+	gdat_data.vol(:,it)=Vol.value(it,2*Lpf1-1:-2:1)'; 
+	% gdat_data.dvoldpsi(:,it)=Vol.value(it,2*Lpf1:-2:2)'; % 2nd index are dV/dpsi
+	gdat_data.rhovolnorm(:,it) = sqrt(abs(gdat_data.vol(:,it) ./ gdat_data.vol(end,it)));
       end
-      psi_tree=adapt_rda(psi_tree,NTIME,ndimrho,itotransposeback);
-      ijnan=find(isnan(psi_tree.value));
-      psi_tree.value(ijnan)=0;
-      gdat_data.dim{1} = gdat_data.t;
-      gdat_data.dimunits{1} = 'time [s]';
+      gdat_data.dim{1} = gdat_data.x;
+      gdat_data.dim{2} = gdat_data.t;
+      gdat_data.dimunits{1} = 'rhopolnorm';
+      gdat_data.dimunits{2} = 'time [s]';
+      if strcmp(data_request_eff,'volume_rho')
+	gdat_data.data = gdat_data.vol;
+	gdat_data.units = Vol.units;
+      else strcmp(data_request_eff,'rhovol')
+	gdat_data.data = gdat_data.rhovolnorm;
+	gdat_data.units = ' ';
+      end
+     case {'rhotor', 'rhotor_edge', 'rhotor_norm'}
+      b0=gdat(shot,'b0');
+      gdat_data.b0 = interpos(b0.t,b0.data,gdat_data.t,-1);
       for it=1:NTIME
 	Lpf1 = Lpf1_t(it);
+	gdat_data.phi(:,it) = phi_tree.value(it,Lpf1:-1:1)';
+	gdat_data.rhotornorm(:,it) = sqrt(abs(gdat_data.phi(:,it) ./ gdat_data.phi(end,it)));
+	gdat_data.rhotor(:,it) = sqrt(abs(gdat_data.phi(:,it) ./ gdat_data.b0(it) ./ pi));
 	psi_it=psi_tree.value(it,Lpf1:-1:1)';
-	if strcmp(data_request_eff,'psi_axis')
-	  gdat_data.data(it)= psi_it(1);
-	elseif strcmp(data_request_eff,'psi_edge')
-	  gdat_data.data(it)= psi_it(end);
-	else
-	end
+	psi_axis(it)= psi_it(1);
+	psi_lcfs(it)= psi_it(end);
+	gdat_data.x(:,it) = sqrt(abs((psi_it-psi_axis(it)) ./(psi_lcfs(it)-psi_axis(it))));
+      end
+      if strcmp(data_request_eff,'rhotor')
+	gdat_data.data = gdat_data.rhotor;
+	gdat_data.units = 'm';
+	gdat_data.dim{1} = gdat_data.x;
+	gdat_data.dim{2} = gdat_data.t;
+	gdat_data.dimunits{1} = 'rhopolnorm';
+	gdat_data.dimunits{2} = 'time [s]';
+      elseif strcmp(data_request_eff,'rhotor_edge')
+	gdat_data.data = gdat_data.rhotor(end,:);
+	gdat_data.units = 'm';
+	gdat_data.dim{1} = gdat_data.t;
+	gdat_data.dimunits{1} = 'time [s]';
+      elseif strcmp(data_request_eff,'rhotor_norm')
+	gdat_data.data = gdat_data.rhotornorm;
+	gdat_data.units = ' ';
+	gdat_data.dim{1} = gdat_data.x;
+	gdat_data.dim{2} = gdat_data.t;
+	gdat_data.dimunits{1} = 'rhopolnorm';
+	gdat_data.dimunits{2} = 'time [s]';
       end
-      gdat_data.units = psi_tree.units;
-      gdat_data.data_fullpath = [DIAG '/PFL extract ' data_request_eff];
     end
+    gdat_data.data_fullpath = [DIAG '/PFL extract in .data: ' data_request_eff];
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    case {'sxr'}
diff --git a/crpptbx/JET/gdat_jet.m b/crpptbx/JET/gdat_jet.m
index 5c3bcc7c..f289ddce 100644
--- a/crpptbx/JET/gdat_jet.m
+++ b/crpptbx/JET/gdat_jet.m
@@ -73,7 +73,8 @@ gdat_params.nverbose = 1;
 
 % construct list of keywords from global set of keywords and specific JET set
 % get data_request names from centralized table
-data_request_names = get_data_request_names;
+%%% data_request_names = get_data_request_names; % do not use xlsx anymore but scan respective machine_requests_mapping.m files
+data_request_names = get_data_request_names_from_gdat_xxx(default_machine);
 % add JET specific to all:
 if ~isempty(data_request_names.jet)
   jet_names = fieldnames(data_request_names.jet);
diff --git a/crpptbx/TCV/gdat_tcv.m b/crpptbx/TCV/gdat_tcv.m
index f37c0abb..5eb934dd 100644
--- a/crpptbx/TCV/gdat_tcv.m
+++ b/crpptbx/TCV/gdat_tcv.m
@@ -72,7 +72,8 @@ gdat_params.nverbose = 1;
 
 % construct list of keywords from global set of keywords and specific TCV set
 % get data_request names from centralized table
-data_request_names = get_data_request_names;
+%%% data_request_names = get_data_request_names; % do not use xlsx anymore but scan respective machine_requests_mapping.m files
+data_request_names = get_data_request_names_from_gdat_xxx(default_machine);
 % add TCV specific to all:
 if ~isempty(data_request_names.tcv)
   tcv_names = fieldnames(data_request_names.tcv);
diff --git a/crpptbx/get_data_request_names_from_gdat_xxx.m b/crpptbx/get_data_request_names_from_gdat_xxx.m
new file mode 100644
index 00000000..427ac9bc
--- /dev/null
+++ b/crpptbx/get_data_request_names_from_gdat_xxx.m
@@ -0,0 +1,42 @@
+function [data_request_names] = get_data_request_names_from_gdat_xxx(machine_in);
+%
+% get list of presently available data_request names grouped and with description
+%
+% at this stage using first 3 columns of file gdat_data_request_names.xlsx
+%
+
+data_request_names = [];
+
+expected_machines = [{'aug'}, {'jet'}, {'tcv'}]; % substrutures created for these at this stage (all means all of these)
+for j=1:length(expected_machines)
+  data_request_names.(expected_machines{j}) = [];
+end
+ij=strmatch(lower(machine_in),expected_machines);
+if isempty(ij)
+  disp(['machine ' machine_in ' not expected in get_data_request_names_from_gdat_xxx'])
+  return
+end
+machine_in = lower(machine_in);
+fid=fopen([machine_in '_requests_mapping.m'],'r');
+nextline=fgetl(fid);
+keywds = [];
+while isempty(nextline) || ~isnumeric(nextline) || nextline~=-1 %length(nextline)>2 || ~strcmp(nextline,'-1')
+  if length(nextline)>7 && strcmp(nextline(1:6),' case ')
+    ij=find(nextline==['''']);
+    if ~isempty(ij)
+      for i=1:2:length(ij)-1
+	keywds_next = nextline(ij(i)+1:ij(i+1)-1);
+	i_backslash = find(keywds_next=='\');
+	i_column = find(keywds_next==':');
+	if isempty(i_backslash) && isempty(i_column)
+	  keywds{end+1} = keywds_next;
+	  data_request_names.(machine_in).(keywds{end}) = keywds{end};
+	end
+      end
+    end
+  end
+  nextline=fgetl(fid);
+end
+fclose(fid);
+data_request_names.all = [];
+
-- 
GitLab