matlab读取.hdf文件

matlab读取.hdf文件

打开hdf文件,以臭氧廓线数据为例

file = ‘OMI-Aura_L2-OMO3PR_2009m0107t1808-o23846_v003-2009m1025t065521.he5’;
file_id = H5F.open(file);

% open data
data_path = ‘/HDFEOS/SWATHS/O3Profile/Data Fields/O3’;
data_id = H5D.open (file_id, data_path);

lat_path=‘HDFEOS/SWATHS/O3Profile/Geolocation Fields/Latitude’;
lat_id=H5D.open(file_id, lat_path);

lon_path=‘HDFEOS/SWATHS/O3Profile/Geolocation Fields/Longitude’;
lon_id=H5D.open(file_id, lon_path);

alt_path=‘HDFEOS/SWATHS/O3Profile/Geolocation Fields/Altitude’;
alt_id=H5D.open(file_id, alt_path);

pressure_path=‘HDFEOS/SWATHS/O3Profile/Geolocation Fields/Pressure’;
pressure_id=H5D.open(file_id, pressure_path);

% ========= Read-in variables from data ========================
data=H5D.read (data_id);
lat=H5D.read(lat_id);
lon=H5D.read(lon_id);
alt=H5D.read(alt_id);
pressure=H5D.read(pressure_id);

% ========= Read-in metadata ========================
% Read units
ATTRIBUTE = ‘Units’;
attr_id = H5A.open_name (data_id, ATTRIBUTE);
units = H5A.read(attr_id);

% Read the offset.
ATTRIBUTE = ‘Offset’;
attr_id = H5A.open_name (data_id, ATTRIBUTE);
offset = H5A.read(attr_id);

% Read the scale.
ATTRIBUTE = ‘ScaleFactor’;
attr_id = H5A.open_name (data_id, ATTRIBUTE);
scale = H5A.read(attr_id);

% Read the fill value.
ATTRIBUTE = ‘_FillValue’;
attr_id = H5A.open_name (data_id, ATTRIBUTE);
fillvalue=H5A.read (attr_id);
attr_id = H5A.open_name (alt_id, ATTRIBUTE);
fillvalue_alt=H5A.read (attr_id);

% Read the missing value.
ATTRIBUTE = ‘MissingValue’;
attr_id = H5A.open_name (data_id, ATTRIBUTE);
missingvalue=H5A.read (attr_id);
attr_id = H5A.open_name (alt_id, ATTRIBUTE);
missingvalue_alt=H5A.read (attr_id);

% Read title attribute.
ATTRIBUTE = ‘Title’;
attr_id = H5A.open_name (data_id, ATTRIBUTE);
long_name=H5A.read (attr_id, ‘H5ML_DEFAULT’);

% Replace fill values with NaN
data(datafillvalue) = NaN;
alt(alt
fillvalue_alt) = NaN;

% Replace missing values with NaN
data(datamissingvalue) = NaN;
alt(alt
missingvalue_alt) = NaN;

% Apply scale and offset, the equation is "scale (data-offset)".
% In this example the ozone scale=1.0 and offset=0.0 so it does nothing.
% However, this may be useful for other variables or datasets.
data = scale
(data-offset);

上一篇:python 读hdf4文件,再转写成一个tif文件


下一篇:matlab读取mls卫星.hdf数据