
! Written by Yun (Helen) He and Chris Ding, NERSC/LBNL.

      program main
      use MPH_module
      implicit none
      include 'mpif.h'

      integer CONTROL_World, COMM_cpl_ice
      integer myProc, myProc_global
      integer k, buf, totalbuf

      call MPH_debug (1)
      CONTROL_World = MPH_components(name1="POP_control")
      if (MPH_global_proc_id() == 0) call MPH_help ('on')
      write(*,*)'I am fine here after set_info'

      call MPI_COMM_RANK (CONTROL_World, myProc, ierr)
      call MPI_COMM_RANK (MPH_Global_World, myProc_global, ierr)
      write(*,*)'comp_name=', MPH_comp_name(), 'local_id=', myProc, 
     & ', global_id=', myProc_global
      write(*,*)'comp_id=', MPH_comp_id()
      write(*,*)'exe_id=', MPH_exe_id()
      write(*,*)'num_comps=', MPH_num_comps()

      call MPH_comm_join("coupler", "ice", COMM_cpl_ice) 

      totalbuf = 0
      write(*,*)'MPH_num_ensemble("POP")=',MPH_num_ensemble("POP")
      do k = 1, MPH_num_ensemble("POP")
         call MPI_RECV(buf, 1, MPI_INTEGER, MPI_ANY_SOURCE, 1000,
     &             MPH_Global_World, istatus, ierr)
         write(*,*)'buf=', buf
         totalbuf = totalbuf + buf
      enddo

      write(*,*)'totalbuf=', totalbuf
    
      call MPI_FINALIZE (ierr)
      end program
