Esempio n. 1
0
int init_output_sds(int32 sd_id, unsigned char *process, SDS outsds[Nbands], SDS sds[Nitems],
	int gzip, int verbose)
{
	int ib;
	int32 dim_id;
	char *dimname1, *dimname2;

	HDF_CHUNK_DEF chunk_def;


	/* same fill value will be used for all output SDSs */
	static int16 fillvalue = FILL_INT16;

	/* band naming convention will be "CorrRefl_XX"
	(11 characters + terminating null) */
	char name[16];


	/* write SDS-specific attributes and dimension names */
	for (ib = 0; ib < Nbands; ib++) {
		if (!process[ib]) continue;

		outsds[ib].num_type = DFNT_INT16;
		outsds[ib].factor = 0.0001;
		outsds[ib].offset = 0;
		outsds[ib].rank = 2;

		sprintf(name, "CorrRefl_%2.2d", ib + 1);
		if ( !(outsds[ib].name = strdup(name)) ) return 1;

		outsds[ib].Nl = outsds[ib].dim_sizes[0] = sds[ib].Nl;
		outsds[ib].Np = outsds[ib].dim_sizes[1] = sds[ib].Np;
		outsds[ib].rowsperscan = sds[ib].rowsperscan;
		if (verbose)
			printf("Creating SDS %s: %dx%d\n", outsds[ib].name,
				outsds[ib].Np, outsds[ib].Nl);
		if ((outsds[ib].id = SDcreate(sd_id, outsds[ib].name, outsds[ib].num_type, outsds[ib].rank,
				outsds[ib].dim_sizes)) == -1) {
			fprintf(stderr, "Cannot create SDS %s\n", outsds[ib].name);
			return 1;
			}

		outsds[ib].fillvalue = &fillvalue;
		if ( SDsetfillvalue(outsds[ib].id, outsds[ib].fillvalue) ) {
			fprintf(stderr, "Cannot write fill value of SDS %s\n", outsds[ib].name);
			return 1;
			}
		if ( SDsetattr(outsds[ib].id, "scale_factor", DFNT_FLOAT64, 1, &outsds[ib].factor) == -1  ||
			SDsetattr(outsds[ib].id, "add_offset",   DFNT_FLOAT64, 1, &outsds[ib].offset) == -1 ) {
			fprintf(stderr, "Cannot write scale factor and offset of SDS \"%s\"\n",  outsds[ib].name);
			return 1;
			}
		if ( SDsetattr(outsds[ib].id, "units", DFNT_CHAR8, 4, "none") == -1 ) {
			fprintf(stderr, "Cannot write units attribute of SDS \"%s\"\n",  outsds[ib].name);
			return 1;
			}

		/* set dimensions */
		outsds[ib].start[1] = 0;
		outsds[ib].edges[0] = outsds[ib].rowsperscan;
		outsds[ib].edges[1] = outsds[ib].Np;

		/* allocate memory for band output data */
		outsds[ib].data = malloc(outsds[ib].rowsperscan * outsds[ib].Np * DFKNTsize(outsds[ib].num_type));
		if (!outsds[ib].data) {
			fputs("Error allocating memory.\n", stderr);
			return 1;
			}

		/* set optional compression */
		if (gzip) {
			chunk_def.chunk_lengths[0] = chunk_def.comp.chunk_lengths[0] = outsds[ib].edges[0];
			chunk_def.chunk_lengths[1] = chunk_def.comp.chunk_lengths[1] = outsds[ib].edges[1];
			chunk_def.comp.comp_type = COMP_CODE_DEFLATE;
			chunk_def.comp.cinfo.deflate.level = 4;
			if (SDsetchunk(outsds[ib].id, chunk_def, HDF_CHUNK | HDF_COMP) == FAIL) {
				fprintf(stderr, "Cannot set chunks for SDS %s\n", outsds[ib].name);
				return 1;
				}
			}


		set_dimnames(outsds[ib].Np, &dimname1, &dimname2);

if (verbose) printf("(%s x %s)\n", dimname1, dimname2);

		/* dimension names */
		if ((dim_id = SDgetdimid(outsds[ib].id, 0)) == -1) {
			fputs("Error getting dimension ID1.\n", stderr);
			return 1;
			}
		if (SDsetdimname(dim_id, dimname1) == -1) {
			fprintf(stderr, "Cannot set first dimension name for SDS %s\n", outsds[ib].name);
			return 1;
			}
		if ((dim_id = SDgetdimid(outsds[ib].id, 1)) == -1) {
			fputs("Error getting dimension ID2.\n", stderr);
			return 1;
			}
		if (SDsetdimname(dim_id, dimname2) == -1) {
			fprintf(stderr, "Cannot set second dimension name for SDS %s\n", outsds[ib].name);
			return 1;
			}
		}

	return 0;
}
Esempio n. 2
0
static intn test_szip_chunk_3d()
{
    /************************* Variable declaration **************************/

    int32         sd_id, sds_id0, sds_id, sds_index;
    intn          status;
    int32         dim_sizes[3];
    HDF_CHUNK_DEF c_def; /* Chunking definitions */ 
    HDF_CHUNK_DEF c_def_out; /* Chunking definitions */ 
    int32         c_flags, c_flags_out;
    int32         start[3], edges[3];
    int16         fill_value = 0;   /* Fill value */
    comp_coder_t  comp_type;        /* to retrieve compression type into */
    comp_info     cinfo;            /* compression information structure */
    int    	  num_errs = 0;     /* number of errors so far */
    int           i,j,k;

    for (i = 0; i < SDS_DIM0; i++) {
	for (j = 0; j < SDS_DIM1; j++) {
	    for (k = 0; k < SDS_DIM2; k++) {
		out_data[i][j][k] = i*100+j*10+k;
    }}}

    /* Initialize chunk lengths. */
    c_def.comp.chunk_lengths[0] = CHK_DIM0;
    c_def.comp.chunk_lengths[1] = CHK_DIM1;
    c_def.comp.chunk_lengths[2] = CHK_DIM2;

    /* Create the file and initialize SD interface. */
    sd_id = SDstart (FILE_NAME_3D, DFACC_CREATE);
    CHECK(sd_id, FAIL, "SDstart");

    /* Create SDS_DIM0xSDS_DIM1 SDS. */
    dim_sizes[0] = SDS_DIM0;
    dim_sizes[1] = SDS_DIM1;
    dim_sizes[2] = SDS_DIM2;
    sds_id = SDcreate (sd_id, SDS_NAME_CH3D, DFNT_INT16, RANK_CH3, dim_sizes);
    CHECK(sds_id, FAIL, "SDcreate:Failed to create a data set for chunking/szip compression testing");

    /* Create a similar SDS and will make it chunked, but will not 
       write data to it */
    sds_id0 = SDcreate (sd_id, SDS_NAME_CH0, DFNT_INT16, RANK_CH3, dim_sizes);
    CHECK(sds_id0, FAIL, "SDcreate:Failed to create a data set for chunking/szip compression testing");

    /* Fill the SDS array with the fill value. */
    status = SDsetfillvalue (sds_id, (VOIDP)&fill_value);
    CHECK(status, FAIL, "SDsetfillvalue");

    /* Set parameters for Chunking/SZIP */
    c_def.comp.comp_type = COMP_CODE_SZIP;
    c_def.comp.cinfo.szip.pixels_per_block = 2;

    c_def.comp.cinfo.szip.options_mask = SZ_EC_OPTION_MASK;
    c_def.comp.cinfo.szip.options_mask |= SZ_MSB_OPTION_MASK;
    c_def.comp.cinfo.szip.bits_per_pixel = 2;
    c_def.comp.cinfo.szip.pixels = 16;
    c_def.comp.cinfo.szip.pixels_per_scanline = 2;
    c_flags = HDF_CHUNK | HDF_COMP;
    status = SDsetchunk (sds_id0, c_def, c_flags);
    status = SDsetchunk (sds_id, c_def, c_flags);
    CHECK(status, FAIL, "SDsetchunk");

    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    edges[0] = SDS_DIM0;
    edges[1] = SDS_DIM1;
    edges[2] = SDS_DIM2;
    status = SDwritedata (sds_id, start, NULL, edges, (VOIDP) out_data); 
    CHECK(status, FAIL, "SDwritedata");

    HDmemset(&c_def_out, 0, sizeof(HDF_CHUNK_DEF));
    c_flags_out = 0;
    status = SDgetchunkinfo(sds_id0, &c_def_out, &c_flags_out);
    CHECK(status, FAIL, "SDgetchunkinfo");
    VERIFY(c_flags_out, c_flags, "SDgetchunkinfo");
    VERIFY(c_def_out.comp.comp_type, COMP_CODE_SZIP, "SDgetchunkinfo");

    HDmemset(&c_def_out, 0, sizeof(HDF_CHUNK_DEF));
    c_flags_out = 0;
    status = SDgetchunkinfo(sds_id, &c_def_out, &c_flags_out);
    CHECK(status, FAIL, "SDgetchunkinfo");
    VERIFY(c_flags_out, c_flags, "SDgetchunkinfo");
    VERIFY(c_def_out.comp.comp_type, COMP_CODE_SZIP, "SDgetchunkinfo");

    /* Terminate access to the data sets. */
    status = SDendaccess (sds_id0);
    CHECK(status, FAIL, "SDendaccess");

    status = SDendaccess (sds_id);
    CHECK(status, FAIL, "SDendaccess");

    /* Terminate access to the SD interface and close the file. */
    status = SDend (sd_id);
    CHECK(status, FAIL, "SDend");

    /*
     * Verify the compressed data
     */

    /* Reopen the file and access the first data set. */
    sd_id = SDstart (FILE_NAME_3D, DFACC_READ);
    sds_index = 0;
    sds_id = SDselect (sd_id, sds_index);
    CHECK(sds_id, FAIL, "SDselect:Failed to select a data set for chunking/szip compression testing");

    /* Retrieve compression information about the dataset */
    comp_type = COMP_CODE_INVALID;  /* reset variables before retrieving info */
    HDmemset(&cinfo, 0, sizeof(cinfo)) ;

    status = SDgetcompinfo(sds_id, &comp_type, &cinfo);
    CHECK(status, FAIL, "SDgetcompinfo");
    VERIFY(comp_type, COMP_CODE_SZIP, "SDgetcompinfo");

    /* Retrieve compression method alone from the dataset */
    comp_type = COMP_CODE_INVALID;  /* reset variables before retrieving info */
    status = SDgetcomptype(sds_id, &comp_type);
    CHECK(status, FAIL, "SDgetcomptype");
    VERIFY(comp_type, COMP_CODE_SZIP, "SDgetcomptype");

    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    edges[0] = SDS_DIM0;
    edges[1] = SDS_DIM1;
    edges[2] = SDS_DIM2;
    status = SDreaddata (sds_id, start, NULL, edges, (VOIDP)all_data);
    CHECK(status, FAIL, "SDreaddata");

    for (i = 0; i < SDS_DIM0; i++) {
	for (j = 0; j < SDS_DIM1; j++) {
	    for (k = 0; k < SDS_DIM2; k++) {
	    if (out_data[i][j][k] != all_data[i][j][k])
	    {
		fprintf(stderr,"Bogus val in loc [%d][%d][%d] want %ld got %ld\n", i, j,k, out_data[i][j][k], all_data[i][j][k]);
		num_errs++;
	    }
	    }
	}
    }

    /* Terminate access to the data set. */
    status = SDendaccess (sds_id);
    CHECK(status, FAIL, "SDendaccess");

    /* Terminate access to the SD interface and close the file. */
    status = SDend (sd_id);
    CHECK(status, FAIL, "SDend");

    /* Return the number of errors that's been kept track of so far */
    return num_errs;
}   /* test_szip_chunk_3D */ 
Esempio n. 3
0
static intn test_szip_chunk()
{
   /************************* Variable declaration **************************/

   int32         sd_id, sds_id, sds_index;
   intn          status;
   int32         flag, maxcache, new_maxcache;
   int32         dim_sizes[2], origin[2];
   HDF_CHUNK_DEF c_def; /* Chunking definitions */ 
   HDF_CHUNK_DEF c_def_out; /* Chunking definitions */ 
   int32         c_flags, c_flags_out;
   int32         all_data[LENGTH_CH][WIDTH_CH];
   int32         start[2], edges[2];
   int32	 comp_size=0, uncomp_size=0;
   int32         chunk_out[CLENGTH][CWIDTH];
   int32         row[CWIDTH] = { 5, 5 };
   int32         column[CLENGTH] = { 4, 4, 4 };
   int32         fill_value = 0;   /* Fill value */
   comp_coder_t  comp_type;        /* to retrieve compression type into */
   comp_info     cinfo;            /* compression information structure */
   int    	 num_errs = 0;     /* number of errors so far */
   int           i,j;

   /*
   * Define all chunks.  Note that chunks 4 & 5 are not used to write,
   * only to verify the read data.  The 'row' and 'column' are used
   * to write in the place of these chunks.
   */
          int32 chunk1[CLENGTH][CWIDTH] = { 1, 1,
                                            1, 1,
                                            1, 1 }; 

          int32 chunk2[CLENGTH][CWIDTH] = { 2, 2,
                                            2, 2,
                                            2, 2 }; 

          int32 chunk3[CLENGTH][CWIDTH] = { 3, 3,
                                            3, 3,
                                            3, 3 }; 

          int32 chunk4[CLENGTH][CWIDTH] = { 0, 4,
                                            0, 4,
                                            0, 4 }; 

          int32 chunk5[CLENGTH][CWIDTH] = { 0, 0,
                                            5, 5,
                                            0, 0 }; 

          int32 chunk6[CLENGTH][CWIDTH] = { 6, 6,
                                            6, 6,
                                            6, 6 };


    /* Initialize chunk lengths. */
    c_def.comp.chunk_lengths[0] = CLENGTH;
    c_def.comp.chunk_lengths[1] = CWIDTH;

    /* Create the file and initialize SD interface. */
    sd_id = SDstart (FILE_NAME, DFACC_CREATE);
    CHECK(sd_id, FAIL, "SDstart");

    /* Create LENGTH_CHxWIDTH_CH SDS. */
    dim_sizes[0] = LENGTH_CH;
    dim_sizes[1] = WIDTH_CH;
    sds_id = SDcreate (sd_id, SDS_NAME_CH,DFNT_INT32, RANK_CH, dim_sizes);
    CHECK(sds_id, FAIL, "SDcreate:Failed to create a data set for chunking/szip compression testing");

    /* Fill the SDS array with the fill value. */
    status = SDsetfillvalue (sds_id, (VOIDP)&fill_value);
    CHECK(status, FAIL, "SDsetfillvalue");

    /* Set parameters for Chunking/SZIP */
    c_def.comp.comp_type = COMP_CODE_SZIP;
    c_def.comp.cinfo.szip.pixels_per_block = 2;

    c_def.comp.cinfo.szip.options_mask = SZ_EC_OPTION_MASK;
    c_def.comp.cinfo.szip.options_mask |= SZ_MSB_OPTION_MASK;
    c_def.comp.cinfo.szip.bits_per_pixel = 0;
    c_def.comp.cinfo.szip.pixels = 0;
    c_def.comp.cinfo.szip.pixels_per_scanline = 0;
    c_flags = HDF_CHUNK | HDF_COMP;
    status = SDsetchunk (sds_id, c_def, c_flags);
       CHECK(status, FAIL, "SDsetchunk");

    /* Set chunk cache to hold maximum of 3 chunks. */
    maxcache = 3;
    flag = 0;
    new_maxcache = SDsetchunkcache (sds_id, maxcache, flag);
    CHECK(new_maxcache, FAIL, "SDsetchunkcache");

    HDmemset(&c_def_out, 0, sizeof(HDF_CHUNK_DEF));
    c_flags_out = 0;
    status = SDgetchunkinfo(sds_id, &c_def_out, &c_flags_out);
    CHECK(status, FAIL, "SDgetchunkinfo");
    VERIFY(c_flags_out, c_flags, "SDgetchunkinfo");
    VERIFY(c_def_out.comp.comp_type, COMP_CODE_SZIP, "SDgetchunkinfo");

    /* 
     * Write chunks using SDwritechunk function.  Chunks can be written 
     * in any order. 
     */

    /* Write the chunk with the coordinates (0,0). */
    origin[0] = 0;
    origin[1] = 0;
    status = SDwritechunk (sds_id, origin, (VOIDP) chunk1);
    CHECK(status, FAIL, "SDwritechunk");

    /* Write the chunk with the coordinates (1,0). */
    origin[0] = 1;
    origin[1] = 0;
    status = SDwritechunk (sds_id, origin, (VOIDP) chunk3);
    CHECK(status, FAIL, "SDwritechunk");

    /* Write the chunk with the coordinates (0,1). */
    origin[0] = 0;
    origin[1] = 1;
    status = SDwritechunk (sds_id, origin, (VOIDP) chunk2);
    CHECK(status, FAIL, "SDwritechunk");

    /* Write chunk with the coordinates (1,2) using SDwritedata function. */
    start[0] = 6;
    start[1] = 2;
    edges[0] = 3;
    edges[1] = 2;
    status = SDwritedata (sds_id, start, NULL, edges, (VOIDP) chunk6); 
    CHECK(status, FAIL, "SDwritedata");

    /* Fill second column in the chunk with the coordinates (1,1) using 
     * SDwritedata function. */
    start[0] = 3;
    start[1] = 3;
    edges[0] = 3;
    edges[1] = 1;
    status = SDwritedata (sds_id, start, NULL, edges, (VOIDP) column); 
    CHECK(status, FAIL, "SDwritedata");

    /* Fill second row in the chunk with the coordinates (0,2) using 
     * SDwritedata function. */
    start[0] = 7;
    start[1] = 0;
    edges[0] = 1;
    edges[1] = 2;
    status = SDwritedata (sds_id, start, NULL, edges, (VOIDP) row); 
    CHECK(status, FAIL, "SDwritedata");
           
    /* Terminate access to the data set. */
    status = SDendaccess (sds_id);
    CHECK(status, FAIL, "SDendaccess");

    /* Terminate access to the SD interface and close the file. */
    status = SDend (sd_id);
    CHECK(status, FAIL, "SDend");

    /*
     * Verify the compressed data
     */

    /* Reopen the file and access the first data set. */
    sd_id = SDstart (FILE_NAME, DFACC_READ);
    sds_index = 0;
    sds_id = SDselect (sd_id, sds_index);
    CHECK(sds_id, FAIL, "SDselect:Failed to select a data set for chunking/szip compression testing");

    /* Retrieve compression information about the dataset */
    comp_type = COMP_CODE_INVALID;  /* reset variables before retrieving info */
    HDmemset(&cinfo, 0, sizeof(cinfo)) ;

    status = SDgetcompinfo(sds_id, &comp_type, &cinfo);
    CHECK(status, FAIL, "SDgetcompinfo");
    VERIFY(comp_type, COMP_CODE_SZIP, "SDgetcompinfo");

    /* Retrieve compression method alone from the dataset */
    comp_type = COMP_CODE_INVALID;  /* reset variables before retrieving info */
    status = SDgetcomptype(sds_id, &comp_type);
    CHECK(status, FAIL, "SDgetcomptype");
    VERIFY(comp_type, COMP_CODE_SZIP, "SDgetcomptype");

    /* Read the entire data set using SDreaddata function. */
    start[0] = 0;
    start[1] = 0;
    edges[0] = LENGTH_CH;
    edges[1] = WIDTH_CH;
    status = SDreaddata (sds_id, start, NULL, edges, (VOIDP)all_data);
    CHECK(status, FAIL, "SDreaddata");

    /* 
    * This is how the entire array should look like:
    *
    *          1 1 2 2
    *          1 1 2 2
    *          1 1 2 2
    *          3 3 0 4
    *          3 3 0 4
    *          3 3 0 4
    *          0 0 6 6
    *          5 5 6 6
    *          0 0 6 6
    */

    /* Read chunk #4 with the coordinates (1,1) and verify it. */
    origin[0] = 1;
    origin[1] = 1;    	
    status = SDreadchunk (sds_id, origin, chunk_out);
    CHECK(status, FAIL, "SDreadchunk");

    for (j=0; j<CLENGTH; j++) 
    {
	for (i=0; i<CWIDTH; i++) 
	{
	    if (chunk_out[j][i] != chunk4[j][i])
	    {
		fprintf(stderr,"Bogus val in loc [%d][%d] in chunk #4, want %ld got %ld\n", j, i, chunk4[j][i], chunk_out[j][i]);
		num_errs++;
	    }
	}
    }

    /* 
    * Read chunk #5 with the coordinates (2,0) and verify it.
    */
    origin[0] = 2;
    origin[1] = 0;    	
    status = SDreadchunk (sds_id, origin, chunk_out);
    CHECK(status, FAIL, "SDreadchunk");

    for (j=0; j<CLENGTH; j++) 
    {
	for (i=0; i<CWIDTH; i++) 
	    if (chunk_out[j][i] != chunk5[j][i])
	    {
		fprintf(stderr,"Bogus val in loc [%d][%d] in chunk #5, want %ld got %ld\n", j, i, chunk5[j][i], chunk_out[j][i]);
		num_errs++;
	    }
    }

    /* Get the data sizes */
    status = SDgetdatasize(sds_id, &comp_size, &uncomp_size);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDgetdatasize");

    /* Terminate access to the data set. */
    status = SDendaccess (sds_id);
    CHECK(status, FAIL, "SDendaccess");

    /* Terminate access to the SD interface and close the file. */
    status = SDend (sd_id);
    CHECK(status, FAIL, "SDend");

    /* Return the number of errors that's been kept track of so far */
    return num_errs;
}   /* test_szip_chunk */ 
Esempio n. 4
0
static intn test_szip_SDSfl64bit()
{
    /************************* Variable declaration **************************/

    int32	sd_id, sds_id;
    intn 	status;
    int32	dim_sizes[2], array_rank, num_type, attributes;
    char	name[H4_MAX_NC_NAME];
    comp_info	c_info;
    int32       start[2], edges[2];
    float64     fill_value = 0;   /* Fill value */
    int         i,j;
    int		num_errs = 0;    /* number of errors so far */
    float64	out_data[LENGTH][WIDTH];
    float64	in_data[LENGTH][WIDTH]={
	   			 100.0,100.0,200.0,200.0,300.0,400.0,
	   			 100.0,100.0,200.0,200.0,300.0,400.0,
				 100.0,100.0,200.0,200.0,300.0,400.0,
				 300.0,300.0,  0.0,400.0,300.0,400.0,
				 300.0,300.0,  0.0,400.0,300.0,400.0,
				 300.0,300.0,  0.0,400.0,300.0,400.0,
				   0.0,  0.0,600.0,600.0,300.0,400.0,
				 500.0,500.0,600.0,600.0,300.0,400.0,
				   0.0,  0.0,600.0,600.0,300.0,400.0};

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

    /* Create the file and initialize SD interface */
    sd_id = SDstart (FILE_NAMEfl64, DFACC_CREATE);
    CHECK(sd_id, FAIL, "SDstart");

    /* Create the SDS */
    dim_sizes[0] = LENGTH;
    dim_sizes[1] = WIDTH;
    sds_id = SDcreate (sd_id, SDS_NAME, DFNT_FLOAT64, RANK, dim_sizes);
    CHECK(sds_id, FAIL, "SDcreate:Failed to create a data set for szip compression testing");

    /* Define the location, pattern, and size of the data set */
    for (i = 0; i < RANK; i++) {
	start[i] = 0;
	edges[i] = dim_sizes[i];
	}

    /* Fill the SDS array with the fill value */
    status = SDsetfillvalue (sds_id, (VOIDP)&fill_value);
    CHECK(status, FAIL, "SDsetfillvalue");

    /* Initialization for SZIP */
    c_info.szip.pixels_per_block = 2;

    c_info.szip.options_mask = SZ_EC_OPTION_MASK;
    c_info.szip.options_mask |= SZ_RAW_OPTION_MASK;
    c_info.szip.bits_per_pixel = 0;
    c_info.szip.pixels = 0;
    c_info.szip.pixels_per_scanline = 0;

    /* Set the compression */
    status = SDsetcompress (sds_id, COMP_CODE_SZIP, &c_info);
    CHECK(status, FAIL, "SDsetcompress");

    /* Write data to the SDS */
    status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)in_data);
    CHECK(status, FAIL, "SDwritedata");

    /* Terminate access to the data set */
    status = SDendaccess (sds_id);
    CHECK(status, FAIL, "SDendaccess");

    /* Terminate access to the SD interface and close the file to 
       flush the compressed info to the file */
    status = SDend (sd_id);
    CHECK(status, FAIL, "SDend");

    /*
     * Verify the compressed data
     */

    /* Reopen the file and select the first SDS */
    sd_id = SDstart (FILE_NAMEfl64, DFACC_READ);
    CHECK(sd_id, FAIL, "SDstart");

    sds_id = SDselect (sd_id, 0);
    CHECK(sds_id, FAIL, "SDselect:Failed to select a data set for szip compression testing");

    /* Retrieve information of the data set */
    status = SDgetinfo(sds_id, name, &array_rank, dim_sizes, &num_type, &attributes);
    CHECK(status, FAIL, "SDgetinfo");

    /* Wipe out the output buffer */
    HDmemset(&out_data, 0, sizeof(out_data));

    /* Read the data set */
    start[0] = 0;
    start[1] = 0;
    edges[0] = LENGTH;
    edges[1] = WIDTH;
    status = SDreaddata (sds_id, start, NULL, edges, (VOIDP)out_data);
    CHECK(status, FAIL, "SDreaddata");

    /* Compare read data against input data */
    for (j=0; j<LENGTH; j++) 
    {
        for (i=0; i<WIDTH; i++)
	    if (out_data[j][i] != in_data[j][i])
	    {
		fprintf(stderr,"Bogus val in loc [%d][%d] in compressed dset, want %ld got %ld\n", j, i, (long)in_data[j][i], (long)out_data[j][i]);
		num_errs++;
	    }
    }

    /* Terminate access to the data set */
    status = SDendaccess (sds_id);
    CHECK(status, FAIL, "SDendaccess");

    /* Terminate access to the SD interface and close the file */
    status = SDend (sd_id);
    CHECK(status, FAIL, "SDend");

    /* Return the number of errors that's been kept track of so far */
    return num_errs;
}  /* test_szip_SDSfl64bit */
Esempio n. 5
0
/* Test with chunked and compressed SDS.  This routine creates 
 * "ChunkedDeflateData" and "ChunkedNoDeflateData" SDSs and writes the same
 * data to both.  It will then use SDgetdatasize to verify the sizes.
 */
