From 6afdbca1234b7156f2059e746eecdb239ec5e86d Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Wed, 30 Sep 2015 12:25:47 +0000
Subject: [PATCH] add nverbose and fix some problems

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5077 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/TCV/gdat_tcv.m            | 100 ++++++++++++++++++------------
 crpptbx/TCV/tcv_help_parameters.m |   3 +-
 2 files changed, 62 insertions(+), 41 deletions(-)

diff --git a/crpptbx/TCV/gdat_tcv.m b/crpptbx/TCV/gdat_tcv.m
index 0824d4c8..62815d56 100644
--- a/crpptbx/TCV/gdat_tcv.m
+++ b/crpptbx/TCV/gdat_tcv.m
@@ -60,7 +60,6 @@ function [gdat_data,gdat_params,error_status,varargout] = gdat_tcv(shot,data_req
 
 varargout{1}=cell(1,1);
 error_status=1;
-nverbose = 1;
 
 % construct default parameters structure
 gdat_params.data_request = '';
@@ -69,6 +68,7 @@ default_machine = 'tcv';
 gdat_params.machine=default_machine;
 gdat_params.doplot = 0;
 gdat_params.liuqe = 1;
+gdat_params.nverbose = 1;
 
 % construct list of keywords from global set of keywords and specific TCV set
 % get data_request names from centralized table
@@ -129,7 +129,7 @@ if nargin>=1
   elseif ischar(shot)
     ivarargin_first_char = 1;
   else
-    warning('type of 1st argument unexpected, should be numeric or char')
+    if gdat_params.nverbose>=1; warning('type of 1st argument unexpected, should be numeric or char'); end
     error_status=2;
     return
   end
@@ -146,7 +146,7 @@ if nargin>=2 && ivarargin_first_char~=1
   % 2nd arg can be a structure with all options except shot_number, or a string for the pathname or keyword, or the start of pairs string/value for the parameters
   if isstruct(data_request)
     if ~isfield(data_request,'data_request')
-      warning('expects field data_request in input parameters structure')
+      if gdat_params.nverbose>=1; warning('expects field data_request in input parameters structure'); end
       error_status=3;
       return
     end
@@ -192,13 +192,13 @@ if (nargin>=ivarargin_first_char)
           gdat_params.(lower(varargin_eff{i})) = varargin_eff{i+1};
         end
       else
-        warning(['input argument nb: ' num2str(i) ' is incorrect, expects a character string'])
+        if gdat_params.nverbose>=1; warning(['input argument nb: ' num2str(i) ' is incorrect, expects a character string']); end
         error_status=401;
         return
       end
     end
   else
-    warning('number of input arguments incorrect, cannot make pairs of parameters')
+    if gdat_params.nverbose>=1; warning('number of input arguments incorrect, cannot make pairs of parameters'); end
     error_status=402;
     return
   end
@@ -268,7 +268,7 @@ if do_mdsopen_mdsclose
     ishot = mdsopen(shot); % if ishot equal to shot, then mdsclose at the end
   end
   if ishot~=shot
-    warning(['cannot open shot= ' num2str(shot)])
+    if gdat_params.nverbose>=1; warning(['cannot open shot= ' num2str(shot)]); end
     return
   end
 end
@@ -306,7 +306,8 @@ if strcmp(mapping_for_tcv.method(1:3),'tdi')
     aatmp=eval(eval_expr);
   end
   if isempty(aatmp.data) || isempty(aatmp.dim) % || ischar(aatmp.data) (to add?)
-    if (nverbose>=3); warning(['problems loading data for ' eval_expr ' for data_request= ' data_request_eff]); end
+    if (gdat_params.nverbose>=1); warning(['problems loading data for ' eval_expr ' for data_request= ' data_request_eff]); end
+    if (gdat_params.nverbose>=3); disp('check .gdat_request list'); end
     return
   end
   gdat_data.data = aatmp.data;
@@ -386,13 +387,13 @@ elseif strcmp(mapping_for_tcv.method,'expression')
   % eval_expr = [mapping_for_tcv.expression ';'];
   eval([mapping_for_tcv.expression ';']);
   if isempty(gdat_tmp) || (~isstruct(gdat_tmp) & ~isobject(gdat_tmp))
-    warning(['expression does not create a gdat_tmp structure: ' mapping_for_tcv.expression])
+    if (gdat_params.nverbose>=1); warning(['expression does not create a gdat_tmp structure: ' mapping_for_tcv.expression]); end
     error_status=801;
     return
   end
   tmp_fieldnames = fieldnames(gdat_tmp);
   if sum(strcmp(tmp_fieldnames,'data'))==0 % note: cannot do isfield since gdat_tmp might be an object
-    warning(['expression does not return a child name ''data'' for ' data_request_eff])
+    if (gdat_params.nverbose>=1); warning(['expression does not return a child name ''data'' for ' data_request_eff]); end
   end
   for i=1:length(tmp_fieldnames)
     gdat_data.(tmp_fieldnames{i}) = gdat_tmp.(tmp_fieldnames{i});
@@ -437,8 +438,16 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     % compute average minor or major radius (on z=zaxis normally)
     nodenameeff=['\results::r_max_psi' substr_liuqe];
     rmaxpsi=tdi(nodenameeff);
+    if isempty(rmaxpsi.data) || isempty(rmaxpsi.dim) || ~any(~isnan(rmaxpsi.data)) % || ischar(rmaxpsi.data) (to add?)
+      if (gdat_params.nverbose>=1); warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff]); end
+      return
+    end   
     nodenameeff2=['\results::r_min_psi' substr_liuqe];
     rminpsi=tdi(nodenameeff2);
