diff --git a/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile.java b/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile.java index 40d0742..90ce370 100644 --- a/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile.java +++ b/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile.java @@ -23,13 +23,13 @@ public abstract class ChFile { protected Double yOffset; protected String detector; - int dataStart; - int startTimePosition; - int endTimePosition; - int unitsPosition; - int yOffsetPosition; - int yScalingPosition; - int detectorPosition; + protected final int dataStart; // Has no use for now + protected final int startTimePosition; + protected final int endTimePosition; + protected final int unitsPosition; + protected final int yOffsetPosition; + protected final int yScalingPosition; + protected final int detectorPosition; protected ChFile(RandomAccessFile input, int dataStart, int startTimePosition, int endTimePosition, int unitsPosition, int yOffsetPosition, int yScalingPosition, int detectorPosition) throws IOException { this.dataStart = dataStart; @@ -46,59 +46,46 @@ protected ChFile(RandomAccessFile input, int dataStart, int startTimePosition, i protected abstract void parseData(RandomAccessFile input) throws IOException; + /** + * Returns the values found in the .ch file, converted to picoampere as the standard imposes. + */ public List getValues() { return values; } - protected void setValues(List values) { - this.values = values; - } - public Float getStartTime() { return startTime; } - private void setStartTime(Float startTime) { - this.startTime = startTime; - } - public Float getEndTime() { return endTime; } - private void setEndTime(Float endTime) { - this.endTime = endTime; + public String getDetector() { + return detector; } + /** + * Returns the unit found in the .ch file.
+ * Warning: the values stored in this class are converted to picoampere, as the standard imposes. + */ protected Unit getUnit() { return unit; } - public String getUnitSymbol() { - return unit.toString(); - } - private void setUnit(String unit) { Unit localUnit = Unit.valueOf(unit); if (!PICO_AMPERE_UNIT.isCompatible(localUnit)) { - throw new IllegalArgumentException("Unsupported unit: " + localUnit); + throw new IllegalArgumentException("Unsupported unit: " + unit); } this.unit = localUnit.asType(ElectricCurrent.class); } - public String getDetector() { - return detector; - } - - private void setDetector(String detector) { - this.detector = detector; - } - protected void readMetadata(RandomAccessFile input) throws IOException { - setStartTime(readMetadataTime(input, startTimePosition)); - setEndTime(readMetadataTime(input, endTimePosition)); + startTime = readMetadataTime(input, startTimePosition); + endTime = readMetadataTime(input, endTimePosition); setUnit(readStringAtPosition(input, unitsPosition, true)); input.seek(yOffsetPosition); @@ -107,6 +94,6 @@ protected void readMetadata(RandomAccessFile input) throws IOException { input.seek(yScalingPosition); yScaling = input.readDouble(); - setDetector(readStringAtPosition(input, detectorPosition, true)); + detector = readStringAtPosition(input, detectorPosition, true); } } diff --git a/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179.java b/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179.java index c9bd6ec..23525cf 100644 --- a/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179.java +++ b/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.ArrayList; -import java.util.List; import static fr.ifpen.allotropeconverters.gc.chemstation.chfile.ReadHelpers.readLittleEndianDouble; @@ -29,15 +28,13 @@ protected void parseData(RandomAccessFile input) throws IOException { throw new IllegalArgumentException("Input too large to parse"); } - List values = new ArrayList<>((int) numberOfPoints); - UnitConverter unitConverter = getUnit().getConverterTo(PICO_AMPERE_UNIT); + values = new ArrayList<>((int) numberOfPoints); + UnitConverter unitConverter = unit.getConverterTo(PICO_AMPERE_UNIT); input.seek(DATA_START); for (int i = 0; i < numberOfPoints; i++) { values.add(unitConverter.convert(readLittleEndianDouble(input) * yScaling)); } - - setValues(values); } } diff --git a/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181.java b/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181.java index 19d3577..25d5783 100644 --- a/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181.java +++ b/src/main/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181.java @@ -1,5 +1,6 @@ package fr.ifpen.allotropeconverters.gc.chemstation.chfile; +import javax.measure.converter.UnitConverter; import java.io.EOFException; import java.io.IOException; import java.io.RandomAccessFile; @@ -26,6 +27,8 @@ protected void parseData(RandomAccessFile input) throws IOException { values = new ArrayList<>(); long[] buffer = new long[]{0, 0, 0}; + UnitConverter unitConverter = unit.getConverterTo(PICO_AMPERE_UNIT); + boolean endOfFile = false; while (!endOfFile) { @@ -41,8 +44,7 @@ protected void parseData(RandomAccessFile input) throws IOException { buffer[1] = 0; } - values.add(buffer[0] * yScaling + yOffset); - + values.add(unitConverter.convert(buffer[0] * yScaling + yOffset)); } catch (EOFException e) { endOfFile = true; } diff --git a/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179Tests.java b/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179Tests.java index 73da39e..3b3ed15 100644 --- a/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179Tests.java +++ b/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile179Tests.java @@ -24,6 +24,5 @@ void getVersionReturnsExpected() throws IOException { Assertions.assertEquals(2.165234, values.get(0), 0.001); Assertions.assertEquals(SI.PICO(SI.AMPERE), chFile.getUnit()); - Assertions.assertEquals("pA", chFile.getUnitSymbol()); } } diff --git a/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181Tests.java b/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181Tests.java index 8698416..bb6119a 100644 --- a/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181Tests.java +++ b/src/test/java/fr/ifpen/allotropeconverters/gc/chemstation/chfile/ChFile181Tests.java @@ -24,6 +24,5 @@ void getVersionReturnsExpected() throws IOException { Assertions.assertEquals(2.1010, values.get(0), 0.001); Assertions.assertEquals(SI.PICO(SI.AMPERE), chFile.getUnit()); - Assertions.assertEquals("pA", chFile.getUnitSymbol()); } }