From 778e66ac1880d17c02a6ff4989f50ef69a8edc1d Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Thu, 2 Nov 2017 08:52:44 +0000
Subject: [PATCH] fixed nans in powers and added radiated power from bolo prad
 total, adapted help

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@8818 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/TCV/gdat_tcv.m            | 39 +++++++++++++++++++++++++++----
 crpptbx/TCV/tcv_help_parameters.m |  2 +-
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/crpptbx/TCV/gdat_tcv.m b/crpptbx/TCV/gdat_tcv.m
index 857cbf4b..b2574ee9 100644
--- a/crpptbx/TCV/gdat_tcv.m
+++ b/crpptbx/TCV/gdat_tcv.m
@@ -1111,6 +1111,12 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
         psitdi = tdi(['tcv_eq(''psi'',''LIUQE.M' substr_liuqe_tcv_eq ''')']);
         psiaxis = tdi(['tcv_eq(''psi_axis'',''LIUQE.M' substr_liuqe_tcv_eq ''')']);
       end
+      if numel(psitdi.dim)<1
+        warning('problem with psitdi in gdat_tcv ')
+        psitdi
+        psiaxis
+        return
+      end
       rmesh=psitdi.dim{1};
       zmesh=psitdi.dim{2};
       zthom=mdsdata('dim_of(\thomson:te,1)');
@@ -1333,7 +1339,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
    case {'powers'}
     % note: same time array for all main, ec, ohm, nbi, ...
     % At this stage fill just ech, later add nbi
-    sources_avail = {'ohm','ec','nbi'}; % note should allow ech, nbh, ohmic in parameter sources
+    sources_avail = {'ohm','ec','nbi','rad'}; % note should allow ech, nbh, ohmic in parameter sources
     % create empty structures for all, so in return one always have same substructres
     for i=1:length(sources_avail)
       gdat_data.(sources_avail{i}).data = [];
@@ -1406,7 +1412,8 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     %
     % add each source in main.data, on ohm time array
     gdat_data.t = linspace(gdat_data.ohm.t(1),gdat_data.ohm.t(end),floor(1e4.*(gdat_data.ohm.t(end)-gdat_data.ohm.t(1))))';
-    gdat_data.data(:,1) = interpos(-21,gdat_data.ohm.t,gdat_data.ohm.data,gdat_data.t);
+    ij=[isfinite(gdat_data.ohm.data)];
+    gdat_data.data(:,1) = interpos(-21,gdat_data.ohm.t(ij),gdat_data.ohm.data(ij),gdat_data.t);
     gdat_data.dim{1} = gdat_data.t;
     gdat_data.x(1) = 1;
     gdat_data.label={'P_{ohm}'};
@@ -1471,12 +1478,35 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
           index_for_energy = 33;
           gdat_data.nbi.energy = nbh_data_tdi.data(:,index_for_energy);
           % add to main with linear interpolation and 0 for extrapolated values
-          gdat_data.data(:,end+1) = interpos(-21,gdat_data.nbi.t,gdat_data.nbi.data,gdat_data.t);
+          ij=[isfinite(gdat_data.nbi.data)];
+          gdat_data.data(:,end+1) = interpos(-21,gdat_data.nbi.t(ij),gdat_data.nbi.data(ij),gdat_data.t);
           gdat_data.x(end+1) = size(gdat_data.data,2);
           gdat_data.label{end+1}=gdat_data.nbi.label;
         end
       end
     end
+    %
+    if any(strmatch('rad',gdat_data.gdat_params.source))
+      % RAD
+      nodenameeff='\results::bolo:prad:total';
+      tracetdi=tdi(nodenameeff);
+      if isempty(tracetdi.data) || isempty(tracetdi.dim) || ischar(tracetdi.data)
+        if (gdat_params.nverbose>=1); warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff]); end
+      else
+        gdat_data.rad.data = tracetdi.data*1e3; % at this stage bolo is in kW'
+        gdat_data.rad.units = 'W';
+        gdat_data.rad.dim=tracetdi.dim;
+        gdat_data.rad.dimunits=tracetdi.dimunits;
+        gdat_data.rad.t=tracetdi.dim{1};
+        gdat_data.rad.data_fullpath=[nodenameeff];
+        gdat_data.rad.label='P_{RAD}';
+        gdat_data.rad.help = tracetdi.help;
+        % add to main with linear interpolation and 0 for extrapolated values
+        gdat_data.data(:,end+1) = interpos(-21,gdat_data.rad.t,gdat_data.rad.data(:,end),gdat_data.t);
+        gdat_data.x(end+1) = size(gdat_data.data,2);
+        gdat_data.label{end+1}=gdat_data.rad.label;
+      end
+    end
     % add all to last index of .data(:,i)
     gdat_data.data(:,end+1) = sum(gdat_data.data,2);
     gdat_data.x(end+1) = size(gdat_data.data,2);
@@ -1619,7 +1649,8 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     %
     params_eff.data_request='\results::surface_flux';
     surface_psi=gdat_tcv([],params_eff);
-    [aa,vsurf] = interpos(surface_psi.t,surface_psi.data,-3);
+    ij=[isfinite(surface_psi.data)];
+    [aa,vsurf] = interpos(63,surface_psi.t(ij),surface_psi.data(ij),-3);
     gdat_data.surface_psi = surface_psi.data;
     gdat_data.vsurf = vsurf;
     gdat_data.vsurf_description = ['time derivative from surface_psi, obtained from \results::surface_flux'];
diff --git a/crpptbx/TCV/tcv_help_parameters.m b/crpptbx/TCV/tcv_help_parameters.m
index 0ccd2b0b..bbb70beb 100644
--- a/crpptbx/TCV/tcv_help_parameters.m
+++ b/crpptbx/TCV/tcv_help_parameters.m
@@ -42,7 +42,7 @@ help_struct_all.trialindx = 'value of trialindx desired to get a specific one wh
 help_struct_all.source = sprintf('%s\n','cxrs: [1 2 3] (default systems);', ...
           'sxr: main source: ''MPX'' (default) or ''XTOMO'', case insensitive', ...
           'mhd request: ''23'':23 LFS/HFS (default), ''23full'': 23cm sector 3 and 11, ''0'':z=0 LFS/HFS, ''0full'': 0cm sector 3 and 11', ...
-          'powers: ohmic in any case + ''ec'', ''nbi''', ...
+          'powers: ohmic in any case + ''ec'', ''nbi''', ''rad''', ...
           'rtc: defined, all, adcs');
 help_struct_all.camera = ['sxr: for MPX: ''central'', ''top'' (default), ''bottom'' or ''both'' ; ' ...
                     ' for XTOMO: ''central'' (a central chord only), defaults if empty, [1 3 5] if only camera 1, 3 and 5 are desired'];
-- 
GitLab