File: GR_write_chunks.c

package info (click to toggle)
libhdf4 4.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,384 kB
  • sloc: ansic: 128,700; sh: 15,015; fortran: 12,444; java: 5,863; xml: 1,205; makefile: 794; yacc: 678; pascal: 418; perl: 360; javascript: 203; lex: 163; csh: 41
file content (99 lines) | stat: -rw-r--r-- 3,012 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>

#include "hdf.h"

#define FILE_NAME  "Image_Chunked.hdf"
#define IMAGE_NAME "Image with Chunks"
#define X_LENGTH   10 /* number of rows in the image */
#define Y_LENGTH   6  /* number of columns in the image */
#define NCOMPS     3  /* number of components in the image */

int
main()
{
    /************************* Variable declaration **************************/

    int32 file_id,           /* HDF file identifier */
        gr_id,               /* GR interface identifier */
        ri_id,               /* raster image identifier */
        dims[2],             /* dimension sizes of the image array */
        origin[2];           /* origin position to write each chunk */
    HDF_CHUNK_DEF chunk_def; /* Chunk definition set */
    int32         chunk00[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};

    int32 chunk01[] = {210, 211, 212, 220, 221, 222, 230, 231, 232,
                       240, 241, 242, 250, 251, 252, 260, 261, 262};

    int32 chunk14[] = {1010, 1011, 1012, 1020, 1021, 1022, 1030, 1031, 1032,
                       1040, 1041, 1042, 1050, 1051, 1052, 1060, 1061, 1062};

    /********************** End of variable declaration **********************/

    /*
     * Create and open the file.
     */
    if ((file_id = Hopen(FILE_NAME, DFACC_CREATE, 0)) == FAIL)
        printf("*** ERROR from Hopen\n");

    /*
     * Initialize the GR interface.
     */
    gr_id = GRstart(file_id);

    /*
     * Set dimensions of the image.
     */
    dims[0] = Y_LENGTH;
    dims[1] = X_LENGTH;

    /*
     * Create the raster image array.
     */
    ri_id = GRcreate(gr_id, IMAGE_NAME, NCOMPS, DFNT_INT32, MFGR_INTERLACE_PIXEL, dims);
    /*
     * Define chunked image.
     */
    chunk_def.comp.comp_type           = COMP_CODE_DEFLATE;
    chunk_def.comp.cinfo.deflate.level = 6;
    chunk_def.comp.chunk_lengths[0]    = 3;
    chunk_def.comp.chunk_lengths[1]    = 2;
    if (GRsetchunk(ri_id, chunk_def, HDF_CHUNK | HDF_COMP) == FAIL)
        printf("*** ERROR from GRsetchunk\n");

    /*
     * Write first chunk(0,0).
     */
    origin[0] = 0;
    origin[1] = 0;
    if (GRwritechunk(ri_id, origin, (void *)chunk00) == FAIL)
        printf("*** ERROR from GRwritechunk\n");

    /*
     * Write second chunk(0,1).
     */
    origin[0] = 0;
    origin[1] = 1;
    if (GRwritechunk(ri_id, origin, (void *)chunk01) == FAIL)
        printf("*** ERROR from GRwritechunk\n");

    /*
     * Write third chunk(1,4).
     */
    origin[0] = 1;
    origin[1] = 4;
    if (GRwritechunk(ri_id, origin, (void *)chunk14) == FAIL)
        printf("*** ERROR from GRwritechunk\n");

    /*
     * Terminate access to the raster image and to the GR interface and,
     * close the HDF file.
     */
    if (GRendaccess(ri_id) == FAIL)
        printf("*** ERROR from GRendaccess\n");
    if (GRend(gr_id) == FAIL)
        printf("*** ERROR from GRend\n");
    if (Hclose(file_id) == FAIL)
        printf("*** ERROR from Hclose\n");

    return 0;
}