/* sbas ephemeris to satellite clock bias -------------------------------------- * compute satellite clock bias with sbas ephemeris * args : gtime_t time I time by satellite clock (gpst) * seph_t *seph I sbas ephemeris * return : satellite clock bias (s) * notes : see ref [3] *-----------------------------------------------------------------------------*/ extern double seph2clk(gtime_t time, const seph_t *seph) { double t; int i; trace(4,"seph2clk: time=%s sat=%2d\n",time_str(time,3),seph->sat); t=timediff(time,seph->t0); for (i=0;i<2;i++) { t-=seph->af0+seph->af1*t; } return seph->af0+seph->af1*t; }
/* timeget() */ void utest10(void) { char s1[64],s2[64]; gtime_t time1,time2; int i,j; time1=timeget(); for (i=0;i<2000000000;i++) j=1; time2=timeget(); time2str(time1,s1,6); time2str(time2,s2,6); assert(timediff(time1,time2)<=0.0); printf("%s utset10 : OK\n",__FILE__); }
static void ati_update_temps(void) { #ifdef HAVE_TIME_H static time_t last = 0; time_t now = time(NULL); /* Only update when more than two seconds have passed since last update */ if (timediff(now, last) > 2) { #endif num_gpus = ati_get_temps(&gpu_temps, MAX_GPUS); #ifdef HAVE_TIME_H last = now; } #endif }
/* broadcast ephemeris to satellite clock bias --------------------------------- * compute satellite clock bias with broadcast ephemeris (gps, galileo, qzss) * args : gtime_t time I time by satellite clock (gpst) * eph_t *eph I broadcast ephemeris * return : satellite clock bias (s) without relativeity correction * notes : see ref [1],[7],[8] * satellite clock does not include relativity correction and tdg *-----------------------------------------------------------------------------*/ extern double eph2clk(gtime_t time, const eph_t *eph) { double t; int i; trace(4,"eph2clk : time=%s sat=%2d\n",time_str(time,3),eph->sat); t=timediff(time,eph->toc); for (i=0;i<2;i++) { t-=eph->f0+eph->f1*t+eph->f2*t*t; } return eph->f0+eph->f1*t+eph->f2*t*t; }
/* glonass ephemeris to satellite clock bias ----------------------------------- * compute satellite clock bias with glonass ephemeris * args : gtime_t time I time by satellite clock (gpst) * geph_t *geph I glonass ephemeris * return : satellite clock bias (s) * notes : see ref [2] *-----------------------------------------------------------------------------*/ extern double geph2clk(gtime_t time, const geph_t *geph) { double t; int i; trace(4,"geph2clk: time=%s sat=%2d\n",time_str(time,3),geph->sat); t=timediff(time,geph->toe); for (i=0;i<2;i++) { t-=-geph->taun+geph->gamn*t; } return -geph->taun+geph->gamn*t; }
void KRB5_CALLCONV krb5int_mutex_unlock_update_stats(k5_debug_mutex_stats *m) { k5_debug_time_t now = get_current_time(); k5_debug_timediff_t tdiff, tdiff2; tdiff = timediff(now, m->time_acquired); tdiff2 = tdiff * tdiff; if (m->count == 1 || m->lockheld.valmin > tdiff) m->lockheld.valmin = tdiff; if (m->count == 1 || m->lockheld.valmax < tdiff) m->lockheld.valmax = tdiff; m->lockheld.valsum += tdiff; m->lockheld.valsqsum += tdiff2; }
/* decode type 19: rtk uncorrected pseudorange -------------------------------*/ static int decode_type19(rtcm_t *rtcm) { gtime_t time; double usec,pr,tt; int i=48,index,freq,sync=1,code,sys,prn,sat; rtklib_trace(4,"decode_type19: len=%d\n",rtcm->len); if (i+24<=rtcm->len*8) { freq=getbitu(rtcm->buff,i, 2); i+= 2+2; usec=getbitu(rtcm->buff,i,20); i+=20; } else { rtklib_trace(2,"rtcm2 19 length error: len=%d\n",rtcm->len); return -1; } if (freq&0x1) { rtklib_trace(2,"rtcm2 19 not supported frequency: freq=%d\n",freq); return -1; } freq>>=1; while (i+48<=rtcm->len*8&&rtcm->obs.n<MAXOBS) { sync=getbitu(rtcm->buff,i, 1); i+= 1; code=getbitu(rtcm->buff,i, 1); i+= 1; sys =getbitu(rtcm->buff,i, 1); i+= 1; prn =getbitu(rtcm->buff,i, 5); i+= 5+8; pr =getbitu(rtcm->buff,i,32); i+=32; if (prn==0) prn=32; if (!(sat=satno(sys?SYS_GLO:SYS_GPS,prn))) { rtklib_trace(2,"rtcm2 19 satellite number error: sys=%d prn=%d\n",sys,prn); continue; } time=timeadd(rtcm->time,usec*1E-6); if (sys) time=utc2gpst(time); /* convert glonass time to gpst */ tt=timediff(rtcm->obs.data[0].time,time); if (rtcm->obsflag||fabs(tt)>1E-9) { rtcm->obs.n=rtcm->obsflag=0; } if ((index=obsindex(&rtcm->obs,time,sat))>=0) { rtcm->obs.data[index].P[freq]=pr*0.02; rtcm->obs.data[index].code[freq]= !freq?(code?CODE_L1P:CODE_L1C):(code?CODE_L2P:CODE_L2C); } } rtcm->obsflag=!sync; return sync?0:1; }
bool handle_domain(void *k, void *l, void *c) { lookup_t *lookup = (lookup_t *) l; lookup_context_t *context = (lookup_context_t *) c; struct timeval now; gettimeofday(&now, NULL); if (timediff(&now, &lookup->next_lookup) < 0) { uint16_t query_flags = 0; if (!context->cmd_args.norecurse) { query_flags |= LDNS_RD; } ldns_pkt *packet; if(LDNS_STATUS_OK != ldns_pkt_query_new_frm_str(&packet, lookup->domain, context->cmd_args.record_types, LDNS_RR_CLASS_IN, query_flags)) { abort(); } ldns_pkt_set_id(packet, lookup->transaction); uint8_t *buf = NULL; size_t packet_size = 0; if(LDNS_STATUS_OK != ldns_pkt2wire(&buf, packet, &packet_size)) { abort(); } ldns_pkt_free(packet); packet = NULL; sockaddr_in_t *resolver = massdns_get_resolver((size_t) rand(), &context->resolvers); ssize_t n = -1; while (n < 0) { n = sendto(context->sock, buf, packet_size, 0, (sockaddr_t *) resolver, sizeof(*resolver)); } free(buf); long addusec = context->cmd_args.interval_ms * 1000; addusec += rand() % (addusec / 5); // Avoid congestion by adding some randomness lookup->next_lookup.tv_usec = (now.tv_usec + addusec) % 1000000; lookup->next_lookup.tv_sec = now.tv_sec + (now.tv_usec + addusec) / 1000000; lookup->tries++; if (lookup->tries == context->cmd_args.resolve_count) { hashmapRemove(context->map, lookup->domain); free(lookup->domain); free(lookup); } } return true; }
/* convert pvt message -------------------------------------------------------*/ static void convpvt(FILE **ofp, rnxopt_t *opt, strfile_t *str, int *n) { gtime_t time,current; static gtime_t firsttime={0,0}; double ep[6]; trace(3,"convpvt :\n"); if (!ofp[7]) return; time=str->pvt->time; if (!screent(time,opt->ts,opt->te,opt->tint)) return; if(n[7]==0) { current=timeget(); if(timediff(time,current)>86400) return; firsttime=time; time2epoch(time,ep); fprintf(ofp[7], "%04.0f %02.0f %02.0f %02.0f %02.0f %02.6f\n", ep[0],ep[1],ep[2],ep[3],ep[4],ep[5]); } fprintf(ofp[7], "%15.7f %14.3lf %14.3lf %14.3lf %11.3lf %11.3lf %11.3lf", timediff(time,firsttime), str->pvt->pos[0], str->pvt->pos[1], str->pvt->pos[2], str->pvt->vel[0], str->pvt->vel[1], str->pvt->vel[2]); fprintf(ofp[7],"\n"); if (opt->tstart.time==0) opt->tstart=time; opt->tend=time; n[7]++; }
//MORPH - Changed by SiRoB, SLS keep only for rar files, reduce saved source and life time //CString CSourceSaver::CalcExpiration(int Days) CString CSourceSaver::CalcExpiration(int Minutes) { CTime expiration = CTime::GetCurrentTime(); //MORPH - Changed by SiRoB, SLS keep only for rare files, reduce Saved Source and life time //CTimeSpan timediff(Days, 0, 0, 0); CTimeSpan timediff(Minutes/1440, (Minutes/60) % 24, Minutes % 60, 0); expiration += timediff; CString strExpiration; //MORPH - Changed by SiRoB, SLS keep only for rare files, reduce Saved Source and life time //strExpiration.Format("%02i%02i%02i", (expiration.GetYear() % 100), expiration.GetMonth(), expiration.GetDay()); strExpiration.Format(_T("%02i%02i%02i%02i%02i"), (expiration.GetYear() % 100), expiration.GetMonth(), expiration.GetDay(), expiration.GetHour(),expiration.GetMinute()); return strExpiration; }
int main(int argc, char *argv[]) { struct buffer b; struct buffer tmpbuf; struct timespec t_0, t_1, t_2; int size = 1024*1024*1024; clock_gettime(CLOCK_MONOTONIC, &t_0); if ( allocbuf(&b, size) && allocbuf(&tmpbuf, size) ) { randbuf(&b); clock_gettime(CLOCK_MONOTONIC, &t_1); mergesort(&b, &tmpbuf, 0); // quicksort(&b); freebuf(&tmpbuf); freebuf(&b); clock_gettime(CLOCK_MONOTONIC, &t_2); printf ("Gesamtzeit: %llu \tRandomzeit: %llu\tSortierzeit: %llu\n", timediff(&t_0, &t_2), timediff(&t_0, &t_1), timediff(&t_1, &t_2)); } else { printf("Fehler beim Allozieren der Puffer\n"); } }
/* ** Get the time and save in the phase time ** array. */ char * timestamp(int end, int phase, char *buf) { time_t now; struct tm *tmp; if (verbose > 1) cache_report(stderr, "libxfs_bcache", libxfs_bcache); now = time(NULL); if (end) { phase_times[phase].end = now; timediff(phase); /* total time in slot zero */ phase_times[0].end = now; timediff(0); if (phase < 7) { phase_times[phase+1].start = now; current_phase = phase + 1; } } else { phase_times[phase].start = now; current_phase = phase; } if (buf) { tmp = localtime((const time_t *)&now); sprintf(buf, _("%02d:%02d:%02d"), tmp->tm_hour, tmp->tm_min, tmp->tm_sec); } return(buf); }
/* decode binex mesaage 0x01-03: decoded sbas ephmemeris ---------------------*/ static int decode_bnx_01_03(raw_t *raw, unsigned char *buff, int len) { seph_t seph={0}; unsigned char *p=buff; double tow,tod,tof; int prn,week,iodn; trace(4,"binex 0x01-03: len=%d\n",len); if (len>=98) { prn =U1(p); p+=1; week =U2(p); p+=2; tow =U4(p); p+=4; seph.af0 =R8(p); p+=8; tod =R4(p); p+=4; tof =U4(p); p+=4; seph.pos[0]=R8(p)*1E3; p+=8; seph.vel[0]=R8(p)*1E3; p+=8; seph.acc[0]=R8(p)*1E3; p+=8; seph.pos[1]=R8(p)*1E3; p+=8; seph.vel[1]=R8(p)*1E3; p+=8; seph.acc[1]=R8(p)*1E3; p+=8; seph.pos[2]=R8(p)*1E3; p+=8; seph.vel[2]=R8(p)*1E3; p+=8; seph.acc[2]=R8(p)*1E3; p+=8; seph.svh =U1(p); p+=1; seph.sva =U1(p); p+=1; iodn =U1(p); } else { trace(2,"binex 0x01-03 length error: len=%d\n",len); return -1; } if (!(seph.sat=satno(SYS_SBS,prn))) { trace(2,"binex 0x01-03 satellite error: prn=%d\n",prn); return -1; } seph.t0=gpst2time(week,tow); seph.tof=adjweek(seph.t0,tof); if (!strstr(raw->opt,"-EPHALL")) { if (fabs(timediff(seph.t0,raw->nav.seph[prn-MINPRNSBS].t0))<1.0&& seph.sva==raw->nav.seph[prn-MINPRNSBS].sva) return 0; /* unchanged */ } raw->nav.seph[prn-MINPRNSBS]=seph; raw->ephsat=seph.sat; return 2; }
int main(int argc, char *argv[]){ struct timespec bgn,nd; npart = atoi(argv[1]); /*command line input expected which provides the number of particles */ nstep = atoi(argv[2]); /*command line input expected which provides the number of particles */ /*initialize the position of particles in space and also their velocity and acceleration vector values*/ initParticles(npart); clock_gettime(CLOCK_REALTIME, &bgn); /*begin the simulation with the initialization done previously and using simulation parameters defined in the global constants*/ begin_simulation(); clock_gettime(CLOCK_REALTIME, &nd); printf("%f\n", timediff(bgn,nd)); }
/* outrneobsb() */ void utest4(void) { char file[]="../data/rinex/07590920.05o"; obs_t obs={0}; int i,j; readrnx(file,1,"",&obs,NULL,NULL); outrnxobsb(stdout,&opt2,obs.data,8,9); outrnxobsb(stdout,&opt2,obs.data,8,0); for (i=j=0;i<obs.n;i=j) { while (j<obs.n&&timediff(obs.data[j].time,obs.data[i].time)<=0.0) j++; outrnxobsb(stdout,&opt2,obs.data+i,j-i,0); } printf("%s utest4 : OK\n",__FILE__); }
/* * Portable function used for waiting a specific amount of ms. * Waiting indefinitely with this function is not allowed, a * zero or negative timeout value will return immediately. * * Return values: * -1 = system call error, or invalid timeout value * 0 = specified timeout has elapsed */ int wait_ms(int timeout_ms) { #if !defined(MSDOS) && !defined(USE_WINSOCK) #ifndef HAVE_POLL_FINE struct timeval pending_tv; #endif struct timeval initial_tv; int pending_ms; int error; #endif int r = 0; if(!timeout_ms) return 0; if(timeout_ms < 0) { errno = EINVAL; return -1; } #if defined(MSDOS) delay(timeout_ms); #elif defined(USE_WINSOCK) Sleep(timeout_ms); #else pending_ms = timeout_ms; initial_tv = tvnow(); do { #if defined(HAVE_POLL_FINE) r = poll(NULL, 0, pending_ms); #else pending_tv.tv_sec = pending_ms / 1000; pending_tv.tv_usec = (pending_ms % 1000) * 1000; r = select(0, NULL, NULL, NULL, &pending_tv); #endif /* HAVE_POLL_FINE */ if(r != -1) break; error = errno; if(error && (error != EINTR)) break; pending_ms = timeout_ms - (int)timediff(tvnow(), initial_tv); if(pending_ms <= 0) break; } while(r == -1); #endif /* USE_WINSOCK */ if(r) r = -1; return r; }
/* displacement by ocean tide loading (ref [2] 7) ----------------------------*/ static void tide_oload(gtime_t tut, const double *odisp, double *denu) { const double args[][5]={ {1.40519E-4, 2.0,-2.0, 0.0, 0.00}, /* M2 */ {1.45444E-4, 0.0, 0.0, 0.0, 0.00}, /* S2 */ {1.37880E-4, 2.0,-3.0, 1.0, 0.00}, /* N2 */ {1.45842E-4, 2.0, 0.0, 0.0, 0.00}, /* K2 */ {0.72921E-4, 1.0, 0.0, 0.0, 0.25}, /* K1 */ {0.67598E-4, 1.0,-2.0, 0.0,-0.25}, /* O1 */ {0.72523E-4,-1.0, 0.0, 0.0,-0.25}, /* P1 */ {0.64959E-4, 1.0,-3.0, 1.0,-0.25}, /* Q1 */ {0.53234E-5, 0.0, 2.0, 0.0, 0.00}, /* Mf */ {0.26392E-5, 0.0, 1.0,-1.0, 0.00}, /* Mm */ {0.03982E-5, 2.0, 0.0, 0.0, 0.00} /* Ssa */ }; const double ep1975[]={1975,1,1,0,0,0}; double ep[6],fday,days,t,t2,t3,a[5],ang,dp[3]={0}; int i,j; trace(3,"tide_oload:\n"); /* angular argument: see subroutine arg.f for reference [1] */ time2epoch(tut,ep); fday=ep[3]*3600.0+ep[4]*60.0+ep[5]; ep[3]=ep[4]=ep[5]=0.0; days=timediff(epoch2time(ep),epoch2time(ep1975))/86400.0; t=(27392.500528+1.000000035*days)/36525.0; t2=t*t; t3=t2*t; a[0]=fday; a[1]=(279.69668+36000.768930485*t+3.03E-4*t2)*D2R; /* H0 */ a[2]=(270.434358+481267.88314137*t-0.001133*t2+1.9E-6*t3)*D2R; /* S0 */ a[3]=(334.329653+4069.0340329577*t+0.010325*t2-1.2E-5*t3)*D2R; /* P0 */ a[4]=2.0*PI; /* displacements by 11 constituents */ for (i=0;i<11;i++) { ang=0.0; for (j=0;j<5;j++) ang+=a[j]*args[i][j]; for (j=0;j<3;j++) dp[j]+=odisp[j+i*6]*cos(ang-odisp[j+3+i*6]*D2R); } denu[0]=-dp[1]; denu[1]=-dp[2]; denu[2]= dp[0]; trace(5,"tide_oload: denu=%.3f %.3f %.3f\n",denu[0],denu[1],denu[2]); }
int single_start(ThreadArgs *ta) { struct timeval start, end; gettimeofday(&start, NULL); int ret = ta->func(ta->args); gettimeofday(&end, NULL); unsigned int tmd = timediff(&start, &end); double speed = ((double)ta->args->testcount / tmd) * 1000000; DINFO("thread test use time:%u, speed:%.2f\n", tmd, speed); free(ta->args); free(ta); return ret; }
/* sbas ephemeris to satellite position and clock bias ------------------------- * compute satellite position and clock bias with sbas ephemeris * args : gtime_t time I time (gpst) * seph_t *seph I sbas ephemeris * double *rs O satellite position {x,y,z} (ecef) (m) * double *dts O satellite clock bias (s) * double *var O satellite position and clock variance (m^2) * return : none * notes : see ref [3] *-----------------------------------------------------------------------------*/ extern void seph2pos(gtime_t time, const seph_t *seph, double *rs, double *dts, double *var) { double t; int i; trace(4,"seph2pos: time=%s sat=%2d\n",time_str(time,3),seph->sat); t=timediff(time,seph->t0); for (i=0;i<3;i++) { rs[i]=seph->pos[i]+seph->vel[i]*t+seph->acc[i]*t*t/2.0; } *dts=seph->af0+seph->af1*t; *var=var_uraeph(seph->sva); }
/* iers mean pole (ref [7] eq.7.25) ------------------------------------------*/ static void iers_mean_pole(gtime_t tut, double *xp_bar, double *yp_bar) { const double ep2000[]={2000,1,1,0,0,0}; double y,y2,y3; y=timediff(tut,epoch2time(ep2000))/86400.0/365.25; if (y<3653.0/365.25) { /* until 2010.0 */ y2=y*y; y3=y2*y; *xp_bar= 55.974+1.8243*y+0.18413*y2+0.007024*y3; /* (mas) */ *yp_bar=346.346+1.7896*y-0.10729*y2-0.000908*y3; } else { /* after 2010.0 */ *xp_bar= 23.513+7.6141*y; /* (mas) */ *yp_bar=358.891-0.6287*y; } }
static void os_cmd_uptime(sourceinfo_t *si, int parc, char *parv[]) { logcommand(si, CMDLOG_GET, "UPTIME"); #ifdef REPRODUCIBLE_BUILDS command_success_nodata(si, "%s [%s]", PACKAGE_STRING, revision); #else command_success_nodata(si, "%s [%s] Build Date: %s", PACKAGE_STRING, revision, __DATE__); #endif command_success_nodata(si, _("Services have been up for %s"), timediff(CURRTIME - me.start)); command_success_nodata(si, _("Current PID: %d"), getpid()); command_success_nodata(si, _("Registered accounts: %d"), cnt.myuser); if (!nicksvs.no_nick_ownership) command_success_nodata(si, _("Registered nicknames: %d"), cnt.mynick); command_success_nodata(si, _("Registered channels: %d"), cnt.mychan); command_success_nodata(si, _("Users currently online: %d"), cnt.user - me.me->users); }
static char *update_file(timely_file *tf) { int rval; struct timeval now; gettimeofday(&now, NULL); if(timediff(&now,&tf->last_read) > tf->thresh) { rval = slurpfile(tf->name, tf->buffer, BUFFSIZE); if(rval == SYNAPSE_FAILURE) { err_msg("update_file() got an error from slurpfile() reading %s", tf->name); return (char *)SYNAPSE_FAILURE; } else tf->last_read = now; } return tf->buffer; }
// update statistics-information for observation-data plot ------------------ void __fastcall TPlot::UpdateInfoObs(void) { AnsiString msgs0[]={" NSAT"," GDOP"," PDOP"," HDOP"," VDOP","",""}; AnsiString msgs1[]={" OBS=L1/2 "," L1 "," L2 "," L1/2/5 "," L1/5 ",""," L5 "}; AnsiString msgs2[]={" SNR=...45.","..40.","..35.","..30.","..25 ",""," <25 "}; AnsiString msgs3[]={" SYS=GPS ","GLO ","GAL ","QZS ","BDS ","SBS ",""}; AnsiString msgs4[]={" MP=..0.6","..0.3","..0.0..","-0.3..","-0.6..","",""}; AnsiString msg,msgs[8]; gtime_t ts={0},te={0},t,tp={0}; int i,n=0,ne=0; char s1[64],s2[64]; trace(3,"UpdateInfoObs:\n"); if (BtnSol1->Down) { for (i=0;i<Obs.n;i++) { t=Obs.data[i].time; if (ts.time==0) ts=t; te=t; if (tp.time==0||timediff(t,tp)>TTOL) ne++; n++; tp=t; } } if (n>0) { TimeStr(ts,0,0,s1); TimeStr(te,0,1,s2); msg.sprintf("[1]%s-%s : EP=%d N=%d",s1,s2+(TimeLabel?5:0),ne,n); for (i=0;i<7;i++) { if (PlotType==PLOT_DOP) { msgs[i]=msgs0[i]; } else if (PlotType<=PLOT_SKY&&ObsType->ItemIndex==0) { msgs[i]=SimObs?msgs3[i]:msgs1[i]; } else if (PlotType==PLOT_MPS) { msgs[i]=msgs4[i]; } else { msgs[i]=SimObs?msgs3[i]:msgs2[i]; } } } ShowMsg(msg); ShowLegend(msgs); }
static int TEST(const char *name, int(*function)(test_input_t *), test_input_t *t) { struct timeval tv1, tv2; double diff; int r; warn("** start to test %s *******************************", name); gettimeofday(&tv1, NULL); r = function(t); gettimeofday(&tv2, NULL); if (r == FAIL) error("** test failed ************************************"); diff = timediff(&tv2, &tv1); warn("** end of test %s : %2.2f seconds ******************", name, diff); return r; }
static void dumpobs(obs_t *obs) { gtime_t time={0}; int i; char str[64]; printf("obs : n=%d\n",obs->n); for (i=0;i<obs->n;i++) { time2str(obs->data[i].time,str,3); printf("%s : %2d %2d %13.3f %13.3f %13.3f %13.3f %d %d\n",str,obs->data[i].sat, obs->data[i].rcv,obs->data[i].L[0],obs->data[i].L[1], obs->data[i].P[0],obs->data[i].P[1],obs->data[i].LLI[0],obs->data[i].LLI[1]); assert(1<=obs->data[i].sat&&obs->data[i].sat<=32); assert(timediff(obs->data[i].time,time)>=-DTTOL); time=obs->data[i].time; } }
/* select sbas ephememeris ---------------------------------------------------*/ static seph_t *selseph(gtime_t time, int sat, const nav_t *nav) { double t,tmax=MAXDTOE_SBS,tmin=tmax+1.0; int i,j=-1; trace(4,"selseph : time=%s sat=%2d\n",time_str(time,3),sat); for (i=0;i<nav->ns;i++) { if (nav->seph[i].sat!=sat) continue; if ((t=fabs(timediff(nav->seph[i].t0,time)))>tmax) continue; if (t<=tmin) {j=i; tmin=t;} /* toe closest to time */ } if (j<0) { trace(3,"no sbas ephemeris : %s sat=%2d\n",time_str(time,0),sat); return NULL; } return nav->seph+j; }
void C1983Encoder::getPosition() { static int nOutput = 0; double fPeriod; double fSample; fPeriod = theCounter->GetPeriod(); fSample = fPeriod * EncoderPulseLength; if ((nOutput++ % 100) == 0) cout << "encoder test is " << fPeriod << "\n"; theCounter->Reset(); #if 0 short result; for (short bit = 16; bit > 0; bit--) { result <<= 1; result += theEncoder->Get(); encoderInterrupt->Pulse(PULSE_LENGTH); while (encoderInterrupt->IsPulsing()) { } } cout<<result<<endl; for (int i = 1; i <= 10; i++) { data[i] = data[i - 1]; data[0] = theEncoder->Get(); timeData[i] = timeData[i - 1]; timeData[0] = timediff(); } double tempRate = 0; for (int i = 0; i < 10; i++) { rate += (data[i] * (10 - i)/timeData[i]); } rate = tempRate / 55; #endif return; }
void register_response(struct queries *q, int timeout, char *note) { u_char *p; int size; int rcode; int id; id = ntohs(q->send.u.h.id); if (note == NULL) note = ""; countqueries++; if (timeout >= 0) { p = q->recvbuf; NS_GET16(size, p); response_size_sum += size; response_size_sum2 += size * size; if (response_size_min == 0 || response_size_min > size) response_size_min = size; if (response_size_max == 0 || response_size_max < size) response_size_max = size; rcode = p[3] & 0x0f; countrcode[rcode]++; countanswers++; if (verbose) printf("recv response id=%d rcode=%d size=%d rtt=%d\n", id, rcode, size, timeout); } else if (timeout == ERRZEROREAD) { countzeroread++; if (verbose) printf("recv response id=%d zeroread\n", id); } else if (timeout == TIMEOUTERROR) { counttimeout++; if (verbose) printf("recv timeout id=%d %" PRId64 " usec\n", id, timediff(¤t, &q->sent)); } else { counterror++; if (verbose) { printf("recv error id=%d errno=%d at %s (%s)\n", id, ERROROFFSET - timeout, note, strerror(errno)); } } #ifdef DEBUG printf("%ld.%03ld no=%d fd=%d %d %s\n", q->sent.tv_sec, q->sent.tv_usec/1000, q->no, q->fd, timeout, note); fflush(stdout); #endif }
/* This function restricts the prediction to the collisionless particles. * Since SPH particles are predicted every timestep, this routine is * called before the tree-construction in order not to save some time * by not redoing the SPH prediction a second time. */ void predict_collisionless_only(double time) { int i,j; double dt,dt_h0; double s_a,s_a_inverse; double t0, t1; t0=second(); if(All.ComovingIntegrationOn) { s_a=All.Hubble*sqrt(All.Omega0 + time*(1-All.Omega0-All.OmegaLambda)+pow(time,3)*All.OmegaLambda); s_a_inverse=1/s_a; for(i=1+N_gas;i<=NumPart;i++) { dt = time - P[i].CurrentTime; dt_h0 = dt*s_a_inverse; for(j=0;j<3;j++) { P[i].PosPred[j] = P[i].Pos[j] + P[i].Vel[j]*dt_h0; P[i].VelPred[j] = P[i].Vel[j] + P[i].Accel[j]*dt; } } } else { for(i=1+N_gas;i<=NumPart;i++) { dt = time - P[i].CurrentTime; for(j=0;j<3;j++) { P[i].PosPred[j] = P[i].Pos[j] + P[i].Vel[j]*dt; P[i].VelPred[j] = P[i].Vel[j] + P[i].Accel[j]*dt; } } } t1=second(); All.CPU_Predict+= timediff(t0,t1); }
C1983Encoder::C1983Encoder(UINT32 channel) { theEncoder = new DigitalInput(channel); theCounter = new Counter(theEncoder); theNotifier = new Notifier(C1983Encoder::callGetPosition,this); theCounter->SetMaxPeriod(1.0); theCounter->SetSemiPeriodMode(true); theCounter->Reset(); theCounter->Start(); m_nCounts = 0; data = new double[10]; timeData = new double[10]; timediff(); theNotifier->StartPeriodic(0.005); }