      program test1
      implicit none
      include '/home/A11D/scott/avs/netcdf-3.4/src/fortran/netcdf.inc'
      integer ndims,times,lats,lons
      parameter (ndims=3)
      parameter (times=17,lats=17,lons=17)
      integer status, ncid, times
      integer rhid
      integer start(ndims),count(ndims)
      real*8   rhsvals(lons,lats,times),rhsvals2(lons,lats,times)
      integer  rhsdim(3)
      integer start,count
      data start /1,1,1/
      data count /lons,lats,times/
      integer ilon,ilat,itme
      integer latid, lonsid, timesid
      integer lens1,lens2,lens3
      
      write(6,*) 'creating'
      status = nf_create('foo.nc',nf_noclobber,ncid)
      if (status.ne.nf_noerr)  call error('error1',status)
      status = nf_def_dim(ncid,'lat',lats,latid)
      if  (status.ne.nf_noerr) call error('error2a',status)
      status = nf_def_dim(ncid,'lons',lons,lonsid)
      if  (status.ne.nf_noerr) call error('error2b',status)
      status = nf_def_dim(ncid,'times',times,timesid)
      if  (status.ne.nf_noerr) call error('error2c',status)
      write(6,*) 'Writing dimensions=',lats,lons,times
      rhsdim(1) = latid
      rhsdim(2) = lonsid
      rhsdim(3) = timesid
      status = nf_def_var(ncid,'rh',nf_double,3,rhsdim,rhid)
      if  (status.ne.nf_noerr) call error('error2d',status)
      status = nf_enddef(ncid)
      do ilon = 1 , lons
         do ilat = 1 , lats
            do itme = 1 ,times
               rhsvals(ilon,ilat,itme) = itme+(ilat-1)*times +
     *              (ilon-1)*lats
            end do
         end do
      end do
      status = nf_put_var_double(ncid,rhid,rhsvals)
      if (status.ne.nf_noerr) call error('error3',status)
      status = nf_close (ncid)
      if (status.ne.nf_noerr) call error('closing',status)
      latid = 0
      lonsid = 0
      timesid = 0
      write(6,*) 'now opening the file'
      status = nf_open('foo.nc',0,ncid)
      if (status.ne.nf_noerr) call error('error4',status)
      status = nf_inq_dimid(ncid,'lat',latid)
      if (status.ne.nf_noerr) call error('error5',status)
      status = nf_inq_dimid(ncid,'lons',lonsid)
      if (status.ne.nf_noerr) call error('error6',status)
      status = nf_inq_dimid(ncid,'times',timesid)
      if (status.ne.nf_noerr) call error('error7',status)
      write(6,*) 'size=',latid,lonsid,timesid,'=====',rhsdim(1),
     *     rhsdim(2),rhsdim(3)
      status = nf_inq_varid(ncid,'rh',rhid)
      if (status.ne.nf_noerr) call error('error8b',status)
      status = nf_inq_dimlen(ncid,latid,lens1)
      if (status.ne.nf_noerr) call error('error8c',status)
      status = nf_inq_dimlen(ncid,latid,lens2)
      if (status.ne.nf_noerr) call error('error8d',status)
      status = nf_inq_dimlen(ncid,latid,lens3)
      if (status.ne.nf_noerr) call error('error8',status)
      write(6,*) 'dimensions= ',lens1,lens2,lens3

      write(6,*) 'rhid=',rhid
      status = nf_get_var_double(ncid,rhid,rhsvals2)
      do ilon = 1 , lons
         do ilat = 1 ,lats
            do itme = 1 ,times
               if (rhsvals(ilon,ilat,itme).ne.rhsvals2(ilon,ilat,itme))
     *              then
                  write(6,55) ilon,ilat,itme,rhsvals(ilon,ilat,itme),
     *                 rhsvals2(ilon,ilat,itme)
               end if
 55            format(3i4,1P,2e12.2)
            end do
         end do
      end do
      status = nf_close(ncid)
      if (status.ne.nf_noerr) call error('closing2',status)
      write(6,*) 'done'
      
      stop
      end

      subroutine error(name,status)
      implicit none
      character*(*) name
      integer status
      write(6,*) name,' ' ,status
      stop
      return
      end
