%----------------------------------------------------------          
%   GetSupportRatioData_S_Module
%----------------------------------------------------------
%   In this module, all the necessary demographic and economic cycle data
%       are read from the appropriate input files
%   
%   Functions 
%       extractUN_DataS
%       extractNTA_DataS
%   are used; the two types of data have different formats

%----------------------------------------------------------          
%   Get the list of countries (and years) for which to run the program
%----------------------------------------------------------          
[Parameters TextData] = xlsread(dataFile,'SCIENCE_countries');
Pcountries = TextData(2:end,1); Pregions = TextData(2:end,2); 
Pyears = Parameters(1:end); 
if isnan(Pyears(1)) Pyears = Pyears(2:end); end
[Ncountries, bogus]=size(Pcountries);

%----------------------------------------------------------          
%   Get the proportion of surviving persons l(x) for combined sexes 
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'lx');
countriesLX = textData(2:end,1); DBlx = numData(1:end,:); dataType = 'lx';
[small_l, allDataFound] = extractUN_DataS(Pcountries, countriesLX, DBlx, dataType);

%----------------------------------------------------------          
%   Get the proportion of surviving females lf(x) (female l(x))
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'lxF');
countriesLFX = textData(2:end,1); DBlfx = numData(1:end,:); dataType = 'lfx';
[small_l_f, allDataFound] = extractUN_DataS(Pcountries, countriesLFX, DBlfx, dataType);

%----------------------------------------------------------          
%   Get the life expectancy e(x)
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'ex');
countriesEX = textData(2:end,1); DBex = numData(1:end,:); dataType = 'ex';
[lifeExpectancy, allDataFound] = extractUN_DataS(Pcountries, countriesEX, DBex, dataType);

%----------------------------------------------------------          
%   Get Birth Ratios   
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'BmBf');
countriesBR = textData(2:end,1); DBbr = numData(1:end,:); dataType = 'br';
[BirthRatio, allDataFound] = extractUN_DataS(Pcountries, countriesBR, DBbr, dataType);
BirthRatio = BirthRatio(1:end,end);

%----------------------------------------------------------          
%   Get age-specific fertility profiles  
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'ASFR');
countriesASFR = textData(2:end,1); DBasfr = numData(1:end,:); dataType = 'asfr';
[fertility, allDataFound] = extractUN_DataS(Pcountries, countriesASFR, DBasfr, dataType);

%----------------------------------------------------------          
%   Get Population profiles for the each country in year 2010                           
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'UN pop2010');
countriesPOP = textData(2:end,1); DBpop = numData(2:end,:); dataType = 'pop';
[population, allDataFound] = extractUN_DataS(Pcountries, countriesPOP, DBpop, dataType);

%----------------------------------------------------------          
%   Get Consumption profiles
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'consumption');
dataType = 'Cons';
[consumption, allDataFound] = extractNTA_DataS(Pcountries, Pyears, textData, numData, dataType, AGE_MAX);

%----------------------------------------------------------          
%   Get Labor Income profiles
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'laborIncome');
dataType = 'LabIn';
[laborIncome, allDataFound] = extractNTA_DataS(Pcountries, Pyears, textData, numData, dataType, AGE_MAX);

%----------------------------------------------------------          
%   Get transfer Inflows profiles
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'tgi');
dataType = 'TGI';
[transferInflows, allDataFound] = extractNTA_DataS(Pcountries, Pyears, textData, numData, dataType, AGE_MAX);

%----------------------------------------------------------          
%   Get transfer Outflows profiles
%----------------------------------------------------------          
[numData textData] = xlsread(dataFile,'tgo');
dataType = 'TGO';
[transferOutflows, allDataFound] = extractNTA_DataS(Pcountries, Pyears, textData, numData, dataType, AGE_MAX);
