/* * Given time strings representing 'update time' and 'stale time', * calculate mIsExpired and mIsStale. */ void CrlInfo::validateTimes( const char *updateTime, // now - expireOverlap const char *staleTime, // now - staleTime unsigned dex) // for debug info { CSSM_DATA *nextUpdateData = fetchValidAttr(ATTR_DEX_NEXT_UPDATE); if((nextUpdateData == NULL) || (nextUpdateData->Length != CSSM_TIME_STRLEN)) { ocspdErrorLog("CrlInfo::validateTimes: Badly formed NextUpdate attr on " "CRL %u", dex); mIsBadlyFormed = true; return; } printString("NextUpdate ", nextUpdateData); char *nextUpdate = (char *)nextUpdateData->Data; if(compareTimes(nextUpdate, updateTime) < 0) { ocspdCrlDebug("...CRL %u is expired", dex); mIsExpired = true; if(compareTimes(nextUpdate, staleTime) < 0) { ocspdCrlDebug("...CRL %u is stale", dex); mIsStale = true; } /* note it can't be stale and not expired */ } }
void PresentationAudioPage::updateTracksNumber() { QTime displayTime(0, 0, 0); int number = m_SoundFilesListBox->count(); if ( number > 0 ) { displayTime.addMSecs(1000 * (number - 1)); for (QMap<QUrl, QTime>::iterator it = d->tracksTime->begin(); it != d->tracksTime->end(); ++it) { int hours = it.value().hour() + displayTime.hour(); int mins = it.value().minute() + displayTime.minute(); int secs = it.value().second() + displayTime.second(); /* QTime doesn't get a overflow value in input. They need * to be cut down to size. */ mins = mins + (int)(secs / 60); secs = secs % 60; hours = hours + (int)(mins / 60); displayTime = QTime(hours, mins, secs); } } m_timeLabel->setText(i18ncp("number of tracks and running time", "1 track [%2]", "%1 tracks [%2]", number, displayTime.toString())); m_soundtrackTimeLabel->setText(displayTime.toString()); d->totalTime = displayTime; compareTimes(); }
//////////////////////////////////////////////////////////////////////////////// // // Function : evict // Description : Implement LRU cache eviction policy // // Inputs : buf - the buffer to put into the cache // drm - the drum ID to place // blk - the block ID to place // Outputs : 0 if successful, -1 otherwise int evict(unsigned char *buf, SMSA_DRUM_ID drm, SMSA_BLOCK_ID blk) { int i; // For each element of the chache... for( i = 0; i < num_cacheLines; i++ ) { // If least recently used if(compareTimes(&cacheLines[lruIndex].used, &cacheLines[i].used) > 0) { // Remember the index lruIndex = i; } } /* By now we have the least recently used cache entry */ // free the LRU cache if(cacheLines[lruIndex].line != NULL) { free(cacheLines[lruIndex].line); cacheLines[lruIndex].line = NULL; } // Replace cache cacheLines[lruIndex].drum = drm; cacheLines[lruIndex].block = blk; cacheLines[lruIndex].line = buf; // Set timestamp gettimeofday(&cacheLines[lruIndex].used, NULL); // Return successfully return 0; }
void GUI_TextField::InputDigit(int chr) { timeval currtime; gettimeofday(&currtime, NULL); if (chr == -1) { input_time.tv_sec = 0; input_time.tv_usec = 0; } else if (inpdigit == chr && compareTimes(&currtime, &input_time)) { // We are already in digit input mode and the same button was pressed within the time limit // In this case, we rotate through the available digits for this character bool was_valid = false; const char *lastptr = inpdigitptr; bool insert = false; while (!was_valid) { inpdigitptr++; if (inpdigitptr[0] == '\0') { inpdigitptr = digitchars[inpdigit]; // back to start } if (inpdigitptr == lastptr) { insert = true; } was_valid = SendChar(inpdigitptr[0], insert); } // Reset timer gettimeofday(&input_time, NULL); input_time.tv_usec += TEXTINPUT_DELAY_TIME; } else { // New key inpdigit = chr; if (inpdigit != -1) { inpdigitptr = digitchars[inpdigit]; // back to start bool was_valid = false; while (true) { was_valid = SendChar(inpdigitptr[0], true); if (was_valid) { break; } inpdigitptr++; if (inpdigitptr[0] == '\0') { break; } } if (inpdigitptr[0] != '\0') { // Start timer gettimeofday(&input_time, NULL); input_time.tv_usec += TEXTINPUT_DELAY_TIME; } } } }
void PresentationAudioPage::slotImageTotalTimeChanged( const QTime& imageTotalTime ) { d->imageTime = imageTotalTime; m_slideTimeLabel->setText(imageTotalTime.toString()); compareTimes(); }
int DiffHypocenters(int argc, char** argv) { int istat1, istat2; char fn_hyp1[FILENAME_MAX]; char fn_hyp2[FILENAME_MAX]; char fn_out[FILENAME_MAX]; char fn_out1[FILENAME_MAX]; char fn_out2[FILENAME_MAX]; FILE *fp_hyp1, *fp_hyp2; FILE *fp_hyp1_out, *fp_hyp2_out, *fp_gmt_out; FILE *fp_gmt_dist_out, *fp_gmt_az_out, *fp_gmt_depth_out, *fp_gmt_horiz_out; char *pchr, *pstmp1, *pstmp2; double time_tolerance; int nobs_tolerance; int nLocMatched, nArrivals, nHypo1, nHypo2; int idiff, ok; HypoDesc Hypo1, Hypo2; GridDesc locgrid; double angle, x1, x2, y1, y2, dx, dy, dz, azim; /* get command line parameters */ strcpy(fn_hyp1, argv[1]); strcpy(fn_hyp2, argv[2]); sscanf(argv[3], "%lf", &time_tolerance); sscanf(argv[4], "%d", &nobs_tolerance); pstmp1 = strrchr(fn_hyp1, '/'); if (pstmp1 == NULL) pstmp1 = fn_hyp1; else pstmp1++; pstmp2 = strrchr(fn_hyp2, '/'); if (pstmp2 == NULL) pstmp2 = fn_hyp2; else pstmp2++; /* open hyp input files */ if ((fp_hyp1 = fopen(fn_hyp1, "r")) == NULL) { puterr2("ERROR: opening hyp file: ", fn_hyp1); return(-1); } if ((fp_hyp2 = fopen(fn_hyp2, "r")) == NULL) { puterr2("ERROR: opening hyp file: ", fn_hyp1); return(-1); } /* open hyp output files */ sprintf(fn_out1, "diff_%s", pstmp1); if ((fp_hyp1_out = fopen(fn_out1, "w")) == NULL) { puterr2("ERROR: opening hyp output file: ", fn_out1); return(-1); } sprintf(fn_out2, "diff_%s", pstmp2); if ((fp_hyp2_out = fopen(fn_out2, "w")) == NULL) { puterr2("ERROR: opening hyp output file: ", fn_out2); return(-1); } /* open gmt output files */ sprintf(fn_out, "diff_%s_%s.xyz", pstmp1, pstmp2); if ((fp_gmt_out = fopen(fn_out, "w")) == NULL) { puterr2("ERROR: opening gmt output file:", fn_out); return(-1); } sprintf(fn_out, "diff_%s_%s.dist", pstmp1, pstmp2); if ((fp_gmt_dist_out = fopen(fn_out, "w")) == NULL) { puterr2("ERROR: opening gmt dist output file:", fn_out); return(-1); } sprintf(fn_out, "diff_%s_%s.az", pstmp1, pstmp2); if ((fp_gmt_az_out = fopen(fn_out, "w")) == NULL) { puterr2("ERROR: opening gmt az output file:", fn_out); return(-1); } sprintf(fn_out, "diff_%s_%s.depth", pstmp1, pstmp2); if ((fp_gmt_depth_out = fopen(fn_out, "w")) == NULL) { puterr2("ERROR: opening gmt depth output file:", fn_out); return(-1); } sprintf(fn_out, "diff_%s_%s.horiz", pstmp1, pstmp2); if ((fp_gmt_horiz_out = fopen(fn_out, "w")) == NULL) { puterr2("ERROR: opening gmt horiz output file:", fn_out); return(-1); } /* difference cooresponding hypocenters */ nLocMatched = 0; if ((istat2 = GetHypLoc(fp_hyp2, fn_hyp2, &Hypo2, NULL, &NumArrivals, 0, &locgrid, 0)) >= 0 && istat2 != EOF) nHypo2++; while (istat2 >= 0 && istat2 != EOF && (istat1 = GetHypLoc(fp_hyp1, fn_hyp1, &Hypo1, NULL, &NumArrivals, 0, &locgrid, 0)) >= 0 && istat1 != EOF) { nHypo1++; ok = 0; while (1) { idiff = compareTimes(Hypo1.year, Hypo2.year, Hypo1.month, Hypo2.month, Hypo1.day, Hypo2.day, Hypo1.hour, Hypo2.hour, Hypo1.min, Hypo2.min, Hypo1.sec, Hypo2.sec, time_tolerance); //WriteLocation(stdout, &Hypo1, Arrival, 0, fn_hyp1, 0, 0, 1, &locgrid, 0); //WriteLocation(stdout, &Hypo2, Arrival, 0, fn_hyp2, 0, 0, 1, &locgrid, 0); if (idiff == 0) { // match ok = 1; break; } else if (idiff > 0) { // hypo2 earlier, read next hypo2 if ((istat2 = GetHypLoc(fp_hyp2, fn_hyp2, &Hypo2, NULL, &NumArrivals, 0, &locgrid, 0)) >= 0 && istat2 != EOF) { nHypo2++; continue; } else // error or EOF hypo2 break; } else { // hypo2 later, read next hypo1 break; } } if (!ok) continue; if (fabs(Hypo1.nreadings - Hypo2.nreadings) > (double) (nobs_tolerance) + 0.1) { //fprintf(stdout, "nobs diff:\n"); //WriteLocation(stdout, &Hypo1, Arrival, 0, fn_hyp1, 0, 0, 1, &locgrid, 0); //WriteLocation(stdout, &Hypo2, Arrival, 0, fn_hyp2, 0, 0, 1, &locgrid, 0); continue; } // output difference WriteLocation(fp_hyp1_out, &Hypo1, Arrival, 0, fn_hyp1, 0, 0, 0, &locgrid, 0); fprintf(fp_hyp1_out, "END_NLLOC\n\n"); WriteLocation(fp_hyp2_out, &Hypo2, Arrival, 0, fn_hyp2, 0, 0, 0, &locgrid, 0); fprintf(fp_hyp2_out, "END_NLLOC\n\n"); strcpy(fn_out, fn_out1); pchr = strstr(fn_out, ".hyp"); *pchr = '\0'; WriteGrid3dHdr(&locgrid, NULL, fn_out, NULL); strcpy(fn_out, fn_out2); pchr = strstr(fn_out, ".hyp"); *pchr = '\0'; WriteGrid3dHdr(&locgrid, NULL, fn_out, NULL); fprintf(fp_gmt_out, "> GMT_LATLONDEPTH\n"); fprintf(fp_gmt_out, "%lf %lf %lf\n", Hypo1.dlat, Hypo1.dlong, Hypo1.depth); fprintf(fp_gmt_out, "%lf %lf %lf\n", Hypo2.dlat, Hypo2.dlong, Hypo2.depth); // set simple transform (assume no rotation!) map_itype[0] = MAP_TRANS_SIMPLE; strcpy(map_trans_type[0], "SIMPLE"); map_orig_lat[0] = Hypo1.dlat; map_orig_long[0] = Hypo2.dlong; map_rot[0] = 0.0; angle = -cRPD * map_rot[0]; map_cosang[0] = cos(angle); map_sinang[0] = sin(angle); latlon2rect(0, Hypo1.dlat, Hypo1.dlong, &x1, &y1); latlon2rect(0, Hypo2.dlat, Hypo2.dlong, &x2, &y2); dx = x1 - x2; dy = y1 - y2; dz = Hypo1.depth - Hypo2.depth; fprintf(fp_gmt_dist_out, "%lf\n", sqrt(dx * dx + dy * dy + dz * dz)); fprintf(fp_gmt_depth_out, "%lf\n", dz); fprintf(fp_gmt_horiz_out, "%lf\n", sqrt(dx * dx + dy * dy)); azim = atan2(dx, dy) / cRPD; if (azim < 0.0) azim += 360.0; fprintf(fp_gmt_az_out, "%lf\n", azim); nLocMatched++; if ((istat2 = GetHypLoc(fp_hyp2, fn_hyp2, &Hypo2, NULL, &NumArrivals, 0, &locgrid, 0)) >= 0 && istat2 != EOF) nHypo2++; } printf("\n%d/%d read, %d matched.\n:", nHypo1, nHypo2, nLocMatched); return(0); }
void SoundtrackDialog::slotImageTotalTimeChanged( const QTime& imageTotalTime ) { m_imageTime = imageTotalTime; m_slideTimeLabel->setText(imageTotalTime.toString()); compareTimes(); }