Skip to content

Commit e015bac

Browse files
Remove IRIS web service, replace with ISC and option for USGS
1 parent b646297 commit e015bac

File tree

1 file changed

+78
-30
lines changed

1 file changed

+78
-30
lines changed

FetchEvent

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# Find the most current version at http://service.iris.edu/clients/
66
#
77
# Fetch event parameters from web services. The default web service
8-
# are from the IRIS DMC, other FDSN web services may be specified by
9-
# setting the following environment variables:
8+
# is from the International Seismological Centre (ISC), other FDSN web
9+
# service implementations may be specified by setting the following
10+
# environment variables:
1011
#
11-
# SERVICEBASE = the base URI of the service(s) to use (http://service.iris.edu/)
12-
# EVENTWS = complete URI of service (http://service.iris.edu/fdsnws/event/1)
12+
# SERVICEBASE = the base URI of the service(s) to use (https://www.isc.ac.uk/)
13+
# EVENTWS = complete URI of service (https://www.isc.ac.uk/fdsnws/event/1)
1314
#
1415
# Dependencies: This script should run without problems on Perl
1516
# release 5.10 or newer, older versions of Perl might require the
@@ -148,7 +149,15 @@
148149
# 2014.340
149150
# - Fix parsing/conversion of depth value if data is separated by XML parser.
150151
#
151-
# Author: Chad Trabant, IRIS Data Management Center
152+
# 2024.113
153+
# - Set PERL_LWP_SSL_VERIFY_HOSTNAME to 0 to allow encrypted connections without
154+
# checking for valid certificate matching the expected hostname.
155+
# - Change the default event source to the ISC fdsnws-event service.
156+
# - Add support for the USGS FDSN fdsnws-event service.
157+
# - Allow -e end time specification to be an offset relative to the
158+
# start time in the pattern #.#[SMHD], e.g. 30m, 1h, 2D, etc.
159+
#
160+
# Author: Chad Trabant, EarthScope Data Services
152161

153162
use strict;
154163
use File::Basename;
@@ -159,12 +168,12 @@ use HTTP::Status qw(status_message);
159168
use HTTP::Date;
160169
use Time::HiRes;
161170

162-
my $version = "2014.340";
171+
my $version = "2024.113";
163172

164173
my $scriptname = basename($0);
165174

166175
# Default web service base
167-
my $servicebase = 'http://service.iris.edu';
176+
my $servicebase = 'https://www.isc.ac.uk';
168177

169178
# Check for environment variable overrides for servicebase
170179
$servicebase = $ENV{'SERVICEBASE'} if ( exists $ENV{'SERVICEBASE'} );
@@ -175,9 +184,15 @@ my $eventservice = "$servicebase/fdsnws/event/1";
175184
# Check for environment variable override for timeseriesservice
176185
$eventservice = $ENV{'EVENTWS'} if ( exists $ENV{'EVENTWS'} );
177186

187+
my $usgs_eventservice = "https://earthquake.usgs.gov/fdsnws/event/1";
188+
178189
# HTTP UserAgent reported to web services
179190
my $useragent = "$scriptname/$version Perl/$] " . new LWP::UserAgent->_agent;
180191

192+
# Allow encrypted connections without checking for valid certificate matching
193+
# the expected hostname.
194+
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
195+
181196
my $usage = undef;
182197
my $verbose = undef;
183198
my $nobsprint = undef;
@@ -226,36 +241,37 @@ Getopt::Long::Configure ("bundling_override");
226241
my $getoptsret = GetOptions ( 'help|usage|h' => \$usage,
227242
'verbose|v+' => \$verbose,
228243
'nobs' => \$nobsprint,
229-
'starttime|s=s' => \$starttime,
230-
'endtime|e=s' => \$endtime,
231-
'lat=s' => \@latrange,
244+
'starttime|s=s' => \$starttime,
245+
'endtime|e=s' => \$endtime,
246+
'lat=s' => \@latrange,
232247
'lon=s' => \@lonrange,
233248
'radius=s' => \@degrange,
234-
'depth=s' => \@deprange,
235-
'mag=s' => \@magrange,
236-
'magtype=s' => \$magtype,
249+
'depth=s' => \@deprange,
250+
'mag=s' => \@magrange,
251+
'magtype=s' => \$magtype,
237252
'catalog|cat=s' => \$catalog,
238253
'contributor|con=s' => \$contributor,
239-
'updatedafter|ua=s' => \$updatedafter,
254+
'updatedafter|ua=s' => \$updatedafter,
240255
'altform' => \$altform,
241-
'limit=s' => \@limitrange,
256+
'limit=s' => \@limitrange,
242257
'allorigins' => \$allorigins,
243258
'allmags' => \$allmags,
244-
'orderbymag' => \$orderbymag,
259+
'orderbymag' => \$orderbymag,
245260

246-
'eventid|evid=s' => \$eventid,
247-
'originid|orid=s' => \$originid,
261+
'eventid|evid=s' => \$eventid,
262+
'originid|orid=s' => \$originid,
248263

249-
'appname|A=s' => \$appname,
250-
'auth|a=s' => \$auth,
251-
'outfile|o=s' => \$outfile,
252-
'xmlfile|X=s' => \$xmlfile,
253-
'eventws=s' => \$eventservice,
254-
);
264+
'appname|A=s' => \$appname,
265+
'auth|a=s' => \$auth,
266+
'outfile|o=s' => \$outfile,
267+
'xmlfile|X=s' => \$xmlfile,
268+
'eventws=s' => \$eventservice,
269+
'usgs|U' => sub { $eventservice = $usgs_eventservice; },
270+
);
255271

