-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb2hypoinv.pl
executable file
·169 lines (134 loc) · 5.69 KB
/
db2hypoinv.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
: # use perl
eval 'exec perl -S $0 "$@"'
if 0;
# db2hypoe
# ----------------
# This program converts arrival tables to the hypoellipse station format
# Written by Heather DeShon, 4/16/2012.
#Revised to deal with ZW4F
use lib "$ENV{ANTELOPE}/data/perl";
if ( @ARGV != 4 )
{ die ( "Usage: $0 database [output].pha julianstartdate julianenddate \n" ); }
use Datascope;
$db = $ARGV[0];
$output = $ARGV[1];
$stdate = $ARGV[2];
$enddate = $ARGV[3];
#$ndef = $ARGV[4];
#$auth = $ARGV[4]; #accepted: hwithers or all
@db = dbopen($db, "r+");
@db = dblookup(@db,"","arrival","","");
@db = dbjoin(@db, dblookup(@db, "", "assoc", "", "") );
@db = dbjoin(@db, dblookup(@db, "", "origin", "","") );
@db = dbjoin(@db, dblookup(@db, "", "event", "","") );
#@db = dbsubset(@db, "origin.orid == event.prefor");
#@db = dbsubset(@db, "origin.auth=='TX:pjdotrayMlMl'");
#@db = dbsubset(@db, "lat>=32 && lat<34 && lon>=-100 && lon<-95");
#@db = dbsubset(@db, "nassoc>=8");
@db = dbsort(@db, "origin.time", "sta", "iphase");
#@db = dbsubset(@db, "origin.time >= '$stdate' && origin.time <= '$enddate'" );
open (TMP, ">temp.hypoe") || die "Can't open tmp.file: $!" ;
open (OUTPUT, ">$output") || die "Can't open $output: $!" ;
$nrecords = dbquery(@db, "dbRECORD_COUNT" );
print "$nrecords\n";
for( $db[3] = 0; $db[3] < $nrecords ; $db[3]++ ) {
($evid, $sta, $phase, $time, $deltim, $delta, $auth, $orgtime, $lat, $lon, $depth, $mag, $timeres, $timedef,$arvauth,$chan) =
dbgetv (@db, qw(evid sta iphase time deltim delta origin.auth origin.time lat lon depth ml timeres timedef arrival.auth chan ) );
#if ($sta =~ /^S/) { $sta = "S" . $sta ; }
printf TMP (" %d %4s %1s %15.5f %8.3f %6.3f %15s %15.5f %6.4f %8.4f %8.4f %4.2f %8.4f %4s %s %s\n",
$evid, $sta, $phase, $time, $delta, $deltim, $auth, $orgtime, $lat, $lon, $depth, $mag, $timeres, $timedef, $arvauth,$chan);
}
close (TMP);
open(FILE, "temp.hypoe");
@line = <FILE>;
$k = 0;
ILOOP: for ($i = 0; $i < @line-1; $i++) {
$j = $i + 1;
chomp $line[$i];
chomp $line[$j];
$evid1 = (split /\s+/,$line[$i])[1]*1;
$evid2 = (split /\s+/,$line[$j])[1]*1;
if ($evid1 != $evid2) { $k=0; }
#print "$line[$i]\n";
($sta1,$orgtime,$lat,$lon,$depth,$mag)=(split /\s+/,$line[$i])[2,8,9,10,11,12];
($sta2,$orgtime2,$lat2,$lon2,$depth2,$mag2)=(split /\s+/,$line[$j])[2,8,9,10,11,12];
$orgyear = epoch2str($orgtime, "%Y");
$orgmon = epoch2str($orgtime, "%m");
$orgday = epoch2str($orgtime, "%d");
$orghr = epoch2str($orgtime, "%H");
$orgmin = epoch2str($orgtime, "%M");
$orgsec = epoch2str($orgtime, "%S");
$orgsec2 = epoch2str($orgtime, "%s");
$orgsec2 = substr($orgsec2,0,2);
if ($lat<0) { $NS="S"; $lat=$lat*-1; } else { $NS="N"; }
if ($lon<0) { $EW="W"; $lon=$lon*-1; } else { $EW="E"; }
($latd,$lats) = (split /\./,$lat)[0,1];
($lond,$lons) = (split /\./,$lon)[0,1];
$lats = ".".$lats; $lats = $lats * 60.0; $lats=sprintf("%4.2f",$lats); $lats=$lats*100;
$lons = ".".$lons; $lons = $lons * 60.0; $lons=sprintf("%4.2f",$lons); $lons=$lons*100;
$depth = sprintf("%3.2f",$depth); $depth=$depth*100;
if ($mag == -999.00) { $mag = 0.00;}
$mag = sprintf("%2.1f",$mag); $mag=$mag*10;
$y2k="/";
#print "$k $i $evid1 $evid2 $oldevid\n";
($phase,$arvtime,$deltime,$arvauth,$chan)=(split /\s+/,$line[$i])[3,4,6,15,16];
($phase2,$arvtime2,$deltime2,$arvauth2)=(split /\s+/,$line[$j])[3,4,6,15];
if ($arvauth =~ /:/) { $arvauth=(split /:/,$arvauth)[1]; }
if ($arvauth =~ /^dbgrassoc/) { print "$arvauth Burp!\n"; next ILOOP; } #only analyst picks
if ($evid1 == $evid2 && $k == 0) {
if ($i!=0) { print OUTPUT "\n"; }
$k++;
} elsif ( $evid1 ne $oldevid ) {
$k=1;
print OUTPUT "\n";
}
if ($phase eq "P") { $phase="Z"; }
if ($phase eq "S") { $phase="s"; }
$qual=convertqual($deltime);
$chan=substr($chan,0,2);
$ayear = epoch2str($arvtime, "%Y"); $ayear=substr($ayear,2,2);
$amon = epoch2str($arvtime, "%m");
$aday = epoch2str($arvtime, "%d");
$ahr = epoch2str($arvtime, "%H");
$amin = epoch2str($arvtime, "%M");
$asec = epoch2str($arvtime, "%S.%s");
#$asec = sprintf("%4.2f",$asec); $asec=$asec*100;
if ($phase2 eq "S") { $phase2="s"; }
$squal=convertqual($deltime2);
$shr = epoch2str($arvtime2, "%H");
$smin = epoch2str($arvtime2, "%M");
$ssec = epoch2str($arvtime2, "%S.%s");
#print "$phase $phase2 $ssec\n";
if ($shr != $ahr && $evid1 == $evid2) { next ILOOP; } #problem with hours
if ($smin >= $amin ) { $diff=($smin-$amin)*60.0; $ssec=$ssec+$diff; }
#$ssec = sprintf("%4.2f",$ssec); $ssec=$ssec*100;
#print "$diff $ssec\n";
if ($sta1 eq $sta2 && $phase eq "Z" && $phase2 eq "s" ) {
printf OUTPUT ("%-4s P %02d%02d%02d%02d%02d%05.2f %05.2f S\n", $sta1,$ayear,$amon,$aday,$ahr,$amin,$asec,$ssec);
$i=$j;
$oldevid=$evid1;
} elsif ( $sta1 ne $sta2 && $phase eq "Z") {
printf OUTPUT ("%-4s P %02d%02d%02d%02d%02d%05.2f\n",$sta1,$ayear,$amon,$aday,$ahr,$amin,$asec);
$oldevid=$evid1;
} elsif ( $sta1 ne $sta2 && $phase eq "s" ) {
printf OUTPUT ("%-4s %05.2f S\n", $sta,$ssec);
$oldevid=$evid1;
}
} # end of ILOOP loop
#print OUTPUT "C*(C) SMU catalog last accessed Nov. 2016\n 1010.00\n";
close(FILE);
close(OUTPUT);
sub convertqual {
my $deltime=@_[0];
my $qual=1;
if ( $deltime==0.010 ) {
$qual=0;
} elsif ( $deltime==0.020) {
$qual=1;
} elsif ( $deltime==0.050) {
$qual=2;
} elsif ( $deltime==0.100 ) {
$qual==3;
}
return $qual;
}