editmask, matlab 7 and mexnc

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
jmrogers
Posts: 9
Joined: Tue Jan 31, 2006 9:15 pm
Location: University of Rhode Island GSO

editmask, matlab 7 and mexnc

#1 Unread post by jmrogers »

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

jevans

#2 Unread post by jevans »

Is it failing on "hraw"? Do a dump on your gridfile, see if the "bath" dimension has a length of 0 or 1. If it is zero, then, yes, I get the same thing. The ncvarget call fails because there is no data to retrieve in that case.

wendy
Posts: 15
Joined: Thu Jan 06, 2005 5:19 pm
Location: Institute of Ocean Sciences

#3 Unread post by wendy »

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';

jmrogers
Posts: 9
Joined: Tue Jan 31, 2006 9:15 pm
Location: University of Rhode Island GSO

Solved

#4 Unread post by jmrogers »

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.

sankaras
Posts: 33
Joined: Mon Nov 27, 2006 6:02 pm
Location: Stanford University.

seagrid bathymetry and editmask.

#5 Unread post by sankaras »

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

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

#6 Unread post by kate »

It is not failing due to no bathymetry but due to the lack of a mask. Seagrid will compute both the bathymetry and the land mask if you ask it to.

sankaras
Posts: 33
Joined: Mon Nov 27, 2006 6:02 pm
Location: Stanford University.

#7 Unread post by sankaras »

Hi Kate,

Thanks for your hint.

I still get the same error. I can see the masks in the seagrid, when I do compute depth and land mask. Still, my header file looks the same as before. I also still get the error message, ?? call to ncvarget failed, when try to editmask the grid.

Sankar

sankaras
Posts: 33
Joined: Mon Nov 27, 2006 6:02 pm
Location: Stanford University.

#8 Unread post by sankaras »

Kate,

I am doing something wrong somewhere while generating the grid using seagrid.

I create the grid and then compute the depth and land mask and save it as a mat file. Then, when I exit seagrid and open seagrid and load the saved grid, I do not see the masks.

Any hints?

Thanks,

Sankar

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

#9 Unread post by kate »

To be honest, I never use Seagrid, having about as much luck with it. We have a goal of replacing it with something better, someday, someday.

sankaras
Posts: 33
Joined: Mon Nov 27, 2006 6:02 pm
Location: Stanford University.

#10 Unread post by sankaras »

Kate,

Thanks for your mail.

It looks like my nc{'hraw'}(:), nc{'bath'}(:) are both empty and this causing the problem. I can not seem to get the hraw filled.

Sankar

jmrogers
Posts: 9
Joined: Tue Jan 31, 2006 9:15 pm
Location: University of Rhode Island GSO

Time

#11 Unread post by jmrogers »

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.

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

#12 Unread post by kate »

Forget hraw. I would bet money that edimask doesn't use it. Your error here:

Code: Select all

Error in ==> editmask at 265
[spherical,rlon,rlat,bath,mask]=read_mask(grid_file); 
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).

jmrogers
Posts: 9
Joined: Tue Jan 31, 2006 9:15 pm
Location: University of Rhode Island GSO

#13 Unread post by jmrogers »

To hopefully settle this - Kate, you are right, editmask is failing while reading the mask variables, but for some reason it tries to read hraw as well. This could easily be edited out of the code.

line 123 of read_mask.m in my version:
if (got.hraw),
bath=nc_read(Gname,Vname.hraw,1);

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

#14 Unread post by arango »

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.

isopycnal
Posts: 15
Joined: Fri Jan 05, 2007 3:36 pm
Location: Ocean institution,Chinese Academy of Sciences

#15 Unread post by isopycnal »

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

isopycnal
Posts: 15
Joined: Fri Jan 05, 2007 3:36 pm
Location: Ocean institution,Chinese Academy of Sciences

#16 Unread post by isopycnal »

now i know why the error appears, it's the directory problem. it must be started in the run directory.

mruizv

Re: editmask, matlab 7 and mexnc

#17 Unread post by mruizv »

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

Post Reply