*** /dev/null Tue Jan 1 04:00:00 1980 --- Makefile Sun Dec 3 17:18:37 2000 *************** *** 0 **** --- 1,75 ---- + # + # NEEDS THE LIBRARY LEX_LIB passed from the make command line + # For solaris or sunos this should be -ll + # For linux it should be flex lib -lfl + # + EXEC = $(ARCH)/refrate + #CFLAGS = -I../include $(ADD_CFLAGS) + #LDFLAGS = -L../lib + CFLAGS = -I. $(ADD_CFLAGS) + LIBS = -lm $(LEX_LIB) + + #uncomment next 2 lines for linux + #ARCH = LINUX + #LIBS = -lm -lfl + + #CFLAGS = -I/passcal/prog/release1.8/src/include + #LDFLAGS =-L/passcal/prog/release1.8/src/lib + #LIBS = -lm -ll /passcal/prog/release1.8/src/lib/libpasscal.a.sun4 + # + HEADERS = arglist.h \ + driftcor.h \ + epoch.h \ + linfit.h \ + median.h \ + minmark.h \ + output.h \ + phase_fix.h \ + pulse.h \ + scan.h \ + scanP.h \ + tokens.h \ + truth.h + # + SRCS = clean_resets.c \ + driftcor.c \ + epoch.c \ + grab_range.c \ + lex.c \ + linfit.c \ + median.c \ + minmark.c \ + output.c \ + parse_julian.c \ + phase_fix.c \ + pulse.c \ + refrate.c \ + scan.c \ + util.c + + OBJS = $(SRCS:%.c=$(ARCH)/%.o) + + OBJDIR= $(ARCH) + + .SUFFIXES: .c .o + + all: $(EXEC) + $(EXEC): $(OBJDIR) $(OBJS) + $(CC) -o $(EXEC) $(LDFLAGS) $(OBJS) $(LIBS) $(CFLAGS) + + $(ARCH)/%.o: %.c + $(CC) $(CFLAGS) -c $(@F:.o=.c) -o $@ $(INCLUDE) $(DEFS) + + lex.c: lex.l tokens.h + $(LEX) $(LEX_FLAGS) lex.l + mv lex.yy.c lex.c + + clean_resets.o phase_fix.o: tokens.h + clean_resets.o output.o refrate.o: arglist.h + scan.o phase_fix.o output.o grab_range.o clean_resets.o: scan.h + + $(OBJDIR): + mkdir $(OBJDIR) ; chmod go+rx $(OBJDIR) + + clean: + @$(RM) $(ARCH)/*.o $(EXEC) *** arglist.h.orig Thu Oct 19 15:36:18 1995 --- arglist.h Sat Dec 2 20:44:13 2000 *************** *** 14,19 **** --- 14,20 ---- int zipstart; int ignore_stop_start; int ignore_stop_start_merge; + int use_clock_power; char *julian_string; char *clockfile; } ArgList; *** lex.l.orig Mon Aug 21 19:07:11 1995 --- lex.l Thu Jan 18 22:37:14 2001 *************** *** 1,8 **** --- 1,17 ---- %{ #include "tokens.h" + #ifdef LINUX + /* LINUX lex forbids redefinition of input. YY_INPUT hook used instead. */ + #define YY_INPUT(buf,result,max_size) { \ + int c = get_next(); \ + result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ + } + #else + /* AT&T lex allows redefinition of input */ #undef input #define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):get_next())==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar) + #endif /* LINUX */ /* definitions of manifest constants */ %} *************** *** 15,28 **** jerk [J] start [B] stop [E] ! resetseq1 {phase}+{jerk}{phase}*{reset}{reset} ! resetseq2 {phase}+{jerk}{phase}*{reset} ! resetseq3 {phase}+{reset}{jerk}{phase}{reset} ! resetseq4 {phase}+{jerk}{phase}*{reset}{phase}{reset} ! resetseq5 {phase}+{reset}{reset}{jerk} ! resetseq6 {phase}+{reset}{jerk} ! resetseq7 {phase}+{reset}{jerk}{reset} %% {resetseq1} return (RESET_SEQUENCE1); {resetseq2} return (RESET_SEQUENCE2); {resetseq3} return (RESET_SEQUENCE3); --- 24,41 ---- jerk [J] start [B] stop [E] ! resetseqb {lock}{phase}+{reset}(({unlock}+{lock})*{phase})*{reset}{phase}*{unlock} ! resetseq1 {lock}{phase}*{jerk}{phase}*{reset}{reset} ! resetseq2 {lock}{phase}*{jerk}{phase}*{reset} ! resetseq3 {lock}{phase}*{reset}{jerk}{phase}({phase}*{reset})+ ! resetseq4 {lock}{phase}*{jerk}{phase}*{reset}{phase}+{reset} ! resetseq5 {lock}{phase}*{reset}{reset}{jerk} ! resetseq6 {lock}{phase}*{reset}{jerk} ! resetseq7 {lock}{phase}*{reset}{jerk}{reset} ! resetseq8 {start}({unlock}|{reset})*({resetseq1}|{resetseq2}|{resetseq3}|{resetseq4}|{resetseq5}|{resetseq6}|{resetseq7}|({lock}{phase}+{reset})) ! resetseq9 {unlock}(({jerk}{reset}({unlock}{0,10}{reset}+)?)|({reset}{unlock}{0,10}{reset}*{jerk}{reset}({unlock}{0,10}{reset}+)?)) %% + {resetseqb} return (RESET_SEQUENCEB); {resetseq1} return (RESET_SEQUENCE1); {resetseq2} return (RESET_SEQUENCE2); {resetseq3} return (RESET_SEQUENCE3); *************** *** 30,34 **** --- 43,49 ---- {resetseq5} return (RESET_SEQUENCE5); {resetseq6} return (RESET_SEQUENCE6); {resetseq7} return (RESET_SEQUENCE7); + {resetseq8} return (RESET_SEQUENCE8); + {resetseq9} return (RESET_SEQUENCE9); . return (IGNORE_ITEM); %% *** output.c.orig Thu Apr 18 22:11:39 1996 --- output.c Sat Dec 9 20:26:53 2000 *************** *** 8,13 **** --- 8,16 ---- #include "util.h" #include "output.h" + /* set to 20 min and 80 min for starting 1999.307 */ + #define BOGUS1SEC_TOLERANCE 1200 /* seconds to match +/-1SEC DSP CLOCK SETS */ + #define MAX_BOGUS1SEC_TOLERANCE 4800 /* max seconds to match +/-1SEC DSP CLOCK SETS */ #ifndef TRUE #define TRUE 1 *************** *** 19,32 **** static int das_num; void output (loglist) LOGLIST *loglist; { ANYITEM *current_ptr=loglist->item_head; ! ANYITEM *next_ptr; CORRECTION result; int SRS, SRU, USR, success, good_match; if (arglist.debug) { fprintf (stdout, --- 22,42 ---- static int das_num; + void output (loglist) LOGLIST *loglist; { ANYITEM *current_ptr=loglist->item_head; ! ANYITEM *next_ptr, *next_reset_ptr; ! ANYITEM *last_bad_reset_ptr; /* holds the last 1 sec corrective pulse */ ! Epoch diff_epoch, *tmp_epoch_ptr, *tmp_epoch_ptr2; ! Epoch add_epoch(); CORRECTION result; int SRS, SRU, USR, success, good_match; + + last_bad_reset_ptr = NULL; + next_reset_ptr = NULL; if (arglist.debug) { fprintf (stdout, *************** *** 138,147 **** do { good_match = 0; ! next_ptr = first_occurrence (next_ptr, "BEPR"); if (next_ptr == NULL) break; /* Special rule for USR Unlock-PULSESET-Reset --- 148,172 ---- do { good_match = 0; ! next_ptr = first_occurrence (next_ptr, "BEPRU"); if (next_ptr == NULL) break; + if ((char)next_ptr->type == 'U') { + /* Follow successive unlocks in case + stop acq follows - want latest unlock + before stop */ + ANYITEM *scroll; + scroll = first_occurrence (next_ptr, "BEPR"); + if (scroll != NULL && (char)scroll->type=='E') { + current_ptr = scroll->previous_item; + next_ptr = scroll; + continue; + } + if (scroll==NULL) break; + next_ptr = scroll; + } + /* Special rule for USR Unlock-PULSESET-Reset *************** *** 150,156 **** (char)next_ptr->previous_item->type == 'S') { good_match=1; USR = TRUE; ! } else if (strchr("BEP", (char)next_ptr->type) != NULL) good_match=1; else { --- 175,181 ---- (char)next_ptr->previous_item->type == 'S') { good_match=1; USR = TRUE; ! } else if (strchr("BEPR", (char)next_ptr->type) != NULL) good_match=1; else { *************** *** 195,200 **** --- 220,271 ---- good_match = 0; next_ptr = first_occurrence(next_ptr, "BEPRSU"); + next_reset_ptr = first_occurrence(next_ptr, "R"); + + + #if 0 + /* 1999.307 --- 1 SECOND BUG SQUASHING */ + /* see if this current_ptr was paired with a + 1 SEC reset already! */ + if (next_reset_ptr !=NULL && current_ptr != last_bad_reset_ptr) { + + diff_epoch=add_epoch( &(((RESET *)current_ptr)->diff), &(((RESET *)next_reset_ptr)->diff)); + + tmp_epoch_ptr = &(((RESET *)current_ptr)->diff); + tmp_epoch_ptr2 = &(((RESET *)next_reset_ptr)->diff); + if (diff_epoch.sec == 0 && diff_epoch.usec == 0) { + /* we may have a 1 sec bug */ + tmp_epoch_ptr = &(((RESET *)current_ptr)->diff); + /* now check timespan between resets */ + diff_epoch = subtract_epoch(&(next_reset_ptr->epoch), &(current_ptr->epoch)); + if ((int)fabs((double)tmp_epoch_ptr->sec) == 1 && tmp_epoch_ptr->usec == 0 && diff_epoch.sec < BOGUS1SEC_TOLERANCE) { + /* 1 second bug detected */ + fprintf (stderr, "CASE 1: 1 SECOND BUG DETECTED within 1 LOCK period!\n Repairing PCF: Correction pulse %d secs from this item.\n", diff_epoch.sec); + fprintf (stderr, "Item in question: "); + print_item (stderr, current_ptr); + /* make it a reset reset */ + next_ptr = next_reset_ptr; + + /* flag that we used the next 1 SEC DSP to correct this one. */ + last_bad_reset_ptr = next_ptr; + good_match=1; + break; + } + if ((int)fabs((double)tmp_epoch_ptr->sec) == 1 && tmp_epoch_ptr->usec == 0 && diff_epoch.sec < MAX_BOGUS1SEC_TOLERANCE) { + /* 1 second bug detected */ + fprintf (stderr, "CASE 2: 1 SECOND BUG DETECTED OUTSIDE 1 LOCK period!\n Repairing PCF: Correction pulse %d secs from this item.\n", diff_epoch.sec); + fprintf (stderr, "Item in question: "); + print_item (stderr, current_ptr); + /* make it a reset reset */ + next_ptr = next_reset_ptr; + /* flag that we used the next 1 SEC DSP to correct this one. */ + last_bad_reset_ptr = next_ptr; + good_match=1; + break; + } + } + } + #endif if (next_ptr == NULL) break; /* *************** *** 241,246 **** --- 312,318 ---- if (arglist.debug) print_items (current_ptr, next_ptr); + /* S = PULSE TIME SET CASE */ if (SRU) success = do_sru(current_ptr, next_ptr, &result); else if (SRS) *************** *** 421,426 **** --- 493,503 ---- int success; switch (next->type) { + case PULSE_TIMESET: + /* this case was a -p case, but was not handled untill now 98.085 */ + success = pulse_pulse (pulse, (PULSE *) next, result); + if (success) print_result (result); + return (success); case PHASE_ERROR: success = pulse_phase (pulse, (PHASE *) next, result); if (success) print_result (result); *************** *** 607,615 **** double y2; CORRECTION *result; { ! double m, b; ! m = (y2 -y1) / (x2 - x1); b = -m*x1 + y1; result->driftrate = m; --- 684,694 ---- double y2; CORRECTION *result; { ! double m, b, diff; ! diff = x2 - x1; ! if (diff == 0.0) return(0); ! m = (y2 -y1) / diff; b = -m*x1 + y1; result->driftrate = m; *************** *** 753,768 **** return(success); } - int pulse_reset (pulse, reset, result) PULSE *pulse; RESET *reset; CORRECTION *result; { ! result->epoch = pulse->epoch; ! result->driftrate = 0.0; ! result->offset = 0.0; return (1); } /* --- 832,866 ---- return(success); } int pulse_reset (pulse, reset, result) PULSE *pulse; RESET *reset; CORRECTION *result; { ! result->epoch = pulse->epoch; ! result->driftrate = 0.0; ! result->offset = 0.0; ! return (1); ! } ! ! /* 98.085 - added this "new" case in that should have been here before */ ! int ! pulse_pulse (pulse1, pulse2, result) ! PULSE *pulse1; ! PULSE *pulse2; ! CORRECTION *result; ! { ! Epoch epoch_diff; ! double x1, y1, x2, y2; ! ! epoch_diff = subtract_epoch (&pulse2->epoch, &pulse1->epoch); ! x2 = epoch2double (&epoch_diff) * 1000.0; ! y2 = pulse2->error; ! ! result->epoch = pulse1->epoch; ! result->offset = 0.0; /* last Pulse presumably zeroed the time */ ! result->driftrate = y2/x2; return (1); } /* *************** *** 864,872 **** epoch_diff = subtract_epoch (&pulse->epoch, &result->epoch); x2 = epoch2double (&epoch_diff) * 1000.0; ! /* offset of second DSP reset assumed to be 0 msec */ ! y1 = 0.0; ! y2 = (pulse->error + 0.005) * 1000.0; success = line_eqn (x1, y1, x2, y2, result); --- 962,973 ---- epoch_diff = subtract_epoch (&pulse->epoch, &result->epoch); x2 = epoch2double (&epoch_diff) * 1000.0; ! /* offset of second DSP reset assumed to be 0 msec if clock locked */ ! if (reset->unlocked) ! y1 = result->offset; ! else ! y1 = 0.0; ! y2 = y1 + (pulse->error + 0.005) * 1000.0; success = line_eqn (x1, y1, x2, y2, result); *************** *** 900,907 **** else result->epoch = reset->oldepoch; ! /* If RESET and PHASE have the same time tag */ ! /* don't bother with a correction. */ if (compare_epoch (&result->epoch, &phase->epoch) >= 0) { phase->epoch = result->epoch; return (0); --- 1001,1008 ---- else result->epoch = reset->oldepoch; ! /* If RESET and PHASE have the same time tag ! don't bother with a correction */ if (compare_epoch (&result->epoch, &phase->epoch) >= 0) { phase->epoch = result->epoch; return (0); *************** *** 914,922 **** epoch_diff = subtract_epoch (&phase->epoch, &result->epoch); x2 = epoch2double (&epoch_diff) * 1000.0; ! /* offset of second DSP reset assumed to be 0 msec */ ! y1 = 0.0; ! y2 = (double) phase2msec (phase->error); success = line_eqn (x1, y1, x2, y2, result); --- 1015,1026 ---- epoch_diff = subtract_epoch (&phase->epoch, &result->epoch); x2 = epoch2double (&epoch_diff) * 1000.0; ! /* offset of second DSP reset assumed to be 0 msec if clock locked */ ! if (reset->unlocked) ! y1 = result->offset; ! else ! y1 = 0.0; ! y2 = y1 + (double) phase2msec (phase->error); success = line_eqn (x1, y1, x2, y2, result); *************** *** 936,942 **** CORRECTION *result; { Epoch epoch_diff; ! int msec_diff; int status; if (compare_epoch (&reset->newepoch, &reset->oldepoch) > 0) --- 1040,1046 ---- CORRECTION *result; { Epoch epoch_diff; ! int msec_diff, msec_cumulative_diff; int status; if (compare_epoch (&reset->newepoch, &reset->oldepoch) > 0) *************** *** 947,952 **** --- 1051,1057 ---- epoch_diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); status = epoch2msec (&msec_diff, &epoch_diff); + status = epoch2msec (&msec_cumulative_diff, &reset->cumulative_sequence_diff); result->driftrate = 0.0; result->offset = result->offset - (double) msec_diff; *************** *** 993,999 **** CORRECTION *result; { Epoch reset_epoch, epoch_diff; ! int msec_diff, status; int correction; if (compare_epoch (&reset->newepoch, &reset->oldepoch) > 0) --- 1098,1104 ---- CORRECTION *result; { Epoch reset_epoch, epoch_diff; ! int msec_diff, msec_cumulative_diff, status; int correction; if (compare_epoch (&reset->newepoch, &reset->oldepoch) > 0) *************** *** 1001,1015 **** else reset_epoch = reset->oldepoch; correction = eval_correction (result, &reset_epoch); epoch_diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); status = epoch2msec (&msec_diff, &epoch_diff); result->epoch = reset_epoch; result->driftrate = 0.0; ! result->offset = (double) (correction - msec_diff); return (1); } --- 1106,1134 ---- else reset_epoch = reset->oldepoch; + /* 98.348, okay see if this is a 1 second reset and the last + reset is out of sequence ! (2.70H cpu bug) */ + if (reset->previous != NULL && reset->previous->reset_num != reset->reset_num-1 && + reset->diff.sec==1) { + fprintf(stderr, "Output: Warning 2.70H bug detected and patched: dsp number %d\n", reset->reset_num); + result->epoch = reset_epoch; + result->driftrate = 0.0; + result->offset = 0.0; + return(1); + } + correction = eval_correction (result, &reset_epoch); epoch_diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); status = epoch2msec (&msec_diff, &epoch_diff); + status = epoch2msec (&msec_cumulative_diff, + &(reset->cumulative_sequence_diff)); result->epoch = reset_epoch; result->driftrate = 0.0; ! result->offset = reset->reset_in_sequence==TRUE ? 0 : ! (double) (correction - msec_diff); return (1); } *************** *** 1041,1047 **** y1 = result->offset; y2 = (double) phase2msec (phase->error); ! success = line_eqn (x1, y1, x2, y2, result); return(success); --- 1160,1172 ---- y1 = result->offset; y2 = (double) phase2msec (phase->error); ! ! /* 97.191 - unlock and phase had same time stamp!!! */ ! if ( (x2 - x1) == 0.0) { ! /* special case, NaN was resulting , carry forward offset*/ ! result->driftrate = 0.0; ! return(1); ! } success = line_eqn (x1, y1, x2, y2, result); return(success); *************** *** 1109,1124 **** reset_epoch = reset->newepoch; else reset_epoch = reset->oldepoch; ! x1 = 0.0; epoch_diff = subtract_epoch (&reset_epoch, &unlock->epoch); /* convert to msec */ x2 = epoch2double (&epoch_diff) * 1000.0; y1 = result->offset; ! reset_diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); ! y2 = epoch2double (&reset_diff) * 1000.0; success = line_eqn (x1, y1, x2, y2, result); --- 1234,1256 ---- reset_epoch = reset->newepoch; else reset_epoch = reset->oldepoch; ! x1 = 0.0; + epoch_diff = subtract_epoch (&reset_epoch, &unlock->epoch); /* convert to msec */ x2 = epoch2double (&epoch_diff) * 1000.0; y1 = result->offset; ! if (reset->reset_in_sequence) ! reset_diff = reset->cumulative_sequence_diff; ! else ! reset_diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); ! if (reset->unlocked) ! y2 = y1; ! else ! y2 = epoch2double (&reset_diff) * 1000.0; success = line_eqn (x1, y1, x2, y2, result); *** phase_fix.c.orig Mon Aug 21 19:07:11 1995 --- phase_fix.c Sat Dec 9 21:53:15 2000 *************** *** 6,11 **** --- 6,13 ---- #include "tokens.h" #include "epoch.h" #include "util.h" + #include "truth.h" + #include "output.h" static ANYITEM *current_item; static ANYITEM *forward_item; *************** *** 51,63 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; - - case RESET_SEQUENCE2: (void) strncpy (lexume, yytext, 160); if (arglist.debug) --- 53,63 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; case RESET_SEQUENCE2: (void) strncpy (lexume, yytext, 160); if (arglist.debug) *************** *** 67,73 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; --- 67,73 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; *************** *** 81,87 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; --- 81,87 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; *************** *** 95,101 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; --- 95,101 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; *************** *** 109,115 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; --- 109,115 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; *************** *** 123,129 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; --- 123,129 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; *************** *** 137,146 **** net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset); current_item = advance (current_item, seq_length); break; default: fprintf (stderr, --- 137,225 ---- net_reset = total_diff (current_item, seq_length); ! correct_phases (current_item, seq_length, &net_reset, 0); ! ! current_item = advance (current_item, seq_length); ! break; ! ! case RESET_SEQUENCE8: { ! ANYITEM *first_phase; ! int first_phase_len; ! (void) strncpy (lexume, yytext, 160); ! if (arglist.debug) ! fprintf (stdout, ! "\nFound reset sequence%d: %s\n", token, lexume); ! seq_length = strlen (lexume); ! ! first_phase = first_occurrence(current_item,"L"); ! first_phase_len = strlen(strchr(lexume,'L')); ! ! net_reset = total_diff (first_phase, first_phase_len); ! ! correct_phases (current_item, seq_length, &net_reset, 0); current_item = advance (current_item, seq_length); break; + } + + case RESET_SEQUENCE9: + /* Odd case of no phase info, but want to track DSP + offset anyway. Arises with malfunctioning DAS/ext. + clock. */ + (void) strncpy (lexume, yytext, 160); + if (arglist.debug) + fprintf (stdout, + "\nFound reset sequence9: %s\n", lexume); + seq_length = strlen (lexume); + + net_reset = total_diff (current_item, seq_length); + + current_item = advance (current_item, seq_length); + break; + + case RESET_SEQUENCEB: { + /* Probable 1 second bug. Fix following phase to + include DAS clock offset. */ + RESET *first_reset, *last_reset; + int between_len; + + (void) strncpy (lexume, yytext, 160); + if (arglist.debug) + fprintf (stdout, + "\nFound reset sequenceB: %s\n", lexume); + seq_length = strlen (lexume); + + net_reset = total_diff (current_item, seq_length); + + if (net_reset.sec == 0.0 && net_reset.usec == 0) { + /* Total offset is zero - assume 1 second offset + corrected at a later time. */ + first_reset = + (RESET *)first_occurrence(current_item,"R"); + last_reset = + (RESET *)first_occurrence(first_reset->next_item,"R"); + + net_reset = last_reset->diff; + between_len = + 1 + strrchr(lexume,'R') - strchr(lexume,'R'); + + correct_phases ((ANYITEM *)first_reset, between_len, + &net_reset, 1); + + } else { + ANYITEM *ptr; + int i; + for (i=0, ptr=current_item; + (inext_item) { + if (ptr->type == DSP_RESET) + ((RESET *)ptr)->reset_in_sequence = FALSE; + } + } + + current_item = advance (current_item, seq_length); + break; + } default: fprintf (stderr, *************** *** 190,196 **** RESET *reset = (RESET *) ptr; Time gmt; ! diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); --- 269,275 ---- RESET *reset = (RESET *) ptr; Time gmt; ! reset->reset_in_sequence = TRUE; diff = subtract_epoch (&reset->newepoch, &reset->oldepoch); *************** *** 224,229 **** --- 303,318 ---- } } + /* Mark cumulative offset for slope calculation prior to reset */ + for (i=0, ptr=current_ptr; + (inext_item) { + if (ptr->type == DSP_RESET) { + RESET *reset = (RESET *) ptr; + reset->cumulative_sequence_diff = total; + } + } + if (arglist.debug) fprintf (stdout, "total: %5d sec %5d msec\n", total.sec, msec); *************** *** 245,254 **** } void ! correct_phases (current_ptr, seq_length, correction) ANYITEM *current_ptr; int seq_length; Epoch *correction; { int i; ANYITEM *ptr; --- 334,344 ---- } void ! correct_phases (current_ptr, seq_length, correction, add) ANYITEM *current_ptr; int seq_length; Epoch *correction; + int add; { int i; ANYITEM *ptr; *************** *** 284,292 **** old_phase = phase2msec (phase->error); fprintf (stdout, "PHASE: %s", string); fprintf (stdout, " old: %d\tnew: %d\n", ! old_phase, error); } ! phase->error = error*1000; } } } --- 374,384 ---- old_phase = phase2msec (phase->error); fprintf (stdout, "PHASE: %s", string); fprintf (stdout, " old: %d\tnew: %d\n", ! old_phase, ! add ? old_phase+error : error); } ! phase->error = ! add ? phase->error+error*1000 : error*1000; } } } *** phase_fix.h.orig Sat Dec 9 19:22:26 2000 --- phase_fix.h Sat Dec 9 19:21:48 2000 *************** *** 15,21 **** int get_next P_((void)); Epoch total_diff P_((ANYITEM *current_ptr, int seq_length)); ANYITEM *advance P_((ANYITEM *current_ptr, int seq_length)); ! void correct_phases P_((ANYITEM *current_ptr, int seq_length, Epoch *correction)); ANYITEM *advance P_((ANYITEM *current_ptr, int seq_length)); void encode_gmt P_((char *string, Time *gmt)); --- 15,21 ---- int get_next P_((void)); Epoch total_diff P_((ANYITEM *current_ptr, int seq_length)); ANYITEM *advance P_((ANYITEM *current_ptr, int seq_length)); ! void correct_phases P_((ANYITEM *current_ptr, int seq_length, Epoch *correction, int add)); ANYITEM *advance P_((ANYITEM *current_ptr, int seq_length)); void encode_gmt P_((char *string, Time *gmt)); *** refrate.c.orig Tue Nov 30 21:32:14 1999 --- refrate.c Thu Jan 18 22:17:42 2001 *************** *** 81,87 **** a DSP RESET... Basically, checking for NULL of a previous_item pointer. ! 96.106 added back -p option. */ #include --- 81,163 ---- a DSP RESET... Basically, checking for NULL of a previous_item pointer. ! VER 96.106 added back -p option. ! ! VER 99.033 fixed division by zero bug in phase-phase changes when ! two times were same (eliminates NaN # Phase-Phase in output). ! ! G. Helffrich/U. Bristol, 30 Nov. 1999 ! ! VER 00.151 merged PASSCAL code to incorporate 1 sec. bug fix in DAS ! software. ! ! G. Helffrich/U. Bristol, 30 May 2000 ! ! VER 00.331 fixed handling of successive DSP resets to include case in ! sequence 3 reset where DSP supplies three successive resets. ! ! G. Helffrich/U. Bristol, 26 Nov 2000 ! ! VER 00.335 fixed handling of DSP resets at first lock following start ! acquisition. This may leave a time tear at the start of the ! data stream, between the first and second ET records. ! Operationally, this lets impatient seismologists start acq ! in the field before a phase lock. ! ! G. Helffrich/U. Bristol, 30 Nov 2000 ! ! VER 00.336 fixed handling of successive DSP resets to include another ! case in sequence 3 reset where DSP supplies three successive ! resets with phase error reports in between them. ! ! G. Helffrich/U. Bristol, 2 Dec 2000 ! ! VER 00.337 added check to make sure clock powered on before refrate whii ! honor clock locks and phase errors. This is to prevent bogus ! clock locks when clock/DAS aren't interacting properly. Use ! option -P to defeat them and return to previous behavior. ! ! relax syntax to correct phase errors prior to and between ! DSP resets to handle case where first phase error appears ! after clock jerk. ! ! G. Helffrich/U. Bristol, 3 Dec 2000 ! ! VER 00.339 modify syntax to recognize variant of reset sequence 4. ! ! G. Helffrich/U. Bristol, 5 Dec 2000 ! ! VER 00.341 check for first sample time before start acquisition. If ! last start acq in span of first sample, set start acq time to ! first sample time - 1 msec. ! ! G. Helffrich/U. Bristol, 7 Dec 2000 ! ! VER 00.343 expand check for clock powered on by adding another case. ! Re-work parsing of DSP resets before first lock following start ! acquisition to include all variants of DSP reset sequences. ! ! Stripped out PASSCAL-supplied code to fix "1 second bugs" ! because it didn't work properly. ! ! Add lex grammar to check for 1 second bugs and compound 1 ! second clock correction to phase errors reported between the ! DSP resets that introduce and then remove the 1 second offset. ! ! G. Helffrich/U. Bristol, 9 Dec 2000 ! ! VER 01.019 add lex grammar to expand checks for 1 second bugs in case where ! unlock/lock does not occur between reset-reset pairs without a ! jerk anywhere between clock lock/unlock span. ! ! Simplify acquisition start recognition code pattern (no change ! in overall effect). ! ! Extend reset sequence 8 grammar to handle some forms of 1 ! second clock error on automatic start acq following power ! loss. ! ! G. Helffrich/U. Bristol, 18 Jan 2001 */ #include *************** *** 99,105 **** ArgList arglist; char *progname; ! char version[] = "96.106"; int --- 175,181 ---- ArgList arglist; char *progname; ! char version[] = "01.018"; int *************** *** 131,139 **** arglist.julian_string = NULL; arglist.ignore_stop_start = FALSE; arglist.ignore_stop_start_merge = FALSE; arglist.clockfile = NULL; ! while ((c = getopt(argc, argv, "c:dDhHj:mnpsz")) != -1) switch (c) { case 'c': arglist.clockfile = optarg; --- 207,216 ---- arglist.julian_string = NULL; arglist.ignore_stop_start = FALSE; arglist.ignore_stop_start_merge = FALSE; + arglist.use_clock_power = TRUE; arglist.clockfile = NULL; ! while ((c = getopt(argc, argv, "c:dDhHj:mnpPsz")) != -1) switch (c) { case 'c': arglist.clockfile = optarg; *************** *** 160,165 **** --- 237,245 ---- break; case 'p': arglist.pulsetime = TRUE; + break; + case 'P': + arglist.use_clock_power = FALSE; break; case 'z': arglist.zipstart = TRUE; *** refrate.man.orig Mon Apr 15 18:19:37 1996 --- refrate.man Sat Dec 2 21:42:12 2000 *************** *** 26,31 **** --- 26,39 ---- minute marks to calculate corrections. See \fB\-p\fR and \fB\-s\fR under OPTIONS for details. + \fBrefrate\fR uses the powered-on state of the external clock to decide + whether to believe any reported clock locks and phase errors in the log file. + Some malfunctions of particular DAS/GPS clock combinations yield spurious + lock and phase error reports even though the GPS clock is not operational. + If you completely trust your log file entries notwithstanding their reporting + of a malfunctioning clock, the \fB-P\fP option will defeat the clock power + checks. + .SH ARGUMENTS .TP \fIlogfile(s)\fR PASSCAL Ref-Tek logfile produced by ref2segy(l). *************** *** 70,75 **** --- 78,88 ---- .br goe 047:05:00:00.000 0.00 0.000 .TP + .B \-P + This option tells the program to ignore clock powered-on state when deciding + whether to accept clock locks and phase error reports. + Default behavior is to only accept them as true if log file also reports clock + powered on at time a lock and phase error is declared. .B \-p This option tells the program to use pulse time set information to get clock drifts and corrections. \fBNOTE: This option is now obsoleted by the *** scan.c.orig Thu Apr 20 22:48:27 2000 --- scan.c Sat Dec 9 14:18:05 2000 *************** *** 55,64 **** FILE *istream; LOGLIST *loglist; { ! char buf[80], *line=buf; ! int das, clock_found=0; ! while ((line = fgets (buf, 80, istream)) != NULL) { line_no++; --- 55,65 ---- FILE *istream; LOGLIST *loglist; { ! char buf[160], *line=buf; ! int das, clock_found=0, clock_power=0, clock_locked=0; ! ACQU *last_start = NULL; ! while ((line = fgets (buf, sizeof(buf), istream)) != NULL) { line_no++; *************** *** 66,71 **** --- 67,74 ---- if (kludge_4997 (line)) continue; + if (arglist.use_clock_power && !clock_power && !clock_locked) + continue; loglist->phase_tail = phase_error (loglist->phase_tail, line); if (loglist->phase_head == NULL) *************** *** 87,92 **** --- 90,96 ---- } if (strstr(line, "NOT LOCK") != NULL) { + clock_locked = 0; loglist->lock_tail = unlocked (loglist->lock_tail, line); if (loglist->lock_head == NULL) loglist->lock_head = loglist->lock_tail; *************** *** 106,111 **** --- 110,119 ---- } if (strstr(line, " LOCKED") != NULL) { + if (arglist.use_clock_power && !clock_power) + continue; + clock_locked = 1; + loglist->lock_tail = generic_item ((ANYITEM *) loglist->lock_tail, line); if (loglist->lock_head == NULL) *************** *** 126,131 **** --- 134,140 ---- } if (strstr(line, "UNLOCKED") != NULL) { + clock_locked = 0; loglist->lock_tail = generic_item ((ANYITEM *) loglist->lock_tail, line); if (loglist->lock_head == NULL) *************** *** 146,151 **** --- 155,161 ---- } if (strstr(line, "NO EXTERNAL CLOCK INPUT") != NULL) { + clock_locked = 0; clock_power = 0; loglist->lock_tail = generic_item ((ANYITEM *) loglist->lock_tail, line); if (loglist->lock_head == NULL) *************** *** 169,175 **** if ((strstr(line, "DSP clock set") != NULL) || (strstr(line, "DSP CLOCK SET") != NULL)) { loglist->reset_tail = ! dsp_reset (loglist->reset_tail, line); if (loglist->reset_head == NULL) loglist->reset_head = loglist->reset_tail; --- 179,186 ---- if ((strstr(line, "DSP clock set") != NULL) || (strstr(line, "DSP CLOCK SET") != NULL)) { loglist->reset_tail = ! dsp_reset (loglist->reset_tail, line, ! clock_locked); if (loglist->reset_head == NULL) loglist->reset_head = loglist->reset_tail; *************** *** 304,312 **** loglist->num_acqu++; ! if (strstr(line, "ACQUISITION STARTED") != NULL) loglist->acqu_tail->type = ACQU_STARTED; ! else if (strstr(line, "ACQUISITION STOP") != NULL) loglist->acqu_tail->type = ACQU_STOPPED; --- 315,324 ---- loglist->num_acqu++; ! if (strstr(line, "ACQUISITION STARTED") != NULL) { loglist->acqu_tail->type = ACQU_STARTED; ! last_start = loglist->acqu_tail; ! } else if (strstr(line, "ACQUISITION STOP") != NULL) loglist->acqu_tail->type = ACQU_STOPPED; *************** *** 315,320 **** --- 327,373 ---- } } + if ( strstr(line, "GPS: ") != NULL ) { + if ( strstr(line, "POWER IS TURNED") != NULL) + clock_power = strstr(line, "ON") != NULL; + else if ( strstr(line, "CMx RECEIVER") != NULL ) + clock_power = 1; + else if ( strstr(line, "GPS: V") != NULL ) + clock_power = 1; + else if ( strstr(line, "BATTERY BACKUP FAILED") != NULL ) + clock_power = 1; + continue; + } + + if (!strncmp("DAS: ",line,5)) { + if (NULL != last_start) { + /* Check if FST precedes last start time, and adjust if so. */ + Time gmt; + Epoch epoch, epoch_end, diff; + int ns, sps, n; + + n = sscanf (line, "DAS: %*d EV: %*d DS: %*d FST = %04d:%03d:%02d:%02d:%02d:%03d TT = %*[0-9:] NS: %d SPS: %d", + &gmt.year, &gmt.day, &gmt.hour, &gmt.min, &gmt.sec, &gmt.usec, + &ns, &sps); + if (n != 8) { + fprintf (stderr, "Invalid event at line %d, ignored.\n", + line_no); + continue; + } + gmt.usec *= 1000; + gmt2epoch (&epoch, &gmt, leap_sec); + + diff.sec = 0; diff.usec = (int)rint(1e3/sps*ns); + epoch_end = add_epoch(&epoch, &diff); + + if (compare_epoch (&epoch, &last_start->epoch) < 0 && + compare_epoch (&epoch_end, &last_start->epoch) > 0) { + diff.sec = 0; diff.usec = 1000; + last_start->epoch = subtract_epoch(&epoch, &diff); + } + } + } + } return (loglist); *************** *** 512,520 **** } static RESET * ! dsp_reset (list, line) RESET *list; char *line; { RESET *reset; Time gmt; --- 565,574 ---- } static RESET * ! dsp_reset (list, line, locked) RESET *list; char *line; + int locked; { RESET *reset; Time gmt; *************** *** 552,565 **** if (list != NULL) list->next = reset; reset->previous = list; /* added 95.066 */ reset->type = DSP_RESET; ! if (gmt.year == 0 || gmt.year == 1988) { reset->ignore_this_reset = TRUE; return reset; /* don't do any more with this reset */ } else reset->ignore_this_reset = FALSE; ! gmt.year += 1900; year = gmt.year; gmt2epoch (&reset->oldepoch, &gmt, leap_sec); --- 606,621 ---- if (list != NULL) list->next = reset; reset->previous = list; /* added 95.066 */ reset->type = DSP_RESET; + reset->unlocked = !locked; ! if ((gmt.year == 0 && gmt.day == 0) || gmt.year == 1988) { reset->ignore_this_reset = TRUE; return reset; /* don't do any more with this reset */ } else reset->ignore_this_reset = FALSE; + reset->reset_in_sequence = FALSE; ! gmt.year += 1900 + (gmt.year<70 ? 100:0); year = gmt.year; gmt2epoch (&reset->oldepoch, &gmt, leap_sec); *************** *** 575,581 **** gmt.usec *= 1000; } ! gmt.year += 1900; year = gmt.year; gmt2epoch (&reset->newepoch, &gmt, leap_sec); --- 631,637 ---- gmt.usec *= 1000; } ! gmt.year += 1900 + (gmt.year<70 ? 100:0); year = gmt.year; gmt2epoch (&reset->newepoch, &gmt, leap_sec); *************** *** 775,781 **** int *das; { sscanf (&line[17], "%d:", yr); ! *yr += 1900; sscanf (&line[43], "%d:", das); } --- 831,837 ---- int *das; { sscanf (&line[17], "%d:", yr); ! *yr += 1900 + (*yr<70 ? 100:0); sscanf (&line[43], "%d:", das); } *** scan.h.orig Tue Dec 5 18:53:06 2000 --- scan.h Tue Dec 5 18:51:58 2000 *************** *** 136,142 **** static LOCK *unlocked P_((LOCK *list, char *line)); static JERK *time_jerk P_((JERK *list, char *line)); static PULSE *pulse_timeset P_((PULSE *list, char *line)); ! static RESET *dsp_reset P_((RESET *list, char *line)); static void dsp_clock_diff P_((RESET *list, char *line)); static void dsp_reset_num P_((RESET *list, char *line)); static int kludge_4997 P_((char *line)); --- 136,142 ---- static LOCK *unlocked P_((LOCK *list, char *line)); static JERK *time_jerk P_((JERK *list, char *line)); static PULSE *pulse_timeset P_((PULSE *list, char *line)); ! static RESET *dsp_reset P_((RESET *list, char *line, int locked)); static void dsp_clock_diff P_((RESET *list, char *line)); static void dsp_reset_num P_((RESET *list, char *line)); static int kludge_4997 P_((char *line)); *** tokens.h.orig Mon Aug 21 19:07:11 1995 --- tokens.h Sat Dec 9 18:45:52 2000 *************** *** 11,16 **** #define RESET_SEQUENCE5 5 #define RESET_SEQUENCE6 6 #define RESET_SEQUENCE7 7 ! #define IGNORE_ITEM 9 #endif /* TOKENS_H */ --- 11,19 ---- #define RESET_SEQUENCE5 5 #define RESET_SEQUENCE6 6 #define RESET_SEQUENCE7 7 ! #define RESET_SEQUENCE8 8 ! #define RESET_SEQUENCE9 9 ! #define RESET_SEQUENCEB 10 ! #define IGNORE_ITEM 11 #endif /* TOKENS_H */