Software Development with Antelope - BRTT · 14 of 56 Software Development with Antelope Perl ......

56
1 of 56 Software Development with Antelope Software Development with Antelope Daniel Quinlan Boulder Real Time Technologies, Inc.

Transcript of Software Development with Antelope - BRTT · 14 of 56 Software Development with Antelope Perl ......

1 o

gies, Inc.

f 56 Software Development with Antelope

SoftwareDevelopmentwithAntelope

Daniel Quinlan

Boulder Real Time Technolo

2 o

ent

C)

f 56 Software Development with Antelope

OutlineAntelope Software Developm

Simple example

Languages: A comparison

References

Hints for tcl, perl, and c

Mini-applications

Extending Antelope

Less well known interfaces (

Predict example

3 o

ent tools, whichlex fashion.

libraries

f 56 Software Development with Antelope

Antelope S/W Developmfollows Unix example: simple

can be combined in a comp

• framework

• collection of subroutines in

4 o

k

?

s?

ll programs?

AKE

f 56 Software Development with Antelope

Development Framewor

• Where are binaries installed

$ANTELOPE/{bin,lib}

• Where can you find data file

$ANTELOPE/{data}/

• How do you make and insta

make(1), $ANTELOPEM

5 o

ams?

eter files

sys errors)

tation?

f 56 Software Development with Antelope

• How do you configure progr

command line => param

• How do you handle errors?

elog routines (rt logging,

• How do you write documen

man pages

6 o

in C.

f 56 Software Development with Antelope

Starting an application 1. Make a directory to work in

2. template dbsimple.c > my.c

3. edit my.c

4. lint my.c

5. repeat 3, 4

6. make my.o

7. ldlibs my.o => $(DBLIBS)

8. Makefile:BIN=myldlibs=$(DBLIBS)include $(ANTELOPEMAKE)

7 o

my.1

f 56 Software Development with Antelope

9. parameter file, PF=my.pf

10. manpage - > my.1, MAN1=

Final Makefile:BIN=myMAN1=my.1PF=my.pfldlibs=$(DBLIBS)include $(ANTELOPEMAKE)

8 o

f 56 Software Development with Antelope

Don’t want to install into$ANTELOPE?

• SUBDIR=/local

• DEST=/home/you/development

beforeinclude $(ANTELOPEMAKE)

9 o

f 56 Software Development with Antelope

Antelope Interfacesdatabase manipulation

parameter files

epoch time calculations

path manipulation

waveform access

orb access/packet unstuffing

10

es from

of 56 Software Development with Antelope

LanguagesThere are 6 possible languag

which to choose:

• sh

• Tcl/Tk

• Perl

• Matlab

• C

• Fortran

11

s

bin/csh

of 56 Software Development with Antelope

Shelleasy

quick

limited by existing application

limited strings

limited calculations

limited variables

use /bin/sh, not /bin/tcsh or /

12

ng GUI

nctions

ing quoting

a smallerontinue touse variousin tcl/tk.

of 56 Software Development with Antelope

Tcl/Tkhands down easiest for maki

easy to extend with your c fu

simple language with confusrules (think c-shell)

actually interactive

future cloudy: seems to havegroup of users; BRTT will csupport it indefinitely, becafundamental programs are

13

e

of 56 Software Development with Antelope

Tcl Programs in Antelopdbe

dbevents

dbhelp

dbloc2 GUI

dbnoise

ecrontab

orbmonrtd

q330mon, k2mon

rtm

14

ed language

ion

, Mac and PCministration

as typing on

of 56 Software Development with Antelope

Perlfaster

more complete, better design

best tool for string manipulat

widespread throughout Unixworld, especially system adand web cgi scripts.

looks at first like someone wwrong row of keyboard.

15

erl

bloc2

etid

tbackup

texec

tmail

runcate_log

of 56 Software Development with Antelope

Antelope programs in P

antelope_update cronrun d

dbmerge deposit g

grepsrc pktmon r

rtdbclean rtdemo r

rtincident rtinit r

rtreport rtrun t

16

rototypes

of 56 Software Development with Antelope

Matlabnumerical work, especially p

not for real time operations

very little string manipulation

not meant for scripts

17

in other

of 56 Software Development with Antelope

Cwhen nothing else will do

require speed

used a lot

need interfaces not availablelanguages

18

le from C

of 56 Software Development with Antelope

Other interfaces availabassociative arrays and lists

waveforms

response functions

niceplot graphics

travel time calculations

vogle (3d) graphics

map transformations

waveform displays

square earth tiling

19

tines

h.

te a fortran

of 56 Software Development with Antelope

Fortranthe one you know

compatibility with existing rou

fast numerical operations

complex arithmetic

incomplete, not used as muc

in many cases, you can creainterface to c routine

20

al (new here)

hop.tar.gz

Kent

pting

of 56 Software Development with Antelope

ReferencesSoftware Development tutori

http://www.brtt.com/works

Antelope Toolbox for Matlab,Lindquist

Datascope tutorial (on cd)

Reference Booklets:

User, Programmer, Scri

21

version

ntelope.html

q

om

site

/~aug

of 56 Software Development with Antelope

Man pages; look at the html

file:/opt/antelope/4.4/a

FAQ http://www.brtt.com/fa

Antelope-users mailing list

[email protected]

Antelope User’s Group web

http://www.indiana.edu

22

ace on

ell script)

