!--------------------------------------- LICENCE BEGIN -----------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------


program main
   use pFUnit
   implicit none
   include "mpif.h"


   type (TestSuite_type) :: suite_master
   type (TestResult_type) :: result_master
   character(len=100) :: summary_statement_master
   integer :: myip, ierr
   external :: userinit_dummy
   integer :: petotal, pex, pey

   call pFUnit_init()
                                        ! Even though mpi_init() has already
                                        ! been called by pFUnit, rpn_comm must be
                                        ! initialized too.
   pex=2
   pey=1
   call rpn_comm_init(userinit_dummy, myip, petotal, pex, pey)
   write(*,*)"rpn_comm_init:  myip, petotal=", myip, petotal

   ! Build suite from test procedures:
   suite_master = TestSuite('Master suite')

   ! Run the tests and accumulate the results
   result_master = newTestResult(mode=MODE_USE_STDOUT+MODE_USE_LOGFILE)
   call Run(suite_master, result_master)

   ! Write the report
                                        ! Because rpn_comm may not be initialized
                                        ! address mpi_comm directly.
   call mpi_comm_rank(mpi_comm_world, myip, ierr)
   if(myip == 0) then
      ! Write only one report
      summary_statement_master=Summary(result_master)
      call sleep(1)                     ! Allow the write buffer to empty
      write(6,*)
      write(6,*)trim(summary_statement_master)
   end if

   call clean(result_master)
   call clean(suite_master)

   call pFUnit_finalize()
end program main




subroutine userinit_dummy(pex, pey)
   implicit none
   integer :: pex, pey
   pex = 0
   pey = 0
end subroutine userinit_dummy