int openfiles(struct parms *parms, struct files *files) { struct Ref Ref; /* subgroup reference list */ int n; if (!I_get_subgroup_ref(parms->group, parms->subgroup, &Ref)) G_fatal_error(_("Unable to read REF file for subgroup <%s> in group <%s>"), parms->subgroup, parms->group); if (Ref.nfiles <= 0) G_fatal_error(_("Subgroup <%s> in group <%s> contains no raster maps"), parms->subgroup, parms->group); /* allocate file descriptors, and io buffer */ files->cellbuf = Rast_allocate_d_buf(); files->outbuf = Rast_allocate_c_buf(); files->isdata = G_malloc(Rast_window_cols()); files->nbands = Ref.nfiles; files->band_fd = (int *)G_calloc(Ref.nfiles, sizeof(int)); /* open all group maps for reading */ for (n = 0; n < Ref.nfiles; n++) files->band_fd[n] = open_cell_old(Ref.file[n].name, Ref.file[n].mapset); /* open output map */ files->output_fd = open_cell_new(parms->output_map); if (parms->goodness_map) files->goodness_fd = Rast_open_new(parms->goodness_map, FCELL_TYPE); else files->goodness_fd = -1; return 0; }
int open_files(void) { char *name, *mapset; FILE *fd; int n; I_init_group_ref(&Ref); if (!I_find_group(group)) G_fatal_error(_("Group <%s> not found"), group); if (!I_find_subgroup(group, subgroup)) G_fatal_error(_("Subgroup <%s> in group <%s> not found"), subgroup, group); I_get_subgroup_ref(group, subgroup, &Ref); if (Ref.nfiles <= 1) { if (Ref.nfiles <= 0) G_fatal_error(_("Subgroup <%s> of group <%s> doesn't have any raster maps. " "The subgroup must have at least 2 raster maps.")); else G_fatal_error(_("Subgroup <%s> of group <%s> only has 1 raster map. " "The subgroup must have at least 2 raster maps.")); } cell = (DCELL **) G_malloc(Ref.nfiles * sizeof(DCELL *)); cellfd = (int *)G_malloc(Ref.nfiles * sizeof(int)); P = (double *)G_malloc(Ref.nfiles * sizeof(double)); for (n = 0; n < Ref.nfiles; n++) { cell[n] = Rast_allocate_d_buf(); name = Ref.file[n].name; mapset = Ref.file[n].mapset; cellfd[n] = Rast_open_old(name, mapset); } I_init_signatures(&S, Ref.nfiles); fd = I_fopen_signature_file_old(group, subgroup, sigfile); if (fd == NULL) G_fatal_error(_("Unable to open signature file <%s>"), sigfile); n = I_read_signatures(fd, &S); fclose(fd); if (n < 0) G_fatal_error(_("Unable to read signature file <%s>"), sigfile); if (S.nsigs > 255) G_fatal_error(_("<%s> has too many signatures (limit is 255)"), sigfile); B = (double *)G_malloc(S.nsigs * sizeof(double)); invert_signatures(); class_fd = Rast_open_c_new(class_name); class_cell = Rast_allocate_c_buf(); reject_cell = NULL; if (reject_name) { reject_fd = Rast_open_c_new(reject_name); reject_cell = Rast_allocate_c_buf(); } return 0; }