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

Commit d99e9ec

Browse files
authored
Merge pull request #1339 from lesserwhirls/level2check
Refactor NEXRAD level2 format checking
2 parents 44fee72 + 6a86757 commit d99e9ec

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

cdm/src/main/java/ucar/nc2/dt/radial/LevelII2Dataset.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
package ucar.nc2.dt.radial;
3434

35+
import static ucar.nc2.iosp.nexrad2.Nexrad2IOServiceProvider.isNEXRAD2Format;
36+
3537
import ucar.nc2.*;
3638
import ucar.nc2.dataset.*;
3739
import ucar.nc2.constants.*;
@@ -67,11 +69,9 @@ public boolean isMine(NetcdfDataset ds) {
6769
String convention = ds.findAttValueIgnoreCase(null, "Conventions", null);
6870
if ((null != convention) && convention.equals(_Coordinate.Convention)) {
6971
String format = ds.findAttValueIgnoreCase(null, "Format", null);
70-
if (format != null && (format.equals("ARCHIVE2")
71-
|| format.equals("AR2V0001") || format.equals("CINRAD-SA")
72-
|| format.equals("AR2V0003") || format.equals("AR2V0002") || format.equals("AR2V0004")
73-
|| format.equals("AR2V0006") || format.equals("AR2V0007")))
72+
if (format != null && (isNEXRAD2Format(format) || format.equals("CINRAD-SA"))) {
7473
return true;
74+
}
7575
}
7676
return false;
7777
}

cdm/src/main/java/ucar/nc2/iosp/nexrad2/Level2VolumeScan.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ public class Level2VolumeScan {
144144
station = NexradStationDB.get(stationId);
145145
}
146146

147-
//see if we have to uncompress
148-
if (dataFormat.equals(AR2V0001) || dataFormat.equals(AR2V0003)
149-
|| dataFormat.equals(AR2V0004) || dataFormat.equals(AR2V0006) || dataFormat.equals(AR2V0007) ) {
147+
// see if we have to uncompress--basically looking for anything but the original Level2 format
148+
// technically speaking, this BZ2 compression is a detail of transmission--there's no requirement in the
149+
// ICDs that this BZ2 block compression is actually applied on disk.
150+
if (dataFormat.startsWith("AR2V")) {
150151
raf.skipBytes(4);
151152
String BZ = raf.readString(2);
152153
if (BZ.equals("BZ")) {

cdm/src/main/java/ucar/nc2/iosp/nexrad2/Nexrad2IOServiceProvider.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,24 @@ public class Nexrad2IOServiceProvider extends AbstractIOServiceProvider {
5757
static private final int MISSING_INT = -9999;
5858
static private final float MISSING_FLOAT = Float.NaN;
5959

60+
public static boolean isNEXRAD2Format(String format) {
61+
return isNEXRAD2Format(format, false);
62+
}
63+
64+
private static boolean isNEXRAD2Format(String format, boolean checkIfKnown) {
65+
if (format != null && (format.equals("ARCHIVE2") || format.startsWith("AR2V"))) {
66+
if (checkIfKnown && format.startsWith("AR2V") && Integer.parseInt(format.substring(4)) > 8) {
67+
logger.warn("Trying to handle unknown but valid-looking format: " + format);
68+
}
69+
return true;
70+
}
71+
return false;
72+
}
6073

6174
public boolean isValidFile( RandomAccessFile raf) throws IOException {
6275
try {
6376
raf.seek(0);
64-
String test = raf.readString(8);
65-
return test.equals( Level2VolumeScan.ARCHIVE2) || test.equals( Level2VolumeScan.AR2V0001) ||
66-
test.equals( Level2VolumeScan.AR2V0003)|| test.equals( Level2VolumeScan.AR2V0004) ||
67-
test.equals( Level2VolumeScan.AR2V0002) || test.equals( Level2VolumeScan.AR2V0006) ||
68-
test.equals( Level2VolumeScan.AR2V0007);
77+
return isNEXRAD2Format(raf.readString(8));
6978
} catch (IOException ioe) {
7079
return false;
7180
}

0 commit comments

Comments
 (0)