Difference between revisions of "MEXNC"

From WikiROMS
Jump to navigationJump to search
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
MEXNC is a mex-file interface to NetCDF files for MATLAB. In simple terms, it is a set of files (mex and .m files) that allows Matlab to read and write NetCDF files, which are the standard input and output files of ROMS.
<div class="title">Matlab MEXNC, SNCTOOLS and ROMS tool-kit</div>
{| style="width:50%; background:Honeydew; margin-top:10px; border:1px solid YellowGreen;" cellpadding="5" cellspacing="0"
|-
|{{note}} Post questions and comments regarding this tutorial in [https://www.myroms.org/forum/viewtopic.php?t=53&highlight=snctools '''THIS'''] forum thread.
|}


[http://mexcdf.sourceforge.net/ HERE] is a link to the MEXNC project page.<br><br>
__TOC__


=How to install MEXNC?=
MATLAB is powerful software that is commonly used to create ROMS inputs and to visualize and analyze ROMS output. However, out-of-the-box Matlab doesn't come with the capabilities to read/write ROMS NetCDF files. For that you need to download and install MEXNC, which is a mex-file interface to NetCDF files for MATLAB. In simple terms, it is a set of files (mex and .m files) that allows Matlab to read and write NetCDF files. Also, if you want to fully exploit Matlab's capabilities to manipulate/analyze ROMS files, you may want to download/install SNCTOOLS and the ROMS Matlab tool-kit, which are Matlab routines (that sit on top of MEXNC) that facilitate the manipulation, visualization and analysis of ROMS input/output NetCDF files. There are free alternatives to Matlab (see links below), however in this tutorial I will only review (some) tools for Matlab.
You have to download the MEXNC version that matches BOTH, your specific Matlab version and your operating system.


(1) First determine what Matlab version you have by typing on the Matlab command line:<div class="box"><span class="red">version('-release') </span></div><br><br>
{| style="width:100%; background:Honeydew; margin-top:10px; border:1px solid YellowGreen; font-size:85%;" cellpadding="1" cellspacing="0"
|-
| '''Quick links:'''
|-
|[http://www.mathworks.com/products/matlab/ MATLAB]
|[http://mexcdf.sourceforge.net/ MEXNC project page]
|[http://mexcdf.sourceforge.net/tutorial SNCTOOLS tutorial]<font color="gray"> (for Matlab)</font>
|-
|[http://www.scilab.org/ Scilab] <font color="red">Free</font> Matlab-clone
|[http://ace.acadiau.ca/math/ACMMaC/software/scilab_netcdf.html Scilab/NetCDF Interface]
|[http://mexcdf.sourceforge.net/netcdf_toolbox/netcdf_toolbox.html NetCDF Toolbox]<font color="gray"> (for Matlab)</font>
|-
|[http://www.gnu.org/software/octave/ Octave] <font color="red">Free</font> Matlab-clone
|[http://ocgmod1.marine.usf.edu/mediawiki/index.php/NetCDF_toolbox_for_Octave OCTCDF]<font color="gray"> Octave/NetCDF interface</font>
|}
<br><br>
__TOC__


(2) Then, go to the [http://mexcdf.sourceforge.net/downloads/ download] area, scroll down and <span style="color:red">click</span> on your Matlab version (verify that you operating system is listed as an option).<br><br>
==How to install MEXNC?==
You have to download the MEXNC version that matches BOTH, your specific Matlab version and your operating system.<br><br>


(3) Download the latest release<br><br>
# First determine what Matlab version you have by typing on the Matlab command line:<div class="box"><span class="red">version('-release') </span></div>
# Then, go to the [http://mexcdf.sourceforge.net/downloads/ download] area, scroll down and <span style="color:red">click</span> on your Matlab version (verify that you operating system is listed as an option).
# Download the latest release
# Extract (i.e. unzip or unpack) the file in a location where it can stay indefinitely
# In Matlab, add the path of your recently extracted mexnc directory. To do this...
#* Click on <span style="color:red"> File > Set Path...</span> (a GUI will pop-up)
#* Click on the <span style="color:red"> Add with Subfolders...</span> button, and add the path to your new mexnc folder
#* Click on the <span style="color:red">Save</span> button, and close the GUI<br><br>
# If you are using WINDOWS operating system (I don't know if others too), you will have to add the netcdf.dll file to your Matlab system directory. To do this...
#* Go to your recently extracted mexnc directory and go inside the win32 folder...
#* Copy the <span style="color:red">netcdf.dll</span> file and PASTE it into one (or both) of the following directories:<div class="box"><span style="color:red">C:\MATLAB\bin</span><br /><br />and/or<br /><br /><span style="color:red">C:\MATLAB\bin\win32</span></div>{{warning}} <small>In the example above, <span class="red">C:\MATLAB</span> is the location where matlab is located, but this '''may be different''' in your computer.</small><br /><br />
#* Similarly as in '''(5)''', add the path to the directory(ies) above (i.e. <span class="red">C:\MATLAB\bin</span> and <span class="red">C:\MATLAB\bin\win32</span>) to the Matlab search path.<br />{{note}} <small>NOTE: In some cases, it will be important to have <span class="red">C:\MATLAB\bin</span> and <span class="red">C:\MATLAB\bin\win32</span> at the '''TOP''' of the searching path.</small><br /><br />
#* Done! However, you may need to download [http://mexcdf.sourceforge.net/ SNCTOOLS] and the matlab tool-kit to be fully operational... read below.


(4) Extract (i.e. unzip or unpack) the file in a location where it can stay indefinitely<br><br>


(5) In Matlab, add the path of your recently extracted mexnc directory. To do this...
{{note}} If you are using [http://www.scilab.org/ Scilab] (free Matlab-clone)... [http://ace.acadiau.ca/math/ACMMaC/software/scilab_netcdf.html Click here] to get the Scilab interface to NetCDF files.<br>
* Click on <span style="color:red"> File > Set Path...</span> (a GUI will pop-up)
{{note}} If you are using [http://www.gnu.org/software/octave/ Octave] (another free Matlab-clone)... [http://ocgmod1.marine.usf.edu/mediawiki/index.php/NetCDF_toolbox_for_Octave Click here] to get the Octave interface to NetCDF files.<br><br>
* Click on the <span style="color:red"> Add with Subfolders...</span> button, and add the path to your new mexnc folder
* Click on the <span style="color:red">Save</span> button, and close the GUI<br><br>


(6) If you are using WINDOWS operating system (I don't know if other too), you will have to add the netcdf.dll file to your Matlab system directory. To do this...
==How to install SNCTOOLS?==
* Go to your recently extracted mexnc directory and go inside the win32 folder...
Written by John Evans, [http://mexcdf.sourceforge.net/ SNCTOOLS] is a set of m-files that sit on top of MEXNC (and optionally, java) and strive to provide the user with a kinder, gentler interface (rather than MEXNC alone). Here is a [http://mexcdf.sourceforge.net/tutorial/index.html tutorial] and below are instructions for download and "installation":
* Copy the <span style="color:red">netcdf.dll</span> file and PASTE it in on (or both) or the following directories:<div class="box"><span class="red">C:\MATLAB\bin <br><br><span class="black">and/or</span><br><br><span class="red">C:\MATLAB\bin\win32</span></div>
:{{warning}} <small>In the example above, <span class="red">C:\MATLAB</span> is the location where matlab is located, but this '''may be different''' in your computer.</small><br><br>
* Similarly as in (5), add the path to the directory(ies) above (i.e. <span class="red">C:\MATLAB\bin</span> and <span class="red">C:\MATLAB\bin\win32</span>) to the Matlab search path.
::{{note}} <small>NOTE: In some cases, it will be important to have <span class="red">C:\MATLAB\bin</span> and <span class="red">C:\MATLAB\bin\win32</span> at the '''TOP''' of the searching path.</small><br><br>
* Done! However, you may need have to download SNCTOOLS and the matlab tool-kit to be fully operational... read below.<br><br>
<br><br>
=How to install SNCTOOLS?=
Written by John Evans, SNCTOOLS is a set of m-files that sits on top of MEXNC (and optionally, java) and strives to provide the user with a kinder, gentler interface (rather than MEXNC alone). Here is a [http://mexcdf.sourceforge.net/tutorial/index.html tutorial]. Here are instructions for download and "installation":
# Go to the [http://sourceforge.net/project/showfiles.php?group_id=119464&package_id=130914 download] page and get the latest release.
# Go to the [http://sourceforge.net/project/showfiles.php?group_id=119464&package_id=130914 download] page and get the latest release.
# Extract the file in a location where it can stay indefinitely
# Extract the file in a location where it can stay indefinitely
# Similarly as in (5), add the path to the recently extracted directory to the Matlab search path.<br><br>
# Similar to step '''(5)''' above, add the path to the recently extracted directory to the Matlab search path.
<br><br>
 


=How to install ROMS Matlab tool-kit?=
==How to install ROMS Matlab tool-kit?==
This is a compilation (from a lot of smart people) of matlab tools (i.e. m-files), that sit on top of SNCTOOLS (which sits on top of MEXNC). Here are instructions for download and "installation":
This is a compilation (from Hernan Arango) of matlab tools (i.e. m-files), that sit on top of SNCTOOLS (which sits on top of MEXNC). Here are instructions for download and "installation":
# Go to the [http://www.myroms.org/index.php?page=Processing download] page and get the latest release.
# Go to the [http://www.myroms.org/index.php?page=Processing download] page, enter the <span style="color:red">matlab</span> directory, and download the <span style="color:red">'''matlab.tar.gz'''</span> file.
# Extract the file in a location where it can stay indefinitely
# Extract the file in a location where it can stay indefinitely
# Similarly as in (5), add the path to the recently extracted directory to the Matlab search path.
# Similar to step (5) above, add the path to the recently extracted directory to the Matlab search path.
 
 
 
==The Matlab ROMS_WILKIN tool-kit==
John Wilkin (jwilkin@rutgers.edu) provides a set of matlab m-files that read ROMS netcdf files using SNCTOOLS, and create simple plots, extract data subsets (e.g. slices at constant depths), or perform simple operations on data (e.g. depth integrals). Most of the tools optionally return the data that form the basis of each plot and the graphics handles so that you can replot according to your own requirements if desired. The tools are designed primarily to work with 'realistic' model output in longitude and latitude coordinates, but will replace the lon/lat with ROMS x/y coordinates if necessary.
# How to use the tools and instructions for download are provided via tiddlywiki at [http://romsmatlab.tiddlyspot.com/ romsmatlab.tiddlyspot.com]
# There is some discussion of these tools at [https://www.myroms.org/forum/viewtopic.php?f=23&t=916&start=0&hilit=roms_wilkin this thread] on the User Forum.

Latest revision as of 22:27, 19 March 2009

Matlab MEXNC, SNCTOOLS and ROMS tool-kit
Note Post questions and comments regarding this tutorial in THIS forum thread.


MATLAB is powerful software that is commonly used to create ROMS inputs and to visualize and analyze ROMS output. However, out-of-the-box Matlab doesn't come with the capabilities to read/write ROMS NetCDF files. For that you need to download and install MEXNC, which is a mex-file interface to NetCDF files for MATLAB. In simple terms, it is a set of files (mex and .m files) that allows Matlab to read and write NetCDF files. Also, if you want to fully exploit Matlab's capabilities to manipulate/analyze ROMS files, you may want to download/install SNCTOOLS and the ROMS Matlab tool-kit, which are Matlab routines (that sit on top of MEXNC) that facilitate the manipulation, visualization and analysis of ROMS input/output NetCDF files. There are free alternatives to Matlab (see links below), however in this tutorial I will only review (some) tools for Matlab.

Quick links:
MATLAB MEXNC project page SNCTOOLS tutorial (for Matlab)
Scilab Free Matlab-clone Scilab/NetCDF Interface NetCDF Toolbox (for Matlab)
Octave Free Matlab-clone OCTCDF Octave/NetCDF interface



How to install MEXNC?

You have to download the MEXNC version that matches BOTH, your specific Matlab version and your operating system.

  1. First determine what Matlab version you have by typing on the Matlab command line:
    version('-release')
  2. Then, go to the download area, scroll down and click on your Matlab version (verify that you operating system is listed as an option).
  3. Download the latest release
  4. Extract (i.e. unzip or unpack) the file in a location where it can stay indefinitely
  5. In Matlab, add the path of your recently extracted mexnc directory. To do this...
    • Click on File > Set Path... (a GUI will pop-up)
    • Click on the Add with Subfolders... button, and add the path to your new mexnc folder
    • Click on the Save button, and close the GUI

  6. If you are using WINDOWS operating system (I don't know if others too), you will have to add the netcdf.dll file to your Matlab system directory. To do this...
    • Go to your recently extracted mexnc directory and go inside the win32 folder...
    • Copy the netcdf.dll file and PASTE it into one (or both) of the following directories:
      C:\MATLAB\bin

      and/or

      C:\MATLAB\bin\win32
      Warning In the example above, C:\MATLAB is the location where matlab is located, but this may be different in your computer.

    • Similarly as in (5), add the path to the directory(ies) above (i.e. C:\MATLAB\bin and C:\MATLAB\bin\win32) to the Matlab search path.
      Note NOTE: In some cases, it will be important to have C:\MATLAB\bin and C:\MATLAB\bin\win32 at the TOP of the searching path.

    • Done! However, you may need to download SNCTOOLS and the matlab tool-kit to be fully operational... read below.


Note If you are using Scilab (free Matlab-clone)... Click here to get the Scilab interface to NetCDF files.
Note If you are using Octave (another free Matlab-clone)... Click here to get the Octave interface to NetCDF files.

How to install SNCTOOLS?

Written by John Evans, SNCTOOLS is a set of m-files that sit on top of MEXNC (and optionally, java) and strive to provide the user with a kinder, gentler interface (rather than MEXNC alone). Here is a tutorial and below are instructions for download and "installation":

  1. Go to the download page and get the latest release.
  2. Extract the file in a location where it can stay indefinitely
  3. Similar to step (5) above, add the path to the recently extracted directory to the Matlab search path.


How to install ROMS Matlab tool-kit?

This is a compilation (from Hernan Arango) of matlab tools (i.e. m-files), that sit on top of SNCTOOLS (which sits on top of MEXNC). Here are instructions for download and "installation":

  1. Go to the download page, enter the matlab directory, and download the matlab.tar.gz file.
  2. Extract the file in a location where it can stay indefinitely
  3. Similar to step (5) above, add the path to the recently extracted directory to the Matlab search path.


The Matlab ROMS_WILKIN tool-kit

John Wilkin (jwilkin@rutgers.edu) provides a set of matlab m-files that read ROMS netcdf files using SNCTOOLS, and create simple plots, extract data subsets (e.g. slices at constant depths), or perform simple operations on data (e.g. depth integrals). Most of the tools optionally return the data that form the basis of each plot and the graphics handles so that you can replot according to your own requirements if desired. The tools are designed primarily to work with 'realistic' model output in longitude and latitude coordinates, but will replace the lon/lat with ROMS x/y coordinates if necessary.

  1. How to use the tools and instructions for download are provided via tiddlywiki at romsmatlab.tiddlyspot.com
  2. There is some discussion of these tools at this thread on the User Forum.