*-----------------------------------------------------------------------
*     VARIABLES
*-----------------------------------------------------------------------
      subroutine nxvdef(ncdfid,cvstrc,cvtype)

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

      character cvstrc*(*),cvtype*(*)

      parameter (maxtyp=4)

      integer   ivtypz(maxtyp),ndimid(MAXVDIMS)
      character cvtypz(maxtyp)*1

      data      ivtypz/   NCCHAR,   NCLONG,  NCFLOAT, NCDOUBLE /
      data      cvtypz/      'c',      'i',      'r',      'd' /


      lencvs=lenc(cvstrc)
      idxlft=indxcf(cvstrc,lencvs,1,'(')
      idxrgt=indxcf(cvstrc,lencvs,1,')')
      ncomma=nindxc(cvstrc,lencvs,1,',')

      ivtype=ivtypz(indxmf(cvtypz,maxtyp,1,cvtype(1:1)))
      if (ivtype.eq.0)
     +     call msgdmp('e','nxvdef',
     +     'data type should be "c", "i", "r" or "d".')

      if (idxlft.eq.0 .and. idxrgt.eq.0) then
        idxcvn=lencvs
        nvdims=0
      else if (1.lt.idxlft .and. idxlft.lt.idxrgt) then
        idxcvn=idxlft-1
        nvdims=ncomma+1
        idxfst=idxlft+1
        do 10 n=1,nvdims
          lenchk=lencvs-idxfst+1
          if (n.ne.nvdims) then
            idxlst=indxcf(cvstrc(idxfst:lencvs),lenchk,1,',')+idxfst-2
          else
            idxlst=idxrgt-1
          end if
          ndimid(n)=ncdid(ncdfid,cvstrc(idxfst:idxlst),ircode)
          if (ircode.ne.0) call msgdmp('e','nxvdef','error in ncdid.')
          idxfst=idxlst+2
   10   continue
      else
        call msgdmp('e','nxvdef','variable structure is inconsistent.')
      end if

      nvarid=ncvdef(ncdfid,cvstrc(1:idxcvn),ivtype,nvdims,ndimid,ircode)
      if (ircode.ne.0) call msgdmp('e','nxvdef','error in ncvdef.')

      end
