empty netcdf file using rgrd_AnaGrid from the rnt toolbox

Discussion of how to use ROMS on different regional and basin scale applications.

Moderators: arango, robertson

Post Reply
Message
Author
mathieudever

empty netcdf file using rgrd_AnaGrid from the rnt toolbox

#1 Unread post by mathieudever »

Hello,

I am trying to create a simple rectangular grid using the rnt toolbox, following the ROMS tutorials (http://www.oces.us/eas-ocean-modeling/R ... rials.html) and using matlab. My problem is in the creation of the netcdf grid file. I follow the tutorial, but my netcdf file is empty, while his contains all the required variables. Here is my MATLAB code

Code: Select all

% Spacing of the grid in the x and y direction [m]
dx=3000; dy=3000;

% Total length of domain in X and Y direction [m]
DX=150000;
DY=600000;

% name of the grid file to be generated
filename='test-grid.nc';

% Generate the grid
Lp=DX/dx;
Mp=DY/dy;
rgrd_AnaGrid(dx,dy,Lp,Mp,filename)
Because the netcdf file is empty, I cannot use any of the rnt_gridload() or rnt_gridinfo() functions.
Why is my netcdf file empty? I went through the MATLAB code, and I just do not get why the variables are not saved...

If anyone has a solution to this, I would very much appreciate the help!
Thanks,
Mat.

User avatar
manu
Posts: 3
Joined: Wed Dec 31, 2003 1:03 am
Location: Georgia Institute of Technology

Re: empty netcdf file using rgrd_AnaGrid from the rnt toolbo

#2 Unread post by manu »

Dear Mat,

I am sorry you are having trouble with generating the analytical grid netcdf file. I tested your code with my version of the routine rgrd_AnaGrid and I was able to generate the grid netcdf file. I strongly suspect that there is an issue with your netcdf toolbox installation. Here is a short video of my test:

https://www.dropbox.com/s/rjd4b10mztqw3 ... naGrid.mov

To check your netcdf toolbox installation, please try in MATLAB to execute the command:

Code: Select all

ncexample


If you do not have this code or if this code gives you an empty file, this will confirm that we need to fix the netcdf installation. Otherwise the issue may be more settle. I am posting here the version of the rgrd_AnaGrid I have, just in case.

Let me know how it goes.

Best wishes,

Manu

Code: Select all

function CreateGridFile(Lp,Mp,filename)
% FUNCTION CreateGridFile(Lp,Mp,filename)
% Creates an empty grid file of dimension Lp x Lm
%
%  05/03  E. Di Lorenzo (edl@gatech.edu) 

%Mp=44;
%Lp=92;
M=Mp-1;
Mm=Mp-2;
L=Lp-1;
Lm=Lp-2;

nc = netcdf(filename, 'clobber');
 
%% Global attributes:
 
nc.type = ncchar('Gridpak file');
nc.gridid = ncchar('                                                                                                                                ');
nc.history = ncchar('Created by E. Di Lorenzo ');
 
%% 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('two') = 2;
nc('bath') = 1; %% (record dimension)
 
%% Variables and attributes:
 
nc{'xl'} = ncdouble; %% 1 element.
nc{'xl'}.long_name = ncchar('domain length in the XI-direction');
nc{'xl'}.units = ncchar('meter');
 
nc{'el'} = ncdouble; %% 1 element.
nc{'el'}.long_name = ncchar('domain length in the ETA-direction');
nc{'el'}.units = ncchar('meter');
 
 
nc{'depthmin'} = ncshort; %% 1 element.
nc{'depthmin'}.long_name = ncchar('Shallow bathymetry clipping depth');
nc{'depthmin'}.units = ncchar('meter');
 
nc{'depthmax'} = ncshort; %% 1 element.
nc{'depthmax'}.long_name = ncchar('Deep bathymetry clipping depth');
nc{'depthmax'}.units = ncchar('meter');


nc{'spherical'} = ncchar; %% 1 element.
nc{'spherical'}.long_name = ncchar('Grid type logical switch');
nc{'spherical'}.option_T = ncchar('spherical');
nc{'spherical'}.option_F = ncchar('Cartesian');
 
 
nc{'hraw'} = ncdouble('bath', 'eta_rho', 'xi_rho'); %% 2068 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'); %% 2068 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'); %% 2068 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'); %% 2068 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'); %% 2068 elements.
nc{'pn'}.long_name = ncchar('curvilinear coordinate metric in ETA');
nc{'pn'}.units = ncchar('meter-1');
nc{'pn'}.field = ncchar('pn, scalar');
  
nc{'x_rho'} = ncdouble('eta_rho', 'xi_rho'); %% 2068 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'); %% 2068 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'); %% 1953 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'); %% 1953 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'); %% 2046 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'); %% 2046 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'); %% 1974 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'); %% 1974 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'); %% 2068 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'); %% 2068 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'); %% 1953 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'); %% 1953 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'); %% 2046 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'); %% 2046 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'); %% 1974 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'); %% 1974 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');
nc{'mask_rho'}.long_name = ncchar('mask on RHO-points');
nc{'mask_rho'}.long_name = 'mask on RHO-points';
nc{'mask_rho'}.option_0 = ncchar('land');
nc{'mask_rho'}.option_0 = 'land';
nc{'mask_rho'}.option_1 = ncchar('water');
nc{'mask_rho'}.option_1 = 'water';

