Showing posts with label try. Show all posts
Showing posts with label try. Show all posts

Friday, March 7, 2014

Check the hdf file for corruption

So, some of my hdf files were corrupted


% this script checks the sanity of hdf files.
aTarget =  '/host/data/modisDATA/AQUA_2007/';
tTarget =  '/host/data/modisDATA/TERRA_2007/';

Target = {aTarget, tTarget}

for daynum = 1:365
daynum

for satellite = 1:2
    satellite
    dir_path = Target{satellite};
    dir_info = dir(dir_path);
  
    iwant = [];
    for jj = 3: length(dir_info)
       
        if (strcmp(dir_info(jj).name(15:17),sprintf('%03.f',daynum)))
            iwant = [iwant jj];
        end
       
    end
   
   
  %For each file in the directory
    for nf=iwant
       
        file_name = dir_info(nf).name;                      %name of file
        file_size = dir_info(nf).bytes;                     %size of file
       
        full_name = [dir_path file_name];
       
        try
           
            Corr_Opt   = double(hdfread(full_name,'Corrected_Optical_Depth_Land'));  %Corrected Optical Thickness at 0.47, 0.55, and 0.66 �m
        catch
            disp(['delete ', full_name])
           
        end
       
    end
end

end