Skip to content

Commit 67c066d

Browse files
committed
added support for emtpy values. added tests
1 parent 3c67efb commit 67c066d

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### Updates from version 1.5.7 to 1.5.8
22
* added support for Windsat Coriolis data
3+
* added conda environment
4+
* extended workflow to run without scheduler on plain console
35

46
### Updates from version 1.5.6 to 1.5.7
57
* added support for SMOS L1C daily aggregated products

core/src/main/java/com/bc/fiduceo/reader/insitu/sic_cci/AbstractSectionParser.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void createCommonVariables(List<Variable> variables, String prefix) {
5656

5757
static Array parseFloat(String token) {
5858
final float floatVal;
59-
if (token.equals("noval")) {
59+
if (token.isEmpty() || token.equals("noval")) {
6060
floatVal = NetCDFUtils.getDefaultFillValue(float.class).floatValue();
6161
} else {
6262
floatVal = Float.parseFloat(token);
@@ -68,7 +68,7 @@ static Array parseFloat(String token) {
6868
static Array parseShort(String token) {
6969
final short shortVal;
7070

71-
if (token.equals("noval")) {
71+
if (token.isEmpty() || token.equals("noval")) {
7272
shortVal = NetCDFUtils.getDefaultFillValue(short.class).shortValue();
7373
} else {
7474
shortVal = Short.parseShort(token);
@@ -77,8 +77,14 @@ static Array parseShort(String token) {
7777
}
7878

7979
static Array parseByte(String token) {
80-
final byte sic_total = Byte.parseByte(token);
81-
return Array.factory(DataType.BYTE, SCALAR, new byte[]{sic_total});
80+
final byte byteVal;
81+
if (token.isEmpty() || token.equals("noval")) {
82+
byteVal = NetCDFUtils.getDefaultFillValue(byte.class).byteValue();
83+
} else {
84+
byteVal = Byte.parseByte(token);
85+
}
86+
87+
return Array.factory(DataType.BYTE, SCALAR, new byte[]{byteVal});
8288
}
8389

8490
static Array parseUtcTime(String token) throws ParseException {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.bc.fiduceo.reader.insitu.sic_cci;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class AbstractSectionParserTest {
8+
9+
@Test
10+
public void testParseByte() {
11+
assertEquals(15, AbstractSectionParser.parseByte("15").getByte(0));
12+
13+
assertEquals(-127, AbstractSectionParser.parseByte("noval").getByte(0));
14+
assertEquals(-127, AbstractSectionParser.parseByte("").getByte(0));
15+
}
16+
17+
@Test
18+
public void testParseShort() {
19+
assertEquals(-8713, AbstractSectionParser.parseShort("-8713").getShort(0));
20+
21+
assertEquals(-32767, AbstractSectionParser.parseShort("noval").getShort(0));
22+
assertEquals(-32767, AbstractSectionParser.parseShort("").getShort(0));
23+
}
24+
25+
@Test
26+
public void testParseFloat() {
27+
assertEquals(66.903, AbstractSectionParser.parseFloat("66.903").getFloat(0), 1e-6);
28+
29+
assertEquals(9.969209968386869E36, AbstractSectionParser.parseFloat("noval").getFloat(0), 1e-8);
30+
assertEquals(9.969209968386869E36, AbstractSectionParser.parseFloat("").getFloat(0), 1e-8);
31+
}
32+
}

0 commit comments

Comments
 (0)