static A jttayamp(J jt,A w,B nf,A x,A h){A y;B ng=!nf;I j,n;V*v=VAV(h); ASSERT(AR(x)<=(nf?v->lr:v->rr),EVRANK); switch(v->id){ case CPLUS: R tpoly(over(x,one)); case CMINUS: R tpoly(nf?over(x,num[-1]):over(negate(x),one)); case CSTAR: R tpoly(over(zero,x)); case CDIV: ASSERT(ng,EVDOMAIN); R tpoly(over(zero,recip(x))); case CJDOT: R tpoly(nf?over(x,a0j1):over(jdot1(x),one)); case CPOLY: ASSERT(nf,EVDOMAIN); R tpoly(BOX&AT(x)?poly1(x):x); case CHGEOM: ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); y=IX(j); R tpoly(divide(hgcoeff(y,h),fact(y))); case CBANG: ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); R tpoly(divide(poly1(box(iota(x))),fact(x))); case CEXP: if(nf)R eva(x,"(^.x)&^ % !"); RE(n=i0(x)); R 0<=n?tpoly(over(reshape(x,zero),one)):atop(ds(CDIV),amp(h,sc(-n))); case CFIT: ASSERT(nf&&CPOLY==ID(v->f),EVDOMAIN); y=over(x,IX(IC(x))); R tpoly(mdiv(df2(x,y,h),atab(CEXP,y,IX(IC(x))))); case CCIRCLE: switch(i0(x)){ case 1: R eval("{&0 1 0 _1@(4&|) % !"); case -3: R eval("{&0 1 0 _1@(4&|) % ]"); case 2: R eval("{&1 0 _1 0@(4&|) % !"); case 5: R eval("2&| % !"); case -7: R eval("2&| % ]"); case 6: R eval("2&|@>: % !"); case -1: R eval("(2&| % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0"); case -5: R eval("({&0 1 0 _1@(4&|) % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0"); }} ASSERT(0,EVDOMAIN); }
void ResetQ(void* a) /* transforma coada in coada vida */ { ACel p = IC(a), aux; /* p - adresa primei celule */ while(p) { aux = p; p = p->urm; free(aux); } IC(a) = SC(a) = NULL; }
int ExtrQ(void *ac, void *ae) /* extrage primul element din coada la adresa ae */ { ACel p = IC(ac); /* p - adresa primei celule */ if(!p) return 0; /* coada vida -> "esec" */ memcpy(ae, &(p->info), DIME(ac)); /* preia informatia */ IC(ac) = p->urm; /* prima celula este scoasa din coada */ free(p); /* si distrusa */ if(!IC(ac)) SC(ac) = NULL; /* prin extragere coada a devenit vida */ return 1; /* operatie reusita -> "succes" */ }
static F1(jtfacit){A c;V*u,*v; RZ(c=coeff(w)); if(AN(c))R tpoly(tymes(c,fact(AT(c)&XNUM+RAT?xco1(IX(IC(c))):IX(IC(c))))); v=VAV(w); if(CFORK==v->id)switch(ID(v->g)){ case CDIV: if(CBANG==ID(v->h))R v->f; break; case CSTAR: if(CFORK==ID(v->h)&&(u=VAV(v->h),CDIV==ID(u->g)&&CBANG==ID(u->h)))R folk(v->f,v->g,u->f); RZ(c=atop(ds(CDIV),ds(CBANG))); if(equ(c,v->f))R v->h; if(equ(c,v->h))R v->f; } R folk(ds(CBANG),ds(CSTAR),w); }
void Stwart(vector<long>&IA,vector<long>&MA, vector<long>&JROW,vector<long>&JCOL) { static long M = JROW.size(); vector<long> IR(M),IC(M),R(M),C(M),IP(M),JP(M),IW(M); static long KERNS, MEND, LG, IER, L = MA[M]; // printf("M = %ld\n",M); // forVector(MA,i) printf("MA[%ld] = %ld\n",i,MA[i]); // forVector(IA,i) printf("IA[%ld] = %ld\n",i,IA[i]); // printf("L=%ld\n",L); // forVector(R,i) printf("R[%ld] = %ld\n",i,R[i]); // forVector(C,i) printf("C[%ld] = %ld\n",i,C[i]); // forVector(IR,i) printf("IR[%ld] = %ld\n",i,IR[i]); // forVector(IC,i) printf("IC[%ld] = %ld\n",i,IC[i]); // forVector(JROW,i) printf("JROW[%ld] = %ld\n",i,JROW[i]); // forVector(JCOL,i) printf("JCOL[%ld] = %ld\n",i,JCOL[i]); // forVector(IP,i) printf("IP[%ld] = %ld\n",i,IP[i]); // forVector(JP,i) printf("JP[%ld] = %ld\n",i,JP[i]); // forVector(IW,i) printf("IW[%ld] = %ld\n",i,IW[i]); printf("KERNS = %ld, MEND = %ld, LG = %ld, IER = %ld\n", KERNS, MEND, LG, IER); stwart_(&IA[0],&L,&MA[0],&M,&R[0],&C[0],&IR[0],&IC[0], &JROW[0],&JCOL[0],&IP[0],&JP[0],&KERNS,&MEND,&IW[0],&LG,&IER); }
/* output solution status for PPP --------------------------------------------*/ extern void pppoutsolstat(rtk_t *rtk, int level, FILE *fp) { ssat_t *ssat; double tow,pos[3],vel[3],acc[3]; int i,j,week,nfreq=1; char id[32]; if (level<=0||!fp) return; trace(3,"pppoutsolstat:\n"); tow=time2gpst(rtk->sol.time,&week); /* receiver position */ fprintf(fp,"$POS,%d,%.3f,%d,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f\n",week,tow, rtk->sol.stat,rtk->x[0],rtk->x[1],rtk->x[2],0.0,0.0,0.0); /* receiver velocity and acceleration */ if (rtk->opt.dynamics) { ecef2pos(rtk->sol.rr,pos); ecef2enu(pos,rtk->x+3,vel); ecef2enu(pos,rtk->x+6,acc); fprintf(fp,"$VELACC,%d,%.3f,%d,%.4f,%.4f,%.4f,%.5f,%.5f,%.5f,%.4f,%.4f,%.4f,%.5f,%.5f,%.5f\n", week,tow,rtk->sol.stat,vel[0],vel[1],vel[2],acc[0],acc[1],acc[2], 0.0,0.0,0.0,0.0,0.0,0.0); } /* receiver clocks */ i=IC(0,&rtk->opt); fprintf(fp,"$CLK,%d,%.3f,%d,%d,%.3f,%.3f,%.3f,%.3f\n", week,tow,rtk->sol.stat,1,rtk->x[i]*1E9/CLIGHT,rtk->x[i+1]*1E9/CLIGHT, 0.0,0.0); /* tropospheric parameters */ if (rtk->opt.tropopt==TROPOPT_EST||rtk->opt.tropopt==TROPOPT_ESTG) { i=IT(&rtk->opt); fprintf(fp,"$TROP,%d,%.3f,%d,%d,%.4f,%.4f\n",week,tow,rtk->sol.stat, 1,rtk->x[i],0.0); } if (rtk->opt.tropopt==TROPOPT_ESTG) { i=IT(&rtk->opt); fprintf(fp,"$TRPG,%d,%.3f,%d,%d,%.5f,%.5f,%.5f,%.5f\n",week,tow, rtk->sol.stat,1,rtk->x[i+1],rtk->x[i+2],0.0,0.0); } if (rtk->sol.stat==SOLQ_NONE||level<=1) return; /* residuals and status */ for (i=0;i<MAXSAT;i++) { ssat=rtk->ssat+i; if (!ssat->vs) continue; satno2id(i+1,id); for (j=0;j<nfreq;j++) { fprintf(fp,"$SAT,%d,%.3f,%s,%d,%.1f,%.1f,%.4f,%.4f,%d,%.0f,%d,%d,%d,%d,%d,%d\n", week,tow,id,j+1,ssat->azel[0]*R2D,ssat->azel[1]*R2D, ssat->resp[j],ssat->resc[j],ssat->vsat[j],ssat->snr[j]*0.25, ssat->fix[j],ssat->slip[j]&3,ssat->lock[j],ssat->outc[j], ssat->slipc[j],ssat->rejc[j]); } } }
size_t PrelQ(void* a, TF1 f) /* prelucreaza elementele, folosind functia f; rezultat = numarul de elemente pentru care f != 0 */ { size_t n = 0; ACel p = IC(a); /* p - adresa primei celule */ for(; p; p = p->urm) if(f(&(p->info))) n++; return n; }
static DF1(jtgsuffix){A h,*hv,z,*zv;I m,n,r; RZ(w); if(jt->rank&&jt->rank[1]<AR(w)){r=jt->rank[1]; jt->rank=0; R rank1ex(w,self,jt->rank[1],jtgsuffix);} jt->rank=0; n=IC(w); h=VAV(self)->h; hv=AAV(h); m=AN(h); GATV(z,BOX,n,1,0); zv=AAV(z); DO(n, RZ(zv[i]=df1(drop(sc(i),w),hv[i%m])););
void Dummy (EifList<int> &TestList) { int ex = TestList.ItCnt(); EifIterator it1 (TestList), it2, it3; ex++; IC (ex, TestList); it2 = it3; IC (ex, TestList); it2 = it1; ex++; IC (ex, TestList); }
void DummyIt(int Exp, EifIterator it, EifList<int> &TestList) { Exp++; IC (Exp, TestList); EifList <char *> StrList (True); StrList.Add ("Trevor"); }
static DF1(insert){PROLOG;A hs,*hv,z;I hn,j,k,m,n; RZ(w); m=IC(w); hs=VAV(self)->h; hn=AN(hs); hv=AAV(hs); if(!m)R df1(w,iden(*hv)); j=n=MAX(hn,m-1); RZ(z=AR(w)?from(sc(n%m),w):ca(w)); if(1==n)R z; DO(n, --j; k=j%hn; RZ(z=(VAV(hv[k])->f2)(from(sc(j%m),w),z,hv[k]))); EPILOG(z); }
double R(double x){ //Mills Ratio if (x > 4){ return 1.0 / x; } double N = IC(x); double D = IN(x); if (D < pow(10,-15)){ //machine epsilon return 1.0 / pow(10,-15); } return exp(log(1. - N)-log(D)); }
static DF1(reduce){PROLOG;DECLF;A y,z;C*u,*v;I c,k,m,old,t; RZ(w); m=IC(w); if(!m)R df1(w,iden(fs)); RZ(z=tail(w)); if(1==m)R z; t=AT(w); c=AN(z); GA(y,t,c,AR(z),AS(z)); u=CAV(y); k=SZT(t,c); v=CAV(w)+k*(m-1); old=tbase+ttop; DO(m-1, MC(u,v-=k,k); RZ(z=f2(y,z,fs)); gc(z,old)); EPILOG(z); }
int IntrQ(void *ac, void *ae) /* adauga element la sfarsitul cozii */ { ACel aux = (ACel)malloc(DIMC(ac)); /* aloca o noua celula */ if(!aux) return 0; /* alocare imposibila -> "esec" */ memcpy(&(aux->info), ae, DIME(ac)); /* completeaza celula */ aux->urm = NULL; if(SC(ac) == NULL) /* coada vida */ IC(ac) = aux; /* -> noua celula se afla la inceputul cozii */ else /* coada nevida */ SC(ac)->urm = aux; /* -> leaga celula dupa ultima din coada */ SC(ac) = aux; /* actualizeaza sfarsitul cozii */ return 1; /* operatie reusita -> "succes" */ }
static A jtmerge1(J jt,A w,A ind){A z;B*b;C*wc,*zc;D*wd,*zd;I c,it,j,k,m,r,*s,t,*u,*wi,*zi; RZ(w&&ind); r=MAX(0,AR(w)-1); s=1+AS(w); t=AT(w); k=bp(t); m=IC(w); c=aii(w); ASSERT(!(t&SPARSE),EVNONCE); ASSERT(r==AR(ind),EVRANK); ASSERT(!ICMP(s,AS(ind),r),EVLENGTH); GA(z,t,c,r,s); if(!(AT(ind)&B01+INT))RZ(ind=cvt(INT,ind)); it=AT(ind); u=AV(ind); b=(B*)u; ASSERT(!c||1<m||!(it&B01),EVINDEX); ASSERT(!c||1!=m||!memchr(b,C1,c),EVINDEX); zi=AV(z); zc=(C*)zi; zd=(D*)zc; wi=AV(w); wc=(C*)wi; wd=(D*)wc; switch(MCASE(it,k)){ case MCASE(B01,sizeof(C)): DO(c, *zc++=wc[*b++?i+c:i];); break; case MCASE(B01,sizeof(I)): DO(c, *zi++=wi[*b++?i+c:i];); break;
int MutaQ(void *ad, void *as) { ACel aux = IC(as); //initializare (1) if(IC(as)==NULL) return 0; //lista vida aux = IC(as); if (IC(as)->urm == NULL) //lista sursa are un element (2) { IC(as)=NULL; SC(as)=NULL; }else IC(as)=IC(as)->urm; aux->urm = NULL; // (3) if(IC(ad)==NULL) { IC(ad)=aux; //daca coada destinatie era vida SC(ad)=aux; }else{ SC(ad)->urm=aux; // (4) SC(ad)=aux; // (5) } return 1; }
/* temporal update of clock --------------------------------------------------*/ static void udclk_ppp(rtk_t *rtk) { double dtr; int i; trace(3,"udclk_ppp:\n"); /* initialize every epoch for clock (white noise) */ for (i=0;i<NSYS;i++) { if (rtk->opt.sateph==EPHOPT_PREC) { /* time of prec ephemeris is based gpst */ /* negelect receiver inter-system bias */ dtr=rtk->sol.dtr[0]; } else { dtr=i==0?rtk->sol.dtr[0]:rtk->sol.dtr[0]+rtk->sol.dtr[i]; } initx(rtk,CLIGHT*dtr,VAR_CLK,IC(i,&rtk->opt)); } }
static DF1(breduce){A z;B b,*u,*v,*x,*xx;I c,cv,d,m;SF f2;VA*p; RZ(w); /* AN(w)&&1<IC(w) */ m=IC(w); RZ(z=tail(w)); c=AN(z); x=BAV(z); v=BAV(w); p=vap(self); switch(1<c?0:p->bf){ case V0001: *x=memchr(v,C0,m)?0:1; R z; case V0111: *x=memchr(v,C1,m)?1:0; R z; case V1110: u=memchr(v,C0,m); d=u?u-v:m; *x=d%2!=d<m-1; R z; case V1000: u=memchr(v,C1,m); d=u?u-v:m; *x=d%2==d<m-1; R z; case V0010: u=memchr(v,C0,m); *x=(u?u-v:m)%2?1:0; R z; case V1011: u=memchr(v,C1,m); *x=(u?u-v:m)%2?0:1; R z; case V0100: *x= *(v+m-1)&&!memchr(v,C1,m-1)?1:0; R z; case V1101: *x=!*(v+m-1)&&!memchr(v,C0,m-1)?0:1; R z; case V0110: b=0; DO(m, b=b!=*v++); *x=b; R z; case V1001: b=1; DO(m, b=b==*v++); *x=b; R z; } switch(p->id){I*x,*xx; case CPLUS: RZ(z=cvt(INT,z)); x=AV(z); if(1==c){d=0; DO(m, if(*v++)d++); *x=d;} else{xx=x+=c; v+=c*(m-1); DO(m-1, DO(c, --x; *x=*--v+*x); x=xx);}
static F1(jttrc){A bot,p,*v,x,y;B b;C*bv,c,ul,ll,*pv;I j,k,m,*s,xn,*xv,yn,*yv; RZ(w); s=AS(w); v=AAV(w); xn=s[0]; RZ(x=apv(xn,0L,0L)); xv=AV(x); yn=s[1]; RZ(y=apv(yn,0L,0L)); yv=AV(y); j=0; DO(xn, xv[i]=IC(v[j]); j+=yn;);
/* phase and code residuals --------------------------------------------------*/ static int res_ppp(int iter, const obsd_t *obs, int n, const double *rs, const double *dts, const double *vare, const int *svh, const nav_t *nav, const double *x, rtk_t *rtk, double *v, double *H, double *R, double *azel) { prcopt_t *opt=&rtk->opt; double r,rr[3],disp[3],pos[3],e[3],meas[2],dtdx[3],dantr[NFREQ]={0}; double dants[NFREQ]={0},var[MAXOBS*2],dtrp=0.0,vart=0.0,varm[2]={0}; int i,j,k,sat,sys,nv=0,nx=rtk->nx,brk,tideopt; trace(3,"res_ppp : n=%d nx=%d\n",n,nx); for (i=0;i<MAXSAT;i++) rtk->ssat[i].vsat[0]=0; for (i=0;i<3;i++) rr[i]=x[i]; /* earth tides correction */ if (opt->tidecorr) { tideopt=opt->tidecorr==1?1:7; /* 1:solid, 2:solid+otl+pole */ tidedisp(gpst2utc(obs[0].time),rr,tideopt,&nav->erp,opt->odisp[0], disp); for (i=0;i<3;i++) rr[i]+=disp[i]; } ecef2pos(rr,pos); for (i=0;i<n&&i<MAXOBS;i++) { sat=obs[i].sat; if (!(sys=satsys(sat,NULL))||!rtk->ssat[sat-1].vs) continue; /* geometric distance/azimuth/elevation angle */ if ((r=geodist(rs+i*6,rr,e))<=0.0|| satazel(pos,e,azel+i*2)<opt->elmin) continue; /* excluded satellite? */ if (satexclude(obs[i].sat,svh[i],opt)) continue; /* tropospheric delay correction */ if (opt->tropopt==TROPOPT_SAAS) { dtrp=tropmodel(obs[i].time,pos,azel+i*2,REL_HUMI); vart=SQR(ERR_SAAS); } else if (opt->tropopt==TROPOPT_SBAS) { dtrp=sbstropcorr(obs[i].time,pos,azel+i*2,&vart); } else if (opt->tropopt==TROPOPT_EST||opt->tropopt==TROPOPT_ESTG) { dtrp=prectrop(obs[i].time,pos,azel+i*2,opt,x+IT(opt),dtdx,&vart); } else if (opt->tropopt==TROPOPT_COR||opt->tropopt==TROPOPT_CORG) { dtrp=prectrop(obs[i].time,pos,azel+i*2,opt,x,dtdx,&vart); } /* satellite antenna model */ if (opt->posopt[0]) { satantpcv(rs+i*6,rr,nav->pcvs+sat-1,dants); } /* receiver antenna model */ antmodel(opt->pcvr,opt->antdel[0],azel+i*2,opt->posopt[1],dantr); /* phase windup correction */ if (opt->posopt[2]) { windupcorr(rtk->sol.time,rs+i*6,rr,&rtk->ssat[sat-1].phw); } /* ionosphere and antenna phase corrected measurements */ if (!corrmeas(obs+i,nav,pos,azel+i*2,&rtk->opt,dantr,dants, rtk->ssat[sat-1].phw,meas,varm,&brk)) { continue; } /* satellite clock and tropospheric delay */ r+=-CLIGHT*dts[i*2]+dtrp; trace(5,"sat=%2d azel=%6.1f %5.1f dtrp=%.3f dantr=%6.3f %6.3f dants=%6.3f %6.3f phw=%6.3f\n", sat,azel[i*2]*R2D,azel[1+i*2]*R2D,dtrp,dantr[0],dantr[1],dants[0], dants[1],rtk->ssat[sat-1].phw); for (j=0;j<2;j++) { /* for phase and code */ if (meas[j]==0.0) continue; for (k=0;k<nx;k++) H[k+nx*nv]=0.0; v[nv]=meas[j]-r; for (k=0;k<3;k++) H[k+nx*nv]=-e[k]; if (sys!=SYS_GLO) { v[nv]-=x[IC(0,opt)]; H[IC(0,opt)+nx*nv]=1.0; } else { v[nv]-=x[IC(1,opt)]; H[IC(1,opt)+nx*nv]=1.0; } if (opt->tropopt>=TROPOPT_EST) { for (k=0;k<(opt->tropopt>=TROPOPT_ESTG?3:1);k++) { H[IT(opt)+k+nx*nv]=dtdx[k]; } } if (j==0) { v[nv]-=x[IB(obs[i].sat,opt)]; H[IB(obs[i].sat,opt)+nx*nv]=1.0; } var[nv]=varerr(obs[i].sat,sys,azel[1+i*2],j,opt)+varm[j]+vare[i]+vart; if (j==0) rtk->ssat[sat-1].resc[0]=v[nv]; else rtk->ssat[sat-1].resp[0]=v[nv]; /* test innovation */ #if 0 if (opt->maxinno>0.0&&fabs(v[nv])>opt->maxinno) { #else if (opt->maxinno>0.0&&fabs(v[nv])>opt->maxinno&&sys!=SYS_GLO) { #endif trace(2,"ppp outlier rejected %s sat=%2d type=%d v=%.3f\n", time_str(obs[i].time,0),sat,j,v[nv]); rtk->ssat[sat-1].rejc[0]++; continue; } if (j==0) rtk->ssat[sat-1].vsat[0]=1; nv++; } } for (i=0;i<nv;i++) for (j=0;j<nv;j++) { R[i+j*nv]=i==j?var[i]:0.0; } trace(5,"x=\n"); tracemat(5,x, 1,nx,8,3); trace(5,"v=\n"); tracemat(5,v, 1,nv,8,3); trace(5,"H=\n"); tracemat(5,H,nx,nv,8,3); trace(5,"R=\n"); tracemat(5,R,nv,nv,8,5); return nv; } /* number of estimated states ------------------------------------------------*/ extern int pppnx(const prcopt_t *opt) { return NX(opt); } /* precise point positioning -------------------------------------------------*/ extern void pppos(rtk_t *rtk, const obsd_t *obs, int n, const nav_t *nav) { const prcopt_t *opt=&rtk->opt; double *rs,*dts,*var,*v,*H,*R,*azel,*xp,*Pp; int i,nv,info,svh[MAXOBS],stat=SOLQ_SINGLE; trace(3,"pppos : nx=%d n=%d\n",rtk->nx,n); rs=mat(6,n); dts=mat(2,n); var=mat(1,n); azel=zeros(2,n); for (i=0;i<MAXSAT;i++) rtk->ssat[i].fix[0]=0; /* temporal update of states */ udstate_ppp(rtk,obs,n,nav); trace(4,"x(0)="); tracemat(4,rtk->x,1,NR(opt),13,4); /* satellite positions and clocks */ satposs(obs[0].time,obs,n,nav,rtk->opt.sateph,rs,dts,var,svh); /* exclude measurements of eclipsing satellite */ if (rtk->opt.posopt[3]) { testeclipse(obs,n,nav,rs); } xp=mat(rtk->nx,1); Pp=zeros(rtk->nx,rtk->nx); matcpy(xp,rtk->x,rtk->nx,1); nv=n*rtk->opt.nf*2; v=mat(nv,1); H=mat(rtk->nx,nv); R=mat(nv,nv); for (i=0;i<rtk->opt.niter;i++) { /* phase and code residuals */ if ((nv=res_ppp(i,obs,n,rs,dts,var,svh,nav,xp,rtk,v,H,R,azel))<=0) break; /* measurement update */ matcpy(Pp,rtk->P,rtk->nx,rtk->nx); if ((info=filter(xp,Pp,H,v,R,rtk->nx,nv))) { trace(2,"ppp filter error %s info=%d\n",time_str(rtk->sol.time,0), info); break; } trace(4,"x(%d)=",i+1); tracemat(4,xp,1,NR(opt),13,4); stat=SOLQ_PPP; } if (stat==SOLQ_PPP) { /* postfit residuals */ res_ppp(1,obs,n,rs,dts,var,svh,nav,xp,rtk,v,H,R,azel); /* update state and covariance matrix */ matcpy(rtk->x,xp,rtk->nx,1); matcpy(rtk->P,Pp,rtk->nx,rtk->nx); /* ambiguity resolution in ppp */ if (opt->modear==ARMODE_PPPAR||opt->modear==ARMODE_PPPAR_ILS) { if (pppamb(rtk,obs,n,nav,azel)) stat=SOLQ_FIX; } /* update solution status */ rtk->sol.ns=0; for (i=0;i<n&&i<MAXOBS;i++) { if (!rtk->ssat[obs[i].sat-1].vsat[0]) continue; rtk->ssat[obs[i].sat-1].lock[0]++; rtk->ssat[obs[i].sat-1].outc[0]=0; rtk->ssat[obs[i].sat-1].fix [0]=4; rtk->sol.ns++; } rtk->sol.stat=stat; for (i=0;i<3;i++) { rtk->sol.rr[i]=rtk->x[i]; rtk->sol.qr[i]=(float)rtk->P[i+i*rtk->nx]; } rtk->sol.qr[3]=(float)rtk->P[1]; rtk->sol.qr[4]=(float)rtk->P[2+rtk->nx]; rtk->sol.qr[5]=(float)rtk->P[2]; rtk->sol.dtr[0]=rtk->x[IC(0,opt)]; rtk->sol.dtr[1]=rtk->x[IC(1,opt)]-rtk->x[IC(0,opt)]; for (i=0;i<n&&i<MAXOBS;i++) { rtk->ssat[obs[i].sat-1].snr[0]=MIN(obs[i].SNR[0],obs[i].SNR[1]); } for (i=0;i<MAXSAT;i++) { if (rtk->ssat[i].slip[0]&3) rtk->ssat[i].slipc[0]++; } } free(rs); free(dts); free(var); free(azel); free(xp); free(Pp); free(v); free(H); free(R); }
IGL_INLINE void igl::resolve_duplicated_faces( const Eigen::PlainObjectBase<DerivedF1>& F1, Eigen::PlainObjectBase<DerivedF2>& F2, Eigen::PlainObjectBase<DerivedJ>& J) { //typedef typename DerivedF1::Scalar Index; Eigen::VectorXi IA,IC; DerivedF1 uF; igl::unique_simplices(F1,uF,IA,IC); const size_t num_faces = F1.rows(); const size_t num_unique_faces = uF.rows(); assert((size_t) IA.rows() == num_unique_faces); // faces on top of each unique face std::vector<std::vector<int> > uF2F(num_unique_faces); // signed counts Eigen::VectorXi counts = Eigen::VectorXi::Zero(num_unique_faces); Eigen::VectorXi ucounts = Eigen::VectorXi::Zero(num_unique_faces); // loop over all faces for (size_t i=0; i<num_faces; i++) { const size_t ui = IC(i); const bool consistent = (F1(i,0) == uF(ui, 0) && F1(i,1) == uF(ui, 1) && F1(i,2) == uF(ui, 2)) || (F1(i,0) == uF(ui, 1) && F1(i,1) == uF(ui, 2) && F1(i,2) == uF(ui, 0)) || (F1(i,0) == uF(ui, 2) && F1(i,1) == uF(ui, 0) && F1(i,2) == uF(ui, 1)); uF2F[ui].push_back(int(i+1) * (consistent?1:-1)); counts(ui) += consistent ? 1:-1; ucounts(ui)++; } std::vector<size_t> kept_faces; for (size_t i=0; i<num_unique_faces; i++) { if (ucounts[i] == 1) { kept_faces.push_back(abs(uF2F[i][0])-1); continue; } if (counts[i] == 1) { bool found = false; for (auto fid : uF2F[i]) { if (fid > 0) { kept_faces.push_back(abs(fid)-1); found = true; break; } } assert(found); } else if (counts[i] == -1) { bool found = false; for (auto fid : uF2F[i]) { if (fid < 0) { kept_faces.push_back(abs(fid)-1); found = true; break; } } assert(found); } else { assert(counts[i] == 0); } } const size_t num_kept = kept_faces.size(); J.resize(num_kept, 1); std::copy(kept_faces.begin(), kept_faces.end(), J.data()); igl::slice(F1, J, 1, F2); }
Z K3(zframesend){PC(x); PC(y); TC2(z,-KI,-KJ); IC(z); ZTK(zframe_t,f); R kj(zframe_send(&f, VSK(y), zi));}
int main() { //SPECIFY PARMETERS, SEE CONFIG.H FILE FOR ENUM OPTIONS Configurations config; //Algorithm for solving for h config.algorithm_solve_h = NEWTON_BRUTE_FORCE; //Total time in years config.total_time = 20; // Initial time step in seconds config.initial_time_step = 30000;//12592000; // Injection stop config.injection_time = 100; // Pressure update interval in years config.pressure_update_injection = 2; config.pressure_update_migration = 5; // Permeability type config.perm_type = PERM_CONSTANT; // Name of formation config.formation_name = UTSIRA; // Parameter beta for the Corey permeability function config.beta = 0.4; ////////////////////////////////////////////////////////////////////////// if (config.formation_name == UTSIRA){ config.formation = "utsira"; config.formation_dir = "Utsira"; } else if(config.formation_name == JOHANSEN){ config.formation = "johansen"; config.formation_dir = "Johansen"; } else { printf("ERROR: No data for this formation"); } //Initialize some variables int nx, ny, nz; float dt, dz; float t, tf; int year = 60*60*24*365; // Device properties cudaSetDevice(0); int device; cudaGetDevice(&device); cudaDeviceProp p; cudaGetDeviceProperties(&p, device); printf("Device name: %s\n", p.name); // Set directory path of output and input files size_t buff_size= 100; char buffer[buff_size]; const char* path; readlink("/proc/self/exe", buffer, buff_size); printf("PATH %s", buffer); char* output_dir_path = "FullyIntegratedVESimulatorMATLAB/SimulationData/ResultData/"; char* input_dir_path = "FullyIntegratedVESimulatorMATLAB/SimulationData/FormationData/"; std::cout << "Trying to open " << input_dir_path << std::endl; std::cout << "Output will end up in " << output_dir_path << std::endl; // Filename strings char dir_input[300]; char filename_input[300]; char dir_output[300]; strcpy(dir_input, input_dir_path); strcat(dir_input, config.formation_dir); strcat(dir_input, "/"); strcpy(dir_output, output_dir_path); strcat(dir_output, config.formation_dir); strcat(dir_output, "/"); strcpy(filename_input, dir_input); strcat (filename_input, "dimensions.mat"); // Output txt files with results FILE* matlab_file_h; FILE* matlab_file_coarse_satu; FILE* matlab_file_volume; // Create output files for coarse saturation, interface height and volume // Files are stored in the directory createOutputFiles(matlab_file_h, matlab_file_coarse_satu, matlab_file_volume, dir_output); readDimensionsFromMATLABFile(filename_input, nx, ny, nz); InitialConditions IC(nx, ny, 5); printf("nx: %i, ny: %i nz: %i dt: %.10f", nx, ny, nz, dt); // Cpu pointers to store formation data from MATLAB CpuPtr_2D H(nx, ny, 0, true); CpuPtr_2D top_surface(nx, ny, 0, true); CpuPtr_2D h(nx, ny, 0, true); CpuPtr_2D normal_z(nx, ny, 0, true); CpuPtr_3D perm3D(nx, ny, nz + 1, 0, true); CpuPtr_3D poro3D(nx, ny, nz + 1, 0, true); CpuPtr_2D pv(nx, ny, 0, true); CpuPtr_2D flux_north(nx, ny, IC.border, true); CpuPtr_2D flux_east(nx, ny, IC.border, true); CpuPtr_2D source(nx, ny, 0, true); CpuPtr_2D grav_north(nx, ny, 0, true); CpuPtr_2D grav_east(nx, ny, 0, true); CpuPtr_2D K_face_north(nx, ny, 0, true); CpuPtr_2D K_face_east(nx, ny, 0, true); CpuPtr_2D active_east(nx, ny, 0, true); CpuPtr_2D active_north(nx, ny, 0, true); CpuPtr_2D volume(nx, ny, 0,true); strcpy(filename_input, dir_input); strcat (filename_input, "data.mat"); readFormationDataFromMATLABFile(filename_input, H.getPtr(), top_surface.getPtr(), h.getPtr(), normal_z.getPtr(), perm3D.getPtr(), poro3D.getPtr(), pv.getPtr(), flux_north.getPtr(), flux_east.getPtr(), grav_north.getPtr(), grav_east.getPtr(), K_face_north.getPtr(), K_face_east.getPtr(), dz); strcpy(filename_input, dir_input); strcat (filename_input, "active_cells.mat"); readActiveCellsFromMATLABFile(filename_input, active_east.getPtr(), active_north.getPtr()); //readDtTableFromMATLABFile(filename, dt_table, size_dt_table); Engine *ep; if (!(ep = engOpen(""))) { fprintf(stderr, "\nCan't start MATLAB engine\n"); return EXIT_FAILURE; } startMatlabEngine(ep, config.formation_dir); // Create double precision array for the data exchange between the GPU program and the MATLAB program mxArray *h_matrix = NULL, *flux_east_matrix = NULL, *flux_north_matrix=NULL; mxArray *source_matrix = NULL, *open_well = NULL; open_well = mxCreateLogicalScalar(true); engPutVariable(ep, "open_well", open_well); double * h_matlab_matrix; h_matlab_matrix = new double[nx*ny]; h_matrix = mxCreateDoubleMatrix(nx, ny, mxREAL); flux_east_matrix = mxCreateDoubleMatrix(nx+2*IC.border,ny+2*IC.border,mxREAL); flux_north_matrix = mxCreateDoubleMatrix(nx+2*IC.border,ny+2*IC.border,mxREAL); source_matrix = mxCreateDoubleMatrix(nx, ny, mxREAL); // Cpu Pointer to store the results CpuPtr_2D zeros(nx, ny, 0, true); //Initial Conditions IC.dz = dz; IC.createnIntervalsTable(H); IC.createScalingParameterTable(H, config.beta); IC.createInitialCoarseSatu(H, h); IC.computeAllGridBlocks(); IC.createDtVec(); // Create mask for sparse grid on GPU std::vector<int> active_block_indexes; std::vector<int> active_block_indexes_flux; int n_active_blocks = 0; int n_active_blocks_flux = 0; createGridMask(H, IC.grid, IC.block, nx, ny, active_block_indexes, n_active_blocks); createGridMaskFlux(H, IC.grid_flux, IC.block_flux, nx, ny, active_block_indexes_flux, n_active_blocks_flux); // Print grid mask properties printf("\n nBlocks: %i nActiveBlocks: %i fraction: %.5f\n", IC.grid.x * IC.grid.y, n_active_blocks, (float) n_active_blocks / (IC.grid.x * IC.grid.y)); printf("nBlocks: %i nActiveBlocks: %i fraction: %.5f\n", IC.grid_flux.x * IC.grid_flux.y, n_active_blocks_flux, (float) n_active_blocks_flux / (IC.grid_flux.x * IC.grid_flux.y)); printf("dz: %.3f\n", IC.dz); dim3 new_sparse_grid(n_active_blocks, 1, 1); dim3 new_sparse_grid_flux(n_active_blocks_flux, 1, 1); CommonArgs common_args; CoarseMobIntegrationKernelArgs coarse_mob_int_args; CoarsePermIntegrationKernelArgs coarse_perm_int_args; FluxKernelArgs flux_kernel_args; TimeIntegrationKernelArgs time_int_kernel_args; TimestepReductionKernelArgs time_red_kernel_args; SolveForhProblemCellsKernelArgs solve_problem_cells_args; printf("Cuda error 0.5: %s\n", cudaGetErrorString(cudaGetLastError())); initAllocate(&common_args, &coarse_perm_int_args, &coarse_mob_int_args, &flux_kernel_args, &time_int_kernel_args, &time_red_kernel_args, &solve_problem_cells_args); h.convertToDoublePointer(h_matlab_matrix); memcpy((void *)mxGetPr(h_matrix), (void *)h_matlab_matrix, sizeof(double)*nx*ny); engPutVariable(ep, "h_matrix", h_matrix); printf("Cuda error 1: %s\n", cudaGetErrorString(cudaGetLastError())); // Allocate and set data on the GPU GpuPtr_3D perm3D_device(nx, ny, nz + 1, 0, perm3D.getPtr()); GpuPtr_2D Lambda_c_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D Lambda_b_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D dLambda_c_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D dLambda_b_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D scaling_parameter_C_device(nx, ny, 0, IC.scaling_parameter.getPtr()); GpuPtr_2D K_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D H_device(nx, ny, 0, H.getPtr()); GpuPtr_2D h_device(nx, ny, 0, h.getPtr()); GpuPtr_2D top_surface_device(nx, ny, 0, top_surface.getPtr()); GpuPtr_2D z_diff_east_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D z_diff_north_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D nInterval_device(nx, ny, 0, IC.nIntervals.getPtr()); GpuPtr_2D U_x_device(nx, ny, IC.border, flux_east.getPtr()); GpuPtr_2D U_y_device(nx, ny, IC.border, flux_north.getPtr()); GpuPtr_2D source_device(nx, ny, 0, source.getPtr()); GpuPtr_2D K_face_east_device(nx, ny, 0, K_face_east.getPtr()); GpuPtr_2D K_face_north_device(nx, ny, 0, K_face_north.getPtr()); GpuPtr_2D grav_east_device(nx, ny, 0, grav_east.getPtr()); GpuPtr_2D grav_north_device(nx, ny, 0, grav_north.getPtr()); GpuPtr_2D normal_z_device(nx, ny, 0, normal_z.getPtr()); GpuPtr_2D R_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D pv_device(nx, ny, 0, pv.getPtr()); GpuPtr_2D output_test_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D active_east_device(nx, ny, 0, active_east.getPtr()); GpuPtr_2D active_north_device(nx, ny, 0, active_north.getPtr()); GpuPtr_2D vol_old_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D vol_new_device(nx, ny, 0, zeros.getPtr()); GpuPtr_2D coarse_satu_device(nx, ny, 0, IC.initial_coarse_satu_c.getPtr()); GpuPtr_1D global_dt_device(3, IC.global_time_data); GpuPtr_1D dt_vector_device(IC.nElements, IC.dt_vector); GpuPtrInt_1D active_block_indexes_device(n_active_blocks, &active_block_indexes[0]); GpuPtrInt_1D active_block_indexes_flux_device(n_active_blocks_flux, &active_block_indexes_flux[0]); cudaCheckError(); setCommonArgs(&common_args, IC.p_ci, IC.delta_rho, IC.g, IC.mu_c, IC.mu_b, IC.s_c_res, IC.s_b_res, IC.lambda_end_point_c, IC.lambda_end_point_b, active_east_device.getRawPtr(), active_north_device.getRawPtr(), H_device.getRawPtr(), pv_device.getRawPtr(), nx, ny, IC.border); setupGPU(&common_args); setCoarsePermIntegrationKernelArgs(&coarse_perm_int_args, K_device.getRawPtr(), perm3D_device.getRawPtr(), nInterval_device.getRawPtr(), IC.dz); callCoarsePermIntegrationKernel(IC.grid, IC.block, &coarse_perm_int_args); setCoarseMobIntegrationKernelArgs(&coarse_mob_int_args, Lambda_c_device.getRawPtr(), Lambda_b_device.getRawPtr(), dLambda_c_device.getRawPtr(), dLambda_b_device.getRawPtr(), h_device.getRawPtr(), perm3D_device.getRawPtr(), K_device.getRawPtr(), nInterval_device.getRawPtr(), scaling_parameter_C_device.getRawPtr(), active_block_indexes_device.getRawPtr(), IC.p_ci, IC.dz, config.perm_type); setFluxKernelArgs(&flux_kernel_args, Lambda_c_device.getRawPtr(),Lambda_b_device.getRawPtr(), dLambda_c_device.getRawPtr(), dLambda_b_device.getRawPtr(), U_x_device.getRawPtr(), U_y_device.getRawPtr(), source_device.getRawPtr(), h_device.getRawPtr(),top_surface_device.getRawPtr(), normal_z_device.getRawPtr(), K_face_east_device.getRawPtr(), K_face_north_device.getRawPtr(), grav_east_device.getRawPtr(), grav_north_device.getRawPtr(), R_device.getRawPtr(), dt_vector_device.getRawPtr(), active_block_indexes_flux_device.getRawPtr(), output_test_device.getRawPtr()); setTimestepReductionKernelArgs(&time_red_kernel_args, TIME_THREADS, IC.nElements, global_dt_device.getRawPtr(), IC.cfl_scale, dt_vector_device.getRawPtr()); //CUDPP CUDPPHandle plan; unsigned int* d_isValid; int* d_in; int* d_out; size_t* d_numValid = NULL; size_t numValidElements; unsigned int numElements=nx*ny; cudaCheckError(); cudaMalloc((void**) &d_isValid, sizeof(unsigned int)*numElements); cudaMalloc((void**) &d_in, sizeof(int)*numElements); cudaMalloc((void**) &d_out, sizeof(int)*numElements); cudaMalloc((void**) &d_numValid, sizeof(size_t)); cudaCheckError(); CUDPPHandle theCudpp; cudppCreate(&theCudpp); setUpCUDPP(theCudpp, plan, nx, ny, d_isValid, d_in, d_out, numElements); printf("\nCudaMemcpy error: %s", cudaGetErrorString(cudaGetLastError())); cudaCheckError(); setTimeIntegrationKernelArgs(&time_int_kernel_args, global_dt_device.getRawPtr(), IC.integral_res,pv_device.getRawPtr(), h_device.getRawPtr(), R_device.getRawPtr(),coarse_satu_device.getRawPtr(), scaling_parameter_C_device.getRawPtr(), vol_old_device.getRawPtr(), vol_new_device.getRawPtr(), d_isValid, d_in); cudaCheckError(); setSolveForhProblemCellsKernelArgs(&solve_problem_cells_args, h_device.getRawPtr(), coarse_satu_device.getRawPtr(), scaling_parameter_C_device.getRawPtr(), d_out, IC.integral_res, d_numValid); cudaCheckError(); //Compute start volume callCoarseMobIntegrationKernel(new_sparse_grid, IC.block, IC.grid.x, &coarse_mob_int_args); callFluxKernel(new_sparse_grid_flux, IC.block_flux, IC.grid_flux.x, &flux_kernel_args); callTimeIntegration(new_sparse_grid, IC.block, IC.grid.x, &time_int_kernel_args); cudaCheckError(); vol_old_device.download(volume.getPtr(), 0, 0, nx, ny); float total_volume_old = computeTotalVolume(volume, nx, ny); t = 0; double t2 = 0; tf = IC.global_time_data[2]; int iter_outer_loop = 0; int iter_inner_loop = 0; int iter_total = 0; int iter_total_lim = 5000; float time = 0; float injected = 0; int table_index = 1; double time_start = getWallTime(); double time_start_iter; double total_time_gpu = 0; while (time < config.total_time && iter_total < iter_total_lim){ t = 0; iter_inner_loop = 0; h_device.download(h.getPtr(), 0, 0, nx, ny); h.convertToDoublePointer(h_matlab_matrix); memcpy((void *)mxGetPr(h_matrix), (void *)h_matlab_matrix, sizeof(double)*nx*ny); engPutVariable(ep, "h_matrix", h_matrix); if (time >= config.injection_time){ open_well = mxCreateLogicalScalar(false); engPutVariable(ep, "open_well", open_well); IC.global_time_data[2] = 31536000*config.pressure_update_migration; tf = IC.global_time_data[2]; cudaMemcpy(global_dt_device.getRawPtr(), IC.global_time_data, sizeof(float)*3, cudaMemcpyHostToDevice); } // MATLAB call engEvalString(ep, "[source, east_flux, north_flux] = pressureFunctionToRunfromCpp(h_matrix, variables, open_well);"); // Get variables from MATLABs pressure solver flux_east_matrix = engGetVariable(ep, "east_flux"); flux_north_matrix = engGetVariable(ep, "north_flux"); source_matrix = engGetVariable(ep, "source"); memcpy((void *)flux_east.getPtr(), (void *)mxGetPr(flux_east_matrix), sizeof(float)*(nx+2*IC.border)*(ny+2*IC.border)); memcpy((void *)flux_north.getPtr(), (void *)mxGetPr(flux_north_matrix), sizeof(float)*(nx+2*IC.border)*(ny+2*IC.border)); memcpy((void *)source.getPtr(), (void *)mxGetPr(source_matrix), sizeof(float)*nx*ny); source_device.upload(source.getPtr(), 0, 0, nx, ny); U_x_device.upload(flux_east.getPtr(), 0, 0, nx+2*IC.border, ny+2*IC.border); U_y_device.upload(flux_north.getPtr(), 0, 0,nx+2*IC.border, ny+2*IC.border); time_start_iter = getWallTime(); while (t < tf && iter_total < iter_total_lim){ cudaCheckError(); callCoarseMobIntegrationKernel(new_sparse_grid, IC.block, IC.grid.x, &coarse_mob_int_args); cudaCheckError(); callFluxKernel(new_sparse_grid_flux, IC.block_flux, IC.grid_flux.x, &flux_kernel_args); cudaCheckError(); callTimestepReductionKernel(TIME_THREADS, &time_red_kernel_args); cudaCheckError(); // Set the initial time step if (iter_total < 1 && iter_inner_loop == 0){ IC.global_time_data[0] = config.initial_time_step; IC.global_time_data[1] += config.initial_time_step; cudaMemcpy(global_dt_device.getRawPtr(), IC.global_time_data, sizeof(float)*3, cudaMemcpyHostToDevice); } //For precomputed time step insertion /* IC.global_time_data[0] = (float)dt_table[table_index]; IC.global_time_data[1] += (float)dt_table[table_index]; cudaMemcpy(global_dt_device.getRawPtr(), IC.global_time_data, sizeof(float)*3, cudaMemcpyHostToDevice); */ cudaCheckError(); if (config.algorithm_solve_h == BRUTE_FORCE) callTimeIntegration(new_sparse_grid, IC.block, IC.grid.x, &time_int_kernel_args); else if (config.algorithm_solve_h == NEWTON_BRUTE_FORCE){ callTimeIntegrationNewton(new_sparse_grid, IC.block, IC.grid.x, &time_int_kernel_args); cudppCompact(plan, d_out, d_numValid, d_in, d_isValid, numElements); callSolveForhProblemCells(IC.grid_pc, IC.block_pc, &solve_problem_cells_args); } else if (config.algorithm_solve_h == NEWTON_BISECTION){ callTimeIntegrationNewton(new_sparse_grid, IC.block, IC.grid.x, &time_int_kernel_args); cudppCompact(plan, d_out, d_numValid, d_in, d_isValid, numElements); callSolveForhProblemCellsBisection(IC.grid_pc, IC.block_pc, &solve_problem_cells_args); } cudaCheckError(); cudaMemcpy(IC.global_time_data, global_dt_device.getRawPtr(), sizeof(float)*3, cudaMemcpyDeviceToHost); cudaCheckError(); // Keep track of injected volume, insert injection coordinate and rate injected += IC.global_time_data[0]*source(50,50); t += IC.global_time_data[0]; //table_index++; iter_inner_loop++; iter_total++; } total_time_gpu += getWallTime() - time_start_iter; printf("Total time in years: %.3f time in this round %.3f timestep %.3f GPU time %.3f time per iter %.8f \n", time, t, IC.global_time_data[0], getWallTime() - time_start_iter, (getWallTime() - time_start_iter)/iter_inner_loop); time += t/(year); iter_outer_loop++; } printf("Elapsed time program: %.5f gpu part: %.5f", getWallTime() - time_start, total_time_gpu); engClose(ep); h_device.download(zeros.getPtr(), 0, 0, nx, ny); zeros.printToFile(matlab_file_h); coarse_satu_device.download(zeros.getPtr(), 0, 0, nx, ny); // Divide by the formation thickness H to get the actual coarse satu for (int i = 0; i < nx; i++){ for (int j = 0; j < ny; j++){ if (H(i,j) != 0) zeros(i,j) = zeros(i,j)/H(i,j); } } zeros.printToFile(matlab_file_coarse_satu); vol_new_device.download(zeros.getPtr(), 0, 0, nx, ny); zeros.printToFile(matlab_file_volume); float total_volume_new = computeTotalVolume(zeros, nx, ny); printf("total volume new %.2f total volume old %.2f injected %.1f injected fraction %.10f", total_volume_new, total_volume_old, injected, (total_volume_new-injected)/(injected)); printf("volume fraction %.10f",(total_volume_new-total_volume_old)/(total_volume_old)); printf("\nCudaMemcpy error: %s", cudaGetErrorString(cudaGetLastError())); printf("FINITO precise time %.6f iter_total %i", time, iter_total); }
int main() { EifList<int> TestList (True), TestList2 (True); EifIterator TestIt, *TestItptr; int d[] = {1, 2, 3, 1, 4, 5, 6, 7, 8, 8, 9, 10, -1}, i; for (i = 0; d [i] != -1; i++) { cout << "\n" << d[i]; TestList.Add (d[i]); } cout << "\n\nList Test\n"; cout << "Should be 10\t" << TestList.Count() << "\n"; TestList.Remove (11); cout << "Should be 10\t" << TestList.Count() << "\n"; TestList.Remove (9); cout << "Should be 9\t" << TestList.Count() << "\n"; TestList.Search (9); cout <<"Should be 0\t" << TestList.Found() << "\n"; TestList.Search (6); cout <<"Should be 1:\t" << TestList.Found() << "\n"; cout << "Should be 6:\t" << TestList.FoundItem() << "\n"; IC (0, TestList); TestItptr = new EifIterator (TestList); IC (1, TestList); EifIterator TestIt2 = *TestItptr; IC (2, TestList); TestIt2 = TestIt; IC (1, TestList); DummyIt (1, *TestItptr, TestList); delete TestItptr; TestItptr = NULL; IC (0, TestList); Dummy (TestList); IC (0, TestList); TestIt = TestList.Iterator(); IC (1, TestList); while (!TestIt.Finished()) { cout <<'\n' << TestList.Item (TestIt); TestIt.Forth(); } IC (0, TestList); TestIt = TestList2.Iterator(); IC (0, TestList2); TestList2.Add (1); TestIt.First(); IC (1, TestList2); TestIt.Forth(); IC (0, TestList2); return 0; }
static DF1(jtsuffix){DECLF;I r; RZ(w); if(jt->rank&&jt->rank[1]<AR(w)){r=jt->rank[1]; jt->rank=0; R rank1ex(w,self,r,jtsuffix);} jt->rank=0; R eachl(IX(IC(w)),w,atop(fs,ds(CDROP))); } /* f\."r w for general f */
static void generate_round_keys(int rnds,uint32_t* K, uint32_t* x, uint32_t* z) { COMPUTE_Z; K[1]=S5[IA(z[2])]^S6[IB(z[2])]^S7[ID(z[1])]^S8[IC(z[1])]^S5[IC(z[0])]; K[2]=S5[IC(z[2])]^S6[ID(z[2])]^S7[IB(z[1])]^S8[IA(z[1])]^S6[IC(z[1])]; K[3]=S5[IA(z[3])]^S6[IB(z[3])]^S7[ID(z[0])]^S8[IC(z[0])]^S7[IB(z[2])]; K[4]=S5[IC(z[3])]^S6[ID(z[3])]^S7[IB(z[0])]^S8[IA(z[0])]^S8[IA(z[3])]; COMPUTE_X; K[5]=S5[ID(x[0])]^S6[IC(x[0])]^S7[IA(x[3])]^S8[IB(x[3])]^S5[IA(x[2])]; K[6]=S5[IB(x[0])]^S6[IA(x[0])]^S7[IC(x[3])]^S8[ID(x[3])]^S6[IB(x[3])]; K[7]=S5[ID(x[1])]^S6[IC(x[1])]^S7[IA(x[2])]^S8[IB(x[2])]^S7[ID(x[0])]; K[8]=S5[IB(x[1])]^S6[IA(x[1])]^S7[IC(x[2])]^S8[ID(x[2])]^S8[ID(x[1])]; COMPUTE_Z; K[9]=S5[ID(z[0])]^S6[IC(z[0])]^S7[IA(z[3])]^S8[IB(z[3])]^S5[IB(z[2])]; K[10]=S5[IB(z[0])]^S6[IA(z[0])]^S7[IC(z[3])]^S8[ID(z[3])]^S6[IA(z[3])]; K[11]=S5[ID(z[1])]^S6[IC(z[1])]^S7[IA(z[2])]^S8[IB(z[2])]^S7[IC(z[0])]; K[12]=S5[IB(z[1])]^S6[IA(z[1])]^S7[IC(z[2])]^S8[ID(z[2])]^S8[IC(z[1])]; COMPUTE_X; if (rnds==16) { K[13]=S5[IA(x[2])]^S6[IB(x[2])]^S7[ID(x[1])]^S8[IC(x[1])]^S5[ID(x[0])]; K[14]=S5[IC(x[2])]^S6[ID(x[2])]^S7[IB(x[1])]^S8[IA(x[1])]^S6[ID(x[1])]; K[15]=S5[IA(x[3])]^S6[IB(x[3])]^S7[ID(x[0])]^S8[IC(x[0])]^S7[IA(x[2])]; K[16]=S5[IC(x[3])]^S6[ID(x[3])]^S7[IB(x[0])]^S8[IA(x[0])]^S8[IB(x[3])]; } }
static char * split_lujvo (char *x) { static char result[2048]; int first=1; /* At start, so we can handle r and n hyphens */ result[0] = 0; while (1) { /* Advance x to look at the tail of the string. */ int len = strlen(x); switch (len) { case 0: case 1: case 2: /* Impossible */ return NULL; break; case 3: case 4: { char *comp = lookup_component(x); if (comp) { if (!first) strcat(result, "+"); strcat(result,comp); } return result; } break; case 5: if (!first) strcat(result, "+"); strcat(result, x); return result; break; default: { if (x[3] == 'y') { strip_leading_rafsi(&x, 3, 1, first, result); } else if (x[4] == 'y') { strip_leading_rafsi(&x, 4, 1, first, result); } else if (x[5] == 'y') { /* Handle cultural rafsi of form CCVVCy */ strip_leading_rafsi(&x, 5, 1, first, result); } else if ((x[6] == 'y') && (x[3] == '\'')) { /* Handle cultural rafsi of form CCV'VCy */ strip_leading_rafsi(&x, 6, 1, first, result); } else { /* Have to decide if there's an r/n hyphen */ if (!is_consonant(x[0])) return NULL; /* can't ever happen */ if (IC(x[1]) && IV(x[2])) { /* CCV at start */ strip_leading_rafsi(&x, 3, 0, first, result); } else if (IV(x[1]) && IC(x[2])) { strip_leading_rafsi(&x, 3, 0, first, result); } else if (IV(x[1])) { if (x[2] == '\'') { /* Everything pushed up by 1 */ if (IV(x[3])) { if (((x[4] == 'r') && (IC(x[5]))) || ((x[4] == 'n') && (x[5] == 'r'))) { /* This pattern can only occur if a hyphen is there. */ strip_leading_rafsi(&x, 4, 1, first, result); } else { strip_leading_rafsi(&x, 4, 0, first, result); } } else { /* CV'C form, impossible. */ return NULL; } } else { if (IV(x[2])) { if (((x[3] == 'r') && (IC(x[4]))) || ((x[3] == 'n') && (x[4] == 'r'))) { /* This pattern can only occur if a hyphen is there. */ strip_leading_rafsi(&x, 3, 1, first, result); } else { strip_leading_rafsi(&x, 3, 0, first, result); } } else { /* CVC form, no r/n hyphen */ strip_leading_rafsi(&x, 3, 0, first, result); } } } else { /* Impossible */ return NULL; } } } break; } first = 0; } }
size_t NrEQ(void* a) /* numarul de elemente din coada */ { size_t n = 0; ACel p = IC(a); /* p - adresa primei celule */ for(; p; p = p->urm) n++; return n; }
int PrimQ(void *ac, void *ae) /* copiaza primul element din coada la adresa ae */ { if(!IC(ac)) return 0; /* coada vida -> "esec" */ memcpy(ae, &(IC(ac)->info), DIME(ac)); /* preia informatia */ return 1; /* operatie reusita -> "succes" */ }
Z K3(device){TC2(x,-KI,-KJ); IC(x); PC(y); PC(z); R kj(zmq_device(xi, VSK(y), VSK(z)));}