/* * Copyright (C) 1997 NCSA * All rights reserved. * * Programmer: Robb Matzke * Friday, October 10, 1997 * * Purpose: Hyperslab operations are rather complex, so this file * attempts to test them extensively so we can be relatively * sure they really work. We only test 1d, 2d, and 3d cases * because testing general dimensionalities would require us to * rewrite much of the hyperslab stuff. */ #include #include #include #ifndef HAVE_FUNCTION #undef __FUNCTION__ #define __FUNCTION__ "" #endif #define AT() printf (" at %s:%d in %s()\n",__FILE__,__LINE__,__FUNCTION__); #define TEST_SMALL 0x0001 #define TEST_MEDIUM 0x0002 #define VARIABLE_SRC 0 #define VARIABLE_DST 1 #define VARIABLE_BOTH 2 /*------------------------------------------------------------------------- * Function: init_full * * Purpose: Initialize full array. * * Return: void * * Programmer: Robb Matzke * Friday, October 10, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static uintn init_full(uint8_t *array, size_t nx, size_t ny, size_t nz) { size_t i, j, k; uint8_t acc = 128; uintn total = 0; for (i=0; i1) { printf("i=%lu:\n", (unsigned long)i); } else { printf("%03lu:", (unsigned long)i); } for (j=0; j1) printf("%03lu:", (unsigned long)j); for (k=0; k1) printf("\n"); } printf("\n"); } } /*------------------------------------------------------------------------- * Function: print_ref * * Purpose: Prints the reference value * * Return: Success: 0 * * Failure: * * Programmer: Robb Matzke * Friday, October 10, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static void print_ref(size_t nx, size_t ny, size_t nz) { uint8_t *array; array = H5MM_calloc(nx*ny*nz*sizeof(uint8_t)); printf("Reference array:\n"); init_full(array, nx, ny, nz); print_array(array, nx, ny, nz); } /*------------------------------------------------------------------------- * Function: test_fill * * Purpose: Tests the H5V_hyper_fill() function. * * Return: Success: SUCCEED * * Failure: FAIL * * Programmer: Robb Matzke * Saturday, October 11, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static herr_t test_fill(size_t nx, size_t ny, size_t nz, size_t di, size_t dj, size_t dk, size_t ddx, size_t ddy, size_t ddz) { uint8_t *dst = NULL; /*destination array */ hsize_t hs_size[3]; /*hyperslab size */ hsize_t dst_size[3]; /*destination total size */ hssize_t dst_offset[3]; /*offset of hyperslab in dest */ uintn ref_value; /*reference value */ uintn acc; /*accumulator */ size_t i, j, k, dx, dy, dz; /*counters */ size_t u, v, w; int ndims; /*hyperslab dimensionality */ char dim[64], s[256]; /*temp string */ uintn fill_value; /*fill value */ /* * Dimensionality. */ if (0 == nz) { if (0 == ny) { ndims = 1; ny = nz = 1; sprintf(dim, "%lu", (unsigned long) nx); } else { ndims = 2; nz = 1; sprintf(dim, "%lux%lu", (unsigned long) nx, (unsigned long) ny); } } else { ndims = 3; sprintf(dim, "%lux%lux%lu", (unsigned long) nx, (unsigned long) ny, (unsigned long) nz); } sprintf(s, "Testing hyperslab fill %-11s variable hyperslab", dim); printf("%-70s", s); fflush(stdout); /* Allocate array */ dst = H5MM_calloc(nx*ny*nz); init_full(dst, nx, ny, nz); for (i = 0; i < nx; i += di) { for (j = 0; j < ny; j += dj) { for (k = 0; k < nz; k += dk) { for (dx = 1; dx <= nx - i; dx += ddx) { for (dy = 1; dy <= ny - j; dy += ddy) { for (dz = 1; dz <= nz - k; dz += ddz) { /* Describe the hyperslab */ dst_size[0] = nx; dst_size[1] = ny; dst_size[2] = nz; dst_offset[0] = (hssize_t)i; dst_offset[1] = (hssize_t)j; dst_offset[2] = (hssize_t)k; hs_size[0] = dx; hs_size[1] = dy; hs_size[2] = dz; for (fill_value=0; fill_value<256; fill_value+=64) { /* * Initialize the full array, then subtract the * original * fill values and add the new ones. */ ref_value = init_full(dst, nx, ny, nz); for (u=dst_offset[0]; u