cleanup test code for custom plots

This commit is contained in:
Stefan Frederik 2022-02-05 02:16:27 +01:00
parent 178d235de6
commit 62766fd618
4 changed files with 18 additions and 23 deletions

View File

@ -388,7 +388,7 @@ void break_wires_at_pins(void)
int changed=0; int changed=0;
hash_wires(); hash_wires();
xctx->need_reb_sel_arr=1; /* <<<< needed ? */ /* xctx->need_reb_sel_arr=1; */ /* seems not needed */
rebuild_selected_array(); rebuild_selected_array();
/* for(k=0;k<xctx->instances;k++) */ /* for(k=0;k<xctx->instances;k++) */

View File

@ -2431,7 +2431,8 @@ void draw_graph(int i, const int flags, Graph_ctx *gr)
XPoint *point = NULL; XPoint *point = NULL;
int dataset = gr->dataset; int dataset = gr->dataset;
int digital = gr->digital; int digital = gr->digital;
if(idx == xctx->graph_nvars -1) plot_raw_custom_data(sweep_idx); /* <<<< */
/* if(idx == xctx->graph_nvars -1) plot_raw_custom_data(sweep_idx); */
ofs = 0; ofs = 0;
start = (gr->gx1 <= gr->gx2) ? gr->gx1 : gr->gx2; start = (gr->gx1 <= gr->gx2) ? gr->gx1 : gr->gx2;
end = (gr->gx1 <= gr->gx2) ? gr->gx2 : gr->gx1; end = (gr->gx1 <= gr->gx2) ? gr->gx2 : gr->gx1;

View File

