From d6350ca86dac65f7bf189492494d9f93131b8f7f Mon Sep 17 00:00:00 2001 From: h_vogt Date: Mon, 21 Dec 2009 00:27:15 +0000 Subject: [PATCH] add vectors to meas --- ChangeLog | 3 ++ src/frontend/com_measure2.c | 11 ++++++-- src/frontend/measure.c | 56 +++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8496544e2..5e79f71da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-12-21 Holger Vogt + * com_measure2.com, measure.c: add vector to the meas command + 2009-12-20 Holger Vogt * fixing the time 0 value of sine in isrc, vsrc * fteext.h, com_measure2.c, measure.c, commands.c: diff --git a/src/frontend/com_measure2.c b/src/frontend/com_measure2.c index 33a2b4398..09f63569f 100644 --- a/src/frontend/com_measure2.c +++ b/src/frontend/com_measure2.c @@ -91,7 +91,9 @@ void correct_vec(MEASUREPTR meas) char *vec2, newvec2[BSIZE_SP]; vec = meas->m_vec; - + /* return if not of type VM() etc */ + if ((*vec != 'v') || (!strstr(vec, "("))) return; + if (*(++vec) != '(') { vecfirst = copy(meas->m_vec); vecfirst[1] = '\0'; @@ -275,7 +277,7 @@ int measure_extract_variables( char *line ) * .MEASURE {DC|AC|TRAN} result FIND out_variable AT=val * + * - * .MEASURE {DC|AC|TRAN} result {AVG|MIN|MAX|PP|RMS} out_variable + * .MEASURE {DC|AC|TRAN} result {AVG|MIN|MAX|MIN_AT|MAX_AT|PP|RMS} out_variable * + * * .MEASURE {DC|AC|TRAN} result INTEG out_variable @@ -393,7 +395,10 @@ static void com_measure_when( timeValue = dTime->v_compdata[i].cx_real; } else if (cieq (meas->m_analysis,"sp")) { - value = get_value(meas, d, i); //d->v_compdata[i].cx_real; + if (d->v_compdata) + value = get_value(meas, d, i); //d->v_compdata[i].cx_real; + else + value = d->v_realdata[i]; timeValue = dTime->v_realdata[i]; } else { diff --git a/src/frontend/measure.c b/src/frontend/measure.c index 98beae75d..088bad76b 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -42,16 +42,66 @@ extern bool rflag; void com_meas(wordlist *wl) { /* wl: in, input line of meas command */ - char *line_in, *outvar, newvec[1000]; - wordlist * wl_count, *wl_let; - int fail; + char *line_in, *outvar, newvec[1000], *vec_found, *token, *equal_ptr, newval[256]; + wordlist * wl_count, *wl_let, *wl_index; + int fail, err=0; double result = 0; + struct dvec *d; if (!wl) { com_display((wordlist *) NULL); return; } wl_count = wl; + + /* check each wl entry, if it contain '=' and if the following token is + a vector. If yes, replace this vector by its value */ + wl_index = wl; + while ( wl_index) { + token = wl_index->wl_word; + /* find the vector vec_found, next token after each '=' sign. + May be in the next wl_word */ + if ( *(token + strlen(token) - 1) == '=' ) { + wl_index = wl_index->wl_next; + vec_found = wl_index->wl_word; + /* token may be already a value, maybe 'LAST', which we have to keep, or maybe a vector */ + if (!cieq(vec_found, "LAST")) { + INPevaluate( &vec_found, &err, 1 ); + /* if not a valid number */ + if (err) { + /* check if vec_found is a valid vector */ + d = vec_get(vec_found); + if (d) { + /* get its value */ + sprintf(newval, "%f\0", d->v_realdata[0]); + tfree(vec_found); + wl_index->wl_word = copy(newval); + } + } + } + } + /* may be inside the same wl_word */ + else if ( (equal_ptr = strstr( token, "=" )) ) { + vec_found = equal_ptr + 1; + if (!cieq(vec_found, "LAST")) { + INPevaluate( &vec_found, &err, 1 ); + if (err) { + d = vec_get(vec_found); + if (d) { + *equal_ptr = '\0'; + sprintf(newval, "%s=%f\0", token, d->v_realdata[0]); +// memory leak with first part of vec_found ? + tfree(token); + wl_index->wl_word = copy(newval); + } + } + } + } else { + ;// nothing + } + wl_index = wl_index->wl_next; + } + line_in = wl_flatten(wl); /* get output var name */