Чтение в сыром закодированном файле данных nrrd в двойной

Кто-нибудь знает, как читать в файле с сырой кодировкой? Так тупо …. Я пытаюсь читать поплавками или двойниками (я думаю). Я застрял на этом в течение нескольких недель. Спасибо!

Файл, из которого я пытаюсь прочитать:
http://www.sci.utah.edu/~gk/DTI-data/gk2/gk2-rcc-mask.raw

Описание сырой кодировки:
привет: //teem.sourceforge.net/nrrd/format.html#encoding (измените привет на http, чтобы перейти на страницу)
— «raw» — данные отображаются на диске точно так же, как и в памяти, с точки зрения значений байтов и порядка следования байтов. Производится методами write () и fwrite (), подходит для read () или fread ().

Информация о файле:
http://www.sci.utah.edu/~gk/DTI-data/gk2/gk2-rcc-mask.nhdr — Я думаю, что единственное, что здесь имеет значение, это обратный порядковый номер (все еще пытающийся понять, что это значит из Google) и грубое кодирование.

Мой текущий подход, не уверен, что это правильно:

 //Function ripped off from example of c++ ifstream::read reference page

void scantensor(string filename){
ifstream tdata(filename, ifstream::binary); // not sure if I should put ifstream::binary here

// other things I tried
// ifstream tdata(filename)  ifstream tdata(filename, ios::in)

if(tdata){
tdata.seekg(0, tdata.end);
int length = tdata.tellg();
tdata.seekg(0, tdata.beg);

char* buffer = new char[length];

tdata.read(buffer, length);

tdata.close();

double* d;
d = (double*) buffer;

} else cerr << "failed" << endl;
}

/*  P.S. I attempted to print the first 100 elements of the array.

Then I print 100 other elements at some arbitrary array indices (i.e. 9,900 - 10,000).  I actually kept increasing the number of 0's until I ran out of bound at 100,000,000 (I don't think that's how it works lol but I was just playing around to see what happens)

Here's the part that makes me suspicious: so the ifstream different has different constructors like the ones I tried above.

the first 100 values are always the same.

if I use ifstream::binary, then I get some values for the 100 arbitrary printing
if I use the other two options, then I get -6.27744e+066 for all 100 of them

So for now I am going to assume that ifstream::binary is the correct one.  The thing is, I am not sure if the file I provided is how binary files actually look like.  I am also unsure if these are the actual numbers that I am supposed to read in or just casting gone wrong.  I do realize that my casting from char* to double* can be unsafe, and I got that from one of the threads.

*/

Я очень ценю это!

Редактировать 1: Прямо сейчас данные, считываемые с использованием вышеуказанного метода, по-видимому, «неверны», так как в paraview значения:

Dxx,Dxy,Dxz,Dyy,Dyz,Dzz
[0, 1], [-15.4006, 13.2248], [-5.32436, 5.39517], [-5.32915, 5.96026], [-17.87, 19.0954], [-6.02961, 5.24771], [-13.9861, 14.0524]

It's a 3 x 3 symmetric matrix, so 7 distinct values, 7 ranges of values.

Поплавки, которые я сейчас анализирую из файла, очень велики (т.е. -4,68855e-229, -1,32351e + 120).

Может, кто-нибудь знает, как извлечь поплавки из Paraview?

0

Решение

Так как вы хотите работать с двойниками, я рекомендую читать данные из файла как буфер двойников:

const long machineMemory = 0x40000000; // 1 GB

FILE* file = fopen("c:\\data.bin", "rb");

if (file)
{
int size = machineMemory / sizeof(double);

if (size > 0)
{
double* data = new double[size];

int read(0);
while (read = fread(data, sizeof(double), size, file))
{
// Process data here (read = number of doubles)
}

delete [] data;
}

fclose(file);
}
0

Другие решения

Других решений пока нет …