256272
my $required = ( defined $starttime || defined $endtime ||
257273
scalar @latrange || scalar @lonrange || scalar @degrange ||
258-
scalar @deprange || scalar @magrange ||
274+
scalar @deprange || scalar @magrange ||
259275
defined $catalog || defined $contributor ||
260276
defined $eventid || defined $originid );
261277

@@ -265,9 +281,10 @@ if ( ! $getoptsret || $usage || ! $required ) {
265281
print "Usage: $scriptname [options]\n\n";
266282
print " Options:\n";
267283
print " -v More verbosity, may be specified multiple times (-vv, -vvv)\n";
284+
print " -usgs or -U Use the USGS FDSN event service instead of the default ISC service\n";
268285
print "\n";
269286
print " -s starttime Limit to origins after time (YYYY-MM-DD,HH:MM:SS.sss)\n";
270-
print " -e endtime Limit to origins before time (YYYY-MM-DD,HH:MM:SS.sss)\n";
287+
print " -e endtime Limit to origins before time (YYYY-MM-DD,HH:MM:SS.sss or or #[SMHD])\n";
271288
print " --lat min:max Specify a minimum and/or maximum latitude range\n";
272289
print " --lon min:max Specify a minimum and/or maximum longitude range\n";
273290
print " --radius lat:lon:maxradius[:minradius]\n";
@@ -309,10 +326,44 @@ if ( $starttime ) {
309326
$starttime .= ".$subsec" if ( $subsec );
310327
}
311328

312-
if ( $endtime ) {
329+
if ( $endtime )
330+
{
331+
# Check for and parse time in duration pattern: #.#[SMHD]
332+
if ( $endtime =~ /^[\d\.]+[SsMmHhDd]?$/ ) {
333+
if ( $starttime ) {
334+
my ($offset, $timeunit) = $endtime =~ /^([\d\.]+)([SsMmHhDd]?)$/i;
335+
$timeunit = 'S' if (! $timeunit);
336+
337+
# Convert offset value to seconds if specified as days, hours or minutes
338+
if ($timeunit =~ /[Dd]/) {
339+
$offset *= 86400;
340+
}
341+
elsif ($timeunit =~ /[Hh]/) {
342+
$offset *= 3600;
343+
}
344+
elsif ($timeunit =~ /[Mm]/) {
345+
$offset *= 60;
346+
}
347+
348+
# Calculate end time from start + offset and generate string
349+
my $rstartepoch = str2time ($starttime, "UTC");
350+
if ( defined $rstartepoch ) {
351+
my ($sec,$min,$hour,$mday,$mon,$year) = gmtime($rstartepoch + $offset);
352+
$endtime = sprintf ("%04d-%02d-%02dT%02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
353+
}
354+
else {
355+
die "Unable to parse start time: '$starttime'\n"
356+
}
357+
}
358+
else {
359+
die "Cannot specify end time as duration without specifying start time\n";
360+
}
361+
}
362+
else {
313363
my ($year,$month,$mday,$hour,$min,$sec,$subsec) = split (/[-:,.\s\/T]/, $endtime);
314364
$endtime = sprintf ("%04d-%02d-%02dT%02d:%02d:%02d", $year, $month, $mday, $hour, $min, $sec);
315365
$endtime .= ".$subsec" if ( $subsec );
366+
}
316367
}
317368

318369
if ( $updatedafter ) {
@@ -561,9 +612,6 @@ sub decimalposition { # decimalposition (value, position)
561612
# value is generally better for printing and is normally usable as the
562613
# value of the eventid service parameter.
563614
#
564-
# An IRIS example for <event publicID= >:
565-
# smi:service.iris.edu/fdsnws/event/1/query?eventid=3954686
566-
#
567615
# An NEIC example for <event publicID= >:
568616
# quakeml://comcat.cr.usgs.gov/fdsnws/event/1/query?eventid=pde20100115001825990_25&amp;format=quakeml
569617
#

0 commit comments

Comments
 (0)