Borrar filtros
Borrar filtros

Open files with certain file size

2 visualizaciones (últimos 30 días)
David du Preez
David du Preez el 31 de Mzo. de 2017
Comentada: David du Preez el 1 de Abr. de 2017
Hi I have hundreds of files with a similar name. I can open them all with the following code:
% Open the HDF5 File.
for k = 1:365
FILE_NAME = sprintf('MLS-Aura_L2GP-O3_v04-20-c01_2006d%03d.SUB.he5',k);
file_id = H5F.open(FILE_NAME, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
end
now I only want to open files when the file size is greater than 37 KB. How do I do that ?

Respuesta aceptada

KSSV
KSSV el 31 de Mzo. de 2017
files = dir('your file extension') ;
% loop for each file
for i = 1:length(files)
if files(i).bytes*1000 > 37 % if file size is > 37 do what you want
filename = files(i).name ;
disp(filename)
%open your file do what you want
end
end
  1 comentario
David du Preez
David du Preez el 1 de Abr. de 2017
Great thanks. Here is my updated script:
for i = 1:length(files)
if files(i).bytes > 50000
filename = files(i).name;
disp(filename)
%open files with data
file_data = H5F.open(filename,'H5F_ACC_RDONLY','H5P_DEFAULT');
%Data field for data wanted
DATAFIELD_NAME = 'HDFEOS/SWATHS/O3 column/Data Fields/L2gpValue';
data_id = H5D.open(file_data,DATAFIELD_NAME);
%Time component
TIME_NAME='HDFEOS/SWATHS/O3 column/Geolocation Fields/Time';
time_id = H5D.open(file_data,TIME_NAME);
data1=H5D.read (data_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', ...
'H5P_DEFAULT');
time=H5D.read(time_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL',...
'H5P_DEFAULT');
time1lvl=datestr(datevec(datenum(1993,1,1,0,0,0)+time(1)/86400));
end
end
How do I change so the output files (data1,time and time1lvl) are not over written each time?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by