From 28d5114f4351f20c43c0141dbbaa7ff3c5a81c3f Mon Sep 17 00:00:00 2001 From: h_vogt Date: Mon, 28 Dec 2009 08:34:55 +0000 Subject: [PATCH] comments, new examples --- ChangeLog | 4 + examples/control_structs/repeat3.sp | 138 +++++++++++++++++++++++++++- src/frontend/measure.c | 12 +-- 3 files changed, 144 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38721ea6b..b9fb39dc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-12-22 Holger Vogt + * measure.c: comments, + /examples/control_structs/repeat3.sp: new examples snippets included + 2009-12-22 Holger Vogt * measure.c: bugfix (%f replaced by %e) diff --git a/examples/control_structs/repeat3.sp b/examples/control_structs/repeat3.sp index 74665a1a1..5650252ab 100644 --- a/examples/control_structs/repeat3.sp +++ b/examples/control_structs/repeat3.sp @@ -1,5 +1,10 @@ -*test sequence for repeat +Test sequences for ngspice control structures +*vectors are used (except foreach) +*start in interactive mode + .control + +* test for while, repeat, if, break let loop = 0 while loop < 4 let index = 0 @@ -9,8 +14,135 @@ break end end - echo echo index "$&index" loop "$&loop" let loop = loop + 1 end -.endc \ No newline at end of file + + +* test sequence for while, dowhile + let loop = 0 + echo + echo enter loop with "$&loop" + dowhile loop < 3 + echo within dowhile loop "$&loop" + let loop = loop + 1 + end + echo after dowhile loop "$&loop" + echo + let loop = 0 + while loop < 3 + echo within while loop "$&loop" + let loop = loop + 1 + end + echo after while loop "$&loop" + let loop = 3 + echo + echo enter loop with "$&loop" + dowhile loop < 3 + echo within dowhile loop "$&loop" $ output expected + let loop = loop + 1 + end + echo after dowhile loop "$&loop" + echo + let loop = 3 + while loop < 3 + echo within while loop "$&loop" $ no output expected + let loop = loop + 1 + end + echo after while loop "$&loop" + + +* test sequence for foreach + echo + foreach outvar 0 0.5 1 1.5 + echo parameters: $outvar $ foreach parameters are variables, not vectors! + end + +* test for if ... else ... end + echo + let loop = 0 + let index = 1 + dowhile loop < 10 + let index = index * 2 + if index < 128 + echo "$&index" lt 128 + else + echo "$&index" ge 128 + end + let loop = loop + 1 + end + +* simple test for label, goto + echo + let loop = 0 + label starthere + echo start "$&loop" + let loop = loop + 1 + if loop < 3 + goto starthere + end + echo end "$&loop" + +* test for label, nested goto + echo + let loop = 0 + label starthere1 + echo start nested "$&loop" + let loop = loop + 1 + if loop < 3 + if loop < 3 + goto starthere1 + end + end + echo end "$&loop" + +* test for label, goto + echo + let index = 0 + label starthere2 + let loop = 0 + echo We are at start with index "$&index" and loop "$&loop" + if index < 6 + label inhere + let index = index + 1 + if loop < 3 + let loop = loop + 1 + if index > 1 + echo jump2 + goto starthere2 + end + end + echo jump + goto inhere + end + echo We are at end with index "$&index" and loop "$&loop" + +* test goto in while loop + echo + let loop = 0 + if 1 $ outer loop to allow nested forward label 'endlabel' + while loop < 10 + if loop > 5 + echo jump + goto endlabel + end + let loop = loop + 1 + end + echo before $ never reached + label endlabel + echo after "$&loop" + end + +*test for using variables +* simple test for label, goto + echo + set loop = 0 + label starthe + echo start $loop + let loop = $loop + 1 $ expression needs vector at lhs + set loop = "$&loop" $ convert vector contents to variable + if $loop < 3 + goto starthe + end + echo end $loop +.endc diff --git a/src/frontend/measure.c b/src/frontend/measure.c index e2c34c5ce..39b6707f6 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -2,6 +2,9 @@ Entry point is function do_measure(), called by fcn dosim() from runcoms.c:335, after simulation is finished. + In addition it contains the fcn com_meas(), which provide the + interactive 'meas' command. + $Id$ */ @@ -127,14 +130,9 @@ com_meas(wordlist *wl) { static bool chkAnalysisType( char *an_type ) { - /* - if ( strcmp( an_type, "ac" ) != 0 && strcmp( an_type, "dc" ) != 0 && - strcmp( an_type, "noise" ) != 0 && strcmp( an_type, "tran" ) != 0 && - strcmp( an_type, "fft" ) != 0 && strcmp( an_type, "four" ) != 0 ) - */ - /* only support tran analysis type for now */ + /* only support tran, dc, ac, sp analysis type for now */ if ( strcmp( an_type, "tran" ) != 0 && strcmp( an_type, "ac" ) != 0 && - strcmp( an_type, "dc" ) != 0) + strcmp( an_type, "dc" ) != 0 && strcmp( an_type, "sp" ) != 0) return FALSE; // else if (ft_batchmode == TRUE) return FALSE; else return TRUE;