Werner
That example creates a 2D dataset, and attaches one dimension scale to each
one of its dimensions.
Every time you attach a dimension scale to a dataset, an attribute called
"REFERENCE_LIST" is either created or updated on the dimension scale
dataset. It contains an array of a compound type with 2 fields: a reference
to the dataset that the dimension scale is attached to, and which dimension
it is attached to.
So, this call in the example
/* attach the DS_1_NAME dimension scale to DSET_NAME at dimension index 0 */
if (H5DSattach_scale(did,dsid,DIM0)<0)
goto out;
creates this attribute in the "Yaxis" dimension scale, shown here by h5dump
(in the DATA section, 800 is the reference of the dataset "Mydata", and 0 is
the dimension index it is attached to)
ATTRIBUTE "REFERENCE_LIST" {
DATATYPE H5T_COMPOUND {
H5T_REFERENCE "dataset";
H5T_STD_I32LE "dimension";
}
DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
DATA {
(0): {
DATASET 800 /Mydata ,
0
}
}
}
It is possible to share the same dimension scale between multiple datasets.
From that example, you would have to do something like
Create another dataset, here called DSET_NAME2
if (H5LTmake_dataset_int(fid,DSET_NAME2,rank,dims,buf)<0)
goto out;
Open the IDs for the dataset DSET_NAME2 and the "Yaxis" dimension scale as
shown in the example code and then attach them with
/* attach the DS_1_NAME dimension scale to DSET_NAME2 at dimension index 0
*/
if (H5DSattach_scale(did,dsid,DIM0)<0)
goto out;
If you open the generated file in h5dump , you'll see that "REFERENCE_LIST"
has another entry to the new dataset "Mydata2"
ATTRIBUTE "REFERENCE_LIST" {
DATATYPE H5T_COMPOUND {
H5T_REFERENCE "dataset";
H5T_STD_I32LE "dimension";
}
DATASPACE SIMPLE { ( 2 ) / ( 2 ) }
DATA {
(0): {
DATASET 800 /Mydata ,
0
},
(1): {
DATASET 1400 /Mydata2 ,
0
}
}
}
There is another attribute that is created or updated every time you call
H5DSattach_scale. It is created on the dataset and it is called
"DIMENSION_LIST". It has as many entries as the rank of the dataset (In this
case, it has 2 entries because the dataset is 2D). Each entry is a variable
length array of references. This is because it is also possible for a
dimension of a dataset to be associated with *several* dimension scales. At
each time, there is one "current" dimension scale associated, but it is
possible to later choose another (to display in a visualization program, for
example).
Here's the h5dump output of this attribute on the DATASET "Mydata"
ATTRIBUTE "DIMENSION_LIST" {
DATATYPE H5T_VLEN { H5T_REFERENCE}
DATASPACE SIMPLE { ( 2 ) / ( 2 ) }
DATA {
(0): (DATASET 1672 /Yaxis ), (DATASET 4096 /Xaxis )
}
Suppose you want to associate the index 0 of the dataset with another
dimension scale. I modified the example with this code
Define a name for the new dimension scale
#define DS_3_NAME "Yaxis_other"
Define an array of values
float s3_wbuf[DIM1_SIZE] = {10,60,90}; /* data of DS 3
dataset */
Create a dataset for this dimension scale
/* make a DS dataset for the third dimension */
if (H5LTmake_dataset_float(fid,DS_3_NAME,rankds,s1_dim,s3_wbuf)<0)
goto out;
and attach them as before, after getting the IDs (I send you the complete
example as attached file).
Now, h5dump shows that index 0 of "DIMENSION_LIST" has a new entry
ATTRIBUTE "DIMENSION_LIST" {
DATATYPE H5T_VLEN { H5T_REFERENCE}
DATASPACE SIMPLE { ( 2 ) / ( 2 ) }
DATA {
(0): (DATASET 1672 /Yaxis , DATASET 4368 /Yaxis_other ),
(1): (DATASET 4096 /Xaxis )
}
Now the fun part is to use a visualization program to see the differences in
bitmaps generated from the dataset "Mydata"
HDF Explorer allows to choose between dimension scales if several are
attached to one dimension index of a dataset.
HDF Explorer is available here
http://www.space-research.org/
Open the file generated by the example, attached here. Right click on the
dataset "Mydata" and choose "Discrete Map View". Note that the *first*
dimension scale associated with index 0 of the dataset was used, the "Yaxis"
dataset, which was defined as an array of
float s1_wbuf[DIM1_SIZE] = {10,20,30}; /* data of DS 1
dataset */
Now, you can choose to use "Yaxis_other" instead for the Y axis. Right click
on the dataset "Mydata" and choose "Scale selection". A dialog box shows up
Click on the "dimensions" box, and you'll see that the "available dimension
scales" box shows all dimensions that are associated with the *selected"
index on the "dimensions" box. Here, there are two (HDF Explorer only shows
the reference number). Choose the second and close the dialog box and do a
new map as previously
Now the map is different, instead of the evenly spaced "Yaxis" dimension
scale, we get the new "Yaxis_other" as a basis for the map generation (the
map is just a translation of each value of the dataset into a color, the
squares you see correspond each one to one data value).
Attached is the modified example and the hdf5 generated file.
Pedro
----- Original Message -----
From: "Werner Benger" <werner@cct.lsu.edu>
To: <hdf-forum@hdfgroup.org>
Sent: Tuesday, August 04, 2009 10:58 PM
Subject: [Hdf-forum] Can Dimension Scales be shared among datasets?
Looking at the dimension scale API
http://www.hdfgroup.org/HDF5/doc/HL/RM_H5DS.html
(btw., the pdf linked from this page is non-existent)
and the example program at
http://www.hdfgroup.org/HDF5/Tutor/h5dimscale.html
I wonder if it's possible to share the same dimension scale (i.e. its
datasets) between multiple datasets?
It won't be too uncommon to have many datasets with the same coordinates
attached. However, the dimension scale datasets seem to include a
reference
to specific dataset, like an h5ls of the example HDF5 file shows:
/Xaxis Dataset {4/4}
Attribute: CLASS scalar
Type: 16-byte null-terminated ASCII string
Data: "DIMENSION_SCALE"
Attribute: REFERENCE_LIST {1}
Type: struct {
"dataset" +0 object reference
"dimension" +8 native int
} 16 bytes
Data: {DATASET-1:800, 1}
Location: 1:1672
Links: 1
Storage: 16 logical bytes, 16 allocated bytes, 100.00% utilization
Type: native int
So it seems in this example the Xaxis dataset is bound to the dataset
DATASET-1:800 and another dataset with the same Xaxis would need to
replicate the same dimension scales.
Or can the dimension scale API handle sharing? It seems to be bound to
the dataspace, which cannot be shared among datasets (though I remember
there had been plans to implement such).
Another, related question - the DS API associates one dataset with
each dimension. Can it also be used to associate one dataset with *all*
dimensions? For instance, providing a two-dimensional dataset of (x,y)
coordinates as dimension scale for a two-dimensional dataset of data.
Werner
--
___________________________________________________________________________
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
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org