| Symbol Tables | 
| Table of ContentsSymbol Tables Abstract Revisions What are Symbol Tables? Illustration of Symbol Table Representation Why use Symbol Tables? Symbol Subroutine Naming Conventions Symbol Table Initialization A Comprehensive Example Creating a symbol Deleting a symbol Duplicating a symbol Renaming a symbol Obtaining the name of a symbol Adding a new value to a symbol Deleting a value from a symbol Obtaining values associated with a symbol Reordering the values associated with a symbol Determining the dimension of a symbol Three Letter Mnemonics used in Subroutine Names Calling Sequences Symbol Tables
 Abstract
 Revisions
 
 
 What are Symbol Tables?
 As implemented in SPICELIB, there are three types of symbol tables: character, double precision, and integer. While the symbol names are always character strings, the type of the symbol table is determined by the data type of the values. For example, an integer symbol table has integer values associated with its symbol names. Illustration of Symbol Table Representation
 
 
   symbol name          associated values
   --------------       -----------------
   BODY4_GM        -->   4.282628654899D4
   BODY4_POLE_DEC  -->   5.2886D1
                        -6.1D-2
                         0.0D0
   BODY4_POLE_RA   -->   3.17681D2
                        -1.08D-1
                         0.0D0
This symbol table contains three symbols. One of the symbols, BODY4 GM,
   points to a single value. The other two symbols each point to three
   values.Why use Symbol Tables?
 The fact that more than one value may be stored under a single name (symbol) allows you to store polynomials, vectors, matrices, or any set of associated values under one name. Examples from the SPICELIB kernel pool include: three axes for one body under the name `BODYxxx AXES'; polynomials for the right ascension and declination of the pole of a body (three terms each) under the name `BODYxxx POLE RA' and `BODYxxx POLE DEC'. Other examples might be to list the names of active satellites under the name of the parent planet; to list one or more vidicom matrices under the name `K-MATRIX'; and to store scalar, vector, and matrix values in a simulated desk calculator. In short, any time you need to store something and look it up later, you can use symbol tables. The advantages come into play mostly when the things to be stored are not known until run-time, or when a program is undergoing development and the things to be stored are subject to rapid change. Symbol Subroutine Naming Conventions
 
 
 
 
 Symbol Table Initialization
 Before using the symbol tables, you must initialize the name table, pointer table, and value table. This initialization sets the size and cardinality of the component tables. The size of the name table must equal the size of the pointer table. In other words, both must contain the same number of elements. Also, the size of the value table should be large enough to accommodate the maximum number of values anticipated. If the size of any of the component tables of a symbol table is too small, it is treated as an error by the symbol table routines. The cardinality of the component tables should be set to zero before using a symbol table. The following piece of code demonstrates the easiest way to initialize a symbol table. Using the cell routines SSIZEx to create a symbol table containing up to thirty symbols and up to one hundred-fifty values, the initialization looks like this: Initialize the name table: 
 CALL SSIZEC ( 30, TABSYM )Initialize the pointer table: 
 CALL SSIZEI ( 30, TABPTR )Initialize the value table: 
 CALL SSIZEC ( 150, TABVAL )The name table always contains character values and is initialized with SSIZEC. Likewise, the pointer table always contains integer values and is thus initialized with SSIZEI. The initialization of the value table is different for each of the types of symbol tables. In the example above the routine SSIZEC was used to initialize the value table for a character symbol table. A double precision value table should be initialized using SSIZED, and an integer values table should be initialized using SSIZEI. A Comprehensive Example
 Creating a symbol
 The call, 
 CALL SYSETC ( 'EINSTEIN', 'BROWNIAN MOTION', TABSYM, TABPTR, TABVAL )creates the symbol table: 
 EINSTEIN --> BROWNIAN MOTIONTo create a symbol giving it more than one value, use the PUT routine. If the VALUES array contains the elements, 
 ELECTRIC CHARGE PHOTOELECTRIC EFFECTN is 2 (the number of elements in the VALUES array), and the symbol you want to create is named `MILLIKAN', the call, 
 CALL SYPUTC ( 'MILLIKAN', VALUES, N, TABSYM, TABPTR, TABVAL )creates a new symbol in the symbol table. The symbol table now looks like this: 
 
   EINSTEIN   -->  BROWNIAN MOTION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
