process.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /***************************************************************************/
  2. /*** ***/
  3. /*** process() ***/
  4. /*** Reads in a raster maps row by row for processing ***/
  5. /*** Jo Wood, V1.0, 13th September, 1994 ***/
  6. /*** ***/
  7. /***************************************************************************/
  8. #include <grass/raster.h>
  9. #include <grass/glocale.h>
  10. #include "frac.h"
  11. /* gmath.h must go last, as it can interfere with ANSI headers */
  12. #include <grass/gmath.h>
  13. int process(void)
  14. {
  15. /*-------------------------------------------------------------------*/
  16. /* INITIALISE */
  17. /*-------------------------------------------------------------------*/
  18. int nrows, /* Will store the current number of */
  19. ncols, /* rows and columns in the raster. */
  20. nn; /* Size of raster to nearest power of 2. */
  21. double *data[2]; /* Array holding complex data. */
  22. /*------------------------------------------------------------------*/
  23. /* GET DETAILS OF INPUT RASTER */
  24. /*------------------------------------------------------------------*/
  25. nrows = Rast_window_rows(); /* Find out the number of rows and */
  26. ncols = Rast_window_cols(); /* columns of the raster view. */
  27. nn = G_math_max_pow2(MAX(nrows, ncols)); /* Find smallest power of 2 that */
  28. /* largest side of raster will fit. */
  29. /*------------------------------------------------------------------*/
  30. /* CREATE SQUARE ARRAY OF SIDE 2^n */
  31. /*------------------------------------------------------------------*/
  32. if (nn * nn * sizeof(double) < 1)
  33. G_fatal_error(_("Unable to allocate data buffer. "
  34. "Check current region with g.region."));
  35. data[0] = (double *)G_malloc(nn * nn * sizeof(double));
  36. data[1] = (double *)G_malloc(nn * nn * sizeof(double));
  37. /*------------------------------------------------------------------*/
  38. /* Apply spectral synthesis algorithm. */
  39. /*------------------------------------------------------------------*/
  40. specsyn(data, nn);
  41. G_free(data[0]);
  42. G_free(data[1]);
  43. return 0;
  44. }
  45. /***************************************************/
  46. /* Initialize real & complex components to zero */
  47. /***************************************************/
  48. int data_reset(double *data[2], int nn)
  49. {
  50. register double *dptr0 = data[0], *dptr1 = data[1];
  51. int total_size = nn * nn, count;
  52. for (count = 0; count < total_size; count++)
  53. *dptr0++ = *dptr1++ = 0.0;
  54. return 0;
  55. }