clear
clc


for Jday=271:280

    
    cd(['/ships19/hercules/mino/Satellite_Out/HIM08/2019/level2/',num2str(Jday),'/'])
    files=dir('*.level2.nc');
	 
    for k=1:length(files)
	 
	 [Jday k]
    filename=files(k).name;
    
    cloud_mask=single(ncread(filename,'cloud_mask'));
    cloud_mask(cloud_mask<0)=NaN;
    cloud_mask(cloud_mask>0)=1;
    Cld_distance_03= (ordfilt2(cloud_mask, 9, true(3)));
    Cld_distance_05= (ordfilt2(cloud_mask, 25, true(5)));
    [row,col]=size(Cld_distance_03);
	 
	 nccreate(filename,'Cld_distance_03',...
          'Dimensions',{'r',row,'c',col},...
          'Format','netcdf4');
   ncwrite(filename,'Cld_distance_03',Cld_distance_03)

   nccreate(filename,'Cld_distance_05',...
          'Dimensions',{'r',row,'c',col},...
          'Format','netcdf4');
   ncwrite(filename,'Cld_distance_05',Cld_distance_05)
	
    
    end
    
end
