From c20f41186d44131e523ff14916b0763f229416c4 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Mon, 28 Sep 2015 16:10:54 +0000
Subject: [PATCH] added cxrs for TCV

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5057 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/TCV/gdat_tcv.m    | 105 +++++++++++++++++++++++++++++---------
 crpptbx/TCV/loadTCVdata.m |  10 ++--
 2 files changed, 85 insertions(+), 30 deletions(-)

diff --git a/crpptbx/TCV/gdat_tcv.m b/crpptbx/TCV/gdat_tcv.m
index 1093b7ad..d5dc66e7 100644
--- a/crpptbx/TCV/gdat_tcv.m
+++ b/crpptbx/TCV/gdat_tcv.m
@@ -509,37 +509,92 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     
    case {'cxrs'}
     %not yet finished, just started
-    return
     % load typical data from cxrs, Ti, ni, vtori and vpoli (if available), as well as zeff from cxrs
     % if 'fit' option is added: 'fit',1, then the fitted profiles are returned
     % 
-    sub_nodes = {'Ti','vi_tor','vi_pol','ni','zeff'}; % first node is also copied into data, choose "default' one
-    % sub_nodes_fit = {'Tifit','vi_torfit','vi_polfit','nifit','zefffit'};
-    params_eff = gdat_data.gdat_params;
+    % sub_nodes names from CXRS_get_profiles function, lower case when used in gdat
+    sub_nodes = {'Ti','vTor','vPol','nC','Zeff'}; % first node is also copied into data, choose "default' one
+    sub_nodes_out = lower({'Ti','vTor','vPol','ni','Zeff'}); % 
+    sub_nodes_units = {'eV','m/s','m/s','m^{-3}',''}; % first node is also copied into data, choose "default' one
     % use A. Karpushov routine to get profiles and then copy the data or the fitted profiles
-    param_cxrs.k_plot=0; param_cxrs.k_debug=0;
-    cxrs_profiles = CXRS_get_profiles(48836,[],[],param_cxrs);
-    if isfield(params_eff,'fit') && params_eff.fit>0
-      sub_nodes_eff = sub_nodes_fit;
+    aa=CXRS_get_profiles; cxrs_params = aa.param;
+    cxrs_params.k_plot=0; cxrs_params.k_debug=0;
+    % add params from gdat call
+    params_eff = gdat_data.gdat_params;
+    if isfield(params_eff,'cxrs_plot') && params_eff.cxrs_plot>0
+      cxrs_plot = params_eff.cxrs_plot;
     else
-      params_eff.fit = 0;
-      sub_nodes_eff = sub_nodes;
+      cxrs_plot = 0;
     end
