summaryrefslogtreecommitdiff
path: root/Windows/spice/examples/tclspice/tcl-testbench4/vspicechart.tcl
blob: 810c2e74ea6e42da4faeb9af535b995c94c9880d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
############ spice chart program                      ###########
############ programmer: stephan thiel                ###########
############             thiel@mikro.ee.tu-berlin.de  ###########   
############             (c) 2008 Berlin, Germany      ###########
############             Don't trust any version      ###########
############             before 1.0                   ###########  


package require BLT
load "../../../src/.libs/libspice.so"

source selectfromlist.tcl
source bltGraph.tcl

namespace import blt::*

wm title . "vspicechart 0.01"
wm geometry . 800x450+40+40
pack propagate . false

set globals(colors) { red green blue orange yellow white gray lightblue pink darkblue \
              lightred lightgray darkgray darkblue darkgreen darkred violet salmon \
              gray100 gold SeaGreen RoyalBlue RosyBrown orchid MintCream magenta LimeGreen \
              gray33 DeepSkyBlue DarkGoldenrod chocolate gray77 aquamarine brown coral \
              DarkOliveGreen DarkOrange DarkSlateGray gray99 HotPink IndianRed LemonChiffon \
              LightSteelBlue PaleGreen peru sienna seashell SpringGreen tomato wheat WhiteSmoke} 


proc replacechar { str pat pat1} {
  set erg "" 
  for { set i 0 } { $i < [string length $str] } {incr i 1 } {
   if { [ string index $str  $i ] == $pat } {
     append erg $pat1
   }  else {
     append erg [string index $str $i ]
   }
  }
  return $erg
}


proc realtostr { r } {
  set b [ expr abs($r) ]  
  set mul 1e-18
  set prefix a
   if { $b > 9.9999999999e-16 } { 
        set mul 1e15 
        set prefix f
 }
  if { $b > 9.9999999999e-13 } { 
        set mul 1e12 
        set prefix p
 }
  if { $b > 9.9999999999e-10 } { 
        set mul 1e9 
        set prefix n
 }
  if { $b > 9.9999999999e-7 } { 
        set mul 1e6 
        set prefix u
 }
  if { $b > 9.9999999999e-4 } { 
        set mul 1e3 
        set prefix m
 }

  if { $b > 0.999999999999999 } { 
        set mul 1 
        set prefix ""
 }

  if { $b > 999 } { 
        set mul 1e-3 
        set prefix K
 }

  if { $b > 9.999999999e5 } { 
        set mul 1e-6 
        set prefix MEG
 }
  if { $b > 9.9999999999e8 } { 
        set mul 1e-9 
        set prefix G
 }
  if { $b > 9.99999999999e11 } { 
        set mul 1e-12 
        set prefix T
 }
  set str [ format "%1.8g$prefix" [expr $r*$mul] ]
 if { $str=="0a" } { set str "0" }
  return $str
}

proc realtostr1 { elem r } {
  scan $r "%f" erg 
 return [ realtostr $erg ]
}

set globals(signals) {};

proc readconfigfile { } {
    global globals
    global const
    if { [file exists $globals(CONFIGFILE)] } {
        set fid [open $globals(CONFIGFILE) r]
	 while { ![eof $fid] } {
           gets $fid tempstring
             if { [string first "PACK-PATH=" $tempstring]==0 } {
               scan $tempstring "PACK-PATH=%s" globals(PACK-PATH)
	     }
             if { [string first "SIMULATOR=" $tempstring]==0 } {
               scan $tempstring "SIMULATOR=%s" globals(SIMULATOR)
	     }
         } 
        close $fid
     } else {
       set globals(PACK-PATH) ""
       set globals(SIMULATOR) "INTERNAL"
     }
}

proc select_vector { } {
   global globals
   set thissignals [spice::spice_data]
   set signals {}
   foreach sig $thissignals {
       if { [lindex $sig 0] != "time" } {
         lappend signals [lindex $sig 0]
       }
   }  
   set selectedsignal [selectionwindow::selectfromlist .select "Select Signal" $signals ]
   if { ( [string trim $selectedsignal] != "") && ([lsearch -exact $globals(signals) $selectedsignal] == -1) } {
      eval "$globals(LSELECTEDSIGNALS) insert end $selectedsignal"
      vector create [replacechar $selectedsignal "\#" "_"]
   }
}


proc start_new_sel { } {
  global globals

    set elemlist [ eval "$globals(chart0) element show" ]  
    for { set j 0 } {$j < [llength $elemlist] } {incr j 1} {
       $globals(chart0)   element delete [lindex $elemlist $j ]   
    }

  set i 0
  foreach sig $globals(signals) {
    set nsig [replacechar $sig "\#" "_"]
    vector create $nsig
    spice::spicetoblt $sig $nsig
  
    $globals(chart0) element create $sig -color  [lindex $globals(colors) $i]  -xdata stime -ydata $nsig -symbol none
    incr i 1
  } 
}


proc delete_selected { } {
   global globals
   set elem [$globals(LSELECTEDSIGNALS) curselection]
    if { $elem != "" } {
       $globals(LSELECTEDSIGNALS) delete  $elem
    }
}



set filename [ lindex $argv 0] 

if { [file exists $filename ] } {
   spice::source $filename
   spice::bg run

after 1000



frame .f1
pack .f1 -side left -expand true -fill both

listbox .f1.blistbox -listvariable globals(signals)
pack .f1.blistbox -side top -fill both -expand true

set globals(LSELECTEDSIGNALS) .f1.blistbox


button .f1.baddvec -text "Select Vector" -command "select_vector"
pack .f1.baddvec -side top -fill x -expand true

button .f1.bdelvec -text "Delete Vector"  -command  "delete_selected"
pack .f1.bdelvec -side top -fill x -expand true

button .f1.bstartsel -text "Start with new selection" -command start_new_sel
pack .f1.bstartsel -side top -fill x -expand true


button .f1.simstop -text "Simulation Stop" -command "spice::stop"
pack .f1.simstop -side top -fill x -expand true

button .f1.simresume -text "Simulation Resume" -command "spice::bg resume"
pack .f1.simresume -side top -fill x -expand true


button .f1.bexit -text "Exit" -command "exit"
pack .f1.bexit -side top -fill x -expand true


frame .f2
pack .f2 -side left -expand true -fill both

stripchart .f2.chart
pack .f2.chart -side top -fill both -expand true 
.f2.chart axis configure x -title "Time in s"


.f2.chart grid configure -hide no 
Blt_ZoomStack .f2.chart
Blt_Crosshairs .f2.chart
Blt_ClosestPoint .f2.chart
Blt_PrintKey .f2.chart
Blt_ActiveLegend .f2.chart
.f2.chart crosshairs configure -color lightblue 

.f2.chart axis configure x -command realtostr1
.f2.chart axis configure y -command realtostr1

set globals(chart0) .f2.chart



  vector create stime


  proc bltupdate {} {
      global globals
   
      spice::spicetoblt time stime
      foreach sig $globals(signals) {
         set nsig [replacechar $sig "\#" "_"]
         spice::spicetoblt $sig $nsig
      } 
    
      after 100 bltupdate
  }
  bltupdate

} else {
    exit;
}