Hello! I am working on a package to parse FCS files (data file from flow 
cytometry experiments) and got stuck when I got to parsing the data segment of 
a FCS file.
    
    
    import streams
    
    var s = newFileStream("a2006_O1T2pb05i_A1_A01.fcs", fmRead) # download this 
file here: https://flowrepository.org/experiments/3/fcs_files/21/download
    s.setPosition(3705) # start position of data segment is stored in the 
header segment
    echo readFloat32(s)
    s.close()
    

This gives me -2.084565955368639e+24, but the expected value is 23406.45.

In python, we can get the right value by specifying the byte order like this:
    
    
    from struct import unpack
    
    s = open("a2006_O1T2pb05i_A1_A01.fcs", "rb")
    s.seek(3705)
    print(unpack('>f', s.read(4))) # '>' denotes big-endian
    s.close()
    

struck's unpack function allows users to specify the byte order in the first 
argument, and I get the right value.
    
    
    (23406.451171875,)
    

**_Is there a way to specify byte order when reading a binary file in a similar 
way to python?_**

* * *

  * [What is a FCS file?](https://en.wikipedia.org/wiki/Flow_Cytometry_Standard)
  * [struct documentation](https://docs.python.org/3/library/struct.html)
  * byte order information is stored in the text segment of the file.


Reply via email to