I’m using ROOT&C++ to read data from a binary data file created by Fortran program. We know that the format of Fortran binary data file is:
[size in byte of the record#1]
[record#1]
[size in byte of the record #1]
[size in byte of the record #2]
[record #2]
[size in byte of the record #2]
…
So, afer in.open(datafilename, ios::binary | ios::in), I use in.read((char*) n, sizeof(Int_t)) to read in the size of record #1. Where, n is an Int_t.
Well, I’m having inconsistant results from the ROOT on my Mac and my Linux box.
I suppose sizeof(Int_t) is a fixed number, 4, on any platforms — that’s the original idea to have Int_t, right?
Here, size_lead and size_tail should have the same number, i.e. the length of the record, which is 4, an interger. And 39 is the right number for sys in my data file.
This code reads in right numbers on Mac OS X but not on Linux after I copied the program and the binary data file over.
Very likely you are facing a byte swapping problem.
The MAC and Intel platforms have different types representation.
If your data have been written on a MAC, you must do the byte swapping
for all types greater than 1 byte.
This is one of the tasks that ROOT is doing for you when writing and
reading with ROOT.