%% ===========================================================================
% Copyright (C):
%       2002 by Forschungszentrum Telekommunikation Wien, Austria;
%                                                         All rights reserved.
% Description   : Table output for ETSI ADSL performance simulations
%
% Project       : B1, FTW
% Author(s)     : Tomas Nordstrom (Tomas.Nordstrom@FTW.at)
%
% Reference:
%    ETSI TM6 021t31r1, Torino, Italy, 4th-8th Feb., 2002
%
% CVS:       $Id: TableOutputRaw.m,v 1.2 2002/03/18 11:58:25 tono Exp $
%% ===========================================================================

%% ===========================================================================
% Change History
%      2002-03-12 (ToNo) Created
%% ===========================================================================

% load simulation results
if 1,
    dvec     = datevec(now);     % Get todays result
    isodate  = sprintf('%4d%02d%02d',dvec(1),dvec(2),dvec(3));
    savefile = sprintf('matlab%s_perf',isodate);
    load(savefile)
else
    load matlab20020313_perf.mat % Change to correct filename
end;

%% ===========================================================================
%  Initialize

dupl = {'EC','FDD'};
ower = {'ISDN','POTS'};
noise = 'ABCD';
usds = {'DS','US'};
updwn = {'DOWN','UP'};

offsetlen=[0 0 1500 2200 1750 1750 4200 1100];

%% ===========================================================================
%  Do all (2*2*4=16) tables

for d=1:2,
    for o=1:2,
        for n=1:4,

            % ================================================================
            % Get min for both downstream and upstream
            u=1; % dir='DS';
            config = sprintf('%s ADSL over %s %sSTREAM',...
                             dupl{d},ower{o},updwn{u});
            varDS = sprintf('ETSI_ADSL_%s_%s_%s_%s',...
                           ower{o},dupl{d},usds{u},noise(n));
            eval(sprintf('valDS=%s;',varDS));
            bitrates=[128 512 768 1024 1544 2048 3072 4096 5120 6144]/1e3; 
            rDS = valDS';

            u=2; % dir='US';
            config = sprintf('%s ADSL over %s %sSTREAM',...
                             dupl{d},ower{o},updwn{u});
            varUS = sprintf('ETSI_ADSL_%s_%s_%s_%s',...
                           ower{o},dupl{d},usds{u},noise(n));
            eval(sprintf('valUS=%s;',varUS));
            rUS = valUS';
            
            % Get the minimum distance for each loop
            mindist = min(rUS(1,:),rDS(1,:))+1; 

            % ================================================================
            % Do downstream
            u=1; % dir='DS';
            ft=300e3;

            config = sprintf('%s ADSL over %s %sSTREAM',...
                             dupl{d},ower{o},updwn{u});
            fprintf(1,'\n=================\n%s\tNoise %s\n\n',config,noise(n));
            for sp=1:size(rDS,1)
                fprintf('%5.f  %4d   ',bitrates(sp)*1e3,ft/1e3);
                for lix=1:(size(rDS,2))
                    if rDS(sp,lix)>3+offsetlen(lix),
                        fprintf('%5.0f',rDS(sp,lix));
                        if rDS(sp,lix) > mindist(lix)
                            fprintf('*');
                        else
                            fprintf(' ');
                        end;
                        
                    else
                        fprintf('    - ',rDS(sp,lix));
                    end;
                end;
                fprintf('\n');
            end;

            % ================================================================
            % Do upstream
            u=2; % dir='US';
            if o==1,
                ft=150e3;
            else
                ft=75e3;
            end;
            
            config = sprintf('%s ADSL over %s %sSTREAM',...
                             dupl{d},ower{o},updwn{u});

            bitrates=[64 128 256 384 512 640]/1e3;    % US bitrates
            
            fprintf(1,'\n=================\n%s\tNoise %s\n\n',config,noise(n));
            for sp=1:size(rUS,1)
                fprintf('%5.f  %4d   ',bitrates(sp)*1e3,ft/1e3);
                for lix=1:(size(rUS,2))
                    if rUS(sp,lix)>3+offsetlen(lix),
                        fprintf('%5.0f',rUS(sp,lix));
                        if rUS(sp,lix) > mindist(lix)
                            fprintf('*');
                        else
                            fprintf(' ');
                        end;
                        
                    else
                        fprintf('    - ',rUS(sp,lix));
                    end;
                end;
                fprintf('\n');
            end;

            % ================================================================
            
        end;
    end;
end;