[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: possible bug with nf_put_att_text



Mary,

> To: address@hidden
> From: address@hidden (Mary Haley)
> Subject: possible bug with nf_put_att_text
> Organization: UCAR/NCAR/SCD
> Keywords: 199801071532.IAA01319

In the above message, you wrote:

> An outside user reported a problem he's having with "nf_put_att_text".
> He uses netCDF on NCAR's Crays, but the problem also occurs on local
> workstations.  I ran his program and got the same results, so I
> thought I'd better pass it on to you.
> 
> Here's part of the user's message:
> 
> > nf_put_att_text does not correctly set an attribute's value whose 
> > length is zero. The behavior is as follows:
> > 
> >   netCDF file made by 
> >       ....
> >       stat=nf_put_att_text(ncid,varid,"long_name",3,"QQQ")
> >       stat=nf_put_att_text(ncid,varid,"unit",0,"")
> >       ...
> >   becomes
> >       ...
> >       test:long_name = "QQQ" ;
> >       test:unit = "Q" ;
> >       ...
> >   where the value of "unit", which has to be "", becomes the first
> >   letter of the previously set attribute.
> >   If nf_put_att_text(ncid,varid,"unit",0,"") is called as the
> >   fisrt call to the function, the resultant value is correctly "".
> > 
> 
> And here's the program:
> 
>       program main
>       implicit none
> #include <netcdf.inc>
>       character(len=20) :: path = "tmp.nc"
>       integer,parameter :: nlon=5
>       integer,parameter :: ntime=4
>       integer :: ncid,varid
>       integer :: stat,i
>       integer,dimension(2) :: dimids,start,length
>       real,dimension(nlon*ntime) :: val
>       
>       stat=nf_create(path,NF_CLOBBER,ncid)
>       stat=nf_def_dim(ncid,"lon",nlon,dimids(1))
>       stat=nf_def_dim(ncid,"time",ntime,dimids(2))
>       stat=nf_def_var(ncid,"test",NF_REAL,2,dimids,varid)
>       stat=nf_put_att_text(ncid,varid,"long_name",3,"QQQ")
>       stat=nf_put_att_text(ncid,varid,"unit",0,"")
>       stat=nf_put_att_text(ncid,varid,"dummy",0,"")
>       stat=nf_enddef(ncid)
>       
>       val=(/ (i,i=1,size(val)) /)
>       start=1
>       length=(/nlon,ntime/)
> 
>       stat=nf_put_var_real(ncid,varid,val)
> 
>       stat=nf_close(ncid)
> 
>       end program main
> 
> 
> Is this a bug?

It's sort of a bug -- but not where you think.  In the netCDF file, the
zero-length attribute is truly zero-length (i.e. it has no values).  The
problem is that the ncdump(1) utility has a problem with zero-length
attributes and, as you see, is printing the first character of the
previously-printed attribute.  Please tell your user that the netCDF
file is OK.

Unfortunately, we're heading off for the AMS conference in Phoenix so
we don't have time to fix ncdump(1) at the moment.  We will fix it,
however, when we return.

--------
Steve Emmerson   <http://www.unidata.ucar.edu>