eventhandler* parse_eventhandler(char* line) { char *token = NULL; char *sptr = NULL; char *cp = strdup(line); /* ignore everything behind # */ char *comment = strchr(line, '#'); if ( comment != NULL ) { *comment = '\0'; } char *delim = " \t\n"; char *evname = ct( strtok_r(cp, delim, &sptr) ); int value = strint( strtok_r(NULL, delim, &sptr) ); char *cmd = ct( strtok_r(NULL, "\n", &sptr) ); free(cp); /* all fields filled? */ if (evname && cmd && (value >= 0)) { eventhandler *eh = malloc( sizeof(eventhandler) ); eh->type = lookup_event_type( evname ); eh->code = lookup_event_code( evname ); eh->value = value; eh->cmdline = cmd; eh->next = NULL; return eh; } else { free(evname); free(cmd); return NULL; } }
int ct(char *s, char *t) { if (0 == *t) return 1; if (0 == *s) return 0; // end of s, but not end of t. if (*s == *t) { return ct(s+1, t+1) + ct(s+1, t); } else { return ct(s+1, t); } }
TreeNode* ct(vector<int>& preorder, vector<int> &inorder, int pst, int ist, int ied) { if(ist > ied) return NULL; int mid = 0; TreeNode* root = new TreeNode(preorder[pst]); for(int i = ist; i <= ied; i++){ if(preorder[pst] == inorder[i]) { mid = i;break;} } root->left = ct(preorder, inorder,pst+1 , ist,mid-1 ); // pst+1 !!! easy for forget root->right = ct(preorder, inorder,pst+(mid-ist+1) , mid+1, ied); return root; }
TreeNode *ct(vector<int> &preorder, vector<int> &inorder, int ist, int ied, int pst){ if(ist > ied) return NULL; TreeNode *res = new TreeNode(preorder[pst]); int mid; for(int i = ist; i <= ied; i++){ if(inorder[i] == res->val){ mid = i; break; } } res->right = ct(preorder, inorder, mid+1, ied, pst+1+mid-ist); res->left = ct(preorder, inorder, ist, mid-1, pst+1); return res; }
QgsRectangle QgsProcessingUtils::combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs ) { QgsRectangle extent; for ( const QgsMapLayer *layer : layers ) { if ( !layer ) continue; if ( crs.isValid() ) { //transform layer extent to target CRS Q_NOWARN_DEPRECATED_PUSH QgsCoordinateTransform ct( layer->crs(), crs ); Q_NOWARN_DEPRECATED_POP try { QgsRectangle reprojExtent = ct.transformBoundingBox( layer->extent() ); extent.combineExtentWith( reprojExtent ); } catch ( QgsCsException & ) { // can't reproject... what to do here? hmmm? // let's ignore this layer for now, but maybe we should just use the original extent? } } else {
/** * \brief get details about a specific calibration */ Calibration GuiderFactoryI::getCalibration(int id, const Ice::Current& /* current */) { // use the database to retrieve the complete calibration data Calibration calibration; try { astro::guiding::CalibrationTable ct(database); astro::guiding::CalibrationRecord r = ct.byid(id); calibration.id = r.id(); calibration.timeago = converttime(r.when); calibration.guider.cameraname = r.camera; calibration.guider.ccdid = r.ccdid; calibration.guider.guiderportname = r.guiderport; for (int i = 0; i < 6; i++) { calibration.coefficients.push_back(r.a[i]); } // add calibration points astro::guiding::CalibrationStore store(database); std::list<astro::guiding::CalibrationPointRecord> points = store.getCalibrationPoints(id); std::list<astro::guiding::CalibrationPointRecord>::iterator i; for (i = points.begin(); i != points.end(); i++) { calibration.points.push_back(convert(*i)); } return calibration; } catch (std::exception& ex) { std::string msg = astro::stringprintf("calibrationd run %d " "not found: %s", id, ex.what()); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); throw NotFound(msg); } }
void CharAllPrestigeTasks::load() { Query q(GetDb()); m_all_prestige_tasks.clear(); //从数据库读任务记录 q.get_result("select tid,cur,state from char_prestige_tasks where cid=" + LEX_CAST_STR(m_charData.m_id) + " order by tid"); while (q.fetch_row()) { int tid = q.getval(); int cur = q.getval(); int state = q.getval(); boost::shared_ptr<basePrestigeTask> bt = Singleton<PrestigeTaskMgr>::Instance().getPrestigeTask(tid); if (!bt.get()) { continue; } boost::shared_ptr<CharPrestigeTask> ct(new CharPrestigeTask(m_charData)); ct->tid = tid; ct->m_task = bt; ct->cur = cur; ct->state = state; m_all_prestige_tasks[bt->id] = ct; } q.free_result(); }
QString QgsCoordinateUtils::formatCoordinateForProject( const QgsPoint& point, const QgsCoordinateReferenceSystem& destCrs, int precision ) { QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "MU" ); QgsPoint geo = point; if ( format == "DM" || format == "DMS" || format == "D" ) { // degrees if ( destCrs.isValid() && !destCrs.geographicFlag() ) { // need to transform to geographic coordinates QgsCoordinateTransform ct( destCrs, QgsCoordinateReferenceSystem( GEOSRID ) ); try { geo = ct.transform( point ); } catch ( QgsCsException& ) { return QString(); } } if ( format == "DM" ) return geo.toDegreesMinutes( precision, true, true ); else if ( format == "DMS" ) return geo.toDegreesMinutesSeconds( precision, true, true ); else return geo.toString( precision ); } else { // coordinates in map units return point.toString( precision ); } }
void DisplayData(void) { int iTask; printf("Display of the instance:\n"); printf("\t Time Horizon T: %ld\n",T()); printf("\t Number of Tasks N: %ld\n",N()); printf("\t Number of Machines M: %ld\n",M()); ConsoleTable ct("Tasks", N(), 6); ct.SetColHeader(0, "QtyCPU") .SetColHeader(1, "QtyGPU") .SetColHeader(2, "QtyRAM") .SetColHeader(3, "QtyHDD") .SetColHeader(4, "IsPreemp") .SetColHeader(5, "CostPreemp"); for (iTask=0;iTask<N();iTask++) { ct.Print(nc(iTask)); ct.Print(ng(iTask)); ct.Print(nr(iTask)); ct.Print(nh(iTask)); ct.Print(R(iTask)); ct.Print(rho(iTask)); } }
complex_t BiquadBase::response (double normalizedFrequency) const { const double a0 = getA0 (); const double a1 = getA1 (); const double a2 = getA2 (); const double b0 = getB0 (); const double b1 = getB1 (); const double b2 = getB2 (); const double w = 2 * doublePi * normalizedFrequency; const complex_t czn1 = std::polar (1., -w); const complex_t czn2 = std::polar (1., -2 * w); complex_t ch (1); complex_t cbot (1); complex_t ct (b0/a0); complex_t cb (1); ct = addmul (ct, b1/a0, czn1); ct = addmul (ct, b2/a0, czn2); cb = addmul (cb, a1/a0, czn1); cb = addmul (cb, a2/a0, czn2); ch *= ct; cbot *= cb; return ch / cbot; }
void TWS_TLServer::tickPrice( TickerId tickerId, TickType tickType, double price, int canAutoExecute) { if ((tickerId>=0)&&(tickerId<(TickerId)stockticks.size()) && needStock(stockticks[tickerId].sym)) { time_t now; time(&now); CTime ct(now); TLTick k; k.date = (ct.GetYear()*10000) + (ct.GetMonth()*100) + ct.GetDay(); k.time = (ct.GetHour()*10000)+(ct.GetMinute()*100)+ct.GetSecond(); k.sym = stockticks[tickerId].sym; if (tickType==LAST) { stockticks[tickerId].trade = price; k.trade = price; k.size = stockticks[tickerId].size; } else if (tickType==BID) { stockticks[tickerId].bid = price; k.bid = stockticks[tickerId].bid; k.bs = stockticks[tickerId].bs; } else if (tickType==ASK) { stockticks[tickerId].ask = price; k.ask = stockticks[tickerId].ask; k.os = stockticks[tickerId].os; } else return; // not relevant tick info if (k.isValid() && needStock(k.sym)) this->SrvGotTick(k); } }
void TDistribution::_calculateNewV(const Mat& m, const vector<double>& EH, const vector<double>& ELogH) { // Use Line Search to search for the best v. CostT ct(this, m, EH, ELogH); GoldenSectionSearch gss(0.1); _v = gss.argmin(ct, 0, 10000); }
void QgsMapCanvasAnnotationItem::setFeatureForMapPosition() { if ( !mAnnotation || !mAnnotation->hasFixedMapPosition() ) return; QgsVectorLayer *vectorLayer = qobject_cast< QgsVectorLayer * >( mAnnotation->mapLayer() ); if ( !vectorLayer ) return; double halfIdentifyWidth = QgsMapTool::searchRadiusMU( mMapCanvas ); QgsPointXY mapPosition = mAnnotation->mapPosition(); try { QgsCoordinateTransform ct( mAnnotation->mapPositionCrs(), mMapCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); if ( ct.isValid() ) mapPosition = ct.transform( mapPosition ); } catch ( QgsCsException & ) { } QgsRectangle searchRect( mapPosition.x() - halfIdentifyWidth, mapPosition.y() - halfIdentifyWidth, mapPosition.x() + halfIdentifyWidth, mapPosition.y() + halfIdentifyWidth ); searchRect = mMapCanvas->mapSettings().mapToLayerCoordinates( vectorLayer, searchRect ); QgsFeatureIterator fit = vectorLayer->getFeatures( QgsFeatureRequest().setFilterRect( searchRect ).setFlags( QgsFeatureRequest::ExactIntersect ).setLimit( 1 ) ); QgsFeature currentFeature; ( void )fit.nextFeature( currentFeature ); mAnnotation->setAssociatedFeature( currentFeature ); }
CSonTime::CSonTime(LPCTSTR mstr) { CString css(mstr); CTokenizer ctt(mstr," /:,"); int i,j[6]; if ((css=="0000 00 00 00:00:00")|(css=="")|(mstr == NULL)) { CTime ct = CTime::GetCurrentTime(); CTime *pt = this; *pt = ct; } else { for (i=0;i<6;i++) { if (ctt.Next(css)) j[i] = atoi(css); else j[i] = 0; } CTime ct(j[0],j[1],j[2],j[3],j[4],j[5]); CTime *pt = this; *pt = ct; } m_pfnV = & VS_MainNum; }
int main(int argc, char* argv[]) { START_EASYLOGGINGPP(argc, argv); parseArgs(argc, argv); LOG(INFO) << "Initializing alignment provider"; DazAlnProvider* ap; ap = new DazAlnProvider(popts); TrgBuf trgBuf(20); CnsBuf cnsBuf(10); std::thread writerThread(Writer, std::ref(cnsBuf)); std::vector<std::thread> cnsThreads; for (int i=0; i < popts.threads; i++) { std::thread ct(Consensus, i, std::ref(trgBuf), std::ref(cnsBuf)); cnsThreads.push_back(std::move(ct)); } std::thread readerThread(Reader, std::ref(trgBuf), ap); writerThread.join(); std::vector<std::thread>::iterator it; for (it = cnsThreads.begin(); it != cnsThreads.end(); ++it) it->join(); readerThread.join(); delete ap; return 0; }
void QgsExtentGroupBox::setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, ExtentState state ) { QgsRectangle extent; if ( mOutputCrs == srcCrs ) { extent = r; } else { try { QgsCoordinateTransform ct( srcCrs, mOutputCrs ); extent = ct.transformBoundingBox( r ); } catch ( QgsCsException & ) { // can't reproject extent = r; } } mXMinLineEdit->setText( QgsRasterBlock::printValue( extent.xMinimum() ) ); mXMaxLineEdit->setText( QgsRasterBlock::printValue( extent.xMaximum() ) ); mYMinLineEdit->setText( QgsRasterBlock::printValue( extent.yMinimum() ) ); mYMaxLineEdit->setText( QgsRasterBlock::printValue( extent.yMaximum() ) ); mExtentState = state; if ( isCheckable() && !isChecked() ) setChecked( true ); updateTitle(); emit extentChanged( extent ); }
static void ActualSave (void (*ct)()) { unsigned int mask_return; Window root_return, child_return; int root_x_return, root_y_return, win_x_return, win_y_return; save_cont = ct; if (!changed) { ct (); return; }; StartArgs; SetArg (XtNvalue, Filename); XtSetValues (save_dialog, UseArgs); if (XQueryPointer (MyDisplay, MyRootWindow, &root_return, &child_return, &root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return)) { Dimension width, height; StartArgs; SetArg (XtNwidth, &width); SetArg (XtNheight, &height); XtGetValues (save_popup, UseArgs); StartArgs; SetArg (XtNx, win_x_return - width/2); SetArg (XtNy, win_y_return - height/10); XtSetValues (save_popup, UseArgs); }; XtPopup (save_popup, XtGrabExclusive); };
void RgShortestPathWidget::exportPath() { RgExportDlg dlg( this ); if ( !dlg.exec() ) return; QgsVectorLayer *vl = dlg.mapLayer(); if ( vl == NULL ) return; QgsPoint p1, p2; QgsGraph *path = getPath( p1, p2 ); if ( path == NULL ) return; QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapSettings().destinationCrs(), vl->crs() ); int startVertexIdx = path->findVertex( p1 ); int stopVertexIdx = path->findVertex( p2 ); double time = 0.0; double cost = 0.0; Unit timeUnit = Unit::byName( mPlugin->timeUnitName() ); Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() ); QgsPolyline p; while ( startVertexIdx != stopVertexIdx ) { if ( stopVertexIdx < 0 ) break; QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc(); if ( l.empty() ) break; const QgsGraphArc& e = path->arc( l.front() ); cost += e.property( 0 ).toDouble(); time += e.property( 1 ).toDouble(); p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) ); stopVertexIdx = e.outVertex(); } p.push_front( ct.transform( p1 ) ); QgsFeature f; f.initAttributes( vl->pendingFields().count() ); f.setGeometry( QgsGeometry::fromPolyline( p ) ); f.setAttribute( 0, cost / distanceUnit.multipler() ); f.setAttribute( 1, time / timeUnit.multipler() ); QgsFeatureList features; features << f; vl->dataProvider()->addFeatures( features ); vl->updateExtents(); mPlugin->iface()->mapCanvas()->update(); delete path; }
qe::ContractTraits getContractTraits() const { checkParsed(); qe::ContractTraits ct(0.035,0.5,0.9); ct.initialContractStates.L = L0_; ct.initialContractStates.Ap = 1.1*L0_; ct.T = qe::rational(contractMaturity_); return ct; }
BOOL CGuiParameter::GetFormatDate(CString& m_szDate, CString Format) { COleDateTime time; if (!GetValue(time)) return FALSE; CTime ct(time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()); m_szDate =ct.Format(Format); return TRUE; }
BOOL CGuiRecordSet::GetFormatDate(int nIndex,CString& m_szDate, CString Format) { COleDateTime time; if (!GetCollect(nIndex,time)) return FALSE; CTime ct(time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()); m_szDate =ct.Format(Format); return TRUE; }
// ----------------------------------------------------------------------------- // CRadioServerSettings::SetClockTime // ----------------------------------------------------------------------------- // void CRadioServerSettings::SetClockTime( TDateTime& aCt ) { TPckgBuf<TDateTime> ct(aCt); RProperty::Set(KRadioServerPropertyCategory, ERadioServPsClockTime, ct ); }
TreeNode *buildTree(vector<int> &preorder, vector<int> &inorder) { // Note: The Solution object is instantiated only once and is reused by each test case. if (preorder.size() == 0){ return NULL; }else{ return ct(preorder, inorder, 0, inorder.size()-1,0); } }
void ScatterBiasArea(int roi, float scan_width, int steps, int samples, int qi_it, float angstep) { std::vector<float> u=linspace(roi/2-scan_width/2,roi/2+scan_width/2, steps); QTrkComputedConfig cfg; cfg.width=cfg.height=roi; cfg.qi_angstep_factor = angstep; cfg.qi_iterations = qi_it; cfg.qi_angular_coverage = 0.7f; cfg.qi_roi_coverage = 1; cfg.qi_radial_coverage = 1.5f; cfg.qi_minradius=0; cfg.zlut_minradius=0; cfg.zlut_angular_coverage = 0.7f; cfg.zlut_roi_coverage = 1; cfg.zlut_radial_coverage = 1.5f; cfg.zlut_minradius = 0; cfg.qi_minradius = 0; cfg.com_bgcorrection = 0; cfg.xc1_profileLength = roi*0.8f; cfg.xc1_profileWidth = roi*0.2f; cfg.xc1_iterations = 1; cfg.Update(); ImageData lut,orglut = ReadLUTFile("10x.radialzlut#4"); vector3f ct(roi/2,roi/2,lut.h/2 + 0.123f); float dx = scan_width/steps; QueuedCPUTracker trk(cfg); ResampleLUT(&trk, &orglut, orglut.h, &lut); int maxval = 10000; ImageData tmp=ImageData::alloc(roi,roi); GenerateImageFromLUT(&tmp, &lut, 0, cfg.zlut_maxradius, vector3f(roi/2,roi/2,lut.h/2)); ApplyPoissonNoise(tmp, maxval); std::string fn = SPrintf( "sb_area_roi%d_scan%d_steps%d_qit%d_N%d", roi, (int)scan_width, steps, qi_it, samples); WriteJPEGFile( (fn + ".jpg").c_str(), tmp); tmp.free(); fn += ".txt"; for (int y=0;y<steps;y++) { for (int x=0;x<steps;x++) { vector3f cpos( (x+0.5f-steps/2) * dx, (y+0.5f-steps/2) * dx, 0 ); cfg.qi_iterations = qi_it; auto r= AccBiasTest(orglut, &trk, samples, cpos+ct, vector3f(), 0, maxval, qi_it < 0 ? LT_XCor1D : 0); float row[] = { r.acc.x, r.acc.y, r.acc.z, r.bias.x, r.bias.y, r.bias.z, r.crlb.x, r.crlb.z, samples }; WriteArrayAsCSVRow(fn.c_str(), row, 9, x+y>0); dbgprintf("X=%d,Y=%d\n", x,y); } } orglut.free(); lut.free(); }
int main() { int i,t,j, k; char s1[101],s2[102],re_s2[102],s[102],z[102]; scanf("%d",&t); for(i = 0;i < t; i++) { scanf("%s %s",s1,s2); if(strlen(s1) < strlen(s2)) printf("NO\n"); else { k = 0; for(j = strlen(s2) - 1;j >= 0; j--) re_s2[k++] = s2[j]; re_s2[k] = '\0'; ct(s1); ct(s2); ct(re_s2); if(check(strlen(s1),strlen(s2),s1,s2,z) || check(strlen(s1),strlen(re_s2),s1,re_s2,z)) printf("YES\n"); else printf("NO\n"); } } return 0; }
const ColorTable ColorTable::getPredefinedTable<ColorTable::Tables::Rainbow>(unsigned int num) { ColorTable ct(num); unsigned int n4 = num / 4; ct.interpolateLinear(0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0, n4); ct.interpolateLinear(0.0, 1.0, 1.0, 0.0, 1.0, 0.0, n4, n4); ct.interpolateLinear(0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 2*n4, n4); ct.interpolateLinear(1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 3*n4, num - 3*n4); return ct; }
void key::WinCompletionPort<T>::DeleteData(T* data) { boost::mutex::scoped_lock lock(this->recycled_mutex); if (this->recycled.size() >= this->number_of_threads * 4) { delete data; return; } if (this->recycled.reserve() == 0) { if (this->recycled.capacity() == 0) { boost::circular_buffer_space_optimized<int>::capacity_type ct(this->number_of_threads * 2, this->number_of_threads * 2); this->recycled.set_capacity(ct); } else { boost::circular_buffer_space_optimized<int>::capacity_type ct(this->recycled.capacity() * 2, this->number_of_threads * 2); this->recycled.set_capacity(ct); } } this->recycled.push_back(data); }
QString PlayerWidget::tickToString( qint64 tickvalue ) { int minute = tickvalue / 60000; int second = (tickvalue-minute*60000)/1000; int msecond = (tickvalue-minute*60000-second*1000) / 100; // round milliseconds to 0-9 range} QTime ct( 0, minute, second, msecond ); return ct.toString( "mm:ss.z" ); }
cover_t apply_keylist(const vector<vector<int> >& vv, const vector<skey_t>& keylist){ cover_t ct(vv.size()); for(int i=0; i<vv.size(); i++) for(int j=0; j<vv[i].size(); j++) ct[i].insert(keylist[vv[i][j]]); return ct; }
void TLTimeNow(std::vector<int> & nowtime) { time_t now; time(&now); CTime ct(now); int date = (ct.GetYear()*10000) + (ct.GetMonth()*100) + ct.GetDay(); int time = (ct.GetHour()*10000)+(ct.GetMinute()*100) + ct.GetSecond(); nowtime.push_back(date); nowtime.push_back(time); }