Imagine now that the symbol table has several symbols.
 
   BARDEEN    -->  TRANSISTOR EFFECT
                   SUPERCONDUCTIVITY
   EINSTEIN   -->  BROWNIAN MOTION
   HAHN       -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   PLANCK     -->  ELEMENTARY QUANTA
Deleting a symbol
 The call, 
 CALL SYDELC ( 'PLANCK', TABSYM, TABPTR, TABVAL )deletes the scientist PLANCK from the table. The symbol table now looks like this: 
 
   BARDEEN    -->  TRANSISTOR EFFECT
                   SUPERCONDUCTIVITY
   EINSTEIN   -->  BROWNIAN MOTION
   HAHN       -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
Duplicating a symbol
 Using the DUP routine, 
 CALL SYDUPC ( 'HAHN', 'STRASSMAN', TABSYM, TABPTR, TABVAL )changes the symbol table contents to: 
 
   BARDEEN    -->  TRANSISTOR EFFECT
                   SUPERCONDUCTIVITY
   EINSTEIN   -->  BROWNIAN MOTION
   HAHN       -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   STRASSMAN  -->  NUCLEAR FISSION
The same results could have been achieved using the SET routine to
   create a symbol with one associated value, or the PUT routine if the
   symbol you wanted to create had more than one associated value. The call
   for creating the symbol `STRASSMAN' with the value `NUCLEAR FISSION'
   would look like this:
 CALL SYSETC ( 'STRASSMAN', 'NUCLEAR FISSION', TABSYM, TABPRT, TABVAL ) Renaming a symbol
 Using the REN routine, 
 CALL SYRENC ( 'HAHN', 'FERMI', TABSYM, TABPTR, TABVAL )the symbol `HAHN' is renamed to `FERMI'. The symbol table now looks like this: 
 
   BARDEEN    -->  TRANSISTOR EFFECT
                   SUPERCONDUCTIVITY
   EINSTEIN   -->  BROWNIAN MOTION
   FERMI      -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   STRASSMAN  -->  NUCLEAR FISSION
Obtaining the name of a symbol
 The following code will `fetch' and write to the screen the names of the first four symbols in the symbol table. 
 
   DO I = 1, 4
      CALL SYFETC ( I, TABSYM, TABPTR, TABVAL, NAME, FOUND )
      WRITE (6,*) NAME
   END DO
Adding a new value to a symbol
 If the call is, 
 CALL SYPSHC ( 'EINSTEIN', 'GENERAL RELATIVITY', TABSYM, TABPTR, TABVAL )the contents of the symbol table are now: 
 
   BARDEEN    -->  TRANSISTOR EFFECT
                   SUPERCONDUCTIVITY
   EINSTEIN   -->  GENERAL RELATIVITY
                   BROWNIAN MOTION
   FERMI      -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   STRASSMAN  -->  NUCLEAR FISSION
Let the next call be:
 CALL SYENQC ( 'EINSTEIN', 'PHOTOELECTRIC EFFECT', TABSYM, TABPTR, TABVAL )The contents of the symbol table are modified to be: 
 
   BARDEEN    -->  TRANSISTOR EFFECT
                   SUPERCONDUCTIVITY
   EINSTEIN   -->  GENERAL RELATIVITY
                   BROWNIAN MOTION
                   PHOTOELECTRIC EFFECT
   FERMI      -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   STRASSMAN  -->  NUCLEAR FISSION
Deleting a value from a symbol
 The call, 
 CALL SYPOPC ( 'BARDEEN', TABSYM, TABPTR, TABVAL, VALUE, FOUND )results in the symbol table: 
 
   BARDEEN    -->  SUPERCONDUCTIVITY
   EINSTEIN   -->  GENERAL RELATIVITY
                   BROWNIAN MOTION
                   PHOTOELECTRIC EFFECT
   FERMI      -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   STRASSMAN  -->  NUCLEAR FISSION
If there are no remaining values associated with the symbol after VALUE
   has been popped, the symbol is removed from the symbol table.Obtaining values associated with a symbol
 Calling the GET routine, 
 CALL SYGETC ( 'EINSTEIN', TABSYM, TABPTR, TABVAL, N, VALUES, FOUND )returns the following information about the symbol: 
 
 
 
 
 
   N        3
 
   VALUES   GENERAL RELATIVITY
            BROWNIAN MOTION
            PHOTOELECTRIC EFFECT
 
   FOUND    TRUE
Reordering the values associated with a symbol
 Calling the ORD routine to order the values associated with the symbol `EINSTEIN', 
 CALL SYORDC ( 'EINSTEIN', TABSYM, TABPTR, TABVAL )the contents of the symbol table are modified to be: 
 
   BARDEEN    -->  SUPERCONDUCTIVITY
   EINSTEIN   -->  BROWNIAN MOTION
                   GENERAL RELATIVITY
                   PHOTOELECTRIC EFFECT
   FERMI      -->  NUCLEAR FISSION
   MILLIKAN   -->  ELECTRIC CHARGE
                   PHOTOELECTRIC EFFECT
   STRASSMAN  -->  NUCLEAR FISSION
