!===================================================
! DO NOT EDIT THIS FILE, it was generated using /mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/tools/cprnc/genf90/genf90.pl 
! Any changes you make to this file may be lost
!===================================================
#define __PIO_FILE__ "rearrange.F90"
!>
!! @file 
!! $Revision: 751 $
!! $LastChangedDate: 2013-04-02 12:01:13 -0400 (Tue, 02 Apr 2013) $
!! @brief Generic interface to the rearrange layer
!<

module rearrange

  use pio_kinds
  use pio_types
  use pio_support
  use box_rearrange


#ifdef TIMING
  use perf_mod, only : t_startf, t_stopf, t_barrierf     ! _EXTERNAL
#endif

  implicit none
  private
  save

!> 
!! @private
!<
  public :: rearrange_init, &
            rearrange_create, &
            rearrange_comp2io, &
            rearrange_io2comp, &
            rearrange_free

# 34 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  interface rearrange_init
    module procedure rearrange_init_
  end interface


# 39 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  interface rearrange_create
    module procedure rearrange_create_box_
  end interface

# 43 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  interface rearrange_comp2io
    ! TYPE real,double,int
    module procedure rearrange_comp2io_real
    ! TYPE real,double,int
    module procedure rearrange_comp2io_double
    ! TYPE real,double,int
    module procedure rearrange_comp2io_int
  end interface

# 48 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  interface rearrange_io2comp
    ! TYPE real,double,int
    module procedure rearrange_io2comp_real
    ! TYPE real,double,int
    module procedure rearrange_io2comp_double
    ! TYPE real,double,int
    module procedure rearrange_io2comp_int
  end interface

# 53 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  interface rearrange_free
    module procedure rearrange_free_
  end interface


# 58 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
contains

! TYPE real,double,int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_comp2io_real
!

# 66 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_comp2io_real(Iosystem,iodesc,compbuf,iobuf)
    implicit none

    type (Iosystem_desc_t) :: Iosystem
    type (io_desc_t)   :: iodesc
    real(r4), intent(in) ::  compbuf(:)
    real(r4), intent(out) :: iobuf(:)

#ifdef TIMING
    call t_barrierf("pio_rearrange_comp2io_real",IoSystem%comp_comm)
    call t_startf("pio_rearrange_comp2io_real")
#endif


    call box_rearrange_comp2io(Iosystem,iodesc,size(compbuf), compbuf,size(iobuf), iobuf)

#ifdef TIMING
    call t_stopf("pio_rearrange_comp2io_real")
#endif

# 86 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_comp2io_real
! TYPE real,double,int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_comp2io_double
!

# 66 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_comp2io_double(Iosystem,iodesc,compbuf,iobuf)
    implicit none

    type (Iosystem_desc_t) :: Iosystem
    type (io_desc_t)   :: iodesc
    real(r8), intent(in) ::  compbuf(:)
    real(r8), intent(out) :: iobuf(:)

#ifdef TIMING
    call t_barrierf("pio_rearrange_comp2io_double",IoSystem%comp_comm)
    call t_startf("pio_rearrange_comp2io_double")
#endif


    call box_rearrange_comp2io(Iosystem,iodesc,size(compbuf), compbuf,size(iobuf), iobuf)

#ifdef TIMING
    call t_stopf("pio_rearrange_comp2io_double")
#endif

# 86 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_comp2io_double
! TYPE real,double,int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_comp2io_int
!

# 66 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_comp2io_int(Iosystem,iodesc,compbuf,iobuf)
    implicit none

    type (Iosystem_desc_t) :: Iosystem
    type (io_desc_t)   :: iodesc
    integer(i4), intent(in) ::  compbuf(:)
    integer(i4), intent(out) :: iobuf(:)

#ifdef TIMING
    call t_barrierf("pio_rearrange_comp2io_int",IoSystem%comp_comm)
    call t_startf("pio_rearrange_comp2io_int")
#endif


    call box_rearrange_comp2io(Iosystem,iodesc,size(compbuf), compbuf,size(iobuf), iobuf)

#ifdef TIMING
    call t_stopf("pio_rearrange_comp2io_int")
#endif

# 86 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_comp2io_int




