module pio
  ! This module provides a stub implementation of a subset of PIO.
  !
  ! This can be used when you need the PIO interfaces in order for your unit tests to
  ! build, but do not actually need to make use of any of the PIO functionality in your
  ! unit tests.

  ! Note that not all PIO functionality is stubbed here. Stubs are written on an
  ! as-needed basis, and others can be added here as needed.

  ! Note about organization: variables, functions/subroutines, etc. should be kept in
  ! alphabetical order to facilitate finding what you want. Currently, this is roughly
  ! true, though is violated for specific routines within a group (e.g., implementations
  ! of the initdecomp interface).

  ! NOTE(wjs, 2015-01-12) In some routines here, variables that are declared as
  ! intent(out) in the real code are declared intent(inout) here. I am using intent(inout)
  ! because I do not want to bother with assigning a value to these, and some compilers
  ! complain if you don't assign a value to an intent(out) argument.


!  uses mpi if available
#ifndef NO_MPIMOD
   use mpi, only : MPI_OFFSET_KIND ! _EXTERNAL
#endif
   use iso_c_binding
  implicit none
  private

#ifdef NO_MPIMOD
   include 'mpif.h'   ! _EXTERNAL
#endif

  type, public :: file_desc_t
  end type file_desc_t

  type, public :: io_desc_t
  end type io_desc_t

  type, public :: iosystem_desc_t
  end type iosystem_desc_t

  type, public :: var_desc_t
  end type var_desc_t

   type, bind(c), public :: PIO_rearr_comm_fc_opt_t
      logical(c_bool) :: enable_hs            ! Enable handshake?
      logical(c_bool) :: enable_isend         ! Enable isends?
      integer(c_int) :: max_pend_req         ! Maximum pending requests
    end type PIO_rearr_comm_fc_opt_t

  type, public :: PIO_rearr_opt_t
      integer(c_int)                         :: comm_type
      integer(c_int)                         :: fcd       ! Flow control direction
      type(PIO_rearr_comm_fc_opt_t)   :: comm_fc_opts_comp2io
      type(PIO_rearr_comm_fc_opt_t)   :: comm_fc_opts_io2comp
  end type PIO_rearr_opt_t

  integer, parameter, private ::          &
       i4        = selected_int_kind(6)   ,&
       i8        = selected_int_kind(13)  ,&
       r4        = selected_real_kind(6)  ,&
       r8        = selected_real_kind(13)

  integer, parameter, public :: PIO_64BIT_OFFSET = 0
  integer, parameter, public :: PIO_64BIT_DATA = 0
  integer(i4), parameter, public :: PIO_BCAST_ERROR = 0
  integer, parameter, public :: PIO_CLOBBER = 0
  integer, parameter, public :: PIO_DOUBLE = 0
  integer, parameter, public :: PIO_GLOBAL = 0
  integer, parameter, public :: PIO_INT = 0
  integer(i4), parameter, public :: PIO_INTERNAL_ERROR = 0
  integer, parameter, public :: PIO_iotype_netcdf = 0
  integer, parameter, public :: PIO_iotype_netcdf4c = 0
  integer, parameter, public :: PIO_iotype_netcdf4p = 0
  integer, parameter, public :: PIO_iotype_pnetcdf = 0
  integer, parameter, public :: PIO_NOWRITE = 0
  integer, parameter, public :: pio_offset = MPI_OFFSET_KIND
  integer, parameter, public :: pio_offset_kind = pio_offset
  integer, parameter, public :: pio_rearr_subset = 0
  integer, parameter, public :: pio_rearr_box = 1
  integer, parameter, public :: PIO_WRITE = 0

  integer, parameter, public :: pio_rearr_comm_p2p = 0
  integer, parameter, public :: pio_rearr_comm_coll = 1
  integer,parameter,public :: PIO_rearr_comm_fc_2d_enable = 0
  integer,parameter,public :: PIO_rearr_comm_fc_1d_comp2io = 1
  integer,parameter,public :: PIO_rearr_comm_fc_1d_io2comp = 2
  integer,parameter,public :: PIO_rearr_comm_fc_2d_disable = 3
  integer, public, parameter :: PIO_REARR_COMM_UNLIMITED_PEND_REQ = -1
  integer, public, parameter :: PIO_NOERR=0

  public :: PIO_set_rearr_opts
  public :: PIO_def_dim
  public :: PIO_enddef
  public :: PIO_FILE_IS_OPEN
  public :: pio_inq_dimid
  public :: pio_inq_dimlen
  public :: pio_set_blocksize

  public :: PIO_closefile
  interface PIO_closefile
     module procedure closefile
  end interface PIO_closefile

  public :: PIO_createfile
  interface PIO_createfile
     module procedure createfile
  end interface

  public :: pio_def_var
  interface pio_def_var
     module procedure &
          def_var_0d, &
          def_var_md
  end interface

  public :: PIO_finalize
  interface PIO_finalize
     module procedure finalize
  end interface

  public :: PIO_freedecomp
  interface PIO_freedecomp
     module procedure freedecomp_ios
     module procedure freedecomp_file
  end interface

  public :: pio_get_att
  interface pio_get_att
     module procedure get_att_{TYPE}, get_att_desc_{TYPE}
     ! TYPE real,int,double
     module procedure get_att_1d_{TYPE}, get_att_desc_1d_{TYPE}
  end interface

  public :: pio_get_var
  interface pio_get_var
     module procedure get_var_{DIMS}d_{TYPE}, get_var_vdesc_{DIMS}d_{TYPE}
     !  DIMS 1,2,3,4,5
     module procedure get_vara_{DIMS}d_{TYPE}, get_vara_vdesc_{DIMS}d_{TYPE}
     module procedure get_var1_{TYPE}, get_var1_vdesc_{TYPE}
  end interface

  public :: PIO_init
  interface PIO_init
     module procedure init_intracom
     module procedure init_intercom
     module procedure init_intercom_from_comms
  end interface

  public :: PIO_initdecomp
  interface PIO_initdecomp
     module procedure PIO_initdecomp_dof_i4  ! previous name: initdecomop_1dof_nf_box
     module procedure PIO_initdecomp_dof_i8  ! previous name: initdecomop_1dof_nf_box
     module procedure PIO_initdecomp_dof_i8_vdc
     module procedure initdecomp_1dof_nf_i4
     module procedure initdecomp_1dof_nf_i8
     module procedure initdecomp_1dof_bin_i4
     module procedure initdecomp_1dof_bin_i8
     module procedure initdecomp_2dof_nf_i4
     module procedure initdecomp_2dof_nf_i8
     module procedure initdecomp_2dof_bin_i4
     module procedure initdecomp_2dof_bin_i8
     module procedure PIO_initdecomp_bc
     module procedure PIO_initdecomp_dof_dof
  end interface

  public :: pio_inq_varid
  interface pio_inq_varid
     module procedure inq_varid_vid, &
          inq_varid_vardesc
  end interface pio_inq_varid

  public :: PIO_openfile
  interface PIO_openfile
     module procedure PIO_openfile
  end interface

  public :: PIO_put_att
  interface PIO_put_att
     module procedure put_att_{TYPE}, put_att_desc_{TYPE}
     ! TYPE real,int,double
     module procedure put_att_1d_{TYPE}, put_att_desc_1d_{TYPE}
  end interface

  public :: pio_put_var
  interface pio_put_var
     !  DIMS 0,1,2,3,4,5
     module procedure put_var_{DIMS}d_{TYPE}, put_var_vdesc_{DIMS}d_{TYPE}
     !  DIMS 1,2,3,4,5
     module procedure put_vara_{DIMS}d_{TYPE}, put_vara_vdesc_{DIMS}d_{TYPE}
     module procedure put_var1_{TYPE}, put_var1_vdesc_{TYPE}
  end interface

  public :: PIO_read_darray
  interface PIO_read_darray
