1 #include "hdf.h"
2
3 #define FILE_NAME "Image_Chunked.hdf"
4 #define IMAGE_NAME "Image with Chunks"
5 #define X_LENGTH 10 /* number of rows in the image */
6 #define Y_LENGTH 6 /* number of columns in the image */
7 #define NCOMPS 3 /* number of components in the image */
8
main()9 int main( )
10 {
11 /************************* Variable declaration **************************/
12
13 intn status; /* status for functions returning an intn */
14 int32 file_id, /* HDF file identifier */
15 gr_id, /* GR interface identifier */
16 ri_id, /* raster image identifier */
17 dims[2], /* dimension sizes of the image array */
18 start[2], /* start position to read the image array */
19 edges[2], /* edges of read array */
20 interlace_mode; /* interlace mode of the image */
21 HDF_CHUNK_DEF chunk_def; /* Chunk defintion set */
22 int32 image_data[X_LENGTH][Y_LENGTH][NCOMPS];
23 int ii, jj;
24
25 /********************** End of variable declaration **********************/
26
27 /*
28 * Open the file for reading.
29 */
30 file_id = Hopen (FILE_NAME, DFACC_RDONLY, 0);
31
32 /*
33 * Initialize the GR interface.
34 */
35 gr_id = GRstart (file_id);
36
37 /*
38 * Open the raster image array.
39 */
40 ri_id = GRselect (gr_id, 0);
41
42 /*
43 * Set dimensions of the image.
44 */
45 dims[0] = X_LENGTH;
46 dims[1] = Y_LENGTH;
47 start[0] = start[1] = 0;
48 edges[0] = dims[0];
49 edges[1] = dims[1];
50
51 /* Read the data in the image array. */
52 status = GRreadimage (ri_id, start, NULL, edges, (VOIDP)image_data);
53
54 printf ("Image Data:\n");
55 printf ("Component 1:\n ");
56 for (ii=0; ii< X_LENGTH; ii++)
57 {
58 for (jj=0; jj< Y_LENGTH; jj++)
59 printf ("%i ",image_data[ii][jj][0]);
60 printf ("\n ");
61 }
62 printf ("\nComponent 2:\n ");
63 for (ii=0; ii< X_LENGTH; ii++)
64 {
65 for (jj=0; jj< Y_LENGTH; jj++)
66 printf ("%i ",image_data[ii][jj][1]);
67 printf ("\n ");
68 }
69 printf ("\nComponent 3:\n ");
70 for (ii=0; ii< X_LENGTH; ii++)
71 {
72 for (jj=0; jj< Y_LENGTH; jj++)
73 printf ("%i ",image_data[ii][jj][2]);
74 printf ("\n ");
75 }
76
77
78 printf ("\n");
79
80 /*
81 * Terminate access to the raster image and to the GR interface and,
82 * close the HDF file.
83 */
84 status = GRendaccess (ri_id);
85 status = GRend (gr_id);
86 status = Hclose (file_id);
87 return 0;
88 }
89
90