NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/matlab_cen/TIDEOBS.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % /usr/yes/naimie/YellowSea/yes/FUNDY5/YES_TIDEOBS_M3D.m
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 % matlab figure positioning
5 %-----------------------------------------------------------------------
6 clear
7 bdwidth=5;
8 topbdwidth=30;
9 set(0,'Units','pixels');
10 scnsize=get(0,'ScreenSize');
11 scnx=scnsize(3);scny=scnsize(4);
12 pos1=[bdwidth,bdwidth,scny/2-2*bdwidth,scny/2-2*topbdwidth];
13 pos2=[bdwidth,scny/2+bdwidth,scny/2-2*bdwidth,scny/2-2*topbdwidth];
14 pos3=[pos2(3)+bdwidth,scny/2+bdwidth,scny/2-2*bdwidth,scny/2-2*topbdwidth];
15 pos4=[pos2(3)+bdwidth,bdwidth,scny/2-2*bdwidth,scny/2-2*topbdwidth];
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17 % Read data file containing observed tidal observations
18 %-----------------------------------------------------------------------
19 ls *ll;
20 fprintf(1,'\nLocal observational tidal data files:\n',ans)
21 fprintf(1,'%c',ans)
22 fprintf(1,'\n')
23 obsfile=input('Enter the name of the observational tidal data file: ','s');
24 fprintf(1,'\nObservational data file name: ')
25 fprintf(1,'%c',obsfile)
26 fprintf(1,'\n')
27 nconst=13;
28 [pfid,message]=fopen([obsfile]);
29 header=fgets(pfid);
30 fprintf(1,'\nObservational data file contents:\n')
31 fprintf(1,'%c',header)
32 fprintf(1,'\n')
33 header=fgets(pfid);
34 header=fgets(pfid);
35 ii=0;
36 for i=1:44
37    header=fgets(pfid);
38    if header(1) == '*'
39       ii=ii+1;
40       place(ii,:)=fscanf(pfid,'%c',15)';
41       data(ii,:)=fscanf(pfid,'%f',2+nconst*2)';
42       header=fgets(pfid);
43    else
44       header=fgets(pfid);
45    end
46 end
47 fclose(pfid);
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 % Remove missing observations and shrink data array down for desired
50 % frequency
51 %-----------------------------------------------------------------------
52 size(data(:,1));
53 nobs=ans(1);
54 nconst=input('Enter the constituent number: ');
55 % nconst=1;
56 if nconst == 1
57    const='M2'
58    freq=0.140519E-03
59 elseif nconst == 2
60    const='S2'
61    freq=0.145444E-03
62 elseif nconst == 3
63    const='N2'
64    freq=0.137880E-03
65 elseif nconst == 5
66    const='K1'
67    freq=0.729212E-04
68 elseif nconst == 12
69    const='M4'
70    freq=2.0*0.140519E-03
71 elseif nconst == 6
72    const='O1'
73    freq=0.675977E-04
74 else
75    dummy=input('Error!!!!!!!','s')
76 end
77 ii=0;
78 %
79 for i=1:nobs
80     if data(i,3+2*(nconst-1)) > 0.0
81        ii=ii+1;
82        place2(ii,:)=place(ii,:);
83        data2(ii,1)=data(i,1);
84        data2(ii,2)=data(i,2);
85        data2(ii,3)=data(i,3+2*(nconst-1));
86        data2(ii,4)=data(i,4+2*(nconst-1));
87     end
88 end
89 nobs=ii;
90 clear data; data=data2; clear data2; clear place; place=place2; clear place2;
91 fprintf(1,'\nThere are %4.0f positive amplitude observations\n',nobs);
92 %
93 xlobs=data(:,1);
94 ylobs=data(:,2);
95 [xobs,yobs]=ll2xy_yes(ylobs,xlobs);
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 % Load .s2c file and finite element mesh
98 % Plot observational names and locations
99 % Load model data arrays at observational locations
100 %-----------------------------------------------------------------------
101 ls *.s2c;
102 fprintf(1,'\nLocal .s2c files:\n',ans)
103 fprintf(1,'%c',ans)
104 fprintf(1,'\n')
105 modfile=input('Enter the name of model generated .s2c file: ','s');
106 [s2c,freqm,mesh]=read_v2r(modfile);
107 freq
108 freqm
109 amp=s2c(:,2);
110 pha=s2c(:,3);
111 mesh=blank(mesh(1:length(mesh)-1));
112 [in,x,y,z,bnd]=loadgrid(mesh);
113 [yl,xl]=xy2ll_yes(x,y);
114 %
115 figure('Position',pos4);
116 whitebg('w')
117 bndo=plotbnd(xl,yl,bnd);
118 set(bndo,'Color','k')
119 hold on
120 plot(xlobs,ylobs,'bo')
121 size(xlobs);
122 nobs=ans(1);
123 for i=1:nobs
124    text(xlobs(i)+0.05,ylobs(i),place(i,:))
125 end
126 %
127 for i=1:nobs
128    [smin(i),nclosest(i)]=min((x-xobs(i)).^2.0+(y-yobs(i)).^2.0);
129    mdata(i,1)=xl(nclosest(i));
130    mdata(i,2)=yl(nclosest(i));
131    mdata(i,3)=amp(nclosest(i));
132    mdata(i,4)=pha(nclosest(i));
133    if (mdata(i,4)-data(i,4)) > 180
134       mdata(i,4)=pha(nclosest(i))-360.0;
135    elseif (mdata(i,4)-data(i,4)) < -180
136       mdata(i,4)=pha(nclosest(i))+360.0;
137    end
138 end
139 plot(mdata(:,1),mdata(:,2),'rx');
140 axis('tight')
141 % close
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 % Perform statistical comparison
144 % Make histogram plot of statistical comparison
145 %-----------------------------------------------------------------------
146 amperr=100*(mdata(:,3)-data(:,3));
147 phaerr=mdata(:,4)-data(:,4);
148 amperrmean=mean(abs(amperr));
149 amperrbias=mean(amperr);
150 amperrstd=std(amperr);
151 phaerrmean=mean(abs(phaerr));
152 phaerrbias=mean(phaerr);
153 phaerrstd=std(phaerr);
154 fprintf(1,'\nAmplitude Error Statistics (mean, bias, std): %5.1f %5.1f %5.1f\n',amperrmean,amperrbias,amperrstd)
155 fprintf(1,'Phase Error Statistics     (mean, bias, std): %5.1f %5.1f %5.1f\n',phaerrmean,phaerrbias,phaerrstd)
156 %
157 figure('Position',pos1)
158 whitebg('w')
159 subplot(2,1,1)
160 hist(amperr)
161 hold on
162 axis([-round(mean(100.0*data(:,3))) round(mean(100.0*data(:,3))) 0.0 20.0])
163 title([verbatim(modfile),': Error Histograms; (mean amp = ',num2str(round(mean(100.0*data(:,3)))),' cm)'])
164 xlabel(['Amplitude Error (cm): [mean,bias,std]=[',num2str(round(amperrmean)),',',num2str(round(amperrbias)),',',num2str(round(amperrstd)),']'])
165 ylabel('Number of Observations')
166 zoom on
167 subplot(2,1,2)
168 hist(phaerr)
169 hold on
170 axis([-180.0 180.0 0.0 20.0])
171 xlabel(['Phase Error (deg): [mean,bias,std]=[',num2str(round(phaerrmean)),',',num2str(round(phaerrbias)),',',num2str(round(phaerrstd)),']'])
172 ylabel('Number of Observations')
173 zoom on
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 % Plot FEM boundary, model results, and observational data(?)
176 %-----------------------------------------------------------------------
177 % moreplots=input('\nProceed with amplitude and phase plots (y/n)? ','s');
178 moreplots='y';
179 if moreplots == 'y'
180 %
181 figure('Position',pos2)
182 whitebg('w');
183 colorcontour_fe(in,xl,yl,bnd,100.0*amp);
184 hold on
185 plot(xlobs,ylobs,'bo')
186 % choice=input('Labels of Obs Amp or Amp Errors (o/e)? ','s');
187 choice='e';
188 if choice=='o'
189    text(xlobs,ylobs,num2str(round(100*data(:,3))));
190    title([verbatim(modfile),': Observed ',const,' Mod Amp and Obs Amp (cm)']);
191 else
192    text(xlobs,ylobs,num2str(round(100*(mdata(:,3)-data(:,3)))))
193    title([verbatim(modfile),': Observed ',const,' Mod Amp - Obs Amp (cm):  RMS=',num2str(100*(rms(mdata(:,3)-data(:,3))))])
194 end
195 axis('tight')
196 zoom on
197 %
198 figure('Position',pos3);
199 whitebg('w');
200 colorcontour_fep(in,xl,yl,bnd,pha);
201 hold on;
202 plot(xlobs,ylobs,'bo');
203 % choice=input('Labels of Obs Phase or Phase Errors (o/e)? ','s');
204 choice='e';
205 if choice=='o'
206    text(xlobs,ylobs,num2str(round(data(:,4))));
207    title([verbatim(modfile),': Observed ',const,' Mod Phase and Obs Phase (deg)']);
208 else
209    text(xlobs,ylobs,num2str(round((mdata(:,4)-data(:,4)))))
210    title([verbatim(modfile),': Observed ',const,' Mod Phase - Obs Phase (deg):  RMS=',num2str(rms(mdata(:,4)-data(:,4)))]);
211 end
212 axis('tight')
213 zoom on
214 end
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 % Convert zeta to time domain (24 samples per tidal period)
217 %-----------------------------------------------------------------------
218 for i=1:24
219    tday(i)=(i-1)/24.0*2.0*pi/freq/3600.0/24.0;
220    for ii=1:nobs
221       elev_obs(i,ii)=data(ii,3)*cos((i-1)/24.0*2.0*pi-data(ii,4)*pi/180.);
222       elev_mod(i,ii)=amp(nclosest(ii))*cos((i-1)/24.0*2.0*pi-pha(nclosest(ii))*pi/180.);
223    end
224 end
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % Plot time-domain reconstruction of observations and model results
227 %  at closest nodes (?)
228 %-----------------------------------------------------------------------
229 % moreplots=input('\nProceed with plots of observed and modeled elevation(t) (y/n)? ','s');
230 moreplots='n';
231 if moreplots == 'y'
232 for ifigure=1:ceil(nobs/35)
233    figure
234    for ii=1+(ifigure-1)*35:min(ifigure*35,nobs)
235       ipanel=ii-(ifigure-1)*35
236       subplot(7,5,ipanel)
237       hold on
238       title(place(ii,:))
239       plot(tday,elev_obs(:,ii),'b-')
240       plot(tday,elev_mod(:,ii),'r-.')
241    end
242 end
243 end
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % Output *m3d files if desired
246 %-----------------------------------------------------------------------
247 % ans=input('Output .m3d files? (y/n)  ','s')
248 ans='y';
249 if ans == 'y'
250 fidobs=fopen([const,'_obs.m3d'],'w');
251 fprintf(fidobs,'XXXX\n');
252 fprintf(fidobs,'%c',mesh);
253 fprintf(fidobs,'\nObserved elevations mapped to nearest finite element mesh nodes\n1995\n6\n');
254 fidmod=fopen([const,'_mod.m3d'],'w');
255 fprintf(fidmod,'XXXX\n');
256 fprintf(fidmod,'%c',mesh);
257 fprintf(fidmod,'\nModel elevations at finite element mesh nodes nearest observational sites\n1995\n6\n');
258 for i=1:24
259    for ii=1:nobs
260 %      fprintf(fidobs,'%12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n',tday(i),xobs(ii),yobs(ii),elev_obs(i,ii),elev_obs(i,ii),elev_obs(i,ii));
261       fprintf(fidobs,'%12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n',tday(i),x(nclosest(ii)),y(nclosest(ii)),elev_obs(i,ii),elev_obs(i,ii),elev_obs(i,ii));
262       fprintf(fidmod,'%12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n',tday(i),x(nclosest(ii)),y(nclosest(ii)),elev_mod(i,ii),elev_mod(i,ii),elev_mod(i,ii));
263    end
264 end
265 fclose(fidobs);
266 fclose(fidmod);
267 end
Note: See TracBrowser for help on using the browser.