% do_paste.m
%
% Program to paste together 1 deg by 1 deg squares of data to produce a 3 sec bathy grid of the
% Gulf of Maine Region (GOM).
%
% Program calls: grdpaste from Generic Mapping Tools.
% 
% Input: 1 degree by 1 degree squares
%
% Output: 3 sec bathy grid of the GOM.
%
% Erin R. Twomey
% etwomey@usgs.gov
% 9/15/08
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% grdpaste only allows for two grids to be pasted together. Grids need to
% be pasted by column for each row. First create a grid for columns one and
% two. This will be the base grid.

row = {'A','B', 'C', 'D', 'E', 'F', 'G'};

for i = 1:7
%for i = 4:6
%for j = 3:9
    
cmd = sprintf('!grdpaste GOM_061311_%s%d_3sec_cut.grd GOM_061311_%s%d_3sec_cut.grd -G%sbase.grd -V',char(row(i)),1,char(row(i)),2,char(row(i)))
%cmd = sprintf('!grdpaste GOM_041609_%s%d_3secx.grd GOM_041609_%s%d_3secx.grd -G%sbase.grd -V',char(row(i)),1,char(row(i)),2,char(row(i)))
eval(cmd)
    
for j = 3:9 %Start with 3 because 1 and 2 are pasted together to create the base grid. 
    %for j = 8:9
    
   
cmd2 = sprintf('!grdpaste %sbase.grd GOM_061311_%s%d_3sec_cut.grd -G%sbase.grd -V',char(row(i)),char(row(i)),j,char(row(i)))
%cmd2 = sprintf('!grdpaste %sbase.grd GOM_041609_%s%d_3secx.grd -G%sbase.grd -V',char(row(i)),char(row(i)),j,char(row(i)))
    
eval(cmd2)

    end
    
end

% Paste the rows together to produce the final grid. 

%cmd3 = sprintf('! grdpaste Abase.grd Bbase.grd -GGOM_070609_%s%d_3sec.grd -V',char(row(i)),char(row(i)),j,char(row(i)));
cmd3 = sprintf('! grdpaste Abase.grd Bbase.grd -GGOM_061311_3sec.grd -V')
%cmd3 = sprintf('! grdpaste Abase.grd Bbase.grd -GGOM_041609_3secx.grd -V',char(row(i)),char(row(i)),j,char(row(i)));

eval(cmd3)

for i = 3:7
%for i = 6
    
    cmd4 = sprintf('! grdpaste GOM_061311_3sec.grd %sbase.grd -GGOM_061311_3sec.grd -V',char(row(i)));
    eval(cmd4)

end    