! TYPE real,int,double
! DIMS 1,2,3,4,5,6,7
     module procedure read_darray_{DIMS}d_{TYPE}
  end interface

  public :: pio_set_buffer_size_limit
  interface pio_set_buffer_size_limit
    module procedure pio_set_buffer_size_limit_i4
    module procedure pio_set_buffer_size_limit_i8
  end interface

  public :: PIO_setdebuglevel
  interface PIO_setdebuglevel
     module procedure setdebuglevel
  end interface PIO_setdebuglevel

  public :: PIO_seterrorhandling
  interface PIO_seterrorhandling
     module procedure seterrorhandlingf
     module procedure seterrorhandlingi
  end interface

  public :: PIO_write_darray
  interface PIO_write_darray
! TYPE real,int,double
! DIMS 1,2,3,4,5,6,7
     module procedure write_darray_{DIMS}d_{TYPE}
  end interface

contains

  subroutine closefile(file)
    type (file_desc_t),intent(inout)   :: file
  end subroutine closefile

  integer function createfile(iosystem, file,iotype, fname, amode_in) result(ierr)
    type (iosystem_desc_t), intent(inout), target :: iosystem
    type (file_desc_t), intent(inout) :: file
    integer, intent(in) :: iotype
    character(len=*), intent(in)  :: fname
    integer, optional, intent(in) :: amode_in

    ierr = 0
  end function createfile

  integer function def_var_0d(File,name,type,vardesc) result(ierr)

    type (File_desc_t), intent(in)  :: File
    character(len=*), intent(in)    :: name
    integer, intent(in)             :: type
    type (Var_desc_t), intent(inout) :: vardesc

    ierr = 0
  end function def_var_0d

  integer function def_var_md(File,name,type,dimids,vardesc) result(ierr)
    type (File_desc_t), intent(in)  :: File
    character(len=*), intent(in)    :: name
    integer, intent(in)             :: type
    integer, intent(in)             :: dimids(:)
    type (Var_desc_t), intent(inout) :: vardesc

    ierr = 0
  end function def_var_md

  subroutine finalize(iosystem,ierr)
     type (iosystem_desc_t), intent(inout) :: iosystem
     integer(i4), intent(out) :: ierr

     ierr = 0
   end subroutine finalize

  subroutine freedecomp_ios(ios,iodesc)
    type (iosystem_desc_t) :: ios
    type (io_desc_t) :: iodesc
  end subroutine freedecomp_ios

  subroutine freedecomp_file(file,iodesc)
    type (file_desc_t) :: file
    type (io_desc_t) :: iodesc
  end subroutine freedecomp_file

  integer function PIO_set_rearr_opts(iosystem, comm_type, fcd,&
                              enable_hs_c2i, enable_isend_c2i,&
                              max_pend_req_c2i,&
                              enable_hs_i2c, enable_isend_i2c,&
                              max_pend_req_i2c) result(ierr)
    type (iosystem_desc_t), intent(inout)  :: iosystem
    integer, intent(in) :: comm_type, fcd
    logical, intent(in) :: enable_hs_c2i, enable_hs_i2c
    logical, intent(in) :: enable_isend_c2i, enable_isend_i2c
    integer, intent(in) :: max_pend_req_c2i, max_pend_req_i2c
  end function PIO_set_rearr_opts

  integer function get_att_desc_{TYPE} (File,varDesc,name,value) result(ierr)
    type (File_desc_t), intent(inout) , target :: File
    type (VAR_desc_t), intent(in)     :: varDesc
    character(len=*), intent(in)      :: name
    {VTYPE}, intent(inout)      :: value

    ierr = 0
  end function get_att_desc_{TYPE}

