[Paraview] Reading C-ordered data from hdf5

Dominik Szczerba dominik at itis.ethz.ch
Sat Aug 16 14:11:11 EDT 2008


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

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
>>>>>
>>>>>
>>>>
>>>
>>
> 

-- 
Dominik Szczerba, Ph.D.
Foundation for Research
on Information Technologies in Society
http://www.itis.ethz.ch


More information about the ParaView mailing list