eilly

of 56 Software Development with Antelope

Tcl hints

package require Tclx ; cmdtr

(like set -x or set -v in sh

http://www.tcl.tk

Tcl/Tk Pocket reference O’R

tcltk-widget

23

ions

of 56 Software Development with Antelope

tclhelp: lookup tcl funct

24

plications

of 56 Software Development with Antelope

tkcon: talk to other tk ap

25

pps

of 56 Software Development with Antelope

tkinspect: configure tk a

26

of 56 Software Development with Antelope

tdb: graphical debugger

27

atic variables.riables whichne call to thee such values like Fortran

ne) globals and indexopriate name.

of 56 Software Development with Antelope

Global variablesOne problem in tcl is local st

A routine does not have vapreserve their value from onext. Instead, you must savinto global variables, muchcommon.

Suggestion: Choose a few (ovariables, make them arrayinto the array with the appr

28

you mighth elements

on, try putting index:

sier to find global

of 56 Software Development with Antelope

E.g., for a program example,have an array Example, witlike:

Example(gain)

Example(t0)

If you need further qualificatitwo names together as the

Example(w0.t0)

Example(w1.t0)

Fewer global statements, eaand organize all the variousvariables.

29

ences

of 56 Software Development with Antelope

Perl Hintsperldoc -f stat

perldoc -q tk

http://www.perl.org

Perl and Perl/Tk Pocket referO’Reilly

perl-widget

30

tkdb

of 56 Software Development with Antelope

Perl debugger: perl -d:p

31

dev/include -P +p

opt/antelope/

of 56 Software Development with Antelope

c hintslint (lint wrapper)

indent (look for .indent.pro)

cextract -D__STDC__ -I/opt/antelope/

protoize -c "-I$ANTELOPE/include -I/tcltk8.3/include"

ldlibs

32

russ ptree $$

of 56 Software Development with Antelope

C Debuggingldd [-s] ‘which trexcerpt‘

truss truss -a -vall -u\* -f -o /tmp/t

stack trace on faultelog_init(argc, argv) ;

collector in workshop

33

malloc.so.1

re/man/)

of 56 Software Development with Antelope

Memory problemssetenv LD_PRELOAD watch

(grepsrc -l LD_PRELOAD /usr/sha

workshop

works sometimes

purify

34

of 56 Software Development with Antelope

ups: the best debugger

35

n Antelope

, dbcalc, ..

lpath,

h

of 56 Software Development with Antelope

Mini Applicationsa command line window to a

library function:

Datascope dbhelp, dbe

epoch time epoch

parameter files pfecho

path abspath, re

cleanpat

orb/pkts orbstat -i

travel times ttcalc

36

oc2)

hics program

ines

of 56 Software Development with Antelope

Extending Antelopeyour waveform format

your packet formats

your travel time calculator

your location program (in dbl

your processing/editing/grapin dbe

elog ELOG_CALLBACK rout

37

s

ath

type)

of 56 Software Development with Antelope

Little known C interfacestock

strmatches, strcontains

hexdump

abspath, relpath, cleanp

ask, askyn, askynaq

db

dbprocess

