function Run_LURNZ_compare_scenarios()
%
% This function provides a crude user interface for running LURNZ. It runs
% two LURNZ simulations and compares the outcomes between the scenarios.
%
% Estimated run times from Motu give LURNZ_compare_scenarios a run time of
%   15 minutes - all modules without saving PDF and ASCI maps
%   25 minutes - all modules saving all PDF and ASCI maps
%  140 minutes - all modules saving all PDF and ASCI maps with ALL_YEARS=1
% Simulating out to 2020 (12 years) at 25ha resolution
%

% Simon Anastasiadis
% 2013-04-23


%% Parameters Scenario 1

% SCENARIO NAME
% enter name here as a string (Warning: long names can cause errors)
scenario1.name = 'Carbon price 5';

% Carbon Price
%    - the international price of a tonne of co2-equiv emissions
%    - frequently set at $25
scenario1.Co2price = 5;

% The default age of harvest is between 26 and 32 years.
% The following variable modifies both these years, so all forestry between
% (26 + harvest_age) and (32 + harvest_age) is elegable for harvest.
scenario1.harvest_age = 0;

%% Parameters Scenario 2

% SCENARIO NAME
% enter name here as a string (Warning: long names can cause errors)
scenario2.name = 'Carbon price 25';

% Carbon Price
%    - the international price of a tonne of co2-equiv emissions
%    - frequently set at $25
scenario2.Co2price = 25;

% The default age of harvest is between 26 and 32 years.
% The following variable modifies both these years, so all forestry between
% (26 + harvest_age) and (32 + harvest_age) is elegable for harvest.
scenario2.harvest_age = 0;

%% Shared parameters

% FINAL SIMULATION YEAR
% Simulation will run from 2008 to last_year (recommended: 2009 to 2030)
last_year = 2020;

% MODULE CHOICE
% Specify which modules you wish to run
%    - value = 1 : module will be run
%    - value = 0 : module will not be run
%    - note: running later moduels requires earlier modules to run.
% Land Use Change Module
run_LUCM = 1;
% Land Use Allocation Module
run_LUAM = 1;
% Land Use Intensity Module
run_LUIM = 0;
% Greenhouse Gas Module
run_GHGM = 0;

% Save output
% Specify which modules you want PDF and ASCI map output from
%    - value = 1 : output will be saved
%    - value = 0 : output will not be saved
%    - only applies to modules that run
%    - Matlab output files and Excel summary tables are saved regardless
% Land Use Allocation Module
LUAM_PDFS = 1;
LUAM_ASCI = 1;
% Land Use InModule
LUIM_PDFS = 0;
LUIM_ASCI = 0;
% Greenhouse Gas Module
GHGM_PDFS = 0;
GHGM_ASCI = 0;

% OUTPUT FOR ALL YEARS
% Saves output for all simulation years or only the last year
%    - value = 0 : only save output for final year
%    - value = 1 : save output for all years
% Significanlty increase the run time of LURNZ
ALL_YEARS = 0;

%% Misc Parameters

% Pixel size
%    - specifies number of hectares per pixel
%    - acceptable values: 1 OR 25
%    - note that 1 ha resolution is not tested (2013-04-23) and will not
%      work without the '-v7.3' parameter included in every save command.
pixel_size = 1;

% -------------------------------------------------------------------
%% Programmer Boundary
% -------------------------------------------------------------------

% WARNING : FOLLOWING CODE IS NOT PART OF THE CRUDE USER INTERFACE
% WARNING : DO NOT EDIT BELOW THIS SECTION

% -------------------------------------------------------------------

%% Clear Command Window

clc

%% Check validity of inputs

% Scenarios have different names
msg = sprintf(['Error in Run LURNZ compare scenaios\n' ...
               'Both scenarios have the same name\n' ...
               'Unique scenario names are requierd to run']);
assert(~strcmpi(scenario1.name,scenario2.name), msg);
% Validity for GHG module
msg = sprintf(['Error in Run LURNZ\n', ...
               'Running GHG module requires Land Use Change, ' ...
               'Allocation and Intensity modules to also run.']);
assert(~(run_GHGM && ~all([run_LUCM, run_LUAM, run_LUIM])),msg);
% Validity for Intensity Module
msg = sprintf(['Error in Run LURNZ\n', ...
               'Running Intensity module requires Land Use Change ' ...
               'and Allocation to also run.']);
assert(~(run_LUIM && ~all([run_LUCM, run_LUAM])),msg);
% Validity for Allocation Module
msg = sprintf(['Error in Run LURNZ\n', ...
               'Running Allocation module requires ' ...
               'Land Use Change Module to also run.']);
assert(~(run_LUIM && ~all(run_LUCM)),msg);

%% Specify output path

% require data in specified format
output_date = datestr(now(), 'yyyy-mm-dd HH.MM.SS');

% output_folder
output_path = ['..\Output\Results ', output_date, ' c' ];
scenario1.output_path = [output_path,'\Scenario 1'];
scenario2.output_path = [output_path,'\Scenario 2'];

%% Add all required folders to path

% reset default path
restoredefaultpath
% Add required directories for LURNZ to Matlab path
P=genpath('.');
path(path,P);

%% Run modules

% Combine scenarios into a joint structure
scenarios = [scenario1, scenario2];

for scen = scenarios
    
    % Inform user
    msg = sprintf([' LURNZ : Beginning Scenario: ',scen.name]);
    disp(msg)
    tic();

    % Land Use Change Module
    if run_LUCM
        [~ ] = LURNZ_Land_Use_Change_Module(scen.Co2price, last_year, scen.output_path, pixel_size );
    end
    % Land Use Allocation Module
    if run_LUCM && run_LUAM
       LURNZ_Land_Use_Allocation_Module(last_year, pixel_size, scen.output_path, scen.Co2price, LUAM_PDFS, LUAM_ASCI, ALL_YEARS, scen.harvest_age );
    end
    % Land Use Intensity Module
    if run_LUCM && run_LUAM && run_LUIM
        LURNZ_Land_Use_Intensity_Module(pixel_size, scen.output_path, last_year, LUIM_PDFS, LUIM_ASCI, ALL_YEARS );
    end
    % Greenhouse Gas Module
    if run_LUCM && run_LUAM && run_LUIM && run_GHGM
        LURNZ_Greenhouse_Gas_Module(pixel_size, scen.output_path, last_year, GHGM_PDFS, GHGM_ASCI, ALL_YEARS );
    end

    % Inform user
    msg = sprintf(' LURNZ : Scenario Complete\n\n Run time : %.2f seconds\n\n',toc());
    disp(msg)
    
end
    
%% Compare scenarios

% Inform user
msg = sprintf(' LURNZ : Beginning Scenario Comparison');
disp(msg)
tic();

% Compare scenarios
LURNZ_Compare_scenarios(pixel_size, output_path, scenario1, scenario2, run_LUCM, run_LUAM, run_LUIM, run_GHGM, ALL_YEARS );

% Inform user
msg = sprintf(' LURNZ : Scenario Comparison Complete\n\n Run time : %.2f seconds\n\n',toc());
disp(msg)

end
