ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
xml.c
Go to the documentation of this file.
1 
6 #include "header.h"
7 
11 int read_int_static_array(char * buffer, int /*@unused@*/ buffer_size, int * j, int * int_static_array, int /*@unused@*/ size)
12 {
13  int arraycount = 0;
14  int array_k;
15  char arraydata[100000];
16 
17  while(buffer[(*j)] != '{')
18  {
19  if(buffer[(*j)] != ' ') return -1;
20  else if(buffer[(*j)] == '\0') return -1;
21  else (*j)++;
22  }
23  (*j)++;
24 
25  while(buffer[(*j)] != '}')
26  {
27  array_k = 0;
28  while(buffer[(*j)] != ',' && buffer[(*j)] != '}')
29  {
30  if(buffer[(*j)] == '\0') return -1;
31  arraydata[array_k] = buffer[(*j)];
32  array_k++;
33  (*j)++;
34  }
35  arraydata[array_k] = '\0';
36  if (arraycount < size) int_static_array[arraycount] = atoi(arraydata);
37  arraycount++;
38  if(buffer[(*j)] != '}') (*j)++;
39  }
40 
41  if (arraycount > size)
42  {
43  fprintf(stderr, "WARNING: %d 'int' values provided for static array of size %d. Surplus values ignored.\n",
44  arraycount, size);
45  }
46 
47  (*j)++;
48  return 0;
49 }
50 
54 int read_float_static_array(char * buffer, int /*@unused@*/ buffer_size, int * j, float * float_static_array, int /*@unused@*/ size)
55 {
56  int arraycount = 0;
57  int array_k;
58  char arraydata[100000];
59 
60  while(buffer[(*j)] != '{')
61  {
62  if(buffer[(*j)] != ' ') return -1;
63  else if(buffer[(*j)] == '\0') return -1;
64  else (*j)++;
65  }
66  (*j)++;
67 
68  while(buffer[(*j)] != '}')
69  {
70  array_k = 0;
71  while(buffer[(*j)] != ',' && buffer[(*j)] != '}')
72  {
73  if(buffer[(*j)] == '\0') return -1;
74  arraydata[array_k] = buffer[(*j)];
75  array_k++;
76  (*j)++;
77  }
78  arraydata[array_k] = '\0';
79  if (arraycount < size) float_static_array[arraycount] = (float)atof(arraydata);
80  arraycount++;
81  if(buffer[(*j)] != '}') (*j)++;
82  }
83 
84  if (arraycount > size)
85  {
86  fprintf(stderr, "WARNING: %d 'float' values provided for static array of size %d. Surplus values ignored.\n",
87  arraycount, size);
88  }
89 
90  (*j)++;
91  return 0;
92 }
93 
97 int read_double_static_array(char * buffer, int /*@unused@*/ buffer_size, int * j, double * double_static_array, int /*@unused@*/ size)
98 {
99  int arraycount = 0;
100  int array_k;
101  char arraydata[100000];
102 
103  while(buffer[(*j)] != '{')
104  {
105  if(buffer[(*j)] != ' ') return -1;
106  else if(buffer[(*j)] == '\0') return -1;
107  else (*j)++;
108  }
109  (*j)++;
110 
111  while(buffer[(*j)] != '}')
112  {
113  array_k = 0;
114  while(buffer[(*j)] != ',' && buffer[(*j)] != '}')
115  {
116  if(buffer[(*j)] == '\0') return -1;
117  arraydata[array_k] = buffer[(*j)];
118  array_k++;
119  (*j)++;
120  }
121  arraydata[array_k] = '\0';
122  if (arraycount < size) double_static_array[arraycount] = atof(arraydata);
123  arraycount++;
124  if(buffer[(*j)] != '}') (*j)++;
125  }
126 
127  if (arraycount > size)
128  {
129  fprintf(stderr, "WARNING: %d 'double' values provided for static array of size %d. Surplus values ignored.\n",
130  arraycount, size);
131  }
132 
133  (*j)++;
134  return 0;
135 }
136 
140 int read_char_static_array(char * buffer, int /*@unused@*/ buffer_size, int * j, char * char_static_array, int size)
141 {
142  int arraycount;
143 
144  while(buffer[(*j)] == ' ')
145  {
146  (*j)++;
147  }
148 
149  for(arraycount = 0; arraycount < size; arraycount++)
150  {
151  char_static_array[arraycount] = buffer[(*j)];
152  (*j)++;
153  }
154 
155  //(*j)++;
156  return 0;
157 }
158 
162 int read_int_dynamic_array(char * buffer, int /*@unused@*/ buffer_size, int * j, int_array * int_dynamic_array)
163 {
164  int arraycount = 0;
165  int array_k;
166  char arraydata[100000];
167 
168  while(buffer[(*j)] != '{')
169  {
170  if(buffer[(*j)] != ' ') return -1;
171  else if(buffer[(*j)] == '\0') return -1;
172  else (*j)++;
173  }
174  (*j)++;
175 
176  while(buffer[(*j)] != '}')
177  {
178  array_k = 0;
179  while(buffer[(*j)] != ',' && buffer[(*j)] != '}')
180  {
181  if(buffer[(*j)] == '\0') return -1;
182  arraydata[array_k] = buffer[(*j)];
183  array_k++;
184  (*j)++;
185  }
186  arraydata[array_k] = '\0';
187  add_int(int_dynamic_array, atoi(arraydata));
188  arraycount++;
189  if(buffer[(*j)] != '}') (*j)++;
190  }
191 
192  (*j)++;
193  return 0;
194 }
195 
199 int read_float_dynamic_array(char * buffer, int /*@unused@*/ buffer_size, int * j, float_array * float_dynamic_array)
200 {
201  int arraycount = 0;
202  int array_k;
203  char arraydata[100000];
204 
205  while(buffer[(*j)] != '{')
206  {
207  if(buffer[(*j)] != ' ') return -1;
208  else if(buffer[(*j)] == '\0') return -1;
209  else (*j)++;
210  }
211  (*j)++;
212 
213  while(buffer[(*j)] != '}')
214  {
215  array_k = 0;
216  while(buffer[(*j)] != ',' && buffer[(*j)] != '}')
217  {
218  if(buffer[(*j)] == '\0') return -1;
219  arraydata[array_k] = buffer[(*j)];
220  array_k++;
221  (*j)++;
222  }
223  arraydata[array_k] = '\0';
224  add_float(float_dynamic_array, (float)atof(arraydata));
225  arraycount++;
226  if(buffer[(*j)] != '}') (*j)++;
227  }
228 
229  (*j)++;
230  return 0;
231 }
232 
236 int read_double_dynamic_array(char * buffer, int /*@unused@*/ buffer_size, int * j, double_array * double_dynamic_array)
237 {
238  int arraycount = 0;
239  int array_k;
240  char arraydata[100000];
241 
242  while(buffer[(*j)] != '{')
243  {
244  if(buffer[(*j)] != ' ') return -1;
245  else if(buffer[(*j)] == '\0') return -1;
246  else (*j)++;
247  }
248  (*j)++;
249 
250  while(buffer[(*j)] != '}')
251  {
252  array_k = 0;
253  while(buffer[(*j)] != ',' && buffer[(*j)] != '}')
254  {
255  if(buffer[(*j)] == '\0') return -1;
256  arraydata[array_k] = buffer[(*j)];
257  array_k++;
258  (*j)++;
259  }
260  arraydata[array_k] = '\0';
261  add_double(double_dynamic_array, atof(arraydata));
262  arraycount++;
263  if(buffer[(*j)] != '}') (*j)++;
264  }
265 
266  (*j)++;
267  return 0;
268 }
269 
273 int read_char_dynamic_array(char * buffer, int /*@unused@*/ buffer_size, int * j, char_array * char_dynamic_array)
274 {
275  if(*j > buffer_size) return -1;
276 
277  while(buffer[(*j)] == ' ')
278  {
279  (*j)++;
280  }
281 
282  while(buffer[(*j)] != '\0' && buffer[(*j)] != ',' && buffer[(*j)] != '}')
283  {
284  add_char(char_dynamic_array, buffer[(*j)]);
285  (*j)++;
286  }
287 
288  return 0;
289 }
290 
291 
295 int read_transaction(char * buffer, int /*@unused@*/ buffer_size, int * j, transaction * temp_datatype)
296 {
297  int array_k;
298  char arraydata[100000];
299 
300 
301  while(buffer[(*j)] != '{')
302  {
303  if(buffer[(*j)] != ' ') return -1;
304  else if(buffer[(*j)] == '\0') return -1;
305  else (*j)++;
306  }
307  (*j)++;
308 
309  (*temp_datatype).quantity = 0;
310  array_k = 0;
311  while(buffer[*j] != ',')
312  {
313  if(buffer[(*j)] == '\0') return -1;
314  arraydata[array_k] = buffer[*j];
315  array_k++;
316  (*j)++;
317  }
318  arraydata[array_k] = '\0';
319  (*temp_datatype).quantity = atoi(arraydata);
320  (*j)++;
321  (*temp_datatype).avg_price = 0.0;
322  array_k = 0;
323  while(buffer[*j] != '}')
324  {
325  if(buffer[(*j)] == '\0') return -1;
326  arraydata[array_k] = buffer[*j];
327  array_k++;
328  (*j)++;
329  }
330  arraydata[array_k] = '\0';
331  (*temp_datatype).avg_price = atof(arraydata);
332  (*j)++;
333 
334  return 0;
335 }
336 
337 int read_transaction_dynamic_array(char * buffer, int buffer_size, int * j, transaction_array * temp_datatype_array)
338 {
339  int arraycount = 0;
340  int rc;
341 
342 
343 
344 
345  while(buffer[(*j)] != '{')
346  {
347  if(buffer[(*j)] != ' ') return -1;
348  else if(buffer[(*j)] == '\0') return -1;
349  else (*j)++;
350  }
351  (*j)++;
352 
353  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
354  {
355  if(buffer[(*j)] == '{')
356  {
357  add_transaction(temp_datatype_array, 0, 0.0);
358  rc = read_transaction(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
359  if(rc != 0) { printf("Error: reading variable 'transaction' of type '\n"); return -1; }
360  arraycount++;
361  (*j)++;
362  }
363  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
364  }
365 
366 
367 
368  return 0;
369 }
370 
371 int read_transaction_static_array(char * buffer, int buffer_size, int * j, transaction * temp_datatype_array, int size)
372 {
373  int arraycount;
374  int rc;
375 
376  while(buffer[(*j)] != '{')
377  {
378  if(buffer[(*j)] != ' ') return -1;
379  else if(buffer[(*j)] == '\0') return -1;
380  else (*j)++;
381  }
382  (*j)++;
383 
384  for(arraycount = 0; arraycount < size; arraycount++)
385  {
386  rc = read_transaction(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
387  if(rc != 0) { printf("Error: reading variable 'transaction' of type '\n"); return -1; }
388  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
389  }
390 
391  (*j)++;
392  return 0;
393 }
394 
398 int read_buyer(char * buffer, int /*@unused@*/ buffer_size, int * j, buyer * temp_datatype)
399 {
400  int array_k;
401  char arraydata[100000];
402 
403 
404  while(buffer[(*j)] != '{')
405  {
406  if(buffer[(*j)] != ' ') return -1;
407  else if(buffer[(*j)] == '\0') return -1;
408  else (*j)++;
409  }
410  (*j)++;
411 
412  (*temp_datatype).id = 0;
413  array_k = 0;
414  while(buffer[*j] != ',')
415  {
416  if(buffer[(*j)] == '\0') return -1;
417  arraydata[array_k] = buffer[*j];
418  array_k++;
419  (*j)++;
420  }
421  arraydata[array_k] = '\0';
422  (*temp_datatype).id = atoi(arraydata);
423  (*j)++;
424  (*temp_datatype).budget = 0.0;
425  array_k = 0;
426  while(buffer[*j] != '}')
427  {
428  if(buffer[(*j)] == '\0') return -1;
429  arraydata[array_k] = buffer[*j];
430  array_k++;
431  (*j)++;
432  }
433  arraydata[array_k] = '\0';
434  (*temp_datatype).budget = atof(arraydata);
435  (*j)++;
436 
437  return 0;
438 }
439 
440 int read_buyer_dynamic_array(char * buffer, int buffer_size, int * j, buyer_array * temp_datatype_array)
441 {
442  int arraycount = 0;
443  int rc;
444 
445 
446 
447 
448  while(buffer[(*j)] != '{')
449  {
450  if(buffer[(*j)] != ' ') return -1;
451  else if(buffer[(*j)] == '\0') return -1;
452  else (*j)++;
453  }
454  (*j)++;
455 
456  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
457  {
458  if(buffer[(*j)] == '{')
459  {
460  add_buyer(temp_datatype_array, 0, 0.0);
461  rc = read_buyer(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
462  if(rc != 0) { printf("Error: reading variable 'buyer' of type '\n"); return -1; }
463  arraycount++;
464  (*j)++;
465  }
466  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
467  }
468 
469 
470 
471  return 0;
472 }
473 
474 int read_buyer_static_array(char * buffer, int buffer_size, int * j, buyer * temp_datatype_array, int size)
475 {
476  int arraycount;
477  int rc;
478 
479  while(buffer[(*j)] != '{')
480  {
481  if(buffer[(*j)] != ' ') return -1;
482  else if(buffer[(*j)] == '\0') return -1;
483  else (*j)++;
484  }
485  (*j)++;
486 
487  for(arraycount = 0; arraycount < size; arraycount++)
488  {
489  rc = read_buyer(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
490  if(rc != 0) { printf("Error: reading variable 'buyer' of type '\n"); return -1; }
491  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
492  }
493 
494  (*j)++;
495  return 0;
496 }
497 
501 int read_seller(char * buffer, int /*@unused@*/ buffer_size, int * j, seller * temp_datatype)
502 {
503  int array_k;
504  char arraydata[100000];
505 
506 
507  while(buffer[(*j)] != '{')
508  {
509  if(buffer[(*j)] != ' ') return -1;
510  else if(buffer[(*j)] == '\0') return -1;
511  else (*j)++;
512  }
513  (*j)++;
514 
515  (*temp_datatype).id = 0;
516  array_k = 0;
517  while(buffer[*j] != ',')
518  {
519  if(buffer[(*j)] == '\0') return -1;
520  arraydata[array_k] = buffer[*j];
521  array_k++;
522  (*j)++;
523  }
524  arraydata[array_k] = '\0';
525  (*temp_datatype).id = atoi(arraydata);
526  (*j)++;
527  (*temp_datatype).price = 0.0;
528  array_k = 0;
529  while(buffer[*j] != ',')
530  {
531  if(buffer[(*j)] == '\0') return -1;
532  arraydata[array_k] = buffer[*j];
533  array_k++;
534  (*j)++;
535  }
536  arraydata[array_k] = '\0';
537  (*temp_datatype).price = atof(arraydata);
538  (*j)++;
539  (*temp_datatype).inventory = 0;
540  array_k = 0;
541  while(buffer[*j] != ',')
542  {
543  if(buffer[(*j)] == '\0') return -1;
544  arraydata[array_k] = buffer[*j];
545  array_k++;
546  (*j)++;
547  }
548  arraydata[array_k] = '\0';
549  (*temp_datatype).inventory = atoi(arraydata);
550  (*j)++;
551  (*temp_datatype).inv_price = 0.0;
552  array_k = 0;
553  while(buffer[*j] != '}')
554  {
555  if(buffer[(*j)] == '\0') return -1;
556  arraydata[array_k] = buffer[*j];
557  array_k++;
558  (*j)++;
559  }
560  arraydata[array_k] = '\0';
561  (*temp_datatype).inv_price = atof(arraydata);
562  (*j)++;
563 
564  return 0;
565 }
566 
567 int read_seller_dynamic_array(char * buffer, int buffer_size, int * j, seller_array * temp_datatype_array)
568 {
569  int arraycount = 0;
570  int rc;
571 
572 
573 
574 
575 
576 
577  while(buffer[(*j)] != '{')
578  {
579  if(buffer[(*j)] != ' ') return -1;
580  else if(buffer[(*j)] == '\0') return -1;
581  else (*j)++;
582  }
583  (*j)++;
584 
585  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
586  {
587  if(buffer[(*j)] == '{')
588  {
589  add_seller(temp_datatype_array, 0, 0.0, 0, 0.0);
590  rc = read_seller(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
591  if(rc != 0) { printf("Error: reading variable 'seller' of type '\n"); return -1; }
592  arraycount++;
593  (*j)++;
594  }
595  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
596  }
597 
598 
599 
600  return 0;
601 }
602 
603 int read_seller_static_array(char * buffer, int buffer_size, int * j, seller * temp_datatype_array, int size)
604 {
605  int arraycount;
606  int rc;
607 
608  while(buffer[(*j)] != '{')
609  {
610  if(buffer[(*j)] != ' ') return -1;
611  else if(buffer[(*j)] == '\0') return -1;
612  else (*j)++;
613  }
614  (*j)++;
615 
616  for(arraycount = 0; arraycount < size; arraycount++)
617  {
618  rc = read_seller(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
619  if(rc != 0) { printf("Error: reading variable 'seller' of type '\n"); return -1; }
620  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
621  }
622 
623  (*j)++;
624  return 0;
625 }
626 
630 int read_vacancy(char * buffer, int /*@unused@*/ buffer_size, int * j, vacancy * temp_datatype)
631 {
632  int array_k;
633  char arraydata[100000];
634 
635 
636  while(buffer[(*j)] != '{')
637  {
638  if(buffer[(*j)] != ' ') return -1;
639  else if(buffer[(*j)] == '\0') return -1;
640  else (*j)++;
641  }
642  (*j)++;
643 
644  (*temp_datatype).id = 0;
645  array_k = 0;
646  while(buffer[*j] != ',')
647  {
648  if(buffer[(*j)] == '\0') return -1;
649  arraydata[array_k] = buffer[*j];
650  array_k++;
651  (*j)++;
652  }
653  arraydata[array_k] = '\0';
654  (*temp_datatype).id = atoi(arraydata);
655  (*j)++;
656  (*temp_datatype).wage = 0.0;
657  array_k = 0;
658  while(buffer[*j] != '}')
659  {
660  if(buffer[(*j)] == '\0') return -1;
661  arraydata[array_k] = buffer[*j];
662  array_k++;
663  (*j)++;
664  }
665  arraydata[array_k] = '\0';
666  (*temp_datatype).wage = atof(arraydata);
667  (*j)++;
668 
669  return 0;
670 }
671 
672 int read_vacancy_dynamic_array(char * buffer, int buffer_size, int * j, vacancy_array * temp_datatype_array)
673 {
674  int arraycount = 0;
675  int rc;
676 
677 
678 
679 
680  while(buffer[(*j)] != '{')
681  {
682  if(buffer[(*j)] != ' ') return -1;
683  else if(buffer[(*j)] == '\0') return -1;
684  else (*j)++;
685  }
686  (*j)++;
687 
688  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
689  {
690  if(buffer[(*j)] == '{')
691  {
692  add_vacancy(temp_datatype_array, 0, 0.0);
693  rc = read_vacancy(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
694  if(rc != 0) { printf("Error: reading variable 'vacancy' of type '\n"); return -1; }
695  arraycount++;
696  (*j)++;
697  }
698  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
699  }
700 
701 
702 
703  return 0;
704 }
705 
706 int read_vacancy_static_array(char * buffer, int buffer_size, int * j, vacancy * temp_datatype_array, int size)
707 {
708  int arraycount;
709  int rc;
710 
711  while(buffer[(*j)] != '{')
712  {
713  if(buffer[(*j)] != ' ') return -1;
714  else if(buffer[(*j)] == '\0') return -1;
715  else (*j)++;
716  }
717  (*j)++;
718 
719  for(arraycount = 0; arraycount < size; arraycount++)
720  {
721  rc = read_vacancy(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
722  if(rc != 0) { printf("Error: reading variable 'vacancy' of type '\n"); return -1; }
723  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
724  }
725 
726  (*j)++;
727  return 0;
728 }
729 
733 int read_employee(char * buffer, int /*@unused@*/ buffer_size, int * j, employee * temp_datatype)
734 {
735  int array_k;
736  char arraydata[100000];
737 
738 
739  while(buffer[(*j)] != '{')
740  {
741  if(buffer[(*j)] != ' ') return -1;
742  else if(buffer[(*j)] == '\0') return -1;
743  else (*j)++;
744  }
745  (*j)++;
746 
747  (*temp_datatype).id = 0;
748  array_k = 0;
749  while(buffer[*j] != ',')
750  {
751  if(buffer[(*j)] == '\0') return -1;
752  arraydata[array_k] = buffer[*j];
753  array_k++;
754  (*j)++;
755  }
756  arraydata[array_k] = '\0';
757  (*temp_datatype).id = atoi(arraydata);
758  (*j)++;
759  (*temp_datatype).wage = 0.0;
760  array_k = 0;
761  while(buffer[*j] != '}')
762  {
763  if(buffer[(*j)] == '\0') return -1;
764  arraydata[array_k] = buffer[*j];
765  array_k++;
766  (*j)++;
767  }
768  arraydata[array_k] = '\0';
769  (*temp_datatype).wage = atof(arraydata);
770  (*j)++;
771 
772  return 0;
773 }
774 
775 int read_employee_dynamic_array(char * buffer, int buffer_size, int * j, employee_array * temp_datatype_array)
776 {
777  int arraycount = 0;
778  int rc;
779 
780 
781 
782 
783  while(buffer[(*j)] != '{')
784  {
785  if(buffer[(*j)] != ' ') return -1;
786  else if(buffer[(*j)] == '\0') return -1;
787  else (*j)++;
788  }
789  (*j)++;
790 
791  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
792  {
793  if(buffer[(*j)] == '{')
794  {
795  add_employee(temp_datatype_array, 0, 0.0);
796  rc = read_employee(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
797  if(rc != 0) { printf("Error: reading variable 'employee' of type '\n"); return -1; }
798  arraycount++;
799  (*j)++;
800  }
801  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
802  }
803 
804 
805 
806  return 0;
807 }
808 
809 int read_employee_static_array(char * buffer, int buffer_size, int * j, employee * temp_datatype_array, int size)
810 {
811  int arraycount;
812  int rc;
813 
814  while(buffer[(*j)] != '{')
815  {
816  if(buffer[(*j)] != ' ') return -1;
817  else if(buffer[(*j)] == '\0') return -1;
818  else (*j)++;
819  }
820  (*j)++;
821 
822  for(arraycount = 0; arraycount < size; arraycount++)
823  {
824  rc = read_employee(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
825  if(rc != 0) { printf("Error: reading variable 'employee' of type '\n"); return -1; }
826  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
827  }
828 
829  (*j)++;
830  return 0;
831 }
832 
836 int read_mortgage(char * buffer, int /*@unused@*/ buffer_size, int * j, mortgage * temp_datatype)
837 {
838  int array_k;
839  char arraydata[100000];
840 
841 
842  while(buffer[(*j)] != '{')
843  {
844  if(buffer[(*j)] != ' ') return -1;
845  else if(buffer[(*j)] == '\0') return -1;
846  else (*j)++;
847  }
848  (*j)++;
849 
850  (*temp_datatype).bank_id = 0;
851  array_k = 0;
852  while(buffer[*j] != ',')
853  {
854  if(buffer[(*j)] == '\0') return -1;
855  arraydata[array_k] = buffer[*j];
856  array_k++;
857  (*j)++;
858  }
859  arraydata[array_k] = '\0';
860  (*temp_datatype).bank_id = atoi(arraydata);
861  (*j)++;
862  (*temp_datatype).principal = 0.0;
863  array_k = 0;
864  while(buffer[*j] != ',')
865  {
866  if(buffer[(*j)] == '\0') return -1;
867  arraydata[array_k] = buffer[*j];
868  array_k++;
869  (*j)++;
870  }
871  arraydata[array_k] = '\0';
872  (*temp_datatype).principal = atof(arraydata);
873  (*j)++;
874  (*temp_datatype).quarters_left = 0;
875  array_k = 0;
876  while(buffer[*j] != ',')
877  {
878  if(buffer[(*j)] == '\0') return -1;
879  arraydata[array_k] = buffer[*j];
880  array_k++;
881  (*j)++;
882  }
883  arraydata[array_k] = '\0';
884  (*temp_datatype).quarters_left = atoi(arraydata);
885  (*j)++;
886  (*temp_datatype).quarterly_interest = 0.0;
887  array_k = 0;
888  while(buffer[*j] != ',')
889  {
890  if(buffer[(*j)] == '\0') return -1;
891  arraydata[array_k] = buffer[*j];
892  array_k++;
893  (*j)++;
894  }
895  arraydata[array_k] = '\0';
896  (*temp_datatype).quarterly_interest = atof(arraydata);
897  (*j)++;
898  (*temp_datatype).quarterly_principal = 0.0;
899  array_k = 0;
900  while(buffer[*j] != ',')
901  {
902  if(buffer[(*j)] == '\0') return -1;
903  arraydata[array_k] = buffer[*j];
904  array_k++;
905  (*j)++;
906  }
907  arraydata[array_k] = '\0';
908  (*temp_datatype).quarterly_principal = atof(arraydata);
909  (*j)++;
910  (*temp_datatype).interestrate = 0.0;
911  array_k = 0;
912  while(buffer[*j] != ',')
913  {
914  if(buffer[(*j)] == '\0') return -1;
915  arraydata[array_k] = buffer[*j];
916  array_k++;
917  (*j)++;
918  }
919  arraydata[array_k] = '\0';
920  (*temp_datatype).interestrate = atof(arraydata);
921  (*j)++;
922  (*temp_datatype).mtype = 0;
923  array_k = 0;
924  while(buffer[*j] != '}')
925  {
926  if(buffer[(*j)] == '\0') return -1;
927  arraydata[array_k] = buffer[*j];
928  array_k++;
929  (*j)++;
930  }
931  arraydata[array_k] = '\0';
932  (*temp_datatype).mtype = atoi(arraydata);
933  (*j)++;
934 
935  return 0;
936 }
937 
938 int read_mortgage_dynamic_array(char * buffer, int buffer_size, int * j, mortgage_array * temp_datatype_array)
939 {
940  int arraycount = 0;
941  int rc;
942 
943 
944 
945 
946 
947 
948 
949 
950 
951  while(buffer[(*j)] != '{')
952  {
953  if(buffer[(*j)] != ' ') return -1;
954  else if(buffer[(*j)] == '\0') return -1;
955  else (*j)++;
956  }
957  (*j)++;
958 
959  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
960  {
961  if(buffer[(*j)] == '{')
962  {
963  add_mortgage(temp_datatype_array, 0, 0.0, 0, 0.0, 0.0, 0.0, 0);
964  rc = read_mortgage(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
965  if(rc != 0) { printf("Error: reading variable 'mortgage' of type '\n"); return -1; }
966  arraycount++;
967  (*j)++;
968  }
969  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
970  }
971 
972 
973 
974  return 0;
975 }
976 
977 int read_mortgage_static_array(char * buffer, int buffer_size, int * j, mortgage * temp_datatype_array, int size)
978 {
979  int arraycount;
980  int rc;
981 
982  while(buffer[(*j)] != '{')
983  {
984  if(buffer[(*j)] != ' ') return -1;
985  else if(buffer[(*j)] == '\0') return -1;
986  else (*j)++;
987  }
988  (*j)++;
989 
990  for(arraycount = 0; arraycount < size; arraycount++)
991  {
992  rc = read_mortgage(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
993  if(rc != 0) { printf("Error: reading variable 'mortgage' of type '\n"); return -1; }
994  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
995  }
996 
997  (*j)++;
998  return 0;
999 }
1000 
1004 int read_loan(char * buffer, int /*@unused@*/ buffer_size, int * j, loan * temp_datatype)
1005 {
1006  int array_k;
1007  char arraydata[100000];
1008 
1009 
1010  while(buffer[(*j)] != '{')
1011  {
1012  if(buffer[(*j)] != ' ') return -1;
1013  else if(buffer[(*j)] == '\0') return -1;
1014  else (*j)++;
1015  }
1016  (*j)++;
1017 
1018  (*temp_datatype).bank_id = 0;
1019  array_k = 0;
1020  while(buffer[*j] != ',')
1021  {
1022  if(buffer[(*j)] == '\0') return -1;
1023  arraydata[array_k] = buffer[*j];
1024  array_k++;
1025  (*j)++;
1026  }
1027  arraydata[array_k] = '\0';
1028  (*temp_datatype).bank_id = atoi(arraydata);
1029  (*j)++;
1030  (*temp_datatype).amount = 0.0;
1031  array_k = 0;
1032  while(buffer[*j] != ',')
1033  {
1034  if(buffer[(*j)] == '\0') return -1;
1035  arraydata[array_k] = buffer[*j];
1036  array_k++;
1037  (*j)++;
1038  }
1039  arraydata[array_k] = '\0';
1040  (*temp_datatype).amount = atof(arraydata);
1041  (*j)++;
1042  (*temp_datatype).to_be_paid = 0.0;
1043  array_k = 0;
1044  while(buffer[*j] != '}')
1045  {
1046  if(buffer[(*j)] == '\0') return -1;
1047  arraydata[array_k] = buffer[*j];
1048  array_k++;
1049  (*j)++;
1050  }
1051  arraydata[array_k] = '\0';
1052  (*temp_datatype).to_be_paid = atof(arraydata);
1053  (*j)++;
1054 
1055  return 0;
1056 }
1057 
1058 int read_loan_dynamic_array(char * buffer, int buffer_size, int * j, loan_array * temp_datatype_array)
1059 {
1060  int arraycount = 0;
1061  int rc;
1062 
1063 
1064 
1065 
1066 
1067  while(buffer[(*j)] != '{')
1068  {
1069  if(buffer[(*j)] != ' ') return -1;
1070  else if(buffer[(*j)] == '\0') return -1;
1071  else (*j)++;
1072  }
1073  (*j)++;
1074 
1075  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
1076  {
1077  if(buffer[(*j)] == '{')
1078  {
1079  add_loan(temp_datatype_array, 0, 0.0, 0.0);
1080  rc = read_loan(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
1081  if(rc != 0) { printf("Error: reading variable 'loan' of type '\n"); return -1; }
1082  arraycount++;
1083  (*j)++;
1084  }
1085  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
1086  }
1087 
1088 
1089 
1090  return 0;
1091 }
1092 
1093 int read_loan_static_array(char * buffer, int buffer_size, int * j, loan * temp_datatype_array, int size)
1094 {
1095  int arraycount;
1096  int rc;
1097 
1098  while(buffer[(*j)] != '{')
1099  {
1100  if(buffer[(*j)] != ' ') return -1;
1101  else if(buffer[(*j)] == '\0') return -1;
1102  else (*j)++;
1103  }
1104  (*j)++;
1105 
1106  for(arraycount = 0; arraycount < size; arraycount++)
1107  {
1108  rc = read_loan(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
1109  if(rc != 0) { printf("Error: reading variable 'loan' of type '\n"); return -1; }
1110  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
1111  }
1112 
1113  (*j)++;
1114  return 0;
1115 }
1116 
1120 int read_hbuyer(char * buffer, int /*@unused@*/ buffer_size, int * j, hbuyer * temp_datatype)
1121 {
1122  int array_k;
1123  char arraydata[100000];
1124 
1125 
1126  while(buffer[(*j)] != '{')
1127  {
1128  if(buffer[(*j)] != ' ') return -1;
1129  else if(buffer[(*j)] == '\0') return -1;
1130  else (*j)++;
1131  }
1132  (*j)++;
1133 
1134  (*temp_datatype).buyer_id = 0;
1135  array_k = 0;
1136  while(buffer[*j] != ',')
1137  {
1138  if(buffer[(*j)] == '\0') return -1;
1139  arraydata[array_k] = buffer[*j];
1140  array_k++;
1141  (*j)++;
1142  }
1143  arraydata[array_k] = '\0';
1144  (*temp_datatype).buyer_id = atoi(arraydata);
1145  (*j)++;
1146  (*temp_datatype).bank_id = 0;
1147  array_k = 0;
1148  while(buffer[*j] != ',')
1149  {
1150  if(buffer[(*j)] == '\0') return -1;
1151  arraydata[array_k] = buffer[*j];
1152  array_k++;
1153  (*j)++;
1154  }
1155  arraydata[array_k] = '\0';
1156  (*temp_datatype).bank_id = atoi(arraydata);
1157  (*j)++;
1158  (*temp_datatype).liquidity = 0.0;
1159  array_k = 0;
1160  while(buffer[*j] != ',')
1161  {
1162  if(buffer[(*j)] == '\0') return -1;
1163  arraydata[array_k] = buffer[*j];
1164  array_k++;
1165  (*j)++;
1166  }
1167  arraydata[array_k] = '\0';
1168  (*temp_datatype).liquidity = atof(arraydata);
1169  (*j)++;
1170  (*temp_datatype).quarterly_income = 0.0;
1171  array_k = 0;
1172  while(buffer[*j] != ',')
1173  {
1174  if(buffer[(*j)] == '\0') return -1;
1175  arraydata[array_k] = buffer[*j];
1176  array_k++;
1177  (*j)++;
1178  }
1179  arraydata[array_k] = '\0';
1180  (*temp_datatype).quarterly_income = atof(arraydata);
1181  (*j)++;
1182  (*temp_datatype).quarterly_mortgage_paid = 0.0;
1183  array_k = 0;
1184  while(buffer[*j] != ',')
1185  {
1186  if(buffer[(*j)] == '\0') return -1;
1187  arraydata[array_k] = buffer[*j];
1188  array_k++;
1189  (*j)++;
1190  }
1191  arraydata[array_k] = '\0';
1192  (*temp_datatype).quarterly_mortgage_paid = atof(arraydata);
1193  (*j)++;
1194  (*temp_datatype).choice = 0;
1195  array_k = 0;
1196  while(buffer[*j] != '}')
1197  {
1198  if(buffer[(*j)] == '\0') return -1;
1199  arraydata[array_k] = buffer[*j];
1200  array_k++;
1201  (*j)++;
1202  }
1203  arraydata[array_k] = '\0';
1204  (*temp_datatype).choice = atoi(arraydata);
1205  (*j)++;
1206 
1207  return 0;
1208 }
1209 
1210 int read_hbuyer_dynamic_array(char * buffer, int buffer_size, int * j, hbuyer_array * temp_datatype_array)
1211 {
1212  int arraycount = 0;
1213  int rc;
1214 
1215 
1216 
1217 
1218 
1219 
1220 
1221 
1222  while(buffer[(*j)] != '{')
1223  {
1224  if(buffer[(*j)] != ' ') return -1;
1225  else if(buffer[(*j)] == '\0') return -1;
1226  else (*j)++;
1227  }
1228  (*j)++;
1229 
1230  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
1231  {
1232  if(buffer[(*j)] == '{')
1233  {
1234  add_hbuyer(temp_datatype_array, 0, 0, 0.0, 0.0, 0.0, 0);
1235  rc = read_hbuyer(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
1236  if(rc != 0) { printf("Error: reading variable 'hbuyer' of type '\n"); return -1; }
1237  arraycount++;
1238  (*j)++;
1239  }
1240  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
1241  }
1242 
1243 
1244 
1245  return 0;
1246 }
1247 
1248 int read_hbuyer_static_array(char * buffer, int buffer_size, int * j, hbuyer * temp_datatype_array, int size)
1249 {
1250  int arraycount;
1251  int rc;
1252 
1253  while(buffer[(*j)] != '{')
1254  {
1255  if(buffer[(*j)] != ' ') return -1;
1256  else if(buffer[(*j)] == '\0') return -1;
1257  else (*j)++;
1258  }
1259  (*j)++;
1260 
1261  for(arraycount = 0; arraycount < size; arraycount++)
1262  {
1263  rc = read_hbuyer(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
1264  if(rc != 0) { printf("Error: reading variable 'hbuyer' of type '\n"); return -1; }
1265  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
1266  }
1267 
1268  (*j)++;
1269  return 0;
1270 }
1271 
1275 int read_hseller(char * buffer, int /*@unused@*/ buffer_size, int * j, hseller * temp_datatype)
1276 {
1277  int array_k;
1278  char arraydata[100000];
1279 
1280 
1281  while(buffer[(*j)] != '{')
1282  {
1283  if(buffer[(*j)] != ' ') return -1;
1284  else if(buffer[(*j)] == '\0') return -1;
1285  else (*j)++;
1286  }
1287  (*j)++;
1288 
1289  (*temp_datatype).seller_id = 0;
1290  array_k = 0;
1291  while(buffer[*j] != ',')
1292  {
1293  if(buffer[(*j)] == '\0') return -1;
1294  arraydata[array_k] = buffer[*j];
1295  array_k++;
1296  (*j)++;
1297  }
1298  arraydata[array_k] = '\0';
1299  (*temp_datatype).seller_id = atoi(arraydata);
1300  (*j)++;
1301  (*temp_datatype).price = 0.0;
1302  array_k = 0;
1303  while(buffer[*j] != ',')
1304  {
1305  if(buffer[(*j)] == '\0') return -1;
1306  arraydata[array_k] = buffer[*j];
1307  array_k++;
1308  (*j)++;
1309  }
1310  arraydata[array_k] = '\0';
1311  (*temp_datatype).price = atof(arraydata);
1312  (*j)++;
1313  (*temp_datatype).quantity = 0;
1314  array_k = 0;
1315  while(buffer[*j] != ',')
1316  {
1317  if(buffer[(*j)] == '\0') return -1;
1318  arraydata[array_k] = buffer[*j];
1319  array_k++;
1320  (*j)++;
1321  }
1322  arraydata[array_k] = '\0';
1323  (*temp_datatype).quantity = atoi(arraydata);
1324  (*j)++;
1325  (*temp_datatype).type = 0;
1326  array_k = 0;
1327  while(buffer[*j] != '}')
1328  {
1329  if(buffer[(*j)] == '\0') return -1;
1330  arraydata[array_k] = buffer[*j];
1331  array_k++;
1332  (*j)++;
1333  }
1334  arraydata[array_k] = '\0';
1335  (*temp_datatype).type = atoi(arraydata);
1336  (*j)++;
1337 
1338  return 0;
1339 }
1340 
1341 int read_hseller_dynamic_array(char * buffer, int buffer_size, int * j, hseller_array * temp_datatype_array)
1342 {
1343  int arraycount = 0;
1344  int rc;
1345 
1346 
1347 
1348 
1349 
1350 
1351  while(buffer[(*j)] != '{')
1352  {
1353  if(buffer[(*j)] != ' ') return -1;
1354  else if(buffer[(*j)] == '\0') return -1;
1355  else (*j)++;
1356  }
1357  (*j)++;
1358 
1359  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
1360  {
1361  if(buffer[(*j)] == '{')
1362  {
1363  add_hseller(temp_datatype_array, 0, 0.0, 0, 0);
1364  rc = read_hseller(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
1365  if(rc != 0) { printf("Error: reading variable 'hseller' of type '\n"); return -1; }
1366  arraycount++;
1367  (*j)++;
1368  }
1369  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
1370  }
1371 
1372 
1373 
1374  return 0;
1375 }
1376 
1377 int read_hseller_static_array(char * buffer, int buffer_size, int * j, hseller * temp_datatype_array, int size)
1378 {
1379  int arraycount;
1380  int rc;
1381 
1382  while(buffer[(*j)] != '{')
1383  {
1384  if(buffer[(*j)] != ' ') return -1;
1385  else if(buffer[(*j)] == '\0') return -1;
1386  else (*j)++;
1387  }
1388  (*j)++;
1389 
1390  for(arraycount = 0; arraycount < size; arraycount++)
1391  {
1392  rc = read_hseller(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
1393  if(rc != 0) { printf("Error: reading variable 'hseller' of type '\n"); return -1; }
1394  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
1395  }
1396 
1397  (*j)++;
1398  return 0;
1399 }
1400 
1404 int read_hbank(char * buffer, int /*@unused@*/ buffer_size, int * j, hbank * temp_datatype)
1405 {
1406  int array_k;
1407  char arraydata[100000];
1408 
1409 
1410  while(buffer[(*j)] != '{')
1411  {
1412  if(buffer[(*j)] != ' ') return -1;
1413  else if(buffer[(*j)] == '\0') return -1;
1414  else (*j)++;
1415  }
1416  (*j)++;
1417 
1418  (*temp_datatype).id = 0;
1419  array_k = 0;
1420  while(buffer[*j] != ',')
1421  {
1422  if(buffer[(*j)] == '\0') return -1;
1423  arraydata[array_k] = buffer[*j];
1424  array_k++;
1425  (*j)++;
1426  }
1427  arraydata[array_k] = '\0';
1428  (*temp_datatype).id = atoi(arraydata);
1429  (*j)++;
1430  (*temp_datatype).equity = 0.0;
1431  array_k = 0;
1432  while(buffer[*j] != ',')
1433  {
1434  if(buffer[(*j)] == '\0') return -1;
1435  arraydata[array_k] = buffer[*j];
1436  array_k++;
1437  (*j)++;
1438  }
1439  arraydata[array_k] = '\0';
1440  (*temp_datatype).equity = atof(arraydata);
1441  (*j)++;
1442  (*temp_datatype).risky_assets = 0.0;
1443  array_k = 0;
1444  while(buffer[*j] != ',')
1445  {
1446  if(buffer[(*j)] == '\0') return -1;
1447  arraydata[array_k] = buffer[*j];
1448  array_k++;
1449  (*j)++;
1450  }
1451  arraydata[array_k] = '\0';
1452  (*temp_datatype).risky_assets = atof(arraydata);
1453  (*j)++;
1454  (*temp_datatype).amount_mortgaged = 0.0;
1455  array_k = 0;
1456  while(buffer[*j] != '}')
1457  {
1458  if(buffer[(*j)] == '\0') return -1;
1459  arraydata[array_k] = buffer[*j];
1460  array_k++;
1461  (*j)++;
1462  }
1463  arraydata[array_k] = '\0';
1464  (*temp_datatype).amount_mortgaged = atof(arraydata);
1465  (*j)++;
1466 
1467  return 0;
1468 }
1469 
1470 int read_hbank_dynamic_array(char * buffer, int buffer_size, int * j, hbank_array * temp_datatype_array)
1471 {
1472  int arraycount = 0;
1473  int rc;
1474 
1475 
1476 
1477 
1478 
1479 
1480  while(buffer[(*j)] != '{')
1481  {
1482  if(buffer[(*j)] != ' ') return -1;
1483  else if(buffer[(*j)] == '\0') return -1;
1484  else (*j)++;
1485  }
1486  (*j)++;
1487 
1488  while(buffer[(*j)] != '\0' && buffer[(*j)] != '}')
1489  {
1490  if(buffer[(*j)] == '{')
1491  {
1492  add_hbank(temp_datatype_array, 0, 0.0, 0.0, 0.0);
1493  rc = read_hbank(buffer, buffer_size, j, &(*temp_datatype_array).array[arraycount]);
1494  if(rc != 0) { printf("Error: reading variable 'hbank' of type '\n"); return -1; }
1495  arraycount++;
1496  (*j)++;
1497  }
1498  while(buffer[(*j)] != '}' && buffer[(*j)] != '\0' && buffer[(*j)] != '{') { (*j)++; }
1499  }
1500 
1501 
1502 
1503  return 0;
1504 }
1505 
1506 int read_hbank_static_array(char * buffer, int buffer_size, int * j, hbank * temp_datatype_array, int size)
1507 {
1508  int arraycount;
1509  int rc;
1510 
1511  while(buffer[(*j)] != '{')
1512  {
1513  if(buffer[(*j)] != ' ') return -1;
1514  else if(buffer[(*j)] == '\0') return -1;
1515  else (*j)++;
1516  }
1517  (*j)++;
1518 
1519  for(arraycount = 0; arraycount < size; arraycount++)
1520  {
1521  rc = read_hbank(buffer, buffer_size, j, &temp_datatype_array[arraycount]);
1522  if(rc != 0) { printf("Error: reading variable 'hbank' of type '\n"); return -1; }
1523  if(arraycount < (size-1)) while(buffer[(*j)] != '{') { (*j)++; }
1524  }
1525 
1526  (*j)++;
1527  return 0;
1528 }
1529 
1530 
1531 
1533 {
1534  FILE * file;
1535  char c = '\0';
1536  char buffer[100000];
1537  int index = 0;
1538  int in_environment = 0;
1539  int in_resume_mode = 0;
1540  int in_print_debug_mode = 0;
1541  int in_warning_mode = 0;
1542  int in_data_collection_mode = 0;
1543  int in_collect_household_data = 0;
1544  int in_collect_firm_data = 0;
1545  int in_ratio_liquidity = 0;
1546  int in_consumption_adjustment_speed = 0;
1547  int in_wealth_effect = 0;
1548  int in_turnover_probability = 0;
1549  int in_production_markup = 0;
1550  int in_price_markup = 0;
1551  int in_firm_memory_persistance = 0;
1552  int in_ratio_fiscal_policy = 0;
1553  int in_ratio_capitalist_households = 0;
1554  int in_inflation_target = 0;
1555  int in_firms_minimum_equity_ratio = 0;
1556  int in_firm_startup_leverage = 0;
1557  int in_household_startup_leverage = 0;
1558  int in_car_buffer_threshold = 0;
1559  int in_housing_market_entrance_prob = 0;
1560  int in_fire_sale_threshold = 0;
1561  int in_household_budget_constraint = 0;
1562  int in_capital_adequecy_ratio = 0;
1563  int in_housing_price_up_rate = 0;
1564  int in_housing_price_down_rate = 0;
1565  int in_household_mortgage_writeoff_high = 0;
1566  int in_household_mortgage_writeoff_low = 0;
1567 
1568 
1569  buffer[0] = '\0';
1570 
1571  /* Open file */
1572  if((file = fopen(location, "r"))==NULL)
1573  {
1574  printf("Error: cannot open import xml file '%s'\n", location);
1575  exit(0);
1576  }
1577  printf("Reading environment data from: %s\n", location);
1578  /* Keep reading file until EOF */
1579  while(c != (char)EOF)
1580  {
1581  /* Get the next char from the file */
1582  c = (char)fgetc(file);
1583  if(c == '>')
1584  {
1585  buffer[index] = '\0';
1586  if(strcmp(buffer, "environment") == 0) in_environment = 1;
1587  if(strcmp(buffer, "/environment") == 0) in_environment = 0;
1588  if(strcmp(buffer, "resume_mode") == 0) in_resume_mode = 1;
1589  if(strcmp(buffer, "/resume_mode") == 0) in_resume_mode = 0;
1590  if(strcmp(buffer, "print_debug_mode") == 0) in_print_debug_mode = 1;
1591  if(strcmp(buffer, "/print_debug_mode") == 0) in_print_debug_mode = 0;
1592  if(strcmp(buffer, "warning_mode") == 0) in_warning_mode = 1;
1593  if(strcmp(buffer, "/warning_mode") == 0) in_warning_mode = 0;
1594  if(strcmp(buffer, "data_collection_mode") == 0) in_data_collection_mode = 1;
1595  if(strcmp(buffer, "/data_collection_mode") == 0) in_data_collection_mode = 0;
1596  if(strcmp(buffer, "collect_household_data") == 0) in_collect_household_data = 1;
1597  if(strcmp(buffer, "/collect_household_data") == 0) in_collect_household_data = 0;
1598  if(strcmp(buffer, "collect_firm_data") == 0) in_collect_firm_data = 1;
1599  if(strcmp(buffer, "/collect_firm_data") == 0) in_collect_firm_data = 0;
1600  if(strcmp(buffer, "ratio_liquidity") == 0) in_ratio_liquidity = 1;
1601  if(strcmp(buffer, "/ratio_liquidity") == 0) in_ratio_liquidity = 0;
1602  if(strcmp(buffer, "consumption_adjustment_speed") == 0) in_consumption_adjustment_speed = 1;
1603  if(strcmp(buffer, "/consumption_adjustment_speed") == 0) in_consumption_adjustment_speed = 0;
1604  if(strcmp(buffer, "wealth_effect") == 0) in_wealth_effect = 1;
1605  if(strcmp(buffer, "/wealth_effect") == 0) in_wealth_effect = 0;
1606  if(strcmp(buffer, "turnover_probability") == 0) in_turnover_probability = 1;
1607  if(strcmp(buffer, "/turnover_probability") == 0) in_turnover_probability = 0;
1608  if(strcmp(buffer, "production_markup") == 0) in_production_markup = 1;
1609  if(strcmp(buffer, "/production_markup") == 0) in_production_markup = 0;
1610  if(strcmp(buffer, "price_markup") == 0) in_price_markup = 1;
1611  if(strcmp(buffer, "/price_markup") == 0) in_price_markup = 0;
1612  if(strcmp(buffer, "firm_memory_persistance") == 0) in_firm_memory_persistance = 1;
1613  if(strcmp(buffer, "/firm_memory_persistance") == 0) in_firm_memory_persistance = 0;
1614  if(strcmp(buffer, "ratio_fiscal_policy") == 0) in_ratio_fiscal_policy = 1;
1615  if(strcmp(buffer, "/ratio_fiscal_policy") == 0) in_ratio_fiscal_policy = 0;
1616  if(strcmp(buffer, "ratio_capitalist_households") == 0) in_ratio_capitalist_households = 1;
1617  if(strcmp(buffer, "/ratio_capitalist_households") == 0) in_ratio_capitalist_households = 0;
1618  if(strcmp(buffer, "inflation_target") == 0) in_inflation_target = 1;
1619  if(strcmp(buffer, "/inflation_target") == 0) in_inflation_target = 0;
1620  if(strcmp(buffer, "firms_minimum_equity_ratio") == 0) in_firms_minimum_equity_ratio = 1;
1621  if(strcmp(buffer, "/firms_minimum_equity_ratio") == 0) in_firms_minimum_equity_ratio = 0;
1622  if(strcmp(buffer, "firm_startup_leverage") == 0) in_firm_startup_leverage = 1;
1623  if(strcmp(buffer, "/firm_startup_leverage") == 0) in_firm_startup_leverage = 0;
1624  if(strcmp(buffer, "household_startup_leverage") == 0) in_household_startup_leverage = 1;
1625  if(strcmp(buffer, "/household_startup_leverage") == 0) in_household_startup_leverage = 0;
1626  if(strcmp(buffer, "car_buffer_threshold") == 0) in_car_buffer_threshold = 1;
1627  if(strcmp(buffer, "/car_buffer_threshold") == 0) in_car_buffer_threshold = 0;
1628  if(strcmp(buffer, "housing_market_entrance_prob") == 0) in_housing_market_entrance_prob = 1;
1629  if(strcmp(buffer, "/housing_market_entrance_prob") == 0) in_housing_market_entrance_prob = 0;
1630  if(strcmp(buffer, "fire_sale_threshold") == 0) in_fire_sale_threshold = 1;
1631  if(strcmp(buffer, "/fire_sale_threshold") == 0) in_fire_sale_threshold = 0;
1632  if(strcmp(buffer, "household_budget_constraint") == 0) in_household_budget_constraint = 1;
1633  if(strcmp(buffer, "/household_budget_constraint") == 0) in_household_budget_constraint = 0;
1634  if(strcmp(buffer, "capital_adequecy_ratio") == 0) in_capital_adequecy_ratio = 1;
1635  if(strcmp(buffer, "/capital_adequecy_ratio") == 0) in_capital_adequecy_ratio = 0;
1636  if(strcmp(buffer, "housing_price_up_rate") == 0) in_housing_price_up_rate = 1;
1637  if(strcmp(buffer, "/housing_price_up_rate") == 0) in_housing_price_up_rate = 0;
1638  if(strcmp(buffer, "housing_price_down_rate") == 0) in_housing_price_down_rate = 1;
1639  if(strcmp(buffer, "/housing_price_down_rate") == 0) in_housing_price_down_rate = 0;
1640  if(strcmp(buffer, "household_mortgage_writeoff_high") == 0) in_household_mortgage_writeoff_high = 1;
1641  if(strcmp(buffer, "/household_mortgage_writeoff_high") == 0) in_household_mortgage_writeoff_high = 0;
1642  if(strcmp(buffer, "household_mortgage_writeoff_low") == 0) in_household_mortgage_writeoff_low = 1;
1643  if(strcmp(buffer, "/household_mortgage_writeoff_low") == 0) in_household_mortgage_writeoff_low = 0;
1644 
1645  index = 0;
1646  buffer[index] = '\0';
1647  }
1648  else if(c == '<')
1649  {
1650  buffer[index] = '\0';
1651  if(in_environment == 1)
1652  {
1653  if(in_resume_mode == 1) { FLAME_environment_variable_resume_mode = atoi(buffer); }
1654  if(in_print_debug_mode == 1) { FLAME_environment_variable_print_debug_mode = atoi(buffer); }
1655  if(in_warning_mode == 1) { FLAME_environment_variable_warning_mode = atoi(buffer); }
1656  if(in_data_collection_mode == 1) { FLAME_environment_variable_data_collection_mode = atoi(buffer); }
1657  if(in_collect_household_data == 1) { FLAME_environment_variable_collect_household_data = atoi(buffer); }
1658  if(in_collect_firm_data == 1) { FLAME_environment_variable_collect_firm_data = atoi(buffer); }
1659  if(in_ratio_liquidity == 1) { FLAME_environment_variable_ratio_liquidity = atof(buffer); }
1660  if(in_consumption_adjustment_speed == 1) { FLAME_environment_variable_consumption_adjustment_speed = atof(buffer); }
1661  if(in_wealth_effect == 1) { FLAME_environment_variable_wealth_effect = atof(buffer); }
1662  if(in_turnover_probability == 1) { FLAME_environment_variable_turnover_probability = atof(buffer); }
1663  if(in_production_markup == 1) { FLAME_environment_variable_production_markup = atof(buffer); }
1664  if(in_price_markup == 1) { FLAME_environment_variable_price_markup = atof(buffer); }
1665  if(in_firm_memory_persistance == 1) { FLAME_environment_variable_firm_memory_persistance = atof(buffer); }
1666  if(in_ratio_fiscal_policy == 1) { FLAME_environment_variable_ratio_fiscal_policy = atof(buffer); }
1667  if(in_ratio_capitalist_households == 1) { FLAME_environment_variable_ratio_capitalist_households = atof(buffer); }
1668  if(in_inflation_target == 1) { FLAME_environment_variable_inflation_target = atof(buffer); }
1669  if(in_firms_minimum_equity_ratio == 1) { FLAME_environment_variable_firms_minimum_equity_ratio = atof(buffer); }
1670  if(in_firm_startup_leverage == 1) { FLAME_environment_variable_firm_startup_leverage = atof(buffer); }
1671  if(in_household_startup_leverage == 1) { FLAME_environment_variable_household_startup_leverage = atof(buffer); }
1672  if(in_car_buffer_threshold == 1) { FLAME_environment_variable_car_buffer_threshold = atof(buffer); }
1673  if(in_housing_market_entrance_prob == 1) { FLAME_environment_variable_housing_market_entrance_prob = atof(buffer); }
1674  if(in_fire_sale_threshold == 1) { FLAME_environment_variable_fire_sale_threshold = atof(buffer); }
1675  if(in_household_budget_constraint == 1) { FLAME_environment_variable_household_budget_constraint = atof(buffer); }
1676  if(in_capital_adequecy_ratio == 1) { FLAME_environment_variable_capital_adequecy_ratio = atof(buffer); }
1677  if(in_housing_price_up_rate == 1) { FLAME_environment_variable_housing_price_up_rate = atof(buffer); }
1678  if(in_housing_price_down_rate == 1) { FLAME_environment_variable_housing_price_down_rate = atof(buffer); }
1679  if(in_household_mortgage_writeoff_high == 1) { FLAME_environment_variable_household_mortgage_writeoff_high = atof(buffer); }
1680  if(in_household_mortgage_writeoff_low == 1) { FLAME_environment_variable_household_mortgage_writeoff_low = atof(buffer); }
1681 
1682  }
1683  index = 0;
1684  buffer[index] = '\0';
1685  }
1686  else
1687  {
1688  buffer[index] = c;
1689  if(index < 999) index++;
1690  }
1691  }
1692  /* Close file */
1693  (void)fclose(file);
1694 
1695  return 0;
1696 }
1697 
1699  double cloud_data[],
1700  int partition_method,
1701  int flag,
1702  int number_partitions,
1703  int agent_count,
1704  int * itno)
1705 {
1706  FILE * file;
1707  char c = '\0';
1708  char buffer[100000];
1709  char agentname[10000];
1710  int index = 0;
1711  int j; /* Index for reading arrays */
1712  int rc;
1713  int in_itno = 0;
1714  int FLAME_in_xagent = 0;
1715  int FLAME_in_name = 0;
1716  int in_firm_agent = 0;
1717  int in_household_agent = 0;
1718  int in_equityfund_agent = 0;
1719  int in_bank_agent = 0;
1720  int in_government_agent = 0;
1721  int in_centralbank_agent = 0;
1722  int in_jpoffice_agent = 0;
1723  int in_mall_agent = 0;
1724  int in_reagency_agent = 0;
1725 
1726  int in_id = 0;
1727  int in_bank_id = 0;
1728  int in_isconstructor = 0;
1729  int in_day_of_month_to_act = 0;
1730  int in_isinsolvent = 0;
1731  int in_it_no = 0;
1732  int in_day_of_week_to_act = 0;
1733  int in_average_goods_price = 0;
1734  int in_employees = 0;
1735  int in_manager = 0;
1736  int in_wage_offer = 0;
1737  int in_average_wage = 0;
1738  int in_no_employees = 0;
1739  int in_vacancies = 0;
1740  int in_employees_needed = 0;
1741  int in_day_of_month_wages_paid = 0;
1742  int in_labour_productivity = 0;
1743  int in_capital_productivity = 0;
1744  int in_capital_goods = 0;
1745  int in_capital_goods_price = 0;
1746  int in_production_current = 0;
1747  int in_expected_sales = 0;
1748  int in_production_plan = 0;
1749  int in_unit_goods_price = 0;
1750  int in_unit_cost = 0;
1751  int in_day_of_month_production_completed = 0;
1752  int in_unit_house_price = 0;
1753  int in_projects = 0;
1754  int in_loans_interest_rate = 0;
1755  int in_debt = 0;
1756  int in_inventory = 0;
1757  int in_sales = 0;
1758  int in_revenues = 0;
1759  int in_total_assets = 0;
1760  int in_operating_costs = 0;
1761  int in_labour_costs = 0;
1762  int in_total_interest_payments = 0;
1763  int in_dividends_paid = 0;
1764  int in_dividends_to_be_paid = 0;
1765  int in_retained_earnings = 0;
1766  int in_net_earnings = 0;
1767  int in_ebit = 0;
1768  int in_equity = 0;
1769  int in_liquidity = 0;
1770  int in_isliquidshort = 0;
1771  int in_hasloan = 0;
1772  int in_hasinvestment = 0;
1773  int in_isilliquid = 0;
1774  int in_planned_investment_costs = 0;
1775  int in_liquidity_need = 0;
1776  int in_loan_list = 0;
1777  int in_labour_tax_rate = 0;
1778  int in_delta_housing_price = 0;
1779  int in_weekly_consumption_budget = 0;
1780  int in_mall_budget = 0;
1781  int in_quarterly_price_change = 0;
1782  int in_my_employer_id = 0;
1783  int in_wage = 0;
1784  int in_ismanager = 0;
1785  int in_government_benefits = 0;
1786  int in_day_of_month_wage_recieved = 0;
1787  int in_mortgages_interest_rate = 0;
1788  int in_mortgages_list = 0;
1789  int in_mortgages = 0;
1790  int in_housing_payment = 0;
1791  int in_housing_price = 0;
1792  int in_housing_units = 0;
1793  int in_n_shares = 0;
1794  int in_capital_income = 0;
1795  int in_previous_wages = 0;
1796  int in_previous_benefits = 0;
1797  int in_labour_income = 0;
1798  int in_housing_value = 0;
1799  int in_expected_housing_payment = 0;
1800  int in_hmarket_role = 0;
1801  int in_equity_ratio = 0;
1802  int in_minimum_equity_ratio = 0;
1803  int in_mortgage_costs = 0;
1804  int in_delta_housing_value = 0;
1805  int in_mortgage_choice = 0;
1806  int in_share_firms = 0;
1807  int in_share_construction_firms = 0;
1808  int in_share_banks = 0;
1809  int in_dividends_recieved = 0;
1810  int in_dividends_retained = 0;
1811  int in_firm_investment = 0;
1812  int in_capital_tax_rate = 0;
1813  int in_loans = 0;
1814  int in_loans_start = 0;
1815  int in_deposits = 0;
1816  int in_centralbank_debt = 0;
1817  int in_total_writeoffs = 0;
1818  int in_interest_rate = 0;
1819  int in_interests_accrued = 0;
1820  int in_interests_paid = 0;
1821  int in_total_dividends = 0;
1822  int in_total_costs = 0;
1823  int in_unemployment_rate = 0;
1824  int in_population_size = 0;
1825  int in_labour_tax_income = 0;
1826  int in_capital_tax_income = 0;
1827  int in_gov_general_benefit_rate = 0;
1828  int in_gov_unemployment_rate = 0;
1829  int in_general_benefits = 0;
1830  int in_unemployment_benefits = 0;
1831  int in_earnings = 0;
1832  int in_centralbank_income = 0;
1833  int in_expenditures = 0;
1834  int in_inflation_rate = 0;
1835  int in_consumption_goods_prices = 0;
1836  int in_goods = 0;
1837  int in_weekly_price_averages = 0;
1838  int in_loans_banks = 0;
1839  int in_loans_government = 0;
1840  int in_fiat_money = 0;
1841  int in_liquidity_banks = 0;
1842  int in_liquidity_government = 0;
1843  int in_liquidity_equityfund = 0;
1844  int in_houses = 0;
1845  int in_goods_transactions = 0;
1846  int in_housing_transactions = 0;
1847 
1848  xmachine_memory_firm * current_firm_agent = NULL;
1849  xmachine_memory_household * current_household_agent = NULL;
1850  xmachine_memory_equityfund * current_equityfund_agent = NULL;
1851  xmachine_memory_bank * current_bank_agent = NULL;
1852  xmachine_memory_government * current_government_agent = NULL;
1853  xmachine_memory_centralbank * current_centralbank_agent = NULL;
1854  xmachine_memory_jpoffice * current_jpoffice_agent = NULL;
1855  xmachine_memory_mall * current_mall_agent = NULL;
1856  xmachine_memory_reagency * current_reagency_agent = NULL;
1857 
1858  /* Things for round-robin partitioning */
1859  int geometric = 1;
1860  int other = 2;
1861  double posx=0.0, posy=0.0, posz=0.0;
1862 
1863  j = 0;
1864  rc = 0;
1865 
1866  /* Use j and rc to stop compiler warnings if not used */
1867  if(j == 0 && rc == 0) {}
1868 
1869  agentname[0] = '\0';
1870  buffer[0] = '\0';
1871 
1872  /* Open file */
1873  if((file = fopen(location, "r"))==NULL)
1874  {
1875  printf("Error: cannot open import xml file '%s'\n", location);
1876  exit(0);
1877  }
1878  printf("Reading agent data from: %s\n", location);
1879  /* Keep reading file until EOF */
1880  while(c != (char)EOF)
1881  {
1882  /* Get the next char from the file */
1883  c = (char)fgetc(file);
1884  if(c == '>')
1885  {
1886  buffer[index] = '\0';
1887  if(strcmp(buffer, "itno") == 0) in_itno = 1;
1888  if(strcmp(buffer, "/itno") == 0) in_itno = 0;
1889  if(strcmp(buffer, "xagent") == 0)
1890  {
1891  FLAME_in_xagent = 1;
1892  agentname[0] = '\0';
1893  }
1894  if(strcmp(buffer, "/xagent") == 0)
1895  {
1896  if(strcmp(agentname, "firm") == 0)
1897  {
1898  if(current_firm_agent == NULL) { printf("Memory error reading firm agent\n"); exit(0); }
1899 
1900  posx = (double)0.0;
1901  posy = (double)0.0;
1902  posz = (double)0.0;
1903 
1904  /* If flag is zero just read the data. We'll partition later.
1905  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
1906  if( flag == 0 )
1907  {
1908  /* Next line should be commented out? */
1909  add_firm_agent_internal(current_firm_agent, firm_start_state);
1910 
1911  /* Update the cloud data */
1912  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
1913  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
1914  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
1915  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
1916  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
1917  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
1918  }
1919  else
1920  {
1921  if(partition_method == geometric)
1922  {
1923  if (
1925  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
1927  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
1929  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
1930  )
1931  {
1932  add_firm_agent_internal(current_firm_agent, firm_start_state);
1933  }
1934  }
1935  else if (partition_method == other)
1936  {
1937  if (agent_count % number_partitions == 0)
1938  {
1939  add_firm_agent_internal(current_firm_agent, firm_start_state);
1940  }
1941  ++agent_count;
1942  }
1943  }
1944  }
1945  else if(strcmp(agentname, "household") == 0)
1946  {
1947  if(current_household_agent == NULL) { printf("Memory error reading household agent\n"); exit(0); }
1948 
1949  posx = (double)0.0;
1950  posy = (double)0.0;
1951  posz = (double)0.0;
1952 
1953  /* If flag is zero just read the data. We'll partition later.
1954  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
1955  if( flag == 0 )
1956  {
1957  /* Next line should be commented out? */
1958  add_household_agent_internal(current_household_agent, household_start_state);
1959 
1960  /* Update the cloud data */
1961  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
1962  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
1963  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
1964  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
1965  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
1966  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
1967  }
1968  else
1969  {
1970  if(partition_method == geometric)
1971  {
1972  if (
1974  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
1976  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
1978  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
1979  )
1980  {
1981  add_household_agent_internal(current_household_agent, household_start_state);
1982  }
1983  }
1984  else if (partition_method == other)
1985  {
1986  if (agent_count % number_partitions == 0)
1987  {
1988  add_household_agent_internal(current_household_agent, household_start_state);
1989  }
1990  ++agent_count;
1991  }
1992  }
1993  }
1994  else if(strcmp(agentname, "equityfund") == 0)
1995  {
1996  if(current_equityfund_agent == NULL) { printf("Memory error reading equityfund agent\n"); exit(0); }
1997 
1998  posx = (double)0.0;
1999  posy = (double)0.0;
2000  posz = (double)0.0;
2001 
2002  /* If flag is zero just read the data. We'll partition later.
2003  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2004  if( flag == 0 )
2005  {
2006  /* Next line should be commented out? */
2007  add_equityfund_agent_internal(current_equityfund_agent, equityfund_start_state);
2008 
2009  /* Update the cloud data */
2010  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2011  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2012  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2013  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2014  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2015  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2016  }
2017  else
2018  {
2019  if(partition_method == geometric)
2020  {
2021  if (
2023  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2025  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2027  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2028  )
2029  {
2030  add_equityfund_agent_internal(current_equityfund_agent, equityfund_start_state);
2031  }
2032  }
2033  else if (partition_method == other)
2034  {
2035  if (agent_count % number_partitions == 0)
2036  {
2037  add_equityfund_agent_internal(current_equityfund_agent, equityfund_start_state);
2038  }
2039  ++agent_count;
2040  }
2041  }
2042  }
2043  else if(strcmp(agentname, "bank") == 0)
2044  {
2045  if(current_bank_agent == NULL) { printf("Memory error reading bank agent\n"); exit(0); }
2046 
2047  posx = (double)0.0;
2048  posy = (double)0.0;
2049  posz = (double)0.0;
2050 
2051  /* If flag is zero just read the data. We'll partition later.
2052  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2053  if( flag == 0 )
2054  {
2055  /* Next line should be commented out? */
2056  add_bank_agent_internal(current_bank_agent, bank_start_state);
2057 
2058  /* Update the cloud data */
2059  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2060  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2061  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2062  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2063  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2064  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2065  }
2066  else
2067  {
2068  if(partition_method == geometric)
2069  {
2070  if (
2072  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2074  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2076  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2077  )
2078  {
2079  add_bank_agent_internal(current_bank_agent, bank_start_state);
2080  }
2081  }
2082  else if (partition_method == other)
2083  {
2084  if (agent_count % number_partitions == 0)
2085  {
2086  add_bank_agent_internal(current_bank_agent, bank_start_state);
2087  }
2088  ++agent_count;
2089  }
2090  }
2091  }
2092  else if(strcmp(agentname, "government") == 0)
2093  {
2094  if(current_government_agent == NULL) { printf("Memory error reading government agent\n"); exit(0); }
2095 
2096  posx = (double)0.0;
2097  posy = (double)0.0;
2098  posz = (double)0.0;
2099 
2100  /* If flag is zero just read the data. We'll partition later.
2101  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2102  if( flag == 0 )
2103  {
2104  /* Next line should be commented out? */
2105  add_government_agent_internal(current_government_agent, government_start_state);
2106 
2107  /* Update the cloud data */
2108  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2109  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2110  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2111  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2112  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2113  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2114  }
2115  else
2116  {
2117  if(partition_method == geometric)
2118  {
2119  if (
2121  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2123  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2125  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2126  )
2127  {
2128  add_government_agent_internal(current_government_agent, government_start_state);
2129  }
2130  }
2131  else if (partition_method == other)
2132  {
2133  if (agent_count % number_partitions == 0)
2134  {
2135  add_government_agent_internal(current_government_agent, government_start_state);
2136  }
2137  ++agent_count;
2138  }
2139  }
2140  }
2141  else if(strcmp(agentname, "centralbank") == 0)
2142  {
2143  if(current_centralbank_agent == NULL) { printf("Memory error reading centralbank agent\n"); exit(0); }
2144 
2145  posx = (double)0.0;
2146  posy = (double)0.0;
2147  posz = (double)0.0;
2148 
2149  /* If flag is zero just read the data. We'll partition later.
2150  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2151  if( flag == 0 )
2152  {
2153  /* Next line should be commented out? */
2154  add_centralbank_agent_internal(current_centralbank_agent, centralbank_start_state);
2155 
2156  /* Update the cloud data */
2157  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2158  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2159  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2160  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2161  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2162  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2163  }
2164  else
2165  {
2166  if(partition_method == geometric)
2167  {
2168  if (
2170  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2172  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2174  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2175  )
2176  {
2177  add_centralbank_agent_internal(current_centralbank_agent, centralbank_start_state);
2178  }
2179  }
2180  else if (partition_method == other)
2181  {
2182  if (agent_count % number_partitions == 0)
2183  {
2184  add_centralbank_agent_internal(current_centralbank_agent, centralbank_start_state);
2185  }
2186  ++agent_count;
2187  }
2188  }
2189  }
2190  else if(strcmp(agentname, "jpoffice") == 0)
2191  {
2192  if(current_jpoffice_agent == NULL) { printf("Memory error reading jpoffice agent\n"); exit(0); }
2193 
2194  posx = (double)0.0;
2195  posy = (double)0.0;
2196  posz = (double)0.0;
2197 
2198  /* If flag is zero just read the data. We'll partition later.
2199  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2200  if( flag == 0 )
2201  {
2202  /* Next line should be commented out? */
2203  add_jpoffice_agent_internal(current_jpoffice_agent, jpoffice_start_state);
2204 
2205  /* Update the cloud data */
2206  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2207  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2208  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2209  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2210  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2211  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2212  }
2213  else
2214  {
2215  if(partition_method == geometric)
2216  {
2217  if (
2219  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2221  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2223  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2224  )
2225  {
2226  add_jpoffice_agent_internal(current_jpoffice_agent, jpoffice_start_state);
2227  }
2228  }
2229  else if (partition_method == other)
2230  {
2231  if (agent_count % number_partitions == 0)
2232  {
2233  add_jpoffice_agent_internal(current_jpoffice_agent, jpoffice_start_state);
2234  }
2235  ++agent_count;
2236  }
2237  }
2238  }
2239  else if(strcmp(agentname, "mall") == 0)
2240  {
2241  if(current_mall_agent == NULL) { printf("Memory error reading mall agent\n"); exit(0); }
2242 
2243  posx = (double)0.0;
2244  posy = (double)0.0;
2245  posz = (double)0.0;
2246 
2247  /* If flag is zero just read the data. We'll partition later.
2248  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2249  if( flag == 0 )
2250  {
2251  /* Next line should be commented out? */
2252  add_mall_agent_internal(current_mall_agent, mall_start_state);
2253 
2254  /* Update the cloud data */
2255  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2256  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2257  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2258  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2259  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2260  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2261  }
2262  else
2263  {
2264  if(partition_method == geometric)
2265  {
2266  if (
2268  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2270  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2272  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2273  )
2274  {
2275  add_mall_agent_internal(current_mall_agent, mall_start_state);
2276  }
2277  }
2278  else if (partition_method == other)
2279  {
2280  if (agent_count % number_partitions == 0)
2281  {
2282  add_mall_agent_internal(current_mall_agent, mall_start_state);
2283  }
2284  ++agent_count;
2285  }
2286  }
2287  }
2288  else if(strcmp(agentname, "reagency") == 0)
2289  {
2290  if(current_reagency_agent == NULL) { printf("Memory error reading reagency agent\n"); exit(0); }
2291 
2292  posx = (double)0.0;
2293  posy = (double)0.0;
2294  posz = (double)0.0;
2295 
2296  /* If flag is zero just read the data. We'll partition later.
2297  * If flag is not zero we aleady have partition data so can read and distribute to the current node.*/
2298  if( flag == 0 )
2299  {
2300  /* Next line should be commented out? */
2301  add_reagency_agent_internal(current_reagency_agent, reagency_start_state);
2302 
2303  /* Update the cloud data */
2304  if ( posx < cloud_data[0] ) cloud_data[0] = posx;
2305  if ( posx > cloud_data[1] ) cloud_data[1] = posx;
2306  if ( posy < cloud_data[2] ) cloud_data[2] = posy;
2307  if ( posy > cloud_data[3] ) cloud_data[3] = posy;
2308  if ( posz < cloud_data[2] ) cloud_data[4] = posz;
2309  if ( posz > cloud_data[3] ) cloud_data[5] = posz;
2310  }
2311  else
2312  {
2313  if(partition_method == geometric)
2314  {
2315  if (
2317  ((current_node->partition_data[1] == SPINF) || (current_node->partition_data[1] != SPINF && posx < current_node->partition_data[1])) &&
2319  ((current_node->partition_data[3] == SPINF) || (current_node->partition_data[3] != SPINF && posy < current_node->partition_data[3])) &&
2321  ((current_node->partition_data[5] == SPINF) || (current_node->partition_data[5] != SPINF && posz < current_node->partition_data[5]))
2322  )
2323  {
2324  add_reagency_agent_internal(current_reagency_agent, reagency_start_state);
2325  }
2326  }
2327  else if (partition_method == other)
2328  {
2329  if (agent_count % number_partitions == 0)
2330  {
2331  add_reagency_agent_internal(current_reagency_agent, reagency_start_state);
2332  }
2333  ++agent_count;
2334  }
2335  }
2336  }
2337  else
2338  {
2339  printf("Warning: agent name undefined - '%s'\n", agentname);
2340  exit(0);
2341  }
2342  agentname[0] = '\0';
2343  FLAME_in_xagent = 0;
2344  in_firm_agent = 0;
2345  in_household_agent = 0;
2346  in_equityfund_agent = 0;
2347  in_bank_agent = 0;
2348  in_government_agent = 0;
2349  in_centralbank_agent = 0;
2350  in_jpoffice_agent = 0;
2351  in_mall_agent = 0;
2352  in_reagency_agent = 0;
2353 
2354  }
2355  if(strcmp(buffer, "name") == 0) FLAME_in_name = 1;
2356  if(strcmp(buffer, "/name") == 0) FLAME_in_name = 0;
2357  if(strcmp(buffer, "id") == 0) { in_id = 1; }
2358  if(strcmp(buffer, "/id") == 0) { in_id = 0; }
2359  if(strcmp(buffer, "bank_id") == 0) { in_bank_id = 1; }
2360  if(strcmp(buffer, "/bank_id") == 0) { in_bank_id = 0; }
2361  if(strcmp(buffer, "isconstructor") == 0) { in_isconstructor = 1; }
2362  if(strcmp(buffer, "/isconstructor") == 0) { in_isconstructor = 0; }
2363  if(strcmp(buffer, "day_of_month_to_act") == 0) { in_day_of_month_to_act = 1; }
2364  if(strcmp(buffer, "/day_of_month_to_act") == 0) { in_day_of_month_to_act = 0; }
2365  if(strcmp(buffer, "isinsolvent") == 0) { in_isinsolvent = 1; }
2366  if(strcmp(buffer, "/isinsolvent") == 0) { in_isinsolvent = 0; }
2367  if(strcmp(buffer, "it_no") == 0) { in_it_no = 1; }
2368  if(strcmp(buffer, "/it_no") == 0) { in_it_no = 0; }
2369  if(strcmp(buffer, "day_of_week_to_act") == 0) { in_day_of_week_to_act = 1; }
2370  if(strcmp(buffer, "/day_of_week_to_act") == 0) { in_day_of_week_to_act = 0; }
2371  if(strcmp(buffer, "average_goods_price") == 0) { in_average_goods_price = 1; }
2372  if(strcmp(buffer, "/average_goods_price") == 0) { in_average_goods_price = 0; }
2373  if(strcmp(buffer, "employees") == 0) { in_employees = 1; }
2374  if(strcmp(buffer, "/employees") == 0) { in_employees = 0; }
2375  if(strcmp(buffer, "manager") == 0) { in_manager = 1; }
2376  if(strcmp(buffer, "/manager") == 0) { in_manager = 0; }
2377  if(strcmp(buffer, "wage_offer") == 0) { in_wage_offer = 1; }
2378  if(strcmp(buffer, "/wage_offer") == 0) { in_wage_offer = 0; }
2379  if(strcmp(buffer, "average_wage") == 0) { in_average_wage = 1; }
2380  if(strcmp(buffer, "/average_wage") == 0) { in_average_wage = 0; }
2381  if(strcmp(buffer, "no_employees") == 0) { in_no_employees = 1; }
2382  if(strcmp(buffer, "/no_employees") == 0) { in_no_employees = 0; }
2383  if(strcmp(buffer, "vacancies") == 0) { in_vacancies = 1; }
2384  if(strcmp(buffer, "/vacancies") == 0) { in_vacancies = 0; }
2385  if(strcmp(buffer, "employees_needed") == 0) { in_employees_needed = 1; }
2386  if(strcmp(buffer, "/employees_needed") == 0) { in_employees_needed = 0; }
2387  if(strcmp(buffer, "day_of_month_wages_paid") == 0) { in_day_of_month_wages_paid = 1; }
2388  if(strcmp(buffer, "/day_of_month_wages_paid") == 0) { in_day_of_month_wages_paid = 0; }
2389  if(strcmp(buffer, "labour_productivity") == 0) { in_labour_productivity = 1; }
2390  if(strcmp(buffer, "/labour_productivity") == 0) { in_labour_productivity = 0; }
2391  if(strcmp(buffer, "capital_productivity") == 0) { in_capital_productivity = 1; }
2392  if(strcmp(buffer, "/capital_productivity") == 0) { in_capital_productivity = 0; }
2393  if(strcmp(buffer, "capital_goods") == 0) { in_capital_goods = 1; }
2394  if(strcmp(buffer, "/capital_goods") == 0) { in_capital_goods = 0; }
2395  if(strcmp(buffer, "capital_goods_price") == 0) { in_capital_goods_price = 1; }
2396  if(strcmp(buffer, "/capital_goods_price") == 0) { in_capital_goods_price = 0; }
2397  if(strcmp(buffer, "production_current") == 0) { in_production_current = 1; }
2398  if(strcmp(buffer, "/production_current") == 0) { in_production_current = 0; }
2399  if(strcmp(buffer, "expected_sales") == 0) { in_expected_sales = 1; }
2400  if(strcmp(buffer, "/expected_sales") == 0) { in_expected_sales = 0; }
2401  if(strcmp(buffer, "production_plan") == 0) { in_production_plan = 1; }
2402  if(strcmp(buffer, "/production_plan") == 0) { in_production_plan = 0; }
2403  if(strcmp(buffer, "unit_goods_price") == 0) { in_unit_goods_price = 1; }
2404  if(strcmp(buffer, "/unit_goods_price") == 0) { in_unit_goods_price = 0; }
2405  if(strcmp(buffer, "unit_cost") == 0) { in_unit_cost = 1; }
2406  if(strcmp(buffer, "/unit_cost") == 0) { in_unit_cost = 0; }
2407  if(strcmp(buffer, "day_of_month_production_completed") == 0) { in_day_of_month_production_completed = 1; }
2408  if(strcmp(buffer, "/day_of_month_production_completed") == 0) { in_day_of_month_production_completed = 0; }
2409  if(strcmp(buffer, "unit_house_price") == 0) { in_unit_house_price = 1; }
2410  if(strcmp(buffer, "/unit_house_price") == 0) { in_unit_house_price = 0; }
2411  if(strcmp(buffer, "projects") == 0) { in_projects = 1; }
2412  if(strcmp(buffer, "/projects") == 0) { in_projects = 0; }
2413  if(strcmp(buffer, "loans_interest_rate") == 0) { in_loans_interest_rate = 1; }
2414  if(strcmp(buffer, "/loans_interest_rate") == 0) { in_loans_interest_rate = 0; }
2415  if(strcmp(buffer, "debt") == 0) { in_debt = 1; }
2416  if(strcmp(buffer, "/debt") == 0) { in_debt = 0; }
2417  if(strcmp(buffer, "inventory") == 0) { in_inventory = 1; }
2418  if(strcmp(buffer, "/inventory") == 0) { in_inventory = 0; }
2419  if(strcmp(buffer, "sales") == 0) { in_sales = 1; }
2420  if(strcmp(buffer, "/sales") == 0) { in_sales = 0; }
2421  if(strcmp(buffer, "revenues") == 0) { in_revenues = 1; }
2422  if(strcmp(buffer, "/revenues") == 0) { in_revenues = 0; }
2423  if(strcmp(buffer, "total_assets") == 0) { in_total_assets = 1; }
2424  if(strcmp(buffer, "/total_assets") == 0) { in_total_assets = 0; }
2425  if(strcmp(buffer, "operating_costs") == 0) { in_operating_costs = 1; }
2426  if(strcmp(buffer, "/operating_costs") == 0) { in_operating_costs = 0; }
2427  if(strcmp(buffer, "labour_costs") == 0) { in_labour_costs = 1; }
2428  if(strcmp(buffer, "/labour_costs") == 0) { in_labour_costs = 0; }
2429  if(strcmp(buffer, "total_interest_payments") == 0) { in_total_interest_payments = 1; }
2430  if(strcmp(buffer, "/total_interest_payments") == 0) { in_total_interest_payments = 0; }
2431  if(strcmp(buffer, "dividends_paid") == 0) { in_dividends_paid = 1; }
2432  if(strcmp(buffer, "/dividends_paid") == 0) { in_dividends_paid = 0; }
2433  if(strcmp(buffer, "dividends_to_be_paid") == 0) { in_dividends_to_be_paid = 1; }
2434  if(strcmp(buffer, "/dividends_to_be_paid") == 0) { in_dividends_to_be_paid = 0; }
2435  if(strcmp(buffer, "retained_earnings") == 0) { in_retained_earnings = 1; }
2436  if(strcmp(buffer, "/retained_earnings") == 0) { in_retained_earnings = 0; }
2437  if(strcmp(buffer, "net_earnings") == 0) { in_net_earnings = 1; }
2438  if(strcmp(buffer, "/net_earnings") == 0) { in_net_earnings = 0; }
2439  if(strcmp(buffer, "ebit") == 0) { in_ebit = 1; }
2440  if(strcmp(buffer, "/ebit") == 0) { in_ebit = 0; }
2441  if(strcmp(buffer, "equity") == 0) { in_equity = 1; }
2442  if(strcmp(buffer, "/equity") == 0) { in_equity = 0; }
2443  if(strcmp(buffer, "liquidity") == 0) { in_liquidity = 1; }
2444  if(strcmp(buffer, "/liquidity") == 0) { in_liquidity = 0; }
2445  if(strcmp(buffer, "isliquidshort") == 0) { in_isliquidshort = 1; }
2446  if(strcmp(buffer, "/isliquidshort") == 0) { in_isliquidshort = 0; }
2447  if(strcmp(buffer, "hasloan") == 0) { in_hasloan = 1; }
2448  if(strcmp(buffer, "/hasloan") == 0) { in_hasloan = 0; }
2449  if(strcmp(buffer, "hasinvestment") == 0) { in_hasinvestment = 1; }
2450  if(strcmp(buffer, "/hasinvestment") == 0) { in_hasinvestment = 0; }
2451  if(strcmp(buffer, "isilliquid") == 0) { in_isilliquid = 1; }
2452  if(strcmp(buffer, "/isilliquid") == 0) { in_isilliquid = 0; }
2453  if(strcmp(buffer, "planned_investment_costs") == 0) { in_planned_investment_costs = 1; }
2454  if(strcmp(buffer, "/planned_investment_costs") == 0) { in_planned_investment_costs = 0; }
2455  if(strcmp(buffer, "liquidity_need") == 0) { in_liquidity_need = 1; }
2456  if(strcmp(buffer, "/liquidity_need") == 0) { in_liquidity_need = 0; }
2457  if(strcmp(buffer, "loan_list") == 0) { in_loan_list = 1; }
2458  if(strcmp(buffer, "/loan_list") == 0) { in_loan_list = 0; }
2459  if(strcmp(buffer, "labour_tax_rate") == 0) { in_labour_tax_rate = 1; }
2460  if(strcmp(buffer, "/labour_tax_rate") == 0) { in_labour_tax_rate = 0; }
2461  if(strcmp(buffer, "delta_housing_price") == 0) { in_delta_housing_price = 1; }
2462  if(strcmp(buffer, "/delta_housing_price") == 0) { in_delta_housing_price = 0; }
2463  if(strcmp(buffer, "weekly_consumption_budget") == 0) { in_weekly_consumption_budget = 1; }
2464  if(strcmp(buffer, "/weekly_consumption_budget") == 0) { in_weekly_consumption_budget = 0; }
2465  if(strcmp(buffer, "mall_budget") == 0) { in_mall_budget = 1; }
2466  if(strcmp(buffer, "/mall_budget") == 0) { in_mall_budget = 0; }
2467  if(strcmp(buffer, "quarterly_price_change") == 0) { in_quarterly_price_change = 1; }
2468  if(strcmp(buffer, "/quarterly_price_change") == 0) { in_quarterly_price_change = 0; }
2469  if(strcmp(buffer, "my_employer_id") == 0) { in_my_employer_id = 1; }
2470  if(strcmp(buffer, "/my_employer_id") == 0) { in_my_employer_id = 0; }
2471  if(strcmp(buffer, "wage") == 0) { in_wage = 1; }
2472  if(strcmp(buffer, "/wage") == 0) { in_wage = 0; }
2473  if(strcmp(buffer, "ismanager") == 0) { in_ismanager = 1; }
2474  if(strcmp(buffer, "/ismanager") == 0) { in_ismanager = 0; }
2475  if(strcmp(buffer, "government_benefits") == 0) { in_government_benefits = 1; }
2476  if(strcmp(buffer, "/government_benefits") == 0) { in_government_benefits = 0; }
2477  if(strcmp(buffer, "day_of_month_wage_recieved") == 0) { in_day_of_month_wage_recieved = 1; }
2478  if(strcmp(buffer, "/day_of_month_wage_recieved") == 0) { in_day_of_month_wage_recieved = 0; }
2479  if(strcmp(buffer, "mortgages_interest_rate") == 0) { in_mortgages_interest_rate = 1; }
2480  if(strcmp(buffer, "/mortgages_interest_rate") == 0) { in_mortgages_interest_rate = 0; }
2481  if(strcmp(buffer, "mortgages_list") == 0) { in_mortgages_list = 1; }
2482  if(strcmp(buffer, "/mortgages_list") == 0) { in_mortgages_list = 0; }
2483  if(strcmp(buffer, "mortgages") == 0) { in_mortgages = 1; }
2484  if(strcmp(buffer, "/mortgages") == 0) { in_mortgages = 0; }
2485  if(strcmp(buffer, "housing_payment") == 0) { in_housing_payment = 1; }
2486  if(strcmp(buffer, "/housing_payment") == 0) { in_housing_payment = 0; }
2487  if(strcmp(buffer, "housing_price") == 0) { in_housing_price = 1; }
2488  if(strcmp(buffer, "/housing_price") == 0) { in_housing_price = 0; }
2489  if(strcmp(buffer, "housing_units") == 0) { in_housing_units = 1; }
2490  if(strcmp(buffer, "/housing_units") == 0) { in_housing_units = 0; }
2491  if(strcmp(buffer, "n_shares") == 0) { in_n_shares = 1; }
2492  if(strcmp(buffer, "/n_shares") == 0) { in_n_shares = 0; }
2493  if(strcmp(buffer, "capital_income") == 0) { in_capital_income = 1; }
2494  if(strcmp(buffer, "/capital_income") == 0) { in_capital_income = 0; }
2495  if(strcmp(buffer, "previous_wages") == 0) { in_previous_wages = 1; }
2496  if(strcmp(buffer, "/previous_wages") == 0) { in_previous_wages = 0; }
2497  if(strcmp(buffer, "previous_benefits") == 0) { in_previous_benefits = 1; }
2498  if(strcmp(buffer, "/previous_benefits") == 0) { in_previous_benefits = 0; }
2499  if(strcmp(buffer, "labour_income") == 0) { in_labour_income = 1; }
2500  if(strcmp(buffer, "/labour_income") == 0) { in_labour_income = 0; }
2501  if(strcmp(buffer, "housing_value") == 0) { in_housing_value = 1; }
2502  if(strcmp(buffer, "/housing_value") == 0) { in_housing_value = 0; }
2503  if(strcmp(buffer, "expected_housing_payment") == 0) { in_expected_housing_payment = 1; }
2504  if(strcmp(buffer, "/expected_housing_payment") == 0) { in_expected_housing_payment = 0; }
2505  if(strcmp(buffer, "hmarket_role") == 0) { in_hmarket_role = 1; }
2506  if(strcmp(buffer, "/hmarket_role") == 0) { in_hmarket_role = 0; }
2507  if(strcmp(buffer, "equity_ratio") == 0) { in_equity_ratio = 1; }
2508  if(strcmp(buffer, "/equity_ratio") == 0) { in_equity_ratio = 0; }
2509  if(strcmp(buffer, "minimum_equity_ratio") == 0) { in_minimum_equity_ratio = 1; }
2510  if(strcmp(buffer, "/minimum_equity_ratio") == 0) { in_minimum_equity_ratio = 0; }
2511  if(strcmp(buffer, "mortgage_costs") == 0) { in_mortgage_costs = 1; }
2512  if(strcmp(buffer, "/mortgage_costs") == 0) { in_mortgage_costs = 0; }
2513  if(strcmp(buffer, "delta_housing_value") == 0) { in_delta_housing_value = 1; }
2514  if(strcmp(buffer, "/delta_housing_value") == 0) { in_delta_housing_value = 0; }
2515  if(strcmp(buffer, "mortgage_choice") == 0) { in_mortgage_choice = 1; }
2516  if(strcmp(buffer, "/mortgage_choice") == 0) { in_mortgage_choice = 0; }
2517  if(strcmp(buffer, "share_firms") == 0) { in_share_firms = 1; }
2518  if(strcmp(buffer, "/share_firms") == 0) { in_share_firms = 0; }
2519  if(strcmp(buffer, "share_construction_firms") == 0) { in_share_construction_firms = 1; }
2520  if(strcmp(buffer, "/share_construction_firms") == 0) { in_share_construction_firms = 0; }
2521  if(strcmp(buffer, "share_banks") == 0) { in_share_banks = 1; }
2522  if(strcmp(buffer, "/share_banks") == 0) { in_share_banks = 0; }
2523  if(strcmp(buffer, "dividends_recieved") == 0) { in_dividends_recieved = 1; }
2524  if(strcmp(buffer, "/dividends_recieved") == 0) { in_dividends_recieved = 0; }
2525  if(strcmp(buffer, "dividends_retained") == 0) { in_dividends_retained = 1; }
2526  if(strcmp(buffer, "/dividends_retained") == 0) { in_dividends_retained = 0; }
2527  if(strcmp(buffer, "firm_investment") == 0) { in_firm_investment = 1; }
2528  if(strcmp(buffer, "/firm_investment") == 0) { in_firm_investment = 0; }
2529  if(strcmp(buffer, "capital_tax_rate") == 0) { in_capital_tax_rate = 1; }
2530  if(strcmp(buffer, "/capital_tax_rate") == 0) { in_capital_tax_rate = 0; }
2531  if(strcmp(buffer, "loans") == 0) { in_loans = 1; }
2532  if(strcmp(buffer, "/loans") == 0) { in_loans = 0; }
2533  if(strcmp(buffer, "loans_start") == 0) { in_loans_start = 1; }
2534  if(strcmp(buffer, "/loans_start") == 0) { in_loans_start = 0; }
2535  if(strcmp(buffer, "deposits") == 0) { in_deposits = 1; }
2536  if(strcmp(buffer, "/deposits") == 0) { in_deposits = 0; }
2537  if(strcmp(buffer, "centralbank_debt") == 0) { in_centralbank_debt = 1; }
2538  if(strcmp(buffer, "/centralbank_debt") == 0) { in_centralbank_debt = 0; }
2539  if(strcmp(buffer, "total_writeoffs") == 0) { in_total_writeoffs = 1; }
2540  if(strcmp(buffer, "/total_writeoffs") == 0) { in_total_writeoffs = 0; }
2541  if(strcmp(buffer, "interest_rate") == 0) { in_interest_rate = 1; }
2542  if(strcmp(buffer, "/interest_rate") == 0) { in_interest_rate = 0; }
2543  if(strcmp(buffer, "interests_accrued") == 0) { in_interests_accrued = 1; }
2544  if(strcmp(buffer, "/interests_accrued") == 0) { in_interests_accrued = 0; }
2545  if(strcmp(buffer, "interests_paid") == 0) { in_interests_paid = 1; }
2546  if(strcmp(buffer, "/interests_paid") == 0) { in_interests_paid = 0; }
2547  if(strcmp(buffer, "total_dividends") == 0) { in_total_dividends = 1; }
2548  if(strcmp(buffer, "/total_dividends") == 0) { in_total_dividends = 0; }
2549  if(strcmp(buffer, "total_costs") == 0) { in_total_costs = 1; }
2550  if(strcmp(buffer, "/total_costs") == 0) { in_total_costs = 0; }
2551  if(strcmp(buffer, "unemployment_rate") == 0) { in_unemployment_rate = 1; }
2552  if(strcmp(buffer, "/unemployment_rate") == 0) { in_unemployment_rate = 0; }
2553  if(strcmp(buffer, "population_size") == 0) { in_population_size = 1; }
2554  if(strcmp(buffer, "/population_size") == 0) { in_population_size = 0; }
2555  if(strcmp(buffer, "labour_tax_income") == 0) { in_labour_tax_income = 1; }
2556  if(strcmp(buffer, "/labour_tax_income") == 0) { in_labour_tax_income = 0; }
2557  if(strcmp(buffer, "capital_tax_income") == 0) { in_capital_tax_income = 1; }
2558  if(strcmp(buffer, "/capital_tax_income") == 0) { in_capital_tax_income = 0; }
2559  if(strcmp(buffer, "gov_general_benefit_rate") == 0) { in_gov_general_benefit_rate = 1; }
2560  if(strcmp(buffer, "/gov_general_benefit_rate") == 0) { in_gov_general_benefit_rate = 0; }
2561  if(strcmp(buffer, "gov_unemployment_rate") == 0) { in_gov_unemployment_rate = 1; }
2562  if(strcmp(buffer, "/gov_unemployment_rate") == 0) { in_gov_unemployment_rate = 0; }
2563  if(strcmp(buffer, "general_benefits") == 0) { in_general_benefits = 1; }
2564  if(strcmp(buffer, "/general_benefits") == 0) { in_general_benefits = 0; }
2565  if(strcmp(buffer, "unemployment_benefits") == 0) { in_unemployment_benefits = 1; }
2566  if(strcmp(buffer, "/unemployment_benefits") == 0) { in_unemployment_benefits = 0; }
2567  if(strcmp(buffer, "earnings") == 0) { in_earnings = 1; }
2568  if(strcmp(buffer, "/earnings") == 0) { in_earnings = 0; }
2569  if(strcmp(buffer, "centralbank_income") == 0) { in_centralbank_income = 1; }
2570  if(strcmp(buffer, "/centralbank_income") == 0) { in_centralbank_income = 0; }
2571  if(strcmp(buffer, "expenditures") == 0) { in_expenditures = 1; }
2572  if(strcmp(buffer, "/expenditures") == 0) { in_expenditures = 0; }
2573  if(strcmp(buffer, "inflation_rate") == 0) { in_inflation_rate = 1; }
2574  if(strcmp(buffer, "/inflation_rate") == 0) { in_inflation_rate = 0; }
2575  if(strcmp(buffer, "consumption_goods_prices") == 0) { in_consumption_goods_prices = 1; }
2576  if(strcmp(buffer, "/consumption_goods_prices") == 0) { in_consumption_goods_prices = 0; }
2577  if(strcmp(buffer, "goods") == 0) { in_goods = 1; }
2578  if(strcmp(buffer, "/goods") == 0) { in_goods = 0; }
2579  if(strcmp(buffer, "weekly_price_averages") == 0) { in_weekly_price_averages = 1; }
2580  if(strcmp(buffer, "/weekly_price_averages") == 0) { in_weekly_price_averages = 0; }
2581  if(strcmp(buffer, "loans_banks") == 0) { in_loans_banks = 1; }
2582  if(strcmp(buffer, "/loans_banks") == 0) { in_loans_banks = 0; }
2583  if(strcmp(buffer, "loans_government") == 0) { in_loans_government = 1; }
2584  if(strcmp(buffer, "/loans_government") == 0) { in_loans_government = 0; }
2585  if(strcmp(buffer, "fiat_money") == 0) { in_fiat_money = 1; }
2586  if(strcmp(buffer, "/fiat_money") == 0) { in_fiat_money = 0; }
2587  if(strcmp(buffer, "liquidity_banks") == 0) { in_liquidity_banks = 1; }
2588  if(strcmp(buffer, "/liquidity_banks") == 0) { in_liquidity_banks = 0; }
2589  if(strcmp(buffer, "liquidity_government") == 0) { in_liquidity_government = 1; }
2590  if(strcmp(buffer, "/liquidity_government") == 0) { in_liquidity_government = 0; }
2591  if(strcmp(buffer, "liquidity_equityfund") == 0) { in_liquidity_equityfund = 1; }
2592  if(strcmp(buffer, "/liquidity_equityfund") == 0) { in_liquidity_equityfund = 0; }
2593  if(strcmp(buffer, "houses") == 0) { in_houses = 1; }
2594  if(strcmp(buffer, "/houses") == 0) { in_houses = 0; }
2595  if(strcmp(buffer, "goods_transactions") == 0) { in_goods_transactions = 1; }
2596  if(strcmp(buffer, "/goods_transactions") == 0) { in_goods_transactions = 0; }
2597  if(strcmp(buffer, "housing_transactions") == 0) { in_housing_transactions = 1; }
2598  if(strcmp(buffer, "/housing_transactions") == 0) { in_housing_transactions = 0; }
2599 
2600  index = 0;
2601  buffer[index] = '\0';
2602  }
2603  else if(c == '<')
2604  {
2605  buffer[index] = '\0';
2606 
2607  if(in_itno && FLAME_in_xagent == 0) *itno = atoi(buffer);
2608  if(FLAME_in_xagent == 1)
2609  {
2610  if(FLAME_in_name == 1)
2611  {
2612  strcpy(agentname, buffer);
2613 
2614  if(strcmp(agentname, "firm") == 0)
2615  {
2616  current_firm_agent = init_firm_agent();
2617  in_firm_agent = 1;
2618  }
2619  else if(strcmp(agentname, "household") == 0)
2620  {
2621  current_household_agent = init_household_agent();
2622  in_household_agent = 1;
2623  }
2624  else if(strcmp(agentname, "equityfund") == 0)
2625  {
2626  current_equityfund_agent = init_equityfund_agent();
2627  in_equityfund_agent = 1;
2628  }
2629  else if(strcmp(agentname, "bank") == 0)
2630  {
2631  current_bank_agent = init_bank_agent();
2632  in_bank_agent = 1;
2633  }
2634  else if(strcmp(agentname, "government") == 0)
2635  {
2636  current_government_agent = init_government_agent();
2637  in_government_agent = 1;
2638  }
2639  else if(strcmp(agentname, "centralbank") == 0)
2640  {
2641  current_centralbank_agent = init_centralbank_agent();
2642  in_centralbank_agent = 1;
2643  }
2644  else if(strcmp(agentname, "jpoffice") == 0)
2645  {
2646  current_jpoffice_agent = init_jpoffice_agent();
2647  in_jpoffice_agent = 1;
2648  }
2649  else if(strcmp(agentname, "mall") == 0)
2650  {
2651  current_mall_agent = init_mall_agent();
2652  in_mall_agent = 1;
2653  }
2654  else if(strcmp(agentname, "reagency") == 0)
2655  {
2656  current_reagency_agent = init_reagency_agent();
2657  in_reagency_agent = 1;
2658  }
2659  else
2660  {
2661  printf("Warning: agent name undefined - '%s'\n", agentname);
2662  exit(0);
2663  }
2664  }
2665  else if(in_firm_agent == 1)
2666  {
2667  if(in_id) { current_firm_agent->id = atoi(buffer); }
2668  if(in_bank_id) { current_firm_agent->bank_id = atoi(buffer); }
2669  if(in_isconstructor) { current_firm_agent->isconstructor = atoi(buffer); }
2670  if(in_day_of_month_to_act) { current_firm_agent->day_of_month_to_act = atoi(buffer); }
2671  if(in_isinsolvent) { current_firm_agent->isinsolvent = atoi(buffer); }
2672  if(in_it_no) { current_firm_agent->it_no = atoi(buffer); }
2673  if(in_day_of_week_to_act) { current_firm_agent->day_of_week_to_act = atoi(buffer); }
2674  if(in_average_goods_price) { current_firm_agent->average_goods_price = atof(buffer); }
2675  if(in_employees) { j = 0;
2676  rc = read_int_dynamic_array(buffer, index, &j, &current_firm_agent->employees);
2677  if(rc != 0) { printf("Error: reading 'firm' agent variable 'employees' of type 'int_array'\n"); exit(0); } }
2678  if(in_manager) { current_firm_agent->manager = atoi(buffer); }
2679  if(in_wage_offer) { current_firm_agent->wage_offer = atof(buffer); }
2680  if(in_average_wage) { current_firm_agent->average_wage = atof(buffer); }
2681  if(in_no_employees) { current_firm_agent->no_employees = atoi(buffer); }
2682  if(in_vacancies) { current_firm_agent->vacancies = atoi(buffer); }
2683  if(in_employees_needed) { current_firm_agent->employees_needed = atoi(buffer); }
2684  if(in_day_of_month_wages_paid) { current_firm_agent->day_of_month_wages_paid = atoi(buffer); }
2685  if(in_labour_productivity) { current_firm_agent->labour_productivity = atof(buffer); }
2686  if(in_capital_productivity) { current_firm_agent->capital_productivity = atof(buffer); }
2687  if(in_capital_goods) { current_firm_agent->capital_goods = atoi(buffer); }
2688  if(in_capital_goods_price) { current_firm_agent->capital_goods_price = atof(buffer); }
2689  if(in_production_current) { current_firm_agent->production_current = atoi(buffer); }
2690  if(in_expected_sales) { current_firm_agent->expected_sales = atoi(buffer); }
2691  if(in_production_plan) { current_firm_agent->production_plan = atoi(buffer); }
2692  if(in_unit_goods_price) { current_firm_agent->unit_goods_price = atof(buffer); }
2693  if(in_unit_cost) { current_firm_agent->unit_cost = atof(buffer); }
2694  if(in_day_of_month_production_completed) { current_firm_agent->day_of_month_production_completed = atoi(buffer); }
2695  if(in_unit_house_price) { current_firm_agent->unit_house_price = atof(buffer); }
2696  if(in_projects) { j = 0;
2697  rc = read_int_static_array(buffer, index, &j, current_firm_agent->projects, 12);
2698  if(rc != 0) { printf("Error: reading 'firm' agent variable 'projects' of type 'int'\n"); exit(0); } }
2699  if(in_loans_interest_rate) { current_firm_agent->loans_interest_rate = atof(buffer); }
2700  if(in_debt) { current_firm_agent->debt = atof(buffer); }
2701  if(in_inventory) { current_firm_agent->inventory = atoi(buffer); }
2702  if(in_sales) { current_firm_agent->sales = atoi(buffer); }
2703  if(in_revenues) { current_firm_agent->revenues = atof(buffer); }
2704  if(in_total_assets) { current_firm_agent->total_assets = atof(buffer); }
2705  if(in_operating_costs) { current_firm_agent->operating_costs = atof(buffer); }
2706  if(in_labour_costs) { current_firm_agent->labour_costs = atof(buffer); }
2707  if(in_total_interest_payments) { current_firm_agent->total_interest_payments = atof(buffer); }
2708  if(in_dividends_paid) { current_firm_agent->dividends_paid = atof(buffer); }
2709  if(in_dividends_to_be_paid) { current_firm_agent->dividends_to_be_paid = atof(buffer); }
2710  if(in_retained_earnings) { current_firm_agent->retained_earnings = atof(buffer); }
2711  if(in_net_earnings) { current_firm_agent->net_earnings = atof(buffer); }
2712  if(in_ebit) { current_firm_agent->ebit = atof(buffer); }
2713  if(in_equity) { current_firm_agent->equity = atof(buffer); }
2714  if(in_liquidity) { current_firm_agent->liquidity = atof(buffer); }
2715  if(in_isliquidshort) { current_firm_agent->isliquidshort = atoi(buffer); }
2716  if(in_hasloan) { current_firm_agent->hasloan = atoi(buffer); }
2717  if(in_hasinvestment) { current_firm_agent->hasinvestment = atoi(buffer); }
2718  if(in_isilliquid) { current_firm_agent->isilliquid = atoi(buffer); }
2719  if(in_planned_investment_costs) { current_firm_agent->planned_investment_costs = atof(buffer); }
2720  if(in_liquidity_need) { current_firm_agent->liquidity_need = atof(buffer); }
2721  if(in_loan_list) { j = 0;
2722  rc = read_loan_static_array(buffer, index, &j, current_firm_agent->loan_list, 2);
2723  if(rc != 0) { printf("Error: reading 'firm' agent variable 'loan_list' of type 'loan'\n"); exit(0); } }
2724  if(in_labour_tax_rate) { current_firm_agent->labour_tax_rate = atof(buffer); }
2725  if(in_delta_housing_price) { current_firm_agent->delta_housing_price = atof(buffer); }
2726  }else if(in_household_agent == 1)
2727  {
2728  if(in_id) { current_household_agent->id = atoi(buffer); }
2729  if(in_bank_id) { current_household_agent->bank_id = atoi(buffer); }
2730  if(in_it_no) { current_household_agent->it_no = atoi(buffer); }
2731  if(in_day_of_week_to_act) { current_household_agent->day_of_week_to_act = atoi(buffer); }
2732  if(in_weekly_consumption_budget) { current_household_agent->weekly_consumption_budget = atof(buffer); }
2733  if(in_mall_budget) { current_household_agent->mall_budget = atof(buffer); }
2734  if(in_quarterly_price_change) { current_household_agent->quarterly_price_change = atof(buffer); }
2735  if(in_my_employer_id) { current_household_agent->my_employer_id = atoi(buffer); }
2736  if(in_wage) { current_household_agent->wage = atof(buffer); }
2737  if(in_ismanager) { current_household_agent->ismanager = atoi(buffer); }
2738  if(in_government_benefits) { current_household_agent->government_benefits = atof(buffer); }
2739  if(in_day_of_month_to_act) { current_household_agent->day_of_month_to_act = atoi(buffer); }
2740  if(in_day_of_month_wage_recieved) { current_household_agent->day_of_month_wage_recieved = atoi(buffer); }
2741  if(in_mortgages_interest_rate) { current_household_agent->mortgages_interest_rate = atof(buffer); }
2742  if(in_labour_tax_rate) { current_household_agent->labour_tax_rate = atof(buffer); }
2743  if(in_mortgages_list) { j = 0;
2744  rc = read_mortgage_dynamic_array(buffer, index, &j, &current_household_agent->mortgages_list);
2745  if(rc != 0) { printf("Error: reading 'household' agent variable 'mortgages_list' of type 'mortgage_array'\n"); exit(0); } }
2746  if(in_mortgages) { current_household_agent->mortgages = atof(buffer); }
2747  if(in_housing_payment) { current_household_agent->housing_payment = atof(buffer); }
2748  if(in_equity) { current_household_agent->equity = atof(buffer); }
2749  if(in_housing_price) { current_household_agent->housing_price = atof(buffer); }
2750  if(in_housing_units) { current_household_agent->housing_units = atoi(buffer); }
2751  if(in_n_shares) { current_household_agent->n_shares = atoi(buffer); }
2752  if(in_liquidity) { current_household_agent->liquidity = atof(buffer); }
2753  if(in_capital_income) { current_household_agent->capital_income = atof(buffer); }
2754  if(in_previous_wages) { j = 0;
2755  rc = read_double_static_array(buffer, index, &j, current_household_agent->previous_wages, 3);
2756  if(rc != 0) { printf("Error: reading 'household' agent variable 'previous_wages' of type 'double'\n"); exit(0); } }
2757  if(in_previous_benefits) { j = 0;
2758  rc = read_double_static_array(buffer, index, &j, current_household_agent->previous_benefits, 3);
2759  if(rc != 0) { printf("Error: reading 'household' agent variable 'previous_benefits' of type 'double'\n"); exit(0); } }
2760  if(in_labour_income) { current_household_agent->labour_income = atof(buffer); }
2761  if(in_total_assets) { current_household_agent->total_assets = atof(buffer); }
2762  if(in_housing_value) { current_household_agent->housing_value = atof(buffer); }
2763  if(in_expected_housing_payment) { current_household_agent->expected_housing_payment = atof(buffer); }
2764  if(in_hmarket_role) { current_household_agent->hmarket_role = atoi(buffer); }
2765  if(in_equity_ratio) { current_household_agent->equity_ratio = atof(buffer); }
2766  if(in_minimum_equity_ratio) { current_household_agent->minimum_equity_ratio = atof(buffer); }
2767  if(in_mortgage_costs) { j = 0;
2768  rc = read_double_static_array(buffer, index, &j, current_household_agent->mortgage_costs, 3);
2769  if(rc != 0) { printf("Error: reading 'household' agent variable 'mortgage_costs' of type 'double'\n"); exit(0); } }
2770  if(in_delta_housing_value) { current_household_agent->delta_housing_value = atof(buffer); }
2771  if(in_mortgage_choice) { current_household_agent->mortgage_choice = atoi(buffer); }
2772  }else if(in_equityfund_agent == 1)
2773  {
2774  if(in_id) { current_equityfund_agent->id = atoi(buffer); }
2775  if(in_it_no) { current_equityfund_agent->it_no = atoi(buffer); }
2776  if(in_day_of_month_to_act) { current_equityfund_agent->day_of_month_to_act = atoi(buffer); }
2777  if(in_day_of_month_wages_paid) { current_equityfund_agent->day_of_month_wages_paid = atoi(buffer); }
2778  if(in_share_firms) { current_equityfund_agent->share_firms = atof(buffer); }
2779  if(in_share_construction_firms) { current_equityfund_agent->share_construction_firms = atof(buffer); }
2780  if(in_share_banks) { current_equityfund_agent->share_banks = atof(buffer); }
2781  if(in_equity) { current_equityfund_agent->equity = atof(buffer); }
2782  if(in_liquidity) { current_equityfund_agent->liquidity = atof(buffer); }
2783  if(in_n_shares) { current_equityfund_agent->n_shares = atoi(buffer); }
2784  if(in_dividends_recieved) { current_equityfund_agent->dividends_recieved = atof(buffer); }
2785  if(in_dividends_retained) { current_equityfund_agent->dividends_retained = atof(buffer); }
2786  if(in_dividends_paid) { current_equityfund_agent->dividends_paid = atof(buffer); }
2787  if(in_firm_investment) { current_equityfund_agent->firm_investment = atof(buffer); }
2788  if(in_capital_tax_rate) { current_equityfund_agent->capital_tax_rate = atof(buffer); }
2789  }else if(in_bank_agent == 1)
2790  {
2791  if(in_id) { current_bank_agent->id = atoi(buffer); }
2792  if(in_day_of_month_to_act) { current_bank_agent->day_of_month_to_act = atoi(buffer); }
2793  if(in_day_of_week_to_act) { current_bank_agent->day_of_week_to_act = atoi(buffer); }
2794  if(in_it_no) { current_bank_agent->it_no = atoi(buffer); }
2795  if(in_total_assets) { current_bank_agent->total_assets = atof(buffer); }
2796  if(in_loans) { current_bank_agent->loans = atof(buffer); }
2797  if(in_loans_start) { current_bank_agent->loans_start = atof(buffer); }
2798  if(in_mortgages) { current_bank_agent->mortgages = atof(buffer); }
2799  if(in_deposits) { current_bank_agent->deposits = atof(buffer); }
2800  if(in_centralbank_debt) { current_bank_agent->centralbank_debt = atof(buffer); }
2801  if(in_equity) { current_bank_agent->equity = atof(buffer); }
2802  if(in_liquidity) { current_bank_agent->liquidity = atof(buffer); }
2803  if(in_revenues) { current_bank_agent->revenues = atof(buffer); }
2804  if(in_total_writeoffs) { current_bank_agent->total_writeoffs = atof(buffer); }
2805  if(in_interest_rate) { current_bank_agent->interest_rate = atof(buffer); }
2806  if(in_interests_accrued) { current_bank_agent->interests_accrued = atof(buffer); }
2807  if(in_interests_paid) { current_bank_agent->interests_paid = atof(buffer); }
2808  if(in_dividends_paid) { current_bank_agent->dividends_paid = atof(buffer); }
2809  if(in_total_dividends) { current_bank_agent->total_dividends = atof(buffer); }
2810  if(in_retained_earnings) { current_bank_agent->retained_earnings = atof(buffer); }
2811  if(in_net_earnings) { current_bank_agent->net_earnings = atof(buffer); }
2812  if(in_total_costs) { current_bank_agent->total_costs = atof(buffer); }
2813  }else if(in_government_agent == 1)
2814  {
2815  if(in_id) { current_government_agent->id = atoi(buffer); }
2816  if(in_it_no) { current_government_agent->it_no = atoi(buffer); }
2817  if(in_average_wage) { current_government_agent->average_wage = atof(buffer); }
2818  if(in_unemployment_rate) { current_government_agent->unemployment_rate = atof(buffer); }
2819  if(in_population_size) { current_government_agent->population_size = atoi(buffer); }
2820  if(in_debt) { current_government_agent->debt = atof(buffer); }
2821  if(in_equity) { current_government_agent->equity = atof(buffer); }
2822  if(in_liquidity) { current_government_agent->liquidity = atof(buffer); }
2823  if(in_day_of_month_to_act) { current_government_agent->day_of_month_to_act = atoi(buffer); }
2824  if(in_day_of_month_wages_paid) { current_government_agent->day_of_month_wages_paid = atoi(buffer); }
2825  if(in_capital_tax_rate) { current_government_agent->capital_tax_rate = atof(buffer); }
2826  if(in_labour_tax_rate) { current_government_agent->labour_tax_rate = atof(buffer); }
2827  if(in_labour_tax_income) { current_government_agent->labour_tax_income = atof(buffer); }
2828  if(in_capital_tax_income) { current_government_agent->capital_tax_income = atof(buffer); }
2829  if(in_gov_general_benefit_rate) { current_government_agent->gov_general_benefit_rate = atof(buffer); }
2830  if(in_gov_unemployment_rate) { current_government_agent->gov_unemployment_rate = atof(buffer); }
2831  if(in_general_benefits) { current_government_agent->general_benefits = atof(buffer); }
2832  if(in_unemployment_benefits) { current_government_agent->unemployment_benefits = atof(buffer); }
2833  if(in_earnings) { current_government_agent->earnings = atof(buffer); }
2834  if(in_centralbank_income) { current_government_agent->centralbank_income = atof(buffer); }
2835  if(in_expenditures) { current_government_agent->expenditures = atof(buffer); }
2836  }else if(in_centralbank_agent == 1)
2837  {
2838  if(in_id) { current_centralbank_agent->id = atoi(buffer); }
2839  if(in_day_of_month_to_act) { current_centralbank_agent->day_of_month_to_act = atoi(buffer); }
2840  if(in_unemployment_rate) { current_centralbank_agent->unemployment_rate = atof(buffer); }
2841  if(in_inflation_rate) { current_centralbank_agent->inflation_rate = atof(buffer); }
2842  if(in_consumption_goods_prices) { j = 0;
2843  rc = read_double_static_array(buffer, index, &j, current_centralbank_agent->consumption_goods_prices, 12);
2844  if(rc != 0) { printf("Error: reading 'centralbank' agent variable 'consumption_goods_prices' of type 'double'\n"); exit(0); } }
2845  if(in_it_no) { current_centralbank_agent->it_no = atoi(buffer); }
2846  if(in_day_of_week_to_act) { current_centralbank_agent->day_of_week_to_act = atoi(buffer); }
2847  if(in_goods) { j = 0;
2848  rc = read_transaction(buffer, index, &j, &current_centralbank_agent->goods);
2849  if(rc != 0) { printf("Error: reading 'centralbank' agent variable 'goods' of type 'transaction'\n"); exit(0); } }
2850  if(in_weekly_price_averages) { j = 0;
2851  rc = read_double_static_array(buffer, index, &j, current_centralbank_agent->weekly_price_averages, 4);
2852  if(rc != 0) { printf("Error: reading 'centralbank' agent variable 'weekly_price_averages' of type 'double'\n"); exit(0); } }
2853  if(in_day_of_month_wages_paid) { current_centralbank_agent->day_of_month_wages_paid = atoi(buffer); }
2854  if(in_interest_rate) { current_centralbank_agent->interest_rate = atof(buffer); }
2855  if(in_liquidity) { current_centralbank_agent->liquidity = atof(buffer); }
2856  if(in_loans_banks) { current_centralbank_agent->loans_banks = atof(buffer); }
2857  if(in_loans_government) { current_centralbank_agent->loans_government = atof(buffer); }
2858  if(in_fiat_money) { current_centralbank_agent->fiat_money = atof(buffer); }
2859  if(in_equity) { current_centralbank_agent->equity = atof(buffer); }
2860  if(in_liquidity_banks) { current_centralbank_agent->liquidity_banks = atof(buffer); }
2861  if(in_liquidity_government) { current_centralbank_agent->liquidity_government = atof(buffer); }
2862  if(in_liquidity_equityfund) { current_centralbank_agent->liquidity_equityfund = atof(buffer); }
2863  if(in_total_assets) { current_centralbank_agent->total_assets = atof(buffer); }
2864  if(in_total_writeoffs) { current_centralbank_agent->total_writeoffs = atof(buffer); }
2865  if(in_interests_accrued) { current_centralbank_agent->interests_accrued = atof(buffer); }
2866  if(in_revenues) { current_centralbank_agent->revenues = atof(buffer); }
2867  if(in_net_earnings) { current_centralbank_agent->net_earnings = atof(buffer); }
2868  if(in_total_costs) { current_centralbank_agent->total_costs = atof(buffer); }
2869  if(in_houses) { j = 0;
2870  rc = read_transaction(buffer, index, &j, &current_centralbank_agent->houses);
2871  if(rc != 0) { printf("Error: reading 'centralbank' agent variable 'houses' of type 'transaction'\n"); exit(0); } }
2872  }else if(in_jpoffice_agent == 1)
2873  {
2874  if(in_id) { current_jpoffice_agent->id = atoi(buffer); }
2875  if(in_it_no) { current_jpoffice_agent->it_no = atoi(buffer); }
2876  if(in_day_of_month_to_act) { current_jpoffice_agent->day_of_month_to_act = atoi(buffer); }
2877  }else if(in_mall_agent == 1)
2878  {
2879  if(in_id) { current_mall_agent->id = atoi(buffer); }
2880  if(in_it_no) { current_mall_agent->it_no = atoi(buffer); }
2881  if(in_day_of_week_to_act) { current_mall_agent->day_of_week_to_act = atoi(buffer); }
2882  if(in_goods_transactions) { j = 0;
2883  rc = read_transaction(buffer, index, &j, &current_mall_agent->goods_transactions);
2884  if(rc != 0) { printf("Error: reading 'mall' agent variable 'goods_transactions' of type 'transaction'\n"); exit(0); } }
2885  }else if(in_reagency_agent == 1)
2886  {
2887  if(in_id) { current_reagency_agent->id = atoi(buffer); }
2888  if(in_day_of_month_to_act) { current_reagency_agent->day_of_month_to_act = atoi(buffer); }
2889  if(in_it_no) { current_reagency_agent->it_no = atoi(buffer); }
2890  if(in_mortgages_interest_rate) { current_reagency_agent->mortgages_interest_rate = atof(buffer); }
2891  if(in_housing_transactions) { j = 0;
2892  rc = read_transaction(buffer, index, &j, &current_reagency_agent->housing_transactions);
2893  if(rc != 0) { printf("Error: reading 'reagency' agent variable 'housing_transactions' of type 'transaction'\n"); exit(0); } }
2894  }
2895  }
2896  index = 0;
2897  buffer[index] = '\0';
2898  }
2899  else
2900  {
2901  buffer[index] = c;
2902  if(index < 99999) index++;
2903  else
2904  {
2905  printf("Error: agent reading buffer too small\n");
2906  printf("%s\n", buffer);
2907  exit(0);
2908  }
2909  }
2910  }
2911  /* Close file */
2912  (void)fclose(file);
2913 
2914  return 0;
2915 }
2916 
2922 {
2923  /* Save a dummy file to directory and remove.
2924  * This checks directory exists and is writable */
2925  FILE * file;
2926  char * buffer;
2927 
2928  buffer = (char *)malloc( (strlen(location) + strlen("dummy.temp") + 1) * sizeof(char));
2929  strcpy(buffer, location);
2930  strcat(buffer, "dummy.temp");
2931 
2932  if((file = fopen(buffer, "w")) == NULL) return 0;
2933 
2934  (void)fclose(file);
2935  /* Remove dummy file */
2936  remove(buffer);
2937 
2938  return 1;
2939 }
2940 
2941 
2952 void readinitialstates(char * filename, char * filelocation, int * itno, double cloud_data[],
2953  int partition_method, int flag)
2954 {
2955  /* Pointer to file */
2956  FILE *file;
2957  /* Char and char buffer for reading file to */
2958  char c = '\0';
2959  char buffer[100000];
2960  char FLAME_location[10000];
2961  char FLAME_format[10000];
2962  char FLAME_type[10000];
2963  FLAME_output * current_FLAME_output = NULL;
2964 
2965  /* Things for round-robin partitioning */
2966  int agent_count = 0;
2967  int number_partitions = 0;
2968  int geometric=1;
2969  int other=2;
2970 
2971 
2972  /* Cloud data array initialisation */
2973  # ifndef S_SPLINT_S
2974  cloud_data[0] = SPINF;
2975  cloud_data[1] = -SPINF;
2976  cloud_data[2] = SPINF;
2977  cloud_data[3] = -SPINF;
2978  cloud_data[4] = SPINF;
2979  cloud_data[5] = -SPINF;
2980  # endif
2981 
2982  /* Temporary node and head of associated agent list to allow adding agents */
2983  node_information temp_node;
2984 
2985  /* Pointer to x-memory for initial state data */
2986  /*xmachine * current_xmachine;*/
2987  /* Variables for checking tags */
2988  int reading = 1;
2989  int i = 0;
2990  int rc;
2991  int in_tag = 0;
2992  int in_itno = 0;
2993  int FLAME_in_imports = 0;
2994  int FLAME_in_import = 0;
2995  int FLAME_in_outputs = 0;
2996  int FLAME_in_output = 0;
2997  int FLAME_in_location = 0;
2998  int FLAME_in_format = 0;
2999  int FLAME_in_type = 0;
3000  int FLAME_in_time = 0;
3001  int FLAME_in_period = 0;
3002  int FLAME_in_phase = 0;
3003  int FLAME_in_name = 0;
3004 
3005  /* Initialise environment vars */
3034 
3035 
3036  /* Open config file to read-only */
3037  if((file = fopen(filename, "r"))==NULL)
3038  {
3039  printf("Error: opening initial states '%s'\n", filename);
3040  exit(0);
3041  }
3042 
3043  /* Initialise variables */
3044  *itno = 0;
3045 
3046 
3047 
3048 
3049 
3050  if(partition_method==geometric) printf("xml: Geometric partitioning\n");
3051  else if(partition_method==other) printf("xml: Round-robin partitioning\n");
3052  else printf("xml: Error - invalid partitioning method\n");
3053 
3054 
3055  /* Set p_xmachine to the agent list passed in then new agents are added to this list
3056  * Will be set to agent list for specific node is space partitions are already known (flag=1)
3057  */
3058  /* If we're reading without knowing partitions already then use the dummy current node (it's not in the list of nodes)*/
3059  if (flag == 0) current_node = &temp_node;
3060 
3061  printf("Reading initial data file: %s\n", filename);
3062  /* Read file until end of xml */
3063  while(reading==1)
3064  {
3065  /* Get the next char from the file */
3066  c = (char)fgetc(file);
3067 
3068  /* If the end of a tag */
3069  if(c == '>')
3070  {
3071  /* Place 0 at end of buffer to make chars a string */
3072  buffer[i] = 0;
3073 
3074  if(strcmp(buffer, "states") == 0) reading = 1;
3075  if(strcmp(buffer, "/states") == 0) reading = 0;
3076  if(strcmp(buffer, "itno") == 0) in_itno = 1;
3077  if(strcmp(buffer, "/itno") == 0) in_itno = 0;
3078  if(strcmp(buffer, "imports") == 0) FLAME_in_imports = 1;
3079  if(strcmp(buffer, "/imports") == 0) FLAME_in_imports = 0;
3080  if(strcmp(buffer, "import") == 0)
3081  {
3082  /*FLAME_location[0] = '\0';*/
3083  strcpy(FLAME_location, filelocation);
3084  FLAME_format[0] = '\0';
3085  FLAME_type[0] = '\0';
3086 
3087  FLAME_in_import = 1;
3088  }
3089  if(strcmp(buffer, "/import") == 0)
3090  {
3091  if(strcmp("agent", FLAME_type) == 0 || strcmp("environment", FLAME_type) == 0)
3092  {
3093  if(strcmp("xml", FLAME_format) == 0)
3094  {
3095  if(strcmp("agent", FLAME_type) == 0) readAgentXML(FLAME_location, cloud_data, partition_method, flag, number_partitions, agent_count, itno);
3096  if(strcmp("environment", FLAME_type) == 0) readEnvironmentXML(FLAME_location);
3097  }
3098  else
3099  {
3100  printf("Error: import format '%s' is unsupported\n", FLAME_format);
3101  exit(0);
3102  }
3103  }
3104  else
3105  {
3106  printf("Error: import type '%s' is not agent or environment\n", FLAME_type);
3107  exit(0);
3108  }
3109 
3110  FLAME_in_import = 0;
3111  }
3112  if(strcmp(buffer, "location") == 0) FLAME_in_location = 1;
3113  if(strcmp(buffer, "/location") == 0) FLAME_in_location = 0;
3114  if(strcmp(buffer, "format") == 0) FLAME_in_format = 1;
3115  if(strcmp(buffer, "/format") == 0) FLAME_in_format = 0;
3116  if(strcmp(buffer, "type") == 0) FLAME_in_type = 1;
3117  if(strcmp(buffer, "/type") == 0) FLAME_in_type = 0;
3118  if(strcmp(buffer, "outputs") == 0) FLAME_in_outputs = 1;
3119  if(strcmp(buffer, "/outputs") == 0) FLAME_in_outputs = 0;
3120  if(strcmp(buffer, "output") == 0)
3121  {
3122  if(FLAME_in_outputs == 1)
3123  {
3124  current_FLAME_output = add_FLAME_output(&FLAME_outputs);
3125 
3126  FLAME_in_output = 1;
3127  }
3128  }
3129  if(strcmp(buffer, "/output") == 0)
3130  {
3131  if(FLAME_in_outputs == 1)
3132  {
3133  if(current_FLAME_output->type == -1)
3134  {
3135  printf("Error: an output type has not been set\n");
3136  exit(0);
3137  }
3138  if(current_FLAME_output->format == -1)
3139  {
3140  printf("Error: an output format has not been set\n");
3141  exit(0);
3142  }
3143  if(current_FLAME_output->location == NULL)
3144  {
3145  printf("Error: an output location has not been set\n");
3146  exit(0);
3147  }
3148  /* If type is xml check if location exists */
3149  if(current_FLAME_output->type == 0)
3150  {
3151  rc = check_location_exists(current_FLAME_output->location);
3152  if(rc == 0)
3153  {
3154  printf("Error: location directory '%s' does not exist\n", current_FLAME_output->location);
3155  exit(0);
3156  }
3157  }
3158  /* Period has to be larger than 0 */
3159  if(current_FLAME_output->period < 1)
3160  {
3161  printf("Error: output period is less than 1: '%d'\n", current_FLAME_output->period);
3162  exit(0);
3163  }
3164  /* Phase cannot be equal or larger than period */
3165  if(current_FLAME_output->phase >= current_FLAME_output->period)
3166  {
3167  printf("Error: output phase is more or equal to period: '%d'\n", current_FLAME_output->phase);
3168  exit(0);
3169  }
3170 
3171  FLAME_in_output = 0;
3172  }
3173  }
3174  if(strcmp(buffer, "time") == 0) FLAME_in_time = 1;
3175  if(strcmp(buffer, "/time") == 0) FLAME_in_time = 0;
3176  if(strcmp(buffer, "period") == 0) FLAME_in_period = 1;
3177  if(strcmp(buffer, "/period") == 0) FLAME_in_period = 0;
3178  if(strcmp(buffer, "phase") == 0) FLAME_in_phase = 1;
3179  if(strcmp(buffer, "/phase") == 0) FLAME_in_phase = 0;
3180  if(strcmp(buffer, "name") == 0) FLAME_in_name = 1;
3181  if(strcmp(buffer, "/name") == 0) FLAME_in_name = 0;
3182 
3183  /* End of tag and reset buffer */
3184  in_tag = 0;
3185  i = 0;
3186  }
3187  /* If start of tag */
3188  else if(c == '<')
3189  {
3190  /* Place /0 at end of buffer to end numbers */
3191  buffer[i] = 0;
3192  /* Flag in tag */
3193  in_tag = 1;
3194 
3195  if(in_itno) *itno = atoi(buffer);
3196  if(FLAME_in_imports == 1)
3197  {
3198  if(FLAME_in_import == 1)
3199  {
3200  if(FLAME_in_location == 1) strcat(FLAME_location, buffer);
3201  if(FLAME_in_format == 1) strcpy(FLAME_format, buffer);
3202  if(FLAME_in_type == 1) strcpy(FLAME_type, buffer);
3203  }
3204  }
3205  if(FLAME_in_outputs == 1)
3206  {
3207  if(FLAME_in_output == 1)
3208  {
3209  if(FLAME_in_type == 1)
3210  {
3211  if(strcmp("snapshot", buffer) == 0) current_FLAME_output->type = 0;
3212  else if(strcmp("agent", buffer) != 0)
3213  {
3214  printf("Error: output type is not 'snapshot' or an 'agent': '%s'\n", buffer);
3215  exit(0);
3216  }
3217  }
3218  if(FLAME_in_name == 1)
3219  {
3220  if(strcmp("firm", buffer) == 0) current_FLAME_output->type = 1;
3221  else if(strcmp("household", buffer) == 0) current_FLAME_output->type = 2;
3222  else if(strcmp("equityfund", buffer) == 0) current_FLAME_output->type = 3;
3223  else if(strcmp("bank", buffer) == 0) current_FLAME_output->type = 4;
3224  else if(strcmp("government", buffer) == 0) current_FLAME_output->type = 5;
3225  else if(strcmp("centralbank", buffer) == 0) current_FLAME_output->type = 6;
3226  else if(strcmp("jpoffice", buffer) == 0) current_FLAME_output->type = 7;
3227  else if(strcmp("mall", buffer) == 0) current_FLAME_output->type = 8;
3228  else if(strcmp("reagency", buffer) == 0) current_FLAME_output->type = 9;
3229  else
3230  {
3231  printf("Error: output name is not an agent name: '%s'\n", buffer);
3232  exit(0);
3233  }
3234  }
3235  if(FLAME_in_format == 1)
3236  {
3237  if(strcmp("xml", buffer) == 0) current_FLAME_output->format = 0;
3238  else
3239  {
3240  printf("Error: output format is unsupported: '%s'\n", buffer);
3241  exit(0);
3242  }
3243  }
3244  if(FLAME_in_location == 1)
3245  {
3246  current_FLAME_output->location = (char *)malloc( (strlen(filelocation) + strlen(buffer) + 1) * sizeof(char));
3247  strcpy(current_FLAME_output->location, filelocation);
3248  strcat(current_FLAME_output->location, buffer);
3249  }
3250  if(FLAME_in_time == 1)
3251  {
3252  if(FLAME_in_period == 1) current_FLAME_output->period = atoi(buffer);
3253  if(FLAME_in_phase == 1) current_FLAME_output->phase = atoi(buffer);
3254  }
3255  }
3256  }
3257  /* Reset buffer */
3258  i = 0;
3259  }
3260  /* If in tag put read char into buffer */
3261  else if(in_tag == 1)
3262  {
3263  buffer[i] = c;
3264  i++;
3265  }
3266  /* If in data read char into buffer */
3267  else
3268  {
3269  buffer[i] = c;
3270  i++;
3271  }
3272  }
3273 
3274  /* Close the file */
3275  (void)fclose(file);
3276 
3277  /* Also try and read environment and agents from 0.xml */
3278  readEnvironmentXML(filename);
3279  readAgentXML(filename, cloud_data, partition_method, flag, number_partitions, agent_count, itno);
3280 
3281  /* If outputs is empty add default snapshot for every iteration */
3282  if(FLAME_outputs == NULL)
3283  {
3284  current_FLAME_output = add_FLAME_output(&FLAME_outputs);
3285  current_FLAME_output->type = 0; /* snapshot */
3286  current_FLAME_output->format = 0; /* xml */
3287  current_FLAME_output->location = (char *)malloc( (strlen(filelocation) + 1) * sizeof(char));
3288  strcpy(current_FLAME_output->location, filelocation); /* location = 0.xml location */
3289  current_FLAME_output->period = 1; /* every iteration */
3290  current_FLAME_output->phase = 0; /* no phase */
3291  }
3292 
3293  /* Print output settings to CLI */
3294  for(current_FLAME_output = FLAME_outputs; current_FLAME_output != NULL; current_FLAME_output = current_FLAME_output->next)
3295  {
3296  printf("output: type='");
3297  if(current_FLAME_output->type == 0) printf("snapshot");
3298  else if(current_FLAME_output->type == 1) printf("agent' name='firm");
3299  else if(current_FLAME_output->type == 2) printf("agent' name='household");
3300  else if(current_FLAME_output->type == 3) printf("agent' name='equityfund");
3301  else if(current_FLAME_output->type == 4) printf("agent' name='bank");
3302  else if(current_FLAME_output->type == 5) printf("agent' name='government");
3303  else if(current_FLAME_output->type == 6) printf("agent' name='centralbank");
3304  else if(current_FLAME_output->type == 7) printf("agent' name='jpoffice");
3305  else if(current_FLAME_output->type == 8) printf("agent' name='mall");
3306  else if(current_FLAME_output->type == 9) printf("agent' name='reagency");
3307  else printf("undefined");
3308  printf("' format='");
3309  if(current_FLAME_output->format == 0) printf("xml");
3310  else printf("undefined");
3311  printf("' location='%s'", current_FLAME_output->location);
3312  printf(" period='%d' phase='%d'\n", current_FLAME_output->period, current_FLAME_output->phase);
3313  }
3314 
3315  /* Make sure cloud data makes sense if any of x,y,z coords were all the same */
3316  if ( partition_method == geometric ) {
3317  if ( cloud_data[0] == cloud_data[1] ) {
3318  cloud_data[0] = -SPINF;
3319  cloud_data[1] = SPINF;
3320  }
3321  if ( cloud_data[2] == cloud_data[3] ) {
3322  cloud_data[2] = -SPINF;
3323  cloud_data[3] = SPINF;
3324  }
3325  if ( cloud_data[4] == cloud_data[5] ) {
3326  cloud_data[4] = -SPINF;
3327  cloud_data[5] = SPINF;
3328  }
3329  }
3330 }
3331 
3335 void write_int_static_array(FILE *file, int * temp, int size)
3336 {
3337  int i;
3338  char data[1000];
3339 
3340  fputs("{", file);
3341  for(i=0; i<size; i++)
3342  {
3343  sprintf(data, "%i", temp[i]);
3344  fputs(data, file);
3345  if(i < size-1) fputs(", ", file);
3346  }
3347  fputs("}", file);
3348 }
3349 
3353 void write_float_static_array(FILE *file, float * temp, int size)
3354 {
3355  int i;
3356  char data[1000];
3357 
3358  fputs("{", file);
3359  for(i=0; i<size; i++)
3360  {
3361  sprintf(data, "%f", temp[i]);
3362  fputs(data, file);
3363  if(i < size-1) fputs(", ", file);
3364  }
3365  fputs("}", file);
3366 }
3367 
3371 void write_double_static_array(FILE *file, double * temp, int size)
3372 {
3373  int i;
3374  char data[1000];
3375 
3376  fputs("{", file);
3377  for(i=0; i<size; i++)
3378  {
3379  sprintf(data, "%f", temp[i]);
3380  fputs(data, file);
3381  if(i < size-1) fputs(", ", file);
3382  }
3383  fputs("}", file);
3384 }
3385 
3389 void write_char_static_array(FILE *file, char * temp, int size)
3390 {
3391  int i;
3392  char data[1000];
3393 
3394  //fputs("{", file);
3395  for(i=0; i<size; i++)
3396  {
3397  sprintf(data, "%c", temp[i]);
3398  fputs(data, file);
3399  //if(i < size-1) fputs(", ", file);
3400  }
3401  //fputs("}", file);
3402 }
3403 
3407 void write_int_dynamic_array(FILE *file, int_array * temp)
3408 {
3409  int i;
3410  char data[1000];
3411 
3412  fputs("{", file);
3413  for(i=0; i<(*temp).size; i++)
3414  {
3415  sprintf(data, "%i", (*temp).array[i]);
3416  fputs(data, file);
3417  if(i < ((*temp).size-1)) fputs(", ", file);
3418  }
3419  fputs("}", file);
3420 }
3421 
3425 void write_float_dynamic_array(FILE *file, float_array * temp)
3426 {
3427  int i;
3428  char data[1000];
3429 
3430  fputs("{", file);
3431  for(i=0; i<(*temp).size; i++)
3432  {
3433  sprintf(data, "%f", (*temp).array[i]);
3434  fputs(data, file);
3435  if(i < ((*temp).size-1)) fputs(", ", file);
3436  }
3437  fputs("}", file);
3438 }
3439 
3444 {
3445  int i;
3446  char data[1000];
3447 
3448  fputs("{", file);
3449  for(i=0; i<(*temp).size; i++)
3450  {
3451  sprintf(data, "%f", (*temp).array[i]);
3452  fputs(data, file);
3453  if(i < ((*temp).size-1)) fputs(", ", file);
3454  }
3455  fputs("}", file);
3456 }
3457 
3461 void write_char_dynamic_array(FILE *file, char_array * temp)
3462 {
3463  int i;
3464  char data[1000];
3465 
3466  for(i=0; i<(*temp).size; i++)
3467  {
3468  sprintf(data, "%c", (*temp).array[i]);
3469  fputs(data, file);
3470  }
3471 }
3472 
3476 void write_transaction(FILE *file, transaction * temp_datatype)
3477 {
3478  char data[1000];
3479 
3480  fputs("{", file);
3481  sprintf(data, "%i", (*temp_datatype).quantity);
3482  fputs(data, file);
3483  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).avg_price);
3484  fputs(data, file);
3485  fputs("}", file);
3486 }
3487 
3488 void write_transaction_static_array(FILE *file, transaction * temp_datatype, int size)
3489 {
3490  int i;
3491 
3492  fputs("{", file);
3493  for(i = 0; i < size; i++)
3494  {
3495  write_transaction(file, &temp_datatype[i]);
3496 
3497  if(i < size - 1) fputs(", ", file);
3498  }
3499  fputs("}", file);
3500 }
3501 
3502 void write_transaction_dynamic_array(FILE *file, transaction_array * temp_datatype)
3503 {
3504  int i;
3505 
3506  fputs("{", file);
3507  for(i = 0; i < (*temp_datatype).size; i++)
3508  {
3509  write_transaction(file, &(*temp_datatype).array[i]);
3510 
3511  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3512  }
3513  fputs("}", file);
3514 }
3515 
3519 void write_buyer(FILE *file, buyer * temp_datatype)
3520 {
3521  char data[1000];
3522 
3523  fputs("{", file);
3524  sprintf(data, "%i", (*temp_datatype).id);
3525  fputs(data, file);
3526  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).budget);
3527  fputs(data, file);
3528  fputs("}", file);
3529 }
3530 
3531 void write_buyer_static_array(FILE *file, buyer * temp_datatype, int size)
3532 {
3533  int i;
3534 
3535  fputs("{", file);
3536  for(i = 0; i < size; i++)
3537  {
3538  write_buyer(file, &temp_datatype[i]);
3539 
3540  if(i < size - 1) fputs(", ", file);
3541  }
3542  fputs("}", file);
3543 }
3544 
3545 void write_buyer_dynamic_array(FILE *file, buyer_array * temp_datatype)
3546 {
3547  int i;
3548 
3549  fputs("{", file);
3550  for(i = 0; i < (*temp_datatype).size; i++)
3551  {
3552  write_buyer(file, &(*temp_datatype).array[i]);
3553 
3554  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3555  }
3556  fputs("}", file);
3557 }
3558 
3562 void write_seller(FILE *file, seller * temp_datatype)
3563 {
3564  char data[1000];
3565 
3566  fputs("{", file);
3567  sprintf(data, "%i", (*temp_datatype).id);
3568  fputs(data, file);
3569  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).price);
3570  fputs(data, file);
3571  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).inventory);
3572  fputs(data, file);
3573  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).inv_price);
3574  fputs(data, file);
3575  fputs("}", file);
3576 }
3577 
3578 void write_seller_static_array(FILE *file, seller * temp_datatype, int size)
3579 {
3580  int i;
3581 
3582  fputs("{", file);
3583  for(i = 0; i < size; i++)
3584  {
3585  write_seller(file, &temp_datatype[i]);
3586 
3587  if(i < size - 1) fputs(", ", file);
3588  }
3589  fputs("}", file);
3590 }
3591 
3592 void write_seller_dynamic_array(FILE *file, seller_array * temp_datatype)
3593 {
3594  int i;
3595 
3596  fputs("{", file);
3597  for(i = 0; i < (*temp_datatype).size; i++)
3598  {
3599  write_seller(file, &(*temp_datatype).array[i]);
3600 
3601  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3602  }
3603  fputs("}", file);
3604 }
3605 
3609 void write_vacancy(FILE *file, vacancy * temp_datatype)
3610 {
3611  char data[1000];
3612 
3613  fputs("{", file);
3614  sprintf(data, "%i", (*temp_datatype).id);
3615  fputs(data, file);
3616  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).wage);
3617  fputs(data, file);
3618  fputs("}", file);
3619 }
3620 
3621 void write_vacancy_static_array(FILE *file, vacancy * temp_datatype, int size)
3622 {
3623  int i;
3624 
3625  fputs("{", file);
3626  for(i = 0; i < size; i++)
3627  {
3628  write_vacancy(file, &temp_datatype[i]);
3629 
3630  if(i < size - 1) fputs(", ", file);
3631  }
3632  fputs("}", file);
3633 }
3634 
3635 void write_vacancy_dynamic_array(FILE *file, vacancy_array * temp_datatype)
3636 {
3637  int i;
3638 
3639  fputs("{", file);
3640  for(i = 0; i < (*temp_datatype).size; i++)
3641  {
3642  write_vacancy(file, &(*temp_datatype).array[i]);
3643 
3644  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3645  }
3646  fputs("}", file);
3647 }
3648 
3652 void write_employee(FILE *file, employee * temp_datatype)
3653 {
3654  char data[1000];
3655 
3656  fputs("{", file);
3657  sprintf(data, "%i", (*temp_datatype).id);
3658  fputs(data, file);
3659  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).wage);
3660  fputs(data, file);
3661  fputs("}", file);
3662 }
3663 
3664 void write_employee_static_array(FILE *file, employee * temp_datatype, int size)
3665 {
3666  int i;
3667 
3668  fputs("{", file);
3669  for(i = 0; i < size; i++)
3670  {
3671  write_employee(file, &temp_datatype[i]);
3672 
3673  if(i < size - 1) fputs(", ", file);
3674  }
3675  fputs("}", file);
3676 }
3677 
3678 void write_employee_dynamic_array(FILE *file, employee_array * temp_datatype)
3679 {
3680  int i;
3681 
3682  fputs("{", file);
3683  for(i = 0; i < (*temp_datatype).size; i++)
3684  {
3685  write_employee(file, &(*temp_datatype).array[i]);
3686 
3687  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3688  }
3689  fputs("}", file);
3690 }
3691 
3695 void write_mortgage(FILE *file, mortgage * temp_datatype)
3696 {
3697  char data[1000];
3698 
3699  fputs("{", file);
3700  sprintf(data, "%i", (*temp_datatype).bank_id);
3701  fputs(data, file);
3702  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).principal);
3703  fputs(data, file);
3704  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).quarters_left);
3705  fputs(data, file);
3706  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).quarterly_interest);
3707  fputs(data, file);
3708  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).quarterly_principal);
3709  fputs(data, file);
3710  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).interestrate);
3711  fputs(data, file);
3712  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).mtype);
3713  fputs(data, file);
3714  fputs("}", file);
3715 }
3716 
3717 void write_mortgage_static_array(FILE *file, mortgage * temp_datatype, int size)
3718 {
3719  int i;
3720 
3721  fputs("{", file);
3722  for(i = 0; i < size; i++)
3723  {
3724  write_mortgage(file, &temp_datatype[i]);
3725 
3726  if(i < size - 1) fputs(", ", file);
3727  }
3728  fputs("}", file);
3729 }
3730 
3731 void write_mortgage_dynamic_array(FILE *file, mortgage_array * temp_datatype)
3732 {
3733  int i;
3734 
3735  fputs("{", file);
3736  for(i = 0; i < (*temp_datatype).size; i++)
3737  {
3738  write_mortgage(file, &(*temp_datatype).array[i]);
3739 
3740  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3741  }
3742  fputs("}", file);
3743 }
3744 
3748 void write_loan(FILE *file, loan * temp_datatype)
3749 {
3750  char data[1000];
3751 
3752  fputs("{", file);
3753  sprintf(data, "%i", (*temp_datatype).bank_id);
3754  fputs(data, file);
3755  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).amount);
3756  fputs(data, file);
3757  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).to_be_paid);
3758  fputs(data, file);
3759  fputs("}", file);
3760 }
3761 
3762 void write_loan_static_array(FILE *file, loan * temp_datatype, int size)
3763 {
3764  int i;
3765 
3766  fputs("{", file);
3767  for(i = 0; i < size; i++)
3768  {
3769  write_loan(file, &temp_datatype[i]);
3770 
3771  if(i < size - 1) fputs(", ", file);
3772  }
3773  fputs("}", file);
3774 }
3775 
3776 void write_loan_dynamic_array(FILE *file, loan_array * temp_datatype)
3777 {
3778  int i;
3779 
3780  fputs("{", file);
3781  for(i = 0; i < (*temp_datatype).size; i++)
3782  {
3783  write_loan(file, &(*temp_datatype).array[i]);
3784 
3785  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3786  }
3787  fputs("}", file);
3788 }
3789 
3793 void write_hbuyer(FILE *file, hbuyer * temp_datatype)
3794 {
3795  char data[1000];
3796 
3797  fputs("{", file);
3798  sprintf(data, "%i", (*temp_datatype).buyer_id);
3799  fputs(data, file);
3800  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).bank_id);
3801  fputs(data, file);
3802  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).liquidity);
3803  fputs(data, file);
3804  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).quarterly_income);
3805  fputs(data, file);
3806  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).quarterly_mortgage_paid);
3807  fputs(data, file);
3808  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).choice);
3809  fputs(data, file);
3810  fputs("}", file);
3811 }
3812 
3813 void write_hbuyer_static_array(FILE *file, hbuyer * temp_datatype, int size)
3814 {
3815  int i;
3816 
3817  fputs("{", file);
3818  for(i = 0; i < size; i++)
3819  {
3820  write_hbuyer(file, &temp_datatype[i]);
3821 
3822  if(i < size - 1) fputs(", ", file);
3823  }
3824  fputs("}", file);
3825 }
3826 
3827 void write_hbuyer_dynamic_array(FILE *file, hbuyer_array * temp_datatype)
3828 {
3829  int i;
3830 
3831  fputs("{", file);
3832  for(i = 0; i < (*temp_datatype).size; i++)
3833  {
3834  write_hbuyer(file, &(*temp_datatype).array[i]);
3835 
3836  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3837  }
3838  fputs("}", file);
3839 }
3840 
3844 void write_hseller(FILE *file, hseller * temp_datatype)
3845 {
3846  char data[1000];
3847 
3848  fputs("{", file);
3849  sprintf(data, "%i", (*temp_datatype).seller_id);
3850  fputs(data, file);
3851  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).price);
3852  fputs(data, file);
3853  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).quantity);
3854  fputs(data, file);
3855  fputs(", ", file); sprintf(data, "%i", (*temp_datatype).type);
3856  fputs(data, file);
3857  fputs("}", file);
3858 }
3859 
3860 void write_hseller_static_array(FILE *file, hseller * temp_datatype, int size)
3861 {
3862  int i;
3863 
3864  fputs("{", file);
3865  for(i = 0; i < size; i++)
3866  {
3867  write_hseller(file, &temp_datatype[i]);
3868 
3869  if(i < size - 1) fputs(", ", file);
3870  }
3871  fputs("}", file);
3872 }
3873 
3874 void write_hseller_dynamic_array(FILE *file, hseller_array * temp_datatype)
3875 {
3876  int i;
3877 
3878  fputs("{", file);
3879  for(i = 0; i < (*temp_datatype).size; i++)
3880  {
3881  write_hseller(file, &(*temp_datatype).array[i]);
3882 
3883  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3884  }
3885  fputs("}", file);
3886 }
3887 
3891 void write_hbank(FILE *file, hbank * temp_datatype)
3892 {
3893  char data[1000];
3894 
3895  fputs("{", file);
3896  sprintf(data, "%i", (*temp_datatype).id);
3897  fputs(data, file);
3898  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).equity);
3899  fputs(data, file);
3900  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).risky_assets);
3901  fputs(data, file);
3902  fputs(", ", file); sprintf(data, "%f", (*temp_datatype).amount_mortgaged);
3903  fputs(data, file);
3904  fputs("}", file);
3905 }
3906 
3907 void write_hbank_static_array(FILE *file, hbank * temp_datatype, int size)
3908 {
3909  int i;
3910 
3911  fputs("{", file);
3912  for(i = 0; i < size; i++)
3913  {
3914  write_hbank(file, &temp_datatype[i]);
3915 
3916  if(i < size - 1) fputs(", ", file);
3917  }
3918  fputs("}", file);
3919 }
3920 
3921 void write_hbank_dynamic_array(FILE *file, hbank_array * temp_datatype)
3922 {
3923  int i;
3924 
3925  fputs("{", file);
3926  for(i = 0; i < (*temp_datatype).size; i++)
3927  {
3928  write_hbank(file, &(*temp_datatype).array[i]);
3929 
3930  if(i < (*temp_datatype).size - 1) fputs(", ", file);
3931  }
3932  fputs("}", file);
3933 }
3934 
3935 
3936 
3937 void write_firm_agent(FILE *file, xmachine_memory_firm * current)
3938 {
3939  char data[1000];
3940  fputs("<xagent>\n" , file);
3941  fputs("<name>firm</name>\n", file);
3942  fputs("<id>", file);
3943  sprintf(data, "%i", current->id);
3944  fputs(data, file);
3945  fputs("</id>\n", file);
3946  fputs("<bank_id>", file);
3947  sprintf(data, "%i", current->bank_id);
3948  fputs(data, file);
3949  fputs("</bank_id>\n", file);
3950  fputs("<isconstructor>", file);
3951  sprintf(data, "%i", current->isconstructor);
3952  fputs(data, file);
3953  fputs("</isconstructor>\n", file);
3954  fputs("<day_of_month_to_act>", file);
3955  sprintf(data, "%i", current->day_of_month_to_act);
3956  fputs(data, file);
3957  fputs("</day_of_month_to_act>\n", file);
3958  fputs("<isinsolvent>", file);
3959  sprintf(data, "%i", current->isinsolvent);
3960  fputs(data, file);
3961  fputs("</isinsolvent>\n", file);
3962  fputs("<it_no>", file);
3963  sprintf(data, "%i", current->it_no);
3964  fputs(data, file);
3965  fputs("</it_no>\n", file);
3966  fputs("<day_of_week_to_act>", file);
3967  sprintf(data, "%i", current->day_of_week_to_act);
3968  fputs(data, file);
3969  fputs("</day_of_week_to_act>\n", file);
3970  fputs("<average_goods_price>", file);
3971  sprintf(data, "%f", current->average_goods_price);
3972  fputs(data, file);
3973  fputs("</average_goods_price>\n", file);
3974  fputs("<employees>", file);
3975  write_int_dynamic_array(file, &current->employees);
3976  fputs("</employees>\n", file);
3977  fputs("<manager>", file);
3978  sprintf(data, "%i", current->manager);
3979  fputs(data, file);
3980  fputs("</manager>\n", file);
3981  fputs("<wage_offer>", file);
3982  sprintf(data, "%f", current->wage_offer);
3983  fputs(data, file);
3984  fputs("</wage_offer>\n", file);
3985  fputs("<average_wage>", file);
3986  sprintf(data, "%f", current->average_wage);
3987  fputs(data, file);
3988  fputs("</average_wage>\n", file);
3989  fputs("<no_employees>", file);
3990  sprintf(data, "%i", current->no_employees);
3991  fputs(data, file);
3992  fputs("</no_employees>\n", file);
3993  fputs("<vacancies>", file);
3994  sprintf(data, "%i", current->vacancies);
3995  fputs(data, file);
3996  fputs("</vacancies>\n", file);
3997  fputs("<employees_needed>", file);
3998  sprintf(data, "%i", current->employees_needed);
3999  fputs(data, file);
4000  fputs("</employees_needed>\n", file);
4001  fputs("<day_of_month_wages_paid>", file);
4002  sprintf(data, "%i", current->day_of_month_wages_paid);
4003  fputs(data, file);
4004  fputs("</day_of_month_wages_paid>\n", file);
4005  fputs("<labour_productivity>", file);
4006  sprintf(data, "%f", current->labour_productivity);
4007  fputs(data, file);
4008  fputs("</labour_productivity>\n", file);
4009  fputs("<capital_productivity>", file);
4010  sprintf(data, "%f", current->capital_productivity);
4011  fputs(data, file);
4012  fputs("</capital_productivity>\n", file);
4013  fputs("<capital_goods>", file);
4014  sprintf(data, "%i", current->capital_goods);
4015  fputs(data, file);
4016  fputs("</capital_goods>\n", file);
4017  fputs("<capital_goods_price>", file);
4018  sprintf(data, "%f", current->capital_goods_price);
4019  fputs(data, file);
4020  fputs("</capital_goods_price>\n", file);
4021  fputs("<production_current>", file);
4022  sprintf(data, "%i", current->production_current);
4023  fputs(data, file);
4024  fputs("</production_current>\n", file);
4025  fputs("<expected_sales>", file);
4026  sprintf(data, "%i", current->expected_sales);
4027  fputs(data, file);
4028  fputs("</expected_sales>\n", file);
4029  fputs("<production_plan>", file);
4030  sprintf(data, "%i", current->production_plan);
4031  fputs(data, file);
4032  fputs("</production_plan>\n", file);
4033  fputs("<unit_goods_price>", file);
4034  sprintf(data, "%f", current->unit_goods_price);
4035  fputs(data, file);
4036  fputs("</unit_goods_price>\n", file);
4037  fputs("<unit_cost>", file);
4038  sprintf(data, "%f", current->unit_cost);
4039  fputs(data, file);
4040  fputs("</unit_cost>\n", file);
4041  fputs("<day_of_month_production_completed>", file);
4042  sprintf(data, "%i", current->day_of_month_production_completed);
4043  fputs(data, file);
4044  fputs("</day_of_month_production_completed>\n", file);
4045  fputs("<unit_house_price>", file);
4046  sprintf(data, "%f", current->unit_house_price);
4047  fputs(data, file);
4048  fputs("</unit_house_price>\n", file);
4049  fputs("<projects>", file);
4050  write_int_static_array(file, current->projects, 12);
4051  fputs("</projects>\n", file);
4052  fputs("<loans_interest_rate>", file);
4053  sprintf(data, "%f", current->loans_interest_rate);
4054  fputs(data, file);
4055  fputs("</loans_interest_rate>\n", file);
4056  fputs("<debt>", file);
4057  sprintf(data, "%f", current->debt);
4058  fputs(data, file);
4059  fputs("</debt>\n", file);
4060  fputs("<inventory>", file);
4061  sprintf(data, "%i", current->inventory);
4062  fputs(data, file);
4063  fputs("</inventory>\n", file);
4064  fputs("<sales>", file);
4065  sprintf(data, "%i", current->sales);
4066  fputs(data, file);
4067  fputs("</sales>\n", file);
4068  fputs("<revenues>", file);
4069  sprintf(data, "%f", current->revenues);
4070  fputs(data, file);
4071  fputs("</revenues>\n", file);
4072  fputs("<total_assets>", file);
4073  sprintf(data, "%f", current->total_assets);
4074  fputs(data, file);
4075  fputs("</total_assets>\n", file);
4076  fputs("<operating_costs>", file);
4077  sprintf(data, "%f", current->operating_costs);
4078  fputs(data, file);
4079  fputs("</operating_costs>\n", file);
4080  fputs("<labour_costs>", file);
4081  sprintf(data, "%f", current->labour_costs);
4082  fputs(data, file);
4083  fputs("</labour_costs>\n", file);
4084  fputs("<total_interest_payments>", file);
4085  sprintf(data, "%f", current->total_interest_payments);
4086  fputs(data, file);
4087  fputs("</total_interest_payments>\n", file);
4088  fputs("<dividends_paid>", file);
4089  sprintf(data, "%f", current->dividends_paid);
4090  fputs(data, file);
4091  fputs("</dividends_paid>\n", file);
4092  fputs("<dividends_to_be_paid>", file);
4093  sprintf(data, "%f", current->dividends_to_be_paid);
4094  fputs(data, file);
4095  fputs("</dividends_to_be_paid>\n", file);
4096  fputs("<retained_earnings>", file);
4097  sprintf(data, "%f", current->retained_earnings);
4098  fputs(data, file);
4099  fputs("</retained_earnings>\n", file);
4100  fputs("<net_earnings>", file);
4101  sprintf(data, "%f", current->net_earnings);
4102  fputs(data, file);
4103  fputs("</net_earnings>\n", file);
4104  fputs("<ebit>", file);
4105  sprintf(data, "%f", current->ebit);
4106  fputs(data, file);
4107  fputs("</ebit>\n", file);
4108  fputs("<equity>", file);
4109  sprintf(data, "%f", current->equity);
4110  fputs(data, file);
4111  fputs("</equity>\n", file);
4112  fputs("<liquidity>", file);
4113  sprintf(data, "%f", current->liquidity);
4114  fputs(data, file);
4115  fputs("</liquidity>\n", file);
4116  fputs("<isliquidshort>", file);
4117  sprintf(data, "%i", current->isliquidshort);
4118  fputs(data, file);
4119  fputs("</isliquidshort>\n", file);
4120  fputs("<hasloan>", file);
4121  sprintf(data, "%i", current->hasloan);
4122  fputs(data, file);
4123  fputs("</hasloan>\n", file);
4124  fputs("<hasinvestment>", file);
4125  sprintf(data, "%i", current->hasinvestment);
4126  fputs(data, file);
4127  fputs("</hasinvestment>\n", file);
4128  fputs("<isilliquid>", file);
4129  sprintf(data, "%i", current->isilliquid);
4130  fputs(data, file);
4131  fputs("</isilliquid>\n", file);
4132  fputs("<planned_investment_costs>", file);
4133  sprintf(data, "%f", current->planned_investment_costs);
4134  fputs(data, file);
4135  fputs("</planned_investment_costs>\n", file);
4136  fputs("<liquidity_need>", file);
4137  sprintf(data, "%f", current->liquidity_need);
4138  fputs(data, file);
4139  fputs("</liquidity_need>\n", file);
4140  fputs("<loan_list>", file);
4141  write_loan_static_array(file, current->loan_list, 2);
4142  fputs("</loan_list>\n", file);
4143  fputs("<labour_tax_rate>", file);
4144  sprintf(data, "%f", current->labour_tax_rate);
4145  fputs(data, file);
4146  fputs("</labour_tax_rate>\n", file);
4147  fputs("<delta_housing_price>", file);
4148  sprintf(data, "%f", current->delta_housing_price);
4149  fputs(data, file);
4150  fputs("</delta_housing_price>\n", file);
4151 
4152  fputs("</xagent>\n", file);
4153 }
4154 
4156 {
4157  char data[1000];
4158  fputs("<xagent>\n" , file);
4159  fputs("<name>household</name>\n", file);
4160  fputs("<id>", file);
4161  sprintf(data, "%i", current->id);
4162  fputs(data, file);
4163  fputs("</id>\n", file);
4164  fputs("<bank_id>", file);
4165  sprintf(data, "%i", current->bank_id);
4166  fputs(data, file);
4167  fputs("</bank_id>\n", file);
4168  fputs("<it_no>", file);
4169  sprintf(data, "%i", current->it_no);
4170  fputs(data, file);
4171  fputs("</it_no>\n", file);
4172  fputs("<day_of_week_to_act>", file);
4173  sprintf(data, "%i", current->day_of_week_to_act);
4174  fputs(data, file);
4175  fputs("</day_of_week_to_act>\n", file);
4176  fputs("<weekly_consumption_budget>", file);
4177  sprintf(data, "%f", current->weekly_consumption_budget);
4178  fputs(data, file);
4179  fputs("</weekly_consumption_budget>\n", file);
4180  fputs("<mall_budget>", file);
4181  sprintf(data, "%f", current->mall_budget);
4182  fputs(data, file);
4183  fputs("</mall_budget>\n", file);
4184  fputs("<quarterly_price_change>", file);
4185  sprintf(data, "%f", current->quarterly_price_change);
4186  fputs(data, file);
4187  fputs("</quarterly_price_change>\n", file);
4188  fputs("<my_employer_id>", file);
4189  sprintf(data, "%i", current->my_employer_id);
4190  fputs(data, file);
4191  fputs("</my_employer_id>\n", file);
4192  fputs("<wage>", file);
4193  sprintf(data, "%f", current->wage);
4194  fputs(data, file);
4195  fputs("</wage>\n", file);
4196  fputs("<ismanager>", file);
4197  sprintf(data, "%i", current->ismanager);
4198  fputs(data, file);
4199  fputs("</ismanager>\n", file);
4200  fputs("<government_benefits>", file);
4201  sprintf(data, "%f", current->government_benefits);
4202  fputs(data, file);
4203  fputs("</government_benefits>\n", file);
4204  fputs("<day_of_month_to_act>", file);
4205  sprintf(data, "%i", current->day_of_month_to_act);
4206  fputs(data, file);
4207  fputs("</day_of_month_to_act>\n", file);
4208  fputs("<day_of_month_wage_recieved>", file);
4209  sprintf(data, "%i", current->day_of_month_wage_recieved);
4210  fputs(data, file);
4211  fputs("</day_of_month_wage_recieved>\n", file);
4212  fputs("<mortgages_interest_rate>", file);
4213  sprintf(data, "%f", current->mortgages_interest_rate);
4214  fputs(data, file);
4215  fputs("</mortgages_interest_rate>\n", file);
4216  fputs("<labour_tax_rate>", file);
4217  sprintf(data, "%f", current->labour_tax_rate);
4218  fputs(data, file);
4219  fputs("</labour_tax_rate>\n", file);
4220  fputs("<mortgages_list>", file);
4222  fputs("</mortgages_list>\n", file);
4223  fputs("<mortgages>", file);
4224  sprintf(data, "%f", current->mortgages);
4225  fputs(data, file);
4226  fputs("</mortgages>\n", file);
4227  fputs("<housing_payment>", file);
4228  sprintf(data, "%f", current->housing_payment);
4229  fputs(data, file);
4230  fputs("</housing_payment>\n", file);
4231  fputs("<equity>", file);
4232  sprintf(data, "%f", current->equity);
4233  fputs(data, file);
4234  fputs("</equity>\n", file);
4235  fputs("<housing_price>", file);
4236  sprintf(data, "%f", current->housing_price);
4237  fputs(data, file);
4238  fputs("</housing_price>\n", file);
4239  fputs("<housing_units>", file);
4240  sprintf(data, "%i", current->housing_units);
4241  fputs(data, file);
4242  fputs("</housing_units>\n", file);
4243  fputs("<n_shares>", file);
4244  sprintf(data, "%i", current->n_shares);
4245  fputs(data, file);
4246  fputs("</n_shares>\n", file);
4247  fputs("<liquidity>", file);
4248  sprintf(data, "%f", current->liquidity);
4249  fputs(data, file);
4250  fputs("</liquidity>\n", file);
4251  fputs("<capital_income>", file);
4252  sprintf(data, "%f", current->capital_income);
4253  fputs(data, file);
4254  fputs("</capital_income>\n", file);
4255  fputs("<previous_wages>", file);
4256  write_double_static_array(file, current->previous_wages, 3);
4257  fputs("</previous_wages>\n", file);
4258  fputs("<previous_benefits>", file);
4259  write_double_static_array(file, current->previous_benefits, 3);
4260  fputs("</previous_benefits>\n", file);
4261  fputs("<labour_income>", file);
4262  sprintf(data, "%f", current->labour_income);
4263  fputs(data, file);
4264  fputs("</labour_income>\n", file);
4265  fputs("<total_assets>", file);
4266  sprintf(data, "%f", current->total_assets);
4267  fputs(data, file);
4268  fputs("</total_assets>\n", file);
4269  fputs("<housing_value>", file);
4270  sprintf(data, "%f", current->housing_value);
4271  fputs(data, file);
4272  fputs("</housing_value>\n", file);
4273  fputs("<expected_housing_payment>", file);
4274  sprintf(data, "%f", current->expected_housing_payment);
4275  fputs(data, file);
4276  fputs("</expected_housing_payment>\n", file);
4277  fputs("<hmarket_role>", file);
4278  sprintf(data, "%i", current->hmarket_role);
4279  fputs(data, file);
4280  fputs("</hmarket_role>\n", file);
4281  fputs("<equity_ratio>", file);
4282  sprintf(data, "%f", current->equity_ratio);
4283  fputs(data, file);
4284  fputs("</equity_ratio>\n", file);
4285  fputs("<minimum_equity_ratio>", file);
4286  sprintf(data, "%f", current->minimum_equity_ratio);
4287  fputs(data, file);
4288  fputs("</minimum_equity_ratio>\n", file);
4289  fputs("<mortgage_costs>", file);
4290  write_double_static_array(file, current->mortgage_costs, 3);
4291  fputs("</mortgage_costs>\n", file);
4292  fputs("<delta_housing_value>", file);
4293  sprintf(data, "%f", current->delta_housing_value);
4294  fputs(data, file);
4295  fputs("</delta_housing_value>\n", file);
4296  fputs("<mortgage_choice>", file);
4297  sprintf(data, "%i", current->mortgage_choice);
4298  fputs(data, file);
4299  fputs("</mortgage_choice>\n", file);
4300 
4301  fputs("</xagent>\n", file);
4302 }
4303 
4305 {
4306  char data[1000];
4307  fputs("<xagent>\n" , file);
4308  fputs("<name>equityfund</name>\n", file);
4309  fputs("<id>", file);
4310  sprintf(data, "%i", current->id);
4311  fputs(data, file);
4312  fputs("</id>\n", file);
4313  fputs("<it_no>", file);
4314  sprintf(data, "%i", current->it_no);
4315  fputs(data, file);
4316  fputs("</it_no>\n", file);
4317  fputs("<day_of_month_to_act>", file);
4318  sprintf(data, "%i", current->day_of_month_to_act);
4319  fputs(data, file);
4320  fputs("</day_of_month_to_act>\n", file);
4321  fputs("<day_of_month_wages_paid>", file);
4322  sprintf(data, "%i", current->day_of_month_wages_paid);
4323  fputs(data, file);
4324  fputs("</day_of_month_wages_paid>\n", file);
4325  fputs("<share_firms>", file);
4326  sprintf(data, "%f", current->share_firms);
4327  fputs(data, file);
4328  fputs("</share_firms>\n", file);
4329  fputs("<share_construction_firms>", file);
4330  sprintf(data, "%f", current->share_construction_firms);
4331  fputs(data, file);
4332  fputs("</share_construction_firms>\n", file);
4333  fputs("<share_banks>", file);
4334  sprintf(data, "%f", current->share_banks);
4335  fputs(data, file);
4336  fputs("</share_banks>\n", file);
4337  fputs("<equity>", file);
4338  sprintf(data, "%f", current->equity);
4339  fputs(data, file);
4340  fputs("</equity>\n", file);
4341  fputs("<liquidity>", file);
4342  sprintf(data, "%f", current->liquidity);
4343  fputs(data, file);
4344  fputs("</liquidity>\n", file);
4345  fputs("<n_shares>", file);
4346  sprintf(data, "%i", current->n_shares);
4347  fputs(data, file);
4348  fputs("</n_shares>\n", file);
4349  fputs("<dividends_recieved>", file);
4350  sprintf(data, "%f", current->dividends_recieved);
4351  fputs(data, file);
4352  fputs("</dividends_recieved>\n", file);
4353  fputs("<dividends_retained>", file);
4354  sprintf(data, "%f", current->dividends_retained);
4355  fputs(data, file);
4356  fputs("</dividends_retained>\n", file);
4357  fputs("<dividends_paid>", file);
4358  sprintf(data, "%f", current->dividends_paid);
4359  fputs(data, file);
4360  fputs("</dividends_paid>\n", file);
4361  fputs("<firm_investment>", file);
4362  sprintf(data, "%f", current->firm_investment);
4363  fputs(data, file);
4364  fputs("</firm_investment>\n", file);
4365  fputs("<capital_tax_rate>", file);
4366  sprintf(data, "%f", current->capital_tax_rate);
4367  fputs(data, file);
4368  fputs("</capital_tax_rate>\n", file);
4369 
4370  fputs("</xagent>\n", file);
4371 }
4372 
4373 void write_bank_agent(FILE *file, xmachine_memory_bank * current)
4374 {
4375  char data[1000];
4376  fputs("<xagent>\n" , file);
4377  fputs("<name>bank</name>\n", file);
4378  fputs("<id>", file);
4379  sprintf(data, "%i", current->id);
4380  fputs(data, file);
4381  fputs("</id>\n", file);
4382  fputs("<day_of_month_to_act>", file);
4383  sprintf(data, "%i", current->day_of_month_to_act);
4384  fputs(data, file);
4385  fputs("</day_of_month_to_act>\n", file);
4386  fputs("<day_of_week_to_act>", file);
4387  sprintf(data, "%i", current->day_of_week_to_act);
4388  fputs(data, file);
4389  fputs("</day_of_week_to_act>\n", file);
4390  fputs("<it_no>", file);
4391  sprintf(data, "%i", current->it_no);
4392  fputs(data, file);
4393  fputs("</it_no>\n", file);
4394  fputs("<total_assets>", file);
4395  sprintf(data, "%f", current->total_assets);
4396  fputs(data, file);
4397  fputs("</total_assets>\n", file);
4398  fputs("<loans>", file);
4399  sprintf(data, "%f", current->loans);
4400  fputs(data, file);
4401  fputs("</loans>\n", file);
4402  fputs("<loans_start>", file);
4403  sprintf(data, "%f", current->loans_start);
4404  fputs(data, file);
4405  fputs("</loans_start>\n", file);
4406  fputs("<mortgages>", file);
4407  sprintf(data, "%f", current->mortgages);
4408  fputs(data, file);
4409  fputs("</mortgages>\n", file);
4410  fputs("<deposits>", file);
4411  sprintf(data, "%f", current->deposits);
4412  fputs(data, file);
4413  fputs("</deposits>\n", file);
4414  fputs("<centralbank_debt>", file);
4415  sprintf(data, "%f", current->centralbank_debt);
4416  fputs(data, file);
4417  fputs("</centralbank_debt>\n", file);
4418  fputs("<equity>", file);
4419  sprintf(data, "%f", current->equity);
4420  fputs(data, file);
4421  fputs("</equity>\n", file);
4422  fputs("<liquidity>", file);
4423  sprintf(data, "%f", current->liquidity);
4424  fputs(data, file);
4425  fputs("</liquidity>\n", file);
4426  fputs("<revenues>", file);
4427  sprintf(data, "%f", current->revenues);
4428  fputs(data, file);
4429  fputs("</revenues>\n", file);
4430  fputs("<total_writeoffs>", file);
4431  sprintf(data, "%f", current->total_writeoffs);
4432  fputs(data, file);
4433  fputs("</total_writeoffs>\n", file);
4434  fputs("<interest_rate>", file);
4435  sprintf(data, "%f", current->interest_rate);
4436  fputs(data, file);
4437  fputs("</interest_rate>\n", file);
4438  fputs("<interests_accrued>", file);
4439  sprintf(data, "%f", current->interests_accrued);
4440  fputs(data, file);
4441  fputs("</interests_accrued>\n", file);
4442  fputs("<interests_paid>", file);
4443  sprintf(data, "%f", current->interests_paid);
4444  fputs(data, file);
4445  fputs("</interests_paid>\n", file);
4446  fputs("<dividends_paid>", file);
4447  sprintf(data, "%f", current->dividends_paid);
4448  fputs(data, file);
4449  fputs("</dividends_paid>\n", file);
4450  fputs("<total_dividends>", file);
4451  sprintf(data, "%f", current->total_dividends);
4452  fputs(data, file);
4453  fputs("</total_dividends>\n", file);
4454  fputs("<retained_earnings>", file);
4455  sprintf(data, "%f", current->retained_earnings);
4456  fputs(data, file);
4457  fputs("</retained_earnings>\n", file);
4458  fputs("<net_earnings>", file);
4459  sprintf(data, "%f", current->net_earnings);
4460  fputs(data, file);
4461  fputs("</net_earnings>\n", file);
4462  fputs("<total_costs>", file);
4463  sprintf(data, "%f", current->total_costs);
4464  fputs(data, file);
4465  fputs("</total_costs>\n", file);
4466 
4467  fputs("</xagent>\n", file);
4468 }
4469 
4471 {
4472  char data[1000];
4473  fputs("<xagent>\n" , file);
4474  fputs("<name>government</name>\n", file);
4475  fputs("<id>", file);
4476  sprintf(data, "%i", current->id);
4477  fputs(data, file);
4478  fputs("</id>\n", file);
4479  fputs("<it_no>", file);
4480  sprintf(data, "%i", current->it_no);
4481  fputs(data, file);
4482  fputs("</it_no>\n", file);
4483  fputs("<average_wage>", file);
4484  sprintf(data, "%f", current->average_wage);
4485  fputs(data, file);
4486  fputs("</average_wage>\n", file);
4487  fputs("<unemployment_rate>", file);
4488  sprintf(data, "%f", current->unemployment_rate);
4489  fputs(data, file);
4490  fputs("</unemployment_rate>\n", file);
4491  fputs("<population_size>", file);
4492  sprintf(data, "%i", current->population_size);
4493  fputs(data, file);
4494  fputs("</population_size>\n", file);
4495  fputs("<debt>", file);
4496  sprintf(data, "%f", current->debt);
4497  fputs(data, file);
4498  fputs("</debt>\n", file);
4499  fputs("<equity>", file);
4500  sprintf(data, "%f", current->equity);
4501  fputs(data, file);
4502  fputs("</equity>\n", file);
4503  fputs("<liquidity>", file);
4504  sprintf(data, "%f", current->liquidity);
4505  fputs(data, file);
4506  fputs("</liquidity>\n", file);
4507  fputs("<day_of_month_to_act>", file);
4508  sprintf(data, "%i", current->day_of_month_to_act);
4509  fputs(data, file);
4510  fputs("</day_of_month_to_act>\n", file);
4511  fputs("<day_of_month_wages_paid>", file);
4512  sprintf(data, "%i", current->day_of_month_wages_paid);
4513  fputs(data, file);
4514  fputs("</day_of_month_wages_paid>\n", file);
4515  fputs("<capital_tax_rate>", file);
4516  sprintf(data, "%f", current->capital_tax_rate);
4517  fputs(data, file);
4518  fputs("</capital_tax_rate>\n", file);
4519  fputs("<labour_tax_rate>", file);
4520  sprintf(data, "%f", current->labour_tax_rate);
4521  fputs(data, file);
4522  fputs("</labour_tax_rate>\n", file);
4523  fputs("<labour_tax_income>", file);
4524  sprintf(data, "%f", current->labour_tax_income);
4525  fputs(data, file);
4526  fputs("</labour_tax_income>\n", file);
4527  fputs("<capital_tax_income>", file);
4528  sprintf(data, "%f", current->capital_tax_income);
4529  fputs(data, file);
4530  fputs("</capital_tax_income>\n", file);
4531  fputs("<gov_general_benefit_rate>", file);
4532  sprintf(data, "%f", current->gov_general_benefit_rate);
4533  fputs(data, file);
4534  fputs("</gov_general_benefit_rate>\n", file);
4535  fputs("<gov_unemployment_rate>", file);
4536  sprintf(data, "%f", current->gov_unemployment_rate);
4537  fputs(data, file);
4538  fputs("</gov_unemployment_rate>\n", file);
4539  fputs("<general_benefits>", file);
4540  sprintf(data, "%f", current->general_benefits);
4541  fputs(data, file);
4542  fputs("</general_benefits>\n", file);
4543  fputs("<unemployment_benefits>", file);
4544  sprintf(data, "%f", current->unemployment_benefits);
4545  fputs(data, file);
4546  fputs("</unemployment_benefits>\n", file);
4547  fputs("<earnings>", file);
4548  sprintf(data, "%f", current->earnings);
4549  fputs(data, file);
4550  fputs("</earnings>\n", file);
4551  fputs("<centralbank_income>", file);
4552  sprintf(data, "%f", current->centralbank_income);
4553  fputs(data, file);
4554  fputs("</centralbank_income>\n", file);
4555  fputs("<expenditures>", file);
4556  sprintf(data, "%f", current->expenditures);
4557  fputs(data, file);
4558  fputs("</expenditures>\n", file);
4559 
4560  fputs("</xagent>\n", file);
4561 }
4562 
4564 {
4565  char data[1000];
4566  fputs("<xagent>\n" , file);
4567  fputs("<name>centralbank</name>\n", file);
4568  fputs("<id>", file);
4569  sprintf(data, "%i", current->id);
4570  fputs(data, file);
4571  fputs("</id>\n", file);
4572  fputs("<day_of_month_to_act>", file);
4573  sprintf(data, "%i", current->day_of_month_to_act);
4574  fputs(data, file);
4575  fputs("</day_of_month_to_act>\n", file);
4576  fputs("<unemployment_rate>", file);
4577  sprintf(data, "%f", current->unemployment_rate);
4578  fputs(data, file);
4579  fputs("</unemployment_rate>\n", file);
4580  fputs("<inflation_rate>", file);
4581  sprintf(data, "%f", current->inflation_rate);
4582  fputs(data, file);
4583  fputs("</inflation_rate>\n", file);
4584  fputs("<consumption_goods_prices>", file);
4586  fputs("</consumption_goods_prices>\n", file);
4587  fputs("<it_no>", file);
4588  sprintf(data, "%i", current->it_no);
4589  fputs(data, file);
4590  fputs("</it_no>\n", file);
4591  fputs("<day_of_week_to_act>", file);
4592  sprintf(data, "%i", current->day_of_week_to_act);
4593  fputs(data, file);
4594  fputs("</day_of_week_to_act>\n", file);
4595  fputs("<goods>", file);
4596  write_transaction(file, &current->goods);
4597  fputs("</goods>\n", file);
4598  fputs("<weekly_price_averages>", file);
4600  fputs("</weekly_price_averages>\n", file);
4601  fputs("<day_of_month_wages_paid>", file);
4602  sprintf(data, "%i", current->day_of_month_wages_paid);
4603  fputs(data, file);
4604  fputs("</day_of_month_wages_paid>\n", file);
4605  fputs("<interest_rate>", file);
4606  sprintf(data, "%f", current->interest_rate);
4607  fputs(data, file);
4608  fputs("</interest_rate>\n", file);
4609  fputs("<liquidity>", file);
4610  sprintf(data, "%f", current->liquidity);
4611  fputs(data, file);
4612  fputs("</liquidity>\n", file);
4613  fputs("<loans_banks>", file);
4614  sprintf(data, "%f", current->loans_banks);
4615  fputs(data, file);
4616  fputs("</loans_banks>\n", file);
4617  fputs("<loans_government>", file);
4618  sprintf(data, "%f", current->loans_government);
4619  fputs(data, file);
4620  fputs("</loans_government>\n", file);
4621  fputs("<fiat_money>", file);
4622  sprintf(data, "%f", current->fiat_money);
4623  fputs(data, file);
4624  fputs("</fiat_money>\n", file);
4625  fputs("<equity>", file);
4626  sprintf(data, "%f", current->equity);
4627  fputs(data, file);
4628  fputs("</equity>\n", file);
4629  fputs("<liquidity_banks>", file);
4630  sprintf(data, "%f", current->liquidity_banks);
4631  fputs(data, file);
4632  fputs("</liquidity_banks>\n", file);
4633  fputs("<liquidity_government>", file);
4634  sprintf(data, "%f", current->liquidity_government);
4635  fputs(data, file);
4636  fputs("</liquidity_government>\n", file);
4637  fputs("<liquidity_equityfund>", file);
4638  sprintf(data, "%f", current->liquidity_equityfund);
4639  fputs(data, file);
4640  fputs("</liquidity_equityfund>\n", file);
4641  fputs("<total_assets>", file);
4642  sprintf(data, "%f", current->total_assets);
4643  fputs(data, file);
4644  fputs("</total_assets>\n", file);
4645  fputs("<total_writeoffs>", file);
4646  sprintf(data, "%f", current->total_writeoffs);
4647  fputs(data, file);
4648  fputs("</total_writeoffs>\n", file);
4649  fputs("<interests_accrued>", file);
4650  sprintf(data, "%f", current->interests_accrued);
4651  fputs(data, file);
4652  fputs("</interests_accrued>\n", file);
4653  fputs("<revenues>", file);
4654  sprintf(data, "%f", current->revenues);
4655  fputs(data, file);
4656  fputs("</revenues>\n", file);
4657  fputs("<net_earnings>", file);
4658  sprintf(data, "%f", current->net_earnings);
4659  fputs(data, file);
4660  fputs("</net_earnings>\n", file);
4661  fputs("<total_costs>", file);
4662  sprintf(data, "%f", current->total_costs);
4663  fputs(data, file);
4664  fputs("</total_costs>\n", file);
4665  fputs("<houses>", file);
4666  write_transaction(file, &current->houses);
4667  fputs("</houses>\n", file);
4668 
4669  fputs("</xagent>\n", file);
4670 }
4671 
4673 {
4674  char data[1000];
4675  fputs("<xagent>\n" , file);
4676  fputs("<name>jpoffice</name>\n", file);
4677  fputs("<id>", file);
4678  sprintf(data, "%i", current->id);
4679  fputs(data, file);
4680  fputs("</id>\n", file);
4681  fputs("<it_no>", file);
4682  sprintf(data, "%i", current->it_no);
4683  fputs(data, file);
4684  fputs("</it_no>\n", file);
4685  fputs("<day_of_month_to_act>", file);
4686  sprintf(data, "%i", current->day_of_month_to_act);
4687  fputs(data, file);
4688  fputs("</day_of_month_to_act>\n", file);
4689 
4690  fputs("</xagent>\n", file);
4691 }
4692 
4693 void write_mall_agent(FILE *file, xmachine_memory_mall * current)
4694 {
4695  char data[1000];
4696  fputs("<xagent>\n" , file);
4697  fputs("<name>mall</name>\n", file);
4698  fputs("<id>", file);
4699  sprintf(data, "%i", current->id);
4700  fputs(data, file);
4701  fputs("</id>\n", file);
4702  fputs("<it_no>", file);
4703  sprintf(data, "%i", current->it_no);
4704  fputs(data, file);
4705  fputs("</it_no>\n", file);
4706  fputs("<day_of_week_to_act>", file);
4707  sprintf(data, "%i", current->day_of_week_to_act);
4708  fputs(data, file);
4709  fputs("</day_of_week_to_act>\n", file);
4710  fputs("<goods_transactions>", file);
4711  write_transaction(file, &current->goods_transactions);
4712  fputs("</goods_transactions>\n", file);
4713 
4714  fputs("</xagent>\n", file);
4715 }
4716 
4718 {
4719  char data[1000];
4720  fputs("<xagent>\n" , file);
4721  fputs("<name>reagency</name>\n", file);
4722  fputs("<id>", file);
4723  sprintf(data, "%i", current->id);
4724  fputs(data, file);
4725  fputs("</id>\n", file);
4726  fputs("<day_of_month_to_act>", file);
4727  sprintf(data, "%i", current->day_of_month_to_act);
4728  fputs(data, file);
4729  fputs("</day_of_month_to_act>\n", file);
4730  fputs("<it_no>", file);
4731  sprintf(data, "%i", current->it_no);
4732  fputs(data, file);
4733  fputs("</it_no>\n", file);
4734  fputs("<mortgages_interest_rate>", file);
4735  sprintf(data, "%f", current->mortgages_interest_rate);
4736  fputs(data, file);
4737  fputs("</mortgages_interest_rate>\n", file);
4738  fputs("<housing_transactions>", file);
4739  write_transaction(file, &current->housing_transactions);
4740  fputs("</housing_transactions>\n", file);
4741 
4742  fputs("</xagent>\n", file);
4743 }
4744 
4745 
4746 void FLAME_write_xml(char * location, int iteration_number, int * output_types, int output_type_size)
4747 {
4748  /* Pointer to file */
4749  FILE *file;
4750  char data[1000];
4751 
4752  sprintf(data, "%s%i.xml", location, iteration_number);
4753 
4754  if((file = fopen(data, "w"))==NULL)
4755  {
4756  printf("Error: cannot open file '%s' for writing\n", data);
4757  exit(0);
4758  }
4759 
4760 
4761  fputs("<states>\n", file);
4762  if(FLAME_integer_in_array(0, output_types, output_type_size))
4763  {
4764  fputs("<itno>", file);
4765  sprintf(data, "%i", iteration_number);
4766  fputs(data, file);
4767  fputs("</itno>\n", file);
4768  fputs("<environment>\n" , file);
4769  fputs("<resume_mode>", file);
4770  sprintf(data, "%i", FLAME_environment_variable_resume_mode);
4771  fputs(data, file);
4772  fputs("</resume_mode>\n", file);
4773  fputs("<print_debug_mode>", file);
4774  sprintf(data, "%i", FLAME_environment_variable_print_debug_mode);
4775  fputs(data, file);
4776  fputs("</print_debug_mode>\n", file);
4777  fputs("<warning_mode>", file);
4778  sprintf(data, "%i", FLAME_environment_variable_warning_mode);
4779  fputs(data, file);
4780  fputs("</warning_mode>\n", file);
4781  fputs("<data_collection_mode>", file);
4783  fputs(data, file);
4784  fputs("</data_collection_mode>\n", file);
4785  fputs("<collect_household_data>", file);
4787  fputs(data, file);
4788  fputs("</collect_household_data>\n", file);
4789  fputs("<collect_firm_data>", file);
4790  sprintf(data, "%i", FLAME_environment_variable_collect_firm_data);
4791  fputs(data, file);
4792  fputs("</collect_firm_data>\n", file);
4793  fputs("<ratio_liquidity>", file);
4794  sprintf(data, "%f", FLAME_environment_variable_ratio_liquidity);
4795  fputs(data, file);
4796  fputs("</ratio_liquidity>\n", file);
4797  fputs("<consumption_adjustment_speed>", file);
4799  fputs(data, file);
4800  fputs("</consumption_adjustment_speed>\n", file);
4801  fputs("<wealth_effect>", file);
4802  sprintf(data, "%f", FLAME_environment_variable_wealth_effect);
4803  fputs(data, file);
4804  fputs("</wealth_effect>\n", file);
4805  fputs("<turnover_probability>", file);
4807  fputs(data, file);
4808  fputs("</turnover_probability>\n", file);
4809  fputs("<production_markup>", file);
4810  sprintf(data, "%f", FLAME_environment_variable_production_markup);
4811  fputs(data, file);
4812  fputs("</production_markup>\n", file);
4813  fputs("<price_markup>", file);
4814  sprintf(data, "%f", FLAME_environment_variable_price_markup);
4815  fputs(data, file);
4816  fputs("</price_markup>\n", file);
4817  fputs("<firm_memory_persistance>", file);
4819  fputs(data, file);
4820  fputs("</firm_memory_persistance>\n", file);
4821  fputs("<ratio_fiscal_policy>", file);
4823  fputs(data, file);
4824  fputs("</ratio_fiscal_policy>\n", file);
4825  fputs("<ratio_capitalist_households>", file);
4827  fputs(data, file);
4828  fputs("</ratio_capitalist_households>\n", file);
4829  fputs("<inflation_target>", file);
4830  sprintf(data, "%f", FLAME_environment_variable_inflation_target);
4831  fputs(data, file);
4832  fputs("</inflation_target>\n", file);
4833  fputs("<firms_minimum_equity_ratio>", file);
4835  fputs(data, file);
4836  fputs("</firms_minimum_equity_ratio>\n", file);
4837  fputs("<firm_startup_leverage>", file);
4839  fputs(data, file);
4840  fputs("</firm_startup_leverage>\n", file);
4841  fputs("<household_startup_leverage>", file);
4843  fputs(data, file);
4844  fputs("</household_startup_leverage>\n", file);
4845  fputs("<car_buffer_threshold>", file);
4847  fputs(data, file);
4848  fputs("</car_buffer_threshold>\n", file);
4849  fputs("<housing_market_entrance_prob>", file);
4851  fputs(data, file);
4852  fputs("</housing_market_entrance_prob>\n", file);
4853  fputs("<fire_sale_threshold>", file);
4855  fputs(data, file);
4856  fputs("</fire_sale_threshold>\n", file);
4857  fputs("<household_budget_constraint>", file);
4859  fputs(data, file);
4860  fputs("</household_budget_constraint>\n", file);
4861  fputs("<capital_adequecy_ratio>", file);
4863  fputs(data, file);
4864  fputs("</capital_adequecy_ratio>\n", file);
4865  fputs("<housing_price_up_rate>", file);
4867  fputs(data, file);
4868  fputs("</housing_price_up_rate>\n", file);
4869  fputs("<housing_price_down_rate>", file);
4871  fputs(data, file);
4872  fputs("</housing_price_down_rate>\n", file);
4873  fputs("<household_mortgage_writeoff_high>", file);
4875  fputs(data, file);
4876  fputs("</household_mortgage_writeoff_high>\n", file);
4877  fputs("<household_mortgage_writeoff_low>", file);
4879  fputs(data, file);
4880  fputs("</household_mortgage_writeoff_low>\n", file);
4881  fputs("</environment>\n" , file);
4882  }
4883 
4884 
4885  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(1, output_types, output_type_size))
4886  {
4889  {
4891 
4893  }
4894  }
4895 
4896  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(2, output_types, output_type_size))
4897  {
4900  {
4902 
4904  }
4905  }
4906 
4907  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(3, output_types, output_type_size))
4908  {
4911  {
4913 
4915  }
4916  }
4917 
4918  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(4, output_types, output_type_size))
4919  {
4922  {
4924 
4926  }
4927  }
4928 
4929  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(5, output_types, output_type_size))
4930  {
4933  {
4935 
4937  }
4938  }
4939 
4940  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(6, output_types, output_type_size))
4941  {
4944  {
4946 
4948  }
4949  }
4950 
4951  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(7, output_types, output_type_size))
4952  {
4955  {
4957 
4959  }
4960  }
4961 
4962  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(8, output_types, output_type_size))
4963  {
4966  {
4968 
4970  }
4971  }
4972 
4973  if(FLAME_integer_in_array(0, output_types, output_type_size) || FLAME_integer_in_array(9, output_types, output_type_size))
4974  {
4977  {
4979 
4981  }
4982  }
4983 
4984  fputs("</states>\n" , file);
4985 
4986  /* Close the file */
4987  (void)fclose(file);
4988 }
4989 
4994 void saveiterationdata(int iteration_number)
4995 {
4996  FLAME_output * current_FLAME_output;
4997  FLAME_output * current_FLAME_output2;
4998  int output_types[1000];
4999  int output_type_size = 0;
5000 
5001  /* For each output */
5002  for(current_FLAME_output = FLAME_outputs; current_FLAME_output != NULL; current_FLAME_output = current_FLAME_output->next)
5003  {
5004  /* If period/phase equates to current iteration */
5005  if(iteration_number%current_FLAME_output->period == current_FLAME_output->phase)
5006  {
5007  /* If output has already been handled */
5008  if(current_FLAME_output->flag == 0)
5009  {
5010  /* Check snapshot */
5011  if(current_FLAME_output->type == 0)
5012  {
5013  //snapshot_location = current_FLAME_output->location;
5014  output_types[0] = 0;
5015  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, 1);
5016  /* Set flag to 1 and every output to same location */
5017  current_FLAME_output->flag = 1;
5018  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5019  {
5020  if(strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5021  {
5022  current_FLAME_output2->flag = 1;
5023  }
5024  }
5025  }
5026  if(current_FLAME_output->type == 1)
5027  {
5028  /* Reinitialise agent size */
5029  output_type_size = 0;
5030  output_types[0] = 1;
5031 
5032  current_FLAME_output->flag = 1;
5033  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5034  {
5035  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5036  {
5037  output_types[++output_type_size] = current_FLAME_output2->type;
5038 
5039  current_FLAME_output2->flag = 1;
5040  }
5041  }
5042 
5043  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5044  }if(current_FLAME_output->type == 2)
5045  {
5046  /* Reinitialise agent size */
5047  output_type_size = 0;
5048  output_types[0] = 2;
5049 
5050  current_FLAME_output->flag = 1;
5051  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5052  {
5053  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5054  {
5055  output_types[++output_type_size] = current_FLAME_output2->type;
5056 
5057  current_FLAME_output2->flag = 1;
5058  }
5059  }
5060 
5061  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5062  }if(current_FLAME_output->type == 3)
5063  {
5064  /* Reinitialise agent size */
5065  output_type_size = 0;
5066  output_types[0] = 3;
5067 
5068  current_FLAME_output->flag = 1;
5069  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5070  {
5071  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5072  {
5073  output_types[++output_type_size] = current_FLAME_output2->type;
5074 
5075  current_FLAME_output2->flag = 1;
5076  }
5077  }
5078 
5079  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5080  }if(current_FLAME_output->type == 4)
5081  {
5082  /* Reinitialise agent size */
5083  output_type_size = 0;
5084  output_types[0] = 4;
5085 
5086  current_FLAME_output->flag = 1;
5087  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5088  {
5089  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5090  {
5091  output_types[++output_type_size] = current_FLAME_output2->type;
5092 
5093  current_FLAME_output2->flag = 1;
5094  }
5095  }
5096 
5097  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5098  }if(current_FLAME_output->type == 5)
5099  {
5100  /* Reinitialise agent size */
5101  output_type_size = 0;
5102  output_types[0] = 5;
5103 
5104  current_FLAME_output->flag = 1;
5105  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5106  {
5107  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5108  {
5109  output_types[++output_type_size] = current_FLAME_output2->type;
5110 
5111  current_FLAME_output2->flag = 1;
5112  }
5113  }
5114 
5115  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5116  }if(current_FLAME_output->type == 6)
5117  {
5118  /* Reinitialise agent size */
5119  output_type_size = 0;
5120  output_types[0] = 6;
5121 
5122  current_FLAME_output->flag = 1;
5123  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5124  {
5125  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5126  {
5127  output_types[++output_type_size] = current_FLAME_output2->type;
5128 
5129  current_FLAME_output2->flag = 1;
5130  }
5131  }
5132 
5133  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5134  }if(current_FLAME_output->type == 7)
5135  {
5136  /* Reinitialise agent size */
5137  output_type_size = 0;
5138  output_types[0] = 7;
5139 
5140  current_FLAME_output->flag = 1;
5141  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5142  {
5143  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5144  {
5145  output_types[++output_type_size] = current_FLAME_output2->type;
5146 
5147  current_FLAME_output2->flag = 1;
5148  }
5149  }
5150 
5151  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5152  }if(current_FLAME_output->type == 8)
5153  {
5154  /* Reinitialise agent size */
5155  output_type_size = 0;
5156  output_types[0] = 8;
5157 
5158  current_FLAME_output->flag = 1;
5159  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5160  {
5161  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5162  {
5163  output_types[++output_type_size] = current_FLAME_output2->type;
5164 
5165  current_FLAME_output2->flag = 1;
5166  }
5167  }
5168 
5169  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5170  }if(current_FLAME_output->type == 9)
5171  {
5172  /* Reinitialise agent size */
5173  output_type_size = 0;
5174  output_types[0] = 9;
5175 
5176  current_FLAME_output->flag = 1;
5177  for(current_FLAME_output2 = FLAME_outputs; current_FLAME_output2 != NULL; current_FLAME_output2 = current_FLAME_output2->next)
5178  {
5179  if(current_FLAME_output2->flag == 0 && strcmp(current_FLAME_output->location, current_FLAME_output2->location) == 0)
5180  {
5181  output_types[++output_type_size] = current_FLAME_output2->type;
5182 
5183  current_FLAME_output2->flag = 1;
5184  }
5185  }
5186 
5187  FLAME_write_xml(current_FLAME_output->location, iteration_number, output_types, output_type_size);
5188  }
5189  }
5190  }
5191  }
5192  /* Set flags back to 0 */
5193  for(current_FLAME_output = FLAME_outputs; current_FLAME_output != NULL; current_FLAME_output = current_FLAME_output->next)
5194  {
5195  current_FLAME_output->flag = 0;
5196  }
5197 }