editmask, matlab 7 and mexnc
editmask, matlab 7 and mexnc
We are trying to upgrade to matlab 7 but editmask does not seem to want to work. It looks like the change from mexcdf60 to mexnc is the issue:
>> editmask
spherical is a scalar and has a value of T
mask_rho has the following dimensions (input order):
1) eta_rho = 150
2) xi_rho = 300
mask_rho loaded into an array of size: [300 150]
??? call to ncvarget failed.
Error in ==> mexcdf53 at 9
[varargout{:}] = feval('mexnc', varargin{:});
Error in ==> mexcdf at 121
[varargout{:}] = feval(fcn, varargin{:});
Error in ==> nc_read at 139
[f,status]=mexcdf('ncvarget',ncid,varid,start,count);
Error in ==> read_mask at 124
bath=nc_read(Gname,Vname.hraw,1);
Error in ==> editmask at 265
[spherical,rlon,rlat,bath,mask]=read_mask(grid_file);
Has anyone encountered this one? It runs fine on matlab 6.5 and mexcdf60.
Thanks,
Justin Rogers
URI GSO
>> editmask
spherical is a scalar and has a value of T
mask_rho has the following dimensions (input order):
1) eta_rho = 150
2) xi_rho = 300
mask_rho loaded into an array of size: [300 150]
??? call to ncvarget failed.
Error in ==> mexcdf53 at 9
[varargout{:}] = feval('mexnc', varargin{:});
Error in ==> mexcdf at 121
[varargout{:}] = feval(fcn, varargin{:});
Error in ==> nc_read at 139
[f,status]=mexcdf('ncvarget',ncid,varid,start,count);
Error in ==> read_mask at 124
bath=nc_read(Gname,Vname.hraw,1);
Error in ==> editmask at 265
[spherical,rlon,rlat,bath,mask]=read_mask(grid_file);
Has anyone encountered this one? It runs fine on matlab 6.5 and mexcdf60.
Thanks,
Justin Rogers
URI GSO
Error in ==> mexcdf at 121
[varargout{:}] = feval(fcn, varargin{:});
Check your mexcdf.m file. In my version, the variable fcn is created at the top of the file based on the version of Matlab you have, and 7 isn't an option, so the variable is never set:
v=version;
if v(1) == '6'
fcn = 'mexcdf60';
elseif v(1) == '5'
fcn = 'mexcdf53';
elseif v(1) == '4'
fcn = 'mexcdf4'
end
This occurs in a few other files as well: ncclose.m, ncmex.m, tmexcdf.m, tnc4ml5.m. Try adding:
elseif v(1) == '7'
fcn = 'netcdf60';
[varargout{:}] = feval(fcn, varargin{:});
Check your mexcdf.m file. In my version, the variable fcn is created at the top of the file based on the version of Matlab you have, and 7 isn't an option, so the variable is never set:
v=version;
if v(1) == '6'
fcn = 'mexcdf60';
elseif v(1) == '5'
fcn = 'mexcdf53';
elseif v(1) == '4'
fcn = 'mexcdf4'
end
This occurs in a few other files as well: ncclose.m, ncmex.m, tmexcdf.m, tnc4ml5.m. Try adding:
elseif v(1) == '7'
fcn = 'netcdf60';
Solved
Thank you both - a combination seemed to work just fine. I commented the old version checks out and changed mexcdf.m to read
%if eval(v(1)) > 4
% fcn = 'mexcdf53'; % Matlab-5 or 6.
%elseif eval(v(1)) == 4
% fcn = 'mexcdf4'; % Matlab-4 only.
%elseif eval(v(1)) == '7'
fcn = 'mexnc';
%else
% error(' ## Unrecognized Matlab version.')
%end
which got the error to happen in the right file, and gave a non-zero value (1,1) to hraw in my .nc file. The fail-on-zero hraw might also be avoided by adding bathymetry first.
%if eval(v(1)) > 4
% fcn = 'mexcdf53'; % Matlab-5 or 6.
%elseif eval(v(1)) == 4
% fcn = 'mexcdf4'; % Matlab-4 only.
%elseif eval(v(1)) == '7'
fcn = 'mexnc';
%else
% error(' ## Unrecognized Matlab version.')
%end
which got the error to happen in the right file, and gave a non-zero value (1,1) to hraw in my .nc file. The fail-on-zero hraw might also be avoided by adding bathymetry first.
seagrid bathymetry and editmask.
Hello all,
I first loaded the amazon bathymetry, generated a coastline, and generated a sample grid. Then I used seagrid2roms to generate the .nc file. The header looks like the following:
netcdf amazont_test {
dimensions:
xi_psi = 9 ;
xi_rho = 10 ;
xi_u = 9 ;
xi_v = 10 ;
eta_psi = 9 ;
eta_rho = 10 ;
eta_u = 10 ;
eta_v = 9 ;
two = 2 ;
bath = UNLIMITED ; // (0 currently)
I have seen postings that say bath cannot be 0 and that can be avoided by adding bathymetry first. How does one do that? Probably because bath = 0, I get the following error message when I do editmask?
??? call to ncvarget failed.
Error in ==> mexcdf53 at 9
[varargout{:}] = feval('mexnc', varargin{:});
Error in ==> mexcdf at 121
[varargout{:}] = feval(fcn, varargin{:});
Error in ==> ncread at 139
[f,status]=mexcdf('ncvarget',ncid,varid,start,count);
Error in ==> nc_read at 150
f=ncread(fname,vname,tindex);
Error in ==> read_mask at 124
bath=nc_read(Gname,Vname.hraw,1);
Error in ==> editmask at 265
[spherical,rlon,rlat,bath,mask]=read_mask(grid_file);
Any help would be appreciated.
Sankar
I first loaded the amazon bathymetry, generated a coastline, and generated a sample grid. Then I used seagrid2roms to generate the .nc file. The header looks like the following:
netcdf amazont_test {
dimensions:
xi_psi = 9 ;
xi_rho = 10 ;
xi_u = 9 ;
xi_v = 10 ;
eta_psi = 9 ;
eta_rho = 10 ;
eta_u = 10 ;
eta_v = 9 ;
two = 2 ;
bath = UNLIMITED ; // (0 currently)
I have seen postings that say bath cannot be 0 and that can be avoided by adding bathymetry first. How does one do that? Probably because bath = 0, I get the following error message when I do editmask?
??? call to ncvarget failed.
Error in ==> mexcdf53 at 9
[varargout{:}] = feval('mexnc', varargin{:});
Error in ==> mexcdf at 121
[varargout{:}] = feval(fcn, varargin{:});
Error in ==> ncread at 139
[f,status]=mexcdf('ncvarget',ncid,varid,start,count);
Error in ==> nc_read at 150
f=ncread(fname,vname,tindex);
Error in ==> read_mask at 124
bath=nc_read(Gname,Vname.hraw,1);
Error in ==> editmask at 265
[spherical,rlon,rlat,bath,mask]=read_mask(grid_file);
Any help would be appreciated.
Sankar
Time
Hi Sankar,
hraw is tricky... it needs a time parameter. For example,
ncwrite('grid.nc','hraw',MyH,1)
I'm not certain what hraw is actually used for, 'h' is the bathymetry variable in the gridfile that is active in my setup. Editmask will likely work once this is assigned.
hraw is tricky... it needs a time parameter. For example,
ncwrite('grid.nc','hraw',MyH,1)
I'm not certain what hraw is actually used for, 'h' is the bathymetry variable in the gridfile that is active in my setup. Editmask will likely work once this is assigned.
Forget hraw. I would bet money that edimask doesn't use it. Your error here:
leads me to believe that you are missing the mask variables. You need to get seagrid (or something else) to provide the starting mask values so that editmask can read and edit them.
If you insist on talking about hraw, it is a working bathymetry, possibly in various stages of smoothing. The next iteration on the grid file format will have a string associated with it too, describing what that bathymetry is. Perhaps you try both ETOPO5 and Gebco and want them both in your grid file. hraw lets you do that. Then you copy your final version into h for the model to use (ROMS doesn't know about hraw).
Code: Select all
Error in ==> editmask at 265
[spherical,rlon,rlat,bath,mask]=read_mask(grid_file);
If you insist on talking about hraw, it is a working bathymetry, possibly in various stages of smoothing. The next iteration on the grid file format will have a string associated with it too, describing what that bathymetry is. Perhaps you try both ETOPO5 and Gebco and want them both in your grid file. hraw lets you do that. Then you copy your final version into h for the model to use (ROMS doesn't know about hraw).
- arango
- Site Admin
- Posts: 1367
- Joined: Wed Feb 26, 2003 4:41 pm
- Location: DMCS, Rutgers University
- Contact:
It seems that there is a confusion with hraw and h variables in the input ROMS grid NetCDF file. The variable hraw has 3 dimensions. The third dimension (bath) is ulimitted and may grow. The first record (bath=1) is intended to contain the raw bathymetry as interpolated from a database. The other records may contain different stages of smoothing. The user then may choose a smoothed record and write it in the h NetCDF variable.
Recall that the ROMS bathymetry requires some smoothing before any applications can be run. The level of smoothing depends on the application, horizontal and vertical resolution, steepness, shallowest and deepest cut-off values, tolerable pressure gradient errors, r-factor, basin volume, land sinking or land filling during filtering, and so on. This kind of knowledge is acquired with modeling experence and ROMS usage. Therefore, the hraw variable can be used cleverly.
Notice that during land/sea masking editing the raw bathymetry (bath=1) may be used as a guideline to locate the coastline. In my applications, nowadays I write the coastlines extracted from GSHHS database which can be used in SeaGrid. This coastline data is needed by editmask. I don't know which version of editmask is out there. My intention is to have all those pre-processing software under svn control in the future.
The hraw bathymetry can be plotted using ROMS plotting package. Check for example the following figure and its zoom by moving the cursor.
Recall that the ROMS bathymetry requires some smoothing before any applications can be run. The level of smoothing depends on the application, horizontal and vertical resolution, steepness, shallowest and deepest cut-off values, tolerable pressure gradient errors, r-factor, basin volume, land sinking or land filling during filtering, and so on. This kind of knowledge is acquired with modeling experence and ROMS usage. Therefore, the hraw variable can be used cleverly.
Notice that during land/sea masking editing the raw bathymetry (bath=1) may be used as a guideline to locate the coastline. In my applications, nowadays I write the coastlines extracted from GSHHS database which can be used in SeaGrid. This coastline data is needed by editmask. I don't know which version of editmask is out there. My intention is to have all those pre-processing software under svn control in the future.
The hraw bathymetry can be plotted using ROMS plotting package. Check for example the following figure and its zoom by moving the cursor.
-
- Posts: 15
- Joined: Fri Jan 05, 2007 3:36 pm
- Location: Ocean institution,Chinese Academy of Sciences
hi, all,
I want to use the roms_tools with matlab 7.0 R14, but got the following errors,
make_grid
Making the grid: ../Run/ROMS_FILES/roms_grd.nc
Title: Benguela Test Model
Resolution: 1/3 deg
Create the grid file...
LLm = 23
MMm = 31
## NetCDF file not opened: ../Run/ROMS_FILES/roms_grd.nc
??? Undefined command/function 'redef'.
Error in ==> create_grid at 38
result = redef(nw);
Error in ==> make_grid at 74
create_grid(L,M,grdname,ROMS_title)
and I add the items for matlab version 7 according to the above posts, and the similar errors remain. can anyone tell me how to do next? thanks
I want to use the roms_tools with matlab 7.0 R14, but got the following errors,
make_grid
Making the grid: ../Run/ROMS_FILES/roms_grd.nc
Title: Benguela Test Model
Resolution: 1/3 deg
Create the grid file...
LLm = 23
MMm = 31
## NetCDF file not opened: ../Run/ROMS_FILES/roms_grd.nc
??? Undefined command/function 'redef'.
Error in ==> create_grid at 38
result = redef(nw);
Error in ==> make_grid at 74
create_grid(L,M,grdname,ROMS_title)
and I add the items for matlab version 7 according to the above posts, and the similar errors remain. can anyone tell me how to do next? thanks
Re: editmask, matlab 7 and mexnc
Hi,
We had the same problem with editmask upgrading from matlab 6 (R13) to matlab 2007a. The problem seems to be that the mexnc functions crashes when retrieving an empty variable if the first dimension is zero, in their version for matlab2007a, whereas in the version for matlab R13 it retrieves an empty matrix. The mexcdf version we use was downloaded from sourceforge for matlab2007a.
This is the output for matlab2007:
#############################################################
filename = '/data/roms/Grids/MR.Hmin40.r0.2.Resolucion31.nc'
filename =
/data/roms/Grids/MR.Hmin40.r0.2.Resolucion31.nc
>> ncread (filename,'hraw')
??? call to ncvarget failed.
Error in ==> mexcdf at 123
[varargout{:}] = feval(fcn, varargin{:});
Error in ==> ncread at 147
[v,status]=mexcdf('ncvarget',ncid,varid,start,count);
#########################################################
and this is the output in matlab 6 (R13)
#########################################################
>> a= ncread (filename,'hraw')
hraw has the following dimensions (input order):
1) bath = 0
2) eta_rho = 355
3) xi_rho = 249
hraw loaded into an array of size: [249 355 0]
a =
Empty array: 249-by-355-by-0
#####################################################
Now we can check whether it is empty or not with "isempty".
Some solutions where suggested in this thread, but perhaps the best solution would be that mexcdf version for matlab 2007 were able to give an emtpy matrix when trying to read hraw ( i.e., an empty variable in an ncfile with a record dimension zero)
Regards,
Manuel
We had the same problem with editmask upgrading from matlab 6 (R13) to matlab 2007a. The problem seems to be that the mexnc functions crashes when retrieving an empty variable if the first dimension is zero, in their version for matlab2007a, whereas in the version for matlab R13 it retrieves an empty matrix. The mexcdf version we use was downloaded from sourceforge for matlab2007a.
This is the output for matlab2007:
#############################################################
filename = '/data/roms/Grids/MR.Hmin40.r0.2.Resolucion31.nc'
filename =
/data/roms/Grids/MR.Hmin40.r0.2.Resolucion31.nc
>> ncread (filename,'hraw')
??? call to ncvarget failed.
Error in ==> mexcdf at 123
[varargout{:}] = feval(fcn, varargin{:});
Error in ==> ncread at 147
[v,status]=mexcdf('ncvarget',ncid,varid,start,count);
#########################################################
and this is the output in matlab 6 (R13)
#########################################################
>> a= ncread (filename,'hraw')
hraw has the following dimensions (input order):
1) bath = 0
2) eta_rho = 355
3) xi_rho = 249
hraw loaded into an array of size: [249 355 0]
a =
Empty array: 249-by-355-by-0
#####################################################
Now we can check whether it is empty or not with "isempty".
Some solutions where suggested in this thread, but perhaps the best solution would be that mexcdf version for matlab 2007 were able to give an emtpy matrix when trying to read hraw ( i.e., an empty variable in an ncfile with a record dimension zero)
Regards,
Manuel