matlab中hdfread,hdfread - MATLAB Answers - MATLAB Central

clear; pack;

% Path of files to be converted

pat='/Applications/M_Files/Gas_ex_model/HDFfiles/';

files=dir([pat'*']);

% Path where Files will be saved

%pat2='C:\ka07\quikscat\';

%---------------------------------------------------------------------------------------------

fori=1:length(files)-2;

fileinfo=hdfinfo([pat files(i+2).name]);

fname=files(i+2).name;

fout=fname; disp(['Converting ',fout]);%Display filename converted

data_set_info = fileinfo.SDS;

ascwp = hdfread(data_set_info(1));% Average Wind Speed (ascending pass)

deswp = hdfread(data_set_info(2));% Average Wind Speed (descending pass)

ascwu = hdfread(data_set_info(3));% Wind speed in the u direction (ascending pass)

deswu = hdfread(data_set_info(4));% Wind speed in the u direction (descending pass)

ascwv = hdfread(data_set_info(5));% Wind speed in the v direction (ascending pass)

deswv = hdfread(data_set_info(6));% Wind speed in the v direction (descending pass)

ascwcount = hdfread(data_set_info(9));% did wind retrieval occur? (ascending pass)

deswcount = hdfread(data_set_info(10));% did wind retrieval occur? (descending pass)

ascwrain=hdfread(data_set_info(13));% Ascending pass rain probability

deswrain=hdfread(data_set_info(14));% Descending pass rain probability

rainflagasc=hdfread(data_set_info(15));% ascending rain flag

rainflagdes=hdfread(data_set_info(16));% descending rain flag

% ascws = hdfread(data_set_info(7)); % Square wind speed (ascending pass)

% desws = hdfread(data_set_info(8)); % Square Wind speed (descending pass)

%

ascwu=0.01*double(ascwu);%Convert to double floating point precision (With correction factor, no offset)

deswu=0.01*double(deswu);%Convert to double floating point precision (With correction factor, no offset)

ascwv=0.01*double(ascwv);%Convert to double floating point precision (With correction factor, no offset)

deswv=0.01*double(deswv);%Convert to double floating point precision (With correction factor, no offset)

ascwcount = double(ascwcount);

deswcount = double(deswcount);

ascwrain = double(ascwrain);% Ascending Rain probability

deswrain = double(deswrain);% Descending Rain probability

rainflagasc=double(rainflagasc);% flag of 1:7 depending on rain and sensors available. see quikscat doc for details

rainflagdes=double(rainflagdes);

ascwcount(rainflagasc==2 | rainflagasc==6)=0;% if rain flag =2 or 6 then don't want to use data so set count to 0.

deswcount(rainflagasc==2 | rainflagdes==6)=0;% then data won't be used in average.

% ascwcount(rainflagasc~=0)=0; % if rain flag doesn't equal 0 then don't want to use data so set count to 0.

% deswcount(rainflagasc~=0)=0; % then data won't be used in average. this is "strictest" interpreation

meanu=(ascwu.*ascwcount + deswu.*deswcount);% Average of Ascending and Descending Passes (won't include rainy ones b/c of above 2 lines)

meanv=(ascwv.*ascwcount + deswv.*deswcount);% Average of Ascending and Descending Passes

rain=(ascwrain.*ascwcount + deswrain.*ascwcount);

totcount=(ascwcount + deswcount);

kk=find(totcount~=0);

meanu(kk)=(meanu(kk)./totcount(kk));

meanv(kk)=(meanv(kk)./totcount(kk));

rain(kk)=(rain(kk)./totcount(kk));

meanu=flipud(meanu');

meanv=flipud(meanv');

rain=flipud(rain');

rainflagasc=flipud(rainflagasc');

rainflagdes=flipud(rainflagdes');

totcount=flipud(totcount');

ws=sqrt(meanu.*meanu + meanv.*meanv);

%end

% % or could calculate based on wind speed but then getting average of

% % square of wind speed which isn't necessarily average wind speed

% ascws=0.01*double(ascws); %Convert to double floating point precision (With correction factor, no offset)

% desws=0.01*double(desws); %Convert to double floating point precision (With correction factor, no offset)

%

% meanws=(ascws.*ascwcount + desws.*deswcount); % Average of Ascending and Descending Passes

% meanws(kk)=(meanws(kk)./totcount(kk));

% meanws=flipud(meanws');

% meanws=meanws.^0.5; % take the square root

%

%

forn=1:length(data_set_info)

disp(data_set_info(n).Name)

% for j=1:length(data_set_info(1).Attributes)

% disp(data_set_info(n).Attributes(j))

% end

end

% Calculate the center lat and lon of the grid box

m=720; n=1440;

% lati=[[-90]:[180/m]:[90-180/m]]'; % works but grid shifted by 0.125 degree

lati=[[-89.875]:[180/m]:[90.25-180/m]]';

% lon=[180]:[-360/n]:[-180+180/n];

% lon=360:-360/n:0; % works but grid is shifted by 0.125 degree

lon=359.875:-360/n:0;

k1=find(lati>=-14.75 & lati<=-11); lati=lati(k1);

k2=find(lon>=330 | lon<=12.2); lon=lon(k2);

ws=ws(k2,k1);

rain=rain(k2,k1);

rainflagasc=rainflagasc(k2,k1);

rainflagdes=rainflagdes(k2,k1);

totcount=totcount(k2,k1);

[LATI, LON]=meshgrid(lati, lon);

%lati=flipud(LAT);

% [m n]=size(ws); % no longer do this since instead earlier have replaced countnumber with zero if raining

% israin=find(rainflag==2 | rainflag==6);

% ws(israin)=NaN; % replace with NaN;

[m n]=size(ws);

iszerocount=find(totcount==0);

ws(iszerocount)=NaN;% replace with NaN;

%

% now save some info that we need

julday(i)=str2num(fileinfo.Filename(59:61));% saves julian day that file pertains to

qws(:,:,i)=ws;% save wind speeds for the day in a multiple dimension array

end

savequikwinds07raincounts qws julday lati lon LATI LON;% save what we

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值