1 #include "hdf.h"
2
3 #define FILE_NAME "General_Vdatas.hdf"
4 #define N_RECORDS 10 /* number of records the vdata contains */
5 #define ORDER_1 3 /* order of first field */
6 #define ORDER_2 1 /* order of second field */
7 #define ORDER_3 2 /* order of third field */
8 #define CLASS_NAME "Particle Data"
9 #define VDATA_NAME "Solid Particle"
10 #define FIELD1_NAME "Position" /* contains x, y, z values */
11 #define FIELD2_NAME "Mass" /* contains weight values */
12 #define FIELD3_NAME "Temperature" /* contains min and max values */
13 #define FIELDNAME_LIST "Position,Mass,Temperature" /* No spaces b/w names */
14
15 /* number of values per record */
16 #define N_VALS_PER_REC (ORDER_1 + ORDER_2 + ORDER_3)
17
main()18 int main( )
19 {
20 /************************* Variable declaration **************************/
21
22 intn status_n; /* returned status for functions returning an intn */
23 int32 status_32, /* returned status for functions returning an int32 */
24 file_id, vdata_id,
25 vdata_ref = -1, /* ref number of a vdata, set to -1 to create */
26 num_of_records; /* number of records actually written to vdata */
27 int16 rec_num; /* current record number */
28 float32 data_buf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
29
30 /********************** End of variable declaration **********************/
31
32 /*
33 * Open the HDF file for writing.
34 */
35 file_id = Hopen (FILE_NAME, DFACC_WRITE, 0);
36
37 /*
38 * Initialize the VS interface.
39 */
40 status_n = Vstart (file_id);
41
42 /*
43 * Create a new vdata.
44 */
45 vdata_id = VSattach (file_id, vdata_ref, "w");
46
47 /*
48 * Set name and class name of the vdata.
49 */
50 status_32 = VSsetname (vdata_id, VDATA_NAME);
51 status_32 = VSsetclass (vdata_id, CLASS_NAME);
52
53 /*
54 * Introduce each field's name, data type, and order. This is the first
55 * part in defining a field.
56 */
57 status_n = VSfdefine (vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER_1 );
58 status_n = VSfdefine (vdata_id, FIELD2_NAME, DFNT_FLOAT32, ORDER_2 );
59 status_n = VSfdefine (vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER_3 );
60
61 /*
62 * Finalize the definition of the fields.
63 */
64 status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
65
66 /*
67 * Buffer the data by the record for fully interlaced mode. Note that the
68 * first three elements contain the three values of the first field, the
69 * fourth element contains the value of the second field, and the last two
70 * elements contain the two values of the third field.
71 */
72 for (rec_num = 0; rec_num < N_RECORDS; rec_num++)
73 {
74 data_buf[rec_num][0] = 1.0 * rec_num;
75 data_buf[rec_num][1] = 2.0 * rec_num;
76 data_buf[rec_num][2] = 3.0 * rec_num;
77 data_buf[rec_num][3] = 0.1 + rec_num;
78 data_buf[rec_num][4] = 0.0;
79 data_buf[rec_num][5] = 65.0;
80 }
81
82 /*
83 * Write the data from data_buf to the vdata with full interlacing mode.
84 */
85 num_of_records = VSwrite (vdata_id, (uint8 *)data_buf, N_RECORDS,
86 FULL_INTERLACE);
87
88 /*
89 * Terminate access to the vdata and to the VS interface, then close
90 * the HDF file.
91 */
92 status_32 = VSdetach (vdata_id);
93 status_n = Vend (file_id);
94 status_32 = Hclose (file_id);
95 return 0;
96 }
97