static intn test_chkcmp_SDSs(int32 fid)
{
    int32         sds_id, sds_index;
    int32         cmpsds_id, cmpsds_index;
    int32         flag, maxcache, new_maxcache;
    int32         dim_sizes[RANK], origin[RANK];
    HDF_CHUNK_DEF c_def; /* Chunking definitions */ 
    int32         fill_value = 0;   /* Fill value */
    int32	  comp_size1=0, uncomp_size1=0;
    int32	  comp_size2=0, uncomp_size2=0;
    intn          status;
    int           num_errs = 0;   /* number of errors so far */

    /* Declare chunks data type and initialize some of them. */
    int16 chunk1[CHK_X][CHK_Y] = { {1, 1},
                           {1, 1},
                           {1, 1} }; 

    int16 chunk3[CHK_X][CHK_Y] = { {3, 3},
                           {3, 3},
                           {3, 3} }; 

    int32 chunk2[CHK_X][CHK_Y] = { {2, 2},
                           {2, 2},
                           {2, 2} }; 

    /* Initialize chunk size */
    HDmemset(&c_def, 0, sizeof(c_def)) ;
    c_def.chunk_lengths[0] = CHK_X;
    c_def.chunk_lengths[1] = CHK_Y;

    /* Create Y_LENGTH2 x X_LENGTH2 SDS */
    dim_sizes[0] = Y_LENGTH2;
    dim_sizes[1] = X_LENGTH2;
    cmpsds_id = SDcreate(fid, "ChunkedDeflateData", DFNT_INT32, RANK, dim_sizes);
    CHECK(cmpsds_id, FAIL, "test_chkcmp_SDSs: SDcreate 'ChunkedDeflateData'");

    sds_id = SDcreate(fid, "ChunkedNoDeflateData", DFNT_INT32, RANK, dim_sizes);
    CHECK(sds_id, FAIL, "test_chkcmp_SDSs: SDcreate 'ChunkedNoDeflateData'");

    /* Fill the SDS array with the fill value */
    status = SDsetfillvalue(cmpsds_id, (VOIDP)&fill_value);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDsetfillvalue 'ChunkedDeflateData'");

    status = SDsetfillvalue(sds_id, (VOIDP)&fill_value);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDsetfillvalue 'ChunkedNoDeflateData'");

    /* Set info for chunking and compression */
    flag = HDF_CHUNK | HDF_COMP;
    c_def.comp.comp_type = COMP_CODE_DEFLATE;
    c_def.comp.cinfo.deflate.level = 6;
    status = SDsetchunk(cmpsds_id, c_def, flag);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDsetchunk 'ChunkedDeflateData'");

    /* Set info for chunking and compression */
    HDmemset(&c_def, 0, sizeof(c_def)) ;
    c_def.chunk_lengths[0] = CHK_X;
    c_def.chunk_lengths[1] = CHK_Y;

    flag = HDF_CHUNK;
    status = SDsetchunk(sds_id, c_def, flag);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDsetchunk 'ChunkedNoDeflateData'");

    /* Set chunk cache to hold maximum of 3 chunks */
    maxcache = 3;
    flag = 0;
    new_maxcache = SDsetchunkcache(cmpsds_id, maxcache, flag);
    CHECK(new_maxcache, FAIL, "test_chkcmp_SDSs: SDsetchunkcache 'ChunkedDeflateData'");

    new_maxcache = SDsetchunkcache(sds_id, maxcache, flag);
    CHECK(new_maxcache, FAIL, "test_chkcmp_SDSs: SDsetchunkcache 'ChunkedNoDeflateData'");

    /* Terminate access to the dataset before writing data to it. */
    status = SDendaccess(cmpsds_id);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDendaccess 'ChunkedDeflateData'");

    status = SDendaccess(sds_id);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDendaccess 'ChunkedNoDeflateData'");

    /* Check that this SDS is still empty after the call to SDsetchunk */
    check_datasizes(fid, "ChunkedDeflateData", 0, 0, &num_errs);
    check_datasizes(fid, "ChunkedNoDeflateData", 0, 0, &num_errs);

    /* Re-select the datasets, write chunks using SDwritechunk function, then
       check their data sizes */

    /* Get index of dataset using its name */
    cmpsds_index = SDnametoindex(fid, "ChunkedDeflateData");
    CHECK(cmpsds_index, FAIL, "test_chkcmp_SDSs: SDnametoindex 'ChunkedDeflateData'");

    sds_index = SDnametoindex(fid, "ChunkedNoDeflateData");
    CHECK(sds_index, FAIL, "test_chkcmp_SDSs: SDnametoindex 'ChunkedNoDeflateData'");

    /* Select the datasets for access */
    cmpsds_id = SDselect(fid, cmpsds_index);
    CHECK(cmpsds_id, FAIL, "test_chkcmp_SDSs: SDselect 'ChunkedDeflateData'");
    sds_id = SDselect(fid, sds_index);
    CHECK(cmpsds_id, FAIL, "test_chkcmp_SDSs: SDselect 'ChunkedNoDeflateData'");

    /* Write the chunk with the coordinates (0,0) */
    origin[0] = 0;
    origin[1] = 0;
    status = SDwritechunk(cmpsds_id, origin, (VOIDP) chunk1);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDwritechunk 'ChunkedDeflateData'");
    status = SDwritechunk(sds_id, origin, (VOIDP) chunk1);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDwritechunk 'ChunkedNoDeflateData'");

    /* Write the chunk with the coordinates (1,0) */
    origin[0] = 1;
    origin[1] = 0;
    status = SDwritechunk(cmpsds_id, origin, (VOIDP) chunk3);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDwritechunk 'ChunkedDeflateData'");
    status = SDwritechunk(sds_id, origin, (VOIDP) chunk3);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDwritechunk 'ChunkedNoDeflateData'");

    /* Write the chunk with the coordinates (0,1) */
    origin[0] = 0;
    origin[1] = 1;
    status = SDwritechunk(cmpsds_id, origin, (VOIDP) chunk2);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDwritechunk 'ChunkedDeflateData'");
    status = SDwritechunk(sds_id, origin, (VOIDP) chunk2);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDwritechunk 'ChunkedNoDeflateData'");

    /* Terminate access to the datasets */
    status = SDendaccess(cmpsds_id);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDendaccess 'ChunkedDeflateData'");
    status = SDendaccess(sds_id);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDendaccess 'ChunkedNoDeflateData'");

    /* Verify the compressed and non-compressed data sizes of the datasets */

    /* Open dataset 'ChunkedDeflateData' */
    cmpsds_id = SDselect(fid, cmpsds_index);
    CHECK(cmpsds_id, FAIL, "test_chkcmp_SDSs: SDselect 'ChunkedDeflateData'");

    /* Get the data sizes */
    status = SDgetdatasize(cmpsds_id, &comp_size1, &uncomp_size1);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDgetdatasize 'ChunkedDeflateData'");

    /* Open dataset 'ChunkedNoDeflateData' */
    sds_id = SDselect(fid, sds_index);
    CHECK(sds_id, FAIL, "test_chkcmp_SDSs: SDselect 'ChunkedNoDeflateData'");

    /* Get the data sizes */
    status = SDgetdatasize(sds_id, &comp_size2, &uncomp_size2);
    CHECK(status, FAIL, "test_chkcmp_SDSs: SDgetdatasize 'ChunkedNoDeflateData'");

    /* Non-compressed data sizes of the two datasets should be the same */
    VERIFY(uncomp_size1, uncomp_size2, "test_chkcmp_SDSs: non-compressed data sizes might be incorrect");

    /* In this test, compressed data size should be smaller than non-compressed
       data size */
    if (comp_size1 >= uncomp_size1)
    {
	printf("*** Routine test_chkcmp_SDSs: FAILED at line %d ***\n", __LINE__);
	printf("    In this test, compressed data size (%d) should be smaller than non-compressed data size (%d)\n", comp_size1, uncomp_size1);
	num_errs++;
    }

    /* Terminate access to the data sets. */
    status = SDendaccess(sds_id);
    CHECK(sds_id, FAIL, "test_chkcmp_SDSs: SDendaccess 'ChunkedNoDeflateData'");

    status = SDendaccess(cmpsds_id);
    CHECK(sds_id, FAIL, "test_chkcmp_SDSs: SDendaccess 'ChunkedDeflateData'");

    /* Return the number of errors that's been kept track of so far */
    return num_errs;
} /* test_chkcmp_SDSs */
Esempio n. 6
0
/* Test with chunked and partially written SDS.  This routine creates a 
 * "Chunked Not Empty" SDS and writes some chunks but not all to it.  It will
 * then call SDgetdatasize to verify the sizes.
 */
