📄 output_css.c
字号:
fprintf (stderr, "\tExecution aborted.\n"); chdir(orig_dir); return; } fclose (outfile); sprintf (outfile_name, "rdseed.wfdisc", css_filename); if ((outfile = fopen (outfile_name, "a")) == NULL) { fprintf (stderr,"\tWARNING (output_css): "); fprintf (stderr,"Output file %s is not available for writing.\n",outfile_name); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } if (fwrite (Wfdisc_buf, strlen(Wfdisc_buf), 1, outfile) != 1) { fprintf (stderr, "WARNING (output_css): "); fprintf (stderr, "failed to properly write CSS WFDISC data to %s.\n", outfile_name); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } fclose (outfile); timecvt(&stime, current_channel->start); siteid++; sprintf(&Wfdisc_buf[0], "%8d ", siteid); sprintf(&Wfdisc_buf[0], "%-6s ", data_hdr->station); sprintf(&Wfdisc_buf[7], " %04d%03d ", stime.year, stime.day); sprintf(&Wfdisc_buf[16], "%8d ", -1); sprintf(&Wfdisc_buf[25], "%9.4f ", current_channel->latitude); sprintf(&Wfdisc_buf[35], "%9.4f ", current_channel->longitude); sprintf(&Wfdisc_buf[45], "%9.4f ", current_channel->elevation/1000); sprintf(&Wfdisc_buf[55], "%-50.50s ", current_station->name); sprintf(&Wfdisc_buf[106], "%-4s ", "-"); sprintf(&Wfdisc_buf[111], "%-6s ", "-"); sprintf(&Wfdisc_buf[118], "%9.4f ", 0.0); sprintf(&Wfdisc_buf[128], "%9.4f ", 0.0); sprintf(&Wfdisc_buf[138], "%-17s\n", lddate); sprintf (outfile_name, "rdseed.site", css_filename); if ((outfile = fopen (outfile_name, "a")) == NULL) { fprintf (stderr,"\tWARNING (output_css): "); fprintf (stderr,"Output SITE file is not available for writing.\n"); fprintf (stderr, "\tExecution continuing.\n"); perror("output_css()"); chdir(orig_dir); return; } if (fwrite (Wfdisc_buf, strlen(Wfdisc_buf), 1, outfile) != 1) { fprintf (stderr, "WARNING (output_css): "); fprintf (stderr, "failed to properly write CSS SITE data to %s.\n", outfile_name); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } fclose (outfile); sprintf(&Wfdisc_buf[0], "%-6s ", data_hdr->station); sprintf(&Wfdisc_buf[7], "%-8s ", channel); sprintf(&Wfdisc_buf[16], " %04d%03d ", stime.year, stime.day); sprintf(&Wfdisc_buf[25], "%8d ", -1); sprintf(&Wfdisc_buf[34], "%8d ", -1); /* off date */ sprintf(&Wfdisc_buf[43], "%-4s ", "n"); sprintf(&Wfdisc_buf[48], "%9.4f ", current_channel->local_depth); sprintf(&Wfdisc_buf[58], "%6.1f ", azimuth); sprintf(&Wfdisc_buf[65], "%6.1f ", dip+90.0); sprintf(&Wfdisc_buf[72], "%-50s ", "-"); sprintf(&Wfdisc_buf[123], "%17s\n", lddate); sprintf (outfile_name, "rdseed.sitechan", css_filename); if ((outfile = fopen (outfile_name, "a")) == NULL) { fprintf (stderr,"\tWARNING (output_css): "); fprintf (stderr,"Output SITE file is not available for writing.\n"); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } if (fwrite (Wfdisc_buf, strlen(Wfdisc_buf), 1, outfile) != 1) { fprintf (stderr, "WARNING (output_css): "); fprintf (stderr, "failed to properly write CSS SITECHAN data to %s.\n", outfile_name); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } fclose (outfile); } current_channel = current_channel->next; } /* for channel */ /* scan for network/station already there */ if (!scan_affiliation("rdseed.affiliation", current_station->network_code, current_station->station)) { if ((outfile = fopen("rdseed.affiliation", "a+")) == NULL) { fprintf (stderr,"\tWARNING (output_css): "); fprintf (stderr,"Output affliation file is not available for writing.\n"); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } if (outfile != NULL) { fprintf(outfile, "%-8.8s%-6.6s%17s\n", current_station->network_code, current_station->station, lddate); fclose(outfile); } } /* affiliation */ if (!scan_network("rdseed.network", current_station->network_code)) { if ((outfile = fopen ("rdseed.network", "a+")) == NULL) { fprintf (stderr,"\tWARNING (output_css): "); fprintf (stderr,"CSS network file is not available for writing.\n"); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } else { fprintf(outfile, "%-8.8s%-80.80s%-4.4s%-15.15s%8.8d%-17s\n", current_station->network_code, get_net(current_station->owner_code), "-1", "-1", -1, lddate); fclose(outfile); } } /* network */ /* no need to create file more than once */ if ((access("rdseed.origin", F_OK) < 0) && (type71_head != NULL)) { int etime; int netmag; char **jdate; char jul_date[10]; struct type71sub *this_mag; int n; if ((outfile = fopen ("rdseed.origin", "a+")) == NULL) { fprintf (stderr,"\tWARNING (output_css): "); fprintf (stderr,"CSS origin file is not available for writing.\n"); perror("output_css()"); fprintf (stderr, "\tExecution continuing.\n"); } else { struct type71 *t71_ptr = type71_head; while (t71_ptr) { n = split(t71_ptr->origin_time, &jdate, ','); if (n == 0) { fprintf(stderr, "Warning, output_css(): Bad hypo date encountered\n"); strcpy(jul_date, "0001001"); } else { n == 1 ? /* no day number */ sprintf(jul_date, "%s001", jdate[0]): sprintf(jul_date, "%s%03d", jdate[0], atoi(jdate[1])); } fuse(&jdate, n); timecvt(&stime, t71_ptr->origin_time); etime = stime.second; etime += stime.minute * 60; etime += stime.hour * 3600; etime += (stime.day-1) * 3600 * 24; for (i = 1971; i <= stime.year; i++) { if (isaleap(i - 1)) etime += 366*24*3600; else etime += 365*24*3600; } fprintf(outfile, "%9.4f %9.4f %9.4f %17.5f %8d %8d %-8s %4d %4d %4d %8d %8d %-7s %9.4f %s", t71_ptr->latitude, t71_ptr->longitude, t71_ptr->depth, (float) etime, ORID, -1, jul_date, -1, /* nass */ -1, /* ndef */ -1, /* ndp */ t71_ptr->seismic_region, t71_ptr->seismic_location, "-", /* event type */ -999.9, /* estimated phase depth */ "-"); /* depth method used */ this_mag = get_mag("mb", t71_ptr->number_magnitudes, t71_ptr->magnitude); if (this_mag == NULL) { fprintf(outfile, " %7.2f %8d ", -999.0, -1); } else { fprintf(outfile, " %7.2f %8d ", this_mag->magnitude, -1); } this_mag = get_mag("ms", t71_ptr->number_magnitudes, t71_ptr->magnitude); if (this_mag == NULL) { fprintf(outfile, "%7.2f %8d ", -999.0, -1); } else { fprintf(outfile, "%7.2f %8d ", this_mag->magnitude, -1); } this_mag = get_mag("ml", t71_ptr->number_magnitudes, t71_ptr->magnitude); if (this_mag == NULL) { fprintf(outfile, "%7.2f %8d ", -999.0, -1); } else { fprintf(outfile, "%7.2f %8d ", this_mag->magnitude, -1); } fprintf(outfile, "%-15s %-15s %8d %-17s\n", "-", get_src_name(type71_head->source_code), -1, lddate); t71_ptr = t71_ptr->next; } /* while more t_71s */ } /* else */ } chdir(orig_dir);}/************************************************** * float get_mag() * helper proc for output_css() * * scans magnitude list in blockette 71 struct for * matching mag based on type (mb,ms, etc). * If one is found, iut builds the netmag file as well * */struct type71sub *get_mag(which_mag_type, num_mags, mag_list)char *which_mag_type; int num_mags; struct type71sub *mag_list; { int i; STRUPPERCASE(which_mag_type); for (i = 0; i < num_mags; i++) { STRUPPERCASE(mag_list[i].type); if (strstr(mag_list[i].type, which_mag_type)) { return &mag_list[i]; } } return NULL;}/************************************************** * int scan_affilition() * helper proc for output_css() * * scan file for matching station/network combo. * */int scan_affiliation(fname, n, s)char *fname, *s, *n;{ char stn[20], net[20], ld_date[20]; FILE *f; if ((f = fopen (fname, "r")) == NULL) return 0; /* not there, scan failed */ while (1) { /* note: load date is 2 fields */ if (fscanf(f, "%s %s %*s %*s\n", net, stn) != 2) { fclose(f); return 0; /* end of the line - bale */ } if ((strcasecmp(n, net) == 0) && (strcasecmp(s, stn) == 0)) { fclose(f); return 1; /* found it - bale */ } } /* should never get here */ return 0;}/***************************************************** * scan_network() helper proc for output_css() * checks each line for existing network */int scan_network(fname, n)char *fname;char *n;{ FILE *f; char net[20]; char buffer[200]; int num_flds; if ((f = fopen (fname, "r")) == NULL) return 0; /* not there, scan failed */ while (fgets(buffer, sizeof(buffer), f)) { /* lop off at first space, only scan network code */ sscanf(buffer, "%s", net); if ((strcasecmp(n, net) == 0)) { fclose(f); return 1; /* found it - bale */ } } fclose(f); return 0;}char *get_net(code)int code;{ char *ch_ptr; struct type33 *t_33_ptr; t_33_ptr = find_type_33(type33_head, code); if (t_33_ptr == NULL) { return ""; } return t_33_ptr->abbreviation; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -