perldb - perl interface to Datascope and related functions
The Datascope extension to perl(1) provides most of the
functionality of c.
Most of the extension routines generate a perl error
when an error occurs, rather than returning a bad-result code.
These errors can be intercepted by using the perl function eval.
When an error occurs, the returned message is the complete
contents of the error log.
Database pointers are most conveniently kept in perl arrays, though because
of the perl calling conventions, you may alternatively keep them in
a set of scalar variables.
The various predefined constants are part of
the package, but dbquery also accepts a string.
Note that dblookup recognizes dbNULL and dbSCRATCH in the
record field.
These extensions must first be loaded with a use statement:
use Datascope ;
For examples of perl scripts using the Datascope extension, please
review the scripts in $ANTELOPE/example/perl.
Following are brief descriptions of the functions implemented.
-
dbopen (database, permissions)
Returns a database pointer to the specified database.
@db = dbopen ( $database, "r+" ) ;
-
dbopen_database (database, permissions)
Returns a database pointer to the specified database, and optionally a
table; a name of "-" reads a view from stdin.
@db = dbopen_database ( "$dbname", "r+" ) ;
-
dbopen_table (database, permissions)
Returns a database pointer to the specified database table; a name
of "-" reads a view from stdin.
@db = dbopen_table ( "demo.wfdisc", "r+" ) ;
-
dbcreate (filename[, schema[, dbpath[, description[, detail]]]])
create a database descriptor file filename, with specified schema,
database path, description and detail.
dbcreate ( "example", "css3.0" ) ;
-
dbtmp (schema)
Returns a database pointer to a temporary, transient database with
the specified schema.
@db = dbtmp ( "rtexec1.0" ) ;
-
dbclose (@db)
closes the database, freeing all resources used by it.
-
dbfree (@db)
frees resources for a table or a database.
-
dblookup (@db, database, table, field, record)
Returns a database pointer for the specified database, table, field,
and record.
@db = dblookup(@db, 0, "wfdisc", 0, 0 ) ;
-
dbadd (@db, [record])
Add the new record to the table specified in @db. If no record is specified,
use the scratch record. Returns the new record number.
$dbevent[3] = dbadd(@dbevent, "**invalid event record**") ;
-
dbaddnull (@db)
Add a new null record to a table.
$new = dbaddnull(@dbevent) ;
-
dbaddv (@db, field_name, value, [field_name, value, ...])
Add a new record with the specified values to the database.
New records are checked to insure the keys are filled out and don't
conflict with other records in the table.
If the id key in a defining table (orid in the origin table, for example)
is not specified, a new id is automatically generated, using dbnextid.
$new = dbaddv(@dbevent, "evid", 1,
"evname", "fake",
"prefor", 1,
"auth", "danq") ;
Here's an example of how to catch an error when using dbaddv:
eval { $db[3] = dbaddv ( @db,
"name", $name,
"execution", $execution ) ;
} ;
if ( $@ ne "" ) {
print STDERR "$@" ;
}
Note, however, that $db[3] is not filled in when dbaddv fails.
However, an error message is left in $@ which
specifies the conflicting row.
-
dbaddchk (@db [, record])
Attempt to add the specified new record, after checking for
conflicts with other records in the table, like dbaddv.
-
dbmark (@db)
sets the specified record to all null values.
-
dbdelete (@db)
physically deletes a record from the database. This invalidates
-
dbcrunch (@db)
Deletes all marked (null) records from the specified table.
-
dbtruncate (@db, n)
Truncate a table to the specified number of records.
-
dbdestroy (@db)
Deletes all tables and the descriptor file for the specified database.
-
dbget (@db [, 0])
Returns the specified table, record, or field from the database, or
if a second argument is specified, copies the value into the scratch
record (except if a whole table is requested):
$record = dbget(@db) ;
Beware requesting a whole record from a view; the record is
actually a collection of binary database pointers. Dealing with
this is not supported.
An alternative approach might be to use dbgetv to
ask for the database pointer corresponding to one of the base tables in
the view, e.g. '$dbs = dbgetv(@dbview, "origin" )'. The returned string dbs
can be converted to a database pointer with split: "@db = split(' ', $dbs);".
-
dbgetv (@db, field_name, [field_name, ...])
Returns the values of the specified fields for a particular record:
($sta, $chan, $time ) = dbgetv(@db, qw( sta chan time ) );
For a database pointer, like bundle from dbgroup(3), use the
following syntax:
($dbbundle) = dbgetv(@db, "bundle" );
@dbbundle = split ( ' ', $dbbundle ) ;
-
dbput (@db [, string])
Saves the specified string into the specified table, record or field.
If no string is specified, the value is taken from the scratch record:
dbput(@dbevent, "This is a bad replacement record" ) ;
-
dbputv (@db, field_name, value, [field_name, value, ...])
Saves the specified values into the specified fields for a particular record.
dbputv(@dbevent, "auth", "Quinlan", "evname", "DQ") ;
-
dbadd_remark (@db, remark)
Add a comment in the remark table for the specified table/record.
dbadd_remark ( @dbevent, "This is a comment" ) ;
-
dbget_remark (@db)
Get any comment from the remark table for the specified table/record.
$return = dbget_remark ( @dbevent ) ;
-
dbgroup (@db, key, [key, ...])
returns a new view which is the input table grouped according to the specified
keys
@dbg = dbgroup ( @dbwfdisc, "sta", "chan" ) ;
-
dbjoin (@db1, @db2, [-outer | join-keys])
returns a new view which is the join of the two tables, using the
join-keys if specified.
@db1 = dbjoin ( @dbassoc, @dborigin ) ;
@db1 = dbjoin ( @db1, @dbarrival ) ;
@db1 = dbjoin ( @dbarrival, @dbsitechan,
"sta", "chan", "time#ondate::offdate" ) ;
-
dbmatches (@db1, @db2, hookname, [join-keys])
returns a list of the records in db2 which match the record specified by
db1. hookname is an arbitrary name which must uniquely specify the join.
@dborigin = dblookup (@db, "", "origin", "orid", "125" ) ;
@records = dbmatches ( @dborigin, @dbassoc, "ahook" ) ;
foreach $i ( @records ) {
$dbassoc[3] = $i ;
($arid, $phase, $delta) =
dbgetv (@dbassoc, qw(arid, phase, delta)) ;
}
-
dbnojoin (db1, db2, [join-keys])
An attempt is made to join the two tables, using the the join-keys if specified.
Any records from the first table which do not join are put into a new view,
which is returned.
@dbno = dbnojoin ( @dbassoc, @dborigin ) ;
#
-
dbprocess (@db, cmd1, cmd2, cmd3 ... )
returns a new view which is the result of applying the dbprocess
commands cmd1, cmd2, etc to the input database pointer.
@dbprocess = dbprocess ( @db, "dbopen wfdisc",
"dbjoin site",
"dbsubset distance(38,-104,lat,lon)<15") ;
all views which use this table.
-
dbseparate (@db, tablename)
returns a new view which consists of all the rows of the
specified table which participate in the joined view @db
@dbs = dbseparate ( @dbview, site ) ;
-
dbsever (@db, tablename)
returns a new view which consists of all the unique rows left
after removing the specified table from a joined view
@dbs = dbsever ( @dbview, site ) ;
-
dbsort (@db, [-u,] [-r,] [key, key..])
returns a new view which is the input table sorted according to the specified
keys, or the primary key if no keys are specified.
@dbsorted = dbsort ( @dbwfdisc, "sta", "chan", "time" ) ;
-
dbselect_hdr (@db, expr, [expr, ...])
-
dbselect (@db, expr, [expr, ...])
print header or table of values from a view
dbselect_hdr (@dbwfdisc, qw(sta chan strtime(time) nsamp)) ;
dbselect (@dbwfdisc, qw(sta chan strtime(time) nsamp)) ;
-
dbsubset (@db, expression)
returns a new view which is the set of all rows which satisfy the expression
@dbsubsetted = dbsubset ( @dbwfdisc, "sta=='AAK'" ) ;
-
dbtheta (@db1, @db2, [expression])
returns a new view which is any combination of rows from the
two tables which satisfies the expression, or all combinations
if no expression is specified.
@dbnearby = dbtheta ( @dborigin, @dbsite,
"distance(lat,lon,site.lat, site.lon) < 10." ) ;
-
dbunjoin (@db, database_name)
Creates a new database, which contains all the records referenced in the
input view. Any existing database of the same name is overwritten.
dbunjoin(@dbsubset, "copy") ;
-
dbsave_view (@db, filename)
Saves the view into the filename.
dbsave_view(@dbsubset, "asubset") ;
-
dbquery (@db, code)
Query the database for information. See dbconstants(5) for valid codes.
$nrecords = dbquery(@db, "dbRECORD_COUNT") ;
$description = dbquery(@db, dbTABLE_DESCRIPTION) ;
$detail = dbquery(@db, "dbTABLE_DETAIL") ;
@primary = dbquery(@db, dbPRIMARY_KEY);
$ntables = dbquery(@db, "dbTABLE_COUNT") ;
%defining_tables = dbquery(@db, dbLINK_FIELDS ) ;
@ids = keys %defining_tables ;
-
dbex_eval (@db, expression)
Evaluate an expression for a particular record.
$distance = dbex_eval ( @db,
"distance (lat, lon, site.lat, site.lon)" ) ;
-
dbcompile (@db, string)
Add new attributes or relations to the schema directly from the perl script.
The string must contain valid schema statements.
dbcompile(@db, "Relation test
Fields (sta chan time commid lddate)
Primary (sta chan time) ; ") ;
-
dbextfile(@db[, base-table])
return the filename for an external file for a particular record in
a view, for a particular base-table if specified.
$filename = dbextfile(@db) ;
-
dbnextid (@db, id_name)
Gets the next free id value for the specified database and id_name.
$id = dbnextid ( @db, "arid" ) ;
-
dbstrtype (@db, $string)
Try to determine the type of a string; returns
strREAL, strINTEGER, strNULL, strSTRING, strTIME, strEXPR,
strFIELD, or strUNKNOWN.
$type = dbstrtype(@db, "time+15") ;
$type = dbstrtype(@db, "NULL") ;
$type = dbstrtype(@db, "wfdisc.calib") ;
-
dbfind (@db, expression [, first [,reverse]])
Find the first record (starting with first, if specified), in
the table selected by @db which satisfies the expression. If
a fourth argument is specified search backwards.
The search begins after (and does not include) $db[3] or first.
To include record 0, set first = -1; to search backwards from
the last record, set first = nrecords.
$record = dbfind ( @db,
"distance (lat, lon, site.lat, site.lon) < 10" ) ;
-
dbinvalid ()
Returns a Dbptr with all dbINVALID values.
-
dbget_range (@dbg)
returns first and last+1 record corresponding to a row in a grouped view.
($first, $last) = dbget_range(@dbg) ;
-
dbbase (@dbv, table)
returns base table dbpointer for a record of dbv
@db = dbbase ( @dbv, "wfdisc" ) ;
-
trsample(@db, $t0, $t1, $sta, $chan[, $apply_calib])
trsample fetches waveform data from the table identified by @db
(or the wfdisc table in that database) for $sta/$chan between
$t0 and $t1. The data is returned as pairs of epoch time and
value. If $apply_calib is non-zero (and calib is non-zero),
then calib is applied to the values.
-
trloadchan(@db, $t0, $t1, $sta, $chan[, $apply_calib])
trloadchan loads data for the identified station $sta and channel $chan
between time $t0 and $t1. The data is returned as a database pointer
to a trace table. Each segment from the database occupies
a separate row in the returned table; parameter values for each
record can be obtained with standard Datascope usage, e.g. dbgetv.
If $apply_calib is non-zero (and calib is non-zero),
then calib is applied to the values.
-
trcreate($sta, $chan, $time, $nsamp, $samprate)
This will create a temporary trace database from scratch
and create a single trace table row
with station code $sta, channel code $chan, time
of first sample $time, number of samples $nsamp and
sample rate $samprate. A sample data array is allocated
and initialized with 0 values. Returns a database pointer
to the new trace table row.
-
trcopy(@trout, @trin)
returns a temporary copy of a trace database table, possible
appending to an existing table; see trcopy(3)
-
trdata(@db[, $i0[, $npts]])
To obtain the data points from a trace table record, use trdata
to request the range of values wanted. trdata returns a
corresponding list of waveform values.
-
trputdata(@db, @data)
The logical inverse of trdata; will put @data that may have
been changed back into the internal data array referenced by @db.
-
trsplit(@tr)
eliminate any marked gaps inside the trace table @tr,
by splitting segments which contain marked gaps.
-
trsplice(@tr)
glue together segments (if possible) in trace table @tr,
eliminating any overlapping segments.
-
trfilter(@tr, filter)
apply the specified filter to the traces; see trfilter(3)
-
trfree(@tr)
The memory used by the trace table is not managed by perl, and
must therefore be explicitly freed.
-
trdestroy(@tr)
same as trfree except will also remove any associated files.
-
trlookup_segtype(char)
return units and description corresponding to specified segtype char
-
elog_init ($0, @ARGV)
initialize the elog message routines
-
elog_log msg
Save a message on the elog message log.
-
elog_debug msg
Write a debug message to the elog message facility for
immediate output.
-
elog_notify msg
Send a message other than an error message to the elog
facility.
-
elog_alert msg
Write an alert message to the elog message facility for
immediate output.
-
elog_complain msg
Write an error message to the elog message facility for
immediate output.
-
elog_die msg
Write a message to the elog message facility and die.
-
elog_callback(replacement)
whenever an elog message routine (elog_log, elog_complain, etc) is called,
call the routine replacement, passing two arguments: the severity code, and a
string containing the elog log. The replacement routine returns an
integer: a non-zero return causes the error log to be cleared.
-
elog_string(first)
return the contents of the elog log starting with the message first;
the log itself is not changed.
-
elog_clear
Clear the elog message log.
-
elog_mark
return the count of messages currently held in the
error log.
-
elog_flush deliver first
Get rid of messages after #first in the error log,
printing them if deliver is a boolean true.
-
elog_query (code, severity)
code is one of
"ELOG_COUNT", "ELOG_MAXMSG", "ELOG_ARGC", "ELOG_ARGV", "ELOG_TAG", "ELOG_DELIVER", "ELOG_DEBUG", or "ELOG_SIGNALS".
severity is one of
"ELOG_DEBUGGING", ELOG_LOG", "ELOG_NOTIFY", "ELOG_ALERT" or "ELOG_DIE".
elog_query returns the current setting.
-
elog_set(code, severity, setting)
elog_set sets the corresponding setting in elog.
See the elog(3) man page for more details.
-
pfget (pfname, key)
extracts the value for the specified key from the specified parameter
file pfname. The key is actually the compound key which pfeval(3)
recognizes. This is a perl-type syntax for picking out a certain
element in a parameter file. For example, a key of
outer_array{2nd_list}[2] would return a reference to the value
Eureka if the parameter file included:
outer_array &Arr{
1st_list &Tbl{
ho
hum
}
2nd_list &Tbl{
item0
item1
Eureka
item3
}
}
In the case of nested arrays or lists, the reference returned by pfget
may be a reference to a perl array or associative array, and the elements
of these arrays might also be references to arrays or associative arrays.
$listref = pfget("above.pf", "outer_array{2nd_list}" ) ;
@list = @$listref ;
$item0 = pfget("above.pf", "outer_array{2nd_list}[0]" ) ;
-
pfget_boolean (pfname, key)
pfget_boolean returns 0 (false) if the specified key is not
found, or the corresponding value is not recognized. In the
latter case, an error message is printed. pfget_boolean calls
yesno(3) to recognize true, ok, yes, y, on, t and 1 for true;
false, no, n, 0, off and f for false.
-
pfget_size (pfname, key)
returns a number which is multiplied by a factor
defined by a trailing character. The following
characters are recognized:
G |
10^9 |
M |
10^6 |
k |
10^3 |
m |
10^-3 |
u |
10^-6 |
-
pfget_time (pfname, key)
returns an epoch time as indicated by the value in the parameter
file, which may take any of the standard str2epoch forms.
-
pfupdate (pfname)
checks and rereads a parameter file if one of the components along
PFPATH has changed. It returns 0 when no read was necessary, 1
if a read were necessary.
-
pffiles (pfname)
returns a list of filenames corresponding to pfname.
-
pf2string (pfname)
returns string representation of pf object pfname
-
pfnew (pfname)
create a new empty pf file object pfname
-
pfcompile (string, pfname)
convert the specified string into a pf object name pfname.
-
pfput (key, value, pfname)
save the specified value into the pf object with name pfname
under the specified key. The value is converted to a string if
it's a scalar; when it's a reference to a perl array or hash,
the entire perl array or hash is stored in the pf object.
-
pfwrite (filename, pfname)
write out pf object pfname to filename
-
pfrequire (pfname, atime)
require that pf_revision_time from last file pfname along PFPATH
is later than atime.
-
pfdel (pfname, key)
delete the named key from pf object pfname
-
ask (string)
-
askyn (string)
-
askynaq (string)
Pose the question string of the controlling tty, and return the
response. askyn returns only 0 (false) or true (1), and accepts only
certain kinds of answers (yes/no, true/false, ok, 0/1, .. )
askynaq allows All and Quit answers also, returning
2 and 3 for these answers, respectively.
$reply = ask ( "how high? " ) ;
-
yesno (s)
returns -1 for true, 0 for false, and 1 if the string
doesn't match any of the valid strings.
-
datapath (env, dir, file, suffix)
-
datafile (env, file)
Tries to find the specified file by looking at first the environment variable,
and then along the path. Returns path if found, undef if not found.
$schemafile = datafile ( "SCHEMADIR", "css3.0" ) ;
-
makedir(directory)
make a directory, if it doesn't already exist. (like "mkdir -p")
-
abspath (file)
returns an absolute path to the specified file.
-
relpath (from, to)
returns a relative path from from to to. Note that
from must be a directory.
-
cleanpath (path [, nolinks])
clean up the input path, removing extra "..", "//", and "./" strings.
If a second argument is specified, resolve any symbolic links along the
path, so that the result has no symbolic links.
-
concatpaths (a,b)
concatenate the two paths a and b properly, adding a slash if necessary.
-
parsepath (a)
returns directory, file basename, and suffix.
-
close_descriptors ( )
close all file descriptors after stderr; useful after fork
-
strsignal (code)
return name for signal, given the integer code
-
is_nfs (path)
returns true if path is on an nfs-mounted filesystem.
-
limit (resource, [limit2set])
limit may be used to return the current resource limit, or set a new resource
limit. The resources which may be set are:
cputime
filesize
datasize
stacksize
coredumpsize
vmemoryuse
descriptors
These correspond exactly to the limit command of tcsh(1).
limit ( coredumpsize, "unlimited" ) ;
-
grn (lat, lon)
-
srn (lat, lon)
-
grname (lat, lon)
-
srname (lat, lon)
return geographic and seismic region numbers (grn and srn) or
names (grname and srname):
$name = grname ( 38.5, -108 ) ;
-
sgsign(signer,data)
returns signature for specified signer and data.
-
sgverify(signer,data,signature)
returns zero if signature is correct for signer and data.
-
units_convert(input,want)
given an input string containing a value and units,
and a second string specifying the desired output units,
returns the corresponding value and output units.
units_convert returns undef if the input or output units
are not recognized.
($value, $units) = units_convert("3.15 gauss", "tesla") ;
-
units_match(xunit)
returns a list of all units which have the same dimensions as xunit.
@matches = units_match("tesla") ;
-
$errno = errno()
returns system errno, resetting errno to zero
-
($ok, $restriction) = legit_ip(pf,ip)
returns 1 if ip address is acceptable in valid_ip_addresses table in pf.
Also returns any accompanying restriction string as a second result.
-
($red, $green, $blue) = hls2rgb(hue, lightness, saturation)
-
($hue, $lightness, $saturation) = rgb2hls(red, green, blue)
Converts between the hls and rgb color models. All parameters are scaled
between 0 and 1 except hue, which varies from 0 to 360 (degrees).
-
now()
return current time to (usually) higher accuracy: microseconds.
-
is_epoch_string(string)
is_epoch_string returns undef and an error message if the input
string seems invalid; otherwise it returns the epoch time.
-
epoch2str (epoch, fmt)
-
epoch2str (epoch, fmt, timezone)
returns the epoch time formatted according to the fmt string; see
epoch2str(3) for details. If the timezone spec is an empty string,
the local timezone is used. If the timezone is omitted, UTC is used.
print epoch2str($time, "%A %B %d, %Y %T%n", "" ) ;
-
str2epoch (string)
Returns the epoch time corresponding to the free-form input time/date.
$time = str2epoch ( "July 20, 1992 18:30" ) ;
str2epoch fails if the input does not appear to be valid.
-
strtime (epoch)
Returns a formatted string of the time and date.
-
strydtime (epoch)
Returns a formatted string of the time and date, including the day of year.
-
strdate (epoch)
Returns a formatted string of the date.
-
strtdelta (epoch)
Returns a formatted string of the specified time interpreted as a time difference, e.g. 2.5 days
printf "Time difference is %s\n", strtdelta($t2-$t1) ;
-
strlocaltime (epoch)
Returns a formatted string of the local time and date.
-
strlocaldate (epoch)
Convert epoch time to date, eg "4/23/2007" in local timezone.
-
strlocalydtime (epoch)
Returns a formatted string of the local time and date, including the day of year.
-
epoch (yearday)
Returns the epoch time corresponding to the integer yearday (eg, 1994305).
$time = epoch ( 1995067 ) ;
-
yearday (epoch)
Returns the yearday corresponding to an epoch time.
$jdate = yearday ( 794705400.0 ) ;
-
wait_for_time(time,verbose)
wait for a particular time
-
exhume(filename,reference,seconds)
Like the c-version exhume(3), specify the filename of the
state file, a reference to a variable to be set in case of some interrupt,
and the number of seconds to wait following the interrupt
for the program to terminate; if not ended by that time,
terminate with extreme prejudice.
exhume("state/my-state", \$stop, 15) ;
-
resurrect(name, ref[, TIME_RELIC])
Specify names and references to corresponding perl variables to save
in state file. Optionally specify the type, normally only useful for
variables containing epoch times.
if ( resurrect("integer", \$integer) == 0 ) {
print STDERR "resurrected integer=$integer\n" ;
}
if ( resurrect("atime", \$atime, TIME_RELIC) == 0 ) {
print STDERR "resurrected atime=$atime\n" ;
}
-
bury()
Save the state file.
These routines use the snetsta, anetsta, schanloc and achanaux tables
and the foreign(3) key routines to map between CSS3.0 station/channel
naming conventions and the different conventions of autodrm and SEED.
-
$sta = map_autodrm_netsta(anet, fsta)
-
$chan = map_autodrm_chanaux(sta,fchan,aux)
-
($anet, $fsta) = autodrm_net(sta)
-
($fchan, $aux) = autodrm_aux(sta, chan)
-
$sta = map_seed_netsta(anet, fsta)
-
$chan = map_seed_chanloc(sta,fchan,loc)
-
($snet, $fsta) = seed_net(sta)
-
($fchan, $loc) = seed_loc(sta,chan)
-
finit_db(@db)
This routine sets the database used
by the foreign keys routines above to find the relevant tables.
If not set, the routines look for a database named foreignkeys.
These simple ring buffers hold only an ordered list of time/value double floating
point pairs, as described in ring(3).
A ring buffer is opened (or created if it doesn't already exist) by
openring or created by newring, which take the arguments below.
An existing ring buffer is overwritten (the old values are lost)
by a call to newring.
-
filename
The data for the ring buffer is kept in this memory mapped
file. The file is locked as well as mapped, so it must be
present on a local (not nfs) file system.
-
id
a RB_IDSZ (64 byte) memory field, completely at the user's disposal
This 64 byte field is read from when a new ring buffer is created,
and written to at every open.
-
depth
the maximum number of time/value pairs held by the ring buffer
-
flags
If bit 0 is set, the ring buffer is opened read only and is not locked.
An open ring buffer is closed with closering.
newring ($filename, $id, $depth, $flags ) ;
$rb = openring($filename, $id, $depth, $flags ) ;
closering($rb) ;
time/value pairs are added to a ring buffer with pushring. This routine
reorders the list (if necessary) to keep it in time order.
cramring adds time/value pairs to the ring, but according to some algorithm (the fourth parameter).
The collapse algorithm only inserts a new value when it's different from the previous value (except
that the second pair entered is always inserted into the ring). Pairs are NOT reordered; a pair with
a time previous to the latest entry in the ring is silently discarded.
countring returns the number of time/value pairs currently in the ring buffer.
tallyring returns the number of time/value pairs within tdelta seconds before the latest pair currently in the ring buffer.
getring returns the i'th time/value pair from the ring buffer, where i=0
gets the most recent time, and countring(rb)-1 returns the oldest time.
pushring($rb, $time, $value) ;
cramring($rb, $time, $value, "collapse") ;
($latest_time, $latest_value) = getring($rb, 0) ;
($oldest_time, $oldest_value) = getring($rb, countring($rb)-1) ;
minring, maxring, avgring and changedring
take two arguments -- the
ring buffer and number of seconds before latest ring buffer entry -- and
return the minimum, maximum, and average value
for the time period from time(i=0) to time(i=0)-tdelta;
minring and maxring
also return the index corresponding
to the minimum and maximum value.
changedring returns one if consecutive values in
the ring buffer have changed over the past tdelta seconds.
findring searches the ring buffer over the specified time period for
a specific value.
($minvalue, $jmin) = minring($rb, $tdelta) ;
($maxvalue, $jmax) = maxring($rb, $tdelta) ;
$avgvalue = avgring($rb, $tdelta) ;
if ( &changedring($rb, 10.0) ) {
&send_warning() ;
}
$index = &findring($rb, $value, $tdelta) ;
if ( $index < 0 ) {
print STDERR "*not found*\n" ;
} else {
print STDERR "$value found at index $index\n" ;
}
meanring calculates the mean and standard deviation for time/value pairs within tdelta of the latest entry.
linearfitring returns the linear least square best fit line which matches the pairs within tdelta of the
latest entry.
($npts, $mean, $stddev) = meanring($rb, $tdelta) ;
($npts, $slope, $y0, $correlation) = linearfitring($rb, $tdelta) ;
-
r3mag(@x)
returns the magnitude of a 3-vector.
-
r3dot(@x,@y)
returns the dot product of two 3-vectors @x and @y
-
r3norm
returns the normalized 3-vector corresponding to the input 3-vector
-
r3cross(@x,@y)
returns the cross product of two 3-vectors.
-
r3orthonormal(@x,@y)
returns the unit vector perpendicular to @x in the direction of @y.
-
deg(radians)
-
rad(degrees)
conversions between degrees and radians.
-
dist(lat1,lon1,lat2,lon2)
returns distance and azimuth (in degrees) from lat1,lon1 to lat2,lon2
-
latlon(lat1,lon1,delta,azimuth)
returns latitude and longitude for the point distance and azimuth degrees from lat1,lon1
-
rotation(@axis,$theta)
returns a 3x3 rotation matrix which rotates a vector theta radians about the axis
-
rotate(@axis,@vector,$theta)
returns the vector rotated about the axis by theta radians.
dbopen, dbopen_table, dbopen_database, dblookup, dbjoin, dbtheta, dbsubset, dbsort, and
dbgroup
all return database pointers.
dbget returns a single field, record, or table.
dbgetv returns a list of all the field values requested; when a dbptr is
the requested field, it is returned as a single string which must be split
into the various components, e.g.:
@db = split ( ' ', $dbptr ) ;
dbput, dbputv, dbsave_view, dbunjoin, dbcompile, dbadd_remark, dbmark,
dbclose, dbdelete, dbfree, dbtruncate, dbcrunch, dbdestroy, and limit
have no return value.
dbadd, dbaddchk, dbaddnull and dbaddv return the record number of the add record.
dbex_eval returns the value of the expression.
dbfind returns a record number, or -1 if no matching record was found.
dbextfile returns the name of the external file.
dbget_remark returns the requested comment from the remark table.
dbquery returns the requested value.
Usually this is a scalar, but in
the case of dbSCHEMA_FIELDS, dbFIELD_TABLES,
dbVIEW_TABLES, dbSCHEMA_TABLES, dbTABLE_FIELDS, dbPRIMARY_KEY,
dbALTERNATE_KEY, and dbFOREIGN_KEYS, a list is returned.
dbquery of
dbFIELD_TYPE returns the string dbINTEGER, dbREAL, dbTIME,
dbDATE, dbYEARDAY, dbSTRING, or dbDBPTR.
dbquery of dbLINK_FIELDS returns an array.
dbnojoin and dbmatches return a list of record numbers.
dbnextid returns the integer next id.
elog_mark returns an integer
epoch and str2epoch return a real time.
yearday returns an integer = year * 1000 + day of year.
epoch2str, strtime, strdate, strydtime and strtdelta return a formatted
string representing a time.
datapath and datafile return file names, or undef if no matching file
is found.
grn and srn return integers; grname and srname return strings.
askyn returns either 0 (no) or 1 (yes).
askynaq returns 2 (all) or 3 (quit) in addition to 0 and 1.
ask returns the reply string.
pfget returns either a string, or a reference to a list or a reference
to an array.
dbconstants(5)
dbintro(3)
dbschema(5)
When an error occurs during the execution of one of these calls,
the routine does not return normally, usually causing the script
to abort. You must wrap a call inside an eval statement if you wish
to continue a script under these conditions.
When referring to the (more detailed) c documentation for these routines,
be sure to look at the man pages in section 3, rather than the man pages
in section 1. dbdelete(3) (as implemented here)
deletes one record at a time, whereas dbdelete(1) takes as input a view
and deletes every record in the view.
Needs better method of getting the Datascope #defined codes.
(dbREAL, dbNULL, dbRECORD_COUNT, etcetera).
Daniel Quinlan
Table of Contents
Antelope Release 5.0-64 SunOS 5.10 2010-11-11
Boulder Real Time Technologies, Inc
For more information, contact support@brtt.com