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.
Ed Yu wrote:
Hi all,Does anyone has an example on how to write a scalar String variable say comment ("this is a comment") to a netcdf file? Should I use an ArrayChar.D1 instead of the 0-rank? Code and comments is appreciated. Thanks!
sorry for the lack of examples, heres some scalar String utilities:public void createString(NetcdfFileWriteable ncfile, String name, String val) {
Dimension slen = ncfile.addDimension(name+"_len", val.length()); ncfile.addVariable(name, char.class, new Dimension[] {slen}); }public void writeString(NetcdfFileWriteable ncfile, String name, String val) throws IOException {
ArrayChar ac = new ArrayChar.D1(val.length()); ac.setString(val); ncfile.write(name, new int[1], ac); }public String readString(NetcdfFile ncfile, String name) throws IOException {
Variable v = ncfile.findVariable(name); ArrayChar ac = (ArrayChar) v.read(); return ac.getString(); }
netcdf-java
archives: