some fixes in draw() (transform multiple op in dc sweep also if per-node rawfile specified), handle per-node rawfile in graph_fullyzoom()

This commit is contained in:
stefan schippers 2023-11-17 01:20:52 +01:00
parent 397293f227
commit 913614b558
1 changed files with 79 additions and 28 deletions

View File

@ -2105,7 +2105,7 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
if(!gr->digital) {
int dset;
int p, v;
const char *bus_msb = NULL;
char *bus_msb = NULL;
int sweep_idx = 0;
double val, start, end;
double min=0.0, max=0.0;
@ -2116,6 +2116,10 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
char *custom_rawfile = NULL; /* "rawfile" attr. set in graph: load and switch to specified raw */
char *sim_type = NULL;
Raw *raw = NULL;
char *tmp_ptr = NULL;
int save_extra_idx = -1;
int save_datasets = -1, save_npoints = -1;
dbg(1, "graph_fullyzoom(): graph_dataset=%d\n", graph_dataset);
my_strdup2(_ALLOC_ID_, &node, get_tok_value(r->prop_ptr,"node",0));
@ -2123,34 +2127,70 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
my_strdup2(_ALLOC_ID_, &custom_rawfile, get_tok_value(r->prop_ptr,"rawfile",0));
my_strdup2(_ALLOC_ID_, &sim_type, get_tok_value(r->prop_ptr,"sim_type",0));
if(sch_waves_loaded() != -1 && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type);
}
raw = xctx->raw;
save_extra_idx = xctx->extra_idx;
nptr = node;
sptr = sweep;
start = (gr->gx1 <= gr->gx2) ? gr->gx1 : gr->gx2;
end = (gr->gx1 <= gr->gx2) ? gr->gx2 : gr->gx1;
while( (ntok = my_strtok_r(nptr, "\n\t ", "\"", 4, &saven)) ) {
char *c1, *c2;
char *nd = find_nth(ntok, "%", "\"", 0, 2);
/* do not consider % in alias names (like SUN %; sun 100 *) */
c1 = strstr(ntok, ";");
c2 = strstr(ntok, "%");
if(c1 && c2 && c1 > c2) nd[0] = '\0';
char *nd = NULL;
char str_extra_idx[30];
if(sch_waves_loaded() != -1 && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type);
}
raw = xctx->raw;
my_strdup2(_ALLOC_ID_, &nd, find_nth(ntok, "%", "\"", 0, 2));
/* if %<n> is specified after node name, <n> is the dataset number to plot in graph */
if(nd[0]) {
node_dataset = atoi(nd);
my_strdup(_ALLOC_ID_, &ntok_copy, find_nth(ntok, "%", "\"", 0, 1));
int pos = 1;
if(isonlydigit(find_nth(nd, "\n ", "\"", 0, 1))) pos = 2;
if(raw && raw->values) {
char *node_rawfile = NULL;
char *node_sim_type = NULL;
tclvareval("subst {", find_nth(nd, "\n ", "\"", 0, pos), "}", NULL);
my_strdup2(_ALLOC_ID_, &node_rawfile, tclresult());
tclvareval("subst {", find_nth(nd, "\n ", "\"", 0, pos + 1), "}", NULL);
my_strdup2(_ALLOC_ID_, &node_sim_type, tclresult()[0] ? tclresult() :
sim_type[0] ? sim_type : xctx->raw->sim_type);
dbg(1, "node_rawfile=|%s| node_sim_type=|%s|\n", node_rawfile, node_sim_type);
if(node_rawfile && node_rawfile[0]) {
extra_rawfile(1, node_rawfile, node_sim_type);
raw = xctx->raw;
}
my_free(_ALLOC_ID_, &node_rawfile);
my_free(_ALLOC_ID_, &node_sim_type);
}
if(pos == 2) node_dataset = atoi(nd);
else node_dataset = -1;
dbg(1, "nd=|%s|, node_dataset = %d\n", nd, node_dataset);
my_strdup(_ALLOC_ID_, &ntok_copy, find_nth(ntok, "%", "\"", 4, 1));
} else {
node_dataset = -1;
my_strdup(_ALLOC_ID_, &ntok_copy, ntok);
}
/* transform multiple OP points into a dc sweep */
if(raw && raw->sim_type && !strcmp(raw->sim_type, "op") && raw->datasets > 1 && raw->npoints[0] == 1) {
save_datasets = raw->datasets;
raw->datasets = 1;
save_npoints = raw->npoints[0];
raw->npoints[0] = raw->allpoints;
}
my_free(_ALLOC_ID_, &nd);
dbg(1, "ntok=|%s|\nntok_copy=|%s|\nnode_dataset=%d\n", ntok, ntok_copy, node_dataset);
tmp_ptr = find_nth(ntok_copy, ";", "\"", 4, 2);
if(strstr(tmp_ptr, ",")) {
tmp_ptr = find_nth(tmp_ptr, ",", "\"", 4, 1);
/* also trim spaces */
my_strdup2(_ALLOC_ID_, &bus_msb, trim_chars(tmp_ptr, "\n "));
}
dbg(1, "ntok_copy=|%s|, bus_msb=|%s|\n", ntok_copy, bus_msb ? bus_msb : "NULL");
stok = my_strtok_r(sptr, "\n\t ", "\"", 0, &saves);
nptr = sptr = NULL;
if(stok && stok[0]) {
@ -2158,7 +2198,6 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
if( sweep_idx == -1) sweep_idx = 0;
}
dbg(1, "graph_fullyzoom(): ntok_copy=%s\n", ntok_copy);
bus_msb = strstr(ntok_copy, ",");
v = -1;
if(!bus_msb) {
char *express = NULL;
@ -2216,7 +2255,18 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
sweepvar_wrap++;
} /* for(dset...) */
}
} /* while( (ntok_copy = my_strtok_r(nptr, "\n\t ", "\"", 0, &saven)) ) */
if(bus_msb) my_free(_ALLOC_ID_, &bus_msb);
if(save_npoints != -1) { /* restore multiple OP points from artificial dc sweep */
raw->datasets = save_datasets;
raw->npoints[0] = save_npoints;
}
if(save_extra_idx != -1) {
my_snprintf(str_extra_idx, S(str_extra_idx), "%d", save_extra_idx);
extra_rawfile(2, str_extra_idx, NULL);
raw = xctx->raw;
}
} /* while( (ntok = my_strtok_r(nptr, "\n\t ", "\"", 0, &saven)) ) */
if(max == min) max += 0.01;
min = floor_to_n_digits(min, 2);
max = ceil_to_n_digits(max, 2);
@ -3288,15 +3338,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
my_strdup2(_ALLOC_ID_, &sweep, get_tok_value(r->prop_ptr,"sweep",0));
my_strdup2(_ALLOC_ID_, &custom_rawfile, get_tok_value(r->prop_ptr,"rawfile",0));
my_strdup2(_ALLOC_ID_, &sim_type, get_tok_value(r->prop_ptr,"sim_type",0));
/* transform multiple OP points into a dc sweep */
if(raw && raw->sim_type && !strcmp(raw->sim_type, "op") && raw->datasets > 1 && raw->npoints[0] == 1) {
save_datasets = raw->datasets;
raw->datasets = 1;
save_npoints = raw->npoints[0];
raw->npoints[0] = raw->allpoints;
}
save_extra_idx = xctx->extra_idx;
dbg(1, "1: save_extra_idx=%d\n", save_extra_idx);
nptr = node;
cptr = color;
@ -3357,6 +3399,16 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
node_dataset = -1;
my_strdup(_ALLOC_ID_, &ntok_copy, ntok);
}
/* transform multiple OP points into a dc sweep */
if(raw && raw->sim_type && !strcmp(raw->sim_type, "op") && raw->datasets > 1 && raw->npoints[0] == 1) {
save_datasets = raw->datasets;
raw->datasets = 1;
save_npoints = raw->npoints[0];
raw->npoints[0] = raw->allpoints;
}
my_free(_ALLOC_ID_, &nd);
dbg(1, "ntok=|%s|\nntok_copy=|%s|\nnode_dataset=%d\n", ntok, ntok_copy, node_dataset);
@ -3513,7 +3565,10 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
} /* if( expression || (idx = get_raw_index(bus_msb ? bus_msb : express)) != -1 ) */
++wcnt;
if(bus_msb) my_free(_ALLOC_ID_, &bus_msb);
if(save_npoints != -1) { /* restore multiple OP points from artificial dc sweep */
raw->datasets = save_datasets;
raw->npoints[0] = save_npoints;
}
if(save_extra_idx != -1) {
my_snprintf(str_extra_idx, S(str_extra_idx), "%d", save_extra_idx);
extra_rawfile(2, str_extra_idx, NULL);
@ -3521,10 +3576,6 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
}
} /* while( (ntok = my_strtok_r(nptr, "\n\t ", "", 0, &saven)) ) */
if(save_npoints != -1) { /* restore multiple OP points from artificial dc sweep */
raw->datasets = save_datasets;
raw->npoints[0] = save_npoints;
}
if(ntok_copy) my_free(_ALLOC_ID_, &ntok_copy);
if(express) my_free(_ALLOC_ID_, &express);
/* if(sch_waves_loaded()!= -1 && custom_rawfile[0]) extra_rawfile(5, NULL, NULL); */