      program ddscat
      parameter (nwav=2, nscat=10)
      real data(nscat)
      complex cxdata(nscat)

       do 10 iwav=1, nwav
         do 20 iscat=1, nscat
          data(iscat)=iscat+(iwav-1)*10
          cxdata(iscat)=cmplx(iscat+(iwav-1)*10, iwav)
 20    continue
      call writessca(nwav, nscat, data, cxdata, cxdata,
     $       iwav,  idnc)
 10   continue

      print*, ' close ', idnc
      call ncclos(idnc, ierr)
      stop
      end

      subroutine writessca(nwav, nscat, data, 
     $         cxdata,  realcxdata, iwav,  idnc)
      include '/usr/local/netcdf-2.4.2/include/netcdf.inc'
      integer istart(7), icount(7), iddim(7)
      real data(nscat)
      complex cxdata(nscat)
      real realcxdata(2,nscat)

      data ientry/0/
      if(ientry.eq.0) then
          ientry=1
          idnc=nccre('test.cdf',ncclob,ierr)
C dimensions
          idnwav=ncddef(idnc,'nwav',nwav,ierr)
          idnscat=ncddef(idnc,'nscat',nscat,ierr)
          id2=ncddef(idnc,'two',2,ierr)
C variables
          iddim(1)=idnwav
          iddim(2)=idnscat
          iddata=ncvdef(idnc,'data',ncfloat,2,iddim,ierr)

          iddim(1)=id2
          iddim(2)=idnscat
          idre=ncvdef(idnc,'datare',ncfloat,2,iddim,ierr)
          call ncendf(idnc,ierr)
      endif

         istart(1)=iwav
         istart(2)=1
         icount(1)=1
         icount(2)=nscat

         print*, ' ncvpt ', istart(1), istart(2), icount(1), icount(2)
c         call ncvpt(idnc, iddata, istart, icount, data, ierr)
C try to dump complex (dump every other one) ??


         do 10 i=1, nscat
          print*, cxdata(i), realcxdata(1,i), realcxdata(2,i)
 10      continue

         istart(1)=1
         istart(2)=1
         icount(1)=2
         icount(2)=nscat
         call ncvpt(idnc, idre, istart, icount, cxdata, ierr)


      return
      end
