% Humboldt University Berlin
% Institute for Mathematics - Dr. Rene Lamour
% *************************************************************
% Program to prepare user driven parameters for main_consi
% *************************************************************
% Name:               setuser_para_mainconsi
%                     ----------------------
% Author:             Sigrid Wehner
% Stand:              28.6.03
%                     ------------------------------------------------------
%                     Initial parameter state is recalled by empty parameter
%                     list:  setuser_para_mainconsi()
% possible
% parameters open
% to user changes: 
% (default values    
% are listed)         threshold=1e-9   (threshold for rank determination)
%                     ep=1e-13         (accuracy of Newton method)
%                     given_index=-1   index check
%                                       or k: index of DAE
%                     ----------------------------------------------
%                                       switches for calculation:
%                     s_Bt=0
%                     s_Dt=0            0 numerical, 1 analytical
%                     s_ft=0           (switches for dependency of t
%                                       and calculation:
%                                      -1 not t dependent
%                                       0 numerical, 1 analytical )
%                     ----------------------------------------------
% usage:              setuser_para_mainconsi('nameP1',valueP1,'nameP2',
%                                             valueP2,...)
%                     parameter name to be closed in ''
%                     one or more parameters may be given in 
%                     arbitrary sequence
% 
% example:            setuser_para_mainconsi('ep',1e-8,'threshold',1e-7)
% -----------------------------------------------------------------------

function [] = setuser_para_mainconsi(varargin)
disp('***** setuser_para_mainconsi: user parameters for mainconsi...');
 
% ############################################################
% first get the default values for main_consi
% ############################################################
[threshold,ep,given_index,s_Bt,s_Dt,s_ft]...
    = init_para_mainconsi;

% interpreting the user input
% elements 1,3,...nargin-1 of varargin list are parameter names
% elements 2,4,...nargin   of varargin list are parameter values

% checking which user parameters are set and
% checking for valid parameter values

errhead='##########           ERROR IN USER SPECIFICATION !!!           ##########';
warhead='##########         WARNING FOR USER SPECIFICATION !!!          ##########';


if (nargin >=1)
   for i=1:2:nargin-1
       valid_par=0;
       given_parname=varargin{i};
   
% ep: error if <=0; warning if > 1
% --------------------------------
      if (strcmp(varargin{i},'ep')~=0)
         ep=varargin{i+1};
         valid_par=1;
         if (ep <= 0)
           disp(errhead);
           error('ERROR setting parameter: "ep"  ==> Must be greater 0 !!!');
         end;
         if (ep > 1)
           disp(warhead);
           warning('WARNING for parameter: "ep"  ==> greater 1! really so big ???');
         end;
      end;

% threshold: error if <=0; warning if > 1
% ---------------------------------------
      if (strcmp(varargin{i},'threshold')~=0)
         threshold=varargin{i+1};
         valid_par=1;
         if (threshold <= 0)
           disp(errhead);
           error('ERROR setting parameter: "threshold"  ==> Must be greater 0 !!!');
         end;
         if (threshold > 1)
           disp(warhead);
           warning('WARNING for parameter: "threshold"  ==> greater 1! really so big ???');
         end;

      end;

% given_index: error if < -1; warning if > 5
% ------------------------------------------
      if (strcmp(varargin{i},'given_index')~=0)
         given_index=varargin{i+1};
         valid_par=1;
         if (given_index < -1)
           disp(errhead);
           error('ERROR setting parameter: "given_index"  ==> Must be at least -1 !!!');
         end;
         if (given_index > 5)
           disp(warhead);
           warning('WARNING for parameter: "given_index"  ==> greater 5! really so big ???');
         end;
      end;

% s_Bt: error if NOT -1 or 0 or 1
% -------------------------------
      if (strcmp(varargin{i},'s_Bt')~=0)
         s_Bt=varargin{i+1};
         valid_par=1;
         if (s_Bt ~=0 & s_Bt ~=-1 & s_Bt ~=1)
           disp(errhead);
           error('ERROR setting parameter: "s_Bt"  ==> only -1/0/1 possible !!!');
         end;
      end;     
      
% s_Dt: error if NOT -1 or 0
% --------------------------
      if (strcmp(varargin{i},'s_Dt')~=0)
         s_Dt=varargin{i+1};
         valid_par=1;
         if (s_Dt ~=0 & s_Dt ~=-1)
           disp(errhead);
           error('ERROR setting parameter: "s_Dt"  ==> only -1 or 0 possible !!!');
         end;
      end;
      
% s_ft: error if NOT -1 or 0 or 1
% -------------------------------
      if (strcmp(varargin{i},'s_ft')~=0)
         s_ft=varargin{i+1};
         valid_par=1;
         if (s_ft ~=0 & s_ft ~=-1 & s_ft ~=1)
           disp(errhead);
           error('ERROR setting parameter: "s_ft"  ==> only -1/0/1 possible !!!');
         end;
      end;

% ERROR: an invalid parameter name was given
% ------------------------------------------
if (valid_par == 0)
    disp(errhead);
    fprintf('invalid parameter name:  %s \n',given_parname);
    error('ERROR in parameters for main_consi! Check it and run again!   ');
end;      
      
end; % for-loop
end; 




% save actual user definitions
save parameter_mainconsi threshold ep given_index ...
    s_Bt s_Dt s_ft;

% restore default version if routine was called with empty list
if (nargin==0)
  [threshold,ep,given_index,...
  s_Bt,s_Dt,s_ft]...
  = init_para_mainconsi(1);
end;
