main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * r.out.gridatb: Exports GRASS raster map to GRIDATB.FOR map file (TOPMODEL)
  3. *
  4. * GRIDATB.FOR Author: Keith Beven <k.beven@lancaster.ac.uk>
  5. *
  6. * Copyright (C) 2000 by the GRASS Development Team
  7. * Author: Huidae Cho <grass4u@gmail.com>
  8. * Hydro Laboratory, Kyungpook National University
  9. * South Korea
  10. *
  11. * This program is free software under the GPL (>=v2)
  12. * Read the file COPYING coming with GRASS for details.
  13. *
  14. */
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <grass/gis.h>
  18. #include <grass/raster.h>
  19. #include <grass/glocale.h>
  20. static void rdwr_gridatb(const char *iname, const char *file)
  21. {
  22. int fd = Rast_open_old(iname, "");
  23. FILE *fp = fopen(file, "w");
  24. DCELL *dcell = Rast_allocate_d_buf();
  25. struct Cell_head cellhd;
  26. int row, col;
  27. Rast_get_window(&cellhd);
  28. fprintf(fp, "%s\n", Rast_get_cell_title(iname, ""));
  29. fprintf(fp, "%d %d %lf\n", cellhd.cols, cellhd.rows, cellhd.ns_res);
  30. for (row = 0; row < cellhd.rows; row++) {
  31. G_percent(row, cellhd.rows, 2);
  32. Rast_get_d_row(fd, dcell, row);
  33. for (col = 0; col < cellhd.cols; col++) {
  34. if (Rast_is_d_null_value(&dcell[col]))
  35. fprintf(fp, " 9999.00 ");
  36. else
  37. fprintf(fp, "%9.2f", (double) dcell[col]);
  38. if (!((col + 1) % 8) || col == cellhd.cols - 1)
  39. fprintf(fp, "\n");
  40. }
  41. }
  42. Rast_close(fd);
  43. }
  44. int main(int argc, char **argv)
  45. {
  46. struct GModule *module;
  47. struct
  48. {
  49. struct Option *input;
  50. struct Option *output;
  51. } params;
  52. G_gisinit(argv[0]);
  53. /* Set description */
  54. module = G_define_module();
  55. G_add_keyword(_("raster"));
  56. G_add_keyword(_("export"));
  57. module->description =
  58. _("Exports GRASS raster map to GRIDATB.FOR map file (TOPMODEL).");
  59. params.input = G_define_standard_option(G_OPT_R_INPUT);
  60. params.output = G_define_standard_option(G_OPT_F_OUTPUT);
  61. if (G_parser(argc, argv))
  62. exit(1);
  63. rdwr_gridatb(params.input->answer, params.output->answer);
  64. return EXIT_SUCCESS;
  65. }