The next three functions convert between "standard time format"
strings and times in units of sample intervals. Normally they should be
invoked after isigopen
, dbinit
, or sampfreq
, any of
which will determine the duration of a sample interval and the base time
from a `header' file, or after defining these quantities using
setsampfreq
and setbasetime
. If this is not done, or if
these time-conversion functions are used after dbquit
, they will
perform conversions in units of seconds (i.e., the sample interval is
taken to be one second in such cases).
char *timstr(DB_Time t) char *mstimstr(DB_Time t)
Return:
These functions convert times or time intervals into null-terminated
ASCII strings. If the argument, t, is greater than zero, it is
treated as a time interval, and converted directly into HH:MM:SS
format by timstr
, or to HH:MM:SS.SSS format by
mstimstr
, with leading zero digits and colons suppressed. If
t is zero or negative, it is taken to represent negated elapsed
time from the beginning of the record, and it is converted to a time of
day using the base time for the record as indicated by the `header'
file or the caller
(see section setbasetime);
in this case, if the base time is defined, the string will contain all
digits even if there are leading zeroes, it will include the date if a
base date is defined, and it will be marked as a time of day by being
bracketed (e.g., `[08:45:00 23/04/1989]'). The result of the
conversion is truncated to a multiple of a second by timstr
, or
to a multiple of a millisecond by mstimstr
. Note in each case
that the returned pointer addresses static data (shared by timstr
and mstimstr
), the contents of which are overwritten by
subsequent calls. See section Example 3: An Annotation Printer, for an illustration of the use of
mstimstr
; also see section Example 5: Reading Signal Specifications, for an example of the use of
timstr
.
DB_Time strtim(char *string)
Return:
This function converts an ASCII string in standard time format to a time in units of sample intervals. Examples of standard time format:
2:14.875
[13:6:0]
[8:0:0 1]
[12:0:0 1/3/1992]
143
4:02:01
s12345
c350.5
e
i
o
If the argument is bracketed (as in the second, third, and fourth examples), it
is taken as a time of day, and strtim
uses the base time defined
by the `header' file or by the caller
(see section setbasetime);
in this case, the value returned is zero or negative (and can be
converted into elapsed time from the beginning of the record by simply
negating it). If the argument is not bracketed, it is taken as a time
interval, and converted directly into a positive number of sample
intervals. These notations match those used by timstr
and
mstimstr
, which are (approximately) inverse functions of
strtim
; in fact, for MIT DB and AHA DB records (and any others
with sampling frequencies below 1 KHz), strtim(mstimstr(t))
= t, for any t. The `s'-format (as in the seventh
example above) is provided to allow "conversion" of time intervals
already expressed in sample intervals. The similar `c'-format
converts counter values
(see section getcfreq)
into sample intervals. The length of the record in
sample intervals can be obtained using strtim("e")
, which
evaluates to zero if this quantity is undefined. The sample number of
the next sample to be read or written can be determined using
strtim("i")
or strtim("o")
. If the argument string is
incorrectly formatted, strtim
returns zero (indistinguishable
from a correct input that evokes a zero output); this may be considered
a feature. Several of the programs in chapter 6 illustrate the use of
strtim
(for example, see section Example 7: A General-Purpose FIR Filter).
Go to the first, previous, next, last section, table of contents.