dbgroup (bundle, bundle

dbcompile

38

j_free

ics

of 56 Software Development with Antelope

dbstrtype

dbuntangle

dbsever

dbseparate

tt: ttcalc, ucalc

proj: pj_init, pf_fwd, pj_inv, p

grx: fortran callable 2d graph

vogle: c 3d graphics

pixaddress:

39

ent (at as), at a list of

p.tar.gz

of 56 Software Development with Antelope

Contrived Problem:print the arrival time for an ev

certain time and coordinatestations (from a database)

http://www.brtt.com/worksho

example code:% ls $ANTELOPE/examplesc/ perl/ shell/ vogle/fortran/ predict/ tcltk/

40

,$lon)” |

,lon,$lat,$lon),$d

of 56 Software Development with Antelope

Shell example#!/bin/shlat=$1lon=$2depth=$3time=$4

epoch=`epoch +%E $time`table=`pfecho -q predict table`

dbsort $table “distance(lat,lon,$latdbselect - staname“strtime($epoch+ptime(distance(latepth))”

41

of 56 Software Development with Antelope

Tcl/Tk Example#!/bin/sh# \exec $ANTELOPE/bin/atcl $0 "$@"package require Datascopepackage require Tclx

set lat [lindex $argv 0]set lon [lindex $argv 1]set depth [lindex $argv 2]set time [lindex $argv 3]set epoch [str2epoch $time]

set table [pfget predict table]set db [dbopen_table $table r]set db [dbsort $dbdistance(lat,lon,$lat,$lon)]

42

$depth)]

0 $i staname] 0]staname [strtime%s %z” ““]]

of 56 Software Development with Antelope

