void ML_multi_Powell::powell(v_ratep_type& p,
                             mat_ratep_type& xi,
                             const double ftol,
                             int& iter,
                             double& fret,
                             ptr_eval_func func
                             )
{
    const int ITMAX = 200;
    const double TINY = 1.0e-25;
    int i, j, ibig;
    double del, fp, fptt, t;

    int n = p.size();
    v_ratep_type pt(n), ptt(n), xit(n);
    fret = (this->*func)(p);
    for (j = 0; j < n; ++j) pt[j] = p[j];
    for (iter = 0; ; ++iter) {
        fp = fret;
        ibig = 0;
        del = 0.0;
        for (i = 0; i < n; ++i) {
            for (j = 0; j < n; ++j) xit[j] = xi[j][i];
            fptt = fret;
            linmin(p, xit, fret, func);
            if (fptt - fret > del) {
                del = fptt - fret;
                ibig = i + 1;
            }
        }
        if (2.0*(fp - fret) <= ftol*(std::abs(fp) + std::abs(fret)) + TINY) {
            return;
        }
        if (iter == ITMAX) {
            std::cerr << "powell(): exceeded max iterations " << ITMAX << std::endl;
            assert(false);
        }
        for (j = 0; j < n; ++j) {
            ptt[j] = 2.0*p[j] - pt[j];
            xit[j] = p[j] - pt[j];
            pt[j] = p[j];
        }
        fptt = (this->*func)(ptt);
        if (fptt < fp) {
            t = 2.0*(fp - 2.0*fret + fptt)*SQR(fp - fret - del) - del*SQR(fp - fptt);
            if (t < 0.0) {
                linmin(p, xit, fret, func);
                for (j = 0; j < n; ++j) {
                    xi[j][ibig-1] = xi[j][n-1];
                    xi[j][n-1] = xit[j];
                }
            }
        }
    }
}
void DevSetup::on_testPTTButton_clicked()
{
  m_test=1-m_test;
  if(m_pttMethodIndex==1 or m_pttMethodIndex==2) {
    ptt(m_pttPort,m_test,&g2_iptt,&g2_COMportOpen);
  }
  if(m_pttMethodIndex==0 and !m_bRigOpen) {
//    on_testCATButton_clicked();
    openRig();
  }
  if(m_pttMethodIndex==0 and m_bRigOpen) {
    if(m_test==0) rig->setPTT(RIG_PTT_OFF, RIG_VFO_CURR);
    if(m_test==1) {
      if(m_pttData) rig->setPTT(RIG_PTT_ON_DATA, RIG_VFO_CURR);
      if(!m_pttData) rig->setPTT(RIG_PTT_ON_MIC, RIG_VFO_CURR);
    }
  }
}
Beispiel #3
0
void
process_packet (char *buf)
{

  /* cut off ending \n */
  buf[strlen (buf) - 1] = '\0';

  /* parse the data into a struct */
  parse_fgdata (&data, buf);

  /* get the selected frequency */
  if (com_select == 0 && data.COM1_SRV == 1)
    selected_frequency = data.COM1_FRQ;
  else if (com_select == 1 && data.NAV1_SRV == 1)
    selected_frequency = data.NAV1_FRQ;
  else if (com_select == 2 && data.COM2_SRV == 1)
    selected_frequency = data.COM2_FRQ;
  else if (com_select == 3 && data.NAV2_SRV == 1)
    selected_frequency = data.NAV2_FRQ;

  /* Check for com frequency changes */
  if (previous_com_frequency != selected_frequency)
    {
      printf ("Selected frequency: %3.3f\n", selected_frequency);

      /* remark the new frequency */
      previous_com_frequency = selected_frequency;

      if (connected == 1)
	{
	  /* hangup call, if connected */
	  iaxc_dump_call ();
	  iaxc_millisleep (5 * DEFAULT_MILLISLEEP);
	  connected = 0;
	}

      strcpy (icao,
	      icaobypos (airportlist, selected_frequency, data.LAT,
			 data.LON, DEFAULT_RANGE));
      icao2number (icao, selected_frequency, tmp);
#ifdef DEBUG
      printf ("DEBUG: dialing %s %3.3f MHz: %s\n", icao, selected_frequency, tmp);
#endif
      do_iaxc_call (username, password, voipserver, tmp);
      /* iaxc_select_call (0); */

      connected = 1;
    }
  /* Check for pressed PTT key */
  if (previous_ptt != data.PTT)
    {
      if (data.PTT == 2)
	{
	  /* select the next com equipment */
	  com_select = (com_select + 1) % 4;
	  printf ("Radio-Select: %s\n", radio_map[com_select]);
	}
      else if (connected == 1)
	{
	  ptt (data.PTT);
	}
      previous_ptt = data.PTT;
    }
}