示例#1
0
void usage()
{
	cbanner("1.0",
		"db file [-n -V -v -pf pffile -sift expression]",
		"Gary L. Pavlis", "Indiana University",
		"*****@*****.**");
	exit(-1);
}
示例#2
0
static void
usage()
{
	cbanner("$Date$",
		"[-sleep seconds] [-pf pfname] \n\t\t\t[-prefix prefix] [-modified_after time] [-v] db orb",
		"Nikolaus Horn",
		"ZAMG / Vienna",
		"*****@*****.**");
	exit(1);
}
示例#3
0
static void
usage ()
{
    cbanner ( "0.99", 
	     "[-p pfname] [-s subset] [-t triggertime] db file start end",
		 "Nikolaus Horn",
		 "Vienna / Austria",
	     "*****@*****.**");
    exit (1);
}
示例#4
0
static void
usage ()
{
    cbanner ( 0,
	     "[-v] [-c calib] miniseed outfile [starttime [endtime|epoch]]", 
	     "Nikolaus Horn", 
	     "Vienna / Austria", 
	     "*****@*****.**" ) ; 
    exit (1);
}
示例#5
0
static void
usage ()
{
	char	*usage="[-v] dbin dbout";
	char 	*version= "1.0";
	char	*author= "Nikolaus Horn";
	char	*location="ZAMG / Vienna";
	char	*email = "*****@*****.**";
    cbanner (version,usage,author,location,email);
    exit (1);
}
示例#6
0
static void
usage( void )
{
	cbanner( "$Date$",
		"[-vV] [-d cachedaemon] [-s statefile] [-p pffile] [-m match] [-f from]  orbname dbcache\n",
		"Dr. Kent Lindquist",
		"Lindquist Consulting, Inc.",
		"*****@*****.**" );

	exit( 1 );
}
示例#7
0
static void
usage ()
{
	char	*usage="[-v] [-c chanmatch] [-t] [-n maxpkts] \n\t[-m targetname] [-r reject] [-S statefile] \n\tevtorb dborb [start-time] [period|end-time]";
	char 	*version= "0.99";
	char	*author= "Nikolaus Horn (12/18/2002)";
	char	*location="ZAMG / Vienna";
	char	*email = "*****@*****.**";
    cbanner (version,usage,author,location,email);
    exit (1);
}
static void
usage()
{
	char           *usage = "[-v] [-close_polygons] [-pname name]\n\t\t[-level level] [-auth author]\n\t\t[-dir dir] [-dfile dfile] datafile db";
	char           *version = "1.0";
	char           *author = "Nikolaus Horn";
	char           *location = "ZAMG / Vienna";
	char           *email = "*****@*****.**";
	cbanner(version, usage, author, location, email);
	exit(1);
}
示例#9
0
void
usage() 
{
	cbanner( "$Date$ $Revision$", 
		 "[-v] [-V] [-p pfname] rtd_ipaddress:port orb",
		 "Kent Lindquist", 
		 "Lindquist Consulting", 
		 "*****@*****.**" );
	
	return;
}
int main(int argc, char **argv)
{
	char *dbin;  /* Input db name */
	char *dbout;  /* output db name */
	Dbptr db;  /* input db pointer */
	Dbptr dbo;  /* base output db pointer */
	Dbptr dbv;  /* set to view formed by join */
	char *pfin=NULL;  /* input parameter file */
	char *sift_exp;  /* sift expression for subset */
	int sift = 0;  /* default is no sift.  */
	Tbl *sortkeys;
	Tbl *joinkey1, *joinkey2;
	/*Pointers to views returned by dbgroup (keyed to origin and event
	respectively */
	Dbptr dborigin_group;
	Tbl *origin_group;  /* relation keys used in grouping*/
	long nevents;
	/* db row variables */
	long evid;
	long nrows, nrows_raw;

	int useold=0;
	Pf *pf;
	Tbl *ta,*tu;
	Tbl *reason_converged, *residual;
	Location_options o;
	Arr *arr_phase;
	int i;
	Tbl *converge_history;

	Hypocenter h0;
	Hypocenter *hypos;
	long niterations;

	char *vmodel;

	int ret_code;  /* ggnloc return code */
	double **C;   /* covariance matrix*/
	float emodel[4];  

	/* entries for S-P feature */
	long nbcs;
	Arr *badclocks;
	/* need global setting of this to handle fixed depth solutions*/
	int global_fix_depth;

	C=dmatrix(0,3,0,3);

	if(argc < 3) usage();
	dbin = argv[1];
	dbout = argv[2];
	for(i=3;i<argc;++i)
	{
		if(!strcmp(argv[i],"-pf"))
		{
			++i;
			if(i>=argc) usage();
			pfin = argv[i];
		}
		else if(!strcmp(argv[i],"-sift"))
		{
			++i;
			if(i>=argc) usage();
			sift_exp = argv[i];
			sift = 1;
		}
		else if(!strcmp(argv[i],"-useold"))
			useold = 1;
		else
			usage();
	}
	/* set default this way*/
	if(pfin == NULL) pfin = strdup("relocate");


	/* Initialize the error log and write a version notice */
	elog_init (argc, argv) ;
	cbanner("Version $Revision$ $Date$\n",
			"relocate inputdb outputdb [-pf pf -sift expression -useold]\n",
			"Gary Pavlis",
                        "Indiana University",
                        "*****@*****.**");

	/* Alway join assoc, arrival, and site.  We join site 
	to make sure station table is properly dynamic to account for
	time changes.  With this setup, the stations can even move
	around and this should still work.*/


	if(dbopen(dbin,"r",&db) == dbINVALID) 
		elog_die(1,"Unable to open input database %s\n",dbin);
	if(dbopen(dbout,"r+",&dbo) == dbINVALID) 
		elog_die(1,"Unable to open output database %s\n",dbout);

	dbv = dbjoin ( dblookup(db,0,"event",0,0),
		dblookup(db,0,"origin",0,0),
		0,0,0,0,0);
	if(dbv.table == dbINVALID)
		elog_die(1,"event->origin join failed\n");
	dbv = dbjoin ( dbv, dblookup(db,0,"assoc",0,0),
			0,0,0,0,0);
	if(dbv.table == dbINVALID)
		elog_die(1,"event->origin->assoc join failed\n");
	dbv = dbjoin ( dbv, dblookup(db,0,"arrival",0,0),
			0,0,0,0,0);
	if(dbv.table == dbINVALID)
		elog_die(1,"event->origin->assoc->arrival join failed\n");
	/* We will explicitly set the keys for this join because it
	was found to fail sometimes */
	joinkey1 = newtbl(0);
	joinkey2 = newtbl(0);
	pushtbl(joinkey1,"arrival.sta");
	pushtbl(joinkey1,"arrival.time");
	pushtbl(joinkey2,"sta");
	pushtbl(joinkey2,"ondate::offdate");
	dbv = dbjoin ( dbv, dblookup(db,0,"site",0,0),
			&joinkey1,&joinkey2,0,0,0);
	if(dbv.table == dbINVALID)
		elog_die(1,"event->origin->assoc->arrival->site join failed\n");

	/* Subset using sift_key if requested */
	if(sift)
	{
		dbv = dbsubset(dbv,sift_exp,0);
		if(dbv.record == dbINVALID)
			elog_die(1,"dbsubset of %s with expression %s failed\n",
				dbin, sift_exp);
	}
	/* This keeps only the prefered origin records intact */
	dbv = dbsubset(dbv,"orid == prefor", 0);
	if(dbv.record == dbINVALID)
			elog_die(1,"Subset to preferred origin records failed\n");

	/* First we have to run a unique key sort in the following order
	to remove redundant picks made on multiple channels.  We will
	issue a warning if the record count changes. */
	dbquery(dbv, dbRECORD_COUNT, &nrows_raw);
	sortkeys = newtbl(0);
	pushtbl(sortkeys,"evid");
	pushtbl(sortkeys,"sta");
	pushtbl(sortkeys,"phase");
	dbv = dbsort(dbv,sortkeys,UNIQUE,0);
	dbquery(dbv, dbRECORD_COUNT, &nrows);
	if(nrows != nrows_raw)
		elog_complain(0,"Input database has duplicate picks of one or more phases on multiple channels\n\
Which picks will be used here is unpredictable\n\
%ld total picks, %ld unique\nContinuing\n", nrows_raw, nrows);

	/* This sort is the required one for the grouping that follows*/

	sortkeys = newtbl(3);
	pushtbl(sortkeys,"evid");
	pushtbl(sortkeys,"orid");
	pushtbl(sortkeys,"arrival.time");
	dbv = dbsort(dbv,sortkeys,0,0);
	if(dbv.record == dbINVALID)
		elog_die(1,"dbsort on evid,orid,arrival.time failed\n");

	/* Set up grouping by events */
	origin_group = newtbl(0);
	pushtbl(origin_group, "evid");
	dborigin_group = dbgroup(dbv, origin_group, "origin_group",1);
	if(dborigin_group.record == dbINVALID)
		elog_die(1,"dbgroup by origin failed\n");

	dbquery(dborigin_group,dbRECORD_COUNT,&nevents);
	elog_notify(0,"Attempting to relocate %ld events in subsetted database\n",
		nevents);
	

	/* DB is now set up correctly, now we turn to the parameter files */
	i = pfread(pfin,&pf);
	if(i != 0) elog_die(1,"Pfread error\n");

	o = parse_options_pf (pf);
	global_fix_depth=o.fix[2];
 	arr_phase = parse_phase_parameter_file(pf);
	vmodel = pfget_string(pf,"velocity_model_name");

	/* set up minus phase for bad clock problems */
	badclocks = newarr(0);
	if(db_badclock_definition(db,pf,badclocks))
		elog_complain(0,"Warning:  problems in database definitions of bad clock time periods\n");
	pfget_badclocks(pf,badclocks);
	nbcs = cntarr(badclocks);
	if(nbcs>0) fprintf(stdout,"relocate:  bad clock feature enabled\n\n");
        /* Change by JN to output evid and orid. */
        /* fprintf(stdout,"lat lon depth time rms wrms interquartile ndata ndgf iterations\n"); */
	fprintf(stdout,"evid orid lat lon depth time rms wrms interquartile ndata ndgf iterations\n");

	/* Main loop.  We utilize the group views and loop through by 
	events */
	for(dborigin_group.record=0;
		dborigin_group.record< nevents;++dborigin_group.record)
	{
		Dbptr db_bundle;  /* db pointer returned from bundle field 
				of dborigin_group for current event */
		Arr *station_table;
		Arr *array_table;
		long is, ie; 
		long orid;  /* orid assigned relocated event in output db */

		if(dbgetv(dborigin_group,0,"evid", &evid,
			"bundle", &db_bundle,NULL ) == dbINVALID)
			elog_complain(1,"dbgetv error for row %ld of event group\n",
				dborigin_group.record);
		dbget_range(db_bundle,&is,&ie);

		station_table = dbload_station_table(dbv,
						is,ie,pf);
		array_table = dbload_array_table(dbv,
						is,ie,pf);
		ta = dbload_arrival_table(dbv,
				is,ie,station_table, arr_phase);


		tu = dbload_slowness_table(dbv,
				is,ie,array_table, arr_phase);
		/* this actually sets up the minus phase feature for bad clocks*/
		if(nbcs)
		{
			if(minus_phases_arrival_edit(ta,arr_phase,badclocks))
				elog_complain(0,"Warning(relocate):  problems in minus_phase_arrival_edit function\n");
		}
		if(useold)
		{
			char dtype[2];
			h0 = db_load_initial(dbv,is);
			/* keep fixed depth if done before.  
			setting dbv.record here is a bit of
			a potential maintenance problem */
			dbv.record=is;
			dbgetv(dbv,0,"dtype",dtype,NULL );
			if( (!strcmp(dtype,"g")) || (!strcmp(dtype,"r")) )
				o.fix[2]=1;
			
		}
		else
			h0 = initial_locate(ta, tu, o, pf);

		ret_code = ggnloc(h0,ta,tu,o,
			&converge_history,&reason_converged,&residual);
			
		if(ret_code < 0)
		{
			elog_complain(1,"ggnloc failed to produce a solution\n");
		}
		else 
		{
			if(ret_code > 0)
			    elog_complain(1,"%d travel time calculator failures in ggnloc\nSolution ok\n",
				ret_code);
			
			niterations = maxtbl(converge_history);
			hypos = (Hypocenter *)gettbl(converge_history,
								niterations-1);
			predicted_errors(*hypos,ta,tu,o,C,emodel);

                        /* Next 3 calls changed by JN to output evid, orid and number_data */
			orid = save_origin(dbv,is,ie,o.fix[3],*hypos,dbo);
			evid = save_event(dbv,is,ie,orid,dbo);

			fprintf(stdout,"%ld %ld %lf %lf %lf %lf %g %g %g %d %d %ld\n",
					evid,
					orid,
					hypos->lat,hypos->lon,hypos->z,hypos->time,
					hypos->rms_raw, hypos->rms_weighted,
					hypos->interquartile,
					hypos->number_data,
					hypos->degrees_of_freedom,
					niterations);
	
			save_origerr(orid,*hypos,C,dbo);
			save_assoc(dbv,is,ie,orid,vmodel,residual,*hypos,dbo);
			/* These save genloc add on tables */
			save_emodel(orid,emodel,dbo);
			save_predarr(dbo,ta,tu,*hypos,orid,vmodel);
		}
		o.fix[2]=global_fix_depth;
		if(maxtbl(converge_history)>0)freetbl(converge_history,free);
		if(maxtbl(reason_converged)>0)freetbl(reason_converged,free);
		if(maxtbl(residual)>0)freetbl(residual,free);
		destroy_data_tables(tu, ta);
		destroy_network_geometry_tables(station_table,array_table);
	}
	return(0);
}
示例#11
0
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;
}