nc{'mask_u'} = ncdouble('eta_u', 'xi_u');
nc{'mask_u'}.long_name = ncchar('mask on U-points');
nc{'mask_u'}.long_name = 'mask on U-points';
nc{'mask_u'}.option_0 = ncchar('land');
nc{'mask_u'}.option_0 = 'land';
nc{'mask_u'}.option_1 = ncchar('water');
nc{'mask_u'}.option_1 = 'water';

nc{'mask_v'} = ncdouble('eta_v', 'xi_v');
nc{'mask_v'}.long_name = ncchar('mask on V-points');
nc{'mask_v'}.long_name = 'mask on V-points';
nc{'mask_v'}.option_0 = ncchar('land');
nc{'mask_v'}.option_0 = 'land';
nc{'mask_v'}.option_1 = ncchar('water');
nc{'mask_v'}.option_1 = 'water';

nc{'mask_psi'} = ncdouble('eta_psi', 'xi_psi');
nc{'mask_psi'}.long_name = ncchar('mask on PSI-points');
nc{'mask_psi'}.long_name = 'mask on PSI-points';
nc{'mask_psi'}.option_0 = ncchar('land');
nc{'mask_psi'}.option_0 = 'land';
nc{'mask_psi'}.option_1 = ncchar('water');
nc{'mask_psi'}.option_1 = 'water';
 
%nc{'angle'} = ncdouble('eta_rho', 'xi_rho'); %% 2068 elements.
%nc{'angle'}.long_name = ncchar('angle between xi axis and east');
%nc{'angle'}.units = ncchar('degree');
 
endef(nc)
close(nc)

erick.fredj
Posts: 1
Joined: Mon Feb 08, 2010 5:40 pm
Location: The Jerusalem College of Technology

Re: empty netcdf file using rgrd_AnaGrid from the rnt toolbo

#3 Unread post by erick.fredj »

Hello,

I am trying to create a simple rectangular grid using the rnt toolbox, following the ROMS tutorials (http://www.oces.us/eas-ocean-modeling/R ... rials.html) and using matlab. My problem is in the creation of the netcdf grid file. I follow the tutorial, but my netcdf file is empty.

% Create analytical grid
% spacing of grid in the x and y directions, [m]

dx=3000; dy=3000;

% grid file to be generated
filename='../roms-examples/coriolis/input/coriolis-grid.nc';

% parameters
depth=300;
f0=1.4544e-04;

% number of gridpoint in the x and y direction
Lp=43; % x - direction
Mp=43; % y - direction

% generate the grid
rgrd_AnaGrid(dx,dy,Lp,Mp,filename)

% modify grid parameters
nc=netcdf(filename,'w');
nc{'f'}(:,:)=f0;
nc{'h'}(:,:)=depth;
close(nc);

I have a matlab 2012b can you please send me the relevant netcdf toolbox to check my installation on my computer. I should point that scntool and mexcdf passed all the checked tests in my computer.

thank you in advance

rockymt
Posts: 5
Joined: Tue Sep 22, 2015 3:09 pm
Location: Ludong University

Re: empty netcdf file using rgrd_AnaGrid from the rnt toolbo

#4 Unread post by rockymt »

I have the same problem in matlab R2014a. I find that the code

nc=netcdf(filename,'w');
.....
nc{'xl'}(:)=xl;

will not write xl in the netcdf file, which means the "write" permission failed. Alternatively, I use matlab function

nccreate(filename,'xl');
ncwrite(filename,'xl',xl);

This will work. But rnt toolbox is too complex to modify every details. Is there any good solution for this probelm?
erick.fredj wrote:Hello,

I am trying to create a simple rectangular grid using the rnt toolbox, following the ROMS tutorials (http://www.oces.us/eas-ocean-modeling/R ... rials.html) and using matlab. My problem is in the creation of the netcdf grid file. I follow the tutorial, but my netcdf file is empty.

% Create analytical grid
% spacing of grid in the x and y directions, [m]

dx=3000; dy=3000;

% grid file to be generated
filename='../roms-examples/coriolis/input/coriolis-grid.nc';

% parameters
depth=300;
f0=1.4544e-04;

% number of gridpoint in the x and y direction
Lp=43; % x - direction
Mp=43; % y - direction

% generate the grid
rgrd_AnaGrid(dx,dy,Lp,Mp,filename)

% modify grid parameters
nc=netcdf(filename,'w');
nc{'f'}(:,:)=f0;
nc{'h'}(:,:)=depth;
close(nc);

I have a matlab 2012b can you please send me the relevant netcdf toolbox to check my installation on my computer. I should point that scntool and mexcdf passed all the checked tests in my computer.

thank you in advance

Chang
Posts: 20
Joined: Sun Dec 04, 2016 1:03 am
Location: ocean university of china

Re: empty netcdf file using rgrd_AnaGrid from the rnt toolbo

#5 Unread post by Chang »

hello
Could anybody here tell me how to download and install the netcdf_toolbox properly?
thank you very much!

Post Reply