Demo entry 5276196

t_tide

   

Submitted by anonymous on Jun 14, 2016 at 01:35
Language: Matlab. Code size: 3.8 kB.

close all;clear;clc;
files = dir('D:\study\numerical simulation\tidal prediction\data0\*.csv');
lf=length(files);
tuk_elev = []; tuk_time = [];

for k = 1 : lf
     data = ['M',num2str(k),'.csv'];
     fdata = fopen(data ,'r');
     C = textscan(fdata,'%s%s%s%s%s%s%s%s','delimiter',',','headerlines',1);
     time = datenum(C{:,1});
     elev = str2double(C{:,2});

     tuk_elev = [tuk_elev;elev];
     tuk_time = [tuk_time;time];
end
save('tide.mat','tuk_elev','tuk_time');
% put the tide level and time of 13 months data into a mat file
tuk_time=datenum(tuk_time);
[year,month,day,hour,minute,second]=datevec(tuk_time);


 for yr=2015
     for mon=1:12
         ind=find( year == yr & month == mon & day == 1 & hour == 0 & minute == 0);
         t(mon)=ind;
         tl(mon)=tuk_time(ind);
     end
 end
yr=2016; ind=find( year == yr & month ==1 & day == 1 & hour == 0 & minute == 0);
t(lf)=ind;
tl(lf)=tuk_time(ind);


[NAME,FREQ,TIDECON,XOUT] = t_tide(tuk_elev,'interval',0.1,'latitude',29.35,'start time ',[2015,01,01,00,00,00],'rayleigh',['S2';'M2';'N2';'K2';'K1';'P1';'O1';'Q1']);
%指定的8个分潮
%  NAME里为调和分析得到的分潮的名字,这个是根据数据的长度来确定的,越长的数据得到的分潮越多。
% FREQ为分潮的角速率(°/h)
% TIDECON第一列为分潮振幅,第三列为分潮迟角
% XOUT(未加上平均海平面)调和分析回报的潮位

[NAME1,FREQ1,TIDECON1,XOUT1] = t_tide(tuk_elev,'interval',0.1,'latitude',29.35,'start time ',[2015,01,01,00,00,00]);
%参数的意义同上,这里是68个分超
avg_elev = mean(tuk_elev)

figure(1)
subplot(211)
plot(tuk_time,tuk_elev,'k','linewi',1);
hold on;
plot(tuk_time,XOUT,'r','linestyle',':','linewi',1);

xlim([tuk_time(1) tuk_time(end)]);
set(gca,'XTick',tl,'Tickdir','out');
set(gca,'XTickLabel',{'2015.1','2015.2','2015.3','2015.4','2015.5','2015.6','2015.7','2015.8','2015.9','2015.10','2015.11','2015.12','2016.1'});
xlabel('Days from 2015.1.1 to 2016.1.31');
ylabel('Elevation');
legend('original time series','tidal prediction with 8constituents');


subplot(212)
plot(tuk_time,tuk_elev,'k','linewi',1);
hold on;
plot(tuk_time,tuk_elev-XOUT,'r','linestyle',':','linewi',2);

xlim([tuk_time(1) tuk_time(end)]);
set(gca,'XTick',tl,'Tickdir','out');
set(gca,'XTickLabel',{'2015.1','2015.2','2015.3','2015.4','2015.5','2015.6','2015.7','2015.8','2015.9','2015.10','2015.11','2015.12','2016.1'});
xlabel('Days from 2015.1.1 to 2016.1.31');
ylabel('Elevation');
legend('original time series','oringinal time series minus prediction');
title('tidal prediction with 8constituents');



figure(2)
subplot(211)
plot(tuk_time,tuk_elev,'k','linewi',1);
hold on;
plot(tuk_time,XOUT1,'b','linestyle','--','linewi',1)
xlim([tuk_time(1) tuk_time(end)]);
set(gca,'XTick',tl,'Tickdir','out');
set(gca,'XTickLabel',{'2015.1','2015.2','2015.3','2015.4','2015.5','2015.6','2015.7','2015.8','2015.9','2015.10','2015.11','2015.12','2016.1'});
xlabel('Days from 2015.1.1 to 2016.1.31');
ylabel('Elevation');
legend('original time series','tidal prediction with 64constituents');
title('tidal prediction with 64constituents');

subplot(212)
plot(tuk_time,tuk_elev,'k','linewi',1);
hold on;
plot(tuk_time,tuk_elev-XOUT1,'b','linestyle','--','linewi',2)
xlim([tuk_time(1) tuk_time(end)]);
set(gca,'XTick',tl,'Tickdir','out');
set(gca,'XTickLabel',{'2015.1','2015.2','2015.3','2015.4','2015.5','2015.6','2015.7','2015.8','2015.9','2015.10','2015.11','2015.12','2016.1'});
xlabel('Days from 2015.1.1 to 2016.1.31');
ylabel('Elevation');
legend('original time series','tidal prediction with 64constituents');
title('tidal prediction with 64constituents');

%预报
startdate = datenum('2016/06/01');
enddate = datenum('2016/12/31');
t = startdate:1/240:enddate;
yout = t_predic(t,NAME1,FREQ1,TIDECON1);
figure(3);
plot(t-datenum('2016,6,1'),yout);
xlabel('days in june2dec 2016');
ylabel('Elevation');
title('prediction');

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).