示例#1
0
void LUforw ( ptrdiff_t first, ptrdiff_t last, ptrdiff_t n, ptrdiff_t nu, ptrdiff_t maxmod,
              double eps, double *L, double *U, double *y )
{

/* ------------------------------------------------------------------
   LUforw updates the factors LC = U by performing a forward sweep
   to eliminate subdiagonals in a row spike in row 'last' of U.

   L     is n by n.
   U     is n by nu.
   y[*]  contains the row spike.  The first nonzero to be eliminated
         is in y[first] or later.
   The 'spike' row of L begins at L[ls].

   18 Mar 1990: First version with L and U stored row-wise.
   ------------------------------------------------------------------ */

  ptrdiff_t    lu, ll, ls, incu, ly, numu;
  double cs, sn;


  lu     = (first - 1)*maxmod + (3 - first)*first/2;
  ll     = (first - 1)*maxmod + 1;
  ls     = (last  - 1)*maxmod + 1;
  incu   = maxmod + 1 - first;

  for (ly = first; ly<last; ly++) {

/*   See if this element of y is worth eliminating.
     We compare y[ly] with the corresponding diagonal of U. */

     if ( fabs(y[ly]) > eps * fabs(U[lu]) ) {

/*   Generate a 2x2 elimination and apply it to U and L. */

        numu   = nu - ly;
        elmgen( &U[lu], &y[ly]  , eps    , &cs, &sn );
        if (numu > 0)
           elm ( 1, numu , &U[lu], &y[ly], cs, sn );
        elm ( 1, n, &L[subvec(ll)], &L[subvec(ls)], cs, sn );
     }

     ll    += maxmod;
     lu    += incu;
     incu--;
  }

/* Copy the remaining part of y into U. */

  numu     = nu - last + 1;
  if (numu > 0)
    LUdcopy ( numu, &y[subvec(last)], 1, &U[subvec(lu)], 1 );

/*   End of LUforw */
}
gMatrixSparse gMatrixSparse::eVect(int index, int length, bool transpose)
{
    vector<elm> vect;
    if (transpose) {
        vect.push_back(elm(0, index - 1, 1.0));
        return gMatrixSparse(1, length, vect);
    } else {
        vect.push_back(elm(index - 1, 0, 1.0));
        return gMatrixSparse(length, 1, vect);
    }
}
示例#3
0
wxString pgsRecord::value() const
{
	wxString data;
	pgsVarMap vars;

	// Go through each line and enclose it into braces
	for (USHORT i = 0; i < count_lines(); i++)
	{
		data += wxT("(");

		// Go through each column and separate them with commas
		for (USHORT j = 0; j < count_columns(); j++)
		{
			wxString elm(m_record[i][j]->eval(vars)->value());
			if (!m_record[i][j]->is_number())
			{
				elm.Replace(wxT("\\"), wxT("\\\\"));
				elm.Replace(wxT("\""), wxT("\\\""));
				elm = wxT("\"") + elm + wxT("\"");
			}
			data += elm + (j != count_columns() - 1 ? wxT(",") : wxT(""));
		}

		data += (i == count_lines() - 1) ? wxT(")") : wxT(")\n");
	}

	// Return the string representation of the record
	return data;
}
示例#4
0
文件: TestNewmark.C 项目: akva2/IFEM
  virtual bool assembleSystem(const TimeDomain& time,
                              const Vectors& prevSol,
                              bool newLHSmatrix, bool)
  {
    const double M = 10.0;   // Mass of the oscillator
    const double K = 1000.0; // Stiffness of the oscillator
    const double F = 1.0;    // External load (constant)

    myEqSys->initialize(newLHSmatrix);

    bool ok;
    if (myProblem->getMode() == SIM::MASS_ONLY) {
      ElmMats elm;
      elm.resize(1,1); elm.redim(1);
      elm.A[0].fill(M); // Mass Matrix
      ok = myEqSys->assemble(&elm,1);
    }
    else {
      const double* intPrm = static_cast<Problem*>(myProblem)->getIntPrm();
      NewmarkMats elm(intPrm[0],intPrm[1],intPrm[2],intPrm[3]);
      elm.resize(3,1); elm.redim(1); elm.vec.resize(3);
      elm.setStepSize(time.dt,0);
      elm.A[1].fill(M); // Mass matrix
      elm.A[2].fill(K); // Stiffness matrix
      elm.b[0] = -K*prevSol.front(); // Elastic forces
      for (int i = 0; i < 3; i++) elm.vec[i] = prevSol[i];
      ok = myEqSys->assemble(&elm,1);
    }

    // Add in the external load
    ok &= mySam->assembleSystem(*myEqSys->getVector(),&F,1);

    return ok && myEqSys->finalize(newLHSmatrix);
  }
