hdfread

5 views (last 30 days)
Caitlin frame
Caitlin frame on 28 Nov 2011
I was given the code below for extracting windspeed data from NASA's quikscat satellite data. The code worked fine with my 2007 version of matlab but when I upgraded to the 2009 version, I got the following error message:
Error using ==> hdfinfo>parseInputs at 405
/Applications/M_Files/Gas_ex_model/HDFfiles/._QS_XWGRD3_2007262.20072631456.XoY91n is not a valid HDF file.
The files in my HDFfiles folder that I'm trying to extract have names such as QS_XWGRD3_2007262.20072631456 but there's no .XoY91n like there is in the name in the error message. Is this possibly why it's having trouble. Anyway, can someone please tell me how to get Matlab to run through a folder full of netCDF files and open them the way this code was designed to?:
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\';
%---------------------------------------------------------------------------------------------
for i=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
%
%
for n=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
save quikwinds07raincounts qws julday lati lon LATI LON; % save what we

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!