open_files.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/raster.h>
  4. #include <grass/glocale.h>
  5. #include "global.h"
  6. int open_files(void)
  7. {
  8. char *name, *mapset;
  9. FILE *fd;
  10. int n, missing;
  11. I_init_group_ref(&ref);
  12. G_strip(group);
  13. if (!I_find_group(group))
  14. G_fatal_error(_("Group <%s> not found in current mapset"), group);
  15. G_strip(subgroup);
  16. if (!I_find_subgroup(group, subgroup))
  17. G_fatal_error(_("Subgroup <%s> in group <%s> not found"),
  18. subgroup, group);
  19. I_free_group_ref(&ref);
  20. I_get_subgroup_ref(group, subgroup, &ref);
  21. missing = 0;
  22. for (n = 0; n < ref.nfiles; n++) {
  23. name = ref.file[n].name;
  24. mapset = ref.file[n].mapset;
  25. if (G_find_raster(name, mapset) == NULL) {
  26. missing = 1;
  27. G_warning(_("Raster map <%s> do not exists in subgroup <%s>"),
  28. G_fully_qualified_name(name, mapset), subgroup);
  29. }
  30. }
  31. if (missing)
  32. G_fatal_error(_("No raster maps found"));
  33. if (ref.nfiles <= 1) {
  34. if (ref.nfiles <= 0)
  35. G_warning(_("Subgroup <%s> doesn't have any raster maps"),
  36. subgroup);
  37. else
  38. G_warning(_("Subgroup <%s> only has 1 raster map"), subgroup);
  39. G_fatal_error(_("Subgroup must have at least 2 raster maps"));
  40. }
  41. cell = (DCELL **) G_malloc(ref.nfiles * sizeof(DCELL *));
  42. cellfd = (int *)G_malloc(ref.nfiles * sizeof(int));
  43. for (n = 0; n < ref.nfiles; n++) {
  44. cell[n] = Rast_allocate_d_buf();
  45. name = ref.file[n].name;
  46. mapset = ref.file[n].mapset;
  47. cellfd[n] = Rast_open_old(name, mapset);
  48. }
  49. I_init_signatures(&in_sig, ref.nfiles);
  50. if (insigfile) {
  51. fd = I_fopen_signature_file_old(group, subgroup, insigfile);
  52. if (fd == NULL)
  53. G_fatal_error(_("Unable to open seed signature file <%s>"),
  54. insigfile);
  55. n = I_read_signatures(fd, &in_sig);
  56. fclose(fd);
  57. if (n < 0)
  58. G_fatal_error(_("Unable to read signature file <%s>"),
  59. insigfile);
  60. if (in_sig.nsigs > 255)
  61. G_fatal_error(_("<%s> has too many signatures (limit is 255)"),
  62. insigfile);
  63. maxclass = in_sig.nsigs;
  64. }
  65. return 0;
  66. }