[med-svn] [cnrun] 13/25: WIP

andrei zavada hmmr-guest at moszumanska.debian.org
Thu Nov 6 22:08:30 UTC 2014


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch WIP
in repository cnrun.

commit 5699a22a5268dd570e9a490f71c8c8bdcdc8c0b0
Author: andrei zavada <johnhommer at gmail.com>
Date:   Tue Jul 8 15:44:47 2014 +0300

    WIP
---
 upstream/configure.ac           |   2 +-
 upstream/src/cnrun/main.cc      | 516 +++++++++++++++++++++++-----------------
 upstream/src/cnrun/runner.hh    | 207 +++++++---------
 upstream/src/libcn/base-unit.cc |  10 -
 upstream/src/libcn/model.hh     |  77 ++++--
 5 files changed, 455 insertions(+), 357 deletions(-)

diff --git a/upstream/configure.ac b/upstream/configure.ac
index ccdd2f3..b5b3dfc 100644
--- a/upstream/configure.ac
+++ b/upstream/configure.ac
@@ -1,7 +1,7 @@
 AC_COPYRIGHT([Copyright (c) 2008-14 Andrei Zavada <johnhommer at gmail.com>])
 
 AC_INIT([cnrun], [1.1.15_rc], [johnhommer at gmail.com])
-AC_CONFIG_SRCDIR([src/cnrun/runner-main.cc])
+AC_CONFIG_SRCDIR([src/cnrun/main.cc])
 AC_CONFIG_MACRO_DIR([m4])
 AC_PREREQ(2.61)
 
diff --git a/upstream/src/cnrun/main.cc b/upstream/src/cnrun/main.cc
index 1d2dd2c..5047c4e 100644
--- a/upstream/src/cnrun/main.cc
+++ b/upstream/src/cnrun/main.cc
@@ -1,17 +1,21 @@
 /*
- * Author: Andrei Zavada <johnhommer at gmail.com>
+ *       File name:  cnrun/main.cc
+ *         Project:  cnrun
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2008-09-02
  *
- * License: GPL-2+
+ *         Purpose:  function main
  *
- * Initial version: 2008-09-02
- *
- * CNModel runner (main, cmdline parser)
+ *         License:  GPL
  */
 
 
-#include <cstdarg>
 #include <unistd.h>
+#include <stdlib.h>
+#include <argp.h>
+#include <cstdarg>
 #include <list>
+#include <string>
 
 #include "libstilton/exprparser.hh"
 #include "runner.hh"
@@ -25,234 +29,320 @@ using namespace std;
 using namespace cnrun;
 
 
