
function [gridout, EASE_r, EASE_s] = mkgrid_global(x)
%MKGRID_GLOBAL(x)  Creates a 586x1383 global EASE grid matrix for mapping   
% gridout = mkgrid_global(x) uses the 2090887 element array (x) and returns
% a 586x1383 global EASE grid matrix.

% The user should change the paths to the EASE grid row and column data (below)
% to their specific system locations.

% Lucas A. Jones <lucas@ntsg.umt.edu>


%Load ancillary EASE grid row and column data, where <MyDir> is the path to 
%wherever the globland_r and globland_c files are located on your machine.
fid = fopen('.\anci\globland_r','r');
EASE_r = fread(fid, 209091, 'int16');
fclose(fid);


fid = fopen('.\anci\globland_c','r');
EASE_s = fread(fid, 209091, 'int16');
fclose(fid);


%Initialize the global EASE grid 
gridout = NaN.*zeros(586,1383);

%Loop through the elment array
for i=1:1:209091     
        
    %Distribute each element to the appropriate location in the output
    %matrix (EASE grid base address is referenced to (0,0), but MATLAB is
    %(1,1)
    gridout(EASE_r(i)+1,EASE_s(i)+1) = x(i);
              
end