gMatrixSparse gMatrixSparse::operator*(gMatrixSparse &right)
{
    assert(numCols == right.numRows);
    
    vector<elm> vect;
    
    gMatrixSparse trans = getTranspose();
    bool nempty[numRows];
    std::map<int, gMatrixSparse::gColumnSparse> rowMap;
    for (int i = 0; i < numRows; i++) {
        nempty[i] = !trans.colIsEmpty(i);
        if (nempty[i]) rowMap[i] = trans.getColumn(i);
    }
    
    for (int c = 0; c < right.numCols; c++) {
        if (right.colIsEmpty(c)) continue;
        gColumnSparse col = right.getColumn(c);
        for (int r = 0; r < numRows; r++) {
            if (nempty[r]) {
                double val = col.dot(rowMap[r]);
                vect.push_back(elm(r, c, val));
            }
        }
    }
    
    return gMatrixSparse(numRows, right.numCols, vect, true);
}
示例#6
0
文件: TestNewmark.C 项目: akva2/IFEM
  virtual bool assembleSystem(const TimeDomain& time,
                              const Vectors& prevSol,
                              bool newLHSmatrix, bool)
  {
    const double M = 1.0;    // Mass of the oscillator
    const double K = 1000.0; // Stiffness of the oscillator

    myEqSys->initialize(newLHSmatrix);

    bool ok;
    if (myProblem->getMode() == SIM::MASS_ONLY) {
      ElmMats elm;
      elm.resize(1,1); elm.redim(2);
      elm.A[0](1,1) = elm.A[0](2,2) = M; // Mass matrix
      ok = myEqSys->assemble(&elm,1);
    }
    else {
      const double* intPrm = static_cast<Problem*>(myProblem)->getIntPrm();
      NewmarkMats elm(intPrm[0],intPrm[1],intPrm[2],intPrm[3]);
      elm.resize(3,1); elm.redim(2); elm.vec.resize(3);
      elm.setStepSize(time.dt,0);
      elm.A[1](1,1) = elm.A[1](2,2) = M; // Mass Matrix
      elm.A[2](1,1) = elm.A[2](2,2) = K; // Stiffness matrix
      elm.A[2](2,1) = elm.A[2](1,2) = -K;
      elm.b[0] = elm.A[2]*prevSol.front(); // Elastic forces
      elm.b[0] *= -1.0;
      for (int i = 0; i < 3; i++) elm.vec[i] = prevSol[i];
      ok = myEqSys->assemble(&elm,1);
    }

    return ok && myEqSys->finalize(newLHSmatrix);
  }