+
+// argparse
+
+const char
+        *argp_program_version = PACKAGE_STRING;
+        *argp_program_bug_address = PACKAGE_BUGREPORT;
+
+static char doc[] =
+       PACKAGE " -- a neuronal network model runner";
+
+namespace opt {
+enum TOptChar {
+        list_units            = 'U',
+        dump_model_units      = 'u',
+        dir                   = 'C',
+        listen_dt             = 'E',
+        log_spiking           = 'k',
+        log_spiking_threshold = 0,
+        log_option            = 'L',
+        precision             = 'e',
+        dt_max                = 'M',
+        dt_min                = 'm',
+        dt_xcap               = 0,
+        sort_units            = 0,
+        verbosely             = 'v',
+        help                  = 'h',
+};
+}  // namespace opt, strictly to enclose enum TOptChar
+
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#pragma GCC diagnostic push
+static struct argp_option options[] = {
+        {"list-units",       opt::list_units, NULL,         0,
+         "List all available units and exit." },
+
+        {"chdir",            opt::dir,        "DIR",        0,
+         "Change to DIR before executing script."},
+
+        {"dump-model-units", opt::dump_model_units, NULL,   0,
+         "Dump all unit types in the model and exit."},
+
+        {"listen-dt",        opt::listen_dt,   "MSEC",      0,
+         "Listen at this interval (default 1 msec; set to 0 "
+         "to listen every cycle, which can slow cnrun down considerably)."},
+
+        {"log-spiking",      opt::log_spiking, "l|0",       0,
+         "Write a model-wide log of spiking neurons, using labels (l) "
+         "or unit ids (0)."},
+
+        {"log-spiking-threshold", opt::log_spiking_threshold, "",       0,
+         "Write a model-wide log of spiking neurons, using labels (l) "
+         "or unit ids (0)."},
+
+        {"log-option",       opt::log_option,  "1dbL",      0,
+         "1, only log the first variable; "
+         "d, defer writing to disk until done rather than write continuously; "
+         "b, write in native binary form rather than in ASCII; "
+         "L, log integrator dt."},
+
+        {"precision",        opt::precision,   "N",         0,
+         "Precision for floating point printed output."},
+
+        {"dt-max",           opt::dt_max,      "MSEC",      0,
+         "Max time step (default 0.5)."},
+        {"dt-min",           opt::dt_min,      "MSEC",      0,
+         "Min time step (default 1e-5)."},
+        {"dt-xcap",          opt::dt_xcap,     "TIMES",     0,
+         "Cap dt increase by current dt value x this (default 5)."},
+
+        {"sort-units",       opt::sort_units,   NULL,       0,
+         "Sort units in any bulk output." },
+
+        {"define",           opt::defvar,      "VAR=EXPR",   0,
+         "Define a variable with an initial value."},
+
+        {"verbose",          opt::verbosely,   "LEVEL",     0,
+         "Verbosity level (default 1; values up to 7 are meaningful).  Use a"
+         " negative value to show the progress percentage only,"
+         " indented on the line at -8 x this value."},
+
+        { 0 }
+};
+#pragma GCC diagnostic pop
+
+static char args_doc[] = "SCRIPTFILE(S)";
+
+static error_t parse_opt( int, char*, struct argp_state*);
+
+static struct argp argp = {
+        options,
+        parse_opt,
+        args_doc,
+        doc
+};
+
+
+static error_t
+parse_opt( int key, const char *arg, struct argp_state *state)
+{
+        auto& Q = *(SOptions*)state->input;
+
+        char *endp = nullptr;
+        switch ( key ) {
+        case opt::dt_max:
+                if ( Q.integration_dt_max = strtof( arg, &endp), *endp ) {
+                        fprintf( stderr, "Expected an FP value for dt-max arg, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+        case opt::dt_min:
+                if ( Q.integration_dt_min = strtof( arg, &endp), *endp ) {
+                        fprintf( stderr, "Expected an FP value for dt-min arg, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+        case opt::dt_xcap:
+                if ( Q.integration_dt_max_cap = strtof( arg, &endp), *endp ) {
+                        fprintf( stderr, "Expected an FP value for dt-xcap arg, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+
+        case opt::log_option:
+                if ( strchr( arg, 'd') )
+                        Q.listen_deferwrite = true;
+                if ( strchr( arg, '1') )
+                        Q.listen_1varonly = true;
+                if ( strchr( arg, 'b') )
+                        Q.listen_binary = true;
+                if ( strchr( arg, 'L') )
+                        Q.log_dt = true;
+                break;
+
+        case opt::listen_dt:
+                if ( Q.listen_dt( arg, &endp), *endp ) {
+                        fprintf( stderr, "Expected an FP value for listen-dt arg, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+
+        case opt::precision:
+                Q.precision = strtoul( arg, &endp, 10);
+                if ( *endp || Q.precision > 16 ) {
+                        fprintf( stderr, "Expected an unsigned int <= 16, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+
+        case opt::log_spiking:
+                Q.log_spikers = true;
+                switch ( *arg ) {
+                case '0': Q.log_spikers_use_serial_id = true;	break;
+                case 'l': Q.log_spikers_use_serial_id = false;	break;
+                default:
+                        fprintf( stderr, "Expecting a '0' or 'l' for log-spiking spec, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+        case opt::log_spiking_threshold:
+                Q.spike_threshold = strtof( arg+1, &endp);
+                if ( *endp ) {
+                        fprintf( stderr, "Expecting an FP value for log-spiking-threshold, got \"%s\"", arg);
+                        return (error_t)ARGP_ERR_UNKNOWN;
+                }
+                break;
+
+        case opt::list_units:
+                Q.list_units = true;
+                break;
+
+        case opt::sort_units:
+                Q.sort_units = true;
+                break;
+
+        case opt::chdir:
+                Q.working_dir = arg;
+                break;
+
+        case opt::defvar:
+	{
+                double  unused;
+                CExpression
+                        expr;
+                if ( expr( arg, unused, &Variables) ) {
+                        fprintf( stderr, "Malformed variable assignment with -D");
+                        return CNRUN_CLPARSE_ERROR;
+                }
+        }
+        break;
+
+        case opt::verbosely:
+                Q.verbosely = strtol( arg, &endp, 10);
+                break;
+
+        case ARGP_KEY_ARG:
+                Q.scripts.emplace_back(arg);
+                break;
+
+        default:
+                return (error_t)ARGP_ERR_UNKNOWN;
+        }
+
+        return (error_t)0;
+}
+
+
 void
 cnrun::
-lprintf( int level, const char* fmt, ...)
+lprintf( int level, int verbosely, const char* fmt, ...)
 {
-	if ( level > Options.verbosely ) {
-		va_list ap;
-		va_start (ap, fmt);
-		vprintf( fmt, ap);
-		va_end (ap);
+        if ( level > verbosely ) {
+                va_list ap;
+                va_start (ap, fmt);
+                vprintf( fmt, ap);
+                va_end (ap);
 	}
 }
 
 
-CModel *cnrun::Model;
-
-
-SCNRunnerOptions cnrun::Options;
-const char *ScriptFileName = ""; // CNRUN_DEFAULT_SCRIPT;
-
-
-
-#define CNRUN_CLPARSE_HELP_REQUEST	-1
-#define CNRUN_CLPARSE_ERROR		-2
-#define CNRUN_DUMP_PARAMS		-3
-
-namespace {
-static int parse_options( int argc, char **argv, list<SVariable>&);
-static void usage( const char *argv0);
-}
-
-#define CNRUN_EARGS		-1
-#define CNRUN_ESETUP		-2
-#define CNRUN_ETRIALFAIL	-3
 
 
 
+// #include "print-version.hh"
 void print_version( const char* appname);
 
 int
 main( int argc, char *argv[])
 {
-	print_version( "cnrun");
-
-	int retval = 0;
-
-	list<SVariable> Variables;
-	switch ( parse_options( argc, argv, Variables) ) {
-	case CNRUN_CLPARSE_ERROR:
-		fprintf( stderr, "Problem parsing command line or sanitising values; try -h for help\n");
-		return CNRUN_EARGS;
-	case CNRUN_CLPARSE_HELP_REQUEST:
-		usage( argv[0]);
-		return 0;
-	}
+        print_version( "cnrun");
+
+        cnrun::SOptions Options;
+        argp_parse( &argp, argc, argv, 0, NULL, (void*)&Options);
 
       // purely informational, requires no model
-	if ( Options.list_units ) {
-		cnmodel_dump_available_units();
-		return 0;
-	}
+        if ( Q.list_units ) {
+                cnmodel_dump_available_units();
+                return 0;
+        }
 
       // cd as requested
-	char *pwd = nullptr;
-	if ( Options.working_dir ) {
-		pwd = getcwd( nullptr, 0);
-		if ( chdir( Options.working_dir) ) {
-			fprintf( stderr, "Failed to cd to \"%s\"", Options.working_dir);
-			return CNRUN_EARGS;
-		}
-	}
-
-	__cn_verbosely = Options.verbosely;
-	__cn_default_unit_precision = Options.precision;
-
-	interpreter_run( ScriptFileName, 0, Options.interp_howstrict,
-			 true, true, Variables);
-
-	delete Model;
-
-	if ( pwd )
-		if ( chdir( pwd) )
-			;
-
-	return retval;
-}
-
-
-
-
-namespace {
-int
-parse_options( int argc, char **argv, list<SVariable>& Variables)
-{
-	int	c;
-
-	while ( (c = getopt( argc, argv, "e:t::L:E:g:k:UsC:n:D:v:h")) != -1 )
-		switch ( c ) {
-
-		case 'e':	ScriptFileName = optarg;					break;
-
-		case 't':	switch ( optarg[0] ) {
-				case 'T':	if ( sscanf( optarg+1, "%lg", &Options.integration_dt_max) != 1 ) {
-							fprintf( stderr, "-tT takes a double");
-							return CNRUN_CLPARSE_ERROR;
-						}						break;
-				case 't':	if ( sscanf( optarg+1, "%lg", &Options.integration_dt_min) != 1 ) {
-							fprintf( stderr, "-tt takes a double");
-							return CNRUN_CLPARSE_ERROR;
-						}						break;
-				case 'x':	if ( sscanf( optarg+1, "%lg", &Options.integration_dt_max_cap) != 1 ) {
-							fprintf( stderr, "-tx takes a double");
-							return CNRUN_CLPARSE_ERROR;
-						}						break;
-				default:	fprintf( stderr, "Unrecognised option modifier for -i");
-							return CNRUN_CLPARSE_ERROR;
-				}								break;
-
-		case 'L':	if ( strchr( optarg, 'd') != nullptr )
-					Options.listen_deferwrite = true;
-				if ( strchr( optarg, '1') != nullptr )
-					Options.listen_1varonly = true;
-				if ( strchr( optarg, 'b') != nullptr )
-					Options.listen_binary = true;
-				if ( strchr( optarg, 'L') != nullptr )
-					Options.log_dt = true;				break;
-
-		case 'E':	if ( sscanf( optarg, "%g", &Options.listen_dt) != 1 ) {
-					fprintf( stderr, "-E takes a double");
-					return CNRUN_CLPARSE_ERROR;
-				}						break;
-		case 'g':	if ( sscanf( optarg, "%u", &Options.precision) != 1 ) {
-					fprintf( stderr, "-g takes a short unsigned int");
-					return CNRUN_CLPARSE_ERROR;
-				}						break;
-
-		case 'n':	if ( optarg && *optarg == 'c' )
-					Options.dont_coalesce = true;		break;
-
-		case 'k':	Options.log_spikers = true;
-				switch ( *optarg ) {
-				case '0':	Options.log_spikers_use_serial_id = true;	break;
-				case 'l':	Options.log_spikers_use_serial_id = false;	break;
-				case 'S':	if ( sscanf( optarg+1, "%g", &Options.spike_threshold) != 1 ) {
-							fprintf( stderr, "-kS takes a double");
-							return CNRUN_CLPARSE_ERROR;
-						}
-				default:	fprintf( stderr, "Expecting 0, l, or S<double> after -k");
-						return CNRUN_CLPARSE_ERROR;
-				}						break;
-
-		case 'U':	Options.list_units = true;			break;
-
-
-		case 's':	Options.sort_units = true;			break;
-
-
-		case 'C':	Options.working_dir = optarg;			break;
-
-		case 'D':	{
-					double	unused;
-					CExpression expr;
-					if ( expr( optarg, unused, &Variables) ) {
-						fprintf( stderr, "Malformed variable assignment with -D");
-						return CNRUN_CLPARSE_ERROR;
-					}
-				}
-
-		case 'v':	Options.verbosely = strtol( optarg, nullptr, 10);
-				{	char *p;
-					if ( (p = strchr( optarg, '%')) )
-						Options.display_progress_percent = (*(p+1) != '-');
-					if ( (p = strchr( optarg, 't')) )
-						Options.display_progress_time    = (*(p+1) != '-');
-				}
-										break;
-		case 'h':
-			return CNRUN_CLPARSE_HELP_REQUEST;
-		case '?':
-		default:
-			return CNRUN_CLPARSE_ERROR;
-		}
-
-	return 0;
+        char *pwd = nullptr;
+        if ( Q.working_dir ) {
+                pwd = getcwd( nullptr, 0);
+                if ( chdir( Q.working_dir.c_str()) ) {
+                        fprintf( stderr, "Failed to cd to \"%s\"", Q.working_dir.c_str());
+                        return -1;
+                }
+        }
+
+        __cn_verbosely = Q.verbosely;
+        __cn_default_unit_precision = Q.precision;
+
+        for ( const auto& F : Options.scripts )
+                interpreter_run(
+                        F, 0, Options,
+                        true, true);
+
+        if ( pwd )
+                if ( chdir( pwd) )
+                        fprintf( stderr, "Failed to cd back to \"%s\"", pwd);
+
+        return 0;
 }
 
 
 
 
-void
-usage( const char *argv0)
-{
-	cout << "Usage: " << argv0 << "\n" <<
-		" -e <script_fname>\tExecute script\n"
-		" -D \t\t\tDump all unit types in the model and exit\n"
-		" -C <dir>\t\tWork in dir\n"
-		" -s \t\t\tSort units\n"
-		"\n"
-		" -L[d1Lx] \t\tLogging & listeners:\n"
-		"    d \t\t\tdefer writing to disk until done rather than writing continuously\n"
-		"    1\t\t\tonly log the first variable\n"
-		"    x\t\t\twrite in native binary form rather than in ASCII\n"
-		"    L\t\t\tlog integrator dt\n"
-		" -E<double>\t\tListen at this interval (default " << Options.listen_dt << ";\n"
-		"\t\t\t   set to 0 to listen every cycle)\n"
-		"\n"
-		" -kl \t\t\tWrite a model-wide log of spiking neurons, using labels\n"
-		" -k0 \t\t\t... use unit id instead\n"
-		" -kS<double>\t\tSpike detection threshold (default " << Options.spike_threshold << ")\n"
-		"\n"
-		" -e <uint>\t\tSet precision for all output (default " << Options.precision << ")\n"
-		"\n"
-		" -tT <double>\t\tdt_max (default " << Options.integration_dt_max << ")\n"
-		" -tt <double>\t\tdt_min (default " << Options.integration_dt_min << ")\n"
-		" -tx <double>\t\tCap dt by current dt value x this (default " << Options.integration_dt_max_cap << ")\n"
-		"\n"
-		" -D EXPR\t\tAny valid expression, will inject whatever variables get assigned in it\n"
-		"\n"
-		" -v <int>\t\tSet verbosity level (default " << Options.verbosely << ")\n"
-		"\t\t\t Use a negative value to show the progress percentage only,\n"
-		" -v[%[-]t[-]]\t\tDisplay (with -, suppress) progress percent and/or time\n"
-		"\t\t\t indented on the line at 8 x (minus) this value.\n"
-		"\n"
-		" -U \t\t\tList available unit types with parameter names\n"
-		"\t\t\t  and values, and exit\n"
-		" -h \t\t\tDisplay this help\n"
-		"\n";
-}
-} // namespace
-
-
-// EOF
+// namespace {
+// void
+// usage( const char *argv0)
+// {
+// 	cout << "Usage: " << argv0 << "\n" <<
+// 		" -e <script_fname>\tExecute script\n"
+// 		" -D \t\t\tDump all unit types in the model and exit\n"
+// 		" -C <dir>\t\tWork in dir\n"
+// 		" -s \t\t\tSort units\n"
+// 		"\n"
+// 		" -L[d1Lx] \t\tLogging & listeners:\n"
+// 		"    d \t\t\tdefer writing to disk until done rather than writing continuously\n"
+// 		"    1\t\t\tonly log the first variable\n"
+// 		"    x\t\t\twrite in native binary form rather than in ASCII\n"
+// 		"    L\t\t\tlog integrator dt\n"
+// 		" -E<double>\t\tListen at this interval (default " << Options.listen_dt << ";\n"
+// 		"\t\t\t   set to 0 to listen every cycle)\n"
+// 		"\n"
+// 		" -kl \t\t\tWrite a model-wide log of spiking neurons, using labels\n"
+// 		" -k0 \t\t\t... use unit id instead\n"
+// 		" -kS<double>\t\tSpike detection threshold (default " << Options.spike_threshold << ")\n"
+// 		"\n"
+// 		" -e <uint>\t\tSet precision for all output (default " << Options.precision << ")\n"
+// 		"\n"
+// 		" -tT <double>\t\tdt_max (default " << Options.integration_dt_max << ")\n"
+// 		" -tt <double>\t\tdt_min (default " << Options.integration_dt_min << ")\n"
+// 		" -tx <double>\t\tCap dt by current dt value x this (default " << Options.integration_dt_max_cap << ")\n"
+// 		"\n"
+// 		" -D EXPR\t\tAny valid expression, will inject whatever variables get assigned in it\n"
+// 		"\n"
+// 		" -v <int>\t\tSet verbosity level (default " << Options.verbosely << ")\n"
+// 		"\t\t\t Use a negative value to show the progress percentage only,\n"
+// 		" -v[%[-]t[-]]\t\tDisplay (with -, suppress) progress percent and/or time\n"
+// 		"\t\t\t indented on the line at 8 x (minus) this value.\n"
+// 		"\n"
+// 		" -U \t\t\tList available unit types with parameter names\n"
+// 		"\t\t\t  and values, and exit\n"
+// 		" -h \t\t\tDisplay this help\n"
+// 		"\n";
+// }
+// } // namespace
+
+
+
+
+// Local Variables:
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/upstream/src/cnrun/runner.hh b/upstream/src/cnrun/runner.hh
index a98488b..123d8d3 100644
--- a/upstream/src/cnrun/runner.hh
+++ b/upstream/src/cnrun/runner.hh
@@ -1,19 +1,19 @@
 /*
- * Author: Andrei Zavada <johnhommer at gmail.com>
+ *       File name:  cnrun/runner.hh
+ *         Project:  cnrun
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2008-11-04
  *
- * License: GPL-2+
+ *         Purpose:  interpreter
  *
- * Initial version: 2008-11-04
- *
- * CNModel runner
+ *         License:  GPL
  */
 
-#ifndef CN_RUNNER_H
-#define CN_RUNNER_H
+#ifndef CN_CNRUN_RUNNER_H_
+#define CN_CNRUN_RUNNER_H_
 
-#include <vector>
 #include <list>
-#include <iostream>
+#include <string>
 
 #include "libstilton/exprparser.hh"
 
@@ -26,120 +26,97 @@
 
 namespace cnrun {
 
-enum {
-	CN_INTRP_STRICT,
-	CN_INTRP_LOOSE
+struct SInitOptions
+  : public cnrun::SModelOptions {
+        bool    dump_params:1,
+                list_units:1;
+        string  working_dir;
+
+        list<string>
+                scripts;
+
+        SInitOptions ()
+              : dump_params(false), list_units (false)
+                working_dir (".")
+                {}
 };
 
-struct SCNRunnerOptions {
-	bool	listen_1varonly:1,
-		listen_deferwrite:1,
-		listen_binary:1,
-		dump_params:1,
-		list_units:1,
-		sort_units:1,
-		log_dt:1,
-		log_spikers:1,
-		log_spikers_use_serial_id:1,
-		log_sdf:1,
-		display_progress_percent:1,
-		display_progress_time:1,
-		dont_coalesce:1;
-	const char *working_dir;
-	unsigned precision;
-	float	spike_threshold,
-		spike_lapse,
-		listen_dt;
-	double	//discrete_dt,
-		integration_dt_max,
-		integration_dt_min,
-		integration_dt_max_cap;
-	float	sxf_start_delay,
-		sxf_sample,
-		sdf_sigma;
-	int	interp_howstrict,
-		verbosely;
-
-	SCNRunnerOptions()
-	      : listen_1varonly (true), listen_deferwrite (false), listen_binary (false),
-		dump_params(false), list_units (false),
-		sort_units (false),
-		log_dt (false),
-		log_spikers (false), log_spikers_use_serial_id (false),
-		log_sdf (false),
-		display_progress_percent (true),
-		display_progress_time (false),
-		dont_coalesce (false),
-		working_dir ("."),
-		precision (8),
-		spike_threshold (0.), spike_lapse (3.),
-		listen_dt(1.),
-		//discrete_dt(.5),
-		integration_dt_max (.5), integration_dt_min (1e-5), integration_dt_max_cap (5.),
-		sxf_start_delay (0.), sxf_sample (0.), sdf_sigma (0.),
-		interp_howstrict (CN_INTRP_LOOSE),
-		verbosely (1)
-		{}
+
+enum class TInterpStrictness {
+        strict,
+        loose
 };
 
-#define CNRUN_DEFAULT_SCRIPT "./Default.cnsh"
-
-extern SCNRunnerOptions Options;
-
-
-
-extern CModel *Model;
-
-int interpreter_run( const char *script_fname, int level, int howstrict,
-		     bool env_import, bool env_export, list<cnrun::SVariable> &varlist);
-
-
-enum {
-	CNCMD__noop = -1,
-	CNCMD_new_model = 0,
-	CNCMD_load_nml,
-	CNCMD_merge_nml,
-	CNCMD_add_neuron,
-	CNCMD_add_synapse,
-	CNCMD_reset,
-	CNCMD_reset_revert_params,
-	CNCMD_reset_state_units,
-	CNCMD_advance_until,
-	CNCMD_advance,
-	CNCMD_putout,
-	CNCMD_decimate,
-	CNCMD_start_listen,
-	CNCMD_stop_listen,
-	CNCMD_listen_dt,
-	CNCMD_listen_mode,
-	CNCMD_integration_dt_min,
-	CNCMD_integration_dt_max,
-	CNCMD_integration_dt_cap,
-	CNCMD_start_log_spikes,
-	CNCMD_stop_log_spikes,
-	CNCMD_set_sxf_params,
-	CNCMD_new_source,
-	CNCMD_show_sources,
-	CNCMD_connect_source,
-	CNCMD_disconnect_source,
-	CNCMD_set_parm_neuron,
-	CNCMD_set_parm_synapse,
-	CNCMD_cull_deaf_synapses,
-	CNCMD_describe_model,
-	CNCMD_show_units,
-	CNCMD_exec,
-	CNCMD_verbosity,
-	CNCMD_show_vars,
-	CNCMD_clear_vars,
-	CNCMD_pause,
-	CNCMD_exit
+class CInterpreter : public SOptions {
+        CModel* model;
+
+    public:
+        CState ()
+              : CModel (nullptr)
+                {}
+       ~CState ()
+                {
+                        if ( model )
+                                delete model;
+                }
+
+    private:
+        bool    regenerate_unit_labels,
+                regenerate_var_names,
+                regenerate_source_ids;
 };
 
+
+
+
 extern const char* const cnrun_cmd[];
 
-extern bool regenerate_unit_labels;
-extern bool regenerate_var_names;
-extern bool regenerate_source_ids;
+int interpreter_run( const char *script_fname, const SOptions&,
+                     bool env_import, bool env_export);
+
+
+enum class TInterpCommand {
+        noop,
+        new_model,
+        load_nml,
+        merge_nml,
+        add_neuron,
+        add_synapse,
+        reset,
+        reset_revert_params,
+        reset_state_units,
+        advance_until,
+        advance,
+        putout,
+        decimate,
+        start_listen,
+        stop_listen,
+        listen_dt,
+        listen_mode,
+        integration_dt_min,
+        integration_dt_max,
+        integration_dt_cap,
+        start_log_spikes,
+        stop_log_spikes,
+        set_sxf_params,
+        new_source,
+        show_sources,
+        connect_source,
+        disconnect_source,
+        set_parm_neuron,
+        set_parm_synapse,
+        cull_deaf_synapses,
+        describe_model,
+        show_units,
+        exec,
+        verbosity,
+        show_vars,
+        clear_vars,
+        pause,
+        exit
+};
+
+
 
 char** cnrun_completion( const char *text, int start, int end);
 
diff --git a/upstream/src/libcn/base-unit.cc b/upstream/src/libcn/base-unit.cc
index 56ec66d..92bdf36 100644
--- a/upstream/src/libcn/base-unit.cc
+++ b/upstream/src/libcn/base-unit.cc
@@ -29,16 +29,6 @@ using namespace std;
 
 
 
-double cnrun::__cn_dummy_double;
-
-unsigned short cnrun::__cn_default_unit_precision = 8;
-
-int cnrun::__cn_verbosely = 2;
-
-
-
-// mind that child
-
 cnrun::C_BaseUnit::
 C_BaseUnit( TUnitType intype, const char *inlabel,
 	    CModel* inM, int s_mask)
diff --git a/upstream/src/libcn/model.hh b/upstream/src/libcn/model.hh
index 2dd17a8..a1b2926 100644
--- a/upstream/src/libcn/model.hh
+++ b/upstream/src/libcn/model.hh
@@ -20,8 +20,8 @@ parameters.
 --------------------------------------------------------------------------*/
 
 
-#ifndef LIBCN_MODEL_H
-#define LIBCN_MODEL_H
+#ifndef CN_LIBCN_MODEL_H_
+#define CN_LIBCN_MODEL_H_
 
 #include <csignal>
 #include <list>
@@ -49,29 +49,66 @@ parameters.
 using namespace std;
 namespace cnrun {
 
-// CModel _status bits
-#define CN_MDL_LOGDT		(1 << 0)
-#define CN_MDL_LOGSPIKERS	(1 << 1)
-#define CN_MDL_LOGUSINGID	(1 << 2)
-#define CN_MDL_SORTUNITS	(1 << 3)
-#define CN_MDL_ALLOWNOISE	(1 << 4)
-#define CN_MDL_NOTREADY		(1 << 5)
-#define CN_MDL_DISKLESS		(1 << 6)
-#define CN_MDL_HAS_DDTB_UNITS	(1 << 7)
-#define CN_MDL_DISPLAY_PROGRESS_PERCENT	(1 << 8)
-#define CN_MDL_DISPLAY_PROGRESS_TIME	(1 << 9)
-#define CN_MDL_DONT_COALESCE		(1 << 10)
+
+struct SModelOptions {
+        bool    listen_1varonly:1,
+                listen_deferwrite:1,
+                listen_binary:1,
+                sort_units:1,
+                log_dt:1,
+                log_spikers:1,
+                log_spikers_use_serial_id:1,
+                log_sdf:1,
+                display_progress_percent:1,
+                display_progress_time:1;
+        int     precision;
+        float   spike_threshold,
+                spike_lapse,
+                listen_dt;
+        double  //discrete_dt,
+                integration_dt_max,
+                integration_dt_min,
+                integration_dt_max_cap;
+        float   sxf_start_delay,
+                sxf_sample,
+                sdf_sigma;
+        int     verbosely;
+
+        list<SVariable>
+                variables;
+
+        SOptions ()
+              : listen_1varonly (true), listen_deferwrite (false), listen_binary (false),
+                sort_units (true),
+                log_dt (false),
+                log_spikers (false), log_spikers_use_serial_id (false),
+                log_sdf (false),
+                display_progress_percent (true),
+                display_progress_time (false),
+                dont_coalesce (false),
+                precision (8),
+                spike_threshold (0.), spike_lapse (3.),
+                listen_dt(1.),
+                //discrete_dt(.5),
+                integration_dt_max (.5), integration_dt_min (1e-5), integration_dt_max_cap (5.),
+                sxf_start_delay (0.), sxf_sample (0.), sdf_sigma (0.),
+                verbosely (1)
+                {}
+};
 
 
 class CModel {
 
     public:
-	string	name;
+        string	name;
 
     private:
-	int	_status;
+        int	_status;
     public:
-	int status()	{ return _status; }
+        int status() const
+                {
+                        return _status;
+                }
 
       // structure ------
     friend class C_BaseSynapse;
@@ -708,4 +745,8 @@ CSynapseMxMap::preadvance()
 
 #endif
 
-// EOF
+// Local Variables:
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/cnrun.git



More information about the debian-med-commit mailing list