Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cdm/core/src/main/java/ucar/nc2/NetcdfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,15 +631,15 @@ private static String makeUncompressed(String filename) throws IOException {

try {
if (suffix.equalsIgnoreCase("Z")) {
try (InputStream in = new UncompressInputStream(new FileInputStream(filename))) {
try (InputStream in = new UncompressInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
copy(in, fout, 100000);
}
if (debugCompress)
log.info("uncompressed {} to {}", filename, uncompressedFile);

} else if (suffix.equalsIgnoreCase("zip")) {

try (ZipInputStream zin = new ZipInputStream(new FileInputStream(filename))) {
try (ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
ZipEntry ze = zin.getNextEntry();
if (ze != null) {
copy(zin, fout, 100000);
Expand All @@ -649,15 +649,15 @@ private static String makeUncompressed(String filename) throws IOException {
}

} else if (suffix.equalsIgnoreCase("bz2")) {
try (InputStream in = new CBZip2InputStream(new FileInputStream(filename), true)) {
try (InputStream in = new CBZip2InputStream(new BufferedInputStream(new FileInputStream(filename)), true)) {
copy(in, fout, 100000);
}
if (debugCompress)
log.info("unbzipped {} to {}", filename, uncompressedFile);

} else if (suffix.equalsIgnoreCase("gzip") || suffix.equalsIgnoreCase("gz")) {

try (InputStream in = new GZIPInputStream(new FileInputStream(filename))) {
try (InputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
copy(in, fout, 100000);
}

Expand Down
9 changes: 5 additions & 4 deletions cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private static String makeUncompressed(String filename) throws Exception {
try {
if (suffix.equalsIgnoreCase("Z")) {
// Z file can only contain one file - copy the whole thing
try (InputStream in = new UncompressInputStream(new FileInputStream(baseFilename))) {
try (InputStream in = new UncompressInputStream(new BufferedInputStream(new FileInputStream(baseFilename)))) {
copy(in, fout, 100000);
}
if (NetcdfFile.debugCompress) {
Expand All @@ -584,7 +584,7 @@ private static String makeUncompressed(String filename) throws Exception {

} else if (suffix.equalsIgnoreCase("zip")) {
// find specified zip entry, if it exists
try (ZipInputStream zin = new ZipInputStream(new FileInputStream(baseFilename))) {
try (ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(baseFilename)))) {
// If a desired zipentry ID was appended to method's filename parameter, then itempath
// is of length > 1 and ID starts at itempath char offset 1.
String itemName = (itempath.length() > 1) ? itempath.substring(1) : "";
Expand All @@ -606,15 +606,16 @@ private static String makeUncompressed(String filename) throws Exception {

} else if (suffix.equalsIgnoreCase("bz2")) {
// bz2 can only contain one file - copy the whole thing
try (InputStream in = new CBZip2InputStream(new FileInputStream(baseFilename), true)) {
try (InputStream in =
new CBZip2InputStream(new BufferedInputStream(new FileInputStream(baseFilename)), true)) {
copy(in, fout, 100000);
}
if (NetcdfFile.debugCompress)
log.info("unbzipped {} to {}", filename, uncompressedFile);

} else if (suffix.equalsIgnoreCase("gzip") || suffix.equalsIgnoreCase("gz")) {
// gzip/gz concatenates streams - copy the whole thing
try (InputStream in = new GZIPInputStream(new FileInputStream(baseFilename))) {
try (InputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(baseFilename)))) {
copy(in, fout, 100000);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package ucar.unidata.geoloc.projection;

import ucar.unidata.geoloc.*;

import java.util.Objects;

/**
* A dummy ProjectionImpl subclass for unstructured grids.
* Since unstructured grids do not follow a single mathematical projection,
* this class does not implement real forward/inverse transformations.
* Instead, it serves as a placeholder so netCDF-Java can represent the
* grid in a coordinate system, while actual lat/lon positions are handled
* separately (e.g., by per-cell coordinate arrays).
*/
public class UnstructuredProjection extends ProjectionImpl {

public static final String EARTH_SHAPE = "earth_shape";
public static final String NUMBER_OF_GRID_USED = "number_of_grid_used";
public static final String NUMBER_OF_GRID_IN_REFERENCE = "number_of_grid_in_reference";
public static final String UUID = "uuid";

int earthShape, numberOfGridUsed, numberOfGridInReference;
String uuid;

/**
* Create a new UnstructuredProjection with a given name.
*/
public UnstructuredProjection(int earthShape, int numberOfGridUsed, int numberOfGridInReference, String uuid) {
super("UnstructuredProjection", false); // false => not lat/lon

this.earthShape = earthShape;
this.numberOfGridUsed = numberOfGridUsed;
this.numberOfGridInReference = numberOfGridInReference;
this.uuid = uuid;

addParameter(EARTH_SHAPE, earthShape);
addParameter(NUMBER_OF_GRID_USED, numberOfGridUsed);
addParameter(NUMBER_OF_GRID_IN_REFERENCE, numberOfGridInReference);
addParameter(UUID, uuid);
}

/**
* Copy constructor for UnstructuredProjection.
*/
private UnstructuredProjection(UnstructuredProjection that) {
this(that.earthShape, that.numberOfGridUsed, that.numberOfGridInReference, that.uuid);
}

@Override
public ProjectionImpl constructCopy() {
// Return a new instance with the same name, etc.
return new UnstructuredProjection(this);
}

/**
* Since we do not have a formula for an unstructured grid,
* throw an exception if someone tries to do forward transform.
*/
@Override
public ProjectionPoint latLonToProj(LatLonPoint latlon, ProjectionPointImpl dest) {
throw new UnsupportedOperationException("UnstructuredProjection: no formula-based transform available");
}

/**
* Similarly, inverse transform is not defined for unstructured grids.
*/
@Override
public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl dest) {
throw new UnsupportedOperationException("UnstructuredProjection: no formula-based transform available");
}

/**
* For unstructured grids, the notion of crossing a seam is irrelevant,
* so we return false (or you could throw an exception).
*/
@Override
public boolean crossSeam(ProjectionPoint pt1, ProjectionPoint pt2) {
return false;
}

@Override
public String paramsToString() {
return "UnstructuredProjection: no transform parameters";
}

@Override
public boolean equals(Object o) {
if (!(o instanceof UnstructuredProjection))
return false;
UnstructuredProjection that = (UnstructuredProjection) o;
return earthShape == that.earthShape && numberOfGridUsed == that.numberOfGridUsed
&& numberOfGridInReference == that.numberOfGridInReference && Objects.equals(uuid, that.uuid);
}

@Override
public int hashCode() {
return Objects.hash(earthShape, numberOfGridUsed, numberOfGridInReference, uuid);
}
}
Loading