static intn test_chunked_partial(int32 fid)
{
    int32         sds_id, sds_index;
    int32         dim_sizes[RANK], origin[RANK];
    HDF_CHUNK_DEF c_def; /* Chunking definitions */ 
    int32         flag; /* Chunking flag */
    int16         fill_value = 0;   /* Fill value */
    intn          status;
    int           num_errs = 0;   /* number of errors so far */

    /* Declare chunks data type and initialize some of them. */
    int16 chunk1[CHK_X][CHK_Y] = { {1, 1},
                           {1, 1},
                           {1, 1} }; 

    int16 chunk3[CHK_X][CHK_Y] = { {3, 3},
                           {3, 3},
                           {3, 3} }; 

    /* Initialize chunk size */
    HDmemset(&c_def, 0, sizeof(c_def)) ;
    c_def.chunk_lengths[0] = CHK_X;
    c_def.chunk_lengths[1] = CHK_Y;

    /* Create Y_LENGTH2 x X_LENGTH2 SDS */
    dim_sizes[0] = X_LENGTH2;
    dim_sizes[1] = Y_LENGTH2;
    sds_id = SDcreate(fid, "Chunked Not Empty", DFNT_INT16, RANK, dim_sizes);
    CHECK(sds_id, FAIL, "test_chunked_partial: SDcreate 'Chunked Not Empty'");

    /* Fill the SDS array with the fill value */
    status = SDsetfillvalue(sds_id, (VOIDP)&fill_value);
    CHECK(status, FAIL, "test_chunked_partial: SDsetfillvalue");

    /* Set info for chunking */
    flag = HDF_CHUNK;
    status = SDsetchunk(sds_id, c_def, flag);
    CHECK(status, FAIL, "test_chunked_partial: SDsetchunk");

    /* Write partially to 'Chunked Not Empty' and check the sizes */

    /* Write the chunk with the coordinates (0,0) */
    origin[0] = 0;
    origin[1] = 0;
    status = SDwritechunk(sds_id, origin, (VOIDP) chunk1);
    CHECK(status, FAIL, "test_chunked_partial: SDwritechunk");

    /* Write the chunk with the coordinates (1,0) */
    origin[0] = 1;
    origin[1] = 0;
    status = SDwritechunk(sds_id, origin, (VOIDP) chunk3);
    CHECK(status, FAIL, "test_chunked_partial: SDwritechunk");

    /* Terminate access to the "Chunked Not Empty" dataset */
    status = SDendaccess(sds_id);
    CHECK(status, FAIL, "test_chunked_partial: SDendaccess 'Chunked Not Empty'");

    /* Check the size of the data of this SDS - only chunked, not compressed,
       so both values should be the same; there are two chunks of size
       CHK_X*CHK_Y in type int16 written */
    check_datasizes(fid, "Chunked Not Empty", CHK_X*CHK_Y*SIZE_INT16*2, CHK_X*CHK_Y*SIZE_INT16*2, &num_errs);

    /* Return the number of errors that's been kept track of so far */
    return num_errs;
} /* test_chunked_partial */