static PyObject * python_orbreap( PyObject *self, PyObject *args ) { char *usage = "Usage: _orbreap(orb)\n"; int orbfd; int pktid; char srcname[ORBSRCNAME_SIZE]; double pkttime; char *pkt = 0; int nbytes = 0; int bufsize = 0; PyObject *obj; int rc; if( ! PyArg_ParseTuple( args, "i", &orbfd ) ) { if( ! PyErr_Occurred() ) { PyErr_SetString( PyExc_RuntimeError, usage ); } return NULL; } rc = orbreap( orbfd, &pktid, srcname, &pkttime, &pkt, &nbytes, &bufsize ); if( rc < 0 ) { elog_flush( 1, 0 ); PyErr_SetString( PyExc_RuntimeError, "orbreap failed\n" ); return NULL; } obj = Py_BuildValue( "s#", pkt, nbytes ); free( pkt ); return Py_BuildValue( "isdOi", pktid, srcname, pkttime, obj, nbytes ); }
static int autodrm_response (Dbptr db) { Dbptr dbstage; static Hook *hook = 0; char sta[MAX_STA_SIZE], chan[MAX_CHAN_SIZE]; double time, endtime; long stageid; char *s; Response *response; Response_group *group; char iunits[96], ounits[96]; char gtype[100]; long i, j; Paz *paz; Fir *fir; Fap *fap; Fap2 *fap2; FILE *file; double samprate, gnom, gcalib; double calper=0.0; long decifac; char dir[100], dfile[100]; char filename[STRSZ]; long nmatches; int errors = 0; Tbl *tbl, *stbl; double mintime=0, maxtime=0; char segtype; static Tbl *keys1 = 0, *keys2 = 0; if (keys1 == 0) { keys1 = strtbl ("sta", "chan", "time", NULL); keys2 = strtbl ("sta", "chan", "time::endtime", NULL); } dbstage = dblookup (db, 0, "stage", 0, 0); nmatches = dbmatches (db, dbstage, &keys1, &keys2, &hook, &tbl); switch (nmatches) { case dbINVALID: case 0: dbgetv (db, 0, "sta", sta, "chan", chan, "time", &time, NULL); complain (0, "Can't match record for %s:%s @ %s in stage table", sta, chan, s = strydtime (time)); free (s); errors++; break; default: stbl = newtbl (maxtbl (tbl)); for (i = 0; i < nmatches; i++) { dbstage.record = (long) gettbl (tbl, i); dbgetv (dbstage, 0, "stageid", &stageid, "time", &time, "endtime", &endtime, NULL); if (i == 0) { mintime = time; maxtime = endtime; } else { mintime = MAX (time, mintime); maxtime = MIN (endtime, maxtime); } settbl (stbl, stageid - 1, (char *) i); } if (maxtbl (tbl) != maxtbl (stbl)) { dbgetv (db, 0, "sta", sta, "chan", chan, "time", &time, NULL); complain (0, "stageid numbers for %s:%s @ %s don't add up.", sta, chan, s = strydtime (time)); free (s); errors++; } else { errors += write_cal2 (db, mintime, maxtime, &calper); for (i = 0; i < nmatches; i++) { j = (long) gettbl (stbl, i); dbstage.record = (long) gettbl (tbl, j); dbgetv (dbstage, 0, "sta", sta, "chan", chan, "time", &time, "endtime", &endtime, "stageid", &stageid, "decifac", &decifac, "samprate", &samprate, "gnom", &gnom, "gcalib", &gcalib, "dir", dir, "dfile", dfile, "gtype", gtype, "iunits", iunits, "ounits", ounits, NULL); if (gcalib > 0.0) { gnom *= gcalib; } else if (gcalib < 0.0) { complain (0, "gcalib = %10.3f < 0. is invalid for %s:%s @ %s.\n", gcalib, sta, chan, s = strydtime (time)); free (s); errors++; } if (*dir != '-' || *dfile != '-') { long mark; dbextfile (dbstage, "stage", filename); mark = elog_mark (); elog_log (0, "response file is '%s'", filename); if ((file = fopen (filename, "r")) == 0 || read_response (file, &response) < 0) { register_error (0, "Can't read response file %s for %s_%s @ %s", filename, sta, chan, s = strydtime (time)); free (s); fclose (file); errors++; } else { fclose (file); if (response->ngroups > 1) { register_error (0, "stage response file %s has %d stages, not 1", filename, response->ngroups); errors++; } else { group = response->groups; switch (group->id) { case PAZ: /* The normalization frequency chosen in the * response file may not necessarily be the * same as the one chosen by calibration * table for insertion into the seed volumes. * Consequently, we have to adjust the * specified gnom to be correct for the seed * normalization frequency. Since the gain * is * * G(f) = gnom_db * A_response_file * P(f) = * gnom_seed * A_seed * P(f) * * We have * * gnom_seed = gnom_db * A_response_file / * A_seed * * gnom_db is just the gnom from the stage * table. A_response_file is the * normalization from the response file, left * in the stage structure. Below, we * calculate A_seed by setting * A_response_file to 1.0. * */ paz = (Paz *) group->pvt; for (j = 0; j < strlen (iunits); j++) { iunits[j] = tolower (iunits[j]); } s = getarr (Segtype, iunits); if (s == 0) { segtype = 'D'; } else { segtype = *s; } adwrite_paz (stageid, 0, gnom, segtype, ounits, paz); break; case IIR: paz = (Paz *) group->pvt; for (j = 0; j < strlen (iunits); j++) { iunits[j] = tolower (iunits[j]); } s = getarr (Segtype, iunits); if (s == 0) { segtype = 'D'; } else { segtype = *s; } adwrite_paz (stageid, 1, gnom, segtype, ounits, paz); break; case FIR: fir = (Fir *) group->pvt; errors += adwrite_fir (stageid, gnom, fir); break; case FAP: fap = (Fap *) group->pvt; errors += adwrite_fap (stageid, ounits, fap); break; case FAP2: fap2 = (Fap2 *) group->pvt; errors += adwrite_fap2 (stageid, ounits, fap2); break; default: complain (0, "Unknown filter type %d in response file %s\n", group->id, filename); errors++; break; } } } elog_flush (mark, 0); } else { char *desc = ""; if (gcalib > 0.0) { gnom *= gcalib; } else if (gcalib < 0.0) { complain (0, "gcalib = %10.3f < 0. is an invalid value.\n", gcalib); errors++; } if (strcmp (gtype, "digitizer") == 0 /* following hack for psd2db */ || strcmp (gtype, "sensor") == 0) { fprintf (stdout, "DIG2 %2ld %15.8e %11.5f %s\n", stageid, gnom, samprate, desc); } else if (strcmp (gtype, "amplifier") == 0) { /* no corners */ fprintf (stdout, "GEN2 %2ld %c %15.8e %7.3f 0 %s\n", stageid, *ounits, gnom, calper, desc); } else { complain (0, "Unrecognized gtype='%s' for %s:%s @ %s", gtype, sta, chan, s = strydtime (time)); free (s); errors++; } } } } freetbl (stbl, 0); break; } freetbl (tbl, 0); return errors; }
int main (int argc, char **argv) { int c, errflg = 0; char *in, *out; Dbptr dbin, dbout; char aline[STRSZ]; int verbose = 0; char *pfname, *error; long orid ; int nostdin=0 ; pfname=strdup("dbgenloc"); elog_init (argc, argv); elog_set ( ELOG_MAXMSG, -1, 0 ) ; while ((c = getopt (argc, argv, "hnp:vV")) != -1) { switch (c) { case 'h': usage (); break ; case 'n': nostdin = 1; break ; case 'p': pfname = optarg ; break ; case 'v': verbose = 1; break; case 'V': cbanner("$Revision$ $Date$\n", "dbgenloc input-db output-db", "Gary Pavlis", "Indiana University", "*****@*****.**"); exit (0); default: errflg++; } } if (errflg || argc - optind != 2) usage (); in = argv[optind++]; if (dbopen (in, "r+", &dbin)) die (1, "Can't open input database %s\n", in); out = argv[optind++]; if (dbopen (out, "r+", &dbout)) die (1, "Unable to open output database %s\n", out); while (nostdin || gets (aline)) { switch (run_location (dbin, dbout, pfname, &orid, &error)) { case 0: printf ("location_solution: new origin %ld\n", orid); break; default: printf ("location_solution: no_solution : %s\n", error); break; } fflush (stdout); elog_flush (1, 0) ; if ( nostdin ) break; } return 0; }