Creating Plot Files Using SAC Graphics

For those who want to develop plotting routines using the sac graphics package, there are two parts of the sac documentation which might prove useful. (I warn you in advance that thre are both some undocumented features and a few errors or misleading comments.) The first document comes with the normal sac distribution: SAC GRAPHICS USERS MANUAL (dated 1987). This contains brief descriptions of the sgftoXXX programs — sgfplot, sgftops, etc. Typing the command with no arguments gives a brief syntax definition for each process. (That is how I found out about "id_flag" in sgftops, which I could not live without. My sgf2ps has expanded on that option some.) This section ends with a brief description of the sgf file format. Two misleading statements: In the discussion about the physical size of the plot, it implies that the increment (0.001 inches) is fundamental. In fact, it is the total width and height — 10 inches wide and 7.5 inches high -- that are fundamental. If you are trying to write an sgf file using their sample file on the last pagge of the section, be forewarned that the value of 0 for "color" as interpreted by sgfplot and sgftops produces totally white plots. The monochromatic default should be 7, for the code to work right. (As of 23 July 1993 I have hardwired sgfp and sgf2ps so that if a color value of 0 comes in, it will be interpreted as a 7.) The second document is not normally distributed: SAC GRAPHICS REFERENCE MANUAL Part 1: Sac Graphics Library (Also 1987). This contains descriptions of the subroutines which live in the library sac.a which can do normal plotting type things. I am sure it is incomplete, but I found it very useful.

The source code for all the SAC graphics subroutines are in a compressed tar file in the sub-directory for Chapter 85.5 on Handbook CD #2.

A Problem with Graphics Using SAC

In 1998 I encountered a problem with programs using SAC graphics on Solaris. The following describes the symptoms and the solution.

Symptom: In the Sun Solaris 2 operating system, plot-output disk files would not get created. The program (focplt, in the focmec package) would continue to run as though everything was fine. If plotting to the screen was called for, that would work okay. Just no output plot disk file when the program exited. This would not always happen, and never happened if the user were superuser. The same result happened if one used SAC calls (such as wsac0) to create sac-format time-series files. These symptoms never occurred in sunos 4.x (Sun's older operating system), and the authors of SAC at LLNL had never heard of this problem before.

Explanation: With the help of Mike Firpo at LLNL, an explanation was found. The subroutine in the SAC library used to open files is zopenc.c. It used the function "open" to open the file, but, according to Kernighan and Ritchie (p 173, second edition) the correct function when opening a new file or overwriting an existing one is "creat." Apparently, sunos is more forgiving than solaris 2 — and/or different compilers or optimzation schemes were used.

Solution: Libraries were corrected as of version 57a for SAC2000. This includes the old fortran-based library which I use for my programs (libsac.a.solaris) and the SAC2000 library (sac.a.57a.solaris, where the 57a is replaced for more recent versions).

Arthur Snoke
Department of Geological Sciences (0420)
Virginia Polytechnic Institute and State University
4044 Derring Hall
Blacksburg, VA 24061, USA
Phone: 540–231–6028 Fax: 540–231–3386
Webpage: /profs/jas.html
This Page:
Originally posted: 31 July 1998. Most recent update: 25 July 2002.