shiba
 All Data Structures Files Functions Variables Macros Pages
main.c
Go to the documentation of this file.
1 
5 #include "shiba.h"
6 
8 
9 
10 int main(int argc, char **argv)
11 {
12 
13  phylo p;
14  // Set defaults for global variables
15  PhyloToUse = 0;
16  DataFile = "shibaInput.xml";
17  PrintData = 0;
18  RUN_BATCH = 1000;
19  Cfg.verbose = 0;
20  Cfg.probSurvA = -1.0;
21  Cfg.probDispA = -1.0;
22 
23  // Read arguments
24  readArgs(argc, argv);
25  // Read datafile
26  readXML();
27 
28  // Parse phylogeny
29  if ((PhyloToUse >= 0) && (PhyloToUse < Phylos))
31  else error("Specified phylo number does not match a phylo in input file");
32  phyloToLineage(p);
33 
34  if (PrintData) printIndata();
35 
36  // main runs
37  shiba(p);
38 
39  // Free memory
40  free(p.parent);
41  free(p.ndaughter);
42  free(p.depth);
43  free(p.age);
44  free(p.bl);
45  free2d1_c(p.taxon, p.nnodes);
46  free2d_d(Area, Times);
47  free3d_d(Dist, Times, Spaces);
48  free(RealTime);
52  free3d_i(Extant, Taxa, Times);
53  free(Cfg.startSpace);
54  free2d_i(LineagePeriod, p.nnodes);
55  free(LineageDaughtersN);
57  free3d_i(LineageExtant, Lineages, Times);
58 
59  return 1;
60 }
61 
69 void readArgs(int argc, char **argv)
70 {
71  int c;
72  opterr = 0;
73 
74  while ((c = getopt (argc, argv, "f:hp:lvd:s:")) != -1)
75  switch (c)
76  {
77  case 'f':
78  DataFile = optarg;
79  break;
80  case 'l':
81  PrintData = 1;
82  break;
83  case 'p':
84  PhyloToUse = atoi(optarg);
85  break;
86  case 'd':
87  if ((atof(optarg) > 0.0) && (atof(optarg) <= 1.0)) {
88  Cfg.probDispA = atof(optarg);
89  break;
90  }
91  else error("Dispersal parameter on command line not acceptable");
92  case 's':
93  if ((atof(optarg) > 0.0) && (atof(optarg) <= 1.0)) {
94  Cfg.probSurvA = atof(optarg);
95  break;
96  }
97  else error("Survival parameter on command line not acceptable");
98  case 'v':
99  RUN_BATCH = 1; // cannot do verbose in parallel mode
100  Cfg.verbose = 1;
101  break;
102  case 'h':
103  help();
104  case '?':
105  if (optopt == 'f')
106  fprintf (stderr, "Option -%c requires an argument.\n", optopt);
107  else if (isprint (optopt))
108  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
109  else
110  fprintf (stderr,
111  "Unknown option character `\\x%x'.\n",
112  optopt);
113  default:
114  abort();
115  }
116 }