clc;clear all;close all
filename='/work/yiwen89419/cesm_POP/OBS_data/OSNAP/OSNAP_MOC_MHT_MFT_TimeSeries_201408_202006_2023.nc' %monthly data
MOC_all=ncread(filename,'MOC_ALL');
MOC_east=ncread(filename,'MOC_EAST');
MOC_west=ncread(filename,'MOC_WEST');

time=ncread(filename,'TIME');
baseDate = datetime(1950, 1, 1);
finalDate = baseDate + days(time);  
disp(finalDate);


MOC={MOC_all MOC_east MOC_west}
OSNAP_year=cell(1,3);
for ii=1:3
 for it = 1:7 %2014:2020(yr)
 if it==1
   OSNAP_year{ii}(it)=nanmean(MOC{ii}((it-1)*12+1:(it-1)*12+5));
 elseif it==7
   OSNAP_year{ii}(it)=nanmean(MOC{ii}((it-1)*12-6:(it-1)*12-1));
 else        %1~12 month
   OSNAP_year{ii}(it)=nanmean(MOC{ii}((it)*12-18:(it)*12-7));   
 end
end
end

OSNAP_mon=MOC;
index={'MOC total','MOC east','MOC west'}

patho='/work/yiwen89419/cesm_POP/OBS_data/OSNAP/2020/'
readme = {['OBS AMOC at 53N'];
          ['year 2009-2020']
          ['-----------------------------------------------'];
          ['OBS_MOC_mon: unit:SV'];
          ['OBS_MOC_year: unit:SV'];
          ['-----------------------------------------------'];
          [''];};

fn21 = [patho 'OSNAP_2022.mat'];
save(fn21,'OSNAP_year','OSNAP_mon','index');





