资源简介
read grib文件, 用于matlab等
代码片段和文件信息
function grib2_struct = read_grib2(grib2nameirecvarargin)
% grib_struct=read_grib2(gribnameirec‘DataFlag‘[0|1]‘ScreenDiag‘[0|1] ...
% ‘ParamTable‘[‘NCEPOPER‘|‘ECMWF160‘|‘NCEPREAN‘|‘ECMWF128‘]);
%
% read_grib for grib2 files (version 2.0)
%
%Single and multiple parameter access (irec={‘Parameter1‘‘Parameter2‘})
%and irec=vector of record numbers (irec=1:10:100)
%and irec=-1 read all of the data
%
% %This works well on windows( xp vista/win7) by the support of wgrib2
% %Requires that wgrib2 version 1.9.2 or later is installed
% %It can also work on a unix-like platform (Linux BSD Ubuntu SUSE etc)
% %by changing the directory of wgrib2
%
% %Written by Liqun-Wang and Hongxing-Wang 20/04/2010
% %Updated on 17/05/2011.
% %E-mail: junyang517@qq.com bestredstar@gmail.com
% %You are appreciated for improving the code
% %and thanks very much for sending us your modified code
%
% %----------------------------NOTICE-------------------------------------%
% %
% %If you are working on vista/win7 or unix-like platform suggest to use
% %the following codes
%
% if ispc
% % Microsoft Windows vista/win7 platform
% [statusresult]=system(‘where wgrib2‘);
% if status ~= 0
% disp(‘wgrib2 is not in your path‘)
% return
% end
% wgrib2=strtrim(result);
% else
% % Unix-like platform (Linux BSD Ubuntu SUSE etc)
% [statusresult]=system(‘which wgrib2‘);
% if status ~= 0
% disp(‘wgrib2 is not in your path‘)
% return
% end
% wgrib2=strtrim(result);
% end
%
% %Suggestion: set directory of wgrib2 and dlls if works on WinXP
% %Notice: the version of wgrib2 should be 1.9.2 or later
wgrib2=‘C:\GreenTools\wgrib2-1.9.2\wgrib2.exe‘;
% %-----------------------------------------------------------------------%
grib2_struct=struct([]);
status=version_check_of_wgrib2(wgrib2);
if status==0 return; end %%version of wgrib2 not suiteable
% %-----------------------------------------------------------------------%
[grib2name_outfpathfnamefext]=estimate_gribname_isempty(grib2name);
grib2name=grib2name_out;
% %-----------------------------------------------------------------------%
% set default
DataFlag=1;
ScreenDiag=1;
% %-----------------------------------------------------------------------%
% Process propertyname/value pairs
k=1;
while k switch lower(varargin{k})
case ‘dataflag‘
DataFlag=varargin{k+1};
varargin([k k+1])=[];
case ‘screendiag‘
ScreenDiag=varargin{k+1};
varargin([k k+1])=[];
case ‘paramtable‘
ParamTable=varargin{k+1};
if ~(any(strcmp(ParamTable{‘NCEPOPER‘‘ECMWF160‘‘NCEPREAN‘‘ECMWF128‘})))
error(‘Invalid Parameter Table to READ_GRIB.‘)
end
varargin([k k+1])=[];
otherwise
k=k+2;
end
end
% %-----------------------
- 上一篇:matlab 2015a许可文件
- 下一篇:均值滤波Matlab程序
评论
共有 条评论