% Loads input files. For global studies, these files should be given as,
% i.e. 180 by 360 matrix (for 1 by 1 degree resolution). Half degree would
% be 360 by 720 etc. This routine will construct a 'mask' with vegetated
% gridcells and will reshape them into a X by 1 matrix, where X is the
% total number of vegetated gridcells.
% The files which contain monthly varying parameters (i.e., precipitation)
% should be given as (for 1 by 1 degree:) 180 by 360 by 12, and will be
% reshaped to a X by 12 matrix, one column for each month.

% load continuous fields maps
eval(['load data/' resolution '/perc_tree'])             % tree cover percentage
eval(['load data/' resolution '/perc_herb'])             % herbaceous percentage

% load climate files
eval(['load data/' resolution '/climatology/airt'])      % air temperature
eval(['load data/' resolution '/climatology/ppt'])       % precipitation
eval(['load data/' resolution '/climatology/solrad'])    % solar radiation, taken from Bishop & Rossow, average 83-99 (from Jim Collatz)
eval(['load data/' resolution '/climatology/NDVI'])      % Fraction of Photosynthetically Active Radiation
eval(['load data/' resolution '/climatology/BF'])        % Fraction of the gridcell that burns

% load other files
eval(['load data/' resolution '/soiltext'])              % soil type
eval(['load data/' resolution '/veg'])                   % vegetation map (SiB / CASA classification)
eval(['load data/' resolution '/fuelneed'])              % amount of fuelwood needed per capita
eval(['load data/' resolution '/popdens'])               % population density map (persons m-2)

% make a mask of vegetated grid cells that contain data for all input
% parameters
[x,y]=size(perc_tree);mask=zeros(x,y);mask(perc_tree+perc_herb>0 & veg>0)=1;    % only vegetated data

numberOfGridCells=sum(mask(:));                                         % number of vegetated grid cells    

% convert maps into one column with only vegetated grid cells
veg         = maskfile(veg,mask);
soiltext    = maskfile(soiltext,mask);
fuelneed    = maskfile(fuelneed,mask);
popdens     = maskfile(popdens,mask);
perc_tree   = maskfile(perc_tree,mask);
perc_herb   = maskfile(perc_herb,mask);

perc_tree   = perc_tree./100; perc_herb = perc_herb./100;

% converts monthly maps into files with one column for each month
airt    = mask12file(airt,mask);
ppt     = mask12file(ppt,mask);
solrad  = mask12file(solrad,mask);
NDVI    = mask12file(NDVI,mask);
BF      = mask12file(BF,mask);

% make a grid area map and mask it
gridArea=maskfile(makeGridArea(x,y),mask);