function comp_timeseries_mon(IBAS,CNAM,CTAG,varargin)

% grid info
%fgrid_mis3='/work/shared/noresm/inputdata/ocn/micom/tnx1v1mis3/20160721/grid.nc';
fgrid_mis3='/projects/NS4659K/chuncheng/diag/Data/grid.nc';
%fgrid_mis3='/projects/NS2345K/noresm/inputdata/ocn/micom/gx1v6/20100629/grid.nc';

lon=ncread(fgrid_mis3,'plon');
lat=ncread(fgrid_mis3,'plat');
area=ncread(fgrid_mis3,'parea');

% Nino 1+2
ninoindex_lon(1,1)=-90;
ninoindex_lon(2,1)=-80;
ninoindex_lat(1,1)=-10;
ninoindex_lat(2,1)=0;

% Nino 3
ninoindex_lon(1,2)=-150;
ninoindex_lon(2,2)=-90;
ninoindex_lat(1,2)=-5;
ninoindex_lat(2,2)=5;

% Nino 3-4
ninoindex_lon(1,3)=-170;
ninoindex_lon(2,3)=-120;
ninoindex_lat(1,3)=-5;
ninoindex_lat(2,3)=5;

% Nino 4
ninoindex_lon(1,4)=160;
ninoindex_lon(2,4)=-150;
ninoindex_lat(1,4)=-5;
ninoindex_lat(2,4)=5;


ind_nino12 =find(lon>ninoindex_lon(1,1)&lon<ninoindex_lon(2,1)& ...
                lat>ninoindex_lat(1,1)&lat<ninoindex_lat(2,1));
ind_nino3  =find(lon>ninoindex_lon(1,2)&lon<ninoindex_lon(2,2)& ...
                lat>ninoindex_lat(1,2)&lat<ninoindex_lat(2,2));
ind_nino34 =find(lon>ninoindex_lon(1,3)&lon<ninoindex_lon(2,3)& ...
                lat>ninoindex_lat(1,3)&lat<ninoindex_lat(2,3));

ind_nino4a =find(lon>ninoindex_lon(1,4)&lon< 180& ...
                lat>ninoindex_lat(1,4)&lat<ninoindex_lat(2,4));
ind_nino4b =find(lon<ninoindex_lon(2,4)&lon>=-180& ...
                lat>ninoindex_lat(1,4)&lat<ninoindex_lat(2,4));
ind_nino4  =[ind_nino4a;ind_nino4b];

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

IDIR=[IBAS filesep CNAM filesep];
ODIR='Data';

YEAR1OLD=varargin{1};
YEAR1=varargin{1+length(varargin)-2};
YEARN=varargin{2+length(varargin)-2};
mkdir(ODIR);
%

for year=YEAR1:YEARN
  yyyy=sprintf('%4.4i',year)
  for month=1:12
    mm=sprintf('%2.2i',month);
   
    n=((year-YEAR1)*12+month);
    FNAME_ocn=[IDIR 'ocn' filesep 'hist' filesep CNAM '.micom.hm.' yyyy '-' mm '.nc'];
    sst=ncread(FNAME_ocn,'sst');sst(isnan(sst))=0;
    SST(:,:,n)=sst;

    %
    sstareasub=sst(ind_nino12).*area(ind_nino12);
    areasub=area(ind_nino12);
    ind=find(~isnan(sstareasub));
    nino12(n)=sum(sstareasub(ind))/sum(areasub(ind));

    sstareasub=sst(ind_nino3).*area(ind_nino3);
    areasub=area(ind_nino3);
    ind=find(~isnan(sstareasub));
    nino3(n)=sum(sstareasub(ind))/sum(areasub(ind));

    sstareasub=sst(ind_nino34).*area(ind_nino34);
    areasub=area(ind_nino34);
    ind=find(~isnan(sstareasub));
    nino34(n)=sum(sstareasub(ind))/sum(areasub(ind));

    sstareasub=sst(ind_nino4).*area(ind_nino4);
    areasub=area(ind_nino4);
    ind=find(~isnan(sstareasub));
    nino4(n)=sum(sstareasub(ind))/sum(areasub(ind));

  end
end

year_list=YEAR1:YEARN;

% save index
save([ODIR filesep 'ninoindexes_' CNAM '_' sprintf('%4.4i',YEAR1OLD) '-' sprintf('%4.4i',YEARN) '.mat'],'-v7.3','nino12','nino3','nino34','nino4','year_list');

SST=single(SST);
save([ODIR filesep 'SST_comp_' CNAM '_' sprintf('%4.4i',YEAR1OLD) '-' sprintf('%4.4i',YEARN) '.mat'],'-v7.3','SST','year_list');
