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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
System Calls
------------
.. seealso:: `For most of these system calls, check Python's os module <https://docs.python.org/3/library/os.html>`_
Path Manipulation
~~~~~~~~~~~~~~~~~
.. function:: chdir
Syntax:
``h.chdir("path")``
Description:
Change working directory to the indicated path. Returns 0 if successful
otherwise -1, ie the usual unix os shell return style.
----
.. function:: getcwd
Syntax:
``h.getcwd()``
Description:
Returns absolute path of current working directory in unix format.
The last character of the path name is '/'.
Must be less than
1000 characters long.
----
.. function:: neuronhome
Name:
neuronhome -- installation path
Syntax:
``h.neuronhome()``
Description:
Returns the full installation path in unix format or, if it exists, the
NEUROHOME environment variable in unix format.
Note that for unix, it isn't exactly the installation path
but the
--prefix/share/nrn directory where --prefix is the
location specified during installation. For the mswin version it is the location
selected during installation and the value is derived from the location
of neuron.exe in neuronhome()/bin/neuron.exe.
For mac it is the folder that contains the neuron
executable program.
----
Machine Identification
~~~~~~~~~~~~~~~~~~~~~~
.. seealso:: `Python's "platform" module provides access to this information and more <https://docs.python.org/3/library/platform.html>`_
.. function:: machine_name
Syntax:
``h("strdef name")``
``h.machine_name(h.name)``
Description:
returns the hostname of the machine.
----
.. function:: unix_mac_pc
Syntax:
``h.unix_mac_pc()``
Description:
Return 1 if unix, 2 if (an older) mac, 3 if mswin, or 4 if mac osx darwin
is the operating system. This
is useful when deciding if a machine specific function can be called or
a dll can be loaded.
Example:
.. code-block::
python
from neuron import h, gui
type = h.unix_mac_pc()
if type == 1:
print("This os is unix based")
elif type == 2:
print("This os is mac based")
elif type == 3:
print("This os is mswin based")
elif type == 4:
print("This os is mac osx darwin based")
----
.. function:: nrnversion
Syntax:
``h.nrnversion()``
``h.nrnversion(i)``
Description:
Returns a string consisting of version information.
When this function was introduced the majorstring was "5.6"
and the branch string was "2004/01/22 Main (36)".
Now the arg can range from 0 to 6. The value of 6 returns
the args passed to configure. When this function was last changed
the return values were.
An arg of 7 now returns a space separated string of the arguments used
during launch.
e.g.
.. code-block::
none
$ nrniv -nobanner -c 'nrnversion()' -c 'nrnversion(7)'
NEURON -- VERSION 7.2 twophase_multisend (534:2160ccb31406) 2010-12-09
nrniv -nobanner -c nrnversion() -c nrnversion(7)
$
An arg of 8 now returns the host-triplet. E.g.
.. code-block::
none
$ nrniv -nobanner -c 'nrnversion(8)'
x86_64-unknown-linux-gnu
An arg of 9 now returns "1" if the neuron main program was launched,
"2" if the library was loaded by Python, and "0" if the launch
progam is unknown
.. code-block::
none
$ nrniv -nobanner -c 'nrnversion(9)'
1
.. code-block::
none
$ python 2</dev/null
>>> from neuron import h
>>> h.nrnversion(9)
'2'
Example:
.. code-block::
python
from neuron import h, gui
h.nrnversion()
NEURON -- VERSION 7.1 (296:ff4976021aae) 2009-02-27
for i in range(6):
print('{} : {}'.format(i, h.nrnversion(i)))
0 : 7.5
1 : NEURON -- VERSION 7.5 (1482:5fb6a5cbbdb7) 2016-11-25
2 : VERSION 7.5 (1482:5fb6a5cbbdb7)
3 : 5fb6a5cbbdb7
4 : 2016-11-25
5 : 1482
6 : '--with-iv=/usr/site/nrniv/iv' '--prefix=/usr/site/../arch/nrn' '--with-nrnpython' '--with-paranrn'
----
Execute a Command
~~~~~~~~~~~~~~~~~
.. function:: WinExec
Syntax:
``h.WinExec("mswin command")``
Description:
MSWin version only.
----
.. function:: system
Name:
system --- issue a shell command
Syntax:
``exitcode = h.system(cmdstr)``
``exitcode = h.system(cmdstr, stdout_str)``
Description:
Executes *cmdstr* as though it had been typed as
command to a unix shell from the terminal. HOC waits until the command is
completed. If the second strdef arg is present, it receives the stdout stream
from the command. Only available memory limits the line length and
number of lines.
Example:
\ ``h.system("ls")``
Prints a directory listing in the console terminal window.
will take up where it left off when the user types the \ ``exit``
command
.. warning::
Fully functional on unix, mswin under cygwin, and mac osx.
Does not work on the mac os 9 version.
Following is obsolete:
Under mswin, executes the string under the cygwin sh.exe in :file:`$NEURONHOME/bin`
via the wrapper, :file:`$NEURONHOME/lib/nrnsys.sh`. Normally, stdout is directed to
the file :file:`tmpdos2.tmp` in the working directory and this is copied to the
terminal. The neuron.exe busy waits until the nrnsys.sh script creates
a tmpdos1.tmp file signaling that the system command has completed.
Redirection of stdout to a file can only be done with the idiom
"command > filename". No other redirection is possible except by modifying
:file:`nrnsys.sh`.
----
Timing
~~~~~~
.. function:: startsw
Syntax:
``h.startsw()``
Initializes a stopwatch with a resolution of 1 second or 0.01 second if
gettimeofday system call is available. See :func:`stopsw` .
----
.. function:: stopsw
Syntax:
``h.stopsw()``
Returns the time in seconds since the stopwatch was last initialized with a :func:`startsw` .
Description:
Really the idiom
.. code-block::
python
x = h.startsw()
h.startsw() - x
should be used since it allows nested timing intervals.
Example:
.. code-block::
python
from neuron import h, gui
from math import sin
h.startsw()
for i in range(100000):
x = sin(0.2)
print(h.stopsw())
.. note::
A pure Python alternative would be to use the time module's perf_counter function.
.. seealso::
:class:`Timer`
----
Miscellaneous
~~~~~~~~~~~~~
.. function:: nrn_load_dll
Syntax:
``h.nrn_load_dll(dll_file_name)``
Description:
Loads a dll containing membrane mechanisms. This works for mswin, mac,
and linux.
.. function:: show_winio
Syntax:
``h.show_winio(0or1)``
Description:
MSWin and Mac version only. Hides or shows the console window.
|