-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructure.c
More file actions
executable file
·221 lines (209 loc) · 5.91 KB
/
Copy pathstructure.c
File metadata and controls
executable file
·221 lines (209 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* This file places data from files and calculated
results into the correct data stucture. This file
also allocates memory for the data structures
dynamically */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "main.h"
extern int models_done;
extern char light_key[50];
extern char heavy_key[50];
extern antoine_struct *a_ptr;
extern unsigned long species;
extern unsigned long numer_of_antoine_data_for_species[100];
long double total_pressure;
void remove_links(void);
void azeotrope_creation(void);
void structure_creation(void);
void feed_array_creation(void);
void insert_antoine_data(void);
void flash_array_creation(void);
void batch_array_creation(void);
void antoine_array_creation(void);
void fractional_distillation_array_creation(void);
void structure_creation(void)
{
feed_array_creation();
antoine_array_creation();
remove_links();
azeotrope_creation();
return;
}
void feed_array_creation(void)
{
int i;
antoine_struct *new_a_ptr = a_ptr;
f_array = NULL;
f_array = (feed_struct**)malloc(sizeof(feed_struct **)*(species+1));
if(f_array == NULL)
{
printf("INSUFFICIENT MEMORY TO CREATE FEED ARRAY\nEXIT PROGRAM\n");
exit(9);
}
for(i = 0; i < species; i++)
{
f_array[i] = (feed_struct*)malloc(sizeof(feed_struct));
if(f_array[i] == NULL)
{
printf("INSUFFICIENT MEMORY TO ADD FEED STRUCTURE\nEXIT PROGRAM\n");
exit(9);
}
if(i == 0)
{
strcpy(f_array[i] -> chemical, a_ptr -> chemical);
}
if(i != 0)
{
if(strcmp(f_array[i-1] -> chemical, a_ptr -> chemical) != 0)
{
strcpy(f_array[i] -> chemical, a_ptr -> chemical);
}
else
{
i--;
}
}
a_ptr=a_ptr->next;
}
a_ptr = new_a_ptr;
f_array[i] = NULL;
return;
}
void antoine_array_creation(void)
{
int i, j;
antoine_struct *new_a_ptr = a_ptr;
for(i = 0; i < species; i++)
{
a_array = NULL;
a_array = (antoine_struct**)malloc(sizeof(antoine_struct **) * numer_of_antoine_data_for_species[i]);
if(a_array == NULL)
{
printf("INSUFFICIENT MEMORY TO CREATE ANTOINE ARRAY\nEXIT PROGRAM\n");
exit(9);
}
f_array[i] -> a_array = a_array;
for(j = 0; j < numer_of_antoine_data_for_species[i]; j++)
{
f_array[i] -> a_array[j] = a_ptr;
a_ptr = a_ptr -> next;
}
f_array[i] -> a_array[j] = NULL;
}
a_ptr = new_a_ptr;
f_array[i] = NULL;
return;
}
void azeotrope_creation(void)
{
int i;
azeotrope_struct *az_ptr;
for(i = 0; i < species; i++)
{
az_ptr = (azeotrope_struct*)malloc(sizeof(azeotrope_struct));
if( az_ptr == NULL)
{
printf("INSUFFICIENT MEMORY TO ADD AZEOTROPE STRUCTURE\nEXIT PROGRAM\n");
exit(9);
}
f_array[i] -> az_ptr = az_ptr;
}
return;
}
void flash_array_creation(void)
{
int i, j;
for(i = 0; i < species; i++)
{
v_array = NULL;
v_array = (vaporization_struct**)malloc(sizeof(vaporization_struct **) * 3.0);
if(v_array == NULL)
{
printf("INSUFFICIENT MEMORY TO CREATE VAPORIZATION ARRAY\nEXIT PROGRAM\n");
exit(9);
}
f_array[i] -> v_array = v_array;
for(j = 0; j < 2; j++)
{
f_array[i] -> v_array[j] = (vaporization_struct *)malloc(sizeof(vaporization_struct));
if(f_array[i] == NULL)
{
printf("INSUFFICIENT MEMORY TO ADD VAPORIZATION STRUCTURE\nEXIT PROGRAM\n");
exit(9);
}
strcpy(f_array[i] -> v_array[j] -> chemical, f_array[i] -> chemical);
f_array[i] -> v_array[j] -> total_pressure = total_pressure;
}
f_array[i] -> v_array[j] = NULL;
}
return;
}
void batch_array_creation(void)
{
int i, j;
b_array = NULL;
for(i = 0; i < species; i++)
{
b_array = (batch_struct**)malloc(sizeof(batch_struct **) * 2.0);
if(b_array == NULL)
{
printf("INSUFFICIENT MEMORY TO CREATE BATCH ARRAY\nEXIT PROGRAM\n");
exit(9);
}
f_array[i] -> b_array = b_array;
for(j = 0; j < 1; j++)
{
f_array[i] -> b_array[j] = (batch_struct *)malloc(sizeof(batch_struct));
if(f_array[i] == NULL)
{
printf("INSUFFICIENT MEMORY TO ADD BATCH STRUCTURE\nEXIT PROGRAM\n");
exit(9);
}
strcpy(f_array[i] -> b_array[j] -> chemical, f_array[i] -> chemical);
f_array[i] -> b_array[j] -> total_pressure = total_pressure;
}
f_array[i] -> b_array[j] = NULL;
}
return;
}
void fractional_distillation_array_creation(void)
{
int i, j;
fd_array = NULL;
for(i = 0; i < species; i++)
{
fd_array = (fractional_distillation_struct**)malloc(sizeof(fractional_distillation_struct **) * 2.0);
if(fd_array == NULL)
{
printf("INSUFFICIENT MEMORY TO ADD DATA\nEXIT PROGRAM\n");
exit(9);
}
f_array[i] -> fd_array = fd_array;
for(j = 0; j < 1; j++)
{
f_array[i] -> fd_array[j] = (fractional_distillation_struct *)malloc(sizeof(fractional_distillation_struct));
if(f_array[i] == NULL)
{
printf("INSUFFICIENT MEMORY TO ADD DATA\nEXIT PROGRAM\n");
exit(9);
}
}
f_array[i] -> fd_array[j] = NULL;
}
return;
}
void remove_links(void)
{
int i, j;
for(i = 0; i < species; i++)
{
for(j = 0; j < numer_of_antoine_data_for_species[i]; j++)
{
f_array[i] -> a_array[j]->next = NULL;
}
f_array[i] -> a_array[j] = NULL;
}
return;
}