libsimcontrol.tcl 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. # Copyright (C) 2005, 2006 Frank Michler, Philipps-University Marburg, Germany
  2. # This program is free software; you can redistribute it and/or
  3. # modify it under the terms of the GNU General Public License
  4. # as published by the Free Software Foundation; either version 2
  5. # of the License, or (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program; if not, write to the Free Software
  12. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  13. set None -9999
  14. proc MakeList2D {x y {DefaultValue 0}} {
  15. set tmprow {}
  16. for {set i 0} {$i < $y} {incr i} {
  17. lappend tmprow $DefaultValue
  18. }
  19. set arr2d {}
  20. for {set j 0} {$j < $x} {incr j} {
  21. lappend arr2d $tmprow
  22. }
  23. return $arr2d
  24. }
  25. proc MakeList3D {x y z {DefaultValue 0}} {
  26. set tmprow [MakeList2D $y $z]
  27. set arr3d {}
  28. for {set j 0} {$j < $x} {incr j} {
  29. lappend arr3d $tmprow
  30. }
  31. return $arr3d
  32. }
  33. proc List2DToArray2D {OriList} {
  34. set i 0
  35. array set OutputArray {}
  36. foreach Row $OriList {
  37. set j 0
  38. foreach Elm $Row {
  39. set OutputArray($i,$j) $Elm
  40. incr j
  41. }
  42. incr i
  43. }
  44. set OutputArray(x) $i
  45. set OutputArray(y) $j
  46. return [array get OutputArray]
  47. }
  48. proc Array2DToList2D {ParaArray} {
  49. array set OriArray $ParaArray
  50. set OutputList {}
  51. for {set i 0} {$i < $OriArray(x)} {incr i} {
  52. set tmprow {}
  53. for {set j 0} {$j < $OriArray(y)} {incr j} {
  54. lappend tmprow $OriArray($i,$j)
  55. }
  56. lappend OutputList $tmprow
  57. }
  58. return $OutputList
  59. }
  60. proc SetArray2DToList2D {ParaArray Value} {
  61. array set OriArray $ParaArray
  62. set OutputList {}
  63. for {set i 0} {$i < $OriArray(x)} {incr i} {
  64. set tmprow {}
  65. for {set j 0} {$j < $OriArray(y)} {incr j} {
  66. lappend tmprow $Value
  67. }
  68. lappend OutputList $tmprow
  69. }
  70. return $OutputList
  71. }
  72. proc SetDiagonal2D {ArrayName value} {
  73. upvar $ArrayName MyArr
  74. for {set xx 0} {$xx<$MyArr(x)} {incr xx} {
  75. set MyArr($xx,$xx) $value
  76. }
  77. }
  78. proc SetWholeArray2D {ArrayName value} {
  79. upvar $ArrayName MyArr
  80. for {set xx 0} {$xx<$MyArr(x)} {incr xx} {
  81. for {set yy 0} {$yy<$MyArr(x)} {incr yy} {
  82. set MyArr($xx,$yy) $value
  83. }
  84. }
  85. }
  86. proc L1Dincr {MyList x} {
  87. upvar $MyList UpList
  88. lset UpList $x [expr [lindex $UpList $x]+1]
  89. }
  90. proc L2Dincr {MyList x y} {
  91. upvar $MyList UpList
  92. lset UpList $x $y [expr [lindex $UpList $x $y]+1]
  93. }
  94. #nicht effizient, aber allgemein
  95. # evtl. mit case-Abfrage die Länge von args berücksichtigen
  96. proc lincr {MyList args} {
  97. upvar $MyList UpList
  98. eval lset [concat UpList $args [expr [eval lindex [concat [list $UpList] $args]] +1]]
  99. }
  100. proc TestLibSimcontrol {} {
  101. puts "LibSimcontrol, Version 0.01"
  102. }
  103. proc DestroyElements {ElementList} {
  104. foreach w $ElementList {
  105. destroy $w
  106. }
  107. }
  108. #####################################
  109. #HIER GEHTS WEITER
  110. proc SetSimDirAndFileNames {SName} {
  111. puts "SimulationName= $SName"
  112. set ::SimDir [pwd]
  113. set ::SimDir "${::SimDir}/"
  114. set ::SimName ${::SimDir}${::SimulationName}
  115. puts "SimName= $::SimName"
  116. set ::SimConfigFile ${::SimDir}settings_${::SimulationName}.cfg
  117. set ::SimOptionsFile ${::SimDir}options_${::SimulationName}.cfg
  118. ReadSimConfigFile
  119. # SimDataDir aus config file auslesen, $HOME durch $::env(HOME) ersetzen
  120. puts "DataDirectory= $::SimOptions(DataDirectory) \n"
  121. set ::SimDataDir [regsub {\$HOME} $::SimOptions(DataDirectory) $::env(HOME)]
  122. #set ::SimDataDir "$::env(HOME)/data/sim/csim/$::SimulationName/"
  123. if {[regexp "/$" $::SimDataDir] != 1} {
  124. puts "add trailing slash to SimDataDir\n";
  125. set ::SimDataDir $::SimDataDir/
  126. }
  127. puts "DataDirectory= $::SimDataDir"
  128. }
  129. proc SimFlagsEntry {ParaName ParaLabel ParentFrame} {
  130. lappend ::SimFlagsList $ParaLabel
  131. set CurCheckbutton [checkbutton ${ParentFrame}.$ParaName -text "$ParaLabel" -variable ::SimFlags($ParaLabel)]
  132. pack $CurCheckbutton -anchor sw -side top
  133. }
  134. proc SimFlagsEntry2 {ParaName ParaLabel ParentFrame} {
  135. lappend ::SimFlagsList $ParaLabel
  136. frame ${ParentFrame}.${ParaName}
  137. pack ${ParentFrame}.${ParaName} -anchor e
  138. set curframe2 ${ParentFrame}.${ParaName}
  139. set CurCheckbutton [checkbutton ${curframe2}.checkbutton -text "$ParaLabel" -variable ::SimFlags($ParaLabel)]
  140. pack $CurCheckbutton -anchor sw -side left
  141. pack [button ${curframe2}.hideButton -command "HideOptionEntry $curframe2 $ParaLabel" -text "Hide"] -side left -anchor center -pady 0
  142. }
  143. proc SimOptionsEntry {ParaName ParaLabel ParentFrame} {
  144. lappend ::SimOptionsList $ParaLabel
  145. frame ${ParentFrame}.${ParaName}
  146. pack ${ParentFrame}.${ParaName} -anchor e
  147. set curframe2 ${ParentFrame}.${ParaName}
  148. label ${curframe2}.${ParaName}label -text "$ParaLabel="
  149. pack ${curframe2}.${ParaName}label -anchor sw -side left
  150. # set mybut [entry ${curframe2}.${ParaName}entry -textvariable ::$ParaLabel -width 7 -bg white -relief flat -border 5 -highlightcolor green]
  151. set mybut [entry ${curframe2}.${ParaName}entry -textvariable ::SimOptions($ParaLabel) -width 7 -bg white -relief sunken -border 1 -highlightcolor green]
  152. pack $mybut -side left -anchor n -side right -pady 2
  153. }
  154. proc SimOptionsEntry2 {ParaName ParentFrame} {
  155. set ParaLabel $ParaName
  156. set FrameName soe$ParaName
  157. lappend ::SimOptionsList $ParaLabel
  158. frame ${ParentFrame}.${FrameName}
  159. pack ${ParentFrame}.${FrameName} -anchor e
  160. set curframe2 ${ParentFrame}.${FrameName}
  161. label ${curframe2}.${FrameName}label -text "$ParaLabel="
  162. pack ${curframe2}.${FrameName}label -anchor sw -side left
  163. set mybut [entry ${curframe2}.${FrameName}entry -textvariable ::SimOptions($ParaName) -width 7 -bg white -relief sunken -border 1 -highlightcolor green]
  164. pack $mybut -side left -anchor n -side right -pady 2
  165. }
  166. proc HideOptionEntry {Frame Label} {
  167. destroy $Frame
  168. set size [file size ${::SimOptionsFile}]
  169. set fd [open ${::SimOptionsFile}]
  170. set xml [read $fd $size]
  171. close $fd
  172. set doc [dom parse -simple $xml]
  173. set root [$doc documentElement]
  174. set node [$root child 1 $Label]
  175. $node setAttribute flag 0
  176. set fd [open ${::SimOptionsFile} w]
  177. puts $fd [$root asXML]
  178. close $fd
  179. $doc delete
  180. }
  181. proc SimOptionsEntry3 {ParaName ParaLabel ParentFrame} {
  182. lappend ::SimOptionsList $ParaLabel
  183. frame ${ParentFrame}.${ParaName}
  184. pack ${ParentFrame}.${ParaName} -anchor e
  185. set curframe2 ${ParentFrame}.${ParaName}
  186. label ${curframe2}.${ParaName}label -text "$ParaLabel="
  187. pack ${curframe2}.${ParaName}label -anchor center -side left -pady 0
  188. set mybut [entry ${curframe2}.${ParaName}entry -textvariable ::SimOptions($ParaLabel) -width 7 -bg white -relief sunken -border 1 -highlightcolor green]
  189. pack $mybut -side left -anchor center -pady 0
  190. pack [button ${curframe2}.hideButton -command "HideOptionEntry $curframe2 $ParaLabel" -text "Hide"] -side left -anchor center -pady 0
  191. }
  192. proc SimParaEntry {ParaName ParaLabel ParentFrame} {
  193. frame ${ParentFrame}.${ParaName}
  194. pack ${ParentFrame}.${ParaName} -anchor e
  195. set curframe2 ${ParentFrame}.${ParaName}
  196. label ${curframe2}.${ParaName}label -text "$ParaLabel="
  197. pack ${curframe2}.${ParaName}label -anchor sw -side left
  198. # set mybut [entry ${curframe2}.${ParaName}entry -textvariable ::$ParaLabel -width 7 -bg white -relief flat -border 5 -highlightcolor green]
  199. set mybut [entry ${curframe2}.${ParaName}entry -textvariable ::$ParaLabel -width 7 -bg white -relief sunken -border 1 -highlightcolor green]
  200. pack $mybut -side left -anchor n -side right -pady 2
  201. }
  202. proc SimParaEntry2 {ParaName ParentFrame} {
  203. set ParseString "::"
  204. set Nothing {}
  205. set ParaLabel [regsub $ParseString $ParaName $Nothing]
  206. set FrameName spe$ParaLabel
  207. frame ${ParentFrame}.${FrameName}
  208. pack ${ParentFrame}.${FrameName} -anchor e
  209. set curframe2 ${ParentFrame}.${FrameName}
  210. label ${curframe2}.${FrameName}label -text "$ParaLabel="
  211. pack ${curframe2}.${FrameName}label -anchor sw -side left
  212. # set mybut [entry ${curframe2}.${FrameName}entry -textvariable ::$ParaLabel -width 7 -bg white -relief flat -border 5 -highlightcolor green]
  213. set mybut [entry ${curframe2}.${FrameName}entry -textvariable ::$ParaLabel -width 7 -bg white -relief sunken -border 1 -highlightcolor green]
  214. pack $mybut -side left -anchor n -side right -pady 2
  215. }
  216. array set SimOptions {}
  217. array set SimFlags {}
  218. set SimOptionsList {}
  219. set SimFlagsList {}
  220. proc ReadSimConfigFile {} {
  221. puts "Read SimConfigFile= $::SimConfigFile"
  222. set fw [open $::SimConfigFile "r"]
  223. while {[eof $fw] != 1} {
  224. set CurLine [gets $fw]
  225. if {[regexp "^\[\[:space:\]\]*\[\[:alpha:\]\]" $CurLine] == 1} {
  226. # puts "Line $CurLine"
  227. set ParseOption "^\[\[:space:\]\]*(\[\[:alnum:\]\]*)\[\[:space:\]\]{1,}:\[\[:space:\]\]{1,}(\[^\[:space:\]\]*)"
  228. if {[regexp $ParseOption $CurLine Match Name Value] == 1} {
  229. # puts "Option $Name = $Value"
  230. set ::SimOptions($Name) $Value
  231. } else {
  232. set ParseFlag "^\[\[:space:\]\]*(\[\[:alpha:\]\]*)"
  233. if {[regexp $ParseFlag $CurLine Match Name] == 1} {
  234. if {[regexp "^No(.*)" $Name Match FlagName] ==1} {
  235. set Value 0
  236. } else {
  237. set FlagName $Name
  238. set Value 1
  239. }
  240. # puts "Flag $FlagName = $Value"
  241. set ::SimFlags($FlagName) $Value
  242. }
  243. }
  244. }
  245. }
  246. }
  247. proc ShowOptionsWindow {OptionsWindowName} {
  248. set ::VisibleSimOptions 1
  249. toplevel $OptionsWindowName
  250. wm protocol $OptionsWindowName WM_DELETE_WINDOW "HideWin $OptionsWindowName ::VisibleSimOptions"
  251. set curframe ${::OptionsWindowName}
  252. # ScrolledWindow ${curframe}.scrollwin
  253. # set curframe2 ${curframe}
  254. # pack $curframe2
  255. # frame ${curframe}.lbframe
  256. # pack ${curframe}.lbframe -side bottom
  257. # set curframe1 ${curframe}.lbframe
  258. # set LBname ${curframe1}.lb
  259. # set SBname ${curframe1}.sb
  260. # ScrollableFrame ${LBname} -areaheight 30
  261. # scrollbar ${SBname} -command [list ${LBname} yview]
  262. # ${LBname} configure -yscrollcommand [list ${SBname} set]
  263. # pack ${SBname} ${LBname} -in ${curframe1} -side right -expand 1 -fill both
  264. # set curframe2 $LBname
  265. # Programmzeilen aus http://wiki.tcl.tk/9924
  266. set sw [ScrolledWindow ${curframe}.sw]
  267. pack $sw -fill both -expand 0
  268. set sf [ScrollableFrame $sw.sf -areawidth 0 -height 600]
  269. $sw setwidget $sf
  270. set uf [$sf getframe]
  271. set curframe2 $uf
  272. if {[file exists ${::SimOptionsFile}] == 0} {
  273. set initFile [open ${::SimOptionsFile} a+]
  274. puts $initFile "<ShowOptionsFlags>"
  275. puts $initFile "</ShowOptionsFlags>"
  276. close $initFile
  277. }
  278. set size [file size ${::SimOptionsFile}]
  279. set fd [open ${::SimOptionsFile}]
  280. set xml [read $fd $size]
  281. close $fd
  282. set doc [dom parse -simple $xml]
  283. set root [$doc documentElement]
  284. puts "Read SimConfigFile= $::SimConfigFile"
  285. set fw [open $::SimConfigFile "r"]
  286. while {[eof $fw] != 1} {
  287. set CurLine [gets $fw]
  288. if {[regexp "^\[\[:space:\]\]*\[\[:alpha:\]\]" $CurLine] == 1} {
  289. # puts "Line $CurLine"
  290. set ParseOption "^\[\[:space:\]\]*(\[\[:alnum:\]_\]*)\[\[:space:\]\]{1,}:\[\[:space:\]\]{1,}(\[^\[:space:\]\]*)"
  291. if {[regexp $ParseOption $CurLine Match Name Value] == 1} {
  292. # puts "Option $Name = $Value"
  293. set node [$root child 1 $Name]
  294. if {$node == ""} {
  295. $root appendFromList [list $Name {flag 1} {}]
  296. set ::SimOptions($Name) $Value
  297. SimOptionsEntry3 win$Name $Name $curframe2
  298. } else {
  299. if {[$node getAttribute flag] == 1} {
  300. set ::SimOptions($Name) $Value
  301. SimOptionsEntry3 win$Name $Name $curframe2
  302. }
  303. }
  304. } else {
  305. set ParseFlag "^\[\[:space:\]\]*(\[\[:alpha:\]\]*)"
  306. if {[regexp $ParseFlag $CurLine Match Name] == 1} {
  307. if {[regexp "^No(.*)" $Name Match FlagName] ==1} {
  308. set Value 0
  309. } else {
  310. set FlagName $Name
  311. set Value 1
  312. }
  313. # puts "Flag $FlagName = $Value"
  314. set node [$root child 1 $FlagName]
  315. if {$node == ""} {
  316. $root appendFromList [list $FlagName {flag 1} {}]
  317. set ::SimFlags($FlagName) $Value
  318. SimFlagsEntry2 win$FlagName $FlagName $curframe2
  319. } else {
  320. if {[$node getAttribute flag] == 1} {
  321. set ::SimFlags($FlagName) $Value
  322. SimFlagsEntry2 win$FlagName $FlagName $curframe2
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. set fd [open ${::SimOptionsFile} w]
  330. puts $fd [$root asXML]
  331. close $fd
  332. $doc delete
  333. # scrollbar ${SBname} -command [list ${LBname} yview]
  334. # ${LBname} configure -yscrollcommand [list ${SBname} set]
  335. # pack ${SBname} ${LBname} -in ${curframe1} -side right -expand 1 -fill both
  336. }
  337. proc HideWin {WinName WinVisible} {
  338. upvar $WinVisible VisibleState
  339. wm withdraw $WinName
  340. set VisibleState 0
  341. }
  342. proc ShowHideWin {WinName WinVisible} {
  343. upvar $WinVisible VisibleState
  344. if {$VisibleState == 0} {
  345. wm withdraw $WinName
  346. } else {
  347. wm deiconify $WinName
  348. }
  349. }
  350. proc OpenIDL {} {
  351. set ::idl [open "|idl-console-start" "w"]
  352. fconfigure $::idl -blocking 0 -buffering line -translation crlf -eofchar {}
  353. puts "OpenIDL"
  354. }
  355. proc ResetIDL {} {
  356. puts $::idl "retall"
  357. puts $::idl "widget_control,/reset"
  358. puts $::idl "close,/all"
  359. puts $::idl "heap_gc,/verbose"
  360. # close $::idl
  361. # OpenIDL
  362. }
  363. proc RestartIDL {} {
  364. close $::idl
  365. OpenIDL
  366. }
  367. proc ShowSpikes {} {
  368. set ShowOptions {}
  369. # if {$::NType == 0} {
  370. # append ShowOptions ",CutSpikes=$::CutSpikePot "
  371. # }
  372. if {$::ShowTestSpikes == 1} {
  373. append ShowOptions ",/Test, TrialNr= $::TrialNr "
  374. }
  375. if {$::UseMinMaxTime == 1} {
  376. append ShowOptions ",Time=\[$::MinTime, $::MaxTime\]"
  377. }
  378. # if {$::SimOptions(NeuronType) == 0} {
  379. # append ShowOptions ",CutSpikes=$::CutSpikePot "
  380. # }
  381. if {$::SpikeOpt != {}} {
  382. append ShowOptions ", $::SpikeOpt "
  383. }
  384. append ShowOptions ",ShowPotentials=$::ShowPotLayer "
  385. set Command "gklearn_showsimspikes, dirname=\"$::SimDataDir\", /ShowSpikes, /sec $ShowOptions \n"
  386. # set Command "csim_showsimspikes, dirname=\"$::SimDataDir\", /sec \n"
  387. puts $Command
  388. puts $::idl $Command
  389. }
  390. proc ShowMovie {} {
  391. set ShowOptions {}
  392. append ShowOptions ",Tau=\[$::MovieTau0, $::MovieTau1\]"
  393. append ShowOptions ",Gain=\[$::MovieGain0, $::MovieGain1\]"
  394. if {$::ShowTestSpikes == 1} {
  395. append ShowOptions ",/Test, TrialNr= $::TrialNr "
  396. }
  397. set Command "gklearn_showsimspikes, dirname=\"$::SimDataDir\", /sec, /movie $ShowOptions \n"
  398. # set Command "csim_showsimspikes, dirname=\"$::SimDataDir\", /sec \n"
  399. puts $Command
  400. puts $::idl $Command
  401. }
  402. proc ShowMovieF2 {} {
  403. set ShowOptions {}
  404. append ShowOptions ",Tau=\[$::MovieTau0, $::MovieTau1, $::MovieTau1\]"
  405. append ShowOptions ",Gain=\[$::MovieGain0, $::MovieGain1, $::MovieGain1\]"
  406. if {$::ShowTestSpikes == 1} {
  407. append ShowOptions ",/Test, TrialNr= $::TrialNr "
  408. }
  409. append ShowOptions ", /XLinear"
  410. set Command "gklearn_showsimspikes, dirname=\"$::SimDataDir\", /sec, /movie $ShowOptions \n"
  411. # set Command "csim_showsimspikes, dirname=\"$::SimDataDir\", /sec \n"
  412. puts $Command
  413. puts $::idl $Command
  414. }
  415. proc ConnectionNames {} {
  416. #ToDo: Check wether SimInfoFile exists or not!!
  417. set ::ConnectionList {}
  418. set SimInfoFile ${::SimDataDir}Sim.SimInfo
  419. puts "InfoFilename $SimInfoFile"
  420. set fw [open $SimInfoFile "r"]
  421. while {[eof $fw] != 1} {
  422. set CurLine [gets $fw]
  423. set exp "<Connection.*Name=\"(.*)\""
  424. if {[regexp $exp $CurLine Match Name]} {
  425. puts $CurLine
  426. lappend ::ConnectionList $Name
  427. }
  428. }
  429. close $fw
  430. }
  431. proc ReadLbSelection {List} {
  432. set CurSelection [$List curselection]
  433. if {$CurSelection == {}} {
  434. # puts "No Weight Selected, use last selection"
  435. set CurSelection $::LastWeightSelection
  436. $List selection set $::LastWeightSelection
  437. }
  438. set ::LastWeightSelection $CurSelection
  439. return $CurSelection
  440. }
  441. proc ShowWeights {{WeightNr 0}} {
  442. set ConName [lindex $::ConnectionList $WeightNr]
  443. set ShowOptions {}
  444. append ShowOptions ", ConSelection=\"$ConName\""
  445. if {$::UseTrialWeights == 1} {
  446. append ShowOptions ", TrialNr='$::TrialNr'"
  447. }
  448. append ShowOptions ", Receptive=$::TWReceptive"
  449. append ShowOptions ", Zoom=2 "
  450. set Command "gklearn_showweights, dirname=\"$::SimDataDir\" $ShowOptions \n"
  451. puts $Command
  452. puts $::idl $Command
  453. }
  454. proc ShowListWeights {List} {
  455. ShowWeights [ReadLbSelection $List]
  456. ConnectionNames
  457. }
  458. proc TomWaits {List} {
  459. set ConName [lindex $::ConnectionList [ReadLbSelection $List]]
  460. set ShowOptions {}
  461. append ShowOptions ", ConSelection=\"$ConName\""
  462. if {$::UseTrialWeights == 1} {
  463. append ShowOptions ", TrialNr='$::TrialNr'"
  464. }
  465. append ShowOptions ", zoom=$::TWZoom"
  466. append ShowOptions ", magnify=$::TWMagnify"
  467. set Command "gklearn_tomwaits, dirname=\"$::SimDataDir\" $ShowOptions \n"
  468. # set Command "csim_showsimspikes, dirname=\"$::SimDataDir\", /sec \n"
  469. puts $Command
  470. puts $::idl $Command
  471. }
  472. proc TomWaitsQt {List} {
  473. set ConName [lindex $::ConnectionList [ReadLbSelection $List]]
  474. set ShowOptions {}
  475. append ShowOptions "$::SimDataDir$ConName"
  476. append ShowOptions "weights.dat"
  477. if {$::UseTrialWeights == 1} {
  478. append ShowOptions "$::TrialNr"
  479. }
  480. set Command "$::LibSimcontrolPath/../tools/tomwaits/tomwaits"
  481. puts $Command
  482. puts $ShowOptions
  483. exec $Command $ShowOptions &
  484. }
  485. proc CalcWeightMovie {List} {
  486. set ConName [lindex $::ConnectionList [ReadLbSelection $List]]
  487. set ShowOptions {}
  488. append ShowOptions ", ConSelection=\"$ConName\""
  489. append ShowOptions ", NTrials=$::WeightMovieTrials "
  490. append ShowOptions ", /show"
  491. # append ShowOptions ", Receptive=$::TWReceptive"
  492. # append ShowOptions ", Zoom=2 "
  493. set Command "csim_calcweightmovie, dirname=\"$::SimDataDir\" $ShowOptions \n"
  494. puts $Command
  495. puts $::idl $Command
  496. }
  497. proc ShowWeightMovie {List} {
  498. set ConName [lindex $::ConnectionList [ReadLbSelection $List]]
  499. set ShowOptions {}
  500. append ShowOptions ", ConSelection=\"$ConName\""
  501. # append ShowOptions ", Receptive=$::TWReceptive"
  502. # append ShowOptions ", Zoom=2 "
  503. set Command "csim_showweightmovie, dirname=\"$::SimDataDir\" $ShowOptions \n"
  504. puts $Command
  505. puts $::idl $Command
  506. }
  507. proc ShowSelectivity {} {
  508. set ShowOptions {}
  509. append ShowOptions ", TrialNr='$::TrialNr'"
  510. append ShowOptions ", /Test "
  511. set Command "gklearn_showsimspikes, dirname=\"$::SimDataDir\", /sec, /ShowSelectivity $ShowOptions \n"
  512. puts $Command
  513. puts $::idl $Command
  514. }
  515. #############################
  516. proc ShowResultsParaWin {} {
  517. set ::VisibleResultsPara 0
  518. toplevel .rpara
  519. set curframe1 .rpara
  520. wm protocol .rpara WM_DELETE_WINDOW "HideWin .rpara VisibleResultsPara"
  521. set ::TWZoom 1
  522. SimParaEntry2 ::TWZoom $curframe1
  523. set ::TWMagnify 2
  524. SimParaEntry2 ::TWMagnify $curframe1
  525. # frame ${curframe}.sub1
  526. # pack ${curframe}.sub1
  527. # set curframe1 ${curframe}.sub1
  528. set ::TWReceptive 1
  529. pack [radiobutton ${curframe1}.one -value 1 -text "Receptive Fields" -variable ::TWReceptive] -anchor sw
  530. pack [radiobutton ${curframe1}.two -value 0 -text "Projective Fields" -variable ::TWReceptive] -anchor sw
  531. set ::MovieTau0 50
  532. set ::MovieTau1 50
  533. set ::MovieGain0 30
  534. set ::MovieGain1 30
  535. SimParaEntry2 ::MovieTau0 $curframe1
  536. SimParaEntry2 ::MovieTau1 $curframe1
  537. SimParaEntry2 ::MovieGain0 $curframe1
  538. SimParaEntry2 ::MovieGain1 $curframe1
  539. set ::WeightMovieTrials 30
  540. SimParaEntry2 ::WeightMovieTrials $curframe1
  541. set ::ShowPotLayer 1
  542. SimParaEntry2 ::ShowPotLayer $curframe1
  543. }
  544. proc ShowResultsWindow {ResultsWindowName} {
  545. set ::VisibleSimResults 1
  546. toplevel $ResultsWindowName
  547. wm protocol $ResultsWindowName WM_DELETE_WINDOW "HideWin $ResultsWindowName ::VisibleSimResults"
  548. labelframe ${::ResultsWindowName}.showsim -text "Show Sim Results" -borderwidth 4 -relief sunken -padx 10 -pady 2
  549. pack ${::ResultsWindowName}.showsim -pady 2
  550. set curframe ${::ResultsWindowName}.showsim
  551. frame ${curframe}.rcontrol1
  552. pack ${curframe}.rcontrol1
  553. set curframe1 ${curframe}.rcontrol1
  554. frame ${curframe1}.sub1
  555. pack ${curframe1}.sub1 -side right
  556. set curframe2 ${curframe1}.sub1
  557. set ::TrialNr 0
  558. SimParaEntry2 ::TrialNr $curframe2
  559. frame ${curframe2}.sub2
  560. pack ${curframe2}.sub2 -side bottom -expand 1 -fill both
  561. set curframe3 ${curframe2}.sub2
  562. set ::UseTrialWeights 0
  563. set CurCheckbutton [checkbutton ${curframe3}.useTrialWeights -text "UseTrialWeights" -variable ::UseTrialWeights]
  564. pack $CurCheckbutton -anchor sw -side right
  565. ShowResultsParaWin
  566. ShowHideWin .rpara ::VisibleResultsPara
  567. pack [checkbutton ${curframe1}.show -text "ShowResParas" -variable ::VisibleResultsPara -command [list ShowHideWin .rpara ::VisibleResultsPara]] -side left
  568. frame ${curframe}.resultbuttons
  569. pack ${curframe}.resultbuttons
  570. set curframe1 ${curframe}.resultbuttons
  571. pack [button ${curframe1}.resetidl -command "ResetIDL" -text "ResetIDL"] -side left
  572. pack [button ${curframe1}.showmovie -command "ShowMovie" -text "Movie"] -side left
  573. pack [button ${curframe1}.showselectivity -command "ShowSelectivity" -text "Selectivity"] -side left
  574. ConnectionNames
  575. frame ${curframe}.weightshow
  576. pack ${curframe}.weightshow
  577. set curframe1 ${curframe}.weightshow
  578. frame ${curframe1}.lbframe
  579. pack ${curframe1}.lbframe -side bottom
  580. set curframe3 ${curframe1}.lbframe
  581. set ::LBname ${curframe3}.lb
  582. set ::SBname ${curframe3}.sb
  583. listbox ${::LBname} -selectmode single -height 3 -listvariable ConnectionList -activestyle dotbox
  584. scrollbar ${::SBname} -command [list ${::LBname} yview]
  585. ${::LBname} configure -yscrollcommand [list ${::SBname} set]
  586. #eval ${::LBname} insert 0 $ConnectionList
  587. pack ${::SBname} ${::LBname} -in ${curframe3} -side right -expand 1 -fill both
  588. #pack ${::LBname} -side left
  589. set LastWeightSelection 1
  590. ${::LBname} selection set 1
  591. #${::LBname} activate 1
  592. frame ${curframe1}.sub1
  593. pack ${curframe1}.sub1 -side top
  594. set curframe2 ${curframe1}.sub1
  595. pack [button ${curframe2}.showweights -command "[list ShowListWeights ${::LBname}]" -text "ShowWeights"] -side left
  596. pack [button ${curframe2}.tomwaits -command "[list TomWaits ${::LBname}]" -text "TomWaits"] -side left
  597. pack [button ${curframe2}.tomwaitsqt -command "[list TomWaitsQt ${::LBname}]" -text "TomWaitsQt"] -side left
  598. frame ${curframe3}.weightbuttonframe
  599. pack ${curframe3}.weightbuttonframe -side left
  600. set curframe4 ${curframe3}.weightbuttonframe
  601. pack [button ${curframe4}.calcwm -command "[list CalcWeightMovie ${::LBname}]" -text "CalcWeightMovie"] -side top
  602. pack [button ${curframe4}.showwm -command "[list ShowWeightMovie ${::LBname}]" -text "ShowWeightMovie"] -side top
  603. frame ${curframe}.results2
  604. pack ${curframe}.results2
  605. set curframe1 ${curframe}.results2
  606. frame ${curframe1}.buttoncheck
  607. pack ${curframe1}.buttoncheck -side left
  608. set curframe2 ${curframe1}.buttoncheck
  609. pack [button ${curframe2}.showspikes -command "ShowSpikes" -text "Spikes"] -side top
  610. set ::UseMinMaxTime 1
  611. pack [checkbutton ${curframe2}.yrange -text "MinMaxTime" -variable ::UseMinMaxTime -command "puts HalloMinMaxTime" ] -anchor sw -side top
  612. set ::ShowTestSpikes 0
  613. pack [checkbutton ${curframe2}.stsp -text "ShowTestSpikes" -variable ShowTestSpikes] -anchor sw -side top
  614. frame ${curframe1}.timeframe
  615. pack ${curframe1}.timeframe -side right
  616. set curframe2 ${curframe1}.timeframe
  617. set ::CutSpikePot 30
  618. SimParaEntry2 ::CutSpikePot $curframe2
  619. set ::MinTime 0
  620. SimParaEntry2 ::MinTime $curframe2
  621. set ::MaxTime 3
  622. SimParaEntry2 ::MaxTime $curframe2
  623. set ::SpikeOpt {}
  624. SimParaEntry2 ::SpikeOpt $curframe2
  625. frame ${curframe1}.cutsp
  626. pack ${curframe1}.cutsp -side right
  627. set curframe2 ${curframe1}.cutsp
  628. }
  629. proc ShowResultsWindow2 {ResultsWindowName} {
  630. set ::VisibleSimResults 1
  631. toplevel $ResultsWindowName
  632. wm protocol $ResultsWindowName WM_DELETE_WINDOW "HideWin $ResultsWindowName ::VisibleSimResults"
  633. labelframe ${::ResultsWindowName}.showsim -text "Show Sim Results" -borderwidth 4 -relief sunken -padx 10 -pady 2
  634. pack ${::ResultsWindowName}.showsim -pady 2
  635. set curframe ${::ResultsWindowName}.showsim
  636. frame ${curframe}.rcontrol1
  637. pack ${curframe}.rcontrol1
  638. set curframe1 ${curframe}.rcontrol1
  639. frame ${curframe1}.sub1
  640. pack ${curframe1}.sub1 -side right
  641. set curframe2 ${curframe1}.sub1
  642. frame ${curframe1}.sub2
  643. pack ${curframe1}.sub2 -side left -expand 1 -fill both
  644. set curframe2 ${curframe1}.sub2
  645. ShowResultsParaWin
  646. ShowHideWin .rpara ::VisibleResultsPara
  647. pack [checkbutton ${curframe1}.show -text "ShowResParas" -variable ::VisibleResultsPara -command [list ShowHideWin .rpara ::VisibleResultsPara]] -side left
  648. frame ${curframe}.resultbuttons
  649. pack ${curframe}.resultbuttons
  650. set curframe1 ${curframe}.resultbuttons
  651. # pack [button ${curframe1}.resetidl -command "ResetIDL" -text "ResetIDL"] -side top
  652. # pack [button ${curframe1}.showmovie -command "ShowMovie" -text "Movie"] -side top
  653. # pack [button ${curframe1}.showselectivity -command "ShowSelectivity" -text "Selectivity"] -side top
  654. frame ${curframe1}.sub1
  655. pack ${curframe1}.sub1 -side top
  656. set curframe2 ${curframe1}.sub1
  657. pack [button ${curframe2}.showweights -command "[list ShowListWeights ${::LBname}]" -text "ShowWeights"] -side left
  658. pack [button ${curframe2}.tomwaits -command "[list TomWaits ${::LBname}]" -text "TomWaits"] -side left
  659. pack [button ${curframe2}.showmovie -command "ShowMovieF2" -text "Movie"] -side left
  660. frame ${curframe}.results2
  661. pack ${curframe}.results2
  662. set curframe1 ${curframe}.results2
  663. frame ${curframe1}.buttoncheck
  664. pack ${curframe1}.buttoncheck -side left
  665. set curframe2 ${curframe1}.buttoncheck
  666. pack [button ${curframe2}.showspikes -command "ShowSpikes" -text "Spikes"] -side top
  667. set ::UseMinMaxTime 1
  668. pack [checkbutton ${curframe2}.yrange -text "MinMaxTime" -variable ::UseMinMaxTime -command "puts HalloMinMaxTime" ] -anchor sw -side top
  669. set ::ShowTestSpikes 0
  670. pack [checkbutton ${curframe2}.stsp -text "ShowTestSpikes" -variable ShowTestSpikes] -anchor sw -side top
  671. frame ${curframe1}.timeframe
  672. pack ${curframe1}.timeframe -side right
  673. set curframe2 ${curframe1}.timeframe
  674. set ::CutSpikePot 30
  675. SimParaEntry2 ::CutSpikePot $curframe2
  676. set ::MinTime 0
  677. SimParaEntry2 ::MinTime $curframe2
  678. set ::MaxTime 3
  679. SimParaEntry2 ::MaxTime $curframe2
  680. frame ${curframe1}.cutsp
  681. pack ${curframe1}.cutsp -side right
  682. set curframe2 ${curframe1}.cutsp
  683. }
  684. proc PutSimoutputToText { {CurFrame ::.fmtextfeld} {NLines 200} } {
  685. if {$::SimOutOrError == 0} {
  686. set SimOutputFile simoutput.txt
  687. } else {
  688. set SimOutputFile simerror.txt
  689. }
  690. # Text löschen
  691. $CurFrame delete 0.0 end
  692. # Text aus Datei einfügen
  693. # check file existence
  694. if ([file exists $SimOutputFile]) {
  695. $CurFrame insert end [exec tail $SimOutputFile -n $::NLines]
  696. } else {
  697. $CurFrame insert end "$SimOutputFile doesn't exist"
  698. }
  699. $CurFrame see end
  700. }
  701. proc ShowHideOutputWin {WinName WinVisible} {
  702. upvar $WinVisible VisibleState
  703. if {$VisibleState == 0} {
  704. wm withdraw $WinName
  705. } else {
  706. wm deiconify $WinName
  707. PutSimoutputToText $::fmtextfeld $::NLines
  708. }
  709. }
  710. proc ShowSimoutputWindow {SimOutputWindowName} {
  711. set ::VisibleSimoutputWindow 0
  712. set ::SimOutOrError 0
  713. toplevel $SimOutputWindowName
  714. wm protocol $SimOutputWindowName WM_DELETE_WINDOW "HideWin $SimOutputWindowName VisibleSimoutputWindow"
  715. # set curframe ${::SimOutputWindowName}
  716. # Textfeld generieren
  717. set curframe ${::SimOutputWindowName}.myfmtextfeld
  718. frame $curframe -width 900 -height 600
  719. pack $curframe
  720. text ${curframe}.mytext
  721. set curframe2 ${curframe}.mytext
  722. set ::fmtextfeld $curframe2
  723. set curframe1 ${curframe}.oben
  724. frame $curframe1
  725. pack $curframe1 -side top
  726. set ::NLines 24
  727. button ${curframe1}.b -text {Text aktualisieren (tail simoutput.txt -n NLines)} -background red -command {PutSimoutputToText $::fmtextfeld $::NLines}
  728. pack ${curframe1}.b -side left -fill x
  729. set curframeright ${curframe1}.right
  730. frame $curframeright
  731. pack $curframeright -side right
  732. set curframe3 ${curframeright}.nlines
  733. frame $curframe3
  734. pack $curframe3 -anchor sw -side left
  735. label ${curframe3}.nlineslabel -text "NLines"
  736. pack ${curframe3}.nlineslabel -side left
  737. set mybut [entry ${curframe3}.nlinesentry -textvariable ::NLines -width 7 -bg white -relief sunken -border 1 -highlightcolor green]
  738. pack $mybut -side top -anchor n -side right -pady 2
  739. # Textfeld platzieren
  740. pack $curframe2 -side bottom
  741. # Text in Textfeld einfuegen
  742. PutSimoutputToText $::fmtextfeld $::NLines
  743. #ToDo 14.08.08: 2 Radio-Buttons: umschalten zwischen SimOutput und SimError -Ausgabe
  744. set curframe4 ${curframeright}.outorerror
  745. frame $curframe4
  746. pack $curframe4 -anchor sw -side right
  747. radiobutton ${curframe4}.out -value 0 -command "PutSimoutputToText $::fmtextfeld $::NLines" -text "SimOutput" -variable ::SimOutOrError
  748. pack ${curframe4}.out -side left
  749. radiobutton ${curframe4}.err -value 1 -command "PutSimoutputToText $::fmtextfeld $::NLines" -text "SimError" -variable ::SimOutOrError
  750. pack ${curframe4}.err -side right
  751. }