% to make sflux plots daily ATL24 for tropical Atlantic.

% /mnt/lustre01/work/uo0122/u241089/ATL/ATL24/daily/F1/file.0001, sflux

addpath /work/uo0122/u241272/Compare_EN4_GECCO2/m_map

lati=ncread('/mnt/lustre01/work/uo0122/u241089/ATL/ATL24/grid_new.nc','yc'); %2D
long=ncread('/mnt/lustre01/work/uo0122/u241089/ATL/ATL24/grid_new.nc','xc'); %2D
% for longitude limits 
a=find(long(:,1)>=-65); % -65
lonlim1=a(1);
%lonlim1=a(1)-1;

a=find(long(:,1)>=-42); % -42
%lonlim2=a(1)-1;
lonlim2=a(1);

% for latitude limits
a=find(lati(1,:)>=5.8); % 5.8
%latlim1=a(1);
latlim1=a(1)-1;

a=find(lati(1,:)>=24); % 24
latlim2=a(1);
%latlim2=a(1)-1;

%Dates for output (plot) filenames
DatesOut=strings(3287,1);
idate=1;
MonthDays=[31 28 31 30 31 30 31 31 30 31 30 31];
MonthDaysLeap=[31 29 31 30 31 30 31 31 30 31 30 31];
for iyear=2003:2011
  for imonth=1:12
    if iyear==2004 || iyear==2008
      for iday=1:MonthDaysLeap(imonth)
        DatesOut(idate)=sprintf('%02d-%02d-%d',iday, imonth, iyear);
        idate=idate+1;
      end
    else
      for iday=1:MonthDays(imonth)
        DatesOut(idate)=sprintf('%02d-%02d-%d',iday, imonth, iyear);
        idate=idate+1;
      end
    end
  end
end

load('/mnt/lustre01/work/uo0122/u241272/ATL24/MyColormap_light_centered','mymap');

for l=VALUEX %1:3287
  tic
  l

  filenum=sprintf('%04d', l);
  %Read sflux
  sf=ncread(strcat('/mnt/lustre01/work/uo0122/u241089/ATL/ATL24/daily/F1/file.',filenum),'sflux',[lonlim1 latlim1 1],[lonlim2-lonlim1+1 latlim2-latlim1+1 1],[1 1 1]);
  epr=(sf./(1029*35))*1e7;
 
    h=figure('units','centimeters','position',[0 0 30 30]);set(h, 'Visible', 'off');
    %figure('units','centimeters','position',[0 0 30 30]);
    m_proj('Mercator','longitude',[-65 -42],'latitude',[7 24]);
    m_pcolor(long(lonlim1:lonlim2,latlim1:latlim2),lati(lonlim1:lonlim2,latlim1:latlim2),epr(1:end,1:end));shading flat;
    m_coast('patch',[0.8 0.8 0.8],'edgecolor','k');
    m_grid('box','fancy','tickdir','in');
    t=strcat('E-P-R, ATL24');
    title([t,strjoin(DatesOut(l))]); set(gca,'FontSize',16);
    %[lc]=bluewhitered(60);
    %colormap(lc);
    %colormap(b2r(-16,10,60));
    %colormap(b2r(-6,3,120));
    %colormap(b2r(-0.02,0.01,120));
    %[lc]=light_centered(130);
    %colormap(lc);
    colormap(mymap);
    cb = colorbar;
    cb.Label.String = 'x 10^-^7  m/s';
    set(gca,'clim',[-2.5 2.5]);
    %caxis([-0.055 0.035])
    %set(gca,'clim',[-6 6]);
    %filename=strcat('/work/uo0122/u241272/ATL24/Box1_new/ATL24_epr_box1_',filenum,'_',DatesOut(l));
    filename=strcat('/work/uo0122/u241272/ATL24/Box1_new/ATL24_epr_box1_new_',filenum,'_',DatesOut(l));
    print(filename,'-dpng');

    close
    clear filename sf filenum epr
toc
end %l

%cbh=colorbar('h');
%set(cbh,'XTick',[0:10:150])

% fudge_zero = 1/10;
%extreme = max(abs(x(:))) * (1+eps);
%L = logspace(fudge_zero,extreme, 128)  %256 entry colormap
%logmap = [-fliplr(L), L];

%[bins, xbinidx] = histc(x, logmap);

