      subroutine WriteMax(ncid,MAX_id,npics,nvar,
     & maxVar,LON_len,LAT_len,nx,ny)
       
c.....netCDF id
      integer*4  ncid
c.....variable ids
      integer*4  MAX_id
c.....error status return
      integer*4  iret
c.....variable number: 1 - HA, 2 - UA, 3 - VA
      integer nvar
c.....netCDF dimension sizes for dimensions used with record variables
      integer*4  LON_len, LAT_len, nx, ny
      integer*4 npics
c.....data variables
      real*4 maxSub(LON_len, LAT_len)
      real*4 maxVar(nx, ny)

      include 'netcdf.inc'
      
c..... Sub-sample maxVar by npics for output
      jj=1
      do j=1,ny,npics
        ii=1
        do i=1,nx,npics
          if (ii.LE.LON_len.AND.jj.LE.LAT_len) then
            maxSub(ii,jj)=maxVar(i,j)
          end if
          ii=ii+1
        end do
        jj=jj+1
      end do
      
      iret = nf_put_var_real(ncid,MAX_id,maxSub)
      call check_err(iret)
      iret =  nf_sync(ncid)
      call check_err(iret)
      end
