📄 output_seed.c
字号:
perror("patch_70"); return 0; } break; } /* switch blockette type */ } /* while fread block 70 file */ /* ----------- */ if (!fill_to_LRECL(fptr_tmp)) { fprintf(stderr, "Error! output_seed_volume: unable to process timespan output file: %s\n", FILE_70_NAME); perror("output_seed_volume"); fclose(fptr); fclose(fptr_tmp); return 0; } fclose(fptr); fclose(fptr_tmp); rename(tmp_fname, FILE_70_NAME); return 1;}/* ------------------------------------------------------------------------- */int output_station_headers(){ FILE *fptr; char fname[200]; char buff[500]; struct type50 *type50_ptr; type50_ptr = type50_head; /* find the last updated station record - later !!!!#### */ while (type50_ptr) { /* this checks for user defined stations from cmd line */ if (!chk_station(type50_ptr->station)) { type50_ptr = type50_ptr->next; continue; } if ((type10.version >= 2.3) && !chk_network(type50_ptr->network_code)) { type50_ptr = type50_ptr->next; continue; } /* this scan list as gotten from the data records parsing */ if (!already_saved(type50_ptr->station)) { type50_ptr = type50_ptr->next; continue; } /* construct header file for each station */ sprintf(fname, "%s.%s", STATION_FRONT_NAME, type50_ptr->station); if ((fptr = fopen(fname, "a")) == NULL) { fprintf(stderr, "Error! output_station_headers: unable to open output file: %s!\n", fname); perror("output_station_headers"); return 0; } sprintf(buff, "0500000%-5s%10.6f%11.6f%7.1f%04d%03d%s~%03d%04d%02d%s~%s~%1s%-2s", type50_ptr->station, type50_ptr->latitude, type50_ptr->longitude, type50_ptr->elevation, type50_ptr->reserved1, type50_ptr->reserved2, type50_ptr->name, type50_ptr->owner_code, type50_ptr->longword_order, type50_ptr->word_order, type50_ptr->start== NULL ? "" : type50_ptr->start, type50_ptr->end == NULL ? "" : type50_ptr->end, type50_ptr->update, type10.version >= 2.3 ? type50_ptr->network_code : ""); fix_rec_length(buff); if (!out_to_disk(fptr, buff, strlen(buff), 'S')) { fprintf(stderr, "Error! output_seed_headers: unable to write station header to output file!\n"); perror("ouput_seed_headers"); fclose(fptr); return 0; } /* type 51 - station comment */ if (!output_station_comment(type50_ptr->type51_head, fptr)) { fclose(fptr); return 0; } /* channel stuff */ if (!output_channel(type50_ptr->type52_head, fptr)) { fclose(fptr); return 0; } /* done with this station */ /* bump up the file to a LRECL boundary */ if (!fill_to_LRECL(fptr)) { fprintf(stderr, "ouput_station_headers: unable to write station headers, file: %s\n", fname); perror("ouput_station_headers"); fclose(fptr); return 0; } fclose(fptr); type50_ptr = type50_ptr->next; } /* while more stations */ return 1;}/* ------------------------------------------------------------------------- */int output_station_comment(type51_ptr, fptr)struct type51 *type51_ptr;FILE *fptr;{ char buff[500]; while (type51_ptr) { sprintf(buff, "0510000%s~%s~%04d%06d", type51_ptr->start == NULL ? "" : type51_ptr->start, type51_ptr->end == NULL ? "" : type51_ptr->end, type51_ptr->comment_code, type51_ptr->level_code); fix_rec_length(buff); if (!out_to_disk(fptr, buff, strlen(buff), 'S')) { fprintf(stderr, "Error! output_type51: unable to write station comments to file!\n"); perror("output_type51"); return 0; } type51_ptr = type51_ptr->next; } return 1; }/* ------------------------------------------------------------------------- */int output_channel(type52_ptr, fptr) struct type52 *type52_ptr; FILE *fptr; { char buff[500]; while (type52_ptr) { /* check to make sure it's a wanted channel */ if (!chk_channel(type52_ptr->channel)) { type52_ptr = type52_ptr->next; continue; } sprintf(buff, "0520000%2s%-3s%04d%03d%s~%03d%03d%10.6f%11.6f%7.1f%5.1f%5.1f%5.1f%04d%02d%10.4e%10.4e%04d%s~%s~%s~%1s", type52_ptr->location == NULL ? "" : type52_ptr->location, type52_ptr->channel, type52_ptr->subchannel, type52_ptr->instrument_code, type52_ptr->inst_comment == NULL ? "" : type52_ptr->inst_comment, type52_ptr->signal_units_code, type52_ptr->calib_units_code, type52_ptr->latitude, type52_ptr->longitude, type52_ptr->elevation, type52_ptr->local_depth, type52_ptr->azimuth, type52_ptr->dip, type52_ptr->format_code, type52_ptr->log2drecl, type52_ptr->samplerate, type52_ptr->clock_tolerance, type52_ptr->reserved1, type52_ptr->channel_flag == NULL ? "" : type52_ptr->channel_flag, type52_ptr->start == NULL ? "" : type52_ptr->start, type52_ptr->end == NULL ? "" : type52_ptr->end, type52_ptr->update == NULL ? "" : type52_ptr->update); fix_rec_length(buff); if (!out_to_disk(fptr, buff, strlen(buff), 'S')) { fprintf(stderr, "Error! output_type51: unable to write station comments to file!\n"); perror("output_type51"); return 0; } if (!output_response(type52_ptr->response_head, fptr)) return 0; if (!output_channel_comment(type52_ptr->type59_head, fptr)) return 0; if (!output_channel(type52_ptr->channel_update, fptr)) return 0; type52_ptr = type52_ptr->next; } return 1;} /* ------------------------------------------------------------------------- */ int output_response(response, fptr)struct response *response;FILE * fptr;{ int error = 0; while (response) { switch (response->type) { case 'P' : error = output_poles_zeros(response->ptr.type53, fptr); break; case 'C' : error = output_coefficients(response->ptr.type54, fptr); break; case 'L' : error = output_list(response->ptr.type55, fptr); break; case 'G' : error = output_generic(response->ptr.type56, fptr); break; case 'D' : error = output_decimations(response->ptr.type57, fptr); break; case 'S' : error = output_sensitivity(response->ptr.type58, fptr); break; case 'R' : /* error = output_reference(response->ptr.type60, fptr); */ break; case 'F' : error = output_FIR(response->ptr.type61, fptr); break; case 'O' : error = output_poly(response->ptr.type62, fptr); break; } if (error) { fprintf(stderr, "Error! output_response: unable to output responses to disk!\n"); perror("output_response"); return 0; } response = response->next; } return 1;}/* ------------------------------------------------------------------------- */int output_poles_zeros(type53_ptr, fptr)struct type53 *type53_ptr;FILE *fptr;{ char *ch_ptr; char wrkstr[10]; char *buff; int i; while (type53_ptr) { /* allocate room for type 53 + zeros and poles - * 40 + 48 bytes; refer to seed docs * plus one for null byte */ buff = malloc(3 + /* type */ 4 + /* size */ 1 + /* transfer */ 2 + /* seq number */ 3 + /* input units */ 3 + /* output units */ 12 + /* A0 */ 12 + /* Normalization */ 3 + /* number of zeros */ 3 + /* number of poles */ /* 46 total */ (48 * (type53_ptr->number_zeroes + type53_ptr->number_poles)) + 1); if (buff == NULL) { return 1; /* error condition */ } memset(buff, 0, 46 + (48 * (type53_ptr->number_zeroes + type53_ptr->number_poles)) + 1); /* --------------------------------------- */ sprintf(buff, "0530000%1s%2d%03d%03d%12.5e%12.5e%03d", type53_ptr->transfer, type53_ptr->stage, type53_ptr->input_units_code, type53_ptr->output_units_code, type53_ptr->ao_norm, type53_ptr->norm_freq, type53_ptr->number_zeroes); ch_ptr = buff + strlen(buff); for (i = 0; i < type53_ptr->number_zeroes; i++) { sprintf(ch_ptr, "%12.5e%12.5e%12.5e%12.5e", type53_ptr->zero[i].real, type53_ptr->zero[i].imag, type53_ptr->zero[i].real_error, type53_ptr->zero[i].real_error); /* moves to the end */ ch_ptr += 48; } sprintf(ch_ptr, "%03d", type53_ptr->number_poles); ch_ptr += 3; for (i = 0; i < type53_ptr->number_poles; i++) { sprintf(ch_ptr, "%12.5e%12.5e%12.5e%12.5e", type53_ptr->pole[i].real, type53_ptr->pole[i].imag, type53_ptr->pole[i].real_error, type53_ptr->pole[i].real_error); /* moves to the end */ ch_ptr += 48; } /* fix up the blockette length field */ sprintf(wrkstr, "%04d", strlen(buff)); memcpy(&buff[3], wrkstr, strlen(wrkstr)); if (!out_to_disk(fptr, buff, strlen(buff), 'S')) { free(buff); return 1; /* error */ } /* --------------------------------------- */ free(buff); type53_ptr = type53_ptr->next; } /* while type 53 */ return 0; /* no error condition */}/* ------------------------------------------------------------------------- */int output_coefficients(type54_ptr, fptr)struct type54 *type54_ptr;FILE *fptr;{ char *ch_ptr; char wrkstr[10]; char *buff; int i; while (type54_ptr) { /* allocate room for blockette */ buff = malloc(3 + /* blockette type */ 4 + /* size */ 1 + /* response type */ 2 + /* stage seq # */ 3 + /* input units */ 3 + /* output units */ 4 + /* # numerators */ 4 + /* # denominators*/ (24 * (type54_ptr->number_numerators+ type54_ptr->number_denominators)) + 1); /* plus 1 for null byte */ if (buff == NULL) { return 1; /* error condition */ } memset(buff, 0, 3+4+1+2+3+3+4+4+ (24 * (type54_ptr->number_numerators + type54_ptr->number_denominators)) + 1); /* --------------------------------------- */ sprintf(buff, "0540000%1s%2d%03d%03d%04d", type54_ptr->transfer, type54_ptr->stage, type54_ptr->input_units_code, type54_ptr->output_units_code, type54_ptr->number_numerators); /* move to end so far */ ch_ptr = buff + strlen(buff); for (i = 0; i < type54_ptr->number_numerators; i++) { sprintf(ch_ptr, "%12.5e%12.5e", type54_ptr->numerator[i].coefficient, type54_ptr->numerator[i].error); /* moves to the end */ ch_ptr += 24; } sprintf(ch_ptr, "%04d", type54_ptr->number_denominators); ch_ptr += 4; for (i = 0; i < type54_ptr->number_denominators; i++) { sprintf(ch_ptr, "%12.5e%12.5e", type54_ptr->denominator[i].coefficient, type54_ptr->denominator[i].error); /* moves to the end */ ch_ptr += 24; } /* fix up the blockette length field */ sprintf(wrkstr, "%04d", strlen(buff)); memcpy(&buff[3], wrkstr, strlen(wrkstr)); /* out to file */ if (!out_to_disk(fptr, buff, strlen(buff), 'S')) { free(buff); return 1; /* error */ } /* --------------------------------------- */ free(buff); type54_ptr = type54_ptr->next; } /* while type 54 */ return 0; /* no error condition */}/* ------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -