add `xschem raw del node` command

This commit is contained in:
stefan schippers 2024-02-25 12:21:13 +01:00
parent 2fae34caa1
commit 7a45497b45
7 changed files with 69 additions and 68 deletions

View File

@ -509,28 +509,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
@ -1096,7 +1074,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
<li><kbd> push_undo</kbd></li><pre>
Push current state on undo stack </pre>
<li><kbd> raw what ...</kbd></li><pre>
what = add | clear | datasets | index | info | loaded | list | new | points | rawfile |
what = add | clear | datasets | index | info | loaded | list | new | points | rawfile | del |
read | set | sim_type | switch | switch_back | table_read | value | values | vars |
xschem raw read filename [type [sweep1 sweep2]]
@ -1109,6 +1087,9 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
unload given file and type. If type not given delete all type sfrom rawfile
if no file is given unload all raw files.
xschem raw del name
delete named vector from current raw file
xschem raw info
print information about loaded raw files and show the currently active one.
@ -1555,22 +1536,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"

View File

@ -230,7 +230,7 @@ void backannotate_at_cursor_b_pos(xRect *r, Graph_ctx *gr)
save_npoints = raw->npoints[0];
raw->npoints[0] = raw->allpoints;
}
sweep_idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1));
sweep_idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1), NULL);
if(sweep_idx < 0) sweep_idx = 0;
cursor2 = xctx->graph_cursor2_x;
start = (gr->gx1 <= gr->gx2) ? gr->gx1 : gr->gx2;
@ -561,7 +561,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
my_free(_ALLOC_ID_, &rawfile);
my_free(_ALLOC_ID_, &sim_type);
idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1));
idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1), NULL);
dset = dataset == -1 ? 0 : dataset;
if(idx < 0 ) idx = 0;
@ -978,7 +978,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
/*
* this calculation is done in 1st loop, only for master graph
* and applied to all locked graphs
int idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1));
int idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1), NULL);
int dset = dataset == -1 ? 0 : dataset;
double wwx1, wwx2, pp, delta, ccx, ddx;

View File

@ -2037,7 +2037,7 @@ static SPICE_DATA **get_bus_idx_array(const char *ntok, int *n_bits)
while( (bit_name = my_strtok_r(NULL, ";, \n", "", 0, &saven)) ) {
int idx;
if(p >= *n_bits) break; /* security check to avoid out of bound writing */
if( (idx = get_raw_index(bit_name)) != -1) {
if( (idx = get_raw_index(bit_name, NULL)) != -1) {
idx_arr[p] = xctx->raw->values[idx];
} else {
idx_arr[p] = NULL;
@ -2083,7 +2083,7 @@ int graph_fullxzoom(int i, Graph_ctx *gr, int dataset)
if((i == xctx->graph_master) && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
}
idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1));
idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1), NULL);
dbg(1, "graph_fullxzoom(): sweep idx=%d\n", idx);
if(idx < 0 ) idx = 0;
if(i != xctx->graph_master ) {
@ -2234,7 +2234,7 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
stok = my_strtok_r(sptr, "\n\t ", "\"", 0, &saves);
nptr = sptr = NULL;
if(stok && stok[0]) {
sweep_idx = get_raw_index(stok);
sweep_idx = get_raw_index(stok, NULL);
if( sweep_idx == -1) sweep_idx = 0;
}
dbg(1, "graph_fullyzoom(): ntok_copy=%s\n", ntok_copy);
@ -2251,7 +2251,7 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
* This is *expecially needed if graph contains more than one expression */
v = calc_custom_data_yrange(sweep_idx, express, gr);
} else {
v = get_raw_index(express);
v = get_raw_index(express, NULL);
}
my_free(_ALLOC_ID_, &express);
dbg(1, "graph_fullyzoom(): v=%d\n", v);
@ -3039,7 +3039,7 @@ int edit_wave_attributes(int what, int i, Graph_ctx *gr)
nptr = cptr = sptr = NULL;
dbg(1, "ntok=%s ctok=%s\n", ntok, ctok? ctok: "NULL");
if(stok && stok[0]) {
sweep_idx = get_raw_index(stok);
sweep_idx = get_raw_index(stok, NULL);
if( sweep_idx == -1) sweep_idx = 0;
}
if(gr->digital) {
@ -3219,7 +3219,7 @@ int find_closest_wave(int i, Graph_ctx *gr)
nptr = sptr = NULL;
dbg(1, "ntok=%s\n", ntok);
if(stok && stok[0]) {
sweep_idx = get_raw_index(stok);
sweep_idx = get_raw_index(stok, NULL);
if( sweep_idx == -1) {
sweep_idx = 0;
}
@ -3238,7 +3238,7 @@ int find_closest_wave(int i, Graph_ctx *gr)
}
}
if(expression) idx = raw->nvars;
else idx = get_raw_index(express);
else idx = get_raw_index(express, NULL);
dbg(1, "find_closest_wave(): expression=%d, idx=%d\n", expression, idx);
if( idx != -1 ) {
int p, dset, ofs, ofs_end;
@ -3310,7 +3310,7 @@ int find_closest_wave(int i, Graph_ctx *gr)
sweepvar_wrap++;
} /* for(dset...) */
} /* if( (idx = get_raw_index(ntok)) != -1 ) */
} /* if( (idx = get_raw_index(ntok, NULL)) != -1 ) */
++wcnt;
} /* while( (ntok = my_strtok_r(nptr, "\n\t ", "", 0, &saven)) ) */
dbg(0, "closest dataset=%d\n", closest_dataset);
@ -3475,7 +3475,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
if(wc < 0) wc = 4;
if(wc >= cadlayers) wc = cadlayers - 1;
if(stok && stok[0]) {
sweep_idx = get_raw_index(stok);
sweep_idx = get_raw_index(stok, NULL);
if( sweep_idx == -1) {
sweep_idx = 0;
}
@ -3496,7 +3496,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
}
}
/* quickly find index number of ntok_copy variable to be plotted */
if( expression || (idx = get_raw_index(bus_msb ? bus_msb : express)) != -1 ) {
if( expression || (idx = get_raw_index(bus_msb ? bus_msb : express, NULL)) != -1 ) {
int p, dset, ofs, ofs_end;
int poly_npoints;
int first, last;
@ -3610,7 +3610,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
my_free(_ALLOC_ID_, &point);
if(idx_arr) my_free(_ALLOC_ID_, &idx_arr);
} /* if( expression || (idx = get_raw_index(bus_msb ? bus_msb : express)) != -1 ) */
} /* if( expression || (idx = get_raw_index(bus_msb ? bus_msb : express, NULL)) != -1 ) */
++wcnt;
if(bus_msb) my_free(_ALLOC_ID_, &bus_msb);
if(save_npoints != -1) { /* restore multiple OP points from artificial dc sweep */

View File

@ -914,6 +914,33 @@ int raw_read(const char *f, Raw **rawptr, const char *type, double sweep1, doubl
return 0;
}
int raw_deletevar(const char *name)
{
int ret = 0;
int i, n;
Raw *raw = xctx->raw;
Int_hashentry *entry;
n = get_raw_index(name, &entry);
if(n < 0) return ret;
dbg(0, "n=%d, %s \n", n, entry->token);
int_hash_lookup(&raw->table, entry->token, 0, XDELETE);
my_free(_ALLOC_ID_, &raw->names[n]);
for(i = n + 1; i < raw->nvars; i++) {
int_hash_lookup(&raw->table, raw->names[i], i - 1, XINSERT); /* update hash table */
raw->names[i - 1] = raw->names[i];
}
my_free(_ALLOC_ID_, &raw->values[n]);
for(i = n + 1; i <= raw->nvars; i++) {
raw->values[i - 1] = raw->values[i];
}
raw->nvars--;
my_realloc(_ALLOC_ID_, &raw->names, sizeof(char *) * raw->nvars);
my_realloc(_ALLOC_ID_, &raw->values, sizeof(SPICE_DATA *) * raw->nvars + 1);
ret = 1;
return ret;
}
/* create a new raw file with '(max - min) / step' points with only a sweep variable in it. */
int new_rawfile(const char *name, const char *type, const char *sweepvar,
double start, double end, double step)
@ -1355,7 +1382,7 @@ int table_read(const char *f)
}
/* given a node XXyy try XXyy , xxyy, XXYY, v(XXyy), v(xxyy), V(XXYY) */
int get_raw_index(const char *node)
int get_raw_index(const char *node, Int_hashentry **entry_ret)
{
char inode[512];
char vnode[512];
@ -1378,6 +1405,8 @@ int get_raw_index(const char *node)
ptr += 2;
entry = int_hash_lookup(&xctx->raw->table, ptr, 0, XLOOKUP);
}
if(entry_ret) *entry_ret = entry;
if(entry) return entry->value;
}
return -1;
@ -1488,7 +1517,7 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
y = xctx->raw->values[xctx->raw->nvars]; /* custom plot data column */
if(yname != NULL) {
int yidx = get_raw_index(yname);
int yidx = get_raw_index(yname, NULL);
if(yidx >= 0) {
y = xctx->raw->values[yidx]; /* provided index */
}
@ -1571,7 +1600,7 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
stack1[stackptr1++].d = atof_spice(n);
}
else { /* SPICE_NODE */
idx = get_raw_index(n);
idx = get_raw_index(n, NULL);
if(idx == -1) {
dbg(1, "plot_raw_custom_data(): no data found: %s\n", n);
my_free(_ALLOC_ID_, &ntok_copy);

View File

@ -3419,7 +3419,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
case 'r': /*----------------------------------------------*/
/* raw what ...
* what = add | clear | datasets | index | info | loaded | list | new | points | rawfile |
* what = add | clear | datasets | index | info | loaded | list | new | points | rawfile | del |
* read | set | sim_type | switch | switch_back | table_read | value | values | vars |
*
* xschem raw read filename [type [sweep1 sweep2]]
@ -3432,6 +3432,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
* unload given file and type. If type not given delete all type sfrom rawfile
* if no file is given unload all raw files.
*
* xschem raw del name
* delete named vector from current raw file
*
* xschem raw info
* print information about loaded raw files and show the currently active one.
*
@ -3551,6 +3554,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
ret = extra_rawfile(5, NULL, NULL, -1.0, -1.0);
update_op();
Tcl_SetResult(interp, my_itoa(ret), TCL_VOLATILE);
} else if(argc > 3 && !strcmp(argv[2], "del")) {
ret = raw_deletevar(argv[3]);
Tcl_SetResult(interp, my_itoa(ret), TCL_VOLATILE);
} else if(argc > 2 && !strcmp(argv[2], "clear")) {
if(argc > 4) {
ret = extra_rawfile(3, argv[3], argv[4], -1.0, -1.0);
@ -3570,7 +3576,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
const char *node = argv[3];
int idx = -1;
if(argc > 5) dataset = atoi(argv[5]);
idx = get_raw_index(node);
idx = get_raw_index(node, NULL);
if(idx >= 0) {
double val;
if( (dataset >=0 && point >= 0 && point < raw->npoints[dataset]) ||
@ -3586,14 +3592,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
} else if(argc > 3 && !strcmp(argv[2], "index")) {
/* xschem raw index v(ldcp) */
int idx;
idx = get_raw_index(argv[3]);
idx = get_raw_index(argv[3], NULL);
Tcl_SetResult(interp, my_itoa(idx), TCL_VOLATILE);
} else if(argc > 3 && !strcmp(argv[2], "values")) {
/* xschem raw values ldcp [dataset] */
int idx;
char n[70];
int p, dataset = 0;
idx = get_raw_index(argv[3]);
idx = get_raw_index(argv[3], NULL);
if(argc > 4) dataset = atoi(argv[4]);
if(idx >= 0) {
int np;
@ -3644,7 +3650,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
const char *node = argv[3];
int idx = -1;
if(argc > 6) dataset = atoi(argv[6]);
idx = get_raw_index(node);
idx = get_raw_index(node, NULL);
if(idx >= 0) {
if( dataset < xctx->raw->datasets &&
( (dataset >=0 && point >= 0 && point < raw->npoints[dataset]) ||

View File

@ -3780,7 +3780,7 @@ const char *translate(int inst, const char* s)
if(rn) my_free(_ALLOC_ID_, &rn);
strtolower(fqnet);
dbg(1, "translate() @spice_get_voltage: fqnet=%s start_level=%d\n", fqnet, start_level);
idx = get_raw_index(fqnet);
idx = get_raw_index(fqnet, NULL);
if(idx >= 0) {
val = xctx->raw->cursor_b_val[idx];
}
@ -3850,7 +3850,7 @@ const char *translate(int inst, const char* s)
}
strtolower(fqnet);
dbg(1, "translate(): net=%s, fqnet=%s start_level=%d\n", net, fqnet, start_level);
idx = get_raw_index(fqnet);
idx = get_raw_index(fqnet, NULL);
if(idx >= 0) {
val = xctx->raw->cursor_b_val[idx];
}
@ -3920,7 +3920,7 @@ const char *translate(int inst, const char* s)
}
strtolower(fqdev);
dbg(1, "fqdev=%s\n", fqdev);
idx = get_raw_index(fqdev);
idx = get_raw_index(fqdev, NULL);
if(idx >= 0) {
val = xctx->raw->cursor_b_val[idx];
}
@ -3981,8 +3981,8 @@ const char *translate(int inst, const char* s)
strtolower(fqnet2);
dbg(1, "translate(): fqnet1=%s start_level=%d\n", fqnet1, start_level);
dbg(1, "translate(): fqnet2=%s start_level=%d\n", fqnet2, start_level);
idx1 = get_raw_index(fqnet1);
idx2 = get_raw_index(fqnet2);
idx1 = get_raw_index(fqnet1, NULL);
idx2 = get_raw_index(fqnet2, NULL);
if(idx1 < 0 || idx2 < 0) {
valstr = "";
xctx->tok_size = 0;
@ -4048,7 +4048,7 @@ const char *translate(int inst, const char* s)
}
dbg(1, "fqdev=%s\n", fqdev);
strtolower(fqdev);
idx = get_raw_index(fqdev);
idx = get_raw_index(fqdev, NULL);
if(idx >= 0) {
val = xctx->raw->cursor_b_val[idx];
}

View File

@ -1224,6 +1224,7 @@ extern int embed_rawfile(const char *rawfile);
extern int read_rawfile_from_attr(const char *b64s, size_t length, const char *type);
extern int raw_read_from_attr(Raw **rawptr, const char *type, double sweep1, double sweep2);
extern int raw_add_vector(const char *varname, const char *expr);
extern int raw_deletevar(const char *name);
extern int new_rawfile(const char *name, const char *type, const char *sweepvar,
double start, double end, double step);
extern char *base64_from_file(const char *f, size_t *length);
@ -1237,7 +1238,7 @@ extern int set_rect_extraptr(int what, xRect *drptr);
extern unsigned char *base64_decode(const char *data, const size_t input_length, size_t *output_length);
extern char *base64_encode(const unsigned char *data, const size_t input_length, size_t *output_length, int brk);
extern unsigned char *ascii85_encode(const unsigned char *data, const size_t input_length, size_t *output_length);
extern int get_raw_index(const char *node);
extern int get_raw_index(const char *node, Int_hashentry **entry_ret);
extern void free_rawfile(Raw **rawptr, int dr);
extern int update_op();
extern int extra_rawfile(int what, const char *f, const char *type, double sweep1, double sweep2);