! TYPE real,int,double
  integer function get_att_desc_1d_{TYPE} (File,varDesc,name,value) result(ierr)
    type (File_desc_t), intent(inout) , target :: File
    type (VAR_desc_t), intent(in)     :: varDesc
    character(len=*), intent(in)      :: name
    {VTYPE}, intent(inout)      :: value(:)

    ierr = 0
  end function get_att_desc_1d_{TYPE}

  integer function get_att_{TYPE} (File,varid,name,value) result(ierr)
    type (File_desc_t), intent(in) , target :: File
    integer(i4), intent(in)        :: varid
    character(len=*), intent(in)   :: name
    {VTYPE}, intent(inout)          :: value

    ierr = 0
  end function get_att_{TYPE}

! TYPE real,int,double
  integer function get_att_1d_{TYPE} (File,varid,name,value) result(ierr)
    type (File_desc_t), intent(in) , target :: File
    integer(i4), intent(in)        :: varid
    character(len=*), intent(in)   :: name
    {VTYPE}, intent(inout)          :: value(:)

    ierr = 0
  end function get_att_1d_{TYPE}

  integer function get_var1_{TYPE} (File,varid, index, ival) result(ierr)
    type (File_desc_t), intent(in) :: File
    integer, intent(in) :: varid, index(:)
    {VTYPE}, intent(inout) :: ival

    ierr = 0
  end function get_var1_{TYPE}

  integer function get_var1_vdesc_{TYPE} (File,vardesc, index, ival) result(ierr)
    type (File_desc_t), intent(in) :: File
    type(var_desc_t), intent(in) :: vardesc
    integer, intent(in) :: index(:)
    {VTYPE}, intent(inout) :: ival

    ierr = 0
  end function get_var1_vdesc_{TYPE}

