static void setpop(struct afrhex *map, int hexid, int *pop) {
struct afrhex *hex;
int i;
+ int sum = 0;
hex = find_hex(map, hexid);
for (i=0; i < 2; i++) {
hex->freq[i] = pop[i];
+ sum += pop[i];
}
+ if (sum % 2) {
+ fprintf(stderr, "allele frequency for hex %d not even\n", hexid);
+ }
+ hex->pop = sum/2;
}
static void setpopstr(struct afrhex *map, char *spec) {
clock_gettime(CLOCK_REALTIME, &ts);
seed = ((unsigned long)(ts.tv_sec) ^ (unsigned long)ts.tv_nsec) & 0xffffffff;
- while ((opt = getopt(ac, av, "r:s:ehp:y:g:m:t:d:")) != -1) {
+ while ((opt = getopt(ac, av, "f:r:s:ehp:y:g:m:t:d:")) != -1) {
switch (opt) {
case 's': seed = atoi(optarg); break;
case 'r': run = atoi(optarg); break;
case 'e': eemian = 1; break;
case 'h': holocene = 1; break;
case 'p': setpopstr(map, optarg); defaultpop = 0;break;
+ case 'f': if (freopen(optarg, "w", stdout) == NULL) {
+ perror("sim");
+ exit(EXIT_FAILURE);
+ }
+ break;
default:
fprintf(stderr, "Usage: %s [-s seed] [-r run] [-y startyear] [-eh] [-p hex:freq,freq[:freq,freq...]\n",
av[0]);
printf("{");
printf(" \"run\": %d, \"seed\": %d, \"gens\": %d", run, seed, gens);
+ printf(",\n\"options\": { \"capfactor\": %g }", capfactor);
printf(",\n\"gendata\": [\n");
dumpgenjson(map, 0, year);