*-----------------------------------------------------------------------
*     ATTRIBUTE
*-----------------------------------------------------------------------
      subroutine nxaptx(ncdfid,caname,catype,naxlen,values)

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

      real      values(*)
      character caname*(*),catype*(*)

      parameter (maxtyp=4)

      integer   iatypz(maxtyp)
      character catypz(maxtyp)*1

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


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

      idxtyp=indxmf(catypz,maxtyp,1,catype(1:1))
      if (idxtyp.lt.2)
     +     call msgdmp('e','nxaptx',
     +     'data type should be "i", "r" or "d".')
      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','nxaptx','error in ncvid.')
      else
        call msgdmp('e','nxaptx','attribute name is inconsistent.')
      end if

      call ncapt(ncdfid,nvarid,caname(idxcol+1:lencan),
     +     iatype,naxlen,values,ircode)
      if (ircode.ne.0) call msgdmp('e','nxaptx','error in ncapt.')

      end
