band_files.c 888 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/glocale.h>
  4. #include "globals.h"
  5. /* open and allocate space for the subgroup band files */
  6. int open_band_files(void)
  7. {
  8. int n, nbands;
  9. char *name, *mapset;
  10. /* allocate row buffers and open raster maps */
  11. nbands = Refer.nfiles;
  12. Bandbuf = (CELL **) G_malloc(nbands * sizeof(CELL *));
  13. Bandfd = (int *)G_malloc(nbands * sizeof(int));
  14. for (n = 0; n < nbands; n++) {
  15. Bandbuf[n] = Rast_allocate_c_buf();
  16. name = Refer.file[n].name;
  17. mapset = Refer.file[n].mapset;
  18. Bandfd[n] = Rast_open_old(name, mapset);
  19. }
  20. return 0;
  21. }
  22. /* close and free space for the subgroup band files */
  23. int close_band_files(void)
  24. {
  25. int n, nbands;
  26. nbands = Refer.nfiles;
  27. for (n = 0; n < nbands; n++) {
  28. G_free(Bandbuf[n]);
  29. Rast_close(Bandfd[n]);
  30. }
  31. G_free(Bandbuf);
  32. G_free(Bandfd);
  33. return 0;
  34. }