! TYPE real,double,int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_io2comp_real
!
# 96 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_io2comp_real (Iosystem,iodesc,iobuf,compbuf)
    implicit none

    type (Iosystem_desc_t) :: Iosystem
    type(io_desc_t) :: iodesc
    real(r4) :: iobuf(:)
    real(r4) ::  compbuf(:)

#ifdef TIMING
    call t_startf("pio_rearrange_io2comp_real")
#endif

    call box_rearrange_io2comp(Iosystem,iodesc,size(iobuf),iobuf,size(compbuf),compbuf)

#ifdef TIMING
    call t_stopf("pio_rearrange_io2comp_real")
#endif

# 114 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_io2comp_real
! TYPE real,double,int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_io2comp_double
!
# 96 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_io2comp_double (Iosystem,iodesc,iobuf,compbuf)
    implicit none

    type (Iosystem_desc_t) :: Iosystem
    type(io_desc_t) :: iodesc
    real(r8) :: iobuf(:)
    real(r8) ::  compbuf(:)

#ifdef TIMING
    call t_startf("pio_rearrange_io2comp_double")
#endif

    call box_rearrange_io2comp(Iosystem,iodesc,size(iobuf),iobuf,size(compbuf),compbuf)

#ifdef TIMING
    call t_stopf("pio_rearrange_io2comp_double")
#endif

# 114 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_io2comp_double
! TYPE real,double,int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_io2comp_int
!
# 96 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_io2comp_int (Iosystem,iodesc,iobuf,compbuf)
    implicit none

    type (Iosystem_desc_t) :: Iosystem
    type(io_desc_t) :: iodesc
    integer(i4) :: iobuf(:)
    integer(i4) ::  compbuf(:)

#ifdef TIMING
    call t_startf("pio_rearrange_io2comp_int")
#endif

    call box_rearrange_io2comp(Iosystem,iodesc,size(iobuf),iobuf,size(compbuf),compbuf)

#ifdef TIMING
    call t_stopf("pio_rearrange_io2comp_int")
#endif

# 114 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_io2comp_int


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_init
! 
! called from initFile_
!


# 125 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_init_(Iosystem)
    implicit none

    type (Iosystem_desc_t), intent(inout) :: Iosystem



        ! no general init required for box rearranger

# 134 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_init_

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
!  rearrange_create_box_
!
!  called from initDecomp
!


# 144 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_create_box_(Iosystem,compDOF, &
                               dims,ndims,ioDesc)
    implicit none

    type (Iosystem_desc_t), intent(in) :: Iosystem
    integer (kind=pio_offset), intent(in) :: compDOF(:)
    integer, intent(in) :: dims(:)
    integer, intent(in) :: ndims
    type (IO_desc_t) :: ioDesc
    
#ifdef TIMING
     call t_startf("pio_rearrange_create_box")
#endif

    if (Iosystem%rearr /= PIO_rearr_box) then
      call piodie( __PIO_FILE__,__LINE__, &
           'rearrange_create called with args for box but rearranger type is not box, Iosystem%rearr=',&
           Iosystem%rearr)
    endif


    call box_rearrange_create( Iosystem,compDOF,dims,ndims,Iosystem%num_iotasks,ioDesc)


#ifdef TIMING
     call t_stopf("pio_rearrange_create_box")
#endif

# 172 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_create_box_




!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! rearrange_free_
!
! called from freeDecomp


# 184 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  subroutine rearrange_free_(Iosystem,ioDesc)
    implicit none

    type (Iosystem_desc_t), intent(in) :: Iosystem
    type (IO_desc_t)                   :: ioDesc


    select case (Iosystem%rearr)
    case (PIO_rearr_box)
       call box_rearrange_free(Iosystem,ioDesc)
    case (PIO_rearr_none)
        ! do nothing 

    case default
       call piodie(__PIO_FILE__,__LINE__,'Unrecognized rearranger:',Iosystem%rearr)

    end select


# 203 "/mnt/cidstore1/models/ctrhodes/ctrhodes/CESM/cesm1_2_2/models/utils/pio/rearrange.F90.in"
  end subroutine rearrange_free_


end module rearrange
