-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb2hypoDDphase.pl
executable file
·120 lines (104 loc) · 3.86 KB
/
db2hypoDDphase.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /usr/bin/env perl
#-----------------------
# db_mkHypoDD.pl -MCW
# Antelope database perl script
#
# Produces a "phase.dat"-style pickfile for hypoDD
# from an Antelope CSS 3.0 database
#
# you must have perl package "Datascope.pm"
# the "use lib" line points to where antelope keeps it
#
# USAGE: db_mkHypoDD.pl my_database
# Database must contain 'origin', 'assoc', and 'arrival' tables
# OUTPUT: file "hdd_picks.dat"
use lib "$ENV{ANTELOPE}/data/perl/";
use Datascope;
if ( @ARGV < 1 )
{ die ( "Usage: $0 database [outputfile] [start] [enddate]" );
}
$outfile = hypoddpicks.pha;
$stdate= "1980-220" ; $enddate= "2099-300" ;
if ( $ARGV[1] ){ $outfile = $ARGV[1]; }
if ( $ARGV[2] ){ $stdate = $ARGV[2]; }
if ( $ARGV[3] ){ $enddate = $ARGV[3]; }
$dbname = $ARGV[0];
#$outfile = "hdd_picks.dat";
open(FILEOUT, ">" , $outfile) or die "Can't open $outfile: $!";
print "Reading database: $dbname\n";
@db = dbopen("$dbname", "r");
@dbo = dblookup(@db, "" , "origin" , "", "" );
@dbo = dbsubset(@dbo, "origin.time >= '$stdate' && origin.time <= '$enddate'");
#@dbo = dbsubset(@dbo, "origin.nass >= 10 ");
#@dbo = dbsubset(@dbo, "origin.lat >= 32 ");
#@dbo = dbsubset(@dbo, "origin.lat <= 33 ");
#@dbo = dbsubset(@dbo, "origin.lon <= -93 ");
#@dbo = dbsubset(@dbo, "origin.lon >= -94 ");
@dbe = @dbo;
$nrecords = dbquery(@dbo, "dbRECORD_COUNT");
$err = 0.000;
$rms = 0.00;
$dbtimeprev=0;
for ( $dbe[3] = 0; $dbe[3] < $nrecords; $dbe[3]++ ) {
#if ($auth =~ /^TX:/) {
($olat,$olon,$otime,$odepth,$omag,$orid,$auth) = dbgetv(@dbe,qw(lat lon time depth ml orid auth));
#$erra = dbgetv(@dbe,qw(smajax));
#$errb = dbgetv(@dbe,qw(sminax));
#$err1 = ($erra+$errb)/2;
#$err2 = dbgetv(@dbe,qw(sdepth));
#$rms = dbgetv(@dbe,qw(sdobs));
if ($omag == -999.00) {
$omag = -2;
}
$odatetime = epoch2str($otime,'%Y %m %d %H %M %S.%s');
$ostrtime = strtime($otime);
#print FILEOUT "# $odatetime $olat $olon $odepth $omag $err $err $rms $orid\n";
$oyear =sprintf("%02d",epoch2str($otime,"%Y"));
$omonth = epoch2str($otime,"%m");
$oday = epoch2str($otime,"%d");
$ohour = epoch2str($otime,"%H");
$omin = epoch2str($otime,"%M");
$osec = epoch2str($otime,"%S");
# #$osecbrief = sprintf("%02d",$osec);
$oall1 = $omin*60;
$oall = $oall1 + $osec;
#
@db = dbsubset(@dbo,"orid==$orid");
@db = dbjoin(@db, dblookup(@db, "", "assoc", "" ,""));
@db = dbjoin(@db, dblookup(@db, "", "arrival", "", ""));
$nassoc = dbquery(@db, "dbRECORD_COUNT");
#$diffsec = $oall-$dbtimeprev;
#$dbtimeprev=$oall;
#$timewindow1 = $otime - 100;
#$timewindow2 = $otime + 100;
#@dba = dbsubset(@dbo, "origin.time >= $timewindow1 && origin.time <= $timewindow2");
#$nevents1 = dbquery(@dba, "dbRECORD_COUNT");
#print "number of events around here is $nevents1 $timewindow1 $timewindow2 $auth\n";
#if ($auth =~ /^TX:/) {
#if ($nevents1 < 5) {
#if (abs($diffsec) > 100) { # 10 seconds differential
print FILEOUT "# $odatetime $olat $olon $odepth $omag $err $err $rms $orid\n";
print "YESSSSS\n";
for ( $db[3] = 0; $db[3] < $nassoc; $db[3]++ ) {
($sta, $arrtime, $deltim, $iphase) = dbgetv(@db, qw(sta arrival.time deltim iphase));
$travtim = $arrtime-$otime;
print "$travtim this is the travel time\n";
$phase = substr($iphase,0,1);
$weight = $deltim;
SWITCH: {
if ($weight <= 0.05) { $weight = 1.00; last SWITCH;}
if ($weight <= 0.1) { $weight = 0.50; last SWITCH;}
if ($weight <= 0.2) { $weight = 0.25; last SWITCH;}
if ($weight <= 0.4) { $weight = 0.12; last SWITCH;}
else { $weight = 0.00; last SWITCH;}
} #switch
if ($phase =~ m/P/) {
printf FILEOUT "$sta %2.3f $weight $phase\n" ,$travtim;}
elsif ($phase =~ m/S/) {
printf FILEOUT "$sta %2.3f $weight $phase\n" ,$travtim;}
}#for
#}#if
# }#if
# }#if
}#for
print "Wrote hypoDD pickfile: $outfile\n"