⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mat2roms_rps.m

📁 任意边界结构正交曲线网格生成程序
💻 M
📖 第 1 页 / 共 2 页
字号:
nc{'x_v'} = ncdouble('eta_v', 'xi_v'); %% 16770 elements.
nc{'x_v'}.long_name = ncchar('x location of V-points');
nc{'x_v'}.units = ncchar('meter');
 
nc{'y_v'} = ncdouble('eta_v', 'xi_v'); %% 16770 elements.
nc{'y_v'}.long_name = ncchar('y location of V-points');
nc{'y_v'}.units = ncchar('meter');
 
nc{'lat_rho'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.
nc{'lat_rho'}.long_name = ncchar('latitude of RHO-points');
nc{'lat_rho'}.units = ncchar('degree_north');
 
nc{'lon_rho'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.
nc{'lon_rho'}.long_name = ncchar('longitude of RHO-points');
nc{'lon_rho'}.units = ncchar('degree_east');
 
nc{'lat_psi'} = ncdouble('eta_psi', 'xi_psi'); %% 16641 elements.
nc{'lat_psi'}.long_name = ncchar('latitude of PSI-points');
nc{'lat_psi'}.units = ncchar('degree_north');
 
nc{'lon_psi'} = ncdouble('eta_psi', 'xi_psi'); %% 16641 elements.
nc{'lon_psi'}.long_name = ncchar('longitude of PSI-points');
nc{'lon_psi'}.units = ncchar('degree_east');
 
nc{'lat_u'} = ncdouble('eta_u', 'xi_u'); %% 16770 elements.
nc{'lat_u'}.long_name = ncchar('latitude of U-points');
nc{'lat_u'}.units = ncchar('degree_north');
 
nc{'lon_u'} = ncdouble('eta_u', 'xi_u'); %% 16770 elements.
nc{'lon_u'}.long_name = ncchar('longitude of U-points');
nc{'lon_u'}.units = ncchar('degree_east');
 
nc{'lat_v'} = ncdouble('eta_v', 'xi_v'); %% 16770 elements.
nc{'lat_v'}.long_name = ncchar('latitude of V-points');
nc{'lat_v'}.units = ncchar('degree_north');
 
nc{'lon_v'} = ncdouble('eta_v', 'xi_v'); %% 16770 elements.
nc{'lon_v'}.long_name = ncchar('longitude of V-points');
nc{'lon_v'}.units = ncchar('degree_east');
 
nc{'mask_rho'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.
nc{'mask_rho'}.long_name = ncchar('mask on RHO-points');
nc{'mask_rho'}.option_0_ = ncchar('land');
nc{'mask_rho'}.option_1_ = ncchar('water');
name(nc{'mask_rho'}.option_0_, 'option(0)')
name(nc{'mask_rho'}.option_1_, 'option(1)')
 
nc{'mask_u'} = ncdouble('eta_u', 'xi_u'); %% 16770 elements.
nc{'mask_u'}.long_name = ncchar('mask on U-points');
nc{'mask_u'}.option_0_ = ncchar('land');
nc{'mask_u'}.option_1_ = ncchar('water');
name(nc{'mask_u'}.option_0_, 'option(0)')
name(nc{'mask_u'}.option_1_, 'option(1)')
%		 nc{'mask_u'}.FillValue_ = ncdouble(1);
 
nc{'mask_v'} = ncdouble('eta_v', 'xi_v'); %% 16770 elements.
nc{'mask_v'}.long_name = ncchar('mask on V-points');
nc{'mask_v'}.option_0_ = ncchar('land');
nc{'mask_v'}.option_1_ = ncchar('water');
name(nc{'mask_v'}.option_0_, 'option(0)')
name(nc{'mask_v'}.option_1_, 'option(1)')
%		 nc{'mask_v'}.FillValue_ = ncdouble(1);
 
nc{'mask_psi'} = ncdouble('eta_psi', 'xi_psi'); %% 16641 elements.
nc{'mask_psi'}.long_name = ncchar('mask on PSI-points');
nc{'mask_psi'}.option_0_ = ncchar('land');
nc{'mask_psi'}.option_1_ = ncchar('water');
name(nc{'mask_psi'}.option_0_, 'option(0)')
name(nc{'mask_psi'}.option_1_, 'option(1)')
%		 nc{'mask_psi'}.FillValue_ = ncdouble(1);

% Now, what about depths: "h" and "hraw".  <== DEPTHS.

nc{'angle'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.
nc{'angle'}.long_name = ncchar('angle between xi axis and east');
nc{'angle'}.units = ncchar('radians');

% Variables.

% Fill the variables with data.

disp(' ## Filling Variables...')

if ~isfield(s, 'projection') | isempty(s.projection)
	s.projection = 'Mercator';
end
projection = s.projection;

switch lower(projection)
case 'mercator'
	theProjection = 'ME';
case 'stereographic'
	theProjection = 'ST';
case 'lambert conformal conic'
	theProjection = 'LC';
otherwise
	theProjection = '??';
end

nc{'JPRJ'}(1:2) = theProjection;
nc{'spherical'}(:) = 'T';   % T or F -- uppercase okay?

% Set projection parameters
%stdlt1o =   60.00
%stdlt2o =   30.00
%stdlono =   80.00
%m_proj('Lambert Conformal Conic','clon',stdlono,'para',[stdlt1o stdlt2o]);

m_proj(projection);

% Cartesian coordinates.
lon=s.rho.lon;
lat=s.rho.lat;

[x,y] = m_ll2xy(lon,lat);
radius=6371229.0;  % earth radius used by COAMPS
x=x*radius;
y=y*radius;

grid_x = interp2(x, 1);
grid_y = interp2(y, 1);

% interpolate Cartesian coordinates to get Geographic Coordinates at
% non-grid cell centers

[geogrid_lon, geogrid_lat] = m_xy2ll(grid_x/radius, grid_y/radius);   % Degrees.

xl = max(grid_x(:)) - min(grid_x(:));
el = max(grid_y(:)) - min(grid_y(:));
nc{'xl'}(:) = xl;
nc{'el'}(:) = el;

f = sw_f(lat);
nc{'f'}(:) = f;

% Handy indices.

[m2, n2] = size(grid_x);

i_rho = 1:2:n2;
j_rho = 1:2:m2;
i_psi = 2:2:n2;
j_psi = 2:2:m2;
i_u = 2:2:n2;
j_u = 1:2:m2;
i_v = 1:2:n2;
j_v = 2:2:m2;

% Locations.

nc{'x_rho'}(:) = x;
nc{'y_rho'}(:) = y;

nc{'x_psi'}(:) = grid_x(j_psi, i_psi);
nc{'y_psi'}(:) = grid_y(j_psi, i_psi);

nc{'x_u'}(:) = grid_x(j_u, i_u);
nc{'y_u'}(:) = grid_y(j_u, i_u);

nc{'x_v'}(:) = grid_x(j_v, i_v);
nc{'y_v'}(:) = grid_y(j_v, i_v);

nc{'lon_rho'}(:) = geogrid_lon(j_rho, i_rho);
nc{'lat_rho'}(:) = geogrid_lat(j_rho, i_rho);

nc{'lon_psi'}(:) = geogrid_lon(j_psi, i_psi);
nc{'lat_psi'}(:) = geogrid_lat(j_psi, i_psi);

lon_u = geogrid_lon(j_u, i_u);
lat_u = geogrid_lat(j_u, i_u);
nc{'lon_u'}(:) = lon_u;
nc{'lat_u'}(:) = lat_u;

lon_v = geogrid_lon(j_v, i_v);
lat_v = geogrid_lat(j_v, i_v);
nc{'lon_v'}(:) = lon_v;
nc{'lat_v'}(:) = lat_v;

% Metric factors: use ones if absent.

if ~isfield(s.rho, 'dx') | isempty(s.rho.dx)
	s.rho.dx = ones(size(nc{'pm'}));
end
if ~isfield(s.rho, 'dy') | isempty(s.rho.dy)
	s.rho.dy = ones(size(nc{'pn'}));
end

% dx = s.rho.dx;    % NO!  This is wrong.  Should calculate
% dy = s.rho.dy;    % dx and dy on spherical earth, not in projected coords

% use sw_dist to compute metric distances between lon/lon points

lat_u=lat_u.';
lon_u=lon_u.';
[dx,ang]=sw_dist(lat_u(:),lon_u(:),'km');

dx=[dx(:); dx(end)]*1000;  % km==> m
dx=reshape(dx,n-1,m);
dx=dx.';
dx=[dx(:,1) dx(:,(1:(end-1))) dx(:,end-1)];

ang=[ang(:); ang(end)];
ang=reshape(ang,n-1,m);
ang=ang.';
ang=[ang(:,1) ang(:,(1:(end-1))) ang(:,end-1)];

dy=sw_dist(lat_v(:),lon_v(:),'km');
dy=[dy(:); dy(end)]*1000;   % km ==> m 
dy=reshape(dy,m-1,n);
dy=[dy(1,:); dy((1:(end-1)),:); dy(end-1,:)];

dx(dx == 0) = NaN;   % Shouldn't be any zeros here.
dy(dy == 0) = NaN;

pm = 1 ./ dx;   % Note reciprocals.
pn = 1 ./ dy;

% Does ROMS tolerate NaNs and/or Infs?
%  Do we have to substitute a NetCDF "_FillValue"?

nc{'pm'}(:) = pm;
nc{'pn'}(:) = pn;

dmde = zeros(size(pm));
dndx = zeros(size(pn));

dmde(2:end-1, :) = 0.5*(1./pm(3:end, :) - 1./pm(1:end-2, :));
dndx(:, 2:end-1) = 0.5*(1./pn(:, 3:end) - 1./pn(:, 1:end-2));

nc{'dmde'}(:) = dmde;
nc{'dndx'}(:) = dndx;


% Depths at RHO points.

bathymetry = s.rho.depth;
mask = isnan(bathymetry) | (bathymetry == -99999);   % ECOM land = -99999.

bathymetry(mask) = min(bathymetry(:));   % set bathy under land to min depth
water = 1 - mask;   % ROMS requires water = 1, land= 0.
if ~isempty(bathymetry)
	nc{'h'}(:) = bathymetry;   % ROMS depths are positive.
end

% Angles at RHO points
nc{'angle'}(:) = ang*pi/180;   % Radians.

% The u, v, and psi masks rely directly on
%  the mask of the surrounding rho points.

nc{'mask_rho'}(:) = water;
nc{'mask_u'}(:) = water(:, 1:end-1) & water(:, 2:end);
nc{'mask_v'}(:) = water(1:end-1, :) & water(2:end, :);
nc{'mask_psi'}(:) = water(1:end-1, 1:end-1) &...
		water(1:end-1, 2:end) & ...
     		water(2:end, 1:end-1) & ...
  		water(2:end, 2:end);

% Close the ROMS File.

if ~isempty(close(nc))
	disp(' ## Unable too close the ROMS output file.')
end

% WetCDF off.

if isMacintosh
	eval('wetcdf off')
end

% ---------- romsnan ---------- %

function r = romsnan

% romsnan -- NaN value prefered by ROMS.
%  romsnan (no argument) returns the value prefered
%   by ROMS in place of NaN.  *** I believe it is
%   the NetCDF _FillValue for doubles.  (CRD)

f = ncfillvalues;
r = f.ncdouble;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -