public IVector[] GetObservedLocalization(IObservationDescriptions observationDescriptions, double distance)
        {
            /* Return identity localization */
            // Console.Out.WriteLine("Return identity localization");
            int     nObs   = observationDescriptions.ObservationCount;
            IVector locvec = new VectorJ2N(state.Size);

            IVector[] result = new IVector[nObs];

            for (int iObs = 0; iObs < nObs; iObs++)
            {
                locvec.SetConstant(1.0);
                result[iObs] = locvec;
            }
            return(result);
        }
        /**
         * Compute time derivative of state at current time.
         * This is used by the time-integration "mod.compute(t)" as the core of the model.
         * @return vector dt
         */

        protected override IVector Dx(IVector xt, double t)
        {
            IVector result = new VectorJ2N(2);

            // The oscillator model
            //
            // simple linear oscilator (e.g. mass-spring system with friction)
            //% d(x)/d(t) = u
            // d(u)/d(t) = - omega^2 * x - (2/t_damp) u
            //
            double[] x     = xt.Values;
            double   omega = Math.Max(0.0, parameterValues[omegaId]);
            double   tDamp = Math.Max(0.0, parameterValues[tDampId]);

            result.SetValue(0, x[1]);
            result.SetValue(1, -(omega * omega) * x[0] - (2.0 / tDamp * x[1]));

            return(result);
        }
        public IModelState LoadPersistentState(string persistentStateFile)
        {
            VectorJ2N x;
            double    persistentTimeStamp;
            int       timestep;

            try
            {
                if (!File.Exists(persistentStateFile))
                {
                    throw new Exception("Could not find file for saved state:" + persistentStateFile);
                }
                // read state and time from file
                StreamReader buff = new StreamReader(persistentStateFile);
                // Read and parse first line
                string   line         = buff.ReadLine();
                string[] keyValuePair = line.Split(new[] { '=' });               // expect eg x=[1.0,2.0,3.0]
                x = new VectorJ2N(keyValuePair[1]);
                // Read and parse second line
                line                = buff.ReadLine();
                keyValuePair        = line.Split(new[] { '=' });        // expect eg t=1.0
                persistentTimeStamp = Double.Parse(keyValuePair[1]);
                // Read and parse third line
                line         = buff.ReadLine();
                keyValuePair = line.Split(new[] { '=' });               // expect eg timestep=3
                timestep     = Int32.Parse(keyValuePair[1]);
                buff.Close();
            }
            catch (IOException e)
            {
                ResultsJ2N.PutMessage("Exception: " + e.Message);
                throw new Exception("Error reading restart file for model");
            }
            // set state and time
            SavedState saveState = new SavedState();

            saveState.time     = persistentTimeStamp;
            saveState.timestep = timestep;
            saveState.state    = x;
            return(saveState);
        }
        //
        //Most data structures are contained in AbstractModelInstance
        //The abstract SimpleModel is based on the following items. Make
        //sure you put your data in the proper items
        //
        //-	parameters of the model that can be used as control variables with their statistics
        //		java.util.Hashtable<String,Double> parameters=null;
        //-	Internal state of the model
        //		Vector state=null;
        //-	Current time
        //		double t;
        //		int timeStep; //integer value is used for testing equality and counting
        //-	Parameters used for calibration
        //		java.util.Vector<String> ParNames=null;
        //		Vector Pars=null; //present values as a vector
        //-	System noise for Kalman filtering, as standarddeviation per unit time
        //		Vector sysNoiseIntensity=null;
        //

        public SimpleOscillatorModelInstance(string workingDir, string configString)
        {
            //
            //  DEFAULTS
            //

            // parameters of the model (deterministic part)
            parameterValues.Add(tDampId, 8.0);                  //characteristic time-scale for friction [seconds]
            parameterValues.Add("omega", 0.25 * 2.0 * Math.PI); //oscilation frequency [rad/s]
            // timespan for the simulation
            AddOrSetParameter(StartTimeId, 0.0);
            AddOrSetParameter(StopTimeId, 10.0);
            AddOrSetParameter(TimeStepId, 0.05);

            // Internal state of the model
            state = new VectorJ2N("[0.8,0.0]");

            //
            // now parse configuration
            //
            Initialize(workingDir, configString);
        }
        public IVector GetObservedValues(IObservationDescriptions descr)
        {
            IVector result = new VectorJ2N(descr.ObservationCount);

            // TODO: handle TimeSeriesObservationDescriptions
            IVector obsTimes = descr.GetValueProperties("time");

            IVector obsIndex = descr.GetValueProperties("index") ?? descr.GetValueProperties("xPosition");

            IVector transformIndex;

            try
            {
                transformIndex = descr.GetValueProperties("transform");
            }
            catch (Exception)
            {
                transformIndex = null;
            }

            Time tHor = new Time(parameterValues[StartTimeId],
                                 parameterValues[StopTimeId])
            ;

            tHor.StepMJD = parameterValues[TimeStepId];

            if (storeObs)
            {
                //work from stored states
                for (int i = 0; i < descr.ObservationCount; i++)
                {
                    // at which timestep is this obs
                    long iObs = Utils.GetTimeStep(tHor, (new Time(obsTimes.GetValue(i))));
                    // find corresponding storage location
                    int thisTIndex = iStore.IndexOf((int)iObs);                      //time index in storage
                    if (thisTIndex < 0)
                    {
                        throw (new Exception("model.getValues: time out of range for observation nr. " + i));
                    }
                    int thisXIndex = (int)obsIndex.GetValue(i);
                    if ((thisXIndex < 0) | (thisXIndex >= state.Size))
                    {
                        throw (new Exception("model.getValues: index out of range for "
                                             + " observation nr. " + i
                                             + " index= " + thisXIndex));
                    }
                    //Console.Out.WriteLine("i="+i+" it="+thisTIndex+" ind= "+thisXIndex);
                    double thisValue = xStore[thisTIndex].GetValue(thisXIndex);
                    // transform values if needed
                    if (transformIndex != null)
                    {
                        if (transformIndex.GetValue(i) == 2)
                        {
                            // magic number for quadratic observations
                            thisValue = thisValue * thisValue;
                        }
                    }
                    result.SetValue(i, thisValue);
                }
            }
            else
            {
                // only current state is available
                for (int i = 0; i < descr.ObservationCount; i++)
                {
                    int thisXIndex = (int)obsIndex.GetValue(i);
                    //TODO if(){ //check time
                    double thisValue = state.GetValue(thisXIndex);
                    // transform values if needed
                    if (transformIndex != null)
                    {
                        if (transformIndex.GetValue(i) == 2)
                        {
                            // magic number for quadratic observations
                            thisValue = thisValue * thisValue;
                        }
                    }
                    result.SetValue(i, thisValue);
                }
            }

            return(result);
        }
        public void Initialize(string workingDir, string configstring)
        {
            //
            //  GENERIC PART
            //

            // Instance counter
            thisInstanceNumber = nextinstanceNumber;
            nextinstanceNumber++;

            //now parse configuration
            //
            // <?xml version="1.0" encoding="UTF-8"?>
            // <oscillatorConfig>
            //<simulationTimespan>[0.0,0.05,10.0]</simulationTimespan>
            //<parameters names="t_damp,omega">[8.0,1.5708]</parameters>
            //<parameterUncertainty names="t_damp,omega">[1.0,0.1257]</parameterUncertainty>
            //<systemNoise>{[0.0,0.0],[0.3,0.3]}</systemNoise>
            //<initialState>[0.8,0.0]</initialState>
            //<initialStateUncertainty>[0.8,0.8]</initialStateUncertainty>
            //</oscillatorConfig>
            //
            ResultsJ2N.PutMessage("configstring = " + configstring);
            conf = new ConfigTreeJ2N(workingDir, configstring);

            //
            // parse simulationTimespan
            //
            // <simulationTimespan>[0.0,0.05,10.0]</simulationTimespan>
            string timespanstring = conf.GetContentstring("simulationTimespan");

            if (timespanstring != null)
            {
                IVector timespanVector = new VectorJ2N(timespanstring);
                AddOrSetParameter(StartTimeId, timespanVector.GetValue(0));
                AddOrSetParameter(TimeStepId, timespanVector.GetValue(1));
                AddOrSetParameter(StopTimeId, timespanVector.GetValue(2));
                ResultsJ2N.PutMessage("simulationTimespan =" + timespanVector);
            }
            // start at initial time
            t        = parameterValues[StartTimeId];
            timeStep = 0;             //counter starts at 0

            //
            // parse parameters
            //
            string namestring = conf.GetAsstring("parameters@names", "");
            string parstring  = conf.GetContentstring("parameters");

            if (parstring != null)
            {
                IVector parValues = new VectorJ2N(parstring);
                ResultsJ2N.PutMessage("parameters@names =" + namestring + " parameters=" + parValues);
                string[] names = namestring.Split(new[] { ',' });
                for (int i = 0; i < names.Length; i++)
                {
                    if (!parameterValues.ContainsKey(names[i]))
                    {
                        parameterValues.Add(names[i], parValues.GetValue(i));
                    }
                    else
                    {
                        ResultsJ2N.PutMessage("parameter " + names[i] + " was not recognized. Value was ignored.");
                    }
                }
            }

            CreateExchangeItems();
            AddExchangeItemsAfterInitialisation();
        }