ISLEC  Version 4.2
load_db.c
Go to the documentation of this file.
1 /* src/load_db.c
2  *
3  * Copyright (C) 2011-2018 Dongdong Li
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundataion; either version 3 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABLITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
31 /* load gas phases */
32 static bool load_gas_phases (FILE *temp_fp)
33 {
34  int species_num;
35  int i;
36  int rv;
37 
38  for (i = 0; i < gas_phase_num; i++)
39  {
40  rv = fscanf (temp_fp, "%s\t%d\n", phase_keyword, &species_num);
41 
42  if (rv != 2)
43  {
44  printf ("ERROR: load_db.c: load_gas_phases () load gas phase ");
45  printf ("error (phase keyword and species number).\n");
46  return false;
47  }
48 
49  // Gas Phase
50  if (strcmp(phase_keyword, PHASE_KEYWORDS[0]) == 0)
51  {
52  phases.gas[i].species_num = species_num;
53 
54  phases.gas[i].gas_species = (SPECIES *)malloc (sizeof (SPECIES) * phases.gas[i].species_num);
55 
56  int j;
57  for (j = 0; j < phases.gas[i].species_num; j ++)
58  {
59  rv = fscanf (temp_fp, "%s\t%d\n", phases.gas[i].gas_species[j].species_symbol,
60  &phases.gas[i].gas_species[j].charge);
61 
62  if (rv != 2)
63  {
64  printf ("ERROR: load_db.c: load_gas_phases () load gas phase ");
65  printf ("error (species symbol and species charge).\n");
66  return false;
67  }
68 
69  phases.gas[i].gas_species[j].elements = (double *)malloc (sizeof (double) * total_comp_num);
70 
71  char compi;
72  char *cbuf = (char*)malloc(32*sizeof(char));
73  memset(cbuf, 0, 32); // initialize memory
74 
75  int k = 0, l = 0;
76  while ((compi = fgetc (temp_fp)) != '\n')
77  {
78  if (compi != '\t' && compi != ' ')
79  {
80  cbuf[k] = compi;
81  k++;
82  }
83  else
84  {
85  phases.gas[i].gas_species[j].elements[l] = atof (cbuf);
86  free (cbuf);
87 
88  cbuf = (char*)malloc(32*sizeof(char));
89  memset(cbuf, 0, 32); // initialize memory
90 
91  k = 0;
92  l ++;
93  }
94  }
95 
96  phases.gas[i].gas_species[j].elements[l] = atof (cbuf); // set the last column
97  free (cbuf);
98 
99  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
100  &phases.gas[i].gas_species[j].thermo_coeff[0],
106  &phases.gas[i].gas_species[j].thermo_coeff[6]);
107  if (rv != 7)
108  {
109  printf ("ERROR: load_db.c: load_gas_phases () load gas phase ");
110  printf ("error (species standard state thermodynamic parameters).\n");
111  return false;
112  }
113  }
114  }
115  else
116  {
117  printf ("ERROR: load_db.c: load_gas_phases () load gas phase ");
118  printf ("error (invalid gas phase keyword, valid keyword is 'GAS').\n");
119  return false;
120  }
121  }
122 
123  return true;
124 }
125 
126 /* load aqueous phases */
127 static bool load_aqueous_phases (FILE *temp_fp)
128 {
129  int species_num; // aqueous species number
130  int i;
131  int rv;
132 
133  for (i = 0; i < aqueous_phase_num; i++)
134  {
135  rv = fscanf (temp_fp, "%s\t%d\n", phase_keyword, &species_num);
136 
137  if (rv != 2)
138  {
139  printf ("ERROR: load_db.c: load_aqueous_phases () load aqueous phase ");
140  printf ("error (phase keyword and species number).\n");
141  return false;
142  }
143 
144  // Aqueous Phase
145  if (strcmp(phase_keyword, PHASE_KEYWORDS[1]) == 0)
146  {
147  phases.aqueous[i].species_num = species_num;
148 
149  phases.aqueous[i].aqueous_species = (SPECIES *)malloc (sizeof (SPECIES) * phases.aqueous[i].species_num);
150 
151  int j;
152  for (j = 0; j < phases.aqueous[i].species_num; j ++)
153  {
154  rv = fscanf (temp_fp, "%s\t%d\n", phases.aqueous[i].aqueous_species[j].species_symbol,
156 
157  if (rv != 2)
158  {
159  printf ("ERROR: load_db.c: load_aqueous_phases () load aqueous phase ");
160  printf ("error (species symbol and species charge).\n");
161  return false;
162  }
163 
164  phases.aqueous[i].aqueous_species[j].elements = (double *)malloc (sizeof (double) * total_comp_num);
165 
166  char compi;
167  char *cbuf = (char*)malloc(32*sizeof(char));
168  memset(cbuf, 0, 32); // initialize memory
169 
170  int k = 0, l = 0;
171  while ((compi = fgetc (temp_fp)) != '\n')
172  {
173  if (compi != '\t' && compi != ' ')
174  {
175  cbuf[k] = compi;
176  k++;
177  }
178  else
179  {
180  phases.aqueous[i].aqueous_species[j].elements[l] = atof (cbuf);
181  free (cbuf);
182 
183  cbuf = (char*)malloc(32*sizeof(char));
184  memset(cbuf, 0, 32); // initialize memory
185 
186  k = 0;
187  l ++;
188  }
189  }
190 
191  phases.aqueous[i].aqueous_species[j].elements[l] = atof (cbuf); // set the last column
192  free (cbuf);
193 
194  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
202  if (rv != 7)
203  {
204  printf ("ERROR: load_db.c: load_aqueous_phases () load aqueous phase ");
205  printf ("error (species standard state thermodynamic parameters).\n");
206  return false;
207  }
208  }
209 
210  // loading binary parameters
211  // cation-anion binary parameters
212  rv = fscanf (temp_fp, "%d\n", &phases.aqueous[i].ii_bin_param_num);
213  if (rv != 1)
214  {
215  printf ("ERROR: load_db.c: load_aqueous_phases () load aqueous phase error (cation-anion parameters).\n");
216  return false;
217  }
218 
219  phases.aqueous[i].ii_bin_params = (IIBINPARAM *)malloc (sizeof (IIBINPARAM) *
221 
222  for (j = 0; j < phases.aqueous[i].ii_bin_param_num; j ++)
223  {
224  rv = fscanf (temp_fp, "%s\t%s\t%lf\t%lf\n",
229  if (rv != 4)
230  {
231  printf ("Load Databank Error (cation-anion)!!!\n");
232  exit (1);
233  }
234 
235  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
236  &phases.aqueous[i].ii_bin_params[j].B0ss[0],
237  &phases.aqueous[i].ii_bin_params[j].B0ss[1],
238  &phases.aqueous[i].ii_bin_params[j].B0ss[2],
239  &phases.aqueous[i].ii_bin_params[j].B0ss[3],
240  &phases.aqueous[i].ii_bin_params[j].B0ss[4],
241  &phases.aqueous[i].ii_bin_params[j].B0ss[5]);
242  if (rv != 6)
243  {
244  printf ("Load Databank Error (cation-anion)!!!\n");
245  exit (1);
246  }
247 
248  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
249  &phases.aqueous[i].ii_bin_params[j].B1ss[0],
250  &phases.aqueous[i].ii_bin_params[j].B1ss[1],
251  &phases.aqueous[i].ii_bin_params[j].B1ss[2],
252  &phases.aqueous[i].ii_bin_params[j].B1ss[3],
253  &phases.aqueous[i].ii_bin_params[j].B1ss[4],
254  &phases.aqueous[i].ii_bin_params[j].B1ss[5]);
255  if (rv != 6)
256  {
257  printf ("Load Databank Error (cation-anion)!!!\n");
258  exit (1);
259  }
260  }
261 
262  // neutral-neutral binary parameters
263  rv = fscanf (temp_fp, "%d\n", &phases.aqueous[i].nn_bin_param_num);
264  if (rv != 1)
265  {
266  printf ("Load Databank Error (neutral-neutral)!!!\n");
267  exit (1);
268  }
269 
270  phases.aqueous[i].nn_bin_params = (NNBINPARAM *)malloc (sizeof (NNBINPARAM) *
272 
273  for (j = 0; j < phases.aqueous[i].nn_bin_param_num; j ++)
274  {
275  rv = fscanf (temp_fp, "%s\t%s\n",
278  if (rv != 2)
279  {
280  printf ("Load Databank Error (neutral-neutral)!!!\n");
281  exit (1);
282  }
283 
284  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
285  &phases.aqueous[i].nn_bin_params[j].Wss[0],
286  &phases.aqueous[i].nn_bin_params[j].Wss[1],
287  &phases.aqueous[i].nn_bin_params[j].Wss[2],
288  &phases.aqueous[i].nn_bin_params[j].Wss[3],
289  &phases.aqueous[i].nn_bin_params[j].Wss[4],
290  &phases.aqueous[i].nn_bin_params[j].Wss[5]);
291  if (rv != 6)
292  {
293  printf ("Load Databank Error (neutral-neutral)!!!\n");
294  exit (1);
295  }
296 
297  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
298  &phases.aqueous[i].nn_bin_params[j].Uss[0],
299  &phases.aqueous[i].nn_bin_params[j].Uss[1],
300  &phases.aqueous[i].nn_bin_params[j].Uss[2],
301  &phases.aqueous[i].nn_bin_params[j].Uss[3],
302  &phases.aqueous[i].nn_bin_params[j].Uss[4],
303  &phases.aqueous[i].nn_bin_params[j].Uss[5]);
304  if (rv != 6)
305  {
306  printf ("Load Databank Error (neutral-neutral)!!!\n");
307  exit (1);
308  }
309  }
310 
311  // neutral-cation-anion ternary parameters
312  rv = fscanf (temp_fp, "%d\n", &phases.aqueous[i].nii_ter_param_num);
313  if (rv != 1)
314  {
315  printf ("Load Databank Error (neutral-cation-anion)!!!\n");
316  exit (1);
317  }
318 
319  phases.aqueous[i].nii_ter_params = (NIITERPARAM *)malloc (sizeof (NIITERPARAM) *
321 
322  for (j = 0; j < phases.aqueous[i].nii_ter_param_num; j ++)
323  {
324  rv = fscanf (temp_fp, "%s\t%s\t%s\n",
328  if (rv != 3)
329  {
330  printf ("Load Databank Error (neutral-cation-anion)!!!\n");
331  exit (1);
332  }
333 
334  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
335  &phases.aqueous[i].nii_ter_params[j].Wsss[0],
336  &phases.aqueous[i].nii_ter_params[j].Wsss[1],
337  &phases.aqueous[i].nii_ter_params[j].Wsss[2],
338  &phases.aqueous[i].nii_ter_params[j].Wsss[3],
339  &phases.aqueous[i].nii_ter_params[j].Wsss[4],
340  &phases.aqueous[i].nii_ter_params[j].Wsss[5]);
341  if (rv != 6)
342  {
343  printf ("Load Databank Error (neutral-cation-anion)!!!\n");
344  exit (1);
345  }
346 
347  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
348  &phases.aqueous[i].nii_ter_params[j].Usss[0],
349  &phases.aqueous[i].nii_ter_params[j].Usss[1],
350  &phases.aqueous[i].nii_ter_params[j].Usss[2],
351  &phases.aqueous[i].nii_ter_params[j].Usss[3],
352  &phases.aqueous[i].nii_ter_params[j].Usss[4],
353  &phases.aqueous[i].nii_ter_params[j].Usss[5]);
354  if (rv != 6)
355  {
356  printf ("Load Databank Error (neutral-cation-anion)!!!\n");
357  exit (1);
358  }
359 
360  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
361  &phases.aqueous[i].nii_ter_params[j].Vsss[0],
362  &phases.aqueous[i].nii_ter_params[j].Vsss[1],
363  &phases.aqueous[i].nii_ter_params[j].Vsss[2],
364  &phases.aqueous[i].nii_ter_params[j].Vsss[3],
365  &phases.aqueous[i].nii_ter_params[j].Vsss[4],
366  &phases.aqueous[i].nii_ter_params[j].Vsss[5]);
367  if (rv != 6)
368  {
369  printf ("Load Databank Error (neutral-cation-anion)!!!\n");
370  exit (1);
371  }
372  }
373 
374  // cation-cation-anion or cation-anion-anion ternary parameters
375  rv = fscanf (temp_fp, "%d\n", &phases.aqueous[i].iii_ter_param_num);
376  if (rv != 1)
377  {
378  printf ("Load Databank Error (cation-cation-anion or cation-anion-anion)!!!\n");
379  exit (1);
380  }
381 
382  phases.aqueous[i].iii_ter_params = (IIITERPARAM *)malloc (sizeof (IIITERPARAM) *
384 
385  for (j = 0; j < phases.aqueous[i].iii_ter_param_num; j ++)
386  {
387  rv = fscanf (temp_fp, "%s\t%s\t%s\n",
391  if (rv != 3)
392  {
393  printf ("Load Databank Error (cation-cation-anion or cation-anion-anion)!!!\n");
394  exit (1);
395  }
396 
397  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
398  &phases.aqueous[i].iii_ter_params[j].Wsss[0],
399  &phases.aqueous[i].iii_ter_params[j].Wsss[1],
400  &phases.aqueous[i].iii_ter_params[j].Wsss[2],
401  &phases.aqueous[i].iii_ter_params[j].Wsss[3],
402  &phases.aqueous[i].iii_ter_params[j].Wsss[4],
403  &phases.aqueous[i].iii_ter_params[j].Wsss[5]);
404  if (rv != 6)
405  {
406  printf ("Load Databank Error (cation-cation-anion or cation-anion-anion)!!!\n");
407  exit (1);
408  }
409  }
410 
411  // neutral-cation-cation-anion or neutral-cation-anion-anion quaternary parameters
412  rv = fscanf (temp_fp, "%d\n", &phases.aqueous[i].niii_qua_param_num);
413  if (rv != 1)
414  {
415  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
416  exit (1);
417  }
418 
419  phases.aqueous[i].niii_qua_params = (NIIIQUAPARAM *)malloc (sizeof (NIIIQUAPARAM) *
421 
422  for (j = 0; j < phases.aqueous[i].niii_qua_param_num; j ++)
423  {
424  rv = fscanf (temp_fp, "%s\t%s\t%s\t%s\n",
429  if (rv != 4)
430  {
431  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
432  exit (1);
433  }
434 
435  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
436  &phases.aqueous[i].niii_qua_params[j].Qssss[0],
437  &phases.aqueous[i].niii_qua_params[j].Qssss[1],
438  &phases.aqueous[i].niii_qua_params[j].Qssss[2],
439  &phases.aqueous[i].niii_qua_params[j].Qssss[3],
440  &phases.aqueous[i].niii_qua_params[j].Qssss[4],
441  &phases.aqueous[i].niii_qua_params[j].Qssss[5]);
442  if (rv != 6)
443  {
444  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
445  exit (1);
446  }
447 
448  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
449  &phases.aqueous[i].niii_qua_params[j].Yssss[0],
450  &phases.aqueous[i].niii_qua_params[j].Yssss[1],
451  &phases.aqueous[i].niii_qua_params[j].Yssss[2],
452  &phases.aqueous[i].niii_qua_params[j].Yssss[3],
453  &phases.aqueous[i].niii_qua_params[j].Yssss[4],
454  &phases.aqueous[i].niii_qua_params[j].Yssss[5]);
455  if (rv != 6)
456  {
457  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
458  exit (1);
459  }
460  }
461 
462  // neutral-neutral-cation-anion quaternary parameters
463  rv = fscanf (temp_fp, "%d\n", &phases.aqueous[i].nnii_qua_param_num);
464  if (rv != 1)
465  {
466  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
467  exit (1);
468  }
469 
470  phases.aqueous[i].nnii_qua_params = (NNIIQUAPARAM *)malloc (sizeof (NNIIQUAPARAM) *
472 
473  for (j = 0; j < phases.aqueous[i].nnii_qua_param_num; j ++)
474  {
475  rv = fscanf (temp_fp, "%s\t%s\t%s\t%s\n",
480  if (rv != 4)
481  {
482  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
483  exit (1);
484  }
485 
486  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
487  &phases.aqueous[i].nnii_qua_params[j].Yssss[0],
488  &phases.aqueous[i].nnii_qua_params[j].Yssss[1],
489  &phases.aqueous[i].nnii_qua_params[j].Yssss[2],
490  &phases.aqueous[i].nnii_qua_params[j].Yssss[3],
491  &phases.aqueous[i].nnii_qua_params[j].Yssss[4],
492  &phases.aqueous[i].nnii_qua_params[j].Yssss[5]);
493  if (rv != 6)
494  {
495  printf ("Load Databank Error (neutral-cation-cation-anion or neutral-cation-anion-anion)!!!\n");
496  exit (1);
497  }
498  }
499  }
500  else
501  {
502  printf ("load_db.c: load_aqueous_phases () load aqueous phase ");
503  printf ("error (invalid aqueous phase keyword, valid keyword is 'LIQUID').\n");
504  return false;
505  }
506  }
507 
508  return true;
509 }
510 
511 static void load_solid_phases (FILE *temp_fp)
512 {
514  int species_num;
515  int i;
516  int rv;
517 
518  for (i = 0; i < solid_phase_num; i++)
519  {
520  rv = fscanf (temp_fp, "%s\t%d\n", phase_keyword, &species_num);
521 
522  if (rv != 2)
523  {
524  printf ("Load Databank Error!!!\n");
525  exit (1);
526  }
527 
528  // Solid Phase
529  if (strcmp(phase_keyword, PHASE_KEYWORDS[2]) == 0)
530  {
531  phases.solids[i].species_num = species_num;
532 
533  phases.solids[i].solid_species = (SPECIES *)malloc (sizeof (SPECIES) * phases.solids[i].species_num);
534 
535  int j;
536  for (j = 0; j < phases.solids[i].species_num; j ++)
537  {
538  rv = fscanf (temp_fp, "%s\t%d\n", phases.solids[i].solid_species[j].species_symbol,
540 
541  if (rv != 2)
542  {
543  printf ("Load Databank Error!!!\n");
544  exit (1);
545  }
546 
547  phases.solids[i].solid_species[j].elements = (double *)malloc (sizeof (double) * total_comp_num);
548 
549  char compi;
550  char *cbuf = (char*)malloc(32*sizeof(char));
551  memset(cbuf, 0, 32); // initialize memory
552 
553  int k = 0, l = 0;
554  while ((compi = fgetc (temp_fp)) != '\n')
555  {
556  if (compi != '\t' && compi != ' ')
557  {
558  cbuf[k] = compi;
559  k++;
560  }
561  else
562  {
563  phases.solids[i].solid_species[j].elements[l] = atof (cbuf);
564  free (cbuf);
565 
566  cbuf = (char*)malloc(32*sizeof(char));
567  memset(cbuf, 0, 32); // initialize memory
568 
569  k = 0;
570  l ++;
571  }
572  }
573 
574  phases.solids[i].solid_species[j].elements[l] = atof (cbuf); // set the last column
575  free (cbuf);
576 
577  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
585  if (rv != 7)
586  {
587  printf ("Load Databank Error!!!\n");
588  exit (1);
589  }
590  }
591 
592  }
593  else
594  {
595  printf ("Invalid Keyword!!!\n");
596  exit (1);
597  }
598  }
600 }
601 
602 static void load_solidsolution_phases (FILE *temp_fp)
603 {
605  int species_num;
606  int i;
607  int rv;
608 
609  for (i = 0; i < solidsolution_phase_num; i++)
610  {
611  rv = fscanf (temp_fp, "%s\t%d\n", phase_keyword, &species_num);
612 
613  if (rv != 2)
614  {
615  printf ("Load Databank Error!!!\n");
616  exit (1);
617  }
618 
619  // Binary Solid Solution Phase
620  if (strcmp(phase_keyword, PHASE_KEYWORDS[3]) == 0)
621  {
622  phases.solidsolution[i].species_num = species_num;
623 
625  (SPECIES *)malloc (sizeof (SPECIES) * phases.solidsolution[i].species_num);
626 
627  int j;
628  for (j = 0; j < phases.solidsolution[i].species_num; j ++)
629  {
630  rv = fscanf (temp_fp, "%s\t%d\n", phases.solidsolution[i].solidsolution_species[j].species_symbol,
632 
633  if (rv != 2)
634  {
635  printf ("Load Databank Error!!!\n");
636  exit (1);
637  }
638 
640  (double *)malloc (sizeof (double) * total_comp_num);
641 
642  char compi;
643  char *cbuf = (char*)malloc(32*sizeof(char));
644  memset(cbuf, 0, 32); // initialize memory
645 
646  int k = 0, l = 0;
647  while ((compi = fgetc (temp_fp)) != '\n')
648  {
649  if (compi != '\t' && compi != ' ')
650  {
651  cbuf[k] = compi;
652  k++;
653  }
654  else
655  {
656  phases.solidsolution[i].solidsolution_species[j].elements[l] = atof (cbuf);
657  free (cbuf);
658 
659  cbuf = (char*)malloc(32*sizeof(char));
660  memset(cbuf, 0, 32); // initialize memory
661 
662  k = 0;
663  l ++;
664  }
665  }
666 
667  phases.solidsolution[i].solidsolution_species[j].elements[l] = atof (cbuf); // set the last column
668  free (cbuf);
669 
670  rv = fscanf (temp_fp, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
678  if (rv != 7)
679  {
680  printf ("Load Databank Error!!!\n");
681  exit (1);
682  }
683  }
684 
685  rv = fscanf (temp_fp, "%d\n", &phases.solidsolution[i].param_num);
686  if (rv != 1)
687  {
688  printf ("Load Databank Error!!!\n");
689  exit (1);
690  }
691 
692  phases.solidsolution[i].params = (SUBRPARAM *)malloc (sizeof (SUBRPARAM) *
694 
695  for (j = 0; j < phases.solidsolution[i].param_num; j++)
696  {
697  rv = fscanf (temp_fp, "%s\t%s\t%lf\t%lf\n",
700  &phases.solidsolution[i].params[j].A0,
701  &phases.solidsolution[i].params[j].A1);
702  if (rv != 4)
703  {
704  printf ("Load Databank Error!!!\n");
705  exit (1);
706  }
707  }
708  }
709  else
710  {
711  printf ("Invalid Keyword!!!\n");
712  exit (1);
713  }
714  }
716 }
717 
718 extern bool load_db (char *input, char *temp)
719 {
720  FILE *temp_fp;
721 
722  clear_comments (input, temp);
723 
724  if ((temp_fp = fopen (temp, "r")) == NULL)
725  {
726  printf ("ERROR: load_db.c: load_db () open temporary file error.\n ");
727  return false;
728  }
729  else
730  {
731  int rv;
732 
733  /* start to load components block */
734  rv = fscanf (temp_fp, "%s\t%d\n", block_keyword, &total_comp_num);
735 
736  if (rv != 2)
737  {
738  printf ("ERROR: load_db.c: load_db () load components block ");
739  printf ("error (block keyword and total components number).\n");
740  return false;
741  }
742 
743  if (strcmp(block_keyword, BLOCK_KEYWORDS[0]) == 0)
744  {
745 
746  components = (ELEMENT *)malloc (sizeof (ELEMENT) * total_comp_num);
747 
748  int i;
749 
750  for (i = 0; i < total_comp_num; i++)
751  {
752  rv = fscanf (temp_fp, "%s\t%d\t%lf\n", components[i].element_symbol,
753  &components[i].element_number,
754  &components[i].element_mass);
755 
756  if (rv != 3)
757  {
758  printf ("ERROR: load_db.c: load_db () load components block ");
759  printf ("error (element symbol, element number and element mass).\n");
760  return false;
761  }
762  }
763  }
764  else
765  {
766  printf ("ERROR: load_db.c: load_db () load components block ");
767  printf ("error (invalid components block keyword, valid is 'COMPONENTS').\n");
768  return false;
769  }
770  // end to load components block
771 
772  // start to load phases block
773  rv = fscanf (temp_fp, "%s\t%d\t%d\t%d\t%d\n", block_keyword,
774  &gas_phase_num,
775  &aqueous_phase_num,
776  &solid_phase_num,
777  &solidsolution_phase_num);
778 
779  if (rv != 5)
780  {
781  printf ("ERROR: load_db.c: load_db () load phases block ");
782  printf ("error (block keyword and gase, liquid, solid, solid solution phases number).\n");
783  return false;
784  }
785 
786  if (strcmp(block_keyword, BLOCK_KEYWORDS[1]) == 0)
787  {
788  total_phase_num = gas_phase_num + aqueous_phase_num + solid_phase_num
790 
791  phases.gas = (GAS_PHASE *)malloc (sizeof (GAS_PHASE) * gas_phase_num);
793  phases.solids = (SOLID_PHASE *)malloc (sizeof (SOLID_PHASE) * solid_phase_num);
795  }
796  else
797  {
798  printf ("ERROR: load_db.c: load_db () load phases block ");
799  printf ("error (invalid phase block keyword, valid is 'PHASES').\n");
800  return false;
801  }
802 
803  /* start to load phases block */
804  load_gas_phases (temp_fp);
805  load_aqueous_phases (temp_fp);
806  load_solid_phases (temp_fp);
807  load_solidsolution_phases (temp_fp);
808  /* end to load phases block */
809 
810  }
811 
812  total_species_num = 0;
813  int i, j;
814 
815  for (i = 0; i < gas_phase_num; i ++)
816  {
818  }
819 
820  for (i = 0; i < aqueous_phase_num; i ++)
821  {
823  }
824 
825  for (i = 0; i < solid_phase_num; i ++)
826  {
828  }
829 
830  for (i = 0; i < solidsolution_phase_num; i ++)
831  {
833  }
834 
835  fclose(temp_fp);
836  remove (temp);
837 
838  return true;
839 }
char species_s1[64]
Definition: islec.h:97
int ii_bin_param_num
Definition: islec.h:158
char species_s3[64]
Definition: islec.h:107
char species_s1[64]
Definition: islec.h:87
char species_s2[64]
Definition: islec.h:116
bool clear_comments(char *input, char *temp)
Clear all commented sentences in a islec database file, and then write databank to a temporary file n...
AQUEOUS_PHASE * aqueous
Definition: islec.h:189
double B0ss[6]
Definition: islec.h:91
int solidsolution_phase_num
Definition: islec.h:198
char species_a[64]
Definition: islec.h:142
char species_s3[64]
Definition: islec.h:117
int species_num
Definition: islec.h:150
IIBINPARAM * ii_bin_params
Definition: islec.h:159
char species_s1[64]
Definition: islec.h:105
double Qssss[6]
Definition: islec.h:127
int species_num
Definition: islec.h:156
SPECIES * gas_species
Definition: islec.h:151
double A0
Definition: islec.h:144
SPECIES * aqueous_species
Definition: islec.h:157
double Usss[6]
Definition: islec.h:109
int species_num
Definition: islec.h:174
int niii_qua_param_num
Definition: islec.h:166
double alpha
Definition: islec.h:89
char species_s1[64]
Definition: islec.h:133
NNBINPARAM * nn_bin_params
Definition: islec.h:161
char BLOCK_KEYWORDS[2][64]
Definition: islec.h:49
int charge
Definition: islec.h:80
double A1
Definition: islec.h:145
NIITERPARAM * nii_ter_params
Definition: islec.h:163
int total_phase_num
Definition: islec.h:199
SOLIDSOLUTION_PHASE * solidsolution
Definition: islec.h:191
double Wsss[6]
Definition: islec.h:118
char species_s2[64]
Definition: islec.h:134
GAS_PHASE * gas
Definition: islec.h:188
int nn_bin_param_num
Definition: islec.h:160
char species_s2[64]
Definition: islec.h:124
double thermo_coeff[7]
Definition: islec.h:82
bool load_db(char *input, char *temp)
Definition: load_db.c:718
Definition: islec.h:77
char species_s2[64]
Definition: islec.h:98
char species_s3[64]
Definition: islec.h:135
double Wsss[6]
Definition: islec.h:108
int aqueous_phase_num
Definition: islec.h:196
double Vsss[6]
Definition: islec.h:110
SOLID_PHASE * solids
Definition: islec.h:190
SPECIES * solid_species
Definition: islec.h:175
Definition: islec.h:70
double * elements
Definition: islec.h:81
char species_s4[64]
Definition: islec.h:136
char species_s4[64]
Definition: islec.h:126
char species_s3[64]
Definition: islec.h:125
char species_b[64]
Definition: islec.h:143
int total_species_num
Definition: islec.h:200
char PHASE_KEYWORDS[4][64]
Definition: islec.h:52
double B1ss[6]
Definition: islec.h:92
char phase_keyword[32]
Definition: islec.h:203
double Yssss[6]
Definition: islec.h:128
char block_keyword[32]
Definition: islec.h:202
int nii_ter_param_num
Definition: islec.h:162
double Yssss[6]
Definition: islec.h:137
char species_s2[64]
Definition: islec.h:106
IIITERPARAM * iii_ter_params
Definition: islec.h:165
SUBRPARAM * params
Definition: islec.h:183
NNIIQUAPARAM * nnii_qua_params
Definition: islec.h:169
PHASES phases
Definition: islec.h:206
char species_symbol[64]
Definition: islec.h:79
char species_s2[64]
Definition: islec.h:88
int total_comp_num
Definition: islec.h:194
double alpha1
Definition: islec.h:90
char species_s1[64]
Definition: islec.h:123
int solid_phase_num
Definition: islec.h:197
NIIIQUAPARAM * niii_qua_params
Definition: islec.h:167
int iii_ter_param_num
Definition: islec.h:164
char species_s1[64]
Definition: islec.h:115
int gas_phase_num
Definition: islec.h:195
int nnii_qua_param_num
Definition: islec.h:168
double Uss[6]
Definition: islec.h:100
double Wss[6]
Definition: islec.h:99
SPECIES * solidsolution_species
Definition: islec.h:181
ELEMENT * components
Definition: islec.h:205