filename = 'D:\ERA5\temp198001.nc'
ncdisp(filename)
Lon = ncread(filename,'longitude'); %读取经度数据
Lat = ncread(filename,'latitude');
TIME = ncread(filename,'time');
LEVEL = ncread(filename,'level');
ncdisp(filename)
filename =
D:\ERA5\temp198001.nc
Source:
D:\ERA5\temp198001.nc
Format:
64bit
Global Attributes:
Conventions = 'CF-1.6'
history = '2019-08-18 04:42:42 GMT by grib_to_netcdf-2.10.0: /opt/ecmwf/eccodes/bin/grib_to_netcdf -o /cache/data9/adaptor.mars.internal-1566103360.9518533-6806-13-fd55a4b3-f6d4-498d-aa10-892e5b867bf5.nc /cache/tmp/fd55a4b3-f6d4-498d-aa10-892e5b867bf5-adaptor.mars.internal-1566103360.9526615-6806-6-tmp.grib'
Dimensions:
longitude = 1440
latitude = 721
level = 6
time = 1
Variables:
longitude
Size: 1440x1
Dimensions: longitude
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'longitude'
latitude
Size: 721x1
Dimensions: latitude
Datatype: single
Attributes:
units = 'degrees_north'
long_name = 'latitude'
level
Size: 6x1
Dimensions: level
Datatype: int32
Attributes:
units = 'millibars'
long_name = 'pressure_level'
time
Size: 1x1
Dimensions: time
Datatype: int32
Attributes:
units = 'hours since 1900-01-01 00:00:00.0'
long_name = 'time'
calendar = 'gregorian'
t
Size: 1440x721x6x1
Dimensions: longitude,latitude,level,time
Datatype: int16
Attributes:
scale_factor = 0.0018795 % 增益
add_offset = 247.979
_FillValue = -32767
missing_value = -32767
units = 'K'
long_name = 'Temperature'
standard_name = 'air_temperature'
long = 1;
lati = 1;
time = 1;
level = 1;
start = [long,lati,level,time]; % varname所指定变量的每一维的开始读取的位置
% 6:time维度从6开始,只读1个; 473:time维度从473开始,只读1个(count)
stride = [1, 1, 1, 1]; % 从start开始,每一维读取的数目为count时,每一维的读取的步长
count = [1440, 721, 1, 1]; % 从start指定的开始位置算起,一共读取的每一维要素的数目
temp_level_time = ncread(filename,'t',start, count, stride); % 边界层高度属性
完整代码:
%*************************************************************************%
%程序目的:学习将ERA5 nc文件转换为.tif文件并写出的方法
%2019年08月15日
%*************************************************************************%
clc
clear all
filename = 'D:\ERA5\temp198001.nc'
ncdisp(filename)
Lon = ncread(filename,'longitude'); %读取经度数据
Lat = ncread(filename,'latitude');
TIME = ncread(filename,'time');
LEVEL = ncread(filename,'level');
long = 1;
lati = 1;
time = 1;
level = 1;
start = [long,lati,level,time]; % varname所指定变量的每一维的开始读取的位置
% 6:time维度从6开始,只读1个; 473:time维度从473开始,只读1个(count)
stride = [1, 1, 1, 1]; % 从start开始,每一维读取的数目为count时,每一维的读取的步长
count = [1440, 721, 1, 1]; % 从start指定的开始位置算起,一共读取的每一维要素的数目
% blh = ncread(filename,'t',start, count, stride); % 边界层高度属性
% t
% Size: 1440x721x6x473
% Dimensions: longitude,latitude,level,time
% Datatype: int16
% Attributes:
% scale_factor = 0.0020267
% add_offset = 252.4038
% _FillValue = -32767
% missing_value = -32767
% units = 'K'
% long_name = 'Temperature'
% standard_name = 'air_temperature'
for time = 1:length(TIME)
time
start
temp_level_time = ncread(filename,'t',start, count, stride); % 边界层高度属性
time1990 = datenum('1900-01-01'); % 从公元0年到1900-01-01所经历的日数
nowtime = time1990 + TIME(time)/24 ; %
month = datestr(double(nowtime),'yyyymm') % 将天数转化为日期 注意:只接受双精度型date number
savename = strcat(month, 'temp100.tif');
savepath = strcat('D:\ERA5\temp\100mb\', savename)
GeoRef = georasterref('Rastersize',[721,1440],'Latlim',[-90,90],'Lonlim',[0,359.75]);
geotiffwrite(savepath,rot90(temp_level_time),GeoRef)
break
end