Ejemplo n.º 1
0
int main()
{
    int a[]={1, 2, 3, 4,5,6,7,8,9 };
    int b[]={1, 4, 2, 3,5,6,7,9,8 };
    
    int n=8;
    
 
    printf("\nis_sorted returned:%d\n\n",is_sorted(a,n));
    
    unsigned int data[]={1, 5, 2, 13,1,7,5,2,9 };//unsigned is used for ASCII
    histogram(data, n);
    
    printf("\nnum_distinct returned:%d\n\n",num_distinct(a, n));
    
    printf("same_contents returned:%d\n\n",same_contents(a,b,n));
    
    rotate_right(a, n);
    
}
Ejemplo n.º 2
0
/*-------------------------------------------------------------------------
 * Function:	test_3
 *
 * Purpose:	Tests writing to an external file set.
 *
 * Return:	Success:	0
 *
 * 		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Wednesday, March  4, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_3 (hid_t fapl)
{
    hid_t	file=-1;		/*file to which to write	*/
    hid_t	dcpl=-1;		/*dataset creation properties	*/
    hid_t	mem_space=-1;		/*memory data space		*/
    hid_t	file_space=-1;		/*file data space		*/
    hid_t	dset=-1;		/*dataset			*/
    unsigned	i;			/*miscellaneous counters	*/
    int		fd;			/*external file descriptor	*/
    int	    part[25],whole[100];	/*raw data buffers		*/
    hsize_t	cur_size=100;		/*current data space size	*/
    hsize_t	max_size=200;		/*maximum data space size	*/
    hsize_t	hs_start=100;		/*hyperslab starting offset	*/
    hsize_t	hs_count=100;		/*hyperslab size		*/
    char	filename[1024];		/*file name			*/
	int temparray[10] = {0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f,0x0f0f0f0f};

    TESTING("write external dataset");

    /* Create another file */
    h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
    if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) {
	goto error;
    }

    /* Create the external file list */
    if((dcpl=H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error;
    if (H5Pset_external(dcpl, "extern_1b.raw", (off_t)0, (hsize_t)sizeof part) < 0 ||
	H5Pset_external(dcpl, "extern_2b.raw", (off_t)10, (hsize_t)sizeof part) < 0 ||
	H5Pset_external(dcpl, "extern_3b.raw", (off_t)20, (hsize_t)sizeof part) < 0 ||
	H5Pset_external(dcpl, "extern_4b.raw", (off_t)30, H5F_UNLIMITED) < 0)
	goto error;

    /* Make sure the output files are fresh*/
    for (i=1; i<=4; i++) {
	sprintf(filename, "extern_%db.raw", i);
	if ((fd= HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
	    H5_FAILED();
	    printf("    cannot open %s: %s\n", filename, strerror(errno));
	    goto error;
	}

	HDwrite(fd, temparray, (i-1)*10);
	HDclose(fd);
    }

    /* Create the dataset */
    if((mem_space = H5Screate_simple(1, &cur_size, &max_size)) < 0) goto error;
    if((file_space = H5Scopy(mem_space)) < 0) goto error;
    if((dset = H5Dcreate2(file, "dset1", H5T_NATIVE_INT, file_space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
	goto error;

    /* Write the entire dataset and compare with the original */
    for(i = 0; i < cur_size; i++)
        whole[i] = i;
    if(H5Dwrite(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, whole) < 0) goto error;
    for(i = 0; i < 4; i++) {
	char name1[64], name2[64];

	sprintf(name1, "extern_%da.raw", i + 1);
	sprintf(name2, "extern_%db.raw", i + 1);
	if(!same_contents(name1, name2)) {
	    H5_FAILED();
	    puts ("   Output differs from expected value.");
	    goto error;
	} /* end if */
    } /* end for */

    /* Extend the dataset by another 100 elements */
    if(H5Dset_extent(dset, &max_size) < 0) goto error;
    if(H5Sclose(file_space) < 0) goto error;
    if((file_space = H5Dget_space(dset)) < 0) goto error;

    /* Write second half of dataset */
    for(i = 0; i < hs_count; i++)
        whole[i] = 100 + i;
    if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, &hs_start, NULL, &hs_count, NULL) < 0) goto error;
    if(H5Dwrite(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, whole) < 0) goto error;


    if(H5Dclose(dset) < 0) goto error;
    if(H5Pclose(dcpl) < 0) goto error;
    if(H5Sclose(mem_space) < 0) goto error;
    if(H5Sclose(file_space) < 0) goto error;
    if(H5Fclose(file) < 0) goto error;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
	H5Dclose(dset);
	H5Pclose(dcpl);
	H5Sclose(mem_space);
	H5Sclose(file_space);
	H5Fclose(file);
    } H5E_END_TRY;
    return 1;
}