! DIMS 1,2,3,4,5
  integer function get_vara_{DIMS}d_{TYPE} (File,varid, start, count, ival) result(ierr)
    type (File_desc_t), intent(in) :: File
    integer, intent(in) :: varid, start(:), count(:)
    {VTYPE}, intent(inout) :: ival{DIMSTR}

    ierr = 0
  end function get_vara_{DIMS}d_{TYPE}

! DIMS 1,2,3,4,5
  integer function get_vara_vdesc_{DIMS}d_{TYPE} (File,vardesc, start, count, ival) result(ierr)
    type (File_desc_t), intent(in) :: File
    type(var_desc_t), intent(in) :: vardesc
    integer, intent(in) :: start(:), count(:)
    {VTYPE}, intent(inout) :: ival{DIMSTR}

    ierr = 0
  end function get_vara_vdesc_{DIMS}d_{TYPE}

  integer function get_var_{DIMS}d_{TYPE} (File,varid, ival) result(ierr)
    type (File_desc_t), intent(in) :: File
    integer, intent(in) :: varid
    {VTYPE}, intent(inout) :: ival{DIMSTR}

    ierr = 0
  end function get_var_{DIMS}d_{TYPE}

  integer function get_var_vdesc_{DIMS}d_{TYPE} (File,vardesc, ival) result(ierr)
    type (File_desc_t), intent(in) :: File
    type(var_desc_t), intent(in) :: vardesc
    {VTYPE}, intent(inout) :: ival{DIMSTR}

    ierr = 0
  end function get_var_vdesc_{DIMS}d_{TYPE}

  subroutine init_intracom(comp_rank, comp_comm, num_iotasks, num_aggregator, stride,  rearr, iosystem,base, rearr_opts)

    integer(i4), intent(in) :: comp_rank
    integer(i4), intent(in) :: comp_comm
    integer(i4), intent(in) :: num_iotasks
    integer(i4), intent(in) :: num_aggregator
    integer(i4), intent(in) :: stride
    integer(i4), intent(in) :: rearr
    type (iosystem_desc_t), intent(out)  :: iosystem  ! io descriptor to initalize
    integer(i4), intent(in),optional :: base
    type (pio_rearr_opt_t), intent(in), optional :: rearr_opts

  end subroutine init_intracom

  subroutine init_intercom(component_count, peer_comm, comp_comms, io_comm, iosystem)
    integer, intent(in) :: component_count
    integer, intent(in) :: peer_comm
    integer, intent(in) :: comp_comms(component_count)   !  The compute communicator
    integer, intent(in) :: io_comm     !  The io communicator

    type (iosystem_desc_t), intent(out)  :: iosystem(component_count)  ! io descriptor to initalize
  end subroutine init_intercom

  subroutine init_intercom_from_comms(iosystem, world_comm, comp_comms, io_comm, rearranger)
    type(iosystem_desc_t), intent(out) :: iosystem(:)
    integer, intent(in) :: world_comm
    integer, intent(in) :: comp_comms(:)
    integer, intent(in) :: io_comm
    integer, intent(in) :: rearranger

  end subroutine init_intercom_from_comms

  subroutine PIO_initdecomp_bc(iosystem,basepiotype,dims,compstart,compcount,iodesc,iostart,iocount)
    type (iosystem_desc_t), intent(inout) :: iosystem
    integer(i4), intent(in)               :: basepiotype
    integer(i4), intent(in)               :: dims(:)
    integer (kind=PIO_OFFSET)             :: compstart(:)
    integer (kind=PIO_OFFSET)             :: compcount(:)
    type (IO_desc_t), intent(inout)         :: iodesc
    integer (kind=PIO_OFFSET),optional    :: iostart(:)
    integer (kind=PIO_OFFSET),optional    :: iocount(:)
  end subroutine PIO_initdecomp_bc

  subroutine PIO_initdecomp_dof_dof(iosystem,basepiotype,dims,compdof,iodesc,iodof)
    type (iosystem_desc_t), intent(inout)          :: iosystem
    integer(i4), intent(in)                        :: basepiotype
    integer(i4), intent(in)                        :: dims(:)
    integer(i4), intent(in)                        :: compdof(:)
    type (IO_desc_t), intent(inout)                   :: iodesc
    integer(i4), intent(in)                        :: iodof(:)
  end subroutine PIO_initdecomp_dof_dof

  subroutine initdecomp_2dof_bin_i4(iosystem,basepiotype,dims,lenblocks,compdof,iodofr,iodofw,iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in)          :: lenblocks
    integer (i4), intent(in)          :: compdof(:)   !> global degrees of freedom for computational decomposition
    integer (i4), intent(in)          :: iodofr(:)     !> global degrees of freedom for io decomposition
    integer (i4), intent(in)          :: iodofw(:)     !> global degrees of freedom for io decomposition
    type (io_desc_t), intent(inout)     :: iodesc
  end subroutine initdecomp_2dof_bin_i4

  subroutine initdecomp_2dof_bin_i8(iosystem,basepiotype,dims,lenblocks,compdof,iodofr,iodofw,iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in)          :: lenblocks
    integer (kind=pio_offset), intent(in)          :: compdof(:)   !> global degrees of freedom for computational decomposition
    integer (kind=pio_offset), intent(in)          :: iodofr(:)     !> global degrees of freedom for io decomposition
    integer (kind=pio_offset), intent(in)          :: iodofw(:)     !> global degrees of freedom for io decomposition
    type (io_desc_t), intent(inout)     :: iodesc
  end subroutine initdecomp_2dof_bin_i8

  subroutine initdecomp_1dof_bin_i8(iosystem,basepiotype,dims,lenblocks,compdof,iodofr,iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer(i4), intent(in)          :: lenblocks
    integer(kind=pio_offset), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer(kind=pio_offset), intent(in)          :: iodofr(:)     ! global degrees of freedom for io decomposition
    type (io_desc_t), intent(inout)     :: iodesc
  end subroutine initdecomp_1dof_bin_i8

  subroutine initdecomp_1dof_bin_i4(iosystem,basepiotype,dims,lenblocks,compdof,iodofr,iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in)          :: lenblocks
    integer (i4), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (i4), intent(in)          :: iodofr(:)     ! global degrees of freedom for io decomposition
    type (io_desc_t), intent(inout)     :: iodesc
  end subroutine initdecomp_1dof_bin_i4

  subroutine initdecomp_2dof_nf_i4(iosystem,basepiotype,dims,lenblocks,compdof,iodofr,iodofw,start, count, iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in)          :: lenblocks
    integer (i4), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (i4), intent(in)          :: iodofr(:)     ! global degrees of freedom for io decomposition
    integer (i4), intent(in)          :: iodofw(:)     ! global degrees of freedom for io decomposition

    type (io_desc_t), intent(inout)     :: iodesc

    integer(kind=PIO_offset), intent(in) :: start(:), count(:)
  end subroutine initdecomp_2dof_nf_i4

  subroutine initdecomp_2dof_nf_i8(iosystem,basepiotype,dims,lenblocks,compdof,iodofr,iodofw,start, count, iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in)          :: lenblocks
    integer (kind=pio_offset), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (kind=pio_offset), intent(in)          :: iodofr(:)     ! global degrees of freedom for io decomposition
    integer (kind=pio_offset), intent(in)          :: iodofw(:)     ! global degrees of freedom for io decomposition

    type (io_desc_t), intent(inout)     :: iodesc

    integer(kind=PIO_offset), intent(in) :: start(:), count(:)
  end subroutine initdecomp_2dof_nf_i8

  subroutine initdecomp_1dof_nf_i4(iosystem,basepiotype,dims,lenblocks,compdof,iodof,start, count, iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in) :: lenblocks
    integer (i4), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (i4), intent(in)          :: iodof(:)     ! global degrees of freedom for io decomposition
    type (io_desc_t), intent(inout)     :: iodesc
    integer :: piotype
    integer(kind=PIO_offset), intent(in) :: start(:), count(:)
  end subroutine initdecomp_1dof_nf_i4

  subroutine initdecomp_1dof_nf_i8(iosystem,basepiotype,dims,lenblocks,compdof,iodof,start, count, iodesc)
    type (iosystem_desc_t), intent(in) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (i4), intent(in) :: lenblocks
    integer (kind=pio_offset), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (kind=pio_offset), intent(in)          :: iodof(:)     ! global degrees of freedom for io decomposition
    type (io_desc_t), intent(inout)     :: iodesc
    integer :: piotype
    integer(kind=PIO_offset), intent(in) :: start(:), count(:)
  end subroutine initdecomp_1dof_nf_i8

  subroutine PIO_initdecomp_dof_i4(iosystem,basepiotype,dims,compdof, iodesc, iostart, iocount, num_ts, bsize, rearr)
    type (iosystem_desc_t), intent(inout) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (kind=PIO_offset), optional :: iostart(:), iocount(:)
    type (io_desc_t), intent(inout)     :: iodesc
    integer(i4), intent(in)           :: dims(:)
    integer, intent(in), optional :: rearr
    !vdf optionals
    integer(i4), intent(in), optional:: num_ts, bsize(3)
  end subroutine PIO_initdecomp_dof_i4

  subroutine PIO_initdecomp_dof_i8(iosystem,basepiotype,dims,compdof, iodesc, iostart, iocount, rearr)
    type (iosystem_desc_t), intent(inout) :: iosystem
    integer(i4), intent(in)           :: basepiotype
    integer(i4), intent(in)           :: dims(:)
    integer (kind=pio_offset), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition
    integer (kind=PIO_offset), optional :: iostart(:), iocount(:)
    type (io_desc_t), intent(inout)     :: iodesc
    integer, intent(in), optional :: rearr
  end subroutine PIO_initdecomp_dof_i8

  subroutine PIO_initdecomp_dof_i8_vdc(iosystem,dims,compdof, iodesc, num_ts, bsize)
    type (iosystem_desc_t), intent(inout) :: iosystem
    integer(i4), intent(in)           :: dims(:)
    integer (kind=pio_offset), intent(in)          :: compdof(:)   ! global degrees of freedom for computational decomposition

    type (io_desc_t), intent(inout)     :: iodesc
    !vdc args
    integer(i4), intent(in) :: num_ts
    integer(i4), intent(in), optional:: bsize(3)
  end subroutine PIO_initdecomp_dof_i8_vdc

  integer function inq_varid_vardesc(File,name,vardesc) result(ierr)

    type (File_desc_t), intent(in)   :: File
    character(len=*), intent(in)     :: name
    type (Var_desc_t), intent(inout) :: vardesc

    ierr = 0
  end function inq_varid_vardesc

  integer function inq_varid_vid(File,name,varid) result(ierr)

    type (File_desc_t), intent(in)   :: File
    character(len=*), intent(in)     :: name
    integer(i4), intent(out)       :: varid

    varid = 0
    ierr = 0
  end function inq_varid_vid


  integer function PIO_def_dim(File,name,len,dimid) result(ierr)

    type (File_desc_t), intent(in)  :: File
    character(len=*), intent(in)    :: name
    integer(i4), intent(in)         :: len
    integer(i4), intent(out)        :: dimid

    dimid = 0
    ierr = 0
  end function PIO_def_dim

  integer function PIO_enddef(File) result(ierr)
    type (File_desc_t), intent(inout) :: File

    ierr = 0
  end function PIO_enddef

  logical function PIO_FILE_IS_OPEN(File)
    type(file_desc_t), intent(in) :: file

    PIO_FILE_IS_OPEN = .false.
  end function PIO_FILE_IS_OPEN

  integer function pio_inq_dimid(File,name,dimid) result(ierr)

    type (File_desc_t), intent(in) :: File
    character(len=*), intent(in)   :: name
    integer, intent(out)           :: dimid        !dimension ID

    dimid = 0
    ierr = 0
  end function pio_inq_dimid

  integer function pio_inq_dimlen(File,dimid,dimlen) result(ierr)

    type (File_desc_t), intent(in) :: File
    integer(i4)     , intent(in)   :: dimid
    integer(i4)     , intent(out)  :: dimlen        !dimension name

    dimlen = 0
    ierr = 0
  end function pio_inq_dimlen

  integer function PIO_openfile(iosystem, file, iotype, fname,mode, CheckMPI) result(ierr)
    type (iosystem_desc_t), intent(inout), target :: iosystem
    type (file_desc_t), intent(out) :: file
    integer, intent(in) :: iotype
    character(len=*), intent(in)  :: fname
    integer, optional, intent(in) :: mode
    logical, optional, intent(in) :: CheckMPI

    ierr = 0
  end function PIO_openfile

  subroutine pio_set_blocksize(newsize)
    integer, intent(in) :: newsize
  end subroutine pio_set_blocksize

  subroutine pio_set_buffer_size_limit_i4(limit)
    integer, intent(in) :: limit
  end subroutine pio_set_buffer_size_limit_i4

  subroutine pio_set_buffer_size_limit_i8(limit)
    integer(pio_offset), intent(in) :: limit
  end subroutine pio_set_buffer_size_limit_i8

  integer function put_att_{TYPE} (File, varid, name, value) result(ierr)
    type (File_desc_t), intent(inout) , target :: File
    integer, intent(in) :: varid
    character(len=*), intent(in) :: name
    {VTYPE}, intent(in) :: value

    ierr = 0
  end function put_att_{TYPE}

! TYPE real,double,int
  integer function put_att_1d_{TYPE} (File, varid, name, value) result(ierr)
    type (File_desc_t), intent(inout) , target :: File
    integer, intent(in) :: varid
    character(len=*), intent(in) :: name
    {VTYPE}, intent(in) :: value(:)

    ierr = 0
  end function put_att_1d_{TYPE}

  integer function put_att_desc_{TYPE} (File,varDesc,name,value) result(ierr)
    type (File_desc_t), intent(inout) , target :: File
    type (VAR_desc_t), intent(in)     :: varDesc
    character(len=*), intent(in)      :: name
    {VTYPE}, intent(in)      :: value

    ierr = 0
  end function put_att_desc_{TYPE}

! TYPE real,int,double
  integer function put_att_desc_1d_{TYPE} (File,varDesc,name,value) result(ierr)
    type (File_desc_t), intent(inout) , target :: File
    type (VAR_desc_t), intent(in)     :: varDesc
    character(len=*), intent(in)      :: name
    {VTYPE}, intent(in)      :: value(:)

    ierr = 0
  end function put_att_desc_1d_{TYPE}

  integer function put_var1_text (File,varid, index, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid, index(:)
    character(len=*), intent(in) :: ival

    ierr = 0
  end function put_var1_text

! TYPE int,real,double
  integer function put_var1_{TYPE} (File,varid, index, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid, index(:)
    {VTYPE}, intent(in) :: ival

    ierr = 0
  end function put_var1_{TYPE}

  integer function put_var1_vdesc_{TYPE} (File,vardesc, start, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    type(var_desc_t), intent(in) :: vardesc
    integer, intent(in) ::  start(:)
    {VTYPE}, intent(in) :: ival

    ierr = 0
  end function put_var1_vdesc_{TYPE}

! DIMS 0,1,2,3,4,5
! TYPE text
  integer function put_var_{DIMS}d_text (File,varid, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid
    character(len=*), intent(in) :: ival{DIMSTR}

    ierr = 0
  end function put_var_{DIMS}d_text

! DIMS 1,2,3,4,5
! TYPE int,real,double
  integer function put_var_{DIMS}d_{TYPE} (File,varid, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid
    {VTYPE}, intent(in) :: ival{DIMSTR}

    ierr = 0
  end function put_var_{DIMS}d_{TYPE}

! TYPE int,real,double
  integer function put_var_0d_{TYPE} (File,varid, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid
    {VTYPE}, intent(in) :: ival

    ierr = 0
  end function put_var_0d_{TYPE}

! DIMS 0,1,2,3,4,5
  integer function put_var_vdesc_{DIMS}d_{TYPE} (File, vardesc, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    type(var_desc_t) , intent(in) :: vardesc
    {VTYPE}, intent(in) :: ival{DIMSTR}

    ierr = 0
  end function put_var_vdesc_{DIMS}d_{TYPE}

! DIMS 1,2,3,4,5
! TYPE text
  integer function put_vara_{DIMS}d_text (File,varid, start, count, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid, start(:), count(:)
    character(len=*), intent(in) :: ival{DIMSTR}

    ierr = 0
  end function put_vara_{DIMS}d_text

! TYPE int,real,double
! DIMS 1,2,3,4,5
  integer function put_vara_{DIMS}d_{TYPE} (File,varid, start, count, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    integer, intent(in) :: varid, start(:), count(:)
    {VTYPE}, intent(in) :: ival{DIMSTR}

    ierr = 0
  end function put_vara_{DIMS}d_{TYPE}

! DIMS 1,2,3,4,5
  integer function put_vara_vdesc_{DIMS}d_{TYPE} (File,vardesc, start, count, ival) result(ierr)
    type (File_desc_t), intent(inout) :: File
    type(var_desc_t), intent(in) :: vardesc
    integer, intent(in) ::  start(:), count(:)
    {VTYPE}, intent(in) :: ival{DIMSTR}

    ierr = 0
  end function put_vara_vdesc_{DIMS}d_{TYPE}

! TYPE real,int,double
  subroutine read_darray_1d_{TYPE} (File,varDesc, ioDesc, array, iostat)
    type (File_desc_t), intent(inout) :: &
         File                   ! file information

    type (var_desc_t), intent(inout) :: &
         varDesc                      ! variable descriptor

    type (io_desc_t), intent(inout) :: &
         ioDesc                      ! iodecomp descriptor

    {VTYPE}, dimension(:), intent(inout) ::  &
         array                 ! array to be read

    integer(i4), intent(out) :: iostat

    iostat = 0
  end subroutine read_darray_1d_{TYPE}

! TYPE real,int,double
! DIMS 2,3,4,5,6,7
  subroutine read_darray_{DIMS}d_{TYPE} (File,varDesc,ioDesc, array, iostat)
    type (File_desc_t), intent(inout) :: &
         File                   ! file information

    type (var_desc_t), intent(inout) :: &
         varDesc                      ! variable descriptor

    type (io_desc_t), intent(inout) :: &
         ioDesc                      ! iodecomp descriptor

    {VTYPE}, intent(inout) ::  array{DIMSTR}                 ! array to be read

    integer(i4), intent(out) :: iostat

    iostat = 0
  end subroutine read_darray_{DIMS}d_{TYPE}

  subroutine setdebuglevel(level)
    integer(i4), intent(in) :: level
  end subroutine setdebuglevel

  subroutine seterrorhandlingf(file, method)
    type(file_desc_t), intent(inout) :: file
    integer, intent(in) :: method
  end subroutine seterrorhandlingf

  subroutine seterrorhandlingi(ios, method)
    type(iosystem_desc_t), intent(inout) :: ios
    integer, intent(in) :: method
  end subroutine seterrorhandlingi

! TYPE real,int,double
  subroutine write_darray_1d_{TYPE} (File,varDesc,ioDesc, array, iostat, fillval)
    type (File_desc_t), intent(inout) :: &
         File                   ! file information

    type (var_desc_t), intent(inout) :: &
         varDesc                      ! variable descriptor

    type (io_desc_t), intent(inout) :: &
         ioDesc                      ! variable descriptor

    {VTYPE}, dimension(:), target, intent(in) ::  &
         array                 ! array to be written

    {VTYPE}, optional, intent(in) :: fillval    ! rearrange receiver fill value

    integer(i4), intent(out) :: iostat

    iostat = 0
  end subroutine write_darray_1d_{TYPE}

! TYPE real,int,double
! DIMS 2,3,4,5,6,7
  subroutine write_darray_{DIMS}d_{TYPE} (File,varDesc,ioDesc, array, iostat, fillval)
    type (File_desc_t), intent(inout) :: &
         File                   ! file information

    type (var_desc_t), intent(inout) :: &
         varDesc                      ! variable descriptor

    type (io_desc_t), intent(inout) :: &
         ioDesc                      ! variable descriptor

    {VTYPE}, intent(in) ::  &
         array{DIMSTR}                 ! array to be written

    {VTYPE}, optional, intent(in) :: fillval    ! rearrange receiver fill value

    integer(i4), intent(out) :: iostat

    iostat = 0
  end subroutine write_darray_{DIMS}d_{TYPE}

end module pio