+    if isempty(rminpsi.data) || isempty(rminpsi.dim) || ~any(~isnan(rminpsi.data)) % || ischar(rminpsi.data) (to add?)
+      if (gdat_params.nverbose>=1); warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff]); end
+      return
+    end
     ij=find(rmaxpsi.data<0.5 | rmaxpsi.data>1.2);
     if ~isempty(ij); rmaxpsi.data(ij)=NaN; end
     ij=find(rminpsi.data<0.5 | rminpsi.data>1.2);
@@ -450,7 +459,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
       gdat_data.data=0.5.*(rmaxpsi.data(end,:) + rminpsi.data(end,:));
       gdat_data.data_fullpath=[nodenameeff ' + ' nodenameeff2 ' /2'];
     else
-      disp(['should not be in this case with data_request_eff = ' data_request_eff])
+      if (gdat_params.nverbose>=1); warning(['should not be in this case with data_request_eff = ' data_request_eff]); end
       return
     end
     gdat_data.dim = rmaxpsi.dim(2);    
@@ -471,7 +480,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
       gdat_data.dim{1} = zcontour.dim{2};
       gdat_data.dimunits{1} = zcontour.dimunits{2};
     else
-      disp(['should not be in this case with data_request_eff = ' data_request_eff])
+      if (gdat_params.nverbose>=1); warning(['should not be in this case with data_request_eff = ' data_request_eff]); end
       return
     end
     gdat_data.t = gdat_data.dim{mapping_for_tcv.gdat_timedim};
@@ -493,7 +502,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
       gdat_data.data=192.E-07 * 0.996 *tracetdi.data/R0EXP;
     end
     if isempty(tracetdi.data) || isempty(tracetdi.dim) % || ischar(tracetdi.data) (to add?)
-      warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff])
+      if (gdat_params.nverbose>=1); warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff]); end
       return
     end
     gdat_data.data_fullpath=[nodenameeff];
@@ -521,7 +530,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     a_minor=gdat_tcv([],params_eff);
     % use beta as time base
     if isempty(b0.data) || isempty(b0.dim) || isempty(ip.data) || isempty(ip.dim) || isempty(a_minor.data) || isempty(a_minor.dim) || isempty(beta.data) || isempty(beta.dim)
-      warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff])
+      if (gdat_params.nverbose>=1); warning(['problems loading data for data_request= ' data_request_eff]); end
       return
     end
     gdat_data.dim = beta.dim;
@@ -636,7 +645,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
       time = gdat_data.gdat_params.time;
     else
       gdat_data.gdat_params.time = time;
-      disp(['"time" is expected as an option, choose default time = ' num2str(time)]);
+      if (gdat_params.nverbose>=3); disp(['"time" is expected as an option, choose default time = ' num2str(time)]); end
     end
     gdat_data.gdat_params.time = time;
     gdat_data.t = time;
@@ -729,7 +738,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
          gdat_data.gdat_params.edge>0)
       gdat_data.gdat_params.edge = 0;
     end
