      subroutine dtailp(p_lvl, t_lvl,nval_obs, q0, q_a,
     1    rad_m0, kern_m0, krngr_mu, krncl_mu, sigmae,
     2    sigmaq, corrlen, tol_q, q, nval_s, nval,
     3    kern_s0, kern0, kern_s, kern, avkern, cov,
     4    wvl_c, sigma0, sigmaa, sigma, qtot0, qtot,
     5    res0, res, itrc)
c
c***********************************************************************
c
c     purpose
c        writes dtailed data records for profile
c
c     variables (converted to real*4 for output)
c       name        type   i/o  description
c       ----        ----   ---  -----------
c       p_lvl        r*4    i   81 pressure levels
c       t_lvl        r*4    i   81 level temperature profile
c       nval_obs     r*4    i   measured n-values at 10 profile channels
c       q0           r*4    i   81 layer first guess ozone profile
c       q_a          r*4    i   81 layer a priori ozone profile
c       rad_m0       r*4    i   msr radiance at 10 profile channels
c       kern_m0      r*4    i   msr kernel 10 channels by 80 layers
c       krngr_mu     r*4    i   msr kernel for clear 10 channels by 11 layers
c       krncl_mu     r*4    i   msr kernel for cloud 10 channels by 11 layers
c       sigmae       r*4    i   meas error covariance initialization param
c       sigmaq       r*4    i   a priori covariance initialization param
c       corrlen      r*4    i   correlation length of a priori covariance
c       tol_q        r*4    i   ozone interpolation tolerance value
c       q            r*4    i   81 layer solution ozone profile
c       nval_s       r*4    i   final ss n-value at 10 ozone profile chans
c       nval         r*4    i   final n-value at 10 ozone profile chans
c       kern_s0      r*4    i   initial ss kernel 10 channels by 80 layers
c       kern0        r*4    i   initial kernel 10 channels by 80 layers
c       kern_s       r*4    i   final ss kernel 10 channels by 80 layers
c       kern         r*4    i   final kernel 10 channels by 80 layers
c       avkern       r*4    i   final averaging kernel 80  by 80
c       cov          r*4    i   solution covariance matrix 80  by 80
c       wvl_c        r*4    i   wavelengths for 10 ozone profile channels
c       sigma0       r*4    i   first guess upper level scale height ratio
c       sigmaa       r*4    i   a priori guess upper level scale height ratio
c       sigma        r*4    i   solution upper level ozone scale height
c       qtot0        r*4    i   first guess total colum ozone
c       qtot         r*4    i   solution total colum ozone
c       res0         r*4    i   initial residues at 10 ozone profile chans
c       res          r*4    i   final residues at 10 ozone profile chans
c       itrc         r*4    i   number of iterations
c
c     calling routine  total
c
c******************************************************************
c
      implicit none
c
      include 'contrl.com'
      integer i,j,k,itrc
      real*4 buf(17505)
      real p_lvl(81), t_lvl(81), nval_obs(10), q0(81), q_a(81),
     1 rad_m0(10), kern_m0(10,80), krngr_mu(10,11), krncl_mu(10,11),
     2 sigmae, sigmaq, corrlen, tol_q, q(81), nval_s(10), nval(10),
     3 kern_s0(10,80), kern0(10,80), kern_s(10,80), kern(10,80),
     4 avkern(80,80), cov(80,80), wvl_c(10), sigma0, sigmaa,
     5 sigma, qtot0, qtot, res0(10), res(10)
c
      do i=1,81
        buf(i)=p_lvl(i)
        buf(i+81)=t_lvl(i)
        buf(i+172)=q0(i)
        buf(i+253)=q_a(i)
        buf(i+1368)=q(i)
      enddo
c
      do i=1,10
        buf(i+162)=nval_obs(i)
        buf(i+334)=rad_m0(i)
        buf(i+1449)=nval_s(i)
        buf(i+1459)=nval(i)
        buf(i+17469)=wvl_c(i)
        buf(i+17484)=res0(i)
        buf(i+17494)=res(i)
      enddo
c
      do j=1,11
        do i=1,10
          k=10*(j-1)+i
          buf(k+1144)=krngr_mu(i,j)
          buf(k+1254)=krncl_mu(i,j)
        enddo
      enddo
c
      do j=1,80
        do i=1,10
          k=10*(j-1)+i
          buf(k+344)=kern_m0(i,j)
          buf(k+1469)=kern_s0(i,j)
          buf(k+2269)=kern0(i,j)
          buf(k+3069)=kern_s(i,j)
          buf(k+3869)=kern(i,j)
        enddo
      enddo
c
      buf(1365)=sigmae
      buf(1366)=sigmaq
      buf(1367)=corrlen
      buf(1368)=tol_q
      buf(17480)=sigma0
      buf(17481)=sigmaa
      buf(17482)=sigma
      buf(17483)=qtot0
      buf(17484)=qtot
      buf(17505)=itrc
c
      do j=1,80
        do i=1,80
          k=80*(j-1)+i
          buf(k+4669)=avkern(i,j)
          buf(k+11069)=cov(i,j)
        enddo
      enddo
c
c     do i=1,13
c       buf(i+17359)=qu_a(i)
c       buf(i+17372)=tu_a(i)
c     enddo
c
      if(.not.iopts(3)) write(15) buf
c
      return
c
      end
