SAC Tutorial
SAC Tutorial
SAC Tutorial
CERI Implementation
SAC is part of CERI's supported software.
On login, each user sources the "ceri_common.cshrc"
file which sets the following UNIX environmental
variables. These variables are needed by the SAC
program to access internal databases.
##########################################
#The Following are sac Variables#
##########################################
setenv SACDIR /ceri_common/supported
/sac2000/sac
set path = ($path $SACDIR/bin)
setenv SACCFLAGS "-w -DBSD4.2 -DSUNOS4.0"
setenv SACFFLAGS "-w -Nn2000 -Nq300"
setenv SACPFLAGS "-P"
setenv SACXWINDOWS x11
setenv SACAUX $SACDIR/aux
setenv SACGRAPHICSDEVICE X
setenv LD_LIBRARY_PATH
$SACDIR/lib:$LD_LIBRARY_PATH
#
Important Note:
At this time (3/05/01) CERI does not have a generally
available copy of the SAC library, "sac.a" or "sacio.a",
that can be used in compiling fortran or C programs on
SUN Solaris systems. A copy is available at /tetemeko
/local/sac/lib/sac.a if you need to compile programs
with SAC I/O routines.
SAC Commands
SAC commands are entered at the command prompt.
Generally data are constructed within SAC or read
from a file before other operations are attempted.
Alternatively, sometimes certain SAC commands are
invoked to prepare a certain kind of data operation or
to set up parameters for a plot.
The definitive website on SAC commands is located at
http://www.llnl.gov/sac/ .
Here is an alphabetical list of commands contained
within SAC. Note, that a command may have a
shorthand form (on the left of each word pair).
lds
lds
listdatasets
lds
fortran
line
external_interface line
linefit
fft
fft
absolutevalue
linefit
dft
fft
absolutevalue
linlin
fileid
fileid
abs
abs
linlin
filterdesign
add
add
linlog
filterdesign
addf
addf
linlog
fd
am
keepam
listhdr
filterdesign
apk
apk
listhdr
fir
fir
axes
axes
lh
floor
floor
axis
axes
listhdr
funcgen
load
funcgen
fg
funcgen load
loadctable
loadctable
qdp
qdp
quantize
quantize
quit
quit
done
quit
end
quit
exit
quit
q
quit
quitsub
quitsub
vspace
vspace
vsp
vspace
lct
loadctable
log
log
log10
log10
loglab
loglab
loglin
loglin
loglog
loglog
lowpass
lowpass
lp
lowpass
bandpass
bandpass
bp
bandpass
bandrej
bandrej
br
bandrej
bbfk
bbfk
beam
beam
beamform
beam
begindevices
begindevices
bd
begindevices
begg
begindevices
bg
begindevices
beginframe
beginframe
begfr
beginframe
bf
beginframe
beginwindow
beginwindow
bw
beginwindow
benioff
benioff
binoperr
macro
macro
m
macro
map
map
markptp
markptp
markp
markptp
marktimes
getbb
getbb marktimes
gmap
gmap markt
marktimes
grayscale
markvalue
grayscale
gs
grayscale markvalue
markv
grid
grid
group
group markvalue
merge
gtext
gtext
merge
gt
gtext
message
message
mes
message
mtw
mtw
mul
mul
mulf
mulf
mulomega
read
read
r
read
readalpha
readalpha
ra
readalpha
readbbf
readbbf
rbbf
readbbf
readcss
readcss
rcss
readcss
readerr
readerr
rerr
readerr
readhdr
readhdr
rh
readhdr
readsdd
readsdd
rsdd
readsdd
readsp
readsp
rsp
readsp
rename
rename
report
wait
wait
wcss
writecss
whpf
whpf
width
width
wiener
wiener
wnr
wiener
wild
wild
window
window
write
write
w
write
writebbf
writebbf
wbbf
writebbf
writecss
writecss
wcss
writecss
writehdr
writehdr
wh
binoperr
boec
binoperr
border
mulomega
report
reverse
reverse
rglitches
rglitches
rmean
rmean
rms
rms
rotate
rotate
rot
rotate
rq
rq
rtrend
rtrend
rtr
rtrend
writehdr
writesdd
writesdd
writesp
writesp
wsp
writesp
news
news
nplotc
nplotc
null
null
scallop
scallop
scp
scallop
setbb
setbb
setdevice
setdevice
setmacro
setmacro
sgf
sgf
hcd
sgf
smooth
smooth
spe
spe
spectrogram
spectrogram
spg
spectrogram
sqr
sqr
sqrt
sqrt
sss
sss
stretch
stretch
sub
sub
subf
subf
symbol
symbol
sym
symbol
synchronize
synchronize
synch
synchronize
xdiv
xdiv
xfudge
xfudge
xfull
xfull
xgrid
xgrid
xlabel
xlabel
xlabl
xlabel
xlim
xlim
xlin
xlin
xlog
xlog
xvport
xvport
xvp
xvport
xwind
xvport
border
capf
capf
ccipf
capf
cds
cds
currentdataset
cds
chnhdr
chnhdr
ch
chnhdr
chpf
chpf
color
color
col
color
comcor
comcor
contour
contour
cont
contour
convert
convert
conv
convert
convolve
convolve
convo
convolve
copy
copy
copyhdr
copyhdr
correlate
correlate
cor
correlate
cut
cut
cuterr
cuterr
hanning
hanning
han
hanning
help
help
h
help
highpass
highpass
hp
highpass
hilbert
hilbert
syntax
syntax
syn
syntax
systemcommand
systemcommand
sc
systemcommand
datagen
datagen
dg
datagen
decimate
decimate
delete
delete
dif
dif
div
div
divf
divf
divomega
divomega
echo
echo
enddevices
enddevices
ed
enddevices
eg
enddevices
endg
enddevices
endframe
endframe
ef
endframe
endfr
endframe
envelope
ifft
ifft
idft
ifft
image
image
inicm
inicm
installmacro
installmacro
int
int
interpolate
interpolate
interp
interpolate
oapf
oapf
ocipf
oapf
ohpf
ohpf
keepam
keepam
khronhite
khronhite
pause
pause
picks
picks
plabel
plabel
plot
p
plot1
plot1
p1
plot1
plot2
plot2
p2
taper
taper
ticks
ticks
title
title
trace
trace
transcript
transcript
transfer
transfer
trans
transfer
transfertable
transfertable
tsize
tsize
plot unsetbb
plot unsetbb
unwrap
unwrap
ydiv
ydiv
yfudge
yfudge
yfull
yfull
ygrid
ygrid
ylabel
ylabel
ylabl
ylabel
ylim
ylim
ylin
ylin
ylog
ylog
yvport
yvport
yvp
yvport
ywind
yvport
zcolors
zcolors
zlabels
zlabels
zlevels
zlevels
zlines
zlines
zticks
zticks
envelope
erase
erase
era
erase
evaluate
evaluate
eval
evaluate
exp
exp
exp10
exp10
external
external_interface
ext
external_interface
plot2
plotalpha
plotalpha
pa
plotalpha
plotc
plotc
pc
plotc
plotctable
plotctable
plotdy
plotdy
plotpk
plotpk
ppk
plotpk
plotpktable
plotpktable
plotpm
plotpm
ppm
plotpm
plotsp
plotsp
psp
plotsp
plotxy
plotxy
pxy
plotxy
production
production
prod
production
ABS
SUMMARY:
Takes the absolute value of each data point.
SYNTAX:
ABS
ERROR MESSAGES:
1301: No data files read in.
1307: Illegal operation on spectral file
HEADER CHANGES:
DEPMIN, DEPMAX, DEPMEN
LATEST REVISION:
January 8, 1983 (Version 8.0)
SAC>
title
Graphics Control Module, e.g.,
begindevices
enddevices
Graphics Action Module, e.g.,
plot
plot1
plotpk
Spectral Analysis Module, e.g.,
fft
plotsp
bandpass
Unary Operations Module, e.g.,
add
mul
sqrt
Binary Operations Module, e.g.,
merge
addf
divf
Signal Correction Module, e.g.,
rtrend
rmean
rotate
decimate
Event Analysis Module, e.g.,
ohpf
oapf
Signal Measurement Module, e.g.,
rms
marktimes
XYZ (3D) Data Module, e.g.,
spectrogram
contour
Instrument Correction Module
transfer
Subprocess Invoking Module
spe (Spectral Estimation Subprocess)
sss (Signal Stacking Subprocess)
Analysis Tools
filterdesign
FK Spectrum
bbfk
beam
map
Explanation
SAC> r MLNT.EGN.NM.1.sac
SAC> lh
FILE: MLNT.EGN.NM.1.sac
-----------------------
file name
NPTS = 18100
B = 0.0000000e+00
E = 1.8098999e+02
IFTYPE = TIME SERIES
FILE
LEVEN = TRUE
DELTA = 9.9999998e-03
DEPMIN =
-4.1800000e+02
DEPMAX = 6.6300000e+02
DEPMEN = 1.0872928e+00
OMARKER = 0
KZDATE = JAN 31 (031),
2001
KZTIME = 01:22:59.370
IZTYPE = BEGIN TIME
KINST = NM
KSTNM = MLNT
CMPAZ = 0.0000000e+00
CMPINC = 9.0000000e+01
STLA = 3.5334000e+01
STLO = -8.9830002e+01
EVLA = 3.5228001e+01
Waiting
EVLO = -8.9998001e+01
DIST = 1.9284590e+01
AZ = 5.2375816e+01
BAZ = 2.3247301e+02
GCARC = 1.7342965e-01
LOVROK = TRUE
SAC>
event longitude
station distance from event in km
station azimuth from event in degrees
event back azimuth from station in
degrees
great circle arc length in degrees
parameter enabling the file to be modified
SAC Plotting
A particular strength of SAC is in visualizing the data
after it is processed. SAC can be programmed to give a
wide variety of plot types. Usually, a graphics window
is initialized to view the plot and commands can be
given to interactively change plot characteristics. Once
the plot has been constructed in suitable form, it can be
saved to a SAC graphics file in "sgf" format. These sgf
files are then usually converted to another format, like
PostScript, for output to a printer or as input to another
graphics program.
This plot was made using the following commands
while working on a Macintosh at home:
Commands/Results
SAC> r mlnt.z mlnt.r mlnt.t
SAC> xvport 0.1 0.6
SAC> qdp off
SAC> xlim 58 70
SAC> title on "Rotated Data
at MLNT"
SAC> xlabel on "Time, sec"
SAC> ylabel on "Digital
Counts"
SAC> bd tek4014
SAC> p1
SAC> bd sgf
SAC> p1
SAC> ed sgf
SAC> sgftops f001.sgf plot1 1
y
SAC> q
Explanation
Read the three data files
change the x direction aspect ratio for the
plot
turn of the "quick and dirt plot" option
only plot time series data between 58 and
70 seconds
make a title
make a label for the x axis
make a label for the y axis
turn on the tek4014 device to plot to tek
window on my mac at home
plot all of this stuff using "plot1", view and
decide to save to a file
begindevice sgf to save to a sgf file
use p1 again, all other commands have
been saved by SAC
enddevice sgf to finish the sgf plot file
use the sgftops conversion utility to
convert the sgf file to PostScript
quit
At this point I ftp'd the plot file to the Mac and used
Adobe Illustrator to convert the PostScript plot into a
gif file for this webpage. Usually, I combine a number
of SAC plots with Adobe Illustrator to produce a figure.
Common plotting commands include:
plot (p) - plot a single seismogram
plot1 (p1) - plot almost any number of seismograms
plotpk (ppk) - interactive windowing and phase
picking routine
ppm - plot particle motion for two components of
motion (usually two horizontal components)
plotsp - plot the amplitude and phase spectra.
last modified 3/05/01
Blackboard Variables
SAC also has the internal functionality of a calculator.
The "Blackboard" is simply a feature that saves user
defined variables. These variables can be manipulated
and used in calculations. Results can be fed into SAC
commands for further data processing. Thus, SAC has
built into it a simple programming language.
The syntax for manipulating blackboard variables is
relatively simple but sometimes obscure. Refer to the
SAC manual for details.
Variables can be defined, evaluated, and put into
simple equations. There are also IF, ELSEIF, ELSE
statements in addition to DO loops. Sometimes it is a
real tradeoff whether to write a fancy SAC macro to
utilize blackboard variables or just use your favorite
programming language to do the same thing.
Examples are given in the Macros section of these
webpages.
last modified 3/05/01
Macros
A SAC macro is a script of SAC commands. SAC macros
can take several forms depending on how you want to
implement them. These include:
A simple macro file containing SAC commands
without keywords or dependent arguments
A macro with dependent arguments
A macro with keywords
How it is used
How it is used
How it is used
CShell Scripts
The UNIX CShell enables SAC macros to be built within
a CShell script and then run. This is particularly useful
when running synthetic seismogram codes that output
time series in SAC binary format. These synthetic time
series can then be processed with SAC with the same
data processing performed on real data.
Here are four CShell Scripts that incorporate SAC in
them to varying degrees
An Example
Here is an f77 program that constructs a gaussian time
function an outputs the result in SAC binary format.
Source Code
c ------ gauss.f program to create gaussian time
function
CHARACTER*90 KNAME
CHARACTER*3 ANS
Explanation
dimension YARRAY(8192)
CHARACTER*80 PASNAME
*
Create the far field time function
-------------------WRITE(*,100)
100 FORMAT('INPUT time width and time shift
of gaussian pulse:')
READ(*,*) twidth,tshift
alpha=2.2/twidth
WRITE(*,101)
101 FORMAT('INPUT DT AND NPTS WANTED:')
READ(*,*) DT,NPOINT
DO 10 I=1,NPOINT
TM=DT*(I-1) - twidth - tshift
EGG=alpha*alpha*tm*tm
IF(EGG.GT.25.) EGG=25.
YARRAY(I)=EXP(-EGG)
C YARRAY(I)=-2.*TM*ALPHA*ALPHA*EXP(-EGG)
10 CONTINUE
C---------- NOW CREATE A HEADER IN SAC
FORMAT.--------------------C
C - Set all header fields to their default values.
C
CALL NEWHDR
C
C - USER ACTION: Shown below are incomplete
statements used
C
to define each of the SAC header fields.
C
Using your own variables, complete the
statements
C
which define the SAC header fields that
you
C
want to be in the file. Delete the
remaining lines.
C
C - The definitions for each of these variables can
be found in the
C appendix to the SAC Command Reference
Manual.
C
WRITE(1,200) KNAME
200 FORMAT(1X,'SAC FILE ',A32,' HAS BEEN
WRITTEN TO DISK')
99 CONTINUE
STOP
END
Important Note:
At this time (3/05/01) CERI does not have a generally
available copy of the SAC library, "sac.a" or "sacio.a",
that can be used in compiling fortran or C programs on
SUN Solaris systems. A copy is available at /tetemeko
/local/sac/lib/sac.a if you need to compile programs
with SAC I/O routines.
last modified 3/06/01