@ -236,7 +236,7 @@ static void read_binary_block(FILE *fd)
} }
/* read buffer */ /* read buffer */
tmp = my_calloc(1405, xctx->graph_nvars - 1, (sizeof(double *) )); tmp = my_calloc(1405, xctx->graph_nvars, (sizeof(double *) ));
/* allocate storage for binary block */ /* allocate storage for binary block */
if(!xctx->graph_values) xctx->graph_values = my_calloc(118, xctx->graph_nvars, sizeof(SPICE_DATA *)); if(!xctx->graph_values) xctx->graph_values = my_calloc(118, xctx->graph_nvars, sizeof(SPICE_DATA *));
for(p = 0 ; p < xctx->graph_nvars; p++) { for(p = 0 ; p < xctx->graph_nvars; p++) {
@ -245,12 +245,12 @@ static void read_binary_block(FILE *fd)
} }
/* read binary block */ /* read binary block */
for(p = 0; p < xctx->graph_npoints[xctx->graph_datasets]; p++) { for(p = 0; p < xctx->graph_npoints[xctx->graph_datasets]; p++) {
if(fread(tmp, sizeof(double) , xctx->graph_nvars - 1, fd) != xctx->graph_nvars - 1) { if(fread(tmp, sizeof(double) , xctx->graph_nvars, fd) != xctx->graph_nvars) {
dbg(0, "Warning: binary block is not of correct size\n"); dbg(0, "Warning: binary block is not of correct size\n");
} }
/* assign to xschem struct, memory aligned per variable, for cache locality */ /* assign to xschem struct, memory aligned per variable, for cache locality */
if(ac) { if(ac) {
for(v = 0; v < xctx->graph_nvars - 1; v += 2) { /*AC analysis: calculate magnitude */ for(v = 0; v < xctx->graph_nvars; v += 2) { /*AC analysis: calculate magnitude */
if( v == 0 ) /* log scale x */ if( v == 0 ) /* log scale x */
xctx->graph_values[v][offset + p] = log10(sqrt( tmp[v] * tmp[v] + tmp[v + 1] * tmp[v + 1])); xctx->graph_values[v][offset + p] = log10(sqrt( tmp[v] * tmp[v] + tmp[v + 1] * tmp[v + 1]));
else /* dB */ else /* dB */
@ -259,7 +259,7 @@ static void read_binary_block(FILE *fd)
xctx->graph_values[v + 1] [offset + p] = atan2(tmp[v + 1], tmp[v]) * 180.0 / XSCH_PI; xctx->graph_values[v + 1] [offset + p] = atan2(tmp[v + 1], tmp[v]) * 180.0 / XSCH_PI;
} }
} }
else for(v = 0; v < xctx->graph_nvars - 1; v++) { else for(v = 0; v < xctx->graph_nvars; v++) {
xctx->graph_values[v][offset + p] = tmp[v]; xctx->graph_values[v][offset + p] = tmp[v];
} }
} }
@ -302,22 +302,15 @@ static int read_dataset(FILE *fd)
/* after this line comes the binary blob made of nvars * npoints * sizeof(double) bytes */ /* after this line comes the binary blob made of nvars * npoints * sizeof(double) bytes */
if(!strcmp(line, "Binary:\n")) { if(!strcmp(line, "Binary:\n")) {
int npoints = xctx->graph_npoints[xctx->graph_datasets]; int npoints = xctx->graph_npoints[xctx->graph_datasets];
/* name of custom data column */
if( xctx->graph_names && xctx->graph_nvars && !xctx->graph_names[xctx->graph_nvars - 1]) {
my_strcat(542, &xctx->graph_names[xctx->graph_nvars - 1], "%custom%");
int_hash_lookup(xctx->raw_table, xctx->graph_names[xctx->graph_nvars - 1],
xctx->graph_nvars - 1, XINSERT_NOREPLACE);
}
if(xctx->graph_sim_type) { if(xctx->graph_sim_type) {
done_header = 1; done_header = 1;
read_binary_block(fd); read_binary_block(fd);
dbg(1, "read_dataset(): read binary block, nvars=%d npoints=%d\n", xctx->graph_nvars - 1, npoints); dbg(1, "read_dataset(): read binary block, nvars=%d npoints=%d\n", xctx->graph_nvars, npoints);
xctx->graph_datasets++; xctx->graph_datasets++;
exit_status = 1; exit_status = 1;
} else { } else {
dbg(1, "read_dataset(): skip binary block, nvars=%d npoints=%d\n", xctx->graph_nvars - 1, npoints); dbg(1, "read_dataset(): skip binary block, nvars=%d npoints=%d\n", xctx->graph_nvars, npoints);
fseek(fd, (xctx->graph_nvars - 1) * npoints * sizeof(double), SEEK_CUR); /* skip binary block */ fseek(fd, (xctx->graph_nvars) * npoints * sizeof(double), SEEK_CUR); /* skip binary block */
} }
done_points = 0; done_points = 0;
} }
@ -347,7 +340,6 @@ static int read_dataset(FILE *fd)
else if(!strncmp(line, "No. Variables:", 14)) { else if(!strncmp(line, "No. Variables:", 14)) {
sscanf(line, "No. Variables: %d", &xctx->graph_nvars); sscanf(line, "No. Variables: %d", &xctx->graph_nvars);
if(xctx->graph_sim_type == 3) xctx->graph_nvars <<= 1; /* mag and phase */ if(xctx->graph_sim_type == 3) xctx->graph_nvars <<= 1; /* mag and phase */
xctx->graph_nvars++; /* add extra column for custom calculated data */
} }
else if(!done_points && !strncmp(line, "No. Points:", 11)) { else if(!done_points && !strncmp(line, "No. Points:", 11)) {
my_realloc(1415, &xctx->graph_npoints, (xctx->graph_datasets+1) * sizeof(int)); my_realloc(1415, &xctx->graph_npoints, (xctx->graph_datasets+1) * sizeof(int));
@ -379,7 +371,7 @@ static int read_dataset(FILE *fd)
} }
} }
dbg(1, "read_dataset(): datasets=%d, last npoints=%d, nvars=%d\n", dbg(1, "read_dataset(): datasets=%d, last npoints=%d, nvars=%d\n",
xctx->graph_datasets, xctx->graph_npoints[xctx->graph_datasets-1], xctx->graph_nvars - 1); xctx->graph_datasets, xctx->graph_npoints[xctx->graph_datasets-1], xctx->graph_nvars);
return exit_status; return exit_status;
} }
@ -508,7 +500,7 @@ int get_raw_index(const char *node)
return -1; return -1;
} }
/* <<<< */
void plot_raw_custom_data(int sweep_idx) void plot_raw_custom_data(int sweep_idx)
{ {
int p, ofs = 0; int p, ofs = 0;
@ -517,14 +509,16 @@ void plot_raw_custom_data(int sweep_idx)
int dset; int dset;
int ret; int ret;
char cmd[100]; char cmd[100];
/* SPICE_DATA *x = xctx->graph_values[sweep_idx]; */ SPICE_DATA *x = xctx->graph_values[sweep_idx];
SPICE_DATA *y = xctx->graph_values[idx]; SPICE_DATA *y = xctx->graph_values[idx];
if(!(tcleval("info procs customplot")[0])) return;
for(dset = 0 ; dset < xctx->graph_datasets; dset++) { for(dset = 0 ; dset < xctx->graph_datasets; dset++) {
for(p = ofs ; p < ofs + xctx->graph_npoints[dset]; p++) { for(p = ofs ; p < ofs + xctx->graph_npoints[dset]; p++) {
my_snprintf(cmd, S(cmd), "customfunc %d %d", p, dset); my_snprintf(cmd, S(cmd), "customplot %d %g", p, x[p]);
ret = Tcl_GlobalEval(interp, cmd); ret = Tcl_GlobalEval(interp, cmd);
if(ret == TCL_OK) { if(ret == TCL_OK) {
y[p] = atof(tclresult()); const char *r = tclresult();
if(r[0]) y[p] = atof(r);
} else { } else {
fprintf(errfp, "plot_raw_custom_data(): evaluation of script: %s failed\n", cmd); fprintf(errfp, "plot_raw_custom_data(): evaluation of script: %s failed\n", cmd);
fprintf(errfp, " : %s\n", Tcl_GetStringResult(interp)); fprintf(errfp, " : %s\n", Tcl_GetStringResult(interp));

View File

@ -440,7 +440,7 @@ void delete(int to_push_undo)
find_inst_to_be_redrawn(2 + 4 + 8 + 32); /* 32: call prepare_netlist_structs(0) find_inst_to_be_redrawn(2 + 4 + 8 + 32); /* 32: call prepare_netlist_structs(0)
* 2: add previously built list * 2: add previously built list
* 4: call symbol_bbox to precisely update bboxes <<< needed? * 4: call symbol_bbox to precisely update bboxes ... needed?
* 8: do not iterate over selection (there is no more selection, deleted) * 8: do not iterate over selection (there is no more selection, deleted)
*/ */
find_inst_to_be_redrawn(16); /* clear data */ find_inst_to_be_redrawn(16); /* clear data */