-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.c
executable file
·152 lines (138 loc) · 7.16 KB
/
parse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*----------------------------------------------------------------------*
* File: gaia.c *
* *
* Purpose: Simulate a 2-D cellular automata model "DEAsy-World". *
* *
* *
* Author: Ben Tatman *
* University of Cambridge *
* *
* License: Copyright 2017-2018 Ben Tatman *
* Permission is hereby granted, free of charge, to any person *
* obtaining a copy of this software and associated documentation files *
* (the "Software"), to deal in the Software without restriction, *
* including without limitation the rights to use, copy, modify, merge, *
* publish, distribute, sublicense, and/or sell copies of the Software, *
* and to permit persons to whom the Software is furnished to do so, *
* subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS *
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN *
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN *
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
* *
* History: 20-Dec-2017, version 1.0 *
*----------------------------------------------------------------------*/
extern int diploid;
extern int sexual;
extern int sim_length;
extern char output_folder[500];
extern float radiation_intensity;
extern float global_temperature;
extern int resources_for_reproducing;
extern int initial_mutation_rate;
extern float initial_colour;
extern float initial_t_opt;
extern int initial_dispersal;
extern int initial_progeny;
extern int initial_pop;
extern int verbose;
extern int verbose_s;
extern int cheat;
extern int goldschmidt;
extern int goldschmidt_freq;
extern int cheat_freq;
extern int runprint;
extern float dominance;
extern float sex_freq;
extern int peak_verb;
extern float oscillation_wavelength;
extern int edea;
/*----------------------------------------------------------------------*
* Function: get_arg *
* Purpose: Extracts value of argument *
* Params: c = pointer to string *
* start = start position of value *
* Returns: value as a float *
*----------------------------------------------------------------------*/
float get_arg(char * c, int start) {
int i;
char str[256] = "";
for (i = start; i < strlen(c); i++) {
str[i-start] = c[i];
}
return atof(str);
}
/*----------------------------------------------------------------------*
* Function: parse_settings *
* Purpose: Parses command line options and sets values. *
* Params: argc = number of arguments *
* argv = array of arguments *
* Returns: 1 if successful, -1 if failed. *
*----------------------------------------------------------------------*/
int parse_settings(int argc, char*argv[]) {
int i;
for (i = 1; i < argc; i++) {
switch (argv[i][0]) {
case 'd': diploid = 1; break;
case 'h': diploid = 0; break;
case 's': sexual = 1; break;
case 'e': edea = 1; break; //
case 'm': dominance = (float) get_arg(argv[i], 1); break; //
case 'a': sexual = 0; break;
case 'c': cheat = 1; cheat_freq = (int) get_arg(argv[i], 1); break;
case 'l': sim_length = (int) get_arg(argv[i], 1); break;
case 'v': verbose = 1; verbose_s = (int) get_arg(argv[i], 1); break; //
case 'u': runprint = 0; break; //
case 'b': peak_verb = 1; break;
case 'o':
switch (argv[i][1]) {
case 's': sex_freq = (float) get_arg(argv[i], 2); break;
default:
if (i < argc - 1) {
strcpy(output_folder, argv[i+1]);
i++;
} else {
printf("Please provide a folder name.");
}
break;
}
break;
case 't': global_temperature = get_arg(argv[i], 1); break;
case 'r': resources_for_reproducing = (int) get_arg(argv[i], 1); break;
case 'k': radiation_intensity = get_arg(argv[i], 1); break;
case 'g': goldschmidt = 1; goldschmidt_freq = (int) get_arg(argv[i], 1); break;
case 'f': oscillation_wavelength = get_arg(argv[i], 1); break;
case 'i':
switch (argv[i][1]) {
case 'm': initial_mutation_rate = (int) (get_arg(argv[i], 2) * 1000); break;
case 'c': initial_colour = get_arg(argv[i], 2); break;
case 't': initial_t_opt = get_arg(argv[i], 2); break;
case 'd': initial_dispersal = (int) get_arg(argv[i], 2); break;
case 'p': initial_pop = (int) get_arg(argv[i], 2); break;
case 'k': initial_progeny = (int) get_arg(argv[i], 2); break;
default: break;
}
break;
case '!':
printf("Welcome to Gaia, a Daisyworld simulation program.\ncNUMBER - mate individuals across the map to simulate human intervention. Number is times in 10,000. \ngNUMBER - introduce goldschmidt macromutations. Number is frequency in 10,000.\nd - create diploid daisies (DEFAULT)\nh - create haploid daisies\ne - activate EDEA\nmNUMBER - set dominance coefficient (DEFAULT = 0.5)\nvNUMBER - enable verbose mode, print detailed map every NUMBER times\nu - disable output\ns - create sexual daisies (DEFAULT)\na - create asexual daisies\nlNUMBER - set number of timesteps to run (DEFAULT = 6000)\noFOLDER - set output folder (DEFAULT = .)\ntNUMBER - set initial temperature\nrNUMBER - set resources needed to reproduce (DEFAULT = 30)\nkNUMBER - set radiation intensity (DEFAULT = 1.0)\nimNUMBER - set initial mutation rate (DEFAULT 0.05)\nicNUMBER - set initial colour (DEFAULT 0.5)\nitNUMBER - set initial optimum temperature\nidNUMBER - set initial dispersal (DEFAULT 3)\nikNUMBER - set initial number of progeny (DEFAULT 2)\nipNUMBER - set initial population (DEFAULT 10)\n");
return -1;
break;
default: break;
}
}
//printf("%d\n", 1+ atoi(argv[1]));
if (sexual == 1 && diploid == 0) {
printf("Can't have sexual haploids.\n");
return -1;
}
return 1;
}