X-Git-Url: https://pd.if.org/git/?p=afpopgen;a=blobdiff_plain;f=sim%2Fsim.c;h=d0e96695cc584b6bb1f39a8dc339baa772131b66;hp=7919300933f8ec045c7deacd6d78cd7d44b22e5e;hb=e7dabc38c4c6fdbe7204cf04b5f055c689eaded4;hpb=d4bca75365547d41ed53da1c3c12f5d5bbf93c84 diff --git a/sim/sim.c b/sim/sim.c index 7919300..d0e9669 100644 --- a/sim/sim.c +++ b/sim/sim.c @@ -15,11 +15,17 @@ void hexlistjson(struct afrhex *map); 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) { @@ -71,7 +77,7 @@ int main (int ac, char *av[]) { 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; @@ -82,6 +88,11 @@ int main (int ac, char *av[]) { 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]); @@ -123,6 +134,7 @@ int main (int ac, char *av[]) { 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);