int run_cmd_list(ll_node_t ** cmd_list) { char *cmd; int rc; int flag = 0; while( (cmd = shift_ll(cmd_list) ) != NULL) { rc = system(cmd); if(rc != 0) { flag = -1; WARNING("run cmd %s failed.", cmd); } } return flag; }
int segment(struct SigSet *S, /* class parameters */ struct parms *parms, struct files *files) { int block_size; /* size of subregion blocks */ int ml; /* max likelihood? */ DCELL ***img; /* multispectral image, img[band][i][j] */ int last_row; int wd, ht; /* image width and height */ struct Region region; /* specifies image subregion */ int nbands; /* number of bands */ int nclasses; /* number of classes */ LIKELIHOOD ****ll_pym; /* pyramid of log likelihoods */ unsigned char ***sf_pym; /* pyramid of segmentations */ int D; /* number of levels in pyramid */ double *alpha_dec; /* class transition probabilities */ int i; ml = parms->ml; /* use maxl? */ block_size = parms->blocksize; wd = Rast_window_cols(); /* get width from GRASS */ ht = Rast_window_rows(); /* get height from GRASS */ /* make blocksize a power of 2 */ if (block_size < 8) block_size = 8; for (i = 0; (block_size >> i) > 1; i++) { } block_size = 1 << i; /**** this code may stay the same ******/ nbands = S->nbands; nclasses = S->nclasses; /* Check for too many classes */ if (nclasses > 256) G_fatal_error(_("Number of classes must be < 256")); /* allocate alpha_dec parameters */ D = levels(block_size, block_size); alpha_dec = (double *)G_malloc(D * sizeof(double)); /* allocate image block */ img = (DCELL ***) multialloc(sizeof(DCELL), 3, nbands, block_size, block_size); /* allocate memory for log likelihood pyramid */ ll_pym = (LIKELIHOOD ****) get_cubic_pyramid(block_size, block_size, nclasses, sizeof(LIKELIHOOD)); /* allocate memory for segmentation pyramid */ sf_pym = (unsigned char ***)get_pyramid(wd, ht, sizeof(char)); /* tiled segmentation */ init_reg(®ion, wd, ht, block_size); extract_init(S); last_row = -1; do { if (last_row != region.ymin) G_message(_("Processing rows %d-%d (of %d)..."), region.ymin + 1, region.ymax, ht); last_row = region.ymin; shift_img(img, nbands, ®ion, block_size); /* this reads grass images into the block defined in region */ read_block(img, ®ion, files); shift_ll(ll_pym, ®ion, block_size); extract(img, ®ion, ll_pym[0], S); if (ml) MLE(sf_pym[0], ll_pym[0], ®ion, nclasses); else { for (i = 0; i < D; i++) alpha_dec[i] = 1.0; seq_MAP(sf_pym, ®ion, ll_pym, nclasses, alpha_dec); } } while (increment_reg(®ion, wd, ht, block_size)); write_img(sf_pym[0], wd, ht, S, parms, files); return 0; }