subroutine EZspline_2NetCDF_array3(n1, n2, n3, x1, x2, x3, f, filename, ier)
  use iso_c_binding, only: fp => c_double
  use EZspline_obj   
  use EZcdf
  implicit none
  integer, intent(in) :: n1, n2, n3
  real(fp), intent(in) :: x1(:), x2(:), x3(:), f(:, :, :)
  character(len=*), intent(in) :: filename
  integer, intent(out) :: ier
  integer ifail

  integer dimlens(3), ncid

  ier = 0
  call cdfOpn(ncid, filename, 'w')
  if(ncid==0) then
     ier = 34
     return
  end if
  dimlens = (/ 1, 1, 1 /)
  call cdfDefVar(ncid, 'n1', dimlens, 'INT', ifail)
  call cdfDefVar(ncid, 'n2', dimlens, 'INT', ifail)
  call cdfDefVar(ncid, 'n3', dimlens, 'INT', ifail)
  dimlens = (/ n1, 1, 1 /)
  call cdfDefVar(ncid, 'x1', dimlens, 'R8', ifail)
  dimlens = (/ n2, 1, 1 /)
  call cdfDefVar(ncid, 'x2', dimlens, 'R8', ifail)
  dimlens = (/ n3, 1, 1 /)
  call cdfDefVar(ncid, 'x3', dimlens, 'R8', ifail)
  dimlens = (/ n1, n2, n3 /)
  call cdfDefVar(ncid, 'f', dimlens, 'R8', ifail)
  if(ifail/=0) then
     ier = 38 
     return
  end if
  call cdfPutVar(ncid, 'n1', n1, ifail)
  call cdfPutVar(ncid, 'n2', n2, ifail)
  call cdfPutVar(ncid, 'n3', n3, ifail)
  call cdfPutVar(ncid, 'x1', x1, ifail)
  call cdfPutVar(ncid, 'x2', x2, ifail)
  call cdfPutVar(ncid, 'x3', x3, ifail)
  call cdfPutVar(ncid, 'f', f, ifail)
  if(ifail/=0) then
     ier = 35 
     return
  end if

  call cdfCls(ncid)

end subroutine EZspline_2NetCDF_array3

subroutine EZspline_2NetCDF_array2(n1, n2, x1, x2, f, filename, ier)
  use EZspline_obj   
  use EZcdf
  implicit none
  integer, intent(in) :: n1, n2
  real(fp), intent(in) :: x1(:), x2(:), f(:,:)
  character(len=*), intent(in) :: filename
  integer, intent(out) :: ier
  integer ifail

  integer dimlens(3), ncid

  ier = 0
  call cdfOpn(ncid, filename, 'w')
  if(ncid==0) then
     ier = 34
     return
  end if
  dimlens = (/ 1, 1, 1 /)
  call cdfDefVar(ncid, 'n1', dimlens, 'INT', ifail)
  call cdfDefVar(ncid, 'n2', dimlens, 'INT', ifail)
  dimlens = (/ n1, 1, 1 /)
  call cdfDefVar(ncid, 'x1', dimlens, 'R8', ifail)
  dimlens = (/ n2, 1, 1 /)
  call cdfDefVar(ncid, 'x2', dimlens, 'R8', ifail)
  dimlens = (/ n1, n2, 1 /)
  call cdfDefVar(ncid, 'f', dimlens, 'R8', ifail)
  if(ifail/=0) then
     ier = 38 
     return
  end if

  call cdfPutVar(ncid, 'n1', n1, ifail)
  call cdfPutVar(ncid, 'n2', n2, ifail)
  call cdfPutVar(ncid, 'x1', x1, ifail)
  call cdfPutVar(ncid, 'x2', x2, ifail)
  call cdfPutVar(ncid, 'f', f, ifail)
  if(ifail/=0) then
     ier = 35 
     return
  end if

  call cdfCls(ncid)

end subroutine EZspline_2NetCDF_array2

