function type = tjsr_checkoptions(type);
% type = tjsr_checkoptions(type); 
% This function belongs to tjsr!
% make tests if options are sensible
% Input: 'type'-struct from tjsr
% Output: Messages on screen and inside of type
%
% Written by tommsch, 2018

    
    if(type.opt.testoldvertex)
        type.info.infotext=vprintf('''testoldvertex'' yields wrong intermediate estimates. \n    If the algorithm terminates, the result is correct. \n    If the algorithm does net terminate set <''delta'',val> or ''<testoldvertex,0>.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext);
        type.info.errortext=vprintf('''testoldvertex'' yields wrong intermediate estimates. \n    If the algorithm terminates, the result is correct. \n    If the algorithm does net terminate set <''delta'',val> or ''<testoldvertex,0>.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext);
    end
    if(type.opt.memory>=1);
        type.info.infotext=vprintf('Change parameters since ''memory'' is set.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext);
        type.info.errortext=vprintf('Change parameters since ''memory'' is set.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext);
        type.opt.plot='none';
    end
    if(type.opt.memory>=2)
        type.opt.testspectralradius=-inf;
        type.opt.testeigenplane=-inf;
    end
    if(type.opt.rholeqval && type.opt.fastnorm); 
        type.info.infotext=vprintf('You may like set <''fastnorm'',0> since ''rholeqval'' is set.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext);
        type.info.errortext=vprintf('You may like set <''fastnorm'',0> since ''rholeqval'' is set.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext);
        %vprintf('Press any key to continue.\n','cpr','err','imp',[0,type.opt.verbose]); pause;
    end;
    if(type.opt.alwaysout && type.opt.fastnorm); 
        vprintf('You should set <''fastnorm'',0> since ''alwaysout'' is set.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); pause; 
    end;
    if(max(cellfun(@(x) tif(isempty(x),0,max(max(x))), type.cyclictree.ordering))>length(type.M_original)); 
        vprintf('Numbers given in ''ordering'' are higher then number of matrices.\n','cpr','err','imp',[0,type.opt.verbose]); 
        return; 
    end;
    if(type.opt.simplepolytope<0)
        type.info.infotext=vprintf('''simplepolytope'' should be greater-equal then zero, otherwise it will have no effect.','cpr','err','imp',[1,type.opt.verbose],'str',type.info.infotext);     
    end
    if(type.opt.testspectralradius>=0);        
        type.info.infotext=vprintf('''testspectralradius'' should be less then zero, to prevent false positives.','cpr','err','imp',[1,type.opt.verbose],'str',type.info.infotext); 
    end;
    if(type.opt.testspectralradius>=0);        
        type.info.infotext=vprintf('''testeigenplane'' should be less then zero, to prevent false positives.','cpr','err','imp',[1,type.opt.verbose],'str',type.info.infotext); 
    end;
%    if(type.opt.notestcycle && type.opt.delta>=1); 
%        type.info.infotext=vprintf('''notestcycle'' is set, but ''delta'' is geq 1. Set ''delta'' to 0.999.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); type.opt.delta=0.999; 
%    end;
    if(type.opt.autoextravertex>=1); 
        type.info.infotext=vprintf('''autoextravertex'' should be smaller then 1.\n','cpr','err','imp',[1,type.opt.verbose],'str',type.info.infotext); 
    end;
    if(type.opt.alwaysout);      
        type.info.infotext=vprintf('!''alwaysout'' is set!\n','imp',[2,type.opt.verbose],'str',type.info.infotext); 
    end;
    if(type.opt.epsequal<0);     
        type.info.infotext=vprintf('epsequal<0. This will cause an error.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); 
        type.info.errortext=vprintf('epsequal<0. This will cause an error.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext); 
    end;
    if(type.opt.epspolytope<type.opt.epslinprog);  
        type.info.infotext=vprintf('''epspolytope'' should be strictly greater then ''epslinprog''.\n','imp','cpr','err',[0,type.opt.verbose],'str',type.info.infotext); 
        type.info.errortext=vprintf('''epspolytope'' should be strictly greater then ''epslinprog''.\n','imp','cpr','err',[0,type.opt.verbose],'str',type.info.errortext); 
    end; 
    if(type.opt.epspolytope<0);  
        type.info.infotext=vprintf('epspolytope<0\n','imp',[1,type.opt.verbose],'str',type.info.infotext); 
    end; 
    if(type.opt.delta>1);        
        type.info.infotext=vprintf('delta>1\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); 
        type.info.errortext=vprintf('delta>1\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext); 
    end;
    if((~isempty(type.cyclictree.v0) || ~isempty(type.cyclictree.v0s) || ~isempty(type.cyclictree.extravertex) ||  ~isempty(type.cyclictree.smpflag)) && ~isequal(type.opt.invariantsubspace,'none'));
        type.info.infotext=vprintf('You should set <''invariantsubspace'',''none''> since you have given explicit starting vectors.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); 
        type.info.errortext=vprintf('You should set <''invariantsubspace'',''none''> since you have given explicit starting vectors.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext); 
    end; 
    if(type.opt.naturalselectiontype>=100 && type.opt.naturalselectiontype<1000);
        type.info.infotext=vprintf('''naturalselectiontype'' has a value where the algorithm will behave very badly.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); 
        type.info.errortext=vprintf('''naturalselectiontype'' has a value where the algorithm will behave very badly.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext); 
    end
    if(type.opt.naturalselection<0);
        type.info.infotext=vprintf('''naturalselection''<0, thus the algorithm cannot report intermediate bounds for the JSR.\n   If the algorithm still reports bounds, these are wrong!\n   If the algorithm reports an exact value, this value is correct.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.infotext); 
        type.info.errortext=vprintf('''naturalselection''<0, thus the algorithm cannot report intermediate bounds for the JSR.\n   If the algorithm still reports bounds, these are wrong!\n   If the algorithm reports an exact value, this value is correct.\n','cpr','err','imp',[0,type.opt.verbose],'str',type.info.errortext); 
    end
end