Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Refactor NEXRAD level2 format checking #1339

Merged
merged 1 commit into from
Oct 9, 2020
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/src/main/java/ucar/nc2/dt/radial/LevelII2Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
package ucar.nc2.dt.radial;

import static ucar.nc2.iosp.nexrad2.Nexrad2IOServiceProvider.isNEXRAD2Format;

import ucar.nc2.*;
import ucar.nc2.dataset.*;
import ucar.nc2.constants.*;
Expand Down Expand Up @@ -67,11 +69,9 @@ public boolean isMine(NetcdfDataset ds) {
String convention = ds.findAttValueIgnoreCase(null, "Conventions", null);
if ((null != convention) && convention.equals(_Coordinate.Convention)) {
String format = ds.findAttValueIgnoreCase(null, "Format", null);
if (format != null && (format.equals("ARCHIVE2")
|| format.equals("AR2V0001") || format.equals("CINRAD-SA")
|| format.equals("AR2V0003") || format.equals("AR2V0002") || format.equals("AR2V0004")
|| format.equals("AR2V0006") || format.equals("AR2V0007")))
if (format != null && (isNEXRAD2Format(format) || format.equals("CINRAD-SA"))) {
return true;
}
}
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions cdm/src/main/java/ucar/nc2/iosp/nexrad2/Level2VolumeScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ public class Level2VolumeScan {
station = NexradStationDB.get(stationId);
}

//see if we have to uncompress
if (dataFormat.equals(AR2V0001) || dataFormat.equals(AR2V0003)
|| dataFormat.equals(AR2V0004) || dataFormat.equals(AR2V0006) || dataFormat.equals(AR2V0007) ) {
// see if we have to uncompress--basically looking for anything but the original Level2 format
// technically speaking, this BZ2 compression is a detail of transmission--there's no requirement in the
// ICDs that this BZ2 block compression is actually applied on disk.
if (dataFormat.startsWith("AR2V")) {
raf.skipBytes(4);
String BZ = raf.readString(2);
if (BZ.equals("BZ")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ public class Nexrad2IOServiceProvider extends AbstractIOServiceProvider {
static private final int MISSING_INT = -9999;
static private final float MISSING_FLOAT = Float.NaN;

public static boolean isNEXRAD2Format(String format) {
return isNEXRAD2Format(format, false);
}

private static boolean isNEXRAD2Format(String format, boolean checkIfKnown) {
if (format != null && (format.equals("ARCHIVE2") || format.startsWith("AR2V"))) {
if (checkIfKnown && format.startsWith("AR2V") && Integer.parseInt(format.substring(4)) > 8) {
logger.warn("Trying to handle unknown but valid-looking format: " + format);
}
return true;
}
return false;
}

public boolean isValidFile( RandomAccessFile raf) throws IOException {
try {
raf.seek(0);
String test = raf.readString(8);
return test.equals( Level2VolumeScan.ARCHIVE2) || test.equals( Level2VolumeScan.AR2V0001) ||
test.equals( Level2VolumeScan.AR2V0003)|| test.equals( Level2VolumeScan.AR2V0004) ||
test.equals( Level2VolumeScan.AR2V0002) || test.equals( Level2VolumeScan.AR2V0006) ||
test.equals( Level2VolumeScan.AR2V0007);
return isNEXRAD2Format(raf.readString(8));
} catch (IOException ioe) {
return false;
}
Expand Down