void printR(link h, int ind) { int i; if (h != z) { for (i=0; i<ind; i++) putchar(' '); printf("%s%c\n", key(h->item), h->red?'*':' '); printR(hl, ind+2); printR(hr, ind+2); } }
void printIrene(int x, int y) { printI(x,y); printR(x+SIZE+GAP,y); printE(x+5*SIZE+2*GAP,y); printN(x+8*SIZE+3*GAP,y); printE(x+12*SIZE+4*GAP,y); }
void printMarcel(int x, int y) { printM(x,y); printA(x+5*SIZE+GAP,y); printR(x+8*SIZE+2*GAP,y); printC(x+12*SIZE+3*GAP,y); printE(x+16*SIZE+4*GAP,y); printL(x+19*SIZE+5*GAP,y); }
bool IDtest(std::string is, std::string target) { std::stringstream ss; ss << "ID: is '" << is << "', should be '" << target << "'\n"; if (is == target) printG(ss.str()); else printR(ss.str()); return is == target; }
void printGameOver(int x, int y) { printG(x,y); printA(x+5*SIZE+GAP, y); printM(x+8*SIZE+2*GAP, y); printE(x+13*SIZE+3*GAP, y); printO(x+16*SIZE+5*GAP, y); printV(x+20*SIZE+6*GAP, y); printE(x+24*SIZE+7*GAP, y); printR(x+27*SIZE+8*GAP, y); }
void NumberEditRepaint() { if (text) { LcdGotoXYFont(1, 1); LcdStr(FONT_1X, text); } printRX2(value, 2); LcdGotoXYFont(1, 6); LcdStr(FONT_1X, "+-"); printR(GetCurDelta(), FONT_1X); }
void readInput() { NodeList NList; cout << "> "; cout.flush(); string line, command; getline (cin, line); // Get a line from standard input while (!cin.eof()) { // Put the line in a stringstream for parsing // Making a new stringstream for each line so flags etc. are in a known state stringstream lineStream (line); lineStream >> command; //call function depending on command if(command == "insertR") insertR(lineStream, NList); else if (command == "setV") setV(lineStream, NList); else if (command == "unsetV") unsetV(lineStream, NList); else if (command == "solve") solve(lineStream, NList); else if (command == "modifyR") modifyR(lineStream, NList); else if (command == "printR") printR(lineStream, NList); else if (command == "printNode") printNode(lineStream, NList); else if (command == "deleteR") deleteR(lineStream, NList); else if (command == "draw") draw(NList); else cout << "Error: invalid command" << endl; command = " "; cout << "> "; cout.flush(); getline (cin, line); } // End input loop until EOF. return; }
// Iteration and Prediction of O_lt for all sites and all time points "XB" void z_pr_its_ar(int *cov, int *its, int *nsite, int *n, int *r, int *rT, int *T, int *p, int *N, double *d, double *d12, double *phip, double *nup, double *sig_ep, double *sig_etap, double *sig_l0p, double *rhop, double *betap, double *mu_lp, double *X, double *valX, double *op, int *constant, double *zpred) { int its1, r1, rT1, N1, col, i, j, k, ns, p1; its1 = *its; r1 = *r; // n1 = *n; rT1 = *rT; N1 = *N; col = *constant; ns = *nsite; p1 = *p; // unsigned iseed = 44; // srand(iseed); double *phi, *nu, *sig_e, *sig_eta, *sig_l0, *rho, *beta, *mu_l, *o, *zpr; phi = (double *) malloc((size_t)((col)*sizeof(double))); nu = (double *) malloc((size_t)((col)*sizeof(double))); sig_e = (double *) malloc((size_t)((col)*sizeof(double))); sig_eta = (double *) malloc((size_t)((col)*sizeof(double))); sig_l0 = (double *) malloc((size_t)((r1*col)*sizeof(double))); rho = (double *) malloc((size_t)((col)*sizeof(double))); beta = (double *) malloc((size_t)((p1)*sizeof(double))); mu_l = (double *) malloc((size_t)((r1)*sizeof(double))); o = (double *) malloc((size_t)((N1)*sizeof(double))); zpr = (double *) malloc((size_t)((rT1*ns)*sizeof(double))); GetRNGstate(); for(i=0; i < its1; i++) { phi[0] = phip[i]; if(cov[0]==4){ nu[0] = nup[i]; } else{ nu[0] = nup[0]; } sig_e[0] = sig_ep[i]; sig_eta[0] = sig_etap[i]; rho[0] = rhop[i]; for(j=0; j < p1; j++) { beta[j] = betap[j+i*p1]; } for(j=0; j < r1; j++) { mu_l[j] = mu_lp[j+i*r1]; } for(j=0; j < r1; j++) { sig_l0[j] = sig_l0p[j+i*r1]; } for(j=0; j < N1; j++) { o[j] = op[j+i*N1]; } z_pr_ar(cov, nsite, n, r, rT, T, p, N, d, d12, phi, nu, sig_e, sig_eta, sig_l0, rho, beta, mu_l, X, valX, o, constant, zpr); for(k=0; k < ns; k++){ for(j=0; j < rT1; j ++){ zpred[j+k*rT1+i*rT1*ns] = zpr[j+k*rT1]; } } printR (i, its1); } // end of iteration loop PutRNGstate(); free(phi); free(nu); free(sig_e); free(sig_eta); free(sig_l0); free(rho); free(beta); free(mu_l); free(o); free(zpr); return; }
void zlt_fore_gpp_its(int *cov, int *its, int *K, int *n, int *m, int *r, int *p, int *rT, int *T, int *rK, int *nrK, double *dnm, double *dm, double *phip, double *nup, double *sig_ep, double *sig_etap, double *betap, double *rhop, double *wp, double *foreX, int *constant, double *foreZ) { int i, j, its1, n1, m1, r1, T1, K1, p1, col; its1 = *its; n1 =*n; m1 =*m; r1 =*r; T1 =*T; K1 =*K; p1 =*p; col =*constant; // unsigned iseed = 44; // srand(iseed); double *phi, *nu, *sig_e, *sig_eta, *rho, *beta, *w, *fZ; phi = (double *) malloc((size_t)((col)*sizeof(double))); nu = (double *) malloc((size_t)((col)*sizeof(double))); sig_e = (double *) malloc((size_t)((col)*sizeof(double))); sig_eta = (double *) malloc((size_t)((col)*sizeof(double))); rho = (double *) malloc((size_t)((col)*sizeof(double))); beta = (double *) malloc((size_t)((p1*col)*sizeof(double))); w = (double *) malloc((size_t)((m1*r1*T1)*sizeof(double))); fZ = (double *) malloc((size_t)((n1*r1*K1*col)*sizeof(double))); GetRNGstate(); for(i=0; i<its1; i++){ phi[0] = phip[i]; if(cov[0]==4){ nu[0] = nup[i]; } else{ nu[0] = 0.0; } sig_e[0] = sig_ep[i]; sig_eta[0] = sig_etap[i]; rho[0] = rhop[i]; for(j=0; j<p1; j++){ beta[j] = betap[j+i*p1]; } for(j=0; j<m1*r1*T1; j++){ w[j] = wp[j+i*m1*r1*T1]; } zlt_fore_gpp(cov, K, n, m, r, p, rT, T, rK, nrK, dnm, dm, phi, nu, sig_e, sig_eta, beta, rho, w, foreX, constant, fZ); for(j=0; j < n1*r1*K1; j++){ foreZ[j+i*n1*r1*K1] = fZ[j]; } printR(i, its1); }// end of iteration loop PutRNGstate(); free(phi); free(nu); free(sig_e); free(sig_eta); free(rho); free(beta); free(w); free(fZ); return; }
//_______________________________________________________________________________________________________ int main(int argc, char** argv) { parseArgs(argc, argv); printf("\n"); printY("[TEST] Test conditions:\n"); if (m_start_dsp) printG("\tDisplay\n"); else printR("\tDisplay\n"); if (m_start_imu) printG("\tIMU\n"); else printR("\tIMU\n"); if (m_start_imu && m_start_env) printG("\tEnvSens\n"); else if (m_start_imu && !m_start_env) printR("\tEnvSens\n"); else if (!m_start_imu && m_start_env) printR("\tskipping EnvSens (IMU needs to be enabled!)\n"); else printR("\tEnvSens\n"); if (m_start_ldc) printG("\tLDC\n"); else printR("\tLDC\n"); if (m_start_bat) printG("\tBatGauge\n"); else printR("\tBatGauge\n"); printf("\n"); printY("[TEST] Init devices...\n"); printf("\n"); fflush(stdout); // Set up display if (m_start_dsp) m_dsp = new display_edison(m_dsp_resolution, m_dsp_hands); // Set up IMU if (m_start_imu) { m_imu = new imu_edison(m_i2c_bus, m_mpu_address, m_start_env); m_imu->setupIMU(); } // Set up LDC if (m_start_ldc) m_ldc = new ldc_edison(m_i2c_bus); // Start battery gauge if (m_start_bat) { m_bat = new batgauge_edison(m_i2c_bus); m_bat->setAlertThreshold(m_alert_threshold); } printf("\n"); usleep(1000000); // start testing bool success = true; // test display if (m_start_dsp) { printY("[TEST] Drawing clock on display...\n"); printf("\n"); m_dsp->clear(); m_dsp->analogClock(true); m_dsp->flush(); } // test IMU if (m_start_imu) { printY("[TEST] Testing IMU...\n"); printf("IMU "); if (!IDtest(m_imu->getID(), m_imu_ID)) success = false; printf("MAG "); if (!IDtest(m_imu->getMagID(), m_mag_ID)) success = false; if (!m_idonly) { std::vector<float> data = m_imu->toReadable(m_imu->readRawIMU()); float mx, my, mz; m_imu->getCompassData(mx, my, mz); printf("Temperature [DegC]:\n\t%f\n", data[6]); printf("Accelerometer [m/s^2]:\n"); printf("\tX: %f\n", data[0]); printf("\tY: %f\n", data[1]); printf("\tZ: %f\n", data[2]); printf("Gyroscope [deg/s]:\n"); printf("\tX: %f\n", data[3]); printf("\tY: %f\n", data[4]); printf("\tZ: %f\n", data[5]); printf("Compass [mGs]:\n"); printf("\tX: %f\n", mx); printf("\tY: %f\n", my); printf("\tZ: %f\n", mz); } printf("\n"); fflush(stdout); } // test EnvSens if (m_start_imu && m_start_env) { printY("[TEST] Testing environmental sensor...\n"); if (!IDtest(m_imu->getEnvID(), m_env_ID)) success = false; if (!m_idonly) { float T, P, H; m_imu->getEnvData(T, P, H); printf("Temperature [DegC]: %f\n", T); printf("Pressure [hPa]: %f\n", P); printf("Humidity [%%RH]: %f\n", H); } printf("\n"); fflush(stdout); } // test LDC if (m_start_ldc) { printY("[TEST] Testing LDC...\n"); if (!IDtest(m_ldc->getVersion(), m_ldc_ID)) success = false; if (!m_idonly) { std::vector<uint16_t> LDC(2, 0); LDC = m_ldc->getADC(); printf("ADC0 (vis/IR) [raw]: %i\n", LDC[0]); printf("ADC1 (IR) [raw]: %i\n", LDC[1]); } printf("\n"); fflush(stdout); } // test BatGauge if (m_start_bat) { printY("[TEST] Testing battery gauge...\n"); if (!IDtest(m_bat->getVersion(), m_bat_ID)) success = false; if (!m_idonly) { printf("Voltage: %fV\n", m_bat->getVCell()); printf("State of Charge: %i%%\n", m_bat->getSoC()); printf("Alert Threshold: %i%%\n", m_bat->getAlertThreshold()); } printf("\n"); fflush(stdout); } if (success) printG("[TEST] All ID tests successful.\n"); else printR("[TEST] Some ID tests failed!\n"); if (m_start_bat) delete m_bat; if (m_start_ldc) delete m_ldc; if (m_start_imu) delete m_imu; if (m_start_dsp) delete m_dsp; if (success) return 0; else return 1; }
void STprint(link head) { printf("\n**** %d keys ****\n", head->N); printR(head, 0); printf("**** ****** ****\n"); }