clc;
close all;
load 'G:\theone\GeoRef';
load 'G:\theone\latlon_china_4000_grid';
load 'G:\theone\latlon_china_4000_FY';
FilePath='Z:\龚雨婷\FY'; %待处理数据所存放的文件夹
files=dir(fullfile(FilePath,'*.hdf'));
% files=dir(fullfile(FilePath,'*.NC'));
FilesCount=length(files);
% [a,R]=geotiffread('C:\Users\Administrator\Desktop\data_fusion\30x30\2017_111_new\gapfill1+xiaozu\clm_0429_0300.tif');
% info=geotiffinfo('C:\Users\Administrator\Desktop\data_fusion\30x30\2017_111_new\gapfill1+xiaozu\clm_0429_0300.tif');
for i=1:FilesCount
filename = fullfile(FilePath,files(i).name);
datasetname = '/CLM'; %待提取的字段
CLM = h5read(filename,datasetname);
CLM = uint16(CLM);
CLM=CLM'; % 0表示确定是云
China_lst = CLM(185:935,555:2180);
% China_cloud
% sizeOfA=size(China_cloud);
% R=sizeOfA(1);% 矩阵有多少行
% L=sizeOfA(2);% 矩阵有多少列
% data=zeros(R,L);
% for k=1:R
% for j=1:L
% if China_cloud(k,j)>=3 %取绝对晴空 3
% data(k,j)=1;
% else %都是有云的情况
% data(k,j)=0;
% end
% end
% end
% res=data.*double(China_lst); %提取
China_lst = double(reshape(China_lst,751*1626,1));
Ref_values = griddata(FY_lon4,FY_lat4,China_lst,grid4_lon,grid4_lat,'nearest');% 1417500*1 'linear' 基于三角形的线性插补法(缺省),'cubic' 基于三角形的三次插补法,'nearest' 最近邻插补法
Ref_values = reshape(Ref_values,900,1575);
Ref_values(Ref_values==0)=255;
Ref_values(Ref_values~=255)=0;
geotiffwrite(['G:\theone\yangzriver\2019\FY\geotif\',files(i).name,'.tif'],Ref_values,GeoRef); %后缀必须是tif
% geotiffwrite(fullfile(output_dir,files(i).name,'.tif'),China_lst,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
end