*-----------------------------------------------------------------------
      subroutine nxaptc(ncdfid,caname,catype,naclen,cvalue)

      include   '/usr/local/include/netcdf.inc'

      character caname*(*),cvalue*(*),catype*(*)

      parameter (maxtyp=4)

      integer   iatypz(maxtyp)
      character catypz(maxtyp)*1,cvtemp*(MAXNCNAM)

      data      iatypz/   NCCHAR,   NCLONG,  NCFLOAT, NCDOUBLE /
      data      catypz/      'c',      'i',      'r',      'd' /


      lencan=lenc(caname)
      lencva=lenc(cvalue)
      idxcol=indxcf(caname,lencan,1,':')

      idxtyp=indxmf(catypz,maxtyp,1,catype(1:1))
      if (idxtyp.ne.1)
     +     call msgdmp('e','nxaptc',
     +     'data type should be "c".')
      iatype=iatypz(idxtyp)

      if (idxcol.eq.1) then
        nvarid=NCGLOBAL
      else if (idxcol.gt.1) then
        nvarid=ncvid(ncdfid,caname(1:idxcol-1),ircode)
        if (ircode.ne.0) call msgdmp('e','nxaptc','error in ncvid.')
      else
        call msgdmp('e','nxaptc','attribute name is inconsistent.')
      end if

      call ncaptc(ncdfid,nvarid,caname(idxcol+1:lencan),
     +     iatype,naclen,cvalue,ircode)
      if (ircode.ne.0) call msgdmp('e','nxaptc','error in ncapt.')

      end
