! -------------------------------------------------------------- !
      subroutine mm_cdat_ms(msgtype,nproc,ms)
! -------------------------------------------------------------- !
! Purpose:  Self-consistent interation loop for mulit-
!           component plasmas
! -------------------------------------------------------------- !
      use gmm
      use communicate
      use ttime
      use stopwatch

      implicit none

      integer, intent(inout):: msgtype
      integer, intent(in):: nproc
      character(len=30),intent(in) :: ms

      integer :: who
      integer :: i
      integer :: info
      external fbuff

      iter = 1
      ilast = 0
      t =  r8_frm_p(1)
      dna = r8_frm_p(2)
      write(istdout,*) 't=',t
      write(istdout,*) 'dna=',dna
      dne = 0.0d0
      do i=0,nproc
         dne = dne+(dna*fracspec(i)) * zbarinit(i)
         fdna(i)=dna*fracspec(i)
      enddo
      do while(iter .le. maxiter) 
!g       write(istdout,*)'  '
!g       write(istdout,*)' --------------------------------------------'
!g       write(istdout,*)'  '
         iter=iter+1
         
         msgtype  = msgtype + 1
         call xx_sdat_c(msgtype)
         msgtype  = msgtype + 1
         call xx_rdat_c(msgtype)

         isumconvrg=0
         do i=0,nproc-1  ! iconvrg = 0-> not converg.; 1-> has converg.
           if( iconvrg(i).eq. 1 ) isumconvrg = isumconvrg + 1
         enddo
!g       write(istdout,*)' iter=',iter-1,' #species converted:',isumconvrg
!g       call fbuff ()
         if(ilast .eq. 0) then
           if(isumconvrg .eq. nproc) ilast = 1
         endif
!g       write(istdout,*)'ilast=',ilast
!g       call fbuff ()

! ---- Checking for last step of a self-consitant iteration: ilast=2

         if( ilast .eq. 2 ) then 
           if( itd .eq. 0) then ! time indep. case  (steady state)
             write(istdout,*)' --------------------------------------------'
             write(istdout,*)' Final interation reached steady state'
             write(istdout,*)' iter=',iter-1,' #species converted:',isumconvrg
             write(istdout,'(a4,1pe14.7)') ' ne=',dne
             call fbuff()
             r8_frm_c(1) = dne
!            if(iprt.eq.1) then 
!              call get_specinfo(msgtype)
!              call radtransport
!            endif
             goto 200
           endif !(itd.eq.1).or.(itd.eq.0)
         else ! (ilast .ne. 2)
!g         write(istdout,*)'slave self-consistent continue notice'
!g         call fbuff()
           msgtype = msgtype + 1
           call x_sflg_c(msgtype,ms,-1)
           dne = 0.0
           do i=0,nproc-1
             dne= dne+ dna*fracspec(i)*zbars(i)
           enddo
!g         write(istdout,'(a4,1pe14.7)') ' ne=',dne 
!g         call fbuff()
         endif 
         if(ilast .eq. 1) ilast = 2
      enddo !do while
200   continue
!g    write(istdout,'(a4,1pe14.7)') ' ne=',dne

!     call pvmfexit(info) 

      contains
! ------------------------------------------------------------------ !
      subroutine xx_sdat_c(msgtype)  !Internal subroutine p. 378
! ------------------------------------------------------------------ !
      integer :: msgtype

      call pk(t)
      call pk(dne)
      call pk(fdna,nproc)
      call destin(msgtype, ms)

!     write(istdout,'(a3,1pe14.7,a8,e14.7)') 'te=',t,' ne_int=',dne
!     write(istdout,'(a3,1pe14.7)') 'na=',dna
!     call fbuff() 
      end subroutine xx_sdat_c
! ----------------------------------------------------------- !
      subroutine xx_rdat_c(msgtype)  !Internal subroutine p. 378
! ----------------------------------------------------------- !
      integer :: msgtype
      do i=1,nproc
         call recv( msgtype )
         call upk( who )
         call upk( iconvrg(who) )
         call upk( iconsum(who) )
         call upk( nho(who) )
         call upk( zbars(who) )

!        write(istdout,*) 'proc.#=',who,' ',elmt((who*2+1): &
!    &           (who*2+2)),' zbar=',zbars(who)
!        write(istdout,*) ' number of levels converged=',   &
!    &           iconsum(who),' out of',nho(who)
!        call fbuff()
      enddo

      end subroutine xx_rdat_c

! ----------------------------------------------------------- !

      end subroutine mm_cdat_ms
