0

I'm trying to open a 'VAX' file without success in python. In old Matlab versions (before 2008) it was possible to do it using the commands:

    fid = fopen(filename, 'r', 'vaxd');                  
    data = fread(fid, inf, 'float32');

But I'm not able to replicate this in python or other programming languages.

I tried to use pyvax (https://github.com/garydoranjr/pyvax), a python wrapper for libvaxdata library in C, but without success. This is what I tried.

import pyvax 
import numpy as np

file = "filepath"

with open(file, 'rb') as fl:
    data = fl.read()
        
fstr = pyvax.from_vax_d8(data)
np.frombuffer(fstr, dtype = 'float32', count=-1, offset=0)

But the data I get are not correct (non sense numbers, not what I expect to be contained in the file). I also tried other functions in the pyvax package and different "dtype" values in the np.frombuffer function. Do you have any suggestion on what to try next?

EDIT: Here a dropbox link to download an example of the file I'm trying to open:https://www.dropbox.com/s/unn10jfmclwh7d6/testfile.THK?dl=0 I expect it to contain about 8k numbers, I suppose float32 (from the matlab code provided). I expect the majority of values to be close to the number 700, but I'm not sure about this last one.

  • 1
    My suggestion would be to say more about what program created the file and about what you expect the contents to be in terms of types/numbers of values/fields and to share the file via Dropbox or Google Drive or somesuch. – Mark Setchell Jul 27 '23 at 08:45
  • *"A vector of numbers"* is not especially useful as a description - how about saying how many numbers you believe are in there and what type you think they are (e.g. 32-bit floating point, or 16-bit integers) and saying if you know what the likely range of the numbers is, e.g. from 800 to 2000? – Mark Setchell Jul 27 '23 at 11:06
  • 2
    Thanks for your help in making my question more pertinent – new_manufacturer Jul 27 '23 at 11:25
  • Based on your MATLAB code and your comment of before 2008 it makes me wonder if you were working on a big-endian machine. That being said, looking at the VAX floating point formats vs IEEE and I'm surprised the MATLAB code ever worked. I'm also wondering if you are using the right version (VAX D instead of F `from_vax_r4` -- my vote --, or VAX G `from_vax_g8`). Finally, worst case I would expect that you could literally work through the byte reshuffling yourself from https://nssdc.gsfc.nasa.gov/nssdc/formats/VAXFloatingPoint.htm and https://en.wikipedia.org/wiki/IEEE_754 – Jimbo Jul 27 '23 at 20:09

0 Answers0