ram2out.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include <grass/raster.h>
  4. #include "cmd_line.h"
  5. #include "costHa.h"
  6. #include "local_proto.h"
  7. #define DATA(map, r, c) (map)[(r) * ncols + (c)]
  8. void ram2out(void)
  9. {
  10. extern CELL *cell, *x_cell, *y_cell;
  11. extern CELL *map_x_out, *map_y_out;
  12. extern float *map_out;
  13. extern int cum_fd, x_fd, y_fd;
  14. extern int nrows, ncols;
  15. extern struct Cell_head window;
  16. double north, west;
  17. double Rast_row_to_northing(), G_col_to_easting();
  18. int row, col;
  19. north = Rast_row_to_northing(0.5, &window);
  20. west = Rast_col_to_easting(0.5, &window);
  21. /* Copy maps in ram to output maps, casting into integers */
  22. G_message("Writing output: %s, x_output: %s, y_output: %s ... ",
  23. out_layer, x_out_layer, y_out_layer);
  24. for (row = 0; row < nrows; row++) {
  25. for (col = 0; col < ncols; col++) {
  26. G_percent(row, nrows, 2);
  27. *(cell + col) = (int)DATA(map_out, row, col);
  28. if (x_out) {
  29. if (DATA(map_x_out, row, col) == 0)
  30. *(x_cell + col) = 0;
  31. else
  32. *(x_cell + col) =
  33. (int)(west +
  34. window.ew_res * DATA(map_x_out, row, col));
  35. }
  36. if (y_out) {
  37. if (DATA(map_y_out, row, col) == 0)
  38. *(y_cell + col) = 0;
  39. else
  40. *(y_cell + col) =
  41. (int)(north -
  42. window.ns_res * DATA(map_y_out, row, col));
  43. }
  44. }
  45. Rast_put_row(cum_fd, cell, CELL_TYPE);
  46. if (x_out)
  47. Rast_put_row(x_fd, x_cell, CELL_TYPE);
  48. if (y_out)
  49. Rast_put_row(y_fd, y_cell, CELL_TYPE);
  50. }
  51. G_percent(row, nrows, 2);
  52. }