[Paraview] Reading C-ordered data from hdf5

John R. Cary cary at txcorp.com
Sat Aug 16 17:44:33 EDT 2008


Dominik Szczerba wrote:
> There is no other way of reading C arrays into Fortran ordering than 
> ordering conversion, but it can be implemented optimally as an 
> in-place transpose (once already in memory) on the reader side. This 
> costs time, not storage. I so much hoped this would be a feature of 
> xdmf2 for example, it is one in my own home grown hdf5 Paraview 
> reader. --DS


So I guess what I could do is reorder my data pointer array, then set 
the pointer
of vtkDataArray to my pointer?

And I should be able to transpose by just swapping the fortran index
and C index locations, but then I have to figure out how to do it
just once.

Thanks....John Cary
>
> John R. Cary wrote:
>> Dominik Szczerba wrote:
>>> You will need SetArray method from the concrete implementation of 
>>> vtkDataArray. I could not quickly find in the source code any hints 
>>> about the underlying storage ordering, but it is trivial to find out 
>>> experimentally. Just post the results please. If it is the same as 
>>> yours no copying is needed.
>>>
>>
>> Well, I was unable to figure out how to get hdf5 to read the data
>> in by Fortran order, so I wrote the snippet below.  Sending by
>> request.
>>
>> This is probably slow, so better solutions always welcome.
>>
>> John Cary
>>
>> // The index tuple is initially zero
>>    size_t* indices = new size_t[rank];
>>    for(size_t k=0; k<rank; ++k) indices[k] = 0;
>> // Step through by global C index
>>    for(size_t k = 0; k<len; ++k) {
>> // Accumulate the Fortran index
>>      size_t indx = indices[rank-1];
>>      for(size_t j = 2; j<=rank; ++j) indx = indx*dims[rank-j] +
>>        indices[rank-j];
>> // Set the value in the VTK array at the Fortran index to the
>> // value in the C array at the C index
>>      if (H5Tequal(type, H5T_NATIVE_DOUBLE)) rv->SetTuple(indx,
>>        &((double*) data)[k]);
>>      if (H5Tequal(type, H5T_NATIVE_FLOAT)) rv->SetTuple(indx,
>>        &((float*) data)[k]);
>> // Update the index tuple
>>      size_t j = rank;
>>      do {
>>        --j;
>>        ++indices[j];
>>        if (indices[j] == dims[j]) indices[j] = 0;
>>        else break;
>>      } while (j != 0);
>>    }
>>
>>
>>
>>>>>
>>>>> John R. Cary wrote:
>>>>>> I have arrays written out from C into HDF5 using the HDF5 C
>>>>>> API, and so in the file the arrays are in C ordering.  I now
>>>>>> need to read them into VTK.  AFAICT, VTK is Fortran ordering,
>>>>>> even though it is written in C++.  So that means I need to
>>>>>> reverse the ordering.  Of course, I can write a loop to do
>>>>>> this, but is there some standard way that VTK folks do this?
>>>>>> I don't want to reinvent the wheel.
>>>>>>
>>>>>> Sorry for what is likely an elementary question, but I could
>>>>>> not find it on the FAQ or after googling quite a bit.
>>>>>>
>>>>>> Thanks so much......John Cary
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>



More information about the ParaView mailing list