      integer function CheckVar(fname,ncid,varName,varid)
          
      integer*4 ncid, varid, iret, ndims,nvars,n3,n4
      character*2 varName,lowName,d2
      character*80 dumb
      character*(*) fname

      include 'netcdf.inc'

c     assumes 1st 2 characters can be used to select correct variable
c     checks upper(passed) & lower case variations of 2 characters

      CheckVar = 0
      iret = nf_open(fname,0,ncid)
      if (iret .ne. NF_NOERR) then
          write(3,*) nf_strerror(iret)
          write(3,*) 'ERROR: file not found:',fname
          return
      end if
      call check_err(nf_inq(ncid,ndims,nvars,n3,n4))
c      write(3,'("nf_inq(",5i3,")")') ncid,ndims,nvars,n3,n4
      call to_lower(varName,lowName)
c      write(3,*) ' to_lower(',varName,',',lowName,')'
      do i=1, nvars
        call check_err(nf_inq_varname(ncid,i,dumb))
c        write(3,*) 'nf_inq_varname(',ncid,i,dumb(1:lnblnk(dumb)),')'
        d2 = dumb(1:2)
        if ((d2 .eq. varName) .or. (d2 .eq. lowName)) then
          call check_err(nf_inq_varid(ncid,dumb(1:lnblnk(dumb)),
     &                   varid))
          CheckVar = CheckVar+1
c          write(3,*) '         ',varName,'/',lowNAME,
c     &               ' variable id:',i,' name: ',dumb(1:lnblnk(dumb))
        endif
      end do
      if(CheckVar .eq. 0) then
          write(3,*) 'ERROR: IC source file has no ',varName,'/',
     &                lowNAME,' variable'
      else if(CheckVar .gt. 1) then
          write(3,*) 'ERROR: IC source file has',CheckVar,' ',varName,
     &               '/',lowNAME,' variables ** may have selected WRONG'
     &               ,' variable'
      endif      
      end
