Need Help Saving Idealized Grid Structure to NetCDF File in MATLAB

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
hyc006
Posts: 24
Joined: Thu Nov 30, 2023 2:12 am
Location: UCSD

Need Help Saving Idealized Grid Structure to NetCDF File in MATLAB

#1 Unread post by hyc006 »

Hi ROMS community,

I'm a new user in ROMS and I'm currently working on setting up an idealized grid for the ROMS model using MATLAB and have run into a bit of a roadblock. I'm trying to save the grid structure to a NetCDF file, as required by ROMS.

On the ROMS wiki [https://www.myroms.org/wiki/Grid_Processing_Scripts], I found the "write_contact.m" function (the last function on this website), but it seems to be designed for nested grids, and mine is not.

Here's the matlab function:
write_contact(ncname, S, Lcreate)
Writes out the nested grids contact points data generated by contact.m or read_contact.m into a NetCDF.

Since my grid isn't nested, I'm wondering if there's a different approach or function to save the grid structure to a NetCDF file in MATLAB.

Any guidance or suggestions would be highly appreciated. Thanks a bunch!

MIDHILAVARNAV
Posts: 30
Joined: Fri Dec 15, 2017 6:07 pm

Re: Need Help Saving Idealized Grid Structure to NetCDF File in MATLAB

#2 Unread post by MIDHILAVARNAV »

The function is c_grid.m. The function takes the following as arguments on input:
%
% Lp Number of RHO-points in the XI-direction
% Mp Number of RHO-points in the ETA-direction
% Gname Grid NetCDF file name (string)
% NewFile Switch to create a new file (logical, OPTIONAL)
% spherical Spherical grid switch (default true)

Write_contact.m is for creating a contact file between two or more nested grids.

hyc006
Posts: 24
Joined: Thu Nov 30, 2023 2:12 am
Location: UCSD

Re: Need Help Saving Idealized Grid Structure to NetCDF File in MATLAB

#3 Unread post by hyc006 »

Thanks a lot for your prompt reply! I truly appreciate your assistance.

Your suggestion to use c_grid for creating a new grid was helpful. Now, I have a follow-up question. If I make changes to specific parameters, such as f, mask_v, or lon_rho these kind of variables, within the grid structure, how can I save these modifications back into the NetCDF file?

I'm eager to learn more and your guidance has been invaluable.

Thanks again

MIDHILAVARNAV
Posts: 30
Joined: Fri Dec 15, 2017 6:07 pm

Re: Need Help Saving Idealized Grid Structure to NetCDF File in MATLAB

#4 Unread post by MIDHILAVARNAV »

If you have made changes to variables you can use the inbuilt function of matlab (nwrite) itself to store them in the existing variable of the netcdf file.

hyc006
Posts: 24
Joined: Thu Nov 30, 2023 2:12 am
Location: UCSD

Re: Need Help Saving Idealized Grid Structure to NetCDF File in MATLAB

#5 Unread post by hyc006 »

Got it! Thank you for your guidance!

Post Reply