xschem raw add: add optional sweep_var parameter

This commit is contained in:
stefan schippers 2024-12-09 00:00:27 +01:00
parent 2ec8c61757
commit 2a7ee749ba
8 changed files with 80 additions and 14 deletions

View File

@ -549,6 +549,8 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
@ -1259,9 +1261,11 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
0.1 0.0 1.5 0.6
... ... ... ...
xschem raw add varname [expr]
xschem raw add varname [expr] [sweep_var]
add a 'varname' vector with all values set to 0 to loaded raw file if expr not given
otherwise initialize data with values calculated from expr.
if expr is given and also sweep_var is given use indicated sweep_var for expressions
that need it. If sweep_var not given use first raw file variable as sweep variable.
If varname is already existing and expr given recalculate data
Example: xschem raw add power {outm outp - i(@r1[i]) *}
</pre>
@ -1666,6 +1670,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
</ul>

View File

@ -22,11 +22,12 @@
#include "scripts.h"
int find_script_perl(const char *name, int logdepth, int fatal)
static int find_script_perl_(const char *name, int logdepth, int fatal, char *extra)
{
char *cflags, *ldflags, *s;
int res;
char *test_c =
char test_c[256];
char *test_c_in =
NL "#include <stdio.h>"
NL "#include <EXTERN.h>"
NL "#include <perl.h>"
@ -34,11 +35,14 @@ int find_script_perl(const char *name, int logdepth, int fatal)
NL " PerlInterpreter *interp;"
NL
NL " interp = perl_alloc();"
NL "%s"
NL " puts(\"OK\");"
NL " return 0;"
NL "}"
NL;
sprintf(test_c, test_c_in, extra);
require("sys/class", logdepth, fatal);
require("cc/cc", logdepth, fatal);
require("/internal/filelist/method", logdepth, fatal);
@ -83,3 +87,16 @@ int find_script_perl(const char *name, int logdepth, int fatal)
return try_fail(logdepth, "libs/script/perl");
}
int find_script_perl(const char *name, int logdepth, int fatal)
{
return find_script_perl_(name, logdepth, fatal, "");
}
int find_script_perl_with_IXpv(const char *name, int logdepth, int fatal)
{
int res = find_script_perl_(name, logdepth, fatal, "(void)interp->IXpv;");
put("libs/script/perl_with_IXpv", "tried");
return res;
}

View File

