NEURON
ivocmain.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <../nrnpython/nrnpython_config.h>
3 
5 
6 #if !HAVE_IV
7 #define Session void
8 int hoc_main1(int, const char**, const char**);
9 void hoc_main1_init(const char*, const char**);
10 #endif
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #if HAVE_UNISTD_H
15 #include <unistd.h>
16 #if !defined (__APPLE__)
17 extern char** environ;
18 #else
19 #include <crt_externs.h>
20 #endif
21 #endif
22 
23 #if HAVE_IV
24 #ifdef WIN32
25 #include <IV-Win/MWlib.h>
26 void iv_display_scale(float);
27 #endif
28 
29 #include <ivstream.h>
30 #include <assert.h>
31 #include "ivoc.h"
32 #include "idraw.h"
33 #include <InterViews/style.h>
34 #endif
35 #include <OS/string.h>
36 #include "string.h"
37 #include "oc2iv.h"
38 #include "nrnmpi.h"
39 
40 #if defined(IVX11_DYNAM)
41 #include <IV-X11/ivx11_dynam.h>
42 #endif
43 
44 #if defined(carbon)
45 #undef MAC
46 #endif
47 
48 #if MAC || defined(WIN32)
49 #include "njconf.h"
50 #else
51 #include "../nrnjava/njconf.h"
52 #endif
53 
54 #if 1
55 void pr_profile();
56 #define PR_PROFILE pr_profile();
57 #else
58 #define PR_PROFILE /**/
59 #endif
60 /*****************************************************************************/
61 
62 #if HAVE_IV
63 static PropertyData properties[] = {
64 {"*gui", "sgimotif"},
65 {"*PopupWindow*overlay", "true"},
66 {"*PopupWindow*saveUnder", "on"},
67 {"*TransientWindow*saveUnder", "on"},
68 {"*background", "#ffffff"},
69 {"*brush_width", "0"},
70 {"*double_buffered", "on"},
71 {"*flat", "#aaaaaa"},
72 #if defined(WIN32)|| defined(CYGWIN)
73 {"*font", "*Arial*bold*--12*"},
74 {"*MenuBar*font", "*Arial*bold*--12*"},
75 {"*MenuItem*font", "*Arial*bold*--12*"},
76 #endif
77 {"*foreground", "#000000"},
78 {"*synchronous", "off"},
79 {"*malloc_debug", "on"},
80 
81 {"*Scene_background", "#ffffff"},
82 {"*Scene_foreground", "#000000"},
83 {"*FieldEditor*background", "#ffffff"},
84 //{"*background", "#cfffff"},
85 {"*default_brush", "0"},
86 {"*view_margin", ".25"},
87 {"*pwm_dismiss_button", "Iconify"},
88 {"*dismiss_button", "Close"},
89 {"*use_transient_windows", "yes"},
90 {"*nrn_library", " $(NEURONHOME)/lib"},
91 {"*view_pick_epsilon", "2"},
92 {"*pwm_canvas_height", "120"},
93 {"*pwm_paper_height", "11"},
94 {"*pwm_paper_width", "8.5"},
95 {"*pwm_paper_resolution", ".5"},
96 {"*pwm_pixel_resolution", "0"},
97 {"*window_manager_offset_x", "5."},
98 {"*window_manager_offset_y", "26."},
99 {"*pwm_print_file_filter", "*.ps"},
100 {"*pwm_idraw_file_filter", "*.id"},
101 {"*pwm_ascii_file_filter", "*"},
102 {"*pwm_save_file_filter", "*.ses"},
103 {"*pwm_idraw_prologue", "$(NEURONHOME)/lib/prologue.id"},
104 {"*pwm_postscript_filter", "sed 's;/Adobe-;/;'"},
105 {"*SlowSlider*autorepeatStart", "0."},
106 {"*scene_print_border", "1"},
107 {"*radioScale", ".9"},
108 {"*stepper_size", "20."},
109 {"*xvalue_field_size_increase", "10."},
110 {"*xvalue_format", "%.5g"},
111 {"*graph_axis_default", "0"},
112 {"*shape_scale_file", "$(NEURONHOME)/lib/shape.cm2"},
113 {"*shape_quadedge", "0"},
114 {"*CBWidget_ncolor", "10"},
115 {"*CBWidget_nbrush", "10"},
116 {"*units_on_flag", "on"},
117 {"*NFRAME", "0"}, // see src/oc/code.cpp for the default value
118 {"*NSTACK", "0"}, // see src/oc/code.cpp for the default value
119 {"*Py_NoSiteFlag", "0"},
120 {"*python", "off"},
121 {"*nopython", "off"},
122 {"*err_dialog", "off"},
123 {"*banner", "on"},
124 {"*pyexe", ""},
125  { NULL }
126 };
127 
128 static OptionDesc options[] = {
129 {"-dismissbutton", "*dismiss_button", OptionValueImplicit, "Close"},
130 {"-extrapipeinput", "*extrapipeinput", OptionValueNext},
131 {"-dll", "*nrnmechdll", OptionValueNext},
132 {"-showwinio", "*showwinio", OptionValueImplicit, "on"},
133 {"-hidewinio", "*showwinio", OptionValueImplicit, "off"},
134 {"-isatty", "*isatty", OptionValueImplicit, "1"},
135 {"-notatty", "*isatty", OptionValueImplicit, "-1"},
136 {"-neosim", "*neosim", OptionValueImplicit, "on"},
137 {"-bbs_nhost", "*bbs_nhost", OptionValueNext},
138 {"-NSTACK", "*NSTACK", OptionValueNext},
139 {"-NFRAME", "*NFRAME", OptionValueNext},
140 {"--version", "*print_nrn_version", OptionValueImplicit, "on"},
141 {"-python", "*python", OptionValueImplicit, "on"},
142 {"-nopython", "*nopython", OptionValueImplicit, "on"},
143 {"-pyexe", "*pyexe", OptionValueNext},
144 {"-Py_NoSiteFlag", "*Py_NoSiteFlag", OptionValueImplicit, "1"},
145 {"-nobanner", "*banner", OptionValueImplicit, "off"},
146 #if defined(WIN32)
147 {"-mswin_scale", "*mswin_scale", OptionValueNext},
148 #endif
149  { NULL }
150 };
151 #endif // HAVE_IV
152 
153  extern int hoc_obj_run(const char*, Object*);
154  extern int nrn_istty_;
155  extern char* nrn_version(int);
156  extern int nrn_nobanner_;
157  extern void hoc_final_exit();
158  void ivoc_final_exit();
159 #if (defined(NRNMECH_DLL_STYLE) || defined(WIN32))
160  extern const char* nrn_mech_dll;
161 #endif
162 #if defined(USE_PYTHON)
163  int nrn_nopython;
164  extern int use_python_interpreter;
165  extern int (*p_nrnpython_start)(int);
166  char* nrnpy_pyexe;
167 #endif
168 
169 /*****************************************************************************/
170 //exported initialized data so shared libraries can have assert pure-text
171 #if HAVE_IV
172 int Oc::refcnt_ = 0;
173 Session* Oc::session_ = 0;
175 ostream* OcIdraw::idraw_stream = 0;
176 #endif
177 /*****************************************************************************/
178 extern void ivoc_cleanup();
179 #if OCSMALL
180 static char* ocsmall_argv[] = {0, "difus.hoc"};
181 #endif
182 #if defined(WIN32) && HAVE_IV
183 extern HWND hCurrWnd;
184 #endif
185 
186 
187  extern void setneuronhome(const char*);
188  extern const char* neuron_home;
189  int hoc_xopen1(const char* filename, const char* rcs);
190  extern int units_on_flag_;
191  extern double hoc_default_dll_loaded_;
192  extern int hoc_print_first_instance;
194 
195 #if !defined(WIN32) && !MAC && !defined(CYGWIN)
196 extern void setneuronhome(const char*) {
197  neuron_home = getenv("NEURONHOME");
198 }
199 #endif
200 
201 #if 0
202 void penv() {
203  int i;
204  for (i=0; environ[i]; ++i) {
205  printf("%p %s\n", environ[i], environ[i]);
206  }
207 }
208 #endif
209 
210 #if DARWIN || defined(__linux__)
211 #include <dlfcn.h>
212 #include <string>
213 
214 /* It is definitely now the case on mac and I think sometimes the case on
215 linux that dlopen needs a full path to the file. A path to the binary
216 is not necessarily sufficent as one may launch python or nrniv on the
217 target machine and the lib folder cannot be derived from the location of
218 the python executable.This seems to be robust if nrn_version is inside a
219 shared library.
220 The return value ends with a '/' and if the prefix cannot be determined
221 the return value is "".
222 */
223 const char* path_prefix_to_libnrniv() {
224  static char* path_prefix_to_libnrniv_ = NULL;
225  if (!path_prefix_to_libnrniv_) {
226  Dl_info info;
227  int rval = dladdr((void*)nrn_version, &info);
228  std::string name;
229  if (rval) {
230  if (info.dli_fname) {
231  name = info.dli_fname;
232  if (info.dli_fname[0] == '/') { // likely full path
233  size_t last_slash = name.rfind("/");
234  path_prefix_to_libnrniv_ = strndup(name.c_str(), last_slash+1);
235  path_prefix_to_libnrniv_[last_slash+1] = '\0';
236  }
237  }
238  }
239  if (!path_prefix_to_libnrniv_) {
240  path_prefix_to_libnrniv_ = strdup("");
241  }
242  }
243  return path_prefix_to_libnrniv_;
244 }
245 #endif // DARWIN || defined(__linux__)
246 
247 #if MAC
248 #include <string.h>
249 #include <sioux.h>
250 extern bool mac_load_dll(const char*);
251 void mac_open_doc(const char* s) {
252  // only chdir and load dll on the first opendoc
253  static bool done = false;
254  char cs[256];
255  strncpy(cs, s, 256);
256  char* cp = strrchr(cs, ':');
257  if (cp && !done) {
258  *cp = '\0';
259  if (chdir(cs) == 0) {
260  done = true;
261  printf("current directory is \"%s\"\n", cs);
262  if (mac_load_dll("nrnmac.dll")) {
264  }
265  }
266  }
267  hoc_xopen1(s, 0);
268 }
269 void mac_open_app(){
270  hoc_xopen1(":lib:hoc:macload.hoc", 0);
271 }
272 #endif
273 
274 #ifdef MAC
275 #pragma export on
276 #endif
277 
278  int ivocmain(int, const char**, const char**);
279  int ivocmain_session(int, const char**, const char**, int start_session);
280  int (*p_neosim_main)(int, const char**, const char**);
281  extern int nrn_global_argc;
282  extern const char** nrn_global_argv;
284  extern int nrn_is_python_extension;
285  extern void hoc_nrnmpi_init();
286 #if NRNMPI_DYNAMICLOAD
287  extern void nrnmpi_stubs();
288  extern char* nrnmpi_load(int is_python);
289 #endif
290 
291 // some things are defined in libraries earlier than they are used so...
292 #include <nrnisaac.h>
293 static void force_load() {
294  if (always_false) {
295  nrnisaac_new();
296  }
297 }
298 
299 #if defined(CYGWIN)
300 // see iv/src/OS/directory.cpp
301 #include <sys/stat.h>
302 static bool isdir(const char* p) {
303  struct stat st;
304  bool b = stat(p, &st) == 0 && S_ISDIR(st.st_mode);
305  //printf("isdir %s returns %d\n", p, b);
306  return b;
307 }
308 #endif
309 
310 #ifdef MAC
311 #pragma export off
312 #endif
313 
314 // in case we are running without IV then get some important args this way
315 static bool nrn_optarg_on(const char* opt, int* argc, char** argv);
316 static char* nrn_optarg(const char* opt, int* argc, char** argv);
317 static int nrn_optargint(const char* opt, int* argc, char** argv, int dflt);
318 
319 static bool nrn_optarg_on(const char* opt, int* pargc, const char** argv) {
320  char* a;
321  int i;
322  for (i=0; i < *pargc; ++i) {
323  if (strcmp(opt, argv[i]) == 0) {
324  *pargc -= 1;
325  for (; i < *pargc; ++i) {
326  argv[i] = argv[i+1];
327  }
328 // printf("nrn_optarg_on %s return true\n", opt);
329  return true;
330  }
331  }
332  return false;
333 }
334 
335 static const char* nrn_optarg(const char* opt, int* pargc, const char** argv) {
336  const char* a;
337  int i;
338  for (i=0; i < *pargc - 1; ++i) {
339  if (strcmp(opt, argv[i]) == 0) {
340  a = argv[i+1];
341  *pargc -= 2;
342  for (; i < *pargc; ++i) {
343  argv[i] = argv[i+2];
344  }
345 // printf("nrn_optarg %s return %s\n", opt, a);
346  return a;
347  }
348  }
349  return 0;
350 }
351 
352 static int nrn_optargint(const char* opt, int* pargc, const char** argv, int dflt) {
353  const char* a;
354  int i;
355  i = dflt;
356  a = nrn_optarg(opt, pargc, argv);
357  if (a) {
358  sscanf(a, "%d", &i);
359  }
360 // printf("nrn_optargint %s return %d\n", opt, i);
361  return i;
362 }
363 
364 #if USENRNJAVA
365 void nrn_InitializeJavaVM();
366 #endif
367 
368 #if 0 //for debugging
369 void prargs(const char* s, int argc, const char** argv) {
370  int i;
371  printf("%s argc=%d\n", s, argc);
372  for (i=0; i < argc; ++i) {
373  printf(" %d |%s|\n", i, argv[i]);
374  }
375 }
376 #endif
377 
379 #if NRNMPI
380  if (!nrnmpi_use) {
381 #if NRNMPI_DYNAMICLOAD
382  nrnmpi_stubs();
383  const char* pmes = nrnmpi_load(1);
384  if (pmes) {
385  printf("%s\n", pmes);
386  }
387 #endif
388 
389  char** foo = (char**)nrn_global_argv;
390  nrnmpi_init(2, &nrn_global_argc, &foo);
391  //if (nrnmpi_myid == 0) {printf("hoc_nrnmpi_init called nrnmpi_init\n");}
392  // turn off gui for all ranks > 0
393  if (nrnmpi_myid_world > 0) {
394  hoc_usegui = 0;
396  }
397  }
398 #endif
399  hoc_ret();
400  hoc_pushx(0.0);
401 }
402 
403 /**
404  * Main entrypoint function into the HOC interpeter
405  *
406  * This function simply calls ivocmain_session with the \c start_session = 1.
407  *
408  * \note This is part of NEURON's public interface
409  *
410  * \note \c env argument should not be used as it might become invalid
411  *
412  * \param argc argument count as found in C/C++ \c main functions
413  * \param argv argument vector as found in C/C++ \c main functions
414  * \param env environment variable array as optionally found in main functions.
415  * \return 0 on success, otherwise error code.
416  */
417 int ivocmain(int argc, const char** argv, const char** env) {
418 
419  return ivocmain_session(argc, argv, env, 1);
420 
421 }
422 /**
423  * This used to be ivocmain, the main entrypoint to the HOC interpreter
424  *
425  * ivocmain_session parses command line argument, calls of initialization
426  * functions and drops into an interactive HOC session.
427  * This function is called for example by the "real main" in \c nrnmain.cpp ,
428  * but can be also called from other external user applications that use
429  * NEURON.
430  * Additionally to the original implemenation a new parameter \c start_session
431  * was introduced to control whether an interactive HOC session shoudl be started
432  * or simply NEURON and all data structures be initialized and control returned
433  * to the caller.
434  *
435  * \note \c env argument should not be used as it might become invalid
436  *
437  * \param argc argument count as found in C/C++ \c main functions
438  * \param argv argument vector as found in C/C++ \c main functions
439  * \param env environment variable array as optionally found in main functions.
440  * \param start_session set to 1 for default behavior (drop into interactive HOC session
441  * otherwise set to 0. If set to 1, but compiled with python support this function will
442  * still directly return (since in that mode we don't need an interactive HOC session
443  * either.
444  * \return 0 on success, otherwise error code.
445  */
446 int ivocmain_session(int argc, const char** argv, const char** env, int start_session) {
447 // third arg should not be used as it might become invalid
448 // after putenv or setenv. Instead, if necessary use
449 // #include <unistd.h>
450 // extern char** environ;
451  int i;
452 // prargs("at beginning", argc, argv);
453  force_load();
455  // https://en.cppreference.com/w/cpp/language/main_function, note that argv is
456  // of length argc + 1 and argv[argc] is null.
457  nrn_global_argv = new const char*[argc+1];
458  for (i = 0; i < argc+1; ++i) {
459  nrn_global_argv[i] = argv[i];
460  }
462  if (nrn_optarg_on("-help", &argc, argv)
463  || nrn_optarg_on("-h", &argc, argv)) {
464  printf("nrniv [options] [fileargs]\n\
465  options:\n\
466  -dll filename dynamically load the linked mod files.\n\
467  -h print this help message\n\
468  -help print this help message\n\
469  -isatty unbuffered stdout, print prompt when waiting for stdin\n\
470  -mpi launched by mpirun or mpiexec, in parallel environment\n\
471  -mswin_scale float scales gui on screen\n\
472  -music launched as a process of the MUlti SImulator Coordinator\n\
473  -NSTACK integer size of stack (default 1000)\n\
474  -NFRAME integer depth of function call nesting (default 200)\n\
475  -nobanner do not print startup banner\n\
476  -nogui do not send any gui info to screen\n\
477  -notatty buffered stdout and no prompt\n\
478  -python Python is the interpreter\n\
479  -pyexe path Python to use if python (or python3 fallback) not right.\n\
480  -nopython Do not initialize Python\n\
481  -Py_NoSiteFlag Set Py_NoSiteFlag=1 before initializing Python\n\
482  -realtime For hard real-time simulation for dynamic clamp\n\
483  --version print version info\n\
484  and all InterViews and X11 options\n\
485  fileargs: any number of following\n\
486  - input from stdin til ^D (end of file)\n\
487  -c \"statement\" execute next statement\n\
488  filename execute contents of filename\n\
489 ");
490  exit(0);
491  }
492  if (nrn_optarg_on("--version", &argc, argv)) {
493  printf("%s\n", nrn_version(1));
494  exit(0);
495  }
496  if (nrn_optarg_on("-nobanner", &argc, argv)) {
497  nrn_nobanner_ = 1;
498  }
499  if (nrn_optarg_on("-Py_NoSiteFlag", &argc, argv)) {
500  nrnpy_nositeflag = 1;
501  }
502 
503  nrnmpi_numprocs = nrn_optargint("-bbs_nhost", &argc, argv, nrnmpi_numprocs);
504  hoc_usegui = 1;
505  if (nrn_optarg_on("-nogui", &argc, argv)) {
506  hoc_usegui = 0;
508  }
509  if (nrnmpi_numprocs > 1) {
510  hoc_usegui = 0;
512  }
513 #if NRNMPI
514  if (nrnmpi_use) {
515  hoc_usegui = 0;
517  }
518 #else
519 
520 // check if user is trying to use -mpi or -p4 when it was not
521 // enabled at build time. If so, issue a warning.
522 
523  int b;
524  b = 0;
525  for (i=0; i < argc; ++i) {
526  if (strncmp("-p4", (argv)[i], 3) == 0) {
527  b = 1;
528  break;
529  }
530  if (strcmp("-mpi", (argv)[i]) == 0) {
531  b = 1;
532  break;
533  }
534  }
535  if (b) {
536  printf("Warning: detected user attempt to enable MPI, but MPI support was disabled at build time.\n");
537  }
538 
539 #endif
540 
541 #if defined(IVX11_DYNAM)
542  if (hoc_usegui && ivx11_dyload()) {
543  hoc_usegui = 0;
545  }
546 #endif
547 
548 #if NRN_MUSIC
549  nrn_optarg_on("-music", &argc, argv);
550 #else
551  if (nrn_optarg_on("-music", &argc, argv)) {
552  printf("Warning: attempt to enable MUSIC but MUSIC support was disabled at build time.\n");
553  }
554 #endif
555 
556 #if !HAVE_IV
557  hoc_usegui = 0;
559 #endif
560  int our_argc = argc;
561  const char** our_argv = argv;
562  int exit_status = 0;
563  Session* session = NULL;
564 #if !defined(WIN32)&&!defined(MAC) && !defined(CYGWIN)
565 // Gary Holt's first pass at this was:
566 //
567 // Set the NEURONHOME environment variable. This should override any setting
568 // in the environment, so someone doesn't accidently use data files from an
569 // old version of neuron.
570 //
571 // But I have decided to use the environment variable if it exists
572  neuron_home = getenv("NEURONHOME");
573  if (!neuron_home) {
574 #if defined(HAVE_PUTENV)
575  // the only reason the following is static is to prevent valgrind
576  // from complaining it is a memory leak.
577  static char* buffer = new char[strlen(NEURON_DATA_DIR) + 12];
578  sprintf(buffer, "NEURONHOME=%s", NEURON_DATA_DIR);
579  putenv(buffer);
580  neuron_home = NEURON_DATA_DIR;
581 #elif defined(HAVE_SETENV)
582  setenv("NEURONHOME", NEURON_DATA_DIR, 1);
583  neuron_home = NEURON_DATA_DIR;
584 #else
585 #error "I don't know how to set environment variables."
586 // Maybe in this case the user will have to set it by hand.
587 #endif
588  // putenv and setenv may invalidate env but we no longer
589  // use it so following should not be needed
590 #if 0
591 #if HAVE_UNISTD_H && !defined(__APPLE__)
592  env = environ;
593 #endif
594 #if defined (__APPLE__)
595  env = (*_NSGetEnviron());
596 #endif
597 #endif
598  }
599 
600 #else // Not unix:
601  neuron_home = getenv("NEURONHOME");
602  if (!neuron_home) {
603  setneuronhome((argc > 0)?argv[0]:0);
604  }
605  if (!neuron_home) {
606 #if defined(WIN32) && HAVE_IV
607  MessageBox(0, "No NEURONHOME environment variable.", "NEURON Incomplete Installation", MB_OK);
608 #else
609  neuron_home = ".";
610  fprintf(stderr, "Warning: no NEURONHOME environment variable-- setting\
611  to %s\n", neuron_home);
612 #endif
613  }
614 #endif // !unix.
615 
616 #if HAVE_IV
617 #if OCSMALL
618  our_argc = 2;
619  our_argv = new char*[2];
620  our_argv[0] = "Neuron";
621  our_argv[1] = ":lib:hoc:macload.hoc";
622  session = new Session("NEURON", our_argc, our_argv, options, properties);
623 #else
624 #if MAC
625  our_argc = 1;
626  our_argv = new char*[1];
627  our_argv[0] = "Neuron";
628  session = new Session("NEURON", our_argc, our_argv, options, properties);
629  SIOUXSettings.asktosaveonclose = false;
630 #else
631 #if defined(WIN32) || carbon
632 IFGUI
633  session = new Session("NEURON", our_argc, (char**)our_argv, options, properties);
634 ENDGUI
635 #else
636 IFGUI
637  if (getenv("DISPLAY")) {
638  session = new Session("NEURON", our_argc, (char**)our_argv, options, properties);
639  }else{
640  fprintf(stderr, "Warning: no DISPLAY environment variable.\
641 \n--No graphics will be displayed.\n");
642  hoc_usegui = 0;
643  }
644 ENDGUI
645 #endif
646 #endif
647  char* nrn_props;
648  nrn_props = new char[strlen(neuron_home) + 20];
649  if (session) {
650  sprintf(nrn_props, "%s/%s", neuron_home, "lib/nrn.defaults");
651 #ifdef WIN32
652  FILE* f;
653  if ((f = fopen(nrn_props, "r")) != (FILE*)0) {
654  fclose(f);
655  session->style()->load_file(String(nrn_props), -5);
656  }else{
657 #if defined(CYGWIN)
658  sprintf(nrn_props, "%s/%s", neuron_home, "lib/nrn.def");
659 #else
660  sprintf(nrn_props, "%s\\%s", neuron_home, "lib\\nrn.def");
661 #endif
662  if ((f = fopen(nrn_props, "r")) != (FILE*)0) {
663  fclose(f);
664  session->style()->load_file(String(nrn_props), -5);
665  }else{
666  char buf[256];
667  sprintf(buf, "Can't load NEURON resources from %s[aults]",
668  nrn_props);
669  printf("%s\n", buf);
670  }
671  }
672 #else
673  session->style()->load_file(String(nrn_props), -5);
674 #endif
675 #if ! MAC
676  char* h = getenv("HOME");
677  if (h) {
678  sprintf(nrn_props, "%s/%s", h, ".nrn.defaults");
679  session->style()->load_file(String(nrn_props), -5);
680  }
681 #endif
682  }
683  delete [] nrn_props;
684 
685 #endif /*OCSMALL*/
686 
687  if (session) {
688  session->style()->find_attribute("NSTACK", hoc_nstack);
689  session->style()->find_attribute("NFRAME", hoc_nframe);
690 IFGUI
691  if (session->style()->value_is_on("err_dialog")) {
693  }
694 ENDGUI
695  }else
696 #endif //HAVE_IV
697  {
698  hoc_nstack = nrn_optargint("-NSTACK", &our_argc, our_argv, 0);
699  hoc_nframe = nrn_optargint("-NFRAME", &our_argc, our_argv, 0);
700  }
701 
702 #if defined(USE_PYTHON)
703  nrn_nopython = 0;
705 #if HAVE_IV
706  if (session) {
707  if (session->style()->value_is_on("nopython")) {
708  nrn_nopython = 1;
709  }
710  String str;
711  if (session->style()->find_attribute("pyexe", str)) {
712  nrnpy_pyexe = strdup(str.string());
713  }
714  }else
715 #endif
716  {
717  if (nrn_optarg_on("-nopython", &our_argc, our_argv)) {
718  nrn_nopython = 1;
719  }
720  const char* buf = nrn_optarg("-pyexe", &our_argc, our_argv);
721  if (buf) {nrnpy_pyexe = strdup(buf);}
722  }
723  }
724 #endif //USE_PYTHON
725 
726 #if defined(WIN32) && HAVE_IV
727 IFGUI
728  double scale = 1.;
729  int pw = GetSystemMetrics(SM_CXVIRTUALSCREEN);
730  if (pw < 1100) {
731  scale = 1200./double(pw);
732  }
733  session->style()->find_attribute("mswin_scale", scale);
734  iv_display_scale(float(scale));
735 ENDGUI
736 #endif
737 
738  // just eliminate from arg list
739  nrn_optarg_on("-mpi", &our_argc, our_argv);
740 
741 #if (defined(NRNMECH_DLL_STYLE) || defined(WIN32))
742  String str;
743 #if HAVE_IV
744  if (session) {
745  if (session->style()->find_attribute("nrnmechdll", str)) {
746  nrn_mech_dll = str.string();
747  }
748  }else
749 #endif
750  { // if running without IV.
751  nrn_mech_dll = nrn_optarg("-dll", &our_argc, our_argv);
752  // may be duplicated since nrnbbs adds all args to special
753  // which is often a script that adds a -dll arg
754  nrn_optarg("-dll", &our_argc, our_argv);
755  }
756 #if NRNMPI
757  if (nrnmpi_use && !nrn_mech_dll) {
758  // for heterogeneous clusters, mpirun allows different programs
759  // but not different arguments. So the -dll is insufficient.
760  // Therefore we check to see if it makes sense to load
761  // a dll from the usual location.
762  // Actually this is done by default in src/nrnoc/init.cpp
763  }
764 #endif
765 
766 #endif //NRNMECH_DLL_STYLE
767 
768 
769 #if HAVE_IV
770  if (session) {
771  long i;
772  if (session->style()->find_attribute("isatty", i)) {
773  nrn_istty_ = i;
774  }
775  }else
776 #endif
777  {
778  nrn_istty_ = nrn_optarg_on("-isatty", &our_argc, our_argv);
779  if (nrn_istty_ == 0) {
780  nrn_istty_ = nrn_optarg_on("-notatty", &our_argc, our_argv);
781  if (nrn_istty_ == 1) { nrn_istty_ = -1; }
782  }
783  }
784 
785 #if HAVE_IV
786  if (session && session->style()->value_is_on("units_on_flag")) {
787  units_on_flag_ = 1;
788  }
789  Oc oc(session, our_argv[0], env);
790 #if defined(WIN32) && !defined(CYGWIN)
791  if (session->style()->find_attribute("showwinio", str)
792  && !session->style()->value_is_on("showwinio")
793  ) {
794  ShowWindow(hCurrWnd, SW_HIDE);
795  hoc_obj_run("pwman_place(100,100)\n", 0);
796  }
797 #endif
798 #else
799  hoc_main1_init(our_argv[0], env);
800 #endif //HAVE_IV
801 
802 #if USENRNJAVA
804 #endif
805 #if OCSMALL
806  if (argc == 1) {
807  ocsmall_argv[0] = our_argv[0];
808  oc.run(2, ocsmall_argv);
809  }else
810 #endif
811 #if defined(USE_PYTHON)
812 #if HAVE_IV
813  if (session && session->style()->value_is_on("python")) {
814  use_python_interpreter = 1;
815  }
816 #endif
817  if (nrn_optarg_on("-python", &our_argc, our_argv)) {
818  use_python_interpreter = 1;
819  }
820 
821  if (nrn_is_python_extension) { return 0; }
822  //printf("p_nrnpython_start = %p\n", p_nrnpython_start);
823  if (p_nrnpython_start) { (*p_nrnpython_start)(1); }
824  if (use_python_interpreter && !p_nrnpython_start) {
825  fprintf(stderr, "Python not available\n");
826  exit(1);
827  }
828 #endif
829  if (start_session) {
830 #if HAVE_IV
831  oc.run(our_argc, our_argv);
832 #else
833  hoc_main1(our_argc, our_argv, env);
834 #endif
835  } else {
836  return 0;
837  }
838 #if HAVE_IV
839  if (session && session->style()->value_is_on("neosim")) {
840  if (p_neosim_main) {
841  (*p_neosim_main)(argc, argv, env);
842  }else{
843  printf("neosim not available.\nModify nrn/src/nrniv/Imakefile and remove nrniv/$CPU/netcvode.o\n");
844  }
845  }
846 #endif
848 #if defined(USE_PYTHON)
849  if (use_python_interpreter) {
850  // process the .py files and an interactive interpreter
851  if (p_nrnpython_start && (*p_nrnpython_start)(2) != 0) {
852  // We encountered an error when processing the -c argument or Python
853  // script given on the commandline.
854  exit_status = 1;
855  }
856  }
857  if (p_nrnpython_start) { (*p_nrnpython_start)(0); }
858 #endif
859  hoc_final_exit();
860  ivoc_final_exit();
861  return exit_status;
862 }
863 
865 #if NRNMPI
867 #endif
868 }
869 
870 extern "C" {
871 extern double *getarg(int i);
872 extern int ifarg(int);
873 } // extern "C"
874 
875 extern void hoc_ret(), hoc_pushx(double);
876 
878 #if HAVE_IV
879 IFGUI
880  void single_event_run();
881 
883 ENDGUI
884 #endif
885  hoc_ret();
886  hoc_pushx(1.);
887 }
888 
889 #if !HAVE_IV
890 int run_til_stdin() {return 1;}
892 #endif
893 
void hoc_final_exit()
Definition: hoc.cpp:1130
void hoc_single_event_run()
Definition: ivocmain.cpp:877
static ostream * idraw_stream
Definition: idraw.h:47
int run_til_stdin()
Definition: ivocmain.cpp:890
int ivocmain_session(int, const char **, const char **, int start_session)
This used to be ivocmain, the main entrypoint to the HOC interpreter.
Definition: ivocmain.cpp:446
#define nrn_assert(ex)
Definition: nrnassrt.h:35
char * nrnpy_pyexe
static void force_load()
Definition: ivocmain.cpp:293
double hoc_default_dll_loaded_
Definition: hoc_init.cpp:266
static int nrn_optargint(const char *opt, int *argc, char **argv, int dflt)
Definition: ivoc.h:36
int dladdr(const void *dl_restrict, Dl_info *dl_restrict)
int nrn_global_argc
Definition: nrnpython.cpp:34
HWND hCurrWnd
size_t p
static char * nrn_optarg(const char *opt, int *argc, char **argv)
void nrnmpi_terminate()
Definition: nrnmpi.cpp:180
static Session * session_
Definition: ivoc.h:75
static int nrnmpi_use
Definition: multisplit.cpp:48
const char ** nrn_global_argv
Definition: nrnpython.cpp:35
char * nrn_mech_dll
Definition: hoc_init.cpp:269
#define PR_PROFILE
Definition: ivocmain.cpp:56
char * nrn_version(int)
Definition: nrnversion.cpp:27
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static List * info
void hoc_notify_value()
Definition: ivocmain.cpp:891
const char * string() const
Definition: string.h:139
int nrn_istty_
Definition: hoc.cpp:870
int nrn_err_dialog_active_
Definition: ivoc.cpp:40
void hoc_ret()
static double done(void *v)
Definition: ocbbs.cpp:280
static int refcnt_
Definition: ivoc.h:74
#define putenv
Definition: mwprefix.h:37
int always_false
Definition: ivocmain.cpp:283
int hoc_print_first_instance
Definition: hoc_oop.cpp:50
int nrnmpi_myid_world
int nrnmpi_numprocs
_CONST char * s
Definition: system.cpp:74
#define printf
Definition: mwprefix.h:26
int(* p_nrnpython_start)(int)
int hoc_xopen1(const char *filename, const char *rcs)
Definition: fileio.cpp:229
void ivoc_final_exit()
Definition: ivocmain.cpp:864
double * getarg(int i)
Definition: code.cpp:1611
int
Definition: nrnmusic.cpp:71
void single_event_run()
void nrnmpi_init(int nrnmpi_under_nrncontrol, int *pargc, char ***pargv)
Definition: nrnmpi.cpp:58
int nrn_nobanner_
Definition: init.cpp:130
#define ENDGUI
Definition: hocdec.h:352
const char * dli_fname
Definition: osxdlfcn.h:48
char * getenv(const char *s)
Definition: macprt.cpp:67
const char * neuron_home
Definition: hoc_init.cpp:268
fprintf(stderr, "Don't know the location of params at %p\, pp)
int ivocmain(int, const char **, const char **)
Main entrypoint function into the HOC interpeter.
Definition: ivocmain.cpp:417
static JavaVMOption * options
Definition: njvm.cpp:94
int nrn_nopython
int units_on_flag_
Definition: code2.cpp:18
static char * env[]
Definition: inithoc.cpp:228
char * name
Definition: init.cpp:16
static bool nrn_optarg_on(const char *opt, int *argc, char **argv)
static HandleStdin * handleStdin_
Definition: ivoc.h:76
int ifarg(int)
Definition: code.cpp:1562
void hoc_pushx(double)
void * nrnisaac_new(void)
Definition: nrnisaac.cpp:12
int nrnpy_nositeflag
Definition: ivocmain.cpp:193
void ivoc_cleanup()
Definition: ocnoiv1.cpp:17
Definition: hocdec.h:226
int hoc_obj_run(const char *, Object *)
Definition: hoc_oop.cpp:323
void nrn_InitializeJavaVM()
Definition: njvm.cpp:335
void pr_profile()
Definition: hoc.cpp:123
String
Definition: ustring.cpp:41
#define i
Definition: md1redef.h:12
long hoc_nframe
Definition: ivocmain.cpp:4
Definition: string.h:34
bool mac_load_dll(const char *name)
Definition: ivocmac.cpp:139
char buf[512]
Definition: init.cpp:13
int hoc_main1(int, const char **, const char **)
Definition: hoc.cpp:972
long hoc_nstack
Definition: ivocmain.cpp:4
void hoc_main1_init(const char *, const char **)
Definition: hoc.cpp:875
void setneuronhome(const char *)
Definition: ivocmain.cpp:196
int hoc_usegui
Definition: hoc.cpp:148
static int argc
Definition: inithoc.cpp:53
#define IFGUI
Definition: hocdec.h:351
int run(int argc, const char **argv)
int nrn_is_python_extension
Definition: fileio.cpp:871
FILE * fopen()
#define OptionDesc
Definition: _defines.h:193
#define Session
Definition: ivocmain.cpp:7
return NULL
Definition: cabcode.cpp:461
int(* p_neosim_main)(int, const char **, const char **)
Definition: ivocmain.cpp:280
void hoc_nrnmpi_init()
Definition: ivocmain.cpp:378
static char ** argv
Definition: inithoc.cpp:54
#define PropertyData
Definition: _defines.h:213