/**************************************************************************** * NCSA HDF * * Software Development Group * * National Center for Supercomputing Applications * * University of Illinois at Urbana-Champaign * * 605 E. Springfield, Champaign IL 61820 * * * * For conditions of distribution and use, see the accompanying * * hdf/COPYING file. * * * ****************************************************************************/ #include "mfhdf.h" #include "hdftest.h" #ifdef H4_HAVE_LIBSZ #include "szlib.h" #endif #define FILE_NAME8 "SDS_8_sziped.hdf" #define FILE_NAME16 "SDS_16_sziped.hdf" #define FILE_NAME32 "SDS_32_sziped.hdf" #define FILE_NAMEfl32 "SDS_fl32_sziped.hdf" #define FILE_NAMEfl64 "SDS_fl64_sziped.hdf" #define SDS_NAME "SzipedData" #define RANK 2 #define WIDTH 6 #define LENGTH 9 static intn test_szip_SDS8bit() { #ifdef H4_HAVE_LIBSZ /************************* Variable declaration **************************/ int32 sd_id, sds_id; intn status; int32 dim_sizes[2], array_rank, num_type, attributes; char name[MAX_NC_NAME]; comp_info c_info; int32 start[2], edges[2]; int8 fill_value = 0; /* Fill value */ int i,j; int num_errs = 0; /* number of errors so far */ comp_coder_t comp_type; /* to retrieve compression type into */ comp_info cinfo; /* compression information structure */ uint32 comp_config; int8 out_data[LENGTH][WIDTH]; int8 in_data[LENGTH][WIDTH]={ 1,1,2,2,3,4, 1,1,2,2,3,4, 1,1,2,2,3,4, 3,3,0,4,3,4, 3,3,0,4,3,4, 3,3,0,4,3,4, 0,0,6,6,3,4, 5,5,6,6,3,4, 0,0,6,6,3,4}; /********************* End of variable declaration ***********************/ HCget_config_info(COMP_CODE_SZIP,&comp_config); /* Create the file and initialize SD interface */ sd_id = SDstart (FILE_NAME8, 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_INT8, 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); if ((comp_config & COMP_ENCODER_ENABLED) == COMP_ENCODER_ENABLED) { /* should work */ CHECK(status, FAIL, "SDsetcompress"); } else { /* skip rest of test?? */ status = SDendaccess (sds_id); CHECK(status, FAIL, "SDendaccess"); status = SDend (sd_id); CHECK(status, FAIL, "SDend"); printf("szip_SD8: SKIPPED\n"); return num_errs; } /* 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_NAME8, 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"); /* Retrieve compression informayion about the dataset */ comp_type = COMP_CODE_INVALID; /* reset variables before retrieving info */ HDmemset(&cinfo, 0, sizeof(cinfo)) ; status = SDgetcompress(sds_id, &comp_type, &cinfo); CHECK(status, FAIL, "SDgetcompress"); VERIFY(comp_type, COMP_CODE_SZIP, "SDgetcompress"); /* 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