      subroutine invert(lpri,lun11,lun,lun2,numrec,epi,ncn2)
c
c     this routine inverts the order
c     author:  T. Kallman
c
      implicit none
c
      include './PARAM'
      integer ll
c
      real epi(ncn)
c     line optical depths
      real tau0(2,nnnl)
c     continuum optical depths
      real dpthc(2,ncn)
      real tauc(2,nnml)
      integer lpri,lun11,lun,lun2,numrec,ncn2
      integer lprisv,nlyc,nry,nbinc,kk,kkm
      real t,r,rdel,xcol,xee,xpx,delr
c
      lprisv=lpri
c      lpri=0
      nlyc=nbinc(13.7,epi,ncn2)
      nry=nlyc+1
      if (lpri.ne.0)
     $ write (lun11,*)'in invert',lun,lun2,numrec
c
      rewind(lun2)
      do kk=1,numrec
        kkm=numrec+1-kk
        rewind(lun)
        do ll=1,kkm
          call unsavd(0,
     $       lpri,lun,lun11,
     $       t,r,rdel,delr,xcol,xee,xpx,
     $       tau0,dpthc,tauc,epi,ncn2)
          enddo
        if (lpri.ne.0)
     $   write (lun11,*)kk,r,t,rdel,kkm,dpthc(1,nry),dpthc(2,nry)
        call savd(0,
     $       lpri,lun2,lun11,
     $       t,r,rdel,delr,xcol,xee,xpx,
     $       tau0,dpthc,tauc)
        enddo
      lpri=lprisv
c
      return
      end
