# Unable to read binary slc file with VTK

**URL:** https://discourse.vtk.org/t/unable-to-read-binary-slc-file-with-vtk/10809
**Category:** Support
**Tags:** python, code, file-formats
**Created:** [February 26, 2023, 6:41am UTC](https://discourse.vtk.org/t/unable-to-read-binary-slc-file-with-vtk/10809 "2023-02-26T06:41:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Latika\_Vashishtha](https://discourse.vtk.org/user_avatar/discourse.vtk.org/latika_vashishtha/32/6636_2.png) [@Latika\_Vashishtha](https://discourse.vtk.org/u/Latika_Vashishtha)
#### Post date: [February 26, 2023, 6:41am UTC](https://discourse.vtk.org/t/unable-to-read-binary-slc-file-with-vtk/10809/1 "2023-02-26T06:41:39Z")

</div>

Hey, I am trying to use vtkSLCReader to red binary slc file but it complains that its unable to read magic number.

```auto
ERR| vtkSLCReader (0x7fee9e404720): Error reading file: binary.slcFailed to read magic number
2023-02-26 11:41:24.544 ( 0.006s) [2CC3F4] vtkSLCReader.cxx:235 ERR| vtkSLCReader (0x7fee9e404720): Error reading file: binary.slcFailed to read magic number

```

I was able to read the above file with the below python code but i am struggling with VTK libraries, can someone help?

```auto
import struct
CHUNK_SIZE = 16 # bytes

# Open the binary SLC file in read mode
with open("JR03698.slc", "rb") as binary_file:
    # Open the ASCII SLC file in write mode
    with open("ascii_file.slc", "w") as ascii_file:
        while True:
            # Read the binary data in chunks
            binary_data = binary_file.read(CHUNK_SIZE)
            if not binary_data:
                break
            length = len(binary_data)
            print(f'length {length}')
            # Unpack the binary data using the struct module
            if len(binary_data) == 16:
                x, y, z, intensity = struct.unpack("f"*4, binary_data)
                # Write the x, y, z and intensity values to the ASCII file
                ascii_file.write("{}\n".format(x, y, z, intensity))

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [February 27, 2023, 9:46am UTC](https://discourse.vtk.org/t/unable-to-read-binary-slc-file-with-vtk/10809/2 "2023-02-27T09:46:38Z")

</div>

please share your .slc file

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [March 1, 2023, 8:04pm UTC](https://discourse.vtk.org/t/unable-to-read-binary-slc-file-with-vtk/10809/3 "2023-03-01T20:04:39Z")

</div>

I’m not familiar with SLC files at all, but the source for this reader indicates [that it wants](https://gitlab.kitware.com/vtk/vtk/-/blob/d669b22d2fbfa9e28e348a7569eab2bea46459b0/graphics/vtkSLCReader.cxx#L150) a “magic number” of 11111. It tests this by reading in an ASCII decimal integer using `fscanf(file_handle, '%d', &magic_number)`. This should be the first thing in the file.

According to Paul Bourke’s [page on SLC](http://paulbourke.net/dataformats/slc/), there doesn’t seem to be a magic number? Perhaps this class was specialized to SLC files written by a particular application?

I guess if you wanted to hack your file so that `vtkSLCReader` would read it, just add the text:  
`11111` to the very beginning of the file, followed by a space, then the rest of your header?
