-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputANSS2db.pl
More file actions
executable file
·69 lines (53 loc) · 1.94 KB
/
inputANSS2db.pl
File metadata and controls
executable file
·69 lines (53 loc) · 1.94 KB
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
#! /usr/bin/env perl
#
# inputANSS2db.pl locfile cat_db
# -by Mark 2012
# takes line catalog info from ANSS easy catalog results
# and writes to origin, origerr and event tables
# in a Datascope database
# NOTE should implement the CNSS standard raw format but for
# now this will work perfectly...
use lib "$ENV{ANTELOPE}/data/perl/";
use Datascope;
#-- Check for valid inputs
$help = <<"EOF";
Usage: anss2db [file] out_db
file - ANSS screen search format
out_db - database to write origins
EOF
if (@ARGV < 1 || $ARGV[0] =~ m/-h/) { $flag = print "$help"; }
MAIN: { last MAIN if $flag;
#-- Command line args --#
$infile = $ARGV[0];
$cat_db = $ARGV[1];
#-- set parameters
open(FILEIN, "<" , $infile) or die "Can't open $infile: $!";
@db = dbopen("$cat_db", "r+");
@dborg = dblookup(@db, "" , "origin" , "", "" );
@dberr = dblookup(@db, "" , "origerr" , "", "" );
@dbevt = dblookup(@db, "" , "event" , "" , "" );
# punt the first two header lines...
<FILEIN>;
<FILEIN>;
while (<FILEIN>) {
chomp;
($date1,$time1,$lat,$lon,$dep,$mag,$mtype,$nsta,$gap,$closest,$rms,$src,$id) = split(" ",$_);
$date1 =~ s/\//\-/g;
$time = str2epoch("$date1 $time1");
# unecessary in this case, but usually a good idea, Antelope only takes 4 places
$lat = sprintf('%2.4f',$lat);
$lon = sprintf('%3.4f',$lon);
#-- Add records to origin, origerr, event tables
$orid = dbnextid(@db,"orid");
$dborg[3] = dbaddv(@dborg,"orid",$orid,"time",$time,"lat",$lat,"lon",$lon,"depth",$dep,"ml",$mag,"nass",$nsta,"ndef",$nsta,"auth",$src);
#$orid = dbgetv(@dborg,"orid");
# no error info for this format, so... stub it out
# for origerr table, only 'orid' is in the primary key (!), so have to kick a NULL check out
# to the calling code when pulling out error info... sorry Future Mark.
dbaddv(@dberr,"orid",$orid,"sdobs",$rms);
dbaddv(@dbevt,"prefor",$orid);
print "Added $date1 $time1 <$lat, $lon> M $mag to $cat_db\n";
}
dbclose(@db);
close(FILEIN);
}