We fequently have questions about NetCDF and Matlab. In order to get NetCDF to work in Matlab, you need to intall the MEXCDF interface. For more information about MEXCDF, please visit the following link:

you need to be careful with the MEX files since they can only be executed on a SUN computer running Solaris. On my computer, these executables have the .mexsol extension.

If you have a different computer architecture, you need to build the appropriate MEXCDF interface. To install the NetCDF toolbox for Matlab, follow the instructions given in:

The SeaGrid generation package also uses MEXCDF files to generate the model grid. It uses the mexinside, mexrec, and mexsepeli programs. You need to build these programs for your computer architecture. See the SeaGrid website for more information:

I run the upwelling/ downwelling example on a DEC Alpha machine. It generated the files ocean_avg.nc, ocean_dia.nc, ocean_his.nc, and ocean_rst.nc (and log).

I downloaded and installed MexCDF and NetCDF from the website http://woodshole.er.usgs.gov/staffpages ... c4ml5.html. They seem to run within Matlab, open a Net CDF Browser window, but give a couple of error messages about contour3 and feval.

Where can I find examples on the use of MexCDF and NetCDF to read a file (such as ocean_avg.nc, ocean_dia.nc, ocean_his.nc, and ocean_rst.nc) and prepare plots, such as those shown in the SCRUM manual (Figures 11-14)?

Hello all - this is my first post here and I have two questions regarding NetCDF

1) I ran the upwelling test case, and the ocean_his.nc, ocean_avg.nc, ocean_dia.nc, and ocean_rst.nc files are created fine. I can read them in using the ncload command (from the matlab.tar.gz file on this website), but cannot using MATLAB's own cdfread or cdfinfo commands. I thought NetCDF files were supposed to be all in the same format. This is more a curiousity question, as I said that I can read the files using ncload.

2) When I try to plot the results, using speed.m (also from the matlab.tar.gz file), I get errors regarding the missing gname (Grid NetCDF file name). This file is not created during runtime, and I assume that this is the file you create before running ROMS to set up the grid. For these test cases, what should one do (short of plotting the results on your own) to learn how to use the plotting functions, such as speed.m?

I am a new user of ROMS. I installed ROMS in windows XP (via Cygwin). I am using MATLAB 7.1 in my pc. I have some quarry regarding seagrid download instructions mentioned on seagrid homepage.

I am not clear what does mean by “making sure preserve the subdirectory structure”. However, I download and install seagrid and find the directories and subdirectories mentioned on the instructions.

I need to know exactly what is Matlab path, however I added the complete seagrid folder into the toolbox of matlab

In matlab I type cd to the .\seagrid\test_data directory, then type "seagrid" and found the following comments:

## Unable to locate Mex-files. Please install
## "mexrect", "mexsepeli", and "mexinside",
## then adjust your Matlab path accordingly.

## SeaGrid requires the "Presto" toolbox.
## Please install and/or include in Matlab path.

Can anyone suggest, how to solve the problem?
Rouf

Thanks Diego.
I follow the instruction and installed MEXNC and SNCTOOLS but there is a problem with MATLAB toolkit installation.
After installing and extracting Matlab tool-kit, I added the directory to the MATLAB path and restart the Matlab. But it shows following comments

Warning: Name is nonexistent or not a directory: \home\arango\ocean\matlab\Damee.
> In path at 113
In startup at 14
In matlabrc at 220 Warning: Name is nonexistent or not a directory: \home\arango\ocean\matlab\coastlines.
> In path at 113
In startup at 15
In matlabrc at 220 Warning: Name is nonexistent or not a directory: \home\arango\ocean\matlab\dx.
> In path at 113
In startup at 16
In matlabrc at 220

…….. similar warning for all subdirectories (floats, forcing, grib, hydro, m_map, presto……) under matlab.

Is there anything wrong? Looking for your suggestion.

In the matlab-toolkit that you just downloaded... there are ~28 directories and 1 file... startup.m

This startup.m file contains a script that adds the path of user-specified directories to Matlab's path... kind of an automatic alternative to the Add-path GUI that you used for MEXNC and SCTOOLS. The problem is that the startup.m file in the matlab-toolkit contains Hernan Arango's paths and NOT yours.

One way to fix this is to edit such startup.m file to reflect YOUR paths... find the following line (in startup.m):

and replace '/home/arango/ocean' with YOUR path to the matlab toolkit.

Another solution (i think) is to delete the startup.m file that is creating the problem (since you already manually added the paths to MEXNC, SNCTOOL, etc )

