static int cmd_dbgprint(cmdint_t *ci, int argc, char **argv) { if (ci->db != NULL) { RP(mdb_DebugShowTABLE(ci->db)); RP(mdb_DebugShowSCHEMA(ci->db)); } return OK; }
static int cmd_cldb(cmdint_t *ci, int argc, char **argv) { NEED_ARGS(1); if (ci->db != NULL) { RP(mdb_DBClose(&ci->db)); } return OK; }
void cylin2spher(t_vec3t *v) { const t_real z = ZP(v); const t_real r = RP(v); RHOP(v) = sqrt(z * z + r * r); PHIP(v) = atan2(r, z); v->type = SPHERICAL; }
void spher2cylin(t_vec3t *v) { const t_real rho = RHOP(v); const t_real theta = THETAP(v); ZP(v) = cos(theta) * rho; RP(v) = sin(theta) * rho; v->type = CYLINDRICAL; }
int proc_compare(const void *pp1, const void *pp2) { register struct macos_proc *p1; register struct macos_proc *p2; register int result; register pctcpu lresult; /* remove one level of indirection */ p1 = *(struct macos_proc **) pp1; p2 = *(struct macos_proc **) pp2; /* compare percent cpu (pctcpu) */ if ((lresult = RP(p2, cpu_usage) - RP(p1, cpu_usage)) == 0) { /* use cpticks to break the tie */ if ((result = MPP(p2, p_cpticks) - MPP(p1, p_cpticks)) == 0) { /* use process state to break the tie */ if ((result = sorted_state[(unsigned char) MPP(p2, p_stat)] - sorted_state[(unsigned char) MPP(p1, p_stat)]) == 0) { /* use priority to break the tie */ if ((result = MPP(p2, p_priority) - MPP(p1, p_priority)) == 0) { /* use resident set size (rssize) to break the tie */ if ((result = RSSIZE(p2) - RSSIZE(p1)) == 0) { /* use total memory to break the tie */ result = PROCSIZE(p2->kproc) - PROCSIZE(p1->kproc); } } } } } else { result = lresult < 0 ? -1 : 1; } return (result); }
/* * In Piccolo, we need "whitening" keys in addition to roundKeys. We choose * to consider them as "additional" roundKeys that are stored on top of * actual roundKeys (i.e. roundKeys[100:103]) */ void Encrypt(uint8_t *block, uint8_t *roundKeys) { uint8_t i; uint16_t *x3 = (uint16_t *)block; uint16_t *x2 = x3 + 1; uint16_t *x1 = x3 + 2; uint16_t *x0 = x3 + 3; uint16_t *rk = (uint16_t *)roundKeys; *x2 ^= READ_ROUND_KEY_WORD(rk[51]); *x0 ^= READ_ROUND_KEY_WORD(rk[50]); for (i = 0; i < NUMBER_OF_ROUNDS - 1; ++i) { *x1 = *x1 ^ F(*x0) ^ READ_ROUND_KEY_WORD(rk[2 * i]); *x3 = *x3 ^ F(*x2) ^ READ_ROUND_KEY_WORD(rk[2 * i + 1]); RP(x0, x1, x2, x3); } *x1 = *x1 ^ F(*x0) ^ READ_ROUND_KEY_WORD(rk[2*NUMBER_OF_ROUNDS - 2]); *x3 = *x3 ^ F(*x2) ^ READ_ROUND_KEY_WORD(rk[2*NUMBER_OF_ROUNDS - 1]); *x0 ^= READ_ROUND_KEY_WORD(rk[52]); *x2 ^= READ_ROUND_KEY_WORD(rk[53]); }
static int cmd_rmdb(cmdint_t *ci, int argc, char **argv) { NEED_ARGS(2); RP(mdb_DBRemove(argv[1])); return OK; }
static int vwalk() { register FTS *t; register FTSENT *p; register NODE *ep, *level; int specdepth, rval; char *argv[2]; argv[0] = "."; argv[1] = NULL; if ((t = fts_open(argv, ftsoptions, NULL)) == NULL) error("fts_open: %s", strerror(errno)); level = root; specdepth = rval = 0; while ((p = fts_read(t))) { switch(p->fts_info) { case FTS_D: break; case FTS_DP: if (specdepth > p->fts_level) { for (level = level->parent; level->prev; level = level->prev); --specdepth; } continue; case FTS_DNR: case FTS_ERR: case FTS_NS: (void)fprintf(stderr, "mtree: %s: %s\n", RP(p), strerror(p->fts_errno)); continue; default: if (dflag) continue; } if (specdepth != p->fts_level) goto extra; for (ep = level; ep; ep = ep->next) if ((ep->flags & F_MAGIC && !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) || !strcmp(ep->name, p->fts_name)) { ep->flags |= F_VISIT; if (compare(ep->name, ep, p)) rval = MISMATCHEXIT; if (ep->flags & F_IGN) (void)fts_set(t, p, FTS_SKIP); else if (ep->child && ep->type == F_DIR && p->fts_info == FTS_D) { level = ep->child; ++specdepth; } break; } if (ep) continue; extra: if (!eflag) { (void)printf("extra: %s", RP(p)); if (rflag) { if ((S_ISDIR(p->fts_statp->st_mode) ? rmdir : unlink)(p->fts_accpath)) { (void)printf(", not removed: %s", strerror(errno)); } else (void)printf(", removed"); } (void)putchar('\n'); } (void)fts_set(t, p, FTS_SKIP); } (void)fts_close(t); if (sflag) (void)fprintf(stderr, "mtree: %s checksum: %u\n", fullpath, crc_total); return (rval); }
int load_thread_info(struct macos_proc * mp) { register kern_return_t rc = 0; register int i = 0; register int t_utime = 0; register int t_stime = 0; register int t_cpu = 0; register task_t the_task = mp->the_task; thread_array_t thread_list = NULL; /* * We need to load all of the threads for the given task so we can get the * performance data from them. */ mp->thread_count = 0; rc = task_threads(the_task, &thread_list, &(mp->thread_count)); if (rc != KERN_SUCCESS) { return (rc); } /* * now, for each of the threads, we need to sum the stats so we can * present the whole thing to the caller. */ for (i = 0; i < mp->thread_count; i++) { struct thread_basic_info t_info; unsigned int icount = THREAD_BASIC_INFO_COUNT; kern_return_t rc = 0; rc = thread_info(thread_list[i], THREAD_BASIC_INFO, (thread_info_t) & t_info, &icount); if (rc != KERN_SUCCESS) { puke("error: unable to load thread info for task (%s); rc = %d", strerror(errno), rc); return (rc); } t_utime += t_info.user_time.seconds; t_stime += t_info.system_time.seconds; t_cpu += t_info.cpu_usage; } vm_deallocate(mach_task_self(), (vm_address_t) thread_list, sizeof(thread_array_t) * (mp->thread_count)); /* * Now, we load the values in the structure above. */ RP(mp, user_time).seconds = t_utime; RP(mp, system_time).seconds = t_stime; RP(mp, cpu_usage) = t_cpu; return (KERN_SUCCESS); }
char * format_next_process(caddr_t handle, char *(*getuserid) ()) { register struct macos_proc *pp; register long cputime; register double pct; struct handle *hp; char *command; /* text outputted to describe the command */ int show_cmd_local = show_fullcmd; /* * we need to keep track of the next proc structure. */ hp = (struct handle *) handle; pp = *(hp->next_proc++); hp->remaining--; /* * get the process structure and take care of the cputime */ if ((MPP(pp, p_flag) & P_INMEM) == 0) { /* we want to print swapped processes as <pname> */ char *comm = MPP(pp, p_comm); #define COMSIZ sizeof(MPP(pp, p_comm)) char buf[COMSIZ]; strncpy(buf, comm, COMSIZ); comm[0] = '<'; strncpy(&comm[1], buf, COMSIZ - 2); comm[COMSIZ - 2] = '\0'; strncat(comm, ">", COMSIZ - 1); comm[COMSIZ - 1] = '\0'; command = comm; } /* * count the cpu time, but ignore the interrupts * * At the present time (DR2 8/1998), MacOS X doesn't correctly report this * information through the kinfo_proc structure. We need to get it from * the task threads. * * cputime = PP(pp, p_rtime).tv_sec; */ cputime = RP(pp, user_time).seconds + RP(pp, system_time).seconds; /* * calculate the base cpu percentages * * Again, at the present time, MacOS X doesn't report this information * through the kinfo_proc. We need to talk to the threads. */ pct = (double) (RP(pp, cpu_usage)) / TH_USAGE_SCALE; /* get the process's command name in to "cmd" */ if (show_fullcmd) if (get_fullcmd(MPP(pp, p_pid), pp->fullcmd) < 0) show_cmd_local = 0; /* Don't show if full command not found. */ /* * format the entry */ /* * In the final version, I would expect this to work correctly, but it * seems that not all of the fields in the proc structure are being used. * * For now, we'll attempt to get some of the things we need from the mach * task info. */ sprintf(fmt, Proc_format, MPP(pp, p_pid), (*getuserid) (MEP(pp, e_pcred.p_ruid)), 0, pp->thread_count, format_k(TASKSIZE(pp) / 1024), format_k(pagetok(RSSIZE(pp))), state_abbrev[(u_char) MPP(pp, p_stat)], format_time(cputime), 100.0 * TP(pp, resident_size) / maxmem, 100.0 * pct, (show_cmd_local == 0 ? command : pp->fullcmd)); return (fmt); }
static int vwalk(void) { FTS *t; FTSENT *p; NODE *ep, *level; int specdepth, rval; char *argv[2]; char dot[] = "."; argv[0] = dot; argv[1] = NULL; if ((t = fts_open(argv, ftsoptions, nsort)) == NULL) err(1, "line %d: fts_open", lineno); level = root; specdepth = rval = 0; while ((p = fts_read(t))) { if (!check_includes(p->fts_name, p->fts_path) || check_excludes(p->fts_name, p->fts_path)) { fts_set(t, p, FTS_SKIP); continue; } switch(p->fts_info) { case FTS_D: case FTS_SL: break; case FTS_DP: if (specdepth > p->fts_level) { for (level = level->parent; level->prev; level = level->prev); --specdepth; } continue; case FTS_DNR: case FTS_ERR: case FTS_NS: warnx("%s: %s", RP(p), strerror(p->fts_errno)); continue; default: if (dflag) continue; } if (specdepth != p->fts_level) goto extra; for (ep = level; ep; ep = ep->next) if ((ep->flags & F_MAGIC && !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) || !strcmp(ep->name, p->fts_name)) { ep->flags |= F_VISIT; if ((ep->flags & F_NOCHANGE) == 0 && compare(ep->name, ep, p)) rval = MISMATCHEXIT; if (ep->flags & F_IGN) (void)fts_set(t, p, FTS_SKIP); else if (ep->child && ep->type == F_DIR && p->fts_info == FTS_D) { level = ep->child; ++specdepth; } break; } if (ep) continue; extra: if (!eflag) { (void)printf("%s extra", RP(p)); if (rflag) { if ((S_ISDIR(p->fts_statp->st_mode) ? rmdir : unlink)(p->fts_accpath)) { (void)printf(", not removed: %s", strerror(errno)); } else (void)printf(", removed"); } (void)putchar('\n'); } (void)fts_set(t, p, FTS_SKIP); } (void)fts_close(t); if (sflag) warnx("%s checksum: %lu", fullpath, (unsigned long)crc_total); return (rval); }
static int statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, u_long *pflags) { FTSENT *p; gid_t sgid; uid_t suid; mode_t smode; u_long sflags; struct group *gr; struct passwd *pw; gid_t savegid = *pgid; uid_t saveuid = *puid; mode_t savemode = *pmode; u_long saveflags = *pflags; u_short maxgid, maxuid, maxmode, maxflags; u_short g[MAXGID], u[MAXUID], m[MAXMODE], f[MAXFLAGS]; char *fflags; static int first = 1; if ((p = fts_children(t, 0)) == NULL) { if (errno) err(1, "%s", RP(parent)); return (1); } bzero(g, sizeof(g)); bzero(u, sizeof(u)); bzero(m, sizeof(m)); bzero(f, sizeof(f)); maxuid = maxgid = maxmode = maxflags = 0; for (; p; p = p->fts_link) { if (!dflag || (dflag && S_ISDIR(p->fts_statp->st_mode))) { smode = p->fts_statp->st_mode & MBITS; if (smode < MAXMODE && ++m[smode] > maxmode) { savemode = smode; maxmode = m[smode]; } sgid = p->fts_statp->st_gid; if (sgid < MAXGID && ++g[sgid] > maxgid) { savegid = sgid; maxgid = g[sgid]; } suid = p->fts_statp->st_uid; if (suid < MAXUID && ++u[suid] > maxuid) { saveuid = suid; maxuid = u[suid]; } /* * XXX * note that the below will break when file flags * are extended beyond the first 4 bytes of each * half word of the flags */ #define FLAGS2IDX(f) ((f & 0xf) | ((f >> 12) & 0xf0)) sflags = p->fts_statp->st_flags; if (FLAGS2IDX(sflags) < MAXFLAGS && ++f[FLAGS2IDX(sflags)] > maxflags) { saveflags = sflags; maxflags = f[FLAGS2IDX(sflags)]; } } } /* * If the /set record is the same as the last one we do not need to output * a new one. So first we check to see if anything changed. Note that we * always output a /set record for the first directory. */ if ((((keys & F_UNAME) | (keys & F_UID)) && (*puid != saveuid)) || (((keys & F_GNAME) | (keys & F_GID)) && (*pgid != savegid)) || ((keys & F_MODE) && (*pmode != savemode)) || ((keys & F_FLAGS) && (*pflags != saveflags)) || (first)) { first = 0; if (dflag) (void)printf("/set type=dir"); else (void)printf("/set type=file"); if (keys & F_UNAME) { pw = getpwuid(saveuid); if (pw != NULL) (void)printf(" uname=%s", pw->pw_name); else if (wflag) warnx( "Could not get uname for uid=%u", saveuid); else errx(1, "Could not get uname for uid=%u", saveuid); } if (keys & F_UID) (void)printf(" uid=%lu", (u_long)saveuid); if (keys & F_GNAME) { gr = getgrgid(savegid); if (gr != NULL) (void)printf(" gname=%s", gr->gr_name); else if (wflag) warnx("Could not get gname for gid=%u", savegid); else errx(1, "Could not get gname for gid=%u", savegid); } if (keys & F_GID) (void)printf(" gid=%lu", (u_long)savegid); if (keys & F_MODE) (void)printf(" mode=%#o", savemode); if (keys & F_NLINK) (void)printf(" nlink=1"); if (keys & F_FLAGS) { fflags = flags_to_string(saveflags); (void)printf(" flags=%s", fflags); free(fflags); } (void)printf("\n"); *puid = saveuid; *pgid = savegid; *pmode = savemode; *pflags = saveflags; } return (0); }
static int statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode) { FTSENT *p; gid_t sgid; uid_t suid; mode_t smode; struct group *gr; struct passwd *pw; gid_t savegid = *pgid; uid_t saveuid = *puid; mode_t savemode = *pmode; int maxgid; int maxuid; u_short maxmode; gid_t g[MAXGID]; uid_t u[MAXUID]; mode_t m[MAXMODE]; static int first = 1; if ((p = fts_children(t, 0)) == NULL) { if (errno) error("%s: %s", RP(parent), strerror(errno)); return (1); } bzero(g, sizeof(g)); bzero(u, sizeof(u)); bzero(m, sizeof(m)); maxuid = maxgid = maxmode = 0; for (; p; p = p->fts_link) { if (!dflag || (dflag && S_ISDIR(p->fts_statp->st_mode))) { smode = p->fts_statp->st_mode & MBITS; if (smode < MAXMODE && ++m[smode] > maxmode) { savemode = smode; maxmode = m[smode]; } sgid = p->fts_statp->st_gid; if (sgid < MAXGID && ++g[sgid] > maxgid) { savegid = sgid; maxgid = g[sgid]; } suid = p->fts_statp->st_uid; if (suid < MAXUID && ++u[suid] > maxuid) { saveuid = suid; maxuid = u[suid]; } } } /* * If the /set record is the same as the last one we do not need to output * a new one. So first we check to see if anything changed. Note that we * always output a /set record for the first directory. */ if ((((keys & F_UNAME) | (keys & F_UID)) && (*puid != saveuid)) || (((keys & F_GNAME) | (keys & F_GID)) && (*pgid != savegid)) || ((keys & F_MODE) && (*pmode != savemode)) || (first)) { first = 0; if (dflag) (void)printf("/set type=dir"); else (void)printf("/set type=file"); if (keys & F_UNAME) { if ((pw = getpwuid(saveuid)) != NULL) (void)printf(" uname=%s", pw->pw_name); else error("could not get uname for uid=%u", saveuid); } if (keys & F_UID) (void)printf(" uid=%u", saveuid); if (keys & F_GNAME) { if ((gr = getgrgid(savegid)) != NULL) (void)printf(" gname=%s", gr->gr_name); else error("could not get gname for gid=%u", savegid); } if (keys & F_GID) (void)printf(" gid=%u", savegid); if (keys & F_MODE) (void)printf(" mode=%#o", savemode); if (keys & F_NLINK) (void)printf(" nlink=1"); (void)printf("\n"); *puid = saveuid; *pgid = savegid; *pmode = savemode; } return (0); }
static int cmd_mkdb(cmdint_t *ci, int argc, char **argv) { NEED_ARGS(3); RP(mdb_DBCreate(argv[1], argv[2], &ci->db)); return OK; }
void CollocationIntegratorInternal::init(){ // Call the base class init IntegratorInternal::init(); // Legendre collocation points double legendre_points[][6] = { {0}, {0,0.500000}, {0,0.211325,0.788675}, {0,0.112702,0.500000,0.887298}, {0,0.069432,0.330009,0.669991,0.930568}, {0,0.046910,0.230765,0.500000,0.769235,0.953090}}; // Radau collocation points double radau_points[][6] = { {0}, {0,1.000000}, {0,0.333333,1.000000}, {0,0.155051,0.644949,1.000000}, {0,0.088588,0.409467,0.787659,1.000000}, {0,0.057104,0.276843,0.583590,0.860240,1.000000}}; // Read options bool use_radau; if(getOption("collocation_scheme")=="radau"){ use_radau = true; } else if(getOption("collocation_scheme")=="legendre"){ use_radau = false; } // Hotstart? hotstart_ = getOption("hotstart"); // Number of finite elements int nk = getOption("number_of_finite_elements"); // Interpolation order int deg = getOption("interpolation_order"); // Assume explicit ODE bool explicit_ode = f_.input(DAE_XDOT).size()==0; // All collocation time points double* tau_root = use_radau ? radau_points[deg] : legendre_points[deg]; // Size of the finite elements double h = (tf_-t0_)/nk; // MX version of the same MX h_mx = h; // Coefficients of the collocation equation vector<vector<MX> > C(deg+1,vector<MX>(deg+1)); // Coefficients of the continuity equation vector<MX> D(deg+1); // Collocation point SXMatrix tau = ssym("tau"); // For all collocation points for(int j=0; j<deg+1; ++j){ // Construct Lagrange polynomials to get the polynomial basis at the collocation point SXMatrix L = 1; for(int j2=0; j2<deg+1; ++j2){ if(j2 != j){ L *= (tau-tau_root[j2])/(tau_root[j]-tau_root[j2]); } } SXFunction lfcn(tau,L); lfcn.init(); // Evaluate the polynomial at the final time to get the coefficients of the continuity equation lfcn.setInput(1.0); lfcn.evaluate(); D[j] = lfcn.output(); // Evaluate the time derivative of the polynomial at all collocation points to get the coefficients of the continuity equation for(int j2=0; j2<deg+1; ++j2){ lfcn.setInput(tau_root[j2]); lfcn.setFwdSeed(1.0); lfcn.evaluate(1,0); C[j][j2] = lfcn.fwdSens(); } } // Initial state MX X0("X0",nx_); // Parameters MX P("P",np_); // Backward state MX RX0("RX0",nrx_); // Backward parameters MX RP("RP",nrp_); // Collocated differential states and algebraic variables int nX = (nk*(deg+1)+1)*(nx_+nrx_); int nZ = nk*deg*(nz_+nrz_); // Unknowns MX V("V",nX+nZ); int offset = 0; // Get collocated states, algebraic variables and times vector<vector<MX> > X(nk+1); vector<vector<MX> > RX(nk+1); vector<vector<MX> > Z(nk); vector<vector<MX> > RZ(nk); coll_time_.resize(nk+1); for(int k=0; k<nk+1; ++k){ // Number of time points int nj = k==nk ? 1 : deg+1; // Allocate differential states expressions at the time points X[k].resize(nj); RX[k].resize(nj); coll_time_[k].resize(nj); // Allocate algebraic variable expressions at the collocation points if(k!=nk){ Z[k].resize(nj-1); RZ[k].resize(nj-1); } // For all time points for(int j=0; j<nj; ++j){ // Get expressions for the differential state X[k][j] = V[range(offset,offset+nx_)]; offset += nx_; RX[k][j] = V[range(offset,offset+nrx_)]; offset += nrx_; // Get the local time coll_time_[k][j] = h*(k + tau_root[j]); // Get expressions for the algebraic variables if(j>0){ Z[k][j-1] = V[range(offset,offset+nz_)]; offset += nz_; RZ[k][j-1] = V[range(offset,offset+nrz_)]; offset += nrz_; } } } // Check offset for consistency casadi_assert(offset==V.size()); // Constraints vector<MX> g; g.reserve(2*(nk+1)); // Quadrature expressions MX QF = MX::zeros(nq_); MX RQF = MX::zeros(nrq_); // Counter int jk = 0; // Add initial condition g.push_back(X[0][0]-X0); // For all finite elements for(int k=0; k<nk; ++k, ++jk){ // For all collocation points for(int j=1; j<deg+1; ++j, ++jk){ // Get the time MX tkj = coll_time_[k][j]; // Get an expression for the state derivative at the collocation point MX xp_jk = 0; for(int j2=0; j2<deg+1; ++j2){ xp_jk += C[j2][j]*X[k][j2]; } // Add collocation equations to the NLP vector<MX> f_in(DAE_NUM_IN); f_in[DAE_T] = tkj; f_in[DAE_P] = P; f_in[DAE_X] = X[k][j]; f_in[DAE_Z] = Z[k][j-1]; vector<MX> f_out; if(explicit_ode){ // Assume equation of the form ydot = f(t,y,p) f_out = f_.call(f_in); g.push_back(h_mx*f_out[DAE_ODE] - xp_jk); } else { // Assume equation of the form 0 = f(t,y,ydot,p) f_in[DAE_XDOT] = xp_jk/h_mx; f_out = f_.call(f_in); g.push_back(f_out[DAE_ODE]); } // Add the algebraic conditions if(nz_>0){ g.push_back(f_out[DAE_ALG]); } // Add the quadrature if(nq_>0){ QF += D[j]*h_mx*f_out[DAE_QUAD]; } // Now for the backward problem if(nrx_>0){ // Get an expression for the state derivative at the collocation point MX rxp_jk = 0; for(int j2=0; j2<deg+1; ++j2){ rxp_jk += C[j2][j]*RX[k][j2]; } // Add collocation equations to the NLP vector<MX> g_in(RDAE_NUM_IN); g_in[RDAE_T] = tkj; g_in[RDAE_X] = X[k][j]; g_in[RDAE_Z] = Z[k][j-1]; g_in[RDAE_P] = P; g_in[RDAE_RP] = RP; g_in[RDAE_RX] = RX[k][j]; g_in[RDAE_RZ] = RZ[k][j-1]; vector<MX> g_out; if(explicit_ode){ // Assume equation of the form xdot = f(t,x,p) g_out = g_.call(g_in); g.push_back(h_mx*g_out[RDAE_ODE] - rxp_jk); } else { // Assume equation of the form 0 = f(t,x,xdot,p) g_in[RDAE_XDOT] = xp_jk/h_mx; g_in[RDAE_RXDOT] = rxp_jk/h_mx; g_out = g_.call(g_in); g.push_back(g_out[RDAE_ODE]); } // Add the algebraic conditions if(nrz_>0){ g.push_back(g_out[RDAE_ALG]); } // Add the backward quadrature if(nrq_>0){ RQF += D[j]*h_mx*g_out[RDAE_QUAD]; } } } // Get an expression for the state at the end of the finite element MX xf_k = 0; for(int j=0; j<deg+1; ++j){ xf_k += D[j]*X[k][j]; } // Add continuity equation to NLP g.push_back(X[k+1][0] - xf_k); if(nrx_>0){ // Get an expression for the state at the end of the finite element MX rxf_k = 0; for(int j=0; j<deg+1; ++j){ rxf_k += D[j]*RX[k][j]; } // Add continuity equation to NLP g.push_back(RX[k+1][0] - rxf_k); } } // Add initial condition for the backward integration if(nrx_>0){ g.push_back(RX[nk][0]-RX0); } // Constraint expression MX gv = vertcat(g); // Make sure that the dimension is consistent with the number of unknowns casadi_assert_message(gv.size()==V.size(),"Implicit function unknowns and equations do not match"); // Nonlinear constraint function input vector<MX> gfcn_in(1+INTEGRATOR_NUM_IN); gfcn_in[0] = V; gfcn_in[1+INTEGRATOR_X0] = X0; gfcn_in[1+INTEGRATOR_P] = P; gfcn_in[1+INTEGRATOR_RX0] = RX0; gfcn_in[1+INTEGRATOR_RP] = RP; vector<MX> gfcn_out(1+INTEGRATOR_NUM_OUT); gfcn_out[0] = gv; gfcn_out[1+INTEGRATOR_XF] = X[nk][0]; gfcn_out[1+INTEGRATOR_QF] = QF; gfcn_out[1+INTEGRATOR_RXF] = RX[0][0]; gfcn_out[1+INTEGRATOR_RQF] = RQF; // Nonlinear constraint function FX gfcn = MXFunction(gfcn_in,gfcn_out); // Expand f? bool expand_f = getOption("expand_f"); if(expand_f){ gfcn.init(); gfcn = SXFunction(shared_cast<MXFunction>(gfcn)); } // Get the NLP creator function implicitFunctionCreator implicit_function_creator = getOption("implicit_solver"); // Allocate an NLP solver implicit_solver_ = implicit_function_creator(gfcn); // Pass options if(hasSetOption("implicit_solver_options")){ const Dictionary& implicit_solver_options = getOption("implicit_solver_options"); implicit_solver_.setOption(implicit_solver_options); } // Initialize the solver implicit_solver_.init(); if(hasSetOption("startup_integrator")){ // Create the linear solver integratorCreator startup_integrator_creator = getOption("startup_integrator"); // Allocate an NLP solver startup_integrator_ = startup_integrator_creator(f_,g_); // Pass options startup_integrator_.setOption("number_of_fwd_dir",0); // not needed startup_integrator_.setOption("number_of_adj_dir",0); // not needed startup_integrator_.setOption("t0",coll_time_.front().front()); startup_integrator_.setOption("tf",coll_time_.back().back()); if(hasSetOption("startup_integrator_options")){ const Dictionary& startup_integrator_options = getOption("startup_integrator_options"); startup_integrator_.setOption(startup_integrator_options); } // Initialize the startup integrator startup_integrator_.init(); } // Mark the system not yet integrated integrated_once_ = false; }
INT32 ret = RLONG(SP()); SP() += 0x20; return ret; } /*************************************************************************** PIXEL READS ***************************************************************************/ #define RP(m1,m2) \ /* TODO: Plane masking */ \ return (TMS34010_RDMEM_WORD(TOBYTE(offset & 0xfffffff0)) >> (offset & m1)) & m2; UINT32 tms340x0_device::read_pixel_1(offs_t offset) { RP(0x0f,0x01) } UINT32 tms340x0_device::read_pixel_2(offs_t offset) { RP(0x0e,0x03) } UINT32 tms340x0_device::read_pixel_4(offs_t offset) { RP(0x0c,0x0f) } UINT32 tms340x0_device::read_pixel_8(offs_t offset) { RP(0x08,0xff) } UINT32 tms340x0_device::read_pixel_16(offs_t offset) { /* TODO: Plane masking */ return TMS34010_RDMEM_WORD(TOBYTE(offset & 0xfffffff0)); } UINT32 tms340x0_device::read_pixel_32(offs_t offset) { /* TODO: Plane masking */ return TMS34010_RDMEM_DWORD(TOBYTE(offset & 0xffffffe0)); } /* Shift register read */
static int cmd_lsdb(cmdint_t *ci, int argc, char **argv) { NEED_ARGS(1); RP(mdb_DBShowList()); return OK; }
vwalk() { extern int ftsoptions, dflag, eflag, rflag; register FTS *t; register FTSENT *p; register NODE *ep, *level; char *argv[2]; int ftsdepth = 0, specdepth = 0; argv[0] = "."; argv[1] = (char *)NULL; if (!(t = fts_open(argv, ftsoptions, (int (*)())NULL))) { (void)fprintf(stderr, "mtree: fts_open: %s.\n", strerror(errno)); exit(1); } level = root; while (p = fts_read(t)) { switch(p->fts_info) { case FTS_D: if (!strcmp(p->fts_name, ".")) continue; ftsdepth++; break; case FTS_DP: ftsdepth--; if (specdepth > ftsdepth) { for (level = level->parent; level->prev; level = level->prev); specdepth--; } continue; case FTS_DNR: case FTS_ERR: case FTS_NS: (void)fprintf(stderr, "mtree: %s: %s.\n", RP(p), strerror(errno)); continue; default: if (dflag) continue; } for (ep = level; ep; ep = ep->next) if (ep->flags & F_MAGIC && fnmatch(ep->name, p->fts_name, FNM_PATHNAME|FNM_QUOTE) || !strcmp(ep->name, p->fts_name)) { ep->flags |= F_VISIT; if (ep->flags & F_IGN) { (void)fts_set(t, p, FTS_SKIP); continue; } compare(ep->name, ep, p); if (ep->child && ep->type == F_DIR && p->fts_info == FTS_D) { level = ep->child; specdepth++; } break; } if (ep) continue; if (!eflag) { (void)printf("extra: %s", RP(p)); if (rflag) { if (unlink(p->fts_accpath)) { (void)printf(", not removed: %s", strerror(errno)); } else (void)printf(", removed"); } (void)putchar('\n'); } (void)fts_set(t, p, FTS_SKIP); } (void)fts_close(t); }
static int runcmd(cmdint_t *ci, char *cmdline) { int res; int i; int argc; char *argv[MAX_ARGS]; char *cmd; char *oldcmd; static char delim[] = " \t\n\r"; if (cmdline[0] == '#') { return OK; } oldcmd = strnew(cmdline); argc = 0; cmd = strtok(cmdline, delim); while(cmd != NULL && argc < MAX_ARGS) { argv[argc++] = cmd; cmd = strtok(NULL, delim); } if (argc == 0) { free(oldcmd); return OK; } cmd = argv[0]; res = INVALID_CMD; if (cmd[0] == '.') { res = runscript(ci, &cmd[1]); } else { for (i = 0; fntab[i].fn != NULL; i++) { if (strcmp(fntab[i].name, cmd) == 0) { res = fntab[i].fn(ci, argc, argv); break; } } } if (res == INVALID_CMD) { genrec_t *rec; RC rc = RC_OK; rec = NULL; if (ci->db != NULL) { rc = mdb_QueryDo(ci->db, oldcmd, &rec); if (rc != RC_COMPILATIONERROR) { RP(rc); } if (rec != NULL) { RP(mdb_GenrecShow(rec)); RP(mdb_GenrecFree(&rec)); } } if (rc != RC_COMPILATIONERROR && ci->db != NULL) { res = OK; } } switch(res) { case INVALID_CMD: fprintf(stderr, "Invalid command: %s\n", cmd); break; case SCRIPT_NOT_FOUND: fprintf(stderr, "script not found: %s\n", &cmd[1]); break; case WRONG_ARGC: fprintf(stderr, "%s: Incorrect number of arguments\n", cmd); break; } free(oldcmd); return res; }
static int statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, u_long *pflags) { FTSENT *p; gid_t sgid; uid_t suid; mode_t smode; u_long sflags = 0; const char *name; gid_t savegid; uid_t saveuid; mode_t savemode; u_long saveflags; u_short maxgid, maxuid, maxmode, maxflags; u_short g[MTREE_MAXGID], u[MTREE_MAXUID], m[MTREE_MAXMODE], f[MTREE_MAXFLAGS]; static int first = 1; savegid = *pgid; saveuid = *puid; savemode = *pmode; saveflags = *pflags; if ((p = fts_children(t, 0)) == NULL) { if (errno) mtree_err("%s: %s", RP(parent), strerror(errno)); return (1); } memset(g, 0, sizeof(g)); memset(u, 0, sizeof(u)); memset(m, 0, sizeof(m)); memset(f, 0, sizeof(f)); maxuid = maxgid = maxmode = maxflags = 0; for (; p; p = p->fts_link) { smode = p->fts_statp->st_mode & MBITS; if (smode < MTREE_MAXMODE && ++m[smode] > maxmode) { savemode = smode; maxmode = m[smode]; } sgid = p->fts_statp->st_gid; if (sgid < MTREE_MAXGID && ++g[sgid] > maxgid) { savegid = sgid; maxgid = g[sgid]; } suid = p->fts_statp->st_uid; if (suid < MTREE_MAXUID && ++u[suid] > maxuid) { saveuid = suid; maxuid = u[suid]; } #if HAVE_STRUCT_STAT_ST_FLAGS sflags = FLAGS2INDEX(p->fts_statp->st_flags); if (sflags < MTREE_MAXFLAGS && ++f[sflags] > maxflags) { saveflags = p->fts_statp->st_flags; maxflags = f[sflags]; } #endif } /* * If the /set record is the same as the last one we do not need to * output a new one. So first we check to see if anything changed. * Note that we always output a /set record for the first directory. */ if (((keys & (F_UNAME | F_UID)) && (*puid != saveuid)) || ((keys & (F_GNAME | F_GID)) && (*pgid != savegid)) || ((keys & F_MODE) && (*pmode != savemode)) || ((keys & F_FLAGS) && (*pflags != saveflags)) || first) { first = 0; printf("/set type=file"); if (keys & (F_UID | F_UNAME)) { if (keys & F_UNAME && (name = user_from_uid(saveuid, 1)) != NULL) printf(" uname=%s", name); else /* if (keys & F_UID) */ printf(" uid=%lu", (u_long)saveuid); } if (keys & (F_GID | F_GNAME)) { if (keys & F_GNAME && (name = group_from_gid(savegid, 1)) != NULL) printf(" gname=%s", name); else /* if (keys & F_UID) */ printf(" gid=%lu", (u_long)savegid); } if (keys & F_MODE) printf(" mode=%#lo", (u_long)savemode); if (keys & F_NLINK) printf(" nlink=1"); if (keys & F_FLAGS) printf(" flags=%s", flags_to_string(saveflags, "none")); printf("\n"); *puid = saveuid; *pgid = savegid; *pmode = savemode; *pflags = saveflags; } return (0); }
void TestPrecession::testPrecessionAnglesVondrak() { const double S=sin(eps0); const double C=cos(eps0); double Z, W; double JulianDay=1219339.078000; // TT double epsilon_A, chi_A, omega_A, psi_A; double P_A, Q_A, X_A, Y_A; double VEC2, VEC3, VEQ3; // get angles for Capitaine parameterisation getPrecessionAnglesVondrak(JulianDay, &epsilon_A, &chi_A, &omega_A, &psi_A); // Get reference angles. We have to call this twice with different dates to avoid returning the cached (zero) angles. getPrecessionAnglesVondrakPQXYe(-1234.567, &P_A, &Q_A, &X_A, &Y_A, &epsilon_A); getPrecessionAnglesVondrakPQXYe(JulianDay, &P_A, &Q_A, &X_A, &Y_A, &epsilon_A); Z=sqrt(qMax(1.0-P_A*P_A-Q_A*Q_A, 0.0)); W=X_A*X_A+Y_A*Y_A; VEC2=-Q_A*C -Z*S; VEC3=-Q_A*S +Z*C; VEQ3=(W<1.0 ? sqrt(1.0-W) : 0.0); QVERIFY2(fabs(P_A -0.00041724785764001342)<=0.000001, QString("JD %1: Pecl,x: %2 Difference: %3").arg(JulianDay).arg(P_A ).arg(P_A -0.00041724785764001342).toUtf8()); QVERIFY2(fabs(VEC2+0.40495491104576162693)<=0.000001, QString("JD %1: Pecl,y: %2 Difference: %3").arg(JulianDay).arg(VEC2).arg(VEC2+0.40495491104576162693).toUtf8()); QVERIFY2(fabs(VEC3-0.91433656053126552350)<=0.000001, QString("JD %1: Pecl,z: %2 Difference: %3").arg(JulianDay).arg(VEC3).arg(VEC3-0.91433656053126552350).toUtf8()); QVERIFY2(fabs(X_A +0.29437643797369031532)<=0.000001, QString("JD %1: Pequ,x: %2 Difference: %3").arg(JulianDay).arg(X_A ).arg(X_A +0.29437643797369031532).toUtf8()); QVERIFY2(fabs(Y_A +0.11719098023370257855)<=0.000001, QString("JD %1: Pequ,y: %2 Difference: %3").arg(JulianDay).arg(Y_A ).arg(Y_A +0.11719098023370257855).toUtf8()); QVERIFY2(fabs(VEQ3-0.94847708824082091796)<=0.000001, QString("JD %1: Pequ,z: %2 Difference: %3").arg(JulianDay).arg(VEQ3).arg(VEQ3-0.94847708824082091796).toUtf8()); // the same, to be seen ... // qDebug() << QString("JD %1: Pecl,x: %2 Difference: %3").arg(JulianDay, 8, 'f', 5).arg(P_A , 15, 'f', 12).arg(P_A -0.00041724785764001342, 15, 'f', 12); // qDebug() << QString("JD %1: Pecl,y: %2 Difference: %3").arg(JulianDay, 8, 'f', 5).arg(VEC2, 15, 'f', 12).arg(VEC2+0.40495491104576162693, 15, 'f', 12); // qDebug() << QString("JD %1: Pecl,z: %2 Difference: %3").arg(JulianDay, 8, 'f', 5).arg(VEC3, 15, 'f', 12).arg(VEC3-0.91433656053126552350, 15, 'f', 12); // qDebug() << QString("JD %1: Pequ,x: %2 Difference: %3").arg(JulianDay, 8, 'f', 5).arg(X_A , 15, 'f', 12).arg(X_A +0.29437643797369031532, 15, 'f', 12); // qDebug() << QString("JD %1: Pequ,y: %2 Difference: %3").arg(JulianDay, 8, 'f', 5).arg(Y_A , 15, 'f', 12).arg(Y_A +0.11719098023370257855, 15, 'f', 12); // qDebug() << QString("JD %1: Pequ,z: %2 Difference: %3").arg(JulianDay, 8, 'f', 5).arg(VEQ3, 15, 'f', 12).arg(VEQ3-0.94847708824082091796, 15, 'f', 12); Vec3d PECL(P_A, VEC2, VEC3); Vec3d PEQR(X_A, Y_A, VEQ3); Vec3d EQX=PEQR^PECL; EQX.normalize(); Vec3d V=PEQR^EQX; Mat3d RP(EQX[0], EQX[1], EQX[2], V[0], V[1], V[2], PEQR[0], PEQR[1], PEQR[2]); // result from paper, section A.3 // Now we create the (hopefully) same rotation matrix from the Capitaine angles. // Mat4d Rrot=Mat4d::zrotation(chi_A) * Mat4d::xrotation(-omega_A) * Mat4d::zrotation(-psi_A) * Mat4d::xrotation(eps0); // Uh-oh - it seems the A&A paper has the matrix operations in the other direction. // So the matrix to be compared must be composed in reverse. Mat4d RRot=Mat4d::xrotation(eps0)*Mat4d::zrotation(-psi_A) * Mat4d::xrotation(-omega_A) * Mat4d::zrotation(chi_A); //qDebug() << "RP : " << RP.toString(15, 'f', 12); //qDebug() << "RcapTr : " << RRot.upper3x3().toString(15, 'f', 12); Mat4d RP4(EQX[0], EQX[1], EQX[2], 0, V[0], V[1], V[2], 0, PEQR[0], PEQR[1], PEQR[2], 0, 0, 0, 0, 1); //QMatrix4x4 matDiff=((RRot-RP4)).convertToQMatrix(); //qDebug() << matDiff; Mat3d matDiff3x3=(RRot-RP4).upper3x3(); double max=0.0; for (int i=0; i<9; ++i) { if (fabs(matDiff3x3[i]) > max) max=fabs(matDiff3x3[i]); } //qDebug() << "largest value in difference of matrices:" << max; QVERIFY2(max<2e-5, QString("Some values in the precession matrices differ by too much.").toUtf8()); double angleRef=RP.angle()*180.0/M_PI; double angleCap=RRot.upper3x3().angle()*180.0/M_PI; //qDebug() << "Rotation angle of reference matrix:" << angleRef; //qDebug() << "Rotation angle of Capitaine matrix:" << angleCap; //qDebug() << "Difference (arcseconds):" << (angleCap-angleRef)*3600.0; // according to Fig12 in the paper, a few arcseconds of difference between PQXY and Capitaine parametrisation are allowed. QVERIFY2((angleCap-angleRef)*3600.0<6.0, QString("Angle between rotation matrices too different!").toUtf8()); //TODO: Add more dates and verify this angle difference is limited to what we can see in Fig.12 }
// Get the silicon pin for a pin static unsigned int pin_number_64(unsigned int pin) { switch (pin) { case RP('E',5) : return 1; case RP('E',6) : return 2; case RP('E',7) : return 3; case RP('G',6) : return 4; case RP('G',7) : return 5; case RP('G',8) : return 6; case RP('G',9) : return 10; case RP('B',5) : return 11; case RP('B',4) : return 12; case RP('B',3) : return 13; case RP('B',2) : return 14; case RP('B',1) : return 15; case RP('B',0) : return 16; case RP('B',6) : return 17; case RP('B',7) : return 18; case RP('B',8) : return 21; case RP('B',9) : return 22; case RP('B',10): return 23; case RP('B',11): return 24; case RP('B',12): return 27; case RP('B',13): return 28; case RP('B',14): return 29; case RP('B',15): return 30; case RP('C',12): return 31; case RP('C',15): return 32; case RP('F',3) : return 38; case RP('F',4) : return 41; case RP('F',5) : return 42; case RP('D',9) : return 43; case RP('D',10): return 44; case RP('D',11): return 45; case RP('D',0) : return 46; case RP('C',13): return 47; case RP('C',14): return 48; case RP('D',1) : return 49; case RP('D',2) : return 50; case RP('D',3) : return 51; case RP('D',4) : return 52; case RP('D',5) : return 53; case RP('F',0) : return 56; case RP('F',1) : return 57; case RP('E',0) : return 58; case RP('E',1) : return 61; case RP('E',2) : return 62; case RP('E',3) : return 63; case RP('E',4) : return 64; } return 0; }
static int cmd_lddb(cmdint_t *ci, int argc, char **argv) { NEED_ARGS(2); RP(mdb_DBOpen(argv[1], &ci->db)); return OK; }