Problem with 'ocean_grd.nc'

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
dhtjtks
Posts: 36
Joined: Thu Apr 19, 2007 12:18 am
Location: University of Florida

Problem with 'ocean_grd.nc'

#1 Unread post by dhtjtks »

Hi all,

I have a problem to simulate a simple tidal basin case. I made a simple rectangular domain (100 km in x-direction by 10 km in y-direction, and the grid spacing is 1 km by 1km). I put the tide at the eastern boundary. I tried both using 'ana_grid.h' and 'ocean_grd.nc', and both worked fine. However, when I put masking at the 'ocean_grd.nc', ROMS worked but with wrong results. When I looked at the result, ROMS made all grid cells to lands, but I didn't created 'ocean_grd.nc' like that. My method worked fine with ROMS3.0, but not with current version. I modified 'grd_spherical_cdl', which comes with ROMS, and created 'ocean_grd.nc'. When I modified, I deleted some variables (hraw, lat_rho, lon_rho, lat_psi, lon_psi, lat_u, lon_u, lat_v, lon_v, rdrag, rdrag2, ZoBot), which I thought I didn't need the values. This method worked fine with old version but not with new version. Below is my CDL file. Please tell me what I am wrong. The result showed that all domain was changed to land. Please help me.

Thanks,

Lee

netcdf ocean_grd {

dimensions:
xi_psi = 101 ;
xi_rho = 102 ;
xi_u = 101 ;
xi_v = 102 ;
eta_psi = 11 ;
eta_rho = 12 ;
eta_u = 12 ;
eta_v = 11 ;
bath = UNLIMITED ; // (0 currently)

variables:
int spherical ;
spherical:long_name = "grid type logical switch" ;
spherical:flag_values = "0, 1" ;
spherical:flag_meanings = "Cartesian spherical" ;
double xl ;
xl:long_name = "domain length in the XI-direction" ;
xl:units = "meter" ;
double el ;
el:long_name = "domain length in the ETA-direction" ;
el:units = "meter" ;
double h(eta_rho, xi_rho) ;
h:long_name = "Final bathymetry at RHO-points" ;
h:units = "meter" ;
h:coordinates = "lon_rho lat_rho" ;
double f(eta_rho, xi_rho) ;
f:long_name = "Coriolis parameter at RHO-points" ;
f:units = "second-1" ;
f:coordinates = "lon_rho lat_rho" ;
double pm(eta_rho, xi_rho) ;
pm:long_name = "curvilinear coordinate metric in XI" ;
pm:units = "meter-1" ;
pm:coordinates = "lon_rho lat_rho" ;
double pn(eta_rho, xi_rho) ;
pn:long_name = "curvilinear coordinate metric in ETA" ;
pn:units = "meter-1" ;
pn:coordinates = "lon_rho lat_rho" ;
double dndx(eta_rho, xi_rho) ;
dndx:long_name = "xi derivative of inverse metric factor pn" ;
dndx:units = "meter" ;
dndx:coordinates = "lon_rho lat_rho" ;
double dmde(eta_rho, xi_rho) ;
dmde:long_name = "eta derivative of inverse metric factor pm" ;
dmde:units = "meter" ;
dmde:coordinates = "lon_rho lat_rho" ;
double x_rho(eta_rho, xi_rho) ;
x_rho:long_name = "x location of RHO-points" ;
x_rho:units = "meter" ;
double y_rho(eta_rho, xi_rho) ;
y_rho:long_name = "y location of RHO-points" ;
y_rho:units = "meter" ;
double x_psi(eta_psi, xi_psi) ;
x_psi:long_name = "x location of PSI-points" ;
x_psi:units = "meter" ;
double y_psi(eta_psi, xi_psi) ;
y_psi:long_name = "y location of PSI-points" ;
y_psi:units = "meter" ;
double x_u(eta_u, xi_u) ;
x_u:long_name = "x location of U-points" ;
x_u:units = "meter" ;
double y_u(eta_u, xi_u) ;
y_u:long_name = "y location of U-points" ;
y_u:units = "meter" ;
double x_v(eta_v, xi_v) ;
x_v:long_name = "x location of V-points" ;
x_v:units = "meter" ;
double y_v(eta_v, xi_v) ;
y_v:long_name = "y location of V-points" ;
y_v:units = "meter" ;
double angle(eta_rho, xi_rho) ;
angle:long_name = "angle between XI-axis and EAST" ;
angle:units = "radians" ;
angle:coordinates = "lon_rho lat_rho" ;
double mask_rho(eta_rho, xi_rho) ;
mask_rho:long_name = "mask on RHO-points" ;
mask_rho:flag_values = 0., 1. ;
mask_rho:flag_meanings = "land water" ;
mask_rho:coordinates = "lon_rho lat_rho" ;
double mask_u(eta_u, xi_u) ;
mask_u:long_name = "mask on U-points" ;
mask_u:flag_values = 0., 1. ;
mask_u:flag_meanings = "land water" ;
mask_u:coordinates = "lon_u lat_u" ;
double mask_v(eta_v, xi_v) ;
mask_v:long_name = "mask on V-points" ;
mask_v:flag_values = 0., 1. ;
mask_v:flag_meanings = "land water" ;
mask_v:coordinates = "lon_v lat_v" ;
double mask_psi(eta_psi, xi_psi) ;
mask_psi:long_name = "mask on PSI-points" ;
mask_psi:flag_values = 0., 1. ;
mask_psi:flag_meanings = "land water" ;
mask_psi:coordinates = "lon_rho lat_rho" ;

// global attributes:
:type = "ROMS GRID file" ;
:title = "NJB grid for LEO-15" ;
}

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: Problem with 'ocean_grd.nc'

