Page:4SIGHT manual- a computer program for modelling degradation of underground low level waste concrete vaults (IA 4sightmanualcomp5612snyd).pdf/107

From Wikisource
Jump to navigation Jump to search
This page needs to be proofread.
31.INITIALIZE SOLUBILITY ARRAY
B.13

31. Initialize solubility array.

soLarray is vital to determining the chemical equilibrium of each element. This procedure also initializes the two ION arrays: anion and cation

⟨Global variables 4⟩ 
 int num.cations; 
 int num.anions; 
 SOLARRAY **sol.array; 
 ION *cation; 
 ION *anion;

32. The routine malloc() requires stdlib.h. ⟨Include files 3⟩

#include <stdlib.h>

33.

⟨Function declarations 23⟩ 
 void initialize.ion.data (void);

34. Initializing ion and salt array. The data for the ions and salts is in the file ion.db. Must first determine the number of anions and cations, including OH~ and H + and then allocate memory for anion, cation, and soLarray.

 void initialize_ion-data() 
 { 
   int i, j, k
   FILE *ion.database; /* ion and salt data base */ 
   if ((ion-database = fopen(" ion.db", "rt")) ) { 
     printf ("\n\ERROR: Unable to open ion db \n\n"); exit/(0); 
   }
   fscanf (ion.database,"%d %d", &num.cations,&num.anions); 
   ⟨Allocate ion and salt arrays 35⟩ 
   ⟨Input ion data 36⟩ 
   ⟨Input salt data 37⟩ 
   fclose(ion.database); 
   ⟨Zero-out ion and salt data 38⟩ 
 }

35. Allocate memory for all of the arrays.

The total number of cations/anions includes and .

⟨Allocate ion and salt arrays 35⟩ 
 anion = (ION *) malloc(num.anions * sizeof (ION)); 
 cation = (ION *) malloc(num.cations * sizeof (ION)); /* allocate 2-D array */ 
 soLarray = (SOLARRAY **) malloc(num-cations * sizeof (SOLARRAY *)); 
 for (i = 0; < num.cations', i++) { 
   sol array[i] = (SOLARRAY *) malloc(num.amons * sizeof (SOLARRAY)); 
 }

This code is used in section 34.