%-------------------------------
%   This Module prepares all the data necessary for the 
%   calculations

% start with empty variable space
clear

%   Define location and name of the data file;
%   This file should include:
%       country names 
%       population in 2010 
%       consumption profiles
%       Labor income profiles
%       transfer inflows profiles
%       transfer outflows profiles
%       l(age)
%       lf(age)
%       ex(age)
%       Birth ratios

%   Define folder and the name of the data file
country_file_folder = '\';  % add your folder address between the first ' and \
country_file_name = '.xls'; % add the data file name between the first ' and .xls
dataFile = [country_file_folder country_file_name];

%-----Define scenario:
%   For each country in the simulation set, the following describe possible
%   scenarios
%       1 - country's own fertility and economic profiles are used
%       2 - default country's fertility is used for all countries;  country's own economic profiles are used
%       3 - country's own fertility is used for all countries;  default country's economic profiles are used
%       
profiles = ['self       '; 'default_fer'; 'default_NTA';];
prof = input('for self fertility and economic data, type 1 \n for default fertility, type 2 \n for default economic cycle, type 3 \n your choice:  ')
profile = profiles(prof,:);

default_country = ' ';  
if prof > 1
    default_country = input('Type the name of default country:  ','s')
end

%---------------------------------------
% open results files for the 2 tables
fid_table1      = fopen([country_file_folder 'Table 1   ' profile ' ' default_country ' ' date  '.xls'],'w');
fid_tablefiscal = fopen([country_file_folder 'Table SRG ' profile ' ' default_country ' ' date  '.xls'],'w');
fid_table3      = fopen([country_file_folder 'Table 3   ' profile ' ' default_country ' ' date  '.xls'],'w');

fids = [fid_table1; fid_tablefiscal; fid_table3];
%---------------------------------------
%   Print headers of the two resulting tables
Print_Table_headers(fids)

%---------------------------------------
%   Get the values of the constants used in calculations
GetConstants_S_Module

%---------------------------------------
%   Read the data for the calculaiton of SR and SRG from the data files
GetSupportRatioData_S_Module

%---------------------------------------
%   In case of a default scenario, assign default country profiles 
if (profile(1:4) == 'defa')
    % get the default profiles
    ExtractDefaultData_S_Module   % get the default profiles
    % then assign the appropriate default profiles for the 2 scenarios
    if (profile == 'default_fer')
        ll = ll_default; ll_f = ll_f_default; expec = expec_default;
    elseif (profile == 'default_NTA')
        c_prof = c_prof_default;  yl_prof = yl_prof_default; 
        tgi_prof = tgi_prof_default; tgo_prof = tgo_prof_default;
    end
    
end