#2 Unread post by kate »

You can create a file with ncgen to get the correct variables and dimensions. How did you specify where you wanted your land mask? Did you have the full array of ones and zeros in the CDL file? Many, many scripting languages have a NetCDF interface which can be used to set the values or you can use the matlab/python mask editing features. If ana_grid.h is working for you, you can also try ana_mask.h.

dhtjtks
Posts: 36
Joined: Thu Apr 19, 2007 12:18 am
Location: University of Florida

Re: Problem with 'ocean_grd.nc'

#3 Unread post by dhtjtks »

kate wrote:You can create a file with ncgen to get the correct variables and dimensions. How did you specify where you wanted your land mask? Did you have the full array of ones and zeros in the CDL file? Many, many scripting languages have a NetCDF interface which can be used to set the values or you can use the matlab/python mask editing features. If ana_grid.h is working for you, you can also try ana_mask.h.
Hi Kate,

I created 'ocean_grd.nc' file using 'ncgen -b grd_spherical.cdl'. And I deleted some variables, which I though I didn't use for my grid. I am sure it worked fine for old version of ROMS, but not with current version. Oh, I am using matlab to fill the values. When I look at the results, the it masked all the domain, and the zeta values showed 1.0*10^23 values. After fill the values using matlab, I always re-check the values using ncload. It looks fine, but... result file doesn't look what I created.

Lee

dhtjtks
Posts: 36
Joined: Thu Apr 19, 2007 12:18 am
Location: University of Florida

Re: Problem with 'ocean_grd.nc'

#4 Unread post by dhtjtks »

kate wrote:You can create a file with ncgen to get the correct variables and dimensions. How did you specify where you wanted your land mask? Did you have the full array of ones and zeros in the CDL file? Many, many scripting languages have a NetCDF interface which can be used to set the values or you can use the matlab/python mask editing features. If ana_grid.h is working for you, you can also try ana_mask.h.
Hi Kate,

When you want to change variables in 'ocean_grd.nc', what method do you usually use? In my case, I use meccdf tool box for matlab. First, I load the values using 'ncload' command in matlab. And then, I changed the values such as h and mask_rho. Then, I save the values using 'ncsave'. It worked fine, but all of sudden it didn't. Do you use other method?

Thanks,
Lee

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: Problem with 'ocean_grd.nc'

#5 Unread post by kate »

For messing with NetCDF files I use NCL and/or Python. I was hoping someone else would help you with the Matlab if that's the road you want to take.

dhtjtks
Posts: 36
Joined: Thu Apr 19, 2007 12:18 am
Location: University of Florida

Re: Problem with 'ocean_grd.nc'

#6 Unread post by dhtjtks »

kate wrote:For messing with NetCDF files I use NCL and/or Python. I was hoping someone else would help you with the Matlab if that's the road you want to take.
Thanks Kate. I think it is the time to learn Phthon. Thanks anyway.

Lee

User avatar
arango
Site Admin
Posts: 1367
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Problem with 'ocean_grd.nc'

#7 Unread post by arango »

You can use the script matlab/grid/c_grid.m to create an empty ROMS grid NetCDF file:

> status=c_grid(Lp, Mp, 'my_grid.nc', true)

where Lp=L+1=Lm+2 and Mp=M+1+Mm+2. That is, Lp and Mp are the total number of points in the I- and J-directions (0:L, 0:M). Once that the file is created, you can use the NetCDF interface to Matlab (see matlab/utility/nc_write.m) to write the values of the grid variables to the desired values.

It is that simple! All these Matlab scripts are located in ROMS :arrow: repository which you can download using:

svn checkout https://www.myroms.org/svn/src/matlab MyDir

I don't understand why are you deleting variable from the CDL script. All these variables are used in one form or another. Believe me, if we won't use such variables, I will be the first one deleting them from the repository files.

:idea: I seems to me that you need to master how to manipulate NetCDF files. This is going to make your life easier when configuring ROMS...

dhtjtks
Posts: 36
Joined: Thu Apr 19, 2007 12:18 am
Location: University of Florida

Re: Problem with 'ocean_grd.nc'

#8 Unread post by dhtjtks »

arango wrote:You can use the script matlab/grid/c_grid.m to create an empty ROMS grid NetCDF file:

> status=c_grid(Lp, Mp, 'my_grid.nc', true)

where Lp=L+1=Lm+2 and Mp=M+1+Mm+2. That is, Lp and Mp are the total number of points in the I- and J-directions (0:L, 0:M). Once that the file is created, you can use the NetCDF interface to Matlab (see matlab/utility/nc_write.m) to write the values of the grid variables to the desired values.

It is that simple! All these Matlab scripts are located in ROMS :arrow: repository which you can download using:

svn checkout https://www.myroms.org/svn/src/matlab MyDir

I don't understand why are you deleting variable from the CDL script. All these variables are used in one form or another. Believe me, if we won't use such variables, I will be the first one deleting them from the repository files.

:idea: I seems to me that you need to master how to manipulate NetCDF files. This is going to make your life easier when configuring ROMS...
Oh! I will try that. Thanks for the help!

Thanks,
Lee

Post Reply