Move from github, collapse gltk and strictmath, add candle
[clnl] / bin / runcmd.scala
1 #!/bin/sh
2 exec scalas "$0" -q "$@"
3 !#
4
5 /***
6   logLevel := Level.Error
7
8   logLevel in Global := Level.Error
9
10   scalaVersion := "2.9.2"
11
12   libraryDependencies ++= Seq(
13     "asm" % "asm-all" % "3.3.1",
14     "org.picocontainer" % "picocontainer" % "2.13.6",
15     "org.nlogo" % "NetLogo" % "5.2.0" from "http://ccl.northwestern.edu/netlogo/5.2.0/NetLogo.jar"
16   )
17 */
18
19 import org.nlogo.headless.HeadlessWorkspace
20 import org.nlogo.api
21 import org.nlogo.nvm
22 import org.nlogo.util.Utils.url2String
23
24 import collection.JavaConversions._
25
26 val input = io.Source.stdin.getLines.mkString("\n").split("\\@\\#\\$\\#\\@\\#\\$\\#\\@")
27
28 System.out.println("----")
29 val workspace = HeadlessWorkspace.newInstance
30 workspace.silent = true
31
32 if (input.length > 2 && input(2).length > 0) {
33   val modelSetup = input(2)
34   workspace.openFromSource(modelSetup +
35 """
36 @#$#@#$#@
37 GRAPHICS-WINDOW
38 210
39 10
40 649
41 470
42 -1
43 -1
44 13.0
45 1
46 10
47 1
48 1
49 1
50 0
51 1
52 1
53 1
54 -1
55 1
56 -1
57 1
58 0
59 0
60 1
61 ticks
62 30.0
63
64 @#$#@#$#@
65 @#$#@#$#@
66 default
67 true
68 0
69 Polygon -7500403 true true 150 5 40 250 150 205 260 250
70
71 sheep
72 false
73 15
74 Circle -1 true true 203 65 88
75 Circle -1 true true 70 65 162
76 Circle -1 true true 150 105 120
77 Polygon -7500403 true false 218 120 240 165 255 165 278 120
78 Circle -7500403 true false 214 72 67
79 Rectangle -1 true true 164 223 179 298
80 Polygon -1 true true 45 285 30 285 30 240 15 195 45 210
81 Circle -1 true true 3 83 150
82 Rectangle -1 true true 65 221 80 296
83 Polygon -1 true true 195 285 210 285 210 240 240 210 195 210
84 Polygon -7500403 true false 276 85 285 105 302 99 294 83
85 Polygon -7500403 true false 219 85 210 105 193 99 201 83
86
87 @#$#@#$#@
88 NetLogo 5.2.0""")
89 } else if (input.length > 3 && input(3).length > 0) {
90   workspace.openFromSource(url2String("file:" + input(3)))
91 } else {
92   workspace.openFromSource(url2String("file:resources/clnl/empty.nlogo"))
93 }
94
95 workspace.mainRNG.setSeed(15)
96
97 val commands = input(0)
98 if(commands.length > 0) {
99   workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, classOf[api.Observer]), workspace.compileCommands(commands))
100 }
101 if(input.length > 1) {
102   val reporter = input(1)
103   if(reporter.length > 0) {
104     System.out.println(org.nlogo.api.Dump.logoObject(workspace.runCompiledReporter(new api.SimpleJobOwner("test", workspace.world.mainRNG, classOf[api.Observer]), workspace.compileReporter(reporter))))
105   }
106 }
107
108 workspace.world.exportWorld(new java.io.PrintWriter(System.out, true), true)
109 System.out.println(org.nlogo.headless.Checksummer.calculateChecksum(workspace.world.exportWorld(_, true)))
110
111 workspace.dispose