%
addpath ./utils
 namerun='p12n_bdy_tr12n_quik';
 namerun_title=regexprep(namerun,'_','\\_');
%namerun='erai21c';

 year='2001';
%year='1990';

 rep='20010101_20011231';
%rep='19900101_19901231';

%temp='votemper';
 temp='thetao';

 dirfile=['/loceanfs/pulsation/cholod/peru12_nemo/outputs/' namerun '/' rep '/']; 
%dirfile=['/net/adonis/usr/adonis/phybiocar/cholod/peru12_nemo/outputs/' namerun '/' rep '/']; 
%dirfile=['/net/cratos/usr/cratos/phybiocar/fclod/NEMO_STEPHANE/1994/' namerun '/'] 

grd=rnt_gridload_xa('roms12nemo'); 
%_______________
% Chris
%    Mfileu=[dirfile 'peru12_1s_' rep '_grid_U_3D.' namerun '.nc'] 
%    Mfilev=[dirfile 'peru12_1s_' rep '_grid_V_3D.' namerun '.nc'] 
%    Mfilet=[dirfile 'peru12_1s_' rep '_grid_T_T3D.' namerun '.nc'] 
% Seb
     Mfileu=[dirfile namerun '_1s_' rep '_grid_U_3D.nc'] 
     Mfilev=[dirfile namerun '_1s_' rep '_grid_V_3D.nc'] 
     Mfilet=[dirfile namerun '_1s_' rep '_grid_T_T3D.nc'] 
%_______________

 time='time_average_1mo';

%Mfileu=[dirfile 'peru12_1s_19940101_19941231_grid_U.' namerun '.nc']
%Mfilev=[dirfile 'peru12_1s_19940101_19941231_grid_V.' namerun '.nc']
%Mfilet=[dirfile 'peru12_1s_19940101_19941231_grid_T.' namerun '.nc']
%time='time_counter';
%time='time';

 ctlMu=rnt_timectl({Mfileu}, time);
 ctlMv=rnt_timectl({Mfilev}, time);
 ctlMt=rnt_timectl({Mfilet}, time);
%ctlMu=rnt_timectl({Mfileu}, 'time_counter');
%ctlMv=rnt_timectl({Mfilev}, 'time_counter');
%ctlMt=rnt_timectl({Mfilet}, 'time_counter');
%
rootprint='./'; %% CUS, PCS, CCS, CBL
season=[5]; 
figname=['peru_' namerun '_' year '_']; %% hfsa4, usw51, canbas, cblanco i
%
vname='r2v';  prename='along_'; dist=3e5;
colaxis=[-0.1 0.1];   %% PCS and CCS
%
latpm=3;
%%latsec=[-10 -25 -31 ];
latsec=-10;
%%%%%%%%%%%%% END INPUTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
nc=netcdf(Mfilet,'r'); zl=-1*nc{'deptht'}(:); close(nc); NN=length(zl);

for k=1:length(latsec)
 latmin=latsec(k)-latpm; latmax=latsec(k)+latpm;
[Mvar,Mmask,Mh,distx]=get_section_meanlongshore_nemo(grd,ctlMu,ctlMv,ctlMt,vname,season,dist,latmin,latmax,NN);
[MTemp,Mmask,Mh,distx]=get_section_meanlongshore_nemo(grd,ctlMu,ctlMv,ctlMt,temp,season,dist,latmin,latmax,NN);
%
   figure;
   contourf(distx/1000,zl,Mvar,30); shading flat; hold on; caxis([colaxis(1) colaxis(2)]); 
   axis([-250 0 -300 0]); plot(distx/1000,-Mh,'k');
   hy=ylabel('Depth [m]'); set(hy,'FontS',14); hx=xlabel('Distance [km]'); set(hx,'FontS',14);
   set(gca,'FontS',14); set(gca,'PlotBoxAspectRatio',[0.7 1 1]); wysiwyg; box on;
   [ctt,htt]=contour(distx/1000,zl,MTemp,[10:1:25]); set(htt,'LineColor',[0.3 0.3 0.3]);
   clabel(ctt,htt,'FontS',14,'LabelSpacing',300,'Color',[0.3 0.3 0.3]);
   hcc=colorbar; set(hcc,'FontS',14);
   title(['Annual Mean (m/s)- ' namerun_title ' (' year ')'], 'FontSize',18);


%
   figname2=[prename figname 'seas' num2str(season) '_lat' num2str(latsec(k))];
%%   eval(['print -depsc2 -r100  ' rootprint figname2 '.eps'])
%%   eval(['print -djpeg  ' rootprint figname2 '.jpg'])
%
end  % end of latsec loop
%%%%%%%%%%%%%%%%%%%%%%%%%

print ('-dpng',figname2);

quit


