NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
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: