clc,clear;
filename1='D:\Share_WIN\nc\200501\200501050500G.nc';
filename2='D:\Share_WIN\nc\200601\200601050500G.nc';
var_06=ncinfo(filename1);
data_G06=ncread(filename1,'G');
var_05=ncinfo(filename2);
data_G05=ncread(filename2,'G');
data=data_G06-data_G05;
mkdir('result-02')
% G_06= ncread(filelist_06(s),'G'); %读入变量G
clc; %清屏
clear; %清空
datadir_05='D:\Share_WIN\nc\200501\'; %指定批量数据所在的文件夹
datadir_06='D:\Share_WIN\nc\200601\'; %指定批量数据所在的文件夹
filelist_05=dir([datadir_05,'*.nc']); %指定批量数据的类型
filelist_06=dir([datadir_06,'*.nc']); %指定批量数据的类型
a=filelist_05(1); %查看你要读取的文件的编号。filelist(1).name在window下为第一个标号数据
b=filelist_06(1); %查看你要读取的文件的编号。filelist(2).name在window下为第二个标号数据
m=length(filelist_05);
n=length(filelist_06);
for s=1:m
filename_05=[datadir_05,filelist_05(s).name]; %任意取其中一个来看数据中所包含的变量特征,以为下面读取数据变量做铺垫
ncid_05=netcdf.open(filename_05,'NC_NOWRITE'); % ncid = netcdf.open('D:\Share_WIN\nc\200501\200501050500G.nc','NOWRITE'); %打开nc文件
ncdisp('D:\Share_WIN\nc\200501\200501050500G.nc'); % ncdisp('D:\Share_WIN\nc\200501\200501050500G.nc'); %在命令窗中显示nc文件的变量
Lat = ncread(filename_05,'lat'); %读入变量lat
Lon = ncread(filename_05,'lon'); %读入变量lon
G_05= ncread(filename_05,'G'); %读入变量G
netcdf.close(ncid_05); % 关闭文件
end;
for t=1:n
filename_06=[datadir_06,filelist_06(t).name]; %任意取其中一个来看数据中所包含的变量特征,以为下面读取数据变量做铺垫
ncid_06=netcdf.open(filename_06,'NC_NOWRITE'); % ncid = netcdf.open('D:\Share_WIN\nc\200601\200601050500G.nc','NOWRITE'); %打开nc文件
ncdisp('D:\Share_WIN\nc\200601\200601050500G.nc'); % ncdisp('D:\Share_WIN\nc\200601\200601050500G.nc'); %在命令窗中显示nc文件的变量
Lat = ncread(filename_06,'lat'); %读入变量lat
Lon = ncread(filename_06,'lon'); %读入变量lon
G_06= ncread(filename_06,'G'); %读入变量G
netcdf.close(ncid_06); % 关闭文件
end;
result_01 = G_06 - G_05;
% 创建文件夹
name=('200501');%新的文件夹名
a=['mkdir ' name];%创建命令
system(a) %创建文件夹
filename1='D:\Share_WIN\nc\200501\200501050500G.nc';
filename2='D:\Share_WIN\nc\200601\200601050500G.nc';
var_200501050500=ncinfo(filename1);
G_200501050500=ncread(filename1,'G');
var_200601050500=ncinfo(filename2);
G_200601050500=ncread(filename2,'G');
G_01050500=G_200601050500-G_200501050500;
lon1=ncread(filename1,'lon');
lat1=ncread(filename1,'lat');
lon2=ncread(filename2,'lon');
lat2=ncread(filename2,'lat');
georef1=georasterref('Rastersize',[201,111],'lonlim',[70,170],'latlim',[0,55]);
data_tif1=strcat(filename1,'试验.tif');
geotiffwrite(data_tif1,G_01050500,georef1);
save('D:\Share_WIN\nc\result-01\G_01050500.nc');
% MAGIC数据统计
tic;
load_Path=['F:\2015-总辐射\']; % 路径
% cd(load_Path); % 更改当前工作路径
DIR = dir(fullfile(load_Path,'*.nc'));% 生成此类数据集
[m n] = size(DIR);
%重采样,生成标准经纬网格
L=141;
H=111;
lon_min=70;%经度
lon_max=140;
lat_min=0;%纬度
lat_max=55;
[LongitudeNew,LatitudeNew]=meshgrid(linspace(lon_min,lon_max,L),linspace(lat_max,lat_min,H));%生成网格采样点
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
Data{j+(i-1)*96}(La,Lo)=0;
Time{j+(i-1)*96}=0;
end
end
end
end
for j=1:m
filename=DIR(j).name;
month=str2num(filename(5:6));
day=str2num(filename(7:8));
hour=str2num(filename(9:10));
minute=str2num(filename(11:12));
daytime=hour+minute/60;
filename=strcat(load_Path,filename);
lat=ncread(filename,'lat');
lon=ncread(filename,'lon');
SWGDNCLR=ncread(filename,'G');
% G(G<50)=NaN;
Data{j}=G';
Month{j}=month;
Day{j}=day;
Time{j}=daytime;
end
save_Path_Name=['F:\matlab数据\','Data.mat'];
save (save_Path_Name,'Data','-v7.3');
save_Path_Name=['F:\matlab数据\','Month.mat'];
save (save_Path_Name,'Month','-mat');
save_Path_Name=['F:\matlab数据\','Day.mat'];
save (save_Path_Name,'Day','-mat');
save_Path_Name=['F:\matlab数据\','Time.mat'];
save (save_Path_Name,'Time','-mat');
tic;
% 总辐射
Data=importdata('D:\俞兰\matlab数据\Data.mat');
Month=importdata('D:\俞兰\matlab数据\Month.mat');
Day=importdata('D:\俞兰\matlab数据\Day.mat');
Time=importdata('D:\俞兰\matlab数据\Time.mat');
[m,~]=size(Data);
% 总辐射
G_1=zeros(111,141);
G_2=zeros(111,141);
G_3=zeros(111,141);
G_4=zeros(111,141);
G_5=zeros(111,141);
G_6=zeros(111,141);
G_7=zeros(111,141);
G_8=zeros(111,141);
G_9=zeros(111,141);
G_10=zeros(111,141);
G_11=zeros(111,141);
G_12=zeros(111,141);
% for k=1:m
% switch Month{k}
% case 1 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96};
end
temp_G{i}=trapz(tempx{i},tempy{i});
day_G_1{i}(La,Lo)=temp_G{i}/24;
end
tempmonth=0;
for i=1:31
tempmonth=tempmonth+day_G_1{i}(La,Lo);
end
G_1(La,Lo)=tempmonth/31;
end
end
% case 2 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96+31*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96+31*96};
end
temp_G{i}=trapz(tempx{i},tempy{i});
day_G_2{i}(La,Lo)=temp_G{i}/24;
end
tempmonth=0;
for i=1:28
tempmonth=tempmonth+day_G_2{i}(La,Lo);
end
G_2(La,Lo)=tempmonth/28;
end
end
% case 3 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96+(31+31)*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96+(31+31)*96};
end
temp_G{i}=trapz(tempx{i},tempy{i});
day_G_3{i}(La,Lo)=temp_G{i}/24;
end
tempmonth=0;
for i=1:31
tempmonth=tempmonth+day_G_3{i}(La,Lo);
end
G_3(La,Lo)=tempmonth/31;
end
end
% case 4 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96+(31+31+31)*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96+(31+31+31)*96};
end
temp_G{i}=trapz(tempx{i},tempy{i});
day_G_4{i}(La,Lo)=temp_G{i}/24;
end
tempmonth=0;
for i=1:30
tempmonth=tempmonth+day_G_4{i}(La,Lo);
end
G_4(La,Lo)=tempmonth/30;
end
end
% case 5 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96+(31+31+31+31)*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96+(31+31+31+31)*96};
end
temp_G{i}=trapz(tempx{i},tempy{i});
day_G_5{i}(La,Lo)=temp_G{i}/24;
end
tempmonth=0;
for i=1:31
tempmonth=tempmonth+day_G_5{i}(La,Lo);
end
G_5(La,Lo)=tempmonth/31;
end
end
% case 6 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96+(31+31+31+31+31)*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96+(31+31+31+31+31)*96};
end
temp_G{i}=trapz(tempx{i},tempy{i});
day_G_6{i}(La,Lo)=temp_G{i}/24;
end
tempmonth=0;
for i=1:30
tempmonth=tempmonth+day_G_6{i}(La,Lo);
end
G_6(La,Lo)=tempmonth/30;
end
end
% case 7 总辐射
for Lo=1:141
for La=1:111
for i=1:31
for j=1:96
tempy{i}(j)=Data{j+(i-1)*96+(31+31+31+31+31+31)*96}(La,Lo);
tempx{i}(j)=Time{j+(i-1)*96+(31+31+31+31+31+31