// // hpti -- Convert hp/Agilent Time Interval Counter output. // // - HP 53131A/53132A counters output data in a human friendly format // that contains thousands separators and scaling units. // - This tool removes the commas, applies the scaling (e.g., us means // microseconds), skips over statistics lines, and outputs the data // in a standard floating point format. // // 28-Dec-2010 Tom Van Baak (tvb) www.LeapSecond.com/tools // #include #include #include double hp53131 (char *line); void main (int argc, char *argv[]) { char line[1000], timestamp[1000]; int n; double scale, value; while (fgets(line, sizeof line, stdin) != NULL) { scale = hp53131(line); if (scale != 0) { n = sscanf(line, "%lf %lf", &value, &value); if (n == 1) { printf("%.15le\n", scale * value); } // If two fields assume first is timestamp and second is value. if (n == 2) { n = sscanf(line, "%s %lf", timestamp, &value); printf("%s %.15le\n", timestamp, scale * value); } } } } // Handle HP/Agilent 53131A/53132A RS-232 output format. double hp53131 (char *line) { char *p; // Ignore user comments. if (line[0] == '#') { return 0; } // Ignore HP 53131A statistics (look for colon and space). if (strstr(line, ": ") != NULL) { return 0; } // Remove embedded commas (US version HP 53131A). while ((p = strchr(line, ',')) != NULL) { strcpy(p, p + 1); } // Handle HP microsecond and second units. if (strstr(line, " us") != NULL) { return 1e-6; } else if (strstr(line, " s") != NULL) { return 1.0; } return 1.0; } #if 0 Sample HP talk-only serial output for time interval measurements: 1.009,3 us 1.003,7 us 1.059,7 us N : 60 STD DEV: 0.020,26 us MEAN : 1.014,33 us MAX : 1.059,7 us MIN : 0.972,6 us 1.054,4 us 1.050,0 us 1.044,4 us ... Same, but with time stamps (MJD): 55558.638530 1.009,3 us 55558.638541 1.003,7 us 55558.638554 1.059,7 us ... #endif