// Create a station from a sacfile station *loadStation(char *filename) { station *s = NULL; SACHEAD *h = io_readSacHead(filename); if (h == NULL) { fprintf(stderr, "On Station file %s not found.\n", filename); return s; } s = malloc(sizeof(station)); s->lat = h->stla; s->lon = h->stlo; // Elevation should be in KM and + is down ! s->el = -h->stel / 1000.0; s->name = NULL; s->net = NULL; // fprintf(stderr, "File: %s ", filename); hdu_getValueFromChar("kstnm", h, NULL, NULL, &s->name); hdu_getValueFromChar("knetwk", h, NULL, NULL, &s->net); h = io_freeData(h); return s; }
// Create a pick from a sacfile pick *loadPick(char *filename, stations * ss) { char *name = NULL; char *net = NULL; int Id; pick *p = NULL; SACHEAD *h = io_readSacHead(filename); if (h == NULL) { fprintf(stderr, "On pick file %s not found.\n", filename); return p; } /* Check if the file is picked */ if (h->f == -12345. || h->a == -12345.) { h = io_freeData(h); return p; } hdu_getValueFromChar("KSTNM", h, NULL, NULL, &name); hdu_getValueFromChar("KNETWK", h, NULL, NULL, &net); Id = getStationId(ss, name, net); if (Id == -1) { fprintf(stderr, "Station for pick %s not found.\n", filename); h = io_freeData(h); name = io_freeData(name); net = io_freeData(net); return p; } p = malloc(sizeof(pick)); p->station = Id; p->phase = 1; p->tobs = h->f - h->o; p->tref = h->a - h->o; p->difference = p->tobs - p->tref; p->residual = -999.9; p->gcarc = h->gcarc; p->baz = h->baz; h = io_freeData(h); name = io_freeData(name); net = io_freeData(net); return p; }
// Create one event from a sac filename event *loadEvent(char *sacFilename) { event *e = NULL; int i; SACHEAD *h = io_readSacHead(sacFilename); if (h == NULL) { fprintf(stderr, "On Event file %s not found.\n", sacFilename); return e; } e = malloc(sizeof(event)); e->Id = NULL; hdu_getValueFromChar("kevnm", h, NULL, NULL, &e->Id); // if no id use the folder name if ((i = strncmp(e->Id, SAC_HEADER_CHAR_UNDEFINED, strlen(SAC_HEADER_CHAR_UNDEFINED)) == 0)) { char *filenamecopy = malloc(sizeof(char) * (strlen(sacFilename)+1)); strcpy(filenamecopy, sacFilename); char *basefolder; basefolder = dirname(filenamecopy); free(e->Id); e->Id = malloc(sizeof(char)*(strlen(basefolder)+1)); strcpy(e->Id, basefolder); free(filenamecopy); filenamecopy = NULL; fprintf(stderr, "Warning, no kevnm defined using the folder name.\n"); } e->lat = h->evla; e->lon = h->evlo; e->depth = h->evdp; e->magnitude = h->mag; e->n = 0; e->resMean = 0.0; e->resStd = 0.0; e->hasMean = 0; e->picks = NULL; h = io_freeData(h); return e; }
int findHas(glob_t *glb) { int has = 0; if (glb == NULL) return has; if (glb->gl_pathc == 0) return has; SACHEAD *head = io_readSacHead(glb->gl_pathv[0]); if (head != NULL){ if (head->unused27 == 1) has = 1; head = io_freeData(head); } return has; }
int findFilters(glob_t *glb, float *lp, float *hp) { int state = 0; // Set default values *lp = getConfigAsNumber(config, NAME_LP, DEFAULT_LP); *hp = getConfigAsNumber(config, NAME_HP, DEFAULT_HP); if (glb == NULL) return state; if (glb->gl_pathc == 0) return state; SACHEAD *head = io_readSacHead(glb->gl_pathv[0]); if (head == NULL) return state; //P phase if (getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK) == P){ if (head->unused11 != -12345.0 && head->unused12 != -12345.0 && head->unused11 > head->unused12) { *lp = head->unused11; *hp = head->unused12; state = (head->unused11 > head->unused12); } } else if (getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK) == S){ //Phase S if (head->unused6 != -12345.0 && head->unused7 != -12345.0 && head->unused6 > head->unused7) { *lp = head->unused6; *hp = head->unused7; state = (head->unused6 > head->unused7); } } else sprintf(message,"Something is not right\n"); head = io_freeData(head); return state; }