javakotlininputstreamfileinputstreamoscilloscope

how to get values from *.dbl/*.mt4


I received data from the oscilloscope in 64-bit doubles (.dbl) or in "measured data" (.mt4) format. How can I parse it (preferably Java or Kotlin) or where can I find documentation for this format?

I tried using DataInputStream.readDouble but the results were weird

c5 12 52 9b ec 3f 12 c0 17 29 e9 87 4e 71 12 c0 6a 3f 80 74 b0 a2 12 c0 b8 39 8e 9e b1 37 12 c0 17 29 e9 87 4e 71 12 c0 c5 12 52 9b ec 3f 12 c0 4e 8d f8 7a 3a 92 12 c0 aa 60 ca a1


Solution

  • You can read it with this. The values are in line with your expectations:

    import java.nio.ByteBuffer;
    import static java.nio.ByteOrder.*;
    import java.nio.file.Path;
    import java.nio.file.Files;
    import java.io.InputStream;
    
    public class Doubler {
        public static void main(String[] args) throws Exception {
            int count = -1;
            byte[] buff = new byte[8];
            ByteBuffer bb = ByteBuffer.allocate(8).order(LITTLE_ENDIAN);
            try (InputStream in = Files.newInputStream(Path.of(args[0]))) {
                while ((count = in.read(buff)) > -1) {
                    bb.put(buff);
                    bb.rewind();
                    System.out.printf("%.2f%n", bb.getDouble());
                    bb.rewind();
                }
            }
        }
    }