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.
Craig Mattocks wrote:
Hi John,I modified the CreateNetcdf.java example file (attached) to add a "valid_range" attribute to the relative humidity field but I am running into problems.When I compare the output with the file generated by "ncgen -b example.cdl", the quotes are contained in the Java-generated file (see line #88).What is the proper way to add an attribute like this? I can't find the info in the Javadocs.Please excuse me if this is a dumb question. Thanks! Craig
You have: ncfile.addVariable("rh", DataType.INT, dim3); ncfile.addVariableAttribute("rh", "long_name", "relative humidity"); ncfile.addVariableAttribute("rh", "units", "percent");ncfile.addVariableAttribute("rh", "valid_range", "0., 100."); // <--- Problem quotes!
which adds a string-valued attribute. You probably want to create an integer valued attribute, since rh is an integer.
normally you could go:ncfile.addVariableAttribute("rh", "valid_range", new Integer(0) );
but since you need an array, its more convoluted:ArrayInt.D1 valid_range = new ArrayInt.D1(2); // create a 1-d integer array of length
valid_range.set(0, 0); // set the firsst element valid_range.set(1,100); // set the second element ncfile.addVariableAttribute("rh", "valid_range", valid_range);
netcdf-java
archives: