This paper documents the numerical formulations, thermochemical data base, and possible applications of computer programs, SOLVGAS and GASWORKS, for calculating multicomponent chemical equilibria in gas-solid-liquid systems. SOLVGAS and GASWORKS compute simultaneous equilibria by solving simultaneously a set of mass balance and mass action equations written for all gas species and for all gas-solid or gas-liquid equilibria. The programs interface with a thermochemical data base, GASTHERM, which contains coefficients for retrieval of the equilibrium constants from 25-degrees to 1200-degrees-C. The equilibrium constants are for derived-species and numerical equilibria written with a specific set of thermodynamic components. GASTHERM includes > 1000 species of gases, solids, and liquids for a 42 element system. The programs and data base model dynamic chemical processes in 30- to 40-component volcanic-gas systems. By linking a series of individual calculations with stepwise changes in temperature, pressure, and composition between steps, we can model gas evaporation from magma, mixing of magmatic and hydrothermal gases, precipitation of minerals during pressure and temperature decrease, mixing of volcanic gas with air, and reaction of gases with wall rock. We show examples of the gas-evaporation-from-magma and precipitation-with-cooling calculations for volcanic gases collected from Mount St. Helens in September 1981. Constraining the model with samples of gases, sublimates, and lavas from the volcano, we predict: (1) the amounts of trace elements volatilized from shallow magma, deep magma, and wall rock, and (2) the solids that precipitate from the gas upon cooling. We then test the model's predictions by comparing them with the measured trace-element concentrations in gases and the observed sublimate sequence. This study leads to the following conclusions: (1) most of the trace elements in the Mount St. Helens gases are volatilized from shallow magma as simple chlorides (CuCl, AgCl, CsCl, et cetera); some elements reside in various other types of gas species (H2MoO4, AuS, Fe(OH)2, Hg, H2Se, et cetera); (2) some elements (for example, Al, Ca) exist dominantly in rock aerosols, not gases, in the gas stream; (3) near-surface cooling of the gases triggers precipitation of oxides, sulfides, halides, tungstates, and native elements; and (4) equilibrium cooling of the gases to 100-degrees-C causes most trace elements, except for Hg, Sb, and Se, to precipitate from the gas.