void writeNetCDF(String filename) { try { FileWriter2 writer = new FileWriter2(ds, filename, NetcdfFileWriter.Version.netcdf3); NetcdfFile result = writer.write(); result.close(); JOptionPane.showMessageDialog(this, "File successfully written"); } catch (Exception ioe) { JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage()); ioe.printStackTrace(); } }
void writeNcstreamHeader(String filename) { try { NcStreamWriter writer = new NcStreamWriter(ds, null); FileOutputStream fos = new FileOutputStream(filename); writer.sendHeader(fos); fos.close(); JOptionPane.showMessageDialog(this, "File successfully written"); } catch (Exception ioe) { JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage()); ioe.printStackTrace(); } }
private void showValuesAsDates(CoordinateAxis axis) { String units = axis.getUnitsString(); String cal = getCalendarAttribute(axis); CalendarDateUnit cdu = CalendarDateUnit.of(cal, units); try { infoTA.appendLine(units); infoTA.appendLine(NCdumpW.printVariableData(axis, null)); if (axis.getDataType().isNumeric()) { if (axis instanceof CoordinateAxis2D) { showDates2D((CoordinateAxis2D) axis, cdu); } else if (axis instanceof CoordinateAxis1D) { // 1D showDates1D((CoordinateAxis1D) axis, cdu); } else { // > 2D Array data = axis.read(); IndexIterator ii = data.getIndexIterator(); while (ii.hasNext()) { double val = ii.getDoubleNext(); infoTA.appendLine(makeCalendarDateStringOrMissing(cdu, val)); } } } else { // must be iso dates Array data = axis.read(); Formatter f = new Formatter(); if (data instanceof ArrayChar) { ArrayChar dataS = (ArrayChar) data; ArrayChar.StringIterator iter = dataS.getStringIterator(); while (iter.hasNext()) f.format(" %s%n", iter.next()); infoTA.appendLine(f.toString()); } else if (data instanceof ArrayObject) { IndexIterator iter = data.getIndexIterator(); while (iter.hasNext()) f.format(" %s%n", iter.next()); infoTA.appendLine(f.toString()); } } } catch (Exception ex) { ex.printStackTrace(); infoTA.appendLine(ex.getMessage()); } }
private void showValueDiffs(CoordinateAxis axis) { if (!axis.isNumeric()) return; try { if (axis instanceof CoordinateAxis1D) { CoordinateAxis1D axis1D = (CoordinateAxis1D) axis; double[] mids = axis1D.getCoordValues(); double[] diffs = new double[mids.length]; for (int i = 0; i < mids.length - 1; i++) diffs[i] = mids[i + 1] - mids[i]; printArrays("midpoint differences", mids, diffs); } else if (axis instanceof CoordinateAxis2D) { CoordinateAxis2D axis2D = (CoordinateAxis2D) axis; ArrayDouble.D2 mids = axis2D.getCoordValuesArray(); int[] shape = mids.getShape(); ArrayDouble.D2 diffx = (ArrayDouble.D2) Array.factory(DataType.DOUBLE, new int[] {shape[0], shape[1] - 1}); for (int j = 0; j < shape[0]; j++) { for (int i = 0; i < shape[1] - 1; i++) { double diff = mids.get(j, i + 1) - mids.get(j, i); diffx.set(j, i, diff); } } infoTA.appendLine(NCdumpW.toString(diffx, "diff in x", null)); ArrayDouble.D2 diffy = (ArrayDouble.D2) Array.factory(DataType.DOUBLE, new int[] {shape[0] - 1, shape[1]}); for (int j = 0; j < shape[0] - 1; j++) { for (int i = 0; i < shape[1]; i++) { double diff = mids.get(j + 1, i) - mids.get(j, i); diffy.set(j, i, diff); } } infoTA.appendLine("\n\n\n"); infoTA.appendLine(NCdumpW.toString(diffy, "diff in y", null)); } } catch (Exception e1) { e1.printStackTrace(); infoTA.appendLine(e1.getMessage()); } }