*** cor_blkt.c.orig Mon May 20 21:42:23 1996 --- cor_blkt.c Thu Nov 30 13:41:17 2000 *************** *** 39,45 **** { extern int blk_sz_exp, blk_sz; extern int Verbose, Start_Epoch, Start_Msecs; ! DATA_HEADER *fxd_hdr, *tmp_fxd; struct CLOCK_RATE *cor_rate; BTIME btime, epoch2btime(); void epoch2fxdhdr(); --- 39,45 ---- { extern int blk_sz_exp, blk_sz; extern int Verbose, Start_Epoch, Start_Msecs; ! DATA_HEADER *fxd_hdr; struct CLOCK_RATE *cor_rate; BTIME btime, epoch2btime(); void epoch2fxdhdr(); *************** *** 55,71 **** double segy_time; /* real epoch of current SEGY file */ char *get_time(); - if(DEBUG == 8) { - while (rate->next != NULL) { - printf("%s\t%f\t%f\n", get_time((int)rate->epoch,(int)(rint(rate->epoch - (int)rate->epoch)*1e2)*1e2), rate->offset, rate->slope); - rate = rate->next; - } - } - - tmp_fxd = (DATA_HEADER *) calloc(1, sizeof(DATA_HEADER)); fxd_hdr = (DATA_HEADER *) calloc(1, sizeof(DATA_HEADER)); if (Verbose) ! fprintf(stdout, "BLKT\tSEGY_time\tOld_mSEED_time\tNew_mSEED_time\tDiff\n"); /* Skip data from first SEGY input file, times already corrected */ jj = 0; cum_Steim_samp = 0; --- 55,63 ---- double segy_time; /* real epoch of current SEGY file */ char *get_time(); fxd_hdr = (DATA_HEADER *) calloc(1, sizeof(DATA_HEADER)); if (Verbose) ! fprintf(stderr, "BLKT\tSEGY_time\tOld_mSEED_time\tNew_mSEED_time\tDiff\n"); /* Skip data from first SEGY input file, times already corrected */ jj = 0; cum_Steim_samp = 0; *************** *** 80,94 **** if ((cor_rate = get_rate_entry(rate, segy_time, files[0]->head->inst_no)) == NULL) { return 0; } set_clock_flags(cor_rate, fxd_hdr); /* copy the corrected fixed header back to the compressed data stream */ memcpy(data + off, (char *) fxd_hdr, sizeof(DATA_HEADER)); - if (Verbose) - fprintf(stdout, "%03d\t%12.4f\t%12.4f\t%12.4f\t%7.3f\t%4d", - jj, segy_time, epoch, - epoch - files[series->s_file]->correction/10000., - files[series->s_file]->correction * 10, cum_Steim_samp); jj++; } --- 72,89 ---- if ((cor_rate = get_rate_entry(rate, segy_time, files[0]->head->inst_no)) == NULL) { return 0; } + if (DEBUG == 5) + fprintf(stderr, "%03d\t%12.4f\t%02d:%02d:%04d\t%02d\t%4d", + jj, segy_time, + fxd_hdr->Record_start_time.minutes, + fxd_hdr->Record_start_time.seconds, + fxd_hdr->Record_start_time.frac_secs, + fxd_hdr->Time_correction, cum_Steim_samp); + set_clock_flags(cor_rate, fxd_hdr); /* copy the corrected fixed header back to the compressed data stream */ memcpy(data + off, (char *) fxd_hdr, sizeof(DATA_HEADER)); jj++; } *************** *** 108,118 **** /* segy_time = (double) (files[ii]->epoch + files[series->s_file]->msecs */ segy_time = (double) (files[ii]->epoch + Start_Msecs + files[ii]->correction)/1000. + Start_Epoch; ! /* Caused GCC under Linux to cough ! if(Verbose) fprintf("segy_time[%d] (%s) = %f = %s\n", ii, files[ii]->filename,segy_time, (char *) get_time((int)segy_time, (int)(rint((segy_time - (int)segy_time)*1e2)*1e2))); - */ /* grab the clock rate entry for this file to set the clock flags */ if ((cor_rate = get_rate_entry(rate, segy_time, files[0]->head->inst_no)) == NULL) { --- 103,111 ---- /* segy_time = (double) (files[ii]->epoch + files[series->s_file]->msecs */ segy_time = (double) (files[ii]->epoch + Start_Msecs + files[ii]->correction)/1000. + Start_Epoch; ! if(Verbose) fprintf(stderr,"\nsegy_time[%d] (%s) = %f = %s\n", ii, files[ii]->filename,segy_time, (char *) get_time((int)segy_time, (int)(rint((segy_time - (int)segy_time)*1e2)*1e2))); /* grab the clock rate entry for this file to set the clock flags */ if ((cor_rate = get_rate_entry(rate, segy_time, files[0]->head->inst_no)) == NULL) { *************** *** 136,154 **** /* copy the value for the Steim block Time Correction in 1/10000 of a second*/ fxd_hdr->Time_correction = files[ii]->correction * 10; /* update clock status flag, I/O bit 5 based on event type */ ! set_clock_flags(cor_rate, fxd_hdr); /* copy the corrected fixed header back to the compressed data stream */ memcpy((char *) data + off, (char *) fxd_hdr, sizeof(DATA_HEADER)); ! if (DEBUG == 5) ! fprintf(stdout, "%03d\t%12.4f\t%02d:%02d:%04d\t%02d:%02d:%04d\t%02d\t%4d\n", ! jj, segy_time, fxd_hdr->Record_start_time.minutes, fxd_hdr->Record_start_time.seconds, ! fxd_hdr->Record_start_time.frac_secs, tmp_fxd->Record_start_time.minutes, ! tmp_fxd->Record_start_time.seconds, tmp_fxd->Record_start_time.frac_secs, ! files[ii]->correction * 10, cum_Steim_samp); ! jj++; cum_Steim_samp += fxd_hdr->Number_of_samples; } remainder = cum_Steim_samp - files[ii]->sample_length; --- 129,149 ---- /* copy the value for the Steim block Time Correction in 1/10000 of a second*/ fxd_hdr->Time_correction = files[ii]->correction * 10; + + if (DEBUG == 5) + fprintf(stderr, "%03d\t%12.4f\t%02d:%02d:%04d\t%02d\t%4d", + jj, segy_time, + fxd_hdr->Record_start_time.minutes, + fxd_hdr->Record_start_time.seconds, + fxd_hdr->Record_start_time.frac_secs, + fxd_hdr->Time_correction, cum_Steim_samp); /* update clock status flag, I/O bit 5 based on event type */ ! set_clock_flags(cor_rate, fxd_hdr); /* copy the corrected fixed header back to the compressed data stream */ memcpy((char *) data + off, (char *) fxd_hdr, sizeof(DATA_HEADER)); ! jj++; cum_Steim_samp += fxd_hdr->Number_of_samples; } remainder = cum_Steim_samp - files[ii]->sample_length; *************** *** 179,185 **** fxd_hdr = (DATA_HEADER *) calloc(1, sizeof(DATA_HEADER)); if (Verbose) ! fprintf(stdout, "BLKT\tSEGY_time\tOld_mSEED_time\tNew_mSEED_time\tDiff\n"); /* First Blockette, indicate this in I/O flag [data+37] */ flag = 0x08; /* 0x08 indicates Start of time series */ --- 174,180 ---- fxd_hdr = (DATA_HEADER *) calloc(1, sizeof(DATA_HEADER)); if (Verbose) ! fprintf(stderr, "BLKT\tSEGY_time\tOld_mSEED_time\tNew_mSEED_time\tDiff\n"); /* First Blockette, indicate this in I/O flag [data+37] */ flag = 0x08; /* 0x08 indicates Start of time series */ *************** *** 202,208 **** btime = epoch2btime(true_time); diff = (true_time - mseed_time) * 1e4; if (Verbose) ! fprintf(stdout, "%03d\t%12.4f\t%12.4f\t%12.4f\t%7.3f\t%4d", i, segy_time, mseed_time, true_time, diff / 10, num_samp); fxd_hdr->Record_start_time.year = btime.year; --- 197,203 ---- btime = epoch2btime(true_time); diff = (true_time - mseed_time) * 1e4; if (Verbose) ! fprintf(stderr, "%03d\t%12.4f\t%12.4f\t%12.4f\t%7.3f\t%4d", i, segy_time, mseed_time, true_time, diff / 10, num_samp); fxd_hdr->Record_start_time.year = btime.year; *************** *** 289,295 **** time_2 = time_2 == 0 ? INT_MAX : time_2; if (time_1 > seed_time) { /* THIS SHOULD NEVER HAPPEN */ ! printf("%s(%s): Error, SEGY time !< mseed time (%g !< %12.3f)", progname, time_1, seed_time); return (-1); } else if (time_1 <= seed_time && time_2 >= seed_time) --- 284,290 ---- time_2 = time_2 == 0 ? INT_MAX : time_2; if (time_1 > seed_time) { /* THIS SHOULD NEVER HAPPEN */ ! fprintf(stderr,"%s(%s): Error, SEGY time !< mseed time (%g !< %12.3f)", progname, time_1, seed_time); return (-1); } else if (time_1 <= seed_time && time_2 >= seed_time) *************** *** 353,367 **** if(Verbose) { epoch = mtime2epoch(fxd_hdr); time_str = get_time((int)epoch,(int) rint((float) fxd_hdr->Record_start_time.frac_secs/10.)); ! fprintf(stdout, " Locked at %s\n", time_str); } return (1); } else { /* Set bit 7 of Data_quality_flags, time tag is questionable */ if(Verbose) { epoch = mtime2epoch(fxd_hdr); ! time_str = get_time((int)epoch,(int) rint((float) fxd_hdr->Record_start_time.frac_secs/10.)); ! fprintf(stdout, " Unlocked at %s\n", time_str); } fxd_hdr->Data_quality_flags |= 0x80; return (0); --- 348,362 ---- if(Verbose) { epoch = mtime2epoch(fxd_hdr); time_str = get_time((int)epoch,(int) rint((float) fxd_hdr->Record_start_time.frac_secs/10.)); ! fprintf(stderr, " Locked at %s\n", time_str); } return (1); } else { /* Set bit 7 of Data_quality_flags, time tag is questionable */ if(Verbose) { epoch = mtime2epoch(fxd_hdr); ! time_str = get_time((int)epoch,fxd_hdr->Record_start_time.frac_secs); ! fprintf(stderr, " Unlocked at %s\n", time_str); } fxd_hdr->Data_quality_flags |= 0x80; return (0); *************** *** 371,377 **** /************************* pr_start_stop_times() *******************************/ /*******************************************************************************/ ! pr_start_stop_times(data_ptr, num_blks) char *data_ptr; int num_blks; { --- 366,373 ---- /************************* pr_start_stop_times() *******************************/ /*******************************************************************************/ ! pr_start_stop_times(str, data_ptr, num_blks) ! FILE *str; char *data_ptr; int num_blks; { *************** *** 396,402 **** fxd->Record_start_time.hours, fxd->Record_start_time.minutes, fxd->Record_start_time.seconds, fxd->Record_start_time.frac_secs); ! printf("%s ", start_time); /* write POD comment blockettes describing Data Outage if appending */ if (p_directory && PREVIOUS_TIME && start_time && !AppendWritten) { --- 392,398 ---- fxd->Record_start_time.hours, fxd->Record_start_time.minutes, fxd->Record_start_time.seconds, fxd->Record_start_time.frac_secs); ! fprintf(str,"%s ", start_time); /* write POD comment blockettes describing Data Outage if appending */ if (p_directory && PREVIOUS_TIME && start_time && !AppendWritten) { *************** *** 421,433 **** SS = (((fxd->Number_of_samples - 1) / rate)); /* update date structure with end point time */ ! epoch = passcal_htoe(date) + fxd->Record_start_time.frac_secs / 10000.; passcal_etoh(&date, epoch + SS); ! day = julian(date); sec = (int) (date.sec); frac = (int) (rint((date.sec - sec)*1e3)) * 10; ! printf("%04d,%03d,%02d:%02d:%02d.%04d\n", date.yr, day, date.hr,date.mn,sec, frac); cfree(fxd); } --- 417,429 ---- SS = (((fxd->Number_of_samples - 1) / rate)); /* update date structure with end point time */ ! epoch = passcal_htoe(&date) + fxd->Record_start_time.frac_secs / 10000.; passcal_etoh(&date, epoch + SS); ! day = julian(&date); sec = (int) (date.sec); frac = (int) (rint((date.sec - sec)*1e3)) * 10; ! fprintf(str,"%04d,%03d,%02d:%02d:%02d.%04d\n", date.yr, day, date.hr,date.mn,sec, frac); cfree(fxd); } *** merge_files.c.orig Mon Jun 5 18:37:48 1995 --- merge_files.c Wed Dec 13 10:30:32 2000 *************** *** 159,164 **** --- 159,165 ---- { double epoch, correction; struct CLOCK_RATE *rate_entry; + int thistype; if (rate == NULL) { return (0); *************** *** 166,175 **** epoch = s_passcal_htoe(file->head) + file->head->m_secs / 1000.; /* rate_entry = get_rate_entry(rate, epoch, file->head->inst_no); */ if ((rate_entry = get_rate_entry(rate, epoch, file->head->inst_no)) == NULL) { ! fprintf (stderr, "get_correction: Couldn't find rate entry for instrument %d at epoch %f,\n", file->head->inst_no, epoch); fprintf (stderr, "\t%s continuing, but file may contain timing error!\n", progname); return 0; } if (rate_entry->slope != 0.0) { correction = (epoch - rate_entry->epoch) * rate_entry->slope + rate_entry->offset; --- 167,221 ---- epoch = s_passcal_htoe(file->head) + file->head->m_secs / 1000.; /* rate_entry = get_rate_entry(rate, epoch, file->head->inst_no); */ if ((rate_entry = get_rate_entry(rate, epoch, file->head->inst_no)) == NULL) { ! struct ptime date; ! passcal_etoh(&date, epoch); ! ! fprintf (stderr, "get_correction: Couldn't find rate entry for instrument %d at %04d:%03d:%02d:%02d:%07.4f,\n", file->head->inst_no, ! date.yr,julian(&date),date.hr,date.mn,date.sec); fprintf (stderr, "\t%s continuing, but file may contain timing error!\n", progname); return 0; } + /* Check if entry is first after a stop, and if next entry is a start. + If so, assume that the clock was unlocked at start of acquisition, + and that the correction to be used is the one at the first lock. + May arise if DAS crashes and automatically restarts acquisition, or + if anxious operator starts acquisition before clock lock. */ + + thistype = rate_entry->type; + if (thistype==RESET_RESET) { + struct CLOCK_RATE *prev_entry; + prev_entry = get_rate_entry(rate, rate_entry->epoch-0.001, + file->head->inst_no); + if (prev_entry != NULL) { + struct ptime date; + passcal_etoh(&date, epoch); + fprintf (stderr, "get_correction: Rate entry for instrument %d at %04d:%03d:%02d:%02d:%07.4f,\n", file->head->inst_no, + date.yr,julian(&date),date.hr,date.mn,date.sec); + fprintf (stderr, "\tfalls between successive DSP resets - using prior time correction\n"); + rate_entry = prev_entry; + } + } + + #if 0 + /* No longer necessary following change to refrate to move back start acq + time to 1 msec before first sample following restart */ + if (thistype==STOP_START||thistype==PHASE_START||thistype==UNLOCK_START|| + thistype==RESET_START) { + struct CLOCK_RATE *phase; + double next_epoch = rate_entry->next==NULL?0:rate_entry->next->epoch; + + for(phase=rate_entry->next; phase!=NULL; phase=phase->next) + if (next_epoch == phase->epoch && + (phase->type == START_PHASE || + phase->type == PHASE_PHASE || + phase->type == RESET_PHASE || + phase->type == UNLOCK_PHASE)) { + rate_entry=phase; + break; + } + } + #endif + if (rate_entry->slope != 0.0) { correction = (epoch - rate_entry->epoch) * rate_entry->slope + rate_entry->offset; *************** *** 384,390 **** fs_ptr->offset = 0; if (fs_ptr->sample_length > fs_ptr->nsamples) sample_offset = fs_ptr->sample_length = fs_ptr->nsamples; ! fs_ptr->sample_length = sample_offset; break; } if (DEBUG == 3) { --- 430,437 ---- fs_ptr->offset = 0; if (fs_ptr->sample_length > fs_ptr->nsamples) sample_offset = fs_ptr->sample_length = fs_ptr->nsamples; ! if (sample_offset > 0 && sample_offset < fs_ptr->nsamples) ! fs_ptr->sample_length = sample_offset; break; } if (DEBUG == 3) { *************** *** 416,422 **** struct time_series *series; { ! long i, num_of_samps; char First_Time[17]; /* --- 463,469 ---- struct time_series *series; { ! long i, num_of_samps = 0; char First_Time[17]; /* *************** *** 529,537 **** struct time_series *entry; float tolerance, get_tolerance(); void format_drop(); ! int i, chan_chk, msecs_per_samp, tol_time, num_of_samps, cum_num_samps, drop_time, num_samps_desired, prev_num_samps, offset, drop_samps, tmp_num_samps, num_remaining, cur_num_samps; int tmp; long delta_chk; int series_cnt = 0; --- 576,585 ---- struct time_series *entry; float tolerance, get_tolerance(); void format_drop(); ! int i, chan_chk, msecs_per_samp, num_of_samps, cum_num_samps, drop_time, num_samps_desired, prev_num_samps, offset, drop_samps, tmp_num_samps, num_remaining, cur_num_samps; + double tol_time; int tmp; long delta_chk; int series_cnt = 0; *************** *** 626,632 **** } } /* END of Equality Check Loop */ ! /* set first file epoch to relative epoch */ files[series[num_series]->s_file]->epoch = 0; if (DEBUG == 2) { --- 674,680 ---- } } /* END of Equality Check Loop */ ! /* set first file epoch to relative epoch. */ files[series[num_series]->s_file]->epoch = 0; if (DEBUG == 2) { *************** *** 654,673 **** fprintf(stderr, "files[%d]->sample_length = %d\n", i, files[i]->sample_length); } else cum_num_samps += files[i]->sample_length; ! tol_time = (files[i - 1]->epoch + (msecs_per_samp * num_of_samps)); if (DEBUG == 2) { fprintf(stderr, "files[%d]->sample_length = %d\n", i, files[i]->sample_length); fprintf(stderr, "\tcum_num_samps = %d,\tnum_remaining = %d\t", cum_num_samps, num_remaining); fprintf(stderr, "tmp_num_samps = %d\n", tmp_num_samps); } ! drop_time = abs((files[i]->epoch - tol_time)); if (drop_time) { ! if (Verbose || drop_time > tolerance) { ! if (DEBUG != 10) ! format_drop(drop_time, files, i); ! ! tmp = num_series + 1; series[tmp] = AllocMember(); series[tmp]->e_file = series[num_series]->e_file; series[tmp]->e_time = series[num_series]->e_time; --- 702,723 ---- fprintf(stderr, "files[%d]->sample_length = %d\n", i, files[i]->sample_length); } else cum_num_samps += files[i]->sample_length; ! tol_time = s_passcal_htoe(files[i-1]->head) + 1e-3*( ! files[i-1]->msecs+files[i-1]->correction + ! (msecs_per_samp * num_of_samps) ! ); if (DEBUG == 2) { fprintf(stderr, "files[%d]->sample_length = %d\n", i, files[i]->sample_length); fprintf(stderr, "\tcum_num_samps = %d,\tnum_remaining = %d\t", cum_num_samps, num_remaining); fprintf(stderr, "tmp_num_samps = %d\n", tmp_num_samps); } ! drop_time = (int)(rint(fabs(1e3*(s_passcal_htoe(files[i]->head)+(files[i]->msecs+files[i]->correction)*1e-3 - tol_time)))); if (drop_time) { ! if (Verbose || drop_time > tolerance) ! format_drop(drop_time, files, i); ! if (drop_time > tolerance) { ! tmp = num_series + 1; series[tmp] = AllocMember(); series[tmp]->e_file = series[num_series]->e_file; series[tmp]->e_time = series[num_series]->e_time; *** mseed.c.orig Mon May 20 21:42:24 1996 --- mseed.c Tue Nov 16 17:07:37 1999 *************** *** 10,16 **** void write_fxd(fxd_hdr, segy_hdr) DATA_HEADER *fxd_hdr; ! struct SegyHead segy_hdr; { extern long num_cont_blk; --- 10,16 ---- void write_fxd(fxd_hdr, segy_hdr) DATA_HEADER *fxd_hdr; ! struct SegyHead *segy_hdr; { extern long num_cont_blk; *************** *** 35,43 **** blk_1000->blockette_type = 1000; /* Data Only Type */ blk_1000->next_blockette_byte = 0; /* Byte offset from logical * rec beginning */ ! blk_1000->encoding_format = 10; /* Ecnoding Fromat, 10 = Steim 1 */ ! blk_1000->word_order = 1; /* Byte swapping order; 0 - VAX, 1 - ! * SPARC */ blk_1000->data_rec_length = blk_sz_exp; /* Exponent (as a pow of 2) of * logical rec len */ blk_1000->reserved = 0; --- 35,43 ---- blk_1000->blockette_type = 1000; /* Data Only Type */ blk_1000->next_blockette_byte = 0; /* Byte offset from logical * rec beginning */ ! blk_1000->encoding_format = 10; /* Encoding Fromat, 10 = Steim 1 */ ! /* Byte swapping order; 0 - VAX, 1 - * SPARC */ ! blk_1000->word_order = get_my_wordorder(); blk_1000->data_rec_length = blk_sz_exp; /* Exponent (as a pow of 2) of * logical rec len */ blk_1000->reserved = 0; *************** *** 57,63 **** /* Set up FXD_HDR station, location, station and network ID strings */ if (!station_id) /* char Station_identifier_code[5] */ ! sprintf(fxd_hdr->Station_identifier_code, "%05d", segy_hdr.inst_no); else /* memcpy(fxd_hdr->Station_identifier_code, tmp, 5); */ /* left justified blank padded strings for these next *_id's */ --- 57,63 ---- /* Set up FXD_HDR station, location, station and network ID strings */ if (!station_id) /* char Station_identifier_code[5] */ ! sprintf(fxd_hdr->Station_identifier_code, "%05d", segy_hdr->inst_no); else /* memcpy(fxd_hdr->Station_identifier_code, tmp, 5); */ /* left justified blank padded strings for these next *_id's */ *************** *** 69,75 **** sprintf(fxd_hdr->Location_identifier, "%-2s", location_id); if (!channel_id) /* char Channel_identifier[3] */ ! sprintf(fxd_hdr->Channel_identifier, "%03d", segy_hdr.channel_number); else sprintf(fxd_hdr->Channel_identifier, "%-3s", channel_id); --- 69,75 ---- sprintf(fxd_hdr->Location_identifier, "%-2s", location_id); if (!channel_id) /* char Channel_identifier[3] */ ! sprintf(fxd_hdr->Channel_identifier, "%03d", segy_hdr->channel_number); else sprintf(fxd_hdr->Channel_identifier, "%-3s", channel_id); *************** *** 78,95 **** else memcpy(fxd_hdr->Network_Code, network_id, 2); ! fxd_hdr->Record_start_time.year = (unsigned short) segy_hdr.year; ! fxd_hdr->Record_start_time.day = (unsigned short) segy_hdr.day; ! fxd_hdr->Record_start_time.hours = (unsigned char) segy_hdr.hour; ! fxd_hdr->Record_start_time.minutes = (unsigned char) segy_hdr.minute; ! fxd_hdr->Record_start_time.seconds = (unsigned char) segy_hdr.second; /* BTIME.frac_secs field in the steim header is in 1/10,000 seconds */ ! fxd_hdr->Record_start_time.frac_secs = (unsigned short) segy_hdr.m_secs * 10; fxd_hdr->Number_of_samples = (unsigned short) 0; fxd_hdr->Number_of_blockettes_follow = 1; ! fxd_hdr->Time_correction = (long) segy_hdr.totalStatic; } void --- 78,95 ---- else memcpy(fxd_hdr->Network_Code, network_id, 2); ! fxd_hdr->Record_start_time.year = (unsigned short) segy_hdr->year; ! fxd_hdr->Record_start_time.day = (unsigned short) segy_hdr->day; ! fxd_hdr->Record_start_time.hours = (unsigned char) segy_hdr->hour; ! fxd_hdr->Record_start_time.minutes = (unsigned char) segy_hdr->minute; ! fxd_hdr->Record_start_time.seconds = (unsigned char) segy_hdr->second; /* BTIME.frac_secs field in the steim header is in 1/10,000 seconds */ ! fxd_hdr->Record_start_time.frac_secs = (unsigned short) segy_hdr->m_secs * 10; fxd_hdr->Number_of_samples = (unsigned short) 0; fxd_hdr->Number_of_blockettes_follow = 1; ! fxd_hdr->Time_correction = (long) segy_hdr->totalStatic; } void *************** *** 118,154 **** void ! print_fxd(i, hdr) int i; DATA_HEADER *hdr; { ! printf("%6d ", i); ! printf("%6.6s ", hdr->SequenceNumber); ! printf("%1.1c ", hdr->Data_header_indicator); ! printf("%5.5s ", hdr->Station_identifier_code); ! printf("%2.2s ", hdr->Location_identifier); ! printf("%3.3s ", hdr->Channel_identifier); ! printf("%2.2s ", hdr->Network_Code); ! printf("%04d:", hdr->Record_start_time.year); ! printf("%03d:", hdr->Record_start_time.day); ! printf("%02d:", hdr->Record_start_time.hours); ! printf("%02d:", hdr->Record_start_time.minutes); ! printf("%02d:", hdr->Record_start_time.seconds); ! printf("%04d ", hdr->Record_start_time.frac_secs); ! printf("%4d ", hdr->Number_of_samples); ! printf("%2d ", hdr->Sample_rate_factor); ! printf("%2d ", hdr->Sample_rate_multiplier); ! printf("%3d ", hdr->Activity_flags); ! printf("%3d ", hdr->IO_flags); ! printf("%3d ", hdr->Data_quality_flags); ! printf("%d ", hdr->Number_of_blockettes_follow); ! printf("%3d ", hdr->Time_correction); ! printf("%3d ", hdr->Beginning_of_data); ! printf("%d \n", hdr->First_blockette); } void ! do_all_hdrs(data, num) char *data; long num; { --- 118,156 ---- void ! print_fxd(str, i, hdr) ! FILE *str; int i; DATA_HEADER *hdr; { ! fprintf(str,"%6d ", i); ! fprintf(str,"%6.6s ", hdr->SequenceNumber); ! fprintf(str,"%1.1c ", hdr->Data_header_indicator); ! fprintf(str,"%5.5s ", hdr->Station_identifier_code); ! fprintf(str,"%2.2s ", hdr->Location_identifier); ! fprintf(str,"%3.3s ", hdr->Channel_identifier); ! fprintf(str,"%2.2s ", hdr->Network_Code); ! fprintf(str,"%04d:", hdr->Record_start_time.year); ! fprintf(str,"%03d:", hdr->Record_start_time.day); ! fprintf(str,"%02d:", hdr->Record_start_time.hours); ! fprintf(str,"%02d:", hdr->Record_start_time.minutes); ! fprintf(str,"%02d.", hdr->Record_start_time.seconds); ! fprintf(str,"%04d ", hdr->Record_start_time.frac_secs); ! fprintf(str,"%4d ", hdr->Number_of_samples); ! fprintf(str,"%2d ", hdr->Sample_rate_factor); ! fprintf(str,"%2d ", hdr->Sample_rate_multiplier); ! fprintf(str,"%3d ", hdr->Activity_flags); ! fprintf(str,"%3d ", hdr->IO_flags); ! fprintf(str,"%3d ", hdr->Data_quality_flags); ! fprintf(str,"%d ", hdr->Number_of_blockettes_follow); ! fprintf(str,"%3d ", hdr->Time_correction); ! fprintf(str,"%3d ", hdr->Beginning_of_data); ! fprintf(str,"%d \n", hdr->First_blockette); } void ! do_all_hdrs(str, data, num) ! FILE *str; char *data; long num; { *************** *** 160,166 **** for (i = 0; i < num; i++) { off = i * blk_sz; memcpy(fxd, data + off, sizeof(DATA_HEADER)); ! print_fxd(i, fxd); } cfree(fxd); } --- 162,168 ---- for (i = 0; i < num; i++) { off = i * blk_sz; memcpy(fxd, data + off, sizeof(DATA_HEADER)); ! print_fxd(str, i, fxd); } cfree(fxd); } *************** *** 189,192 **** --- 191,220 ---- memcpy(data + off, fxd, sizeof(DATA_HEADER)); cfree(fxd); + } + + /************************************************************************/ + /* get_my_wordorder */ + /* Determine which endian (byte order) this machine is. */ + /* Set default hdr and data wordorder if not previously set. */ + /* Stolen from Doug Neuhauser's qlib routines */ + /* by G. Helffrich/U Bristol */ + /************************************************************************/ + + /* Definitions for blockette 1000 */ + #define SEED_LITTLE_ENDIAN 0 + #define SEED_BIG_ENDIAN 1 + + int get_my_wordorder() + { + int ival = 0x01234567; /* hex 01234567 */ + unsigned char *pc = (unsigned char *)&ival; + int my_wordorder = + (*pc == 0x01) ? SEED_BIG_ENDIAN : + (*pc == 0x67) ? SEED_LITTLE_ENDIAN : -1; + if (my_wordorder < 0) { + fprintf (stderr, "Error: Unable to determine computer wordorder.\n"); + exit (1); + } + return (my_wordorder); } *** segy2mseed.c.orig Mon May 20 21:42:24 1996 --- segy2mseed.c Wed Dec 6 10:43:10 2000 *************** *** 93,98 **** --- 93,121 ---- * record length from the default 4096 to any power of * two permissible by the SEED conventions, range of 256 * to 2^256. + * + * VER 99.xxx -- Bug fixes for Linux version by + * G. Helffrich/U. Bristol, 13 Nov. 1999. Calling problems to cfree + * in main(), calling problems to julian() and pascal_htoe() in + * print_start_end. + * Also fixed bug in steim.c that didn't write proper byte order + * on VAX/Intel machines (linux). + * + * VER 00.334 -- Improve error reporting of time corrections outside span of + * log file. Also add heuristic to time corrections that if correction + * needed during time DAS is "stopped", then it will use correction + * for following start (which fixes problems with DAS crashes and + * automatic acquisition starts). + * G. Helffrich/U. Bristol, 30 Nov. 2000. + * + * VER 00.335 -- Handle unusual case where time correction for file start + * falls between successive DSP resets. In this case, use the + * immediately prior to DSP reset because this has been set to the + * cumulative phase error by refrate already. + * G. Helffrich/U. Bristol, 1 Dec. 2000. + * + * VER 00.340 -- Fix another bug in checking for data gaps between segy files. + * G. Helffrich/U. Bristol, 6 Dec. 2000. */ #define MAIN *************** *** 103,109 **** #include "mk_pod_blocks.h" #include "errors.h" ! #define VER_NO "96.138" /* #define STEIM_REC_LEN 4096 */ /* STEIM_REC_LEN has been replaced by blk_sz, a global set from * blk_sz_exp, a command line argument, default blk_sz = 4096, 2^12 */ --- 126,132 ---- #include "mk_pod_blocks.h" #include "errors.h" ! #define VER_NO "00.340" /* #define STEIM_REC_LEN 4096 */ /* STEIM_REC_LEN has been replaced by blk_sz, a global set from * blk_sz_exp, a command line argument, default blk_sz = 4096, 2^12 */ *************** *** 137,143 **** char *argv[]; { /* char *calloc(), get_time_str(); */ ! char get_time_str(); int sam_rate; long num_steim_rec; --- 160,166 ---- char *argv[]; { /* char *calloc(), get_time_str(); */ ! char *get_time_str(); int sam_rate; long num_steim_rec; *************** *** 167,172 **** --- 190,196 ---- long num_of_samps; double epoch; + extern int verbose; /* for steim.c debugging */ if ((progname = (char *) strrchr(argv[0], '/')) == NULL) *************** *** 221,229 **** /* 94.112, quick stripping out to function, NEEDS WORK */ tot_num_samps = merge_files(Series[num_series]); if (tot_num_samps < 0) { ! printf ("tot_num_samps = %d ", tot_num_samps); tot_num_samps = samp_rd(files[Series[num_series]->s_file]->head); ! printf ("%s: Resetting nsam to %d, file %d\n", progname, tot_num_samps, num_series); } s_file = Series[num_series]->s_file; --- 245,253 ---- /* 94.112, quick stripping out to function, NEEDS WORK */ tot_num_samps = merge_files(Series[num_series]); if (tot_num_samps < 0) { ! fprintf (stderr,"tot_num_samps = %d ", tot_num_samps); tot_num_samps = samp_rd(files[Series[num_series]->s_file]->head); ! fprintf (stderr,"%s: Resetting nsam to %d, file %d\n", progname, tot_num_samps, num_series); } s_file = Series[num_series]->s_file; *************** *** 234,240 **** * Now that all the data buffers are copied and freed, * allocate steim_data */ ! steim_data = (char *) calloc(tot_num_samps, sizeof(long)); if (steim_data == NULL) { fprintf(stderr, "Unable to allocate %d bytes for steim_data in %s\n", --- 258,264 ---- * Now that all the data buffers are copied and freed, * allocate steim_data */ ! steim_data = (char *) calloc(tot_num_samps*4+1024, sizeof(long)); if (steim_data == NULL) { fprintf(stderr, "Unable to allocate %d bytes for steim_data in %s\n", *************** *** 255,261 **** /* DEBUG */ if (DEBUG) { ! printf("after update_hdr: start time of seed volume = %s\n", get_time_str(segy_hdr, 0)); } --- 279,285 ---- /* DEBUG */ if (DEBUG) { ! fprintf(stderr,"after update_hdr: start time of seed volume = %s\n", get_time_str(segy_hdr, 0)); } *************** *** 269,277 **** /* Compose SEED Fixed Data Header */ write_fxd(fxd_hdr, segy_hdr); if (DEBUG > 9) ! print_fxd(-1, fxd_hdr); /* Pass current time series to Steim1 compressor */ num_steim_rec = Steim_comp((long *) data_buf, fxd_hdr, tot_num_samps, blk_sz, steim_data, num_cont_blk, num_cont_blk_bytes, cont_blk, num_once_blk, num_once_blk_bytes, once_blk); --- 293,302 ---- /* Compose SEED Fixed Data Header */ write_fxd(fxd_hdr, segy_hdr); if (DEBUG > 9) ! print_fxd(stderr, -1, fxd_hdr); /* Pass current time series to Steim1 compressor */ + if (DEBUG > 19) verbose = 1; num_steim_rec = Steim_comp((long *) data_buf, fxd_hdr, tot_num_samps, blk_sz, steim_data, num_cont_blk, num_cont_blk_bytes, cont_blk, num_once_blk, num_once_blk_bytes, once_blk); *************** *** 280,301 **** update_fxd(steim_data, num_steim_rec); if (DEBUG > 9) ! do_all_hdrs(steim_data, num_steim_rec); /* If rating file, time correct Steim Blockettes */ ! if (rate_file) if(!cor_blkt2(steim_data, ratings, num_steim_rec, Series[num_series])) ! printf("Error: no timing corrections found\n"); ! if (DEBUG > 9) ! do_all_hdrs(steim_data, num_steim_rec); /* Write current time series to Output File */ if((j = fwrite(steim_data, (size_t) blk_sz, (size_t) num_steim_rec, ofp)) != num_steim_rec) ! printf("Error writing %d blocks of steim data, wrote %d\n", num_steim_rec, j); /* if(p_directory) */ /* print start and stop times of this series*/ ! pr_start_stop_times(steim_data, num_steim_rec); if(steim_data != NULL) if (DEBUG) --- 305,327 ---- update_fxd(steim_data, num_steim_rec); if (DEBUG > 9) ! do_all_hdrs(stderr, steim_data, num_steim_rec); /* If rating file, time correct Steim Blockettes */ ! if (rate_file) { if(!cor_blkt2(steim_data, ratings, num_steim_rec, Series[num_series])) ! fprintf(stderr,"Error: no timing corrections found\n"); ! if (DEBUG > 9) ! do_all_hdrs(stderr, steim_data, num_steim_rec); ! } /* Write current time series to Output File */ if((j = fwrite(steim_data, (size_t) blk_sz, (size_t) num_steim_rec, ofp)) != num_steim_rec) ! fprintf(stderr,"Error writing %d blocks of steim data, wrote %d\n", num_steim_rec, j); /* if(p_directory) */ /* print start and stop times of this series*/ ! pr_start_stop_times(stderr,steim_data, num_steim_rec); if(steim_data != NULL) if (DEBUG) *************** *** 307,313 **** for (i = 0; i < no_files; ++i) { /* 95.229 already freed in merge_files.c line 768 - thanks to TestCenter */ /* cfree(files[i]->data); */ ! cfree(&files[i]); } free(fxd_hdr); exit(0); --- 333,339 ---- for (i = 0; i < no_files; ++i) { /* 95.229 already freed in merge_files.c line 768 - thanks to TestCenter */ /* cfree(files[i]->data); */ ! cfree(files[i]); } free(fxd_hdr); exit(0); *** steim.c.orig Sun Nov 14 21:55:28 1999 --- steim.c Wed Nov 22 20:29:39 2000 *************** *** 409,415 **** ULONG tossed = 0 ; ULONG stat[4]; LONG ck ; ! LONG wk ; int token, i ; DATA_HEADER new_fsdh ; /* buffer for new fixed section data headers */ DATA_STATE ds ; --- 409,419 ---- ULONG tossed = 0 ; ULONG stat[4]; LONG ck ; ! union { ! LONG wkl ; ! WORD w[2]; ! char c[4]; ! } wk ; int token, i ; DATA_HEADER new_fsdh ; /* buffer for new fixed section data headers */ DATA_STATE ds ; *************** *** 554,567 **** new_fsdh.Number_of_samples += 1 ; break; case _D2_D2_f: ! /* two 2-byte differences (two 16 bit samples) */ ! wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; ck = 2 ; new_fsdh.Number_of_samples += 2 ; break; case _D1_D1_D1_D1_f: ! /* four 1-byte differences (four 8 bit samples) */ ! wk = ((d[0]&0xFFL) << 24) | ((d[1]&0xFFL) << 16) | ((d[2]&0xFFL) << 8) | (d[3]&0xFFL) ; ck = 1 ; new_fsdh.Number_of_samples += 4 ; break; --- 558,574 ---- new_fsdh.Number_of_samples += 1 ; break; case _D2_D2_f: ! /* two 2-byte differences (two 16 bit samples) *//* ! wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; */ ! wk.w[0] = d[0] ; wk.w[1] = d[1]; ck = 2 ; new_fsdh.Number_of_samples += 2 ; break; case _D1_D1_D1_D1_f: ! /* four 1-byte differences (four 8 bit samples) *//* ! wk = ((d[0]&0xFFL) << 24) | ((d[1]&0xFFL) << 16) | ((d[2]&0xFFL) << 8) | (d[3]&0xFFL) ; */ ! wk.c[0] = d[0]; wk.c[1] = d[1]; ! wk.c[2] = d[2]; wk.c[3] = d[3]; ck = 1 ; new_fsdh.Number_of_samples += 4 ; break; *************** *** 569,575 **** stat[ck]++; state = _START_STATE ; ! Add_word( p_seed_data_records, &new_fsdh, wk, ck, &ds ) ; } --- 576,582 ---- stat[ck]++; state = _START_STATE ; ! Add_word( p_seed_data_records, &new_fsdh, wk.wkl, ck, &ds ) ; } *************** *** 599,620 **** case _D1_D1: ck = 2; stat[ck]++; ! wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; new_fsdh.Number_of_samples += 2 ; break; case _D1_D1_D1: ck = 2; stat[ck]++; ! wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; new_fsdh.Number_of_samples += 2 ; ! Add_word( p_seed_data_records, &new_fsdh, wk, ck, &ds ) ; ck = 3; stat[ck]++; wk = d[2]; new_fsdh.Number_of_samples += 1 ; break; } ! Add_word( p_seed_data_records, &new_fsdh, wk, ck, &ds ) ; } } --- 606,629 ---- case _D1_D1: ck = 2; stat[ck]++; ! /* wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; */ ! wk.w[0] = d[0] ; wk.w[1] = d[1]; new_fsdh.Number_of_samples += 2 ; break; case _D1_D1_D1: ck = 2; stat[ck]++; ! /* wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; */ ! wk.w[0] = d[0] ; wk.w[1] = d[1]; new_fsdh.Number_of_samples += 2 ; ! Add_word( p_seed_data_records, &new_fsdh, wk.wkl, ck, &ds ) ; ck = 3; stat[ck]++; wk = d[2]; new_fsdh.Number_of_samples += 1 ; break; } ! Add_word( p_seed_data_records, &new_fsdh, wk.wkl, ck, &ds ) ; } }