@ -43,13 +43,13 @@ static int find_script_python_(const char *name, int logdepth, int fatal, int ve
char *inc_py =
NL "import distutils.sysconfig;"
NL "print '-I' + distutils.sysconfig.get_python_inc().replace('\\\\','/')"
NL "print ('-I' + distutils.sysconfig.get_python_inc().replace('\\\\','/'))"
NL;
char *lib_py =
NL "import distutils.sysconfig;"
NL "print '-L' + distutils.sysconfig.PREFIX.replace('\\\\','/') + '/libs',;"
NL "print ('-L' + distutils.sysconfig.PREFIX.replace('\\\\','/') + '/libs')"
NL "import sys;"
NL "print '-lpython' + str(sys.version_info[0]) + str(sys.version_info[1])"
NL "print ('-lpython' + str(sys.version_info[0]) + str(sys.version_info[1]))"
NL;

View File

@ -34,6 +34,7 @@ void deps_scripts_init()
dep_add("libs/script/python/*", find_script_python);
dep_add("libs/script/python3/*", find_script_python3);
dep_add("libs/script/perl/*", find_script_perl);
dep_add("libs/script/perl_with_IXpv", find_script_perl_with_IXpv);
dep_add("libs/script/mawk/*", find_script_mawk);
dep_add("libs/script/lua/*", find_script_lua);
dep_add("libs/script/guile/*", find_script_guile);
@ -58,7 +59,7 @@ int brute_force_include(int logdepth, const char *language, const char *test_c,
{
char **files, *cflags, *ldflags;
char nodename[1024], deflink[sizeof(nodename)];
int fileno, n, res;
int fileno, n, res, tries = 0;
size_t llen;
if (ldflags_base == NULL)
@ -78,12 +79,26 @@ int brute_force_include(int logdepth, const char *language, const char *test_c,
sprintf(ldflags, "%s -l%s", ldflags_base, files[n]);
cflags = malloc(strlen(files[n]) + strlen(basedir) + 16);
sprintf(cflags, "-I%s/%s", basedir, files[n]);
if (try_icl(logdepth, nodename, test_c, NULL, cflags, ldflags) || try_icl(logdepth, nodename, test_c, NULL, cflags, deflink)) {
retry:;
tries++;
if ((tries < 4) && (try_icl(logdepth, nodename, test_c, NULL, cflags, ldflags) || try_icl(logdepth, nodename, test_c, NULL, cflags, deflink))) {
filelist_free(&fileno, &files);
free(cflags);
free(ldflags);
return 1;
}
if ((files[n])[llen] == '-') {
char *s;
/* on OpenBSD 7.2 the include dir is called lua-5.2 but -llua5.2
is used for linking; if '-' follows lang name and the first attempt
with that failed, try removing the '-' and rebuild the -l and
retry */
for(s = files[n]+llen; *s != '\0'; s++)
s[0] = s[1];
sprintf(ldflags, "%s -l%s", ldflags_base, files[n]); /* no need to allocate new, it's shorter */
goto retry;
}
free(cflags);
free(ldflags);
}

View File

@ -18,6 +18,7 @@ int find_script_mruby(const char *name, int logdepth, int fatal);
int find_script_python(const char *name, int logdepth, int fatal);
int find_script_python3(const char *name, int logdepth, int fatal);
int find_script_perl(const char *name, int logdepth, int fatal);
int find_script_perl_with_IXpv(const char *name, int logdepth, int fatal);
int find_script_mawk(const char *name, int logdepth, int fatal);
int find_script_lua(const char *name, int logdepth, int fatal);
int find_script_guile(const char *name, int logdepth, int fatal);

View File

@ -964,7 +964,7 @@ int raw_read_from_attr(Raw **rawptr, const char *type, double sweep1, double swe
return res;
}
int raw_add_vector(const char *varname, const char *expr)
int raw_add_vector(const char *varname, const char *expr, int sweep_idx)
{
int f;
int res = 0;
@ -985,7 +985,7 @@ int raw_add_vector(const char *varname, const char *expr)
res = 1;
}
if(expr) {
plot_raw_custom_data(0, 0, raw->allpoints -1, expr, varname);
plot_raw_custom_data(sweep_idx, 0, raw->allpoints -1, expr, varname);
} else if(res == 1) {
for(f = 0; f < raw->allpoints; f++) {
raw->values[raw->nvars - 1][f] = 0.0;
@ -1689,6 +1689,9 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
SPICE_DATA *x = xctx->raw->values[sweep_idx];
SPICE_DATA *sweepx = xctx->raw->values[0];
/* dbg(0, "sweep_idx=%d first=%d last=%d expr=%s, yname=%s\n",
* sweep_idx, first, last, expr ? expr : "<NULL>", yname ? yname: "<NULL>");
*/
y = xctx->raw->values[xctx->raw->nvars]; /* custom plot data column */
if(yname != NULL) {
int yidx = get_raw_index(yname, NULL);

View File

@ -3884,9 +3884,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
* 0.1 0.0 1.5 0.6
* ... ... ... ...
*
* xschem raw add varname [expr]
* xschem raw add varname [expr] [sweep_var]
* add a 'varname' vector with all values set to 0 to loaded raw file if expr not given
* otherwise initialize data with values calculated from expr.
* if expr is given and also sweep_var is given use indicated sweep_var for expressions
* that need it. If sweep_var not given use first raw file variable as sweep variable.
* If varname is already existing and expr given recalculate data
* Example: xschem raw add power {outm outp - i(@r1[i]) *}
*
@ -3991,10 +3993,33 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
}
} else if(argc > 3 && !strcmp(argv[2], "add")) {
int res = 0;
int sweep_idx = 0;
if(argc > 5) { /* provided sweep variable */
sweep_idx = get_raw_index(argv[5], NULL);
if(sweep_idx <= 0) sweep_idx = 0;
}
if(argc > 4) {
res = raw_add_vector(argv[3], argv[4]);
#if 0 /* seems not necessary... */
int save_datasets = -1, save_npoints = -1;
/* transform multiple OP points into a dc sweep */
if(sch_waves_loaded()!= -1 && xctx->raw && xctx->raw->sim_type && !strcmp(xctx->raw->sim_type, "op")
&& xctx->raw->datasets > 1 && xctx->raw->npoints[0] == 1) {
save_datasets = xctx->raw->datasets;
xctx->raw->datasets = 1;
save_npoints = xctx->raw->npoints[0];
xctx->raw->npoints[0] = xctx->raw->allpoints;
}
#endif
res = raw_add_vector(argv[3], argv[4], sweep_idx);
#if 0
if(sch_waves_loaded()!= -1 && save_npoints != -1) { /* restore multiple OP points */
xctx->raw->datasets = save_datasets;
xctx->raw->npoints[0] = save_npoints;
}
#endif
} else {
res = raw_add_vector(argv[3], NULL);
res = raw_add_vector(argv[3], NULL, 0);
}
Tcl_SetResult(interp, my_itoa(res), TCL_VOLATILE);
} else if(argc > 2 && !strcmp(argv[2], "datasets")) {

View File

@ -1250,7 +1250,7 @@ extern int filter_data(const char *din, const size_t ilen,
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_add_vector(const char *varname, const char *expr, int sweep_idx);
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);