clc;clear all;close all;

path_prefix = '/data3/yiwen/Timcom_exp/EXP_TIMCOM_renew/';

folder_names = {'test01_control/ice/',...
                'change_wind_shr_45/GTJRAv2.10/ice/hist/', ...
                'change_FWF_45/GTJRAv2.10/ice/hist/'};

% folder_names = {'test01_control/ice/',...
%                 'change_wind_shr_45/GTJRAv2.10/ice/hist/', ...
%                 'change_wind_shr_NS/GTJRAv2.10/ice/hist/',...
%                 'change_FWF_45/GTJRAv2.10/ice/hist/',...
%                 'change_FWF_NS/GTJRAv2.10/ice/hist/'};

file_template = 'GTJRAv2.10.cice.h.%04d-%02d.nc';

nyra_start = 346;nyra_end = 366;
nx = 320;ny = 288;
n_months = (nyra_end - nyra_start + 1) * 12;


U_vel = zeros(nx, ny, n_months, numel(folder_names));
V_vel = zeros(nx, ny, n_months, numel(folder_names));
AREA_TD = zeros(nx, ny, n_months, numel(folder_names));


for i_folder = 1:numel(folder_names)
    current_folder = folder_names{i_folder};
    for iyr = nyra_start:nyra_end
        for im = 1:12
            count = (iyr - nyra_start) * 12 + im;
            current_file = sprintf(file_template, iyr, im);
            full_path = [path_prefix current_folder current_file];
            
            uvel = ncread(full_path, 'uvel');
            vvel = ncread(full_path, 'vvel');
            area_td = ncread(full_path, 'daidtd');
            
            U_vel(:, :, count, i_folder) = uvel;
            V_vel(:, :, count, i_folder) = vvel;
            AREA_TD(:, :, count, i_folder) = area_td;
        end
    end
end


Uvel_mean = squeeze(nanmean(U_vel, 3));
Vvel_mean = squeeze(nanmean(V_vel, 3));
AREATD_mean = squeeze(nanmean(AREA_TD, 3));


%%
period = [nyra_start,nyra_end];
patho='/data3/yiwen/Timcom_exp/matlab_code/SIC_renew/';
fn2 = [patho 'SIC_V&F'];
save(fn2,'Uvel_mean','Vvel_mean','AREATD_mean','period')
     
     
     
     
     
