I have been making simple rectangular Lambert grids, optionally rotated, using simple Matlab code and the m_map toolbox and some utilities from the myroms Matlab toolset to compute the grid metrics.
Code: Select all
mstruct = defaultm('lambertstd');
mstruct.mapparallels = 71.42;
mstruct.origin = [71.42 -52.6];
mstruct = defaultm(mstruct);
% grid dimensions
Lp = 3*2^7+2;
Mp = 3*2^5+2;
% Build rectangular grid from central point
[I,J] = meshgrid(1:Lp,1:Mp);
I = I-Lp/2;
J = J-Mp/2;
% guess at suitable domain size in projected coordinates to get dx,dy
% (alternative would be to experiment with minvtran calls to relate actual
% distance in latitude to dy units)
XL = 0.014;
EL = 0.0035;
dx = XL/Lp;
dy = EL/Mp;
% convert i,j to x,y
X = dx*I;
Y = dy*J;
theta = 0*pi/180;
if theta ~= 0
% rotate the grid
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
XY = [X(:) Y(:)]';
XY2 = R*XY;
X = reshape(XY2(1,:),size(X));
Y = reshape(XY2(2,:),size(Y));
end
% convert projected coordinate back to lon/lat
[rlat,rlon] = minvtran(mstruct,X,Y);
% Coastline for plotting
% clear S
if ~exist('S','var')
file = fullfile('/Users/wilkin/Dropbox/MATLAB/toolbox/myroms/m_map',...
'private/gshhs_h.b');
indexfile = gshhs(file, 'createindex');
S = gshhs(file,range(rlat),range(rlon));
end
% Plot
figure(1)
clf
axesm(mstruct,'MapLonLimit',range(rlon),'MapLatLimit',range(rlat),'Grid','on')
plotm(rlat,rlon,'k.')
a = axis;
levels = [S.Level];
L1 = S(levels==1);
geoshow([L1.Lat],[L1.Lon],'Color','k')
axis(a)
figure(2)
clf
plot(rlon,rlat,'.')
a = axis;
hold on
for k=1:size(S)
plot(S(k).Lon,S(k).Lat,'-')
end
hold off
axis(a)
amerc
% write the roms grid file
set_grid(rlon, rlat, 'test.nc','linear','i')
g = roms_get_grid('ks2.nc');