}     // SetBoidArray()

    public void DetermineParamValue(string name, out float paramValue)
    {
        // check if deltaTime is more than SceneDuration of  the action plan => reset SceneStartTime to
        // the current time.

        if (m_SimulationDeltaT >= m_AnimationCycle)
        {
            m_SceneStartTime = m_currTime; // m_currTime is set in Update()
                                           // m_SimulationDeltaT = 0f; // wrap to the beginning of actionPlan to repeat the scene
        }
        // ref float paramValue has a value before the function was alled


        m_SimulationDeltaT = m_currTime - m_SceneStartTime; //  the delta time since the beginning of the
                                                            // current animation cycle
                                                            //Debug.Log("DeltaT=");
                                                            //Debug.Log(deltaT);

        List <ActionPlanController.Action> timedActions = m_actionPlan[name];


        ActionPlanController.TimeInterval timedActionBinaryTree
            = m_actionPlanController.m_actionPlanWithBinaryTree[name];

        // find the interval in the timedActions to which deltaTime belongs
        // for (int j = 0; j < timedActions.Count; j++) // actionPlan is a piecewise linear function of each parameter
        // {

        // m_SimulationDeltaT satisfies one of the following conditions always
        // The first "action" for the current parameter, timedActions[0], has
        // the first interval ( T[0], T[1]). If the delta is less than the midpoint of the interval
        // the midpoint value of the interval, timedActions[0].V, is used.
        if (m_SimulationDeltaT < (timedActions[0].T[0] + timedActions[0].T[1]) / 2)
        {
            paramValue = timedActions[0].V;
            return;
        } // first interval

        // The last "action" for the current parameter, timedActions[0], has
        // the interval ( T[0], T[1]). If the delta is greater than the midpoint of the
        // last interval, the midpoint value of the interval,
        //  timedActions[timedActions.Count - 1].V, is used.

        else if (m_SimulationDeltaT >= (timedActions[timedActions.Count - 1].T[0] + timedActions[timedActions.Count - 1].T[1]) / 2)
        { // the ith action is found for the current parameter
            paramValue = timedActions[timedActions.Count - 1].V;
            return;
        } // last interval

        // Otherwise, the value of the current parameter is interpolated between the midpoint
        // value of the previous interval and the midpoint value of the current interval
        else
        { // m_SimulationDeltaT is between timedActions[k - 1].T[1] and timedActions[k].T[0]
          // for some k.

            // int k = findCurrentActionIndex(timedActions, m_SimulationDeltaT);
            int k = m_actionPlanController.searchForActionIndex(timedActionBinaryTree, m_SimulationDeltaT);

            //int actionIndex
            //              = m_actionPlanController.searchForActionIndex(timedActionBinaryTree, m_SimulationDeltaT);

            //if ( actionIndex == -1 )
            //    {
            //    Debug.LogError(" No action index has been found for the current time");

            //    #if UNITY_EDITOR
            //    // Application.Quit() does not work in the editor so
            //    UnityEditor.EditorApplication.isPlaying = false;
            //    #else
            //       Application.Quit();
            //   #endif

            //   }
            //if ( k != actionIndex)
            //     {
            //      Debug.LogError(" Binary Search does not work");
            //    m_writer.WriteLine("Binary Search does not work");
            //     #if UNITY_EDITOR
            //       // Application.Quit() does not work in the editor so
            //       UnityEditor.EditorApplication.isPlaying = false;
            //        #else
            //       Application.Quit();
            //       #endif

            //     }

            if (k == -1)
            {
                Debug.LogError(" Some time intervals of the action plan table are specified incorrectly. " +
                               "please corrent them first");

                m_writer.WriteLine(" Some time intervals of the action plan table are specified incorrectly. " +
                                   "please corrent them first");
                paramValue = -1; // undefined out paramValue

#if UNITY_EDITOR
                // Application.Quit() does not work in the editor so
                UnityEditor.EditorApplication.isPlaying = false;
#else
                Application.Quit();
#endif
            }
            else
            {
                float firstTimePoint  = (timedActions[k - 1].T[0] + timedActions[k - 1].T[1]) / 2;
                float secondTimePoint = (timedActions[k].T[0] + timedActions[k].T[1]) / 2;
                float t = (m_SimulationDeltaT - firstTimePoint) /
                          (secondTimePoint - firstTimePoint);

                paramValue = timedActions[k - 1].V * (1 - t) + timedActions[k].V * t;
                return;
            }
        } // else (intermediate intervals)
    }     // DetermineParaValue()