Changeset 3169


Ignore:
Timestamp:
08/05/08 16:05:04 (5 years ago)
Author:
given
Message:

First checkin of hypophasedump

File:
1 copied

Legend:

Unmodified
Added
Removed
  • PP/trunk/perl_utils/hypophasedump.pl

    r2029 r3169  
    77 
    88use DBI;            # Load the DBI module 
    9 use lib "/home/tpp/bin/perlmodules";use DefNames;   #dbase access info 
     9use strict; 
    1010 
    11   if ($#ARGV < 0) { 
    12    print "Syntax: $0 [<evid>] [<dbasename>]\n"; 
    13    exit; 
    14   } 
     11# get masterdb and username/password 
     12use lib "$ENV{TPP_BIN_HOME}/perlmodules"; 
     13use DbConn; 
     14use MasterDbs; 
    1515 
    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)  
     17use Getopt::Std; 
     18use vars qw/ $opt_d $opt_h /;  #prevent "only used once" error 
    2219 
    23 $dbase = "dbi:Oracle:$masterdb"; 
    24 $evid  = $ARGV[0]; 
     20getopts('d:h');  # "d:" means a value must follow 
     21if ($opt_h) {&usage(); exit;}; 
    2522 
    26   my $dbconn = DBI->connect( $dbase, $dbusername, $dbpassword, {PrintError => 0}  ) 
    27          or die "Can't connect to Oracle database $masterdb: $DBI::errstr\n"; 
     23my $dbase = $masterdb; 
     24if ($opt_d) { $dbase = $opt_d };   
     25 
     26if ($#ARGV == -1) {&usage(); exit;}; 
     27 
     28my $evid = $ARGV[0]; 
     29if (!($evid =~ /^\d+$/) ) { print"<id> must be a number: $evid\n"; exit; }  
     30 
     31my $dbconn = DbConn->new($dbase)->getConn(); 
    2832 
    2933# get a list of candidate phases 
    30     $sql = $dbconn->prepare(" Select  
     34    my $sql = $dbconn->prepare(" Select  
    3135        net, sta, seedchan, datetime, AssocArO.iphase, Arrival.subsource,  
    3236        fm, quality, Arrival.rflag, qual 
     
    4246print "\n"; 
    4347 
    44 while (@data = $sql->fetchrow_array()) { 
     48my ($sec,$min,$hour,$mday,$mon,$year,$frac); 
     49 
     50while (my @data = $sql->fetchrow_array()) { 
    4551    my $net       = $data[0] || ' '; 
    4652    my $sta       = $data[1] || ' '; 
     
    7379    } 
    7480 
    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"; 
    80102 
    81 $str = sprintf ("%-5s%2s %1s%3s ",$sta, $net , substr($chan, 2,1), $chan ); 
     103} # end of while loop 
    82104 
    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 
    88109 
    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); 
     135my $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 
     141my $latdeg = int($lat); 
     142my $latmin = ($lat - $latdeg+0.00005) * 6000;    # * 600000 dec -> min & shift decimal 
     143my $londeg = int($lon); 
     144my $lonmin = ($lon - $londeg+0.00005) * 6000;  
     145my $zx = ($z + 0.005) * 100; 
     146 
     147# handle fix flags (hypo can't do fixed origin time) 
     148my $fixFlag = " "; 
     149if ($fixloc eq "y") { $fixFlag = "X";} 
     150if ($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 
     159my $str = sprintf ("      %7s%2.2d %4.2d%3.3d %4.4d%5d%s                         %10d",  
     160          $otstr, $latdeg, $latmin,  $londeg, $lonmin, $zx, $fixFlag, $evid); 
    94161 
    95162print "$str\n"; 
    96  
    97 } 
    98163 
    99164### Disconnect from the database 
     
    101166$dbconn->disconnect 
    102167  or warn "Disconnection failed: $DBI::errstr\n"; 
     168   
     169exit; 
    103170 
    104 # 
    105 # Add the terminator line with ID# 
    106 #                             
    107 print `/home/tpp/bin/hypoterminator ${evid} ${masterdb}`; 
     171# ----------------------------------------------------------------- 
     172sub usage() { 
     173print <<"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 
     183EOF 
     184exit; 
     185} 
     186 
Note: See TracChangeset for help on using the changeset viewer.