mat2roms with modern matlab

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
jpringle
Posts: 108
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

mat2roms with modern matlab

#1 Unread post by jpringle »

Dear all --

I would like to create a ROMS grid file from a grid of h at longitude and latitude points. In the past this was possible with mat2roms_rps.m ( https://github.com/rsignell-usgs/seagri ... roms_rps.m ) Unfortunately, the code I can find on the web for this uses Chuck Denham's out of date NetCDF code for matlab. Has anyone updated it to work with modern MATLAB?

If not, I shall do so soon and post here. But I would prefer to be lazy. Well tested solutions to go from lat/lon and depth to ROMS grid files, with all metrics and lon_rho, x_rho, f & etc filled out, would also work. Don't care about language, within reason. But would prefer mat2roms_rps because it is well tested.

I know that the actual requirements of the grid files that ROMS needs are minimal (basically, f, angle, masks and the metrics). However, many plotting and nesting codes require more fields -- in particular, the positions of the state variables and derived mask values. Thus I would prefer to build on other's work rather than roll my own.

Jamie Pringle

jcwarner
Posts: 1200
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

Re: mat2roms with modern matlab

#2 Unread post by jcwarner »

We use the attached file:
mat2roms_mw.m
that uses Matlab inherent netcdf calls to create a roms grid file. An example usage would be:

***************************
theWRFFile='wrfinput_d01';
theROMSFile='roms_grid.nc';

% open the wrf file
rho.lat=ncread(theWRFFile,'XLAT');
rho.lon=ncread(theWRFFile,'XLONG');
rho.depth=zeros(size(rho.lon))+100;
rho.mask=1.0-ncread(theWRFFile,'LANDMASK');
spherical='T';
projection='mercator';
%call generic grid creation
save temp_jcw33.mat
eval(['mat2roms_mw(''temp_jcw33.mat'',''',theROMSFile,''');'])
!del temp_jcw33.mat
***************************

So the key parts are to make rho.lat,rho.lon,rho.depth,rho.mask, and set spherical flag and projection.
This m file will also work for rectangular, but then you set rho.x and rho.y, and spherical='F'.

-j
Attachments
mat2roms_mw.m
(6.97 KiB) Downloaded 313 times
create_roms_netcdf_grid_file.m
(7.52 KiB) Downloaded 321 times

Post Reply