# xyz=C++, zyx=Fortran

**URL:** <https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299>\
**Category:** Hdf-forum archives\
**Created:** [June 5, 2009, 11:39am UTC](https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299 "2009-06-05T11:39:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jens](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@Jens](https://forum.hdfgroup.org/u/Jens)\
**Post date:** [June 5, 2009, 11:39am UTC](https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299/1 "2009-06-05T11:39:33Z")

</div>

Hi everyone,

if you create a 3d-array(i,j,k) and use HDF5-library to dump it to disk,  
it will look different depending on the application-language:

Fortran-App (=ZYX-style)  
&nbsp;&nbsp;[iii][iii][iii] [iii][iii][iii] [iii][iii][iii]  
[j][j][j]  
[k]

C/C++-App (=XYZ-style)  
&nbsp;&nbsp;[kkk][kkk][kkk] [kkk][kkk][kkk] [kkk][kkk][kkk]  
[j][j][j]  
[i]

Is there any possibility to tell hdf5 what array-style the application  
is using?  
The same way I can jump from little-endian- to big-endian-machines, I  
would like to jump from Fortran-Apps to C++Apps.

Greetings  
Jens

> **···**
>
> ----------------------------------------------------------------------  
> This mailing list is for HDF software users discussion.  
> To subscribe to this list, send a message to [hdf-forum-subscribe@hdfgroup.org](mailto:hdf-forum-subscribe@hdfgroup.org).  
> To unsubscribe, send a message to [hdf-forum-unsubscribe@hdfgroup.org](mailto:hdf-forum-unsubscribe@hdfgroup.org).

---

<div class="post-metadata">

**Author:** ![Dominik\_Szczerba](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@Dominik\_Szczerba](https://forum.hdfgroup.org/u/Dominik_Szczerba)\
**Post date:** [June 5, 2009, 12:37pm UTC](https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299/2 "2009-06-05T12:37:15Z")

</div>

I dont think it is possible. I help myself out with attributes to know the ordering.

Together with the missing compression support in the high level API, those two are the biggest shortcomings of the otherwise great hdf5 library.

-- DOminik

Jens wrote:

> **···**
>
> > Hi everyone,
> > 
> > if you create a 3d-array(i,j,k) and use HDF5-library to dump it to disk,  
> > it will look different depending on the application-language:
> > 
> > Fortran-App (=ZYX-style)  
> > &nbsp;&nbsp;[iii][iii][iii] [iii][iii][iii] [iii][iii][iii]  
> > [j][j][j]  
> > [k]
> > 
> > C/C++-App (=XYZ-style)  
> > &nbsp;&nbsp;[kkk][kkk][kkk] [kkk][kkk][kkk] [kkk][kkk][kkk]  
> > [j][j][j]  
> > [i]
> > 
> > Is there any possibility to tell hdf5 what array-style the application  
> > is using?  
> > The same way I can jump from little-endian- to big-endian-machines, I  
> > would like to jump from Fortran-Apps to C++Apps.
> > 
> > Greetings  
> > Jens
> > 
> > ----------------------------------------------------------------------  
> > This mailing list is for HDF software users discussion.  
> > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> 
> ----------------------------------------------------------------------  
> This mailing list is for HDF software users discussion.  
> To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

---

<div class="post-metadata">

**Author:** ![Ger\_van\_Diepen](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/g/6de8d8/32.png) [@Ger\_van\_Diepen](https://forum.hdfgroup.org/u/Ger_van_Diepen)\
**Post date:** [June 5, 2009, 1:08pm UTC](https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299/3 "2009-06-05T13:08:00Z")

</div>

We also have this problem.  
Data are always stored in C order in HDF5 files.  
In code where Fortran order is needed, the axes are reversed (thus data are not transposed).  
So Fortran code accesses data arrays as [x,y,z], and C++ (or numpy) code as [z,y,x]

Cheers,  
Ger

> > > Dominik Szczerba \<domi@vision.ee.ethz.ch\> 06/05/09 2:37 PM \>\>\>

I dont think it is possible. I help myself out with attributes to know  
the ordering.

Together with the missing compression support in the high level API,  
those two are the biggest shortcomings of the otherwise great hdf5 library.

-- DOminik

Jens wrote:

> **···**
>
> > Hi everyone,
> > 
> > if you create a 3d-array(i,j,k) and use HDF5-library to dump it to disk,  
> > it will look different depending on the application-language:
> > 
> > Fortran-App (=ZYX-style)  
> > &nbsp;&nbsp;[iii][iii][iii] [iii][iii][iii] [iii][iii][iii]  
> > [j][j][j]  
> > [k]
> > 
> > C/C++-App (=XYZ-style)  
> > &nbsp;&nbsp;[kkk][kkk][kkk] [kkk][kkk][kkk] [kkk][kkk][kkk]  
> > [j][j][j]  
> > [i]
> > 
> > Is there any possibility to tell hdf5 what array-style the application  
> > is using?  
> > The same way I can jump from little-endian- to big-endian-machines, I  
> > would like to jump from Fortran-Apps to C++Apps.
> > 
> > Greetings  
> > Jens
> > 
> > ----------------------------------------------------------------------  
> > This mailing list is for HDF software users discussion.  
> > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> 
> ----------------------------------------------------------------------  
> This mailing list is for HDF software users discussion.  
> To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> 
> ----------------------------------------------------------------------  
> This mailing list is for HDF software users discussion.  
> To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

---

<div class="post-metadata">

**Author:** ![werner](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@werner](https://forum.hdfgroup.org/u/werner)\
**Post date:** [June 5, 2009, 2:20pm UTC](https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299/4 "2009-06-05T14:20:51Z")

</div>

I remember that there had been plans to introduce this index ordering as  
a dataspace property in HDF5, such that for each dataspace one could tell  
whether it is Fortran or C ordering.

It probably didn't make it into an implementation due to lack of funding;  
it sounds quite complex to mix hyperslab operations between Fortran-ordering  
and C-ordering arrays.

While I originally stumbled across this problem myself as well some time  
ago, using Fortran convention arrays in my C/C++ code, it didn't turn out  
to be much of an issue. Only requirement is to carefully swap the number  
of axis when dealing with HDF5 dimensions, and do that consistently on  
all operations. The data itself don't need to be touched in any way, and  
the only drawback is that the dimensions of a dataset look reversed when  
using "h5ls". Once one got used to that, it's not a big deal. I have my  
own API on top of HDF5 now which deals with Fortran-convention arrays  
consistently (and also supports C-convention arrays via some attribute  
as well).

There was once also the idea of a "shared dataspace" that could be  
stored to a file like a "named datatype". That one could then carry  
attributes itself. Not sure if this shared dataspace ever was implemented,  
but if so, that would be a natural place to store such an ordering  
attribute. Or more general, would be a nice place to store the names  
of axis, like "X","Y","Z" versus "sagittal", "coronal", ... and  
eventually dimensions with them "T", "X" -\> "seconds", "metres".

&nbsp;&nbsp;Werner

> **···**
>
> On Fri, 05 Jun 2009 08:08:00 -0500, Ger van Diepen \<diepen@astron.nl\> wrote:
> 
> > We also have this problem.  
> > Data are always stored in C order in HDF5 files.  
> > In code where Fortran order is needed, the axes are reversed (thus data are not transposed).  
> > So Fortran code accesses data arrays as [x,y,z], and C++ (or numpy) code as [z,y,x]
> > 
> > Cheers,  
> > Ger
> > 
> > > > > Dominik Szczerba \<domi@vision.ee.ethz.ch\> 06/05/09 2:37 PM \>\>\>
> > 
> > I dont think it is possible. I help myself out with attributes to know  
> > the ordering.
> > 
> > Together with the missing compression support in the high level API,  
> > those two are the biggest shortcomings of the otherwise great hdf5 library.
> > 
> > -- DOminik
> > 
> > Jens wrote:
> > 
> > > Hi everyone,
> > > 
> > > if you create a 3d-array(i,j,k) and use HDF5-library to dump it to disk,  
> > > it will look different depending on the application-language:
> > > 
> > > Fortran-App (=ZYX-style)  
> > > &nbsp;&nbsp;[iii][iii][iii] [iii][iii][iii] [iii][iii][iii]  
> > > [j][j][j]  
> > > [k]
> > > 
> > > C/C++-App (=XYZ-style)  
> > > &nbsp;&nbsp;[kkk][kkk][kkk] [kkk][kkk][kkk] [kkk][kkk][kkk]  
> > > [j][j][j]  
> > > [i]
> > > 
> > > Is there any possibility to tell hdf5 what array-style the application  
> > > is using?  
> > > The same way I can jump from little-endian- to big-endian-machines, I  
> > > would like to jump from Fortran-Apps to C++Apps.
> > > 
> > > Greetings  
> > > Jens
> > > 
> > > ----------------------------------------------------------------------  
> > > This mailing list is for HDF software users discussion.  
> > > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> > 
> > ----------------------------------------------------------------------  
> > This mailing list is for HDF software users discussion.  
> > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> > 
> > ----------------------------------------------------------------------  
> > This mailing list is for HDF software users discussion.  
> > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> 
> --  
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Dr. Werner Benger \<werner@cct.lsu.edu\> Visualization Research  
> Laboratory for Creative Arts and Technology (LCAT)  
> Center for Computation & Technology at Louisiana State University (CCT/LSU)  
> 239 Johnston Hall, Baton Rouge, Louisiana 70803  
> Tel.: +1 225 578 4809 Fax.: +1 225 578-5362
> 
> ----------------------------------------------------------------------  
> This mailing list is for HDF software users discussion.  
> To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

---

<div class="post-metadata">

**Author:** ![Quincey\_Koziol](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/q/dbc845/32.png) [@Quincey\_Koziol](https://forum.hdfgroup.org/u/Quincey_Koziol)\
**Post date:** [June 5, 2009, 6:31pm UTC](https://forum.hdfgroup.org/t/xyz-c-zyx-fortran/1299/5 "2009-06-05T18:31:40Z")

</div>

> I remember that there had been plans to introduce this index ordering as  
> a dataspace property in HDF5, such that for each dataspace one could tell  
> whether it is Fortran or C ordering.
> 
> It probably didn't make it into an implementation due to lack of funding;  
> it sounds quite complex to mix hyperslab operations between Fortran-ordering  
> and C-ordering arrays.

&nbsp;&nbsp;Yes, you are correct on both accounts (we planned to do it and it was shelved due to lack of demand at the time and lack of funding).

> While I originally stumbled across this problem myself as well some time  
> ago, using Fortran convention arrays in my C/C++ code, it didn't turn out  
> to be much of an issue. Only requirement is to carefully swap the number  
> of axis when dealing with HDF5 dimensions, and do that consistently on  
> all operations. The data itself don't need to be touched in any way, and  
> the only drawback is that the dimensions of a dataset look reversed when  
> using "h5ls". Once one got used to that, it's not a big deal. I have my  
> own API on top of HDF5 now which deals with Fortran-convention arrays  
> consistently (and also supports C-convention arrays via some attribute  
> as well).

&nbsp;&nbsp;Yes, this seems to be how most people do it.

> There was once also the idea of a "shared dataspace" that could be  
> stored to a file like a "named datatype". That one could then carry  
> attributes itself. Not sure if this shared dataspace ever was implemented,  
> but if so, that would be a natural place to store such an ordering  
> attribute. Or more general, would be a nice place to store the names  
> of axis, like "X","Y","Z" versus "sagittal", "coronal", ... and  
> eventually dimensions with them "T", "X" -\> "seconds", "metres".

&nbsp;&nbsp;We have not moved forward on the shared dataspace idea, although it was tempting to implement when we were working on features to support the netCDF data model. I think it's still a good concept to put into code.

&nbsp;&nbsp;The names of axis, etc. can be set with the "dimension scales" high-level API though, which is available in the 1.8.x release series.

&nbsp;&nbsp;Quincey

> **···**
>
> On Jun 5, 2009, at 9:20 AM, Werner Benger wrote:
> 
> > &nbsp;&nbsp;Werner
> > 
> > On Fri, 05 Jun 2009 08:08:00 -0500, Ger van Diepen \> \<diepen@astron.nl\> wrote:
> > 
> > > We also have this problem.  
> > > Data are always stored in C order in HDF5 files.  
> > > In code where Fortran order is needed, the axes are reversed (thus data are not transposed).  
> > > So Fortran code accesses data arrays as [x,y,z], and C++ (or numpy) code as [z,y,x]
> > > 
> > > Cheers,  
> > > Ger
> > > 
> > > > > > Dominik Szczerba \<domi@vision.ee.ethz.ch\> 06/05/09 2:37 PM \>\>\>
> > > 
> > > I dont think it is possible. I help myself out with attributes to know  
> > > the ordering.
> > > 
> > > Together with the missing compression support in the high level API,  
> > > those two are the biggest shortcomings of the otherwise great hdf5 library.
> > > 
> > > -- DOminik
> > > 
> > > Jens wrote:
> > > 
> > > > Hi everyone,
> > > > 
> > > > if you create a 3d-array(i,j,k) and use HDF5-library to dump it to disk,  
> > > > it will look different depending on the application-language:
> > > > 
> > > > Fortran-App (=ZYX-style)  
> > > > [iii][iii][iii] [iii][iii][iii] [iii][iii][iii]  
> > > > [j][j][j]  
> > > > [k]
> > > > 
> > > > C/C++-App (=XYZ-style)  
> > > > [kkk][kkk][kkk] [kkk][kkk][kkk] [kkk][kkk][kkk]  
> > > > [j][j][j]  
> > > > [i]
> > > > 
> > > > Is there any possibility to tell hdf5 what array-style the application  
> > > > is using?  
> > > > The same way I can jump from little-endian- to big-endian-machines, I  
> > > > would like to jump from Fortran-Apps to C++Apps.
> > > > 
> > > > Greetings  
> > > > Jens
> > > > 
> > > > ----------------------------------------------------------------------  
> > > > This mailing list is for HDF software users discussion.  
> > > > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > > > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> > > 
> > > ----------------------------------------------------------------------  
> > > This mailing list is for HDF software users discussion.  
> > > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> > > 
> > > ----------------------------------------------------------------------  
> > > This mailing list is for HDF software users discussion.  
> > > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
> > 
> > --  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Dr. Werner Benger \<werner@cct.lsu.edu\> Visualization Research  
> > Laboratory for Creative Arts and Technology (LCAT)  
> > Center for Computation & Technology at Louisiana State University (CCT/LSU)  
> > 239 Johnston Hall, Baton Rouge, Louisiana 70803  
> > Tel.: +1 225 578 4809 Fax.: +1 225 578-5362
> > 
> > ----------------------------------------------------------------------  
> > This mailing list is for HDF software users discussion.  
> > To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> > To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
