nc_read problem in matlab with mexnc_twm

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
wilkin
Posts: 918
Joined: Mon Apr 28, 2003 5:44 pm
Location: Rutgers University
Contact:

nc_read problem in matlab with mexnc_twm

#1 Unread post by wilkin »

I'm trying to use the editmask tool available amongst the Matlab routines distributed in the myroms.org matlab svn repository (editmask is in matlab/landmask/) . This uses nc_read in the same repository (in matlab/utility/). On my Macbook I'm using Matlab 7.7.0.471 (R2008b).

nc_read fails on any file reading any variable with the error like:

Code: Select all

>> nc_read('test.nc','spherical')
??? Error using ==> mexnc_tmw at 106
Function string 'parameter' is not recognized.

Error in ==> mexnc at 532
	[varargout{:}] = mexnc_method(varargin{:});

Error in ==> nc_read>ncread at 214
[NC_BYTE  ]=mexnc('parameter','nc_byte');

Error in ==> nc_read at 151
    f=ncread(fname,vname);
The command

Code: Select all

[NC_BYTE  ]=mexnc('parameter','nc_byte');
appears to be the problem. The error is not due to case sensitivity in the arguments passed to mexnc.

I can read the data in these files OK with snctools nc_varget, but would rather not have to modify all of editmask to use the snctools I/O to get editmask to work.

Is there something I can change in the mexnc set-up on my Mac to get this to work?

Thanks, John.
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

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

Re: nc_read problem in matlab with mexnc_twm

#2 Unread post by arango »

Is the problem only with nc_byte? or your have problems with the other parameters nc_char, nc_double, nc_float, nc_int, nc_short?

This is not a problem with nc_read but mexnc. I wonder what actually are you using for mexnc. I think that this is a problem with the native NetCDF interface in matlab and not mexnc.mex.

User avatar
wilkin
Posts: 918
Joined: Mon Apr 28, 2003 5:44 pm
Location: Rutgers University
Contact:

Re: nc_read problem in matlab with mexnc_twm

#3 Unread post by wilkin »

I checked with John Evans and he said a related problem surfaced recently and needed changes to the mexnc and snctools download. I updated that from sourceforge and now things are basically working.

However, two other problems arose.

The first is that nc_read doesn't have an option to handle the character type variable 'spherical' so I added that to nc_read:

Code: Select all

des003:myroms wilkin$ svn diff
Index: utility/nc_read.m
===================================================================
--- utility/nc_read.m	(revision 357)
+++ utility/nc_read.m	(working copy)
@@ -319,6 +319,8 @@
     [f,status]=mexnc('get_var_float' ,ncid,varid);
   elseif (nctype == NC_INT),
     [f,status]=mexnc('get_var_int'   ,ncid,varid);
+  elseif (nctype == NC_CHAR),
+    [f,status]=mexnc('get_var_text'  ,ncid,varid);
   else,
     [f,status]=mexnc('ncvarget1'     ,ncid,varid,[0]);
   end,
The second issue is that matlab command "strmatch" returns [] if there is no match, and this fails the logical test to read a coastline file. If a grid file has coastline data already in it (as variables lon_coast and lat_coast) it won't trip this error. So I modified editmask to catch this case.

Now I'm in back business, using editmask on my Macbook with Matlab version
7.7.0.471 (R2008b)

Code: Select all

Index: landmask/editmask.m
===================================================================
--- landmask/editmask.m	(revision 357)
+++ landmask/editmask.m	(working copy)
@@ -279,7 +279,8 @@
    got_Clon=strmatch('lon_coast',varnam);
    got_Clat=strmatch('lat_coast',varnam);
 
-   if (~(got_Clon & got_Clat)),
+   %if (~(got_Clon & got_Clat)),
+   if isempty(got_Clon) | isempty(got_Clat)
      if (any(coast_file=='*')),
        [fn,pth]=uigetfile(coast_file,'Select Coastline file...');
        if (~fn),
 
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

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

Re: nc_read problem in matlab with mexnc_twm

#4 Unread post by arango »

OK, thank you. I corrected the repository. See the following track :arrow: ticket.

On a relate matter, I changed the definitions of logical in ROMS to be CF compliant. For example, the ROMS output NetCDF files have:

Code: Select all

        int Lstflux(tracer) ;
                Lstflux:long_name = "surface tracer fluxes adjustment switch" ;
                Lstflux:flag_values = 0, 1 ;
                Lstflux:flag_meanings = ".FALSE. .TRUE." ;
        int Lobc(Nstate, boundary) ;
                Lobc:long_name = "open boundary conditions adjustment switch" ;
                Lobc:flag_values = 0, 1 ;
                Lobc:flag_meanings = ".FALSE. .TRUE." ;
This is because NetCDF do not support logical-type variables. If we use character variable (T/F) is cumbersome to write characters vectors and matrices in NetCDF 3.x. There is a new string variable type in NetCDF-4. Currently, I have the netcdf_put_lvar routine to write logical variables as integers. I guess that I will write the netcdf_get_lvar when needed.

I still need to resolve the issue with spherical which is still written as a character:

Code: Select all

        char spherical ;
                spherical:long_name = "grid type logical switch" ;
                spherical:flag_values = "T, F" ;
                spherical:flag_meanings = "spherical Cartesian" ;

Post Reply