示例#7
0
void rels_file::write(const std::wstring & RootPath)
{    
    std::wstringstream resStream;
    rels_.xml_to_stream(resStream);

    simple_element elm(filename_, resStream.str());
    elm.write(RootPath);
}
示例#8
0
// SXADDLQSI = SXAddl_SXCQsi_SXDId SXADDLDBQUERY *UNKNOWNFRT SXAddl_SXCQsi_SXDEnd
const bool SXADDLQSI::loadContent(BinProcessor& proc)
{
	bool result = false;
	int level = 0;
	
	while (true)
	{
		CFRecordType::TypeId type = proc.getNextRecordType();	

		if (type != rt_SXAddl) break;
	
		proc.optional<SXAddl>();

		SXAddl* addl = dynamic_cast<SXAddl*>(elements_.back().get());				
		if (!addl) continue;
		
		if (result && addl->bStartElement)
		{
			level++;
			_sxAddl elm(current, level); 

			current = &current->back().levels;
			
			current->push_back(elm);
			
			elements_.pop_back();
			continue;
		}
		
		result = true;
		
		if (addl->bEndElement)
		{ 
			elements_.pop_back();
			
			if (level == 0)
				break;
			else level--;

			current = current->back().prev;
			continue;
		}
		if (level == 0)
		{
			SXAddl_SXCQsi_SXDId* p0 = dynamic_cast<SXAddl_SXCQsi_SXDId*>(addl->content.get());
			if (p0)
			{
				m_SXAddl_SXCQsi_SXDId = addl->content;
			}
		}

		current->back().elements.push_back(elements_.back());
		elements_.pop_back();
	}

	current = NULL;
	return result;
}
示例#9
0
Handler<WidgetObject> WorldObject::findWidgetById(const std::string& widgetid)
{
	Handler<World> const world = this->world();
	Handler<WidgetElement> elm(world->findWidgetById(widgetid));
	if( !elm ) {
		return Handler<WidgetObject>();
	}
	return elm->widget()->donutObject();
}
示例#10
0
gMatrixSparse gMatrixSparse::getIdentity(int numRows, int numCols)
{
    vector<elm> vect;
    
    int d = min(numRows, numCols);
    for (int i = 0; i < d; i++)
        vect.push_back(elm(i, i, 1.0));
    
    return gMatrixSparse(numRows, numCols, vect);
}
示例#11
0
Handler<Element> TabCombo::removeChild(std::size_t const& idx)
{
	Handler<Element> elm(this->frame_->removeChild(idx));
	auto const it = this->buttonMap_.find(elm);
	Handler<TabButton> btn(it->second);
	this->buttonMap_.erase(it);
	this->buttons_->removeChild(btn);
	if(Handler<Element> front = this->frontChild()){ //もうボタンが残っていない場合、nullが帰ってくるので
		updateButtonState(front, Handler<TabButton>());
	}
	return elm;
}
示例#12
0
void core_file::write(const std::wstring & RootPath)
{
    std::wstringstream resStream;

    resStream << L"<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" "
    L"xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" "
    L"xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >";

	//resStream << L"<dc:creator>ONLYOFFICE</dc:creator>";
	//resStream << L"<cp:lastModifiedBy>ONLYOFFICE</cp:lastModifiedBy>";
	resStream << L"<cp:revision>1</cp:revision>";
    resStream << L"</cp:coreProperties>";

    simple_element elm(L"core.xml", resStream.str());
    elm.write(RootPath);
}
示例#13
0
void app_file::write(const std::wstring & RootPath)
{
    std::wstringstream resStream;

    resStream << L"<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" "
        L"xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\" >";
   
	resStream << L"<Application>";
	std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvApplicationName);
	if (sApplication.empty())
		sApplication = NSSystemUtils::gc_EnvApplicationNameDefault;
	resStream << sApplication;
#if defined(INTVER)
	std::string s = VALUE2STR(INTVER);
	resStream << L"/" << std::wstring(s.begin(), s.end()) ;
#endif	
	resStream << L"</Application></Properties>";
    
    simple_element elm(L"app.xml", resStream.str());
    elm.write(RootPath);
}
示例#14
0
//   computes the current 13 3-node circuits of s1-t1+neighbours
//   and s2-t2+neighbours. Puts results in sub-a 13*1 vector.
//   computes the future 13 3-node circuits of s1-t2 and neighbours
//   and s2-t1+neighbours. Puts results in add-a 13*1 vector.
//   Takes into account that double edges are switched
void fill_13_dbl(Network *N,int s1,int t1,int s2,int t2,int sub[14],int add[14])

