% Humboldt University Berlin
% Institute for Mathematics - Dr. Rene Lamour
% *************************************************************************
% Purpose:          Prepare user defined GENERAL parameters.
%                   Given user parameters will be merged 
%                   to the default parameter version and then saved.
%                   Initial parameter state is recalled by empty 
%                   parameter list.
% *************************************************************************
% Name:             setuser_para_general
%                   --------------------
% Author:           Sigrid Wehner
% Stand:            28.6.03
% Possible
% parameters open
% to user changes: 
%                   parameter      default      meaning
%                   -------------------------------------------------------
%                   s_A            =0  ***      numerical calculation;
%                                   1           df/dy is given by user
%                   s_D            =0  ***      numerical calculation;
%                                   1           df/dx is given by user
%                   s_B            =0  ***      numerical calculation;
%                                   1           dx/dt is given by user
%                   s_log          =0           NO logfile
%                                   1  ***      give logfile
%                   s_sol          =0  ***      NO solution output
%                                   1           numerical solution into file
%                   s_solexact     =0  ***      NO exact solution
%                                   1           exact solution into file
%                   print_level    =0           NO output
%                                   1  ***      standard (screen)
%                                   2           separate files
% *************************************************************************
% Usage:              setuser_para_general('nameP1',valueP1,'nameP2',
%                                             valueP2,...)
%                     Parameter name has to be closed in '' .
%                     One or more parameters may be given in
%                     arbitrary sequence.
% *************************************************************************

function [] = setuser_para_general(varargin)
disp('***** setuser_para_general: user definition of TASK parameters...');
 
% #############################################################
% first get the default values and create local default version
% #############################################################

[s_A, s_D, s_B, s_log, s_sol, s_solexact, print_level]...
        =init_para_general(1);

% 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};
      
% s_A: error if not 0 or 1
% ------------------------
      if (strcmp(varargin{i},'s_A')~=0)
         s_A=varargin{i+1};
         valid_par=1;
         if (s_A ~=0 & s_A ~= 1)
           disp(errhead);
           error('ERROR setting parameter: "s_A"  ==> Only 0 or 1 is allowed !!!');
         end;
     end;
     
% s_D: error if not 0 or 1
% ------------------------
      if (strcmp(varargin{i},'s_D')~=0)
         s_D=varargin{i+1};
         valid_par=1;
         if (s_D ~=0 & s_D ~= 1)
           disp(errhead);
           error('ERROR setting parameter: "s_D"  ==> Only 0 or 1 is allowed !!!');
         end;
     end;
        
% s_B: error if not 0 or 1
% ------------------------
      if (strcmp(varargin{i},'s_B')~=0)
         s_B=varargin{i+1};
         valid_par=1;
         if (s_B ~=0 & s_B ~= 1)
           disp(errhead);
           error('ERROR setting parameter: "s_B"  ==> Only 0 or 1 is allowed !!!');
         end;
     end;

          
% s_log: error if not 0 or 1
% --------------------------
      if (strcmp(varargin{i},'s_log')~=0)
         s_log=varargin{i+1};
         valid_par=1;
         if (s_log ~=0 & s_log ~= 1)
           disp(errhead);
           error('ERROR setting parameter: "s_log"  ==> Only 0 or 1 is allowed !!!');
         end;
     end;
     
% s_sol: error if not 0 or 1
% --------------------------
      if (strcmp(varargin{i},'s_sol')~=0)
         s_sol=varargin{i+1};
         valid_par=1;
         if (s_sol ~=0 & s_sol ~= 1)
           disp(errhead);
           error('ERROR setting parameter: "s_sol"  ==> Only 0 or 1 is allowed !!!');
         end;
     end;    
     
% s_solexact: error if not 0 or 1
% -------------------------------
      if (strcmp(varargin{i},'s_solexact')~=0)
         s_solexact=varargin{i+1};
         valid_par=1;
         if (s_solexact ~=0 & s_solexact ~= 1)
           disp(errhead);
           error('ERROR setting parameter: "s_solexact"  ==> Only 0 or 1 is allowed !!!');
         end;
     end;    
 
% print_level: error if not 0 or 1 or 2
% -------------------------------------
      if (strcmp(varargin{i},'print_level')~=0)
         print_level=varargin{i+1};
         valid_par=1;
         if (print_level ~=0 & print_level ~= 1 & print_level~=2)
           disp(errhead);
           error('ERROR setting parameter: "print_level"  ==> Only 0 or 1 or 2 is allowed !!!');
         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 general parameters! Check it and run again!   ');
end;

end; % for-loop
end;

% save actual user definitions
save parameter_general ...
         s_A s_D  s_B  s_log s_sol s_solexact print_level;
         

% restore default version if routine was called with empty list
if (nargin==0)
[s_A, s_D, s_B, s_log, s_sol, s_solexact, print_level]...
        =init_para_general(1);
end;

