int Rast3d_put_value(RASTER3D_Map * map, int x, int y, int z, const void *value, int type) { if (type == FCELL_TYPE) return (Rast3d_put_float(map, x, y, z, *((float *)value))); return (Rast3d_put_double(map, x, y, z, *((double *)value))); }
static void init_flowaccum(RASTER3D_Region * region, RASTER3D_Map * flowacc) { int c, r, d; for (d = 0; d < region->depths; d++) for (r = 0; r < region->rows; r++) for (c = 0; c < region->cols; c++) if (Rast3d_put_float(flowacc, c, r, d, 0) != 1) Rast3d_fatal_error(_("init_flowaccum: error in Rast3d_put_float")); }
int Rast3d_put_double(RASTER3D_Map * map, int x, int y, int z, double value) { int tileIndex, offs; double *tile; if (map->typeIntern == FCELL_TYPE) return (Rast3d_put_float(map, x, y, z, (float)value)); Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs); tile = (double *)Rast3d_get_tile_ptr(map, tileIndex); if (tile == NULL) { Rast3d_error("Rast3d_put_double: error in Rast3d_get_tile_ptr"); return 0; } tile[offs] = value; return 1; }
static void makeMask(char *name, d_Mask * maskRules) { void *map, *mask; RASTER3D_Region region; int tileX, tileY, tileZ, x, y, z, cacheSize; double value; float floatNull; cacheSize = Rast3d_cache_size_encode(RASTER3D_USE_CACHE_XY, 1); if (NULL == G_find_raster3d(name, "")) Rast3d_fatal_error(_("3D raster map <%s> not found"), name); map = Rast3d_open_cell_old(name, G_mapset(), RASTER3D_DEFAULT_WINDOW, DCELL_TYPE, cacheSize); if (map == NULL) Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"), name); Rast3d_get_region_struct_map(map, ®ion); Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ); mask = Rast3d_open_new_param(Rast3d_mask_file(), FCELL_TYPE, cacheSize, ®ion, FCELL_TYPE, RASTER3D_COMPRESSION, 0, tileX, tileY, tileZ); if (mask == NULL) Rast3d_fatal_error(_("Unable to open 3D raster mask file")); Rast3d_min_unlocked(map, RASTER3D_USE_CACHE_X); Rast3d_autolock_on(map); Rast3d_unlock_all(map); Rast3d_min_unlocked(mask, RASTER3D_USE_CACHE_X); Rast3d_autolock_on(mask); Rast3d_unlock_all(mask); Rast3d_set_null_value(&floatNull, 1, FCELL_TYPE); for (z = 0; z < region.depths; z++) { if ((z % tileZ) == 0) { Rast3d_unlock_all(map); Rast3d_unlock_all(mask); } for (y = 0; y < region.rows; y++) /* We count from north to south in the cube coordinate system */ for (x = 0; x < region.cols; x++) { value = Rast3d_get_double_region(map, x, y, z); if (Rast3d_mask_d_select((DCELL *) & value, maskRules)) Rast3d_put_float(mask, x, y, z, (float)floatNull); /* mask-out value */ else Rast3d_put_float(mask, x, y, z, (float)0.0); /* not mask-out value */ } if ((z % tileZ) == 0) { if (!Rast3d_flush_tiles_in_cube (mask, 0, 0, MAX(0, z - tileZ), region.rows - 1, region.cols - 1, z)) Rast3d_fatal_error(_("makeMask: error flushing tiles in cube")); } } if (!Rast3d_flush_all_tiles(mask)) Rast3d_fatal_error(_("makeMask: error flushing all tiles")); Rast3d_autolock_off(map); Rast3d_unlock_all(map); Rast3d_autolock_off(mask); Rast3d_unlock_all(mask); if (!Rast3d_close(mask)) Rast3d_fatal_error(_("Unable to close 3D raster mask file")); if (!Rast3d_close(map)) Rast3d_fatal_error(_("Unable to close raster map <%s>"), name); }
int OUTGR() { void *cf1, *cf2, *cf3, *cf4, *cf5, *cf6, *cf7; int read_val; FCELL *cell; float *data; int i, iarc, cnt; int bmask = 1; int x, y; float value; if ((cellinp != NULL) && (cellout != NULL)) { cell = Rast_allocate_f_buf(); for (i = 0; i < nsizr; i++) { /* seek to the right row */ G_fseek (Tmp_fd_cell, ((off_t)(nsizr - 1 - i) * nsizc * sizeof(FCELL)), 0); fread(cell, sizeof(FCELL), nsizc, Tmp_fd_cell); Rast_put_f_row(fdcout, cell); } } /*** Initialize output g3d region ***/ current_region.bottom = z_orig_in; current_region.top = nsizl * tb_res_in + z_orig_in; if (!(data = (float *)G_malloc(sizeof(float) * nsizr * nsizc * nsizl))) { clean(); G_fatal_error(_("Out of memory")); } /*** Write elevation results ***/ if (outz != NULL) { cf1 = Rast3d_open_new_opt_tile_size(outz, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf1 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), outz); } /* seek to the beginning */ G_fseek(Tmp_fd_z, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_z); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt]; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf1, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf1) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), outz); } else G_message(_("3D raster map <%s> created"), outz); } /*** Write out the gradient results ***/ if (gradient != NULL) { cf2 = Rast3d_open_new_opt_tile_size(gradient, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf2 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), gradient); } /* seek to the beginning */ G_fseek(Tmp_fd_dx, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dx); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt]; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf2, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf2) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), gradient); } else G_message(_("3D raster map <%s> created"), gradient); } /*** Write out aspect1 results ***/ if (aspect1 != NULL) { cf3 = Rast3d_open_new_opt_tile_size(aspect1, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf3 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), aspect1); } /* seek to the beginning */ G_fseek(Tmp_fd_dy, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dy); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt] * 180 / M_PI; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf3, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf3) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), aspect1); } else G_message(_("3D raster map <%s> created"), aspect1); } /*** Write out aspect2 results ***/ if (aspect2 != NULL) { cf4 = Rast3d_open_new_opt_tile_size(aspect2, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf4 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), aspect2); } /* seek to the beginning */ G_fseek(Tmp_fd_dz, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dz); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt] * 180 / M_PI; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf4, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf4) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), aspect2); } else G_message(_("3D raster map <%s> created"), aspect2); } /*** Write out ncurv results ***/ if (ncurv != NULL) { cf5 = Rast3d_open_new_opt_tile_size(ncurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf5 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), ncurv); } /* seek to the beginning */ G_fseek(Tmp_fd_xx, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_xx); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt]; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf5, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf5) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), ncurv); } else G_message(_("3D raster map <%s> created"), ncurv); } /*** Write out gcurv results ***/ if (gcurv != NULL) { cf6 = Rast3d_open_new_opt_tile_size(gcurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf6 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), gcurv); } /* seek to the beginning */ G_fseek(Tmp_fd_yy, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_yy); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt]; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf6, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf6) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), gcurv); } else G_message(_("3D raster map <%s> created"), gcurv); } /*** Write mcurv results ***/ if (mcurv != NULL) { cf7 = Rast3d_open_new_opt_tile_size(mcurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32); if (cf7 == NULL) { clean(); G_fatal_error(_("Unable to open %s for writing"), mcurv); } /* seek to the beginning */ G_fseek(Tmp_fd_xy, 0L, 0); /* Read data in from temp file */ read_val = fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_xy); if (read_val < 0) { clean(); G_fatal_error(_("Unable to read data from temp file")); } cnt = 0; for (iarc = 0; iarc < nsizl; iarc++) { for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */ for (x = 0; x < nsizc; x++) { if (maskmap != NULL) bmask = BM_get(bitmask, x, nsizr - y - 1); else bmask = 1; value = data[cnt]; if (!bmask) Rast3d_set_null_value(&value, 1, FCELL_TYPE); if (Rast3d_put_float(cf7, x, y, iarc, value) == 0) { clean(); G_fatal_error( _("Error writing cell (%d,%d,%d) with value %f"), x, y, iarc, value); } cnt++; } } } /* Close the file */ if (Rast3d_close(cf7) == 0) { clean(); G_fatal_error(_("Error closing output file %s"), mcurv); } else G_message(_("3D raster map <%s> created"), mcurv); } G_free(data); return 1; }