Let me know what works for you... I may update the tutorial so that future users know what to do with the startup.m file.

Dear Diego
In terms of Matlab toolkit, I replace the root path in startup.m file but found similar problem and when I delete the startup.m, there is no warning.

My matlab version is 7.1.0.246 (R14) Service Pack 3. That’s why, I chooses the R14sp3 MEXNC version. Then follow the instruction accordingly. In matlab, when I type cd to the .\seagrid\test_data directory, then type "seagrid" But still the following error:

## Unable to locate Mex-files. Please install
## "mexrect", "mexsepeli", and "mexinside",
## then adjust your Matlab path accordingly.

I search the files in my downloaded Mexnc folder but there are no above named the files.
I also like to inform that my Matlab search path follow the following order: matlab tools, SNCTOOLS, Matlab\bin…Matlab\bin\win32, MEXNC………

Unfortunately I haven't work with Seagrid (I tried, but I also ran into troubles), so I won't be able to help a lot more on this ...Hernan said in the begining of this thread that

It uses the mexinside, mexrec, and mexsepeli programs. You need to build these programs for your computer architecture. See the SeaGrid website for more information:

I can tell you already visit the website above and read the instructions. There it says to add the " appropriate
.\seagrid\mex_<version>_<os> directory to your matlab path. " . Since you are on a PC it looks like .\seagrid\mex is the appropriate directory to add to the path. If that doesn't work... you may have to compile the MEX files for your Matlab version from source code... tricky for us new users.

It is not nearly as powerful as seagrid, but it is easier to get up-and-running. I am still working on this tutorial, but it may be finished-enough to be helpful for you.

Back to seagrid... Perhaps a more advanced user can suggest Rouf how to fix his seagrid problem?

Sorry I did a mistake; I didn’t add the seagrid folders into Matlab path properly. Now I overcome the above-mentioned problem. Thanks Diego.

I am following Signell_seagrid tutorial. I extract, process and save the coast file and bathy file properly. My computer is also able to open the coast and bathy file properly in seagrid. But when I tried to make grid with 4 boundary points, I found following error in matlab

??? Invalid MEX-file 'C:\cygwin\seagrid\mex_matlab71_win32\mexrect.dll': Access is denied.

.

Error in ==> mexrect2grid at 98
zrect = feval('mexrect', zrect, length(zrect), ...

Error in ==> seagrid.gridcalc at 179
[w, err] = feval(theFcn, zti, [], ci, [m n]); % <Error> seagrid.dogrid at 64
gridcalc(self) % <Calculate> seagrid.doupdate at 92
dogrid(self, needsUpdate); % <== Step #2 <Error> seagrid.getboundary at 109
doupdate(self, 1)

Error in ==> seagrid.doevent at 129
getboundary(self, theCommand, theMessage)

Error in ==> psevent at 25
doevent(ps(gcbf), theEvent, theMessage);

??? Error while evaluating figure WindowButtonDownFcn.

My Matlab version is 7.1. If I add mex_matlab71_win32 in the matlab path and try to make grid with 4 boundary points, it shows following error: ??? Invalid MEX-file 'C:\cygwin\seagrid\mex_matlab71_win32\mexrect.dll': Access is denied.

If I add mex_74_win32 in Matlab path it shows following ??? Invalid MEX-file 'C:\cygwin\seagrid\mex_matlab74_win32\mexrect.mexw32': Access is denied.

I need to know which mex_matlab??_win32 should I add with my Matlab path?

I check the Matlab Release Notes. I suspect (but not sure) that I have to recompile all MEX-files. There are lot of mex files here in Matlab. Is it mean I have to recompile all or only mexrect", mexsepeli, and mexinside?

I will be pleased if someone let me know details how to recompile the files in Matlab? Or any other way to overcome the problem as I am not sure wheather its a recompiling issue or not?

I asked John Evans at The Mathworks about this, and he is as mystified as me. Here is his reply:

Uhm, hmm, my first thought was that the user must be using an old mex-file,
because the 7.1 release is supposed to be using "*.mexw32" instead of "*.dll"
for an extension... but it looks like I was the one who built it as a *.dll
in the first place. Looking a bit further, it seems that dropping the dll
extension is strongly recommended, but not required for 7.1. It *should*
still work, though.

I went ahead and rebuilt the win32 mex-file for 7.1 (R14sp3) as having
the "*.mexw32" extention. It tests ok and is posted at the sourceforge site.
Tell the user to try it out.

So I suggest you try John's new mex files posted on sourceforge where you got the files before, and let us know what happens.

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