|
%%this program is used for data dispose of the output file ouput.rch from the result of swat model
clc
clear
outlet=5; %the outlet of of your watershed
%% The file path for the input and output file
file_in='E:work文章1_土地利用变化land use change and its effects on streamflowfigureHT';
file_out='E:work文章1_土地利用变化land use change and its effects on streamflowfigurestremflow';
file_name='up_output.rch';
%% read file
fid=fopen(strcat(file_in,file_name),'r'); %open the input file
fidout=fopen('temp.txt','w'); % creat temporary file
while ~feof(fid) %circulation will not finished if the pointer is not at the end of the file
tline=fgetl(fid); %read the characters in a line; delete the line break; return -1 for the end of the file
if ~isempty(tline)&& strcmp(tline(1),'R'); %the line can'b empty and with a character 'R' in the first location
tline(1:8)=[]; %delete the empty characters
fprintf(fidout,'%sn',tline); % write into the tempfile
end
end
fclose(fid);
%% extract the average month streamflow for the subbasin at the outlet
temp=load('temp.txt');
% delete the data for years
id=find(temp(:,3)>1000);
temp(id,:)=[];
% extract the stremflow at outlet
id_outlet=find(temp(:,1)==5);
sub_outlet=temp(id_outlet,:);
outlet_month=zeros(12,1);
for j=1:12
id_month=find(sub_outlet(:,3)==j); %find the data of each month
sub_moth=sub_outlet(id_month,:);
sub_moth_avg=mean(sub_moth(:,6));
outlet_month(j,1)=sub_moth_avg;
end
%% delete temporary file
fclose('all');
delete temp.txt;
%% write out the file
xlswrite(strcat(file_out,'stream_up_HT.xls'),outlet_month);
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-6-2 14:26
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社