-    [gdat_data] = get_thomson_raw_data(shot,data_request_eff,gdat_data,gdat_data.gdat_params.edge,nverbose);
+    [gdat_data] = get_thomson_raw_data(shot,data_request_eff,gdat_data,gdat_data.gdat_params.edge,gdat_params.nverbose);
     
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    case {'ne_rho', 'te_rho', 'nete_rho'}
@@ -744,7 +753,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
          gdat_data.gdat_params.edge>0)
       gdat_data.gdat_params.edge = 0;
     end
-    [gdat_data] = get_thomson_raw_data(shot,data_request_eff,gdat_data,gdat_data.gdat_params.edge,nverbose);
+    [gdat_data] = get_thomson_raw_data(shot,data_request_eff,gdat_data,gdat_data.gdat_params.edge,gdat_params.nverbose);
     % construct rho mesh
     edge_str_ = '';
     edge_str_dot = '';
@@ -770,10 +779,11 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
         case length(psiscatvol.dim{1})
           zeffshift=interp1(psiscatvol.dim{1},zeffshift,psitdi.dim{3});
         otherwise
-          disp(' bad time dimension for zshift')
-          disp(['it should be 1 or ' num2str(length(psiscatvol.dim{1})) ' or ' num2str(length(psitdi.dim{3}))])
+         if (gdat_params.nverbose>=1);
+           disp(' bad time dimension for zshift')
+           disp(['it should be 1 or ' num2str(length(psiscatvol.dim{1})) ' or ' num2str(length(psitdi.dim{3}))])
+         end
       end
-max(zeffshift)
       for it=1:length(psiscatvol.dim{1})
         itpsitdi=iround(psitdi.dim{3},psiscatvol.dim{1}(it));
         psirz=psitdi.data(:,:,itpsitdi);
@@ -809,8 +819,10 @@ max(zeffshift)
        case 'conf'
         def_proffit = '\results::conf:';
        otherwise
-        disp('should not be in switch gdat_data.gdat_params.fit_type')
-        disp('ask olivier.sauter@epfl.ch')
+        if (gdat_params.nverbose>=1);
+          disp('should not be in switch gdat_data.gdat_params.fit_type')
+          disp('ask olivier.sauter@epfl.ch')
+        end
         return
       end
       if strcmp(gdat_data.gdat_params.fit_type,'conf')
@@ -821,7 +833,9 @@ max(zeffshift)
         elseif strcmp(data_request_eff(1:2),'te')
           nodenameeff = [def_proffit 'teft'];
         else
-          disp(['should not be here: data_request_eff, data_request_eff(1:2)= ',data_request_eff, data_request_eff(1:2)]);
+         if (gdat_params.nverbose>=1);
+           disp(['should not be here: data_request_eff, data_request_eff(1:2)= ',data_request_eff, data_request_eff(1:2)]);
+         end
         end
       end
       if isfield(gdat_data.gdat_params,'trialindx') && ~isempty(gdat_data.gdat_params.trialindx) && ...
@@ -837,7 +851,7 @@ max(zeffshift)
         if ~isempty(tracetdi.data) && ~isempty(tracetdi.dim) && ~ischar(tracetdi.data)
           gdat_data.fit.data = tracetdi.data;
         else
-          if nverbose>=1
+          if gdat_params.nverbose>=1
             disp([nodenameeff ' is empty, thus no fits, check hldsi(shot) and may need to run anaprofs?'])
           end
           gdat_data.fit.data = [];
@@ -848,7 +862,7 @@ max(zeffshift)
         if ~isempty(tracetdi.data) && size(tracetdi.data,3)>=trialindx+1
           gdat_data.fit.data = tracetdi.data(:,:,trialindx+1);
         else
-          if nverbose>=1
+          if gdat_params.nverbose>=1
             disp([nodenameeff ' with trialindx=' num2str(trialindx) ' is empty, thus no fits, check hldsi(shot) and may need to run anaprofs?'])
           end
           gdat_data.fit.data = [];
@@ -859,9 +873,11 @@ max(zeffshift)
       gdat_data.fit.x=tracetdi.dim{1};
       gdat_data.fit.t=tracetdi.dim{2};
       if mapping_for_tcv.timedim~=2 | mapping_for_tcv.gdat_timedim~=2
