  function view_cdf(time)
% ADD PATH    ADD PATH    ADD PATH     ADD PATH   ADD PATH
% *****************************************************
    
% DEFINE ERROR STRINGS
err1=str2mat('You must specify 1 input argument; call VIEW_CDF',...
      'as view_cdf(jlong), time -- how many days beginning',...
      'from Oct 27, 1992 you would like to view.',...
      ' The total length is 2151 days. ');
if nargin < 1
   disp('??? Error using ==> view_cdf ');disp(' ');
   disp(err1);
   return
end

netcdfhome = '/whoinet/bernard/usr/people/valery/netcdf/';

eval(['addpath ' netcdfhome]);
eval(['addpath ' netcdfhome 'ncfiles']);
eval(['addpath ' netcdfhome 'nctype']);
eval(['addpath ' netcdfhome 'ncutility']);

% *****************************************************
    flg=1;
    n=3;
    jlong=time;
%  program view_cdf.m     
% view content of the netCDF file: predicted streamfunction (SLA) field, 
% referenced SLA field (OA output), and pridicted-referenced difference.
% $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
%                                                                      $
%                      PROGRAM VIEW_CDF                                $
%                                                                      $
% $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
% set up input parameters:
% BATS site coordinates
       xbats=-64.17;
       ybats=31.74;
% set julian day, model day, the beginning and the ending days of the movie  
       jul=datenum(1992,10,27);
       t=jul-datenum(1992,1,1)
       jbeg=1
       jend=jbeg+jlong
% set colormap
       colormap(jet(10));
% set caxis limits
       cval1=[-20:4:20];
       cval2=[-10:4:10];
       cval3=[1:11];
% ------------------------------------------------------------%
% ------------------------------------------------------------%
%          OPEN SOURCE (CDF) FILE                             %
% ------------------------------------------------------------%
% ------------------------------------------------------------% 
        nc = netcdf('tp2cdf_d.nc', 'nowrite');
        description = nc.description(:)                      
        variables = var(nc);                                 
        for i = 1:length(variables)
        disp([name(variables{i}) ' =']), disp(' ');
%       disp(variables{i}(:))
        end
%
% load source var to draw  T/P and ERS tracks
       if(flg==1)                
       va1=nc{'alt_1'}(:);
       va2=nc{'alt_2'}(:);             
       va1=[va1;va2];
       clear va2;
       va2=nc{'alt_3'}(:);            
       va1=[va1;va2];
       clear va2;
       end
% load dynheight
       dyn=nc{'dynheight'}(:);
% load bermuda
       berm=nc{'ber'}(:);
% load source files: computed and referenced streamfunction and vorticity
       a=nc{'streamf_sim'}(:);
       a=a/2.3162;
       b=nc{'streamf_ref'}(:);
       b=b/2.3162;
       xi=nc{'lon'}(:);
       yi=nc{'lat'}(:);
set(gcf,'color','k');
       hh=1;
% "diamond" perimeter
       xv=[xi(1,1);xi(1,31);xi(25,31);xi(25,1);xi(1,1)];
       yv=[yi(1,1);yi(1,31);yi(25,31);yi(25,1);yi(1,1)];  
% set Box Aspect Ratio 
       lonmax=-min(xi(:));
       lonmin=-max(xi(:));
       latmax=max(yi(:));
       latmin=min(yi(:));
       weight=111*cos(pi*(latmin+(latmax-latmin)*.5)/180);
       xc=(lonmax-lonmin)*weight;
       yc=(latmax-latmin)*111;
       relyx=yc/xc;
% -------- CLOSE CDF FILE ---------------------------------%
       close(nc)
% start drawing SLA field
       for j=[jbeg:jend];
       as=a(:,:,j);
       bs=b(:,:,j);
       cs=as-bs;
% draw predicted SLA
       
       subplot(2,2,1)
       contourf3(xi,yi,as,cval1);
       hold on;
       plot(berm(:,1),berm(:,2),'color','k','LineWidth',[1.2]);
%      plot(xl,yl,'k-','LineWidth',[4.0]);
       if(isempty(find((j+299)==dyn)))
       plot(xbats,ybats,'r.','MarkerSize',22);
       else
       plot(xbats,ybats,'o','MarkerSize',10,'Markerfacecolor',...
       'w','Markeredgecolor','r');
       end
       text(xbats,ybats,['  BATS '],'HorizontalAlignment','left',...
       'FontWeight','bold','FontSize',10);
       hold off
%       axis square;
       set(gca,'PlotBoxAspectRatio',[1 relyx*1 1]);
       caxis([-20 20]);
              
       h1=colorbar;
   

       set(h1,'XColor','w','YColor','w');
       set(h1,'FontWeight','bold','FontSize',10);
       set(h1,'ytick',cval1);
