void loop(){ if(Serial.available()>0) { x = Serial.read(); if(x=='w') { goFd(); delay(200); stp(); } else if(x=='s') { goBk(); delay(200); stp(); } else if(x=='a') { goLt(); delay(200); stp(); } else if(x=='d') { goRt(); delay(200); stp(); } else { stp(); delay(200); } } }
double ee_clear_distance (const Face *face0, const Face *face1, const Vec3 &d, double last_dist, Bary &b0, Bary &b1) { for (int e0 = 0; e0 < 3; e0++) { for (int e1 = 0; e1 < 3; e1++) { const Vec3 &x00 = face0->v[e0]->node->x, &x01 = face0->v[NEXT(e0)]->node->x, &x10 = face1->v[e1]->node->x, &x11 = face1->v[NEXT(e1)]->node->x; Vec3 n = cross(normalize(x01-x00), normalize(x11-x10)); double h = dot(x00-x10, n), dh = dot(d, n); if (h*dh >= 0) continue; double a00 = stp(x01-x10, x11-x10, d), a01 = stp(x11-x10, x00-x10, d), a10 = stp(x01-x00, x11-x00, d), a11 = stp(x10-x00, x01-x00, d); if (a00*a01 <= 0 || a10*a11 <= 0) continue; double dist = -h/dh; if (dist > last_dist) { last_dist = dist; b0 = Bary(0); b0[e0] = a00/(a00+a01); b0[NEXT(e0)] = a01/(a00+a01); b1 = Bary(0); b1[e1] = a10/(a10+a11); b1[NEXT(e1)] = a11/(a10+a11); } } } return last_dist; }
double vf_clear_distance (const Face *face0, const Face *face1, const Vec3 &d, double last_dist, Bary &b0, Bary &b1) { for (int v = 0; v < 3; v++) { const Vec3 &xv = face0->v[v]->node->x, &x0 = face1->v[0]->node->x, &x1 = face1->v[1]->node->x, &x2 = face1->v[2]->node->x; const Vec3 &n = face1->n; double h = dot(xv-x0, n), dh = dot(d, n); if (h*dh >= 0) continue; double a0 = stp(x2-x1, xv-x1, d), a1 = stp(x0-x2, xv-x2, d), a2 = stp(x1-x0, xv-x0, d); if (a0 <= 0 || a1 <= 0 || a2 <= 0) continue; double dist = -h/dh; if (dist > last_dist) { last_dist = dist; b0 = Bary(0); b0[v] = 1; b1[0] = a0/(a0+a1+a2); b1[1] = a1/(a0+a1+a2); b1[2] = a2/(a0+a1+a2); } } return last_dist; }
void CNotifyFavProgress::SetFavProgress(string appId, int progress, nsDownStates dstate, bool allowState) { if(m_hwndNotify) { LPDOWNLOADSTATUS pstatus = new DOWNLOADSTATUS; pstatus->appId = appId; char temp[100] = {0}; sprintf_s(temp, 100 , "%d", progress); string stp(temp); pstatus->progress = stp; switch(dstate) { case nsDownloading:pstatus->status = "正在下载"; break; case nsInstalling:pstatus->status = "正在安装"; break; default:pstatus->status = ""; break; } switch(allowState) { case true:pstatus->logo = "1"; break; default:pstatus->logo = "0"; break; } ::PostMessage (m_hwndNotify, WM_AX_FRAME_CHANGE_PROGRESS, (WPARAM)pstatus, 0); } }
void modules_transform::apply(const context& ctx, meta_model::model& m) { tracing::scoped_transform_tracer stp(lg, "modules transform", transform_id, m.name().qualified().dot(), *ctx.tracer(), m); const auto im(gather_internal_modules(m)); create_modules(im, m); stp.end_transform(m); }
// Directs users/OS based on command entered void dispatcher() { switch (queueArray[currentPriority][0]->processType) { case 1: run(); break; case 3: stp(); break; } }
int cp (int argc, char *argv[]) { Stat_s a; Stat_s b; a = t_get_stats(TreeA); b = t_get_stats(TreeB); if (memcmp( &a, &b, sizeof(a)) != 0) { printf("We have a problem Huston.\n"); stp(argc, argv); } return t_compare(TreeA, TreeB); }
void reader() { while(1){ ManagedString incoming = uBit.serial.readUntil(";") + ";"; ManagedString id = incoming.substring(0,3); if(id == "set"){ uBit.serial.send("ack;"); set(incoming); } else if(id == "ack"){ uBit.serial.send("ack;"); ack(incoming); } else if(id == "stp"){ uBit.serial.send("ack;"); stp(); } } }
void PiersonMoskowitz::set( Ostream& os ) { // Get the input parameters scalar Hs(readScalar(dict_.lookup("Hs"))); scalar Tp(readScalar(dict_.lookup("Tp"))); scalar depth(readScalar(dict_.lookup("depth"))); vector direction(vector(dict_.lookup("direction"))); label N = readLabel(dict_.lookup("N")); // Calculate the frequency axis autoPtr<Foam::frequencyAxis> fA = Foam::frequencyAxis::New(rT_, dict_); scalarField nodeFrequency(N + 1, 0); // An intermediate step needed for certain discretisation types // Placed in scopes such that the temporary variables to not 'survive' { equidistantFrequencyAxis equiFA(rT_, dict_); scalarField tempFreqAxis = equiFA.freqAxis(10000); scalarField tempSpectrum = this->spectralValue(Hs, Tp, tempFreqAxis); nodeFrequency = fA->freqAxis(tempFreqAxis, tempSpectrum, N); } // Prepare variables freq_.setSize(N); amp_.setSize(N); phi_.setSize(N); k_.setSize(N); // Compute spectrum scalarField S = this->spectralValue(Hs, Tp, nodeFrequency); // Prepare stokesFirst to compute wave numbers Foam::stokesFirstProperties stp( rT_, dict_ ); // Compute return variables for (int i = 1; i < N + 1; i++) { // The frequency is the mid-point between two nodes freq_[i - 1] = 0.5*(nodeFrequency[i - 1] + nodeFrequency[i]); // Amplitude is the square root of the trapezoidal integral amp_[i - 1] = Foam::sqrt ( (S[i-1] + S[i]) *(nodeFrequency[i] - nodeFrequency[i - 1]) ); // Wave number based on linear wave theory k_[i - 1] = direction*stp.linearWaveNumber(depth, freq_[i-1]); // The phase is computed based on the phase-function phi_[i - 1] = phases_->phase(freq_[i - 1], k_[i - 1]); } writeSpectrum(os, nodeFrequency, S); }
int main(int argc, char** argv) { if (argc != 2) BNB_ERROR_REPORT("Usage: searchgdsc.exe json_file\n"); std::string jsons; FileUtils::getStringFromFile(argv[1], jsons); lur::ParseJson::parseModelData(jsons, mm); double ev; lur::ParseJson::parseLatticeData(jsons, mm, ev, x); #if 0 // Lennard Jones lur::PairPotentialEnergy enrg(mm, lur::ljpotent); #endif #if 0 // Cutted Lennard Jones lur::PairPotentialEnergy enrg(mm, ljcutpotent); #endif #if 0 // Morse lur::PairPotentialEnergy enrg(mm, lur::morsepotent); #endif #if 0 lur::PotentialCutter pc(6, 0.5, lur::ljpotent); lur::PairPotentialEnergy enrg(mm, pc); #endif #if 1 // Tersoff lur::TersoffParams tparam; lur::fillCarbonParametersTersoffOriginal(tparam); lur::TersoffUtils tutils(tparam); lur::TersoffEnergy enrg(mm, tutils); //enrg.setFixedAtoms(true); #endif #if 1 // Sets the fixed atoms attribute // enrg.setFixedAtoms(true); #endif const int N = mm.mNumLayers * 3; lur::LurieObj obj(enrg, mm); NumGradObjective<double> nobj(obj); nobj.setH(1E-4); Box<double> box(N); lur::ParseJson::parseBoxData(jsons, box); std::cout << "Searching in box " << BoxUtils::toString(box) << "\n"; #if 0 GbdStopper stp(box); GradBoxDescent<double> locs(box, &stp); locs.getOptions().mGInit = .1; #endif #if 1 BBStopper stp; BBBoxDescent<double> locs(box, &stp); locs.getOptions().mHInit = 4; locs.getOptions().mDec = 0.5; locs.getOptions().mHLB = 1e-6; locs.getOptions().mInc = 1.75; //locs.getOptions().mOnlyCoordinateDescent = true; #endif // TMP DEBUG #if 0 double xxx[12] = {0.866173, 0.982091, 0.982755, 0.950314, 2.08087, 1.84751, 0.4, 2.99746, 1.86217, 0.865676, 1.49372, 0.974428}; std::cout << nobj.func(xxx) << "\n"; double ggg[12]; nobj.grad(xxx, ggg); VecUtils::vecPrint(12, ggg); exit(0); #endif // TMP signal(SIGINT, output); VecUtils::vecPrint(N, x); locs.setObjective(&nobj); locs.search(x, &bv); std::cout << "Found v = " << bv << "\n"; VecUtils::vecPrint(N, x); std::string json; json += "{\n"; lur::GenJSON::genModel(mm, json); json += ", \n"; lur::GenJSON::genBox(box, json); json += ", \n"; lur::GenJSON::genLattice(mm, bv, x, json); json += "\n}\n"; std::cout << json << "\n"; return 0; }
TEST(plot, plot_timep) { DummyShortTimeProcess stp(512); DspGui gui(&stp, &plot_signal_pocessing_run); gui.start(); }
void run(double *accum, int *cur_loc, mem_array mem) { int prg_counter = 0, // mem cell location of the command being executed next_loc = 0, // mem cell location of the next command to be executed run_flag = CONTINUE; // flag for when to stop the execution of the // user's program. Values are CONTINUE, STOP // and RUN_ERR char cmdtrans[80]; // an English translation of the current command enum speed run_speed; // the run mode hidemouse(); // if they want to run if(get_speed(&run_speed) == CONTINUE) { // set up screen for running put_accum(accum); clear_monitor(); clear_keyboard(); clear_keys(); /* user's program loop */ do { // execute at the next location prg_counter = next_loc; // THF patch, was +2 put_prg_counter(prg_counter + 1); put_instruct(mem[prg_counter]); bright_cell(prg_counter, mem[prg_counter]); // case statement for run mode switch(run_speed) { case SLOW: delay(SLOW_DELAY_TIME); break; case FAST: delay(FAST_DELAY_TIME); } /// if there is a command in the cell if(mem[prg_counter].entry_type == CMD) { // command type case statement switch(mem[prg_counter].cmd_type) { case LDC: run_flag = ldc(accum, mem, cmdtrans, prg_counter, &next_loc); break; case ADC: run_flag = adc(accum, mem, cmdtrans, prg_counter, &next_loc); break; case LDA: run_flag = lda(accum, mem, cmdtrans, prg_counter, &next_loc); break; case STA: run_flag = sta(accum, mem, cmdtrans, prg_counter, &next_loc); break; case ADD: run_flag = add(accum, mem, cmdtrans, prg_counter, &next_loc); break; case SUB: run_flag = sub(accum, mem, cmdtrans, prg_counter, &next_loc); break; case MUL: run_flag = mul(accum, mem, cmdtrans, prg_counter, &next_loc); break; case DIV: run_flag = div(accum, mem, cmdtrans, prg_counter, &next_loc); break; case INP: run_flag = inp(mem, cmdtrans, prg_counter, &next_loc); break; case OUT: run_flag = out(mem, cmdtrans, prg_counter, &next_loc); break; case BPA: run_flag = bpa(accum, mem, cmdtrans, prg_counter, &next_loc); break; case BNA: run_flag = bna(accum, mem, cmdtrans, prg_counter, &next_loc); break; case BZA: run_flag = bza(accum, mem, cmdtrans, prg_counter, &next_loc); break; case BRU: run_flag = bru(mem, cmdtrans, prg_counter, &next_loc); break; case STP: run_flag = stp(cmdtrans, prg_counter, &next_loc); if(run_speed == CYCLE) { display_cmdtrans(cmdtrans); } break; default: run_err_message("ERROR: Unkown command at this location."); run_flag = RUN_ERR; break; } } else { run_err_message("ERROR: Unkown command at this location."); run_flag = RUN_ERR; } // check to see if the user wants to stop if(kbhit()) { if(getch() == EscKey) { run_flag = STOP; } } if((run_speed == CYCLE) && (run_flag == CONTINUE)) { run_flag = display_cmdtrans(cmdtrans); } dim_cell(prg_counter, mem[prg_counter]); } while((run_flag == CONTINUE) && (mem[prg_counter].cmd_type != STP)); // clear the registers when program is done clear_instruct(); clear_prg_counter(); } showmouse(); if(run_flag == RUN_ERR) { *cur_loc = prg_counter; } display_keys(); }
bool NXConnection::SetParameters( NXSettings* sets ) { string sTmp = ""; ClearParameters( pSession ); sTmp = options->GetNXPersonalDirectory(); NX_LOG_LOGDEBUG( "setting 'NX_PersonalDirectory' to '" + sTmp + "'." ); SetStringParameter( pSession, NX_PersonalDirectory, sTmp.c_str() ); NX_LOG_LOGDEBUG( "checking cookie..."); sTmp = options->GetNXCookieFilePath(); NX_LOG_LOGDEBUG( "Info: setting 'NX_CookieTempFilePath' to '" + sTmp + "'." ); SetStringParameter( pSession, NX_CookieTempFilePath, sTmp.c_str() ); if( GetExistingSessionCookie( pSession ) != NX_Ok ) { if( GenerateSessionCookie( pSession ) != NX_Ok ) { NX_LOG_LOGERROR( "session cookie NOT found... and cannot create a new one." ); return false; } } NX_LOG_LOGDEBUG( "cookie found..."); sTmp = options->GetNXSshPath(); NX_LOG_LOGDEBUG( "Info: setting 'NX_SshPath' to '" + sTmp + "'."); SetStringParameter( pSession, NX_SshPath, options->GetNXSshPath().c_str() ); sTmp = options->GetNXSshKeyPath(); NX_LOG_LOGDEBUG( "Info: setting 'NX_SshKeyPath' to '" + sTmp + "'."); SetStringParameter( pSession, NX_SshKeyPath, sTmp.c_str() ); sTmp = options->GetNXSshLogPath(); NX_LOG_LOGDEBUG( "Info: setting 'NX_SshLogPath' to '" + sTmp + "'." ); SetStringParameter( pSession, NX_SshLogPath, sTmp.c_str() ); #ifndef WIN32 SetBoolParameter(pSession, NX_ProxyUseOptionsFile, true); #endif /* Convert other Paramaters */ SettingsToParameters stp( sets, pSession ); stp.Convert(); SetStringParameter( pSession, NX_ProxyPath, options->GetNXProxyPath().c_str() ); SetStringParameter( pSession, NX_ProxyLibraryPath, options->GetNXLibDirectory().c_str() ); SetStringParameter( pSession, NX_ProxyMode, "S" ); #if defined (WIN32) /* XServer */ string xspath = options->GetNXBinDirectory() + "\\nxwin.exe"; SetStringParameter( pSession, NX_XServerPath, xspath.c_str() ); SetStringParameter( pSession, NX_XServerName, "nxwin.exe" ); SetStringParameter( pSession, NX_XServerPort, ":0" ); SetStringParameter( pSession, NX_ProxyDisplay, ":0" ); SetStringParameter( pSession, NX_XServer_FirstCustomOption, "-emulate3buttons" ); SetStringParameter( pSession, NX_XServer_FirstCustomOption + 1, "-agent" ); SetStringParameter( pSession, NX_XServer_FirstCustomOption + 2, "-hide" ); SetStringParameter( pSession, NX_XServer_FirstCustomOption + 3 , "-noreset" ); SetStringParameter( pSession, NX_XServer_FirstCustomOption + 4 , "-ac" ); #endif return true; }