Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.

ncgen don't line "minus zero".

If a variable in an .cdl file contains a value of "-0" or "+0", ncgen 
produces a syntax error. The reason is seems to be the following in ncgen.l:
[+-]?[1-9][0-9]*[lL]?|0[lL]? {

I am not familar with lex, but it seems to me, the author defined a long
constant as beginning with + or - and a number 1-9, or as a single 0 without
+ or -.

I don't know why this was done, so I don't want to change it. 

The whole thing don't look like a problem, why should anyone insert a -0 in
his .cdl file?

BUT: At least on the Sun (SUN OS 4.1.3), ncdump often generates a -0!
(This seems to be a bug in SUNs output formatting routines, the MS-DOS Version
of ncdump don't have this problem).

Run the following little program:
/* ------------- Cut Here ----------------*/
#include <stdio.h>
#include <netcdf.h>

main()
{
  double d=0;
  int ncid, dimid, varid;
  long start=0, count=1;



  d *= -1;

  ncid = nccreate("test.nc",NC_CLOBBER);
  dimid=ncdimdef(ncid, "time",1);
  varid=ncvardef(ncid, "velocity",NC_DOUBLE,1,&dimid);
  ncendef(ncid);
  ncvarput (ncid,varid,&start, &count,&d);
  ncclose(ncid);
}
/* ------------- Cut Here ----------------*/
Now run "ncdump test.nc":

netcdf test {
dimensions:
        time = 1 ;

variables:
        double velocity(time) ;

data:

 velocity = -0 ;  // <---------- Here it is.
}

Try to run ncgen on the output and you get:
ncgen: test.cdl line 10: syntax error
 
Now I would like to change ncgen to accept the "-0" or ncdump to
produce at least "-0." like it does in attributes. Any ideas what's the
best solution?

Bernward Bretthauer
  
 


----- End Included Message -----


  • 1995 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: