利用CRU数据求每月的降水量tif
%求每月的降水量,分辨率为0.5度,数据来源CRU
clear;clc;close all
ncdisp('C:\Users\ljx\Downloads\cru_ts4.04.1901.1910.pre.dat.nc');
data1=ncread('C:\Users\ljx\Downloads\cru_ts4.04.1901.1910.pre.dat.nc','pre');
data3=data1(:,:,1);
data4=rot90(data3);
% data5=flipud(data4);
% data4(isnan(data4))=-999;
dlmwrite('样例2.txt',data4,'\t',1,1); %通过arcgis生成样例tif
[aaaaa,R]=geotiffread('E:\test_cru\example_pre.tif');%先导入纬度数据
info=geotiffinfo('E:\test_cru\example_pre.tif');
% ncdisp('F:\NDVI_WINTER\气象因素\cru_ts4.04.1901.2019.tmp.dat.nc')
data=ncread('F:\NDVI_WINTER\气象因素\cru_ts4.04.1901.2019.tmp.dat.nc','tmp');%和pre格式一样
for year=2000:2019
data1=data(:,:,1+12*(year-1901):12+12*(year-1901)); %得到每年的12个月数据
for mon=1:12
data2=data1(:,:,mon);
data4=rot90(data2);
data4(isnan(data4))=-999;
filename=strcat('F:\NDVI_WINTER\气象因素\月尺度tmp\全球',int2str(year),'年_',int2str(mon),'月tmp.tif');
geotiffwrite(filename,data4,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
end
end