clear all;close all;clc

bryfile = 'FC_bry_grd10_ZEROFLOW.nc';
grdfile = 'FLC_rossby_grd10_spong.nc';
inifile='FLC_rossby_v3_ini.nc';
ncload(bryfile);

addpath /WSmounts/phoddat/share/domingues/MYROMS/matlab_NEWROMS/utility

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ncgrd = netcdf(grdfile);
h2 = ncgrd{'h'}(:,:);
lon = ncgrd{'lon_rho'}(:,:);
lat = ncgrd{'lat_rho'}(:,:);

lonv = ncgrd{'lon_v'}(:,:);
latv = ncgrd{'lon_v'}(:,:);

mask_rho = ncgrd{'mask_rho'}(:,:);
close(ncgrd);

N=30;
Vtransform=2;
Vstretching=4;
theta_s=4;
theta_b=0;
Tcline=10;

[zt]=set_depth(Vtransform, Vstretching, theta_s, theta_b, Tcline, N, 1, h2);
[ztV]=set_depth(Vtransform, Vstretching, theta_s, theta_b, Tcline, N, 3, h2);
close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ncload(bryfile)

U_W = squeeze(u_west(1,:,:));
U_E = squeeze(u_east(1,:,:));
U_N = squeeze(u_north(1,:,:));
U_S = squeeze(u_south(1,:,:));

UBAR_W = squeeze(ubar_west(1,:));
UBAR_E = squeeze(ubar_east(1,:));
UBAR_N = squeeze(ubar_north(1,:));
UBAR_S = squeeze(ubar_south(1,:));

V_W = squeeze(v_west(1,:,:));
V_E = squeeze(v_east(1,:,:));
V_N = squeeze(v_north(1,:,:));
V_S = squeeze(v_south(1,:,:));

VBAR_W = squeeze(vbar_west(1,:));
VBAR_E = squeeze(vbar_east(1,:));
VBAR_N = squeeze(vbar_north(1,:));
VBAR_S = squeeze(vbar_south(1,:));

ZETA_E = squeeze(zeta_east(1,:));
ZETA_W = squeeze(zeta_west(1,:));
ZETA_N = squeeze(zeta_north(1,:));
ZETA_S = squeeze(zeta_south(1,:));

%  DO FOR TEMP AND SALT BASED ON INI CONDITIONS

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  close all

nc = netcdf(bryfile,'write');

%=================================================================================================
bry_time = nc{'bry_time'}(:)
bry_time = round(linspace(0,157680000,length(bry_time))) %5 years
%=================================================================================================
for t=1:length(bry_time)
t
	u_west(t,:,:) = zeros(size(U_W));
	u_east(t,:,:) = zeros(size(U_E));
	u_north(t,:,:) = zeros(size(U_N));
	u_south(t,:,:) = zeros(size(U_S));

	ubar_west(t,:) = zeros(size(UBAR_W));
	ubar_east(t,:) = zeros(size(UBAR_E));
	ubar_north(t,:) = zeros(size(UBAR_N));
	ubar_south(t,:) = zeros(size(UBAR_S));

	v_west(t,:,:) = zeros(size(V_W));
	v_east(t,:,:) = zeros(size(V_E));
	v_north(t,:,:) = zeros(size(V_N));
	v_south(t,:,:) = zeros(size(V_S));

	vbar_west(t,:) = zeros(size(VBAR_W));
	vbar_east(t,:) = zeros(size(VBAR_E));
	vbar_north(t,:) = zeros(size(VBAR_N));
	vbar_south(t,:) = zeros(size(VBAR_S));

	zeta_east(t,:) = zeros(size(ZETA_E));
	zeta_west(t,:) = zeros(size(ZETA_W));
	zeta_north(t,:) = zeros(size(ZETA_N));
	zeta_south(t,:) = zeros(size(ZETA_S));

end


NCWRITE=1;
if NCWRITE
	nc{'bry_time'}(:,:,:) = bry_time;

	nc{'u_west'}(:,:,:) = u_west;
	nc{'u_east'}(:,:,:) = u_east;
	nc{'u_south'}(:,:,:) = u_south;
	nc{'u_north'}(:,:,:) = u_north;

	nc{'ubar_west'}(:,:) = ubar_west;
	nc{'ubar_east'}(:,:) = ubar_east;
	nc{'ubar_south'}(:,:) = ubar_south;
	nc{'ubar_north'}(:,:) = ubar_north;

	nc{'v_west'}(:,:,:) = v_west;
	nc{'v_east'}(:,:,:) = v_east;
	nc{'v_south'}(:,:,:) = v_south;
	nc{'v_north'}(:,:,:) = v_north;

	nc{'vbar_west'}(:,:) = vbar_west;
	nc{'vbar_east'}(:,:) = vbar_east;
	nc{'vbar_south'}(:,:) = vbar_south;
	nc{'vbar_north'}(:,:) = vbar_north;


	nc{'zeta_east'}(:,:) = zeta_east;
	nc{'zeta_west'}(:,:) = zeta_west;
	nc{'zeta_south'}(:,:) = zeta_south;
	nc{'zeta_north'}(:,:) = zeta_north;

	result = sync(nc);


end
close(nc);
