Borrar filtros
Borrar filtros

failure Reading Variables from multiple Netcdf files

3 visualizaciones (últimos 30 días)
Tianchu Lu
Tianchu Lu el 11 de Jul. de 2022
Comentada: Tianchu Lu el 2 de Ag. de 2022
I am trying to read multiple different variables that is within a netcdf file, and almost extract the number that is associated with the variable that is listed. so what i have done is for it to loop for each variable, but i get an error displaying that one of the variable is not found even though it is on the nc file if i do ncdisp. could anyone help or optimise the code a little?
many thanks
ncvars={'duration','tecmin','tecmax','elevmin','elevmax','elev_tecmax','alt_elevmax','lat_elevmax','lon_elevmax','alt_tecmax','lat_tecmax','lon_tecmax','alt_start','lat_start','lon_start','alt_stop','lat_stop','lon_stop'};
projectdir= 'F:\cosmic_2_data_file';
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
durations=cell(num_files,1);
tecmins=cell(num_files,1);
tecmaxs=cell(num_files,1);
elevmins=cell(num_files,1);
elevmaxs=cell(num_files,1);
elevtecmaxs=cell(num_files,1);
altelevmaxs=cell(num_files,1);
latelevmaxs=cell(num_files,1);
lonelevmaxs=cell(num_files,1);
alttecmaxs=cell(num_files,1);
lattecmaxs=cell(num_files,1);
lontecmaxs=cell(num_files,1);
altstarts=cell(num_files,1);
latstarts=cell(num_files,1);
lonstarts=cell(num_files,1);
altstops=cell(num_files,1);
latstops=cell(num_files,1);
lonstops=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
durations{i}=ncread(this_file,ncvars{1});
tecmins{i}=ncread(this_file,ncvars{2});
tecmaxs{i}=ncread(this_file,ncvars{3});
elevmins{i}=ncread(this_file,ncvars{4});
elevmaxs{i}=ncread(this_file,ncvars{5});
elevtecmaxs{i}=ncread(this_file,ncvars{6});
altelevmaxs{i}=ncread(this_file,ncvars{7});
latelevmaxs{i}=ncread(this_file,ncvars{8});
lonelevmaxs{i}=ncread(this_file,ncvars{9});
alttecmaxs{i}=ncread(this_file,ncvars{10});
lattecmaxs{i}=ncread(this_file,ncvars{11});
lontecmaxs{i}=ncread(this_file,ncvars{12});
altstarts{i}=ncread(this_file,ncvars{13});
latstarts{i}=ncread(this_file,ncvars{14});
lonstarts{i}=ncread(this_file,ncvars{15});
altstops{i}=ncread(this_file,ncvars{16});
latstops{i}=ncread(this_file,ncvars{17});
lonstop{i}=ncread(this_file,ncvars{18});
end
there are about 9400 .0001_nc files so i am hoping it can loop through and read the variables that i want and almost record that number and save it as a new cell.
  4 comentarios
Walter Roberson
Walter Roberson el 25 de Jul. de 2022
Please show the output of
ncinfo(this_file)
for the first file.
Tianchu Lu
Tianchu Lu el 2 de Ag. de 2022
ncvars={'TEC','elevation','time','x_LEO','y_LEO','z_LEO','x_GPS','y_GPS','z_GPS'};
projectdir= "F:\podtc2_data\podTc2_nrt_2022_004";
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
TEC_podtc2s=cell(num_files,1);
Elevation_podtc2s=cell(num_files,1);
times=cell(num_files,1);
x_LEOs=cell(num_files,1);
y_LEOs=cell(num_files,1);
z_LEOs=cell(num_files,1);
x_GPSs=cell(num_files,1);
y_GPSs=cell(num_files,1);
z_GPSs=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
TEC_podtc2s{i}=ncread(this_file,ncvars{1});
Elevation_podtc2s{i}=ncread(this_file,ncvars{2});
times{i}=ncread(this_file,ncvars{3});
x_LEOs{i}=ncread(this_file,ncvars{4});
y_LEOs{i}=ncread(this_file,ncvars{5});
z_LEOs{i}=ncread(this_file,ncvars{6});
x_GPSs{i}=ncread(this_file,ncvars{7});
y_GPSs{i}=ncread(this_file,ncvars{8});
z_GPSs{i}=ncread(this_file,ncvars{9});
end

Iniciar sesión para comentar.

Respuesta aceptada

Tianchu Lu
Tianchu Lu el 2 de Ag. de 2022
ncvars={'TEC','elevation','time','x_LEO','y_LEO','z_LEO','x_GPS','y_GPS','z_GPS'};
projectdir= "F:\podtc2_data\podTc2_nrt_2022_004";
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
TEC_podtc2s=cell(num_files,1);
Elevation_podtc2s=cell(num_files,1);
times=cell(num_files,1);
x_LEOs=cell(num_files,1);
y_LEOs=cell(num_files,1);
z_LEOs=cell(num_files,1);
x_GPSs=cell(num_files,1);
y_GPSs=cell(num_files,1);
z_GPSs=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
TEC_podtc2s{i}=ncread(this_file,ncvars{1});
Elevation_podtc2s{i}=ncread(this_file,ncvars{2});
times{i}=ncread(this_file,ncvars{3});
x_LEOs{i}=ncread(this_file,ncvars{4});
y_LEOs{i}=ncread(this_file,ncvars{5});
z_LEOs{i}=ncread(this_file,ncvars{6});
x_GPSs{i}=ncread(this_file,ncvars{7});
y_GPSs{i}=ncread(this_file,ncvars{8});
z_GPSs{i}=ncread(this_file,ncvars{9});
end
  2 comentarios
Walter Roberson
Walter Roberson el 2 de Ag. de 2022
is the problem solved?
Tianchu Lu
Tianchu Lu el 2 de Ag. de 2022
yes thank you so much for your time. could you help me on the other question I just posted with the ongoing project?
thank you for your time

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by