{

   int sarr1[ARR_NUM];
   int tarr1[ARR_NUM];
   int sarr2[ARR_NUM];
   int tarr2[ARR_NUM];
   int sarr1_len,tarr1_len,sarr2_len,tarr2_len;
   register int i;
   int state_var;
   int index;
   int old_triple[ARR_NUM][4];
   int new_triple[ARR_NUM][4];
   int old_len=0;
   int new_len=0;
   int first,second,third;

   zero_neighbours(sarr1,&sarr1_len);
   zero_neighbours(tarr1,&tarr1_len);
   zero_neighbours(sarr2,&sarr2_len);
   zero_neighbours(tarr2,&tarr2_len);

   fill_neighbours(N,s1,t1,1,sarr1,&sarr1_len);
   fill_neighbours(N,t1,s1,0,tarr1,&tarr1_len);
   fill_neighbours(N,s2,t2,1,sarr2,&sarr2_len);
   fill_neighbours(N,t2,s2,0,tarr2,&tarr2_len);

   for (i=0;i<14;i++)
   {
		sub[i]=0;
		add[i]=0;
   }

   for (i=0;i<ARR_NUM;i++)
   {
		old_triple[i][0]=0;old_triple[i][1]=0;old_triple[i][2]=0;old_triple[i][3]=0;
		new_triple[i][0]=0;new_triple[i][1]=0;new_triple[i][2]=0;new_triple[i][3]=0;
   }
   old_len=0;
   new_len=0;

//	fprintf(GNRL_ST.mat_metrop_fp,"starting old set\n");

   /* update sub with the circuits of sarr1,s1,t1 */
   for (i=0;i<sarr1_len;i++)
   {
		refine(old_triple,&old_len,sarr1[i],s1,t1);
   }

   /* update sub with the circuits of s1,t1,tarr1 */
   for (i=0;i<tarr1_len;i++)
   {
		refine(old_triple,&old_len,s1,t1,tarr1[i]);
   }

	/* update sub with the circuits of sarr2,s2,t2 */
   for (i=0;i<sarr2_len;i++)
   {
		refine(old_triple,&old_len,sarr2[i],s2,t2);
   }


   /* update sub with the circuits of s2,t2,tarr2 */
   for (i=0;i<tarr2_len;i++)
   {
		refine(old_triple,&old_len,s2,t2,tarr2[i]);
   }


	/********* New bug fix - when a node connects to both s1 and t2 **********/
   /* update sub with the circuits of sarr1,s1,t2 */
   for (i=0;i<sarr1_len;i++)
   {
		refine(old_triple,&old_len,sarr1[i],s1,t2);
   }

   /* update sub with the circuits of s1,t2,tarr2 */
   for (i=0;i<tarr2_len;i++)
   {
		refine(old_triple,&old_len,s1,t2,tarr2[i]);
   }

	/* update sub with the circuits of sarr2,s2,t1 */
   for (i=0;i<sarr2_len;i++)
   {
		refine(old_triple,&old_len,sarr2[i],s2,t1);
   }


   /* update sub with the circuits of s2,t1,tarr1 */
   for (i=0;i<tarr1_len;i++)
   {
		refine(old_triple,&old_len,s2,t1,tarr1[i]);
   }



   for (i=0;i<old_len;i++)
   {
	   first=old_triple[i][1];
	   second=old_triple[i][2];
	   third=old_triple[i][3];
	   state_var=32*is_edge(N,first,second)+16*is_edge(N,second,third)+8*is_edge(N,third,first)
		+4*is_edge(N,second,first)+2*is_edge(N,third,second)+is_edge(N,first,third);
		index=elm(state_var);
		if ((index>0)&&(index<=13))
			sub[index]=sub[index]+1;
		state_var=32*is_edge2_dbl(N,first,second,s1,t1,s2,t2)+16*is_edge2_dbl(N,second,third,s1,t1,s2,t2)+8*is_edge2(N,third,first,s1,t1,s2,t2)
		+4*is_edge2_dbl(N,second,first,s1,t1,s2,t2)+2*is_edge2_dbl(N,third,second,s1,t1,s2,t2)+is_edge2_dbl(N,first,third,s1,t1,s2,t2);
		index=elm(state_var);
		if ((index>0)&&(index<=13))
			add[index]=add[index]+1;
   }

}
示例#15
0
		   void operator()( const element& e ) {
			   Element elm( e.symbol_, e.name_, e.atomicNumber_, e.valence_ );
			   for ( int i = 0; i < e.isotopeCount_; ++i )
				   elm.addIsotope( Element::Isotope( e.ma_[i].mass_, e.ma_[i].abund_ ) );
			   vec_.push_back( elm );
		   }
示例#16
0
 virtual void map(int row, int col, double valLeft, double valRight) {
     vect.push_back(elm(row, col, (valLeft + valRight) * .5));
 }
