summaryrefslogtreecommitdiffstats
path: root/examples/h5_compound.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-10-01 14:04:36 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-10-01 14:04:36 (GMT)
commitf1ba03cea5b82699a984c80bd2deac14fdc8df18 (patch)
treeebe777c3e0b83f4c4cec9212731da9ebe0a0cfd3 /examples/h5_compound.c
parent10343c197906415388f2a4c8d292e21d25cf7381 (diff)
downloadhdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.zip
hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.gz
hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.bz2
Source formatted
Diffstat (limited to 'examples/h5_compound.c')
-rw-r--r--examples/h5_compound.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/examples/h5_compound.c b/examples/h5_compound.c
index b3b3a4a..6b4888e 100644
--- a/examples/h5_compound.c
+++ b/examples/h5_compound.c
@@ -19,10 +19,10 @@
#include "hdf5.h"
-#define H5FILE_NAME "SDScompound.h5"
-#define DATASETNAME "ArrayOfStructures"
-#define LENGTH 10
-#define RANK 1
+#define H5FILE_NAME "SDScompound.h5"
+#define DATASETNAME "ArrayOfStructures"
+#define LENGTH 10
+#define RANK 1
int
main(void)
@@ -30,38 +30,37 @@ main(void)
/* First structure and dataset*/
typedef struct s1_t {
- int a;
- float b;
- double c;
+ int a;
+ float b;
+ double c;
} s1_t;
- s1_t s1[LENGTH];
- hid_t s1_tid; /* File datatype identifier */
+ s1_t s1[LENGTH];
+ hid_t s1_tid; /* File datatype identifier */
/* Second structure (subset of s1_t) and dataset*/
typedef struct s2_t {
- double c;
- int a;
+ double c;
+ int a;
} s2_t;
- s2_t s2[LENGTH];
- hid_t s2_tid; /* Memory datatype handle */
+ s2_t s2[LENGTH];
+ hid_t s2_tid; /* Memory datatype handle */
/* Third "structure" ( will be used to read float field of s1) */
- hid_t s3_tid; /* Memory datatype handle */
- float s3[LENGTH];
-
- int i;
- hid_t file, dataset, space; /* Handles */
- herr_t status;
- hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
+ hid_t s3_tid; /* Memory datatype handle */
+ float s3[LENGTH];
+ int i;
+ hid_t file, dataset, space; /* Handles */
+ herr_t status;
+ hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
/*
* Initialize the data
*/
- for (i = 0; i< LENGTH; i++) {
+ for (i = 0; i < LENGTH; i++) {
s1[i].a = i;
- s1[i].b = i*i;
- s1[i].c = 1./(i+1);
+ s1[i].b = i * i;
+ s1[i].c = 1. / (i + 1);
}
/*
@@ -77,7 +76,7 @@ main(void)
/*
* Create the memory data type.
*/
- s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
+ s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
@@ -126,12 +125,14 @@ main(void)
*/
printf("\n");
printf("Field c : \n");
- for( i = 0; i < LENGTH; i++) printf("%.4f ", s2[i].c);
+ for (i = 0; i < LENGTH; i++)
+ printf("%.4f ", s2[i].c);
printf("\n");
printf("\n");
printf("Field a : \n");
- for( i = 0; i < LENGTH; i++) printf("%d ", s2[i].a);
+ for (i = 0; i < LENGTH; i++)
+ printf("%d ", s2[i].a);
printf("\n");
/*
@@ -151,7 +152,8 @@ main(void)
*/
printf("\n");
printf("Field b : \n");
- for( i = 0; i < LENGTH; i++) printf("%.4f ", s3[i]);
+ for (i = 0; i < LENGTH; i++)
+ printf("%.4f ", s3[i]);
printf("\n");
/*