void Rast3d_retile(void *map, const char *nameOut, int tileX, int tileY, int tileZ) { void *map2; double value; int x, y, z, saveType; int rows, cols, depths, typeIntern; int xTile, yTile, zTile; int xOffs, yOffs, zOffs, prev; int tileXsave, tileYsave, tileZsave; RASTER3D_Region region; if (!Rast3d_tile_use_cache_map(map)) { retileNocache(map, nameOut, tileX, tileY, tileZ); return; } saveType = Rast3d_get_file_type(); Rast3d_set_file_type(Rast3d_file_type_map(map)); Rast3d_get_tile_dimension(&tileXsave, &tileYsave, &tileZsave); Rast3d_set_tile_dimension(tileX, tileY, tileZ); typeIntern = Rast3d_tile_type_map(map); Rast3d_get_region_struct_map(map, ®ion); map2 = Rast3d_open_cell_new(nameOut, typeIntern, RASTER3D_USE_CACHE_DEFAULT, ®ion); if (map2 == NULL) Rast3d_fatal_error("Rast3d_retile: error in Rast3d_open_cell_new"); Rast3d_set_file_type(saveType); Rast3d_set_tile_dimension(tileXsave, tileYsave, tileZsave); Rast3d_coord2tile_coord(map2, 0, 0, 0, &xTile, &yTile, &zTile, &xOffs, &yOffs, &zOffs); prev = zTile; x = 0; y = 0; Rast3d_get_coords_map(map, &rows, &cols, &depths); for (z = 0; z < depths; z++) { G_percent(z, depths, 1); Rast3d_coord2tile_coord(map2, x, y, z, &xTile, &yTile, &zTile, &xOffs, &yOffs, &zOffs); if (zTile > prev) { if (!Rast3d_flush_all_tiles(map2)) Rast3d_fatal_error("Rast3d_retile: error in Rast3d_flush_all_tiles"); prev++; } for (y = 0; y < rows; y++) for (x = 0; x < cols; x++) { Rast3d_get_value_region(map, x, y, z, &value, typeIntern); if (!Rast3d_put_value(map2, x, y, z, &value, typeIntern)) Rast3d_fatal_error("Rast3d_retile: error in Rast3d_put_value"); } } G_percent(1, 1, 1); if (!Rast3d_flush_all_tiles(map2)) Rast3d_fatal_error("Rast3d_retile: error in Rast3d_flush_all_tiles"); if (!Rast3d_close(map2)) Rast3d_fatal_error("Rast3d_retile: error in Rast3d_close"); }
int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size) { int sum = 0; int x, y, z, i; DCELL value, random_value; DCELL *random_value_vector = G_calloc(RAND_VALUE_VECTOR_SIZE, sizeof(DCELL)); G_message("Testing DCELL put function for large files filled with sparse random values"); RASTER3D_Region region; RASTER3D_Map *map = NULL; /* We need to set up a specific region for the new raster3d map. * First we safe the default region. */ Rast3d_get_window(®ion); region.bottom = -365.5; region.top = 365.5; region.south = -90; region.north = 90; region.west = -180; region.east = 180; region.rows = rows; region.cols = cols; region.depths = depths; Rast3d_adjust_region(®ion); G_message("Creating 3D raster map filled with sparse random values"); map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_sparse_random", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size); /* The window is the same as the map region ... of course */ Rast3d_set_window_map(map, ®ion); srand(1); /* We fill the random value vector */ for(i = 0; i < RAND_VALUE_VECTOR_SIZE; i++) { /* Put the counter as cell value */ value = (DCELL)rand(); value /= RAND_MAX; if(value <= 0.7) value = 0.0; else if(value <= 0.8) value = 1.0; else if(value <= 0.9) value = 2.0; else if(value <= 1.0) value = 3.0; else value = 4.0; random_value_vector[i] = value; } i = 0; for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Put the counter as cell value */ value = random_value_vector[i]; Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE); i++; if(i == RAND_VALUE_VECTOR_SIZE) i = 0; } } } G_percent(1, 1, 1); /* Write everything to the disk */ Rast3d_flush_all_tiles(map); Rast3d_close(map); G_message("Verifying 3D raster map filled with sparse random values"); map = Rast3d_open_cell_old("test_put_get_value_dcell_large_sparse_random", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY); i = 0; for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Check the counter as cell value */ Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE); if(fabs(value - random_value_vector[i]) > EPSILON) { G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, random_value); sum++; } i++; if(i == RAND_VALUE_VECTOR_SIZE) i = 0; } } } G_percent(1, 1, 1); Rast3d_close(map); G_free(random_value_vector); G_remove("grid3", "test_put_get_value_dcell_large_sparse_random"); return sum; }
int test_large_file(int depths, int rows, int cols, int tile_size) { int sum = 0; int x, y, z, count; DCELL value; G_message("Testing DCELL put function for large files"); RASTER3D_Region region; RASTER3D_Map *map = NULL; /* We need to set up a specific region for the new raster3d map. * First we safe the default region. */ Rast3d_get_window(®ion); region.bottom = -365.5; region.top = 365.5; region.south = -90; region.north = 90; region.west = -180; region.east = 180; region.rows = rows; region.cols = cols; region.depths = depths; Rast3d_adjust_region(®ion); G_message("Creating 3D raster map"); map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size); /* The window is the same as the map region ... of course */ Rast3d_set_window_map(map, ®ion); /*Write -1 first to see if the tile handling works correctly */ for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Put the counter as cell value */ value = -1; Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE); } } } G_percent(1, 1, 1); G_message("Rewriting the values"); /* Now write the values to be evaluated */ count = 1; for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Put the counter as cell value */ value = count; Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE); count++; } } } G_percent(1, 1, 1); G_message("Verifying 3D raster map"); count = 1; for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Check the counter as cell value */ Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE); if(fabs(value - (double)(count) > EPSILON)) { G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, (double)(count)); sum++; } count++; } } } G_percent(1, 1, 1); Rast3d_close(map); G_remove("grid3", "test_put_get_value_dcell_large"); return sum; }
int test_large_file_zeros(int depths, int rows, int cols, int tile_size) { int sum = 0; int x, y, z; DCELL value; G_message("Testing DCELL put function for large files filled with zeros"); RASTER3D_Region region; RASTER3D_Map *map = NULL; /* We need to set up a specific region for the new raster3d map. * First we safe the default region. */ Rast3d_get_window(®ion); region.bottom = -365.5; region.top = 365.5; region.south = -90; region.north = 90; region.west = -180; region.east = 180; region.rows = rows; region.cols = cols; region.depths = depths; Rast3d_adjust_region(®ion); G_message("Creating 3D raster map filled with zeros"); map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_zeros", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size); /* The window is the same as the map region ... of course */ Rast3d_set_window_map(map, ®ion); for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Put the counter as cell value */ value = 0.0; Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE); } } } G_percent(1, 1, 1); /* Write everything to the disk */ Rast3d_flush_all_tiles(map); Rast3d_close(map); G_message("Verifying 3D raster map filled with zeros"); map = Rast3d_open_cell_old("test_put_get_value_dcell_large_zeros", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY); for(z = 0; z < region.depths; z++) { G_percent(z, region.depths, 1); for(y = 0; y < region.rows; y++) { for(x = 0; x < region.cols; x++) { /* Check the counter as cell value */ Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE); if(value > EPSILON) { G_message("At: z %i y %i x %i -- value %.14lf != 0.0\n", z, y, x, value); sum++; } } } } G_percent(1, 1, 1); Rast3d_close(map); G_remove("grid3", "test_put_get_value_dcell_large_zeros"); return sum; }