In order to transpose the first and second value associated with the
   symbol `MILLIKAN', use the TRN routine.The call, 
 CALL SYTRNC ( 'MILLIKAN', 1, 2, TABSYM, TABPTR, TABVAL )Changes the symbol table to look like this: 
 
   BARDEEN    -->  SUPERCONDUCTIVITY
   EINSTEIN   -->  BROWNIAN MOTION
                   GENERAL RELATIVITY
                   PHOTOELECTRIC EFFECT
   FERMI      -->  NUCLEAR FISSION
   MILLIKAN   -->  PHOTOELECTRIC EFFECT
                   ELECTRIC CHARGE
   STRASSMAN  -->  NUCLEAR FISSION
Determining the dimension of a symbol
 The code, 
 NUMSUB = SYDIMC ( 'EINSTEIN', TABSYM, TABPTR, TABVAL )returns the value of 3 for NUMSUB. Three Letter Mnemonics used in Subroutine Names
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Calling Sequences
 Subroutines: 
 SYDELx ( NAME, TABSYM, TABPTR, TABVAL ) SYDUPx ( NAME, COPY, TABSYM, TABPTR, TABVAL ) SYENQx ( NAME, VALUE, TABSYM, TABPTR, TABVAL ) SYFETx ( NTH, TABSYM, TABPTR, TABVAL, NAME, FOUND ) SYGETx ( NAME, TABSYM, TABPTR, TABVAL, N, VALUES, FOUND ) SYNTHx ( NAME, NTH, TABSYM, TABPTR, TABVAL, VALUE, FOUND ) SYORDx ( NAME, TABSYM, TABPTR, TABVAL ) SYPOPx ( NAME, TABSYM, TABPTR, TABVAL, VALUE, FOUND ) SYPSHx ( NAME, VALUE, TABSYM, TABPTR, TABVAL ) SYPUTx ( NAME, VALUES, N, TABSYM, TABPTR, TABVAL ) SYRENx ( OLD, NEW, TABSYM, TABPTR, TABVAL ) SYSELx ( NAME, BEGIN, END, TABSYM, TABPTR, TABVAL, VALUES, FOUND ) SYSETx ( NAME, VALUE, TABSYM, TABPTR, TABVAL ) SYTRNx ( NAME, I, J, TABSYM, TABPTR, TABVAL )Functions: 
 SYDIMx ( NAME, TABSYM, TABPTR, TABVAL ) |