-
-
-    gdat_data.dim = beta.dim;
-    gdat_data.t = beta.dim{1};
-    gdat_data.data = beta.data;
-    ij=find(~isnan(ip.data));
-    ip_t = interp1(ip.dim{1}(ij),ip.data(ij),gdat_data.t);
-    ij=find(~isnan(b0.data));
-    b0_t = interp1(b0.dim{1}(ij),b0.data(ij),gdat_data.t);
-    ij=find(~isnan(a_minor.data));
-    a_minor_t = interp1(a_minor.dim{1}(ij),a_minor.data(ij),gdat_data.t);
-    gdat_data.data = 100.*beta.data ./ abs(ip_t).*1.e6 .* abs(b0_t) .* a_minor_t;
-    gdat_data.data_fullpath='100*beta/ip*1e6*b0*a_minor, each from gdat_tcv';
-    gdat_data.units = '';
-    gdat_data.dimunits = beta.dimunits;
+    gdat_data.gdat_params.cxrs_plot = cxrs_plot;
+    if isfield(params_eff,'time_interval') && ~isempty(params_eff.time_interval) && length(params_eff.time_interval)>=2
+      time_interval = params_eff.time_interval(1:2);
+      cxrs_plot=1;
+    else
+      time_interval = [];
+    end
+    gdat_data.gdat_params.time_interval = time_interval;
+    gdat_data.gdat_params.cxrs_plot = cxrs_plot;
+    if isfield(params_eff,'fit_tension') && params_eff.fit_tension>0
+      fit_tension = params_eff.fit_tension;
+    else
+      fit_tension = -30.;
+    end
+    gdat_data.gdat_params.fit_tension = fit_tension;
+    cxrs_params.prof.Ti.taus = fit_tension; cxrs_params.prof.vi.taus = fit_tension; cxrs_params.prof.nc.taus = fit_tension; cxrs_params.prof.zeff.taus = fit_tension; 
+    cxrs_params.k_plot = cxrs_plot;
+    cxrs_profiles = CXRS_get_profiles(shot,[1 2 3],time_interval,cxrs_params);
+    inb_times = length(cxrs_profiles.Times);
+    inb_channels =120; % need to change if gets bigger!!! but easier to prefill with NaNs and use the "use" part
+    for i=1:length(sub_nodes)
+      sub_eff = sub_nodes{i};
+      sub_eff_out = sub_nodes_out{i};
+      % fits
+      if isfield(cxrs_profiles.proffit,sub_eff)
+        gdat_data.(sub_eff_out).fit.data = cxrs_profiles.proffit.(sub_eff);
+        gdat_data.(sub_eff_out).fit.rho = cxrs_profiles.proffit.([sub_eff '_rho']);
+        gdat_data.(sub_eff_out).fit.error_bar = cxrs_profiles.proffit.(['d' sub_eff]);
+      else
+        gdat_data.(sub_eff_out).fit.data = [];
+        gdat_data.(sub_eff_out).fit.rho = [];
+        gdat_data.(sub_eff_out).fit.error_bar = [];
+      end
+      % raw data (use all data so keep same size)
+      gdat_data.(sub_eff_out).raw.data = NaN * ones(inb_channels,inb_times);
+      gdat_data.(sub_eff_out).raw.rho = NaN * ones(inb_channels,inb_times);
+      gdat_data.(sub_eff_out).raw.error_bar = NaN * ones(inb_channels,inb_times);
+      gdat_data.(sub_eff_out).raw.error_bar_rho = NaN * ones(inb_channels,inb_times);
+      gdat_data.(sub_eff_out).raw.cxrs_system = NaN * ones(inb_channels,inb_times);
+      gdat_data.time_interval = [];
+      for it=1:inb_times
+        if isfield(cxrs_profiles,sub_eff)
+          nb_raw_points = length(cxrs_profiles.(sub_eff){it}.use.y);
+          gdat_data.(sub_eff_out).raw.data(1:nb_raw_points,it) = cxrs_profiles.(sub_eff){it}.use.y;
+          gdat_data.(sub_eff_out).raw.rho(1:nb_raw_points,it) = cxrs_profiles.(sub_eff){it}.use.x;
+          gdat_data.(sub_eff_out).raw.error_bar(1:nb_raw_points,it) = cxrs_profiles.(sub_eff){it}.use.dy;
+          gdat_data.(sub_eff_out).raw.error_bar_rho(1:nb_raw_points,it) = cxrs_profiles.(sub_eff){it}.use.dx;
+          gdat_data.(sub_eff_out).raw.cxrs_system(1:nb_raw_points,it) = cxrs_profiles.(sub_eff){it}.use.sys;
+          gdat_data.time_interval{it} = cxrs_profiles.(sub_eff){it}.t_lim;
+        end          
+      end
+      gdat_data.(sub_eff_out).units = sub_nodes_units{i};
+      if i==1
+        gdat_data.data = gdat_data.(sub_eff_out).fit.data;
+        gdat_data.x = gdat_data.(sub_eff_out).fit.rho;
+        gdat_data.error_bar = gdat_data.(sub_eff_out).fit.error_bar;
+        gdat_data.units = gdat_data.(sub_eff_out).units;
+      end
+    end
+    gdat_data.cxrs_params = cxrs_profiles.param;
+    gdat_data.t = cxrs_profiles.proffit.time;
+    gdat_data.dim = {gdat_data.x; gdat_data.t};
+    if isempty(time_interval)
+      gdat_data.data_fullpath=['CXRS_get_profiles(' num2str(shot) ',[1 2 3],[],cxrs_params); % with cxrs_params'];
+    else
+      gdat_data.data_fullpath=['CXRS_get_profiles(' num2str(shot) ',[1 2 3],[' num2str(time_interval) '],cxrs_params); % with cxrs_params'];
+    end
+    gdat_data.dimunits{1} = '';
+    gdat_data.dimunits{2} = 's';
     
    case {'eqdsk'}
     %
diff --git a/crpptbx/TCV/loadTCVdata.m b/crpptbx/TCV/loadTCVdata.m
index d027797f..e6a323dd 100644
--- a/crpptbx/TCV/loadTCVdata.m
+++ b/crpptbx/TCV/loadTCVdata.m
@@ -498,7 +498,7 @@ switch TCVkeywrdcase{index}
 
     %  load TCV other data
     if liuqe_version==-1
-      mdsopen( 'pcs', shot); %synthetic shot generated with FBT and MGAMS.
+      mdsopen( 'pcs', shot); %synthetic shot generated with FBTE and MGAMS.
     else
       mdsopen(shot);
       % test if node exists
@@ -1038,7 +1038,7 @@ switch TCVkeywrdcase{index}
   case {'B0'}
     % B0 at R0=0.88
     if liuqe_version==-1
-      % mdsopen( 'pcs', shot); %synthetic shot generated with FBT and MGAMS.
+      % mdsopen( 'pcs', shot); %synthetic shot generated with FBTE and MGAMS.
       mdsopen(shot)
       nodenameeff = 'tcv_eq("BZERO","FBTE")';
       tracetdi=tdi(nodenameeff);
@@ -1068,7 +1068,7 @@ switch TCVkeywrdcase{index}
   case {'qrho'}
     % q profile on psi from liuqe
     if liuqe_version==-1
-      mdsopen( 'pcs', shot); %synthetic shot generated with FBT and MGAMS.
+      mdsopen( 'pcs', shot); %synthetic shot generated with FBTE and MGAMS.
     else
       mdsopen(shot);
     end
@@ -1091,7 +1091,7 @@ switch TCVkeywrdcase{index}
     % vol from psitbx
     if liuqe_version==-1
       begstr = 'tcv_psitbx("';
-      mdsopen( 'pcs', shot); %synthetic shot generated with FBT and MGAMS.
+      mdsopen( 'pcs', shot); %synthetic shot generated with FBTE and MGAMS.
       nodenameeff=[begstr 'vol' endstr];
       tracetdi=tdi(nodenameeff);
     else
@@ -1131,7 +1131,7 @@ switch TCVkeywrdcase{index}
     % vol from psitbx
     if liuqe_version==-1
       begstr = 'tcv_psitbx("';
-      mdsopen( 'pcs', shot); %synthetic shot generated with FBT and MGAMS.
+      mdsopen( 'pcs', shot); %synthetic shot generated with FBTE and MGAMS.
       nodenameeff=[begstr 'vol' endstr];
       tracetdi=tdi(nodenameeff);
     else
-- 
GitLab