-        disp(['unexpected timedim in fit: data_request_eff= ' data_request_eff ...
-              ', mapping_for_tcv.timedim= ' mapping_for_tcv.timedim ...
-              ', mapping_for_tcv.gdat_timedim= ' mapping_for_tcv.gdat_timedim]);
+        if (gdat_params.nverbose>=1);
+          disp(['unexpected timedim in fit: data_request_eff= ' data_request_eff ...
+                ', mapping_for_tcv.timedim= ' mapping_for_tcv.timedim ...
+                ', mapping_for_tcv.gdat_timedim= ' mapping_for_tcv.gdat_timedim]);
+        end
       end
       gdat_data.dim=tracetdi.dim(1:2);
       gdat_data.dimunits=tracetdi.dimunits(1:2);
@@ -1020,7 +1036,7 @@ max(zeffshift)
     b0=gdat_tcv([],params_eff);
     b0tpsi = interp1(b0.t,b0.data,psi_axis.t); %q_rho on same time base as psi_axis
     if isempty(psi_axis.data) || isempty(psi_axis.dim) || isempty(q_rho.data) || isempty(q_rho.dim)
-      warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff])
+      if (gdat_params.nverbose>=1); warning(['problems loading data for ' nodenameeff ' for data_request= ' data_request_eff]); end
       return
     end
     rhoequal = linspace(0,1,length(q_rho.dim{1}));
@@ -1091,7 +1107,9 @@ max(zeffshift)
         gdat_data.data_fullpath='sqrt(\results::psitbx:vol/vol_edge)';
         gdat_data.request_description = 'sqrt(volume(rho)/volume(edge))';
       else
-        disp(['should not be here in vol cases with data_request = ' data_request_eff]);
+         if (gdat_params.nverbose>=1)
+           disp(['should not be here in vol cases with data_request = ' data_request_eff]);
+         end
         return
       end
     end
@@ -1130,7 +1148,7 @@ max(zeffshift)
       else
         gdat_data.data=tracetdi.data'; % error in dimensions for autofits
         if ~isempty(tracetdi.dim) && ~ischar(tracetdi.data)
-          if nverbose>=3; disp('assumes dim{2} for x in THOMSON.PROFILES.AUTO'); end
+          if gdat_params.nverbose>=3; disp('assumes dim{2} for x in THOMSON.PROFILES.AUTO'); end
           gdat_data.x=tracetdi.dim{2};
           gdat_data.t=tracetdi.dim{1};
           error_status=0;
@@ -1154,13 +1172,13 @@ max(zeffshift)
     gdat_data.fullpath = ['Thomson autfits from ' nodenameeff];
 
    otherwise
-    warning(['switchcase= ' data_request_eff ' not known in gdat_tcv'])
+    if (gdat_params.nverbose>=1); warning(['switchcase= ' data_request_eff ' not known in gdat_tcv']); end
     error_status=901;
     return
   end
   
 else
-  warning(['TCV method=' mapping_for_tcv.method ' not known yet, contact Olivier.Sauter@epfl.ch'])
+  if (gdat_params.nverbose>=1); warning(['TCV method=' mapping_for_tcv.method ' not known yet, contact Olivier.Sauter@epfl.ch']); end
   error_status=602;
   return
 end
@@ -1175,7 +1193,7 @@ error_status=0;
 return
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-function [firthomratio] = get_fir_thom_rat_data(shot,maintracename,timebase);
+function [firthomratio] = get_fir_thom_rat_data(shot,maintracename,timebase,nverbose);
 %
 % since depends on shot number for using auto fit and thomson or thomson edge, use tracename and function here
 %
@@ -1195,7 +1213,9 @@ end
 
 firthomratio = NaN;
 if ~exist('timebase') || isempty(timebase)
-  disp('need a timebase in get_fir_thom_rat_data')
+  if (nverbose>=1)
+    disp('need a timebase in get_fir_thom_rat_data')
+  end
   return
 end
 firthomratio = NaN*ones(size(timebase));
@@ -1204,30 +1224,30 @@ if strcmp(maintracename_eff,'thomson')
   if shot>=23801
     tracefirrat=tdi('\results::thomson.profiles.auto:fir_thom_rat'); %time base not same!!
     if isempty(tracefirrat.data) || ischar(tracefirrat.data)
