xrowcol.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include "globals.h"
  4. #include "expression.h"
  5. #include "func_proto.h"
  6. /**********************************************************************
  7. col() column number
  8. row() row number
  9. depth() depth number
  10. ncols() number of columns
  11. nrows() number of rows
  12. ndepths() number of depths
  13. **********************************************************************/
  14. int f_col(int argc, const int *argt, void **args)
  15. {
  16. CELL *res = args[0];
  17. int i;
  18. if (argc > 0)
  19. return E_ARG_HI;
  20. if (argt[0] != CELL_TYPE)
  21. return E_RES_TYPE;
  22. for (i = 0; i < columns; i++)
  23. res[i] = i + 1;
  24. return 0;
  25. }
  26. int f_row(int argc, const int *argt, void **args)
  27. {
  28. CELL *res = args[0];
  29. int row = current_row + 1;
  30. int i;
  31. if (argc > 0)
  32. return E_ARG_HI;
  33. if (argt[0] != CELL_TYPE)
  34. return E_RES_TYPE;
  35. for (i = 0; i < columns; i++)
  36. res[i] = row;
  37. return 0;
  38. }
  39. int f_depth(int argc, const int *argt, void **args)
  40. {
  41. CELL *res = args[0];
  42. int depth = current_depth + 1;
  43. int i;
  44. if (argc > 0)
  45. return E_ARG_HI;
  46. if (argt[0] != CELL_TYPE)
  47. return E_RES_TYPE;
  48. for (i = 0; i < columns; i++)
  49. res[i] = depth;
  50. return 0;
  51. }
  52. int f_nrows(int argc, const int *argt, void **args)
  53. {
  54. CELL *res = args[0];
  55. int i;
  56. if (argc > 0)
  57. return E_ARG_HI;
  58. if (argt[0] != CELL_TYPE)
  59. return E_RES_TYPE;
  60. for (i = 0; i < columns; i++)
  61. res[i] = rows;
  62. return 0;
  63. }
  64. int f_ncols(int argc, const int *argt, void **args)
  65. {
  66. CELL *res = args[0];
  67. int i;
  68. if (argc > 0)
  69. return E_ARG_HI;
  70. if (argt[0] != CELL_TYPE)
  71. return E_RES_TYPE;
  72. for (i = 0; i < columns; i++)
  73. res[i] = columns;
  74. return 0;
  75. }
  76. int f_ndepths(int argc, const int *argt, void **args)
  77. {
  78. CELL *res = args[0];
  79. int i;
  80. if (argc > 0)
  81. return E_ARG_HI;
  82. if (argt[0] != CELL_TYPE)
  83. return E_RES_TYPE;
  84. for (i = 0; i < columns; i++)
  85. res[i] = depths;
  86. return 0;
  87. }