/** * Create an ArrayChar from a String * * @param s String * @param max maximum length * @return equivilent ArrayChar */ public static ArrayChar makeFromString(String s, int max) { ArrayChar result = new ArrayChar.D1( max); for (int i=0; i<max && i<s.length(); i++) result.setChar( i, s.charAt(i)); return result; }
/** * Create an ArrayChar from a String * * @param s String * @param max maximum length * @return equivilent ArrayChar */ public static ArrayChar makeFromString(String s, int max) { ArrayChar result = new ArrayChar.D1( max); for (int i=0; i<max && i<s.length(); i++) result.setChar( i, s.charAt(i)); return result; }
/** * Create an ArrayChar from a String * * @param s String * @param max maximum length * @return equivilent ArrayChar */ public static ArrayChar makeFromString(String s, int max) { ArrayChar result = new ArrayChar.D1( max); for (int i=0; i<max && i<s.length(); i++) result.setChar( i, s.charAt(i)); return result; }
ArrayChar ac = new ArrayChar.D1(svar_len.getLength()); ima = ac.getIndex(); String val = "Testing 1-2-3"; ArrayChar ac2 = new ArrayChar.D1(svar_len.getLength()); ac2.setString("Two pairs of ladies stockings!"); v = writer.findVariable("svar2");
ArrayChar ac = new ArrayChar.D1(svar_len.getLength()); ima = ac.getIndex(); String val = "Testing 1-2-3"; ArrayChar ac2 = new ArrayChar.D1(svar_len.getLength()); ac2.setString("Two pairs of ladies stockings!"); ncfile.write(sVar2, origin1, ac2);
shape = v.getShape(); int[] origin1 = new int[1]; ArrayChar ac = new ArrayChar.D1(shape[0]); ima = ac.getIndex(); String val = "Testing 1-2-3"; len = shape[0]; try { ArrayChar ac2 = new ArrayChar.D1(len); ac2.setString("Two pairs of ladies stockings!"); writer.write(v, ac2);
public void makeNetCDF() throws IOException, InvalidRangeException { String helloGreek = makeString(helloGreekCode, true); helloGreek = ""; //Normalizer.normalize(helloGreek, Normalizer.Form.NFC); System.out.println("normalized= "+showString(helloGreek)); String filename = "C:/data/unicode/helloNorm.nc"; NetcdfFileWriter ncfile = NetcdfFileWriter.createNew(filename, true); ucar.nc2.Dimension dim = ncfile.addDimension(helloGreek, 20); ncfile.addVariable(helloGreek, DataType.CHAR, helloGreek); ncfile.addVariableAttribute(helloGreek, "units", helloGreek); ncfile.create(); ArrayChar.D1 data = new ArrayChar.D1(dim.getLength()); data.setString(helloGreek); ncfile.write(helloGreek, data); ncfile.close(); NetcdfFile nc = NetcdfFile.open(filename); Variable v = ncfile.findVariable(helloGreek); assert v != null; assert v.getShortName().equals(helloGreek); Attribute att = v.findAttribute("units"); assert att != null; assert att.isString(); assert(helloGreek.equals(att.getStringValue())); nc.close(); }
static ArrayChar factory(Index index, char[] storage) { switch (index.getRank()) { case 0: return new ArrayChar.D0(index, storage); case 1: return new ArrayChar.D1(index, storage); case 2: return new ArrayChar.D2(index, storage); case 3: return new ArrayChar.D3(index, storage); case 4: return new ArrayChar.D4(index, storage); case 5: return new ArrayChar.D5(index, storage); case 6: return new ArrayChar.D6(index, storage); case 7: return new ArrayChar.D7(index, storage); default: return new ArrayChar(index, storage); } }
static ArrayChar factory(Index index, char[] storage) { if (index instanceof Index0D) { return new ArrayChar.D0(index, storage); } else if (index instanceof Index1D) { return new ArrayChar.D1(index, storage); } else if (index instanceof Index2D) { return new ArrayChar.D2(index, storage); } else if (index instanceof Index3D) { return new ArrayChar.D3(index, storage); } else if (index instanceof Index4D) { return new ArrayChar.D4(index, storage); } else if (index instanceof Index5D) { return new ArrayChar.D5(index, storage); } else if (index instanceof Index6D) { return new ArrayChar.D6(index, storage); } else if (index instanceof Index7D) { return new ArrayChar.D7(index, storage); } else { return new ArrayChar(index, storage); } }
static ArrayChar factory(Index index, char[] storage) { switch (index.getRank()) { case 0: return new ArrayChar.D0(index, storage); case 1: return new ArrayChar.D1(index, storage); case 2: return new ArrayChar.D2(index, storage); case 3: return new ArrayChar.D3(index, storage); case 4: return new ArrayChar.D4(index, storage); case 5: return new ArrayChar.D5(index, storage); case 6: return new ArrayChar.D6(index, storage); case 7: return new ArrayChar.D7(index, storage); default: return new ArrayChar(index, storage); } }
@Test public void testWriteBigString() throws IOException { String filename = tempFolder.newFile().getAbsolutePath(); try (NetcdfFileWriter ncfile = NetcdfFileWriter.createNew(filename, false)) { int len = 120000; ArrayChar.D1 arrayCharD1 = new ArrayChar.D1(len); for (int i = 0; i < len; i++) arrayCharD1.set(i, '1'); ncfile.addGlobalAttribute( new Attribute("tooLongChar", arrayCharD1)); char[] carray = new char[len]; for (int i = 0; i < len; i++) carray[i] = '2'; String val = new String(carray); ncfile.addGlobalAttribute("tooLongString", val); ncfile.create(); } }