-      disp('problem with \results::thomson.profiles.auto:fir_thom_rat: empty, use thomson:fir_thom_rat')
+      if (nverbose>=1); disp('problem with \results::thomson.profiles.auto:fir_thom_rat: empty, use thomson:fir_thom_rat'); end
       tracefirrat=tdi('\results::thomson:fir_thom_rat');
     end
   else
     tracefirrat=tdi('\results::thomson:fir_thom_rat');
     if isempty(tracefirrat.data) || ischar(tracefirrat.data)
-      disp('problem with \results::thomson:fir_thom_rat: empty')
+      if (nverbose>=1); disp('problem with \results::thomson:fir_thom_rat: empty'); end
     end
   end
 elseif strcmp(maintracename_eff,'thomson_edge')
   if shot>=23801
     tracefirrat=tdi('\results::thomson.profiles.auto:fir_thom_rat'); %time base not same!!
     if isempty(tracefirrat.data) || ischar(tracefirrat.data)
-      disp('problem with \results::thomson.profiles.auto:fir_thom_rat: empty, use thomson:fir_thom_rat')
+      if (nverbose>=1); disp('problem with \results::thomson.profiles.auto:fir_thom_rat: empty, use thomson:fir_thom_rat'); end
       tracefirrat=tdi('\results::thomson:fir_thom_rat');
     end
   else
     tracefirrat=tdi('\results::thomson_edge:fir_thom_rat');
     if isempty(tracefirrat.data) || ischar(tracefirrat.data)
-      disp('problem with \results::thomson_edge:fir_thom_rat: empty')
+      if (nverbose>=1); disp('problem with \results::thomson_edge:fir_thom_rat: empty'); end
     end
   end
 else
-  disp('bad input in get_fir_thom_rat_data')
+  if (nverbose>=1); disp('bad input in get_fir_thom_rat_data'); end
   return
 end  
 
@@ -1271,7 +1291,7 @@ gdat_data.error_bar=tracestd.data';
 gdat_data.data_fullpath=[nodenameeff '; error_bar'];
 % add fir if ne requested
 if strcmp(data_request_eff(1:2),'ne')
-  tracefirrat_data = get_fir_thom_rat_data(shot,['thomson' edge_str_],time);
+  tracefirrat_data = get_fir_thom_rat_data(shot,['thomson' edge_str_],time,nverbose);
   gdat_data.firrat=tracefirrat_data;
   gdat_data.data_raw = gdat_data.data;
   gdat_data.data = gdat_data.data_raw * diag(tracefirrat_data);
diff --git a/crpptbx/TCV/tcv_help_parameters.m b/crpptbx/TCV/tcv_help_parameters.m
index bbb5f433..102d9858 100644
--- a/crpptbx/TCV/tcv_help_parameters.m
+++ b/crpptbx/TCV/tcv_help_parameters.m
@@ -19,6 +19,7 @@ help_struct_all = struct(...
     ,'machine', 'machine name like ''TCV'', ''AUG'', case insensitive' ...
     ,'doplot', '0 (default), if 1 calls gdat_plot for a new figure, -1 plot over current figure with hold all, see gdat_plot for details' ...
     ,'liuqe','liuqe version 1 (default), 2, 3 for LIUQE1, 2, 3 resp. or -1 for model values' ...
+    ,'nverbose','1 (default) displays warnings, 0: only errors, >=3: displays all extra information' ...
     );
 
 % TCV related
@@ -33,7 +34,7 @@ help_struct_all.zshift = 'vertical shift of equilibrium, either for eqdsk or for
 help_struct_all.cocos = ['cocos value desired in output, uses eqdsk_cocos_transform. Note should use latter if a specific Ip and/or B0 sign' ...
                     'is wanted. See O. Sauter et al Comput. Phys. Commun. 184 (2013) 293'];
 help_struct_all.edge = '0 (default), 1 to get edge Thomson values';
-help_struct_all.fit = '1 if fit profiles desired as well, relevant for _rho profiles. Default is (0). See also fit_type';
+help_struct_all.fit = '0, no fit profiles, 1 (default) if fit profiles desired as well, relevant for _rho profiles. See also fit_type';
 help_struct_all.fit_type = 'provenance of fitted profiles ''conf'' (default) from conf nodes, ''avg'' or ''local'' for resp. proffit: nodes';
 help_struct_all.trialindx = 'value of trialindx desired to get a specific one when relevant, otherwise gets ok_trialindx, that is 1 usually';
 %help_struct_all. = '';
-- 
GitLab