ISLEC  Version 4.2
load_exp.c
Go to the documentation of this file.
1 /* src/load_exp.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 
32 extern bool load_exp (char *exp)
33 {
34  FILE *exp_fp;
35 
36  if ((exp_fp = fopen (exp, "r")) == NULL)
37  {
38  printf ("Open Experimental Data File Error!!!\n");
39  return false;
40  }
41  else
42  {
43  int i, j, k;
44  int rv;
45 
46  // load water activity data
47  rv = fscanf (exp_fp, "%d\n", &total_exp_aw_num);
48  if (rv != 1)
49  {
50  printf ("Load Experimental Data File Error!!!\n");
51  exit (1);
52  }
53 
54  printf ("%d\n", total_exp_aw_num);
55 
56  expaw = (EXPAW *)malloc (sizeof (EXPAW) * total_exp_aw_num);
57 
58  for (i = 0; i < total_exp_aw_num; i ++)
59  {
60  rv = fscanf (exp_fp, "%lf\t%lf", &expaw[i].T, &expaw[i].P);
61  if (rv != 2)
62  {
63  printf ("Load Experimental Data File Error!!!\n");
64  exit (1);
65  }
66 
67  printf ("%lf\t%lf\t", expaw[i].T, expaw[i].P);
68 
69  expaw[i].component = (double *) malloc(sizeof (double) * total_comp_num);
70 
71  for (j = 0; j < total_comp_num; j++)
72  {
73  rv = fscanf (exp_fp, "\t%lf", &expaw[i].component[j]);
74 
75  if (rv != 1)
76  {
77  printf ("Load Experimental Data File Error!!!\n");
78  exit (1);
79  }
80 
81  printf ("%lf\t", expaw[i].component[j]);
82  }
83 
84  rv = fscanf (exp_fp, "\t%d\t%lf\t%lf\n", &expaw[i].index, &expaw[i].value, &expaw[i].sigma);
85  if (rv != 3)
86  {
87  printf ("Load Experimental Data File Error!!!\n");
88  exit (1);
89  }
90 
91  printf ("%d\t%lf\t%lf\n", expaw[i].index, expaw[i].value, expaw[i].sigma);
92  }
93 
94  // load pH data
95  rv = fscanf (exp_fp, "%d\n", &total_exp_ph_num);
96  if (rv != 1)
97  {
98  printf ("Load Experimental Data File Error!!!\n");
99  exit (1);
100  }
101 
102  printf ("%d\n", total_exp_ph_num);
103 
104  expph = (EXPPH *)malloc (sizeof (EXPPH) * total_exp_ph_num);
105 
106  for (i = 0; i < total_exp_ph_num; i ++)
107  {
108  rv = fscanf (exp_fp, "%lf\t%lf", &expph[i].T, &expph[i].P);
109  if (rv != 2)
110  {
111  printf ("Load Experimental Data File Error!!!\n");
112  exit (1);
113  }
114 
115  printf ("%lf\t%lf\t", expph[i].T, expph[i].P);
116 
117  expph[i].component = (double *) malloc(sizeof (double) * total_comp_num);
118 
119  for (j = 0; j < total_comp_num; j++)
120  {
121  rv = fscanf (exp_fp, "\t%lf", &expph[i].component[j]);
122 
123  if (rv != 1)
124  {
125  printf ("Load Experimental Data File Error!!!\n");
126  exit (1);
127  }
128 
129  printf ("%lf\t", expph[i].component[j]);
130  }
131 
132  rv = fscanf (exp_fp, "\t%d\t%lf\t%lf\n", &expph[i].index, &expph[i].value, &expph[i].sigma);
133  if (rv != 3)
134  {
135  printf ("Load Experimental Data File Error!!!\n");
136  exit (1);
137  }
138 
139  printf ("%d\t%lf\t%lf\n", expph[i].index, expph[i].value, expph[i].sigma);
140  }
141 
142  // load solubility data
143  rv = fscanf (exp_fp, "%d\n", &total_exp_sol_num);
144  if (rv != 1)
145  {
146  printf ("Load Experimental Data File Error!!!\n");
147  exit (1);
148  }
149 
150  printf ("%d\n", total_exp_sol_num);
151 
152  expsol = (EXPSOL *)malloc (sizeof (EXPSOL) * total_exp_sol_num);
153 
154 
155  for (i = 0; i < total_exp_sol_num; i ++)
156  {
157  rv = fscanf (exp_fp, "%lf\t%lf", &expsol[i].T, &expsol[i].P);
158  if (rv != 2)
159  {
160  printf ("Load Experimental Data File Error!!!\n");
161  exit (1);
162  }
163 
164  printf ("%lf\t%lf\t", expsol[i].T, expsol[i].P);
165 
166  expsol[i].component = (double *) malloc(sizeof (double) * total_comp_num);
167 
168  for (j = 0; j < total_comp_num; j++)
169  {
170  rv = fscanf (exp_fp, "\t%lf", &expsol[i].component[j]);
171 
172  if (rv != 1)
173  {
174  printf ("Load Experimental Data File Error!!!\n");
175  exit (1);
176  }
177 
178  printf ("%lf\t", expsol[i].component[j]);
179  }
180 
181  rv = fscanf (exp_fp, "\t%d", &expsol[i].index);
182  if (rv != 1)
183  {
184  printf ("Load Experimental Data File Error!!!\n");
185  exit (1);
186  }
187  printf ("%d\t", expsol[i].index);
188 
189  expsol[i].species = (double *) malloc(sizeof (double) * phases.aqueous[expsol[i].index].species_num);
190  for (j = 0; j < phases.aqueous[expsol[i].index].species_num; j++)
191  {
192  rv = fscanf (exp_fp, "\t%lf", &expsol[i].species[j]);
193 
194  if (rv != 1)
195  {
196  printf ("Load Experimental Data File Error!!!\n");
197  exit (1);
198  }
199 
200  printf ("%lf\t", expsol[i].species[j]);
201  }
202 
203  rv = fscanf (exp_fp, "\t%lf\t%lf\n", &expsol[i].lnk, &expsol[i].sigma);
204  if (rv != 2)
205  {
206  printf ("Load Experimental Data File Error!!!\n");
207  exit (1);
208  }
209  printf ("%lf\t%lf\n", expsol[i].lnk, expsol[i].sigma);
210  }
211  }
212 
213  return true;
214 }
AQUEOUS_PHASE * aqueous
Definition: islec.h:189
int index
Definition: islre.h:218
bool load_exp(char *exp)
Definition: load_exp.c:32
int species_num
Definition: islec.h:156
double * species
Definition: islre.h:219
Definition: islre.h:213
double * component
Definition: islre.h:208
int total_exp_sol_num
Definition: islre.h:280
double * component
Definition: islre.h:217
double * component
Definition: islre.h:198
EXPAW * expaw
Definition: islre.h:285
EXPSOL * expsol
Definition: islre.h:286
int total_exp_aw_num
Definition: islre.h:272
Definition: islre.h:203
PHASES phases
Definition: islec.h:206
int total_comp_num
Definition: islec.h:194
int total_exp_ph_num
Definition: islre.h:273
EXPPH * expph
Definition: islre.h:287
Definition: islre.h:193