Error in c_initial matlab script

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
ifeanyee
Posts: 14
Joined: Mon Nov 22, 2021 11:05 pm
Location: Laboratoire des sciences du climat et de l'environ

Error in c_initial matlab script

#1 Unread post by ifeanyee »

Hi Everyone,

I'm a newbie with working in ROMS. I tried the venerable Emmanuel Dilorenzo's intro course and was stuck with using some of his RNT toolkit (especially rnt_timectl - datenum issue). I decided to test the shipped matlab routine provided https://www.myroms.org/wiki/Matlab_Scripts but I was greeted with an error when I tried to used the d_script to create an initial condition.

Code: Select all

>>  INIname = 'shallow2d-init-v2.nc';
>>  OA_INTERPOLATE = 1;
>> S.ncname = INIname;
>> S.spherical = 0;
>> S.Lm = 128;
>> S.Mm = 128;
>>
>> S.N = 20;
>>
>> S.NT = 2;
>> S.Vtransform = 2;
>>
>> S.Vstretching = 2;
>> S.theta_s = 7.0;
>> S.theta_b = 0.1;
>> S.Tcline  = 200.0;
>>
>> S.hc = S.Tcline;
>> [~]=c_initial(S);

Output argument "status" (and maybe others) not assigned during call to "nc_vdef".

Error in c_initial (line 275)
[~,status]=nc_vdef(ncid,Var);
I was wondering if anyone has encounter this sort of issue and how I can fix it.

Thanks.

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

Re: Error in c_initial matlab script

#2 Unread post by wilkin »

I just tried that exact code you posted and it works fine for me ...

Code: Select all

>> INIname = 'shallow2d-init-v2.nc';
OA_INTERPOLATE = 1;
S.ncname = INIname;
S.spherical = 0;
S.Lm = 128;
S.Mm = 128;
S.N = 20;
S.NT = 2;
S.Vtransform = 2;
S.Vstretching = 2;
S.theta_s = 7.0;
S.theta_b = 0.1;
S.Tcline  = 200.0;
S.hc = S.Tcline;
[~]=c_initial(S);

I = ncinfo(INIname)
I = 
  struct with fields:
      Filename: '/Users/wilkin/Dropbox/sandbox/shallow2d-init-v2.nc'
          Name: '/'
    Dimensions: [1×10 struct]
     Variables: [1×26 struct]
    Attributes: [1×2 struct]
        Groups: []
        Format: 'classic'
	...
Maybe check that you have up-to-date versions of nc_vedf.m etc. in your myroms Matlab toolboxes.
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

ifeanyee
Posts: 14
Joined: Mon Nov 22, 2021 11:05 pm
Location: Laboratoire des sciences du climat et de l'environ

Re: Error in c_initial matlab script

#3 Unread post by ifeanyee »

Thanks for the Wilkin. I retried again and still ran into error. The error message now is:

Code: Select all

Unrecognized function or variable 'mexnc'.

Error in c_initial (line 157)
[ncid,status]=mexnc('create',ncname,'clobber');
I suspect this has to do with the use of mexnc interface but my version of matlab is 2019b so I don't know why the native interface isn't used.Or is the mexnc supposed to be manaully compiled before I use it?

Thanks for your help.

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

Re: Error in c_initial matlab script

#4 Unread post by wilkin »

It's explained in mexnc.m.

Code: Select all

function [varargout] = mexnc ( varargin )
%    MEXNC is a gateway to the netCDF interface. To use this function, you 
%    should be familiar with the information about netCDF contained in the 
%    "User's Guide for netCDF".  This documentation may be obtained from 
%    Unidata at 
%    <http://my.unidata.ucar.edu/content/software/netcdf/docs.html>.
%
%    R2008b and Beyond
%    -----------------
%    Starting with R2008b, MATLAB comes with native netCDF support.  If 
%    your version of MATLAB is earlier than R2008b, mexnc will use it's own
%    mex-file.  If MATLAB is R2008b or higher, mexnc will use MATLAB's 
%    native package by default.  
With 2019b the function becomes a wrapper to the native netcdf toolbox. You won't need the actually compiled mex code, but you still need the wrapper. It was done in this way to maintain backward compatibility.
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

ifeanyee
Posts: 14
Joined: Mon Nov 22, 2021 11:05 pm
Location: Laboratoire des sciences du climat et de l'environ

Re: Error in c_initial matlab script

#5 Unread post by ifeanyee »

Interesting. I can't even find the mexnc() script you provided. A linux recursive find command return empty search result. I just updated/checkout the latest version of the matlab script and still the same issue.

Code: Select all

svn checkout  https://mexcdf.svn.sourceforge.net/svnroot/mexcdf/mexnc/trunk MyDir

isn't working neither is snctools. And I'm not sure where the issue now. Please which directory is your mexnc() located.

ifeanyee
Posts: 14
Joined: Mon Nov 22, 2021 11:05 pm
Location: Laboratoire des sciences du climat et de l'environ

Re: Error in c_initial matlab script

#6 Unread post by ifeanyee »

Reading the src of c_initial.m it seem there is a delibrate use of mexnc() in the definition of the dimension. This is case for all dimension definition used throughout the script. It isn't clear to me where the use of the native interface netcdf.open or nccreate is used in the file.

Code: Select all

%--------------------------------------------------------------------------
%  Create initial conditions NetCDF file.
%--------------------------------------------------------------------------

[ncid,status]=mexnc('create',ncname,'clobber');
if (status ~= 0),
  disp('  ');
  disp(mexnc('strerror',status));
  error(['C_INITIAL: CREATE - unable to create file: ', ncname]);
end

%--------------------------------------------------------------------------
%  Define dimensions.
%--------------------------------------------------------------------------

[did.xr,status]=mexnc('def_dim',ncid,Dname.xr,Dsize.xr);
if (status ~= 0),
  disp('  ');
  disp(mexnc('strerror',status));
  error(['C_INITIAL: ncdimdef - unable to define dimension: ',Dname.xr]);
end

[did.xu,status]=mexnc('def_dim',ncid,Dname.xu,Dsize.xu);
if (status ~= 0),
  disp('  ');
  disp(mexnc('strerror',status));
  error(['C_INITIAL: DEF_DIM - unable to define dimension: ',Dname.xu]);
end

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

Re: Error in c_initial matlab script

#7 Unread post by arango »

Yes, I updated c_initial.m, c_climatology.m, and c_biology.m to use the native Matlab interface to NetCDF. I have been removing slowly the old and obsolete interface to mexnc. Please update your repository. Thank for reporting this issue.

ifeanyee
Posts: 14
Joined: Mon Nov 22, 2021 11:05 pm
Location: Laboratoire des sciences du climat et de l'environ

Re: Error in c_initial matlab script

#8 Unread post by ifeanyee »

Perfect!!. Updated the repo and it work now. Thanks Hernan and John. Really appreciate your time.

Guess the only issue now remains using RNT Toolbox error (rnt_timectl). I understand that's a seperate issue as the scripts are third-party to the ROMS official script. In any case, I can always work with the main support matlab script.

Thanks a lot.

JMette
Posts: 14
Joined: Wed Oct 25, 2023 3:15 pm
Location: University of Bremen

Re: Error in c_initial matlab script

#9 Unread post by JMette »

Hi, I'm getting a similar behavior with the c_boundary.m function. If I understood it correctly, the script doesn't use the native NetCDF interface, when the mexnc() function is called, right? Because c_boundary.m creates the NetCDF file still with mexnc().

Post Reply