OverviewSAC, the acronym for Seismic Analysis Code, was developed at Lawrence Livermore National Laboratory, University of California, in the early 1980's. It is a command-driven program generally implemented on many types of UNIX operating systems and has become a standard data manipulation tool in seismology. Its binary data format is one of the principle data formats used today in storing and manipulating seismological time series data. With SAC: one can interactively read seismogram data and perform many standard data processing operations, such as filtering time picks amplitude picks correlation Fourier transforms seismic instrument corrections particle motion rotation trace envelopes spectral ratios linear regressions frequency-wavenumber analysis and create a variety of plots of the data and resulting analysis There are also utility programs that can be used to view plots or to convert SAC graphics files into other formats such as PostScript. These files can then be used with other graphics programs such as Adobe Illustrator to construct more complex figures. One can also interact directly with the UNIX operating system while using SAC, calling system functions or running secondary programs as needed. Macros (scripts of SAC commands) can be combined with CShell scripts for automating seismic processing. SAC binary data files can be written and read from fortran and C programs using input/output routines contained in the SAC library, "sac.a". last modified 3/05/01 a" or "sacio. "sac. These variables are needed by the SAC program to access internal databases.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.CERI Implementation SAC is part of CERI's supported software. . each user sources the "ceri_common.2 -DSUNOS4. ########################################## #The Following are sac Variables# ########################################## setenv SACDIR /ceri_common/supported /sac2000/sac set path = ($path $SACDIR/bin) setenv SACCFLAGS "-w -DBSD4.a".cshrc" file which sets the following UNIX environmental variables. On login.a if you need to compile programs with SAC I/O routines. that can be used in compiling fortran or C programs on SUN Solaris systems. A copy is available at /tetemeko /local/sac/lib/sac. The SAC program is started by typing. for example: system prompt> sac2000 You then see: NEW SEISMIC ANALYSIS CODE [March 28. 1996 (Version 00.51)] Copyright 1995 Regents of the University of California SAC> And SAC is ready to go! last modified 3/05/01 . SAC Commands SAC commands are entered at the command prompt.gov/sac/ . 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 . Generally data are constructed within SAC or read from a file before other operations are attempted. The definitive website on SAC commands is located at http://www.llnl. Here is an alphabetical list of commands contained within SAC. sometimes certain SAC commands are invoked to prepare a certain kind of data operation or to set up parameters for a plot. Note. that a command may have a shorthand form (on the left of each word pair). Alternatively. 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 . abs: .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 A description of each command can be obtained while in the SAC program by typing SAC> help commandname For example. here is what you would see for the command. SYNTAX: ABS ERROR MESSAGES: 1301: No data files read in.g. DEPMEN LATEST REVISION: January 8. e.. 1983 (Version 8.g. DEPMAX.g. read cut listhdr Graphics Environment Module.SAC> help abs SAC Command Reference Manual ABS SUMMARY: Takes the absolute value of each data point.0) SAC> SAC commands can be grouped into several functional categories: Executive Function Module. e. xvport ... e. 1307: Illegal operation on spectral file HEADER CHANGES: DEPMIN. manipulate blackboard variables help macro quit Data-Set Module Data File Module. add mul sqrt Binary Operations Module.. ohpf oapf Signal Measurement Module.g. e. rtrend rmean rotate decimate Event Analysis Module.g.. plot plot1 plotpk Spectral Analysis Module..g.. e. begindevices enddevices Graphics Action Module..g. merge addf divf Signal Correction Module..g.. fft plotsp bandpass Unary Operations Module.g. . e..g. e.g. e. rms marktimes XYZ (3D) Data Module. e. e..g. e.title Graphics Control Module. e. it pays to "play" with SAC. there are many things that you can tell the SAC program to do.to process more data. last modified 3/05/01 . the commands can be written into a file and used as a script . Usually. Once you have your processing clarified.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 As you can probably tell.the SAC macro . or to keep a record of exactly what you did to the data. executing commands to process a few seismograms to understand what you want to do with the data. SAC Data Formats SAC can read data in a variety of formats: SAC Binary Format (read) CSS format (readcss) SDD format (readsdd) ASCII formats (readalpha) Use the "help" facility in SAC or refer to the online manual for detailed descriptions of these formats. SAC header: The header portion of the file is very important to the datafile since it contains information on sampling interval. and all other parameters important in earthquake data processing. event location. station location. A SAC binary file consists of a header of ascii data that defines the following binary seismic data. The data may consist of equally incremented or irregularly spaced time series data. For example. ground motion components. or complex spectral data. here is a listing of the header variables for NS waveform data recorded at MLNT from the . These parameters are used by the various SAC commands to manipulate the data. SAC Binary Format This is the standard format for most seismic data. NM.EGN.3247301e+02 GCARC = 1.8098999e+02 IFTYPE = TIME SERIES FILE LEVEN = TRUE DELTA = 9.sac SAC> lh Read the data file list the header using "lh" FILE: MLNT.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 ----------------------- file name NPTS = 18100 B = 0.0000000e+00 E = 1. 2001 KZTIME = 01:22:59.9999998e-03 DEPMIN = -4.NM.5228001e+01 Waiting number of points in the file begin time ending time type of file evenly sampled time series time increment minimum amplitude in file maximum amplitude in file mean amplitude of file origin marker time date (Julian day) UT reference reference time equivalence generic name of instrument station name component azimuth relative to north component "incidence angle" reletive to the vertical station latitude station longitude event latitude EVLO = -8.1800000e+02 DEPMAX = 6.5334000e+01 STLO = -8.2375816e+01 BAZ = 2.9998001e+01 DIST = 1. microearthquake: Commands/Results Explanation SAC> r MLNT.1.0000000e+01 STLA = 3.1.9830002e+01 EVLA = 3.recent Shelby Co.0000000e+00 CMPINC = 9.EGN.370 IZTYPE = BEGIN TIME KINST = NM KSTNM = MLNT CMPAZ = 0.0872928e+00 OMARKER = 0 KZDATE = JAN 31 (031).9284590e+01 AZ = 5.6300000e+02 DEPMEN = 1. Some of the information in the SAC header is computed automatically once the appropriate header variables have been defined. using the "write" ("w") command. in SAC binary format. Once data are manuipulated by SAC. and "GCARC" are computed once the station and event locations are defined by their geographical coordinates. For example. SAC> r file1 SAC> hp bu co 1 n 2 p 1 SAC> w file2 last modified 3/05/01 . "DIST". "BAZ". "AZ". For example "CMPAZ" and "CMPINC" must be defined to use the "rotate" command to rotate horizontal seismic data into tangential and radial motions or to compute a particle motion plot using "ppm". the result can be written to disk. Other information is essential for particular SAC commands to work. for output to a printer or as input to another graphics program. a graphics window is initialized to view the plot and commands can be given to interactively change plot characteristics. it can be saved to a SAC graphics file in "sgf" format. These sgf files are then usually converted to another format. Once the plot has been constructed in suitable form. This plot was made using the following commands while working on a Macintosh at home: . like PostScript. Usually.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. z mlnt.Commands/Results SAC> r mlnt.r mlnt.interactive windowing and phase picking routine ppm . view and decide to save to a file begindevice sgf to save to a sgf file use p1 again. I combine a number of SAC plots with Adobe Illustrator to produce a figure. last modified 3/05/01 .plot the amplitude and phase spectra.6 SAC> qdp off SAC> xlim 58 70 SAC> title on "Rotated Data at MLNT" SAC> xlabel on "Time.plot particle motion for two components of motion (usually two horizontal components) plotsp .t SAC> xvport 0.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".1 0.plot a single seismogram plot1 (p1) . 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. Common plotting commands include: plot (p) . sec" SAC> ylabel on "Digital Counts" SAC> bd tek4014 SAC> p1 SAC> bd sgf SAC> p1 SAC> ed sgf SAC> sgftops f001. Usually.plot almost any number of seismograms plotpk (ppk) . Examples are given in the Macros section of these webpages. Variables can be defined. 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.Blackboard Variables SAC also has the internal functionality of a calculator. evaluated. last modified 3/05/01 . ELSEIF. The syntax for manipulating blackboard variables is relatively simple but sometimes obscure. SAC has built into it a simple programming language. Thus. These variables can be manipulated and used in calculations. The "Blackboard" is simply a feature that saves user defined variables. Refer to the SAC manual for details. Results can be fed into SAC commands for further data processing. There are also IF. and put into simple equations. SAC macros can take several forms depending on how you want to implement them. sec" ylabel on "Digital Counts" bd sgf p1 ed sgf sgftops f001.A simple macro based on the plotting example macro name = mlntplot r mlnt.sgf plot1 1 y How it is used SAC> macro mlntplot Example 2 .t xvport 0. These include: A simple macro file containing SAC commands without keywords or dependent arguments A macro with dependent arguments A macro with keywords Example 1 .1 0.z mlnt.The same macro driven by dependent arguments .r mlnt.Macros A SAC macro is a script of SAC commands.6 qdp off xlim 58 70 title on "Rotated Data at MLNT" xlabel on "Time. The same macro driven by keywords macro name = mlntplot3 How it is used $keys files values r $files xvport 0.sgf plot1 1 y How it is used SAC> macro mlntplot2 mlnt. sec" ylabel on "Digital Counts" bd sgf p1 ed sgf sgftops f001.r MLNT" mlnt.6 qdp off xlim 58 70 title on "Rotated Data at MLNT" xlabel on "Time.sgf plot1 1 y Macros can also call other macros.z mlnt. particularly when using SAC with .1 0.macro name = mlntplot2 r $1 $2 $3 xvport 0.6 qdp off xlim $values title on "Rotated Data at SAC> macro mlntplot3 files mlnt. sec" ylabel on "Digital Counts" bd sgf p1 ed sgf sgftops f001.t Example 3 . This is very useful in applying a generic operation to many specific data files.1 0. Another useful trick.r mlnt.z mlnt.t values 58 70 xlabel on "Time. we could produce the plot by typing the following at the UNIX system prompt: sysprompt> sac2000 < mlntplot > sac. For example. reduce the traveltime and scale last modified 3/05/01 .macro . using the first macro above. is to use the UNIX directed input.CShells.output" is a file that catches all the sac i/o that would normally be seen on the screen. Langston ("The truth is out where?") mom_correlate .output "sac.A.macro .read in a file.plot data and synthetic seismograms together reduce. Macro examples from the SAC files of C.find the best scale factor between two time series in the least-squares sense datasynplot. last modified 3/05/01 . picksetup2.make the SAC macros to produce data/synthetic comparisons. Here are four CShell Scripts that incorporate SAC in them to varying degrees kintcalc2 . This is particularly useful when running synthetic seismogram codes that output time series in SAC binary format. phasepick2 . data_model_plot .CShell Scripts The UNIX CShell enables SAC macros to be built within a CShell script and then run.produce synthetic seismograms from a wavenumber integration program.use ppk interactively to pick amplitude and times from seismograms. Save the picks in file for more processing. These synthetic time series can then be processed with SAC with the same data processing performed on real data. An Example Here is an f77 program that constructs a gaussian time function an outputs the result in SAC binary format. It also useful to read SAC binary files to perform more specialized functions that SAC does not include. rsac2 . This is accomplished by called the following IO routines available in the SAC library. rsac1 .Use in Fortran Programs Time series data can be generated in your own fortran (and C ) programs and output in SAC binary format. wsac2 .writes an unevenly spaced data file.gauss. In addition to these routines.reads an unevenly spaced data file. there are a number of subroutines that access or define each SAC header variable.f program to create gaussian time function CHARACTER*90 KNAME CHARACTER*3 ANS Explanation .a".writes an evenly spaced data file. "sac. wsac1 . Source Code c -----. See the SAC manual for details. Many of my programs use this capability since it is useful to compare data and synthetic seismograms in the same format.reads an evenly spaced data file. tshift EGG=alpha*alpha*tm*tm IF(EGG.100) 100 FORMAT('INPUT time width and time shift of gaussian pulse:') READ(*.Set all header fields to their default values.25.2/twidth WRITE(*.dimension YARRAY(8192) CHARACTER*80 PASNAME * Create the far field time function -------------------WRITE(*.twidth . complete the statements C which define the SAC header fields that you C want to be in the file. C C . C Using your own variables.) EGG=25.*TM*ALPHA*ALPHA*EXP(-EGG) 10 CONTINUE C---------.tshift alpha=2.USER ACTION: Shown below are incomplete statements used C to define each of the SAC header fields.101) 101 FORMAT('INPUT DT AND NPTS WANTED:') READ(*.*) twidth.NPOINT TM=DT*(I-1) .*) DT.NOW CREATE A HEADER IN SAC FORMAT. C calculate the gaussian function Set up a new SAC header .The definitions for each of these variables can be found in the C appendix to the SAC Command Reference Manual. C CALL NEWHDR C C . YARRAY(I)=EXP(-EGG) C YARRAY(I)=-2.NPOINT DO 10 I=1.GT.--------------------C C . Delete the remaining lines. YARRAY.NERR) CALL SETFHV('DELTA'. DELTA=DT E=B+FLOAT(NPTS-1)*DELTA CALL SETFHV('B'...delta. See the above mentioned appendix.NPTS.npts.NERR) CALL SETIHV('IEVTYP'.The following fields are required: C NPTS=NPOINT B=0.Fields which begin with an "L" are logical fields and must C be either .TRUE. C . but can only C be set to a limited number of values.All other fields are real.E. each corresponding C to a specific condition. or . C CALL WSAC1(KNAME.b.NERR) CALL SETLHV('LOVROK'.NERR) CALL SETLHV('LEVEN'.NERR) CALL SETIHV('IFTYPE'.WRITE THE FILE TO DISK. C . C .NERR) C Set header variables needed use wsac1 to create an evenly spaced binary file .NERR) CALL SETFHV('E'..FALSE.NERR) CALL SETIHV('IZTYPE'. C ..NERR) CALL SETLHV('LPSPOL'.'IUNKN'.NERR) C KNAME='gauss.NERR) CALL SETIHV('IDEP'.TRUE.tfunc' C C .TRUE.Fields which begin with an "I" are also integers.NERR) CALL SETNHV('NPTS'..B.'IDISP'. C C .C .Fields which begin with a "K" are character variables of C length 8 unless otherwise noted.'IB'..Fields which begin with an "N" are integer fields.TRUE.DELTA.'ITIME'. WRITE(1.a if you need to compile programs with SAC I/O routines.'SAC FILE '. "sac.a". last modified 3/06/01 . that can be used in compiling fortran or C programs on SUN Solaris systems.f $(LIB)/sac. A copy is available at /tetemeko /local/sac/lib/sac.f f77 $(FFLAGS) -o $(MYBIN)/gauss gauss.200) KNAME 200 FORMAT(1X.' HAS BEEN WRITTEN TO DISK') 99 CONTINUE STOP END Here is the make file used to compile this program: FFLAGS = -g MYBIN = /yourdirectory/bin LIB = $(SACDIR)/lib gauss: gauss.a Important Note: At this time (3/05/01) CERI does not have a generally available copy of the SAC library.A32.a" or "sacio.