Changeset 3169
- Timestamp:
- 08/05/08 16:05:04 (5 years ago)
- File:
-
- 1 copied
-
PP/trunk/perl_utils/hypophasedump.pl (copied) (copied from PP/trunk/perl_utils/hypophasedump) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
PP/trunk/perl_utils/hypophasedump.pl
r2029 r3169 7 7 8 8 use DBI; # Load the DBI module 9 use lib "/home/tpp/bin/perlmodules";use DefNames; #dbase access info9 use strict; 10 10 11 if ($#ARGV < 0) { 12 print "Syntax: $0 [<evid>] [<dbasename>]\n";13 exit;14 } 11 # get masterdb and username/password 12 use lib "$ENV{TPP_BIN_HOME}/perlmodules"; 13 use DbConn; 14 use MasterDbs; 15 15 16 if ($#ARGV >= 1) { 17 $masterdb = $ARGV[1]; 18 } else { 19 # lookup current masterdb 20 $masterdb = `/home/tpp/bin/masterdb`; chomp $masterdb; 21 } 16 # parse optional switches (N.B. this 'shift's the @ARGV array) 17 use Getopt::Std; 18 use vars qw/ $opt_d $opt_h /; #prevent "only used once" error 22 19 23 $dbase = "dbi:Oracle:$masterdb"; 24 $evid = $ARGV[0];20 getopts('d:h'); # "d:" means a value must follow 21 if ($opt_h) {&usage(); exit;}; 25 22 26 my $dbconn = DBI->connect( $dbase, $dbusername, $dbpassword, {PrintError => 0} ) 27 or die "Can't connect to Oracle database $masterdb: $DBI::errstr\n"; 23 my $dbase = $masterdb; 24 if ($opt_d) { $dbase = $opt_d }; 25 26 if ($#ARGV == -1) {&usage(); exit;}; 27 28 my $evid = $ARGV[0]; 29 if (!($evid =~ /^\d+$/) ) { print"<id> must be a number: $evid\n"; exit; } 30 31 my $dbconn = DbConn->new($dbase)->getConn(); 28 32 29 33 # get a list of candidate phases 30 $sql = $dbconn->prepare(" Select34 my $sql = $dbconn->prepare(" Select 31 35 net, sta, seedchan, datetime, AssocArO.iphase, Arrival.subsource, 32 36 fm, quality, Arrival.rflag, qual … … 42 46 print "\n"; 43 47 44 while (@data = $sql->fetchrow_array()) { 48 my ($sec,$min,$hour,$mday,$mon,$year,$frac); 49 50 while (my @data = $sql->fetchrow_array()) { 45 51 my $net = $data[0] || ' '; 46 52 my $sta = $data[1] || ' '; … … 73 79 } 74 80 75 # Parse & compose time string 76 my $frac = ($phasetime - int($phasetime) + 0.005) *100; 77 ($sec,$min,$hour,$mday,$mon,$year) = gmtime($phasetime); 78 $timstr1 = sprintf "%4d%2.2d%2.2d%2.2d%2.2d" , $year+1900, $mon+1, $mday, $hour, $min; 79 $timstr2 = sprintf "%2.2d%2.2d" ,$sec,$frac; 81 # Parse & compose time string 82 $frac = ($phasetime - int($phasetime) + 0.005) *100; 83 ($sec,$min,$hour,$mday,$mon,$year) = gmtime($phasetime); 84 my $timstr1 = sprintf "%4d%2.2d%2.2d%2.2d%2.2d" , $year+1900, $mon+1, $mday, $hour, $min; 85 my $timstr2 = sprintf "%2.2d%2.2d" ,$sec,$frac; 86 87 my $str = sprintf ("%-5s%2s %1s%3s ",$sta, $net , substr($chan, 2,1), $chan ); 88 89 # 1 2 3 4 5 6 7 8 9 10 11 90 #12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 91 #STATNnt cCMP pr yearmodyhrmnseconPresPwtS-secSr sSrespek2pekmmSwtPdlySdlyDistAngADPerRCodaAzmDurMagPimpSimpSFX 92 #MCV NC VVHZ PU0199806262007 4310 -9110 0 0 0 0 0 0 0 0 1616400 0 159297404 0 502 0WD 93 #HMT CI VVHZ 199811102059 0 0 0 5632IS 0 -27 151 0 0 0 0 708 9000 0 0228 0 0 0 94 95 if ($phase eq "P" ) { 96 $str = $str.$eiw.$phase.$fm.$wt . $timstr1 ." " . $timstr2; 97 } else { # S-wave 98 $str = $str ." 4" . $timstr1 ." " . $timstr2 . $eiw. $phase . " " . $wt; 99 } 100 101 print "$str\n"; 80 102 81 $str = sprintf ("%-5s%2s %1s%3s ",$sta, $net , substr($chan, 2,1), $chan ); 103 } # end of while loop 82 104 83 # 1 2 3 4 5 6 7 8 9 10 11 84 #12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 85 #STATNnt cCMP pr yearmodyhrmnseconPresPwtS-secSr sSrespek2pekmmSwtPdlySdlyDistAngADPerRCodaAzmDurMagPimpSimpSFX 86 #MCV NC VVHZ PU0199806262007 4310 -9110 0 0 0 0 0 0 0 0 1616400 0 159297404 0 502 0WD 87 #HMT CI VVHZ 199811102059 0 0 0 5632IS 0 -27 151 0 0 0 0 708 9000 0 0228 0 0 0 105 # ######################################################################### 106 # Add the terminator line with ID# 107 # 108 #get the current orid 88 109 89 if ($phase eq "P" ) { 90 $str = $str.$eiw.$phase.$fm.$wt . $timstr1 ." " . $timstr2; 91 } else { # S-wave 92 $str = $str ." 4" . $timstr1 ." " . $timstr2 . $eiw. $phase . " " . $wt; 93 } 110 $sql = $dbconn->prepare( "Select 111 Event.evid, Origin.datetime, Origin.lat, Origin.lon, Origin.depth, 112 Origin.fdepth, Origin.fepi 113 from Event, Origin, NetMag 114 WHERE selectflag = 1 and 115 (Event.prefor = Origin.orid(+)) 116 and Event.evid = ? 117 "); 118 119 $sql->execute($evid); 120 121 my @data = $sql->fetchrow_array(); 122 123 my $evidx = $data[0] || 'null'; 124 my $ot = $data[1] || 0; 125 my $lat = $data[2] || 0; 126 my $lon = $data[3] || 0; 127 my $z = $data[4] || 0; 128 my $fixz = $data[5] || 'n'; # y/n or null 129 my $fixloc = $data[6] || 'n'; # y/n 130 131 # convert, parse & format the time string (doesn't use yr,mo,day) 132 $frac = ($ot - int($ot) + 0.005) *100; 133 #($sec,$min,$hour,$mday,$mon,$year) = gmtime($ot); 134 ($sec,$min,$hour) = gmtime($ot); 135 my $otstr = sprintf "%2.2d%2.2d%2.2d%2.2d" , $hour, $min ,$sec, $frac; 136 137 # convert decimal lat/lon to Hypo phase format 138 $lat = abs($lat); 139 $lon = abs($lon); 140 141 my $latdeg = int($lat); 142 my $latmin = ($lat - $latdeg+0.00005) * 6000; # * 600000 dec -> min & shift decimal 143 my $londeg = int($lon); 144 my $lonmin = ($lon - $londeg+0.00005) * 6000; 145 my $zx = ($z + 0.005) * 100; 146 147 # handle fix flags (hypo can't do fixed origin time) 148 my $fixFlag = " "; 149 if ($fixloc eq "y") { $fixFlag = "X";} 150 if ($fixz eq "y") { $zx = -$zx;} 151 152 # 1 2 3 4 5 6 7 153 #1234567890123456789012345678901234567890123456789012345678901234567890 154 # xxi2i2f4.2i2 f4.2i3 f4.2 f5.2 i10 155 #^^^^xxhrmnsecsLT minsLON minszzzzz IDnumberxx 156 # 0218152533 3050117 4512 600 9876543 157 # 2102210036 0108117 4638 1.36X 9082441 158 # 2149378533 4929117 3098 00830 10065513 159 my $str = sprintf (" %7s%2.2d %4.2d%3.3d %4.4d%5d%s %10d", 160 $otstr, $latdeg, $latmin, $londeg, $lonmin, $zx, $fixFlag, $evid); 94 161 95 162 print "$str\n"; 96 97 }98 163 99 164 ### Disconnect from the database … … 101 166 $dbconn->disconnect 102 167 or warn "Disconnection failed: $DBI::errstr\n"; 168 169 exit; 103 170 104 # 105 # Add the terminator line with ID# 106 # 107 print `/home/tpp/bin/hypoterminator ${evid} ${masterdb}`; 171 # ----------------------------------------------------------------- 172 sub usage() { 173 print <<"EOF"; 174 175 Dump event phase info in hypoinverse format. 176 177 usage: $0 -[h] [-d dbase] <evid> 178 179 -h : print usage info 180 -d dbase : use this particular dbase (defaults to "MasterDB") 181 182 example: $0 -d k2db 9277430 183 EOF 184 exit; 185 } 186
Note: See TracChangeset
for help on using the changeset viewer.