%       set(h1,'YTickLabel',[-20 -12 -4 0 4 12 20]); 
       set(h1,'ticklength',[0.05 0.025]);
       set(gca,'XColor','w','YColor','w');
       set(gca,'FontWeight','bold','FontSize',12);
%      xlabel('Longitude (deg E)','color','w','FontWeight','bold','FontSize',8);
       ylabel('Latitude (deg N)','color','w','FontWeight','bold','FontSize',12);
       title(['Predicted SLA (cm)'],'color','g',...
       'FontAngle','italic','FontWeight','bold','FontSize',12);

       set(gca,'XGrid','on','color','k','YGrid','on','color','k');
% find TP and ERS tracks for 7 days period      
       if(flg==1)
       tmin=t-n;
       tmax=t+n+1;
       v1=va1(find(va1(:,1)>=tmin & va1(:,1)<=tmax),:);
       er1=v1(find(v1(:,5)==15),:);
       tp1=v1(find(v1(:,5)==1),:);
       end; 
% draw observed SLA
       subplot(2,2,2)
       contourf3(xi,yi,bs,cval1);
       hold on
       plot(berm(:,1),berm(:,2),'color','k','LineWidth',[1.2]);
%      plot(xl,yl,'k-','LineWidth',[4.0]);
       if(flg==1)
       plot(tp1(:,3),tp1(:,2),'w.','markersize',7.0);      
       plot(er1(:,3),er1(:,2),'g.','markersize',7.0);      
       end
       if(isempty(find((j+299)==dyn)))
       plot(xbats,ybats,'r.','MarkerSize',22);
       else
       plot(xbats,ybats,'o','MarkerSize',10,'Markerfacecolor',...
       'w','Markeredgecolor','r');
       end
       text(xbats,ybats,['  BATS '],'HorizontalAlignment','left',...
       'FontWeight','bold','FontSize',10);
       hold off
%       axis square;
       set(gca,'PlotBoxAspectRatio',[1 relyx*1 1]);
       caxis([-20 20]);
       
       h2=colorbar;
%
       set(h2,'XColor','w','YColor','w');
       set(h2,'FontWeight','bold','FontSize',10);
       set(h2,'ytick',cval1);
%       set(h2,'YTickLabel',[-20 -12 -4 0 4 12 20]);
       set(h2,'ticklength',[0.05 0.025]);
       set(gca,'XColor','w','YColor','w');
       set(gca,'FontWeight','bold','FontSize',12);
%      xlabel('Longitude (deg E)','color','w','FontWeight','bold','FontSize',8);
%      ylabel('Latitude (deg N)','color','w','FontWeight','bold','FontSize',12);
       title(['Observed SLA (cm)'],'color','g',...
       'FontAngle','italic','FontWeight','bold','FontSize',12);
       set(gca,'XGrid','on','color','k','YGrid','on','color','k');
% draw predicted - observed SLA difference
       subplot(2,2,3)
       contourf3(xi,yi,cs,cval1);
       hold on;
       plot(berm(:,1),berm(:,2),'color','k','LineWidth',[1.2]);
%      plot(xl,yl,'k-','LineWidth',[4.0]);
       if(isempty(find((j+299)==dyn)))
       plot(xbats,ybats,'r.','MarkerSize',22);
       else
       plot(xbats,ybats,'o','MarkerSize',10,'Markerfacecolor',...
       'w','Markeredgecolor','r');
       end
       text(xbats,ybats,['  BATS '],'HorizontalAlignment','left',...
       'FontWeight','bold','FontSize',10);
       hold off
%       axis square;
       set(gca,'PlotBoxAspectRatio',[1 relyx*1 1]);
       caxis([-20 20]);

       h3=colorbar;

       set(h3,'XColor','w','YColor','w');
       set(h3,'FontWeight','bold','FontSize',10);
       if(j==1)
       set(h3,'ytick',cval3);
       set(h3,'yticklabel',[-20 -16 -12 -8 -4 0 4 8 12  16  20]);
       else
       set(h3,'ytick',cval1);
%       set(h3,'yticklabel',[-10  -6  -2  2  6  10]);
       end
       set(h3,'ticklength',[0.05 0.025]);
       set(gca,'XColor','w','YColor','w');
       set(gca,'FontWeight','bold','FontSize',12);
       xlabel('Longitude (deg E)','color','w','FontWeight','bold','FontSize',12);
       ylabel('Latitude (deg N)','color','w','FontWeight','bold','FontSize',12);
       title(['SLA Difference (cm)'],'color','g',...
       'FontAngle','italic','FontWeight','bold','FontSize',12);
       set(gca,'XGrid','on','color','k','YGrid','on','color','k');
       subplot(224)
       set(gca,'color','k')
       title([datestr(jul,1)]...
       ,'color','g','FontWeight','bold','FontSize',14);
% set path for output files
       t=t+1;
       jul=jul+1;
       input('Press "Enter" to see next plot');
       end
