write_rast.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* updated to GRASS 5FP 11/99 Markus Neteler */
  2. /***************************************************************************/
  3. /*** ***/
  4. /*** write_rast() ***/
  5. /*** Extracts real component from complex array and writes as raster. ***/
  6. /*** Jo Wood, V1.0, 20th October, 1994 ***/
  7. /*** ***/
  8. /***************************************************************************/
  9. #include <grass/raster.h>
  10. #include <grass/glocale.h>
  11. #include "frac.h"
  12. int write_rast(double *data[2], /* Array holding complex data. */
  13. int nn, /* Size of side of array. */
  14. int step /* Version of file to send. */
  15. )
  16. {
  17. /*------------------------------------------------------------------*/
  18. /* INITIALISE */
  19. /*------------------------------------------------------------------*/
  20. DCELL *row_out; /* Buffers to hold raster rows. */
  21. char file_name[GNAME_MAX]; /* Name of each file to be written */
  22. struct History history; /* cmd line history metadata */
  23. int nrows, /* Will store the current number of */
  24. ncols, /* rows and columns in the raster. */
  25. row, col; /* Counts through each row and column */
  26. /* of the input raster. */
  27. nrows = Rast_window_rows(); /* Find out the number of rows and */
  28. ncols = Rast_window_cols(); /* columns of the raster view. */
  29. row_out = Rast_allocate_d_buf();
  30. /*------------------------------------------------------------------*/
  31. /* Open new file and set the output file descriptor. */
  32. /*------------------------------------------------------------------*/
  33. if (Steps != step)
  34. sprintf(file_name, "%s.%d", rast_out_name, step);
  35. else
  36. strcpy(file_name, rast_out_name);
  37. fd_out = Rast_open_new(file_name, DCELL_TYPE);
  38. /*------------------------------------------------------------------*/
  39. /* Extract real component of transform and save as a GRASS raster. */
  40. /*------------------------------------------------------------------*/
  41. for (row = 0; row < nrows; row++) {
  42. for (col = 0; col < ncols; col++)
  43. *(row_out + col) = (DCELL) (*(data[0] + row * nn + col) * 100000);
  44. Rast_put_row(fd_out, (DCELL *) row_out, DCELL_TYPE);
  45. }
  46. Rast_close(fd_out);
  47. Rast_short_history(file_name, "raster", &history);
  48. Rast_command_history(&history);
  49. Rast_write_history(file_name, &history);
  50. return 0;
  51. }