private String createValidObjectName(String name) { return N3iosp.makeValidNetcdfObjectName(name); }
private static void testValid(String test) { //boolean isValid = isValidNetcdf3ObjectName(test); //String convert = makeValidNetcdf3ObjectName(test); //boolean isValid2 = isValidNetcdf3ObjectName(convert); //System.out.printf("old: %s (%s) == %s (%s) %n", test, isValid, convert, isValid2); boolean isValid = isValidNetcdfObjectName(test); String convert = makeValidNetcdfObjectName(test); boolean isValid2 = isValidNetcdfObjectName(convert); System.out.printf("new: %s (%s) == %s (%s) %n%n", test, isValid, convert, isValid2); } }
protected void fillNonRecordVariables() throws IOException { // run through each variable for (Variable v : ncfile.getVariables()) { if (v.isUnlimited()) continue; try { writeData(v, v.getShapeAsSection(), makeConstantArray(v)); } catch (InvalidRangeException e) { e.printStackTrace(); // shouldnt happen } } }
private boolean isValidObjectName(String name) { return N3iosp.isValidNetcdfObjectName(name); }
@Override public long readToByteChannel(ucar.nc2.Variable v2, Section section, WritableByteChannel channel) throws java.io.IOException, ucar.ma2.InvalidRangeException { if (v2 instanceof Structure) return readRecordData((Structure) v2, section, channel); N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); Layout layout = (!v2.isUnlimited()) ? new LayoutRegular(vinfo.begin, v2.getElementSize(), v2.getShape(), section) : new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, v2.getShape(), section); return readData(layout, dataType, channel); }
public void create(String filename, ucar.nc2.NetcdfFile ncfile, int extra, long preallocateSize, boolean largeFile) throws IOException { this.ncfile = ncfile; this.readonly = false; // finish any structures ncfile.finish(); raf = new ucar.unidata.io.RandomAccessFile(filename, "rw"); raf.order(RandomAccessFile.BIG_ENDIAN); if (preallocateSize > 0) { java.io.RandomAccessFile myRaf = raf.getRandomAccessFile(); myRaf.setLength(preallocateSize); } header = new N3header(); header.create(raf, ncfile, extra, largeFile, null); //recsize = header.recsize; // record size //recStart = header.recStart; // record variables start here //fileUsed = headerParser.getMinLength(); // track what is actually used _create(raf); if (fill) fillNonRecordVariables(); //else // raf.setMinLength(recStart); // make sure file length is long enough, even if not written to. }
private ucar.ma2.Array readNestedData(ucar.nc2.Variable v2, Section section) throws java.io.IOException, ucar.ma2.InvalidRangeException { N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); // construct the full shape for use by RegularIndexer int[] fullShape = new int[v2.getRank() + 1]; fullShape[0] = header.numrecs; // the first dimension System.arraycopy(v2.getShape(), 0, fullShape, 1, v2.getRank()); // the remaining dimensions Layout layout = new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, fullShape, section); Object dataObject = readData(layout, dataType); return Array.factory(dataType, section.getShape(), dataObject); }
public void openForWriting(ucar.unidata.io.RandomAccessFile raf, ucar.nc2.NetcdfFile ncfile, ucar.nc2.util.CancelTask cancelTask) throws IOException { open(raf, ncfile, cancelTask); }
@Override public void open(ucar.unidata.io.RandomAccessFile raf, ucar.nc2.NetcdfFile ncfile, ucar.nc2.util.CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); String location = raf.getLocation(); if (!location.startsWith("http:")) { File file = new File(location); if (file.exists()) lastModified = file.lastModified(); } // its a netcdf-3 file raf.order(RandomAccessFile.BIG_ENDIAN); header = new N3header(); header.read(raf, ncfile, null); // read header here //numrecs = header.numrecs; //recsize = header.recsize; //recStart = header.recStart; _open(raf); ncfile.finish(); }
protected void setNumrecs(int n) throws IOException, InvalidRangeException { if (n <= header.numrecs) return; int startRec = header.numrecs; if (debugSize) System.out.println("extend records to = " + n); //fileUsed = recStart + recsize * n; header.setNumrecs(n); //this.numrecs = n; // need to let unlimited dimension know of new shape for (Dimension dim : ncfile.getDimensions()) { if (dim.isUnlimited()) dim.setLength(n); } // need to let all unlimited variables know of new shape for (Variable v : ncfile.getVariables()) { if (v.isUnlimited()) { v.resetShape(); v.setCachedData(null, false); } } // extend file, handle filling if (fill) fillRecordVariables(startRec, n); else raf.setMinLength( header.calcFileSize()); }
private boolean isValidObjectName(String name) { return N3iosp.isValidNetcdfObjectName(name); }
public long readToByteChannel(ucar.nc2.Variable v2, Section section, WritableByteChannel channel) throws java.io.IOException, ucar.ma2.InvalidRangeException { if (v2 instanceof Structure) return readRecordData((Structure) v2, section, channel); N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); Layout layout = (!v2.isUnlimited()) ? new LayoutRegular(vinfo.begin, v2.getElementSize(), v2.getShape(), section) : new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, v2.getShape(), section); return readData(layout, dataType, channel); }
@Override public void create(String filename, ucar.nc2.NetcdfFile ncfile, int extra, long preallocateSize, boolean largeFile) throws IOException { this.ncfile = ncfile; this.readonly = false; // finish any structures ncfile.finish(); raf = new ucar.unidata.io.RandomAccessFile(filename, "rw"); raf.order(RandomAccessFile.BIG_ENDIAN); if (preallocateSize > 0) { java.io.RandomAccessFile myRaf = raf.getRandomAccessFile(); myRaf.setLength(preallocateSize); } header = new N3header(); header.create(raf, ncfile, extra, largeFile, null); //recsize = header.recsize; // record size //recStart = header.recStart; // record variables start here //fileUsed = headerParser.getMinLength(); // track what is actually used _create(raf); if (fill) fillNonRecordVariables(); //else // raf.setMinLength(recStart); // make sure file length is long enough, even if not written to. }
private ucar.ma2.Array readNestedData(ucar.nc2.Variable v2, Section section) throws java.io.IOException, ucar.ma2.InvalidRangeException { N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); // construct the full shape for use by RegularIndexer int[] fullShape = new int[v2.getRank() + 1]; fullShape[0] = header.numrecs; // the first dimension System.arraycopy(v2.getShape(), 0, fullShape, 1, v2.getRank()); // the remaining dimensions Layout layout = new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, fullShape, section); Object dataObject = readData(layout, dataType); return Array.factory(dataType.getPrimitiveClassType(), section.getShape(), dataObject); }
@Override public void openForWriting(ucar.unidata.io.RandomAccessFile raf, ucar.nc2.NetcdfFile ncfile, ucar.nc2.util.CancelTask cancelTask) throws IOException { open(raf, ncfile, cancelTask); }
@Override public void open(ucar.unidata.io.RandomAccessFile raf, ucar.nc2.NetcdfFile ncfile, ucar.nc2.util.CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); this.ncfile = ncfile; String location = raf.getLocation(); if (!location.startsWith("http:")) { File file = new File(location); if (file.exists()) lastModified = file.lastModified(); } // its a netcdf-3 file raf.order(RandomAccessFile.BIG_ENDIAN); header = new N3header(); header.read(raf, ncfile, null); // read header here //numrecs = header.numrecs; //recsize = header.recsize; //recStart = header.recStart; _open(raf); ncfile.finish(); }
protected void setNumrecs(int n) throws IOException, InvalidRangeException { if (n <= header.numrecs) return; int startRec = header.numrecs; if (debugSize) System.out.println("extend records to = " + n); //fileUsed = recStart + recsize * n; header.setNumrecs(n); //this.numrecs = n; // need to let unlimited dimension know of new shape for (Dimension dim : ncfile.getDimensions()) { if (dim.isUnlimited()) dim.setLength(n); } // need to let all unlimited variables know of new shape for (Variable v : ncfile.getVariables()) { if (v.isUnlimited()) { v.resetShape(); v.setCachedData(null, false); } } // extend file, handle filling if (fill) fillRecordVariables(startRec, n); else raf.setMinLength( header.calcFileSize()); }
private String createValidObjectName(String name) { return N3iosp.makeValidNetcdfObjectName(name); }
private static void testValid(String test) { //boolean isValid = isValidNetcdf3ObjectName(test); //String convert = makeValidNetcdf3ObjectName(test); //boolean isValid2 = isValidNetcdf3ObjectName(convert); //System.out.printf("old: %s (%s) == %s (%s) %n", test, isValid, convert, isValid2); boolean isValid = isValidNetcdfObjectName(test); String convert = makeValidNetcdfObjectName(test); boolean isValid2 = isValidNetcdfObjectName(convert); System.out.printf("new: %s (%s) == %s (%s) %n%n", test, isValid, convert, isValid2); }
private boolean isValidObjectName(String name) { return N3iosp.isValidNetcdfObjectName(name); }