MATLAB工具箱推荐(2)mexcdf工具箱 – Eddy’s World

1. 简介

mexcdf工具箱是一款很多前辈使用matlab读写nc文件常用的工具箱,该工具箱历史久远,最后一个版本停留在R2013a-svn commit # 4053。但由于很多老程序是使用该工具箱里的函数编写的,因此该工具箱几乎是一个物理海洋人不得不装的工具箱。近期由于ROMS输出画图,该工具箱又重新需要安装起来。本文是一个mexcdf安装教程。

该工具箱包含2个包,但通常老程序还会要求安装第三个NetCDF Toolbox。引用一下wikiroms的介绍页面

MEXNC: For maximum flexibility accessing NetCDF files with Matlab, you need to install the machine-dependent MEXNC for your system.

SNCTOOLS: If you just want to access NetCDF files with Matlab (not write them), you can use use the SNCTOOLS, which have a mode that uses machine-independent Java instead of the machine-dependent MEXNC.

NetCDF Toolbox: An overloaded “language” for dealing with NetCDF files, developed by Chuck Denham. Not under active development.

2. 下载

这一步参考该页面
在该工具箱的下载页面选择自己matlab版本对应的工具箱版本,如果你是R2013a以后的matlab版本可以直接使用其svn服务器上的最新版本。
在你的工具箱目录下新建一个文件夹mexcdf,其实不新建也行,因为这一步会自动新建

  svn co svn://svn.code.sf.net/p/mexcdf/svn/mexnc/trunk ./mexcdf/mexnc
  svn co svn://svn.code.sf.net/p/mexcdf/svn/snctools/trunk ./mexcdf/snctools

另外还需要下载netcdf-java4.3,目前Unidata官网已经更新到4.7,但本着不折腾的原则我们还是安装4.3版本。
下载完毕后,文件结构如下:

.
├── mexcdf
│   ├── mexnc
│   └── snctools
└── netcdfAll-4.3.jar

3. 安装

这一步参考该页面

javaaddpath([pwd '/netcdfAll-4.3.jar']);
javaaddpath ([pwd '/mexcdf/snctools/classes']);
addpath ([pwd '/mexcdf/mexnc']);
addpath ([pwd '/mexcdf/snctools']);

4. 测试

>> test_snctools()
Testing tmw backend ...
    Testing hdf4...
        Testing NC_ATTGET...OK
        Testing NC_DUMP ...  OK
        Testing NC_ISCOORDVAR...  OK
        Testing NC_ISUNLIMITEDVAR ...OK
        Testing NC_VARGETR ...  OK
        Testing NC_VARGET ...  OK
    Testing netcdf-3...
        Testing NC_ATTGET...OK
        Testing NC_VARGETR ...  OK
        Testing NC_VARGET ...  OK
        Testing NC_DATATYPE_STRING ...  OK
        Testing NC_ISCOORDVAR...  OK
        Testing NC_ISUNLIMITEDVAR ...OK
        Testing NC_GETLAST...  OK
        Testing NC_ISVAR ...OK
        Testing NC_VARSIZE ...  OK
        Testing NC_GETVARINFO...  OK
        Testing NC_GETBUFFER ...  OK
        Testing NC_INFO ...  OK
        Testing NC_GETDIMINFO ...  OK
        Testing NC_ISDIM ...OK
        Testing NC_DUMP ...  OK
        Testing NC_ADDDIM ...  OK
        Testing NC_ADDVAR ...  OK
        Testing NC_ATTPUT...  OK
        Testing NC_VARPUT...  OK
        Testing NC_ADDHIST... OK
        Testing NC_ADDNEWRECS ...  OK
        Testing NC_CREATE_EMPTY... OK
        Testing NC_VARRENAME...  OK
        Testing NC_ADDRECS...  OK
        Testing NC_CAT...  OK
    Testing netcdf4-classic..
        Testing NC_ATTGET...OK
        Testing NC_VARGETR ...  OK
        Testing NC_VARGET ...  OK
        Testing NC_DATATYPE_STRING ...  OK
        Testing NC_ISCOORDVAR...  OK
        Testing NC_ISUNLIMITEDVAR ...OK
        Testing NC_GETLAST...  OK
        Testing NC_ISVAR ...OK
        Testing NC_VARSIZE ...  OK
        Testing NC_GETVARINFO...  OK
        Testing NC_GETBUFFER ...  OK
        Testing NC_INFO ...  OK
        Testing NC_GETDIMINFO ...  OK
        Testing NC_ISDIM ...OK
        Testing NC_DUMP ...  OK
        Testing NC_ADDDIM ...  OK
        Testing NC_ADDVAR ...  OK
        Testing NC_ATTPUT...  OK
        Testing NC_VARPUT...  OK
        Testing NC_ADDHIST... OK
        Testing NC_ADDNEWRECS ...  OK
        Testing NC_CREATE_EMPTY... OK
        Testing NC_VARRENAME...  OK
        Testing NC_ADDRECS...  OK
        Testing NC_CAT...  OK
    Testing netcdf4-enhanced... 
        Testing NC_VARGET ...  OK
        Testing NC_INFO ...  OK
        Testing NC_ATTGET...OK
    Testing OPeNDAP...
        java opendap testing filtered out when SNCTOOLS 'TEST_REMOTE' or 'TEST_OPENDAP' preferences are false.
Testing mexnc backend ...
    mexnc testing filtered out on release 2019a.
Testing java backend ...
    netcdf-3 java backend testing with local files filtered out on release 2019a
    netcdf-4 java backend testing with local files filtered out on release 2019a
    Testing java/http...
        java http testing filtered out when either of SNCTOOLS preferences 
        'TEST_REMOTE' or 'TEST_HTTP' or 'USE_NETCDF_JAVA' is false.
    Testing GRIB... 
        java GRIB testing filtered out when SNCTOOLS preferences 
        'TEST_GRIB2' is false.
    Skipping THREDDS tests...
    OPeNDAP tests not run via java on 
All  possible tests for your configuration have been run.

If this is the first time you have run SNCTOOLS, then you should
know that several preferences have been set.

ans = 

  struct with fields:

       PRESERVE_FVD: 0
        TEST_REMOTE: 0
         TEST_GRIB2: 0
    USE_NETCDF_JAVA: 0

Only the 'PRESERVE_FVD' preference is important for daily
use of SNCTOOLS.  Check the top-level README for details.  
Bye-bye.

如果绝大部分都OK的话说明安装成功。

Ten articles before and after

ARGO数据使用笔记 – Eddy’s World

MATLAB编码方式-解决中文乱码问题 – Eddy’s World

使用Zotero进行从未有过的畅快学术体验 – Eddy’s World

手把手教你系列之一:我的TAMU留学准备 – Eddy’s World

DDNS搭建与扶墙回国 – Eddy’s World

百度网盘高速下载【唯一有效方案】 – Eddy’s World

ROMS:从入门到精通-2.Lake Signell Case – Eddy’s World

在Mac上安装Ferret – Eddy’s World

科学之路 — 我的启悟(黄瑞新) – Eddy’s World

一个神奇的网站:JCOMMOPS – Eddy’s World