NS_IMETHODIMP
nsXMLDocument::Load(const nsAString& aUrl, bool *aReturn)
{
  bool hasHadScriptObject = true;
  nsIScriptGlobalObject* scriptObject =
    GetScriptHandlingObject(hasHadScriptObject);
  NS_ENSURE_STATE(scriptObject || !hasHadScriptObject);

  ReportUseOfDeprecatedMethod(this, "UseOfDOM3LoadMethodWarning");

  NS_ENSURE_ARG_POINTER(aReturn);
  *aReturn = false;

  nsCOMPtr<nsIDocument> callingDoc =
    do_QueryInterface(nsContentUtils::GetDocumentFromContext());

  nsIURI *baseURI = mDocumentURI;
  nsAutoCString charset;

  if (callingDoc) {
    baseURI = callingDoc->GetDocBaseURI();
    charset = callingDoc->GetDocumentCharacterSet();
  }

  // Create a new URI
  nsCOMPtr<nsIURI> uri;
  nsresult rv = NS_NewURI(getter_AddRefs(uri), aUrl, charset.get(), baseURI);
  if (NS_FAILED(rv)) {
    return rv;
  }

  // Check to see whether the current document is allowed to load this URI.
  // It's important to use the current document's principal for this check so
  // that we don't end up in a case where code with elevated privileges is
  // calling us and changing the principal of this document.

  // Enforce same-origin even for chrome loaders to avoid someone accidentally
  // using a document that content has a reference to and turn that into a
  // chrome document.
  nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
  if (!nsContentUtils::IsSystemPrincipal(principal)) {
    rv = principal->CheckMayLoad(uri, false, false);
    NS_ENSURE_SUCCESS(rv, rv);

    int16_t shouldLoad = nsIContentPolicy::ACCEPT;
    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
                                   uri,
                                   principal,
                                   callingDoc ? callingDoc.get() :
                                     static_cast<nsIDocument*>(this),
                                   NS_LITERAL_CSTRING("application/xml"),
                                   nullptr,
                                   &shouldLoad,
                                   nsContentUtils::GetContentPolicy(),
                                   nsContentUtils::GetSecurityManager());
    NS_ENSURE_SUCCESS(rv, rv);
    if (NS_CP_REJECTED(shouldLoad)) {
      return NS_ERROR_CONTENT_BLOCKED;
    }
  } else {
    // We're called from chrome, check to make sure the URI we're
    // about to load is also chrome.

    bool isChrome = false;
    if (NS_FAILED(uri->SchemeIs("chrome", &isChrome)) || !isChrome) {
      nsAutoCString spec;
      if (mDocumentURI)
        mDocumentURI->GetSpec(spec);

      nsAutoString error;
      error.AssignLiteral("Cross site loading using document.load is no "
                          "longer supported. Use XMLHttpRequest instead.");
      nsCOMPtr<nsIScriptError> errorObject =
          do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
      NS_ENSURE_SUCCESS(rv, rv);

      rv = errorObject->InitWithWindowID(error,
                                         NS_ConvertUTF8toUTF16(spec),
                                         EmptyString(),
                                         0, 0, nsIScriptError::warningFlag,
                                         "DOM",
                                         callingDoc ?
                                           callingDoc->InnerWindowID() :
                                           this->InnerWindowID());

      NS_ENSURE_SUCCESS(rv, rv);

      nsCOMPtr<nsIConsoleService> consoleService =
        do_GetService(NS_CONSOLESERVICE_CONTRACTID);
      if (consoleService) {
        consoleService->LogMessage(errorObject);
      }

      return NS_ERROR_DOM_SECURITY_ERR;
    }
  }

  // Partial Reset, need to restore principal for security reasons and
  // event listener manager so that load listeners etc. will
  // remain. This should be done before the security check is done to
  // ensure that the document is reset even if the new document can't
  // be loaded.  Note that we need to hold a strong ref to |principal|
  // here, because ResetToURI will null out our node principal before
  // setting the new one.
  nsRefPtr<nsEventListenerManager> elm(mListenerManager);
  mListenerManager = nullptr;

  // When we are called from JS we can find the load group for the page,
  // and add ourselves to it. This way any pending requests
  // will be automatically aborted if the user leaves the page.

  nsCOMPtr<nsILoadGroup> loadGroup;
  if (callingDoc) {
    loadGroup = callingDoc->GetDocumentLoadGroup();
  }

  ResetToURI(uri, loadGroup, principal);

  mListenerManager = elm;

  // Create a channel
  nsCOMPtr<nsIInterfaceRequestor> req = nsContentUtils::GetSameOriginChecker();
  NS_ENSURE_TRUE(req, NS_ERROR_OUT_OF_MEMORY);  

  nsCOMPtr<nsIChannel> channel;
  // nsIRequest::LOAD_BACKGROUND prevents throbber from becoming active,
  // which in turn keeps STOP button from becoming active  
  rv = NS_NewChannel(getter_AddRefs(channel), uri, nullptr, loadGroup, req, 
                     nsIRequest::LOAD_BACKGROUND);
  if (NS_FAILED(rv)) {
    return rv;
  }

  // StartDocumentLoad asserts that readyState is uninitialized, so
  // uninitialize it. SetReadyStateInternal make this transition invisible to
  // Web content. But before doing that, assert that the current readyState
  // is complete as it should be after the call to ResetToURI() above.
  MOZ_ASSERT(GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE,
             "Bad readyState");
  SetReadyStateInternal(nsIDocument::READYSTATE_UNINITIALIZED);

  // Prepare for loading the XML document "into oneself"
  nsCOMPtr<nsIStreamListener> listener;
  if (NS_FAILED(rv = StartDocumentLoad(kLoadAsData, channel, 
                                       loadGroup, nullptr, 
                                       getter_AddRefs(listener),
                                       false))) {
    NS_ERROR("nsXMLDocument::Load: Failed to start the document load.");
    return rv;
  }

  // After this point, if we error out of this method we should clear
  // mChannelIsPending.

  // Start an asynchronous read of the XML document
  rv = channel->AsyncOpen(listener, nullptr);
  if (NS_FAILED(rv)) {
    mChannelIsPending = false;
    return rv;
  }

  if (!mAsync) {
    nsCOMPtr<nsIThread> thread = do_GetCurrentThread();

    nsAutoSyncOperation sync(this);
    mLoopingForSyncLoad = true;
    while (mLoopingForSyncLoad) {
      if (!NS_ProcessNextEvent(thread))
        break;
    }

    // We set return to true unless there was a parsing error
    nsCOMPtr<nsIDOMNode> node = do_QueryInterface(GetRootElement());
    if (node) {
      nsAutoString name, ns;      
      if (NS_SUCCEEDED(node->GetLocalName(name)) &&
          name.EqualsLiteral("parsererror") &&
          NS_SUCCEEDED(node->GetNamespaceURI(ns)) &&
          ns.EqualsLiteral("http://www.mozilla.org/newlayout/xml/parsererror.xml")) {
        //return is already false
      } else {
        *aReturn = true;
      }
    }
  } else {
    *aReturn = true;
  }

  return NS_OK;
}
示例#18
0
/** \brief Set up input/output handling.
 *
 *  Sets up the module for input/output handling, based on the options in the configuration file.
 *
 * \param conf Configuration file instance.
 * \return Enum indicating the setup state.
 */
