필터 지우기
필터 지우기

Extract data from NetCDF files to text files (For SWAT Model).

조회 수: 10 (최근 30일)
shobhit pipil
shobhit pipil 2018년 12월 23일
편집: shobhit pipil 2021년 3월 16일
% 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
Image Analyst
Image Analyst 2018년 12월 23일
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
shobhit pipil 2018년 12월 23일
편집: shobhit pipil 2018년 12월 23일
outfiles shows 365 days records instead of 730 days, because single netcsd contains 1 year records per lat long.
one can copy the same NetCDF file in same directory and change year from 1890 to 91 for testing the code for two files. Single file size is 4.5 GB so I have uploaded just one.
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

shobhit pipil
shobhit pipil 2018년 12월 24일
편집: madhan ravi 2018년 12월 24일
Now It works for me:-
% 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);
outfile =sprintf('%d_%d_PCP.txt',lat(j),long(i));
fopen all;
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,'At');
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by