% function results(runid)

clear all

runid = ['FCAST_1.1B1/EN324_FC.01']
% based on RESULTS_CRUISE_Q4.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Load observational data
%
OPATH=['../fcast_archives/',runid,'/OBS/']
UVOF=[OPATH,'UV_INTEG.m3d']
%
[UVO,gridname,year,ncol,gmt]=read_obs(UVOF);
%
% Load model results
%
for isim=1:3
   MPATH=['../fcast_archives/',runid,'/CRUISE_Q4.',num2str(isim),'/'];
   UVMF=[MPATH,'UV_INTEG-Q4.m3d']
   [UVEM(isim,:,:),gridname,year,ncol,gmt]=read_obs_trunc(UVMF);
   nmod=length(UVEM(isim,:,1));
%DJM
   for i=1:length(UVEM(isim,:,1))
      ii(i)=find(abs(UVO(:,1)-UVEM(isim,i,1))<0.0001);
   end
 end

gridname='../MESH/bank150';
gridstruct=loadgrid(gridname);

%DJM
[la,lo]=xy2ll(gridstruct.x,gridstruct.y);
gridstruct.x=lo;gridstruct.y=la;

%
% Vector plots of observational and model results
%
tallfigure;
%
subplot(2,2,1)
hb=plotbnd(gridstruct);
axis('tight');
hc=lcontour(gridstruct,'z',[40 50 60 70 80 90 100]);
set(hc,'LineWidth',.25)
%DJM
% axis([150000 250000 -250000 -150000]);
% axis('square');set(gca,'XTick',[]);set(gca,'YTick',[]);
axis('square')
hold on
V=UVO(ii,:);
%DJM
   [la,lo]=xy2ll(V(:,2),V(:,3));
   V(:,2)=lo;V(:,3)=la;

hv=vecplot2(V(:,2),V(:,3),V(:,4),V(:,5),0.5,'m/s',230000.,-160000.);
set(hv,'color','blue');
title(verbatim(['Observations: RMS = ',num2str(rms(V(:,4)+sqrt(-1.0)*V(:,5))),' m/s']))
for isim=1:3
   subplot(2,2,isim+1)
   V=reshape(UVEM(isim,:,:),length(UVEM(isim,:,1)),ncol);
   hb=plotbnd(gridstruct);
   axis('tight');
   set(hb,'LineWidth',.5)
   hc=lcontour(gridstruct,'z',[40 50 60 70 80 90 100]);
   set(hc,'LineWidth',.25)
%DJM
%  axis([150000 250000 -250000 -150000]);
%  axis('square');set(gca,'XTick',[]);set(gca,'YTick',[]);
%  axis('square');
   axis([-68.5 -67.0 40.75 41.5])
   hold on
   V=reshape(UVEM(isim,:,:),length(UVEM(isim,:,1)),ncol);
%DJM
   [la,lo]=xy2ll(V(:,2),V(:,3));
   V(:,2)=lo;V(:,3)=la;

   hv=vecplot2(V(:,2),V(:,3),V(:,4),V(:,5),0.5,'m/s',-68.4,40.8);
   set(hv,'color','black')
   title([runid,' Quoddy Simulation ',num2str(isim),': rms error=',num2str(rms(V(:,4)+sqrt(-1)*V(:,5))),' m/s']);
end

figure
hb=plotbnd(gridstruct);
   axis('tight');
   set(hb,'LineWidth',.5)
   hc=lcontour(gridstruct,'z',[40 50 60 70 80 90 100]);
   set(hc,'LineWidth',.25)
   axis([-68.0 -66.75 40.5 41.5])
   hold on
   V=reshape(UVEM(isim,:,:),length(UVEM(isim,:,1)),ncol);
%DJM
   [la,lo]=xy2ll(V(:,2),V(:,3));
   V(:,2)=lo;V(:,3)=la;

   hv=vecplot2(V(:,2),V(:,3),V(:,4),V(:,5),0.5,'m/s',-67.9,41.4);
   set(hv,'color','black')
   title([runid,' Quoddy Simulation ',num2str(isim),': rms error=',num2str(rms(V(:,4)+sqrt(-1)*V(:,5))),' m/s']);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
