1 #include "hdf.h"
2
3 #define FILE_NAME "General_RImages.hdf"
4 #define IMAGE_NAME "Image Array 2"
5 #define F_ATT1_NAME "File Attribute 1"
6 #define F_ATT2_NAME "File Attribute 2"
7 #define RI_ATT1_NAME "Image Attribute 1"
8 #define RI_ATT2_NAME "Image Attribute 2"
9 #define F_ATT1_VAL "Contents of First FILE Attribute"
10 #define F_ATT2_VAL "Contents of Second FILE Attribute"
11 #define F_ATT1_N_VALUES 32
12 #define F_ATT2_N_VALUES 33
13 #define RI_ATT1_VAL "Contents of IMAGE's First Attribute"
14 #define RI_ATT1_N_VALUES 35
15 #define RI_ATT2_N_VALUES 6
16
main()17 int main( )
18 {
19 /************************* Variable declaration **************************/
20
21 intn status; /* status for functions returning an intn */
22 int32 gr_id, ri_id, file_id,
23 ri_index;
24 int16 ri_attr_2[RI_ATT2_N_VALUES] = {1, 2, 3, 4, 5, 6};
25
26 /********************** End of variable declaration **********************/
27
28 /*
29 * Open the HDF file.
30 */
31 file_id = Hopen (FILE_NAME, DFACC_WRITE, 0);
32
33 /*
34 * Initialize the GR interface.
35 */
36 gr_id = GRstart (file_id);
37
38 /*
39 * Set two file attributes to the file with names, data types, numbers of
40 * values, and values of the attributes specified.
41 */
42 status = GRsetattr (gr_id, F_ATT1_NAME, DFNT_CHAR8, F_ATT1_N_VALUES,
43 (VOIDP)F_ATT1_VAL);
44
45 status = GRsetattr (gr_id, F_ATT2_NAME, DFNT_CHAR8, F_ATT2_N_VALUES,
46 (VOIDP)F_ATT2_VAL);
47
48 /*
49 * Obtain the index of the image named IMAGE_NAME.
50 */
51 ri_index = GRnametoindex (gr_id, IMAGE_NAME);
52
53 /*
54 * Obtain the identifier of this image.
55 */
56 ri_id = GRselect (gr_id, ri_index);
57
58 /*
59 * Set two attributes to the image with names, data types, numbers of
60 * values, and values of the attributes specified.
61 */
62 status = GRsetattr (ri_id, RI_ATT1_NAME, DFNT_CHAR8, RI_ATT1_N_VALUES,
63 (VOIDP)RI_ATT1_VAL);
64
65 status = GRsetattr (ri_id, RI_ATT2_NAME, DFNT_INT16, RI_ATT2_N_VALUES,
66 (VOIDP)ri_attr_2);
67
68 /*
69 * Terminate access to the image and to the GR interface, and close the
70 * HDF file.
71 */
72 status = GRendaccess (ri_id);
73 status = GRend (gr_id);
74 status = Hclose (file_id);
75 return 0;
76 }
77