%
%  signal_stats_SRS.m  ver 1.0  December 3, 2012
%
%  (also does VRS)
%
function[]=signal_stats_SRS(m,THF,mina,maxa,iflag)
%
[~,mina,maxa]=coordinates_ss(m,THF,mina,maxa,iflag);
%
    grid on;
    io=0;
    while(io < 2 )
        disp(' ');    
        disp(' Additional Options ');
        disp(' 1=add dB margin    ');
        if(m==2)
            disp(' 2=Superimpose another SRS curve');
        else
            disp(' 2=Superimpose another VRS curve');           
        end
        disp(' 3=exit             ');   
        io=input(' ');
        disp(' ')
        if(io==1)
            dB=input(' Input Margin (dB) ');
            scale=10^(dB/20);
            THF(:,2)=THF(:,2)*scale;
            if(sz(2)==3)
                THF(:,3)=THF(:,3)*scale;      
            end
            [~,mina,maxa]=coordinates_ss(m,THF,mina,maxa,iflag);       
        end   
        if(io==2)
            hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            disp(' Select data input method ')
            disp('  1=data preloaded in matlab ')  
            disp('  2=keyboard entry ');
            disp('  3=external ASCII file ');
            disp('  4=Excel file ');
%
            method2=input('');                 
            disp(' ')
%
            if(method2==1)
                FS = input(' Enter the matrix name:  ','s');
                THF2=evalin('caller',FS);
                sz2=size(THF2);
                f2=double(THF2(:,1));        
                a2=double(THF2(:,2));      
%
                if(m==2)
                    if(sz2(2)==2)
%                        table=[f2 ; a2]';               
                    else
%                        b2=double(THF2(:,2)); 
%                        table=[f2 ; a2 ; b2]';    
                    end
                else
%                    table=[f2 ; a2]';
                end
%        
            end   
%
            if(method2==2)
                n2=input(' Input the number of coordinates  ');	
%
                for i=1:n2
                    if(m==1)
                        out = sprintf('\n Enter Frequency %ld ',i);
                    else
                        out = sprintf('\n Enter Natural Frequency %ld ',i);      
                    end
                    disp(out);
                    f2(i)=input('');
%
                    out = sprintf('\n Enter amplitude %ld ',i);
                    disp(out);
                    a2(i)=input('');  
                end 
                table=[f2 ; a2]';
                THF2=table; 
            end
            if(method2==3)
                [filename, pathname] = uigetfile('*.*');
                filename = fullfile(pathname, filename);
%      
%                 fid = fopen(filename,'r');
%        THF = fscanf(fid,'%g %g',[2 inf]);
%        THF=THF';
                THF2=load(filename);
                sz2=size(THF2);
                f2=double(THF2(:,1));
                a2=double(THF2(:,2));
                if(sz2(2)==3)
%                    b2=double(THF2(:,3));
%                    table=[f2 , a2 , b2];   
                else
%                    table=[f2 , a2];
                end       
            end 
%
            if(method2==4)
                [filename, pathname] = uigetfile('*.*');
                xfile = fullfile(pathname, filename);
%        
                THF2 = xlsread(xfile);
%        
                f2=double(THF2(:,1));
                a2=double(THF2(:,2));  
%       
%                table=[f2 ; a2]; 
            end               
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            iflag=1;
            [~,mina,maxa]=coordinates_ss(m,THF2,mina,maxa,iflag);  
        end
    end