【matlab程序】matlab利用工具包nctool读取grib2、nc、opendaf、hdf5、hdf4等格式数据
引用:
B. Schlining, R. Signell, A. Crosby, nctoolbox (2009), Github repository, https://github.com/nctoolbox/nctoolbox
Brief summary:
nctoolbox is a Matlab toolbox that provides read-only access to common data model datasets. Under the hood, nctoolbox uses NetCDF-Java as the data access layer. This allows nctoolbox to access NetCDF, OPeNDAP, HDF5, GRIB, GRIB2, HDF4 and many (15+) other file formats and services using the same API. It works with Matlab 2008a and later.
更多内容请点击阅读原文!
工具包下载地址:https://github.com/nctoolbox/nctoolbox
工具包介绍:NCTOOLBOX Tools for read-only access to Common Data Model dataset.
版本: Version 1.1.1-13-g8582810++ 12-03-2015
文件或函数的功能:
01: setup_nctoolbox - sets your path and classpath to access the nctoolbox functions
02:cfdataset - Provide access to CF/COARDS convention datasets accessable by the
03: ncdataset - Provide access to datasets accessable by the NetCDF 4 API
04: ncgeodataset - NCGEODATASET
05:ncgeovariable - Provide advanced access to variables and their related
06: nctoolbox_info - nctoolbox_info Provide information on the NCTOOLBOX version and dependencies
07: ncugrid - Extention of dataset object class for unstructured grid datasets.
08: ncuvariable - Extention of variable object class for unstructured grid/mesh variables.
09 ncvariable - Provide advanced access to variables and their related
简单例子:
本次数据来源于:fnl.
clc;clear;close all
cd nctoolbox-master/
setup_nctoolbox
cd ..
data=ncgeodataset('fnl_20090601_00_00.grib2');
data.variables
% Extract the Temperature_surface
param='Temperature_surface';
air_temperature=data{param}(1,:,:);
lat=data{'lat'}(:);
lon=data{'lon'}(:);
% From this point on the code is identical to the previous example:
air_temperature=double(squeeze(air_temperature));
lat=double(lat);
lon=double(lon)-180;
%% figure
close all
figure
m_proj('Equidistant Cylindrical','lon',[-180 180],'lat',[-90 90]);
m_contourf(lon,lat,air_temperature-273.15,1000,'linestyle','none');
m_coast('patch',[0.1 .85 .7],'edgecolor',[0 0 0],'linewidth',1);
m_grid('ytick',[-90:30:90],'xtick',[-180:60:180],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
% 调用ncl色带
rainbow_r=textread('D:\matlab_work\函数名为colormore的颜色索引表制作\ncl_color_txt\BlueWhiteOrangeRed.txt');
colormap(rainbow_r(:,1:3));
hold on
c=colorbar('eastoutside','ticklength',0);
clim([-60,40])
% 调整colorbar
ax = gca;
axpos = ax.Position;
c.Position(3) = 0.5*c.Position(3);
ax.Position = axpos;
cbarrow;
title('nctoolbox read grib2');
xlabel({'time:20231125','海洋与大气科学'})
export_fig('12nctoolbox read grib2.png','-r300')