zhanghouxing的个人博客分享 http://blog.sciencenet.cn/u/zhanghouxing

博文

SWAT output.rch文件中流域出口径流提取代码

已有 4066 次阅读 2014-11-24 11:09 |系统分类:科研笔记

%%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);




https://wap.sciencenet.cn/blog-922140-845843.html

上一篇:转入转出土地空间分布图
下一篇:matlab 编译可执行exe文件方法
收藏 IP: 210.77.68.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-2 14:26

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部