some possible errors using matlab tool

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
Dan_chan
Posts: 38
Joined: Wed Apr 17, 2019 2:37 am
Location: IAP, UCAS

some possible errors using matlab tool

#1 Unread post by Dan_chan »

Unrecognized field name "f" using coarse2fine

Hi,

I am using the latest version matlab tools ( https://www.myroms.org/svn/src/matlab) to generate finer grid nc. But, I encounter the following error:

Code: Select all

Unrecognized field name "f".

Error in coarse2fine (line 666)
  status = nc_write (Gout, field, F.(field));
I test coarse2fine function and find that Coriolis parameter f is written into R not F structure value on around line 466. So, I change it to F, then function works.

Code: Select all

% Coriolis parameter.

% R.f = refined_gridvar(C, F, 'f', Fmethod);
F.f = refined_gridvar(C, F, 'f', Fmethod);
I am not sure if that's reasonable, but hope it's useful for using or updating.

Have a nice day

-----------------------------update this topic------------------------------------------

Thanks for developers and users in this forum who really have been of great help to me. I am a beginner in ROMS, and always use matlab tools. There may be problems due to different versions such as matlab version. So, I would like to post problems I encounter in this topic.

Hoping helpful. :P

Dan
Last edited by Dan_chan on Thu Nov 03, 2022 2:32 pm, edited 2 times in total.

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

Re: Unrecognized field name "f" using coarse2fine

#2 Unread post by wilkin »

Yes, that's a bug I just discovered myself. There are some other similar bugs but not for "spherical" grids using lon/lat coordinates.
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: 1347
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Unrecognized field name "f" using coarse2fine

#3 Unread post by arango »

Yes, please update.

Dan_chan
Posts: 38
Joined: Wed Apr 17, 2019 2:37 am
Location: IAP, UCAS

Re: some possible errors using matlab tool

#4 Unread post by Dan_chan »

The NetCDF library encountered an error during execution of 'renameDim' function -
'Operation not allowed in data mode (NC_ENOTINDEFINE)'.


When I use 'nc_drename' function today,I encounter the following error:

Code: Select all

>> nc_drename(fid,'xrho','xi_rho')
Error using matlab.internal.imagesci.netcdflib
The NetCDF library encountered an error during execution of 'renameDim' function -
'Operation not allowed in data mode (NC_ENOTINDEFINE)'.

Error in netcdf.renameDim (line 33)
matlab.internal.imagesci.netcdflib('renameDim', ncid, dimid, new_name);

Error in nc_drename>nc_drename_matlab (line 104)
netcdf.renameDim(ncid, dimid, Dname_new);

Error in nc_drename (line 46)
    status = nc_drename_matlab(ncfile, Dname_old, Dname_new, Info);
I was not sure if the problem a coincidence or a memory problem (as some posts in matlab forum have suggested), while I used the function last week and it worked fine at the time......

My matlab version is R2021b. After testing, I find that it is the bug about chosen matlab native interface.This is an example in renameDim.m of matlab native netcdf interface:

Code: Select all

%   Example:
%       srcFile = fullfile(matlabroot,'toolbox','matlab','demos','example.nc');
%       copyfile(srcFile,'myfile.nc');
%       fileattrib('myfile.nc','+w');
%       ncid = netcdf.open('myfile.nc','WRITE');
%       netcdf.reDef(ncid);
%       dimid = netcdf.inqDimID(ncid,'x');
%       netcdf.renameDim(ncid,dimid,'new_x');
%       netcdf.close(ncid);
But in 'nc_drename_matlab' sub-function of nc_drename, command 'netcdf.reDef(ncid)' is missing. So have a try to add it.

Code: Select all

function status = nc_drename_matlab(ncfile, Dname_old, Dname_new, Info)
......
% Open NetCDF file and get variable ID.

ncid  = netcdf.open(ncfile, 'nc_write');
netcdf.reDef(ncid);  %!!!!!!!!!!!!
dimid = netcdf.inqDimID(ncid, Dname_old);
There is similar bug in nc_attadd or any other netcdf redefine functions. I guess it has something to do with matlab version or chosen netcdf interface.

Have a nice day :P

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

Re: some possible errors using matlab tool

#5 Unread post by wilkin »

You are correct. Something has changed with Matlab netcdf handling. I'm using R2022b (the latest) and get the same error.

Your fix to add netcdf.reDef at line 100 works

Code: Select all

% svn diff nc_drename.m 
Index: nc_drename.m
===================================================================
--- nc_drename.m	(revision 1144)
+++ nc_drename.m	(working copy)
@@ -97,6 +97,7 @@
 % Open NetCDF file and get variable ID.
 
 ncid  = netcdf.open(ncfile, 'nc_write');
+netcdf.reDef(ncid);
 dimid = netcdf.inqDimID(ncid, Dname_old);
 
However, I did not get any errors using nc_attadd or nc_varrename. Only nc_drename.
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: 1347
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: some possible errors using matlab tool

#6 Unread post by arango »

Yes, thank you. We need to put the NetCDF file in define mode. I missed that call. I updated the repository.

Dan_chan
Posts: 38
Joined: Wed Apr 17, 2019 2:37 am
Location: IAP, UCAS

Re: some possible errors using matlab tool

#7 Unread post by Dan_chan »

Thank you Wikin, you are right. nc_attadd and nc_varrename are ok.
wilkin wrote: Thu Nov 03, 2022 3:29 pm However, I did not get any errors using nc_attadd or nc_varrename. Only nc_drename.

Post Reply