set n [dbquery $db dbRECORD_COUNT]loop i 0 $n { set db [lreplace $db 3 3 $i] set pred [dbeval $dbptime(distance(lat,lon,$lat,$lon),

set pred [expr $pred+$epoch] set staname [lindex [dbgetv $db puts [format “%-55s %s (%s)” $$pred] [epoch2str $pred “%H:%M:%S.

}

43

l -S $0 "$@"'

;

;

,$lat,$lon)” ) ;

;++){

of 56 Software Development with Antelope

Perl Example: # use perleval 'exec $ANTELOPE/../perl/bin/perif 0;

use lib "$ENV{ANTELOPE}/data/perl" ;use Datascope ;

($lat, $lon, $depth, $time) = @ARGV $epoch = str2epoch ($time) ;$table = pfget (“predict”, “table”)

@db = dbopen_table($table, “r”) ;@db = dbsort( @db, “distance(lat,lon

$n = dbquery (@db, “dbRECORD_COUNT”)for ($db[3] = 0 ; $db[3]<$n ; $db[3]

44

lon),

me”);

of 56 Software Development with Antelope

$pred = dbex_eval (@db, “ptime(distance(lat,lon,$lat,$ $depth)” ) ;

$pred += $epoch ;($staname) = dbgetv(@db, “stanaprintf “%-55s %s (%s)\n”,

$staname, strtime($pred),epoch2str($pred,

“%H:%M:%S.%s %z”, ““) ;}

45

me” exit 1

-nojvm -nosplash

of 56 Software Development with Antelope

Matlab Example#!/bin/shif [ $# != 4 ] ; then echo “Usage: $0 lat lon depth tifi

exec /usr/local/bin/matlab -nodisplay<< EOF > /dev/null

fid = fopen ( ‘/dev/stderr’, ‘w’ ) ;

lat = $1 ;lon = $2 ;depth = $3 ;time = ‘$4’ ;epoch = str2epoch (time) ;

pf = dbpf ( ‘predict’ ) ;

46

on);

lon,%f,%f),%f)’,

;

;

of 56 Software Development with Antelope

dbtable = pfget ( pf, ‘table’ ) ;[db, table] = strtok(dbtable, ‘.’) ;table = strrep(table, ‘.’, ‘’) ;

db = dbopen (db, ‘r’ ) ;db = dblookup_table ( db, table) ;

expr = sprintf ( ‘distance(lat,lon,%f,%f)’, lat, ldb = dbsort( db, expr ) ;

expr = sprintf (‘ptime(distance(lat,lat, lon, depth ) ;

n = dbquery ( db, ‘dbRECORD_COUNT’ )for i = 0:1:n-1 db.record = i ; pred = dbeval(db, expr) + epoch

47

;

of 56 Software Development with Antelope

staname = dbgetv(db, ‘staname’ ) s = strtime(pred) ; fprintf ( fid, ‘%-55s %s\n’,

staname, s ) ;endexit ;EOF

48

”,

of 56 Software Development with Antelope

C example#include <stdio.h>#include “coords.h”#include “db.h”

static voidusage (){ cbanner (“$Revision: 1.3 $”, “[-v] lat lon depth time “BRTT example”, “BRTT”, “[email protected]” ) ; exit (1);}intmain (int argc, char **argv)

49

th ;,

)

of 56 Software Development with Antelope

{ Dbptr db; Pf *pf; char *table, *lat, *lon, *dep char expr[256], staname[128]

*s1, *s2 ; int n ; double epoch, pred ; Tbl *keys ; Expression *pgm ;

elog_init ( argc, argv ) ;

if (pfread (“predict”, &pf) != 0 die (0, “Can’t read pf\n”);

if (argc-optind != 4) usage ();

50

);

” ) ;

<0) ) ;

on);

,

of 56 Software Development with Antelope

lat = argv[optind++]; lon = argv[optind++]; depth = argv[optind++]; epoch = str2epoch(argv[optind++]

table = pfget_string (pf, “table

if(dbopen_table(table, “r”, &db) die(0,“Can’t open %s”, table sprintf ( expr, “distance(lat,lon,%s,%s)”,lat,l keys = strtbl(expr, 0) ; db = dbsort( db, keys, 0, 0 ) ;

sprintf ( expr,“ptime(distance(lat,lon,%s,%s),%s)

lat, lon, depth ) ;

51

; ;;record++){ ) ;

e,0);

) ;

;

of 56 Software Development with Antelope

dbex_compile(db, expr, &pgm, 0 ) dbquery(db, dbRECORD_COUNT, &n ) for ( db.record=0 ; db.record<n

db.dbex_eval (db, pgm, 0, &predpred += epoch ;dbgetv(db,0,“staname”,stanams1=strtime(pred),s2=zepoch2str(pred,

“%H:%M:%S.%s %z”, ““)printf (“%-55s %s (%s)\n”,

staname, s1, s2 )free(s1) ; free(s2) ;

} dbex_free(pgm) ; return 0;}

52

, result, n, keysameime, stime

lt )

eter file” )

of 56 Software Development with Antelope

Fortran exampleprogram fpredictimplicit none

#include “db.i”real*8 str2epoch, epoch, predinteger iargc, db(4), pf, pgm, icharacter*256 table, expr, stancharacter*64 lat, lon, depth, t

call elog_init(0,0)

call pfread(“predict”, pf, resuif ( result ) then

call die ( “Can’t read paramendif

53

t lon depth time”)

table )

db) .LT. 0 )tabase” )

of 56 Software Development with Antelope

if ( iargc() .ne. 4 ) thencall die(“Usage: fpredict la

endif

call getarg(1, lat)call getarg(2, lon)call getarg(3, depth)call getarg(4, time)epoch = str2epoch(time)

call pfget_string(pf, “table”,

if ( dbopen_table ( table, “r”, * call die ( 0, “Can’t open da

54

‘,’, a, ‘)’)

““ )

pth,’,a,‘)’)r, pgm, 0 )

of 56 Software Development with Antelope

write (expr, 100) lat, lon100 format (‘distance(lat,lon,’, a,

call strtbl(keys, expr, 0)call dbsort ( db, db, keys, 0,

write ( expr, 101) lat, lon, de101 format (‘ptime(distance(lat,lon * a,‘,’,a,‘),‘,

result = dbex_compile ( db, exp

55

NT, n )

, 0, pred )

ame”, staname, 0)

e

of 56 Software Development with Antelope

call dbquery ( db, dbRECORD_COUdo i = 0, n-1

db(4) = iresult = dbex_eval ( db, pgmpred = pred + epochresult = dbgetv(db, ““, “stancall strtime(stime, pred)write (*, 110) staname, stim

end do

110 format ( a55, a )end

56

predict \

of 56 Software Development with Antelope

Makefile

BIN=cpredict fpredict mlpredict tclpredict perlpredict

ldlibs=$(DBLIBS)include $(ANTELOPEMAKE)

Missing MAN1=