subroutine EZspline_2NetCDF1(n1, x1, f, filename, ier)
  use EZspline_obj   
  use EZcdf
  implicit none
  integer, intent(in) :: n1
  real(fp), intent(in) :: x1(:), f(:)
  character(len=*), intent(in) :: filename
  integer, intent(out) :: ier
  integer ifail

  integer dimlens(3), ncid

  ier = 0
  call cdfOpn(ncid, filename, 'w')
  if(ncid==0) then
     ier = 34
     return
  end if
  dimlens = (/ 1, 1, 1 /)
  call cdfDefVar(ncid, 'n1', dimlens, 'INT', ifail)
  dimlens = (/ n1, 1, 1 /)
  call cdfDefVar(ncid, 'x1', dimlens, 'R8', ifail)
  dimlens = (/ n1, 1, 1 /)
  call cdfDefVar(ncid, 'f', dimlens, 'R8', ifail)
  if(ifail/=0) then
     ier = 38 
     return
  end if

  call cdfPutVar(ncid, 'n1', n1, ifail)
  call cdfPutVar(ncid, 'x1', x1, ifail)
  call cdfPutVar(ncid, 'f', f, ifail)
  if(ifail/=0) then
     ier = 35 
     return
  end if

  call cdfCls(ncid)

end subroutine EZspline_2NetCDF1

subroutine EZspline_2NetCDF_cloud3(n, x1, x2, x3, f, filename, ier)
  use EZspline_obj   
  use EZcdf
  implicit none
  integer, intent(in) :: n
  real(fp), intent(in) :: x1(:), x2(:), x3(:), f(:)
  character(len=*), intent(in) :: filename
  integer, intent(out) :: ier
  integer ifail

  integer dimlens(3), ncid

  ier = 0
  call cdfOpn(ncid, filename, 'w')
  if(ncid==0) then
     ier = 34
     return
  end if
  dimlens = (/ 1, 1, 1 /)
  call cdfDefVar(ncid, 'n', dimlens, 'INT', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'x1', dimlens, 'R8', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'x2', dimlens, 'R8', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'x3', dimlens, 'R8', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'f', dimlens, 'R8', ifail)
  if(ifail/=0) then
     ier = 38 
     return
  end if

  call cdfPutVar(ncid, 'n', n, ifail)
  call cdfPutVar(ncid, 'x1', x1, ifail)
  call cdfPutVar(ncid, 'x2', x2, ifail)
  call cdfPutVar(ncid, 'x3', x3, ifail)
  call cdfPutVar(ncid, 'f', f, ifail)
  if(ifail/=0) then
     ier = 35 
     return
  end if

  call cdfCls(ncid)

end subroutine EZspline_2NetCDF_cloud3

subroutine EZspline_2NetCDF_cloud2(n, x1, x2, f, filename, ier)
  use EZspline_obj   
  use EZcdf
  implicit none
  integer, intent(in) :: n
  real(fp), intent(in) :: x1(:), x2(:), f(:)
  character(len=*), intent(in) :: filename
  integer, intent(out) :: ier
  integer ifail

  integer dimlens(3), ncid

  ier = 0
  call cdfOpn(ncid, filename, 'w')
  if(ncid==0) then
     ier = 34
     return
  end if
  dimlens = (/ 1, 1, 1 /)
  call cdfDefVar(ncid, 'n', dimlens, 'INT', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'x1', dimlens, 'R8', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'x2', dimlens, 'R8', ifail)
  dimlens = (/ n, 1, 1 /)
  call cdfDefVar(ncid, 'f', dimlens, 'R8', ifail)
  if(ifail/=0) then
     ier = 38 
     return
  end if

  call cdfPutVar(ncid, 'n', n, ifail)
  call cdfPutVar(ncid, 'x1', x1, ifail)
  call cdfPutVar(ncid, 'x2', x2, ifail)
  call cdfPutVar(ncid, 'f', f, ifail)
  if(ifail/=0) then
     ier = 35 
     return
  end if

  call cdfCls(ncid)

end subroutine EZspline_2NetCDF_cloud2
