      subroutine copy_profile(qmix,z,ml,nl,idg,ng,id_in, ml_out,
     &      output)
      implicit none
cccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      integer*4  ml, nl, idg, ng, id_in, ml_out
      real*4 qmix, output,z

      dimension qmix(ml,ng), output(ml_out), idg(ng),z(ml)
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      integer i,j
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      if( nl .gt. ml_out) stop 'copy_profile: dimension error'

      do i=1,ng
        if(idg(i) .eq. id_in) then
           do j=1,nl
              output(j) = qmix(j,i)
c              print*,output(j), z(j)
           enddo
c          stop
c            print*,'&'
           return
        endif
      enddo
      print*,'copy_profile: id ',id_in, 'not found' 
      return
      end
