failure Reading Variables from multiple Netcdf files

6 vues (au cours des 30 derniers jours)
Tianchu Lu
Tianchu Lu le 11 Juil 2022
Commenté : Tianchu Lu le 2 Août 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 commentaires
Walter Roberson
Walter Roberson le 25 Juil 2022
Please show the output of
ncinfo(this_file)
for the first file.
Tianchu Lu
Tianchu Lu le 2 Août 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

Connectez-vous pour commenter.

Réponse acceptée

Tianchu Lu
Tianchu Lu le 2 Août 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 commentaires
Walter Roberson
Walter Roberson le 2 Août 2022
is the problem solved?
Tianchu Lu
Tianchu Lu le 2 Août 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by