Extract data from NetCDF files to text files (For SWAT Model).
Ältere Kommentare anzeigen
% new code to extract data from netcdf file to SWAT format text file.
data =[];
Files = dir('*.nc');
for k=1:length(Files)
FilesNames = Files(k).name;
for t=1:2
pr = ncread(FilesNames,'rainfall_amount');
long = ncread(FilesNames,'x');
lat = ncread(FilesNames,'y');
end
for j = 716:746(lat);
for i = 328:368(long);
v = pr(i,j,:);
data2 = (v);
data2(isnan(data2)) = -99.0;
outfile =sprintf('%d_%d_PCP.txt',lat(j),long(i));
fopen all
fid = fopen(outfile,'wt');
data = {data;data2};
fprintf(fid,'%5.1f\n',data2);
end
fclose all
end
end
disp([outfile 'created'])
% original code source:
% http://dficklin.weebly.com/netcdf-to-swat-climate-input-files.html
4 Kommentare
Image Analyst
am 23 Dez. 2018
What's the problem? Please read this link
Was en error thrown? Did you have an error with ncread()? Or fprintf()? Or these lines
for j = 716:746(lat);
for i = 328:368(long);
Get rid of the (lat) and (long) and the semicolons.
Or is it something else?
shobhit pipil
am 23 Dez. 2018
Bearbeitet: shobhit pipil
am 26 Dez. 2018
Image Analyst
am 23 Dez. 2018
Please read the link I gave you. I know you haven't yet read it because you have not attached the two data files. So please read it.
shobhit pipil
am 23 Dez. 2018
Bearbeitet: shobhit pipil
am 23 Dez. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu NetCDF finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!