function fldOut=aste_uv_hconv(u_aste,v_aste,dxg,dyg,nfx,nfy)
%--------------------------------------------------
% function fldOut=calc_UV_conv_1face(u_aste,v_aste,dxg,dyg,nfx,nfy)
% Input: 
% [u,v]_aste: u and v at mitgcm C-grid points [East,South] , compact format size 270 x 1350 x nz x nt
% [dxg,dyg] : these are DXG,DYG, compact format size 270x1350
% [nfx,nfy] : dimensions in x and y of the 5 faces
%
% Output:
%  fldOut: convergence field (scalar), 5 faces, unit m2/s (the z-dim drF is not (yet) applied)
%        {1} [270 x 450 x nz x nt]
%        {2} [  0 x   0          ]
%        {3} [270 x 270 x nz x nt]
%        {4} [180 x 270 x nz x nt]
%        {5} [450 x 270 x nz x nt]
%
% atn 17/Mar/2019, copy from Gael Forget gcmfaces calc_UV_conv.m
%     02/Nov/2020, modified to enabble 4th dimension
%--------------------------------------------------

%check size
su=size(u_aste);
sv=size(v_aste);
if(su(1)~=sv(1)|sv(2)~=sv(2));error('size u_aste and v_aste inconsistent and need to be the same');end;

nz=1;nt=1;
if(length(su)>=3);nz=su(3);if(length(su)==4);nt=su(4);end;end;

%first make u*dyG and v*dxG , unit [m/s * m = m2/s]
u_aste=u_aste.*dyg;
v_aste=v_aste.*dxg;
%next add padding, outputs are now 5 faces
[up,vp]=aste_uv_addpadding(u_aste,v_aste,nfx,nfy);

%now looping through 5 faces to compute du*dyG plus dv*dxG, convergence = INTO the grid
fldOut=[];
for iface=1:5;
  dudx=[];
  dvdy=[];
  if(sum(nfx(iface)+nfy(iface))>0);
    dudx(1:nfx(iface),1:nfy(iface),1:nz,1:nt) = ...
      ( up{iface}(1:nfx(iface),:,1:nz,1:nt) - up{iface}(2:nfx(iface)+1,:,1:nz,1:nt) );
    dvdy(1:nfx(iface),1:nfy(iface),1:nz,1:nt) = ...
      ( vp{iface}(:,1:nfy(iface),1:nz,1:nt) - vp{iface}(:,2:nfy(iface)+1,1:nz,1:nt) );
  end;
  fldOut{iface}=dudx+dvdy;
end;

return
