clc;clear all;close all
%--- daily data ----%
file='/data3/yiwen/cesm2/OBS_data/MOVE/2022/OS_MOVE_TRANSPORTS.nc' 
MOVE=ncread(file,'TRANSPORT_TOTAL');
time=ncread(file,'TIME');
baseDate = datetime(1950, 1, 1);
finalDate = baseDate + days(time);  % 將天數加到基準日期上
disp(finalDate)

%----- 2000~2018 yrs -----%
year_start = 2000;
year_end = 2022;

mon_days  = [31,28,31,30,31,30,31,31,30,31,30,31];
mon_days2 = [31,29,31,30,31,30,31,31,30,31,30,31];

years = year_start:year_end;

OBS_MOC_mon = [];
OBS_MOC_year = [];

countm = 0;
countmdays = 0;
countydays = 0;

for iyr = 1:length(years)
    % 判断是否为闰年
    if mod(years(iyr), 4) == 0 && (mod(years(iyr), 100) ~= 0 || mod(years(iyr), 400) == 0)
        days = mon_days2;
    else
        days = mon_days;
    end
    
    if years(iyr) == 2022
        ms = 1; me = 6;  % 到2018年6月
        totaldays = sum(days(ms:me));
    else
        ms = 1; me = 12;
        totaldays = sum(days(ms:me));
    end
    
    for im = ms:me
        countm = countm + 1;
        tempA = MOVE(countmdays+1:countmdays+days(im));
        
        MOVE_mon(countm) = mean(tempA(~isnan(tempA)));
        countmdays = countmdays + days(im);
    end
    
    tempA = MOVE(countydays+1:countydays+totaldays);
    MOVE_year(iyr) = mean(tempA(~isnan(tempA)));
    countydays = countydays + totaldays;
end

%
%patho='/work/yiwen89419/cesm_POP/OBS_data/MOVE/2018/'
patho='/work/yiwen89419/cesm_POP/OBS_data/MOVE/2022/'

readme = {['OBS AMOC at 16N'];
          ['year 2000-2022']
          ['-----------------------------------------------'];
          ['OBS_MOC_mon: unit:SV'];
          ['OBS_MOC_year: unit:SV'];
          ['-----------------------------------------------'];
          [''];};

fn21 = [patho 'MOVE_2022.mat'];
save(fn21,'MOVE_mon','MOVE_year');



