uint8_t Initializer::setUpIO(shared_ptr<Config> conf) {

    // Child for managing sensor instances.
    shared_ptr<SensorIO> sensors(new SensorIO);

    // Get accelerometer options.
    i2cDev acc;
    uint8_t accType;
    conf->getAcc(acc);
    conf->getAccType(accType);

    cerr << "Initializer: setup acc" << endl;

    // Create accelerometer child.
    if (accType == T_MPU6050) {

        cerr << "Initializer: creating mpu" << endl;

        // Create and set up MPU6050.
        shared_ptr<MPU6050> mpu6050(new MPU6050(acc.addr, acc.path));

        cerr << "Initializer: initializing mpu" << endl;

        if (mpu6050->initialize()) {
            printErr(INIT_ERR_DEV_SETUP, "imu (mpu6050)");
            return INIT_ERR_DEV_SETUP;
        }

        cerr << "Initializer: adding child" << endl;

        // Add child to sensors.
        sensors->append(mpu6050);

        cerr << "Initializer: acc done" << endl;

    } else return INIT_ERR_DEV_UNKNOWN;

    // Create gps receiver instance.
    uartDev gps;
    uint8_t gpsType;
    conf->getGPS(gps);
    conf->getGPSType(gpsType);

    cerr << "Initializer: setup gps" << endl;

    // Create gps child.
    if (gpsType == T_ADAFRUIT) {

        // Create and set up Adafruit receiver.
        shared_ptr<GpsAdafruit> adafruit(new GpsAdafruit(gps.path, gps.baud));
        if (adafruit->initialize()) {
            printErr(INIT_ERR_DEV_SETUP, "gps (adafruit)");
            return INIT_ERR_DEV_SETUP;
        }

        cerr << "Init:  GPS adding" << endl;

        // Add child to sensors.
        sensors->append(adafruit);

    } else return INIT_ERR_DEV_UNKNOWN;

    // Create obd receiver instance.
    uartDev obd;
    conf->getOBD(obd);

    cerr << "Initializer: obd path is " << obd.path << endl;

    // Create and set up obd receiver.
    shared_ptr<OBDReader> elm(new OBDReader(obd.path, obd.baud));
    if (elm->reset()) {
        printErr(INIT_ERR_DEV_SETUP, "obd module");
        return INIT_ERR_DEV_SETUP;
    } else if (elm->setup()) {
        printErr(INIT_ERR_DEV_SETUP, "obd module");
        return INIT_ERR_DEV_SETUP;
    }

    // Add child to sensors.
    sensors->append(elm);

    this->io.addChild(sensors);
    this->io.setSensorIO(sensors);

    return INIT_OK;
}
示例#19
0
void LUback ( ptrdiff_t first, ptrdiff_t *last, ptrdiff_t n, ptrdiff_t nu,
              ptrdiff_t maxmod, double eps,
              double *L, double *U, double *y, double *z )
{

/* ------------------------------------------------------------------
   LUback updates the factors LC = U by performing a backward sweep
   to eliminate all but the 'last' nonzero in the column vector z[*],
   stopping at z[first].

   If 'last' is positive, LUback searches backwards for a nonzero
   element in z and possibly alters 'last' accordingly.
   Otherwise, 'last' will be reset to abs(last) and so used.

   L     is n by n.
   U     is n by nu.
   y[*]  will eventually contain a row spike in row 'last' of U.
   The 'spike' row of L begins at L[ls].

   18 Mar 1990: First version with L and U stored row-wise.
   29 Jun 1999: Save w[last] = zlast at end so column replace
                can do correct forward sweep.
   ------------------------------------------------------------------ */

  ptrdiff_t    i, lz, lu, ll,ls, incu, numu;
  double zero = 0.0;
  double zlast, cs, sn;


  if ((*last) > 0) {

/*   Find the last significant element in z[*]. */

     for (i = (*last); i>first; i--)
        if (fabs(z[i]) > eps) break;

     (*last)   = i;
  }
  else
     (*last)   = abs((*last));

/*  Load the 'last' row of U into the end of y
    and do the backward sweep. */

  zlast  = z[(*last)];
  lu     = ((*last)  - 1)*maxmod + (3 - (*last))*(*last)/2;
  ll     = ((*last)  - 1)*maxmod + 1;
  ls     = ll;
  incu   = maxmod + 1 - (*last);
  numu   = nu     + 1 - (*last);
  if (numu > 0)
    LUdcopy ( numu, &U[subvec(lu)], 1, &y[subvec((*last))], 1 );

  for (lz = (*last) - 1; lz>=first; lz--) {
     ll    -= maxmod;
     incu++;
     lu    -= incu;
     y[lz]  = zero;

/*   See if this element of z is worth eliminating.
     We compare z[lz] with the current last nonzero, zlast. */

     if ( fabs(z[lz]) <= eps * fabs(zlast) ) continue;

/*   Generate a 2x2 elimination and apply it to U and L. */

     numu   = nu + 1 - lz;
     elmgen( &zlast, &z[lz], eps   , &cs, &sn );
     elm   ( 1, numu , &y[subvec(lz)], &U[subvec(lu)], cs, sn );
     elm   ( 1, n    , &L[subvec(ls)], &L[subvec(ll)], cs, sn );
  }

  z[(*last)] = zlast;

/*   End of LUback */
}
 const T &
 operator[](FgVect2UI coord) const
 {return elm(coord[0],coord[1]); }
示例#21
0
SXADDLQSI::SXADDLQSI() : current( &content)
{
	_sxAddl elm(NULL, 0);
	current->push_back(elm);
}