static void popup_any_cb(ExplorerUI *eui, int type) { TreeItemList items; int count, i; Quark *qnew = NULL; Quark *q; GProject *gp; int gpcount = 0; GProject **gplist; TreeGetHighlighted(eui->tree, &items); count = items.count; if (!count) { xfree(items.items); return; } gplist = xmalloc(gapp->gpcount*sizeof(GProject)); if (!gplist) { return; } for (i = 0; i < count; i++) { q = TreeGetQuark(items.items[i]); gp = gproject_from_quark(q); add_to_list(gplist, &gpcount, gp); switch (type) { case HIDE_CB: quark_set_active(q, FALSE); break; case SHOW_CB: quark_set_active(q, TRUE); break; case DELETE_CB: quark_free(q); break; case DUPLICATE_CB: quark_copy(q); break; case ADD_FRAME_CB: qnew = frame_new(q); break; case ADD_GRAPH_CB: qnew = graph_new(q); break; case ADD_SSD_CB: qnew = gapp_ssd_new(q); break; case ADD_SET_CB: qnew = gapp_set_new(q); break; case ADD_AXISGRID_CB: qnew = axisgrid_new(q); break; case ADD_AXIS_CB: qnew = axis_new(q); break; case ADD_LINE_CB: qnew = object_new_complete(q, DO_LINE); break; case ADD_BOX_CB: qnew = object_new_complete(q, DO_BOX); break; case ADD_ARC_CB: qnew = object_new_complete(q, DO_ARC); break; case ADD_TEXT_CB: qnew = atext_new(q); break; } } xfree(items.items); for (i = 0; i < gpcount; i++) { explorer_snapshot(gapp, gplist[i], TRUE); } xfree(gplist); if (qnew) { select_quark_explorer(qnew); } }
static int leval_aac_cb(void *data) { int i, nscols, type; double start, stop; int npts; char *formula[MAX_SET_COLS]; Quark *pset, *gr; GVar *t; Leval_ui *ui = (Leval_ui *) data; Grace *grace; gr = ui->gr; type = GetOptionChoice(ui->set_type); nscols = settype_cols(type); if (xv_evalexpr(ui->start, &start) != RETURN_SUCCESS) { errmsg("Start item undefined"); return RETURN_FAILURE; } if (xv_evalexpr(ui->stop, &stop) != RETURN_SUCCESS) { errmsg("Stop item undefined"); return RETURN_FAILURE; } if (xv_evalexpri(ui->npts, &npts) != RETURN_SUCCESS) { errmsg("Number of points undefined"); return RETURN_FAILURE; } TableCommitEdit(ui->mw, FALSE); for (i = 0; i < nscols; i++) { formula[i] = TableGetCell(ui->mw, i, 0); } pset = gapp_set_new(gr); set_set_type(pset, type); grace = grace_from_quark(pset); t = graal_get_var(grace_get_graal(grace), "$t", TRUE); if (t == NULL) { errmsg("Internal error"); return RETURN_FAILURE; } #if 0 if (t->length != 0) { xfree(t->data); t->length = 0; } t->data = allocate_mesh(start, stop, npts); if (t->data == NULL) { return RETURN_FAILURE; } t->length = npts; if (set_set_length(pset, npts) != RETURN_SUCCESS) { quark_free(pset); XCFREE(t->data); t->length = 0; return RETURN_FAILURE; } #endif for (i = 0; i < nscols; i++) { char buf[32], *expr; int res; /* preparing the expression */ sprintf(buf, "%s = ", dataset_col_name(grace, i)); expr = copy_string(NULL, buf); expr = concat_strings(expr, formula[i]); /* evaluate the expression */ res = graal_parse_line(grace_get_graal(grace), expr, NULL); xfree(expr); if (res != RETURN_SUCCESS) { quark_free(pset); return RETURN_FAILURE; } } #if 0 XCFREE(t->data); t->length = 0; #endif update_set_lists(gr); return RETURN_SUCCESS; }
/* * split a set into lpart length sets */ int do_splitsets(Quark *pset, int lpart) { int i, j, k, ncols, len, plen, npsets; double *x; char s[256]; Quark *gr, *ptmp; Dataset *dsp, *dsptmp; if ((len = set_get_length(pset)) < 2) { errmsg("Set length < 2"); return RETURN_FAILURE; } if (lpart >= len) { errmsg("Split length >= set length"); return RETURN_FAILURE; } if (lpart <= 0) { errmsg("Split length <= 0"); return RETURN_FAILURE; } npsets = (len - 1)/lpart + 1; /* get number of columns in this set */ ncols = set_get_ncols(pset); gr = get_parent_graph(pset); dsp = set_get_dataset(pset); /* now load each set */ for (i = 0; i < npsets; i++) { plen = MIN2(lpart, len - i*lpart); ptmp = gapp_set_new(gr); if (!ptmp) { errmsg("Can't create new set"); return RETURN_FAILURE; } dsptmp = set_get_dataset(ptmp); /* set the plot parameters */ copy_set_params(pset, ptmp); if (set_set_length(ptmp, plen) != RETURN_SUCCESS) { return RETURN_FAILURE; } if (dsp->s) { dataset_enable_scol(dsptmp, TRUE); } /* load the data into each column */ for (k = 0; k < ncols; k++) { x = set_get_col(ptmp, k); for (j = 0; j < plen; j++) { x[j] = dsp->ex[k][i*lpart + j]; } } if (dsp->s) { for (j = 0; j < plen; j++) { dsptmp->s[j] = copy_string(NULL, dsp->s[i*lpart + j]); } } sprintf(s, "partition %d of set %s", i + 1, quark_idstr_get(pset)); set_set_comment(ptmp, s); } /* kill the original set */ quark_free(pset); return RETURN_SUCCESS; }