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

📄 mat2roms.m

📁 任意边界结构正交曲线网格生成程序
💻 M
📖 第 1 页 / 共 2 页
字号:
function mat2roms(theMatFile, theROMSFile)% mat2roms -- Convert from Mat-file to ROMS file.%  mat2roms('theMatFile', 'theROMSFile') converts%   'theMatFile' (mostly RHO information) to%   'theROMSFile'. % Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO.%  All Rights Reserved.%   Disclosure without explicit written consent from the%    copyright owner does not constitute publication. % Version of 22-May-2002 16:25:10.% Updated    17-Jun-2002 16:49:32.isMacintosh = ~isunix & any(findstr(lower(computer), 'mac'));if nargin < 1, theMatFile = '*.mat'; endif nargin < 2, theROMSFile = 'roms_model_grid.nc'; end% Get the file names.if any(theMatFile == '*')	help(mfilename)	theFilterSpec = theMatFile;	thePrompt = 'Select a Mat-File';	[theFile, thePath] = uigetfile(theFilterSpec, thePrompt);	if ~any(theFile), return, end	if thePath(end) ~= filesep, thePath(end+1) = filesep; end	theMatFile = [thePath theFile];endif any(theROMSFile == '*')	theFilterSpec = theROMSFile;	thePrompt = 'Save As ROMS File';	[theFile, thePath] = uiputfile(theFilterSpec, thePrompt);	if ~any(theFile), return, end	if thePath(end) ~= filesep, thePath(end+1) = filesep; end	theROMSFile = [thePath theFile];endif isequal(theMatFile, theROMSFile)	disp([' ## Must not select same file for input and output.'])	returnend% Load the Mat-File.s = load(theMatFile);if isempty(s)	disp([' ## Mat-File is empty.'])	returnend% We need to pay attention to the (i, j) coordinates%  stored in the file.  They are our only clue on the%  actual orientation of the data.  The "i" index%  goes left-to-right in the grid-world, while%  the "j" index runs bottom-to-top.% WetCDF on.if isMacintosh	eval('wetcdf on')end% Open the ROMS File.nc = netcdf(theROMSFile, 'clobber');if isempty(nc)	disp([' ## Unable to open ROMS NetCDF output file.'])	returnend% Populate the ROMS File. %% Global attributes:disp(' ## Defining Global Attributes...') nc.type = ncchar('Gridpak file');theGridTitle = 'ROMS Model Grid';nc.gridid = theGridTitle;nc.history = ncchar(['Created by "' mfilename '" on ' datestr(now)]);nc.CPP_options = ncchar('DCOMPLEX, DBLEPREC, NCARG_32, PLOTS,');name(nc.CPP_options, 'CPP-options')% Dimensions:[m, n] = size(s.rho.x);% The xi direction (left-right):LP = n;   % The rho dimension.L = LP-1; % The psi dimension.% The eta direction (up-down):MP = m;   % The rho dimension.M = MP-1; % The psi dimension.disp(' ## Defining Dimensions...') nc('xi_psi') = L;nc('xi_rho') = LP;nc('xi_u') = L;nc('xi_v') = LP;nc('eta_psi') = M;nc('eta_rho') = MP;nc('eta_u') = MP;nc('eta_v') = M;nc('one') = 1;nc('two') = 2;nc('bath') = 0; %% (record dimension) %% Variables and attributes:disp(' ## Defining Variables and Attributes...') nc{'xl'} = ncdouble('one'); %% 1 element.nc{'xl'}.long_name = ncchar('domain length in the XI-direction');nc{'xl'}.units = ncchar('meter'); nc{'el'} = ncdouble('one'); %% 1 element.nc{'el'}.long_name = ncchar('domain length in the ETA-direction');nc{'el'}.units = ncchar('meter'); nc{'JPRJ'} = ncchar('two'); %% 2 elements.nc{'JPRJ'}.long_name = ncchar('Map projection type');nc{'JPRJ'}.option_ME_ = ncchar('Mercator');nc{'JPRJ'}.option_ST_ = ncchar('Stereographic');nc{'JPRJ'}.option_LC_ = ncchar('Lambert conformal conic');name(nc{'JPRJ'}.option_ME_, 'option(ME)')name(nc{'JPRJ'}.option_ST_, 'option(ST)')name(nc{'JPRJ'}.option_LC_, 'option(LC)') nc{'PLAT'} = ncfloat('two'); %% 2 elements.nc{'PLAT'}.long_name = ncchar('Reference latitude(s) for map projection');nc{'PLAT'}.units = ncchar('degree_north'); nc{'PLONG'} = ncfloat('one'); %% 1 element.nc{'PLONG'}.long_name = ncchar('Reference longitude for map projection');nc{'PLONG'}.units = ncchar('degree_east'); nc{'ROTA'} = ncfloat('one'); %% 1 element.nc{'ROTA'}.long_name = ncchar('Rotation angle for map projection');nc{'ROTA'}.units = ncchar('degree'); nc{'JLTS'} = ncchar('two'); %% 2 elements.nc{'JLTS'}.long_name = ncchar('How limits of map are chosen');nc{'JLTS'}.option_CO_ = ncchar('P1, .. P4 define two opposite corners ');nc{'JLTS'}.option_MA_ = ncchar('Maximum (whole world)');nc{'JLTS'}.option_AN_ = ncchar('Angles - P1..P4 define angles to edge of domain');nc{'JLTS'}.option_LI_ = ncchar('Limits - P1..P4 define limits in u,v space');name(nc{'JLTS'}.option_CO_, 'option(CO)')name(nc{'JLTS'}.option_MA_, 'option(MA)')name(nc{'JLTS'}.option_AN_, 'option(AN)')name(nc{'JLTS'}.option_LI_, 'option(LI)') nc{'P1'} = ncfloat('one'); %% 1 element.nc{'P1'}.long_name = ncchar('Map limit parameter number 1'); nc{'P2'} = ncfloat('one'); %% 1 element.nc{'P2'}.long_name = ncchar('Map limit parameter number 2'); nc{'P3'} = ncfloat('one'); %% 1 element.nc{'P3'}.long_name = ncchar('Map limit parameter number 3'); nc{'P4'} = ncfloat('one'); %% 1 element.nc{'P4'}.long_name = ncchar('Map limit parameter number 4'); nc{'XOFF'} = ncfloat('one'); %% 1 element.nc{'XOFF'}.long_name = ncchar('Offset in x direction');nc{'XOFF'}.units = ncchar('meter'); nc{'YOFF'} = ncfloat('one'); %% 1 element.nc{'YOFF'}.long_name = ncchar('Offset in y direction');nc{'YOFF'}.units = ncchar('meter'); nc{'depthmin'} = ncshort('one'); %% 1 element.nc{'depthmin'}.long_name = ncchar('Shallow bathymetry clipping depth');nc{'depthmin'}.units = ncchar('meter'); nc{'depthmax'} = ncshort('one'); %% 1 element.nc{'depthmax'}.long_name = ncchar('Deep bathymetry clipping depth');nc{'depthmax'}.units = ncchar('meter'); nc{'spherical'} = ncchar('one'); %% 1 element.nc{'spherical'}.long_name = ncchar('Grid type logical switch');nc{'spherical'}.option_T_ = ncchar('spherical');nc{'spherical'}.option_F_ = ncchar('Cartesian');name(nc{'spherical'}.option_T_, 'option(T)')name(nc{'spherical'}.option_F_, 'option(F)') nc{'hraw'} = ncdouble('bath', 'eta_rho', 'xi_rho'); %% 0 elements.nc{'hraw'}.long_name = ncchar('Working bathymetry at RHO-points');nc{'hraw'}.units = ncchar('meter');nc{'hraw'}.field = ncchar('bath, scalar'); nc{'h'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'h'}.long_name = ncchar('Final bathymetry at RHO-points');nc{'h'}.units = ncchar('meter');nc{'h'}.field = ncchar('bath, scalar'); nc{'f'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'f'}.long_name = ncchar('Coriolis parameter at RHO-points');nc{'f'}.units = ncchar('second-1');nc{'f'}.field = ncchar('Coriolis, scalar'); nc{'pm'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'pm'}.long_name = ncchar('curvilinear coordinate metric in XI');nc{'pm'}.units = ncchar('meter-1');nc{'pm'}.field = ncchar('pm, scalar'); nc{'pn'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'pn'}.long_name = ncchar('curvilinear coordinate metric in ETA');nc{'pn'}.units = ncchar('meter-1');nc{'pn'}.field = ncchar('pn, scalar'); nc{'dndx'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'dndx'}.long_name = ncchar('xi derivative of inverse metric factor pn');nc{'dndx'}.units = ncchar('meter');nc{'dndx'}.field = ncchar('dndx, scalar'); nc{'dmde'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'dmde'}.long_name = ncchar('eta derivative of inverse metric factor pm');nc{'dmde'}.units = ncchar('meter');nc{'dmde'}.field = ncchar('dmde, scalar'); nc{'x_rho'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'x_rho'}.long_name = ncchar('x location of RHO-points');nc{'x_rho'}.units = ncchar('meter'); nc{'y_rho'} = ncdouble('eta_rho', 'xi_rho'); %% 16900 elements.nc{'y_rho'}.long_name = ncchar('y location of RHO-points');nc{'y_rho'}.units = ncchar('meter'); nc{'x_psi'} = ncdouble('eta_psi', 'xi_psi'); %% 16641 elements.nc{'x_psi'}.long_name = ncchar('x location of PSI-points');nc{'x_psi'}.units = ncchar('meter'); nc{'y_psi'} = ncdouble('eta_psi', 'xi_psi'); %% 16641 elements.nc{'y_psi'}.long_name = ncchar('y location of PSI-points');nc{'y_psi'}.units = ncchar('meter'); nc{'x_u'} = ncdouble('eta_u', 'xi_u'); %% 16770 elements.nc{'x_u'}.long_name = ncchar('x location of U-points');nc{'x_u'}.units = ncchar('meter'); nc{'y_u'} = ncdouble('eta_u', 'xi_u'); %% 16770 elements.nc{'y_u'}.long_name = ncchar('y location of U-points');nc{'y_u'}.units = ncchar('meter'); nc{'x_v'} = ncdouble('eta_v', 'xi_v'); %% 16770 elements.

⌨️ 快捷键说明

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