[med-svn] [indelible] 01/02: Imported Upstream version 1.03

Fabian Klötzl kloetzl-guest at moszumanska.debian.org
Wed Dec 9 14:55:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

kloetzl-guest pushed a commit to branch master
in repository indelible.

commit 290ff2074b2bc823395edce1fbc8bbd47beb020e
Author: Fabian Klötzl <fabian at kloetzl.info>
Date:   Wed Dec 9 14:31:11 2015 +0100

    Imported Upstream version 1.03
---
 bin/G4_readme.txt                                 |    4 +
 bin/M5-13_OSX_G4                                  |  Bin 0 -> 73396 bytes
 bin/M5-13_OSX_intel                               |  Bin 0 -> 101364 bytes
 bin/M5-13_Windows.exe                             |  Bin 0 -> 217088 bytes
 bin/indelible_1.03_OSX_intel                      |  Bin 0 -> 902416 bytes
 bin/indelible_1.03_Windows.exe                    |  Bin 0 -> 1003520 bytes
 control.txt                                       |   44 +
 help/example_files/AMINOACID.shtml                |  104 +
 help/example_files/CODON.shtml                    |  146 +
 help/example_files/CODONsites.shtml               |  107 +
 help/example_files/NUCLEOTIDE.shtml               |  119 +
 help/example_files/basic.shtml                    |   46 +
 help/example_files/basicaminoacid.shtml           |   49 +
 help/example_files/basiccodon.shtml               |   51 +
 help/example_files/basicnucleotide.shtml          |   49 +
 help/example_files/branch.shtml                   |   74 +
 help/example_files/branch2.shtml                  |  100 +
 help/example_files/codon_RATES.txt                |  715 +++
 help/example_files/indels.shtml                   |  117 +
 help/example_files/multi-partitions.shtml         |   78 +
 help/example_files/mylengthmodel.txt              | 1000 +++++
 help/example_files/nucleotide-branch.shtml        |  112 +
 help/example_files/nucleotide_RATES.txt           |  685 +++
 help/example_files/random_branch_length_trees.JPG |  Bin 0 -> 29703 bytes
 help/example_files/rates.shtml                    |   69 +
 help/example_files/settings.shtml                 |  122 +
 help/example_files/sitebranch.shtml               |   75 +
 help/example_files/trees.shtml                    |  185 +
 help/example_files/trees.txt                      |   60 +
 help/example_files/userAAmodel.txt                |   23 +
 help/examples.shtml                               |   62 +
 help/manual.shtml                                 |   57 +
 help/manual_files/branches.shtml                  |   44 +
 help/manual_files/codon_RATES.txt                 |  715 +++
 help/manual_files/evolve.shtml                    |   26 +
 help/manual_files/model.shtml                     |  249 ++
 help/manual_files/mylengthmodel.txt               | 1000 +++++
 help/manual_files/nucleotide_RATES.txt            |  685 +++
 help/manual_files/partitions.shtml                |   37 +
 help/manual_files/random_branch_length_trees.JPG  |  Bin 0 -> 29703 bytes
 help/manual_files/settings.shtml                  |   99 +
 help/manual_files/symQmatrix.gif                  |  Bin 0 -> 4515 bytes
 help/manual_files/tree.shtml                      |  130 +
 help/manual_files/trees.txt                       |   60 +
 help/manual_files/type.shtml                      |   24 +
 help/manual_files/userAAmodel.txt                 |   23 +
 readme.txt                                        |   29 +
 src/M5-13.cpp                                     | 1506 +++++++
 src/MersenneTwister.h                             |  473 ++
 src/README.txt                                    |   52 +
 src/control.cpp                                   | 4167 +++++++++++++++++
 src/indelible.cpp                                 | 4973 +++++++++++++++++++++
 src/models.cpp                                    | 3579 +++++++++++++++
 src/paml.cpp                                      | 2164 +++++++++
 src/randoms.cpp                                   |  184 +
 55 files changed, 24472 insertions(+)

diff --git a/bin/G4_readme.txt b/bin/G4_readme.txt
new file mode 100644
index 0000000..7470fcd
--- /dev/null
+++ b/bin/G4_readme.txt
@@ -0,0 +1,4 @@
+I only have limited access to an old G4 mac at the moment.
+I will compile a G4 version as soon as I can and include it in the download package.
+Until then you can compile your own version using the source code
+and the instructions in the "src" folder.
diff --git a/bin/M5-13_OSX_G4 b/bin/M5-13_OSX_G4
new file mode 100644
index 0000000..5e20362
Binary files /dev/null and b/bin/M5-13_OSX_G4 differ
diff --git a/bin/M5-13_OSX_intel b/bin/M5-13_OSX_intel
new file mode 100644
index 0000000..ec7efaf
Binary files /dev/null and b/bin/M5-13_OSX_intel differ
diff --git a/bin/M5-13_Windows.exe b/bin/M5-13_Windows.exe
new file mode 100644
index 0000000..3ceeccd
Binary files /dev/null and b/bin/M5-13_Windows.exe differ
diff --git a/bin/indelible_1.03_OSX_intel b/bin/indelible_1.03_OSX_intel
new file mode 100644
index 0000000..0bf7d45
Binary files /dev/null and b/bin/indelible_1.03_OSX_intel differ
diff --git a/bin/indelible_1.03_Windows.exe b/bin/indelible_1.03_Windows.exe
new file mode 100644
index 0000000..a42d385
Binary files /dev/null and b/bin/indelible_1.03_Windows.exe differ
diff --git a/control.txt b/control.txt
new file mode 100644
index 0000000..0e3b0cf
--- /dev/null
+++ b/control.txt
@@ -0,0 +1,44 @@
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - basic.txt                                       //
+//                                                                                 //
+//      A basic introduction to the structure of the INDELible control file.       //
+//                                                                                 //
+//      There are other examples in the file examples.html in the help folder      //
+//      Any one of those examples will work if cut and paste into a control file.  //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+// It is useful to know that anything on a line after two forward slashes is ignored.
+
+/*
+   Another useful thing to know is that anything after a forward slash and star
+   is ignored until INDELible sees a star followed by a forward slash later on.
+*/     
+
+[TYPE] NUCLEOTIDE 1	//  EVERY control file must begin with a [TYPE] command.
+			//  The word can be NUCLEOTIDE, AMINOACID or CODON depending 
+			//  on what kind of simulation you want to do but must be in 
+			//  upper case. The number can be 1 or 2 and chooses the 
+			//  algorithm that INDELible uses (see manuscript). Both give 
+			//  identical results but in some cases one is quicker.
+			//  Other blocks and commands following this statement
+			//  can come in any order you like.
+
+[MODEL]    modelname  	//  Evolutionary models are defined in [MODEL] blocks.
+[submodel] JC         	//  Here the substitution model is simply set as JC69.
+                      	//  No indel model has been given so no indels will occur. 
+  
+[TREE] treename  (A:0.1,B:0.1);        //  User trees are defined here
+
+[PARTITIONS] partitionname             //  [PARTITIONS] blocks say which models go with
+  [treename modelname 1000]            //  which trees and define the length of the
+                                       //  sequence generated at the root (1000 here).
+
+[EVOLVE] partitionname 100 outputname  //  This will generate 100 replicate datasets 
+                                       //  from the [PARTITIONS] block named above.
+
+// The true alignment will be output in a file named outputname_TRUE.phy
+// The unaligned sequences will be output in a file named outputname.fas
+
+
diff --git a/help/example_files/AMINOACID.shtml b/help/example_files/AMINOACID.shtml
new file mode 100644
index 0000000..3b1c148
--- /dev/null
+++ b/help/example_files/AMINOACID.shtml
@@ -0,0 +1,104 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - AMINOACID.txt                                   //
+//                                                                                 //
+//      An introduction to different amino-acid substitution models.               //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* Again - the control file must begin with the [TYPE] statement */
+
+<font color=red>[TYPE] AMINOACID 1</font>	//  amino-acid simulation using algorithm from method 1.
+
+  /* Many different models can be defined in a single control file */
+
+<font color=red>[MODEL]    JTTexample1</font>
+<font color=red>  [submodel]  JTT                     </font>	//  JTT model defined using the code.
+
+<font color=red>[MODEL]    JTTexample2</font>
+<font color=red>  [submodel]  1                       </font>	//  JTT model defined using a number.
+
+<font color=red>[MODEL]    WAGexample</font>
+<font color=red>  [submodel]  WAG                </font>	//  WAG defined using the code
+
+  /* Specifying stationary frequencies will force the +F version of a model */
+
+<font color=red>[MODEL]    WAG_Fexample</font>
+<font color=red>  [submodel]  WAG  </font>                    // WAG+F
+<font color=red>    [statefreq]  </font>                                       // list of 20 numbers 
+<font color=red>      0.079066  0.055941  0.041977  0.053052  0.012937 </font> // A R N D C  
+<font color=red>      0.040767  0.071586  0.057337  0.022355  0.062157 </font> // Q E G H I 
+<font color=red>      0.099081  0.064600  0.022951  0.042302  0.044040 </font> // L K M F P 
+<font color=red>      0.061197  0.053287  0.012066  0.034155  0.069147 </font> // S T W Y V
+
+  /* User defined (reversible) amino-acid substitution model */
+
+<font color=red>[MODEL]   USERexample</font>                 // e.g. formatted like <a href="userAAmodel.txt" target="_blank">this</a>
+<font color=red>  [submodel]  userAAmodel.txt  </font>	      // for the Dayhoff-dcmut model.
+
+  /* Many different trees can be defined in a single control file */
+
+<font color=red>[TREE] t1  (A:0.1,B:0.1);</font> 
+<font color=red>[TREE] t2  ( (A:0.1, B:0.1):0.1, (C:0.3, D:0.3):0.5 );</font>   
+<font color=red>[TREE] t3  ( species1:0.1, species2:0.1, (species3:0.2, species4:0.2):0.01 );</font>      
+<font color=red>[TREE] t4  
+ (((1:0.1,2:0.1):0.1,(3:0.1,4:0.1):0.1):0.1,((5:0.1,6:0.1):0.1,(7:0.1,8:0.1):0.1):0.1);</font> 
+
+  /* Many different partition groupings can be defined in a single control file */
+
+<font color=red>[PARTITIONS] pJTT1  [t1 JTTexample1 160]</font>  // tree t1, model JTTexample1, root length 160
+<font color=red>[PARTITIONS] pJTT2  [t2 JTTexample2 500]</font>  // tree t2, model JTTexample2, root length 500
+<font color=red>[PARTITIONS] pWAG1  [t3 WAGexample 988]</font>   // tree t3, model WAGexample, root length 988
+<font color=red>[PARTITIONS] pWAG2  [t4 WAG_Fexample 75]</font>  // tree t4, model WAG_Fexample, root length 75
+<font color=red>[PARTITIONS] pUSER  [t3 USERexample 988]</font>  // tree t3, model USERexample, root length 988
+
+  /* The [EVOLVE] statement is then used to list all the simulations you want to do */
+
+<font color=red>[EVOLVE] </font>
+  <font color=red>pJTT1 40 J1out</font> // 40 replicates generated from partition pJTT1 in file J1out.fas etc
+  <font color=red>pJTT2 50 J2out</font> // 50 replicates generated from partition pJTT2 in file J2out.fas etc
+  <font color=red>pWAG1 25 Wout</font>  // 25 replicates generated from partition pWAG1 in file Wout.fas etc
+  <font color=red>pWAG2 10 WFout</font> // 10 replicates generated from partition pWAG2 in file WFout.fas etc
+  <font color=red>pUSER 13 Uout</font>  // 13 replicates generated from partition pUSER in file Uout.fas etc
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+     All amino-acid substitution models are specified as: <font color=blue>[submodel] value</font>
+     where <b>value</b> is just an integer <b>N</b> or a <b>code</b> used to pick the amino-acid 
+     substitution model as defined below (references given where appropriate):
+
+    +-----+---------------+-------------------------------+
+    |  <b>N</b>  | <b>code</b>          | <b>Reference</b>                     |
+    +-----+---------------+-------------------------------+
+    |  0  | Poisson       |  n/a                          |
+    |  1  | JTT           |  Jones et al,. 1992           |
+    |  2  | JTT-dcmut     |  Kosiol and Goldman, 2005     |
+    |  3  | Dayhoff       |  Dayhoff et al., 1978         |
+    |  4  | Dayhoff-dcmut |  Kosiol and Goldman, 2005     |
+    |  5  | WAG           |  Whelan and Goldman, 2001     |
+    |  6  | mtMAM         |  Yang et al., 1998            |
+    |  7  | mtART         |  Abascal et al., 2007         |
+    |  8  | mtREV         |  Adachi and Hasegawa, 1996    |
+    |  9  | rtREV         |  Dimmic et al., 2002          |
+    |  10 | cpREV         |  Adachi, 2000                 |
+    |  11 | Vt            |  Muller and Vingron, 2000     |
+    |  12 | Blosum        |  Henikoff and Henikoff, 1992  |
+    |  13 | LG            |  Le and Gascuel, 2008         |
+    |  14 | HIVb          |  Nickle et al., 2007          |
+    |  15 | HIVw          |  Nickle et al., 2007          |
+    |  16 | USER          |  n/a                          |
+    +-----+---------------+-------------------------------+
+   
+    The only exception is the user-model where you simply specify the  
+    name of the file that contains the state frequencies and the rate
+    matrix Q. This file should be in the same folder as INDELible.
+
+*/ 
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/CODON.shtml b/help/example_files/CODON.shtml
new file mode 100644
index 0000000..0a1c97c
--- /dev/null
+++ b/help/example_files/CODON.shtml
@@ -0,0 +1,146 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - CODON.txt                                       //
+//                                                                                 //
+//      An introduction to codon substitution models.                              //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* Again - the control file must begin with the [TYPE] statement */
+
+<font color=red>[TYPE] CODON 2</font>	//  codon simulation using algorithm from method 2
+
+  /* Many different models can be defined in a single control file */
+
+<font color=red>[MODEL] M0example1</font>  
+<font color=red>    [submodel]  2.5  0.5  </font>                   //  kappa=2.5, w=0.5
+
+<font color=red>[MODEL] M0example2</font>  
+<font color=red>    [submodel]  5.0  1.0  </font>                   //  kappa=5.0, w=1.0
+
+
+  /* The genetic code is the standard code by default but can be changed, e.g. */
+
+<font color=red>[MODEL] M0example3</font>  
+<font color=red>    [submodel]     2.5  0.5  </font>                //  kappa=2.5, w=0.5
+<font color=red>    [geneticcode]  3  </font>                       //  The Yeast Mitochondrial Code 
+<font color=red></font>                                             //  (see end of file for more)
+
+  /* The stationary frequencies are set equal by default but can be changed, e.g. */
+  /* (Notice how the stop codons for this genetic code have a value of zero). */
+
+<font color=red>[MODEL] M0example4</font>  
+<font color=red>    [submodel]     2.5  0.5  </font>                //  kappa=2.5, w=0.5
+<font color=red>    [statefreq]  </font>
+<font color=red>      0.016133 0.014626 0.012261 0.019123  </font>  //  TTT  TTC  TTA  TTG
+<font color=red>      0.008365 0.007583 0.006357 0.009915  </font>  //  TCT  TCC  TCA  TCG 
+<font color=red>      0.013290 0.012048 0        0         </font>  //  TAT  TAC  TAA  TAG
+<font color=red>      0.009947 0.009018 0        0.011790  </font>  //  TGT  TGC  TGA  TGG
+
+<font color=red>      0.019297 0.017494 0.014665 0.022873  </font>  //  CTT  CTC  CTA  CTG 
+<font color=red>      0.010005 0.009070 0.007604 0.011859  </font>  //  CCT  CCC  CCA  CCG 
+<font color=red>      0.015896 0.014410 0.012080 0.018841  </font>  //  CAT  CAC  CAA  CAG 
+<font color=red>      0.011898 0.010786 0.009042 0.014102  </font>  //  CGT  CGC  CGA  CGG 
+
+<font color=red>      0.030728 0.027857 0.023353 0.036422  </font>  //  ATT  ATC  ATA  ATG  
+<font color=red>      0.015932 0.014443 0.012108 0.018884  </font>  //  ACT  ACC  ACA  ACG  
+<font color=red>      0.025312 0.022947 0.019236 0.030002  </font>  //  AAT  AAC  AAA  AAG  
+<font color=red>      0.018945 0.017175 0.014398 0.022456  </font>  //  AGT  AGC  AGA  AGG 
+
+<font color=red>      0.024518 0.022227 0.018633 0.029061  </font>  //  GTT  GTC  GTA  GTG 
+<font color=red>      0.012712 0.011524 0.009661 0.015068  </font>  //  GCT  GCC  GCA  GCG  
+<font color=red>      0.020196 0.018309 0.015349 0.023938  </font>  //  GAT  GAC  GAA  GAG  
+<font color=red>      0.015117 0.013704 0.011488 0.017919  </font>  //  GGT  GGC  GGA  GGG
+
+
+  /* Many different trees can be defined in a single control file */
+
+<font color=red>[TREE] t1  (A:0.1,B:0.1);</font> 
+<font color=red>[TREE] t2  ( (A:0.1, B:0.1):0.1, (C:0.3, D:0.3):0.5 );</font>   
+<font color=red>[TREE] t3  ( species1:0.1, species2:0.1, (species3:0.2, species4:0.2):0.01 );</font>
+<font color=red>[TREE] t4  
+ (((1:0.1,2:0.1):0.1,(3:0.1,4:0.1):0.1):0.1,((5:0.1,6:0.1):0.1,(7:0.1,8:0.1):0.1):0.1);</font>
+
+  /* Many different partition groupings can be defined in a single control file */
+
+<font color=red>[PARTITIONS] pM0_1  [t1 M0example1 160]</font>  // tree t1, model M0example1, root length 160
+<font color=red>[PARTITIONS] pM0_2  [t2 M0example2 500]</font>  // tree t2, model M0example2, root length 500
+<font color=red>[PARTITIONS] pM0_3  [t3 M0example3 988]</font>  // tree t3, model M0example3, root length 988
+<font color=red>[PARTITIONS] pM0_4  [t4 M0example4 75]</font>   // tree t4, model M0example4, root length 75
+
+  /* The [EVOLVE] statement is then used to list all the simulations you want to do */
+
+<font color=red>[EVOLVE] </font>
+  <font color=red>pM0_1  40 out1</font>  // 40 replicates generated from partition pM0_1 in file out1.fas etc
+  <font color=red>pM0_2  50 out2</font>  // 50 replicates generated from partition pM0_2 in file out2.fas etc
+  <font color=red>pM0_3  25 out3</font>  // 25 replicates generated from partition pM0_3 in file out3.fas etc
+  <font color=red>pM0_4  10 out4</font>  // 10 replicates generated from partition pM0_4 in file out4.fas etc
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+    Codon frequencies are changed from being equal by listing 64 numbers (separated 
+    by white space) after the command <font color=blue>[statefreq]</font>.
+
+    The genetic code is changed using the command <font color=blue>[geneticcode]</font>.
+
+    e.g. [geneticcode] 3
+
+    The value should be an integer 1 to 6, 9 to 16, or 21 to 24, corresponding to the 
+    genetic codes listed on Genbank. The value 1 (corresponding to the universal genetic 
+    code) is the default setting if the command is not specified.
+    
+    These genetic codes determine which codons are stop codons and therefore not 
+    included in the simulation. They are also used to translate codons to amino-acids 
+    for output if that option is chosen.  The codes listed at <a href="http://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi">Genbank</a> (in Oct. 2008) 
+    are given below (* represents a stop codon). Please note that some codes listed
+    are identical and only differ in terms of Starts. For more info. visit Genbank.
+
+       1  - The Standard Code
+       FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       2  - The Vertebrate Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG
+       3  - The Yeast Mitochondrial Code
+       FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       4  - The Mold, Protozoan, and Coelenterate Mitochondrial
+            Code and the Mycoplasma/Spiroplasma Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       5  - The Invertebrate Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG
+       6  - The Ciliate, Dasycladacean and Hexamita Nuclear Code
+       FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       9  - The Echinoderm and Flatworm Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG
+       10 - The Euplotid Nuclear Code
+       FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       11 - The Bacterial and Plant Plastid Code
+       FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       12 - The Alternative Yeast Nuclear Code
+       FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       13 - The Ascidian Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG
+       14 - The Alternative Flatworm Mitochondrial Code
+       FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG
+       15 - The Blepharisma Nuclear Code
+       FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       16 - The Chlorophycean Mitochondrial Code
+       FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       21 - The Trematode Mitochondrial Code 
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG
+       22 - The Scenedesmus obliquus mitochondrial Code 
+       FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       23 - The Thraustochytrium Mitochondrial Code
+       FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+
+Base1: TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+Base2: TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+Base3: TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+
+*/
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/CODONsites.shtml b/help/example_files/CODONsites.shtml
new file mode 100644
index 0000000..11b484d
--- /dev/null
+++ b/help/example_files/CODONsites.shtml
@@ -0,0 +1,107 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - CODONsites.txt                                  //
+//                                                                                 //
+//      An introduction to different codon site models.                            //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* Again - the control file must begin with the [TYPE] statement */
+
+<font color=red>[TYPE] CODON 1</font>	//  codon simulation using algorithm from method 1
+
+
+  /* Many different models can be defined in a single control file */
+
+<font color=red>[MODEL] M0example</font>  
+<font color=red>    [submodel]  2.5  0.5  </font>                   //  kappa=2.5, w=0.5
+ 									
+<font color=red>[MODEL] M1example</font>    
+<font color=red>    [submodel]  2.5     </font>                     //  kappa=2.5
+<font color=red>                0.2     </font>                     //  p0=0.2, p1=0.8
+<font color=red>                0.5  1  </font>                     //  w0=0.5, w1=1
+  
+<font color=red>[MODEL] m1example</font>    
+<font color=red>    [submodel]  2.5  0.2  0.5  1</font>             //  same as above, but can be on one line
+
+<font color=red>[MODEL] M2example</font>    
+<font color=red>    [submodel]  2.0          </font>                //  kappa=2
+<font color=red>                0.2  0.3     </font>                //  p0=0.2, p1=0.3, p2=0.5
+<font color=red>                0.5  1.0  2.0</font>                //  w0=0.5, w1=1, w2=2
+  
+<font color=red>[MODEL] M3example </font>  
+<font color=red>    [submodel]  2.5  </font>                                 //  kappa=2.5
+<font color=red>                0.05  0.10  0.20  0.30  0.25 </font>         //  p0, p1, p2, p3, p4, p5=0.1 
+<font color=red>                0.13  0.72  1.38  2.74  5.42  10.23 </font>  //  w0, w1, w2, w3, w4, w5
+  
+<font color=red>[MODEL] M4example </font>  
+<font color=red>    [submodel]  2.5  </font>                                 //  kappa=2.5
+<font color=red>                0.05  0.1        0.2        0.3 </font>      //  p0, p1, p2, p3, p4=0.35 
+<font color=red>                0     0.333333   0.666666   1    3</font>    //  w0, w1, w2, w3, w4
+
+
+<font color=red>[TREE] t1  (A:0.1,B:0.1);</font> 
+
+
+  /* Many different partition groupings can be defined in a single control file */
+
+<font color=red>[PARTITIONS] pM0   [t1 M0example 160]</font>  // tree t1, model M0example, root length 160
+<font color=red>[PARTITIONS] pM1   [t1 M1example 500]</font>  // tree t1, model M1example, root length 500
+<font color=red>[PARTITIONS] pM2   [t1 M2example 988]</font>  // tree t1, model M2example, root length 988
+<font color=red>[PARTITIONS] pM3   [t1 M3example 821]</font>  // tree t1, model M3example, root length 821
+<font color=red>[PARTITIONS] pM4   [t1 M4example 75]</font>   // tree t1, model M4example, root length 75
+
+
+  /* The [EVOLVE] statement is then used to list all the simulations you want to do */
+
+<font color=red>[EVOLVE] </font>
+  <font color=red>pM0  40 out1</font>  // 40 replicates generated from partition pM0 in file out1.fas etc
+  <font color=red>pM1  50 out2</font>  // 50 replicates generated from partition pM1 in file out2.fas etc
+  <font color=red>pM2  25 out3</font>  // 25 replicates generated from partition pM2 in file out3.fas etc
+  <font color=red>pM3  11 out4</font>  // 11 replicates generated from partition pM3 in file out4.fas etc
+  <font color=red>pM4  10 out5</font>  // 10 replicates generated from partition pM4 in file out5.fas etc
+
+
+///////////////////////////////////////////////////////////////////////////////////
+
+/*
+    The command is <font color=blue> [submodel] ECMunrest</font> for the empirical unrestricted model.
+    The command is <font color=blue> [submodel] ECMrest</font> for the empirical restricted model.
+
+    The non-empirical codon substitution models are all special cases of M3.
+    They are specified using the following format for a model with K categories:
+
+    M3 (discrete)                       // p<sub>(K-1)</sub>=1-p<sub>(K-2)</sub>-...-p<sub>1</sub>-p<sub>0</sub>
+   <font color=blue> [submodel]  kappa</font>
+   <font color=blue>             p<sub>0</sub>  p<sub>1</sub>  ...  p<sub>(K-2)</sub>   <sub>     </sub>  </font>// proportions
+   <font color=blue>             ω<sub>0</sub>  ω<sub>1</sub>  ...  ω<sub>(K-2)</sub>  ω<sub>(K-1)</sub> </font> // omegas
+
+    All models M0-M13 can be represented in this M3 format, e.g.
+
+    M0 (one-ratio) 
+    <font color=blue>[submodel]  kappa  &omega<sub>0</sub>                   </font>//  p<sub>0</sub>=1
+ 
+    M1 (neutral)   
+    <font color=blue>[submodel]  kappa  p<sub>0</sub>  ω<sub>0</sub>  1           </font> //  ω<sub>1</sub>=1;  p<sub>1</sub>=1-p<sub>0</sub>
+
+    M2 (selection)  
+    <font color=blue>[submodel]  kappa  p<sub>0</sub>  p<sub>1</sub>  ω<sub>0</sub>  1   ω<sub>2</sub>   </font>//  ω<sub>1</sub>=1;  p<sub>2</sub>=1-p<sub>1</sub>-p<sub>0</sub>
+   
+    M4 (freqs) with K=5  
+    <font color=blue>[submodel]  kappa  </font>
+    <font color=blue>            p<sub>0</sub>  p<sub>1</sub>         p<sub>2</sub>         p<sub>3</sub>   <sub> </sub>  </font>//  p<sub>4</sub>=1-p<sub>3</sub>-p<sub>2</sub>-p<sub>1</sub>-p<sub>0</sub>
+    <font color=blue>            0<sub> </sub>  0.333333<sub> </sub>  0.666666<sub> </sub>  1<sub> </sub>  3<sub> </sub>  </font>//  ω<sub>0</sub>,  ω<sub>1</sub>,  ω<sub>2</sub>,  ω<sub>3</sub>,  ω<sub>4</sub> 
+
+    A script (named "M5-13") is provided with INDELible to calculate the discrete 
+    values for this command from the parameters used in models M5-M13.
+
+    Codon frequencies are changed from being equal by listing 64 numbers 
+    (separated by white space) after the command <font color=blue>[statefreq]</font>.
+*/
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/NUCLEOTIDE.shtml b/help/example_files/NUCLEOTIDE.shtml
new file mode 100644
index 0000000..d54e9bd
--- /dev/null
+++ b/help/example_files/NUCLEOTIDE.shtml
@@ -0,0 +1,119 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - NUCLEOTIDE.txt                                  //
+//                                                                                 //
+//      An introduction to different nucleotide substitution models.               //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* Again - the control file must begin with the [TYPE] statement */
+
+<font color=red>[TYPE] NUCLEOTIDE 2</font>	//  nucleotide simulation using algorithm from method 2.
+
+  /* Many different models can be defined in a single control file */
+
+<font color=red>[MODEL]    JCexample</font>
+<font color=red>  [submodel]  JC                     </font>	//  JC69
+
+<font color=red>[MODEL]    HKYexample</font>
+<font color=red>  [submodel]  HKY 2.5                </font>	//  HKY with a=f=kappa=2.5, b=c=d=e=1
+<font color=red>  [statefreq] 0.4 0.3 0.2 0.1        </font>	//  pi_T=0.4, pi_C=0.3, pi_A=0.2, pi_G=0.1
+
+<font color=red>[MODEL]    K81example</font>
+<font color=red>  [submodel]  K81 1.5 2.5            </font>	//  K81 with b=e=1.5, c=d=2.5, a=f=1
+
+<font color=red>[MODEL]    GTRexample</font>
+<font color=red>  [submodel]  GTR 0.2 0.4 0.6 0.8 1.2</font>	//  GTR: a=0.2, b=0.4, c=0.6, d=0.8, e=1.2, f=1
+<font color=red>  [statefreq] 0.1 0.2 0.3 0.4        </font>	//  pi_T=0.1, pi_C=0.2, pi_A=0.3, pi_G=0.4
+
+  /* Many different trees can be defined in a single control file */
+
+<font color=red>[TREE] t1  (A:0.1,B:0.1);</font> 
+<font color=red>[TREE] t2  ( (A:0.1, B:0.1):0.1, (C:0.3, D:0.3):0.5 );</font>   
+<font color=red>[TREE] t3  ( species1:0.1, species2:0.1, (species3:0.2, species4:0.2):0.01 );</font>      
+<font color=red>[TREE] t4  
+ (((1:0.1,2:0.1):0.1,(3:0.1,4:0.1):0.1):0.1,((5:0.1,6:0.1):0.1,(7:0.1,8:0.1):0.1):0.1);</font> 
+
+  /* Many different partition groupings can be defined in a single control file */
+
+<font color=red>[PARTITIONS] pJC   [t1 JCexample 1600]</font> //  tree t1, model JCexample, root length of 1600
+<font color=red>[PARTITIONS] pHKY  [t2 HKYexample 500]</font> //  tree t2, model HKYexample, root length of 500
+<font color=red>[PARTITIONS] pK81  [t3 K81example 988]</font> //  tree t3, model K81example, root length of 988
+<font color=red>[PARTITIONS] pGTR  [t4 GTRexample 754]</font> //  tree t4, model GTRexample, root length of 754
+
+  /* The [EVOLVE] statement is then used to list all the simulations you want to do */
+
+<font color=red>[EVOLVE] </font>
+  <font color=red>pJC 500 JCout</font>   //  500 replicates generated from partition pJC in file JCout.fas etc
+  <font color=red>pHKY 50 HKYout</font>  //  50 replicates generated from partition pHKY in file HKYout.fas etc
+  <font color=red>pK81 25 K81out</font>  //  25 replicates generated from partition pK81 in file K81out.fas etc
+  <font color=red>pGTR 10 GTRout</font>  //  10 replicates generated from partition pGTR in file GTRout.fas etc
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+     All nucleotide substitution models (apart from UNREST) are specified in 
+     relation to this general substitution rate matrix:
+                                                                               
+                                    TO                                      
+               ---------------------------------------------            
+         FROM ||     T    |    C     |    A     |    G                  
+        ------++----------+----------+----------+-----------            
+          T   ||     -    |  a Pi_C  |  b Pi_A  |  c Pi_G                
+          C   ||  a Pi_T  |     -    |  d Pi_A  |  e Pi_G                
+          A   ||  b Pi_T  |  d Pi_C  |     -    |  f Pi_G                
+          G   ||  c Pi_T  |  e Pi_C  |  f Pi_A  |     -                   
+	
+     where Pi_T, Pi_C, Pi_A, Pi_G are the stationary base frequencies.
+
+     The different models are specified using the commands listed below in blue 
+     (the names correspond to those used by <a href="http://darwin.uvigo.es/software/modeltest.html" target="_blank">Modeltest</a>):</li>
+
+       
+    +-----+----------------------------------+----------------------------------+
+    | <b> N </b> |    <b>Usage </b>                        |  <b>Notes  </b>                         |
+    +-----+----------------------------------+----------------------------------+
+    |  0  |  <font color=blue> [submodel] JC                </font>  |  a=b=c=d=e=f=1                   |
+    |  1  |  <font color=blue> [submodel] F81               </font>  |  a=b=c=d=e=f=1                   |
+    +-----+----------------------------------+----------------------------------+
+    |  2  |  <font color=blue> [submodel] K80    a          </font>  |  a=f=kappa, b=c=d=e=1            |
+    |  3  |  <font color=blue> [submodel] HKY    a          </font>  |  a=f=kappa, b=c=d=e=1            |
+    +-----+----------------------------------+----------------------------------+
+    |  4  |  <font color=blue> [submodel] TrNef  a f        </font>  |  a=kappa1, f=kappa2, b=c=d=e=1   |
+    |  5  |  <font color=blue> [submodel] TrN    a f       </font>   |  a=kappa1, f=kappa2, b=c=d=e=1   |
+    +-----+----------------------------------+----------------------------------+
+    |  6  |  <font color=blue> [submodel] K81    b c        </font>  |  b=e, c=d, a=f=1                 |
+    |  7  |  <font color=blue> [submodel] K81uf  a b c d e  </font>  |  b=e, c=d, a=f=1                 |
+    +-----+----------------------------------+----------------------------------+
+    |  8  |  <font color=blue> [submodel] TIMef  a b c      </font>  |  b=e, c=d, f=1                   |
+    |  9  |  <font color=blue> [submodel] TIM    a b c      </font>  |  b=e, c=d, f=1                   |
+    +-----+----------------------------------+----------------------------------+
+    |  10 |  <font color=blue> [submodel] TVMef  b c d e    </font>  |  a=f=1                           |
+    |  11 |  <font color=blue> [submodel] TVM    b c d e    </font>  |  a=f=1                           |
+    +-----+----------------------------------+----------------------------------+
+    |  12 |  <font color=blue> [submodel] SYM    a b c d e  </font>  |  f=1                             |
+    |  13 |  <font color=blue> [submodel] GTR    a b c d e  </font>  |  f=1                             |
+    +-----+----------------------------------+----------------------------------+
+    |  14 |  <font color=blue> [submodel] F84ef  k   </font>         |  b=c=d=e=1, a=(1+k/Y), f=(1+k/R) |
+    |  15 |  <font color=blue> [submodel] F84    k   </font>         |  b=c=d=e=1, a=(1+k/Y), f=(1+k/R) |
+    |     |                                  |  N.B. Y=pi_T+pi_C , R=pi_A+pi_G  | 
+    +-----+----------------------------------+--------------------------+-------+
+    |  16 |  <font color=blue> [submodel] UNREST TC TA TG CT CA CG AT AC AG GT GC</font>        |  GA=1 |
+    +-----+-------------------------------------------------------------+-------+
+
+    N.B. <i>N</i> can be substituted for the model name.  
+    e.g. <font color=blue>[submodel] 0</font> instead of <font color=blue>[submodel] JC</font> 
+
+     For the models with even N (0-16) the base frequencies are set automatically.
+
+     For models with odd N (1-15) the base frequencies are given using the command: 
+
+       <font color=blue>[statefreq] Pi_T Pi_C Pi_A Pi_G</font>
+*/ 
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/basic.shtml b/help/example_files/basic.shtml
new file mode 100644
index 0000000..f7e83f9
--- /dev/null
+++ b/help/example_files/basic.shtml
@@ -0,0 +1,46 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - basic.txt                                       //
+//                                                                                 //
+//      A basic introduction to the structure of the INDELible control file.       //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+// It is useful to know that anything on a line after two forward slashes is ignored.
+
+/*
+   Another useful thing to know is that anything after a forward slash and star
+   is ignored until INDELible sees a star followed by a forward slash later on.
+*/     
+
+<font color=red>[TYPE] NUCLEOTIDE 1</font>	//  EVERY control file must begin with a [TYPE] command.
+			//  The word can be NUCLEOTIDE, AMINOACID or CODON depending 
+			//  on what kind of simulation you want to do but must be in 
+			//  upper case. The number can be 1 or 2 and chooses the 
+			//  algorithm that INDELible uses (see manuscript). Both give 
+			//  identical results but in some cases one is quicker.
+			//  Other blocks and commands following this statement
+			//  can come in any order you like.
+
+<font color=red>[MODEL]    modelname</font>  	//  Evolutionary models are defined in [MODEL] blocks.
+<font color=red>[submodel] JC         </font>	//  Here the substitution model is simply set as JC69.
+                      	//  No indel model has been given so no indels will occur. 
+  
+<font color=red>[TREE] treename  (A:0.1,B:0.1);</font>        //  User trees are defined here
+
+<font color=red>[PARTITIONS] partitionname  </font>           //  [PARTITIONS] blocks say which models go with
+<font color=red>  [treename modelname 1000]</font>            //  which trees and define the length of the
+                                       //  sequence generated at the root (1000 here).
+
+<font color=red>[EVOLVE] partitionname 100 outputname</font>  //  This will generate 100 replicate datasets 
+                                       //  from the [PARTITIONS] block named above.
+
+// The true alignment will be output in a file named outputname_TRUE.phy
+// The unaligned sequences will be output in a file named outputname.fas
+
+</pre>
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/basicaminoacid.shtml b/help/example_files/basicaminoacid.shtml
new file mode 100644
index 0000000..74c0589
--- /dev/null
+++ b/help/example_files/basicaminoacid.shtml
@@ -0,0 +1,49 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - basicaminoacid.txt                              //
+//                                                                                 //
+//      A basic introduction to the structure of the INDELible control file.       //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+// It is useful to know that anything on a line after two forward slashes is ignored.
+
+/*
+   Another useful thing to know is that anything after a forward slash and star
+   is ignored until INDELible sees a star followed by a forward slash later on.
+*/     
+
+<font color=red>[TYPE] AMINOACID 2</font>	//  EVERY control file must begin with a [TYPE] command.
+			//  The number after "AMINOACID" can be 1 or 2 and chooses the 
+			//  algorithm that INDELible uses (see manuscript). Both give 
+			//  identical results but in some cases one is quicker.
+			//  Other blocks and commands following this statement
+			//  can come in any order you like.
+
+<font color=red>[MODEL]    modelname</font>         //  Evolutionary models are defined in [MODEL] blocks.
+<font color=red>  [submodel] WAG        </font>     //  Here the substitution model is simply set as WAG.
+<font color=red>  [indelmodel]  POW  1.7 500</font> //  Power law insertion/deletion length distribution (a=1.7)
+<font color=red>  [indelrate]   0.1 </font>         //  insertion rate = deletion rate = 0.1
+<font color=red>                     </font>        //  relative to average substitution rate of 1.   
+
+<font color=red>[TREE] treename  (A:0.1,B:0.1);</font>        //  User trees are defined here
+
+<font color=red>[PARTITIONS] partitionname  </font>           //  [PARTITIONS] blocks say which models go with
+<font color=red>  [treename modelname 1000]</font>            //  which trees and define the length of the
+                                       //  sequence generated at the root (1000 here).
+
+<font color=red>[EVOLVE] partitionname 100 outputname</font>  //  This will generate 100 replicate datasets 
+                                       //  from the [PARTITIONS] block named above.
+
+// The true alignment will be output in a file named outputname_TRUE.phy
+// The unaligned sequences will be output in a file named outputname.fas
+// To learn how to implement more complicated simulations (or different 
+// models) please consult the manual or the other example control files.
+
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/basiccodon.shtml b/help/example_files/basiccodon.shtml
new file mode 100644
index 0000000..3dae7ce
--- /dev/null
+++ b/help/example_files/basiccodon.shtml
@@ -0,0 +1,51 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - basiccodon.txt                                  //
+//                                                                                 //
+//      A basic introduction to the structure of the INDELible control file.       //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+// It is useful to know that anything on a line after two forward slashes is ignored.
+
+/*
+   Another useful thing to know is that anything after a forward slash and star
+   is ignored until INDELible sees a star followed by a forward slash later on.
+*/     
+
+<font color=red>[TYPE] CODON 1     </font>	//  EVERY control file must begin with a [TYPE] command.
+			//  The number after "CODON" can be 1 or 2 and chooses the 
+			//  algorithm that INDELible uses (see manuscript). Both give 
+			//  identical results but in some cases one is quicker.
+			//  Other blocks and commands following this statement
+			//  can come in any order you like.
+
+<font color=red>[MODEL]    modelname</font>          //  Evolutionary models are defined in [MODEL] blocks.
+<font color=red>  [submodel]     2.5  0.5   </font>  //  Substitution model is M0 with kappa=2.5, omega=0.5
+<font color=red>  [insertmodel]  POW  1.7 500</font> //  Power law insertion length distribution (a=1.7, M=500)
+<font color=red>  [deletemodel]  POW  1.8 500</font> //  Power law deletion length distribution (a=1.8, M=500)
+<font color=red>  [indelrate]    0.1 </font>         //  insertion rate = deletion rate = 0.1
+<font color=red>                     </font>         //  relative to average substitution rate of 1.   
+
+
+<font color=red>[TREE] treename  (A:0.1,B:0.1);</font>        //  User trees are defined here
+
+<font color=red>[PARTITIONS] partitionname  </font>           //  [PARTITIONS] blocks say which models go with
+<font color=red>  [treename modelname 1000]</font>            //  which trees and define the length of the
+                                       //  sequence generated at the root (1000 here).
+
+<font color=red>[EVOLVE] partitionname 100 outputname</font>  //  This will generate 100 replicate datasets 
+                                       //  from the [PARTITIONS] block named above.
+
+// The true alignment will be output in a file named outputname_TRUE.phy
+// The unaligned sequences will be output in a file named outputname.fas
+// To learn how to implement more complicated simulations (or different 
+// models) please consult the manual or the other example control files.
+
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/basicnucleotide.shtml b/help/example_files/basicnucleotide.shtml
new file mode 100644
index 0000000..daaf846
--- /dev/null
+++ b/help/example_files/basicnucleotide.shtml
@@ -0,0 +1,49 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - basicnucleotide.txt                             //
+//                                                                                 //
+//      A basic introduction to the structure of the INDELible control file.       //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+// It is useful to know that anything on a line after two forward slashes is ignored.
+
+/*
+   Another useful thing to know is that anything after a forward slash and star
+   is ignored until INDELible sees a star followed by a forward slash later on.
+*/     
+
+<font color=red>[TYPE] NUCLEOTIDE 1</font>	//  EVERY control file must begin with a [TYPE] command.
+			//  The number after "NUCLEOTIDE" can be 1 or 2 and chooses the 
+			//  algorithm that INDELible uses (see manuscript). Both give 
+			//  identical results but in some cases one is quicker.
+			//  Other blocks and commands following this statement
+			//  can come in any order you like.
+
+<font color=red>[MODEL]    modelname</font>        //  Evolutionary models are defined in [MODEL] blocks.
+<font color=red>  [submodel]     JC         </font>//  Here the substitution model is simply set as JC69.
+<font color=red>  [indelmodel]   NB  0.4 1</font>  //  Geometric indel length distribution (q=0.4, r=1)
+<font color=red>  [insertrate]   0.08 </font>      //  insertion rate = 0.08 relative to substitution rate of 1
+<font color=red>  [deleterate]   0.12       </font>//  deletion rate = 0.12 relative to substitution rate of 1
+  
+<font color=red>[TREE] treename  (A:0.1,B:0.1);</font>        //  User trees are defined here
+
+<font color=red>[PARTITIONS] partitionname  </font>           //  [PARTITIONS] blocks say which models go with
+<font color=red>  [treename modelname 1000]</font>            //  which trees and define the length of the
+                                       //  sequence generated at the root (1000 here).
+
+<font color=red>[EVOLVE] partitionname 100 outputname</font>  //  This will generate 100 replicate datasets 
+                                       //  from the [PARTITIONS] block named above.
+
+// The true alignment will be output in a file named outputname_TRUE.phy
+// The unaligned sequences will be output in a file named outputname.fas
+// To learn how to implement more complicated simulations (or different 
+// models) please consult the manual or the other example control files.
+
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/branch.shtml b/help/example_files/branch.shtml
new file mode 100644
index 0000000..08922cb
--- /dev/null
+++ b/help/example_files/branch.shtml
@@ -0,0 +1,74 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - branch.txt                                      //
+//                                                                                 //
+//      Using models that change across the tree to implement codon branch models  //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+<font color=red>[TYPE] CODON 1    </font>                //  codon simulation using algorithm from method 1
+
+
+<font color=red>[MODEL] mA    [submodel] 2.5 2.0</font>  //  M0 with kappa=2.5, omega=2.0
+<font color=red>[MODEL] mB    [submodel] 2.5 3.0</font>  //  M0 with kappa=2.5, omega=3.0
+<font color=red>[MODEL] mC    [submodel] 2.5 0.5</font>  //  M0 with kappa=2.5, omega=0.5
+<font color=red>[MODEL] mD    [submodel] 2.5 1.5</font>  //  M0 with kappa=2.5, omega=1.5
+<font color=red>[MODEL] mAB   [submodel] 2.5 2.5</font>  //  M0 with kappa=2.5, omega=2.5
+<font color=red>[MODEL] mCD   [submodel] 2.5 0.0</font>  //  M0 with kappa=2.5, omega=0.0
+<font color=red>[MODEL] mROOT [submodel] 2.5 1.0</font>  //  M0 with kappa=2.5, omega=1.0
+
+/*
+  In the same way that lengths of branches are listed after a <font color=blue>:</font> symbol in a [TREE]
+  block, model names on branches are listed after a <font color=blue>#</font> symbol in a [BRANCHES] block. 
+  N.B. The structure of the tree & order of taxa is the same (see notes at end of file).
+*/
+
+<font color=red>[TREE]     t1 ( (A:1.0, B:1.0):1.0,(C:1.0, D:1.0):1.0);  </font>
+
+<font color=red>[BRANCHES] b1 ( (A #mA, B#mB) #mAB,(C #mC, D #mD) #mCD)#mROOT;  </font>
+
+          
+  /* [BRANCHES] blocks are included in [PARTITIONS] blocks in the same way as models */
+
+<font color=red>[PARTITIONS] Pname  [t1 b1 1000]</font>    // tree t1, branchclass b1, root length 1000
+
+<font color=red>[EVOLVE]     Pname  10  outputname</font>  // 10 replicates generated from partition Pname
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+  It is important that the order of the taxa and structure of the tree remains
+  unchanged between [TREE] and [BRANCHES] blocks (like in this example) because
+  taxa names and branch lengths are ignored. <b>i.e. b1a, b1b, b1c are identical to b1.
+  but b2a, b2b and b2c are NOT even though the underlying trees are still "correct".</b>
+
+<font color=blue>
+  [BRANCHES] b1a ((A:1.0#mA,B:1.0#mB):1.0 #mAB, (C:1.0 #mC, D:1.0#mD):1.0 #mCD)#mROOT;
+
+  [BRANCHES] b1b ( (#mA, #mB) #mAB,(#mC,  #mD) #mCD)#mROOT;
+
+  [BRANCHES] b1c   </font>
+  <font color=blue>     (   </font>
+  <font color=blue>        (           </font>              // like [TREE] blocks, [BRANCHES] trees 
+  <font color=blue>          A #mA, B#mB     </font>        // can contain any amount of white space
+  <font color=blue>        ) #mAB            </font>        // or comments between the first ( and 
+  <font color=blue>      ,                    </font>       // the ; at the end.
+  <font color=blue>        (C #mC, D #mD)   </font>
+  <font color=blue>      #mCD)#mROOT;  </font>
+
+<font color=blue>
+  [BRANCHES] b2a ( (B #mB, A#mA) #mAB,(C #mC, D #mD) #mCD)#mROOT;  
+
+  [BRANCHES] b2b ( (C #mC, D #mD) #mCD, (A #mA, B#mB) #mAB)#mROOT;
+
+  [BRANCHES] b2c ( (#mA, #mB) #mAB,(#mD, #mC) #mCD)#mROOT;
+</font>
+*/
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/branch2.shtml b/help/example_files/branch2.shtml
new file mode 100644
index 0000000..444261c
--- /dev/null
+++ b/help/example_files/branch2.shtml
@@ -0,0 +1,100 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - branch2.txt                                     //
+//                                                                                 //
+//      Using models that change across the tree to implement codon branch models  //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* 
+     Any aspect of a codon model can change over different branches, including:
+     kappa, omega, stationary frequencies, indel rates and length distributions.
+     However, the number of site classes and the genetic code canNOT change.
+     The example below is arbitrary and not meant to be biologically realistic!
+  */
+
+<font color=red>[TYPE] CODON 1    </font>                //  codon simulation using algorithm from method 1
+
+<font color=red>[MODEL] mA    </font>
+<font color=red>  [submodel]    3.0 1.0</font>  // kappa=3.0, omega=1.0, frequencies equal, no insertions
+<font color=red>  [deletemodel] NB 0.2 4</font> // Pascal deletion length distribution (q=0.2, r=4)
+<font color=red>  [deleterate]  0.13   </font>  // rate of deletion compared to substitution rate of 1
+
+<font color=red>[MODEL] mB    </font>
+<font color=red>  [submodel]    1.0 3.0</font>       // kappa=1.0, omega=3.0, frequencies equal, no deletions
+<font color=red>  [insertmodel] POW 1.8 500</font>   // Power-Law insertion length distribution (a=1.8, M=500)
+<font color=red>  [insertrate]  0.08   </font>       // rate of insertion compared to substitution rate of 1
+
+<font color=red>[MODEL] mAB    </font>
+<font color=red>  [submodel]    2.0 2.0</font>  // kappa=2.0, omega=2.0, frequencies different, no indels
+<font color=red>  [statefreq]  </font>
+<font color=red>    0.016133 0.014626 0.012261 0.019123  </font>  //  TTT  TTC  TTA  TTG
+<font color=red>    0.008365 0.007583 0.006357 0.009915  </font>  //  TCT  TCC  TCA  TCG 
+<font color=red>    0.013290 0.012048 0        0         </font>  //  TAT  TAC  TAA  TAG
+<font color=red>    0.009947 0.009018 0        0.011790  </font>  //  TGT  TGC  TGA  TGG
+<font color=red>    0.019297 0.017494 0.014665 0.022873  </font>  //  CTT  CTC  CTA  CTG 
+<font color=red>    0.010005 0.009070 0.007604 0.011859  </font>  //  CCT  CCC  CCA  CCG 
+<font color=red>    0.015896 0.014410 0.012080 0.018841  </font>  //  CAT  CAC  CAA  CAG 
+<font color=red>    0.011898 0.010786 0.009042 0.014102  </font>  //  CGT  CGC  CGA  CGG 
+<font color=red>    0.030728 0.027857 0.023353 0.036422  </font>  //  ATT  ATC  ATA  ATG  
+<font color=red>    0.015932 0.014443 0.012108 0.018884  </font>  //  ACT  ACC  ACA  ACG  
+<font color=red>    0.025312 0.022947 0.019236 0.030002  </font>  //  AAT  AAC  AAA  AAG  
+<font color=red>    0.018945 0.017175 0.014398 0.022456  </font>  //  AGT  AGC  AGA  AGG 
+<font color=red>    0.024518 0.022227 0.018633 0.029061  </font>  //  GTT  GTC  GTA  GTG 
+<font color=red>    0.012712 0.011524 0.009661 0.015068  </font>  //  GCT  GCC  GCA  GCG  
+<font color=red>    0.020196 0.018309 0.015349 0.023938  </font>  //  GAT  GAC  GAA  GAG  
+<font color=red>    0.015117 0.013704 0.011488 0.017919  </font>  //  GGT  GGC  GGA  GGG
+               
+
+<font color=red>[MODEL] mC    </font>
+<font color=red>  [insertrate]  0.15   </font>      // rate of insertion compared to substitution rate of 1
+<font color=red>  [submodel]    2.5 0.5</font>      // kappa=2.5, omega=0.5, frequencies equal
+<font color=red>  [indelmodel]  POW 2.2 500</font>  // Power Law insertion AND deletion distribution (a=2.2)
+<font color=red>  [deleterate]  0.05   </font>      // rate of deletion compared to substitution rate of 1
+
+<font color=red>[MODEL] mD    </font>
+<font color=red>  [insertmodel] POW 1.9 500</font>  // Power-Law insertion length distribution (a=1.9, M=500)
+<font color=red>  [deletemodel] POW 1.7 600</font>  // Power-Law deletion length distribution (a=1.7, M=600)
+<font color=red>  [submodel]    2.5 1.5</font>      // kappa=2.5, omega=1.5, frequencies equal
+<font color=red>  [indelrate]   0.1   </font>       // rate of insertion AND deletion compared to 
+<font color=red>                      </font>       // substitution rate of 1
+
+<font color=red>[MODEL] mCD   </font>
+<font color=red>  [submodel]    2.5 1.0</font>      // kappa=2.5, omega=1.0, frequencies different, no indels
+<font color=red>  [insertmodel] POW 1.9 400</font>  // Power-Law insertion length distribution (a=1.9, M=400)
+<font color=red>  [insertrate]  0.03   </font>      // rate of insertion compared to substitution rate of 1
+<font color=red>  [deletemodel] POW 1.7 700</font>  // Power-Law deletion length distribution (a=1.7, M=700)
+<font color=red>  [deleterate]  0.17   </font>      // rate of deletion compared to substitution rate of 1
+
+<font color=red>[MODEL] mROOT   </font>         // Whichever model is defined in the root, that model is only
+<font color=red>  [submodel]    0.0 1.0</font>  // used in generation of the root sequence and setting
+<font color=red>                       </font>  // up the number of site classes across the tree.
+
+/*
+  In the same way that lengths of branches are listed after a <font color=blue>:</font> symbol in a [TREE]
+  block, model names on branches are listed after a <font color=blue>#</font> symbol in a [BRANCHES] block. 
+  N.B. The structure of the tree & order of taxa is the same (see notes at end of file).
+*/
+
+<font color=red>[TREE]     t1 ( (A:1.0, B:1.0):1.0,(C:1.0, D:1.0):1.0);  </font>
+
+<font color=red>[BRANCHES] b1 ( (A #mA, B#mB) #mAB,(C #mC, D #mD) #mCD)#mROOT;  </font>
+
+          
+  /* [BRANCHES] blocks are included in [PARTITIONS] blocks in the same way as models */
+
+<font color=red>[PARTITIONS] Pname  [t1 b1 1000]</font>    // tree t1, branchclass b1, root length 1000
+
+<font color=red>[EVOLVE]     Pname  10  outputname</font>  // 10 replicates generated from partition Pname
+
+/////////////////////////////////////////////////////////////////////////////////////
+/*
+    See extra relevant notes at the end of the file branch.txt <a href="http://abacus.gene.ucl.ac.uk/software/indelible/tutorial/branch.shtml">here</a>
+*/
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/codon_RATES.txt b/help/example_files/codon_RATES.txt
new file mode 100644
index 0000000..e590e78
--- /dev/null
+++ b/help/example_files/codon_RATES.txt
@@ -0,0 +1,715 @@
+Rates file : INDELible V1.00 				
+				
+  N.B. Site classes are numbered from lowest to highest values of omega.				
+       The omegas are not given explicitly as they are permitted to change on different				
+       branches whereas the site classes are not allowed to change.				
+				
+Site	Class	Insert?	Partition	
+1	3		1	
+2	0	Y	1	
+3	3	Y	1	
+4	2	Y	1	
+5	0	Y	1	
+6	0		1	
+7	1	Y	1	
+8	3	Y	1	
+9	1	Y	1	
+10	2	Y	1	
+11	3	Y	1	
+12	1	Y	1	
+13	1	Y	1	
+14	3	Y	1	
+15	0	Y	1	
+16	2	Y	1	
+17	0		1	
+18	3	Y	1	
+19	3	Y	1	
+20	3	Y	1	
+21	3		1	
+22	3	Y	1	
+23	2		1	
+24	2	Y	1	
+25	2		1	
+26	3	Y	1	
+27	0	Y	1	
+28	0		1	
+29	0		1	
+30	0		1	
+31	0	Y	1	
+32	0	Y	1	
+33	3	Y	1	
+34	3		1	
+35	3	Y	1	
+36	3		1	
+37	1	Y	1	
+38	3	Y	1	
+39	3	Y	1	
+40	2		1	
+41	2	Y	1	
+42	0	Y	1	
+43	3	Y	1	
+44	2	Y	1	
+45	2		1	
+46	2	Y	1	
+47	1	Y	1	
+48	1		1	
+49	0	Y	1	
+50	0		1	
+51	0		1	
+52	1	Y	1	
+53	0	Y	1	
+54	1	Y	1	
+55	3	Y	1	
+56	1	Y	1	
+57	0	Y	1	
+58	3	Y	1	
+59	2	Y	1	
+60	1	Y	1	
+61	2	Y	1	
+62	3	Y	1	
+63	2	Y	1	
+64	2	Y	1	
+65	3	Y	1	
+66	0	Y	1	
+67	2	Y	1	
+68	1	Y	1	
+69	0	Y	1	
+70	3	Y	1	
+71	1	Y	1	
+72	0	Y	1	
+73	3	Y	1	
+74	3	Y	1	
+75	3	Y	1	
+76	2	Y	1	
+77	0	Y	1	
+78	2	Y	1	
+79	3		1	
+80	2		1	
+81	3		1	
+82	2	Y	1	
+83	0	Y	1	
+84	1	Y	1	
+85	2	Y	1	
+86	0	Y	1	
+87	1	Y	1	
+88	2	Y	1	
+89	2	Y	1	
+90	2	Y	1	
+91	1		1	
+92	1		1	
+93	3	Y	1	
+94	2		1	
+95	3		1	
+96	1	Y	1	
+97	2		1	
+98	0	Y	1	
+99	3		1	
+100	3	Y	1	
+101	0	Y	1	
+102	3	Y	1	
+103	0	Y	1	
+104	2		1	
+105	0	Y	1	
+106	2		1	
+107	3	Y	1	
+108	0	Y	1	
+109	3		1	
+110	2	Y	1	
+111	2	Y	1	
+112	2	Y	1	
+113	2	Y	1	
+114	3	Y	1	
+115	3	Y	1	
+116	3	Y	1	
+117	3	Y	1	
+118	3		1	
+119	1		1	
+120	3		1	
+121	1		1	
+122	2	Y	1	
+123	2		1	
+124	1	Y	1	
+125	0		1	
+126	3		1	
+127	3		1	
+128	2	Y	1	
+129	2	Y	1	
+130	1	Y	1	
+131	0		1	
+132	0		1	
+133	2		1	
+134	1		1	
+135	3		1	
+136	1		1	
+137	2		1	
+138	3		1	
+139	0		1	
+140	3		1	
+141	2		1	
+142	3		1	
+143	3	Y	1	
+144	3	Y	1	
+145	2		1	
+146	2	Y	1	
+147	2	Y	1	
+148	3	Y	1	
+149	2	Y	1	
+150	3	Y	1	
+151	3		1	
+152	2		1	
+153	1		1	
+154	0		1	
+155	1		1	
+156	0		1	
+157	1	Y	1	
+158	3	Y	1	
+159	3	Y	1	
+160	2	Y	1	
+161	3	Y	1	
+162	1	Y	1	
+163	3	Y	1	
+164	3	Y	1	
+165	2	Y	1	
+166	3	Y	1	
+167	1		1	
+168	0	Y	1	
+169	0	Y	1	
+170	2		1	
+171	3	Y	1	
+172	3		1	
+173	2	Y	1	
+174	2		1	
+175	0	Y	1	
+176	3	Y	1	
+177	1	Y	1	
+178	3		1	
+179	3		1	
+180	0	Y	1	
+181	2		1	
+182	3		1	
+183	2		1	
+184	2	Y	1	
+185	2		1	
+186	3		1	
+187	2		1	
+188	3	Y	1	
+189	3	Y	1	
+190	0		1	
+191	3		1	
+192	0	Y	1	
+193	2		1	
+194	1		1	
+195	0	Y	1	
+196	0		1	
+197	0		1	
+198	2		1	
+199	0		1	
+200	0		1	
+201	0		1	
+202	0	Y	1	
+203	3	Y	1	
+204	0	Y	1	
+205	0		1	
+206	0		1	
+207	2		1	
+208	3		1	
+209	3	Y	1	
+210	3	Y	1	
+211	2	Y	1	
+212	2		1	
+213	0		1	
+214	2	Y	1	
+215	0	Y	1	
+216	2	Y	1	
+217	1	Y	1	
+218	3	Y	1	
+219	3	Y	1	
+220	1	Y	1	
+221	3	Y	1	
+222	3	Y	1	
+223	0	Y	1	
+224	0	Y	1	
+225	2	Y	1	
+226	0	Y	1	
+227	2	Y	1	
+228	0	Y	1	
+229	3	Y	1	
+230	1	Y	1	
+231	3	Y	1	
+232	3	Y	1	
+233	1	Y	1	
+234	2	Y	1	
+235	2	Y	1	
+236	1	Y	1	
+237	3	Y	1	
+238	2	Y	1	
+239	3	Y	1	
+240	1	Y	1	
+241	0	Y	1	
+242	1	Y	1	
+243	2	Y	1	
+244	0	Y	1	
+245	3		1	
+246	0		1	
+247	3	Y	1	
+248	2	Y	1	
+249	1		1	
+250	3		1	
+251	3	Y	1	
+252	0	Y	1	
+253	2	Y	1	
+254	3	Y	1	
+255	0	Y	1	
+256	1	Y	1	
+257	2	Y	1	
+258	2	Y	1	
+259	0	Y	1	
+260	3	Y	1	
+261	2	Y	1	
+262	1		1	
+263	3	Y	1	
+264	3	Y	1	
+265	1	Y	1	
+266	1	Y	1	
+267	2	Y	1	
+268	1		1	
+269	0		1	
+270	2		1	
+271	3		1	
+272	3	Y	1	
+273	3		1	
+274	1		1	
+275	2		1	
+276	2		1	
+277	3	Y	1	
+278	0		1	
+279	3		1	
+280	3		1	
+281	2	Y	1	
+282	3		1	
+283	0		2	
+284	1	Y	2	
+285	2	Y	2	
+286	3		2	
+287	3		2	
+288	0		2	
+289	3	Y	2	
+290	2	Y	2	
+291	2	Y	2	
+292	2		2	
+293	3	Y	2	
+294	0	Y	2	
+295	2	Y	2	
+296	2	Y	2	
+297	2	Y	2	
+298	3	Y	2	
+299	0	Y	2	
+300	0		2	
+301	0		2	
+302	2	Y	2	
+303	2	Y	2	
+304	0	Y	2	
+305	0		2	
+306	3	Y	2	
+307	0	Y	2	
+308	3		2	
+309	1	Y	2	
+310	3		2	
+311	3	Y	2	
+312	2	Y	2	
+313	3	Y	2	
+314	3		2	
+315	0		2	
+316	2	Y	2	
+317	3	Y	2	
+318	3	Y	2	
+319	0	Y	2	
+320	2		2	
+321	0	Y	2	
+322	2	Y	2	
+323	1	Y	2	
+324	1	Y	2	
+325	2	Y	2	
+326	3	Y	2	
+327	2	Y	2	
+328	2	Y	2	
+329	3	Y	2	
+330	1	Y	2	
+331	1	Y	2	
+332	3	Y	2	
+333	1	Y	2	
+334	0	Y	2	
+335	2	Y	2	
+336	2	Y	2	
+337	0	Y	2	
+338	0	Y	2	
+339	2	Y	2	
+340	0	Y	2	
+341	3	Y	2	
+342	0	Y	2	
+343	2	Y	2	
+344	1	Y	2	
+345	3	Y	2	
+346	2	Y	2	
+347	1	Y	2	
+348	2	Y	2	
+349	2	Y	2	
+350	3	Y	2	
+351	2		2	
+352	2	Y	2	
+353	0	Y	2	
+354	2	Y	2	
+355	2	Y	2	
+356	3	Y	2	
+357	1	Y	2	
+358	2	Y	2	
+359	1	Y	2	
+360	3	Y	2	
+361	2		2	
+362	3	Y	2	
+363	1	Y	2	
+364	0	Y	2	
+365	2	Y	2	
+366	3	Y	2	
+367	1		2	
+368	2	Y	2	
+369	2		2	
+370	3	Y	2	
+371	0	Y	2	
+372	2		2	
+373	0	Y	2	
+374	2	Y	2	
+375	1	Y	2	
+376	3	Y	2	
+377	1	Y	2	
+378	2	Y	2	
+379	0	Y	2	
+380	2	Y	2	
+381	0		2	
+382	0		2	
+383	1		2	
+384	3		2	
+385	2		2	
+386	2	Y	2	
+387	3	Y	2	
+388	2		2	
+389	1	Y	2	
+390	2		2	
+391	2	Y	2	
+392	0		2	
+393	2	Y	2	
+394	2		2	
+395	0	Y	2	
+396	0	Y	2	
+397	2	Y	2	
+398	3	Y	2	
+399	2	Y	2	
+400	2	Y	2	
+401	0		2	
+402	1	Y	2	
+403	1	Y	2	
+404	2	Y	2	
+405	3	Y	2	
+406	2	Y	2	
+407	3	Y	2	
+408	2	Y	2	
+409	3	Y	2	
+410	2	Y	2	
+411	1	Y	2	
+412	1	Y	2	
+413	0	Y	2	
+414	3	Y	2	
+415	2	Y	2	
+416	1	Y	2	
+417	1		2	
+418	3	Y	2	
+419	2		2	
+420	0	Y	2	
+421	3	Y	2	
+422	3	Y	2	
+423	1		2	
+424	3	Y	2	
+425	1		2	
+426	2	Y	2	
+427	1	Y	2	
+428	1		2	
+429	3	Y	2	
+430	0	Y	2	
+431	0		2	
+432	0	Y	2	
+433	1	Y	2	
+434	3	Y	2	
+435	0	Y	2	
+436	2	Y	2	
+437	3		2	
+438	2		2	
+439	1	Y	2	
+440	0	Y	2	
+441	0	Y	2	
+442	2	Y	2	
+443	1	Y	2	
+444	2	Y	2	
+445	3	Y	2	
+446	2	Y	2	
+447	3	Y	2	
+448	1	Y	2	
+449	0	Y	2	
+450	3	Y	2	
+451	3	Y	2	
+452	3	Y	2	
+453	2	Y	2	
+454	0	Y	2	
+455	2	Y	2	
+456	3	Y	2	
+457	3	Y	2	
+458	1	Y	2	
+459	0	Y	2	
+460	1		2	
+461	3	Y	2	
+462	0	Y	2	
+463	2	Y	2	
+464	1	Y	2	
+465	0	Y	2	
+466	3	Y	2	
+467	3	Y	2	
+468	0	Y	2	
+469	2	Y	2	
+470	2		2	
+471	3	Y	2	
+472	3		2	
+473	2	Y	2	
+474	0		2	
+475	1	Y	2	
+476	1	Y	2	
+477	2		2	
+478	3	Y	2	
+479	1		2	
+480	0	Y	2	
+481	0	Y	2	
+482	3	Y	2	
+483	0		2	
+484	2	Y	2	
+485	3	Y	2	
+486	1	Y	2	
+487	1		2	
+488	3	Y	2	
+489	1	Y	2	
+490	0	Y	2	
+491	2	Y	2	
+492	0	Y	2	
+493	1	Y	2	
+494	0	Y	2	
+495	2	Y	2	
+496	3	Y	2	
+497	3	Y	2	
+498	3	Y	2	
+499	3	Y	2	
+500	1	Y	2	
+501	3	Y	2	
+502	1	Y	2	
+503	0	Y	2	
+504	2	Y	2	
+505	2	Y	2	
+506	3	Y	2	
+507	0	Y	2	
+508	0	Y	2	
+509	0	Y	2	
+510	0	Y	2	
+511	1	Y	2	
+512	2	Y	2	
+513	1	Y	2	
+514	0	Y	2	
+515	3	Y	2	
+516	0	Y	2	
+517	3	Y	2	
+518	2	Y	2	
+519	0	Y	2	
+520	2	Y	2	
+521	0	Y	2	
+522	0	Y	2	
+523	1	Y	2	
+524	1	Y	2	
+525	3	Y	2	
+526	3	Y	2	
+527	3	Y	2	
+528	2	Y	2	
+529	3	Y	2	
+530	3	Y	2	
+531	3	Y	2	
+532	3	Y	2	
+533	3	Y	2	
+534	2	Y	2	
+535	1	Y	2	
+536	0		2	
+537	0	Y	2	
+538	1	Y	2	
+539	0	Y	2	
+540	3	Y	2	
+541	3	Y	2	
+542	2	Y	2	
+543	0	Y	2	
+544	1	Y	2	
+545	3	Y	2	
+546	2	Y	2	
+547	2	Y	2	
+548	1	Y	2	
+549	3	Y	2	
+550	3	Y	2	
+551	0	Y	2	
+552	3		2	
+553	3	Y	2	
+554	2		2	
+555	0		2	
+556	2	Y	2	
+557	3	Y	2	
+558	3	Y	2	
+559	3	Y	2	
+560	1	Y	2	
+561	0	Y	2	
+562	1		2	
+563	3		2	
+564	2	Y	2	
+565	3	Y	2	
+566	1	Y	2	
+567	0	Y	2	
+568	3	Y	2	
+569	3	Y	2	
+570	2	Y	2	
+571	3		2	
+572	2		2	
+573	2		2	
+574	3		2	
+575	3	Y	2	
+576	2		2	
+577	2		2	
+578	3		2	
+579	0		2	
+580	3		2	
+581	2		2	
+582	3	Y	2	
+583	2	Y	2	
+584	2		2	
+585	0	Y	2	
+586	3	Y	2	
+587	3		2	
+588	3	Y	2	
+589	1		2	
+590	3		2	
+591	2	Y	2	
+592	2	Y	2	
+593	3	Y	2	
+594	0	Y	2	
+595	2	Y	2	
+596	3	Y	2	
+597	2	Y	2	
+598	1	Y	2	
+599	2		2	
+600	3		2	
+601	2	Y	2	
+602	2	Y	2	
+603	1		2	
+604	0	Y	2	
+605	3		2	
+606	3		2	
+607	2	Y	2	
+608	1	Y	2	
+609	0	Y	2	
+610	1	Y	2	
+611	0	Y	2	
+612	1	Y	2	
+613	1	Y	2	
+614	2	Y	2	
+615	0	Y	2	
+616	2	Y	2	
+617	0	Y	2	
+618	2	Y	2	
+619	0		2	
+620	2	Y	2	
+621	1	Y	2	
+622	2	Y	2	
+623	2		2	
+624	1	Y	2	
+625	2	Y	2	
+626	2		2	
+627	0	Y	2	
+628	2	Y	2	
+629	3		2	
+630	1		2	
+631	2	Y	2	
+632	3	Y	2	
+633	1		2	
+634	2	Y	2	
+635	2	Y	2	
+636	3	Y	2	
+637	0	Y	2	
+638	1	Y	2	
+639	3	Y	2	
+640	0	Y	2	
+641	0	Y	2	
+642	3	Y	2	
+643	3	Y	2	
+644	0	Y	2	
+645	3		2	
+646	2	Y	2	
+647	0	Y	2	
+648	3	Y	2	
+649	3	Y	2	
+650	1	Y	2	
+651	3	Y	2	
+652	2	Y	2	
+653	2		2	
+654	3		2	
+655	1		2	
+656	2		2	
+657	1	Y	2	
+658	0	Y	2	
+659	3	Y	2	
+660	3	Y	2	
+661	0	Y	2	
+662	1	Y	2	
+663	2	Y	2	
+664	3		2	
+665	0		2	
+666	0		2	
+667	0		2	
+668	3		2	
+669	3	Y	2	
+670	2	Y	2	
+671	0	Y	2	
+672	3	Y	2	
+673	1	Y	2	
+674	3	Y	2	
+675	1		2	
+676	0	Y	2	
+677	2		2	
+678	0		2	
+679	3	Y	2	
+680	2	Y	2	
+681	3	Y	2	
+682	2	Y	2	
+683	1	Y	2	
+684	1		2	
+685	3		2	
+686	1	Y	2	
+687	1		2	
+688	2		2	
+689	0	Y	2	
+690	0	Y	2	
+691	3	Y	2	
+692	3		2	
+693	0		2	
+694	1		2	
+695	3		2	
+696	2	Y	2	
+697	3		2	
+698	3	Y	2	
+699	1	Y	2	
+700	0		2	
+701	1	Y	2	
+702	1		2	
+703	3	Y	2	
+704	3	Y	2	
+705	0		2	
+706	0	Y	2	
+707	3	Y	2	
+708	0	Y	2	
diff --git a/help/example_files/indels.shtml b/help/example_files/indels.shtml
new file mode 100644
index 0000000..d6c0f56
--- /dev/null
+++ b/help/example_files/indels.shtml
@@ -0,0 +1,117 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - indels.txt                                      //
+//                                                                                 //
+//      Adding indels to a nucleotide, amino-acid or codon substitution model      //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+
+<font color=red>[TYPE] AMINOACID 2</font>            //  amino-acid simulation using algorithm from method 2
+
+
+<font color=red>[MODEL] mymodel1  </font>            // this is identical to mymodel2
+<font color=red>  [submodel]     WAG </font>         
+<font color=red>  [insertmodel]  POW 1.7 500</font>  // Power law insertion length distribution (a=1.7, M=500)
+<font color=red>  [deletemodel]  POW 1.7 500</font>  // Power law deletion length distribution (a=1.7, M=500)
+<font color=red>  [insertrate]   0.1 </font>         // insertion rate = 0.1 relative to substitution rate of 1
+<font color=red>  [deleterate]   0.1 </font>         // deletion rate = 0.1 relative to substitution rate of 1
+
+
+<font color=red>[MODEL] mymodel2  </font>            // this is identical to mymodel1
+<font color=red>  [submodel]     WAG </font>         
+<font color=red>  [indelmodel]   POW  1.7 500</font> // Power law insertion/deletion length distribution (a=1.7)
+<font color=red>  [indelrate]    0.1 </font>         // insertion rate = deletion rate = 0.1
+<font color=red>                     </font>         // relative to average substitution rate of 1.   
+ 				
+					
+<font color=red>[MODEL] mymodel3  </font>            // insertion/deletion lengths and rates can be different.
+<font color=red>  [submodel]     WAG </font>         
+<font color=red>  [insertmodel]  NB  0.2 4</font>    // Pascal insertion length distribution (q=0.2, r=4)
+<font color=red>  [deletemodel]  LAV 1.8 500</font>  // Lavalette deletion length distribution (a=1.8, M=500)
+<font color=red>  [insertrate]   0.1 </font>         // insertion rate = 0.1 relative to substitution rate of 1
+<font color=red>  [deleterate]   0.2 </font>         // deletion rate = 0.2 relative to substitution rate of 1
+			
+						
+<font color=red>[MODEL] mymodel4  </font>            // insertion/deletion lengths and rates can be different.
+<font color=red>  [submodel]     JTT </font>         
+<font color=red>  [insertmodel]  NB  0.4 1</font>    // Geometric insertion length distribution (q=0.4, r=1)
+<font color=red>  [insertrate]   0.1 </font>         // insertion rate = 0.1 relative to substitution rate of 1
+<font color=red>                     </font>         // deletion rate = 0 relative to substitution rate of 1
+
+
+
+<font color=red>[TREE] t1  (A:0.1,B:0.1);</font>             
+
+
+<font color=red>[PARTITIONS] Pname1 [t1 mymodel1 1000]</font> // tree t1, model mymodel1, root length 1000
+<font color=red>[PARTITIONS] Pname2 [t1 mymodel2 1000]</font> // tree t1, model mymodel2, root length 1000
+<font color=red>[PARTITIONS] Pname3 [t1 mymodel3 1000]</font> // tree t1, model mymodel3, root length 1000
+<font color=red>[PARTITIONS] Pname4 [t1 mymodel4 1000]</font> // tree t1, model mymodel4, root length 1000
+
+<font color=red>[EVOLVE]     Pname1 10 outputname1</font>     // 10 replicates generated from partition Pname1
+<font color=red>             Pname2 10 outputname2</font>     // 10 replicates generated from partition Pname2
+<font color=red>             Pname3 10 outputname3</font>     // 10 replicates generated from partition Pname3
+<font color=red>             Pname4 10 outputname4</font>     // 10 replicates generated from partition Pname4
+
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+   New commands that are relevant to insertions and deletions (indels) are:
+
+   <font color="blue">[insertrate]</font> 
+   Sets the rate of insertion relative to an average substitution rate of 1.
+   
+   <font color="blue">[deleterate]</font> 
+   Sets the rate of insertion relative to an average substitution rate of 1.
+   
+   <font color="blue">[indelrate]</font> 
+   Sets the rate of insertion AND deletion to be equal. It is equivalent 
+   to specifying <font color="blue">[insertrate]</font> and <font color="blue">[deleterate]</font> to have the same value.
+   
+   If <font color="blue">[insertrate]</font> & <font color="blue">[indelrate]</font> are not specified then rate of insertion is zero.
+   If <font color="blue">[deleterate]</font> & <font color="blue">[indelrate]</font> are not specified then rate of deletion is zero.
+
+   <font color="blue">[insertmodel]</font>
+   Works the same as <font color="blue">[indelmodel]</font> but only sets the insertion length distribution.
+
+   <font color="blue">[deletemodel]</font>
+   Works the same as <font color="blue">[indelmodel]</font> but only sets the deletion length distribution.
+
+   <font color="blue">[indelmodel]</font>
+   This sets the insertion and deletion length distributions at the same time. 
+   It is equivalent to specifying the commands <font color="blue">[insertmodel]</font> and <font color="blue">[deletemodel]</font> 
+   to have the same value.  Options for this command are:
+   
+   (1)  <font color="blue">[indelmodel]  NB   q  r</font>               //  Negative Binomial Distribution
+   (2a) <font color="blue">[indelmodel]  POW  a</font>                  //  Zipfian Distribution 
+   (2b) <font color="blue">[indelmodel]  POW  a  M</font>               //  Zipfian Distribution 
+   (3)  <font color="blue">[indelmodel]  LAV  a  M</font>               //  Lavalette Distribution
+   (4)  <font color="blue">[indelmodel]  USER mylengthmodel.txt</font>  //  User-Defined Distribution
+
+   (1)  This specifies a Pascal (negative binomial) distribution where <font color="blue">q</font> is a 
+        decimal (<font color="blue">0<=q<=1</font>) and <font color="blue">r</font> is an integer (<font color="blue">r>0</font>).
+
+   (2a) This specifies a Zipfian (power law) distribution where <font color="blue">a</font> is a decimal (<font color="blue">a>1</font>).
+
+   (2b) This also specifies a Zipfian distribution where <font color="blue">a</font> is a decimal (<font color="blue">a>1</font>).
+        However with this format indels longer than length <font color="blue">M</font> are not permitted.
+        This format is highly recommended for small values of <font color="blue">a</font> because 
+        of the fat-tailed shape of the resulting distribution.
+
+   (3)  This specifies a Lavalette distribution where <font color="blue">a</font> is a decimal (<font color="blue">a>1</font>) and <font color="blue">M</font> is 
+        an integer (<font color="blue">M>1</font>) representing the maximum indel length.
+
+   (4)  This specifies a user-defined indel length model. The file <font color="blue">mylengthmodel.txt</font> 
+        should be in the same directory as the INDELible executable and contain a 
+        list of relative frequencies (in order of increasing indel length) 
+        separated by white space, like <a href="http://abacus.gene.ucl.ac.uk/software/indelible/tutorial/mylengthmodel.txt" target="_blank">this</a>.
+*/
+</pre>
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/multi-partitions.shtml b/help/example_files/multi-partitions.shtml
new file mode 100644
index 0000000..d262d7b
--- /dev/null
+++ b/help/example_files/multi-partitions.shtml
@@ -0,0 +1,78 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - multi-partitions.txt                            //
+//                                                                                 //
+//      Generating multi-partitioned datasets                                      //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+
+<font color=red>[TYPE] NUCLEOTIDE 1    </font>          // nucleotide simulation using algorithm from method 1
+
+  /*
+    Generating multi-partitioned datasets is achieved by simply adding more [..] 
+    statements to [PARTITIONS] blocks (see below).  Each partition may contain
+    a different [MODEL] or [BRANCHES] block, may have a different length, and may
+    use a different tree.  The only restriction is that random trees cannot be used 
+    in the same partition as [BRANCHES] blocks and the different trees must all
+    have the same number of taxa (with the same taxa names).
+  */
+
+
+<font color=red>[PARTITIONS] Pname1  </font>               // this block only contains a single partition
+<font color=red>  [t1 b1 1000]</font>                      // tree t1, branchclass b1, root length 1000
+
+<font color=red>[PARTITIONS] Pname2  </font>               // this block contains multiple partitions
+<font color=red>  [t2 m1 100]</font>                       // tree t2, model m1, root length 100
+<font color=red>  [t1 b1 500]</font>                       // tree t1, branchclass b1, root length 500
+<font color=red>  [t3 m2 200]</font>                       // tree t3, model m2, root length 200
+<font color=red>  [t4 m3 350]</font>                       // tree t4, model m3, root length 350
+<font color=red>             </font>                       // total root length = 1150
+
+// Models
+
+<font color=red>[MODEL] m1    </font>                   // no insertions, no gamma
+<font color=red>  [submodel]    HKY 2.5</font>          // HKY with kappa=2.5
+<font color=red>  [statefreq]   0.1 0.2 0.3 0.4</font>  // frequencies for T C A G
+<font color=red>  [deletemodel] NB 0.2 4</font>         // Pascal deletion distribution (q=0.2, r=4)
+<font color=red>  [deleterate]  0.13   </font>          // rate of deletion (substitution rate = 1)
+
+
+<font color=red>[MODEL] m2    </font>                   // no deletions, no gamma
+<font color=red>  [submodel]    HKY 5.0</font>          // HKY with kappa=5.0
+<font color=red>  [statefreq]   0.4 0.3 0.2 0.1</font>  // frequencies for T C A G
+<font color=red>  [insertmodel] POW 1.8 500</font>      // Power-Law insertion distribution (a=1.8, M=500)
+<font color=red>  [insertrate]  0.08   </font>          // rate of insertion (substitution rate = 1)
+
+<font color=red>[MODEL] m3    </font>                        //  no indels, continuous gamma
+<font color=red>  [submodel]  GTR 0.2 0.4 0.6 0.8 1.2</font> //  GTR: a=0.2, b=0.4, c=0.6, d=0.8, e=1.2, f=1
+<font color=red>  [statefreq] 0.2 0.1 0.4 0.3        </font> //  frequencies for T C A G
+<font color=red>  [rates]     0   1.0 0              </font> //  continuous gamma with alpha = 1.0
+              
+<font color=red>[TREE]     t1 ( (1:1.0, 2:1.0):1.0,(3:1.0, 4:1.0):1.0);  </font>
+
+<font color=red>[BRANCHES] b1 ( (1 #m1, 2#m2) #m3,(3 #m3, 4 #m2) #m1)#m1;  </font>
+
+<font color=red>[TREE]     t2 ( (1:0.3, 2:2.0):0.5,(3:0.4, 4:1.0):0.1);  </font>
+
+<font color=red>[TREE]     t3 ( (3:0.3, 2:2.0):0.5,(1:0.4, 4:1.0):0.1);  </font>
+
+<font color=red>[TREE]     t4 [unrooted] 4 2.4 1.1 0.2566 0.34  </font>// ntaxa birth death sample mut
+
+<font color=red>[EVOLVE]     </font>
+<font color=red>  Pname1  10  outputname1</font>           // 10 replicates generated from partition Pname1
+<font color=red>  Pname2  10  outputname2</font>           // 10 replicates generated from partition Pname2
+
+//////////////////////////////////////////////////////////////////////////////////////
+
+/*
+    See extra relevant notes at the end of the file branch.txt <a href="http://abacus.gene.ucl.ac.uk/software/indelible/tutorial/branch.shtml">here</a>
+*/
+</pre>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/mylengthmodel.txt b/help/example_files/mylengthmodel.txt
new file mode 100644
index 0000000..00b28f9
--- /dev/null
+++ b/help/example_files/mylengthmodel.txt
@@ -0,0 +1,1000 @@
+0.673643922711
+0.146287925004
+0.059820608527
+0.031697700931
+0.019358287305
+0.012933272346
+0.009193158625
+0.006837868923
+0.005265293128
+0.004166701951
+0.003371040086
+0.002777560301
+0.002323915321
+0.001969910312
+0.001688724636
+0.001461928529
+0.001276532822
+0.001123178093
+0.00099498778
+0.000886821517
+0.000794777043
+0.000715850644
+0.000647701104
+0.000588482706
+0.000536725187
+0.000491246179
+0.00045108649
+0.000415461683
+0.000383725432
+0.000355341508
+0.00032986215
+0.000306911211
+0.00028617093
+0.000267371444
+0.000250282438
+0.000234706428
+0.000220473338
+0.000207436089
+0.000195466987
+0.00018445476
+0.000174302102
+0.000164923633
+0.000156244203
+0.000148197464
+0.000140724667
+0.000133773652
+0.000127297986
+0.000121256228
+0.000115611306
+0.000110329976
+0.000105382365
+0.000100741568
+0.000096383307
+0.000092285629
+0.000088428647
+0.000084794311
+0.000081366213
+0.000078129408
+0.000075070266
+0.000072176334
+0.000069436215
+0.000066839468
+0.00006437651
+0.000062038538
+0.000059817448
+0.000057705776
+0.000055696635
+0.000053783666
+0.000051960988
+0.000050223157
+0.000048565126
+0.000046982214
+0.000045470073
+0.000044024662
+0.000042642218
+0.000041319238
+0.000040052455
+0.000038838819
+0.000037675482
+0.000036559783
+0.00003548923
+0.00003446149
+0.000033474376
+0.000032525839
+0.000031613953
+0.00003073691
+0.000029893012
+0.000029080658
+0.000028298344
+0.000027544653
+0.000026818248
+0.000026117868
+0.000025442324
+0.000024790492
+0.000024161311
+0.000023553777
+0.00002296694
+0.0000223999
+0.000021851807
+0.000021321853
+0.000020809272
+0.00002031334
+0.000019833367
+0.000019368698
+0.000018918712
+0.000018482817
+0.000018060452
+0.000017651082
+0.000017254198
+0.000016869315
+0.00001649597
+0.000016133724
+0.000015782156
+0.000015440867
+0.000015109474
+0.000014787611
+0.00001447493
+0.000014171099
+0.000013875798
+0.000013588723
+0.000013309583
+0.0000130381
+0.000012774005
+0.000012517044
+0.000012266973
+0.000012023556
+0.000011786568
+0.000011555794
+0.000011331028
+0.00001111207
+0.00001089873
+0.000010690826
+0.000010488181
+0.000010290627
+0.000010098002
+0.00000991015
+0.000009726921
+0.00000954817
+0.00000937376
+0.000009203556
+0.00000903743
+0.000008875258
+0.000008716922
+0.000008562306
+0.000008411299
+0.000008263796
+0.000008119692
+0.00000797889
+0.000007841294
+0.00000770681
+0.000007575351
+0.00000744683
+0.000007321164
+0.000007198273
+0.00000707808
+0.00000696051
+0.00000684549
+0.000006732951
+0.000006622826
+0.000006515048
+0.000006409555
+0.000006306286
+0.000006205182
+0.000006106185
+0.00000600924
+0.000005914293
+0.000005821293
+0.000005730189
+0.000005640933
+0.000005553478
+0.000005467777
+0.000005383786
+0.000005301463
+0.000005220765
+0.000005141653
+0.000005064088
+0.00000498803
+0.000004913444
+0.000004840294
+0.000004768544
+0.000004698162
+0.000004629115
+0.00000456137
+0.000004494897
+0.000004429666
+0.000004365647
+0.000004302814
+0.000004241137
+0.000004180591
+0.000004121149
+0.000004062787
+0.000004005479
+0.000003949202
+0.000003893932
+0.000003839647
+0.000003786326
+0.000003733946
+0.000003682487
+0.000003631928
+0.00000358225
+0.000003533434
+0.000003485462
+0.000003438314
+0.000003391973
+0.000003346422
+0.000003301644
+0.000003257622
+0.000003214342
+0.000003171787
+0.000003129941
+0.000003088792
+0.000003048322
+0.00000300852
+0.000002969371
+0.000002930862
+0.00000289298
+0.000002855711
+0.000002819045
+0.000002782968
+0.000002747469
+0.000002712536
+0.000002678158
+0.000002644325
+0.000002611025
+0.000002578248
+0.000002545983
+0.000002514222
+0.000002482954
+0.000002452169
+0.000002421859
+0.000002392014
+0.000002362625
+0.000002333684
+0.000002305182
+0.000002277112
+0.000002249465
+0.000002222232
+0.000002195407
+0.000002168982
+0.000002142949
+0.000002117302
+0.000002092033
+0.000002067135
+0.000002042602
+0.000002018427
+0.000001994603
+0.000001971125
+0.000001947985
+0.000001925179
+0.0000019027
+0.000001880542
+0.0000018587
+0.000001837168
+0.00000181594
+0.000001795012
+0.000001774379
+0.000001754034
+0.000001733973
+0.000001714192
+0.000001694685
+0.000001675448
+0.000001656477
+0.000001637766
+0.000001619311
+0.000001601108
+0.000001583153
+0.000001565442
+0.00000154797
+0.000001530734
+0.00000151373
+0.000001496953
+0.000001480401
+0.000001464069
+0.000001447954
+0.000001432053
+0.000001416361
+0.000001400876
+0.000001385594
+0.000001370512
+0.000001355627
+0.000001340936
+0.000001326435
+0.000001312121
+0.000001297993
+0.000001284045
+0.000001270277
+0.000001256685
+0.000001243266
+0.000001230017
+0.000001216937
+0.000001204021
+0.000001191269
+0.000001178677
+0.000001166243
+0.000001153964
+0.000001141839
+0.000001129864
+0.000001118037
+0.000001106357
+0.000001094821
+0.000001083427
+0.000001072173
+0.000001061057
+0.000001050076
+0.000001039229
+0.000001028513
+0.000001017927
+0.00000100747
+0.000000997138
+0.00000098693
+0.000000976845
+0.00000096688
+0.000000957034
+0.000000947305
+0.000000937692
+0.000000928193
+0.000000918805
+0.000000909528
+0.000000900361
+0.0000008913
+0.000000882346
+0.000000873496
+0.000000864749
+0.000000856104
+0.000000847559
+0.000000839112
+0.000000830763
+0.00000082251
+0.000000814351
+0.000000806286
+0.000000798313
+0.000000790431
+0.000000782639
+0.000000774935
+0.000000767318
+0.000000759787
+0.00000075234
+0.000000744978
+0.000000737698
+0.0000007305
+0.000000723382
+0.000000716343
+0.000000709382
+0.000000702499
+0.000000695692
+0.00000068896
+0.000000682302
+0.000000675717
+0.000000669205
+0.000000662764
+0.000000656393
+0.000000650092
+0.000000643859
+0.000000637694
+0.000000631596
+0.000000625564
+0.000000619597
+0.000000613694
+0.000000607855
+0.000000602078
+0.000000596363
+0.000000590709
+0.000000585115
+0.000000579581
+0.000000574106
+0.000000568688
+0.000000563328
+0.000000558025
+0.000000552777
+0.000000547585
+0.000000542447
+0.000000537362
+0.000000532332
+0.000000527353
+0.000000522426
+0.000000517551
+0.000000512726
+0.000000507951
+0.000000503226
+0.000000498549
+0.000000493921
+0.00000048934
+0.000000484806
+0.000000480318
+0.000000475877
+0.00000047148
+0.000000467129
+0.000000462822
+0.000000458558
+0.000000454338
+0.00000045016
+0.000000446025
+0.000000441931
+0.000000437879
+0.000000433867
+0.000000429895
+0.000000425964
+0.000000422071
+0.000000418218
+0.000000414402
+0.000000410625
+0.000000406885
+0.000000403183
+0.000000399517
+0.000000395887
+0.000000392293
+0.000000388734
+0.000000385211
+0.000000381722
+0.000000378267
+0.000000374846
+0.000000371458
+0.000000368104
+0.000000364782
+0.000000361493
+0.000000358235
+0.000000355009
+0.000000351814
+0.00000034865
+0.000000345517
+0.000000342414
+0.000000339341
+0.000000336297
+0.000000333282
+0.000000330297
+0.00000032734
+0.000000324411
+0.00000032151
+0.000000318637
+0.000000315791
+0.000000312972
+0.00000031018
+0.000000307414
+0.000000304674
+0.000000301961
+0.000000299272
+0.00000029661
+0.000000293972
+0.000000291359
+0.00000028877
+0.000000286206
+0.000000283666
+0.00000028115
+0.000000278657
+0.000000276187
+0.00000027374
+0.000000271316
+0.000000268914
+0.000000266535
+0.000000264178
+0.000000261842
+0.000000259528
+0.000000257236
+0.000000254964
+0.000000252714
+0.000000250484
+0.000000248275
+0.000000246085
+0.000000243916
+0.000000241767
+0.000000239637
+0.000000237527
+0.000000235436
+0.000000233364
+0.000000231311
+0.000000229277
+0.000000227261
+0.000000225263
+0.000000223283
+0.000000221321
+0.000000219377
+0.000000217451
+0.000000215541
+0.000000213649
+0.000000211774
+0.000000209916
+0.000000208074
+0.000000206249
+0.000000204441
+0.000000202648
+0.000000200872
+0.000000199111
+0.000000197366
+0.000000195636
+0.000000193922
+0.000000192224
+0.00000019054
+0.000000188871
+0.000000187217
+0.000000185577
+0.000000183952
+0.000000182342
+0.000000180745
+0.000000179163
+0.000000177595
+0.00000017604
+0.000000174499
+0.000000172972
+0.000000171458
+0.000000169957
+0.00000016847
+0.000000166995
+0.000000165533
+0.000000164084
+0.000000162648
+0.000000161224
+0.000000159813
+0.000000158414
+0.000000157027
+0.000000155652
+0.000000154289
+0.000000152938
+0.000000151599
+0.000000150271
+0.000000148955
+0.00000014765
+0.000000146356
+0.000000145074
+0.000000143802
+0.000000142542
+0.000000141292
+0.000000140053
+0.000000138825
+0.000000137607
+0.0000001364
+0.000000135203
+0.000000134017
+0.00000013284
+0.000000131674
+0.000000130518
+0.000000129371
+0.000000128235
+0.000000127108
+0.00000012599
+0.000000124882
+0.000000123784
+0.000000122695
+0.000000121615
+0.000000120545
+0.000000119483
+0.000000118431
+0.000000117387
+0.000000116352
+0.000000115326
+0.000000114309
+0.0000001133
+0.0000001123
+0.000000111309
+0.000000110325
+0.000000109351
+0.000000108384
+0.000000107425
+0.000000106475
+0.000000105532
+0.000000104598
+0.000000103671
+0.000000102752
+0.000000101841
+0.000000100938
+0.000000100042
+0.000000099153
+0.000000098273
+0.000000097399
+0.000000096533
+0.000000095674
+0.000000094822
+0.000000093978
+0.00000009314
+0.00000009231
+0.000000091486
+0.00000009067
+0.00000008986
+0.000000089057
+0.00000008826
+0.000000087471
+0.000000086688
+0.000000085911
+0.000000085141
+0.000000084377
+0.00000008362
+0.000000082869
+0.000000082124
+0.000000081386
+0.000000080653
+0.000000079927
+0.000000079207
+0.000000078492
+0.000000077784
+0.000000077082
+0.000000076385
+0.000000075694
+0.000000075009
+0.00000007433
+0.000000073656
+0.000000072988
+0.000000072325
+0.000000071668
+0.000000071016
+0.00000007037
+0.000000069729
+0.000000069094
+0.000000068463
+0.000000067838
+0.000000067218
+0.000000066604
+0.000000065994
+0.000000065389
+0.00000006479
+0.000000064195
+0.000000063605
+0.000000063021
+0.000000062441
+0.000000061865
+0.000000061295
+0.000000060729
+0.000000060168
+0.000000059612
+0.00000005906
+0.000000058513
+0.00000005797
+0.000000057432
+0.000000056898
+0.000000056369
+0.000000055844
+0.000000055323
+0.000000054807
+0.000000054295
+0.000000053787
+0.000000053284
+0.000000052784
+0.000000052289
+0.000000051798
+0.000000051311
+0.000000050828
+0.000000050349
+0.000000049873
+0.000000049402
+0.000000048935
+0.000000048472
+0.000000048012
+0.000000047556
+0.000000047104
+0.000000046656
+0.000000046212
+0.000000045771
+0.000000045334
+0.0000000449
+0.00000004447
+0.000000044044
+0.000000043621
+0.000000043202
+0.000000042786
+0.000000042374
+0.000000041965
+0.000000041559
+0.000000041157
+0.000000040758
+0.000000040363
+0.000000039971
+0.000000039582
+0.000000039196
+0.000000038813
+0.000000038434
+0.000000038058
+0.000000037685
+0.000000037315
+0.000000036948
+0.000000036585
+0.000000036224
+0.000000035866
+0.000000035512
+0.00000003516
+0.000000034811
+0.000000034465
+0.000000034122
+0.000000033782
+0.000000033445
+0.000000033111
+0.000000032779
+0.000000032451
+0.000000032125
+0.000000031801
+0.000000031481
+0.000000031163
+0.000000030848
+0.000000030535
+0.000000030225
+0.000000029918
+0.000000029613
+0.000000029311
+0.000000029012
+0.000000028715
+0.00000002842
+0.000000028128
+0.000000027839
+0.000000027552
+0.000000027267
+0.000000026985
+0.000000026705
+0.000000026428
+0.000000026153
+0.00000002588
+0.00000002561
+0.000000025342
+0.000000025076
+0.000000024812
+0.000000024551
+0.000000024292
+0.000000024035
+0.000000023781
+0.000000023528
+0.000000023278
+0.00000002303
+0.000000022784
+0.00000002254
+0.000000022299
+0.000000022059
+0.000000021822
+0.000000021586
+0.000000021353
+0.000000021121
+0.000000020892
+0.000000020664
+0.000000020439
+0.000000020216
+0.000000019994
+0.000000019775
+0.000000019557
+0.000000019341
+0.000000019127
+0.000000018915
+0.000000018705
+0.000000018497
+0.00000001829
+0.000000018086
+0.000000017883
+0.000000017682
+0.000000017483
+0.000000017285
+0.00000001709
+0.000000016896
+0.000000016703
+0.000000016513
+0.000000016324
+0.000000016137
+0.000000015951
+0.000000015767
+0.000000015585
+0.000000015405
+0.000000015226
+0.000000015048
+0.000000014873
+0.000000014699
+0.000000014526
+0.000000014355
+0.000000014186
+0.000000014018
+0.000000013851
+0.000000013686
+0.000000013523
+0.000000013361
+0.000000013201
+0.000000013042
+0.000000012885
+0.000000012729
+0.000000012574
+0.000000012421
+0.000000012269
+0.000000012119
+0.00000001197
+0.000000011823
+0.000000011676
+0.000000011532
+0.000000011388
+0.000000011246
+0.000000011105
+0.000000010966
+0.000000010828
+0.000000010691
+0.000000010556
+0.000000010421
+0.000000010289
+0.000000010157
+0.000000010026
+0.000000009897
+0.000000009769
+0.000000009643
+0.000000009517
+0.000000009393
+0.00000000927
+0.000000009148
+0.000000009027
+0.000000008908
+0.000000008789
+0.000000008672
+0.000000008556
+0.000000008441
+0.000000008328
+0.000000008215
+0.000000008103
+0.000000007993
+0.000000007884
+0.000000007775
+0.000000007668
+0.000000007562
+0.000000007457
+0.000000007353
+0.00000000725
+0.000000007148
+0.000000007048
+0.000000006948
+0.000000006849
+0.000000006751
+0.000000006654
+0.000000006559
+0.000000006464
+0.00000000637
+0.000000006277
+0.000000006185
+0.000000006094
+0.000000006004
+0.000000005915
+0.000000005827
+0.00000000574
+0.000000005654
+0.000000005569
+0.000000005484
+0.000000005401
+0.000000005318
+0.000000005237
+0.000000005156
+0.000000005076
+0.000000004997
+0.000000004919
+0.000000004841
+0.000000004765
+0.000000004689
+0.000000004614
+0.00000000454
+0.000000004467
+0.000000004395
+0.000000004323
+0.000000004253
+0.000000004183
+0.000000004114
+0.000000004045
+0.000000003978
+0.000000003911
+0.000000003845
+0.00000000378
+0.000000003715
+0.000000003652
+0.000000003589
+0.000000003526
+0.000000003465
+0.000000003404
+0.000000003344
+0.000000003285
+0.000000003226
+0.000000003168
+0.000000003111
+0.000000003055
+0.000000002999
+0.000000002944
+0.000000002889
+0.000000002835
+0.000000002782
+0.00000000273
+0.000000002678
+0.000000002627
+0.000000002577
+0.000000002527
+0.000000002478
+0.000000002429
+0.000000002381
+0.000000002334
+0.000000002287
+0.000000002241
+0.000000002196
+0.000000002151
+0.000000002107
+0.000000002063
+0.00000000202
+0.000000001978
+0.000000001936
+0.000000001895
+0.000000001854
+0.000000001814
+0.000000001775
+0.000000001736
+0.000000001697
+0.000000001659
+0.000000001622
+0.000000001585
+0.000000001549
+0.000000001513
+0.000000001478
+0.000000001444
+0.00000000141
+0.000000001376
+0.000000001343
+0.00000000131
+0.000000001278
+0.000000001247
+0.000000001216
+0.000000001185
+0.000000001155
+0.000000001125
+0.000000001096
+0.000000001068
+0.000000001039
+0.000000001012
+0.000000000985
+0.000000000958
+0.000000000932
+0.000000000906
+0.00000000088
+0.000000000855
+0.000000000831
+0.000000000807
+0.000000000783
+0.00000000076
+0.000000000737
+0.000000000715
+0.000000000693
+0.000000000671
+0.00000000065
+0.00000000063
+0.000000000609
+0.00000000059
+0.00000000057
+0.000000000551
+0.000000000532
+0.000000000514
+0.000000000496
+0.000000000479
+0.000000000462
+0.000000000445
+0.000000000428
+0.000000000412
+0.000000000397
+0.000000000381
+0.000000000366
+0.000000000352
+0.000000000338
+0.000000000324
+0.00000000031
+0.000000000297
+0.000000000284
+0.000000000272
+0.00000000026
+0.000000000248
+0.000000000236
+0.000000000225
+0.000000000214
+0.000000000203
+0.000000000193
+0.000000000183
+0.000000000174
+0.000000000164
+0.000000000155
+0.000000000146
+0.000000000138
+0.00000000013
+0.000000000122
+0.000000000114
+0.000000000107
+0.0000000001
+0.000000000093
+0.000000000087
+0.000000000081
+0.000000000075
+0.000000000069
+0.000000000063
+0.000000000058
+0.000000000053
+0.000000000049
+0.000000000044
+0.00000000004
+0.000000000036
+0.000000000032
+0.000000000029
+0.000000000025
+0.000000000022
+0.00000000002
+0.000000000017
+0.000000000015
+0.000000000012
+0.00000000001
+0.000000000008
+0.000000000007
+0.000000000005
+0.000000000004
+0.000000000003
+0.000000000002
+0.000000000001
+0.000000000001
+0
+0
+0
diff --git a/help/example_files/nucleotide-branch.shtml b/help/example_files/nucleotide-branch.shtml
new file mode 100644
index 0000000..e3f0c7f
--- /dev/null
+++ b/help/example_files/nucleotide-branch.shtml
@@ -0,0 +1,112 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - nucleotide-branch.txt                           //
+//                                                                                 //
+//      Models that change across the tree in nucleotide/amino-acid simulations    //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* 
+     Any aspect of a nucleotide/amino-acid model can change over different branches, 
+     including: the substitution model, the stationary frequencies, the rates of 
+     insertion and deletion and the insertion/deletion length distributions.
+     The number of categories in the discrete gamma approximation canNOT change.
+     The examples below is arbitrary and not meant to be biologically realistic!
+  */
+
+<font color=red>[TYPE] NUCLEOTIDE 1    </font>          // nucleotide simulation using algorithm from method 1
+
+<font color=red>[MODEL] mHKY1    </font>                // no insertions, no gamma
+<font color=red>  [submodel]    HKY 2.5</font>          // HKY with kappa=2.5
+<font color=red>  [statefreq]   0.1 0.2 0.3 0.4</font>  // frequencies for T C A G
+<font color=red>  [deletemodel] NB 0.2 4</font>         // Pascal deletion distribution (q=0.2, r=4)
+<font color=red>  [deleterate]  0.13   </font>          // rate of deletion (substitution rate = 1)
+
+
+<font color=red>[MODEL] mHKY2    </font>                // no deletions, no gamma
+<font color=red>  [submodel]    HKY 5.0</font>          // HKY with kappa=5.0
+<font color=red>  [statefreq]   0.4 0.3 0.2 0.1</font>  // frequencies for T C A G
+<font color=red>  [insertmodel] POW 1.8 500</font>      // Power-Law insertion distribution (a=1.8, M=500)
+<font color=red>  [insertrate]  0.08   </font>          // rate of insertion (substitution rate = 1)
+
+<font color=red>[MODEL] mGTR1    </font>                     //  no indels, continuous gamma
+<font color=red>  [submodel]  GTR 0.2 0.4 0.6 0.8 1.2</font> //  GTR: a=0.2, b=0.4, c=0.6, d=0.8, e=1.2, f=1
+<font color=red>  [statefreq] 0.2 0.1 0.4 0.3        </font> //  frequencies for T C A G
+<font color=red>  [rates]     0   1.0 0              </font> //  continuous gamma with alpha = 1.0
+               
+/*
+  In the same way that lengths of branches are listed after a <font color=blue>:</font> symbol in a [TREE]
+  block, model names on branches are listed after a <font color=blue>#</font> symbol in a [BRANCHES] block. 
+  N.B. The structure of the tree & order of taxa is the same (see notes at end of file).
+*/
+
+<font color=red>[TREE]     t1 ( (A:1.0, B:1.0):1.0,(C:1.0, D:1.0):1.0);  </font>
+
+<font color=red>[BRANCHES] b1 ( (A #mHKY1, B#mHKY2) #mGTR1,(C #mHKY1, D #mHKY2) #mGTR1)#mGTR1;  </font>
+
+//////////////////////////////////////////////////////////////////////////////////////
+
+<font color=red>[MODEL] mHKY3    </font>                // no insertions, discrete gamma
+<font color=red>  [submodel]    HKY 2.5</font>          // HKY with kappa=2.5
+<font color=red>  [statefreq]   0.1 0.2 0.3 0.4</font>  // frequencies for T C A G
+<font color=red>  [deletemodel] NB 0.2 4</font>         // Pascal deletion length distribution (q=0.2, r=4)
+<font color=red>  [deleterate]  0.13   </font>          // rate of deletion (substitution rate = 1)
+<font color=red>  [rates]       0  2.0 10  </font>      // 10 category discrete gamma, alpha=2.0
+
+<font color=red>[MODEL] mHKY4    </font>                // no deletions, discrete gamma
+<font color=red>  [submodel]    HKY 5.0</font>          // HKY with kappa=5.0
+<font color=red>  [statefreq]   0.4 0.3 0.2 0.1</font>  // frequencies for T C A G
+<font color=red>  [insertmodel] POW 1.8 600</font>      // Power-Law insertion length distribution (a=1.8, M=600)
+<font color=red>  [insertrate]  0.08   </font>          // rate of insertion (substitution rate = 1)
+<font color=red>  [rates]       0  0.5 10  </font>      // 10 category discrete gamma, alpha=0.5
+
+
+<font color=red>[MODEL] mGTR2    </font>                        //insertions and deletions, discrete gamma
+<font color=red>  [insertrate]  0.15   </font>                  // rate of insertion (substitution rate = 1)
+<font color=red>  [statefreq]   0.26 0.24 0.2 0.3</font>        // frequencies for T C A G
+<font color=red>  [submodel]    GTR 0.2 0.4 0.6 0.8 1.2</font>  // a=0.2, b=0.4, c=0.6, d=0.8, e=1.2, f=1
+<font color=red>  [indelmodel]  POW 2.2 500</font>              // Power Law indel distribution (a=2.2, M=500)
+<font color=red>  [deleterate]  0.05   </font>                  // rate of deletion (substitution rate = 1)
+<font color=red>  [rates]       0  1.0 10  </font>              // 10 category discrete gamma, alpha=1.0
+
+<font color=red>[MODEL] mGTR3    </font>                        // insertions and deletions, no gamma
+<font color=red>  [insertmodel] POW 1.9 900</font>              // Power-Law insertion distribution (a=1.9, M=900)
+<font color=red>  [deletemodel] POW 1.7 1000</font>             // Power-Law deletion distribution (a=1.7, M=1000)
+<font color=red>  [submodel]    GTR 1.2 1.0 0.8 0.6 0.4</font>  // a=1.2, b=1.0, c=0.8, d=0.6, e=0.4, f=1
+<font color=red>  [statefreq]   0.6 0.1 0.15 0.15</font>        // frequencies for T C A G
+<font color=red>  [indelrate]   0.1   </font>                   // rate of insertion AND deletion compared 
+<font color=red>                      </font>                   // to substitution rate of 1
+               
+/*
+  In the same way that lengths of branches are listed after a <font color=blue>:</font> symbol in a [TREE]
+  block, model names on branches are listed after a <font color=blue>#</font> symbol in a [BRANCHES] block. 
+  N.B. The structure of the tree & order of taxa is the same (see notes at end of file).
+*/
+
+<font color=red>[TREE]     t2 ( A:1.0, B:1.0, (C:1.0, D:1.0):1.0);  </font>
+
+<font color=red>[BRANCHES] b2 ( A #mGTR2, B#mGTR3, (C #mHKY3, D #mHKY4) #mHKY1)#mHKY3;  </font>
+
+//////////////////////////////////////////////////////////////////////////////////////
+         
+  /* [BRANCHES] blocks are included in [PARTITIONS] blocks in the same way as models */
+
+<font color=red>[PARTITIONS] Pname1  [t1 b1 1000]</font>   // tree t1, branchclass b1, root length 1000
+<font color=red>[PARTITIONS] Pname2  [t2 b2 1000]</font>   // tree t2, branchclass b2, root length 1000
+
+<font color=red>[EVOLVE]     </font>
+<font color=red>  Pname1  10  outputname1</font>           // 10 replicates generated from partition Pname1
+<font color=red>  Pname2  10  outputname2</font>           // 10 replicates generated from partition Pname2
+
+
+//////////////////////////////////////////////////////////////////////////////////////
+
+/*
+    See extra relevant notes at the end of the file branch.txt <a href="http://abacus.gene.ucl.ac.uk/software/indelible/tutorial/branch.shtml">here</a>
+*/
+</pre>
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/nucleotide_RATES.txt b/help/example_files/nucleotide_RATES.txt
new file mode 100644
index 0000000..8608f0a
--- /dev/null
+++ b/help/example_files/nucleotide_RATES.txt
@@ -0,0 +1,685 @@
+Rates file : INDELible V1.00 
+
+Site	Rate	Inserted?	Partition
+1	0.249957	Y	1
+2	0.872481	Y	1
+3	0.980657	Y	1
+4	0.393844	Y	1
+5	0.875117	Y	1
+1	0.249957 	Y	1
+2	0.872481 	Y	1
+3	0.980657 	Y	1
+4	0.393844 	Y	1
+5	0.875117 	Y	1
+6	0.791917 	 	1
+7	0.465039 	Y	1
+8	0.186378 	 	1
+9	0.30224  	Y	1
+10	0.460121 	 	1
+11	0.811728 	Y	1
+12	0.32821  	Y	1
+13	2.6801   	 	1
+14	0.952254 	Y	1
+15	1.03319  	 	1
+16	0.177073 	Y	1
+17	0.935987 	Y	1
+18	0.247596 	Y	1
+19	1.58896  	 	1
+20	1.2062   	Y	1
+21	0.746537 	Y	1
+22	0.918666 	Y	1
+23	0.944981 	Y	1
+24	0.454774 	Y	1
+25	0.522728 	Y	1
+26	1.97235  	Y	1
+27	0.359178 	Y	1
+28	0.184927 	Y	1
+29	1.66388  	 	1
+30	0.473696 	Y	1
+31	1.07622  	Y	1
+32	0.564921 	 	1
+33	1.93328  	 	1
+34	0.253382 	Y	1
+35	0.902886 	Y	1
+36	1.24948  	 	1
+37	0.708456 	 	1
+38	0.47735  	Y	1
+39	1.57542  	Y	1
+40	1.58743  	 	1
+41	0.485011 	Y	1
+42	0.76292  	Y	1
+43	0.862071 	Y	1
+44	0.949702 	Y	1
+45	0.373606 	Y	1
+46	0.588943 	Y	1
+47	1.20029  	Y	1
+48	1.85733  	Y	1
+49	0.821937 	 	1
+50	1.55513  	 	1
+51	0.336266 	Y	1
+52	2.41017  	 	1
+53	0.916736 	 	1
+54	1.00476  	Y	1
+55	1.43367  	Y	1
+56	0.999933 	Y	1
+57	2.01392  	Y	1
+58	0.845175 	Y	1
+59	1.95497  	Y	1
+60	3.26338  	Y	1
+61	1.25536  	Y	1
+62	1.31304  	Y	1
+63	0.0783243	Y	1
+64	0.736997 	Y	1
+65	0.945556 	Y	1
+66	0.455374 	Y	1
+67	1.34109  	Y	1
+68	0.694815 	Y	1
+69	1.36036  	Y	1
+70	1.72777  	Y	1
+71	0.117869 	Y	1
+72	0.544521 	 	1
+73	1.05876  	Y	1
+74	0.823658 	Y	1
+75	1.90874  	Y	1
+76	0.329399 	Y	1
+77	0.385247 	Y	1
+78	0.187594 	 	1
+79	1.40182  	Y	1
+80	2.46539  	Y	1
+81	1.86131  	Y	1
+82	0.223623 	Y	1
+83	0.189851 	Y	1
+84	0.989944 	Y	1
+85	1.69327  	Y	1
+86	1.96202  	Y	1
+87	0.567865 	Y	1
+88	0.746278 	Y	1
+89	0.78294  	Y	1
+90	0.68429  	Y	1
+91	0.254162 	 	1
+92	0.27365  	Y	1
+93	0.482601 	Y	1
+94	0.74716  	 	1
+95	0.458177 	Y	1
+96	2.17723  	 	1
+97	1.26743  	 	1
+98	0.234839 	 	1
+99	1.32562  	 	1
+100	0.347025 	Y	1
+101	1.06726  	Y	1
+102	1.69343  	Y	1
+103	0.588804 	Y	1
+104	3.09656  	Y	1
+105	0.754185 	Y	1
+106	0.552769 	Y	1
+107	0.776593 	Y	1
+108	0.803058 	Y	1
+109	0.70077  	 	1
+110	0.729849 	 	1
+111	0.410579 	Y	1
+112	1.49225  	Y	1
+113	2.00986  	Y	1
+114	0.261835 	Y	1
+115	1.98319  	 	1
+116	1.61365  	Y	1
+117	1.38582  	Y	1
+118	1.39488  	Y	1
+119	0.501454 	Y	1
+120	0.70998  	Y	1
+121	0.331795 	Y	1
+122	0.485105 	Y	1
+123	0.312151 	Y	1
+124	2.25576  	Y	1
+125	0.569814 	Y	1
+126	1.29459  	Y	1
+127	2.45452  	Y	1
+128	0.910478 	Y	1
+129	0.712834 	 	1
+130	0.244339 	Y	1
+131	2.30076  	 	1
+132	1.03157  	 	1
+133	0.675499 	 	1
+134	1.54959  	Y	1
+135	0.430812 	Y	1
+136	1.95741  	Y	1
+137	0.0310587	Y	1
+138	1.57342  	Y	1
+139	1.27166  	Y	1
+140	1.62914  	 	1
+141	1.03634  	Y	1
+142	0.628177 	 	1
+143	0.37337  	Y	1
+144	0.406194 	 	1
+145	1.31427  	Y	1
+146	1.80333  	 	1
+147	0.530385 	Y	1
+148	0.532045 	Y	1
+149	0.172479 	Y	1
+150	1.01958  	 	1
+151	0.972377 	Y	1
+152	0.604558 	Y	1
+153	1.86302  	 	1
+154	1.06046  	Y	1
+155	0.657714 	 	1
+156	2.63459  	Y	1
+157	0.924919 	 	1
+158	1.63187  	Y	1
+159	0.24556  	Y	1
+160	0.521293 	Y	1
+161	1.55852  	Y	1
+162	0.286215 	Y	1
+163	0.980977 	 	1
+164	0.889197 	Y	1
+165	0.150078 	Y	1
+166	0.125449 	Y	1
+167	0.371049 	 	1
+168	0.96819  	Y	1
+169	1.90233  	Y	1
+170	2.82239  	Y	1
+171	0.314519 	 	1
+172	1.2457   	Y	1
+173	1.40561  	Y	1
+174	0.104023 	Y	1
+175	0.191259 	 	1
+176	1.10075  	Y	1
+177	0.471978 	 	1
+178	0.521206 	 	1
+179	0.904074 	Y	1
+180	0.305125 	 	1
+181	2.00481  	Y	1
+182	1.1185   	Y	1
+183	1.25254  	 	1
+184	0.352447 	 	1
+185	1.77956  	Y	1
+186	1.43163  	Y	1
+187	0.237888 	Y	1
+188	0.24623  	Y	1
+189	1.41508  	Y	1
+190	0.602284 	 	1
+191	0.381701 	Y	1
+192	0.601748 	Y	1
+193	1.2223   	Y	1
+194	1.2409   	Y	1
+195	0.517592 	Y	1
+196	0.616613 	 	1
+197	0.559638 	Y	1
+198	0.76103  	 	1
+199	1.31136  	Y	1
+200	0.198858 	Y	1
+201	1.54253  	Y	1
+202	0.363423 	Y	1
+203	1.53675  	Y	1
+204	0.306936 	 	1
+205	0.287824 	 	1
+206	1.01682  	 	1
+207	2.67341  	 	1
+208	0.790511 	Y	1
+209	1.60437  	 	1
+210	0.850907 	 	1
+211	0.348633 	Y	1
+212	2.24245  	Y	1
+213	0.191527 	Y	1
+214	0.462724 	 	1
+215	1.24113  	 	1
+216	0.317217 	 	1
+217	0.165044 	 	1
+218	0.847599 	Y	1
+219	0.607848 	Y	1
+220	0.434421 	 	1
+221	0.650792 	Y	1
+222	1.55706  	 	1
+223	1.84468  	Y	1
+224	2.38921  	Y	1
+225	0.674795 	Y	1
+226	0.307901 	 	1
+227	0.703835 	 	1
+228	0.692353 	Y	1
+229	0.227558 	Y	1
+230	0.557155 	Y	1
+231	3.2873   	Y	1
+232	0.982411 	Y	1
+233	1.43288  	Y	1
+234	0.503484 	Y	1
+235	2.11936  	 	1
+236	1.35123  	 	1
+237	1.62377  	 	1
+238	1.9435   	Y	1
+239	0.829563 	Y	1
+240	0.808758 	Y	1
+241	0.108672 	Y	1
+242	0.683026 	Y	1
+243	0.327198 	 	1
+244	0.39526  	Y	1
+245	1.11183  	Y	1
+246	2.12909  	 	1
+247	0.341678 	 	1
+248	0.983624 	Y	1
+249	0.592593 	Y	1
+250	0.643122 	 	1
+251	1.09984  	Y	1
+252	0.554412 	 	1
+253	1.93019  	Y	1
+254	1.4179   	Y	1
+255	0.994049 	Y	1
+256	0.425317 	Y	1
+257	0.914301 	Y	1
+258	0.747811 	Y	1
+259	2.40244  	Y	1
+260	1.21901  	 	1
+261	0.854944 	 	1
+262	0.31072  	 	1
+263	0.374872 	Y	1
+264	1.03458  	 	1
+265	0.64697  	Y	1
+266	3.03872  	 	1
+267	0.65626  	 	1
+268	2.6087   	Y	1
+269	1.55944  	Y	1
+270	0.468887 	Y	1
+271	0.714307 	Y	1
+272	1.57652  	Y	1
+273	1.54202  	Y	1
+274	0.39241  	Y	1
+275	0.292652 	Y	1
+276	0.513898 	Y	1
+277	1.2683   	Y	1
+278	1.46854  	Y	1
+279	0.798511 	Y	1
+280	0.547613 	Y	1
+281	4.32147  	Y	1
+282	0.375858 	Y	1
+283	1.37047  	Y	1
+284	0.884493 	Y	1
+285	1.62142  	Y	1
+286	0.0614729	Y	1
+287	0.735878 	Y	1
+288	1.12611  	Y	1
+289	0.223438 	Y	1
+290	0.817089 	Y	1
+291	0.269421 	Y	1
+292	0.636062 	 	1
+293	1.77009  	Y	1
+294	0.875993 	Y	1
+295	0.700604 	 	1
+296	0.316974 	Y	1
+297	2.53561  	 	1
+298	1.29629  	 	1
+299	1.08557  	 	1
+300	0.716177 	Y	1
+301	0.779094 	 	1
+302	0.604449 	Y	1
+303	0.538389 	Y	1
+304	0.861123 	 	1
+305	0.509631 	Y	1
+306	0.484631 	Y	1
+307	1.06734  	Y	1
+308	1.30366  	Y	1
+309	2.20686  	Y	1
+310	1.64733  	 	1
+311	2.3059   	Y	1
+312	0.378002 	Y	1
+313	0.784026 	Y	1
+314	2.35966  	Y	1
+315	1.49118  	Y	1
+316	1.11968  	Y	1
+317	0.487402 	 	1
+318	0.188567 	Y	1
+319	1.60619  	Y	1
+320	1.39191  	 	1
+321	0.841103 	 	1
+322	0.978581 	 	1
+323	0.870735 	Y	1
+324	1.63125  	 	1
+325	1.76922  	 	1
+326	0.445871 	 	1
+327	0.263504 	Y	1
+328	0.156602 	 	1
+329	1.28387  	 	1
+330	0.821501 	 	1
+331	0.729364 	 	1
+332	1.01711  	 	1
+333	2.60401  	 	1
+6	0.160109	Y	2
+7	0.0428472	Y	2
+8	1.33058	Y	2
+1	0.160109 	Y	2
+2	0.0428472	Y	2
+3	1.33058  	Y	2
+4	0.490114 	 	2
+5	0.767275 	 	2
+6	0        	Y	2
+7	2.85469  	Y	2
+8	0        	Y	2
+9	0        	Y	2
+10	0        	Y	2
+11	2.88344  	Y	2
+12	1.3605   	Y	2
+13	0.293199 	Y	2
+14	0        	Y	2
+15	1.52114  	Y	2
+16	0        	Y	2
+17	0        	Y	2
+18	0        	Y	2
+19	2.33513  	Y	2
+20	2.98584  	 	2
+21	1.32706  	Y	2
+22	1.9684   	Y	2
+23	2.03099  	Y	2
+24	0        	Y	2
+25	1.1591   	 	2
+26	1.54952  	 	2
+27	2.55582  	 	2
+28	0.432553 	Y	2
+29	0        	Y	2
+30	2.06446  	Y	2
+31	0        	Y	2
+32	0.161588 	Y	2
+33	0        	Y	2
+34	1.33458  	Y	2
+35	0        	Y	2
+36	1.34994  	Y	2
+37	0.384733 	Y	2
+38	0        	 	2
+39	0        	 	2
+40	1.82708  	Y	2
+41	1.45464  	 	2
+42	0.904905 	 	2
+43	0.520922 	Y	2
+44	0        	Y	2
+45	3.08618  	Y	2
+46	0.989367 	Y	2
+47	0        	Y	2
+48	1.99929  	Y	2
+49	0.457647 	Y	2
+50	0        	Y	2
+51	0.480238 	Y	2
+52	0        	Y	2
+53	1.77594  	Y	2
+54	0        	Y	2
+55	1.33498  	Y	2
+56	0.341005 	Y	2
+57	1.34464  	Y	2
+58	0        	Y	2
+59	0        	Y	2
+60	1.3242   	Y	2
+61	0        	Y	2
+62	0        	Y	2
+63	1.18069  	Y	2
+64	0.823308 	Y	2
+65	3.21632  	Y	2
+66	0        	Y	2
+67	1.05904  	Y	2
+68	0        	Y	2
+69	0.552467 	Y	2
+70	2.11862  	Y	2
+71	0.524586 	 	2
+72	0        	 	2
+73	1.90698  	 	2
+74	0.471826 	 	2
+75	0        	Y	2
+76	0        	Y	2
+77	0        	Y	2
+78	1.56499  	Y	2
+79	1.62721  	 	2
+80	1.931    	Y	2
+81	2.02313  	Y	2
+82	2.00539  	 	2
+83	0        	Y	2
+84	0.725401 	 	2
+85	4.69031  	Y	2
+86	0        	Y	2
+87	1.99463  	Y	2
+88	1.19036  	 	2
+89	3.39791  	Y	2
+90	1.58744  	 	2
+91	0.799174 	Y	2
+92	0.363233 	 	2
+93	0.94096  	 	2
+94	0.643149 	Y	2
+95	2.03014  	Y	2
+96	0        	 	2
+97	0.870119 	Y	2
+98	1.11653  	Y	2
+99	0.721238 	Y	2
+100	0.748319 	Y	2
+101	3.83632  	Y	2
+102	0        	Y	2
+103	1.50354  	Y	2
+104	0        	Y	2
+105	0        	Y	2
+106	0.747972 	Y	2
+107	2.93681  	Y	2
+108	1.93804  	Y	2
+109	0        	Y	2
+110	0.62641  	 	2
+111	1.09533  	 	2
+112	0.335808 	Y	2
+113	0        	Y	2
+114	0.674984 	 	2
+115	1.6564   	Y	2
+116	0        	Y	2
+117	1.92226  	Y	2
+118	0        	 	2
+119	0        	 	2
+120	0.792303 	Y	2
+121	0.811686 	Y	2
+122	0        	Y	2
+123	0        	Y	2
+124	0.124224 	Y	2
+125	0.659214 	Y	2
+126	0.565793 	 	2
+127	1.20414  	Y	2
+128	0.474411 	Y	2
+129	1.04551  	Y	2
+130	1.87444  	Y	2
+131	0.423945 	 	2
+132	0        	Y	2
+133	0.578594 	 	2
+134	0        	Y	2
+135	0.653803 	Y	2
+136	0        	Y	2
+137	0.353462 	Y	2
+138	1.78101  	 	2
+139	0.2076   	Y	2
+140	1.31161  	Y	2
+141	0.955153 	 	2
+142	0        	Y	2
+143	0.857177 	Y	2
+144	2.95138  	Y	2
+145	0.280407 	Y	2
+146	0.31548  	Y	2
+147	0        	Y	2
+148	2.51072  	Y	2
+149	0.745482 	Y	2
+150	0        	Y	2
+151	2.45905  	Y	2
+152	3.6838   	 	2
+153	0.705751 	 	2
+154	0        	Y	2
+155	2.45382  	 	2
+156	2.10212  	Y	2
+157	3.33327  	Y	2
+158	0.215105 	Y	2
+159	0        	 	2
+160	0.503885 	Y	2
+161	0        	Y	2
+162	0.746868 	Y	2
+163	0.608215 	 	2
+164	0.83693  	Y	2
+165	0.601628 	Y	2
+166	1.04207  	Y	2
+167	0        	 	2
+168	0        	Y	2
+169	0        	Y	2
+170	0        	Y	2
+171	1.58989  	Y	2
+172	0        	Y	2
+173	0        	 	2
+174	0.591605 	Y	2
+175	1.16007  	Y	2
+176	2.87367  	Y	2
+177	0        	 	2
+178	1.97588  	 	2
+179	0        	Y	2
+180	2.78596  	Y	2
+181	0        	Y	2
+182	2.80532  	Y	2
+183	1.48172  	 	2
+184	0.377787 	Y	2
+185	0        	Y	2
+186	0        	 	2
+187	1.24746  	 	2
+188	0        	Y	2
+189	1.10607  	 	2
+190	3.63165  	 	2
+191	1.25262  	 	2
+192	0        	 	2
+193	0        	 	2
+194	1.29678  	Y	2
+195	1.46779  	 	2
+196	0        	 	2
+197	1.6192   	Y	2
+198	0.761319 	 	2
+199	1.59083  	 	2
+200	0        	 	2
+201	1.2853   	Y	2
+202	0        	Y	2
+203	0        	Y	2
+204	1.75012  	Y	2
+205	0        	Y	2
+206	1.35364  	Y	2
+207	1.24017  	Y	2
+208	0.867253 	 	2
+209	0        	 	2
+210	2.55934  	Y	2
+211	0.600399 	Y	2
+212	0.790759 	Y	2
+213	0        	Y	2
+214	0.668983 	 	2
+215	0        	Y	2
+216	2.51011  	 	2
+217	0.851854 	Y	2
+218	0        	Y	2
+219	3.34492  	Y	2
+220	0.821375 	Y	2
+221	0        	Y	2
+222	2.83345  	 	2
+223	2.21489  	Y	2
+224	1.38715  	Y	2
+225	0        	Y	2
+226	0.55967  	 	2
+227	0        	 	2
+228	0.162868 	 	2
+229	0        	 	2
+230	1.85547  	Y	2
+231	0.916852 	Y	2
+232	0        	Y	2
+233	0        	 	2
+234	2.98562  	 	2
+235	1.56992  	Y	2
+236	1.25945  	Y	2
+237	1.65672  	Y	2
+238	0        	Y	2
+239	1.14264  	Y	2
+240	0.359083 	Y	2
+241	1.23818  	Y	2
+242	1.25847  	Y	2
+243	1.41182  	Y	2
+244	0.744149 	Y	2
+245	1.33012  	Y	2
+246	4.94438  	 	2
+247	0        	 	2
+248	0        	 	2
+249	0        	Y	2
+250	0        	Y	2
+251	0        	Y	2
+252	2.72715  	Y	2
+253	0        	Y	2
+254	0        	Y	2
+255	3.65499  	Y	2
+256	0        	Y	2
+257	3.78742  	Y	2
+258	0.827003 	Y	2
+259	2.20194  	Y	2
+260	0        	 	2
+261	0        	Y	2
+262	0.723882 	Y	2
+263	0        	 	2
+264	0.439193 	 	2
+265	0        	 	2
+266	0.312494 	 	2
+267	0.676104 	 	2
+268	1.87421  	Y	2
+269	0.606016 	Y	2
+270	1.38591  	Y	2
+271	0.867269 	Y	2
+272	0.681016 	Y	2
+273	0        	Y	2
+274	0.421938 	 	2
+275	1.62438  	Y	2
+276	0.825435 	Y	2
+277	0.691646 	Y	2
+278	0.873512 	Y	2
+279	0        	Y	2
+280	1.10565  	 	2
+281	0        	 	2
+282	0        	 	2
+283	0.778692 	Y	2
+284	0.239517 	 	2
+285	0        	Y	2
+286	0        	Y	2
+287	0.375574 	Y	2
+288	1.79261  	 	2
+289	2.64067  	 	2
+290	0        	 	2
+291	1.33295  	 	2
+292	0.528891 	Y	2
+293	0.895208 	Y	2
+294	0        	 	2
+295	1.60097  	Y	2
+296	0        	Y	2
+297	0        	Y	2
+298	1.35965  	Y	2
+299	1.64604  	Y	2
+300	0        	 	2
+301	0        	 	2
+302	2.04655  	 	2
+303	0.362101 	Y	2
+304	0        	Y	2
+305	2.43253  	Y	2
+306	0.431022 	Y	2
+307	1.89166  	 	2
+308	1.60154  	 	2
+309	0.84181  	Y	2
+310	1.04489  	 	2
+311	0        	 	2
+312	3.42973  	Y	2
+313	0.713986 	Y	2
+314	2.42327  	Y	2
+315	2.37023  	Y	2
+316	1.93284  	 	2
+317	0.762738 	Y	2
+318	1.24872  	 	2
+319	0.16129  	Y	2
+320	0        	Y	2
+321	1.75649  	 	2
+322	0        	Y	2
+323	0        	 	2
+324	2.31344  	Y	2
+325	0.653912 	Y	2
+326	2.00172  	Y	2
+327	2.74299  	Y	2
+328	0        	 	2
+329	2.73293  	 	2
+330	0.999909 	Y	2
+331	3.85435  	Y	2
+332	0        	Y	2
+333	2.08006  	 	2
+334	0        	Y	2
+335	0.684066 	Y	2
+336	1.5619   	Y	2
+337	2.27034  	 	2
+338	1.3827   	Y	2
+339	0        	Y	2
+340	0.836637 	 	2
+341	1.29447  	Y	2
diff --git a/help/example_files/random_branch_length_trees.JPG b/help/example_files/random_branch_length_trees.JPG
new file mode 100644
index 0000000..266230d
Binary files /dev/null and b/help/example_files/random_branch_length_trees.JPG differ
diff --git a/help/example_files/rates.shtml b/help/example_files/rates.shtml
new file mode 100644
index 0000000..a02a6ca
--- /dev/null
+++ b/help/example_files/rates.shtml
@@ -0,0 +1,69 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - rates.txt                                       //
+//                                                                                 //
+//      Adding proportion of invariable sites or gamma rate heterogeneity.         //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+  Nucleotide models are used as an example but the principle is exactly the 
+  same for amino-acid models. You just add the [rates] command to a model:
+
+    <font color=blue>[rates]  pinv  alpha  ngamcat</font>
+
+  This command has no effect in <i>CODON</i> simulations.
+
+  * <i>pinv</i> is the proportion of invariable sites (0<=<i>pinv</i><=1).
+  * <i>alpha</i> is the shape parameter for the gamma distribution (<i>alpha</i>>0).
+  * If <i>alpha</i>=0 then there will be no gamma rate variation.</li>
+  * <i>ngamcat</i> is the number of categories to use in the discrete gamma approximation.
+  * If <i>ngamcat</i>=0 then continuous gamma distribution will be used for rate variation.
+  * If the command [rates] is not specified all rates will be constant.
+
+*/
+
+
+<font color=red>[TYPE] NUCLEOTIDE 1</font>	//  nucleotide simulation using algorithm from method 1
+
+
+<font color=red>[MODEL] mymodel1  [submodel]  JC  </font>       //   JC69 with pinv=0.2 and no gamma
+<font color=red>                  [rates]     0.2 0 0  </font>     
+ 									
+<font color=red>[MODEL] mymodel2  [submodel]  JC  </font>       //   JC69 with no proportion invariable,
+<font color=red>                  [rates]     0 2 0  </font>    //   continuous gamma with alpha=2     
+
+<font color=red>[MODEL] mymodel3  [submodel]  JC  </font>       //   JC69 with no proportion invariable,
+<font color=red>                  [rates]     0 1 10  </font>   //   10 category discrete gamma with alpha=1
+                                                                    
+<font color=red>[MODEL] mymodel4  [submodel]  JC  </font>       //   JC69 with pinv=0.2 
+<font color=red>                  [rates]     0.2 0.5 0  </font>//   continuous gamma with alpha=0.5     
+
+<font color=red>[MODEL] mymodel5  [submodel]  JC  </font>       //   JC69 with pinv=0.1
+<font color=red>                  [rates]     0.1 1.5 5  </font>//   5 category discrete gamma with alpha=1.5
+
+
+<font color=red>[TREE] T1  (A:0.1,B:0.1);</font>             
+
+
+<font color=red>[PARTITIONS] Pname1  [T1 mymodel1 1000]</font>   // tree T1, model mymodel1, root length 1000
+<font color=red>[PARTITIONS] Pname2  [T1 mymodel2 1000]</font>   // tree T1, model mymodel2, root length 1000
+<font color=red>[PARTITIONS] Pname3  [T1 mymodel3 1000]</font>   // tree T1, model mymodel3, root length 1000
+<font color=red>[PARTITIONS] Pname4  [T1 mymodel4 1000]</font>   // tree T1, model mymodel4, root length 1000
+<font color=red>[PARTITIONS] Pname5  [T1 mymodel5 1000]</font>   // tree T1, model mymodel5, root length 1000
+
+
+
+ 
+<font color=red>[EVOLVE]     Pname1  10  outputname1</font>     // 10 replicates generated from partition Pname1
+<font color=red>             Pname2  10  outputname2</font>     // 10 replicates generated from partition Pname2
+<font color=red>             Pname3  10  outputname3</font>     // 10 replicates generated from partition Pname3
+<font color=red>             Pname4  10  outputname4</font>     // 10 replicates generated from partition Pname4
+<font color=red>             Pname5  10  outputname5</font>     // 10 replicates generated from partition Pname5
+
+</pre>
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/settings.shtml b/help/example_files/settings.shtml
new file mode 100644
index 0000000..1347487
--- /dev/null
+++ b/help/example_files/settings.shtml
@@ -0,0 +1,122 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - settings.txt                                    //
+//                                                                                 //
+//      How to include paup blocks, set seeds for the random number generator,     //
+//      change the output format for generated data, or how to print "reports"     //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+<font color=red>[TYPE] NUCLEOTIDE 2</font>	//  nucleotide simulation using algorithm from method 2
+
+  //
+  // * If a command is not specified in the [SETTINGS] block then it will have the 
+  //   default value shown below. The only exception to this is [randomseed] whose 
+  //   value will be randomly chosen if not specified.
+  // * If no [SETTINGS] block is specified all commands will have these default values.
+  // * More information on each of the commands can be found at the end of the file.
+  //
+
+
+<font color=red>[SETTINGS] </font>   
+  <font color=red>[ancestralprint]</font>           FALSE     // NEW, SAME or FALSE
+  <font color=red>[output]</font>                   PHYLIP    // FASTA, NEXUS, PHYLIP or PHYLIPT
+  <font color=red>[phylipextension]</font>          phy       // any alpha-numeric string
+  <font color=red>[nexusextension]</font>           nex       // any alpha-numeric string
+  <font color=red>[fastaextension]</font>           fas       // any alpha-numeric string
+  <font color=red>[randomseed]</font>               1568746   // any integer
+  <font color=red>[printrates]</font>               FALSE     // FALSE or TRUE
+  <font color=red>[insertaslowercase]</font>        TRUE      // FALSE or TRUE
+  <font color=red>[markdeletedinsertions]</font>    FALSE     // FALSE or TRUE 
+  <font color=red>[printcodonsasaminoacids]</font>  FALSE     // FALSE or TRUE
+  <font color=red>[fileperrep]</font>               FALSE     // FALSE or TRUE
+
+
+<font color=red>[MODEL] mymodel  [submodel]  JC  </font>     
+
+
+<font color=red>[TREE] t1 ((A:0.1,B:0.1):0.1,(C:0.1,D:0.1):0.1);</font>
+
+
+<font color=red>[PARTITIONS] Pname  [t1 mymodel 1000]</font>   // tree t1, model mymodel, root length 1000
+
+ 
+<font color=red>[EVOLVE]     Pname  10  filename</font>        // 10 replicates generated from partition Pname
+
+/*
+  <font color=blue><a name="[ancestralprint]">[ancestralprint]</a></font>
+  * <i>NEW</i> will print ancestral sequences in a separate file to leaf sequences.
+  * <i>SAME</i> prints ancestral sequences in the same file as the leaf sequences.
+  * <i>FALSE</i> will not print any ancestral sequences.
+  * It should be noted that if you used different guide trees for different partitions 
+    in a partitioned (multi-gene) analysis then only the root sequence will be printed 
+    in the SAME/NEW file specified in this command.
+
+  <font color=blue>[output]</font>
+  * Unaligned sequences are always output in FASTA format as e.g. filename.fas
+  * This command sets the output type for the true alignment and prints it to a file 
+    named e.g. filename_TRUE.phy
+  * <i>FASTA</i>, <i>NEXUS</i>, <i>PHYLIP</i> will print out sequences to file in either 
+    fasta, nexus, or phylip format respectively. 
+  * FASTA is used by NCBI and accepted by most sequence alignment programs.  
+    NEXUS is used by e.g. MacClade, Mesquite, ModelTest, MrBayes and PAUP*.  
+    PHYLIP is used by PHYLIP and PAML.
+  * <i>PHYLIPT</i> gives PHYLIP format with filenames truncated to 8 characters. 
+
+  <font color=blue>[phylipextension]</font>
+  * This command sets the file extension for true alignments in phylip format so they 
+    are e.g. filename.phy or whatever you choose them to be.
+
+  <font color=blue>[nexusextension]</font>
+  * This command sets the file extension for true alignments in nexus format so they 
+    are e.g. filename.nex or whatever you choose them to be.
+
+  <font color=blue>[fastaextension]</font>
+  * This command sets the file extension for fasta formatted output files so they 
+    are e.g. filename.fas or whatever you choose them to be.
+
+  <font color=blue>[randomseed]</font>
+  * This must be an integer value and is used to seed the random number generator.
+  * Running simulations with the same random seed value (and the same control file) 
+    will produce identical datasets.
+ 
+  <font color=blue>[printrates]</font>
+  * <i>TRUE</i> will print out a detailed output file for each replicate of each block 
+    that lists what the site-classes or relative rates of substitution are.
+  * <i>FALSE</i> will not print any rates information.
+  * Follow these links for examples of the output for <a href="nucleotide_RATES.txt" target="_blank";>NUCLEOTIDE / AMINOACID</a> simulations, 
+    or for <a href="codon_RATES.txt" target="_blank";>CODON</a> simulations. 
+  
+  <font color=blue>[markdeletedinsertions]</font>
+  * <i>TRUE</i> will output inserted bases/residues that have been subsequently been 
+    deleted as * rather than - for easy identification.
+  * <i>FALSE</i> leave everything as -.
+  
+  <font color=blue>[insertaslowercase]</font>
+  * <i>TRUE</i> will output inserted bases/residues as lower case letters for easy identification.
+  * <i>FALSE</i> will output all bases/residues as upper case letters.
+  
+  <font color=blue>[printcodonsasaminoacids]</font>
+  * <i>TRUE</i> will output codon datasets as amino-acids - how they are translated will 
+    depend on the genetic code specified in the model.
+  * <i>FALSE</i> will print codons as nucleotide triplets.
+
+  <font color=blue>[fileperrep]</font>
+  * <i>TRUE</i> will output each replicate dataset in a separate file.
+    Unaligned sequences will go in e.g. filename_1.fas, filename_2.fas, etc
+    The true alignment will go in e.g. filename_TRUE_1.phy, filename_TRUE_2.phy, etc
+  * <i>FALSE</i> will print all replicates in a single file.
+    Unaligned sequences for each dataset will all go in e.g. filename.fas    
+    All the true alignments will go in e.g. filename_TRUE.phy
+  * If a file called paupstart.txt (or paupend.txt) exists in the same directory as 
+    INDELible then it will be copied to the beginning (or end) of each file. 
+  * If a file called paupmiddle.txt exists in the same directory as INDELible then it 
+    will be copied to e.g. filename_TRUE.phy after each replicate datset.
+  * These features are useful if you want to include PAUP or MrBayes blocks in your files.
+*/
+</pre>
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/sitebranch.shtml b/help/example_files/sitebranch.shtml
new file mode 100644
index 0000000..d02d7e6
--- /dev/null
+++ b/help/example_files/sitebranch.shtml
@@ -0,0 +1,75 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - sitebranches.txt                                //
+//                                                                                 //
+//      Implementing codon site-branch models using the [BRANCHES] command         //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+  /* 
+    Site-branch models are defined just like branch models except the individual models 
+    have more site classes (i.e. omega categories). Different models can be defined for 
+    every branch on the tree if desired and there is no limit on the number of site 
+    classes that can be defined. However, it is important to remember that the number 
+    of site classes (and their relative proportions) cannot change on the tree.
+
+    Also, the genetic code is not permitted to change but everything else is, including:
+    kappa, omega, stationary frequencies, and the indel rates and length distributions. 
+    The examples below will only show omega changing amongst models.
+  */ 
+
+<font color=red>[TYPE] CODON 1    </font>                
+
+  /* Notice that the number of classes and proportions do not change below. */
+
+                   // Kap p0  p1  w0  w1  w2     (p2=1-p1-p0=0.5) 
+<font color=red>[MODEL] x1 [submodel] 2.5 0.2 0.3 0.0 0.5 1.0</font> 
+<font color=red>[MODEL] x2 [submodel] 2.5 0.2 0.3 0.1 1.0 3.0</font>  
+<font color=red>[MODEL] x3 [submodel] 2.5 0.2 0.3 0.2 2.0 6.0</font>  
+                            
+  /* 
+     Like before, to get a correctly formatted [BRANCHES] block from a [TREE] block
+     simply cut and paste the tree and change the branch lengths to model names.
+     The stationary frequencies of the model at the root are used to generate the
+     root sequence and this model defines the number of site categories used.
+  */
+
+<font color=red>[TREE]     t1  ((A:1.0, B:1.0):1.0,(C:1.0, D:1.0):1.0);  </font>
+
+<font color=red>[BRANCHES] b1  ((A #x1, B #x2) #x1,(C #x1, D #x3) #x1)#x1;  </font>
+
+
+          
+<font color=red>[PARTITIONS] Pname  [t1 b1 1000]</font>    // tree t1, branchclass b1, root length 1000
+
+<font color=red>[EVOLVE]     Pname  10  outputname</font>  // 10 replicates generated from partition Pname
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+/*
+   If (instead of model names) we write omega values after the # symbol
+   on branches in a tree then the branches class b1 above is the same 
+   as saying that different sites will evolve according to the following:
+    
+      <font color=blue>0.2   ( (A #0.0, B#0.1) #0.0,(C #0.0, D #0.2) #0.0); </font>
+      <font color=blue>0.3   ( (A #0.5, B#1.0) #0.5,(C #0.5, D #2.0) #0.5); </font>
+      <font color=blue>0.5   ( (A #1.0, B#3.0) #1.0,(C #1.0, D #6.0) #1.0); </font>
+
+    i.e. 20% of sites will evolve with omega=0 except on the branch to B 
+           where omega = 0.1 and on the branch to D where omega = 0.2,
+         30% of sites will evolve with omega=0.5 except on the branch to B 
+           where omega = 1 and on the branch to D where omega = 2,
+         50% of sites will evolve with omega=1.0 except on the branch to B 
+           where omega = 3 and on the branch to D where omega = 6.
+
+    A format similar to above is used by Evolver in the PAML suite for simulating
+    under branch-site codon models. However, the method implemented in INDELible 
+    also allows for kappa, stationary frequencies and indel parameters to change too.
+ 
+    Also, see extra relevant notes at the end of the file branch.txt <a href="http://abacus.gene.ucl.ac.uk/software/indelible/tutorial/branch.shtml">here</a>
+*/
+</pre>
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/trees.shtml b/help/example_files/trees.shtml
new file mode 100644
index 0000000..74848fd
--- /dev/null
+++ b/help/example_files/trees.shtml
@@ -0,0 +1,185 @@
+<!--#include file="files/top.html" -->
+
+<pre>
+/////////////////////////////////////////////////////////////////////////////////////
+//                                                                                 //
+//  INDELible V1.03 control file - trees.txt                                       //
+//                                                                                 //
+//      How to define user trees and how to generate random trees...               //
+//                                                                                 //
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+<font color=red>[TYPE] NUCLEOTIDE 1</font>	//  nucleotide simulation using algorithm from method 1
+
+
+<font color=red>[MODEL] mymodel  [submodel]  JC  </font>     
+
+
+  //  You will have already come across user-defined trees in the other examples. 
+  //  The following three trees are identical - "white space" of any kind is ignored.
+
+<font color=red>[TREE] t1 ((A:0.1,B:0.1):0.1,(C:0.1,D:0.1):0.1);</font>
+
+<font color=red>[TREE] t2 ( (A:0.1, B:0.1):0.1, (C:0.1, D:0.1):0.1 );</font>
+
+<font color=red>[TREE] t3 </font>
+<font color=red>    (         </font>    // trees can span any number of lines
+<font color=red>      (       </font>    // and include any amount of whitespace
+<font color=red>        A:0.1, </font>   // including new lines.
+<font color=red>        B:0.1  </font>  
+<font color=red>      ):0.1 ,  </font>   // comments within the tree will be ignored.
+<font color=red>     (C:0.1,D:0.1):0.1); </font>
+
+  //  But any tree can also be rescaled to be a certain tree length.
+  //  For example the two following trees are identical.
+<font color=red>
+[TREE] T1 ((A:0.1,B:0.2):0.3,(C:0.4,D:0.5):0.6);
+[treelength] 4.2
+
+[TREE] T2 ((A:0.2,B:0.4):0.6,(C:0.8,D:1.0):1.2);
+</font>
+  
+   //  Random rooted & unrooted trees can also be created by INDELible. 
+   //  A different tree will be generated for each replicate.
+   //  Explanation of these commands follow the examples...
+<font color=red>
+[TREE] tree1
+  [unrooted] 10 2.4 1.1 0.2566 0.34  </font>// ntaxa birth death sample mut
+<font color=red>
+[TREE] tree2
+  [unrooted] 10 2.4 1.1 0.2566 0.34  </font>// ntaxa birth death sample mut
+  <font color=red>[seed] 2381242     </font>                
+ <font color=red>
+[TREE] tree3
+  [rooted] 15 6.7 2.5 0.234 0.31     </font>// ntaxa birth death sample mut
+  <font color=red>[treedepth] 0.4</font></font>
+<font color=red>
+[TREE] tree4
+  [rooted] 15 6.7 2.5 0.234 0.31     </font>// ntaxa birth death sample mut
+  <font color=red>[treelength] 8</font></font>
+
+/*
+  * Random trees always have taxa names that are numbers. 
+    e.g. (1:0.1,2:0.1,(3:0.1,4:0.1):0.1);
+
+  * <font color=blue>tree1</font> and <font color=blue>tree2</font> will be unrooted random trees.
+  * <font color=blue>tree3</font> and <font color=blue>tree4</font> will be rooted random trees. 
+
+  * Every time that INDELible is run <font color=blue>tree2</font> will produce the same sequence 
+    of random trees, until the number after the <font color=blue>[seed]</font> command is changed. 
+  * The others (<font color=blue>tree1</font>, <font color=blue>tree3</font> and <font color=blue>tree4</font>) will always produce different trees.
+  * Please note that the <font color=blue>[seed]</font> command overrules the <font color=blue>[randomseed]</font> 
+    command from a <font color=blue>[SETTINGS]</font> block, for a random tree.
+
+  * <font color=blue>tree4</font> will produce random trees that are always rescaled to have a tree 
+    length of 8, and <font color=blue>tree3</font> will produce random trees that are always rescaled 
+    to have a depth (root to tip) of 0.4, whilst the other two (<font color=blue>tree1</font> and 
+    <font color=blue>tree2</font>) will always produce random trees with different tree lengths/depths.
+
+  * The numbers that come after the <font color=blue>[unrooted]</font> and <font color=blue>[rooted]</font> commands are 
+    the same in both cases.  The first number is the number of taxa 
+    (10 for tree1 and tree2, 15 for tree3 and tree4).
+  * The next  four are the parameters used in the birth-death process to 
+    create the random trees. In order, from left to right, these are the 
+    <font color=blue>birth-rate</font>, <font color=blue>death-rate</font>, <font color=blue>sampling fraction</font> and <font color=blue>mutation rate</font>. 
+    Further details on these parameters can be found in this paper: 
+    <a href="http://abacus.gene.ucl.ac.uk/ziheng/pdf/1997YangRannalaMBEv14p717.pdf" target="_blank">http://abacus.gene.ucl.ac.uk/ziheng/pdf/1997YangRannalaMBEv14p717.pdf</a>
+
+  * Trees (random or user) that are used during the simulation will be output 
+    by INDELible in a file <a href="trees.txt" target="_blank">like this</a>.
+
+  * One last point to remember about random trees is that they CANNOT be 
+    used when you want the evolutionary model to be permitted to change 
+    over the tree. i.e. they CANNOT be used with [BRANCHES] blocks.
+   
+*/
+
+
+   //  For a given topology INDELible can also create branch lengths. 
+   //  This is done by using the command [branchlengths]
+   //  Further explanation of the four examples is given below
+
+<font color=red>
+<a name="branchlengths"></a>
+[TREE] EQUAL-TREE
+ </font> // No branch lengths need to be provided<font color=red>  
+  ((((A,B),(C,D)),((E,F),(G,H))),(((I,J),(K,L)),((M,N),(O,P))));
+       
+  [branchlengths] EQUAL </font>// All branch lengths will be equal
+  <font color=red>[treedepth] 0.1</font>       // Root-to-longest-tip distance of 0.1
+<font color=red>
+[TREE] EQUAL-TREE2
+</font>  // If branch lengths are provided, they are ignored<font color=red>
+  ((((A:0.2,B:0.1):0.4,(C:0.3,D:0.1):0.6):0.1,
+  ((E:0.1,F:0.1):0.1,(G:0.2,H:0.1):0.1):0.3):0.1,
+  (((I:0.1,J:0.6):0.1,(K:0.1,L:0.1):0.1):0.1,
+  ((M:0.4,N:0.1):0.1,(O:0.6,P:0.1):0.1):0.1):0.1); 
+
+  [branchlengths] EQUAL </font>// Again, all branch lengths will be equal
+  <font color=red>[treedepth] 0.1</font>       // Root-to-longest-tip distance of 0.1
+ <font color=red>
+[TREE] ULTRAMETRIC-TREE
+ </font> // No branch lengths need to be provided<font color=red>  
+  ((((A,B),(C,D)),((E,F),(G,H))),(((I,J),(K,L)),((M,N),(O,P))));
+
+  [branchlengths] ULTRAMETRIC </font>// All branch lengths will be equal
+  <font color=red>[treedepth] 0.1</font>             // Root-to-longest-tip distance of 0.1
+<font color=red>
+[TREE] NON-ULTRAMETRIC-TREE
+ </font> // No branch lengths need to be provided<font color=red>  
+  ((((A,B),(C,D)),((E,F),(G,H))),(((I,J),(K,L)),((M,N),(O,P))));
+
+  [branchlengths] NON-ULTRAMETRIC </font>// All branch lengths will be equal
+  <font color=red>[maxdistance] 0.2</font>               // Maximum pairwise distance of 0.2
+
+
+  
+/*
+  * <font color=blue>[treedepth] 0.1</font> rescales the tree to have a maximum root-to-tip distance of 0.1
+  * After using the <font color=blue>[branchlengths]</font> command you should use <font color=blue>[treelength]</font> or 
+    <font color=blue>[treedepth]</font>, or <font color=blue>[maxdistance]</font> to rescale your tree.
+
+  * <font color=blue>[branchlengths] EQUAL</font> will make every branch on the tree equal to 0.1.
+  * <font color=blue>[branchlengths] NON-ULTRAMETRIC</font> gives every branch a random length between 0 and 1.
+  * <font color=blue>[branchlengths] ULTRAMETRIC</font> gives every branch a random length between 0 and 1, 
+    but will also extend the terminal branches so that the root-to-tip distance is 
+    the same for every tip.
+
+  * If the <font color=blue>[branchlengths]</font> command is used then the tree toplogy can be specified 
+    with or without branch lengths. It does not matter. Any branch lengths will be ignored.
+    i.e. the trees EQUAL-TREE and EQUAL-TREE2 will be identical.
+
+  * Examples of the trees produced above can be seen <a href="random_branch_length_trees.JPG">here</a>.
+  
+  * All trees in the image are rescaled to have a maximum tree-depth of 0.1. 
+    This means that the root-to-tip distance for taxon G is equal to 0.1 in all 3 trees.
+
+  * N.B. For ultrametric trees <font color=blue>[maxdistance] 0.2</font> is equivalent to <font color=blue>[treedepth] 0.1</font>
+    For the non-ultrametric tree they are not the same.
+    <font color=blue>[maxdistance] 0.2</font> on the non-ultrametric tree scales the tree such that the sum of 
+    the branch lengths in between (in <a href="random_branch_length_trees.JPG">this</a> case) taxons G and N would be 0.2
+
+*/
+
+
+<font color=red>[PARTITIONS] Pname1  [t1 mymodel 1000]</font>   // tree t1, model mymodel, root length 1000
+<font color=red>[PARTITIONS] Pname2  [t2 mymodel 1000]</font>   // tree t2, model mymodel, root length 1000
+<font color=red>[PARTITIONS] Pname3  [t3 mymodel 1000]</font>   // tree t3, model mymodel, root length 1000
+<font color=red>[PARTITIONS] Pname4  [T1 mymodel 1000]</font>   // tree T1, model mymodel, root length 1000
+<font color=red>[PARTITIONS] Pname5  [T2 mymodel 1000]</font>   // tree T2, model mymodel, root length 1000
+
+
+ 
+<font color=red>[EVOLVE]     Pname1  10  outputname1</font>     // 10 replicates generated from partition Pname1
+<font color=red>             Pname2  10  outputname2</font>     // 10 replicates generated from partition Pname2
+<font color=red>             Pname3  10  outputname3</font>     // 10 replicates generated from partition Pname3
+<font color=red>             Pname4  10  outputname4</font>     // 10 replicates generated from partition Pname4
+<font color=red>             Pname5  10  outputname5</font>     // 10 replicates generated from partition Pname5
+
+</pre>
+<br><hr><br>
+Please click <a href="http://abacus.gene.ucl.ac.uk/software/indelible/tutorial/">here</a> to return to the tutorial menu page for more examples.
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/example_files/trees.txt b/help/example_files/trees.txt
new file mode 100644
index 0000000..3c72ac2
--- /dev/null
+++ b/help/example_files/trees.txt
@@ -0,0 +1,60 @@
+Tree file : INDELible V1.00 
+
+N.B. Simulation blocks with no random trees will have their trees printed for the first replicate only.
+
+FILE	TREE	NTAXA	REP	PART	LENGTH		TREE STRING
+p1a	t1	16	1	1	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p1b	t1	16	1	1	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1b	t2	16	1	2	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1b	t3	16	1	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p1	tree5	16	1	1	2.07469 	(((10:0.0251716,2:0.0251716):0.225636,((16:0.11026,12:0.11026):0.0179151,(1:0.104375,((8:0.0237011,5:0.0237011):0.0432994,6:0.0670005):0.0373747):0.0237997):0.122633):0.0591923,(((11:0.130562,(15:0.101111,((9:0.0257804,(7:0.0206163,14:0.0206163):0.00516404):0.0246742,3:0.0504546):0.0506567):0.0294507):0.0699838,13:0.200546):0.0155818,4:0.216128):0.0938724);
+p1	tree6	16	1	2	8.00001 	(((((11:0.55303,(((9:0.149849,3:0.149849):0.0855073,14:0.235356):0.0242804,(7:0.100483,2:0.100483):0.159153):0.293392):0.00305025,8:0.556081):0.0753802,((6:0.407102,(10:0.0566947,12:0.0566947):0.350407):0.127903,(4:0.310611,16:0.310611):0.224394):0.0964549):0.0196918,((13:0.564191,15:0.564191):0.0841506,1:0.648343):0.00280967):0.519353,5:1.17051);
+p1	t1	16	1	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	2	1	2.14452 	(((12:0.0575492,(10:0.0355436,5:0.0355436):0.0220056):0.0149737,15:0.0725229):0.237477,((14:0.129775,16:0.129775):0.110644,((((6:0.021887,9:0.021887):0.0611004,(3:0.0624181,(8:0.0434107,(1:0.0361316,7:0.0361316):0.00727905):0.0190075):0.0205693):0.0851256,(4:0.162494,13:0.162494):0.005619):0.0455205,(2:0.197639,11:0.197639):0.0159947):0.0267857):0.0695807);
+p1	tree6	16	2	2	8		(((((5:0.171401,(13:0.0492202,11:0.0492202):0.122181):0.255348,((14:0.0618468,7:0.0618468):0.269745,15:0.331592):0.0951573):0.10226,(12:0.514306,(((1:0.141204,8:0.141204):0.0163946,10:0.157599):0.202264,16:0.359863):0.154445):0.0147004):0.66522,6:1.19423):0.155977,((4:0.0282738,9:0.0282738):0.684942,(2:0.621086,3:0.621086):0.0921285):0.636988);
+p1	t1	16	2	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	3	1	1.735 		(((12:0.0975239,6:0.0975239):0.0611663,(((13:0.0688148,(((2:0.018292,16:0.018292):0.0144716,7:0.0327637):0.00907203,5:0.0418357):0.0269791):0.00323871,14:0.0720535):0.0798468,1:0.1519):0.00678992):0.15131,(((9:0.0962845,8:0.0962845):0.0056347,((10:0.0368431,(3:0.0210577,11:0.0210577):0.0157854):0.0296972,15:0.0665403):0.0353789):0.0485615,4:0.150481):0.159519);
+p1	tree6	16	3	2	8		(((2:0.0015762,10:0.0015762):0.933616,(12:0.726972,(6:0.563104,((14:0.385092,13:0.385092):0.00288606,((3:0.0168091,(8:0.00931587,7:0.00931587):0.00749325):0.231392,16:0.248201):0.139778):0.175126):0.163869):0.208219):0.909205,(9:0.417326,(((4:0.00506781,11:0.00506781):0.127212,5:0.132279):0.181356,(15:0.168658,1:0.168658):0.144978):0.10369):1.42707);
+p1	t1	16	3	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	4	1	2.73732 	(((((((12:0.0929284,6:0.0929284):0.0310408,((14:0.0420909,7:0.0420909):0.0712017,10:0.113293):0.0106765):0.096479,15:0.220448):0.0275901,2:0.248038):0.00894932,((4:0.0610078,1:0.0610078):0.16738,11:0.228387):0.0286001):0.0197955,5:0.276783):0.033217,((13:0.0987875,16:0.0987875):0.0674287,(8:0.119003,(3:0.0693831,9:0.0693831):0.0496202):0.0472129):0.143784);
+p1	tree6	16	4	2	8		(((16:0.388518,((6:0.32561,9:0.32561):0.0237181,(14:0.284777,3:0.284777):0.0645518):0.0391898):0.524666,13:0.913184):0.286973,((8:0.310698,(10:0.28525,15:0.28525):0.0254482):0.690973,((4:0.179299,7:0.179299):0.333821,((((5:0.0854129,2:0.0854129):0.00325413,12:0.0886673):0.32849,1:0.417155):0.0398375,11:0.456993):0.0561259):0.488549):0.198487);
+p1	t1	16	4	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	5	1	1.8936		((((12:0.0668171,(16:0.0579271,2:0.0579271):0.00889005):0.0572596,(8:0.0588584,7:0.0588584):0.0652184):0.0590675,(6:0.0889992,(5:0.0265993,(15:0.0119911,1:0.0119911):0.0146082):0.0623999):0.0941451):0.126856,(13:0.204947,(3:0.153933,(4:0.136852,(((9:0.0199244,10:0.0199244):0.0325816,11:0.0525059):0.0345205,14:0.0870265):0.0498254):0.0170807):0.0510144):0.105053);
+p1	tree6	16	5	2	8		((((((15:0.0693106,6:0.0693106):0.44311,((10:0.204551,5:0.204551):0.0607202,16:0.265271):0.247149):0.0414907,(13:0.00408851,9:0.00408851):0.549822):0.367133,(((11:0.316018,12:0.316018):0.0240882,(4:0.0994128,7:0.0994128):0.240694):0.430903,14:0.77101):0.150034):0.073126,(2:0.549335,8:0.549335):0.444834):0.0540178,(3:0.302978,1:0.302978):0.745211);
+p1	t1	16	5	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p2	tree4	16	1	1	2.8485		(((((5:0.112557,3:0.112557):0.114089,11:0.226645):0.0265085,((4:0.0278513,10:0.0278513):0.179506,6:0.207358):0.0457964):0.0471312,((7:0.0798369,8:0.0798369):0.132501,((12:0.127369,(2:0.0874179,14:0.0874179):0.0399507):0.0423396,15:0.169708):0.0426297):0.0879471):0.00294979,(13:0.117293,(1:0.0169825,16:0.0169825):0.10031):0.185942,9:0.303235);
+p2	tree4	16	2	1	3.31545 	(((4:0.307894,((11:0.0321027,(8:0.01745,14:0.01745):0.0146527):0.233149,(9:0.202673,(6:0.0713661,(7:0.0456646,13:0.0456646):0.0257015):0.131307):0.0625789):0.0426418):0.0206553,2:0.328549):0.000983572,(10:0.119042,1:0.119042):0.210491,((12:0.281206,(15:0.212231,(5:0.147151,3:0.147151):0.0650795):0.0689751):0.0150686,16:0.296274):0.0332583);
+p2	tree4	16	3	1	3.42676 	(((8:0.0352956,(5:0.00783672,11:0.00783672):0.0274589):0.24574,15:0.281035):0.0532647,((1:0.102692,10:0.102692):0.19055,(4:0.238645,12:0.238645):0.0545974):0.0410577,(((9:0.1825,14:0.1825):0.0939923,(7:0.0973296,3:0.0973296):0.179162):0.0139557,((13:0.219061,(16:0.175524,6:0.175524):0.0435363):0.00469507,2:0.223756):0.066692):0.043852);
+p2	tree4	16	4	1	3.09609 	((((16:0.234742,(4:0.065675,14:0.065675):0.169067):0.00109323,10:0.235835):0.0273879,12:0.263223):0.073974,((((5:0.110609,9:0.110609):0.0307443,6:0.141353):0.0703576,((7:0.0722642,3:0.0722642):0.105236,8:0.1775):0.0342104):0.0282193,(2:0.162816,(13:0.0345524,11:0.0345524):0.128263):0.0771144):0.0972669,(15:0.134284,1:0.134284):0.202913);
+p2	tree4	16	5	1	3.29314 	(((((16:0.0741958,14:0.0741958):0.0266528,(8:0.0628713,10:0.0628713):0.0379773):0.188173,(9:0.237269,13:0.237269):0.0517527):0.00700942,(2:0.278772,((5:0.174857,(6:0.12343,(4:0.113574,7:0.113574):0.00985668):0.0514261):0.0725645,1:0.247421):0.0313511):0.0172585):0.0423361,3:0.338367,(12:0.181036,(11:0.0987093,15:0.0987093):0.082327):0.15733);
+
+p7	tree4	16	1	1	2.8485		(((((5:0.112557,3:0.112557):0.114089,11:0.226645):0.0265085,((4:0.0278513,10:0.0278513):0.179506,6:0.207358):0.0457964):0.0471312,((7:0.0798369,8:0.0798369):0.132501,((12:0.127369,(2:0.0874179,14:0.0874179):0.0399507):0.0423396,15:0.169708):0.0426297):0.0879471):0.00294979,(13:0.117293,(1:0.0169825,16:0.0169825):0.10031):0.185942,9:0.303235);
+p7	tree6	16	1	2	8		((14:0.487088,(2:0.126887,13:0.126887):0.3602):1.06951,(((5:0.141802,12:0.141802):0.590438,((9:0.186562,((7:0.0520105,10:0.0520105):0.103103,16:0.155114):0.0314484):0.326649,1:0.51321):0.219028):0.105282,(((6:0.154349,(4:0.0545005,11:0.0545005):0.0998482):0.390959,(15:0.062744,3:0.062744):0.482564):0.292161,8:0.83747):5.18287e-05):0.719078);
+p7	t1	16	1	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	2	1	3.31545 	(((4:0.307894,((11:0.0321027,(8:0.01745,14:0.01745):0.0146527):0.233149,(9:0.202673,(6:0.0713661,(7:0.0456646,13:0.0456646):0.0257015):0.131307):0.0625789):0.0426418):0.0206553,2:0.328549):0.000983572,(10:0.119042,1:0.119042):0.210491,((12:0.281206,(15:0.212231,(5:0.147151,3:0.147151):0.0650795):0.0689751):0.0150686,16:0.296274):0.0332583);
+p7	tree6	16	2	2	8		(16:1.25506,((((7:0.116597,11:0.116597):0.124659,(15:0.142871,5:0.142871):0.0983849):0.0725679,(14:0.311169,2:0.311169):0.00265526):0.668951,((((8:0.412028,10:0.412028):0.0674837,(3:0.373415,(9:0.174412,4:0.174412):0.199003):0.106097):0.0535935,(6:0.264671,13:0.264671):0.268434):0.0581441,(1:0.552995,12:0.552995):0.0382555):0.391525):0.272284);
+p7	t1	16	2	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	3	1	3.42676 	(((8:0.0352956,(5:0.00783672,11:0.00783672):0.0274589):0.24574,15:0.281035):0.0532647,((1:0.102692,10:0.102692):0.19055,(4:0.238645,12:0.238645):0.0545974):0.0410577,(((9:0.1825,14:0.1825):0.0939923,(7:0.0973296,3:0.0973296):0.179162):0.0139557,((13:0.219061,(16:0.175524,6:0.175524):0.0435363):0.00469507,2:0.223756):0.066692):0.043852);
+p7	tree6	16	3	2	8		((5:0.717836,10:0.717836):0.365796,((8:0.188465,1:0.188465):0.795659,(((4:0.275071,3:0.275071):0.314526,((15:0.200236,12:0.200236):0.229528,(14:0.361098,(6:0.275461,16:0.275461):0.0856381):0.0686649):0.159833):0.0760304,(11:0.450497,(13:0.389999,((2:0.0336032,7:0.0336032):0.237755,9:0.271359):0.11864):0.0605002):0.215129):0.318496):0.0995089);
+p7	t1	16	3	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	4	1	3.09609 	((((16:0.234742,(4:0.065675,14:0.065675):0.169067):0.00109323,10:0.235835):0.0273879,12:0.263223):0.073974,((((5:0.110609,9:0.110609):0.0307443,6:0.141353):0.0703576,((7:0.0722642,3:0.0722642):0.105236,8:0.1775):0.0342104):0.0282193,(2:0.162816,(13:0.0345524,11:0.0345524):0.128263):0.0771144):0.0972669,(15:0.134284,1:0.134284):0.202913);
+p7	tree6	16	4	2	8		(((14:0.44356,(6:0.418219,15:0.418219):0.0253389):0.353999,((5:0.65665,(13:0.647129,((11:0.20976,9:0.20976):0.257568,8:0.467327):0.179799):0.00952174):0.00739611,(7:0.537691,3:0.537691):0.126354):0.133512):0.197561,((1:0.169463,(2:0.0351903,10:0.0351903):0.134272):0.319193,((16:0.162323,12:0.162323):0.14987,4:0.312193):0.176462):0.506464);
+p7	t1	16	4	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	5	1	3.29314 	(((((16:0.0741958,14:0.0741958):0.0266528,(8:0.0628713,10:0.0628713):0.0379773):0.188173,(9:0.237269,13:0.237269):0.0517527):0.00700942,(2:0.278772,((5:0.174857,(6:0.12343,(4:0.113574,7:0.113574):0.00985668):0.0514261):0.0725645,1:0.247421):0.0313511):0.0172585):0.0423361,3:0.338367,(12:0.181036,(11:0.0987093,15:0.0987093):0.082327):0.15733);
+p7	tree6	16	5	2	8		((11:0.770019,(10:0.182883,7:0.182883):0.587135):0.444682,((2:0.783165,((((((16:0.0278589,1:0.0278589):0.162142,8:0.190001):0.209444,13:0.399445):0.00428104,4:0.403727):0.0557297,(6:0.393446,12:0.393446):0.0660119):0.0864789,14:0.545934):0.23723):0.03592,(5:0.481292,((15:0.0430772,9:0.0430772):0.0281307,3:0.0712081):0.410083):0.337794):0.395616);
+p7	t1	16	5	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p3	tree5	16	1	1	1.75504 	((((((2:0.0359762,12:0.0359762):0.0163278,5:0.052304):0.023317,(11:0.0710584,16:0.0710584):0.00456256):0.0104657,10:0.0860867):0.0157686,(6:0.0900789,((7:0.0274396,1:0.0274396):0.0360231,4:0.0634627):0.0266162):0.0117763):0.208145,((((13:0.000951513,3:0.000951513):0.0340047,8:0.0349562):0.133207,14:0.168164):0.106116,(15:0.0528084,9:0.0528084):0.221471):0.0357209);
+p3	tree5	16	2	1	1.63435 	((15:0.109502,14:0.109502):0.200498,(((4:0.106899,(((10:0.000968828,1:0.000968828):0.0581853,((9:0.00120325,7:0.00120325):0.0554193,(8:0.054203,(5:0.0412523,16:0.0412523):0.0129507):0.00241962):0.00253158):0.0433431,2:0.102497):0.00440143):0.0644602,((13:0.0246952,3:0.0246952):0.0183126,11:0.0430078):0.128351):0.00880369,(12:0.0628254,6:0.0628254):0.117337):0.129837);
+p3	tree5	16	3	1	2.25393 	((((5:0.134281,(13:0.100718,((6:0.0341843,12:0.0341843):0.0385873,(3:0.0689088,8:0.0689088):0.00386283):0.0279463):0.0335631):0.0643055,(((2:0.030439,15:0.030439):0.0823861,9:0.112825):0.0237421,7:0.136567):0.0620193):0.0186373,(4:0.125324,(16:0.0585481,11:0.0585481):0.0667755):0.0919003):0.0927761,(10:0.23649,(14:0.107067,1:0.107067):0.129423):0.0735102);
+p3	tree5	16	4	1	2.2668		(3:0.31,((((1:0.105771,(14:0.104195,(13:0.0277489,2:0.0277489):0.0764459):0.00157609):0.0053371,(16:0.00953588,5:0.00953588):0.101572):0.0551514,(9:0.0294335,15:0.0294335):0.136826):0.0704364,(((8:0.145421,4:0.145421):0.00862213,(10:0.0953953,7:0.0953953):0.0586481):0.0311614,(12:0.166533,(6:0.109454,11:0.109454):0.0570781):0.0186722):0.0514911):0.0733041);
+p3	tree5	16	5	1	1.9882		(((((7:0.0600188,4:0.0600188):0.00813354,1:0.0681523):0.089071,((((6:0.104907,9:0.104907):0.00692074,(((12:0.0537501,13:0.0537501):0.0209333,5:0.0746834):0.00248677,10:0.0771702):0.0346573):0.011542,(3:0.0433617,(11:0.0264326,16:0.0264326):0.0169292):0.0800078):0.00453639,8:0.127906):0.0293175):0.0637721,(2:0.118399,14:0.118399):0.102596):0.0890046,15:0.31);
+
+p4	tree6	16	1	1	8		((13:0.203328,5:0.203328):0.820493,((16:0.288933,1:0.288933):0.422177,(((4:0.629042,(((2:0.158208,12:0.158208):0.418452,15:0.576662):0.0502138,9:0.626875):0.00216817):0.0328959,((6:0.425625,((3:0.1651,(11:0.154244,7:0.154244):0.0108556):0.0368995,14:0.201999):0.223628):0.0502607,10:0.475888):0.186051):0.0114662,8:0.673403):0.0377067):0.312709);
+p4	tree6	16	2	1	8		((12:0.612383,(10:0.277312,16:0.277312):0.335072):0.704844,(8:1.31255,((7:0.526814,(((5:0.275105,4:0.275105):0.15673,15:0.431834):0.0313425,(2:0.301107,((14:0.065467,1:0.065467):0.184595,13:0.250062):0.0510455):0.16207):0.0636365):0.0644863,(3:0.16065,((9:0.0411075,6:0.0411075):0.0155733,11:0.0566807):0.10397):0.430648):0.721245):0.00468028);
+p4	tree6	16	3	1	8		((9:0.808603,((((((1:0.261297,(4:0.209442,(2:0.18019,15:0.18019):0.029252):0.0518549):0.00204327,12:0.26334):0.00450785,(14:0.25266,7:0.25266):0.0151881):0.0752688,10:0.343117):0.119999,11:0.463118):0.224235,(5:0.388933,13:0.388933):0.298418):0.121251):0.531461,(((8:0.116294,3:0.116294):0.308149,6:0.424444):0.228794,16:0.653238):0.686826);
+p4	tree6	16	4	1	8		(2:1.25157,(((7:0.0331616,3:0.0331616):0.155006,13:0.188168):1.03387,(15:0.706163,((((11:0.00174269,6:0.00174269):0.0175912,1:0.0193339):0.573283,(5:0.530758,10:0.530758):0.0618586):0.0203591,((16:0.0816713,4:0.0816713):0.502428,((9:0.0632228,14:0.0632228):0.426785,(8:0.370903,12:0.370903):0.119104):0.0940917):0.0288772):0.0931865):0.515876):0.0295296);
+p4	tree6	16	5	1	8		((9:1.04182,(((((1:0.152451,6:0.152451):0.167588,13:0.320039):0.0359561,2:0.355995):0.148171,12:0.504165):0.498338,(10:0.701825,((7:0.0113513,16:0.0113513):0.508482,5:0.519833):0.181993):0.300681):0.0393138):0.0252188,(((3:0.184398,4:0.184398):0.179885,(11:0.128553,(15:0.0635779,14:0.0635779):0.0649751):0.23573):0.150844,8:0.515128):0.55191);
diff --git a/help/example_files/userAAmodel.txt b/help/example_files/userAAmodel.txt
new file mode 100644
index 0000000..a2e1103
--- /dev/null
+++ b/help/example_files/userAAmodel.txt
@@ -0,0 +1,23 @@
+ 
+0.267828 
+0.984474 0.327059 
+1.199805 0.000000 8.931515 
+0.360016 0.232374 0.000000 0.000000 
+0.887753 2.439939 1.028509 1.348551 0.000000 
+1.961167 0.000000 1.493409 11.388659 0.000000 7.086022 
+2.386111 0.087791 1.385352 1.240981 0.107278 0.281581 0.811907 
+0.228116 2.383148 5.290024 0.868241 0.282729 6.011613 0.439469 0.106802 
+0.653416 0.632629 0.768024 0.239248 0.438074 0.180393 0.609526 0.000000 0.076981 
+0.406431 0.154924 0.341113 0.000000 0.000000 0.730772 0.112880 0.071514 0.443504 2.556685 
+0.258635 4.610124 3.148371 0.716913 0.000000 1.519078 0.830078 0.267683 0.270475 0.460857 0.180629 
+0.717840 0.896321 0.000000 0.000000 0.000000 1.127499 0.304803 0.170372 0.000000 3.332732 5.230115 2.411739 
+0.183641 0.136906 0.138503 0.000000 0.000000 0.000000 0.000000 0.153478 0.475927 1.951951 1.565160 0.000000 0.921860 
+2.485920 1.028313 0.419244 0.133940 0.187550 1.526188 0.507003 0.347153 0.933709 0.119152 0.316258 0.335419 0.170205 0.110506 
+4.051870 1.531590 4.885892 0.956097 1.598356 0.561828 0.793999 2.322243 0.353643 0.247955 0.171432 0.954557 0.619951 0.459901 2.427202 
+3.680365 0.265745 2.271697 0.660930 0.162366 0.525651 0.340156 0.306662 0.226333 1.900739 0.331090 1.350599 1.031534 0.136655 0.782857 5.436674 
+0.000000 2.001375 0.224968 0.000000 0.000000 0.000000 0.000000 0.000000 0.270564 0.000000 0.461776 0.000000 0.000000 0.762354 0.000000 0.740819 0.000000 
+0.244139 0.078012 0.946940 0.000000 0.953164 0.000000 0.214717 0.000000 1.265400 0.374834 0.286572 0.132142 0.000000 6.952629 0.000000 0.336289 0.417839 0.608070 
+2.059564 0.240368 0.158067 0.178316 0.484678 0.346983 0.367250 0.538165 0.438715 8.810038 1.745156 0.103850 2.565955 0.123606 0.485026 0.303836 1.561997 0.000000 0.279379 
+
+
+0.087127 0.040904 0.040432 0.046872 0.033474 0.038255 0.049530 0.088612 0.033619 0.036886 0.085357 0.080481 0.014753 0.039772 0.050680 0.069577 0.058542 0.010494 0.029916 0.064718 
diff --git a/help/examples.shtml b/help/examples.shtml
new file mode 100644
index 0000000..ed02787
--- /dev/null
+++ b/help/examples.shtml
@@ -0,0 +1,62 @@
+<!--#include file="example_files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>Tutorial Section</h2>
+
+
+<p>
+<li>Below are example control files that introduce the different features available in INDELible.  </li>
+<li>Each example file is annotated with actual commands shown in <font color=red>red</font>.  </li>
+<li>At the beginning or end of most files there are some explanations of what is in the file.  </li>
+<li>This tutorial and text versions of all the control files are included in the download package. </li>
+<li>There is a lot of overlap with the manual section - which is designed to be a command reference guide that you can dip into when you want to 
+know about one command or block type.</li>
+<li>In contrast, this tutorial section includes real control files that gradually introduce new & more complex features in real settings.</li>
+<li>If you are new to INDELible then it is recommended to read the examples in order.</li>
+</p>
+<br>
+
+<hr>
+
+
+<ul>
+<br><p><u><b>Simple Examples:</u></b></p>
+<li><a href="example_files/basicnucleotide.shtml">This very simple control file</a> will show you the <font color=blue>basic format</font> of the INDELible control file for <font color=blue>nucleotide</font> simulations.</li>
+
+<li><a href="example_files/basicaminoacid.shtml">This very simple control file</a> will show you the <font color=blue>basic format</font> of the INDELible control file for <font color=blue>amino-acid</font> simulations.</li>
+<li><a href="example_files/basiccodon.shtml">This very simple control file</a> will show you the <font color=blue>basic format</font> of the INDELible control file for <font color=blue>codon</font> simulations.</li>
+
+
+<br><p><u><b>Evolutionary Models:</u></b></p>
+<li><a href="example_files/NUCLEOTIDE.shtml">This control file</a> will show you how to specify different <font color=blue>nucleotide substitution models</font>.</li>
+<li><a href="example_files/AMINOACID.shtml">This control file</a> will show you how to specify different <font color=blue>amino-acid substitution models</font>.</li>
+<li><a href="example_files/rates.shtml">This control file</a> will show you how to add <font color=blue>gamma rates</font> and/or a <font color=blue>proportion of 
+invariable sites</font>.</li>
+<li><a href="example_files/CODON.shtml">This control file</a> will show you how to specify <font color=blue>codon substitution models</font> & change the genetic code.</li>
+<li><a href="example_files/CODONsites.shtml">This control file</a> will show you how to specify different <font color=blue>codon site models</font>.</li>
+<li><a href="example_files/indels.shtml">This control file</a> will show you how to specify different <font color=blue>indel models</font>.</li>
+
+<br><p><u><b>Non-Homogenous Non-Stationary Models:</u></b></p>
+<li><a href="example_files/branch.shtml">This control file</a> will introduce you to letting models change across the tree, by showing 
+you how to implement <font color=blue>codon branch models</font> where <b>ω</b> can vary across the tree.</li>
+<li><a href="example_files/sitebranch.shtml">This control file</a> will show you how to implement <font color=blue>codon site-branch models</font>.</li>
+<li><a href="example_files/branch2.shtml">This control file</a> will go one step further and show you how <font color=blue>any aspect of a codon model can vary across the tree</font>, including 
+kappa, omega, the rates of insertion and deletion, and the insertion and deletion length distributions.</li>
+<li><a href="example_files/nucleotide-branch.shtml">This control file</a> will show you how to implement <font color=blue>changing models for nucleotide/amino-acid</font> simulations, including 
+changing stationary frequencies, substitution rates, levels of rate heterogeneity, indel rates and indel distributions.</li>
+<li><a href="example_files/multi-partitions.shtml">This control file</a> will show you how to generate <font color=blue>multi-partitioned</font> datasets</li>
+
+<br><p><u><b>Miscellaneous other examples</u></b></p>
+<li><a href="example_files/trees.shtml">This control file</a> will show you how to generate different kinds of <font color=blue>trees</font>.</li>
+<li><a href="example_files/settings.shtml">This control file</a> will show you how to change a number of non-essential <font color=blue>settings</font> such as seeds 
+for the random number generator, output file formats etc..</li>
+
+</ul>
+<br>
+
+
+
+
+
+
+<!--#include file="example_files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual.shtml b/help/manual.shtml
new file mode 100644
index 0000000..4a361cf
--- /dev/null
+++ b/help/manual.shtml
@@ -0,0 +1,57 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>Manual</h2>
+<p><font color=red>
+This manual is not designed as a tutorial. It is a command reference guide and is meant to be something to refer to when you want to 
+know about one command or block type. A <b>quicker</b> and <b>easier</b> way 
+to <b>learn</b> about INDELible for the first time would be to look the through the examples in the tutorial section. </font>
+<ul>
+<li>The INDELible control file is made up of 7 different "block" types as described below.</li>
+<li>It does not matter what order commands are specified inside a block.</li>
+<li>It does not matter what order blocks are specified in the control file except that the file must begin with a [TYPE] block.</li>
+<li>Control files must contain at least one [MODEL], [TREE] and [PARTITIONS] block and exactly one [EVOLVE] block. There are no other restrictions.</li>
+<li>INDELible tries to get instructions from a file named <i>control.txt</i> which must be located in the same directory as the INDELible executable.</li>
+<li>If no file named <i>control.txt</i> is found then you will be prompted to give the full filename of a suitable file for INDELible to parse.</li>
+<li>White space (e.g. tabs, spaces and new lines) is used to separate different commands and settings in the control file so it does not matter if commands or values span multiple lines.</li>
+<li>When INDELible sees <b>//</b> on a line then anything else on that line is ignored and when INDELible sees <b>/*</b> all text is ignored until after the next <b>*/</b>.</li>
+</ul></p>
+
+<br><hr><br>
+
+More information on the commands for each block can be found by following the links.<br>
+<br><pre><a href="manual_files/type.shtml">[TYPE]</a></pre>
+This block tells INDELible whether it is simulating under nucleotide, amino-acid or codon models and which algorithm to use.
+
+<br><pre><a href="manual_files/settings.shtml">[SETTINGS]</a></pre>
+This block specifies non-essential user preferences such as output file types and formats, seeds for the random number generator, and whether to output detailed reports.
+
+<br><pre><a href="manual_files/model.shtml">[MODEL]</a></pre>
+These blocks are used to specify all aspects of the evolutionary models used during simulation. There are a variety of commands available for specifying different 
+substitution models and indel models as well as rates of insertion and deletion to substitution etc. Codon site-models are defined here.
+
+<br><pre><a href="manual_files/tree.shtml">[TREE]</a></pre>
+These blocks can be used to set the parameters that control random rooted and unrooted guide tree generation or to define user-specified guide trees.
+
+<br><pre><a href="manual_files/branches.shtml">[BRANCHES]</a></pre>
+These blocks are used to simulate non-stationary and non-homogenous processes.  Different models from different [MODEL] blocks can be specified on different branches of the guide-tree 
+allowing branches to have different models of substitution, indel length distribution, rate heterogeneity, base composition etc.
+
+<br><pre><a href="manual_files/partitions.shtml">[PARTITIONS]</a></pre>
+This block type is used to set root lengths and to choose which models are used with which trees. In addition it is used when simulating multi-partitioned datasets where different sections 
+of the simulated dataset are created with different trees and models.
+
+<br><pre><a href="manual_files/evolve.shtml">[EVOLVE]</a></pre>
+This block tells INDELible how many replicates to generate from each [PARTITIONS] block and what the output files should be named.
+
+
+
+
+
+
+
+<br>
+
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/branches.shtml b/help/manual_files/branches.shtml
new file mode 100644
index 0000000..0afaeee
--- /dev/null
+++ b/help/manual_files/branches.shtml
@@ -0,0 +1,44 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[BRANCHES] block</h2>
+
+<p>
+These blocks are used to simulate non-stationary and non-homogenous processes. Different models from different 
+<a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/model.shtml">[MODEL]</a> blocks can be specified on 
+different branches of the guide-tree allowing branches to have different models of substitution, indel length distribution, rate heterogeneity, base composition etc. 
+
+<hr>
+<a name="top"><br><p><u><b>Example Usage:</u></b></p></a>  
+<pre>
+  [TREE]     t1 ( (A:0.1, B:0.1):0.1,(C:0.1, D:0.1):0.1);
+
+  [BRANCHES] b1 ( (A #mA, B#mB) #mAB,(C #mC, D #mD) #mCD)#mROOT;
+</pre>
+<li> The easiest way to format a <font color=blue>[BRANCHES]</font> block is to cut and paste a tree from a tree block (<font color=blue>t1</font> in this case) and 
+replace the branch lengths with model names from previously defined <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/model.shtml">[MODEL]</a> blocks (
+<font color=blue>mA</font>, <font color=blue>mB</font> ,... etc)</li>
+<li>In a similar way that branch lengths are given after a ":" symbol, here model names are given after a "#" symbol.</li>
+<li>A model must also be added at the root of the tree also (<font color=blue>mROOT</font> here) and will be used in creation of the initial sequence at the root.</li>
+<li>Branch lengths and taxa names can be included or omitted at the user's convenience as they are ignored by INDELible - <font color=red>it is only the model names and their position in the parentheses that has any effect</font>. 
+e.g. the following four examples will produce identical results.</li>
+
+<pre>
+  [BRANCHES] b1a ((A:0.1#mA,B:0.1#mB):0.1 #mAB, (C:0.1 #mC, D:0.1#mD):0.1 #mCD)#mROOT;
+
+  [BRANCHES] b1b ( (A #mA, B#mB) #mAB,(C #mC, D #mD) #mCD)#mROOT;
+
+  [BRANCHES] b1c ( (#mA, #mB) #mAB,(#mC,  #mD) #mCD)#mROOT;
+
+  [BRANCHES] b1d 
+     ( 
+        (                       // like [TREE] blocks, [BRANCHES] trees 
+          A #mA, B#mB           // can contain any amount of white space
+        ) #mAB                  // or comments between the first ( and 
+      ,                         // the ; at the end.
+        (C #mC, D #mD) 
+      #mCD)#mROOT;
+</pre>
+
+<li>For more examples please see the tutorial section.</li>
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/codon_RATES.txt b/help/manual_files/codon_RATES.txt
new file mode 100644
index 0000000..e590e78
--- /dev/null
+++ b/help/manual_files/codon_RATES.txt
@@ -0,0 +1,715 @@
+Rates file : INDELible V1.00 				
+				
+  N.B. Site classes are numbered from lowest to highest values of omega.				
+       The omegas are not given explicitly as they are permitted to change on different				
+       branches whereas the site classes are not allowed to change.				
+				
+Site	Class	Insert?	Partition	
+1	3		1	
+2	0	Y	1	
+3	3	Y	1	
+4	2	Y	1	
+5	0	Y	1	
+6	0		1	
+7	1	Y	1	
+8	3	Y	1	
+9	1	Y	1	
+10	2	Y	1	
+11	3	Y	1	
+12	1	Y	1	
+13	1	Y	1	
+14	3	Y	1	
+15	0	Y	1	
+16	2	Y	1	
+17	0		1	
+18	3	Y	1	
+19	3	Y	1	
+20	3	Y	1	
+21	3		1	
+22	3	Y	1	
+23	2		1	
+24	2	Y	1	
+25	2		1	
+26	3	Y	1	
+27	0	Y	1	
+28	0		1	
+29	0		1	
+30	0		1	
+31	0	Y	1	
+32	0	Y	1	
+33	3	Y	1	
+34	3		1	
+35	3	Y	1	
+36	3		1	
+37	1	Y	1	
+38	3	Y	1	
+39	3	Y	1	
+40	2		1	
+41	2	Y	1	
+42	0	Y	1	
+43	3	Y	1	
+44	2	Y	1	
+45	2		1	
+46	2	Y	1	
+47	1	Y	1	
+48	1		1	
+49	0	Y	1	
+50	0		1	
+51	0		1	
+52	1	Y	1	
+53	0	Y	1	
+54	1	Y	1	
+55	3	Y	1	
+56	1	Y	1	
+57	0	Y	1	
+58	3	Y	1	
+59	2	Y	1	
+60	1	Y	1	
+61	2	Y	1	
+62	3	Y	1	
+63	2	Y	1	
+64	2	Y	1	
+65	3	Y	1	
+66	0	Y	1	
+67	2	Y	1	
+68	1	Y	1	
+69	0	Y	1	
+70	3	Y	1	
+71	1	Y	1	
+72	0	Y	1	
+73	3	Y	1	
+74	3	Y	1	
+75	3	Y	1	
+76	2	Y	1	
+77	0	Y	1	
+78	2	Y	1	
+79	3		1	
+80	2		1	
+81	3		1	
+82	2	Y	1	
+83	0	Y	1	
+84	1	Y	1	
+85	2	Y	1	
+86	0	Y	1	
+87	1	Y	1	
+88	2	Y	1	
+89	2	Y	1	
+90	2	Y	1	
+91	1		1	
+92	1		1	
+93	3	Y	1	
+94	2		1	
+95	3		1	
+96	1	Y	1	
+97	2		1	
+98	0	Y	1	
+99	3		1	
+100	3	Y	1	
+101	0	Y	1	
+102	3	Y	1	
+103	0	Y	1	
+104	2		1	
+105	0	Y	1	
+106	2		1	
+107	3	Y	1	
+108	0	Y	1	
+109	3		1	
+110	2	Y	1	
+111	2	Y	1	
+112	2	Y	1	
+113	2	Y	1	
+114	3	Y	1	
+115	3	Y	1	
+116	3	Y	1	
+117	3	Y	1	
+118	3		1	
+119	1		1	
+120	3		1	
+121	1		1	
+122	2	Y	1	
+123	2		1	
+124	1	Y	1	
+125	0		1	
+126	3		1	
+127	3		1	
+128	2	Y	1	
+129	2	Y	1	
+130	1	Y	1	
+131	0		1	
+132	0		1	
+133	2		1	
+134	1		1	
+135	3		1	
+136	1		1	
+137	2		1	
+138	3		1	
+139	0		1	
+140	3		1	
+141	2		1	
+142	3		1	
+143	3	Y	1	
+144	3	Y	1	
+145	2		1	
+146	2	Y	1	
+147	2	Y	1	
+148	3	Y	1	
+149	2	Y	1	
+150	3	Y	1	
+151	3		1	
+152	2		1	
+153	1		1	
+154	0		1	
+155	1		1	
+156	0		1	
+157	1	Y	1	
+158	3	Y	1	
+159	3	Y	1	
+160	2	Y	1	
+161	3	Y	1	
+162	1	Y	1	
+163	3	Y	1	
+164	3	Y	1	
+165	2	Y	1	
+166	3	Y	1	
+167	1		1	
+168	0	Y	1	
+169	0	Y	1	
+170	2		1	
+171	3	Y	1	
+172	3		1	
+173	2	Y	1	
+174	2		1	
+175	0	Y	1	
+176	3	Y	1	
+177	1	Y	1	
+178	3		1	
+179	3		1	
+180	0	Y	1	
+181	2		1	
+182	3		1	
+183	2		1	
+184	2	Y	1	
+185	2		1	
+186	3		1	
+187	2		1	
+188	3	Y	1	
+189	3	Y	1	
+190	0		1	
+191	3		1	
+192	0	Y	1	
+193	2		1	
+194	1		1	
+195	0	Y	1	
+196	0		1	
+197	0		1	
+198	2		1	
+199	0		1	
+200	0		1	
+201	0		1	
+202	0	Y	1	
+203	3	Y	1	
+204	0	Y	1	
+205	0		1	
+206	0		1	
+207	2		1	
+208	3		1	
+209	3	Y	1	
+210	3	Y	1	
+211	2	Y	1	
+212	2		1	
+213	0		1	
+214	2	Y	1	
+215	0	Y	1	
+216	2	Y	1	
+217	1	Y	1	
+218	3	Y	1	
+219	3	Y	1	
+220	1	Y	1	
+221	3	Y	1	
+222	3	Y	1	
+223	0	Y	1	
+224	0	Y	1	
+225	2	Y	1	
+226	0	Y	1	
+227	2	Y	1	
+228	0	Y	1	
+229	3	Y	1	
+230	1	Y	1	
+231	3	Y	1	
+232	3	Y	1	
+233	1	Y	1	
+234	2	Y	1	
+235	2	Y	1	
+236	1	Y	1	
+237	3	Y	1	
+238	2	Y	1	
+239	3	Y	1	
+240	1	Y	1	
+241	0	Y	1	
+242	1	Y	1	
+243	2	Y	1	
+244	0	Y	1	
+245	3		1	
+246	0		1	
+247	3	Y	1	
+248	2	Y	1	
+249	1		1	
+250	3		1	
+251	3	Y	1	
+252	0	Y	1	
+253	2	Y	1	
+254	3	Y	1	
+255	0	Y	1	
+256	1	Y	1	
+257	2	Y	1	
+258	2	Y	1	
+259	0	Y	1	
+260	3	Y	1	
+261	2	Y	1	
+262	1		1	
+263	3	Y	1	
+264	3	Y	1	
+265	1	Y	1	
+266	1	Y	1	
+267	2	Y	1	
+268	1		1	
+269	0		1	
+270	2		1	
+271	3		1	
+272	3	Y	1	
+273	3		1	
+274	1		1	
+275	2		1	
+276	2		1	
+277	3	Y	1	
+278	0		1	
+279	3		1	
+280	3		1	
+281	2	Y	1	
+282	3		1	
+283	0		2	
+284	1	Y	2	
+285	2	Y	2	
+286	3		2	
+287	3		2	
+288	0		2	
+289	3	Y	2	
+290	2	Y	2	
+291	2	Y	2	
+292	2		2	
+293	3	Y	2	
+294	0	Y	2	
+295	2	Y	2	
+296	2	Y	2	
+297	2	Y	2	
+298	3	Y	2	
+299	0	Y	2	
+300	0		2	
+301	0		2	
+302	2	Y	2	
+303	2	Y	2	
+304	0	Y	2	
+305	0		2	
+306	3	Y	2	
+307	0	Y	2	
+308	3		2	
+309	1	Y	2	
+310	3		2	
+311	3	Y	2	
+312	2	Y	2	
+313	3	Y	2	
+314	3		2	
+315	0		2	
+316	2	Y	2	
+317	3	Y	2	
+318	3	Y	2	
+319	0	Y	2	
+320	2		2	
+321	0	Y	2	
+322	2	Y	2	
+323	1	Y	2	
+324	1	Y	2	
+325	2	Y	2	
+326	3	Y	2	
+327	2	Y	2	
+328	2	Y	2	
+329	3	Y	2	
+330	1	Y	2	
+331	1	Y	2	
+332	3	Y	2	
+333	1	Y	2	
+334	0	Y	2	
+335	2	Y	2	
+336	2	Y	2	
+337	0	Y	2	
+338	0	Y	2	
+339	2	Y	2	
+340	0	Y	2	
+341	3	Y	2	
+342	0	Y	2	
+343	2	Y	2	
+344	1	Y	2	
+345	3	Y	2	
+346	2	Y	2	
+347	1	Y	2	
+348	2	Y	2	
+349	2	Y	2	
+350	3	Y	2	
+351	2		2	
+352	2	Y	2	
+353	0	Y	2	
+354	2	Y	2	
+355	2	Y	2	
+356	3	Y	2	
+357	1	Y	2	
+358	2	Y	2	
+359	1	Y	2	
+360	3	Y	2	
+361	2		2	
+362	3	Y	2	
+363	1	Y	2	
+364	0	Y	2	
+365	2	Y	2	
+366	3	Y	2	
+367	1		2	
+368	2	Y	2	
+369	2		2	
+370	3	Y	2	
+371	0	Y	2	
+372	2		2	
+373	0	Y	2	
+374	2	Y	2	
+375	1	Y	2	
+376	3	Y	2	
+377	1	Y	2	
+378	2	Y	2	
+379	0	Y	2	
+380	2	Y	2	
+381	0		2	
+382	0		2	
+383	1		2	
+384	3		2	
+385	2		2	
+386	2	Y	2	
+387	3	Y	2	
+388	2		2	
+389	1	Y	2	
+390	2		2	
+391	2	Y	2	
+392	0		2	
+393	2	Y	2	
+394	2		2	
+395	0	Y	2	
+396	0	Y	2	
+397	2	Y	2	
+398	3	Y	2	
+399	2	Y	2	
+400	2	Y	2	
+401	0		2	
+402	1	Y	2	
+403	1	Y	2	
+404	2	Y	2	
+405	3	Y	2	
+406	2	Y	2	
+407	3	Y	2	
+408	2	Y	2	
+409	3	Y	2	
+410	2	Y	2	
+411	1	Y	2	
+412	1	Y	2	
+413	0	Y	2	
+414	3	Y	2	
+415	2	Y	2	
+416	1	Y	2	
+417	1		2	
+418	3	Y	2	
+419	2		2	
+420	0	Y	2	
+421	3	Y	2	
+422	3	Y	2	
+423	1		2	
+424	3	Y	2	
+425	1		2	
+426	2	Y	2	
+427	1	Y	2	
+428	1		2	
+429	3	Y	2	
+430	0	Y	2	
+431	0		2	
+432	0	Y	2	
+433	1	Y	2	
+434	3	Y	2	
+435	0	Y	2	
+436	2	Y	2	
+437	3		2	
+438	2		2	
+439	1	Y	2	
+440	0	Y	2	
+441	0	Y	2	
+442	2	Y	2	
+443	1	Y	2	
+444	2	Y	2	
+445	3	Y	2	
+446	2	Y	2	
+447	3	Y	2	
+448	1	Y	2	
+449	0	Y	2	
+450	3	Y	2	
+451	3	Y	2	
+452	3	Y	2	
+453	2	Y	2	
+454	0	Y	2	
+455	2	Y	2	
+456	3	Y	2	
+457	3	Y	2	
+458	1	Y	2	
+459	0	Y	2	
+460	1		2	
+461	3	Y	2	
+462	0	Y	2	
+463	2	Y	2	
+464	1	Y	2	
+465	0	Y	2	
+466	3	Y	2	
+467	3	Y	2	
+468	0	Y	2	
+469	2	Y	2	
+470	2		2	
+471	3	Y	2	
+472	3		2	
+473	2	Y	2	
+474	0		2	
+475	1	Y	2	
+476	1	Y	2	
+477	2		2	
+478	3	Y	2	
+479	1		2	
+480	0	Y	2	
+481	0	Y	2	
+482	3	Y	2	
+483	0		2	
+484	2	Y	2	
+485	3	Y	2	
+486	1	Y	2	
+487	1		2	
+488	3	Y	2	
+489	1	Y	2	
+490	0	Y	2	
+491	2	Y	2	
+492	0	Y	2	
+493	1	Y	2	
+494	0	Y	2	
+495	2	Y	2	
+496	3	Y	2	
+497	3	Y	2	
+498	3	Y	2	
+499	3	Y	2	
+500	1	Y	2	
+501	3	Y	2	
+502	1	Y	2	
+503	0	Y	2	
+504	2	Y	2	
+505	2	Y	2	
+506	3	Y	2	
+507	0	Y	2	
+508	0	Y	2	
+509	0	Y	2	
+510	0	Y	2	
+511	1	Y	2	
+512	2	Y	2	
+513	1	Y	2	
+514	0	Y	2	
+515	3	Y	2	
+516	0	Y	2	
+517	3	Y	2	
+518	2	Y	2	
+519	0	Y	2	
+520	2	Y	2	
+521	0	Y	2	
+522	0	Y	2	
+523	1	Y	2	
+524	1	Y	2	
+525	3	Y	2	
+526	3	Y	2	
+527	3	Y	2	
+528	2	Y	2	
+529	3	Y	2	
+530	3	Y	2	
+531	3	Y	2	
+532	3	Y	2	
+533	3	Y	2	
+534	2	Y	2	
+535	1	Y	2	
+536	0		2	
+537	0	Y	2	
+538	1	Y	2	
+539	0	Y	2	
+540	3	Y	2	
+541	3	Y	2	
+542	2	Y	2	
+543	0	Y	2	
+544	1	Y	2	
+545	3	Y	2	
+546	2	Y	2	
+547	2	Y	2	
+548	1	Y	2	
+549	3	Y	2	
+550	3	Y	2	
+551	0	Y	2	
+552	3		2	
+553	3	Y	2	
+554	2		2	
+555	0		2	
+556	2	Y	2	
+557	3	Y	2	
+558	3	Y	2	
+559	3	Y	2	
+560	1	Y	2	
+561	0	Y	2	
+562	1		2	
+563	3		2	
+564	2	Y	2	
+565	3	Y	2	
+566	1	Y	2	
+567	0	Y	2	
+568	3	Y	2	
+569	3	Y	2	
+570	2	Y	2	
+571	3		2	
+572	2		2	
+573	2		2	
+574	3		2	
+575	3	Y	2	
+576	2		2	
+577	2		2	
+578	3		2	
+579	0		2	
+580	3		2	
+581	2		2	
+582	3	Y	2	
+583	2	Y	2	
+584	2		2	
+585	0	Y	2	
+586	3	Y	2	
+587	3		2	
+588	3	Y	2	
+589	1		2	
+590	3		2	
+591	2	Y	2	
+592	2	Y	2	
+593	3	Y	2	
+594	0	Y	2	
+595	2	Y	2	
+596	3	Y	2	
+597	2	Y	2	
+598	1	Y	2	
+599	2		2	
+600	3		2	
+601	2	Y	2	
+602	2	Y	2	
+603	1		2	
+604	0	Y	2	
+605	3		2	
+606	3		2	
+607	2	Y	2	
+608	1	Y	2	
+609	0	Y	2	
+610	1	Y	2	
+611	0	Y	2	
+612	1	Y	2	
+613	1	Y	2	
+614	2	Y	2	
+615	0	Y	2	
+616	2	Y	2	
+617	0	Y	2	
+618	2	Y	2	
+619	0		2	
+620	2	Y	2	
+621	1	Y	2	
+622	2	Y	2	
+623	2		2	
+624	1	Y	2	
+625	2	Y	2	
+626	2		2	
+627	0	Y	2	
+628	2	Y	2	
+629	3		2	
+630	1		2	
+631	2	Y	2	
+632	3	Y	2	
+633	1		2	
+634	2	Y	2	
+635	2	Y	2	
+636	3	Y	2	
+637	0	Y	2	
+638	1	Y	2	
+639	3	Y	2	
+640	0	Y	2	
+641	0	Y	2	
+642	3	Y	2	
+643	3	Y	2	
+644	0	Y	2	
+645	3		2	
+646	2	Y	2	
+647	0	Y	2	
+648	3	Y	2	
+649	3	Y	2	
+650	1	Y	2	
+651	3	Y	2	
+652	2	Y	2	
+653	2		2	
+654	3		2	
+655	1		2	
+656	2		2	
+657	1	Y	2	
+658	0	Y	2	
+659	3	Y	2	
+660	3	Y	2	
+661	0	Y	2	
+662	1	Y	2	
+663	2	Y	2	
+664	3		2	
+665	0		2	
+666	0		2	
+667	0		2	
+668	3		2	
+669	3	Y	2	
+670	2	Y	2	
+671	0	Y	2	
+672	3	Y	2	
+673	1	Y	2	
+674	3	Y	2	
+675	1		2	
+676	0	Y	2	
+677	2		2	
+678	0		2	
+679	3	Y	2	
+680	2	Y	2	
+681	3	Y	2	
+682	2	Y	2	
+683	1	Y	2	
+684	1		2	
+685	3		2	
+686	1	Y	2	
+687	1		2	
+688	2		2	
+689	0	Y	2	
+690	0	Y	2	
+691	3	Y	2	
+692	3		2	
+693	0		2	
+694	1		2	
+695	3		2	
+696	2	Y	2	
+697	3		2	
+698	3	Y	2	
+699	1	Y	2	
+700	0		2	
+701	1	Y	2	
+702	1		2	
+703	3	Y	2	
+704	3	Y	2	
+705	0		2	
+706	0	Y	2	
+707	3	Y	2	
+708	0	Y	2	
diff --git a/help/manual_files/evolve.shtml b/help/manual_files/evolve.shtml
new file mode 100644
index 0000000..cfec283
--- /dev/null
+++ b/help/manual_files/evolve.shtml
@@ -0,0 +1,26 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[EVOLVE] block</h2>
+
+<p>
+This block basically defines the queue of jobs that INDELible must complete. It tells INDELible how many replicates to generate from each <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/partitions.shtml">[PARTITIONS]</a> block and what the output files should be named. 
+<hr>
+<a name="top"><br><p><u><b>Example Usage:</u></b></p></a>  
+<pre>
+  [EVOLVE] 
+    p1 100 outputname1
+    p2 100 outputname2
+    p3 100 outputname3
+    p4 100 outputname4
+    p5 100 outputname5
+    p6 100 outputname6
+    p7 100 outputname7
+    p8 100 outputname8
+</pre>
+<li><i>p1</i> etc refers to the name of previously defined <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/partitions.shtml">[PARTITIONS]</a> blocks.</li> 
+<li><i>100</i> is the number of replicates that will be generated for each job.</li> 
+<li><i>outputname1</i> etc will be used in the filenames of the generated datasets.
+<li>Each control file must contain exactly <b>one</b> of these blocks.
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/model.shtml b/help/manual_files/model.shtml
new file mode 100644
index 0000000..0977f1b
--- /dev/null
+++ b/help/manual_files/model.shtml
@@ -0,0 +1,249 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[MODEL] block</h2>
+
+<p><ul>
+<li>These blocks are used to specify the evolutionary models used during simulation. </li>
+<li>There are a variety of commands available for specifying different substitution models and indel models as well as rates of insertion and deletion to substitution etc. </li>
+<li>Each model block in the control file must be given a name (e.g. "mymodelname" below). This is used to refer to the model elsewhere in the control file.</li>
+<li>It does not matter whether the "white space" (between commands and values) is spaces, tabs or new lines.</li>
+<li>If a command is not specified the default value is used. Default values are listed in the description of each command.
+<li>Please click on any of the commands to learn more about them.</li>
+</ul></p>
+<hr>
+<a name="top"><br><p><u><b>Example Usage:</u></b></p></a>  
+
+<pre>
+[MODEL] mymodelname    
+  <a href="#[submodel1]"   >[submodel]</a>      HKY 2.5             //  HKY with kappa of 2.5
+  <a href="#[indelmodel]"  >[indelmodel]</a>    LAV 1.7  541        //  specifies the indel length distribution
+  <a href="#[indelrate]"   >[indelrate]</a>     0.1                 //  rates of insertion and deletion are both 0.1
+  <a href="#[geneticcode]" >[geneticcode]</a>   2                   //  only used in CODON simulations
+  <a href="#[rates]"       >[rates]</a>         0.25 0.50 10        //  pinv alpha ngamcat
+  <a href="#[statefreq]"   >[statefreq]</a>     0.4  0.3  0.2  0.1  //  frequencies for T C A G
+</pre>								
+
+</ul><hr><pre><a name="[submodel1]">[submodel]    for NUCLEOTIDE simulations</a></pre><ul>
+<li>Follow the links for information about this command for <a href="#[submodel2]">AMINOACID</a> or <a href="#[submodel3]">CODON</a> simulations.</li>
+<li>Most substitution models implemented in INDELible are variations of the following general matrix:</li>
+<pre>
+                   <img src="symQmatrix.gif">
+</pre>
+<li> The different models are specified using the commands listed below in blue (the names correspond to those used by <a href="http://darwin.uvigo.es/software/modeltest.html" target="_blank">Modeltest</a>):</li>
+<pre>
+  +-----+----------------------------------+----------------------------------+
+  | <b> N </b> |    <b>Usage </b>                        |  <b>Notes  </b>                         |
+  +-----+----------------------------------+----------------------------------+
+  |  0  |  <font color=blue> [submodel] JC                </font>  |  a=b=c=d=e=f=1                   |
+  |  1  |  <font color=blue> [submodel] F81               </font>  |  a=b=c=d=e=f=1                   |
+  +-----+----------------------------------+----------------------------------+
+  |  2  |  <font color=blue> [submodel] K80    a          </font>  |  a=f=kappa, b=c=d=e=1            |
+  |  3  |  <font color=blue> [submodel] HKY    a          </font>  |  a=f=kappa, b=c=d=e=1            |
+  +-----+----------------------------------+----------------------------------+
+  |  4  |  <font color=blue> [submodel] TrNef  a f        </font>  |  a=kappa1, f=kappa2, b=c=d=e=1   |
+  |  5  |  <font color=blue> [submodel] TrN    a f       </font>   |  a=kappa1, f=kappa2, b=c=d=e=1   |
+  +-----+----------------------------------+----------------------------------+
+  |  6  |  <font color=blue> [submodel] K81    b c        </font>  |  b=e, c=d, a=f=1                 |
+  |  7  |  <font color=blue> [submodel] K81uf  b c        </font>  |  b=e, c=d, a=f=1                 |
+  +-----+----------------------------------+----------------------------------+
+  |  8  |  <font color=blue> [submodel] TIMef  a b c      </font>  |  b=e, c=d, f=1                   |
+  |  9  |  <font color=blue> [submodel] TIM    a b c      </font>  |  b=e, c=d, f=1                   |
+  +-----+----------------------------------+----------------------------------+
+  |  10 |  <font color=blue> [submodel] TVMef  b c d e    </font>  |  a=f=1                           |
+  |  11 |  <font color=blue> [submodel] TVM    b c d e    </font>  |  a=f=1                           |
+  +-----+----------------------------------+----------------------------------+
+  |  12 |  <font color=blue> [submodel] SYM    a b c d e  </font>  |  f=1                             |
+  |  13 |  <font color=blue> [submodel] GTR    a b c d e  </font>  |  f=1                             |
+  +-----+----------------------------------+----------------------------------+
+  |  14 |  <font color=blue> [submodel] F84ef  k   </font>         |  b=c=d=e=1, a=(1+k/Y), f=(1+k/R) |
+  |  15 |  <font color=blue> [submodel] F84    k   </font>         |  b=c=d=e=1, a=(1+k/Y), f=(1+k/R) |
+  +-----+----------------------------------+--------------------------+-------+
+  |  16 |  <font color=blue> [submodel] UNREST TC TA TG CT CA CG AT AC AG GT GC</font>        |  GA=1 |
+  +-----+-------------------------------------------------------------+-------+
+
+  N.B. <i>N</i> can be substituted for the model name.  
+  e.g. <font color=blue>[submodel] 0</font> instead of <font color=blue>[submodel] JC</font> 
+</pre>
+
+
+<li>For F84: Y=π<sub>T</sub>+π<sub>C</sub> and R=π<sub>A</sub>+π<sub>G</sub></li>
+<li>For the models with odd  <i>N</i> (1-15) the base frequencies π<sub>T</sub>, π<sub>C</sub>, π<sub>A</sub>, π<sub>G</sub> are given in <a href="#[statefreq]">[statefreq]</a>.</li>
+<li>For the models with even <i>N</i> (0-16) the base frequencies need not be given in <a href="#[statefreq]">[statefreq]</a> and are set automatically.</li>
+
+
+<li><a name="[submodel2]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[submodel]    for AMINOACID simulations</pre><ul>
+<li>Follow the links for information about this command for <a href="#[submodel1]">NUCLEOTIDE</a> or <a href="#[submodel3]">CODON</a> simulations.</li>
+<li>This command is quite simple in this case. Usage is just: <font color=blue><i>[submodel] value</i>  </li></font>
+<li><i>value</i> is just an integer <i>N</i> or a <i>code</i> used to pick the amino-acid substitution model as defined below (references from paper given where appropriate):</li>
+<pre>
+  +-----+---------------+-------------------------------+
+  |  <b>N</b>  | <b>code</b>          | <b>Reference</b>                     |
+  +-----+---------------+-------------------------------+
+  |  0  | Poisson       |  n/a                          |
+  |  1  | JTT           |  Jones et al,. 1992           |
+  |  2  | JTT-dcmut     |  Kosiol and Goldman, 2005     |
+  |  3  | Dayhoff       |  Dayhoff et al., 1978         |
+  |  4  | Dayhoff-dcmut |  Kosiol and Goldman, 2005     |
+  |  5  | WAG           |  Whelan and Goldman, 2001     |
+  |  6  | mtMAM         |  Yang et al., 1998            |
+  |  7  | mtART         |  Abascal et al., 2007         |
+  |  8  | mtREV         |  Adachi and Hasegawa, 1996    |
+  |  9  | rtREV         |  Dimmic et al., 2002          |
+  |  10 | cpREV         |  Adachi, 2000                 |
+  |  11 | Vt            |  Muller and Vingron, 2000     |
+  |  12 | Blosum        |  Henikoff and Henikoff, 1992  |
+  |  13 | LG            |  Le and Gascuel, 2008         |
+  |  14 | HIVb          |  Nickle et al., 2007          |
+  |  15 | HIVw          |  Nickle et al., 2007          |
+  |  16 | USER          |  n/a                          |
+  +-----+---------------+-------------------------------+
+</pre>
+<li>For the user defined substitution model the number <i>16</i> or the code <i>USER</i> should be followed by a filename containing the rate matrix Q. For example:
+<br><i><font color=blue>[submodel] USER userAAmodel.txt</font></i></li>
+<li>This file should be in the same directory as the INDELible executable.</li>
+<li>The formatting of this file follows the PAML convention. e.g. for the Dayhoff-dcmut model the file should be formatted like <a href="userAAmodel.txt" target="_blank">this</a>.
+<li><i>+F</i> versions of these models are specified by defining stationary frequencies using the <a href="#[statefreq]">[statefreq]</a> command.
+<li>If the <a href="#[statefreq]">[statefreq]</a> is not specified the stationary frequencies from the model are used..
+<li><a name="[submodel3]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[submodel]    for CODON simulations</pre><ul>
+<li>Follow the links for information about this command for  <a href="#[submodel1]">NUCLEOTIDE</a> or <a href="#[submodel2]">AMINOACID</a> simulations.</li>
+<li>This command is <font color=blue> [submodel] ECMunrest  </font> for the empirical unrestricted model.</li>
+<li>This command is <font color=blue> [submodel] ECMrest  </font> for the empirical restricted model.</li>
+<li>Otherwise a codon model with <font color=blue> K </font> discrete omega categories is defined using the commands below in blue:</li>
+<pre>
+  // M3 (discrete)                       // p<sub>(K-1)</sub>=1-p<sub>(K-2)</sub>-...-p<sub>1</sub>-p<sub>0</sub>
+ <font color=blue> [submodel]  kappa</font>
+ <font color=blue>             p<sub>0</sub>  p<sub>1</sub>  ...  p<sub>(K-2)</sub>   <sub>     </sub>  </font>// proportions
+ <font color=blue>             ω<sub>0</sub>  ω<sub>1</sub>  ...  ω<sub>(K-2)</sub>  ω<sub>(K-1)</sub> </font> // omegas
+</pre>
+<li>All other models from M0-M13 can be represented in this M3 format. For example:</li>
+<pre>
+  // M0 (one-ratio) 
+  <font color=blue>[submodel]  kappa  &omega<sub>0</sub>                   </font>//  p<sub>0</sub>=1
+ 
+  // M1 (neutral)   
+  <font color=blue>[submodel]  kappa  p<sub>0</sub>  ω<sub>0</sub>  1           </font> //  ω<sub>1</sub>=1;  p<sub>1</sub>=1-p<sub>0</sub>
+
+  // M2 (selection)  
+  <font color=blue>[submodel]  kappa  p<sub>0</sub>  p<sub>1</sub>  ω<sub>0</sub>  1   ω<sub>2</sub>   </font>//  ω<sub>1</sub>=1;  p<sub>2</sub>=1-p<sub>1</sub>-p<sub>0</sub>
+   
+  // M4 (freqs) with K=5  
+  <font color=blue>[submodel]  kappa  </font>
+  <font color=blue>            p<sub>0</sub>  p<sub>1</sub>         p<sub>2</sub>         p<sub>3</sub>   <sub> </sub>  </font>//  p<sub>4</sub>=1-p<sub>3</sub>-p<sub>2</sub>-p<sub>1</sub>-p<sub>0</sub>
+  <font color=blue>            0<sub> </sub>  0.333333<sub> </sub>  0.666666<sub> </sub>  1<sub> </sub>  3<sub> </sub>  </font>//  ω<sub>0</sub>,  ω<sub>1</sub>,  ω<sub>2</sub>,  ω<sub>3</sub>,  ω<sub>4</sub> 
+</pre>
+<li>A script (named "M5-13") is provided with INDELible to calculate the discrete values for this command from the parameters used in models M5-M13.</li>
+<li><a name="[indelmodel]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[indelmodel]</pre><ul>
+<li>This sets the insertion and deletion length distributions to be the same with four possible choices:</li>
+<pre>
+   (1)  <font color="blue">[indelmodel]  NB   q  r</font>               //  Negative Binomial Distribution
+   (2a) <font color="blue">[indelmodel]  POW  a</font>                  //  Zipfian Distribution 
+   (2b) <font color="blue">[indelmodel]  POW  a  M</font>               //  Zipfian Distribution 
+   (3)  <font color="blue">[indelmodel]  LAV  a  M</font>               //  Lavalette Distribution
+   (4)  <font color="blue">[indelmodel]  USER mylengthmodel.txt</font>  //  User-Defined Distribution
+</pre>
+<li>(1)  This specifies a Pascal (negative binomial) distribution where <font color=blue>q</font> is a decimal (<font color=blue>0<=q<=1</font>) and <font color=blue>r</font> is an integer (<font color=blue>r>0</font>).</li>
+<li>(2a) This specifies a Zipfian (power law) distribution where <font color=blue>a</font> is a decimal (<font color=blue>a>1</font>).</li>
+<li>(2b) This also specifies a Zipfian distribution where <font color="blue">a</font> is a decimal (<font color="blue">a>1</font>).
+         However with this format indels longer than length <font color="blue">M</font> are not permitted.
+         This format is highly recommended for small values of <font color="blue">a</font> because of the fat-tailed shape of the distribution.</li>
+<li>(3)  This specifies a Lavalette distribution where <font color=blue>a</font> is a decimal (<font color=blue>a>1</font>) and <font color=blue>M</font> is an integer (<font color=blue>M>1</font>) representing the maximum indel length.</li>
+<li>(4)  This specifies a user-defined indel length distribution. The file <font color=blue>mylengthmodel.txt</font> should be in the same directory as the INDELible executable and contain a list of 
+relative frequencies (in order of increasing indel length) separated by white space, like <a href="mylengthmodel.txt" target="_blank">this</a>.
+<li>If you want to specify different length distributions for insertions and deletions then do not use <font color=blue>[indelmodel]</font>.</li>
+<li>In this case use the commands <font color=blue>[insertmodel]</font> and <font color=blue>[deletemodel]</font> instead. The format of these two commands is the same as for <font color=blue>[indelmodel]</font>.</li>
+<li><a name="[indelrate]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[indelrate]</pre><ul>
+<li>This sets the insertion and deletion rates to both be equal to whatever value is given.</li>
+<li>Both rates are relative to an average substitution rate of 1.
+<li>N.B. This means that <i>insertionrate = indelrate</i> and <i>deletionrate = indelrate</i>.</li>
+<li>This is not the same as <i>insertionrate + deletionrate = indelrate</i>.</li>
+<li>To specify different rates for insertions and deletions then do not use <font color=blue>[indelrate]</font>.</li>
+<li>In this case use the commands <font color=blue>[insertrate]</font> and <font color=blue>[deleterate]</font> instead.  The values for each command are the rates relative to an average substitution rate of 1.</li>
+<li><a name="[geneticcode]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[geneticcode]</pre><ul>
+<li>This command can only be used in <i>CODON</i> simulations.</li>
+<li>The value should be an integer 1 to 6, 9 to 16, or 21 to 24, corresponding to the genetic codes listed on Genbank.</li>
+<li>The value 1 (corresponding to the universal genetic code) is the default setting if the command is not specified.</li>
+<li>These genetic codes determine which codons are stop codons and therefore not simulated by INDELible.</li>
+<li>They are also used to translate codons to amino-acids for output if <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/settings.shtml#[printcodonsasaminoacids]">that option</a> is chosen.</li>
+<li>The codes listed at <a href="http://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi">Genbank</a> (in Oct. 2008) are given below (* represents a stop codon).</li>
+<li>Please note some codes are identical and differ only in terms of Starts. Please see Genbank for more info.</li>
+<pre>
+       1  - The Standard Code
+       FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       2  - The Vertebrate Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG
+       3  - The Yeast Mitochondrial Code
+       FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       4  - The Mold, Protozoan, and Coelenterate Mitochondrial
+            Code and the Mycoplasma/Spiroplasma Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       5  - The Invertebrate Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG
+       6  - The Ciliate, Dasycladacean and Hexamita Nuclear Code
+       FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       9  - The Echinoderm and Flatworm Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG
+       10 - The Euplotid Nuclear Code
+       FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       11 - The Bacterial and Plant Plastid Code
+       FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       12 - The Alternative Yeast Nuclear Code
+       FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       13 - The Ascidian Mitochondrial Code
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG
+       14 - The Alternative Flatworm Mitochondrial Code
+       FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG
+       15 - The Blepharisma Nuclear Code
+       FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       16 - The Chlorophycean Mitochondrial Code
+       FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       21 - The Trematode Mitochondrial Code 
+       FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG
+       22 - The Scenedesmus obliquus mitochondrial Code 
+       FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+       23 - The Thraustochytrium Mitochondrial Code
+       FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
+
+Base1: TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+Base2: TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+Base3: TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+
+</pre>
+
+<li><a name="[rates]"><a href="#top">Return to example usage.</a></a></li>
+
+
+</ul><hr>
+<pre>[rates]</pre><ul>
+<li>This command has no effect in <i>CODON</i> simulations.
+<li>The 3 entries in this command are (from left to right): <i>pinv</i>, <i>alpha</i> and <i>ngamcat</i>.</li>
+<li><i>pinv</i> is the proportion of invariable sites (should be a number between 0 and 1).</li>
+<li><i>alpha</i> is the shape parameter for the gamma distribution (should be a positive number).</li>
+<li>If <i>alpha</i>=0 then there will be no gamma rate variation.</li>
+<li><i>ngamcat</i> is the number of categories to use in the discrete gamma approximation.</li>
+<li>If <i>ngamcat</i>=0 then continuous gamma distribution will be used for rate variation.</li>
+<li><a name="[statefreq]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[statefreq]</pre><ul>
+<li>This command is used to specify the stationary frequencies used in the model by listing them separated by white space.</li>
+<li>If the command is not specified in a [MODEL] block then all stationary frequencies will be set to be equal.</li>
+<li>If the list of numbers does not add up to 1 then they will be rescaled so that they do.</li>
+<li>For <i>NUCLEOTIDE</i> simulations this must be a list of 4 numbers representing the frequencies for the different nucleotides (in the order <font color=red>T C A G</font>).</li>
+<li>For <i>AMINOACID</i> simulations this must be a list of 20 numbers representing the frequencies for the different amino-acids (in the order <font color=red>A R N D C Q E G H I L K M F P S T W Y V</font>). 
+This will change the stationary frequencies from those defined in by the substitution model specified in <a href="#[submodel2]">[submodel]</a> (i.e. INDELible will simulate under a +F variant).</li>
+<li>For <i>CODON</i> simulations this must be a list of 64 numbers representing the frequencies for the different codons (in the order <font color=red>TTT TTC TTA TTG TCT TCC TCA .... GGA GGG</font>). </li>
+<li>Care should be taken that the stationary frequencies corresponding to any stop codons in your chosen genetic code are equal to zero. If your input contradicts this then INDELible will inform you.</li>
+<li><a name="[istatefreq]"><a href="#top">Return to example usage.</a></a></li>
+
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/mylengthmodel.txt b/help/manual_files/mylengthmodel.txt
new file mode 100644
index 0000000..00b28f9
--- /dev/null
+++ b/help/manual_files/mylengthmodel.txt
@@ -0,0 +1,1000 @@
+0.673643922711
+0.146287925004
+0.059820608527
+0.031697700931
+0.019358287305
+0.012933272346
+0.009193158625
+0.006837868923
+0.005265293128
+0.004166701951
+0.003371040086
+0.002777560301
+0.002323915321
+0.001969910312
+0.001688724636
+0.001461928529
+0.001276532822
+0.001123178093
+0.00099498778
+0.000886821517
+0.000794777043
+0.000715850644
+0.000647701104
+0.000588482706
+0.000536725187
+0.000491246179
+0.00045108649
+0.000415461683
+0.000383725432
+0.000355341508
+0.00032986215
+0.000306911211
+0.00028617093
+0.000267371444
+0.000250282438
+0.000234706428
+0.000220473338
+0.000207436089
+0.000195466987
+0.00018445476
+0.000174302102
+0.000164923633
+0.000156244203
+0.000148197464
+0.000140724667
+0.000133773652
+0.000127297986
+0.000121256228
+0.000115611306
+0.000110329976
+0.000105382365
+0.000100741568
+0.000096383307
+0.000092285629
+0.000088428647
+0.000084794311
+0.000081366213
+0.000078129408
+0.000075070266
+0.000072176334
+0.000069436215
+0.000066839468
+0.00006437651
+0.000062038538
+0.000059817448
+0.000057705776
+0.000055696635
+0.000053783666
+0.000051960988
+0.000050223157
+0.000048565126
+0.000046982214
+0.000045470073
+0.000044024662
+0.000042642218
+0.000041319238
+0.000040052455
+0.000038838819
+0.000037675482
+0.000036559783
+0.00003548923
+0.00003446149
+0.000033474376
+0.000032525839
+0.000031613953
+0.00003073691
+0.000029893012
+0.000029080658
+0.000028298344
+0.000027544653
+0.000026818248
+0.000026117868
+0.000025442324
+0.000024790492
+0.000024161311
+0.000023553777
+0.00002296694
+0.0000223999
+0.000021851807
+0.000021321853
+0.000020809272
+0.00002031334
+0.000019833367
+0.000019368698
+0.000018918712
+0.000018482817
+0.000018060452
+0.000017651082
+0.000017254198
+0.000016869315
+0.00001649597
+0.000016133724
+0.000015782156
+0.000015440867
+0.000015109474
+0.000014787611
+0.00001447493
+0.000014171099
+0.000013875798
+0.000013588723
+0.000013309583
+0.0000130381
+0.000012774005
+0.000012517044
+0.000012266973
+0.000012023556
+0.000011786568
+0.000011555794
+0.000011331028
+0.00001111207
+0.00001089873
+0.000010690826
+0.000010488181
+0.000010290627
+0.000010098002
+0.00000991015
+0.000009726921
+0.00000954817
+0.00000937376
+0.000009203556
+0.00000903743
+0.000008875258
+0.000008716922
+0.000008562306
+0.000008411299
+0.000008263796
+0.000008119692
+0.00000797889
+0.000007841294
+0.00000770681
+0.000007575351
+0.00000744683
+0.000007321164
+0.000007198273
+0.00000707808
+0.00000696051
+0.00000684549
+0.000006732951
+0.000006622826
+0.000006515048
+0.000006409555
+0.000006306286
+0.000006205182
+0.000006106185
+0.00000600924
+0.000005914293
+0.000005821293
+0.000005730189
+0.000005640933
+0.000005553478
+0.000005467777
+0.000005383786
+0.000005301463
+0.000005220765
+0.000005141653
+0.000005064088
+0.00000498803
+0.000004913444
+0.000004840294
+0.000004768544
+0.000004698162
+0.000004629115
+0.00000456137
+0.000004494897
+0.000004429666
+0.000004365647
+0.000004302814
+0.000004241137
+0.000004180591
+0.000004121149
+0.000004062787
+0.000004005479
+0.000003949202
+0.000003893932
+0.000003839647
+0.000003786326
+0.000003733946
+0.000003682487
+0.000003631928
+0.00000358225
+0.000003533434
+0.000003485462
+0.000003438314
+0.000003391973
+0.000003346422
+0.000003301644
+0.000003257622
+0.000003214342
+0.000003171787
+0.000003129941
+0.000003088792
+0.000003048322
+0.00000300852
+0.000002969371
+0.000002930862
+0.00000289298
+0.000002855711
+0.000002819045
+0.000002782968
+0.000002747469
+0.000002712536
+0.000002678158
+0.000002644325
+0.000002611025
+0.000002578248
+0.000002545983
+0.000002514222
+0.000002482954
+0.000002452169
+0.000002421859
+0.000002392014
+0.000002362625
+0.000002333684
+0.000002305182
+0.000002277112
+0.000002249465
+0.000002222232
+0.000002195407
+0.000002168982
+0.000002142949
+0.000002117302
+0.000002092033
+0.000002067135
+0.000002042602
+0.000002018427
+0.000001994603
+0.000001971125
+0.000001947985
+0.000001925179
+0.0000019027
+0.000001880542
+0.0000018587
+0.000001837168
+0.00000181594
+0.000001795012
+0.000001774379
+0.000001754034
+0.000001733973
+0.000001714192
+0.000001694685
+0.000001675448
+0.000001656477
+0.000001637766
+0.000001619311
+0.000001601108
+0.000001583153
+0.000001565442
+0.00000154797
+0.000001530734
+0.00000151373
+0.000001496953
+0.000001480401
+0.000001464069
+0.000001447954
+0.000001432053
+0.000001416361
+0.000001400876
+0.000001385594
+0.000001370512
+0.000001355627
+0.000001340936
+0.000001326435
+0.000001312121
+0.000001297993
+0.000001284045
+0.000001270277
+0.000001256685
+0.000001243266
+0.000001230017
+0.000001216937
+0.000001204021
+0.000001191269
+0.000001178677
+0.000001166243
+0.000001153964
+0.000001141839
+0.000001129864
+0.000001118037
+0.000001106357
+0.000001094821
+0.000001083427
+0.000001072173
+0.000001061057
+0.000001050076
+0.000001039229
+0.000001028513
+0.000001017927
+0.00000100747
+0.000000997138
+0.00000098693
+0.000000976845
+0.00000096688
+0.000000957034
+0.000000947305
+0.000000937692
+0.000000928193
+0.000000918805
+0.000000909528
+0.000000900361
+0.0000008913
+0.000000882346
+0.000000873496
+0.000000864749
+0.000000856104
+0.000000847559
+0.000000839112
+0.000000830763
+0.00000082251
+0.000000814351
+0.000000806286
+0.000000798313
+0.000000790431
+0.000000782639
+0.000000774935
+0.000000767318
+0.000000759787
+0.00000075234
+0.000000744978
+0.000000737698
+0.0000007305
+0.000000723382
+0.000000716343
+0.000000709382
+0.000000702499
+0.000000695692
+0.00000068896
+0.000000682302
+0.000000675717
+0.000000669205
+0.000000662764
+0.000000656393
+0.000000650092
+0.000000643859
+0.000000637694
+0.000000631596
+0.000000625564
+0.000000619597
+0.000000613694
+0.000000607855
+0.000000602078
+0.000000596363
+0.000000590709
+0.000000585115
+0.000000579581
+0.000000574106
+0.000000568688
+0.000000563328
+0.000000558025
+0.000000552777
+0.000000547585
+0.000000542447
+0.000000537362
+0.000000532332
+0.000000527353
+0.000000522426
+0.000000517551
+0.000000512726
+0.000000507951
+0.000000503226
+0.000000498549
+0.000000493921
+0.00000048934
+0.000000484806
+0.000000480318
+0.000000475877
+0.00000047148
+0.000000467129
+0.000000462822
+0.000000458558
+0.000000454338
+0.00000045016
+0.000000446025
+0.000000441931
+0.000000437879
+0.000000433867
+0.000000429895
+0.000000425964
+0.000000422071
+0.000000418218
+0.000000414402
+0.000000410625
+0.000000406885
+0.000000403183
+0.000000399517
+0.000000395887
+0.000000392293
+0.000000388734
+0.000000385211
+0.000000381722
+0.000000378267
+0.000000374846
+0.000000371458
+0.000000368104
+0.000000364782
+0.000000361493
+0.000000358235
+0.000000355009
+0.000000351814
+0.00000034865
+0.000000345517
+0.000000342414
+0.000000339341
+0.000000336297
+0.000000333282
+0.000000330297
+0.00000032734
+0.000000324411
+0.00000032151
+0.000000318637
+0.000000315791
+0.000000312972
+0.00000031018
+0.000000307414
+0.000000304674
+0.000000301961
+0.000000299272
+0.00000029661
+0.000000293972
+0.000000291359
+0.00000028877
+0.000000286206
+0.000000283666
+0.00000028115
+0.000000278657
+0.000000276187
+0.00000027374
+0.000000271316
+0.000000268914
+0.000000266535
+0.000000264178
+0.000000261842
+0.000000259528
+0.000000257236
+0.000000254964
+0.000000252714
+0.000000250484
+0.000000248275
+0.000000246085
+0.000000243916
+0.000000241767
+0.000000239637
+0.000000237527
+0.000000235436
+0.000000233364
+0.000000231311
+0.000000229277
+0.000000227261
+0.000000225263
+0.000000223283
+0.000000221321
+0.000000219377
+0.000000217451
+0.000000215541
+0.000000213649
+0.000000211774
+0.000000209916
+0.000000208074
+0.000000206249
+0.000000204441
+0.000000202648
+0.000000200872
+0.000000199111
+0.000000197366
+0.000000195636
+0.000000193922
+0.000000192224
+0.00000019054
+0.000000188871
+0.000000187217
+0.000000185577
+0.000000183952
+0.000000182342
+0.000000180745
+0.000000179163
+0.000000177595
+0.00000017604
+0.000000174499
+0.000000172972
+0.000000171458
+0.000000169957
+0.00000016847
+0.000000166995
+0.000000165533
+0.000000164084
+0.000000162648
+0.000000161224
+0.000000159813
+0.000000158414
+0.000000157027
+0.000000155652
+0.000000154289
+0.000000152938
+0.000000151599
+0.000000150271
+0.000000148955
+0.00000014765
+0.000000146356
+0.000000145074
+0.000000143802
+0.000000142542
+0.000000141292
+0.000000140053
+0.000000138825
+0.000000137607
+0.0000001364
+0.000000135203
+0.000000134017
+0.00000013284
+0.000000131674
+0.000000130518
+0.000000129371
+0.000000128235
+0.000000127108
+0.00000012599
+0.000000124882
+0.000000123784
+0.000000122695
+0.000000121615
+0.000000120545
+0.000000119483
+0.000000118431
+0.000000117387
+0.000000116352
+0.000000115326
+0.000000114309
+0.0000001133
+0.0000001123
+0.000000111309
+0.000000110325
+0.000000109351
+0.000000108384
+0.000000107425
+0.000000106475
+0.000000105532
+0.000000104598
+0.000000103671
+0.000000102752
+0.000000101841
+0.000000100938
+0.000000100042
+0.000000099153
+0.000000098273
+0.000000097399
+0.000000096533
+0.000000095674
+0.000000094822
+0.000000093978
+0.00000009314
+0.00000009231
+0.000000091486
+0.00000009067
+0.00000008986
+0.000000089057
+0.00000008826
+0.000000087471
+0.000000086688
+0.000000085911
+0.000000085141
+0.000000084377
+0.00000008362
+0.000000082869
+0.000000082124
+0.000000081386
+0.000000080653
+0.000000079927
+0.000000079207
+0.000000078492
+0.000000077784
+0.000000077082
+0.000000076385
+0.000000075694
+0.000000075009
+0.00000007433
+0.000000073656
+0.000000072988
+0.000000072325
+0.000000071668
+0.000000071016
+0.00000007037
+0.000000069729
+0.000000069094
+0.000000068463
+0.000000067838
+0.000000067218
+0.000000066604
+0.000000065994
+0.000000065389
+0.00000006479
+0.000000064195
+0.000000063605
+0.000000063021
+0.000000062441
+0.000000061865
+0.000000061295
+0.000000060729
+0.000000060168
+0.000000059612
+0.00000005906
+0.000000058513
+0.00000005797
+0.000000057432
+0.000000056898
+0.000000056369
+0.000000055844
+0.000000055323
+0.000000054807
+0.000000054295
+0.000000053787
+0.000000053284
+0.000000052784
+0.000000052289
+0.000000051798
+0.000000051311
+0.000000050828
+0.000000050349
+0.000000049873
+0.000000049402
+0.000000048935
+0.000000048472
+0.000000048012
+0.000000047556
+0.000000047104
+0.000000046656
+0.000000046212
+0.000000045771
+0.000000045334
+0.0000000449
+0.00000004447
+0.000000044044
+0.000000043621
+0.000000043202
+0.000000042786
+0.000000042374
+0.000000041965
+0.000000041559
+0.000000041157
+0.000000040758
+0.000000040363
+0.000000039971
+0.000000039582
+0.000000039196
+0.000000038813
+0.000000038434
+0.000000038058
+0.000000037685
+0.000000037315
+0.000000036948
+0.000000036585
+0.000000036224
+0.000000035866
+0.000000035512
+0.00000003516
+0.000000034811
+0.000000034465
+0.000000034122
+0.000000033782
+0.000000033445
+0.000000033111
+0.000000032779
+0.000000032451
+0.000000032125
+0.000000031801
+0.000000031481
+0.000000031163
+0.000000030848
+0.000000030535
+0.000000030225
+0.000000029918
+0.000000029613
+0.000000029311
+0.000000029012
+0.000000028715
+0.00000002842
+0.000000028128
+0.000000027839
+0.000000027552
+0.000000027267
+0.000000026985
+0.000000026705
+0.000000026428
+0.000000026153
+0.00000002588
+0.00000002561
+0.000000025342
+0.000000025076
+0.000000024812
+0.000000024551
+0.000000024292
+0.000000024035
+0.000000023781
+0.000000023528
+0.000000023278
+0.00000002303
+0.000000022784
+0.00000002254
+0.000000022299
+0.000000022059
+0.000000021822
+0.000000021586
+0.000000021353
+0.000000021121
+0.000000020892
+0.000000020664
+0.000000020439
+0.000000020216
+0.000000019994
+0.000000019775
+0.000000019557
+0.000000019341
+0.000000019127
+0.000000018915
+0.000000018705
+0.000000018497
+0.00000001829
+0.000000018086
+0.000000017883
+0.000000017682
+0.000000017483
+0.000000017285
+0.00000001709
+0.000000016896
+0.000000016703
+0.000000016513
+0.000000016324
+0.000000016137
+0.000000015951
+0.000000015767
+0.000000015585
+0.000000015405
+0.000000015226
+0.000000015048
+0.000000014873
+0.000000014699
+0.000000014526
+0.000000014355
+0.000000014186
+0.000000014018
+0.000000013851
+0.000000013686
+0.000000013523
+0.000000013361
+0.000000013201
+0.000000013042
+0.000000012885
+0.000000012729
+0.000000012574
+0.000000012421
+0.000000012269
+0.000000012119
+0.00000001197
+0.000000011823
+0.000000011676
+0.000000011532
+0.000000011388
+0.000000011246
+0.000000011105
+0.000000010966
+0.000000010828
+0.000000010691
+0.000000010556
+0.000000010421
+0.000000010289
+0.000000010157
+0.000000010026
+0.000000009897
+0.000000009769
+0.000000009643
+0.000000009517
+0.000000009393
+0.00000000927
+0.000000009148
+0.000000009027
+0.000000008908
+0.000000008789
+0.000000008672
+0.000000008556
+0.000000008441
+0.000000008328
+0.000000008215
+0.000000008103
+0.000000007993
+0.000000007884
+0.000000007775
+0.000000007668
+0.000000007562
+0.000000007457
+0.000000007353
+0.00000000725
+0.000000007148
+0.000000007048
+0.000000006948
+0.000000006849
+0.000000006751
+0.000000006654
+0.000000006559
+0.000000006464
+0.00000000637
+0.000000006277
+0.000000006185
+0.000000006094
+0.000000006004
+0.000000005915
+0.000000005827
+0.00000000574
+0.000000005654
+0.000000005569
+0.000000005484
+0.000000005401
+0.000000005318
+0.000000005237
+0.000000005156
+0.000000005076
+0.000000004997
+0.000000004919
+0.000000004841
+0.000000004765
+0.000000004689
+0.000000004614
+0.00000000454
+0.000000004467
+0.000000004395
+0.000000004323
+0.000000004253
+0.000000004183
+0.000000004114
+0.000000004045
+0.000000003978
+0.000000003911
+0.000000003845
+0.00000000378
+0.000000003715
+0.000000003652
+0.000000003589
+0.000000003526
+0.000000003465
+0.000000003404
+0.000000003344
+0.000000003285
+0.000000003226
+0.000000003168
+0.000000003111
+0.000000003055
+0.000000002999
+0.000000002944
+0.000000002889
+0.000000002835
+0.000000002782
+0.00000000273
+0.000000002678
+0.000000002627
+0.000000002577
+0.000000002527
+0.000000002478
+0.000000002429
+0.000000002381
+0.000000002334
+0.000000002287
+0.000000002241
+0.000000002196
+0.000000002151
+0.000000002107
+0.000000002063
+0.00000000202
+0.000000001978
+0.000000001936
+0.000000001895
+0.000000001854
+0.000000001814
+0.000000001775
+0.000000001736
+0.000000001697
+0.000000001659
+0.000000001622
+0.000000001585
+0.000000001549
+0.000000001513
+0.000000001478
+0.000000001444
+0.00000000141
+0.000000001376
+0.000000001343
+0.00000000131
+0.000000001278
+0.000000001247
+0.000000001216
+0.000000001185
+0.000000001155
+0.000000001125
+0.000000001096
+0.000000001068
+0.000000001039
+0.000000001012
+0.000000000985
+0.000000000958
+0.000000000932
+0.000000000906
+0.00000000088
+0.000000000855
+0.000000000831
+0.000000000807
+0.000000000783
+0.00000000076
+0.000000000737
+0.000000000715
+0.000000000693
+0.000000000671
+0.00000000065
+0.00000000063
+0.000000000609
+0.00000000059
+0.00000000057
+0.000000000551
+0.000000000532
+0.000000000514
+0.000000000496
+0.000000000479
+0.000000000462
+0.000000000445
+0.000000000428
+0.000000000412
+0.000000000397
+0.000000000381
+0.000000000366
+0.000000000352
+0.000000000338
+0.000000000324
+0.00000000031
+0.000000000297
+0.000000000284
+0.000000000272
+0.00000000026
+0.000000000248
+0.000000000236
+0.000000000225
+0.000000000214
+0.000000000203
+0.000000000193
+0.000000000183
+0.000000000174
+0.000000000164
+0.000000000155
+0.000000000146
+0.000000000138
+0.00000000013
+0.000000000122
+0.000000000114
+0.000000000107
+0.0000000001
+0.000000000093
+0.000000000087
+0.000000000081
+0.000000000075
+0.000000000069
+0.000000000063
+0.000000000058
+0.000000000053
+0.000000000049
+0.000000000044
+0.00000000004
+0.000000000036
+0.000000000032
+0.000000000029
+0.000000000025
+0.000000000022
+0.00000000002
+0.000000000017
+0.000000000015
+0.000000000012
+0.00000000001
+0.000000000008
+0.000000000007
+0.000000000005
+0.000000000004
+0.000000000003
+0.000000000002
+0.000000000001
+0.000000000001
+0
+0
+0
diff --git a/help/manual_files/nucleotide_RATES.txt b/help/manual_files/nucleotide_RATES.txt
new file mode 100644
index 0000000..8608f0a
--- /dev/null
+++ b/help/manual_files/nucleotide_RATES.txt
@@ -0,0 +1,685 @@
+Rates file : INDELible V1.00 
+
+Site	Rate	Inserted?	Partition
+1	0.249957	Y	1
+2	0.872481	Y	1
+3	0.980657	Y	1
+4	0.393844	Y	1
+5	0.875117	Y	1
+1	0.249957 	Y	1
+2	0.872481 	Y	1
+3	0.980657 	Y	1
+4	0.393844 	Y	1
+5	0.875117 	Y	1
+6	0.791917 	 	1
+7	0.465039 	Y	1
+8	0.186378 	 	1
+9	0.30224  	Y	1
+10	0.460121 	 	1
+11	0.811728 	Y	1
+12	0.32821  	Y	1
+13	2.6801   	 	1
+14	0.952254 	Y	1
+15	1.03319  	 	1
+16	0.177073 	Y	1
+17	0.935987 	Y	1
+18	0.247596 	Y	1
+19	1.58896  	 	1
+20	1.2062   	Y	1
+21	0.746537 	Y	1
+22	0.918666 	Y	1
+23	0.944981 	Y	1
+24	0.454774 	Y	1
+25	0.522728 	Y	1
+26	1.97235  	Y	1
+27	0.359178 	Y	1
+28	0.184927 	Y	1
+29	1.66388  	 	1
+30	0.473696 	Y	1
+31	1.07622  	Y	1
+32	0.564921 	 	1
+33	1.93328  	 	1
+34	0.253382 	Y	1
+35	0.902886 	Y	1
+36	1.24948  	 	1
+37	0.708456 	 	1
+38	0.47735  	Y	1
+39	1.57542  	Y	1
+40	1.58743  	 	1
+41	0.485011 	Y	1
+42	0.76292  	Y	1
+43	0.862071 	Y	1
+44	0.949702 	Y	1
+45	0.373606 	Y	1
+46	0.588943 	Y	1
+47	1.20029  	Y	1
+48	1.85733  	Y	1
+49	0.821937 	 	1
+50	1.55513  	 	1
+51	0.336266 	Y	1
+52	2.41017  	 	1
+53	0.916736 	 	1
+54	1.00476  	Y	1
+55	1.43367  	Y	1
+56	0.999933 	Y	1
+57	2.01392  	Y	1
+58	0.845175 	Y	1
+59	1.95497  	Y	1
+60	3.26338  	Y	1
+61	1.25536  	Y	1
+62	1.31304  	Y	1
+63	0.0783243	Y	1
+64	0.736997 	Y	1
+65	0.945556 	Y	1
+66	0.455374 	Y	1
+67	1.34109  	Y	1
+68	0.694815 	Y	1
+69	1.36036  	Y	1
+70	1.72777  	Y	1
+71	0.117869 	Y	1
+72	0.544521 	 	1
+73	1.05876  	Y	1
+74	0.823658 	Y	1
+75	1.90874  	Y	1
+76	0.329399 	Y	1
+77	0.385247 	Y	1
+78	0.187594 	 	1
+79	1.40182  	Y	1
+80	2.46539  	Y	1
+81	1.86131  	Y	1
+82	0.223623 	Y	1
+83	0.189851 	Y	1
+84	0.989944 	Y	1
+85	1.69327  	Y	1
+86	1.96202  	Y	1
+87	0.567865 	Y	1
+88	0.746278 	Y	1
+89	0.78294  	Y	1
+90	0.68429  	Y	1
+91	0.254162 	 	1
+92	0.27365  	Y	1
+93	0.482601 	Y	1
+94	0.74716  	 	1
+95	0.458177 	Y	1
+96	2.17723  	 	1
+97	1.26743  	 	1
+98	0.234839 	 	1
+99	1.32562  	 	1
+100	0.347025 	Y	1
+101	1.06726  	Y	1
+102	1.69343  	Y	1
+103	0.588804 	Y	1
+104	3.09656  	Y	1
+105	0.754185 	Y	1
+106	0.552769 	Y	1
+107	0.776593 	Y	1
+108	0.803058 	Y	1
+109	0.70077  	 	1
+110	0.729849 	 	1
+111	0.410579 	Y	1
+112	1.49225  	Y	1
+113	2.00986  	Y	1
+114	0.261835 	Y	1
+115	1.98319  	 	1
+116	1.61365  	Y	1
+117	1.38582  	Y	1
+118	1.39488  	Y	1
+119	0.501454 	Y	1
+120	0.70998  	Y	1
+121	0.331795 	Y	1
+122	0.485105 	Y	1
+123	0.312151 	Y	1
+124	2.25576  	Y	1
+125	0.569814 	Y	1
+126	1.29459  	Y	1
+127	2.45452  	Y	1
+128	0.910478 	Y	1
+129	0.712834 	 	1
+130	0.244339 	Y	1
+131	2.30076  	 	1
+132	1.03157  	 	1
+133	0.675499 	 	1
+134	1.54959  	Y	1
+135	0.430812 	Y	1
+136	1.95741  	Y	1
+137	0.0310587	Y	1
+138	1.57342  	Y	1
+139	1.27166  	Y	1
+140	1.62914  	 	1
+141	1.03634  	Y	1
+142	0.628177 	 	1
+143	0.37337  	Y	1
+144	0.406194 	 	1
+145	1.31427  	Y	1
+146	1.80333  	 	1
+147	0.530385 	Y	1
+148	0.532045 	Y	1
+149	0.172479 	Y	1
+150	1.01958  	 	1
+151	0.972377 	Y	1
+152	0.604558 	Y	1
+153	1.86302  	 	1
+154	1.06046  	Y	1
+155	0.657714 	 	1
+156	2.63459  	Y	1
+157	0.924919 	 	1
+158	1.63187  	Y	1
+159	0.24556  	Y	1
+160	0.521293 	Y	1
+161	1.55852  	Y	1
+162	0.286215 	Y	1
+163	0.980977 	 	1
+164	0.889197 	Y	1
+165	0.150078 	Y	1
+166	0.125449 	Y	1
+167	0.371049 	 	1
+168	0.96819  	Y	1
+169	1.90233  	Y	1
+170	2.82239  	Y	1
+171	0.314519 	 	1
+172	1.2457   	Y	1
+173	1.40561  	Y	1
+174	0.104023 	Y	1
+175	0.191259 	 	1
+176	1.10075  	Y	1
+177	0.471978 	 	1
+178	0.521206 	 	1
+179	0.904074 	Y	1
+180	0.305125 	 	1
+181	2.00481  	Y	1
+182	1.1185   	Y	1
+183	1.25254  	 	1
+184	0.352447 	 	1
+185	1.77956  	Y	1
+186	1.43163  	Y	1
+187	0.237888 	Y	1
+188	0.24623  	Y	1
+189	1.41508  	Y	1
+190	0.602284 	 	1
+191	0.381701 	Y	1
+192	0.601748 	Y	1
+193	1.2223   	Y	1
+194	1.2409   	Y	1
+195	0.517592 	Y	1
+196	0.616613 	 	1
+197	0.559638 	Y	1
+198	0.76103  	 	1
+199	1.31136  	Y	1
+200	0.198858 	Y	1
+201	1.54253  	Y	1
+202	0.363423 	Y	1
+203	1.53675  	Y	1
+204	0.306936 	 	1
+205	0.287824 	 	1
+206	1.01682  	 	1
+207	2.67341  	 	1
+208	0.790511 	Y	1
+209	1.60437  	 	1
+210	0.850907 	 	1
+211	0.348633 	Y	1
+212	2.24245  	Y	1
+213	0.191527 	Y	1
+214	0.462724 	 	1
+215	1.24113  	 	1
+216	0.317217 	 	1
+217	0.165044 	 	1
+218	0.847599 	Y	1
+219	0.607848 	Y	1
+220	0.434421 	 	1
+221	0.650792 	Y	1
+222	1.55706  	 	1
+223	1.84468  	Y	1
+224	2.38921  	Y	1
+225	0.674795 	Y	1
+226	0.307901 	 	1
+227	0.703835 	 	1
+228	0.692353 	Y	1
+229	0.227558 	Y	1
+230	0.557155 	Y	1
+231	3.2873   	Y	1
+232	0.982411 	Y	1
+233	1.43288  	Y	1
+234	0.503484 	Y	1
+235	2.11936  	 	1
+236	1.35123  	 	1
+237	1.62377  	 	1
+238	1.9435   	Y	1
+239	0.829563 	Y	1
+240	0.808758 	Y	1
+241	0.108672 	Y	1
+242	0.683026 	Y	1
+243	0.327198 	 	1
+244	0.39526  	Y	1
+245	1.11183  	Y	1
+246	2.12909  	 	1
+247	0.341678 	 	1
+248	0.983624 	Y	1
+249	0.592593 	Y	1
+250	0.643122 	 	1
+251	1.09984  	Y	1
+252	0.554412 	 	1
+253	1.93019  	Y	1
+254	1.4179   	Y	1
+255	0.994049 	Y	1
+256	0.425317 	Y	1
+257	0.914301 	Y	1
+258	0.747811 	Y	1
+259	2.40244  	Y	1
+260	1.21901  	 	1
+261	0.854944 	 	1
+262	0.31072  	 	1
+263	0.374872 	Y	1
+264	1.03458  	 	1
+265	0.64697  	Y	1
+266	3.03872  	 	1
+267	0.65626  	 	1
+268	2.6087   	Y	1
+269	1.55944  	Y	1
+270	0.468887 	Y	1
+271	0.714307 	Y	1
+272	1.57652  	Y	1
+273	1.54202  	Y	1
+274	0.39241  	Y	1
+275	0.292652 	Y	1
+276	0.513898 	Y	1
+277	1.2683   	Y	1
+278	1.46854  	Y	1
+279	0.798511 	Y	1
+280	0.547613 	Y	1
+281	4.32147  	Y	1
+282	0.375858 	Y	1
+283	1.37047  	Y	1
+284	0.884493 	Y	1
+285	1.62142  	Y	1
+286	0.0614729	Y	1
+287	0.735878 	Y	1
+288	1.12611  	Y	1
+289	0.223438 	Y	1
+290	0.817089 	Y	1
+291	0.269421 	Y	1
+292	0.636062 	 	1
+293	1.77009  	Y	1
+294	0.875993 	Y	1
+295	0.700604 	 	1
+296	0.316974 	Y	1
+297	2.53561  	 	1
+298	1.29629  	 	1
+299	1.08557  	 	1
+300	0.716177 	Y	1
+301	0.779094 	 	1
+302	0.604449 	Y	1
+303	0.538389 	Y	1
+304	0.861123 	 	1
+305	0.509631 	Y	1
+306	0.484631 	Y	1
+307	1.06734  	Y	1
+308	1.30366  	Y	1
+309	2.20686  	Y	1
+310	1.64733  	 	1
+311	2.3059   	Y	1
+312	0.378002 	Y	1
+313	0.784026 	Y	1
+314	2.35966  	Y	1
+315	1.49118  	Y	1
+316	1.11968  	Y	1
+317	0.487402 	 	1
+318	0.188567 	Y	1
+319	1.60619  	Y	1
+320	1.39191  	 	1
+321	0.841103 	 	1
+322	0.978581 	 	1
+323	0.870735 	Y	1
+324	1.63125  	 	1
+325	1.76922  	 	1
+326	0.445871 	 	1
+327	0.263504 	Y	1
+328	0.156602 	 	1
+329	1.28387  	 	1
+330	0.821501 	 	1
+331	0.729364 	 	1
+332	1.01711  	 	1
+333	2.60401  	 	1
+6	0.160109	Y	2
+7	0.0428472	Y	2
+8	1.33058	Y	2
+1	0.160109 	Y	2
+2	0.0428472	Y	2
+3	1.33058  	Y	2
+4	0.490114 	 	2
+5	0.767275 	 	2
+6	0        	Y	2
+7	2.85469  	Y	2
+8	0        	Y	2
+9	0        	Y	2
+10	0        	Y	2
+11	2.88344  	Y	2
+12	1.3605   	Y	2
+13	0.293199 	Y	2
+14	0        	Y	2
+15	1.52114  	Y	2
+16	0        	Y	2
+17	0        	Y	2
+18	0        	Y	2
+19	2.33513  	Y	2
+20	2.98584  	 	2
+21	1.32706  	Y	2
+22	1.9684   	Y	2
+23	2.03099  	Y	2
+24	0        	Y	2
+25	1.1591   	 	2
+26	1.54952  	 	2
+27	2.55582  	 	2
+28	0.432553 	Y	2
+29	0        	Y	2
+30	2.06446  	Y	2
+31	0        	Y	2
+32	0.161588 	Y	2
+33	0        	Y	2
+34	1.33458  	Y	2
+35	0        	Y	2
+36	1.34994  	Y	2
+37	0.384733 	Y	2
+38	0        	 	2
+39	0        	 	2
+40	1.82708  	Y	2
+41	1.45464  	 	2
+42	0.904905 	 	2
+43	0.520922 	Y	2
+44	0        	Y	2
+45	3.08618  	Y	2
+46	0.989367 	Y	2
+47	0        	Y	2
+48	1.99929  	Y	2
+49	0.457647 	Y	2
+50	0        	Y	2
+51	0.480238 	Y	2
+52	0        	Y	2
+53	1.77594  	Y	2
+54	0        	Y	2
+55	1.33498  	Y	2
+56	0.341005 	Y	2
+57	1.34464  	Y	2
+58	0        	Y	2
+59	0        	Y	2
+60	1.3242   	Y	2
+61	0        	Y	2
+62	0        	Y	2
+63	1.18069  	Y	2
+64	0.823308 	Y	2
+65	3.21632  	Y	2
+66	0        	Y	2
+67	1.05904  	Y	2
+68	0        	Y	2
+69	0.552467 	Y	2
+70	2.11862  	Y	2
+71	0.524586 	 	2
+72	0        	 	2
+73	1.90698  	 	2
+74	0.471826 	 	2
+75	0        	Y	2
+76	0        	Y	2
+77	0        	Y	2
+78	1.56499  	Y	2
+79	1.62721  	 	2
+80	1.931    	Y	2
+81	2.02313  	Y	2
+82	2.00539  	 	2
+83	0        	Y	2
+84	0.725401 	 	2
+85	4.69031  	Y	2
+86	0        	Y	2
+87	1.99463  	Y	2
+88	1.19036  	 	2
+89	3.39791  	Y	2
+90	1.58744  	 	2
+91	0.799174 	Y	2
+92	0.363233 	 	2
+93	0.94096  	 	2
+94	0.643149 	Y	2
+95	2.03014  	Y	2
+96	0        	 	2
+97	0.870119 	Y	2
+98	1.11653  	Y	2
+99	0.721238 	Y	2
+100	0.748319 	Y	2
+101	3.83632  	Y	2
+102	0        	Y	2
+103	1.50354  	Y	2
+104	0        	Y	2
+105	0        	Y	2
+106	0.747972 	Y	2
+107	2.93681  	Y	2
+108	1.93804  	Y	2
+109	0        	Y	2
+110	0.62641  	 	2
+111	1.09533  	 	2
+112	0.335808 	Y	2
+113	0        	Y	2
+114	0.674984 	 	2
+115	1.6564   	Y	2
+116	0        	Y	2
+117	1.92226  	Y	2
+118	0        	 	2
+119	0        	 	2
+120	0.792303 	Y	2
+121	0.811686 	Y	2
+122	0        	Y	2
+123	0        	Y	2
+124	0.124224 	Y	2
+125	0.659214 	Y	2
+126	0.565793 	 	2
+127	1.20414  	Y	2
+128	0.474411 	Y	2
+129	1.04551  	Y	2
+130	1.87444  	Y	2
+131	0.423945 	 	2
+132	0        	Y	2
+133	0.578594 	 	2
+134	0        	Y	2
+135	0.653803 	Y	2
+136	0        	Y	2
+137	0.353462 	Y	2
+138	1.78101  	 	2
+139	0.2076   	Y	2
+140	1.31161  	Y	2
+141	0.955153 	 	2
+142	0        	Y	2
+143	0.857177 	Y	2
+144	2.95138  	Y	2
+145	0.280407 	Y	2
+146	0.31548  	Y	2
+147	0        	Y	2
+148	2.51072  	Y	2
+149	0.745482 	Y	2
+150	0        	Y	2
+151	2.45905  	Y	2
+152	3.6838   	 	2
+153	0.705751 	 	2
+154	0        	Y	2
+155	2.45382  	 	2
+156	2.10212  	Y	2
+157	3.33327  	Y	2
+158	0.215105 	Y	2
+159	0        	 	2
+160	0.503885 	Y	2
+161	0        	Y	2
+162	0.746868 	Y	2
+163	0.608215 	 	2
+164	0.83693  	Y	2
+165	0.601628 	Y	2
+166	1.04207  	Y	2
+167	0        	 	2
+168	0        	Y	2
+169	0        	Y	2
+170	0        	Y	2
+171	1.58989  	Y	2
+172	0        	Y	2
+173	0        	 	2
+174	0.591605 	Y	2
+175	1.16007  	Y	2
+176	2.87367  	Y	2
+177	0        	 	2
+178	1.97588  	 	2
+179	0        	Y	2
+180	2.78596  	Y	2
+181	0        	Y	2
+182	2.80532  	Y	2
+183	1.48172  	 	2
+184	0.377787 	Y	2
+185	0        	Y	2
+186	0        	 	2
+187	1.24746  	 	2
+188	0        	Y	2
+189	1.10607  	 	2
+190	3.63165  	 	2
+191	1.25262  	 	2
+192	0        	 	2
+193	0        	 	2
+194	1.29678  	Y	2
+195	1.46779  	 	2
+196	0        	 	2
+197	1.6192   	Y	2
+198	0.761319 	 	2
+199	1.59083  	 	2
+200	0        	 	2
+201	1.2853   	Y	2
+202	0        	Y	2
+203	0        	Y	2
+204	1.75012  	Y	2
+205	0        	Y	2
+206	1.35364  	Y	2
+207	1.24017  	Y	2
+208	0.867253 	 	2
+209	0        	 	2
+210	2.55934  	Y	2
+211	0.600399 	Y	2
+212	0.790759 	Y	2
+213	0        	Y	2
+214	0.668983 	 	2
+215	0        	Y	2
+216	2.51011  	 	2
+217	0.851854 	Y	2
+218	0        	Y	2
+219	3.34492  	Y	2
+220	0.821375 	Y	2
+221	0        	Y	2
+222	2.83345  	 	2
+223	2.21489  	Y	2
+224	1.38715  	Y	2
+225	0        	Y	2
+226	0.55967  	 	2
+227	0        	 	2
+228	0.162868 	 	2
+229	0        	 	2
+230	1.85547  	Y	2
+231	0.916852 	Y	2
+232	0        	Y	2
+233	0        	 	2
+234	2.98562  	 	2
+235	1.56992  	Y	2
+236	1.25945  	Y	2
+237	1.65672  	Y	2
+238	0        	Y	2
+239	1.14264  	Y	2
+240	0.359083 	Y	2
+241	1.23818  	Y	2
+242	1.25847  	Y	2
+243	1.41182  	Y	2
+244	0.744149 	Y	2
+245	1.33012  	Y	2
+246	4.94438  	 	2
+247	0        	 	2
+248	0        	 	2
+249	0        	Y	2
+250	0        	Y	2
+251	0        	Y	2
+252	2.72715  	Y	2
+253	0        	Y	2
+254	0        	Y	2
+255	3.65499  	Y	2
+256	0        	Y	2
+257	3.78742  	Y	2
+258	0.827003 	Y	2
+259	2.20194  	Y	2
+260	0        	 	2
+261	0        	Y	2
+262	0.723882 	Y	2
+263	0        	 	2
+264	0.439193 	 	2
+265	0        	 	2
+266	0.312494 	 	2
+267	0.676104 	 	2
+268	1.87421  	Y	2
+269	0.606016 	Y	2
+270	1.38591  	Y	2
+271	0.867269 	Y	2
+272	0.681016 	Y	2
+273	0        	Y	2
+274	0.421938 	 	2
+275	1.62438  	Y	2
+276	0.825435 	Y	2
+277	0.691646 	Y	2
+278	0.873512 	Y	2
+279	0        	Y	2
+280	1.10565  	 	2
+281	0        	 	2
+282	0        	 	2
+283	0.778692 	Y	2
+284	0.239517 	 	2
+285	0        	Y	2
+286	0        	Y	2
+287	0.375574 	Y	2
+288	1.79261  	 	2
+289	2.64067  	 	2
+290	0        	 	2
+291	1.33295  	 	2
+292	0.528891 	Y	2
+293	0.895208 	Y	2
+294	0        	 	2
+295	1.60097  	Y	2
+296	0        	Y	2
+297	0        	Y	2
+298	1.35965  	Y	2
+299	1.64604  	Y	2
+300	0        	 	2
+301	0        	 	2
+302	2.04655  	 	2
+303	0.362101 	Y	2
+304	0        	Y	2
+305	2.43253  	Y	2
+306	0.431022 	Y	2
+307	1.89166  	 	2
+308	1.60154  	 	2
+309	0.84181  	Y	2
+310	1.04489  	 	2
+311	0        	 	2
+312	3.42973  	Y	2
+313	0.713986 	Y	2
+314	2.42327  	Y	2
+315	2.37023  	Y	2
+316	1.93284  	 	2
+317	0.762738 	Y	2
+318	1.24872  	 	2
+319	0.16129  	Y	2
+320	0        	Y	2
+321	1.75649  	 	2
+322	0        	Y	2
+323	0        	 	2
+324	2.31344  	Y	2
+325	0.653912 	Y	2
+326	2.00172  	Y	2
+327	2.74299  	Y	2
+328	0        	 	2
+329	2.73293  	 	2
+330	0.999909 	Y	2
+331	3.85435  	Y	2
+332	0        	Y	2
+333	2.08006  	 	2
+334	0        	Y	2
+335	0.684066 	Y	2
+336	1.5619   	Y	2
+337	2.27034  	 	2
+338	1.3827   	Y	2
+339	0        	Y	2
+340	0.836637 	 	2
+341	1.29447  	Y	2
diff --git a/help/manual_files/partitions.shtml b/help/manual_files/partitions.shtml
new file mode 100644
index 0000000..28b2f12
--- /dev/null
+++ b/help/manual_files/partitions.shtml
@@ -0,0 +1,37 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[PARTITIONS] block</h2>
+
+<p>
+This block type is used to set root lengths and to choose which models are used with which trees. 
+In addition it is used when simulating multi-partitioned datasets where different sections of the 
+simulated dataset are created with different trees and models. 
+
+<hr>
+<a name="top"><br><p><u><b>Example Usage:</u></b></p></a>  
+<pre>
+  [PARTITIONS] partitionname [treename name rootlength]
+
+  [PARTITIONS] pM		
+    [t1  m1  rootlength1]
+    [t2  m2  rootlength2] 
+    [t3  b3  rootlength3]
+    [t4  m4  rootlength4]
+    [t5  b5  rootlength5]
+</pre>
+<li><i>partitionname</i> is used to identify a particular [PARTITIONS] block in the <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/tree.shtml">[EVOLVE]</a> block.</li> 
+<li><i>treename</i> is the name of any previously defined <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/tree.shtml">[TREE]</a> block.</li> 
+<li><i>name</i> is the name of any previously defined <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/model.shtml">[MODEL]</a> or 
+<a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/branches.shtml">[BRANCHES]</a> block.</li>
+<li><i>rootlength</i> is the length of the root sequence that will be generated for this partition.</li>
+<br>
+<li>If using a <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/branches.shtml">[BRANCHES]</a> block instead of a <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/model.shtml">[MODEL]</a> block 
+then remember that the trees from the <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/tree.shtml">[TREE]</a> and the <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/branches.shtml">[BRANCHES]</a> block 
+must match.</li>
+<li>Because of this it is NOT permitted to use random trees with <a href="http://abacus.gene.ucl.ac.uk/software/indelible/manual/branches.shtml">[BRANCHES]</a> blocks.</li>
+<br>
+<li><i>pM</i> is an example of how to define the [PARTITIONS] block when you want to generate multi-partitioned datasets.</li>
+<li>The tree, root length and model/branch class can be different in each and every partition and there is no limit on the number of partitions other than that imposed by computer memory.</li>
+<li>However the trees must all have the same number of taxa and branch-classes can not be used in the same partition as random trees.
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/random_branch_length_trees.JPG b/help/manual_files/random_branch_length_trees.JPG
new file mode 100644
index 0000000..266230d
Binary files /dev/null and b/help/manual_files/random_branch_length_trees.JPG differ
diff --git a/help/manual_files/settings.shtml b/help/manual_files/settings.shtml
new file mode 100644
index 0000000..d03d3dd
--- /dev/null
+++ b/help/manual_files/settings.shtml
@@ -0,0 +1,99 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[SETTINGS] block</h2>
+
+<p><ul>
+<li>This block specifies non-essential user preferences such as output file types and formats, seeds for the random number generator, and whether to output detailed reports.</li>
+<li>If a command is not specified in the [SETTINGS] block then it will have the default value shown below in the example usage. The only exception to this is <a href="#[randomseed]">[randomseed]</a> whose value will be randomly chosen if not specified.</li>
+<li>If no [SETTINGS] block is specified all commands will have these default values.</li>
+<li>Please click on any of the commands to learn more about them.</li>
+</ul></p>
+<hr>
+<a name="top"><br><p><u><b>Example Usage:</u></b></p></a>  
+
+<pre>
+[SETTINGS]    
+  <a href="#[ancestralprint]"         >[ancestralprint]</a>           FALSE     // NEW, SAME or FALSE
+  <a href="#[output]"                 >[output]</a>                   PHYLIP    // FASTA, NEXUS, PHYLIP or PHYLIPT
+  <a href="#[phylipextension]"        >[phylipextension]</a>          phy       // any alpha-numeric string
+  <a href="#[nexusextension]"         >[nexusextension]</a>           nex       // any alpha-numeric string
+  <a href="#[fastaextension]"         >[fastaextension]</a>           fas       // any alpha-numeric string
+  <a href="#[randomseed]"             >[randomseed]</a>               1568746   // any integer
+  <a href="#[printrates]"             >[printrates]</a>               FALSE     // FALSE or TRUE
+  <a href="#[insertaslowercase]"      >[insertaslowercase]</a>        TRUE      // FALSE or TRUE
+  <a href="#[markdeletedinsertions]"  >[markdeletedinsertions]</a>    FALSE     // FALSE or TRUE
+  <a href="#[printcodonsasaminoacids]">[printcodonsasaminoacids]</a>  FALSE     // FALSE or TRUE
+  <a href="#[fileperrep]"             >[fileperrep]</a>               FALSE     // FALSE or TRUE
+</pre>
+<hr>
+
+<pre><a name="[ancestralprint]">[ancestralprint]</a></pre><ul>
+<li><i>NEW</i> will print ancestral sequences in a separate file to leaf sequences.</li>
+<li><i>SAME</i> prints ancestral sequences in the same file as the leaf sequences.</li>
+<li><i>FALSE</i> will not print any ancestral sequences.</li>
+<li>It should be noted that if you used different guide trees for different partitions in a partitioned (multi-gene) analysis then only the root sequence will be printed in SAME/NEW file specified in the last command.</li>
+<li><a name="[output]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[output]</pre><ul>
+<li><i>FASTA</i>, <i>NEXUS</i>, <i>PHYLIP</i> will print out sequences to file in either fasta, nexus, or phylip format respectively. </li>
+<li>FASTA is used by NCBI and accepted by most sequence alignment programs.  NEXUS is used by e.g. MacClade, Mesquite, ModelTest, MrBayes and PAUP*.  PHYLIP is used by PHYLIP and PAML.</li>
+<li><i>PHYLIPT</i> gives PHYLIP format with filenames truncated to 8 characters. </li>
+<li>Unaligned sequences are always output in FASTA format as e.g. filename.fas</li>
+<li>This command sets the output type for the true alignment and prints it to a file named e.g. filename_TRUE.phy</li>
+<li>For more details about different output files see the examples section.</li>
+<li><a name="[phylipextension]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[phylipextension]</pre><ul>
+<li>This command sets the file extension for true alignments in phylip format so they are e.g. filename.phy or whatever you choose them to be.</li>
+<li><a name="[nexusextension]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[nexusextension]</pre><ul>
+<li>This command sets the file extension for true alignments in nexus format so they are e.g. filename.nex or whatever you choose them to be.</li>
+<li><a name="[fastaextension]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[fastaextension]</pre><ul>
+<li>This command sets the file extension for fasta formatted output files so they are e.g. filename.fas or whatever you choose them to be.</li>
+<li><a name="[randomseed]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[randomseed]</pre><ul>
+<li>This must be an integer value and is used to seed the random number generator.</li>
+<li>Running simulations with the same random seed value (and the same control file) will produce identical datasets.</li>
+<li><a name="[printrates]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[printrates]</pre><ul>
+<li><i>TRUE</i> will print out a detailed output file for each replicate of each block that lists what the site-classes or 
+relative rates of substitution are.</li>
+<li><i>FALSE</i> will not print any rates information.</li>
+<li>Follow these links for examples of the output for <a href="nucleotide_RATES.txt" target="_blank";>NUCLEOTIDE / AMINOACID</a> simulations, or for <a href="codon_RATES.txt" target="_blank";>CODON</a> simulations.</li>
+<li><a name="[markdeletedinsertions]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[markdeletedinsertions]</pre><ul>
+<li><i>TRUE</i> will output inserted bases/residues that have been subsequently been deleted as * rather than - for easy identification.</li>
+<li><i>FALSE</i> will output all deletions as "-".</li>
+<li><a name="[insertaslowercase]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[insertaslowercase]</pre><ul>
+<li><i>TRUE</i> will output inserted bases/residues in lower case letters for easy identification.</li>
+<li><i>FALSE</i> will output all bases/residues as upper case letters.</li>
+<li><a name="[printcodonsasaminoacids]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[printcodonsasaminoacids]</pre><ul>
+<li><i>TRUE</i> will output codon datasets as amino-acids - how they are translated will depend on the genetic code specified in the model.</li>
+<li><i>FALSE</i> will print codons as nucleotide triplets.</li>
+<li><a name="[fileperrep]"><a href="#top">Return to example usage.</a></a></li>
+
+</ul><hr><pre>[fileperrep]</pre><ul>
+<li><i>TRUE</i> will output each replicate dataset in a separate file. <br>
+Unaligned sequences will go in e.g. filename_1.fas, filename_2.fas, etc. <br>
+The true alignment will go in e.g. filename_TRUE_1.phy, filename_TRUE_2.phy, etc</li>
+<li><i>FALSE</i> will print all replicates in a single file. <br>
+Unaligned sequences for each dataset will all go in e.g. filename.fas.  <br>
+All the true alignments will go in e.g. filename_TRUE.phy</li>
+<li>If a file called paupstart.txt (or paupend.txt) exists in the same directory as INDELible then it will be copied to the beginning (or end) of each output file. </li>
+<li>If a file called paupmiddle.txt exists in the same directory as INDELible then it will be copied to e.g. filename_TRUE.phy after each replicate datset.</li>
+<li>These features are useful if you want to include PAUP or MrBayes blocks in your files.</li>
+
+<li><a href="#top">Return to example usage.</a></li>
+</ul>
+<!--#include file="files/bottom.html" -->
diff --git a/help/manual_files/symQmatrix.gif b/help/manual_files/symQmatrix.gif
new file mode 100644
index 0000000..faaed17
Binary files /dev/null and b/help/manual_files/symQmatrix.gif differ
diff --git a/help/manual_files/tree.shtml b/help/manual_files/tree.shtml
new file mode 100644
index 0000000..7af0745
--- /dev/null
+++ b/help/manual_files/tree.shtml
@@ -0,0 +1,130 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[TREE] block</h2>
+
+<p>
+These blocks are used to specify the trees used during simulation.
+
+<hr>
+<a name="top"><br><p><u><b>User Defined Trees:</u></b></p></a>  
+<li>User trees can be rooted or unrooted and may contain any number of spaces, tabs or new lines.</li>
+<li>The tree name is used to refer to the tree in <a href="partitions.shtml">[PARTITIONS]</a> blocks.</li>
+<li>The 3 user trees (named t1, t2 and t3 below) will all be read as identical.</li>
+<pre>
+  [TREE] t1 ((A:0.1,B:0.1):0.1,(C:0.1,D:0.1):0.1);
+
+  [TREE] t2 ( (A:0.1, B:0.1):0.1, (C:0.1, D:0.1):0.1 );
+
+  [TREE] t3 
+    (             // trees can span any number of lines
+      (           // and include any amount of whitespace
+        A:0.1,    // including new lines.
+        B:0.1    
+      ):0.1 ,     // comments within the tree will be ignored.
+     (C:0.1,D:0.1):0.1);
+</pre>
+<li>Any tree can also be rescaled to be a certain tree length. For example the two following trees are identical.</li>
+<pre>
+  [TREE] T1 ((A:0.1,B:0.2):0.3,(C:0.4,D:0.5):0.6);
+  [treelength] 4.2
+
+  [TREE] T2 ((A:0.2,B:0.4):0.6,(C:0.8,D:1.0):1.2);
+</pre>
+
+<hr>
+<a name="top"><br><p><u><b>Random Trees:</u></b></p></a>  
+<li>Random trees can also be created by INDELible. A different tree will be generated for each replicate.</li>
+<li>Random rooted and unrooted trees require the use of more commands:</li>
+<pre>
+  [TREE] tree1
+  [unrooted] 10 2.4 1.1 0.2566 0.34  // ntaxa birth death sample mut
+
+  [TREE] tree2
+  [unrooted] 10 2.4 1.1 0.2566 0.34  // ntaxa birth death sample mut
+  [seed] 2381242                     
+ 
+  [TREE] tree3
+  [rooted] 15 6.7 2.5 0.234 0.31     // ntaxa birth death sample mut
+
+  [TREE] tree4
+  [rooted] 15 6.7 2.5 0.234 0.31     // ntaxa birth death sample mut
+  [treelength] 8
+
+  [TREE] tree5
+  [rooted] 15 6.7 2.5 0.234 0.31     // ntaxa birth death sample mut
+  [treedepth] 0.4
+</pre>
+<li><font color=blue>tree1</font> and <font color=blue>tree2</font> will be unrooted random trees whilst 
+ <font color=blue>tree3</font> and <font color=blue>tree4</font> will be rooted random trees. </li>
+<li>Every time that INDELible is run <font color=blue>tree2</font> will produce the same sequence of random trees beginning with the first replicate in 
+any <font color=blue>[EVOLVE]</font> block where it is used, until the number after 
+the <font color=blue>[seed]</font> command is changed. The other four (<font color=blue>tree1</font>, <font color=blue>tree3</font>,  <font color=blue>tree4</font> and 
+<font color=blue>tree5</font>) will always produce different trees.</li>
+<li>Please note that the  <font color=blue>[seed]</font> command overrules the use of  <font color=blue>[randomseed]</font> in a 
+ <font color=blue>[SETTINGS]</font> block. If <font color=blue>[seed]</font> is not used, then <font color=blue>[randomseed]</font> will generate
+the same sequence of trees every time a control file is run.
+<li><font color=blue>tree4</font> will produce random trees that are always rescaled to have a tree length of 8, and 
+<font color=blue>tree5</font> will produce random trees that are always rescaled to have a depth (root to tip) of 0.4, whilst the other three 
+(<font color=blue>tree1</font>, <font color=blue>tree2</font> and <font color=blue>tree3</font>) will always produce random trees 
+with different tree lengths/depths. Tree Depth can only be set for random trees.</li>
+<li>The numbers that come after the <font color=blue>[unrooted]</font> and <font color=blue>[rooted]</font> commands
+are the same in both cases.  The first number is the number of taxa (10 for tree1 and tree2, 15 for tree3 and tree4).</li>
+<li>The next  four are the parameters used in the birth-death process to create the random trees.</li>
+<li>In order, from left to right, these are the <font color=blue>birth-rate</font>, <font color=blue>death-rate</font>, 
+<font color=blue>sampling fraction</font> and <font color=blue>mutation rate</font>. Further details on these 
+parameters can be found in <a href="http://abacus.gene.ucl.ac.uk/ziheng/pdf/1997YangRannalaMBEv14p717.pdf" target="_blank">this paper</a>.</li>
+
+
+<br>
+<hr>
+<a name="top"><br><p><u><b>Branch Lengths:</u></b></p></a>  
+<li>For a given topology INDELible can also create branch lengths. </li>
+<li>This is done by using the command [branchlengths]</li>
+<pre>
+  [TREE] EQUAL-TREE
+  // No branch lengths need to be provided
+  ((((A,B),(C,D)),((E,F),(G,H))),(((I,J),(K,L)),((M,N),(O,P))));
+       
+  [branchlengths] EQUAL // All branch lengths will be equal
+  [treedepth] 0.1       // Root-to-longest-tip distance of 0.1
+
+[TREE] EQUAL-TREE2
+  // If branch lengths are provided, they are ignored
+  ((((A:0.2,B:0.1):0.4,(C:0.3,D:0.1):0.6):0.1,
+  ((E:0.1,F:0.1):0.1,(G:0.2,H:0.1):0.1):0.3):0.1,
+  (((I:0.1,J:0.6):0.1,(K:0.1,L:0.1):0.1):0.1,
+  ((M:0.4,N:0.1):0.1,(O:0.6,P:0.1):0.1):0.1):0.1); 
+
+  [branchlengths] EQUAL // Again, all branch lengths will be equal
+  [treedepth] 0.1       // Root-to-longest-tip distance of 0.1
+ 
+[TREE] ULTRAMETRIC-TREE
+  // No branch lengths need to be provided  
+  ((((A,B),(C,D)),((E,F),(G,H))),(((I,J),(K,L)),((M,N),(O,P))));
+
+  [branchlengths] ULTRAMETRIC // All branch lengths will be equal
+  [treedepth] 0.1             // Root-to-longest-tip distance of 0.1
+
+[TREE] NON-ULTRAMETRIC-TREE
+  // No branch lengths need to be provided  
+  ((((A,B),(C,D)),((E,F),(G,H))),(((I,J),(K,L)),((M,N),(O,P))));
+
+  [branchlengths] NON-ULTRAMETRIC // All branch lengths will be equal
+  [maxdistance] 0.2               // maximum pairwise distance of 0.2
+
+</pre>
+<li><font color=blue>[treedepth] 0.1</font> rescales the tree to have a maximum root-to-tip distance of 0.1
+<li>After using the <font color=blue>[branchlengths]</font> command you should use <font color=blue>[treelength]</font> or <font color=blue>[treedepth]</font>, or <font color=blue>[maxdistance]</font> to rescale your tree.
+<li><font color=blue>[branchlengths] EQUAL</font> will make every branch on the tree equal to 0.1.
+<li><font color=blue>[branchlengths] NON-ULTRAMETRIC</font> gives every branch a random length between 0 and 1.
+<li><font color=blue>[branchlengths] ULTRAMETRIC</font> gives every branch a random length between 0 and 1, but will also extend the terminal branches so that the root-to-tip distance is the same for every tip.
+<li>If the <font color=blue>[branchlengths]</font> command is used then the tree toplogy can be specified with or without branch lengths. It does not matter. Any branch lengths will be ignored. i.e. the trees EQUAL-TREE and EQUAL-TREE2 will be identical.
+<li>Examples of the trees produced above can be seen <a href="random_branch_length_trees.JPG">here</a>.
+<li>All trees in the image are rescaled to have a maximum tree-depth of 0.1.  This means that the root-to-tip distance for taxon G is equal to 0.1 in all 3 trees.
+<li>N.B. For ultrametric trees <font color=blue>[maxdistance] 0.2</font> is equivalent to <font color=blue>[treedepth] 0.1</font>. For the non-ultrametric tree they are not the same. <font color=blue>[maxdistance] 0.2</font> on the non-ultrametric tree scales the tree such that the sum of the branch lengths in between (in <a href="random_branch_length_trees.JPG">this</a> case) taxons G and N would be 0.2
+</ul></p><br>
+<hr>
+<br>
+Trees (random or user) that are used during the simulation will be output by INDELible in a file <a href="trees.txt" target="_blank">like this</a>.
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/trees.txt b/help/manual_files/trees.txt
new file mode 100644
index 0000000..3c72ac2
--- /dev/null
+++ b/help/manual_files/trees.txt
@@ -0,0 +1,60 @@
+Tree file : INDELible V1.00 
+
+N.B. Simulation blocks with no random trees will have their trees printed for the first replicate only.
+
+FILE	TREE	NTAXA	REP	PART	LENGTH		TREE STRING
+p1a	t1	16	1	1	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p1b	t1	16	1	1	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1b	t2	16	1	2	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1b	t3	16	1	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p1	tree5	16	1	1	2.07469 	(((10:0.0251716,2:0.0251716):0.225636,((16:0.11026,12:0.11026):0.0179151,(1:0.104375,((8:0.0237011,5:0.0237011):0.0432994,6:0.0670005):0.0373747):0.0237997):0.122633):0.0591923,(((11:0.130562,(15:0.101111,((9:0.0257804,(7:0.0206163,14:0.0206163):0.00516404):0.0246742,3:0.0504546):0.0506567):0.0294507):0.0699838,13:0.200546):0.0155818,4:0.216128):0.0938724);
+p1	tree6	16	1	2	8.00001 	(((((11:0.55303,(((9:0.149849,3:0.149849):0.0855073,14:0.235356):0.0242804,(7:0.100483,2:0.100483):0.159153):0.293392):0.00305025,8:0.556081):0.0753802,((6:0.407102,(10:0.0566947,12:0.0566947):0.350407):0.127903,(4:0.310611,16:0.310611):0.224394):0.0964549):0.0196918,((13:0.564191,15:0.564191):0.0841506,1:0.648343):0.00280967):0.519353,5:1.17051);
+p1	t1	16	1	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	2	1	2.14452 	(((12:0.0575492,(10:0.0355436,5:0.0355436):0.0220056):0.0149737,15:0.0725229):0.237477,((14:0.129775,16:0.129775):0.110644,((((6:0.021887,9:0.021887):0.0611004,(3:0.0624181,(8:0.0434107,(1:0.0361316,7:0.0361316):0.00727905):0.0190075):0.0205693):0.0851256,(4:0.162494,13:0.162494):0.005619):0.0455205,(2:0.197639,11:0.197639):0.0159947):0.0267857):0.0695807);
+p1	tree6	16	2	2	8		(((((5:0.171401,(13:0.0492202,11:0.0492202):0.122181):0.255348,((14:0.0618468,7:0.0618468):0.269745,15:0.331592):0.0951573):0.10226,(12:0.514306,(((1:0.141204,8:0.141204):0.0163946,10:0.157599):0.202264,16:0.359863):0.154445):0.0147004):0.66522,6:1.19423):0.155977,((4:0.0282738,9:0.0282738):0.684942,(2:0.621086,3:0.621086):0.0921285):0.636988);
+p1	t1	16	2	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	3	1	1.735 		(((12:0.0975239,6:0.0975239):0.0611663,(((13:0.0688148,(((2:0.018292,16:0.018292):0.0144716,7:0.0327637):0.00907203,5:0.0418357):0.0269791):0.00323871,14:0.0720535):0.0798468,1:0.1519):0.00678992):0.15131,(((9:0.0962845,8:0.0962845):0.0056347,((10:0.0368431,(3:0.0210577,11:0.0210577):0.0157854):0.0296972,15:0.0665403):0.0353789):0.0485615,4:0.150481):0.159519);
+p1	tree6	16	3	2	8		(((2:0.0015762,10:0.0015762):0.933616,(12:0.726972,(6:0.563104,((14:0.385092,13:0.385092):0.00288606,((3:0.0168091,(8:0.00931587,7:0.00931587):0.00749325):0.231392,16:0.248201):0.139778):0.175126):0.163869):0.208219):0.909205,(9:0.417326,(((4:0.00506781,11:0.00506781):0.127212,5:0.132279):0.181356,(15:0.168658,1:0.168658):0.144978):0.10369):1.42707);
+p1	t1	16	3	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	4	1	2.73732 	(((((((12:0.0929284,6:0.0929284):0.0310408,((14:0.0420909,7:0.0420909):0.0712017,10:0.113293):0.0106765):0.096479,15:0.220448):0.0275901,2:0.248038):0.00894932,((4:0.0610078,1:0.0610078):0.16738,11:0.228387):0.0286001):0.0197955,5:0.276783):0.033217,((13:0.0987875,16:0.0987875):0.0674287,(8:0.119003,(3:0.0693831,9:0.0693831):0.0496202):0.0472129):0.143784);
+p1	tree6	16	4	2	8		(((16:0.388518,((6:0.32561,9:0.32561):0.0237181,(14:0.284777,3:0.284777):0.0645518):0.0391898):0.524666,13:0.913184):0.286973,((8:0.310698,(10:0.28525,15:0.28525):0.0254482):0.690973,((4:0.179299,7:0.179299):0.333821,((((5:0.0854129,2:0.0854129):0.00325413,12:0.0886673):0.32849,1:0.417155):0.0398375,11:0.456993):0.0561259):0.488549):0.198487);
+p1	t1	16	4	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p1	tree5	16	5	1	1.8936		((((12:0.0668171,(16:0.0579271,2:0.0579271):0.00889005):0.0572596,(8:0.0588584,7:0.0588584):0.0652184):0.0590675,(6:0.0889992,(5:0.0265993,(15:0.0119911,1:0.0119911):0.0146082):0.0623999):0.0941451):0.126856,(13:0.204947,(3:0.153933,(4:0.136852,(((9:0.0199244,10:0.0199244):0.0325816,11:0.0525059):0.0345205,14:0.0870265):0.0498254):0.0170807):0.0510144):0.105053);
+p1	tree6	16	5	2	8		((((((15:0.0693106,6:0.0693106):0.44311,((10:0.204551,5:0.204551):0.0607202,16:0.265271):0.247149):0.0414907,(13:0.00408851,9:0.00408851):0.549822):0.367133,(((11:0.316018,12:0.316018):0.0240882,(4:0.0994128,7:0.0994128):0.240694):0.430903,14:0.77101):0.150034):0.073126,(2:0.549335,8:0.549335):0.444834):0.0540178,(3:0.302978,1:0.302978):0.745211);
+p1	t1	16	5	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p2	tree4	16	1	1	2.8485		(((((5:0.112557,3:0.112557):0.114089,11:0.226645):0.0265085,((4:0.0278513,10:0.0278513):0.179506,6:0.207358):0.0457964):0.0471312,((7:0.0798369,8:0.0798369):0.132501,((12:0.127369,(2:0.0874179,14:0.0874179):0.0399507):0.0423396,15:0.169708):0.0426297):0.0879471):0.00294979,(13:0.117293,(1:0.0169825,16:0.0169825):0.10031):0.185942,9:0.303235);
+p2	tree4	16	2	1	3.31545 	(((4:0.307894,((11:0.0321027,(8:0.01745,14:0.01745):0.0146527):0.233149,(9:0.202673,(6:0.0713661,(7:0.0456646,13:0.0456646):0.0257015):0.131307):0.0625789):0.0426418):0.0206553,2:0.328549):0.000983572,(10:0.119042,1:0.119042):0.210491,((12:0.281206,(15:0.212231,(5:0.147151,3:0.147151):0.0650795):0.0689751):0.0150686,16:0.296274):0.0332583);
+p2	tree4	16	3	1	3.42676 	(((8:0.0352956,(5:0.00783672,11:0.00783672):0.0274589):0.24574,15:0.281035):0.0532647,((1:0.102692,10:0.102692):0.19055,(4:0.238645,12:0.238645):0.0545974):0.0410577,(((9:0.1825,14:0.1825):0.0939923,(7:0.0973296,3:0.0973296):0.179162):0.0139557,((13:0.219061,(16:0.175524,6:0.175524):0.0435363):0.00469507,2:0.223756):0.066692):0.043852);
+p2	tree4	16	4	1	3.09609 	((((16:0.234742,(4:0.065675,14:0.065675):0.169067):0.00109323,10:0.235835):0.0273879,12:0.263223):0.073974,((((5:0.110609,9:0.110609):0.0307443,6:0.141353):0.0703576,((7:0.0722642,3:0.0722642):0.105236,8:0.1775):0.0342104):0.0282193,(2:0.162816,(13:0.0345524,11:0.0345524):0.128263):0.0771144):0.0972669,(15:0.134284,1:0.134284):0.202913);
+p2	tree4	16	5	1	3.29314 	(((((16:0.0741958,14:0.0741958):0.0266528,(8:0.0628713,10:0.0628713):0.0379773):0.188173,(9:0.237269,13:0.237269):0.0517527):0.00700942,(2:0.278772,((5:0.174857,(6:0.12343,(4:0.113574,7:0.113574):0.00985668):0.0514261):0.0725645,1:0.247421):0.0313511):0.0172585):0.0423361,3:0.338367,(12:0.181036,(11:0.0987093,15:0.0987093):0.082327):0.15733);
+
+p7	tree4	16	1	1	2.8485		(((((5:0.112557,3:0.112557):0.114089,11:0.226645):0.0265085,((4:0.0278513,10:0.0278513):0.179506,6:0.207358):0.0457964):0.0471312,((7:0.0798369,8:0.0798369):0.132501,((12:0.127369,(2:0.0874179,14:0.0874179):0.0399507):0.0423396,15:0.169708):0.0426297):0.0879471):0.00294979,(13:0.117293,(1:0.0169825,16:0.0169825):0.10031):0.185942,9:0.303235);
+p7	tree6	16	1	2	8		((14:0.487088,(2:0.126887,13:0.126887):0.3602):1.06951,(((5:0.141802,12:0.141802):0.590438,((9:0.186562,((7:0.0520105,10:0.0520105):0.103103,16:0.155114):0.0314484):0.326649,1:0.51321):0.219028):0.105282,(((6:0.154349,(4:0.0545005,11:0.0545005):0.0998482):0.390959,(15:0.062744,3:0.062744):0.482564):0.292161,8:0.83747):5.18287e-05):0.719078);
+p7	t1	16	1	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	2	1	3.31545 	(((4:0.307894,((11:0.0321027,(8:0.01745,14:0.01745):0.0146527):0.233149,(9:0.202673,(6:0.0713661,(7:0.0456646,13:0.0456646):0.0257015):0.131307):0.0625789):0.0426418):0.0206553,2:0.328549):0.000983572,(10:0.119042,1:0.119042):0.210491,((12:0.281206,(15:0.212231,(5:0.147151,3:0.147151):0.0650795):0.0689751):0.0150686,16:0.296274):0.0332583);
+p7	tree6	16	2	2	8		(16:1.25506,((((7:0.116597,11:0.116597):0.124659,(15:0.142871,5:0.142871):0.0983849):0.0725679,(14:0.311169,2:0.311169):0.00265526):0.668951,((((8:0.412028,10:0.412028):0.0674837,(3:0.373415,(9:0.174412,4:0.174412):0.199003):0.106097):0.0535935,(6:0.264671,13:0.264671):0.268434):0.0581441,(1:0.552995,12:0.552995):0.0382555):0.391525):0.272284);
+p7	t1	16	2	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	3	1	3.42676 	(((8:0.0352956,(5:0.00783672,11:0.00783672):0.0274589):0.24574,15:0.281035):0.0532647,((1:0.102692,10:0.102692):0.19055,(4:0.238645,12:0.238645):0.0545974):0.0410577,(((9:0.1825,14:0.1825):0.0939923,(7:0.0973296,3:0.0973296):0.179162):0.0139557,((13:0.219061,(16:0.175524,6:0.175524):0.0435363):0.00469507,2:0.223756):0.066692):0.043852);
+p7	tree6	16	3	2	8		((5:0.717836,10:0.717836):0.365796,((8:0.188465,1:0.188465):0.795659,(((4:0.275071,3:0.275071):0.314526,((15:0.200236,12:0.200236):0.229528,(14:0.361098,(6:0.275461,16:0.275461):0.0856381):0.0686649):0.159833):0.0760304,(11:0.450497,(13:0.389999,((2:0.0336032,7:0.0336032):0.237755,9:0.271359):0.11864):0.0605002):0.215129):0.318496):0.0995089);
+p7	t1	16	3	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	4	1	3.09609 	((((16:0.234742,(4:0.065675,14:0.065675):0.169067):0.00109323,10:0.235835):0.0273879,12:0.263223):0.073974,((((5:0.110609,9:0.110609):0.0307443,6:0.141353):0.0703576,((7:0.0722642,3:0.0722642):0.105236,8:0.1775):0.0342104):0.0282193,(2:0.162816,(13:0.0345524,11:0.0345524):0.128263):0.0771144):0.0972669,(15:0.134284,1:0.134284):0.202913);
+p7	tree6	16	4	2	8		(((14:0.44356,(6:0.418219,15:0.418219):0.0253389):0.353999,((5:0.65665,(13:0.647129,((11:0.20976,9:0.20976):0.257568,8:0.467327):0.179799):0.00952174):0.00739611,(7:0.537691,3:0.537691):0.126354):0.133512):0.197561,((1:0.169463,(2:0.0351903,10:0.0351903):0.134272):0.319193,((16:0.162323,12:0.162323):0.14987,4:0.312193):0.176462):0.506464);
+p7	t1	16	4	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+p7	tree4	16	5	1	3.29314 	(((((16:0.0741958,14:0.0741958):0.0266528,(8:0.0628713,10:0.0628713):0.0379773):0.188173,(9:0.237269,13:0.237269):0.0517527):0.00700942,(2:0.278772,((5:0.174857,(6:0.12343,(4:0.113574,7:0.113574):0.00985668):0.0514261):0.0725645,1:0.247421):0.0313511):0.0172585):0.0423361,3:0.338367,(12:0.181036,(11:0.0987093,15:0.0987093):0.082327):0.15733);
+p7	tree6	16	5	2	8		((11:0.770019,(10:0.182883,7:0.182883):0.587135):0.444682,((2:0.783165,((((((16:0.0278589,1:0.0278589):0.162142,8:0.190001):0.209444,13:0.399445):0.00428104,4:0.403727):0.0557297,(6:0.393446,12:0.393446):0.0660119):0.0864789,14:0.545934):0.23723):0.03592,(5:0.481292,((15:0.0430772,9:0.0430772):0.0281307,3:0.0712081):0.410083):0.337794):0.395616);
+p7	t1	16	5	3	30		((((1:1,2:1):1,(3:1,4:1):1):1,((5:1,6:1):1,(7:1,8:1):1):1):1,(((9:1,11:1):1,(10:1,12:1):1):1,((13:1,14:1):1,(15:1,16:1):1):1):1);
+
+p3	tree5	16	1	1	1.75504 	((((((2:0.0359762,12:0.0359762):0.0163278,5:0.052304):0.023317,(11:0.0710584,16:0.0710584):0.00456256):0.0104657,10:0.0860867):0.0157686,(6:0.0900789,((7:0.0274396,1:0.0274396):0.0360231,4:0.0634627):0.0266162):0.0117763):0.208145,((((13:0.000951513,3:0.000951513):0.0340047,8:0.0349562):0.133207,14:0.168164):0.106116,(15:0.0528084,9:0.0528084):0.221471):0.0357209);
+p3	tree5	16	2	1	1.63435 	((15:0.109502,14:0.109502):0.200498,(((4:0.106899,(((10:0.000968828,1:0.000968828):0.0581853,((9:0.00120325,7:0.00120325):0.0554193,(8:0.054203,(5:0.0412523,16:0.0412523):0.0129507):0.00241962):0.00253158):0.0433431,2:0.102497):0.00440143):0.0644602,((13:0.0246952,3:0.0246952):0.0183126,11:0.0430078):0.128351):0.00880369,(12:0.0628254,6:0.0628254):0.117337):0.129837);
+p3	tree5	16	3	1	2.25393 	((((5:0.134281,(13:0.100718,((6:0.0341843,12:0.0341843):0.0385873,(3:0.0689088,8:0.0689088):0.00386283):0.0279463):0.0335631):0.0643055,(((2:0.030439,15:0.030439):0.0823861,9:0.112825):0.0237421,7:0.136567):0.0620193):0.0186373,(4:0.125324,(16:0.0585481,11:0.0585481):0.0667755):0.0919003):0.0927761,(10:0.23649,(14:0.107067,1:0.107067):0.129423):0.0735102);
+p3	tree5	16	4	1	2.2668		(3:0.31,((((1:0.105771,(14:0.104195,(13:0.0277489,2:0.0277489):0.0764459):0.00157609):0.0053371,(16:0.00953588,5:0.00953588):0.101572):0.0551514,(9:0.0294335,15:0.0294335):0.136826):0.0704364,(((8:0.145421,4:0.145421):0.00862213,(10:0.0953953,7:0.0953953):0.0586481):0.0311614,(12:0.166533,(6:0.109454,11:0.109454):0.0570781):0.0186722):0.0514911):0.0733041);
+p3	tree5	16	5	1	1.9882		(((((7:0.0600188,4:0.0600188):0.00813354,1:0.0681523):0.089071,((((6:0.104907,9:0.104907):0.00692074,(((12:0.0537501,13:0.0537501):0.0209333,5:0.0746834):0.00248677,10:0.0771702):0.0346573):0.011542,(3:0.0433617,(11:0.0264326,16:0.0264326):0.0169292):0.0800078):0.00453639,8:0.127906):0.0293175):0.0637721,(2:0.118399,14:0.118399):0.102596):0.0890046,15:0.31);
+
+p4	tree6	16	1	1	8		((13:0.203328,5:0.203328):0.820493,((16:0.288933,1:0.288933):0.422177,(((4:0.629042,(((2:0.158208,12:0.158208):0.418452,15:0.576662):0.0502138,9:0.626875):0.00216817):0.0328959,((6:0.425625,((3:0.1651,(11:0.154244,7:0.154244):0.0108556):0.0368995,14:0.201999):0.223628):0.0502607,10:0.475888):0.186051):0.0114662,8:0.673403):0.0377067):0.312709);
+p4	tree6	16	2	1	8		((12:0.612383,(10:0.277312,16:0.277312):0.335072):0.704844,(8:1.31255,((7:0.526814,(((5:0.275105,4:0.275105):0.15673,15:0.431834):0.0313425,(2:0.301107,((14:0.065467,1:0.065467):0.184595,13:0.250062):0.0510455):0.16207):0.0636365):0.0644863,(3:0.16065,((9:0.0411075,6:0.0411075):0.0155733,11:0.0566807):0.10397):0.430648):0.721245):0.00468028);
+p4	tree6	16	3	1	8		((9:0.808603,((((((1:0.261297,(4:0.209442,(2:0.18019,15:0.18019):0.029252):0.0518549):0.00204327,12:0.26334):0.00450785,(14:0.25266,7:0.25266):0.0151881):0.0752688,10:0.343117):0.119999,11:0.463118):0.224235,(5:0.388933,13:0.388933):0.298418):0.121251):0.531461,(((8:0.116294,3:0.116294):0.308149,6:0.424444):0.228794,16:0.653238):0.686826);
+p4	tree6	16	4	1	8		(2:1.25157,(((7:0.0331616,3:0.0331616):0.155006,13:0.188168):1.03387,(15:0.706163,((((11:0.00174269,6:0.00174269):0.0175912,1:0.0193339):0.573283,(5:0.530758,10:0.530758):0.0618586):0.0203591,((16:0.0816713,4:0.0816713):0.502428,((9:0.0632228,14:0.0632228):0.426785,(8:0.370903,12:0.370903):0.119104):0.0940917):0.0288772):0.0931865):0.515876):0.0295296);
+p4	tree6	16	5	1	8		((9:1.04182,(((((1:0.152451,6:0.152451):0.167588,13:0.320039):0.0359561,2:0.355995):0.148171,12:0.504165):0.498338,(10:0.701825,((7:0.0113513,16:0.0113513):0.508482,5:0.519833):0.181993):0.300681):0.0393138):0.0252188,(((3:0.184398,4:0.184398):0.179885,(11:0.128553,(15:0.0635779,14:0.0635779):0.0649751):0.23573):0.150844,8:0.515128):0.55191);
diff --git a/help/manual_files/type.shtml b/help/manual_files/type.shtml
new file mode 100644
index 0000000..d215e4f
--- /dev/null
+++ b/help/manual_files/type.shtml
@@ -0,0 +1,24 @@
+<!--#include file="files/top.html" -->
+  
+<h1>INDELible</h1>
+<h2>[TYPE] block</h2>
+
+<p><ul>
+<li>This block tells INDELible whether it is simulating under nucleotide, amino-acid or codon models and whether to use <i>method 1</i> or <i>method 2</i> (see paper).</li>
+<li>Both methods give identical results but in some situations one will be faster than the other.</li>
+<li>It is important that this block comes first in the control file because it is used to check all subsequent input in that file for user typos.</li>
+</ul></p>
+<br>
+<p><u><b>Example Usage:</u></b></p>
+
+
+<p><ul>
+<li><pre>[TYPE] NUCLEOTIDE 1<pre></li>
+<li><pre>[TYPE] NUCLEOTIDE 2<pre></li>
+<li><pre>[TYPE] AMINOACID 1<pre></li>
+<li><pre>[TYPE] AMINOACID 2<pre></li>
+<li><pre>[TYPE] CODON 1<pre></li>
+<li><pre>[TYPE] CODON 2<pre></li>
+</ul></p>
+
+<!--#include file="files/bottom.html" -->
\ No newline at end of file
diff --git a/help/manual_files/userAAmodel.txt b/help/manual_files/userAAmodel.txt
new file mode 100644
index 0000000..a2e1103
--- /dev/null
+++ b/help/manual_files/userAAmodel.txt
@@ -0,0 +1,23 @@
+ 
+0.267828 
+0.984474 0.327059 
+1.199805 0.000000 8.931515 
+0.360016 0.232374 0.000000 0.000000 
+0.887753 2.439939 1.028509 1.348551 0.000000 
+1.961167 0.000000 1.493409 11.388659 0.000000 7.086022 
+2.386111 0.087791 1.385352 1.240981 0.107278 0.281581 0.811907 
+0.228116 2.383148 5.290024 0.868241 0.282729 6.011613 0.439469 0.106802 
+0.653416 0.632629 0.768024 0.239248 0.438074 0.180393 0.609526 0.000000 0.076981 
+0.406431 0.154924 0.341113 0.000000 0.000000 0.730772 0.112880 0.071514 0.443504 2.556685 
+0.258635 4.610124 3.148371 0.716913 0.000000 1.519078 0.830078 0.267683 0.270475 0.460857 0.180629 
+0.717840 0.896321 0.000000 0.000000 0.000000 1.127499 0.304803 0.170372 0.000000 3.332732 5.230115 2.411739 
+0.183641 0.136906 0.138503 0.000000 0.000000 0.000000 0.000000 0.153478 0.475927 1.951951 1.565160 0.000000 0.921860 
+2.485920 1.028313 0.419244 0.133940 0.187550 1.526188 0.507003 0.347153 0.933709 0.119152 0.316258 0.335419 0.170205 0.110506 
+4.051870 1.531590 4.885892 0.956097 1.598356 0.561828 0.793999 2.322243 0.353643 0.247955 0.171432 0.954557 0.619951 0.459901 2.427202 
+3.680365 0.265745 2.271697 0.660930 0.162366 0.525651 0.340156 0.306662 0.226333 1.900739 0.331090 1.350599 1.031534 0.136655 0.782857 5.436674 
+0.000000 2.001375 0.224968 0.000000 0.000000 0.000000 0.000000 0.000000 0.270564 0.000000 0.461776 0.000000 0.000000 0.762354 0.000000 0.740819 0.000000 
+0.244139 0.078012 0.946940 0.000000 0.953164 0.000000 0.214717 0.000000 1.265400 0.374834 0.286572 0.132142 0.000000 6.952629 0.000000 0.336289 0.417839 0.608070 
+2.059564 0.240368 0.158067 0.178316 0.484678 0.346983 0.367250 0.538165 0.438715 8.810038 1.745156 0.103850 2.565955 0.123606 0.485026 0.303836 1.561997 0.000000 0.279379 
+
+
+0.087127 0.040904 0.040432 0.046872 0.033474 0.038255 0.049530 0.088612 0.033619 0.036886 0.085357 0.080481 0.014753 0.039772 0.050680 0.069577 0.058542 0.010494 0.029916 0.064718 
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..4e0ccc9
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,29 @@
+If the text files look strange on WINDOWS, please open them in WORDPAD, not NOTEPAD!!
+
+Thank you for downloading INDELible V1.03
+
+The folder bin contains executables for Windows and Mac OS-X (intel & G4).
+
+To run type "bin/indelible" once you have navigated to the INDELible folder.
+
+The help folder contains the manual and tutorial from the website.
+
+The src folder contains the source code and compilation instructions.
+
+If you have a question, want to check if there is a newer version of INDELible, 
+or want to report a bug then please go to:
+
+http://abacus.gene.ucl.ac.uk/software/indelible/
+
+Please note that if I discover small bugs that do not affect simulation output
+then I will just fix them and not release a new version of INDELible.
+
+If bugs are uncovered that may affect simulation output then I will fix them and 
+release a new version e.g. V1.01, V1.02 and so on.
+
+Therefore, please make sure to check back at the web address above for any
+new version of the program before embarking on complicated/long simulations!
+
+Thank you and enjoy!
+
+WF.
diff --git a/src/M5-13.cpp b/src/M5-13.cpp
new file mode 100644
index 0000000..ecc2e3f
--- /dev/null
+++ b/src/M5-13.cpp
@@ -0,0 +1,1506 @@
+/*  
+   INDELible V1.03
+    "A comprehensive and flexible simulator of molecular sequence evolution"
+    Copyright (C) 2009 William Fletcher
+
+    If using this software please cite the following reference:
+
+    Fletcher, W. and Yang, Z. 2009. 
+	"INDELible: a flexible simulator of biological sequence evolution." 
+	Mol. Biol. and Evol. (in press). 
+
+    If you need to contact me with any queries, questions, problems or (god-forbid) bugs
+    then please go to http://abacus.gene.ucl.ac.uk/software/indelible/bug.php
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    Please visit http://www.gnu.org/licenses/ for a full copy of the license.
+*/
+
+#include <math.h>
+#include <string>
+#include <sstream>
+#include <vector>
+#include "float.h"
+#include <iostream>
+#include <fstream>
+#include <time.h>
+#include <string>
+
+using namespace std;
+
+
+
+
+/*  
+  //script to calculate discrete M3 values for M4 to M13
+
+	 5  gamma         2:    alpha, beta
+	 6  2gamma        4:    p0, alpha1,beta1, alpha2=beta2
+	 7  beta          2:    p_beta, q_beta
+	 8  beta&w        4:    p0, p_beta, q_beta, w estimated
+	 9  beta&gamma    5:    p0, p_beta, q_beta, alpha, beta
+	10  beta&1+gamma  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+	11  beta&1>normal 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+	12  0&2normal     5:    p0, p1, mu2, s1, s2
+	13  3normal       6:    p0, p1, mu2, s0, s1, s2
+	14  M8a:beta&w=1  3:    p0, p_beta, q_beta, w=1 fixed
+	15  M8a:beta&w>=1 4:    p0, p_beta, q_beta, w>=1 estimated
+*/
+
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	// code below is to do with codon models discrete rates... used by scipting function to set up M3
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////
+				
+const int NSnneutral=1;
+const int NSpselection=2;
+const int NSdiscrete=3;
+const int NSfreqs=4;
+const int NSgamma=5;
+const int NS2gamma=6;
+const int NSbeta=7;
+const int NSbetaw=8;
+const int NSbetagamma=9;
+const int NSbeta1gamma=10;
+const int NSbeta1normal=11;
+const int NS02normal=12;
+const int NS3normal=13;
+
+				int LASTROUND;
+
+void error2 (char * message)
+				{ printf("\nError: %s.\n", message); exit(-1); }
+
+#define FOR(i,n) for(i=0; i<n; i++)
+#define square(a) ((a)*(a))
+#define min2(a,b) ((a)<(b)?(a):(b))
+#define max2(a,b) ((a)>(b)?(a):(b))
+				#define NS            5000
+				#define NBRANCH       (NS*2-2)
+				#define MAXNSONS      20
+				#define LSPNAME       50
+				#define NCODE         64
+				#define NCATG         40
+					#define FPN(file) fputc('\n', file)
+				#define F0 stdout
+
+	
+				double LnGamma (double alpha);
+				double IncompleteGamma (double x, double alpha, double ln_gamma_alpha);
+
+				double PointNormal (double prob);
+				double PointChi2 (double prob, double v);
+
+									struct CommonInfo {
+				   char *z[2*NS-1], spname[NS][LSPNAME+1], daafile[96], cleandata, readpattern;
+				   int ns, ls, npatt, np, ntime, ncode, clock, rooted, model, icode;
+				   int seqtype, *pose, ncatG, NSsites, fix_omega;
+				   double *fpatt, kappa, omega, alpha, pi[64], *conP, daa[20*20];
+				   double freqK[NCATG], rK[NCATG];
+				   char *siteID;    /* used if ncatG>1 */
+				   double *siterates, omega_fix;   /* rates for gamma or omega for site or branch-site models */
+				   double *omegaBS, *QfactorBS;     /* omega IDs for branch-site models */
+				}  com;			
+
+
+
+double CDFNormal (double x)
+{
+//  Hill ID  (1973)  The normal integral.  Applied Statistics, 22:424-427.
+//    Algorithm AS 66.
+//    adapted by Z. Yang, March 1994.  Hill's routine is quite bad, and I 
+//    haven't consulted 
+//      Adams AG  (1969)  Algorithm 39.  Areas under the normal curve.
+//      Computer J. 12: 197-198.
+
+    int invers=0;
+    double p, limit=10, t=1.28, y=x*x/2;
+
+    if (x<0) {  invers=1;  x*=-1; }
+    if (x>limit)  return (invers?0:1);
+    if (x<1.28)  
+       p = .5 - x * (    .398942280444 - .399903438504 * y
+                   /(y + 5.75885480458 - 29.8213557808
+		   /(y + 2.62433121679 + 48.6959930692
+		   /(y + 5.92885724438))));
+    else 
+       p = 0.398942280385 * exp(-y) /
+           (x - 3.8052e-8 + 1.00000615302 /
+           (x + 3.98064794e-4 + 1.98615381364 /
+           (x - 0.151679116635 + 5.29330324926 /
+           (x + 4.8385912808 - 15.1508972451 /
+           (x + 0.742380924027 + 30.789933034 /
+           (x + 3.99019417011))))));
+
+    return  invers ? p : 1-p;
+}
+
+				double LnGamma (double alpha)
+				{
+				// returns ln(gamma(alpha)) for alpha>0, accurate to 10 decimal places.  
+				// Stirling's formula is used for the central polynomial part of the procedure.
+				// Pike MC & Hill ID (1966) Algorithm 291: Logarithm of the gamma function.
+				// Communications of the Association for Computing Machinery, 9:684
+				
+				   double x=alpha, f=0, z;
+
+				   if (x<7) {
+					  f=1;  z=x-1;
+					  while (++z<7)  f*=z;
+					  x=z;   f=-log(f);
+				   }
+				   z = 1/(x*x);
+				   return  f + (x-0.5)*log(x) - x + .918938533204673 
+					  + (((-.000595238095238*z+.000793650793651)*z-.002777777777778)*z
+						   +.083333333333333)/x;  
+				}
+
+
+double LnGammaFunction (double alpha)
+{
+/* returns ln(gamma(alpha)) for alpha>0, accurate to 10 decimal places.  
+   Stirling's formula is used for the central polynomial part of the procedure.
+   Pike MC & Hill ID (1966) Algorithm 291: Logarithm of the gamma function.
+   Communications of the Association for Computing Machinery, 9:684
+*/
+   double x=alpha, f=0, z;
+
+   if (x<7) {
+       f=1;  z=x-1;
+       while (++z<7)  f*=z;
+       x=z;   f=-log(f);
+   }
+   z = 1/(x*x);
+   return  f + (x-0.5)*log(x) - x + .918938533204673 
+          + (((-.000595238095238*z+.000793650793651)*z-.002777777777778)*z
+               +.083333333333333)/x;  
+}
+
+
+
+
+				double IncompleteGamma (double x, double alpha, double ln_gamma_alpha)
+				{
+				/* returns the incomplete gamma ratio I(x,alpha) where x is the upper 
+					   limit of the integration and alpha is the shape parameter.
+				   returns (-1) if in error
+				   ln_gamma_alpha = ln(Gamma(alpha)), is almost redundant.
+				   (1) series expansion     if (alpha>x || x<=1)
+				   (2) continued fraction   otherwise
+				   RATNEST FORTRAN by
+				   Bhattacharjee GP (1970) The incomplete gamma integral.  Applied Statistics,
+				   19: 285-287 (AS32)
+				*/
+				   int i;
+				   double p=alpha, g=ln_gamma_alpha;
+				   double accurate=1e-8, overflow=1e30;
+				   double factor, gin=0, rn=0, a=0,b=0,an=0,dif=0, term=0, pn[6];
+
+				   if (x==0) return (0);
+				   if (x<0 || p<=0) return (-1);
+
+				   factor=exp(p*log(x)-x-g);   
+				   if (x>1 && x>=p) goto l30;
+				   /* (1) series expansion */
+				   gin=1;  term=1;  rn=p;
+				 l20:
+				   rn++;
+				   term*=x/rn;   gin+=term;
+
+				   if (term > accurate) goto l20;
+				   gin*=factor/p;
+				   goto l50;
+				 l30:
+				   /* (2) continued fraction */
+				   a=1-p;   b=a+x+1;  term=0;
+				   pn[0]=1;  pn[1]=x;  pn[2]=x+1;  pn[3]=x*b;
+				   gin=pn[2]/pn[3];
+				 l32:
+				   a++;  b+=2;  term++;   an=a*term;
+				   for (i=0; i<2; i++) pn[i+4]=b*pn[i+2]-an*pn[i];
+				   if (pn[5] == 0) goto l35;
+				   rn=pn[4]/pn[5];   dif=fabs(gin-rn);
+				   if (dif>accurate) goto l34;
+				   if (dif<=accurate*rn) goto l42;
+				 l34:
+				   gin=rn;
+				 l35:
+				   for (i=0; i<4; i++) pn[i]=pn[i+2];
+				   if (fabs(pn[4]) < overflow) goto l32;
+				   for (i=0; i<4; i++) pn[i]/=overflow;
+				   goto l32;
+				 l42:
+				   gin=1-factor*gin;
+
+				 l50:
+				   return (gin);
+				}
+
+
+				/* functions concerning the CDF and percentage points of the gamma and
+				   Chi2 distribution
+				*/
+				double PointNormal (double prob)
+				{
+				/* returns z so that Prob{x<z}=prob where x ~ N(0,1) and (1e-12)<prob<1-(1e-12)
+				   returns (-9999) if in error
+				   Odeh RE & Evans JO (1974) The percentage points of the normal distribution.
+				   Applied Statistics 22: 96-97 (AS70)
+
+				   Newer methods:
+					 Wichura MJ (1988) Algorithm AS 241: the percentage points of the
+					   normal distribution.  37: 477-484.
+					 Beasley JD & Springer SG  (1977).  Algorithm AS 111: the percentage 
+					   points of the normal distribution.  26: 118-121.
+
+				*/
+				   double a0=-.322232431088, a1=-1, a2=-.342242088547, a3=-.0204231210245;
+				   double a4=-.453642210148e-4, b0=.0993484626060, b1=.588581570495;
+				   double b2=.531103462366, b3=.103537752850, b4=.0038560700634;
+				   double y, z=0, p=prob, p1;
+
+				   p1 = (p<0.5 ? p : 1-p);
+				   if (p1<1e-20) return (-9999);
+
+				   y = sqrt (log(1/(p1*p1)));   
+				   z = y + ((((y*a4+a3)*y+a2)*y+a1)*y+a0) / ((((y*b4+b3)*y+b2)*y+b1)*y+b0);
+				   return (p<0.5 ? -z : z);
+				}
+
+
+				double PointChi2 (double prob, double v)
+				{
+				/* returns z so that Prob{x<z}=prob where x is Chi2 distributed with df=v
+				   returns -1 if in error.   0.000002<prob<0.999998
+				   RATNEST FORTRAN by
+					   Best DJ & Roberts DE (1975) The percentage points of the 
+					   Chi2 distribution.  Applied Statistics 24: 385-388.  (AS91)
+				   Converted into C by Ziheng Yang, Oct. 1993.
+				*/
+				   double e=.5e-6, aa=.6931471805, p=prob, g;
+				   double xx, c, ch, a=0,q=0,p1=0,p2=0,t=0,x=0,b=0,s1,s2,s3,s4,s5,s6;
+
+				   if (p<.000002 || p>.999998 || v<=0) return (-1);
+
+				   g = LnGamma (v/2);
+				   xx=v/2;   c=xx-1;
+				   if (v >= -1.24*log(p)) goto l1;
+
+				   ch=pow((p*xx*exp(g+xx*aa)), 1/xx);
+				   if (ch-e<0) return (ch);
+				   goto l4;
+				l1:
+				   if (v>.32) goto l3;
+				   ch=0.4;   a=log(1-p);
+				l2:
+				   q=ch;  p1=1+ch*(4.67+ch);  p2=ch*(6.73+ch*(6.66+ch));
+				   t=-0.5+(4.67+2*ch)/p1 - (6.73+ch*(13.32+3*ch))/p2;
+				   ch-=(1-exp(a+g+.5*ch+c*aa)*p2/p1)/t;
+				   if (fabs(q/ch-1)-.01 <= 0) goto l4;
+				   else                       goto l2;
+  
+				l3: 
+				   x=PointNormal (p);
+				   p1=0.222222/v;   ch=v*pow((x*sqrt(p1)+1-p1), 3.0);
+				   if (ch>2.2*v+6)  ch=-2*(log(1-p)-c*log(.5*ch)+g);
+				l4:
+				   q=ch;   p1=.5*ch;
+				   if ((t=IncompleteGamma (p1, xx, g))<0) {
+					  return (-1);
+				   }
+				   p2=p-t;
+				   t=p2*exp(xx*aa+g+p1-c*log(ch));   
+				   b=t/ch;  a=0.5*t-b*c;
+
+				   s1=(210+a*(140+a*(105+a*(84+a*(70+60*a))))) / 420;
+				   s2=(420+a*(735+a*(966+a*(1141+1278*a))))/2520;
+				   s3=(210+a*(462+a*(707+932*a)))/2520;
+				   s4=(252+a*(672+1182*a)+c*(294+a*(889+1740*a)))/5040;
+				   s5=(84+264*a+c*(175+606*a))/2520;
+				   s6=(120+c*(346+127*c))/5040;
+				   ch+=t*(1+0.5*t*s1-b*c*(s1-b*(s2-b*(s3-b*(s4-b*(s5-b*s6))))));
+				   if (fabs(q/ch-1) > e) goto l4;
+
+				   return (ch);
+				}
+
+
+
+				#define PointGamma(prob,alpha,beta) PointChi2(prob,2.0*(alpha))/(2.0*(beta))
+double PDFBeta(double x, double p, double q)
+{
+/* Returns pdf of beta(p,q)
+*/
+   double y, small=1e-20;
+
+   if(x<small || x>1-small) 
+      error2("bad x in PDFbeta");
+
+   y = (p-1)*log(x) + (q-1)*log(1-x);
+   y-= LnGamma(p)+LnGamma(q)-LnGamma(p+q);
+
+   return(exp(y));
+}
+
+double CDFBeta(double x, double pin, double qin, double lnbeta)
+{
+/* Returns distribution function of the standard form of the beta distribution, 
+   that is, the incomplete beta ratio I_x(p,q).
+
+   lnbeta is log of the complete beta function; provide it if known,
+   and otherwise use 0.
+
+   This is called from InverseCDFBeta() in a root-finding loop.
+
+    This routine is a translation into C of a Fortran subroutine
+    by W. Fullerton of Los Alamos Scientific Laboratory.
+    Bosten and Battiste (1974).
+    Remark on Algorithm 179, CACM 17, p153, (1974).
+*/
+   double ans, c, finsum, p, ps, p1, q, term, xb, xi, y, small=1e-15;
+   int n, i, ib;
+   static double eps = 0, alneps = 0, sml = 0, alnsml = 0;
+
+   if(x<small)        return 0;
+   else if(x>1-small) return 1;
+   if(pin<=0 || qin<=0)  { 
+      printf("p=%.4f q=%.4f: parameter outside range in CDFBeta",pin,qin); 
+      return (-1); 
+   }
+
+   if (eps == 0) {/* initialize machine constants ONCE */
+      eps = pow((double)FLT_RADIX, -(double)DBL_MANT_DIG);
+      alneps = log(eps);
+      sml = DBL_MIN;
+      alnsml = log(sml);
+   }
+   y = x;  p = pin;  q = qin;
+
+    /* swap tails if x is greater than the mean */
+   if (p / (p + q) < x) {
+      y = 1 - y;
+      p = qin;
+      q = pin;
+   }
+
+   if(lnbeta==0) lnbeta=LnGamma(p)+LnGamma(q)-LnGamma(p+q);
+
+   if ((p + q) * y / (p + 1) < eps) {  /* tail approximation */
+      ans = 0;
+      xb = p * log(max2(y, sml)) - log(p) - lnbeta;
+      if (xb > alnsml && y != 0)
+         ans = exp(xb);
+      if (y != x || p != pin)
+      ans = 1 - ans;
+   }
+   else {
+      /* evaluate the infinite sum first.  term will equal */
+      /* y^p / beta(ps, p) * (1 - ps)-sub-i * y^i / fac(i) */
+      ps = q - floor(q);
+      if (ps == 0)
+         ps = 1;
+
+      xb=LnGamma(ps)+LnGamma(p)-LnGamma(ps+p);
+      xb = p * log(y) - xb - log(p);
+
+      ans = 0;
+      if (xb >= alnsml) {
+         ans = exp(xb);
+         term = ans * p;
+         if (ps != 1) {
+            n = (int)max2(alneps/log(y), 4.0);
+         for(i=1 ; i<= n ; i++) {
+            xi = i;
+            term = term * (xi - ps) * y / xi;
+            ans = ans + term / (p + xi);
+         }
+      }
+   }
+
+   /* evaluate the finite sum. */
+   if (q > 1) {
+      xb = p * log(y) + q * log(1 - y) - lnbeta - log(q);
+      ib = (int) (xb/alnsml);  if(ib<0) ib=0;
+      term = exp(xb - ib * alnsml);
+      c = 1 / (1 - y);
+      p1 = q * c / (p + q - 1);
+
+      finsum = 0;
+      n = (int) q;
+      if (q == (double)n)
+         n = n - 1;
+         for(i=1 ; i<=n ; i++) {
+            if (p1 <= 1 && term / eps <= finsum)
+               break;
+            xi = i;
+            term = (q - xi + 1) * c * term / (p + q - xi);
+            if (term > 1) {
+               ib = ib - 1;
+               term = term * sml;
+            }
+            if (ib == 0)
+               finsum = finsum + term;
+         }
+         ans = ans + finsum;
+      }
+      if (y != x || p != pin)
+         ans = 1 - ans;
+      if(ans>1) ans=1;
+      if(ans<0) ans=0;
+   }
+   return ans;
+}
+
+double InverseCDFBeta(double prob, double p, double q, double lnbeta)
+{
+/* This calculates the inverseCDF of the beta distribution
+
+   Cran, G. W., K. J. Martin and G. E. Thomas (1977).
+   Remark AS R19 and Algorithm AS 109, Applied Statistics, 26(1), 111-114.
+   Remark AS R83 (v.39, 309-310) and correction (v.40(1) p.236).
+
+   My own implementation of the algorithm did not bracket the variable well.  
+   This version is Adpated from the pbeta and qbeta routines from 
+   "R : A Computer Language for Statistical Data Analysis".  It fails for 
+   extreme values of p and q as well, although it seems better than my 
+   previous version.
+   Ziheng Yang, May 2001
+*/
+   double fpu=3e-308, acu_min=1e-300, lower=fpu, upper=1-2.22e-16;
+   /* acu_min>= fpu: Minimal value for accuracy 'acu' which will depend on (a,p); */
+   int swap_tail, i_pb, i_inn, niterations=2000;
+   double a, adj, g, h, pp, prev=0, qq, r, s, t, tx=0, w, y, yprev;
+   double acu, xinbta;
+
+   if(prob<0 || prob>1 || p<0 || q<0) error2("out of range in InverseCDFBeta");
+
+   /* define accuracy and initialize */
+   xinbta = prob;
+
+   /* test for admissibility of parameters */
+   if(p<0 || q<0 || prob<0 || prob>1)  error2("beta par err");
+   if (prob == 0 || prob == 1)
+      return prob;
+
+   if(lnbeta==0) lnbeta=LnGamma(p)+LnGamma(q)-LnGamma(p+q);
+
+   /* change tail if necessary;  afterwards   0 < a <= 1/2    */
+   if (prob <= 0.5) {
+      a = prob;   pp = p; qq = q; swap_tail = 0;
+   }
+   else {
+      a = 1. - prob; pp = q; qq = p; swap_tail = 1;
+   }
+
+   /* calculate the initial approximation */
+   r = sqrt(-log(a * a));
+   y = r - (2.30753+0.27061*r)/(1.+ (0.99229+0.04481*r) * r);
+
+   if (pp > 1. && qq > 1.) {
+      r = (y * y - 3.) / 6.;
+      s = 1. / (pp*2. - 1.);
+      t = 1. / (qq*2. - 1.);
+      h = 2. / (s + t);
+      w = y * sqrt(h + r) / h - (t - s) * (r + 5./6. - 2./(3.*h));
+      xinbta = pp / (pp + qq * exp(w + w));
+   }
+   else {
+      r = qq*2.;
+      t = 1. / (9. * qq);
+      t = r * pow(1. - t + y * sqrt(t), 3.);
+      if (t <= 0.)
+         xinbta = 1. - exp((log((1. - a) * qq) + lnbeta) / qq);
+      else {
+         t = (4.*pp + r - 2.) / t;
+         if (t <= 1.)
+            xinbta = exp((log(a * pp) + lnbeta) / pp);
+         else
+            xinbta = 1. - 2./(t+1.);
+      }
+   }
+
+   /* solve for x by a modified newton-raphson method, using CDFBeta */
+   r = 1. - pp;
+   t = 1. - qq;
+   yprev = 0.;
+   adj = 1.;
+
+
+   
+/* Changes made by Ziheng to fix a bug in qbeta()
+   qbeta(0.25, 0.143891, 0.05) = 3e-308   wrong (correct value is 0.457227)
+*/
+   if(xinbta<=lower || xinbta>=upper)  xinbta=(a+.5)/2;
+
+   /* Desired accuracy should depend on (a,p)
+    * This is from Remark .. on AS 109, adapted.
+    * However, it's not clear if this is "optimal" for IEEE double prec.
+    * acu = fmax2(acu_min, pow(10., -25. - 5./(pp * pp) - 1./(a * a)));
+    * NEW: 'acu' accuracy NOT for squared adjustment, but simple;
+    * ---- i.e.,  "new acu" = sqrt(old acu)
+    */
+   acu = pow(10., -13. - 2.5/(pp * pp) - 0.5/(a * a));
+   acu = max2(acu, acu_min);
+
+   for (i_pb=0; i_pb<niterations; i_pb++) {
+      y = CDFBeta(xinbta, pp, qq, lnbeta);
+      y = (y - a) *
+         exp(lnbeta + r * log(xinbta) + t * log(1. - xinbta));
+      if (y * yprev <= 0)
+         prev = max2(fabs(adj),fpu);
+      for (i_inn=0,g=1; i_inn<niterations; i_inn++) {
+         adj = g * y;
+         if (fabs(adj) < prev) {
+            tx = xinbta - adj; /* trial new x */
+            if (tx >= 0. && tx <= 1.) {
+               if (prev <= acu || fabs(y) <= acu)   goto L_converged;
+               if (tx != 0. && tx != 1.)  break;
+            }
+         }
+         g /= 3.;
+      }
+      if (fabs(tx-xinbta)<fpu) 
+         goto L_converged;
+      xinbta = tx;
+      yprev = y;
+   }
+//   if(!PAML_RELEASE) 
+//    printf("\nInverseCDFBeta(%.2f, %.5f, %.5f) = %.6e\t%d rounds\n", 
+//     prob,p,q, (swap_tail ? 1. - xinbta : xinbta), niterations);
+
+   L_converged:
+   return (swap_tail ? 1. - xinbta : xinbta);
+}
+
+
+
+
+
+
+double LineSearch (double(*fun)(double x),double *f,double *x0,double xb[2],double step, double e)
+{
+/* linear search using quadratic interpolation 
+
+   From Wolfe M. A.  1978.  Numerical methods for unconstrained
+   optimization: An introduction.  Van Nostrand Reinhold Company, New York.
+   pp. 62-73.
+   step is used to find the bracket (a1,a2,a3)
+
+   This is the same routine as LineSearch2(), but I have not got time 
+   to test and improve it properly.  Ziheng note, September, 2002
+*/
+   int ii=0, maxround=100, i;
+   double factor=2, step1, percentUse=0;
+   double a0,a1,a2,a3,a4=-1,a5,a6, f0,f1,f2,f3,f4=-1,f5,f6;
+
+/* find a bracket (a1,a2,a3) with function values (f1,f2,f3)
+   so that a1<a2<a3 and f2<f1 and f2<f3
+*/
+
+   if(step<=0) return(*x0);
+   a0=a1=a2=a3=f0=f1=f2=f3=-1;
+   if(*x0<xb[0]||*x0>xb[1]) 
+      error2("err LineSearch: x0 out of range");
+   f2=f0=fun(a2=a0=*x0);
+   step1=min2(step,(a0-xb[0])/4);
+   step1=max2(step1,e);
+   for(i=0,a1=a0,f1=f0; ; i++) {
+      a1-=(step1*=factor); 
+      if(a1>xb[0]) {
+         f1=fun(a1);
+         if(f1>f2)  break;
+         else {
+            a3=a2; f3=f2; a2=a1; f2=f1;
+         }
+      }
+      else {
+         a1=xb[0];  f1=fun(a1);
+         if(f1<=f2) { a2=a1; f2=f1; }
+         break;
+      }
+
+      /* if(noisy>2) printf("\ta = %.6f\tf = %.6f %5d\n", a2, f2, NFunCall);
+      */
+
+   }
+
+   if(i==0) { /* *x0 is the best point during the previous search */
+      step1=min2(step,(xb[1]-a0)/4);
+      for(i=0,a3=a2,f3=f2; ; i++) {
+         a3+=(step1*=factor); 
+         if(a3<xb[1]) {
+            f3=fun(a3);
+            if(f3>f2)  break;
+            else 
+               { a1=a2; f1=f2; a2=a3; f2=f3; }
+         }
+         else {
+            a3=xb[1];  f3=fun(a3);
+            if(f3<f2) { a2=a3; f2=f3; }
+            break;
+         }
+
+//	 if(noisy>2) printf("\ta = %.6f\tf = %.6f %5d\n", a3, f3, NFunCall);
+
+      }
+   }
+
+   /* iteration by quadratic interpolation, fig 2.2.9-10 (pp 71-71) */
+   for (ii=0; ii<maxround; ii++) {
+      /* a4 is the minimum from the parabola over (a1,a2,a3)  */
+
+      if (a1>a2+1e-99 || a3<a2-1e-99 || f2>f1+1e-99 || f2>f3+1e-99) /* for linux */
+         { printf("\npoints out of order (ii=%d)!",ii+1); break; }
+
+      a4 = (a2-a3)*f1+(a3-a1)*f2+(a1-a2)*f3;
+      if (fabs(a4)>1e-100)
+         a4=((a2*a2-a3*a3)*f1+(a3*a3-a1*a1)*f2+(a1*a1-a2*a2)*f3)/(2*a4);
+      if (a4>a3 || a4<a1)  a4=(a1+a2)/2;  /* out of range */
+      else                 percentUse++;
+      f4=fun(a4);
+
+      /*
+      if (noisy>2) printf("\ta = %.6f\tf = %.6f %5d\n", a4, f4, NFunCall);
+      */
+
+      if (fabs(f2-f4)*(1+fabs(f2))<=e && fabs(a2-a4)*(1+fabs(a2))<=e)  break;
+
+      if (a1<=a4 && a4<=a2) {    /* fig 2.2.10 */
+         if (fabs(a2-a4)>.2*fabs(a1-a2)) {
+            if (f1>=f4 && f4<=f2) { a3=a2; a2=a4;  f3=f2; f2=f4; }
+            else { a1=a4; f1=f4; }
+         }
+         else {
+            if (f4>f2) {
+               a5=(a2+a3)/2; f5=fun(a5);
+               if (f5>f2) { a1=a4; a3=a5;  f1=f4; f3=f5; }
+               else       { a1=a2; a2=a5;  f1=f2; f2=f5; }
+            }
+            else {
+               a5=(a1+a4)/2; f5=fun(a5);
+               if (f5>=f4 && f4<=f2)
+                  { a3=a2; a2=a4; a1=a5;  f3=f2; f2=f4; f1=f5; }
+               else {
+                  a6=(a1+a5)/2; f6=fun(a6);
+                  if (f6>f5)
+                       { a1=a6; a2=a5; a3=a4;  f1=f6; f2=f5; f3=f4; }
+                  else { a2=a6; a3=a5;  f2=f6; f3=f5; }
+               }
+            }
+         }
+      }
+      else {                     /* fig 2.2.9 */
+         if (fabs(a2-a4)>.2*fabs(a2-a3)) {
+            if (f2>=f4 && f4<=f3) { a1=a2; a2=a4;  f1=f2; f2=f4; }
+            else                  { a3=a4; f3=f4; }
+         }
+         else {
+            if (f4>f2) {
+               a5=(a1+a2)/2; f5=fun(a5);
+               if (f5>f2) { a1=a5; a3=a4;  f1=f5; f3=f4; }
+               else       { a3=a2; a2=a5;  f3=f2; f2=f5; }
+            }
+            else {
+               a5=(a3+a4)/2; f5=fun(a5);
+               if (f2>=f4 && f4<=f5)
+                  { a1=a2; a2=a4; a3=a5;  f1=f2; f2=f4; f3=f5; }
+               else {
+                  a6=(a3+a5)/2; f6=fun(a6);
+                  if (f6>f5)
+                      { a1=a4; a2=a5; a3=a6;  f1=f4; f2=f5; f3=f6; }
+                  else { a1=a5; a2=a6;  f1=f5; f2=f6; }
+               }
+            }
+         }
+      }
+   }   /*  for (ii) */
+   if (f2<=f4)  { *f=f2; a4=a2; }
+   else           *f=f4;
+
+   return (*x0=(a4+a2)/2);
+}
+
+
+
+
+
+static double prob_InverseCDF, *par_InverseCDF;
+static double (*cdf_InverseCDF)(double x,double par[]);
+double diff_InverseCDF(double x);
+
+double diff_InverseCDF(double x)
+{
+// This is the difference between the given p and the CDF(x), the 
+// objective function to be minimized.
+
+   double px=(*cdf_InverseCDF)(x,par_InverseCDF);
+   return(square(prob_InverseCDF-px));
+}
+
+
+double InverseCDF(double(*cdf)(double x,double par[]),
+       double p,double x,double par[],double xb[2])
+{
+// Use x for initial value if in range
+
+//   int noisy0=noisy;
+   double sdiff,step=min2(0.05,(xb[1]-xb[0])/100), e=1e-15;
+
+//   noisy=0;
+   prob_InverseCDF=p;  par_InverseCDF=par; cdf_InverseCDF=cdf;
+   if(x<=xb[0]||x>=xb[1]) x=.5;
+   LineSearch(diff_InverseCDF, &sdiff, &x, xb, step, e);
+//   noisy=noisy0;
+
+   return(x);
+}
+
+#define CDFGamma(x,alpha,beta) IncompleteGamma((beta)*(x),alpha,LnGammaFunction(alpha))
+
+
+int matout (FILE *fout, double x[], int n, int m)
+{
+   int i,j;
+   for (i=0,FPN(fout); i<n; i++,FPN(fout)) 
+      FOR(j,m) fprintf(fout," %11.6f", x[i*m+j]);
+   return (0);
+}
+
+double CDFdN_dS(double x,double p[])
+{
+/* This calculates the CDF of the continuous dN/dS distribution over sites, 
+   to be used as argument to the routine InverseCDF().  When the distribution
+   has spikes, the spikes are ignored in this routine, and the scaling
+   is done outside this routine, for example, in DiscreteNSsites().
+   All parameters (par) for the w distribution are passed to this routine, 
+   although some (p0 for the spike at 0) are not used in this routine.  
+   Parameters are arranged in the following order:
+
+      NSgamma (2):       alpha, beta
+      NS2gamma (4):      p0, alpha1, beta1, alpha2 (=beta2)
+      NSbeta (2):        p_beta, q_beta
+      NSbetaw (4):       p0, p_beta, q_beta, w (if !com.fix_omega, not used here)
+      NSbetagamma (5):   p0, p_beta, q_beta, alpha, beta
+      NSbeta1gamma (5):  p0, p_beta, q_beta, alpha, beta (1+gamma)
+      NSbeta1normal (5): p0, p_beta, q_beta, mu, s (normal>1)
+      NS02normal (5):    p0, p1, mu2, s1, s2 (s are sigma's)
+      NS3normal (6):     p0, p1, mu2, s0, s1, s2 (s are sigma's)
+
+   Parameters p0 & p1 are transformed if (!LASTROUND)
+
+*/
+   double cdf=-1;
+   double z, f[3],mu[3]={0,1,2},sig[3]; /* 3normal: mu0=0 fixed. mu2 estimated */
+
+   switch(com.NSsites) {
+   case(NSgamma):  cdf=CDFGamma(x,p[0],p[1]);   break;
+   case(NS2gamma): 
+      cdf=p[0] *CDFGamma(x,p[1],p[2])+(1-p[0])*CDFGamma(x,p[3],p[3]);  break;
+   case(NSbeta):   cdf=CDFBeta(x,p[0],p[1],0);  break;
+   case(NSbetaw):  cdf=CDFBeta(x,p[1],p[2],0);  break;
+   case(NSbetagamma):
+      cdf=p[0]*CDFBeta(x,p[1],p[2],0)+(1-p[0])*CDFGamma(x,p[3],p[4]);  break;
+
+   case(NSbeta1gamma):
+      if(x<=1) cdf=p[0]*CDFBeta(x,p[1],p[2],0);
+      else     cdf=p[0]+(1-p[0])*CDFGamma(x-1,p[3],p[4]);
+      break;
+   case(NSbeta1normal):
+      if(x<=1) cdf=p[0]*CDFBeta(x,p[1],p[2],0);
+      else {
+         cdf=CDFNormal((p[3]-1)/p[4]);
+         if(cdf<1e-9) {
+            matout(F0,p,1,5);;
+            printf("PHI(%.6f)=%.6f\n",(p[3]-1)/p[4],cdf);  getchar();
+         }
+         cdf=p[0]+(1-p[0])*(1- CDFNormal((p[3]-x)/p[4])/cdf);
+      }
+      break;
+   case(NS02normal):
+      mu[2]=p[2]; sig[1]=p[3]; sig[2]=p[4];
+      f[1]=p[1];  f[2]=1-f[1];
+      cdf = 1 - f[1]* CDFNormal(-(x-mu[1])/sig[1])/CDFNormal(mu[1]/sig[1])
+              - f[2]* CDFNormal(-(x-mu[2])/sig[2])/CDFNormal(mu[2]/sig[2]);
+      break;
+   case(NS3normal):
+      mu[2]=p[2]; sig[0]=p[3]; sig[1]=p[4]; sig[2]=p[5];
+
+      if(LASTROUND) { f[0]=p[0]; f[1]=p[1]; }
+      else          { z=(f[0]=exp(p[0]))+(f[1]=exp(p[1]))+1; f[0]/=z; f[1]/=z;}
+      f[2]=1-f[0]-f[1];
+      cdf = 1 - f[0]* 2*CDFNormal(-x/sig[0])
+              - f[1]* CDFNormal(-(x-mu[1])/sig[1])/CDFNormal(mu[1]/sig[1])
+              - f[2]* CDFNormal(-(x-mu[2])/sig[2])/CDFNormal(mu[2]/sig[2]);
+      break;
+   }
+   return(cdf);
+}
+/*
+(*) Codon models for variable dN/dS ratios among sites
+    (com.nrate includes kappa & omega) (see also CDFdN_dS)
+
+    NSsites          npara
+
+    0  one-ratio     0:    one ratio for all sites
+    1  neutral       1:    p0 (w0=0, w1=1)
+    2  selection     3:    p0, p1, w2 (w0=0, w1=1)
+    3  discrete      2K-1: p0,p1,..., and w0,w1,...
+    4  freqs         K:    p's (w's are fixed)
+    5  gamma         2:    alpha, beta
+    6  2gamma        4:    p0, alpha1,beta1, alpha2=beta2
+    7  beta          2:    p_beta, q_beta
+    8  beta&w        4:    p0, p_beta, q_beta, w estimated
+    9  beta&gamma    5:    p0, p_beta, q_beta, alpha, beta
+   10  beta&1+gamma  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+   11  beta&1>normal 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+   12  0&2normal     5:    p0, p1, mu2, s1, s2
+   13  3normal       6:    p0, p1, mu2, s0, s1, s2
+   14  M8a:beta&w=1  3:    p0, p_beta, q_beta, w=1 fixed
+   15  M8a:beta&w>=1 4:    p0, p_beta, q_beta, w>=1 estimated
+
+
+   */
+
+
+/*
+
+int DiscreteNSsites(vector<double> &params, int &ncatG, int &NSsites, vector<double> &output)//double a, double b, double c,double d) //double par[])
+{
+/* This discretizes the continuous distribution for dN/dS ratios among sites
+   and calculates freqK[] and rK[], using the median method.
+   par[] contains all paras in the w distribution.  par[0] is the 
+   proportion of beta if (NSsites==betaw), or the proportion of w=0 if 
+   (NSsites=NS02normal).
+   This routine uses NSsites, ncatG, freqK, rK.
+   betaw has ncatG-1 site classes in the beta distribution, and 02normal 
+   has ncatG-1 site classes in the mixed normal distribution.
+   See the function CDFdN_dS() for definitions of parameters.
+*/
+/*
+//	double par[4]={a,b,c,d};
+int thesize=params.size();
+double *par; par=new double[thesize];
+double *rK; rK=new double[thesize];
+double *freqK; freqK=new double[thesize];
+
+for(int gv=1; gv<params.size(); gv++) par[gv]=params.at(gv);
+for( gv=1; gv<params.size(); gv++) cout<<" WEWE "<<par[gv]<<endl;
+
+cout<<ncatG<<" EWEWE "<<NSsites<<endl;
+	int status=0, j,off, K=ncatG-(NSsites==NSbetaw || NSsites==NS02normal);
+
+double xb[2]={1e-7,99};  // bounds for omega.  
+   int K1=6, K2=4, UseK1K2=0;
+   double p01=0, p,w0, lnbeta;
+
+   if(NSsites==NSbeta || NSsites==NSbetaw) xb[1]=1;
+
+#ifdef NSSITES_K1_K2_CLASSES
+ //  cout<<"A"<<endl;
+   if((NSsites==NSgamma||NSsites==NS2gamma||NSsites>=NSbetagamma)){
+      K2=max2(K2,K/3);  K1=K-K2;  UseK1K2=1;
+      p01=CDFdN_dS(1.,par);
+
+      // printf("\nK:%3d%3d\t p01=%9.5f\n",K1,K2,p01); 
+      FOR(j,K) {
+         if(j<K1) { p=p01*(j*2.+1)/(2.*K1); w0=p; }
+         else     { p=p01+(1-p01)*((j-K1)*2.+1)/(2.*K2); w0=1.01+(j-K1)/K2; }
+         rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+         freqK[j]=(j<K1 ? p01/K1 : (1-p01)/K2); thread
+      }
+   }
+#endif
+
+   if(!UseK1K2) { // this is currently used 
+   cout<<"B"<<endl;
+      if(NSsites==NSbeta || NSsites==NSbetaw) {
+         off=(NSsites==NSbetaw);  // par[0] is proportion for beta for M8 
+         lnbeta=LnGamma(par[off])+LnGamma(par[off+1])-LnGamma(par[off]+par[off+1]);
+         for(j=0; j<K; j++) {
+            p=(j*2.+1)/(2.*K);
+            rK[j]=InverseCDFBeta(p, par[off], par[off+1], lnbeta);
+         }
+      }
+      else {
+   cout<<"C"<<endl;
+         FOR(j,K) {
+            p=(j*2.+1)/(2.*K);
+            w0=.01+j/K; if(rK[j]) w0=(w0+rK[j])/2;
+            rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+			cout<<"WDWD "<<InverseCDF(CDFdN_dS,p,w0,par,xb)<<endl;
+         }
+      }
+      FOR(j,K) freqK[j]=1./K;
+   }
+
+   if(NSsites==NSbetaw) {
+    //if(!fix_omega) rK[ncatG-1]=par[3];
+	   rK[ncatG-1]=par[3];
+    //else               rK[ncatG-1]=omega_fix;
+      freqK[K]=1-par[0]; FOR(j,K) freqK[j]*=par[0];
+   }
+   if(NSsites==NS02normal) {
+      for(j=K-1;j>=0;j--) // shift to right by 1 to make room for spike at 0
+         { rK[j+1]=rK[j]; freqK[j+1]=freqK[j];  }
+      rK[0]=0;  freqK[0]=par[0];
+      for(j=1;j<K+1;j++) freqK[j]*=(1-par[0]);
+   }
+
+   if(NSsites>=NSgamma){
+      if(!status && NSsites==NSbeta) 
+         for(j=1;j<ncatG;j++) if(rK[j]+1e-7<rK[j-1]) status=1;
+
+      if(status) {
+         printf("\nwarning: DiscreteNSsites\nparameters: ");
+         FOR(j,(NSsites==7?2:4)) printf(" %12.6f", par[j]);  FPN(F0);
+         FOR(j,ncatG)            printf("%13.5f", freqK[j]);  FPN(F0);
+         FOR(j,ncatG)            printf("%13.5e", rK[j]);  FPN(F0);
+      }
+   }
+
+   output.clear();
+   cout<<"WOWOWOWOW "<<ncatG<<endl;
+
+   for(int jk=0; jk<ncatG; jk++) 
+   {output.push_back(rK[jk]); cout<<rK[jk]<<" WEGFQEGEG"<<endl;}
+   
+   return(0);
+}*/
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// note from WF - not really used any more as options for models M4-M13 have been disabled.
+
+
+int DiscreteNSsites(double par[], int ngamcat, int model, vector<double> &output, vector<double> &freqs)
+{
+/* 
+Yang, Z., Nielsen, R., Goldman, N. and Pedersen, A-M. K. (2000) Codon-Substitution Models for Heterogeneous Selection Pressure at Amino Acid Sites. Genetics 155: 431-439 (May 2000)
+
+  
+  
+   This discretizes the continuous distribution for dN/dS ratios among sites
+   and calculates freqK[] and rK[], using the median method.
+   par[] contains all paras in the w distribution.  par[0] is the 
+   proportion of beta if (com.NSsites==betaw), or the proportion of w=0 if 
+   (com.NSsites=NS02normal).
+   This routine uses com.NSsites, com.ncatG, com.freqK, com.rK.
+   betaw has com.ncatG-1 site classes in the beta distribution, and 02normal 
+   has com.ncatG-1 site classes in the mixed normal distribution.
+   See the function CDFdN_dS() for definitions of parameters.
+*/
+//	cout<<"!!!!!!!!!! !"<<endl;
+	com.ncatG=ngamcat;
+	com.NSsites=model;
+
+   int status=0, j,off, K=com.ncatG-(com.NSsites==NSbetaw || com.NSsites==NS02normal);
+   //cout<<"KKKKKKKKKKKKKKKKKKK   "<<K<<"  "<<model<<endl;
+   double xb[2]={1e-7,99};  /* bounds for omega.  */
+   int K1=6, K2=4, UseK1K2=0;
+   double p01=0, p,w0, lnbeta;
+
+   if(com.NSsites==NSbeta || com.NSsites==NSbetaw) xb[1]=1;
+
+#ifdef NSSITES_K1_K2_CLASSES
+   if((com.NSsites==NSgamma||com.NSsites==NS2gamma||com.NSsites>=NSbetagamma)){
+      K2=max2(K2,K/3);  K1=K-K2;  UseK1K2=1;
+      p01=CDFdN_dS(1.,par);
+
+      /* printf("\nK:%3d%3d\t p01=%9.5f\n",K1,K2,p01); */
+      FOR(j,K) {
+         if(j<K1) { p=p01*(j*2.+1)/(2.*K1); w0=p; }
+         else     { p=p01+(1-p01)*((j-K1)*2.+1)/(2.*K2); w0=1.01+(j-K1)/K2; }
+         com.rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+         com.freqK[j]=(j<K1 ? p01/K1 : (1-p01)/K2); thread
+      }
+   }
+#endif
+
+   if(!UseK1K2) { /* this is currently used */
+      if(com.NSsites==NSbeta || com.NSsites==NSbetaw) {
+         off=(com.NSsites==NSbetaw);  /* par[0] is proportion for beta for M8 */
+         lnbeta=LnGamma(par[off])+LnGamma(par[off+1])-LnGamma(par[off]+par[off+1]);
+         for(j=0; j<K; j++) {
+            p=(j*2.+1)/(2.*K);
+            com.rK[j]=InverseCDFBeta(p, par[off], par[off+1], lnbeta);
+         }
+      }
+      else {
+         FOR(j,K) {
+            p=(j*2.+1)/(2.*K);
+            w0=.01+j/K; if(com.rK[j]) w0=(w0+com.rK[j])/2;
+            com.rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+         }
+      }
+      FOR(j,K) com.freqK[j]=1./K;
+   }
+
+   if(com.NSsites==NSbetaw) {
+      if(!com.fix_omega) com.rK[com.ncatG-1]=par[3];
+      else               com.rK[com.ncatG-1]=com.omega_fix;
+      com.freqK[K]=1-par[0]; FOR(j,K) com.freqK[j]*=par[0];
+   }
+   if(com.NSsites==NS02normal) {
+      for(j=K-1;j>=0;j--) /* shift to right by 1 to make room for spike at 0*/
+         { com.rK[j+1]=com.rK[j]; com.freqK[j+1]=com.freqK[j];  }
+      com.rK[0]=0;  com.freqK[0]=par[0];
+      for(j=1;j<K+1;j++) com.freqK[j]*=(1-par[0]);
+   }
+
+   if(com.NSsites>=NSgamma){
+      if(!status && com.NSsites==NSbeta) 
+         for(j=1;j<com.ncatG;j++) if(com.rK[j]+1e-7<com.rK[j-1]) status=1;
+
+      if(status) {
+         printf("\nwarning: DiscreteNSsites\nparameters: ");
+         FOR(j,(com.NSsites==7?2:4)) printf(" %12.6f", par[j]);  FPN(F0);
+         FOR(j,com.ncatG)            printf("%13.5f", com.freqK[j]);  FPN(F0);
+         FOR(j,com.ncatG)            printf("%13.5e", com.rK[j]);  FPN(F0);
+      }
+   }
+
+   for(int i=0; i<ngamcat; i++) output.push_back(com.rK[i]);
+ 
+   for(int pp=0; pp<ngamcat; pp++) freqs.push_back(com.freqK[pp]);
+
+   return(0);
+}
+
+
+
+
+
+/*  
+  //script to calculate discrete M3 values for M4 to M13
+
+	 5  gamma         2:    alpha, beta
+	 6  2gamma        4:    p0, alpha1,beta1, alpha2=beta2
+	 7  beta          2:    p_beta, q_beta
+	 8  beta&w        4:    p0, p_beta, q_beta, w estimated
+	 9  beta&gamma    5:    p0, p_beta, q_beta, alpha, beta
+	10  beta&1+gamma  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+	11  beta&1>normal 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+	12  0&2normal     5:    p0, p1, mu2, s1, s2
+	13  3normal       6:    p0, p1, mu2, s0, s1, s2
+	14  M8a:beta&w=1  3:    p0, p_beta, q_beta, w=1 fixed
+	15  M8a:beta&w>=1 4:    p0, p_beta, q_beta, w>=1 estimated
+*/
+
+
+
+bool itis(string test, string check)
+{
+	bool result=true;
+
+	for(int p=0; p<test.size(); p++)
+	{
+		char c1=test[p];
+		bool minitest=false;
+		
+		for(int y=0; y<check.size(); y++)
+		{
+			char c2=check[y];
+			if(c2==c1) {minitest=true; break;}
+		}
+
+		if(minitest==false) {result=false; break;}
+	}
+
+	return result;
+
+}
+
+
+
+int main(int argc, char* argv[])
+{
+
+
+
+/*
+if(modelnumber==4)
+				{
+
+					//as K-1 for 4, 2K-1 for 3, but is K and 2K because of kappa, difference of K
+					// for modelnumber 4, K=5 means size is 5 (kappa, p0, p1, p2, p3) with p4=1-p1-p2-p3 etc
+					double sum=0, mysize=myparams.size()-2;  // mysize is 3
+					for(int yf=1; yf<mysize+2; yf++)   //from 1 in the list (p0 after kappa) to mysize+2=5 goes up to p3
+					{
+						//cout<<yf<<" "<<"1"<<endl;
+						omega=(yf-1)/mysize;  //omega is 0, 1/3, 2/3. 1
+						//cout<<yf<<" "<<"2 "<<endl;
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+						
+							
+						//cout<<yf<<" "<<"3"<<endl;
+						sum+=myparams.at(yf);
+						//cout<<yf<<" "<<"4"<<endl;
+						cumfreqs.push_back(myparams.at(yf));
+						//cout<<yf<<" "<<"5 "<<myparams.at(yf)<<"  "<<omega<<endl;
+
+					}
+					if(sum<=1)
+					{
+						//cout<<"BLAH"<<endl;
+						omega=mysize; //omega is 3
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+						
+									
+						cumfreqs.push_back(1-sum);
+						//cout<<"BLAH "<<1-sum<<" "<<omega<<endl;
+
+					}
+					else cout<<"Error in sum of category frequencies in codon model 4"<<endl;
+				
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+					for(int yf0=0; yf0<Qvecs.size(); yf0++)   {d(Qvecs.at(yf0),S); getJvec(S,name,myrates,Qvecs.at(yf0),Jvec,basefreqs); Jvecs.push_back(Jvec); }
+
+				}
+				else 
+				{
+
+					if(modelnumber==12 || modelnumber==8)
+					{
+						if(modelnumber==12)
+						{
+							omega=0;
+							Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+							
+					 					
+							cumfreqs.push_back(myparams.at(1));
+							for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back((1-myparams.at(1))/double(ngamcat));
+						}
+						else
+						{
+							omega=myparams.at(4);
+							Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+							
+							 					
+							cumfreqs.push_back(1-myparams.at(1));
+							for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back(myparams.at(1)/double(ngamcat));
+						}
+					}
+					else cumfreqs.assign(ngamcat,1/double(ngamcat));
+ 
+					//for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back(1/ngamcat);
+						
+					vector<double> output;
+
+					//double *mypar; mypar=new double[myparams.size()];
+					
+					double mypar[10]={0,0,0,0,0,0,0,0,0,0};
+
+					//mypar[0]=0;
+					for(int iu=1; iu<myparams.size(); iu++) {mypar[iu-1]=myparams.at(iu); }  
+
+					// this function of Ziheng's calculates the discrete rates for different site classes from the model parameters
+
+					DiscreteNSsites(mypar, ngamcat, modelnumber, output);
+
+					for(int i=0; i<ngamcat; i++)
+					{
+						omega=output.at(i);
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+											
+					}
+
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+					for(int yf0=0; yf0<Qvecs.size(); yf0++)   {d(Qvecs.at(yf0),S);  getJvec(S,name,myrates,Qvecs.at(yf0),Jvec,basefreqs); Jvecs.push_back(Jvec); }
+
+				}
+
+*/
+
+
+	
+
+/*  
+  //script to calculate discrete M3 values for M4 to M13
+
+	 5  gamma         2:    alpha, beta
+	 6  2gamma        4:    p0, alpha1,beta1, alpha2=beta2
+	 7  beta          2:    p_beta, q_beta
+	 8  beta&w        4:    p0, p_beta, q_beta, w estimated
+	 9  beta&gamma    5:    p0, p_beta, q_beta, alpha, beta
+	10  beta&1+gamma  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+	11  beta&1>normal 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+	12  0&2normal     5:    p0, p1, mu2, s1, s2
+	13  3normal       6:    p0, p1, mu2, s0, s1, s2
+	14  M8a:beta&w=1  3:    p0, p_beta, q_beta, w=1 fixed
+	15  M8a:beta&w>=1 4:    p0, p_beta, q_beta, w>=1 estimated
+*/
+	ofstream of1; of1.open("M5-13_output.txt");
+
+
+while(true)
+{
+
+	double mypar[11]={0,0,0,0,0,0,0,0,0,0,0};
+	int	nparams[11]={2,4,2,4,5,5,5,5,6,3,4};
+	vector<string> modelnames;
+	modelnames.push_back("gamma");
+	modelnames.push_back("2gamma");
+	modelnames.push_back("beta");
+	modelnames.push_back("beta&w");
+	modelnames.push_back("beta&gamma");
+	modelnames.push_back("beta&1+gamma");
+	modelnames.push_back("beta&1>normal");
+	modelnames.push_back("0&2normal");
+	modelnames.push_back("3normal");
+	modelnames.push_back("M8a:beta&w=1");
+	modelnames.push_back("M8a:beta&w>=1");
+
+
+	vector<vector<string> > paramlist; vector<string> blah;
+		blah.push_back("alpha"); blah.push_back("beta");  paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("alpha1"); blah.push_back("beta1"); blah.push_back("alpha2 (=beta2)"); paramlist.push_back(blah); blah.clear();
+		blah.push_back("p_beta"); blah.push_back("q_beta"); paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p_beta"); blah.push_back("q_beta"); blah.push_back("w");     paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p_beta"); blah.push_back("q_beta"); blah.push_back("alpha"); blah.push_back("beta");     paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p_beta"); blah.push_back("q_beta"); blah.push_back("alpha"); blah.push_back("beta"); paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p_beta"); blah.push_back("q_beta"); blah.push_back("mu"); blah.push_back("s"); paramlist.push_back(blah); blah.clear();
+ 		blah.push_back("p0"); blah.push_back("p1"); blah.push_back("mu2"); blah.push_back("s1"); blah.push_back("s2"); paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p1"); blah.push_back("mu2"); blah.push_back("s0"); blah.push_back("s1"); blah.push_back("s2"); paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p_beta"); blah.push_back("q_beta"); blah.push_back("w=1 fixed"); paramlist.push_back(blah); blah.clear();
+		blah.push_back("p0"); blah.push_back("p_beta"); blah.push_back("q_beta"); blah.push_back("w>=1 estimated"); paramlist.push_back(blah); blah.clear();
+
+
+
+	int modelnumber;
+	string test="!";
+
+	while(true)
+	{
+		cout<<endl<<" Please enter an integer between 5 and 13 (e.g. 5 for M5, 6 for M6 etc): "<<flush;
+		cin>>test;
+		if(itis(test,"0123456789"))
+		{
+			modelnumber=atoi(test.c_str());
+
+			// model number 5 to 13
+			if(modelnumber>4 && modelnumber<14) break;
+			else cout<<endl<<"    That integer is outside the accepted range."<<endl;
+		}
+		else cout<<endl<<"    That is not an integer! "<<endl;
+	}
+
+	int mysize=nparams[modelnumber-5];
+
+	cout<<endl<<" Model chosen: M"<<modelnumber<<"  ("<<modelnames.at(modelnumber-5)<<")"<<endl<<endl;
+	cout<<" This model has "<<mysize<<" parameters."<<endl<<endl;
+	cout<<" The parameters are: "<<endl<<endl;
+	//blah=paramlist.at(modelnumber-5); cout<<blah.at(0); for(int yg=1; yg<blah.size(); yg++) cout<<", "<<blah.at(yg);
+	blah=paramlist.at(modelnumber-5); for(int yg2=0; yg2<blah.size(); yg2++) cout<<"    Parameter "<<yg2+1<<":\t"<<blah.at(yg2)<<endl;
+	cout<<endl;
+
+	vector<double> params;
+
+	cout<<" Please enter them in this order pressing enter after each parameter"<<endl<<endl;
+
+	params.assign(mysize,0);
+
+	for(int pi=0; pi<mysize; pi++)
+	{ 
+		// get input
+		double temp;
+		string readin;
+		cout<<"    Parameter "<<pi+1<<": "<<flush;
+		cin>>readin;
+
+
+
+
+		// check string does not contain illegal characters
+		string check="0123456789.";
+
+		if( modelnumber==11 && pi==3) check+="-";
+	
+		if(  (modelnumber==12 || modelnumber==13) && pi==2) check+="-";
+
+		if(!itis(readin,check))
+		{
+			if(  (modelnumber==12 || modelnumber==13) && pi==2) cout<<endl<<"      ERROR: this parameter must be a real number. Allowed characters are:"<<endl<<"      -.0123456789"<<endl;
+				
+			else if( modelnumber==11 && pi==3) cout<<endl<<"      ERROR: this parameter must be a real number. Allowed characters are:"<<endl<<"      -.0123456789"<<endl;
+	
+			else  cout<<endl<<"      ERROR: this parameter must be a decimal number. Allowed characters are:"<<endl<<"      .0123456789"<<endl;
+
+			cout<<"     Try again."<<endl<<endl;  pi--; continue;
+		}
+		else temp=atof(readin.c_str());
+			
+		
+		// check value is not incorrect
+		if(modelnumber==5 || modelnumber==7) { if(temp==0) {cout<<endl<<"      ERROR: this parameter must be greater than zero. Try again."<<endl<<endl; pi--; continue;}}
+		
+		else
+		{
+			if(  (modelnumber==12 || modelnumber==13) && pi==2) {}  //mu_2
+				
+			else if( modelnumber==11 && pi==3) {}  // mu
+
+			else if( modelnumber==8 && pi==3) {}  // omega 
+	
+			else
+			{
+
+				if(pi==0) {if(temp>1) {cout<<endl<<"      ERROR: proportion p0 must be between 0 and 1.  You entered "<<temp<<endl<<"      Try again."<<endl<<endl; pi--; continue;}}
+
+				else if(pi==1) 
+				{
+					if(modelnumber==12 || modelnumber==13)
+					{
+						if(temp>1) {cout<<endl<<"      ERROR: proportion p1 must be between 0 and 1.  You entered "<<temp<<endl<<"      Try again."<<endl<<endl; pi--; continue;}
+						
+						if(temp+params.at(0)>1) {cout<<endl<<"      ERROR: sum of proportions p0 and p1 must be between 0 and 1.\n    You entered "<<temp+params.at(0)<<endl<<"      Try again."<<endl<<endl; pi--; continue;}
+					}
+					else if(temp==0) {cout<<endl<<"      ERROR: this parameter must be greater than zero. Try again."<<endl<<endl; pi--; continue;}
+
+				}
+				else if(temp==0) {cout<<endl<<"      ERROR: this parameter must be greater than zero. Try again."<<endl<<endl; pi--; continue;}
+			}			
+
+		}
+
+		
+		params.at(pi)=temp;
+
+	}
+		
+	int ngamcat;  test="";
+
+	cout<<endl<<endl;
+	cout<<"  I also need to know how many categories you want to use for"<<endl;
+	cout<<"   the discrete approximation to the continuous distribution."<<endl<<endl;
+
+	while(true)
+	{
+		cout<<endl<<" Please enter an integer between 4 and 40: "<<flush;
+		cin>>test;
+		if(itis(test,"0123456789"))
+		{
+			ngamcat=atoi(test.c_str());
+
+			if(ngamcat>3 && ngamcat<41) break;
+			else cout<<endl<<"    That integer is outside the accepted range."<<endl;
+		}
+		else cout<<endl<<"    That is not an integer! "<<endl;
+	}
+	
+	
+	
+	cout<<endl<<endl<<"******************************************************"<<endl<<endl;
+	
+
+
+	vector<double> output2, cumfreqs, freqs2;
+	for(int iu=0; iu<params.size(); iu++) {mypar[iu]=params.at(iu); }  
+	
+	DiscreteNSsites(mypar, ngamcat, modelnumber, output2, freqs2);
+
+	vector<string> output,freqs; for(int tg=0; tg<ngamcat; tg++)
+	{
+		stringstream sd1; sd1<<output2.at(tg); output.push_back(sd1.str());
+		stringstream sd2; sd2<<freqs2.at(tg); freqs.push_back(sd2.str());
+	}
+
+	/*
+					if(modelnumber==12 || modelnumber==8)
+					{
+						if(modelnumber==12)
+						{
+							vector<double> temp=output; output.clear(); output.push_back(0); for(int y=0; y<temp.size(); y++) output.push_back(temp.at(y));
+					 					
+							cumfreqs.push_back(params.at(0));
+							for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back((1-params.at(0))/double(ngamcat));
+						}
+						else
+						{
+							vector<double> temp=output; output.clear(); output.push_back(params.at(3)); for(int y=0; y<temp.size(); y++) output.push_back(temp.at(y));
+						 					
+							cumfreqs.push_back(1-params.at(0));
+							for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back(params.at(0)/double(ngamcat));
+						}
+					}
+					else cumfreqs.assign(ngamcat,1/double(ngamcat));
+*/
+	cout<<"Your [submodel] command for INDELible has been output in the file:"<<endl<<"M5-13_output.txt"<<endl<<endl;
+
+	of1<<"/*"<<endl;
+	of1<<"  M3 approximation to M"<<modelnumber<<"  ("<<modelnames.at(modelnumber-5)<<")  with "<<ngamcat<<" categories used in discrete approximation"<<endl<<endl;
+	of1<<" You chose the following values:"<<endl<<endl;
+	blah=paramlist.at(modelnumber-5); for(int yg1=0; yg1<blah.size(); yg1++) of1<<"    Parameter "<<yg1+1<<":\t"<<blah.at(yg1)<<"\t"<<params.at(yg1)<<endl;
+	of1<<"*/"<<endl<<endl;
+
+	of1<<"  [submodel]\tkappa  // use your own value for kappa here!"<<endl;
+
+	of1<<"\t\t"; for(int s=0; s<freqs.size(); s++) 
+	{
+		string s1=output.at(s), s2=freqs.at(s); 
+		if(s==freqs.size()-1) s2="";
+		int diff=s1.size()-s2.size();  
+
+		of1<<s2<<" "; 
+
+		if(diff>0) for(int fd=0; fd<diff; fd++) of1<<" ";
+	}
+	of1<<"  // proportions"<<endl;
+
+	of1<<"\t\t"; for(int t=0; t<output.size(); t++) 
+	{
+		string s1=output.at(t), s2=freqs.at(t); 
+		
+		int diff=s2.size()-s1.size();  
+
+		of1<<s1<<" "; 
+
+		if(diff>0) for(int fd=0; fd<diff; fd++) of1<<" ";
+	}
+	of1<<"  // omega values"<<endl;
+	
+
+	
+	
+
+//	cout<<"              "kappa"<<endl;
+	of1<<endl<<endl<<"/*********************************************/"<<endl<<endl;
+
+
+
+	
+	}
+
+
+  //script to calculate discrete M3 values for M4 to M13
+/*
+	 5  "gamma"         2:    alpha, beta
+	 6  "2gamma"        4:    p0, alpha1,beta1, alpha2=beta2
+	 7  "beta"          2:    p_beta, q_beta
+	 8  "beta&w"        4:    p0, p_beta, q_beta, w estimated
+	 9  "beta&gamma"    5:    p0, p_beta, q_beta, alpha, beta
+	10  "beta&1+gamma"  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+	11  "beta&1>normal" 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+	12  "0&2normal"     5:    p0, p1, mu2, s1, s2
+	13  "3normal"       6:    p0, p1, mu2, s0, s1, s2
+	14  "M8a:beta&w=1"  3:    p0, p_beta, q_beta, w=1 fixed
+	15  "M8a:beta&w>=1" 4:    p0, p_beta, q_beta, w>=1 estimated
+*/
+
+
+
+				
+
+	return 0;
+}
\ No newline at end of file
diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h
new file mode 100644
index 0000000..5493269
--- /dev/null
+++ b/src/MersenneTwister.h
@@ -0,0 +1,473 @@
+// MersenneTwister.h 
+// Mersenne Twister random number generator -- a C++ class MTRand
+// Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus
+// Richard J. Wagner  v1.0  15 May 2003  rjwagner at writeme.com
+
+// The Mersenne Twister is an algorithm for generating random numbers.  It
+// was designed with consideration of the flaws in various other generators.
+// The period, 2^19937-1, and the order of equidistribution, 623 dimensions,
+// are far greater.  The generator is also fast; it avoids multiplication and
+// division, and it benefits from caches and pipelines.  For more information 
+// see the inventors' web page at http://www.math.keio.ac.jp/~matumoto/emt.html
+ 
+// Reference
+// M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
+// Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on
+// Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
+
+// Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+// Copyright (C) 2000 - 2003, Richard J. Wagner
+// All rights reserved.                          
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+//   1. Redistributions of source code must retain the above copyright
+//      notice, this list of conditions and the following disclaimer.
+//
+//   2. Redistributions in binary form must reproduce the above copyright
+//      notice, this list of conditions and the following disclaimer in the
+//      documentation and/or other materials provided with the distribution.
+//
+//   3. The names of its contributors may not be used to endorse or promote 
+//      products derived from this software without specific prior written 
+//      permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The original code included the following notice:
+//
+//     When you use this, send an email to: matumoto at math.keio.ac.jp
+//     with an appropriate reference to your work.
+//
+// It would be nice to CC: rjwagner at writeme.com and Cokus at math.washington.edu
+// when you write.
+
+#ifndef MERSENNETWISTER_H
+#define MERSENNETWISTER_H
+
+// Not thread safe (unless auto-initialization is avoided and each thread has
+// its own MTRand object)
+
+#include <iostream>
+#include <limits.h>
+#include <stdio.h>
+#include <time.h>
+#include <math.h>
+
+class MTRand {
+// Data
+public:
+	typedef unsigned long uint32;  // unsigned integer type, at least 32 bits
+	
+	enum { N = 624 };       // length of state vector
+	enum { SAVE = N + 1 };  // length of array for save()
+
+protected:
+	enum { M = 397 };  // period parameter
+	
+	uint32 state[N];   // internal state
+	uint32 *pNext;     // next value to get from state
+	int left;          // number of values left before reload needed
+
+
+//Methods
+public:
+	MTRand( const uint32& oneSeed );  // initialize with a simple uint32
+	MTRand( uint32 *const bigSeed, uint32 const seedLength = N );  // or an array
+	MTRand();  // auto-initialize with /dev/urandom or time() and clock()
+	
+	// Do NOT use for CRYPTOGRAPHY without securely hashing several returned
+	// values together, otherwise the generator state can be learned after
+	// reading 624 consecutive values.
+	
+	// Access to 32-bit random numbers
+	double rand();                          // real number in [0,1]
+	double rand( const double& n );         // real number in [0,n]
+	double randExc();                       // real number in [0,1)
+	double randExc( const double& n );      // real number in [0,n)
+	double randDblExc();                    // real number in (0,1)
+	double randDblExc( const double& n );   // real number in (0,n)
+	uint32 randInt();                       // integer in [0,2^32-1]
+	uint32 randInt( const uint32& n );      // integer in [0,n] for n < 2^32
+	double operator()() { return rand(); }  // same as rand()
+	
+	// Access to 53-bit random numbers (capacity of IEEE double precision)
+	double rand53();  // real number in [0,1)
+	
+	// Access to nonuniform random number distributions
+	double randNorm( const double& mean = 0.0, const double& variance = 0.0 );
+	
+	// Re-seeding functions with same behavior as initializers
+	void seed( const uint32 oneSeed );
+	void seed( uint32 *const bigSeed, const uint32 seedLength = N );
+	void seed();
+	
+	// Saving and loading generator state
+	void save( uint32* saveArray ) const;  // to array of size SAVE
+	void load( uint32 *const loadArray );  // from such array
+	friend std::ostream& operator<<( std::ostream& os, const MTRand& mtrand );
+	friend std::istream& operator>>( std::istream& is, MTRand& mtrand );
+
+protected:
+	void initialize( const uint32 oneSeed );
+	void reload();
+	uint32 hiBit( const uint32& u ) const { return u & 0x80000000UL; }
+	uint32 loBit( const uint32& u ) const { return u & 0x00000001UL; }
+	uint32 loBits( const uint32& u ) const { return u & 0x7fffffffUL; }
+	uint32 mixBits( const uint32& u, const uint32& v ) const
+		{ return hiBit(u) | loBits(v); }
+	uint32 twist( const uint32& m, const uint32& s0, const uint32& s1 ) const
+		{ return m ^ (mixBits(s0,s1)>>1) ^ (-loBit(s1) & 0x9908b0dfUL); }
+	static uint32 hash( time_t t, clock_t c );
+};
+
+
+inline MTRand::MTRand( const uint32& oneSeed )
+	{ seed(oneSeed); }
+
+inline MTRand::MTRand( uint32 *const bigSeed, const uint32 seedLength )
+	{ seed(bigSeed,seedLength); }
+
+inline MTRand::MTRand()
+	{ seed(); }
+
+inline double MTRand::rand()
+	{ return double(randInt()) * (1.0/4294967295.0); }
+
+inline double MTRand::rand( const double& n )
+	{ return rand() * n; }
+
+inline double MTRand::randExc()
+	{ return double(randInt()) * (1.0/4294967296.0); }
+
+inline double MTRand::randExc( const double& n )
+	{ return randExc() * n; }
+
+inline double MTRand::randDblExc()
+	{ return ( double(randInt()) + 0.5 ) * (1.0/4294967296.0); }
+
+inline double MTRand::randDblExc( const double& n )
+	{ return randDblExc() * n; }
+
+inline double MTRand::rand53()
+{
+	uint32 a = randInt() >> 5, b = randInt() >> 6;
+	return ( a * 67108864.0 + b ) * (1.0/9007199254740992.0);  // by Isaku Wada
+}
+
+inline double MTRand::randNorm( const double& mean, const double& variance )
+{
+	// Return a real number from a normal (Gaussian) distribution with given
+	// mean and variance by Box-Muller method
+	double r = sqrt( -2.0 * log( 1.0-randDblExc()) ) * variance;
+	double phi = 2.0 * 3.14159265358979323846264338328 * randExc();
+	return mean + r * cos(phi);
+}
+
+inline MTRand::uint32 MTRand::randInt()
+{
+	// Pull a 32-bit integer from the generator state
+	// Every other access function simply transforms the numbers extracted here
+	
+	if( left == 0 ) reload();
+	--left;
+		
+	register uint32 s1;
+	s1 = *pNext++;
+	s1 ^= (s1 >> 11);
+	s1 ^= (s1 <<  7) & 0x9d2c5680UL;
+	s1 ^= (s1 << 15) & 0xefc60000UL;
+	return ( s1 ^ (s1 >> 18) );
+}
+
+inline MTRand::uint32 MTRand::randInt( const uint32& n )
+{
+	// Find which bits are used in n
+	// Optimized by Magnus Jonsson (magnus at smartelectronix.com)
+	uint32 used = n;
+	used |= used >> 1;
+	used |= used >> 2;
+	used |= used >> 4;
+	used |= used >> 8;
+	used |= used >> 16;
+	
+	// Draw numbers until one is found in [0,n]
+	uint32 i;
+	do
+		i = randInt() & used;  // toss unused bits to shorten search
+	while( i > n );
+	return i;
+}
+
+
+inline void MTRand::seed( const uint32 oneSeed )
+{
+	// Seed the generator with a simple uint32
+	initialize(oneSeed);
+	reload();
+}
+
+
+inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength )
+{
+	// Seed the generator with an array of uint32's
+	// There are 2^19937-1 possible initial states.  This function allows
+	// all of those to be accessed by providing at least 19937 bits (with a
+	// default seed length of N = 624 uint32's).  Any bits above the lower 32
+	// in each element are discarded.
+	// Just call seed() if you want to get array from /dev/urandom
+	initialize(19650218UL);
+	register int i = 1;
+	register uint32 j = 0;
+	register int k = ( N > seedLength ? N : seedLength );
+	for( ; k; --k )
+	{
+		state[i] =
+			state[i] ^ ( (state[i-1] ^ (state[i-1] >> 30)) * 1664525UL );
+		state[i] += ( bigSeed[j] & 0xffffffffUL ) + j;
+		state[i] &= 0xffffffffUL;
+		++i;  ++j;
+		if( i >= N ) { state[0] = state[N-1];  i = 1; }
+		if( j >= seedLength ) j = 0;
+	}
+	for( k = N - 1; k; --k )
+	{
+		state[i] =
+			state[i] ^ ( (state[i-1] ^ (state[i-1] >> 30)) * 1566083941UL );
+		state[i] -= i;
+		state[i] &= 0xffffffffUL;
+		++i;
+		if( i >= N ) { state[0] = state[N-1];  i = 1; }
+	}
+	state[0] = 0x80000000UL;  // MSB is 1, assuring non-zero initial array
+	reload();
+}
+
+
+inline void MTRand::seed()
+{
+	// Seed the generator with a hash of time() and clock() values
+	
+	seed( hash( time(NULL), clock() ) );
+}
+
+
+inline void MTRand::initialize( const uint32 seed )
+{
+	// Initialize generator state with seed
+	// See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
+	// In previous versions, most significant bits (MSBs) of the seed affect
+	// only MSBs of the state array.  Modified 9 Jan 2002 by Makoto Matsumoto.
+	register uint32 *s = state;
+	register uint32 *r = state;
+	register int i = 1;
+	*s++ = seed & 0xffffffffUL;
+	for( ; i < N; ++i )
+	{
+		*s++ = ( 1812433253UL * ( *r ^ (*r >> 30) ) + i ) & 0xffffffffUL;
+		r++;
+	}
+}
+
+
+inline void MTRand::reload()
+{
+	// Generate N new values in state
+	// Made clearer and faster by Matthew Bellew (matthew.bellew at home.com)
+	register uint32 *p = state;
+	register int i;
+	for( i = N - M; i--; ++p )
+		*p = twist( p[M], p[0], p[1] );
+	for( i = M; --i; ++p )
+		*p = twist( p[M-N], p[0], p[1] );
+	*p = twist( p[M-N], p[0], state[0] );
+
+	left = N, pNext = state;
+}
+
+
+inline MTRand::uint32 MTRand::hash( time_t t, clock_t c )
+{
+	int totalpath=0;
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	// MODIFIED BY WF
+
+	// hash function in Mersenne Twister file
+	// takes hash of time and clock, but for very
+	// small jobs run in separate folders that start
+	// in the same second it is possible to get the 
+	// same seed. This version modified by WF used to
+	// include the working directory name into the hash
+	// for UNIX systems. However g++ 4.3.2 optimises the
+	// code out with compiler flags such as -O2 etc....
+
+	// So now, it uses the number of milliseconds since 
+	// system startup on Windows systems with gettickcount()
+	// and uses the process id on unix systems with getpid()
+
+	#ifndef WINDOWS
+
+	totalpath=getpid();
+/*
+		printf(" ");
+		size_t size;
+		
+		printf(" ");
+		char *path=new char[PATH_MAX]; 
+		
+		printf(" ");
+		getcwd(path,size);	
+		
+		printf(" ");
+		int pathchar;
+
+		//printf("%d  ",PATH_MAX);
+
+		for(int ygh=0; ygh<PATH_MAX; ygh++)
+		{
+			char c=path[ygh];
+		//	printf("%c",c);
+		//	printf(" ");
+
+			if(c==' ') break;
+			pathchar=c; totalpath+=pathchar; 
+		}
+
+		//printf("  %d\n",totalpath);
+		printf(" ");
+*/
+	#else
+		unsigned long blah=GetTickCount();
+		totalpath=int(blah);
+	#endif
+
+	//  ONLY OTHER CHANGE TO THIS FUNCTION IS " + totalpath " IN RETURN STATEMENT.
+//////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+
+	// Get a uint32 from t and c
+	// Better than uint32(x) in case x is floating point in [0,1]
+	// Based on code by Lawrence Kirby (fred at genesis.demon.co.uk)
+
+	static uint32 differ = 0;  // guarantee time-based seeds will change
+
+	uint32 h1 = 0;
+	unsigned char *p = (unsigned char *) &t;
+	for( size_t i = 0; i < sizeof(t); ++i )
+	{
+		h1 *= UCHAR_MAX + 2U;
+		h1 += p[i];
+	}
+	uint32 h2 = 0;
+	p = (unsigned char *) &c;
+	for( size_t j = 0; j < sizeof(c); ++j )
+	{
+		h2 *= UCHAR_MAX + 2U;
+		h2 += p[j];
+	}
+	return ( h1 + differ++ ) ^ h2  + totalpath;
+}
+
+
+inline void MTRand::save( uint32* saveArray ) const
+{
+	register uint32 *sa = saveArray;
+	register const uint32 *s = state;
+	register int i = N;
+	for( ; i--; *sa++ = *s++ ) {}
+	*sa = left;
+}
+
+
+inline void MTRand::load( uint32 *const loadArray )
+{
+	register uint32 *s = state;
+	register uint32 *la = loadArray;
+	register int i = N;
+	for( ; i--; *s++ = *la++ ) {}
+	left = *la;
+	pNext = &state[N-left];
+}
+
+
+inline std::ostream& operator<<( std::ostream& os, const MTRand& mtrand )
+{
+	register const MTRand::uint32 *s = mtrand.state;
+	register int i = mtrand.N;
+	for( ; i--; os << *s++ << "\t" ) {}
+	return os << mtrand.left;
+}
+
+
+inline std::istream& operator>>( std::istream& is, MTRand& mtrand )
+{
+	register MTRand::uint32 *s = mtrand.state;
+	register int i = mtrand.N;
+	for( ; i--; is >> *s++ ) {}
+	is >> mtrand.left;
+	mtrand.pNext = &mtrand.state[mtrand.N-mtrand.left];
+	return is;
+}
+
+#endif  // MERSENNETWISTER_H
+
+// Change log:
+//
+// v0.1 - First release on 15 May 2000
+//      - Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus
+//      - Translated from C to C++
+//      - Made completely ANSI compliant
+//      - Designed convenient interface for initialization, seeding, and
+//        obtaining numbers in default or user-defined ranges
+//      - Added automatic seeding from /dev/urandom or time() and clock()
+//      - Provided functions for saving and loading generator state
+//
+// v0.2 - Fixed bug which reloaded generator one step too late
+//
+// v0.3 - Switched to clearer, faster reload() code from Matthew Bellew
+//
+// v0.4 - Removed trailing newline in saved generator format to be consistent
+//        with output format of built-in types
+//
+// v0.5 - Improved portability by replacing static const int's with enum's and
+//        clarifying return values in seed(); suggested by Eric Heimburg
+//      - Removed MAXINT constant; use 0xffffffffUL instead
+//
+// v0.6 - Eliminated seed overflow when uint32 is larger than 32 bits
+//      - Changed integer [0,n] generator to give better uniformity
+//
+// v0.7 - Fixed operator precedence ambiguity in reload()
+//      - Added access for real numbers in (0,1) and (0,n)
+//
+// v0.8 - Included time.h header to properly support time_t and clock_t
+//
+// v1.0 - Revised seeding to match 26 Jan 2002 update of Nishimura and Matsumoto
+//      - Allowed for seeding with arrays of any length
+//      - Added access for real numbers in [0,1) with 53-bit resolution
+//      - Added access for real numbers from normal (Gaussian) distributions
+//      - Increased overall speed by optimizing twist()
+//      - Doubled speed of integer [0,n] generation
+//      - Fixed out-of-range number generation on 64-bit machines
+//      - Improved portability by substituting literal constants for long enum's
+//      - Changed license from GNU LGPL to BSD
diff --git a/src/README.txt b/src/README.txt
new file mode 100644
index 0000000..3ff2297
--- /dev/null
+++ b/src/README.txt
@@ -0,0 +1,52 @@
+UNIX
+----
+
+To compile the source code on UNIX use a suitable compiler such as g++.
+
+  e.g.  g++ -o indelible -O4 indelible.cpp
+
+but insert the relevant compiler flags for your system.
+
+I use:
+  
+   g++ -o indelible -m64 -O4 -march=opteron indelible.cpp -lm
+
+but there are many other flags that can be added.
+
+
+MAC - (N.B. pre-compiled executables in "bin" folder)
+-----------------------------------------------------
+
+The process is similar to that of UNIX.  
+
+Just open a terminal window, use 'cd' to navigate to the folder where the 
+source code is, then type the compile command.
+
+  e.g. g++ -o indelible -O4 -march=pentium-m indelible.cpp -lm
+
+for new intel-based MACs.
+
+The following two seem to work on older G4 and G5 systems:
+
+  e.g. g++ -o indelible -O4 -mcpu=G4 indelible.cpp -lm
+  e.g. g++ -o indelible -O4 -mcpu=G5 indelible.cpp -lm
+
+
+WINDOWS - (N.B. pre-compiled executables in "bin" folder)
+---------------------------------------------------------
+
+Using Microsoft Visual Studio 6.0 simply load the file indelible.cpp making 
+sure it is in the same folder as the other source files.
+* Click on the compile button.  
+* Once compiled go to the build menu and choose "set active configuration".
+* Then choose "RELEASE" otherwise you will get a very slow version with debug code in.
+* Then re-compile and build.
+* The INDELible executable will be in the "release" folder 
+
+Please note if you do not want to use the executable and wish
+to compile INDELible yourself on Windows systems then please
+include the line
+
+ #define WINDOWS
+
+at the top of the file indelible.cpp
\ No newline at end of file
diff --git a/src/control.cpp b/src/control.cpp
new file mode 100644
index 0000000..0361f3e
--- /dev/null
+++ b/src/control.cpp
@@ -0,0 +1,4167 @@
+/* 
+   INDELible V1.03
+    "A comprehensive and flexible simulator of molecular sequence evolution"
+    Copyright (C) 2009 William Fletcher
+
+    If using this software please cite the following reference:
+
+    Fletcher, W. and Yang, Z. 2009. 
+	"INDELible: a flexible simulator of biological sequence evolution." 
+	Mol. Biol. and Evol. (in press). 
+
+    If you need to contact me with any queries, questions, problems or (god-forbid) bugs 
+    then please go to http://abacus.gene.ucl.ac.uk/software/indelible/bug.php
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    Please visit http://www.gnu.org/licenses/ for a full copy of the license.
+*/
+
+
+#include <iostream>
+#include <iomanip> 
+#include <fstream> 
+#include <string>
+#include <vector> 
+#include <math.h>
+#include <sstream>  
+#include <algorithm>
+#include <map> 
+#include "models.cpp"
+
+using namespace std;
+
+bool controldebug=false;   //"false" will cease everything when a -1 error occurs, "true" will continue on - for debugging (but may lead to crashes)
+
+extern string masterfilename;//="control.txt";
+
+bool oldmethod;				// false for method 1, true for waiting time method
+
+bool breakonerror=true;   // "true" will allow "return -1;" statements after an error.
+                          // "false" will continue on and probably make the program crash but is useful
+                          // for checking errors in the control file programs.
+
+#pragma warning(disable:4786)
+
+bool globalseed=false;				// whether one seed sets both random trees, and sequence generation.
+
+bool insertaslowercase   = false;    // prints inserted sites as lower case and core sites as uppercase
+
+bool fixtrueproportions = false;   //  if true then the proportions of codon sites models will be true rather than random.
+
+bool markdeletedinsertions = false; //
+bool fileperrep          = false;	// prints all replicates in same file if false, otherwise in their own files.
+
+bool printrates			 = false;	// whether to print out relative rate information or not.
+bool printallrates			 = false;	// whether to print out relative rate information or not for every branch
+
+bool printcodonsasDNA=true;		// whether to print codons as DNA bases or not (true for DNA/false for amino acids)
+
+
+bool printinsert		 = false;	// whether to print indel statistics
+bool ancestralprint		 = false;	// whether to print ancestral sequences to another file
+bool ancestralfile		 = true;	// whether ancestral sequences go in same or different file.  true for different file
+//bool replicatesfile		 = true;	// whether replicate datasets should be printed in the same file or into separate files.
+bool phylipnametruncate	 = false;	// truncates taxa names to 10 characters to comply with PHYLIP format
+bool guidetreebinary	 = true;	// whether guide tree contains polytomies
+bool guidetreerooted	 = true;	// whether guide tree is unrooted or rooted
+
+string phylipextension	="phy";		// used for output file filename extension
+string fastaextension	="fas";		// used for output file filename extension
+string nexusextension	="nex";		// used for output file filename extension
+
+int outputtype			= 2;		// 1 for FASTA, 2 for PHYLIP, 3 for NEXUS
+int guidetreetype		= 0;		// used for logfile
+
+
+// makes a time string to append to output file names.
+string makesimtime()
+{
+	time_t stringtime;
+
+	struct tm *mytime; time(&stringtime);
+	
+	mytime=localtime(&stringtime); 
+
+	string s1="_",s2=asctime(mytime); //hexToAsci(%3A)
+	for(int i=0; i<s2.size()-1; i++) {if(s2[i]==':') s1+="."; else s1+=s2[i]; }
+	for(int j=0; j<s1.size(); j++) if(s1[j]==' ') s1[j]='_';
+	return s1;
+}
+
+string simtime; //=makesimtime();   //disabled time stamp so that output is over-written.
+
+ofstream* LOG=new ofstream;		// used to print out information from simulations
+
+
+// need "total" vectors for models, sites, branches, and modelnames, sitenames, branchesnames etc
+
+vector<char> originalcontrol;  // used to store control file used.
+
+vector<string>		totalmodelnames;
+vector<string>		totalsitenames;
+vector<string>		totalbranchesnames;
+vector<string>		totaltreenames;
+vector<string>		totalpartitionnames;
+vector<model>		totalmodels;
+
+
+// blocktype e.g. [MODEL], blockname #de1#  (* ??? *), commandname= [submodel], instring error print, myline last input
+void controlerrorprint2(string blocktype, string blockname, string commandname, string instring, string myline)
+{
+	// this functions provides a framework for a standard output of an error to the screen and log file
+	// mostly it is just formatting the border of the error box and white space etc
+
+//	cout<<"\r                                                                      \n ERROR occurred in "<<blocktype<<" block "<<blockname<<".\n See below for details or consult LOG.txt                       ";
+	cout<<"\r                                                                      \n";
+
+	vector<string> toprint;
+	
+	string startline="ERROR in "+blocktype+" block ";
+	if(blockname!="")   startline+=blockname;
+	if(commandname!="") startline+=" in command "+commandname;
+
+//	stringstream fd1; fd1<<linecount; string fd1s=fd1.str();
+//	startline+=fd1s; startline+=" of control file:";
+	
+	toprint.push_back(startline);
+
+	string tempstring;
+	char c;
+	int themaxsize=startline.size();
+	
+	for(int j0=0; j0<instring.size(); j0++) 
+	{
+		c=instring[j0]; 
+		if(c=='\n') 
+		{
+			toprint.push_back(tempstring);
+			if(themaxsize<tempstring.size()) themaxsize=tempstring.size();
+			tempstring="";
+		} 
+		else tempstring+=c;
+	} 
+	toprint.push_back(tempstring);if(themaxsize<tempstring.size()) themaxsize=tempstring.size();
+	
+	if(myline!="") {string endline="Last Input read was: "; endline+=myline; if(themaxsize<endline.size()) themaxsize=endline.size(); toprint.push_back(endline);}
+
+	cout<<endl<<endl; (*LOG)<<endl;
+
+	for(int i0=0; i0<toprint.size(); i0++)
+	{
+		string tempstring2=toprint.at(i0);
+		for(int h1=tempstring2.size(); h1<themaxsize; h1++) tempstring2+=" ";
+		toprint.at(i0)=tempstring2;
+	}
+
+	cout<<endl<<" +";  (*LOG)<<endl<<"+";  
+	for(int i1=0; i1<themaxsize+2; i1++) {cout<<"-"; (*LOG)<<"-";}
+	cout<<"+"<<endl;	(*LOG)<<"+"<<endl;
+	
+	for(int i2=0; i2<toprint.size(); i2++) {cout<<" | "<<toprint.at(i2)<<" |"<<endl; (*LOG)<<"| "<<toprint.at(i2)<<" |"<<endl;}
+	
+	cout<<" +"; (*LOG)<<"+"; 
+	for(int i3=0; i3<themaxsize+2; i3++) {cout<<"-"; (*LOG)<<"-";}
+	cout<<"+"<<endl<<endl;	(*LOG)<<"+"<<endl<<endl;
+
+	
+}
+
+
+int checkthere(string mytest,vector<string> mylist)
+{
+	// returns -1 if mytest is not in mylist otherwise returns position in list
+	int blah=-1;
+	for(int h1=0; h1<mylist.size(); h1++) if(mylist.at(h1)==mytest) {blah=h1; break;}
+	return blah;
+}
+
+int checkthereN(int mytest,vector<int> mylist)
+{
+	// returns -1 if mytest is not in mylist otherwise returns position in list
+	int blah=-1;
+	for(int h1=0; h1<mylist.size(); h1++) if(mylist.at(h1)==mytest) {blah=h1; break;}
+	return blah;
+}
+
+
+bool AinB(char testchar, string referencestring)
+{
+	// returns true if testchar is in referencestring
+	// returns false if testchar is not in referencestring
+
+	bool answer1=false;
+
+	for(int i=0; i<referencestring.size(); i++) if(testchar==referencestring[i]) {answer1=true; break;}
+
+	return answer1;
+}
+
+bool AonlyfromB(string teststring, string referencestring)
+{
+	// checks test string to make sure it is only made up of 
+	// characters from referencestring. Anything else gives false.
+	// returns false if teststring contains illegal characters
+
+	bool answer;
+
+	for(int i=0; i<teststring.size(); i++)
+	{
+		answer=AinB(teststring[i],referencestring);
+		if(!answer) break;
+	}
+
+return answer;
+
+}
+
+
+bool allAinB(string teststring, string referencestring)
+{
+	// checks test string to make sure it is only made up of 
+	// characters from referencestring. Anything else gives false.
+	// returns false if teststring contains illegal characters
+
+	bool answer;
+
+	for(int i=0; i<teststring.size(); i++)
+	{
+		answer=AinB(teststring[i],referencestring);
+		if(!answer) break;
+	}
+
+return answer;
+
+}
+
+
+bool noneAinB(string teststring, string referencestring)
+{
+	// checks test string to make sure it is only made up of 
+	// characters from referencestring. Anything else gives false.
+	// returns false if teststring contains illegal characters
+
+	bool answer;
+
+	for(int i=0; i<teststring.size(); i++)
+	{
+		answer=AinB(teststring[i],referencestring);
+		if(answer) break;
+	}
+
+return !answer;
+
+}
+
+
+////////////////////////////////////////////////
+
+class branchclass
+{
+	// this class provides the framework for simulations that use different models on different branches in the guide tree.
+
+public:
+	string treewithrootmodel;         // original tree given in control file, has a model at the root.
+	string tree;                      // tree minus model at root.
+	string baretree;                  // tree expressed as only a pattern of parentheses and commas
+	string name;					  // name of branch class
+	vector<string> modelnames;		  // names of models used, given in same order as modelpositions
+	//vector<model> branchmodels;
+	vector<int> modelpositions;       // position of models used in totalmodels.
+	vector<int> allmodelsused;		  // list of all models used in branch class (listed by model number)
+	vector<double> rootbasefreqs;     // base frequencies of model defined at root of branch class tree.
+	double insertrate;                // insertion rate at root?
+	double deleterate;                // deletion rate at root?
+	int rootmodelpos;                 // position of root model in totalmodels.
+
+	bool geneticcodefixed;			  // whether to allow geneticcode to change on trees.
+	int geneticcode;                  // genetic code used (for codon simulations) must be the same across entire tree
+	int error;                        // whether branch class successfully set itself up without errors.
+
+	int numcats;					  // number of categories in discrete gamma model or in site/branch-site models
+	                                  //    must be the same across the whole tree.
+
+	bool changecats;				  // says whether to rescale root cats and therefore check all for change.
+	
+	vector<double> catprops;          // relative proportion of categories (must be same in different models).
+
+	branchclass(string &ttree, string &myname, vector<string> &totalmodelnames, bool iscodefixed)
+	{
+		// constructor
+		geneticcodefixed=iscodefixed;
+
+		error=1;
+		treewithrootmodel=ttree;
+		for(int fd=0; fd<treewithrootmodel.size(); fd++) {char c=treewithrootmodel[fd]; if(c=='(' || c==')' || c==',' || c==';') baretree+=c;}
+		name=myname;
+		
+		if(error!=-1) error=getrootfreqs(treewithrootmodel);
+		if(error!=-1) error=buildbranches(tree,myname,modelnames);
+			
+		if(error!=-1) error=getbranchmodels(modelnames,totalmodelnames,modelpositions); //branchmodels);
+
+		if(error!=-1 /*&& geneticcodefixed*/) error=testgeneticcode2(modelpositions);
+
+	}
+
+private:
+
+
+	int getrootfreqs(string &testtree2)
+	{
+		// this function takes the original tree with root model and strips off the defined model at root.
+		// it then checks that that model exists, and collects information about the model.
+			
+		int testtreesize=testtree2.size()-1;
+		string testtree, rootmodel;
+		int pospos;
+
+		for(int pp=testtreesize; pp>0; pp--) if(testtree2[pp]==')') {pospos=pp; break;}
+
+		for(int pp2=0; pp2<testtreesize; pp2++) 
+		{
+			char c1=testtree2[pp2];
+			if(pp2>pospos) 
+			{
+				if(pp2!=pospos+1) rootmodel+=c1; 
+			}
+			else testtree+=c1;
+		}
+ 		testtree+=';';
+
+		if(rootmodel=="") {controlerrorprint2("[BRANCHES]", name ,"","You haven't named a model for the root of this branch class.\nThe branch class tree should be of the form: (...)#m;\nwhere #m represents the (previously defined) root model m.",""	); return -1;} 
+		else
+		{
+			int ans=checkthere(rootmodel,totalmodelnames);
+
+			if(ans==-1) {controlerrorprint2("[BRANCHES]", name ,"","The model "+rootmodel+" in this branches block has not been defined",""	); return -1; }
+			else 
+			{
+				modelpositions.push_back(ans);
+				model* n=&(totalmodels.at(ans));
+
+			//	if(type==3) 
+			//	{
+					catprops=(*n).cumfreqs;
+					numcats=catprops.size();
+					if(numcats==1) changecats=true; else changecats=false;
+			//	}
+				
+				insertrate=(*n).insertrate;
+				deleterate=(*n).deleterate;
+				rootbasefreqs=(*n).rootbasefreqs;
+				rootmodelpos=(*n).modelpos;
+
+			}
+		}
+
+		tree=testtree;
+
+		return 0;
+	}	
+
+///////////////////////////
+
+	int testgeneticcode(vector<int> modelpositions)
+	{
+		// this function simply tests that the genetic code defined in each model on each
+		// branch in the guide tree is the same and throws an error if they are not.
+
+		model* amodel=&(totalmodels.at(modelpositions.at(0)));
+		int mygeneticcode=(*amodel).geneticcode;
+		int lastgeneticcode;
+		string n2;
+
+		string n1=totalmodelnames.at(modelpositions.at(0));
+
+		geneticcode=mygeneticcode;
+		for(int ds=1; ds<modelpositions.size(); ds++)
+		{
+			lastgeneticcode=mygeneticcode;
+			n2=n1;
+
+			amodel=&(totalmodels.at(modelpositions.at(ds)));
+			mygeneticcode=(*amodel).geneticcode;
+
+			string n2=totalmodelnames.at(modelpositions.at(ds));
+
+			stringstream dd1; dd1<<lastgeneticcode;   string d1=dd1.str();
+			stringstream dd2; dd2<<mygeneticcode;     string d2=dd2.str();
+			
+			if(mygeneticcode!=lastgeneticcode) {controlerrorprint2("[BRANCHES]", name ,"","All models in a branches block should use the same genetic code.\nmodel "+n1+" has genetic code "+d1+"\nmodel "+n2+" has genetic code "+d2+"\nIf you want to allow the genetic code to change then use the command\n[BRANCHES*] instead of [BRANCHES] to turn off this safeguard.",""	); {if(breakonerror) return -1;} } 
+		}
+
+		return 0;
+	}
+///////////////////////////
+	
+	int testgeneticcode2(vector<int> modelpositions)
+	{
+		// this function simply tests that the genetic code defined in each model on each
+		// branch in the guide tree is the same and throws an error if they are not.
+
+		model* amodel=&(totalmodels.at(modelpositions.at(0)));
+		int rootgeneticcode=(*amodel).geneticcode;
+		vector<int> myallowedlist=allowedcodes(rootgeneticcode);
+		int lastgeneticcode;
+		
+		stringstream dd2; dd2<<rootgeneticcode;     string d2=dd2.str();
+			
+		string n1=totalmodelnames.at(modelpositions.at(0)), n2;
+
+		geneticcode=rootgeneticcode;
+		for(int ds=1; ds<modelpositions.size(); ds++)
+		{
+			amodel=&(totalmodels.at(modelpositions.at(ds)));
+			lastgeneticcode=(*amodel).geneticcode;
+
+			string n2=totalmodelnames.at(modelpositions.at(ds));
+
+			stringstream dd1; dd1<<lastgeneticcode;   string d1=dd1.str();
+
+			bool codeerror=true;
+			for(int qwe=0; qwe<myallowedlist.size(); qwe++)
+			{
+				if(lastgeneticcode==myallowedlist.at(qwe)) {codeerror=false; break;}
+			}
+			if(codeerror) {controlerrorprint2("[BRANCHES]", name ,"","All models in a branches block should use genetic codes that share \nthe same stop codons.\nmodel "+n1+" has genetic code "+d1+"\nmodel "+n2+" has genetic code "+d2+"\nThese codes do not share all stop codons and so cannot be combined. ",""	); {if(breakonerror) return -1;} } 	
+		}
+
+		return 0;
+	}
+///////////////////////////
+	int getbranchmodels(vector<string> &modelnames,vector<string> &totalmodelnames, vector<int> &modelpositions) //vector<model> &branchmodels)
+	{	
+		// this function tests all the models found by buildbranches function. if the models do not exist, or if they
+		// have the wrong number of categories, or the categories have different proportions then an error is thrown.
+
+		for(int hgg=0; hgg<modelnames.size(); hgg++)
+		{
+			string thisname=modelnames.at(hgg);
+
+			int found=checkthere(thisname,totalmodelnames);
+			if(found==-1) {controlerrorprint2("[BRANCHES]", name ,"","The model "+thisname+" in this branches block has not been defined",""	); return -1;}
+			else 
+			{
+	//			if(type==3) 
+	//			{
+					model *k=&(totalmodels.at(found));
+			
+					int x=((*k).cumfreqs).size();
+				
+					if( numcats!=1 && x==1 && type!=3)
+					{
+						if(numcats!=0)
+						{
+							totalmodels.push_back(totalmodels.at(found));
+						
+							model *k2=&(totalmodels.back());
+
+							totalmodelnames.push_back(  ((*k2).name)+"_with_all_classes_equal"  );
+					
+							//for(int pq=0; pq<((*k2).cumfreqs).size(); pq++) cout<<"1 "<<pq<<" "<<((*k2).cumfreqs).at(pq)<<endl;
+							(*k2).cumfreqs=(totalmodels.at(rootmodelpos)).cumfreqs;
+							//for(int pq=0; pq<((*k2).cumfreqs).size(); pq++) cout<<"2 "<<pq<<" "<<((*k2).cumfreqs).at(pq)<<endl;
+
+							(*k2).changeQandJ(numcats);
+
+							modelnames.at(hgg)=(*k2).name;
+
+							found=totalmodels.size()-1;
+						}
+					}
+					else
+					{
+				
+
+						if( numcats!=x )  
+						{
+
+							stringstream s1,s2; s1<<x; s2<<numcats; string ss1=s1.str(), ss2=s2.str(); 
+							string nn1=totalmodelnames.at(found); string nn2=totalmodelnames.at(rootmodelpos);
+							controlerrorprint2("[BRANCHES]", name ,"","Number of site/rate classes in model "+nn1+" is "+ss1+"\nNumber of site/rate classes in root model "+nn2+" is "+ss2+"\nThese should be equal.",""); 
+								
+							return -1;
+						}
+
+
+						
+						for(int op=0; op<numcats; op++) 
+						{
+							// cout<<"\t"<<catprops.at(op)<<"\t"<<((*k).cumfreqs).at(op)<<endl;
+
+							if( catprops.at(op)!=((*k).cumfreqs).at(op) )  
+							{
+								stringstream s1,s2,s3; s1<<((*k).cumfreqs).at(op); s2<<catprops.at(op); s3<<op+1; 
+								string ss1=s1.str(), ss2=s2.str(), op2=s3.str(); 
+								string nn1=totalmodelnames.at(found); string nn2=totalmodelnames.at(rootmodelpos);
+								controlerrorprint2("[BRANCHES]", name ,"","Site/rate class "+op2+" in model "+nn1+" has proportion "+ss1+"\nSite/rate class "+op2+" in root model "+nn2+" has proportion "+ss2+"\nThese should be equal.",""); 
+									
+								return -1;
+							}
+
+						}
+
+					}
+			//	}
+				
+				modelpositions.push_back(found);
+				int minicheck=checkthereN(found,allmodelsused);
+				if(minicheck==-1) allmodelsused.push_back(found);
+			
+			}
+			
+			//cout<<"model found "<<thisname<<" "<<found<<endl;
+		}
+
+		return 0;
+
+	}
+	///////////////
+
+		int buildbranches(string &testtree, string &branchesname, vector<string> &modelnames)
+		{
+			// this function navigates the branch class guide tree defined in the control file
+			// and extracts model names subject to further testing, whether they exist and so on...
+
+
+			char c1='Q';			
+
+			int bracketcount=0;
+			bool istherehash=false;
+			for(int i=0; i<testtree.size(); i++)
+			{
+				c1=testtree[i];
+
+				if(c1=='#') istherehash=true;
+				if(c1=='(') bracketcount++;
+				if(c1==')') bracketcount--;
+			}
+			if(bracketcount!=0) {controlerrorprint2("[BRANCHES]", name ,"","Number of parentheses in tree for this branch class do not match",""); return -1;}
+
+			//cout<<"Number of parentheses in tree for branch class "<<branchesname<<" do not match"<<endl;
+			//if(c1!=';') cout<<"Tree for branch class "<<branchesname<<" must be in newick format and end in a ;"<<endl;
+			
+			if(testtree.size()>0 && testtree[testtree.size()-1]==';')
+			{
+				bracketcount=1;
+				string rfstring="";
+				
+
+				for(int rf=1; rf<testtree.size(); rf++)
+				{
+					c1=testtree[rf];
+					if(c1=='(') bracketcount++;
+					if(c1==')') bracketcount--;
+			//		if(bracketcount==0 ||(bracketcount==1 && (c1==','||c1==')')) )
+					if((bracketcount==1 && c1==',') || bracketcount==0) 
+					{
+						buildbranches(rfstring,branchesname,modelnames);
+						rfstring="";
+					}
+					else if(c1!=' ') rfstring+=c1;
+
+				}
+			}
+			else if(istherehash)
+			{
+				bracketcount=1;
+				string teststring, modelnamestring;
+				vector<string>remaining;
+
+				bool modelnamewrite=false;
+
+				if(testtree[0]!='(') 
+				{
+					for(int i1=0; i1<testtree.size(); i1++)
+					{
+						///////////////////////////////////////////////////////////////////
+						c1=testtree[i1]; 
+						
+						//if(modelnamewrite) cout<<"Q"<<c1<<"Q ";
+						//if((c1==','||c1==')') && modelnamewrite) {modelnames.push_back(modelnamestring); break;}
+						//if(c1=='#' && modelnamewrite) {modelnames.push_back(modelnamestring); break;}
+			
+						if(modelnamewrite) {modelnamestring+=c1;}		// cout<<"X "<<modelnamestring<<endl;}
+						if(c1=='#' && !modelnamewrite) modelnamewrite=true;
+					}
+					modelnames.push_back(modelnamestring); 
+	
+				}
+				else
+				{
+					for(int i=1; i<testtree.size(); i++)
+					{
+						c1=testtree[i];
+
+						if(c1=='(') bracketcount++;
+						if(c1==')') bracketcount--;
+
+				//		if(bracketcount==0 ||(bracketcount==1 && (c1==','||c1==')')) )			
+						if((bracketcount==1 && c1==',') || bracketcount==0) 
+						{
+							//	cout<<"AA "<<teststring<<endl;
+							remaining.push_back(teststring);
+							teststring="";
+							if(bracketcount==0) bracketcount=-99;
+						}
+						else if(bracketcount==-99)
+						{
+								//if((c1==','||c1==')') && modelnamewrite) { modelnames.push_back(modelnamestring); break;}
+								//if(c1=='#' && modelnamewrite) {modelnames.push_back(modelnamestring); break;}
+								
+								//if(modelnamewrite) cout<<"Q2"<<c1<<"Q ";
+
+							if(modelnamewrite) {modelnamestring+=c1; }		//cout<<"X2 "<<modelnamestring<<endl;}
+							if(c1=='#' && !modelnamewrite) modelnamewrite=true;
+						}
+						else teststring+=c1;
+					}
+					modelnames.push_back(modelnamestring);
+				}
+				for(int kd=0; kd<remaining.size(); kd++) buildbranches(remaining.at(kd),branchesname,modelnames);
+					
+				
+
+			}
+
+			return 0;
+		}	
+};
+///////////////////////////////////////////////////////////
+
+vector<branchclass> totalbranches;			// storage for branch classes
+
+
+
+
+class siteclass
+{
+	// site class is now disabled.  It allows the use of different models in different proportions along a sequence.
+
+public:
+
+	vector<int> allmodelsused;
+	vector<bool>   trueformodel;  //true for model, false for branch class, in mbnames, mbpositions
+	vector<int>    mbpositions;
+	vector<string> mbnames;
+	vector<double> props;  // cumulative props remember!
+	vector<vector<double> > trootbasefreqs;
+
+	int geneticcode;
+	int error;
+	string mbtree;
+	string name;
+
+	bool therearemodels;
+	bool therearebranches;
+	
+//	siteclasscopy(site copysite)
+//	{
+//		//??????
+//	}
+
+//	createsiteprops()
+//	{
+//		//????
+//	}
+	
+	siteclass(string sitename, vector<string> &mynames, vector<double> &myprops, vector<string> &totalmodelnames, vector<string> &totalbranchnames)
+	{
+		error=1;
+		therearemodels=false;
+		therearebranches=false;
+		vector<string> mbtrees;
+
+		name=sitename;
+		props=myprops;
+		mbnames=mynames;
+	
+		if(error!=-1) error=sortoutnames(mbtrees,totalmodelnames,totalbranchnames);
+		if(error!=-1) error=sortouttrees(mbtrees);
+		if(error!=-1) error=testgeneticcode();
+
+	}
+
+
+///////////////////////////////////
+private:
+
+	
+	int testgeneticcode()
+	{
+		int lastgeneticcode;
+		string modelorbranch1="model";
+		string modelorbranch2="model";
+		string n1,n2;
+
+		model* amodel;
+
+		branchclass* abranchclass;
+
+		if(trueformodel.at(0))
+		{	
+			amodel=&(totalmodels.at(mbpositions.at(0)));
+			geneticcode=(*amodel).geneticcode;
+		}
+		else
+		{	
+			abranchclass=&(totalbranches.at(mbpositions.at(0)));
+			geneticcode=(*abranchclass).geneticcode;
+			
+			modelorbranch1="branch class";
+			modelorbranch2="branch class";
+		}
+
+
+		for(int ds=0; ds<mbpositions.size(); ds++)
+		{
+			lastgeneticcode=geneticcode;
+			n2=n1;
+			int pos=mbpositions.at(ds);
+			modelorbranch2=modelorbranch1;
+			if(trueformodel.at(ds)) 
+			{
+				modelorbranch1="model"; 
+				n1=totalmodelnames.at(pos);
+				amodel=&(totalmodels.at(pos));
+				geneticcode=(*amodel).geneticcode;
+			}
+			else 
+			{
+				modelorbranch1="branch class"; 
+				n1=totalbranchesnames.at(pos);
+				abranchclass=&(totalbranches.at(pos));
+				geneticcode=(*abranchclass).geneticcode;
+			}
+
+			
+			
+			stringstream dd1; dd1<<lastgeneticcode; string d1=dd1.str();
+			stringstream dd2; dd2<<geneticcode;     string d2=dd2.str();
+		
+			if(geneticcode!=lastgeneticcode) {controlerrorprint2("[SITES]", name ,"","All models/branches in a sites block should use the same genetic code.\n"+modelorbranch1+" "+n1+" has genetic code "+d1+"\n"+modelorbranch2+" "+n2+" has genetic code "+d2,""	); {if(breakonerror) return -1;} } 
+			
+		}
+		return 0;
+	}
+
+	int sortoutnames(vector<string> &mbtrees, vector<string> &totalmodelnames, vector<string> &totalbranchnames)
+	{
+		for(int gh=0; gh<mbnames.size(); gh++)
+		{
+			bool modelorbranch=true;
+			string mbname=mbnames.at(gh);
+			string tree,stree;
+
+			int ans=checkthere(mbname,totalmodelnames);
+			
+			//cout<<"ans "<<ans<<endl;
+			if(ans==-1) 
+			{
+				ans=checkthere(mbname,totalbranchnames); 
+
+				
+			//	cout<<"\tans "<<ans<<endl;
+				modelorbranch=false;
+				
+				if(ans==-1) {controlerrorprint2("[SITES]", name, "", "You specified \""+mbname+"\" in this sites class.\nNo model/branch class with this name has been defined yet.",""); {if(breakonerror) return -1;} }
+				else 
+				{
+					branchclass* b=&(totalbranches.at(ans));
+					
+					trootbasefreqs.push_back( (*b).rootbasefreqs );
+		
+					tree=(*b).tree; 
+					therearebranches=true;
+					
+					vector<int> modpos=((*b).allmodelsused);
+					for(int o1=0; o1<modpos.size(); o1++)
+					{
+						int y=modpos.at(o1);
+						int minicheck=checkthereN(y,allmodelsused);
+						if(minicheck==-1) allmodelsused.push_back(y);	
+					}
+
+					
+
+				}
+
+				for(int yf=0; yf<tree.size(); yf++) {char c=tree[yf]; if(c=='(' || c==')' || c==',' || c==';') stree+=c;}
+
+				if(mbtree=="") mbtree=stree;
+
+			}
+			else 
+			{
+				therearemodels=true;
+				int minicheck=checkthereN(ans,allmodelsused);
+				if(minicheck==-1) allmodelsused.push_back(ans);
+				model* m=&(totalmodels.at(ans));
+				trootbasefreqs.push_back( (*m).rootbasefreqs );
+			}
+
+			trueformodel.push_back(modelorbranch);
+			mbpositions.push_back(ans);
+			
+			mbtrees.push_back(stree);
+		}
+
+		return 0;
+	}
+	/////////////////
+	int sortouttrees(vector<string> &mbtrees)
+	{
+
+		int lastpos=-1;
+		for(int fc=0; fc<mbtrees.size(); fc++)
+		{
+			string testtree=mbtrees.at(fc);
+
+			if(testtree!="")
+			{
+				if(lastpos==-1) lastpos=fc;
+				else if(mbtree!=testtree)
+				{
+					string s1=mbnames.at(lastpos), s2=mbnames.at(fc), t1=mbtree, t2=testtree, u1;
+					int s1s=s1.size(), s2s=s2.size();
+						
+					if(s1s>s2s) {for(int fv=0; fv<s1s-s2s; fv++) s2+=" ";} 
+					else        {for(int fv=0; fv<s2s-s1s; fv++) s1+=" ";}
+
+					controlerrorprint2("[SITES]", name, "", "Two branch classes in this site class have different guide trees.\n1) "+s1+"  "+t1+"\n2) "+s2+"  "+t2+"\nTrees must have their taxa/branches written in identical order.",""); 
+					{if(breakonerror) return -1;} 
+				}
+			}
+		}
+		return 0;
+	}
+	////////
+};
+///////////////////////////////////////////////////////////
+vector<siteclass>	totalsites;	// storage for site classes
+
+
+
+///////////////
+int teststring(int lastresult,  string com, vector<string> &allowed, string blocktype, string allowedstring, string blockname)
+{
+	// test function used by many other functions for testing "chunks" in the control file until they are processed.
+
+	// returns -1 if com not a statement beginning with [
+	// reurns x if com is the xth command in allowed
+	// returns x if currently on command x and input is not a new command or non-decimal number.
+	// returns -2 if com begins with [ but is not in allowed
+	// returns -2 if com contains characters not in allowedstring.
+	int myresult=-1;
+	
+	if(com[0]=='[') 
+	{	
+		for(int k=0; k<allowed.size(); k++) if(com==allowed.at(k)) {myresult=k; break;}
+
+		if(myresult==-1) 
+		{
+			controlerrorprint2(blocktype, blockname,"" ,"Unknown command.",com); 
+		
+			myresult=-2;
+		}
+	}
+	else
+	{
+		if(!AonlyfromB(com,allowedstring)) 
+		{
+			
+			//	cout<<com<<"  "<<allowedstring<<endl;
+	//		if(allowedstring!="0123456789.") myresult=lastresult;
+			
+			myresult=-2; 
+
+			string ds; if(lastresult!=-999) ds=allowed.at(lastresult);
+			
+//			cout<<blocktype<<" "<<com<<" teststring func 1"<<endl;
+			if(blocktype=="[TREE]" && ds=="[user]") myresult=lastresult;
+			else 
+			{
+				ifstream gf1; gf1.open(com.c_str()); 
+				if(gf1.good()) myresult=lastresult;	   // i.e. if it is a filename and the file exists and can be opened.
+					else controlerrorprint2(blocktype, blockname,ds ,"Input value must be a positive decimal number or a command [..]\nIf this was meant to be a filename no such file exists.",com);
+			}
+
+		} else myresult=lastresult;
+	}
+//	cout<<"myresult "<<myresult<<endl;
+	return myresult;
+}
+////////////////////////////////////////////////////////////////////////////////////
+
+int dealwithsettings(vector<string> &block)	
+{
+	// this function deals with [SETTINGS] blocks in the control file.
+
+	//for(int i=0; i<block.size(); i++) cout<<"settings "<<block.at(i)<<endl;
+	
+	int size=block.size();
+
+	if(size==0) {controlerrorprint2("[SETTINGS]","","","The settings block seems to be empty.",""); {if(breakonerror) return -1;} }
+
+	if(size%2!=0) {controlerrorprint2("[SETTINGS]","","","The settings block must contain an even number of statements:\n[COMMAND1] value1\n[COMMAND2] value2\nand so on....",""); {if(breakonerror) return -1;} }
+
+	string s1,s2;
+	string scommands[15]={"[printindelstatistics]","[ancestralprint]","[phylipextension]","[nexusextension]","[fastaextension]","[output]","[randomseed]","[printrates]","[insertaslowercase]","[printcodonsasaminoacids]","[fileperrep]","[markdeletedinsertions]","[fixproportions]","[printallrates]","[globalseed]"};
+	vector<string> commands(scommands,scommands+15); 
+
+	int idum2;
+	int commanderror;
+	
+	for(int j=1; j<size; j=j+2)
+	{
+		s1=block.at(j-1);		
+		s2=block.at(j);
+		if(!allAinB(s2,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SETTINGS]", "", "", "Values after commands should only contain ,.;()-_ \nand alpha-numeric characters.",""); {if(breakonerror) return -1;} }
+
+		commanderror=-1;
+		
+		if(s1[0]!='[' || s1[s1.size()-1]!=']') {controlerrorprint2("[SETTINGS]","","","Was expecting a command in square brackets e.g. [COMMAND]\nbut found: "+s1,""); {if(breakonerror) return -1;} }
+		else commanderror=checkthere(s1,commands);
+
+		if(commanderror==-1) {controlerrorprint2("[SETTINGS]","","","The command "+s1+" is not valid in a setting block.\nPlease consult manual or example control file.",""); {if(breakonerror) return -1;} }
+		
+		else if(commanderror==0)
+		{
+			//printindelstatistics
+			//myinclude.at(25)=true;
+
+			if(s2=="TRUE") printinsert=true; else if(s2=="FALSE") printinsert=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==1)
+		{
+			//ancestralprint
+			//myinclude.at(26)=true;
+
+			     if(s2=="SAME") {ancestralprint=true; ancestralfile=false;} 
+			else if(s2=="NEW")  {ancestralprint=true; ancestralfile=true;} 
+			else if(s2=="FALSE") ancestralprint=false; 
+			else {controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be SAME, NEW or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==2) phylipextension=s2;			
+		
+		else if(commanderror==3) nexusextension=s2;			
+		
+		else if(commanderror==4) fastaextension=s2;			
+
+		else if(commanderror==5)
+		{
+			//output
+			//myinclude.at(22)=true;
+			
+			     if(s2=="FASTA"   ) {outputtype=1; phylipnametruncate=false;}
+  		    else if(s2=="PHYLIP"  ) {outputtype=2; phylipnametruncate=false;}
+			else if(s2=="PHYLIPT" ) {outputtype=2; phylipnametruncate=true; }
+			else if(s2=="NEXUS"   ) {outputtype=3; phylipnametruncate=false;}
+			else {controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be FASTA, PHYLIP, PHYLIPT or NEXUS for this command.",""); {if(breakonerror) return -1;} }					
+		}
+		else if(commanderror==6)
+		{
+			//randomseed
+
+			if(!allAinB(s2,"1234567890-")) { controlerrorprint2("[SETTINGS]", "",scommands[commanderror], "This value must be an integer.",""); {if(breakonerror) return -1;} }
+
+			idum=atoi(s2.c_str()); if(idum<0) idum=-idum; 	mtrand1.seed(idum);	
+		}
+		else if(commanderror==7)
+		{
+			//printindelstatistics
+			//myinclude.at(25)=true;
+
+			if(s2=="TRUE") printrates=true; else if(s2=="FALSE") printrates=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==8)
+		{
+
+			if(s2=="TRUE") insertaslowercase=true; else if(s2=="FALSE") insertaslowercase=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==9)
+		{
+			// command is "[printcodonsasaminoacids]"
+			if(s2=="TRUE") printcodonsasDNA=false; else if(s2=="FALSE") printcodonsasDNA=true; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==10)
+		{
+			// command is "[fileperrep]"
+			if(s2=="TRUE") fileperrep=true; else if(s2=="FALSE") fileperrep=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==11)
+		{
+			// command is "[markdeletedinsertions]"
+			if(s2=="TRUE") markdeletedinsertions=true; else if(s2=="FALSE") markdeletedinsertions=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==12)
+		{
+			// command is "[fixproportions]"
+			if(s2=="TRUE") fixtrueproportions=true; else if(s2=="FALSE") fixtrueproportions=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==13)
+		{
+			//printallrates
+
+
+			if(s2=="TRUE") printallrates=true; else if(s2=="FALSE") printallrates=false; else
+			{controlerrorprint2("[SETTINGS]","",scommands[commanderror],"Value must be TRUE or FALSE for this command.",""); {if(breakonerror) return -1;} }
+		}
+		else if(commanderror==14)
+		{
+			//randomseed
+
+			globalseed=true;
+			if(!allAinB(s2,"1234567890-")) { controlerrorprint2("[SETTINGS]", "",scommands[commanderror], "This value must be an integer.",""); {if(breakonerror) return -1;} }
+
+			idum2=atoi(s2.c_str()); if(idum2<0) idum2=-idum2; 	
+		}
+
+	}
+
+	if(globalseed) {idum=idum2; mtrand1.seed(idum);	}
+
+	return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////////
+
+
+int dealwithmodel(vector<string> &block)		
+{
+	// this is a big function that deals with setting up of substitution and indel models.  What is not tested or pre-processed here is passed to the model class constructor.
+	
+	vector<double> insertrates, deleterates;
+	if(!oldmethod) {insertrates.push_back(0); deleterates.push_back(0);}
+	else 
+	{
+		int tempsize; 
+		if(type==1) tempsize=4; else if(type==2) tempsize=20; else if(type==3) tempsize=64; else cout<<"tempsize and type error in dealwithmodel"<<endl;
+		for(int jp=0; jp<tempsize; jp++) {insertrates.push_back(0); deleterates.push_back(0);}
+	}
+ 
+	vector<double> aamodel;
+	string name="DEFAULT";
+	int modelnumber=0;
+	int geneticcode=1;
+	bool copiedmodel=false;
+	double insertrate=0;
+	double deleterate=0;
+	indelmodel insertmodel=indelmodel();
+	indelmodel deletemodel=indelmodel();
+	double alpha=0;
+	double pinv=0;
+	int ngamcat=5;
+	double codonrates[3]; codonrates[0]=codonrates[1]=codonrates[2]=1;
+	vector<double> basefreqs, rootbasefreqs, insertfreqs, params;
+
+	string commandsarray[143]={"[insertmodel]","[deletemodel]","[indelmodel]","[insertrate]","[deleterate]","[indelrate]",
+		"[geneticcode]", "[submodel]","[rates]","[Crates]","[statefreq]","[istatefreq]","[rootstatefreq]","[XXXrootseq]",
+		"[testindeldistributions]"};  // acceptable list of commands
+	
+	// what about tree creation etc?
+
+	vector<string> commands(commandsarray,commandsarray+13);
+	string mymodelname;
+			
+//	for(int i=0; i<block.size(); i++) cout<<"model "<<block.at(i)<<endl;
+
+
+	string hg=block.at(0), hg1;
+//	if(hg[0]!='#' || hg[hg.size()-1]!='#') { controlerrorprint2("[MODEL]", "?", "", "First statement in a [MODEL] block must be a model name statement in the form #modelname#",""); {if(breakonerror) return -1;} }
+	if(!allAinB(hg,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[MODEL]", hg, "", "First statement in a [MODEL] block must be a model name statement.\nThe name should only contain  ,.;()-_ and alpha-numeric characters.",hg); {if(breakonerror) return -1;} }
+	else 
+	{
+		for(int i0=0; i0<hg.size(); i0++) if(hg[i0]!=' ') mymodelname+=hg[i0];
+	//	cout<<"MODEL NAME "<<mymodelname<<endl;
+
+		if(checkthere(mymodelname,totalmodelnames)!=-1)
+		{ controlerrorprint2("[MODEL]", mymodelname, "", "A model with this name has been specified twice.",""); {if(breakonerror) return -1;} }
+		else {
+				totalmodelnames.push_back(mymodelname); 
+				name=mymodelname; 
+			}
+	
+		vector<string> tempvec;
+		int blocksize=block.size()-1;
+		
+		//bool waitforcommand=false;
+		
+		hg="";
+		int lasttest=-999;
+		int mytest=-999;
+		int astart=1;
+		if(blocksize+1>astart) hg=block.at(astart);
+		if(hg[0]=='#')
+		{ 
+			// this if bracket is concerned with automatically copying from model to model.
+			// feature will be disabled in final program - so has not been checked after Dec 2008
+
+			mymodelname="";
+			for(int i0=1; i0<hg.size(); i0++) if(hg[i0]!=' ') mymodelname+=hg[i0];
+		//	cout<<"MODEL NAME 2"<<mymodelname<<endl;
+	
+			if(mymodelname==name) {controlerrorprint2("[MODEL]", mymodelname, "", "You cannot copy a model within it's own definition statement!\nThe second model name should be different from "+mymodelname,""); {if(breakonerror) return -1;} }
+	
+			int ans=checkthere(mymodelname,totalmodelnames);
+			if(ans==-1) {controlerrorprint2("[MODEL]", name, "", "Cannot copy model "+mymodelname+".\nNo model with this name has been defined yet.",""); {if(breakonerror) return -1;} }
+			else
+			{
+				model* m=&(totalmodels.at(ans));
+
+				modelnumber=(*m).modelnumber;
+				geneticcode=(*m).geneticcode;
+				copiedmodel=true;
+				insertrate=(*m).insertrate;
+				deleterate=(*m).deleterate;
+				
+				//insertrates=(*m).insertrates;
+				//deleterates=(*m).deleterates;
+
+				//inlength=(*m).inlength;
+				//dellength=(*m).dellength;
+				//rootlength=(*m).rootlength;
+				alpha=(*m).alpha;
+				pinv=(*m).pinv;
+				ngamcat=(*m).ngamcat;
+				codonrates[0]=(*m).codonrates[0];
+				codonrates[1]=(*m).codonrates[1];
+				codonrates[2]=(*m).codonrates[2];
+
+				//	vector<double> params;  // ??
+
+				rootbasefreqs=(*m).rootbasefreqs;
+				basefreqs=(*m).basefreqs;
+				insertfreqs=(*m).insertfreqs;
+				astart++;
+				//	vector<double> ratevec; // ??
+			}
+
+		}
+
+		string oldhg="Z";
+		for(int i1=astart; i1<blocksize+1; i1++) 
+		{
+			hg=block.at(i1); 
+			lasttest=mytest;
+			string myallowed="0123456789.";
+			
+			if(oldhg=="[insertmodel]" || oldhg=="[deletemodel]" || oldhg=="[indelmodel]"  ) myallowed="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."; //"NBUSEROLDPOWCUMDAWGLAV";
+
+			mytest=teststring(lasttest, hg, commands, "[MODEL]",myallowed,mymodelname);
+			
+			oldhg=hg;
+
+			if(mytest==-2) {if(breakonerror) return -1;} 
+			else 
+			{//a1
+			 //			cout<<"H2 "<<hg<<" "<<mytest<<" "<<lasttest<<"  "<<blocksize<<"  "<<astart<<endl;
+				
+			if(i1==blocksize )  {tempvec.push_back(hg); }//cout<<"H1 "<<hg<<endl;}
+				
+			if(mytest==lasttest && i1!=blocksize )  {tempvec.push_back(hg); }// cout<<"H1 "<<hg<<endl;}
+				else if(i1!=astart)
+				{//a2
+
+					if(tempvec.size()==0) 
+					{
+						controlerrorprint2("[MODEL]", name, commands.at(lasttest), "No values were found after this command in the control file.","");
+						{if(breakonerror) return -1;} 
+					}
+					else if(lasttest>-1 && lasttest<3)
+					{
+						// indel models
+		
+						// lasttest = 0  for insertion length model
+						//            1  for deletion  length model
+						//            2 for same length model for both insertions and deletions
+
+						bool noindelerror=true;
+						string myin=tempvec.at(0);
+						int tempsize=tempvec.size();
+
+						int myindelmodelint;
+						double mr, mM;
+						double mq, ma, mb;
+
+						double entryd=0, totald=0, meand=0;
+						int thecount=0;
+						
+						vector<double> usermodel;
+	
+						// 0 USER
+						// 1 NB
+						// 2 POW
+						// 3 LAV
+
+						// 11 NBOLD - NB calculated using p GEO
+						// 12 POWCUM - power law calculated using cumulative method used for USER and LAV
+						// 13 POWDAWG - power law calculated using zipf function from DAWG
+
+						// User Model
+						if(myin=="USER") 
+						{
+							myindelmodelint=0;
+
+							if(tempsize!=2) noindelerror=false;
+														
+							if(noindelerror)
+							{
+								myin=tempvec.at(1); 
+
+								ifstream if1; if1.open(myin.c_str());
+								
+								double countcount=0;
+								if(!(if1.good()))
+								{
+									controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Could not find a file named:\n"+myin,"");
+									mytest=-2; {if(breakonerror) return -1;}
+								}
+								char c=if1.get();
+								string s;
+
+								bool writeon=false;
+								while(if1.good())
+								{ 
+									if(!AinB(c,"0123456789. \n\t\r")) 
+									{
+										string y; y+=c;
+										controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Illegal character "+y+" found in file named:\n"+myin+"\nAllowed characters are 0.123456789\nSpaces, horizontal tabs, and new lines are also allowed","");
+										mytest=-2; {if(breakonerror) return -1;}
+									}
+									if(AinB(c,"0123456789.")) writeon=true; 
+
+									if(writeon && !AinB(c,"0123456789.")) 
+									{
+										countcount++; 
+										writeon=false; 
+										entryd=atof(s.c_str());
+										meand+=(countcount*entryd); 
+										totald+=entryd; 
+										usermodel.push_back(totald); 
+										s=""; 
+									}
+
+									if(writeon) s+=c;
+
+									c=if1.get();
+								}
+
+
+
+								if(s!="") 
+								{
+									countcount++; 
+									entryd=atof(s.c_str()); 
+									meand+=(countcount*entryd); 
+									totald+=entryd; 
+									usermodel.push_back(totald); 
+								}
+								
+								if(usermodel.empty()) 							
+								{
+									controlerrorprint2("[MODEL]", name, commands.at(lasttest), "The user-defined indel length model must contain at least one value.!","");
+									mytest=-2; {if(breakonerror) return -1;}
+								}
+
+								double diff=totald-1;
+								if(diff<0) diff=-diff;
+								if(diff>0.00001) 
+								{
+									stringstream df; df<<totald; string ff=df.str();
+									controlerrorprint2("[MODEL]", name, commands.at(lasttest), "User-defined indel model does not sum to 1 and so has been rescaled.\n(It summed to "+ff+") ","");
+
+									for(int i=0; i<usermodel.size(); i++) {(usermodel.at(i))/=totald; }
+								}
+	
+								meand/=totald;
+							}
+
+						} // end of User Model
+
+						// Negative Binomial Distribution
+						else if(myin=="NB" || myin=="NBOLD") 
+						{
+							if(myin=="NB")	myindelmodelint=1;	// used in program
+							else			myindelmodelint=11;	// alternative parameterisation for testing
+										
+							if(tempsize!=3) noindelerror=false;
+														
+							if(noindelerror)
+							{
+								myin=tempvec.at(1); 
+								if(!allAinB(myin,"0123456789.")) noindelerror=false;
+								else mq=atof(myin.c_str());
+								if(mq<0 || mq>1) noindelerror=false;
+							}
+								
+							if(noindelerror)
+							{
+								myin=tempvec.at(2); 
+								if(!allAinB(myin,"0123456789")) noindelerror=false;
+								else mr=atoi(myin.c_str());
+								if(mr==0) noindelerror=false;
+							}
+
+							if(!noindelerror) 							
+							{	
+								controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Expecting 2 values after \"NB\" when using Negative Binomial Model.\nThe first should be a proportion 0 <= q <= 1.\nThe second should be an integer r > 0.","");
+								mytest=-2; {if(breakonerror) return -1;} 
+							}
+
+							meand =  1.0+mr*mq/(1.0-mq);
+
+						} // end of Negative Binomial Distribution
+
+
+						// Zipfian Distribution (Power Law)
+						else if(myin=="POW" || myin=="POWDAWG" || myin=="POWCUM") 
+						{
+							if(myin=="POW")     myindelmodelint=2;  // Fast Zipf
+
+							if(myin=="POWDAWG") myindelmodelint=13; // Slower Zipf from DAWG - here for checking fast zipf!
+
+							if(myin=="POWCUM")  myindelmodelint=12; // cumulative method as for USER and LAV used to check both above!
+
+							if(tempsize!=2 && tempsize!=3) noindelerror=false;
+														
+							if(noindelerror)
+							{
+								myin=tempvec.at(1); 
+								if(!allAinB(myin,"0123456789.")) noindelerror=false;
+								else ma=atof(myin.c_str());
+								if(ma<=1) noindelerror=false;
+							}
+
+							if(tempsize==3 && noindelerror)
+							{
+								myin=tempvec.at(2); 
+								if(!allAinB(myin,"0123456789")) noindelerror=false;
+								else mM=atoi(myin.c_str());
+								if(mM<=1) noindelerror=false;
+							}
+							else mM=2147483647; // largest integer value possible. //mM=pow(10,12); //mM=~0-1; // largest known genome is 132 pg  (1pg is ~ 978 MB, so 132pg is ~ 129 GB, i.e. 10^12 is bigger than any genome!)
+							
+							if(!noindelerror) 							
+							{	
+								controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Expecting 1 or 2 values after \"POW\" when using Zipfian Power Model.\nThis obligatory first value should be a decimal number a > 1.\nThe second optional value should be an integer M > 1.","");
+								mytest=-2; {if(breakonerror) return -1;} 
+							}
+
+							double blah;
+							if(myindelmodelint==12)
+							{
+								for(double u=1; u<mM+1; u++) {entryd=pow(u,-1*ma); totald+=entryd; meand+=( entryd * u );usermodel.push_back(totald); }
+		
+								for(int i=0; i<usermodel.size(); i++) {(usermodel.at(i))/=totald;  }
+							}
+							else
+							{
+								//cout<<"mM is "<<mM<<endl;
+								double last=2, diff, bit=pow(10,-15);
+								for(double u=1; u<mM+1; u++) {entryd=pow(u,-1*ma); meand+=(entryd*u); totald+=entryd; diff=last-entryd; last=entryd;  if(diff<bit) {blah=u; break;}}	
+							}
+							//cout<<"BLAH  "<<blah<<endl;
+							meand/=totald;
+							//cout<<meand<<"  "<<totald<<endl;
+	
+						} // end of Zipfian Distribution (Power Law)
+
+						// Lavalette Distribution
+						else  if(myin=="LAV") 
+						{					
+							/*
+							Lavalette Distribution References
+
+							Lavalette distribution (Lavalette, 1996; Popescu et al., 1997; Popescu, 2003).  
+							Lavalette D. (1996) Facteur d�impact: impartialit� ou impuissance?, Internal Report, INSERM U350, Institut Curie - Recherche, B�t. 112, Centre Universitaire, 91405 Orsay, France (November 1996)
+							Popescu, I.I. (1997) On the Lavalette Ranking Law (with M. Ganciu, M. C. Penache, and D. Penache), Romanian Reports in Physics, 49, 3-27
+							Popescu, I.I. (2003) On a Zipf�s law extension to impact factors. Glottometrics, 6. 83-93.
+							*/
+
+							myindelmodelint=3;
+
+							if(tempsize!=3) noindelerror=false;
+														
+							if(noindelerror)
+							{
+								myin=tempvec.at(1); 
+								if(!allAinB(myin,"0123456789.")) noindelerror=false;
+								else mb=atof(myin.c_str());
+								if(mb<=1) noindelerror=false;
+							}
+
+							if(noindelerror)
+							{
+								myin=tempvec.at(2); 
+								if(!allAinB(myin,"0123456789")) noindelerror=false;
+								else mM=atoi(myin.c_str());
+								if(mM<=1) noindelerror=false;
+							}
+
+							if(!noindelerror) 							
+							{	
+								controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Expecting 2 values after \"LAV\" when using Lavalette Model.\nThe first should be a decimal b > 1.\nThe second (maximum length) should be an integer M>1.","");
+								mytest=-2; {if(breakonerror) return -1;} 
+							}
+
+							
+							for(double u=1; u<mM+1; u++) {entryd=pow(mM*u/(mM-u+1),-1*mb); meand+=(u*entryd); totald+=entryd; usermodel.push_back(totald); }
+		
+							for(int i=0; i<usermodel.size(); i++) {(usermodel.at(i))/=totald; }
+							meand/=totald;
+
+
+						} // end of Lavalette Distribution
+
+						else
+						{	
+							controlerrorprint2("[MODEL]", name, commands.at(lasttest), "The first value in this command specifies the insertion or deletion model.\nPossible values are:\n\n     NB = Negative Binomial Distribution\n    POW = Zipfian Distribution (Power Law)\n    LAV = Lavalette Distribution\n   USER = explicit, user-defined indel length distribution\n",myin);
+							mytest=-2; {if(breakonerror) return -1;} 
+						}
+		
+						if(lasttest==0 || lasttest==2) 
+						{
+							insertmodel.type=myindelmodelint;
+							insertmodel.r=int(mr);
+							insertmodel.q=mq;
+							insertmodel.a=ma;
+							insertmodel.b=mb;
+							insertmodel.M=int(mM);			//cout<<"mM before "<<mM<<"  and after "<<int(mM)<<endl;
+							insertmodel.meansize=meand;
+							insertmodel.usermodel=usermodel;
+						}
+						if(lasttest==1 || lasttest==2) 
+						{
+							deletemodel.type=myindelmodelint;
+							deletemodel.r=int(mr);
+							deletemodel.q=mq;
+							deletemodel.a=ma;
+							deletemodel.b=mb;
+							deletemodel.M=int(mM);			//cout<<"mM before "<<mM<<"  and after "<<int(mM)<<endl;
+							deletemodel.meansize=meand;
+							deletemodel.usermodel=usermodel;
+						}
+						
+					} // end of indel model stuff
+
+					else if(lasttest>2 && lasttest<7) 
+					{
+						// last test = 3  for insertion rate
+						// last test = 4  for deletion rate
+						// last test = 5  for insertion AND deletion rate
+						// last test = 6  for genetic code
+
+						if(tempvec.size()>1) 
+						{	
+							controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Expecting 1 value after this command but found "+tempvec.at(0)+" then "+tempvec.at(1)+".","");
+							mytest=-2; {if(breakonerror) return -1;} 
+						}
+
+						string myin=tempvec.at(0);
+			
+						if(lasttest==6)
+						{
+							// genetic code
+							
+							if(type!=3) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "This command only has effect in CODON simulations.","");   {if(breakonerror) return -1;} }  
+
+							if(AinB('.',myin)) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Value for this command should not be decimal, was expecting integer.",myin);   {if(breakonerror) return -1;} }  
+
+							else
+							{
+								int myout=atoi(myin.c_str());
+									
+								if(  (myout>0 && myout<7) || (myout>8 && myout<17) || (myout>20 && myout<24)  ) geneticcode=myout; 
+								
+								else {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Value for this command should be an integer 1-6, 9-16, or 21-23\nThese correspond to the entries on GenBank (October 2008).",myin);   {if(breakonerror) return -1;} }
+							}
+						}
+						else 
+						{ 
+							double myout=atof(myin.c_str());
+
+							if(myout<0) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Value for this command should be greater than or equal to zero.",myin);   {if(breakonerror) return -1;} }  
+
+							if(lasttest==3) insertrate=myout; 
+							
+							else if(lasttest==4) deleterate=myout;
+
+							else insertrate=deleterate=myout;
+						}
+							
+					} 
+					else if(lasttest==7)
+					{
+						// lasttest == 7 is the substitution model  -----> big if bracket
+
+						string myin=tempvec.at(0);
+
+						if(!allAinB(myin,"0123456789.") )
+						{
+							ifstream ig1; ig1.open(myin.c_str()); 
+
+							if(type==2)
+							{
+								if(!(ig1.good())) {controlerrorprint2("[MODEL]", name, "[submodel]", myin+"\nis not a model name or number and no file of this name exists.\nFor protein models, the entry after a [submodel] command must be\nan integer or a filename.",""); {if(breakonerror) return -1;} }
+								
+								modelnumber=-1;
+								char c2; string sss;
+
+								c2=ig1.get(); aamodel.clear(); 
+								bool writeon=false;
+								while(ig1.good())
+								{	
+									if(AinB(c2,"1234567890. \t\n\r"))
+									{
+										if(AinB(c2," \t\n\r")) writeon=false; else writeon=true;
+										
+										if(writeon) sss+=c2;
+										else if(sss!="") {aamodel.push_back(  atof(sss.c_str())  ); sss="";}
+									}
+									else {controlerrorprint2("[MODEL]", name, "[submodel]", "Reading user defined protein substitution model from file:\n"+myin+"\n...but have found illegal character \""+c2+"\"\nEntries in this file can only be decimal numbers separated by\nspaces, horizontal tabs and new lines.",""); {if(breakonerror) return -1;} }
+								
+									c2=ig1.get(); 
+								}
+								int wrongsize2=aamodel.size(); stringstream dd; dd<<wrongsize2; string wrongsize=dd.str();
+
+								if(wrongsize2!=210) {controlerrorprint2("[MODEL]", name, "[submodel]", "Reading user defined protein substitution model from file:\n"+myin+"\n...but have found "+wrongsize+" entries. Was expecting 210 entries.\nThe first 190 entries are from the substitution matrix.\nThe final 20 values are for the stationary amino-acid frequencies.\nThe substititution model must be symmetric and the file must only contain\nthe lower triangular half of the substitution matrix.",""); {if(breakoner [...]
+							}
+							else if(type==1) {controlerrorprint2("[MODEL]", name, "[submodel]", myin+" is not an integer model number.\nThe entry after a [submodel] command must be an integer.",""); {if(breakonerror) return -1;} }
+		
+						}
+						else
+						{
+
+							int mymodel=atoi(myin.c_str());
+
+							int b=17; string typestring="NUCLEOTIDE"; string bnum="16";  //for type 1
+							if(type==2) {typestring="AMINOACID";}
+							else if(type==3) {b=16; bnum="15"; typestring="CODON";}
+
+							if(type!=3)
+							{
+								if(mymodel>-1 && mymodel<b && !AinB('.',myin)) {modelnumber=mymodel;} 
+								else {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "First value for this command represents the model number.\nThis should be a integer between 0 and "+bnum+" inclusive\nwhen type is set to "+typestring+".",myin);   {if(breakonerror) return -1;} }
+							}
+							else
+							{
+								if(mymodel!=14 && mymodel!=15) modelnumber=mymodel=3;
+							}
+							int nstsize=tempvec.size();
+							
+							// old way
+							//for(int hy=1; hy<nstsize; hy++) {params.push_back(atof((tempvec.at(hy)).c_str())); }    //cout<<"WER "<<atof((tempvec.at(hy)).c_str())<<endl;}
+
+							if(type==3) for(int hy=0; hy<nstsize; hy++) {params.push_back(atof((tempvec.at(hy)).c_str())); }    //cout<<"WER "<<atof((tempvec.at(hy)).c_str())<<endl;}
+							else        for(int hy=1; hy<nstsize; hy++) {params.push_back(atof((tempvec.at(hy)).c_str())); }    //cout<<"WER "<<atof((tempvec.at(hy)).c_str())<<endl;}
+
+							if(type==2) 
+							{
+								if(nstsize>1) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Value for this command should be a single integer between 0 and "+bnum+"\nor a model/file name when type is set to AMINOACID.\nBut found "+tempvec.at(0)+" then "+tempvec.at(1)+".","");   {if(breakonerror) return -1;} }
+
+
+							}
+							
+							else if(type==1)
+							{
+								stringstream fr; fr<<nstsize-1; string fh=fr.str();
+
+	 								 if(mymodel==0  && nstsize!=1)                 {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as JC69. \nNot expecting any substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==1  && nstsize!=1)                 {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as F81. \nNot expecting any substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==2  && nstsize!=2 && nstsize!=3)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as K80. \nExpecting 1 or 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==3  && nstsize!=2 && nstsize!=3)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as HKY85. \nExpecting 1 or 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==4  && nstsize!=3 && nstsize!=4)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as TN93ef. \nExpecting 2 or 3 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==5  && nstsize!=3 && nstsize!=4)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as TN93. \nExpecting 2 or 3 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==6  && nstsize!=3 && nstsize!=4)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as K81. \nExpecting 2 or 3 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==7  && nstsize!=3 && nstsize!=4)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as K81uf. \nExpecting 2 or 3 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==8  && nstsize!=4 && nstsize!=5)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as TIMef. \nExpecting 3 or 4 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==9  && nstsize!=4 && nstsize!=5)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as TIM. \nExpecting 3 or 4 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==10 && nstsize!=5 && nstsize!=6)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as TVMef. \nExpecting 4 or 5 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==11 && nstsize!=5 && nstsize!=6)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as TVM. \nExpecting 4 or 5 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==12 && nstsize!=6 && nstsize!=7)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as SYM. \nExpecting 5 or 6 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==13 && nstsize!=6 && nstsize!=7)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as GTR. \nExpecting 5 or 6 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								
+								else if(mymodel==14 && nstsize!=2 && nstsize!=3)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as F84ef. \nExpecting 1 or 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==15 && nstsize!=2 && nstsize!=3)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as F84. \nExpecting 1 or 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+							//	else if(mymodel==16 && nstsize!=3 && nstsize!=4)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as T92. \nExpecting 2 or 3 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+							//	else if(mymodel==17 && nstsize!=12 && nstsize!=13) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as UNREST. \nExpecting 11 or 12 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==16 && nstsize!=12 && nstsize!=13) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as UNREST. \nExpecting 11 or 12 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+							}
+
+							else if(type==3)
+							{
+								ngamcat=1;
+								//nstsize--;
+								stringstream fr; fr<<nstsize; string fh=fr.str();
+
+	 								 if(mymodel==0  && nstsize!=2) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M0. \nWas expecting 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==1  && nstsize!=3) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M1. \nWas expecting 3 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==2  && nstsize!=5) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M2. \nWas expecting 5 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								
+
+								/*
+								else if(mymodel==5 ) 
+								{
+									if(nstsize==4) 
+									{
+										if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 4 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} }
+										else ngamcat=atoi((tempvec.back()).c_str());
+									}
+									else 
+									{
+										if(nstsize!=3) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWas expecting 3 or 4 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} } 
+										else ngamcat=0;
+									}
+								}
+
+								
+								else if(mymodel==5 ) {if(nstsize==4){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 4 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==6 ) {if(nstsize==6){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 6 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==7 ) {if(nstsize==4){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 4 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==8 ) {if(nstsize==6){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 6 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==9 ) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==10) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==11) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==12) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								else if(mymodel==13) {if(nstsize==8){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWhen specifying 8 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());param [...]
+								/*
+								else if(mymodel==5  && nstsize!=3 && nstsize!=4) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5. \nWas expecting 3 or 4 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==6  && nstsize!=5 && nstsize!=6) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M6. \nWas expecting 5 or 6 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==7  && nstsize!=3 && nstsize!=4) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M7. \nWas expecting 3 or 4 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==8  && nstsize!=5 && nstsize!=6) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M8. \nWas expecting 5 or 6 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==9  && nstsize!=6 && nstsize!=7) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M9. \nWas expecting 6 or 7 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==10 && nstsize!=6 && nstsize!=7) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M10.\nWas expecting 6 or 7 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==11 && nstsize!=6 && nstsize!=7) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M11.\nWas expecting 6 or 7 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==12 && nstsize!=6 && nstsize!=7) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M12.\nWas expecting 6 or 7 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==13 && nstsize!=7 && nstsize!=8) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M13.\nWas expecting 7 or 8 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								*/
+
+								else if(mymodel==5 ) {if(nstsize==4){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M5.\nWhen specifying 4 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());params [...]
+								else if(mymodel==6 ) {if(nstsize==6){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M6.\nWhen specifying 6 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());params [...]
+								else if(mymodel==7 ) {if(nstsize==4){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M7.\nWhen specifying 4 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());params [...]
+								else if(mymodel==8 ) {if(nstsize==6){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M8.\nWhen specifying 6 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());params [...]
+								else if(mymodel==9 ) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M9.\nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());params [...]
+								else if(mymodel==10) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M10. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());para [...]
+								else if(mymodel==11) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M11. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());para [...]
+								else if(mymodel==12) {if(nstsize==7){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M12. \nWhen specifying 7 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());para [...]
+								else if(mymodel==13) {if(nstsize==8){ if(AinB('.',tempvec.back())) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M13. \nWhen specifying 8 substitution parameters after the model number the\nlast value represents the number of categories to use in the discrete \napproximation for any continuous distributions.  This must be an integer. ",tempvec.back()); {if(breakonerror) return -1;} } else {ngamcat=atoi((tempvec.back()).c_str());para [...]
+
+
+
+								else if(mymodel==3  && (nstsize%2)!=0) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M3. \nWas expecting 2K substitution parameters for K categories.\nOrder should be: kappa p_0  p_1  ... p_(k-2)  w_0  w_1  ... w_(k-1)\nFor M0 this would be: kappa w_0\nFor M1a this would be: kappa p_0 w_0 w_1.\nFor M2a this would be: kappa p_0 p_1 w_0 w_1 w_2 etc.\nInstead found an odd number of parameters ("+fh+") after model number",""); {if(break [...]
+
+
+								//else if(mymodel==3  && (nstsize%2)!=0) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M3. \nWas expecting 2K-1 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==4  && nstsize<3) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as M4. \nWas expecting at least 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								
+								else if(mymodel==14 && nstsize!=0) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as ECMrest. \nNot expecting any substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+								else if(mymodel==15 && nstsize!=0) {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "CODON substitution model set as ECMunrest. \nNot expecting any substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+
+
+								// why is this here?  it says NUCLEOTIDE - is this the same as before? - maybe just used for copying?
+								//else if(mymodel==2  && nstsize!=2 && nstsize!=3)   {controlerrorprint2("[MODEL]", name, commands.at(lasttest),  "NUCLEOTIDE substitution model set as K80. \nExpecting 1 or 2 substitution parameters.\nInstead found "+fh+" parameters after model number",""); {if(breakonerror) return -1;} }
+
+								// cout<<"NGAMCAT "<<ngamcat<<endl;
+		
+								if(mymodel==12 || mymodel==13 || mymodel==2)
+								{
+									if(params.at(1)>1) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "proportion p0 must be between 0 and 1.  You entered "+tempvec.at(2),""); {if(breakonerror) return -1;} }
+									if(params.at(2)>1) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "proportion p1 must be between 0 and 1.  You entered "+tempvec.at(3),""); {if(breakonerror) return -1;} }
+									if(mymodel!=12 && params.at(1)+params.at(2)>1) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "sum of proportions p0 and p1 must be between 0 and 1.  \nYou entered "+tempvec.at(2)+" and "+tempvec.at(3),""); {if(breakonerror) return -1;} }
+
+								}
+								else if( (mymodel<12 && mymodel>7) || mymodel==6 || mymodel==1)
+								{
+									if(params.at(1)>1) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "proportion p0 must be between 0 and 1.  You entered "+tempvec.at(2),""); {if(breakonerror) return -1;} }
+								}
+								else if(mymodel==3 || mymodel==4)
+								{
+									int thesize=params.size(); 
+									if(mymodel==3) thesize=(thesize-1)/2 +1;
+									double sum=0;
+									for(int gh8=1; gh8<thesize; gh8++) 
+									{
+										sum+=params.at(gh8);
+										if(params.at(gh8)>1) 
+										{
+											stringstream cd; cd<<gh8-1; string hf=cd.str();
+											controlerrorprint2("[MODEL]", name, commands.at(lasttest), "proportion p"+hf+" must be between 0 and 1.  You entered "+tempvec.at(gh8+1),""); 
+											{if(breakonerror) return -1;} 
+										}			
+									}
+									if(sum>1) 
+									{
+										stringstream cd; cd<<sum; string hf=cd.str();
+											
+										controlerrorprint2("[MODEL]", name, commands.at(lasttest), "sum of proportions must be between 0 and 1.  It was "+hf+".",""); {if(breakonerror) return -1;} 
+									}
+									
+								}
+							
+							} // end of else if type =3 bracket							
+
+						}
+					}// end of lasttest == 7 bracket 	
+					else if(lasttest==99)
+					{//y1
+						// params
+						
+///////////////////////////////////////////////
+
+						//  disabled bracket now
+
+
+					}//y1
+					else if(lasttest==8)
+					{
+						// lasttest == 8 sets site specific rates for.   order of commands is --------> rates  pinv alpha ngamcat
+
+						if(type==3)	{controlerrorprint2("[MODEL]", name, commands.at(lasttest), "This command has no effect in a CODON simulation.","");   {if(breakonerror) return -1;} }
+						else if(tempvec.size()!=3) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "There should be 3 values following a [rates] command: pinv alpha ngamcat.","");  {if(breakonerror) return -1;} }
+						else
+						{
+							if(AinB('.',tempvec.at(2))) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "The 3rd value representing ngamcat should be an integer",tempvec.at(2));  {if(breakonerror) return -1;} }
+
+							pinv=atof((tempvec.at(0)).c_str());
+							alpha=atof((tempvec.at(1)).c_str());
+							ngamcat=atoi((tempvec.at(2)).c_str());
+
+							if(pinv>1) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "The 1st value representing pinv should be between 0 and 1.",tempvec.at(0));  {if(breakonerror) return -1;} }
+							
+						}
+					}
+					else if(lasttest==9)
+					{
+						// Crates  ---->    now disabled, was for fixed relative rates for each codon position.
+
+						if(tempvec.size()!=3) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "There should be 3 decimal values following a [Crates] command.","");  {if(breakonerror) return -1;} }
+						else
+						{
+							codonrates[0]=atof((tempvec.at(0)).c_str());
+							codonrates[1]=atof((tempvec.at(1)).c_str());
+							codonrates[2]=atoi((tempvec.at(2)).c_str());
+						}
+					}
+					else if(lasttest>9)
+					{//x1
+						// lasttest == 10 is base frequencies being defined
+						// lasttest == 11 is insertion base frequenciess being defined (i.e. diff. base freqs being used for creating inserted sequences and for substitution model)
+						// lasttest == 12 is root base frequencies being defined  (i.e.  using diff base freqs for creating root sequence than those used by substitution model)
+
+						// base frequency stuff
+
+						int mysize=tempvec.size();
+				
+						stringstream fd; fd<<mysize; string mysizeS=fd.str();
+						bool errorprint=false;
+						string mytype, mysizes;
+
+						if(type==3) {if(mysize!=4 && mysize!=12 && mysize!=64) {mytype="CODON"; mysizes="4, 12, or 64"; errorprint=true; }}
+						else if(type==2) {if(mysize!=20){mytype="AMINOACID"; mysizes="20"; errorprint=true; }}
+						else if(type==1) {if(mysize!=4) {mytype="NUCLEOTIDE";     mysizes="4"; errorprint=true; }}
+
+						if(errorprint) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "There should be "+mysizes+" values for a base frequency command\nwhen simulating "+mytype+" data. You entered "+mysizeS+" values.","");  {if(breakonerror) return -1;} }
+						else
+						{ //x2
+							vector<double> tempbases, tempbases2; 
+							for(int kh=0; kh<mysize; kh++) 
+							{
+								double mytemp=atof( ( tempvec.at(kh) ).c_str() );
+								if(mytemp<0) {controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Values for base frequency commands must be positive.","");  {if(breakonerror) return -1;} }
+								else tempbases.push_back(mytemp);
+							}
+
+							double scaler=0,lastscaler,diff;
+
+							if(type==3 && mysize==4)
+							{
+								// F1X4 frequencies
+								scaler=0;
+								for(int gh1q=0; gh1q<mysize; gh1q++) scaler+=tempbases.at(gh1q); 
+								for(int gh2q=0; gh2q<mysize; gh2q++) tempbases.at(gh2q)/=scaler;
+
+								diff=scaler-1; if(diff<0) diff=-diff;
+								if(diff>0.0001) controlerrorprint2("[MODEL]", name, commands.at(lasttest), "F1X4 base frequencies did not add up to 1 so they have been rescaled.",""); 
+
+								//for(int i1=0; i1<4; i1++) for(int j1=0; j1<4; j1++) for(int k1=0; k1<4; k1++)
+								//tempbases2.push_back(tempbases.at(i1)*tempbases.at(j1)*tempbases.at(k1));
+								
+								//enforcestops(geneticcode,tempbases2);
+								//mysize=64;
+
+								tempbases2=tempbases;
+								
+							}
+							else if(type==3 && mysize==12) 
+							{
+								// F3X4 frequencies
+								scaler=0;
+								for(int gh1a=0; gh1a<4; gh1a++) scaler+=tempbases.at(gh1a); 
+								for(int gh2a=0; gh2a<4; gh2a++) tempbases.at(gh2a)/=scaler;
+
+								diff=scaler-1; if(diff<0) diff=-diff;
+								if(diff>0.0001) controlerrorprint2("[MODEL]", name, commands.at(lasttest), "F3X4 base frequencies for the 1st codon position\ndid not add up to 1 so they have been rescaled.",""); 
+
+								scaler=0;
+								for(int gh1b=4; gh1b<8; gh1b++) scaler+=tempbases.at(gh1b); 
+								for(int gh2b=4; gh2b<8; gh2b++) tempbases.at(gh2b)/=scaler;
+
+								diff=scaler-1; if(diff<0) diff=-diff;
+								if(diff>0.0001) controlerrorprint2("[MODEL]", name, commands.at(lasttest), "F3X4 base frequencies for the 2nd codon position\ndid not add up to 1 so they have been rescaled.",""); 
+
+								scaler=0;
+								for(int gh1c=8; gh1c<12; gh1c++) scaler+=tempbases.at(gh1c); 
+								for(int gh2c=8; gh2c<12; gh2c++) tempbases.at(gh2c)/=scaler;
+
+								diff=scaler-1; if(diff<0) diff=-diff;
+								if(diff>0.0001) controlerrorprint2("[MODEL]", name, commands.at(lasttest), "F3X4 base frequencies for the 3rd codon position\ndid not add up to 1 so they have been rescaled.",""); 
+
+
+								//for(int i1=0; i1<4; i1++) for(int j1=4; j1<8; j1++) for(int k1=8; k1<12; k1++)
+								//tempbases2.push_back(tempbases.at(i1)*tempbases.at(j1)*tempbases.at(k1));
+
+								//enforcestops(geneticcode,tempbases2);
+								//mysize=64;
+
+								tempbases2=tempbases;
+
+							}
+							else if(type==3 && mysize==64)
+							{
+								//Fcodon frequencies
+								scaler=0;
+								for(int gh1s=0; gh1s<mysize; gh1s++) scaler+=tempbases.at(gh1s); 
+								for(int gh2s=0; gh2s<mysize; gh2s++) tempbases.at(gh2s)/=scaler;
+
+								lastscaler=scaler;
+								diff=scaler-1; if(diff<0) diff=-diff;
+								if(diff>0.0001) controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Base frequencies did not add up to 1 so they have been rescaled.",""); 
+								
+								tempbases2=tempbases;
+							
+							}
+							else tempbases2=tempbases;
+		
+							if(type==1 || type==2)
+							{
+								scaler=0;
+								for(int gh1=0; gh1<mysize; gh1++) scaler+=tempbases2.at(gh1); 
+								for(int gh2=0; gh2<mysize; gh2++) tempbases2.at(gh2)/=scaler;
+
+								diff=scaler-1; if(diff<0) diff=-diff;
+								if(diff>0.0001) controlerrorprint2("[MODEL]", name, commands.at(lasttest), "Base frequencies did not add up to 1 so they have been rescaled.",""); 
+							}
+					
+							if(lasttest==10) 
+							{
+								basefreqs=tempbases2;
+							}
+							else if(lasttest==11) insertfreqs=tempbases2;
+							else if(lasttest==12) rootbasefreqs=tempbases2;
+						
+						}//x2
+					}//x1
+
+					tempvec.clear();
+
+				} //end of a2  bracket (long way above!)	
+
+			} //end of a1  bracket ( long long way above!)
+
+		}	// end of for bracket
+
+	} // end of model name else bracket
+
+
+		totalmodels.push_back(model(totalmodels.size(), type, name, modelnumber, geneticcode, copiedmodel, insertrate, deleterate,  alpha, pinv, ngamcat, codonrates, basefreqs, rootbasefreqs, insertfreqs, params, aamodel, insertmodel, deletemodel ));
+		
+		if((totalmodels.back()).error==-1) return -1;   // returns error if there was an error resulting from the model constructor in the model class
+	
+	return 0;
+
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+int dealwithsites(vector<string> &block)		
+{
+	// this function is not used any more as the sites class is disabled now.
+
+	int mymy=block.size();
+	string name;
+	if(mymy==0) {controlerrorprint2("[SITES]", "", "", "You must specify a name for a sites block. This one is empty.",""); {if(breakonerror) return -1;}  }
+	else
+	{
+		name=block.at(0);
+		if(!allAinB(name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SITES]", name, "", "First statement in a [SITES] block must be a sites name statement.\nThe name should only contain  ,.;()-_ and alpha-numeric characters.",""); {if(breakonerror) return -1;} }		
+
+		if(checkthere(name,totalsitenames)!=-1)
+		{ controlerrorprint2("[SITES]", name, "", "A sites class with this name has been specified twice.",""); {if(breakonerror) return -1;} }
+	
+	}
+
+	if(mymy==1) {controlerrorprint2("[SITES]", name, "", "This sites block contains no commands.",""); {if(breakonerror) return -1;}  }
+	else name=block.at(0);
+
+	vector<double> props;
+	vector<string> names;
+
+	if(mymy==2)
+	{
+		string a=block.at(1),b;
+		int commacount=0;
+		bool lastcomma=false;
+		bool modelnameempty=false;
+		
+		for(int y=0; y<a.size(); y++) 
+		{
+			if(lastcomma==true) {if(a[y]==',' || a[y-2]=='[' || a[y]==']') modelnameempty=true;  lastcomma=false;}
+
+			if(a[y]==',' && lastcomma==false) {commacount++; lastcomma=true;}
+		}			
+
+		if(type!=1)
+		{
+			string protcod; if(type==2) protcod="AMINOACID"; else protcod="CODON";
+			controlerrorprint2("[SITES]", name, a, "The command C[x,y,z] is used to specify different models or branch\nclasses for each codon position in a NUCLEOTIDE analysis.\nIt cannot be used for a "+protcod+" type analysis.",""); 
+			{if(breakonerror) return -1;}  
+		}
+
+		if(a[0]!='C' || a[1]!='[' || a[a.size()-1]!=']') 
+		{controlerrorprint2("[SITES]", name, a, "Only one statement after the sites class name means you are specifiying\na codon sites class and you must use the following notation:\nC[mymodelname1,mymodelname2,mymodelname3] or\nC[mybranchclass1,mybranchclass2,mybranchclass3]",""); {if(breakonerror) return -1;}  }
+		
+		
+		
+
+		if( commacount!=2)
+		{
+			stringstream sss; sss<<commacount+1; string cc=sss.str();
+			controlerrorprint2("[SITES]", name, a, "You must specify 3 models in a codons site class, you specified "+cc+"\nCorrect format of the statement is:\nC[mymodelname1,mymodelname2,mymodelname3] or\nC[mybranchclass1,mybranchclass2,mybranchclass3]",""); {if(breakonerror) return -1;}  
+		}
+		
+		if(modelnameempty )
+		{
+			controlerrorprint2("[SITES]", name, a, "This codon sites class contains an empty model name.\nCorrect format of the statement is:\nC[mymodelname1,mymodelname2,mymodelname3] or\nC[mybranchclass1,mybranchclass2,mybranchclass3]",""); {if(breakonerror) return -1;}  
+		}
+
+		bool writeon=false;
+		for(int y1=0; y1<a.size(); y1++)
+		{
+			char c=a[y1];
+
+			if(c==',' || c==']') 
+			{
+				if(allAinB(b,"0.123456789")) { controlerrorprint2("[SITES]", name, "", "This model/branchclass name is a decimal number, is this a mistake?\n\""+a+"\" cannot be used as a model/branchclass name.",""); {if(breakonerror) return -1;} }
+				if(!allAinB(b,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SITES]", name, "", "Model/Branchclass names should only contain ,.;()-_ and alpha-numeric characters.",""); {if(breakonerror) return -1;} }
+
+				names.push_back(b); b="";
+			}
+			if(writeon && c!=',') b+=c;
+			if(c=='[') writeon=true;
+			
+		}
+
+		// for(int ii=0; ii<names.size(); ii++) cout<<names.at(ii)<<"  "<<endl;
+
+		
+	
+		totalsitenames.push_back(name); 
+		totalsites.push_back(siteclass(name, names,props,totalmodelnames,totalbranchesnames));
+
+	}
+	else if(mymy%2!=1){controlerrorprint2("[SITES]", name, "", "Sites blocks must have an even number of statements in pairs of the form:\n'proportion model' or 'proportion branchclass' e.g. 0.2 mymodelname.",""); {if(breakonerror) return -1;}  }
+	else if(mymy==3){controlerrorprint2("[SITES]", name, "", "Sites blocks need at least two site classes otherwise\njust evolve a model or a branchclass not a siteclass!",""); {if(breakonerror) return -1;}  }
+	else //aaa
+	{
+		for(int i1=1; i1<mymy; i1++) 
+		{
+			string a=block.at(i1);
+			if(a[0]=='[' && a[a.size()-1]==']')  {controlerrorprint2("[SITES]", name, a, "Sites blocks do not contain other commands.\nHave you made a spelling mistake?",""); {if(breakonerror) return -1;}  }
+
+			if(i1%2==0) 
+			{ 
+				if(allAinB(a,"0.123456789")) { controlerrorprint2("[SITES]", name, "", "This model/branchclass name is a decimal number, is this a mistake?\n\""+a+"\" cannot be used as a model/branchclass name.",""); {if(breakonerror) return -1;} }
+				if(!allAinB(a,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SITES]", name, "", "Model/Branchclass names should only contain ,.;()-_ and alpha-numeric characters.",""); {if(breakonerror) return -1;} }
+			}
+
+			else  {if(!allAinB(a,"0123456789.")) { controlerrorprint2("[SITES]", name, "", "Possible Spelling Mistake...\nProportions should be decimal numbers, control file had:\n"+a+"\nIs this a model name or branch class name?\nIf so, the proportion should come before the name.",""); {if(breakonerror) return -1;} }}
+		}
+			
+		double sum=0; 
+
+		//need to have C[x.y.z] for codon dna  models!
+
+		//and to set up things for putting it all in to a site class!
+
+		//what about the debugging for the whole thing?
+
+		for(int i=1; i<mymy; i=i+2) 
+		{
+			string a=block.at(i);
+			double num=atof(a.c_str());
+			sum+=num;
+			props.push_back(num);
+			names.push_back(block.at(i+1));	
+		}
+
+		double diff=sum-1; if(diff<0) diff=-diff;
+		if(diff>0.0001) 
+		{
+			stringstream qwe; qwe<<sum; string blah=qwe.str();
+			controlerrorprint2("[SITES]", name, "", "Site class proportions summed to "+blah+" not 1,\nThey have been rescaled so that they sum to 1",""); 
+			for(int j=0; j<props.size(); j++) {props.at(j)/=sum;}// cout<<props.at(j)<<" ";} cout<<endl;
+			
+		}
+
+		for(int k=1; k<props.size(); k++) props.at(k)+=props.at(k-1);
+		
+		//for(int k1=0; k1<props.size(); k1++) cout<<props.at(k1)<<" "; cout<<endl;
+
+		diff=props.back()-1; if(diff<0) diff=-diff;
+		if(diff>0.0001) cout<<"INTERNAL ERROR in rescaling site class proportions."<<endl;
+
+		//for(int ii=0; ii<names.size(); ii++) cout<<names.at(ii)<<"  "<<props.at(ii)<<endl;
+
+		totalsitenames.push_back(name); 
+		totalsites.push_back(siteclass(name, names,props,totalmodelnames,totalbranchesnames));
+
+		
+		if((totalsites.back()).error==-1) return -1;
+
+	}//aaa
+
+	
+
+
+	return 0;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int dealwithbranches(vector<string> &block, bool iscodefixed)		
+{
+	// this function reads in the branch class information and pre-processes it for the branch class constructor
+
+	int mymy=block.size();
+	string tree;
+	string name;
+	if(mymy==0) {controlerrorprint2("[BRANCHES]", "", "", "You must specify a name for a branches block. This one is empty.",""); {if(breakonerror) return -1;}  }
+	else
+	{
+		name=block.at(0);
+		if(!allAinB(name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[BRANCHES]", name, "", "First statement in a [BRANCHES] block must be a branches name statement.\nThe name should only contain  ,.;()-_ and alpha-numeric characters.",""); {if(breakonerror) return -1;} }		
+
+		if(checkthere(name,totalbranchesnames)!=-1)
+		{ controlerrorprint2("[BRANCHES]", name, "", "A branches class with this name has been specified twice.",""); {if(breakonerror) return -1;} }
+		
+	
+	}
+
+	if(mymy==1) {controlerrorprint2("[BRANCHES]", name, "", "This branches block contains no tree.",""); {if(breakonerror) return -1;}  }
+	else name=block.at(0);
+
+	for(int i=1; i<mymy; i++) 
+	{
+		string s=block.at(i);
+		if(s[0]=='[' && s[s.size()-1]==']')  {controlerrorprint2("[BRANCHES]", name, s, "Branch blocks do not contain other commands.\nHave you made a spelling mistake?",""); {if(breakonerror) return -1;}  }
+		else tree+=s;
+//		cout<<"branches "<<block.at(i)<<endl;
+	}
+	
+	//cout<<tree<<endl;
+
+	bool treeerror=false;
+	char c='q';
+
+	int size=tree.size();
+
+	if(tree[0]!='(' || tree[size-1]!=';' ) //|| tree[size-2]!=')')
+	{controlerrorprint2("[BRANCHES]", name, "", "User defined tree does not appear to be a NEWICK format tree (...); ",""); {if(breakonerror) return -1;}  }
+
+	int mybracketleft=0, mybracketright=0, taxaon=0, lengthon=0, rootbranches=0, bracketlevel=0; 
+
+	for(int fg1=0; fg1<size; fg1++)  
+	{
+		c=tree[fg1]; 
+		if(c=='(') {mybracketleft++; bracketlevel++;} 
+		if(c==')') {mybracketright++; bracketlevel--;}
+		if(bracketlevel==1 && c==',') rootbranches++;
+	}
+			
+	if(mybracketleft!=mybracketright) 	
+	{treeerror=true; controlerrorprint2("[BRANCHES]", name, "", "Number of parantheses in guide tree do not match.",""); {if(breakonerror) return -1;}  }
+
+	if(mybracketleft==0)  
+	{treeerror=true; controlerrorprint2("[BRANCHES]", name,"", "Branch class guide tree must contain as least one set of parentheses.",""); {if(breakonerror) return -1;}  }
+
+	bool myerror=true;
+	//cout<<"W"<<tree<<"W"<<endl;
+	int hashcount=0;
+	for(int yg=0; yg<size; yg++)
+	{
+		c=tree[yg];
+		if(c=='#') hashcount++;
+		
+		if(c==',' || c==')')
+		{
+			if(hashcount==0) {controlerrorprint2("[BRANCHES]", name,"", "Branch class guide tree contains a branch without a model name.\nModel names must have a # character in front of them.",""); {if(breakonerror) return -1;}  }
+			if(hashcount> 1) {controlerrorprint2("[BRANCHES]", name,"", "Branch class guide tree contains a branch with more than one model name.\nModel names must be preceded with one single #.",""); {if(breakonerror) return -1;}  }
+			hashcount=0;
+		}
+	}
+
+	// this adds an extra model to the root for the branch class 
+	// corresponds to extra branch added for forced insertions in dealwithtrees function
+#ifdef checkingindelsubs
+	string sd;
+	for(int p=tree.size()-1; p>-1; p--) 
+	{	
+		if(tree[p]=='#') break;
+		if(tree[p]!=';' ) sd+=tree[p];
+	}
+	string temp="("; 
+	temp+=tree;
+	temp[temp.size()-1]=')';
+	temp+="#";
+	for(int p2=sd.size()-1; p2>-1; p2--) temp+=sd[p2]; 
+	temp+=";";
+	tree=temp;
+#endif
+		
+	totalbranchesnames.push_back(name); 
+
+	totalbranches.push_back(branchclass(tree,name,totalmodelnames,iscodefixed));
+
+	if((totalbranches.back()).error==-1) return -1;
+
+	return 0;
+
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////
+ 
+vector<unsigned long> treeseeds;   //storage for tree seeds.....
+	
+
+class Tree
+{
+	// this class stores a tree as defined by the user or creates random trees based on user defined settings...
+
+public:
+	bool treerandom;
+//	bool randomeveryrep;
+	bool seedgiven;
+	string tree;
+	string name;
+	int ntaxa, seed, guidetreeroot, last;
+	double scaler, scalerd, scalerm, birth, death, sample, mut, max_distance;
+	double treelength, treedepth;
+	MTRand mymtrand;
+	string doctorlengths;
+	
+	Tree(bool myseedgiven, string mtree, double mscaler, double mscalerd, int mntaxa, double mbirth,double mdeath,double msample, double mmut, int mseed, int mguidetreeroot, string mname, string mydoctor, double mscalerm)
+	{
+		tree=mtree;
+		ntaxa=mntaxa;
+		scaler=mscaler;
+		scalerd=mscalerd;
+		treerandom=false;
+		seedgiven=myseedgiven;
+		name=mname;
+		doctorlengths=mydoctor;
+		scalerm=mscalerm;
+		max_distance=0;
+
+		if(tree=="RANDOM")
+		{
+			treerandom=true;
+			birth=mbirth;
+			death=mdeath;
+			sample=msample;
+			mut=mmut;
+			seed=mseed;
+			guidetreeroot=mguidetreeroot;
+
+//			if(seedgiven) {mymtrand.seed(seed);tester.seed(seed);}// cout<<"name "<<name<<" SEEDDDD "<<seed<<endl;} 	
+		}
+
+
+		if(!treerandom)
+		{
+			if(doctorlengths=="ULTRAMETRIC") tree=randomise_ultrametric(tree);
+
+//			cout<<"Q"<<max_distance<<"Q"<<endl;
+			treedepth=getmaxtreedepth(tree);	
+//			cout<<"R"<<max_distance<<"R"<<endl<<endl;
+			treelength=gettreelength(tree); 
+
+			if(scalerm!=-1) tree=rescaledtree(tree, max_distance, scalerm);
+			if(scaler!=-1)  tree=rescaledtree(tree, treelength,   scaler);
+			if(scalerd!=-1) tree=rescaledtree(tree, treedepth,    scalerd);////tree=redepthtree(tree, gettreelength(tree), scaler);
+
+			max_distance=0;
+			treedepth=getmaxtreedepth(tree);
+//			cout<<"S"<<max_distance<<"S"<<endl<<endl;
+			treelength=gettreelength(tree); 
+//			cout<<"T"<<max_distance<<"T"<<endl<<endl;
+			
+			if(scaler!=-1)  { double diff=treelength-scaler;    if(diff<0) diff=-diff; if(diff>0.0001) controlerrorprint2("[TREE]", name,"", "The treelength adjustment is not within the limits I expected.\n Please report this and it will be promptly fixed!","");}
+			if(scalerd!=-1) { double diff=treedepth-scalerd;    if(diff<0) diff=-diff; if(diff>0.0001) controlerrorprint2("[TREE]", name,"", "The treedepth adjustment is not within the limits I expected.\n Please report this and it will be promptly fixed!","");}
+			if(scalerm!=-1) { double diff=max_distance-scalerm; if(diff<0) diff=-diff; if(diff>0.0001) controlerrorprint2("[TREE]", name,"", "The maxdistance adjustment is not within the limits I expected.\n Please report this and it will be promptly fixed!","");}
+		}
+
+
+	}
+
+	////////////
+	void newrandom(int rep) //, unsigned long &last)
+	{
+		// this function should be called at the beginning of simulating each replicate when using random trees.
+
+		/*
+		if(rep==1) 
+		{
+			// [globalseed] overrides [seed] and [randomseed]
+			if(globalseed) mymtrand.seed(mtrand1.randInt()); 
+
+			// otherwise if a [TREE] [seed] has been given it is used
+			else if(seedgiven) mymtrand.seed(seed); 
+			
+			// otherwise the random seed is automatically generated.
+			else mymtrand.seed(); 
+		
+		} 	
+		else mymtrand.seed(last);
+	
+		last = mymtrand.randInt();
+		
+		string temptree=newrandomtree(ntaxa,birth,death,sample,mut,last,guidetreeroot); 
+
+		*/
+
+		if(rep==1) {if(seedgiven) mymtrand.seed(seed);}
+
+		int theseed;  if(seedgiven) theseed=mymtrand.randInt(); else theseed=mtrand1.randInt();
+
+		string temptree=newrandomtree(ntaxa,birth,death,sample,mut,theseed,guidetreeroot); 
+		
+		// FOR SOME REASON THE CODE FOR RANDOM TREES FROM ZIHENG'S EVOLVER LABELS SPECIES AS 1, 2, 3,... FOR
+		// NTAXA <20 BUT AS S1, S2, S3... FOR NTAXA>=20!!  THIS FILTERS THE 'S' OUT.
+
+//		cout<<"Q "<<temptree<<endl;
+
+		tree="";
+		for(int yq=0; yq<temptree.size(); yq++) if(temptree[yq]!='S') tree+=temptree[yq];
+
+//		cout<<"W "<<tree<<endl;
+	
+		if(scaler!=-1) tree=rescaledtree(tree, gettreelength(tree), scaler);
+
+		if(scalerd!=-1) tree=rescaledtree(tree, getmaxtreedepth(tree),scalerd);
+			
+	//	for(int po=0; po<40; po++) cout<<tree[po]; cout<<endl;
+
+		treelength=gettreelength(tree);
+		treedepth=getmaxtreedepth(tree);
+	}
+
+
+private:
+	////////////
+	
+	
+	double correctlastdepth(double maxdepth, string originaltree, double depthsofar, vector<string> &originals, vector<string> &changes)
+	{
+		vector<string> bits;
+		string s,t;
+
+		int bracketcount=1, pi;
+
+		if(originaltree[0]=='(')
+		{
+			//cout<<"Q"<<originaltree<<"W"<<endl;
+			for(pi=1; pi<originaltree.size(); pi++)
+			{
+				char c=originaltree[pi];
+				if(c=='(') bracketcount++;
+				if(c==')') bracketcount--;
+
+				//cout<<c<<"  "<<bracketcount<<endl;
+				if(bracketcount==1 && c==',') {bits.push_back(s); /*cout<<"S"<<s<<"S"<<endl;*/ s=""; continue;}
+				if(bracketcount==0) {bits.push_back(s);/* cout<<"SS"<<s<<"SS"<<endl; */break;}
+
+				s+=c;
+			}
+
+			//for(int yf=0; yf<bits.size(); yf++) cout<<bits.at(yf)<<endl;
+		
+//			if(!isitfirstgoo)
+//			{
+				s="";
+				
+				pi++;
+				if(originaltree[pi]!=':') { controlerrorprint2("[TREE]", name,"", "Something is wrong in the getnextdepthcommand.\n Please report this and it will be promptly fixed!",""); }
+		
+				
+				pi++;
+				for(int yg=pi; yg<originaltree.size(); yg++) s+=originaltree[yg];
+
+				/*cout<<"length to add "<<s<<endl;*/
+
+				depthsofar+=atof(s.c_str());
+
+//			}
+
+			for(pi=0; pi<bits.size(); pi++) correctlastdepth(maxdepth, bits.at(pi), depthsofar, originals, changes);
+		}	
+		else
+		{
+			//end of the tree!!!
+
+			bool lengthon=false;
+
+			for(pi=0; pi<originaltree.size(); pi++)
+			{
+				if(lengthon) s+=originaltree[pi];
+
+				if(!lengthon) {	if(originaltree[pi]==':') lengthon=true;}
+			}
+
+			//cout<<"END LENGTH "<<s<<endl;
+
+			originals.push_back(s);
+			
+			double endbranch=atof(s.c_str());
+
+			depthsofar+=endbranch;
+			
+			double diff=maxdepth-depthsofar;
+			stringstream newendbranch;
+			newendbranch<<endbranch+diff;
+			
+			changes.push_back(newendbranch.str());
+			
+			//cout<<"Depth is "<<depthsofar<<" but we have target of "<<maxdepth<<" which is difference of "<<diff<<endl;
+			//cout<<"Old branch was "<<s<<" so now it is "<<newendbranch.str()<<endl;
+			//cout<<"******************"<<endl;
+		}
+		
+		return 0;
+	}	
+	
+	string randomise_ultrametric(string originaltree)
+	{
+		vector<string> onestochange, whattochangeto;
+		double diff, depthsofar=0;
+		double maxdepth=getmaxtreedepth(originaltree);
+
+		string tree;
+		int sizey=originaltree.size()-1;
+		if(originaltree[sizey]==';')
+		{
+			for(int fr=0; fr<sizey; fr++) tree+=originaltree[fr];
+			tree+=":0.0";
+		}
+		else tree=originaltree;
+	
+		correctlastdepth(maxdepth, tree, depthsofar, onestochange, whattochangeto);
+				
+		int branch=0;
+		string mylength, newtree;
+		char c;
+			
+		tree=originaltree;
+
+		for(int uj=0; uj<tree.size(); uj++)
+		{
+			c=tree[uj];
+			if(c==',' || c==')') 
+			{
+				branch=0; 
+				int pos=-1;
+				for(int rf=0; rf<onestochange.size(); rf++)
+				{
+					//cout<<rf<<" "<<mylength<<"  "<<onestochange.at(rf)<<"  ";
+					if(mylength==onestochange.at(rf)) {pos=rf; /*cout<<whattochangeto.at(pos)<<endl;*/ break;}
+					//cout<<endl;
+				}
+				if(pos==-1) newtree+=mylength;	
+				else newtree+=whattochangeto.at(pos);
+				mylength="";
+			}
+			if(branch==1) mylength+=c; else newtree+=c;
+			if(c==':') branch=1;
+		}
+
+	  return newtree;
+		
+	}
+	
+	double getmaxtreedepth(string originaltree)
+	{
+		string ss, newtree;
+		double depthsofar=0;
+		int sizey=originaltree.size()-1;
+		if(originaltree[sizey]==';')
+		{
+			for(int fr=0; fr<sizey; fr++) newtree+=originaltree[fr];
+			newtree+=":0.0";
+		}
+		else newtree=originaltree;
+		
+//		if(depths.empty()) controlerrorprint2("[TREE]", name,"", "The treedepth command has misbehaved and the depths vector is empty.\n Please report this and it will be promptly fixed!","");
+				
+		return getnextdepth(newtree,depthsofar);
+	}
+	
+	double getnextdepth(string originaltree, double depthsofar)
+	{
+		vector<string> bits;
+		string s,t;
+
+		int bracketcount=1, pi;
+
+		if(originaltree[0]=='(')
+		{
+			//cout<<"Q"<<originaltree<<"W"<<endl;
+			for(pi=1; pi<originaltree.size(); pi++)
+			{
+				char c=originaltree[pi];
+				if(c=='(') bracketcount++;
+				if(c==')') bracketcount--;
+
+				//cout<<c<<"  "<<bracketcount<<endl;
+				if(bracketcount==1 && c==',') {bits.push_back(s); /*cout<<"S"<<s<<"S"<<endl;*/ s=""; continue;}
+				if(bracketcount==0) {bits.push_back(s);/* cout<<"SS"<<s<<"SS"<<endl; */break;}
+
+				s+=c;
+			}
+
+			//for(int yf=0; yf<bits.size(); yf++) cout<<bits.at(yf)<<endl;
+		
+//			if(!isitfirstgoo)
+//			{
+				s="";
+				
+				pi++;
+				if(originaltree[pi]!=':') { controlerrorprint2("[TREE]", name,"", "Something is wrong in the getnextdepthcommand.\n Please report this and it will be promptly fixed!",""); }
+		
+				
+				pi++;
+				for(int yg=pi; yg<originaltree.size(); yg++) s+=originaltree[yg];
+
+				/*cout<<"length to add "<<s<<endl;*/
+
+				depthsofar+=atof(s.c_str());
+
+//			}
+
+			vector<double> mydepths, mydistances;
+			vector<vector<double> > distances;
+			double mymax=0;
+			int sizey=bits.size();
+ 
+//			for(pi=0; pi<sizey; pi++) cout<<"R "<<bits.at(pi)<<endl; cout<<"****"<<endl;
+
+// these two lines ended up stuck in a loop on very deep trees!
+
+		//	for(pi=0; pi<sizey; pi++) mydepths.push_back(getnextdepth(bits.at(pi),depthsofar));
+
+		//	for(pi=0; pi<sizey; pi++) mydistances.push_back(getnextdepth(bits.at(pi),0));
+
+			for(pi=0; pi<sizey; pi++) 
+			{
+				double newdepth=getnextdepth(bits.at(pi),depthsofar);
+				mydepths.push_back(newdepth);
+				mydistances.push_back(newdepth-depthsofar);
+			}
+
+		
+			for(pi=0; pi<sizey; pi++) 
+			{
+	//			cout<<"    "<<mydepths.at(pi)<<endl;
+				if(mydepths.at(pi)>mymax) mymax=mydepths.at(pi);
+				
+				for(int pi2=0; pi2<sizey; pi2++)
+				{
+					if(pi==pi2) continue;
+				
+					double x=mydistances.at(pi)+mydistances.at(pi2);
+	//				cout<<"Q  "<<mydistances.at(pi)<<"  "<<mydistances.at(pi2)<<"  "<<x<<"  "<<max_distance<<endl;
+					if(x>max_distance) max_distance=x;
+				}
+			}
+			
+			return mymax;
+		}	
+		else
+		{
+			//end of the tree!!!
+
+			bool lengthon=false;
+
+			for(pi=0; pi<originaltree.size(); pi++)
+			{
+				if(lengthon) s+=originaltree[pi];
+
+				if(!lengthon) {	if(originaltree[pi]==':') lengthon=true;}
+			}
+
+			//cout<<"END LENGTH "<<s<<endl;
+
+			depthsofar+=atof(s.c_str());
+
+			return depthsofar;
+			//depths.push_back(depthsofar);
+
+		}
+		
+		return 0;
+	}	
+
+	////////////
+	double gettreelength(string originaltree)
+	{
+		// returns tree length of originaltree
+
+		int branch=0;
+		string mylength;
+		double treelength=0;
+		char c;
+
+		for(int uj=0; uj<originaltree.size(); uj++)
+		{
+			c=originaltree[uj];
+			if(c==',' || c==')') {branch=0; double length=atof(mylength.c_str()); treelength+=length; mylength="";}
+			if(branch==1) mylength+=c;
+			if(c==':') branch=1;
+		}
+
+	  return treelength;
+	}	 
+	/////
+
+	string rescaledtree(string originaltree, double treelength, double newtreelength)
+	{
+		// this function will rescale a tree according to a desired total tree length.
+
+		int branch=0;
+		string mylength, newtree;
+		char c;
+
+		for(int uj=0; uj<originaltree.size(); uj++)
+		{
+			c=originaltree[uj];
+			if(c==',' || c==')') 
+			{
+				branch=0; double length=atof(mylength.c_str()); 
+  				length=length*newtreelength/treelength; 
+				stringstream fd; fd<<length; string fg=fd.str(); 
+				newtree+=fg;
+				mylength="";
+			}
+			if(branch==1) mylength+=c;
+			else newtree+=c;
+			if(c==':') branch=1;
+		}
+
+	  return newtree;
+	}
+	///////////
+
+};
+//////////////////
+vector<Tree>	totaltrees;	   // storage for trees!
+
+//////////////////////////
+
+int dealwithtrees(vector<string> &block)		
+{
+	// this reads in tree information and pre-processes it for the tree class.
+	// it also checks whether the tree is inconsistent in any way.
+
+	int seed		  = 1;
+	int mysize		  = block.size();	
+	int blocksize	  = mysize-1;
+	int ntaxa         = 4;
+	
+	bool seedgiven=false;
+	int guidetreeroot = -1;
+	double scaler = -1, scalerd=-1, scalerm=-1;
+
+	// change the following to default values used in Yang et al. ?
+
+	// or make it so they must always be entered?
+
+	double birth  = 1;
+	double death  = 1;
+	double sample = 1;
+	double mut    = 1;
+
+	string commandsarray[8]={"[user]","[rooted]","[unrooted]","[seed]","[treedepth]","[treelength]","[branchlengths]","[maxdistance]"};
+	
+	string tree;
+	string doctorlengths="NO";
+ 
+	//rooted or unrooted then: "ntaxa" or "ntaxa birthrate deathrate samplingrate mutationrate"
+	
+	vector<string> commands(commandsarray,commandsarray+8);
+
+	//	cout<<mysize<<" is block size"<<endl;
+	
+	//	for(int i=0; i<mysize; i++) cout<<"trees "<<block.at(i)<<endl;
+	
+	if(mysize==0) {controlerrorprint2("[TREE]", "", "", "No tree name has been given","");  {if(breakonerror) return -1;} }
+
+	string name=block.at(0);
+
+	if(mysize==1) {controlerrorprint2("[TREE]", name, "","The tree block is empty.","");  {if(breakonerror) return -1;} }
+	
+	if(mysize==2) if(block.at(1)=="[user]") {controlerrorprint2("[TREE]", name, "","There is no tree in the tree block.","");  {if(breakonerror) return -1;} }
+	
+	string lastbit=block.at(blocksize);
+	if(lastbit[0]=='[') {controlerrorprint2("[TREE]", name, lastbit, "The last entry in a [TREE] block cannot be a command.","");  {if(breakonerror) return -1;} }
+
+	bool well[8]={false,false,false,false,false,false,false,false};
+
+	for(int p1=0; p1<mysize; p1++) 
+	{
+		string ss=block.at(p1);
+		for(int p2=0; p2<8; p2++) if(ss==commands.at(p2)) well[p2]=true;
+	}
+
+	if(well[0]) for(int p3=1; p3<4; p3++) if(well[p3]) {controlerrorprint2("[TREE]", name, commands.at(p3),"This command cannot be used in a user-defined tree block.",commands.at(p3));  {if(breakonerror) return -1;} }
+
+	bool doultra=false;
+
+	if((well[6])) 
+	{
+		for(int i1=1; i1<blocksize+1; i1++) 
+		{
+			string hg=block.at(i1); 
+			if(hg=="NON-ULTRAMETRIC" || hg=="ULTRAMETRIC") doultra=true;
+		}
+	}
+
+	if( !(well[0]) && well[6]) {controlerrorprint2("[TREE]", name, commands.at(6),"This command cannot be used in a random tree block.",commands.at(6));  {if(breakonerror) return -1;} }
+	
+	
+/*
+
+[rooted]
+[unrooted] ntaxa birthrate deathrate samplingrate mutationrate
+[guidetreeseed]
+[treelength]
+
+*/
+	string hg=block.at(0), hg1;
+//	if(hg[0]!='#' || hg[hg.size()-1]!='#') { controlerrorprint2("[MODEL]", "?", "", "First statement in a [MODEL] block must be a model name statement in the form #modelname#",""); {if(breakonerror) return -1;} }
+	if(!allAinB(hg,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[TREE]", name, "", "First statement in a [TREE] block must be a tree name statement.\nThe name should only contain  ,.;()-_ and alpha-numeric characters.",hg); {if(breakonerror) return -1;} }
+	else
+	{
+		if(checkthere(name,totaltreenames)!=-1) { controlerrorprint2("[TREE]", name, "", "A tree with this name has been specified twice.",""); {if(breakonerror) return -1;} }
+		else totaltreenames.push_back(name); 
+		
+	
+		vector<string> tempvec;
+		
+		string hg="";
+		int lasttest=-999;
+		int mytest=-999;
+
+		for(int i1=1; i1<blocksize+1; i1++) 
+		{
+			hg=block.at(i1); 
+		
+			lasttest=mytest;
+			if(block.at(i1-1)!="[branchlengths]") mytest=teststring(lasttest, hg, commands, "[TREE]","0123456789.",name);
+
+			if(mytest==-2) {if(breakonerror) return -1;} 
+			else 
+			{//a1
+			
+				if(i1==blocksize )  {tempvec.push_back(hg); } //cout<<"H1 "<<hg<<endl;}
+				
+				if(mytest==lasttest && i1!=blocksize )  {tempvec.push_back(hg);}// cout<<"H1 "<<hg<<endl;}
+				else if(i1!=1)
+				{//a2
+				
+					int tempsize=tempvec.size();
+
+					if(tempsize==0) {controlerrorprint2("[TREE]", name, commands.at(lasttest), "No values were found after this command in the control file.",""); {if(breakonerror) return -1;}  }
+					
+					else if(lasttest>2 && lasttest<8)
+					{
+						if(tempsize!=1) {/* cout<<tempvec.at(0)<<" "<<tempvec.at(1)<<" "<<tempvec.at(1 )<<" E"<<endl;*/ controlerrorprint2("[TREE]", name, commands.at(lasttest), "There should be only one value after this command in the control file.",""); {if(breakonerror) return -1;}  }
+	
+						string bit=tempvec.at(0);
+						
+						if(lasttest==3) 
+						{
+							if(AinB('.',bit)) {controlerrorprint2("[TREE]", name, commands.at(lasttest), "First value after this command should be an integer.",bit); {if(breakonerror) return -1;}  }
+
+							seedgiven=true;
+							seed=(atoi(bit.c_str()));	
+							// seed for random tree
+							//myinclude.at(8)=true;
+						}
+						else if(lasttest==5) 
+						{
+							scaler=atof(bit.c_str());				
+							// scaler for treelength				
+							// myinclude statement here?
+						}
+						else if(lasttest==4) 
+						{
+							scalerd=atof(bit.c_str());				
+							// scaler for treedepth				
+							// myinclude statement here?
+						}
+						else if(lasttest==6)
+						{
+							if(bit=="ULTRAMETRIC" || bit=="NON-ULTRAMETRIC" || bit=="EQUAL") doctorlengths=bit;
+							else  {controlerrorprint2("[TREE]", name, commands.at(lasttest), "This command can take the following values\n\"ULTRAMETRIC\"\n\"NON-ULTRAMETRIC\"\n\"EQUAL\"\nYou entered:",bit); {if(breakonerror) return -1;}  }
+						}
+						else if(lasttest==7) 
+						{
+							scalerm=atof(bit.c_str());				
+							// scaler for treedepth				
+							// myinclude statement here?
+						}
+					}
+					else if(lasttest==1 || lasttest==2)
+					{
+						if(lasttest==1) guidetreeroot=2; //rooted
+						else			guidetreeroot=1; //unrooted
+
+						string bit=tempvec.at(0);
+
+						if(AinB('.',bit)) {controlerrorprint2("[TREE]", name, commands.at(lasttest), "First value after this command should be an integer.",bit); {if(breakonerror) return -1;}  }
+						
+						// myinclude.at(3)=true;
+						ntaxa=atoi(bit.c_str());
+
+						if(tempsize!=1 && tempsize!=5)  
+						{
+							stringstream fg; fg<<tempsize; string fd=fg.str();
+							controlerrorprint2("[TREE]", name, commands.at(lasttest), "Found "+fd+" values but was expecting 1 integer, or \n1 integer and 4 decimal values after this command.",""); 
+							{if(breakonerror) return -1;}  
+						}
+						
+						
+						if(tempsize==5)
+						{
+							//myinclude.at(4)=true;
+							//myinclude.at(5)=true;
+							//myinclude.at(6)=true;
+							//myinclude.at(7)=true;
+							
+							birth=atof((tempvec.at(1)).c_str());
+							death=atof((tempvec.at(2)).c_str());
+							sample=atof((tempvec.at(3)).c_str());
+							mut=atof((tempvec.at(4)).c_str());
+						}
+						guidetreetype=2;
+
+					}
+					else 
+					{
+						// lasttest=0  [user]  user specified tree			
+						bool treeerror=false;
+						char c='q',c1='q',c2='q',c3='q',c4='q',c5='q',c6='q',c7='q',c8='q',c9='q',c10='q';
+						string rawvalue;
+						if(tempvec.size()==1) {rawvalue=tempvec.at(0);}// cout<<"RAWVALUE 1 "<<rawvalue<<endl;}
+						else 
+						{
+							for(int jh=0; jh<tempvec.size(); jh++) 
+							{
+								string bl=tempvec.at(jh);
+
+								//if(bl[0]=='[')	{controlerrorprint2("[TREE]", name, commands.at(lasttest), "No other command can be specified in a tree block with a user-defined tree",bl); {if(breakonerror) return -1;}  }
+
+								rawvalue+=bl;
+							}
+						}
+
+#ifdef checkingindelsubs
+
+// when checking substitutions for inserted sites, 
+// this bit of code adds a very small branch to the 
+// root of the tree so that many insertions can
+// be "forced" and then these inserted sites can be
+// observed to evolve along the tree for testing.
+
+	string temp="("; 
+	temp+=rawvalue;
+	temp[temp.size()-1]=':';
+	temp+="0.0001);";
+	rawvalue=temp;
+#endif
+						int size=rawvalue.size();
+
+						if(rawvalue[0]!='(' || rawvalue[size-1]!=';' || rawvalue[size-2]!=')')
+						{controlerrorprint2("[TREE]", name, commands.at(lasttest), "User defined tree does not appear to be a NEWICK format tree (...); ",rawvalue); {if(breakonerror) return -1;}  }
+
+						// if [branchlengths] command has been used then go through tree and 
+						if(well[6])
+						{
+							string rawvalue2, rawvalue3, rawvalue4;
+							char c, c1, c2;
+							
+							// strip lengths from tree if there
+							bool skip=false;
+							for(int ds2=0; ds2<rawvalue.size(); ds2++)
+							{
+								c=rawvalue[ds2];
+								if(c==':') skip=true;
+								if(skip && (c==',' || c==')') ) skip=false;
+								if(!skip) rawvalue2+=c;
+							}
+							
+							// add equal or random branch lengths back.
+							bool randomise; if(doultra)randomise=true;  else randomise=false;
+							//cout<<doctorlengths<<endl;
+							rawvalue3+=rawvalue2[0];
+							string newlength;
+
+							for(int ds1=1; ds1<rawvalue2.size()-1; ds1++)
+							{
+								c1=rawvalue2[ds1-1];
+								c =rawvalue2[ds1];
+								c2=rawvalue2[ds1+1];
+
+								if( (c==')' && c2!=';')  || (c2==')' && c!=')'))// ||  c1!=')') )
+								{
+									rawvalue3+=c;
+									rawvalue3+=':';
+									if(randomise)
+									{
+										double newlengthD=mtrand1();
+										stringstream xx; 
+										xx<<newlengthD;
+										newlength=xx.str();
+									}
+									else newlength="0.1";
+									rawvalue3+=newlength;
+								}
+								else if(c==',' && c1!=')')// && c1!=')') // || (c!=')' && c1!=')') )
+								{
+									
+									rawvalue3+=':';
+									if(randomise)
+									{
+										double newlengthD=mtrand1();
+										stringstream xx; 
+										xx<<newlengthD;
+										newlength=xx.str();
+									}
+									else newlength="0.1";
+									rawvalue3+=newlength;								
+									rawvalue3+=c;
+								}
+								else rawvalue3+=c;
+							}
+							rawvalue3+=';';
+						
+						//	cout<<rawvalue<<endl;
+							rawvalue=rawvalue3;
+						//	cout<<rawvalue2<<endl;
+						//	cout<<rawvalue3<<endl;
+						//	cout<<rawvalue4<<endl;
+						// 	cout<<rawvalue<<endl;
+							size=rawvalue.size();
+						}
+						
+						
+						int mybracketleft=0, mybracketright=0, taxaon=0, lengthon=0, rootbranches=0, bracketlevel=0; 
+
+						
+						for(int fg1=0; fg1<size; fg1++)  
+						{
+							c=rawvalue[fg1]; 
+							if(c=='(') {mybracketleft++; bracketlevel++;} 
+							if(c==')') {mybracketright++; bracketlevel--;}
+							if(bracketlevel==1 && c==',') rootbranches++;
+						}
+			
+						if(mybracketleft!=mybracketright) 	
+						{cout<<rawvalue<<endl<<mybracketleft<<"  "<<mybracketright<<endl;
+						treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "Number of parantheses in guide tree do not match.",""); {if(breakonerror) return -1;}  }
+
+						if(mybracketleft==0)  
+						{treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "Guide tree must contain as least one set of parentheses.",""); {if(breakonerror) return -1;}  }
+													
+						c1='Q'; c2='Q'; 
+						int taxacount=0, coloncount=0, intbranch=0, extbranch=0;
+						
+						string lasterror, currentlength;
+
+						for(int fg2=0; fg2<size; fg2++) 
+						{
+							c10=c9; c9=c8; c8=c7; c7=c6; c6=c5; c5=c4; c4=c3; c3=c2; c2=c1;  c1=rawvalue[fg2]; 
+							lasterror=""; lasterror+=c10;lasterror+=c9;lasterror+=c8;lasterror+=c7;lasterror+=c6;lasterror+=c5;lasterror+=c4;lasterror+=c3;lasterror+=c2;lasterror+=c1;
+						
+							if(c1==')' || c1=='(' || c1==',' && (taxaon==2 || lengthon==1) )
+							{
+								//if(taxaon==1 )	{treeerror=true; controlerrorprint(blocknumber, "There is no branch length in this taxon in the guide tree.",linecount,lasterror); if(breakonerror==1) {breakonerror=2; break;}}
+								if(taxaon==2)	{taxaon=3; taxacount++;}
+								if(lengthon==1) {lengthon=2;}
+							}					
+							
+							if(lengthon==2 || taxaon==3)
+							{
+								lengthon=0; taxaon=0;  
+								
+								int zerowarn=0;
+								for(int yg=0; yg<currentlength.size(); yg++)
+								{
+									c=currentlength[yg];
+									if(!AinB(c,"0.")) zerowarn=1;
+									if(!AinB(c,"0.123456789:")) {treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "A branch length in the guide tree appears non-numerical",""); {if(breakonerror) return -1;}  }
+									
+								}
+							//	if(zerowarn==0 && currentlength!="") {treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "This guide tree contains a zero branch length.  This is not necessary.\nPolytomies (of any order) are allowed at root (or any node) of guide tree.",""); {if(breakonerror) return -1;}  }
+							}
+												
+							if(lengthon==1 || taxaon==2) currentlength+=c1;
+							
+							if(c2==')' && c1!=';' && lengthon==0) 
+							{ 
+								if(c1!=':') {treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "There is no branch length after a right paranthesis in the tree.\nIt happened here \""+lasterror+"\"",""); {if(breakonerror) return -1;}  }
+								else {lengthon=1; currentlength="";}
+							}
+							
+							if(c1==')' || c1==',') 
+							{
+								if(!AinB(c2,"0123456789")) {treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "There is a missing branch length in the tree.\nIt happened here \""+lasterror+"\"",""); {if(breakonerror) return -1;}  }
+								else {lengthon=1; currentlength="";}
+							}
+							
+							if(c2!=')' && c2!='(' && c2!=',' && taxaon==0) {taxaon=1; }
+							if(taxaon==1 && c1==':') {taxaon=2; currentlength=""; }
+			
+							if(c1==':') {coloncount++; if(c2==')') intbranch++; else extbranch++;}
+
+							if(c2==':' && (c1!='0' && c1!='1' && c1!='2' && c1!='3' && c1!='4' && c1!='5' && c1!='6' && c1!='7' && c1!='8' && c1!='9' ) )
+								{treeerror=true; controlerrorprint2("[TREE]", name, commands.at(lasttest), "There is a missing branch length after a : in the guide tree",""); {if(breakonerror) return -1;}  }
+
+						}
+
+						if(!treeerror)
+						{	
+							tree=rawvalue;
+							guidetreetype=1;
+							ntaxa=extbranch;
+							if(rootbranches==0) ;//cout<<"1 taxon guide tree "<<rawvalue<<" entered. One branch will be simulated."<<endl<<" ";
+							else
+							{
+								if(extbranch==2 || extbranch==3) ;//cout<<"Guide tree of "<<extbranch<<" taxa read in successfully:"<<endl<<" "<<rawvalue<<endl<<" "<<endl<<" ";
+								else
+								{
+									if(intbranch==0) ;//cout<<"Guide tree read in as "<<extbranch<<" taxa star tree:"<<endl<<" "<<rawvalue<<endl<<" "<<endl<<" ";
+									else
+									{
+										int rootvalue=0;
+										if(rootbranches==1) rootvalue++;
+
+										
+										//cout<<extbranch<<" taxa "; 
+										if(coloncount!=2*extbranch-3 +rootvalue) guidetreebinary=false; else guidetreebinary=true;
+										if(rootbranches==1) guidetreerooted=true;
+										if(rootbranches==2) guidetreerooted=false;
+
+										//cout<<"guide tree with "<<intbranch+extbranch<<" branches read in successfully:"<<endl<<" "<<endl<<" "<<originaltree<<endl<<" "<<endl<<" ";
+										//if(coloncount!=2*taxacount-3 ) {cout<<"WARNING: guide tree is not binary."<<endl<<" ";}											
+									}
+								}
+							}
+									
+						
+						}
+
+
+					} // end of else for user tree
+				
+					tempvec.clear();
+
+				}// end of i1==1 if/else
+
+			} // end of mytest==-2 else
+
+		}//end of for block
+
+	} // end of initial else
+
+	if(scaler!=-1  && scalerd!=-1) 	{controlerrorprint2("[TREE]", name,"[treedepth]", "You cannot use [treelength] and [treedepth] at the same time!",""); {if(breakonerror) return -1;}  }
+	if(scaler!=-1  && scalerm!=-1) 	{controlerrorprint2("[TREE]", name,"[treelength]", "You cannot use [treelength] and [maxdistance] at the same time!",""); {if(breakonerror) return -1;}  }
+	if(scalerm!=-1 && scalerd!=-1)  {controlerrorprint2("[TREE]", name,"[treedepth]", "You cannot use [maxdistance] and [treedepth] at the same time!",""); {if(breakonerror) return -1;}  }
+
+	
+
+	if(guidetreetype==2) {tree="RANDOM"; if(scalerm!=-1) {scalerd=0.5*scalerm; scalerm=-1;}} // random trees always ultrametric, so max. pairwise distance i
+	totaltrees.push_back(Tree(seedgiven,tree,scaler,scalerd,ntaxa,birth,death,sample,mut,seed,guidetreeroot,name,doctorlengths,scalerm));
+	treeseeds.push_back(seed);
+	
+	return 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+class partitionclass
+{
+	// this class stores the information for simulations that use different partitions
+	// A partition may be a branch class, site class or model class.
+
+
+public:
+	string name;
+	int ntaxa;
+	bool randomtrees;
+
+	vector<int> geneticcodes;
+	vector<vector<int> > rootseqints;
+	vector<int> blank;
+	vector<int> mbsposvec;
+	vector<int> rootmodelpos;
+	vector<int> rootlengthvec;
+//	vector<int> ntaxavec;
+	vector<int> treeposvec;
+
+	vector<bool> isitsites;
+	vector<bool> isitbranches;
+//	vector<bool> isitrandomvec;
+
+
+
+	partitionclass(string myname, vector<int> rootlengths, vector<string> &rootseqtxtvec,  vector<string> rootfilenames, vector<int> mmbsposvec, vector<string> mbstypes, vector<string> mbnames, vector<int> mrootmodelpos, vector<int> geneticcodevec, vector<int> mytreeposvec, vector<string> mytreenamevec, int myntaxa, bool isitrandom)
+	{
+		// constructor
+
+		randomtrees=isitrandom;
+		geneticcodes=geneticcodevec;
+		name=myname;
+		mbsposvec=mmbsposvec;
+		rootlengthvec=rootlengths;
+		treeposvec=mytreeposvec;
+
+		checktaxaintrees(mytreeposvec);
+
+		ntaxa=myntaxa;
+		rootmodelpos=mrootmodelpos;
+//		isitrandomvec=myisitrandomvec;
+		
+		rootseqints.assign(rootseqtxtvec.size(),blank);
+
+		for(int kk=0; kk<rootseqtxtvec.size(); kk++) 
+		{
+			string mbstype=mbstypes.at(kk);
+			
+			if(mbstype=="model")    {isitsites.push_back(false); isitbranches.push_back(false);}
+			if(mbstype=="branches") {isitsites.push_back(false); isitbranches.push_back(true); }
+			if(mbstype=="sites")    
+			{
+				isitsites.push_back(true);
+				siteclass* s=&(totalsites.at(mbsposvec.at(kk)));
+				bool now=(*s).therearebranches;
+				isitbranches.push_back(now);
+			}
+			
+			makerootseqints(rootseqints.at(kk),rootlengths, rootseqtxtvec.at(kk), kk, mbsposvec.at(kk), rootfilenames, mbstype, mbnames, geneticcodevec);
+		}
+	}
+
+private:
+	
+	int checktaxaintrees(vector<int> posvec)
+	{
+		Tree t=totaltrees.at(posvec.at(0));
+
+		int ntaxa=t.ntaxa;
+
+		for(int p=1; p<posvec.size(); p++)
+		{
+			Tree t=totaltrees.at(posvec.at(p));
+			if(t.ntaxa != ntaxa) 
+			{
+				stringstream n1, n2; n1<<ntaxa; n2<<t.ntaxa; string s1=n1.str(), s2=n2.str(); string name1=(totaltrees.at(posvec.at(0))).name, name2=(totaltrees.at(posvec.at(p))).name;
+				controlerrorprint2("[PARTITIONS]", name, "", "Two trees in this partition group have a different number of taxa.\nTree "+name1+" has "+s1+" taxa.\nTree "+name2+" has "+s2+" taxa.\nThis is not allowed. Please correct.",""); 
+				if(breakonerror) return -1; 	
+			}
+
+		}
+	
+		return 0;
+	}
+
+	
+	int makerootseqints(vector<int> &rootseqint, vector<int> rootlengths, string &rootseqtxt, int kk, int mbspos, vector<string> rootfilenames, string mbstype, vector<string> mbnames, vector<int> geneticcodevec)
+	{
+		int rootlength=rootlengths.at(kk);
+		int myrootlength=rootseqtxt.size();
+		int geneticcode=geneticcodevec.at(kk);
+		
+		string rootfilename=rootfilenames.at(kk);
+		string mbname=mbnames.at(kk);
+
+		if(rootseqtxt=="CREATE")
+		{
+			// CREATION OF ROOT SEQUENCE NOW DONE IN SETUPROOT FUNCTION IN MAIN SKELETON FILE
+
+			/*
+			model* m=&(totalmodels.at(mbspos));
+
+			vector<double> rootbasefreqs=(*m).rootbasefreqs;
+			vector<double> cumfreqs; cumfreqs.push_back(rootbasefreqs.at(0));
+			int rsize=rootbasefreqs.size();
+			
+			for(int gh1=1; gh1<rsize; gh1++) cumfreqs.push_back(rootbasefreqs.at(gh1)+cumfreqs.at(gh1-1));
+
+			double diff=1-cumfreqs.back(); if(diff<0) diff=-diff;
+			if(diff>0.0001) {controlerrorprint2("[PARTITIONS]", name, "", "INTERNAL ERROR: root base freqs do not sum to 1 in partitions class.",""); {if(breakonerror) return -1;} }	
+
+			for(int gf=0; gf<rootlength; gf++) 
+			{
+				double rand=mtrand1(); 
+				for(int ds=0; ds<rsize; ds++) if(rand<cumfreqs.at(ds)) {rootseqint.push_back(ds); break;}
+			}
+
+			//for(int as=0; as<rootseqint.size(); as++) cout<<as<<" "<<rootseqint.at(as)<<endl; cout<<endl;	
+			*/
+		}
+		else
+		{
+				if(type==2)
+				{
+					string test="ARNDCQEGHILKMFPSTWYVarndcqeghilkmfpstwyv";
+					if(!allAinB(rootseqtxt,test)) { controlerrorprint2("[PARTITIONS]", name, "", "AMINOACID root sequence in file can only contain following letters:\nARNDCQEGHILKMFPSTWYVarndcqeghilkmfpstwyv",""); {if(breakonerror) return -1;} }
+					
+					int size=20;
+
+					/*
+						//always equal now
+					if(rootlength!=myrootlength) 
+					{
+						stringstream rr1; rr1<<rootlength;   string r1=rr1.str();
+						stringstream rr2; rr2<<myrootlength; string r2=rr2.str();
+						controlerrorprint2("[PARTITIONS]", name, "", "In partitions command you specified a root length of "+r1+"\nbut in file "+rootfilename+"\nthe root sequence has a length of "+r2+" amino acids.\nThe two numbers should match.  Have you made a mistake?",""); 
+						{if(breakonerror) return -1;} 
+					}
+					*/
+
+					for(int fd0=0; fd0<myrootlength; fd0++)
+					{
+						char c=rootseqtxt[fd0];
+						bool error=true;
+						
+						for(int fd1=0; fd1<size; fd1++) if(c==test[fd1] || c==test[fd1+size]) {error=false; rootseqint.push_back(fd1); break;}
+						
+						if(error) { controlerrorprint2("[PARTITIONS]", name, "", "INTERNAL ERROR when making NUCLEOTIDE root sequence.",""); {if(breakonerror) return -1;} }		
+					}
+				}
+				else
+				{
+					string test="TCAGtcag", bit;
+					if(type==1) bit="NUCLEOTIDE"; else bit="CODON";
+				
+					if(!allAinB(rootseqtxt,test)) { controlerrorprint2("[PARTITIONS]", name, "", bit+" root sequence in file can only contain following letters:\nTCAGtcag",""); {if(breakonerror) return -1;} }		
+			
+					
+
+					int size=4;
+					if(type==1) 
+					{
+						/*
+						//always equal now
+						if(rootlength!=myrootlength) 
+						{
+							stringstream rr1; rr1<<rootlength;   string r1=rr1.str();
+							stringstream rr2; rr2<<myrootlength; string r2=rr2.str();
+							controlerrorprint2("[PARTITIONS]", name, "", "In partitions command you specified a root length of "+r1+"\nbut in file "+rootfilename+"\nthe root sequence has a length of "+r2+" nucleotide bases.\nThe two numbers should match.  Have you made a mistake?",""); 
+							{if(breakonerror) return -1;} 
+						}	
+						*/
+						size=4; 
+						for(int fd0=0; fd0<myrootlength; fd0++)
+						{
+						//	char cc=s[fd0];
+						//	stringstream ccc; ccc<<cc; string c=ccc.str();
+						
+							bool error=true;
+							char c=rootseqtxt[fd0];
+						
+							for(int fd1=0; fd1<size; fd1++) if(c==test[fd1] || c==test[fd1+size]) {error=false; rootseqint.push_back(fd1); break;}
+														
+							if(error) { controlerrorprint2("[PARTITIONS]", name, "", "INTERNAL ERROR when making "+bit+" root sequence.",""); {if(breakonerror) return -1;} }		
+						}
+					}
+					else
+					{ 
+						if(myrootlength%3!=0) 
+						{
+							stringstream rd; rd<<myrootlength; string rdd=rd.str();
+							controlerrorprint2("[PARTITIONS]", name, "", "CODON root sequence length is "+rdd+" nucleotides in the file\nbut must be a multiple of 3.",""); 
+							{if(breakonerror) return -1;} 
+						}		
+					
+						/*
+						if(rootlength!=myrootlength/3) 
+						{
+							stringstream rr1; rr1<<rootlength;   string r1=rr1.str();
+							stringstream rr2; rr2<<myrootlength/3; string r2=rr2.str();
+							controlerrorprint2("[PARTITIONS]", name, "", "In partitions command you specified a root length of "+r1+"\nbut in file "+rootfilename+"\nthe root sequence has a length of "+r2+" codons.\nThe two numbers should match.  Have you made a mistake?",""); 
+							{if(breakonerror) return -1;} 
+						}
+						*/
+
+						///////////////////////////////////////////////////////////////////////
+
+						vector<int> notallowed=getstops(geneticcode);
+
+						/*  //OLD WAY
+						vector<int> notallowed;
+
+						if(geneticcode!=6 && geneticcode!=12) notallowed.push_back(10);
+						if(geneticcode!=6 && geneticcode!=13) notallowed.push_back(11);
+						if(geneticcode==0 || geneticcode==6 || geneticcode==9 || geneticcode==10 || geneticcode==13) notallowed.push_back(14);
+						if(geneticcode==1) {notallowed.push_back(46); notallowed.push_back(47);}
+						*/
+
+						int notsize=notallowed.size();
+
+						stringstream we; we<<geneticcode; string wer=we.str();
+
+						for(int fd0=2; fd0<myrootlength; fd0=fd0+3)
+						{
+							char c1=rootseqtxt[fd0-2], c2=rootseqtxt[fd0-1], c3=rootseqtxt[fd0];	
+							bool error1=true, error2=true, error3=true;
+							int i1,i2,i3,tot;
+
+							for(int fd1=0; fd1<size; fd1++) 
+							{
+								if(c1==test[fd1])      {i1=fd1; error1=false;}
+								if(c1==test[fd1+size]) {i1=fd1; error1=false;}
+								if(c2==test[fd1])      {i2=fd1; error2=false;}
+								if(c2==test[fd1+size]) {i2=fd1; error2=false;}
+								if(c3==test[fd1])      {i3=fd1; error3=false;}
+								if(c3==test[fd1+size]) {i3=fd1; error3=false;}
+							
+							}
+								
+							if(error1 || error2 || error3) { controlerrorprint2("[PARTITIONS]", name, "", "INTERNAL ERROR when making "+bit+" root sequence.",""); {if(breakonerror) return -1;} }		
+							
+							tot=(i1<<4)+(i2<<2)+i3; //cout<<tot<<endl;
+
+							for(int fd2=0; fd2<notsize; fd2++) if(tot==notallowed.at(fd2)) 
+							{
+								stringstream m; m<<fd0/3+1; string mm=m.str();
+								controlerrorprint2("[PARTITIONS]", name, "", "Root sequence file: "+rootfilename+"\nThis root sequence contains the codon "+c1+c2+c3+" at position "+mm+"\nBut "+mbstype+" class "+mbname+" uses genetic code "+wer+".\nUnder this genetic code "+c1+c2+c3+" is a stop codon and is not allowed.",""); 
+								{if(breakonerror) return -1;} 
+							}		
+														
+							rootseqint.push_back(tot); 
+							
+						}
+
+						myrootlength/=3;
+
+					} // end of type=3 else in type1/type3 else
+
+				} // end of type1/type3 else
+
+
+		}
+		
+		return 0;
+	}
+
+};
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+vector<partitionclass> totalpartitions;   // storage for partitions
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+int dealwithpartitions(vector<string> &block)	
+{
+	// this function deals with information in the control file about partitions and pre-processes it for the class constructor
+
+	int mymy=block.size();
+	string name;
+	if(mymy==0) {controlerrorprint2("[PARTITIONS]", "", "", "You must specify a name for a partitions block. This one is empty.",""); {if(breakonerror) return -1;}  }
+	else
+	{
+		name=block.at(0);
+		if(!allAinB(name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SITES]", name, "", "First statement in a [PARTITIONS] block must be a name statement.\nThe name should only contain  ,.;()-_ and alpha-numeric characters.",""); {if(breakonerror) return -1;} }		
+
+		if(checkthere(name,totalpartitionnames)!=-1)
+		{ controlerrorprint2("[PARTITIONS]", name, "", "A partitions class with this name has been specified twice.",""); {if(breakonerror) return -1;} }
+		else totalpartitionnames.push_back(name); 
+	
+	}
+
+	if(mymy==1) {controlerrorprint2("[PARTITIONS]", name, "", "This partitions block contains no commands.",""); {if(breakonerror) return -1;}  }
+
+	int count=0;
+	if(mymy>1)
+	{
+		string ss1=block.at(1);
+		string ss2=block.at(mymy-1);
+		int ss2s=ss2.size()-1;
+		if(ss1[0]!='[') {controlerrorprint2("[PARTITIONS]", name, "", "First statement in a partitions block must begin with a [. check input.",""); {if(breakonerror) return -1;}  }
+		if(ss2[ss2s]!=']') {controlerrorprint2("[PARTITIONS]", name, "", "Last statement in a partitions block must end with a ]. check input.",""); {if(breakonerror) return -1;}  }
+	}
+
+	int mbspos;
+	string mbstype,tree,treename, rootseqtxt, strippedtree;
+	int treepos, rootlength;
+	vector<int> ntaxavec, rootlengthvec, mbsposvec;
+	vector<string> treenamevec, mbnamevec, mbstypevec, rootseqtxtvec, rootfilenamevec;
+	vector<int> treeposvec, rootseqint, rootmodelpos, geneticcodevec;
+
+	bool isitrandom=false, overallrandom=false;
+	int geneticcode;
+
+	string mbname;
+
+	for(int k=1; k<mymy; k++)
+	{
+		string s=block.at(k), t;
+		if(s=="") continue;
+		count++;
+
+		if(s[s.size()-1]==']') 
+		{
+			//cout<<"SS "<<s<<endl;
+			if( count!=3 && s!="]") 
+			{
+				//cout<<"Q"<<s<<"Q"<<endl;
+				stringstream ds; if(s=="]") count--; ds<<count; string dss=ds.str();
+				controlerrorprint2("[PARTITIONS]", name, "", "Statement [..] in a partitions block must contain 3 elements not "+dss+":\n[tree1 model/branchclass/siteclass rootlength] or "+"\n[tree2 model/branchclass/siteclass rootseqfilename]\nConsult manual for more information.",""); {if(breakonerror) return -1;}  
+			}
+		
+			t=s; s=""; for(int gj=0; gj<t.size()-1; gj++) s+=t[gj];
+		}
+
+		if(s[0]=='[') 
+		{
+			count=1;
+			if(s=="["){k++; s=block.at(k);}
+			else{t=s; s=""; for(int gj=1; gj<t.size(); gj++) s+=t[gj];}
+		}
+
+		if(count==1)
+		{
+			//expect tree
+			strippedtree="";
+
+			//cout<<"partitions tree "<<s<<endl;
+			if(!allAinB(s,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SITES]", name, "", "The tree name should only contain  ,.;()-_ and alpha-numeric characters.",""); {if(breakonerror) return -1;} }		
+
+			treename=s;	
+			treepos=checkthere(treename,totaltreenames);
+			
+			//cout<<totaltaxa.size()<<" W "<<totaltreenames.size()<<endl;
+
+			if(treepos==-1) 
+			{controlerrorprint2("[PARTITIONS]", name, "", "No tree named \""+treename+"\" has been defined.","");  {if(breakonerror) return -1;} }
+			else
+			{
+				Tree* testtree=&(totaltrees.at(treepos));
+		
+				tree=(*testtree).tree;
+				for(int qw=0; qw<tree.size(); qw++) {char c=tree[qw]; if(c==')' || c=='(' || c==',' || c==';') strippedtree+=c;}
+				treeposvec.push_back(treepos);
+
+				treenamevec.push_back(treename);
+				ntaxavec.push_back((*testtree).ntaxa);
+
+				isitrandom=(*testtree).treerandom;  if(isitrandom) overallrandom=true;
+//				isitrandomvec.push_back(isitrandom);
+		
+				
+		
+				// if tree random it cannot be used with branch class .
+				// else for this case strip it down to check branchclass tree.
+			}
+		}
+		else if(count==2)
+		{
+			//expect model/branchclass/siteclass name
+			
+			//cout<<"partitions mbs name "<<s<<endl;
+			if(!allAinB(s,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[SITES]", name, "", "The model/branch class/site class name should only contain  \n,.;()-_ and alpha-numeric characters.",s); {if(breakonerror) return -1;} }		
+
+			mbname=s;
+			mbspos=checkthere(mbname,totalmodelnames);
+			
+			if(mbspos==-1) 
+			{
+				mbspos=checkthere(mbname,totalbranchesnames); 
+				
+				if(mbspos==-1) 
+				{
+					mbspos=checkthere(mbname,totalsitenames); 
+				
+					if(mbspos==-1) 
+					{
+						controlerrorprint2("[PARTITIONS]", name, "", "You specified \""+mbname+"\" in this partitions class.\nNo model/branch/sites class with this name has been defined.",""); 
+						{if(breakonerror) return -1;} 
+					}
+					else 
+					{
+						siteclass* s=&(totalsites.at(mbspos));
+
+						if(isitrandom && (*s).therearebranches) 
+						{controlerrorprint2("[PARTITIONS]", name, "", "\""+treename+"\" is a random tree.\n\""+mbname+"\" is a sites class that contains at least one branch class.\nThis combination is not allowed.  Guide tree must be user specified.","");  {if(breakonerror) return -1;} }
+					
+						else 
+						{
+							mbstype="sites";			
+							geneticcode=(*s).geneticcode;
+							string strippedtree2=(*s).mbtree;
+							bool anerror=false;
+
+							if(!(*s).therearebranches) {}
+							else if(strippedtree.size()!=strippedtree2.size()) anerror=true;
+							else for(int we=0; we<strippedtree.size(); we++)
+							{
+								char c1=strippedtree[we]; char c2=strippedtree2[we];
+								if(c1!=c2) {anerror=true; break;}
+							}
+
+							if(anerror)	{controlerrorprint2("[PARTITIONS]", name, "", "Guide tree (1) does not match the tree used in \nsites class "+mbname+" (2).\n1) "+strippedtree+"\n2) "+strippedtree2+"\nThe trees must have their taxa/branches written in identical order.",""); {if(breakonerror) return -1;} }
+
+						}
+					}
+				
+				}
+				else if(isitrandom) {controlerrorprint2("[PARTITIONS]", name, "","\""+treename+"\" is a random tree.\n\""+mbname+"\" is a branches class.\nThis combination is not allowed.  Guide tree must be user specified.","");  {if(breakonerror) return -1;} }
+
+				else 
+				{
+					mbstype="branches";		
+					branchclass* b=&(totalbranches.at(mbspos));
+
+					geneticcode=(*b).geneticcode;
+					string strippedtree2=(*b).baretree;
+
+					bool anerror=false;
+					if(strippedtree.size()!=strippedtree2.size()) anerror=true;
+					else for(int we=0; we<strippedtree.size(); we++)
+					{
+						char c1=strippedtree[we]; char c2=strippedtree2[we];
+						if(c1!=c2) {anerror=true; break;}
+					}
+					if(anerror)	{controlerrorprint2("[PARTITIONS]", name, "", "Guide tree (1) does not match the tree used in \nbranches class "+mbname+" (2).\n1) "+strippedtree+"\n2) "+strippedtree2+"\nThe trees must have their taxa/branches written in identical order.",""); {if(breakonerror) return -1;} }
+					
+				}
+
+			}
+			else 
+			{
+				mbstype="model";
+				model* m=&(totalmodels.at(mbspos));
+				geneticcode=(*m).geneticcode;
+			}
+			mbstypevec.push_back(mbstype);
+			mbsposvec.push_back(mbspos);
+			mbnamevec.push_back(mbname);
+			geneticcodevec.push_back(geneticcode);
+		}
+		else if(count==3)
+		{
+			// expect either a root length, for use in creating root sequence, or a filename containing a root sequence to be read in.
+
+			if(allAinB(s,"1234567890")) 
+			{	
+				// i.e. entry is numerical, it is a root length
+				rootfilenamevec.push_back("NONE");
+				rootseqtxtvec.push_back("CREATE");
+				rootlength=atoi(s.c_str());	
+
+				if(rootlength==0) { controlerrorprint2("[PARTITIONS]", name, "", "The root length must be an integer greater than zero.",s); {if(breakonerror) return -1;} }
+	
+				rootlengthvec.push_back(rootlength);
+
+			}
+			else
+			{			
+				// get root sequence
+				ifstream if1;
+				if1.open(s.c_str());
+				if(!if1.good()){ controlerrorprint2("[PARTITIONS]", name, "", "1) This entry is not a positive integer representing a root length.\n2) No root sequence file with this name exists in the program directory.\nPlease format partition sections of the control file as described in the manual",s); {if(breakonerror) return -1;} }		
+				else rootfilenamevec.push_back(s);
+	
+				string test="TCAGtcag";
+				if(type==2) test="ARNDCQEGHILKMFPSTWYVarndcqeghilkmfpstwyv";
+				char c='\n';
+
+				while(if1.good())
+				{
+					if(AinB(c,test) && !AinB(c,"\n\r\t ")) rootseqtxt+=c;
+					else 
+					{
+						if(!AinB(c,"\n\r\t "))
+						{
+							string bit="NUCLEOTIDE";
+							if(type==2) bit="AMINOACID";
+							if(type==3) bit="CODON";
+							string s; s+=c;
+							controlerrorprint2("[PARTITIONS]", name, "", bit+" root sequence in file can only contain following letters:\n"+test,s); {if(breakonerror) return -1;} 
+						}
+					}
+					c=if1.get();
+				}
+				
+				rootseqtxtvec.push_back(rootseqtxt);
+				rootlengthvec.push_back(rootseqtxt.size());
+
+			} // end of else for if rootseqfilename 
+						
+		} // end of else bracket for 3rd element.
+
+		/*
+				// old way of doing step 3 in two steps....... changed to make root sequence creation the default
+
+		else if(count==3)
+		{
+			if(allAinB(s,"1234567890")) rootlength=atoi(s.c_str());		
+			else { controlerrorprint2("[PARTITIONS]", name, "", "The root length must be an integer greater than zero.",s); {if(breakonerror) return -1;} }
+			if(rootlength==0) { controlerrorprint2("[PARTITIONS]", name, "", "The root length must be an integer greater than zero.",s); {if(breakonerror) return -1;} }
+
+			rootlengthvec.push_back(rootlength);
+		}
+		else if(count==4)
+		{
+			
+			//int ans=checkthere(s,totalmodelnames);
+				
+			//if(ans!=-1) 
+			//{
+			//	model* m=&(totalmodels.at(ans));
+			//	int geneticcode2=(*m).geneticcode;
+
+			//	if(geneticcode!=geneticcode2)
+			//	{ 
+			//		string type;
+			//		if(mbstype=="model") type="Model";
+			//		if(mbstype=="branches") type="Branch class";
+			//		if(mbstype=="sites") type="Sites class";
+					
+			//		stringstream ss1;ss1<<geneticcode; string sss1=ss1.str();
+			//		stringstream ss2;ss2<<geneticcode2;string sss2=ss2.str();
+
+			//		controlerrorprint2("[PARTITIONS]", name, "", type+" \""+mbname+"\" has genetic code "+sss1+"\nbut root model \""+s+"\" has genetic code "+sss2,""); {if(breakonerror) return -1;} 
+			//	}
+			
+
+			//	rootfilenamevec.push_back("NONE");
+			//	rootmodelpos.push_back(ans);
+			//	rootseqtxtvec.push_back("CREATE");
+			//}
+			//else
+			
+			if(s=="CREATE")
+			{
+				rootfilenamevec.push_back("NONE");
+				//rootmodelpos.push_back(ans);
+				rootseqtxtvec.push_back("CREATE");
+			}
+			else
+			{			
+				// get root sequence
+				ifstream if1;
+				if1.open(s.c_str());
+				if(!if1.good()){ controlerrorprint2("[PARTITIONS]", name, "", "No model with this name has been specified.\nNo root sequence file with this name exists in the program directory.",s); {if(breakonerror) return -1;} }		
+				else rootfilenamevec.push_back(s);
+	
+				string test="TCAGtcag";
+				if(type==2) test="ARNDCQEGHILKMFPSTWYVarndcqeghilkmfpstwyv";
+				char c='\n';
+
+				while(if1.good())
+				{
+					if(AinB(c,test) && !AinB(c,"\n\r\t ")) rootseqtxt+=c;
+					else 
+					{
+						if(!AinB(c,"\n\r\t "))
+						{
+							string bit="NUCLEOTIDE";
+							if(type==2) bit="AMINOACID";
+							if(type==3) bit="CODON";
+							string s; s+=c;
+							controlerrorprint2("[PARTITIONS]", name, "", bit+" root sequence in file can only contain following letters:\n"+test,s); {if(breakonerror) return -1;} 
+						}
+					}
+					c=if1.get();
+				}
+				
+				rootseqtxtvec.push_back(rootseqtxt);
+
+			} // end of else for if rootseqfilename
+						
+		} // end of else bracket for 4th element.
+
+		*/
+
+
+
+
+	} //	end of for(int k=1; k<mymy; k++) bracket
+
+	int t1=ntaxavec.at(0), t2;
+	for(int ft=1; ft<ntaxavec.size(); ft++) 
+	{
+		// this bracket simply compares guide trees being used by different partitions in a simulation.
+		// They can be different but they need to have the same number of external branches
+
+		t2=t1; t1=ntaxavec.at(ft);
+
+		if(t2!=t1)
+		{
+			string n1=treenamevec.at(ft);
+			string n2=treenamevec.at(ft-1);
+			stringstream t1ss,t2ss;
+			t1ss<<t1; t2ss<<t2;
+			string t1s=t1ss.str();
+			string t2s=t2ss.str();
+			controlerrorprint2("[PARTITIONS]", name, "", "Guide tree \""+n1+"\" has "+t1s+" taxa.\nGuide tree \""+n2+"\" has "+t2s+" taxa.\nGuide trees in different partitions can differ but the \ntotal number of external branches must be constant.",""); 
+			{if(breakonerror) return -1;} 
+		}
+	}
+	
+	totalpartitions.push_back(partitionclass(name,rootlengthvec, rootseqtxtvec, rootfilenamevec, mbsposvec, mbstypevec, mbnamevec, rootmodelpos, geneticcodevec,treeposvec,treenamevec,t1,overallrandom));
+//	totalpartitions.push_back(partitionclass(treeposvec,treenamevec,rootlengthvec,mbnamevec,mbstypevec,mbsposvec,rootseqtxtvec));
+
+
+	return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class evolve
+{
+	// real simple class!
+	// this is the one that links it all together.
+	// Each instance of the class evolve is a standalone simulation of a partition that contains a branch class, or a model or so on....
+
+	public:
+	int reps;
+	int partitionpos;
+	string filenamestub;
+	
+	evolve(int myreps, int mypartitionpos, string myfilenamestub)
+	{
+		reps=myreps;						// number of replicates
+		partitionpos=mypartitionpos;		// position in totalpartitions of the partition in question
+		filenamestub=myfilenamestub;		// filenamestub which is used to create output filenames
+	}
+};
+
+vector<evolve> totalevolve;		// storage for the evolve class instances.
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+int dealwithevolve(vector<string> &block)		
+{
+	//	this function pre-processes the evolve blocks for the class evolve.   pretty self explanatory,.... at least it should be.
+
+	int size=block.size()-1, partitionpos, reps;
+
+	string filenamestub;
+
+	if(size==0) {controlerrorprint2("[EVOLVE]","","","The block is empty.",""); {if(breakonerror) return -1;} }
+//	cout<<"size "<<size<<endl;
+	if(size%3!=0) {controlerrorprint2("[EVOLVE]","","","The Evolve block must contain a multiple of 3 statements:\nPartitionClassName1  NumberOfReps1  FilenameStub1\nPartitionClassName2  NumberOfReps2  FilenameStub2\nand so on..."/*\nIf you have followed this instruction then the error may be caused\nas there is no white space after the last entry in the control file!\nPlease put a space or a new line after your last entry in this case"*/,""); {if(breakonerror) return -1;} }
+
+	string s1,s2,s3,t1,t2,t3;
+	int ans;
+	for(int j=2; j<size; j=j+3) 
+	{
+//		stringstream tt1,tt2,tt3; tt1<<j-2; tt2<<j-1; tt3<<j; t1=tt1.str(); t2=tt2.str(); t3=tt3.str();
+
+		s1=block.at(j-2); s2=block.at(j-1); s3=block.at(j);
+
+		if(!allAinB(s1,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;()-_")) { controlerrorprint2("[EVOLVE]", "", "", "Partition class names should only contain  ,.;()-_ \nand alpha-numeric characters.",s1); {if(breakonerror) return -1;} }		
+		ans=checkthere(s1,totalpartitionnames);
+		if(ans==-1) {controlerrorprint2("[EVOLVE]","","","No partitions block called "+s1+" has been defined.",""); {if(breakonerror) return -1;} }
+		else partitionpos=ans;
+
+		if(!allAinB(s2,"123456780")) { controlerrorprint2("[EVOLVE]", "", "", "Number of repetitions must be an integer value",s2); {if(breakonerror) return -1;} }		
+		else reps=atoi(s2.c_str());				
+		
+		if(!allAinB(s3,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.;/()-_")) { controlerrorprint2("[EVOLVE]", "", "", "Filename stubs should only contain  ,.;()-_ and alpha-numeric characters.",s3); {if(breakonerror) return -1;} }		
+		else 
+		{
+			filenamestub=s3;		
+			bool error=false;
+			for(int i=0; i<totalevolve.size(); i++)
+			{
+				if( (totalevolve.at(i)).filenamestub==filenamestub ) error=true;
+			}
+			if(error) {controlerrorprint2("[EVOLVE]", "", "", "Several lines in the [EVOLVE] block contain the same filename stub.\nThis will cause output files to be overwritten - please correct.",s3); {if(breakonerror) return -1;} }		
+	
+		}
+
+		// cout<<partitionpos<<" "<<reps<<" "<<filenamestub<<endl;
+		totalevolve.push_back(evolve(reps,partitionpos,filenamestub));
+
+	}
+
+	return 0;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+string paupstart, paupmiddle, paupend;
+
+int docontrol()
+{		
+	// this is the main function that processes the control file and calls the other relevant processing functions
+
+	int isthereanerror=0;
+	ifstream if1;
+	if1.open(masterfilename.c_str());
+
+	char c1='q', c2='q'; //,c2,c3,c4,c5,c6;
+	bool notwhitespace=true;
+	string s, newfilename=masterfilename;
+	vector<string> sv;
+
+
+	// get command blocks if they exist
+	ifstream paups, paupm, paupf;
+
+	paups.open("paupstart.txt");
+	paupm.open("paupmiddle.txt");	
+	paupf.open("paupend.txt");
+
+	while(paups.good()) {char c=paups.get(); if(c!='�') paupstart+=c; }//cout<<c<<endl;}   
+	while(paupm.good()) {char c=paupm.get(); if(c!='�') paupmiddle+=c; }//cout<<c<<endl;}
+	while(paupf.good()) {char c=paupf.get(); if(c!='�') paupend+=c; }//cout<<c<<endl;}
+
+	if(paupstart!="") paupstart+="\n\n";
+	if(paupmiddle!="") paupmiddle+="\n"; paupmiddle+="\n";
+	if(paupend!="") paupend+="\n\n";
+
+	bool writeon=true;
+	string s1,s2,s3;
+	if(!if1.good()) 
+	{
+		bool waste=true;
+		for(int qa=0; qa<10; qa++)
+		{
+			// this prompts for a different control file name if there is no file sharing name of masterfilename that is hardwired in code.
+
+			controlerrorprint2("CONTROL FILE","","","There is no control file. INDELible was looking for file named:\n" +newfilename+"\nPlease enter the correct filename.","");  
+			
+			cin>>newfilename;
+
+			if1.open(newfilename.c_str());
+
+			if(if1.good()) {waste=false; break;}
+		}
+		
+		if(waste)
+		{
+			controlerrorprint2("CONTROL FILE","","","There is no control file. INDELible was looking for file named:\n" +newfilename+"\n10 failed attempts - please check your filenames and re-run INDELible.","");  
+			isthereanerror=-1;
+			return -1;
+		}
+	}
+	
+
+	/*
+		// old way of reading in control file 
+
+		while(if1.good())
+		{
+			// ignore comment lines in command file
+			getline(if1,s1); s3="";
+			if(s1[0]!='/' && s1[1]!='/') 
+			{
+				for(int rd=0; rd<s1.size(); rd++) 
+				{
+					if(s1[rd]=='/' ) break; //&& (s1[rd+1]=='/' || s1[rd+1]=='\n' || s1[rd+1]=='\r')) break;
+					else s3+=s1[rd];
+				}
+				s2+=s3; s2+='\n';
+			}
+		}
+
+		for(int hb=0; hb<s2.size(); hb++)
+		{
+			c2=c1; c1=s2[hb];  
+			//if(c2=='/' && c1=='*') writeon=false;
+			
+			if(writeon)
+			{	
+				if(AinB(c1," \n\r\t")) {if(s!="") sv.push_back(s); s="";}
+				else{s+=c1;}
+			}
+
+		}
+		sv.push_back(s);
+	*/
+
+
+	vector<char> temp1, temp2, temp3;
+
+	temp1.push_back(' ');   // to prevent crashes at *1 below
+	while(if1.good()) {char c=if1.get(); temp1.push_back(c); originalcontrol.push_back(c);}          // parse control file character by character into temp1
+	temp1.push_back('\n');  // to prevent crashes at *2 below, and also if control file does not end in new line..
+
+	bool WR=true;
+
+	int mymycount=0;
+
+	for(int th1=1; th1<temp1.size()-1; th1++)
+	{
+		// this for loop will weed out any commented text between /* .... */ in the control file (from temp1 to temp2)
+
+		if(temp1.at(th1) == '/' && temp1.at(th1+1)=='*') {WR=false; mymycount++;}  ///// *1
+
+		if(WR) temp2.push_back(temp1.at(th1));
+
+		if(temp1.at(th1-1)=='*' && temp1.at(th1) == '/') {WR=true; mymycount--;}   ///// *2
+
+		if(mymycount<0)  {controlerrorprint2("CONTROL FILE","","","There is a '*/' statement without a preceding\nand matching '/*' statement! ",""); return -1;}
+
+	}	
+	
+	temp2.push_back(' ');   WR=true;
+
+	for(int th2=0; th2<temp2.size()-1; th2++) 
+	{
+		// this for loop should get rid of any remaining lines that begin with double slash //
+		// or get rid of the end of any lines that have // ends to them
+
+		char q1=temp2.at(th2);
+
+		if(q1=='/' && temp2.at(th2+1)=='/') WR=false;
+
+		if(WR) temp3.push_back(q1);
+
+		if(q1=='\n' || q1=='\r') WR=true;
+	}
+
+	
+	// re-sorts information into "word size" string blocks
+	for(int th3=0; th3<temp3.size(); th3++) 
+	{
+		c1=temp3.at(th3);  
+		                                     //  again this is to keep backward compatibility with all my old control files
+		if(AinB(c1," \n\r\t")) {if(s!="") {if(s=="[basefreq]") sv.push_back("[statefreq]"); else sv.push_back(s);} s="";}
+		else{s+=c1;}	
+	}
+	sv.push_back(s);
+
+
+
+	// archaic little function to put "[user]" back in user-defined tree code -----> easier than re-writing the whole of the dealwithtrees function.
+	// BUT it doesn't put it back in if it is already there! ---> that means I can use my mountaind of old "validation" control files without having to amend them.
+
+	bool weareonbaby=false;
+
+	for(int sd=0; sd<sv.size()-1; sd++)
+	{
+		string sq1=sv.at(sd), sq2=sv.at(sd+1);  
+		if(sq1=="[TYPE]" || sq1=="[SETTINGS]" || sq1=="[MODEL]" || sq1=="[SITES]" || sq1=="[BRANCHES]" || sq1=="[PARTITIONS]" || sq1=="[EVOLVE]" || sq1== "[BRANCHES*]") weareonbaby=false;
+		if(sq1=="[TREE]") weareonbaby=true;
+		
+		if(weareonbaby && sq2[0]=='(')
+		{
+			if(sq1 != "[user]" )  {sv.insert(sv.begin()+sd+1,"[user]"); sd++;}
+			weareonbaby=false;
+		}
+ 
+	}
+
+
+
+	// archaic little function to put "M3" back in codon model code -----> easier than re-writing the whole of the type 3 [submodel] command in the dealwithmodel function.
+	// BUT it doesn't put it back in if it is already there! ---> that means I can use my mountaind of old "validation" control files without having to amend them.
+
+	if(type==3)
+	{
+		bool weareonbaby=false;
+
+		for(int sd=0; sd<sv.size()-1; sd++)
+		{
+			string sq1=sv.at(sd), sq2=sv.at(sd+1);  
+			if(sq1=="[submodel]") weareonbaby=true;
+			else if(sq1[0]=='[') weareonbaby=false;
+			
+			if(weareonbaby && sq2[0]=='(')
+			{
+				if(sq1 != "M3" && sq1 != "M2" && sq1 != "M1" && sq1 != "M0" && sq1 != "ECMrest" && sq1 != "ECMunrest")  {sv.insert(sv.begin()+sd+1,"M3"); sd++;}
+				weareonbaby=false;
+			}
+ 
+		}
+
+	}	
+			
+	
+		bool settingsblock,modelblock,sitesblock,branchesblock,partitionsblock,evolveblock,doneanymodelsyet;
+		settingsblock=modelblock=sitesblock=branchesblock=partitionsblock=evolveblock=doneanymodelsyet=false;
+		
+		string lastbit;
+		vector<string> block;
+		int well=0;
+
+		if(sv.at(0)!="[TYPE]") { controlerrorprint2("CONTROL FILE","","","First entry in control file must be a [TYPE] command.",""); return -1;}
+		else if(sv.at(1)=="NUCLEOTIDE")		type=1;
+		else if(sv.at(1)=="AMINOACID")		type=2;
+		else if(sv.at(1)=="CODON")			type=3;
+		else {isthereanerror=-1; 	controlerrorprint2("[TYPE]","","","First value for [TYPE] command must be NUCLEOTIDE, AMINOACID, or CODON",""); return -1;}
+
+
+
+		
+	//this loop will go through and change model names (new system. e.g "HKY") to numbers (old system, e.g. "3") but will ignore old system if used.
+	
+	string codonmodelnames[16]={"M0","M1","M2","M3","M4xxx","M5xxx","M6xxx","M7xxx","M8xxx","M9xxx","M10xxx","M11xxx","M12xxx","M13xxx","ECMrest","ECMunrest"};
+
+	string nucleotidemodelnames[17]={"JC","F81","K80","HKY","TrNef","TrN","K81","K81uf","TIMef","TIM","TVMef","TVM","SYM","GTR","F84ef","F84","UNREST"};
+
+	string aminoacidmodelnames[17]={"Poisson","JTT","JTT-dcmut","Dayhoff","Dayhoff-dcmut","WAG","mtMAM","mtART","mtREV","rtREV","cpREV","Vt","Blosum","LG","HIVb","HIVw","USER"};
+
+	string option3="M0, M1, M2, M3, ECMrest, ECMunrest.";
+
+	string option1="JC, F81, K80, HKY, TrNef, TrN, K81, K81uf, TIMef,\nTIM, TVMef, TVM, SYM, GTR, F84ef, F84, UNREST.";
+
+	string option2="Poisson, JTT, JTT-dcmut, Dayhoff, Dayhoff-dcmut, WAG, mtMAM,\nmtART, mtREV, rtREV, cpREV, Vt, Blosum, LG, HIVb, HIVw, USER.";
+
+
+	vector<string> replacenames;   string myname, mybit=sv.at(1), optionstring;
+
+	if(type==3)			{for(int pg=0; pg<16; pg++) replacenames.push_back(codonmodelnames[pg]);       optionstring=option3;}
+	else if(type==2)	{for(int pg=0; pg<17; pg++) replacenames.push_back(aminoacidmodelnames[pg]);   optionstring=option2;}
+	else if(type==1)	{for(int pg=0; pg<17; pg++) replacenames.push_back(nucleotidemodelnames[pg]);  optionstring=option1;}
+
+	for(int qw=1; qw<sv.size(); qw++)
+	{
+		string test=sv.at(qw), oldtest=sv.at(qw-1);
+
+		if(oldtest=="[MODEL]") myname=test;
+
+		if(oldtest=="[submodel]")
+		{
+			if(allAinB(test,"0123456789.")) continue;
+			
+			bool error=true;
+			stringstream sss; string ss;
+			for(int pg=0; pg<replacenames.size(); pg++) if(replacenames.at(pg)==test) {sss<<pg; ss=sss.str(); sv.at(qw)=ss; error=false; break;}
+
+			if(type==2 && error) 
+			{
+				ifstream ig1; ig1.open(test.c_str()); 
+
+				if(!(ig1.good())) {controlerrorprint2("[MODEL]", myname, "[submodel]", test+"\nis not a model name or number and no file of this name exists.\nFor protein models, the entry after a [submodel] command must be\nan integer, model name or a filename.",""); {if(breakonerror) return -1;} }
+				else error=false;
+				
+								
+			}
+
+			if(error) 
+			{
+				string mystring="\nThere is no "+mybit+" substitution model named: "+test+".\n\nYour options are:\n\n"+optionstring+"\n\nor the numerical counterparts. Please consult manual.";
+				if(type==2) mystring+="\nThere is also no file named "+mybit+" in the INDELible directory.";
+				controlerrorprint2("[MODEL]",myname,"[submodel]",mystring,""); 
+				return -1;
+			}
+
+		}
+	}
+/*
+		string blah=sv.back(),blah2;
+		if(blah.size()!=1)
+		{
+			//to prevent parsing error if there is no space, horizontal tab or new line after last entry in control file.
+			for(int ghg=0; ghg<blah.size()-1; ghg++) blah2+=blah[ghg];
+
+			sv.back()=blah2; sv.push_back("\n");
+		}
+*/		
+
+		// checks which algorithm people want to use
+		if(sv.at(2)=="1") oldmethod=false;		//old model
+		else if(sv.at(2)=="2") oldmethod=true; //new model
+
+		else {isthereanerror=-1; 	controlerrorprint2("[TYPE]","","","Second value for [TYPE] command must 1 or 2 for choice of algorithm",""); return -1;}
+
+
+		int mytype=-1;
+
+		vector<string> rough, settingsV, evolveV;
+		vector<vector<string> > modelsV, sitesV, branchesV, treesV, partitionsV;
+		vector<bool> branchesCV;
+
+
+	//	string thisbit=sv.at(2);
+		string thisbit;
+		string MAIN[8]={"[SETTINGS]","[MODEL]","[SITES]","[BRANCHES]","[TREE]","[PARTITIONS]","[BRANCHES*]","[EVOLVE]"};
+
+		bool doit=true;
+		int numberofsettingsblocks=0;
+		int numberofmodelsblocks=0;
+
+	/*		
+		if(well!=-1)
+		{
+			if(thisbit=="[SETTINGS]") mytype=0;
+			else if (thisbit=="[MODEL]") mytype=1;
+			else cout<<"ERROR: After the [TYPE] setting should come a [SETTINGS] or [MODEL] block."<<endl;
+		}
+
+		if(mytype==0 || mytype==1) 
+	*/
+		if(sv.at(3)!="[MODEL]" && sv.at(3)!="[SETTINGS]") {isthereanerror=-1;	controlerrorprint2("[TYPE]","","","There is some text after the [TYPE] command before the first block.\n Is this a mistake? Was expecting a [MODEL] or [SETTINGS] block",sv.at(3)); return -1;}
+
+
+		if(isthereanerror!=-1) for(int i=3; i<sv.size(); i++) 
+		{
+			// if there is no error then this function collects together blocks of same type etc.
+
+			thisbit=sv.at(i);
+
+			doit=true;
+
+			for(int j=0; j<8; j++) 
+			{
+				if(thisbit==MAIN[j]) 
+				{
+					
+					if(mytype==0)		{settingsV=rough; numberofsettingsblocks++;}
+	  				else if(mytype==1)	{modelsV.push_back(rough); numberofmodelsblocks++;}
+					else if(mytype==2)	sitesV.push_back(rough);
+					else if(mytype==3)	{branchesV.push_back(rough); branchesCV.push_back(true);}
+					else if(mytype==4)	treesV.push_back(rough);
+					else if(mytype==5)	partitionsV.push_back(rough);
+					else if(mytype==6)	{branchesV.push_back(rough); branchesCV.push_back(false);}
+
+					mytype=j;
+					rough.clear();
+					doit=false;
+					break;
+				}
+				
+
+			}
+
+			if(doit) rough.push_back(thisbit);	
+		}
+
+		if(well!=-1)
+		{
+			// final error checking
+
+			if(numberofsettingsblocks>1) {controlerrorprint2("[SETTINGS]","","","ERROR: There was more than one [SETTINGS] block.","");   return -1;}
+			if(numberofmodelsblocks==0) {controlerrorprint2("[MODEL]","","","ERROR: No [MODEL] blocks were specified.","");   return -1;}
+
+
+			if(mytype!=7) {controlerrorprint2("[EVOLVE]","","","ERROR: Control file should end with an [EVOLVE] block","");    return -1;}
+			else evolveV=rough;
+			rough.clear();
+			sv.clear();
+		}
+
+	
+	int p; //,q;
+
+	// settings blocks first!
+	if(isthereanerror!=-1 && numberofsettingsblocks>0) dealwithsettings(settingsV);
+
+	// runs through commands in correct order, and skips if an error occurs anywhere
+	for(p=0; p<modelsV.size();     p++) { if(isthereanerror==-1 ) return -1; else isthereanerror=dealwithmodel(modelsV.at(p)); }
+	for(p=0; p<branchesV.size();   p++) { if(isthereanerror==-1 ) return -1; else isthereanerror=dealwithbranches(branchesV.at(p), branchesCV.at(p)); }	
+	for(p=0; p<sitesV.size();      p++) { if(isthereanerror==-1 ) return -1; else isthereanerror=dealwithsites(sitesV.at(p)); }
+	for(p=0; p<treesV.size();      p++) { if(isthereanerror==-1 ) return -1; else isthereanerror=dealwithtrees(treesV.at(p)); }
+	for(p=0; p<partitionsV.size(); p++) { if(isthereanerror==-1 ) return -1; else isthereanerror=dealwithpartitions(partitionsV.at(p)); }
+	if(isthereanerror==-1 ) return -1; else isthereanerror=dealwithevolve(evolveV);
+
+
+	
+//	cout<<"HERE"<<endl;
+	
+
+//	cout<<"HERE"<<endl;
+/*
+	// for testing model copying and assigning etc
+
+	for(p=0; p<totalmodels.size(); p++)    
+	{
+		model m=totalmodels.at(p);
+		cout<<endl<<"MODEL "<<m.name<<endl<<endl;
+
+		cout<<m.modelnumber<<" modelnumber"<<endl;
+		cout<<m.geneticcode<<" geneticcode"<<endl;
+		cout<<m.indeltosub<<" indeltosub"<<endl;
+		cout<<m.instodel<<" instodel"<<endl;
+		cout<<m.inlength<<" inlength"<<endl;
+		cout<<m.dellength<<" dellength"<<endl;
+
+		cout<<m.alpha<<" alpha"<<endl;
+		cout<<m.pinv<<" pinv"<<endl;
+		cout<<m.ngamcat<<" ngamcat"<<endl;
+
+		vector<double> bits; int gg;
+		double sum=0;
+
+		sum=0; bits=m.rootbasefreqs; cout<<"rootbasefreqs ";
+		for(gg=0;gg<bits.size();gg++) {sum+=bits.at(gg); cout<<bits.at(gg)<<" ";}//<<endl;}
+		cout<<sum<<endl;
+		sum=0; bits=m.insertfreqs; cout<<"insertfreqs ";
+		for(gg=0;gg<bits.size();gg++) {sum+=bits.at(gg); cout<<bits.at(gg)<<" ";}//endl;}
+		cout<<sum<<endl;
+		sum=0; bits=m.basefreqs; cout<<"basefreqs ";
+		for(gg=0;gg<bits.size();gg++) {sum+=bits.at(gg); cout<<bits.at(gg)<<" ";}//endl;}
+		cout<<sum<<endl;
+
+	}
+*/
+
+	/*
+	// for printing of information
+
+	for(q=0; q<settingsV.size(); q++)	cout<<"settings "<<q<<" "<<settingsV.at(q)<<endl;
+   
+	for(p=0; p<modelsV.size(); p++)		for(q=0; q<(modelsV.at(p)).size(); q++) cout<<"models "<<p<<" "<<q<<" "<<(modelsV.at(p)).at(q)<<endl;
+	
+	for(p=0; p<sitesV.size(); p++)		for(q=0; q<(sitesV.at(p)).size(); q++) cout<<"sites "<<p<<" "<<q<<" "<<(sitesV.at(p)).at(q)<<endl;
+    
+	for(p=0; p<branchesV.size(); p++)	for(q=0; q<(branchesV.at(p)).size(); q++) cout<<"branches "<<p<<" "<<q<<" "<<(branchesV.at(p)).at(q)<<endl;
+	
+	for(p=0; p<partitionsV.size(); p++)	for(q=0; q<(partitionsV.at(p)).size(); q++) cout<<"partitions "<<p<<" "<<q<<" "<<(partitionsV.at(p)).at(q)<<endl;
+
+	for(q=0; q<evolveV.size(); q++)		cout<<"evolve "<<q<<" "<<evolveV.at(q)<<endl;
+    */
+
+	printf("\n");
+  return isthereanerror;
+}				
+
+
+// include code below if you want to run standalone tests of the code in here without linking to main skeleton program
+//double main(int argc, char* argv[])
+//{
+//	return 0;
+//}	
+	
diff --git a/src/indelible.cpp b/src/indelible.cpp
new file mode 100644
index 0000000..46de883
--- /dev/null
+++ b/src/indelible.cpp
@@ -0,0 +1,4973 @@
+// Please uncomment this line if compiling source code on Windows machine
+// #define WINDOWS
+
+/* 
+   INDELible V1.03
+    "A comprehensive and flexible simulator of molecular sequence evolution"
+    Copyright (C) 2009 William Fletcher
+ 
+    If using this software please cite the following reference:
+
+    Fletcher, W. and Yang, Z. 2009. 
+	"INDELible: a flexible simulator of biological sequence evolution." 
+	Mol. Biol. and Evol. (submitted on Friday 13th March 2009). 
+
+    If you need to contact me with any queries, questions, problems or (god-forbid) bugs
+    then please go to http://abacus.gene.ucl.ac.uk/software/indelible/bug.php
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    Please visit http://www.gnu.org/licenses/ for a full copy of the license.
+*/
+
+///////////////////////////////////////
+// debugging options
+
+//#define printoverrideok  // this allows the use of the same filename for different blocks
+
+//if(globalthisrep==6877+1 || globalthisrep==5775+1) 
+//#define printrepstoscreen	// just prints reps to screen
+
+//#define inheritancycheck	// used to check if inheritancy of insertions is correct, needs
+	    						// a guide tree with a max. of 5 branches depth root to tip
+//#define checkingindelsubs1
+//#define checkingindelsubs2
+//#define checkingindelsubs3
+ 
+//#define checkingindelsininsertions
+
+//#define myevolvedebugger	// used to check if insertions work and evolve correctly
+int	fixedsize		= 3;	// fixed size of indels if inheritancy check is used.
+//#define fixedindels	
+
+
+//#define checkindeldistributions	// used to check whether indel length distributions are consistent.
+
+//#define rippartitions		// used to rip partitioned datasets in to separate datasets for each partition for checking purposes.
+
+//#define splittree			// used to split 24 taxa dataset into 3 x 8 taxa datasets t o see if subtrees evolve properly with different models
+
+//#define printmaxindelsize	// just prints out the new maximum indel length as it changes
+				// for picking up bugs that steal lots of memory etc here
+
+//#define runseedstillbreak   // this will run the same control file over and over, outputting seeds to the log file.
+                            // then if there is an error - it can be repeated and tracked.
+int globalthisrep;
+
+#ifdef printmaxindelsize
+ int maxindelsize=0;
+#endif
+
+#ifdef checkingindelsubs1
+	bool mytest;
+	#define checkingindelsubs
+#endif
+#ifdef checkingindelsubs2
+	bool mytest;
+	#define checkingindelsubs
+#endif
+#ifdef checkingindelsubs3
+	bool mytest;
+	#define checkingindelsubs
+#endif
+
+//#define INDELLOG			// lists all indel events, where they occurred, changes etc.  for debugging indel routines.
+
+//#define checkpinv
+	// N.B. the pinv test crashes when used with partitions, and will be incorrect with partitions or non-stationary models.
+int inspinvcount, corepinvcount;
+
+//#define timewatch			// times each step of simulation, setup, evolving, then printing. keep disabled as prints
+							// lots of junk when simulations with a large number of replicates are performed.
+//#define checksitesclass
+/////////////////////////////////////////
+
+//#include <cmath>
+
+
+
+// needed for time monitoring
+
+#include <stdio.h>
+#include <stdlib.h>
+/*
+// example use of time monitoring
+
+   clock_t start, finish;
+   double  duration;
+
+ // Measure the duration of an event. 
+   printf( "Time to do %ld empty loops is ", i );
+   start = clock();
+   while( i-- ) 
+      ;
+   finish = clock();
+   duration = (double)(finish - start) / CLOCKS_PER_SEC;
+   printf( "%2.1f seconds\n", duration );
+*/
+#include <iostream>
+#include <iomanip> 
+#include <fstream>
+#include <time.h>
+#include <string>
+#include <vector>
+#include <math.h>
+#include <sstream>
+#include <algorithm>
+#include <map>
+
+#ifdef WINDOWS
+	#include "windows.h"
+#else
+	#include "limits.h"
+#endif
+
+#include "control.cpp"
+
+using namespace std;
+
+// used for timing
+clock_t start, finish, startofprinting, startofevolution, endofprinting, endofblock, startofblock;
+double  duration;
+
+
+// this annoying warning always pops up in Visual C++ V6.0, it is a confirmed bug in the compiler.
+#pragma warning(disable:4786)
+
+// this one too - it warns of exceptions for using <string> class etc
+#pragma warning(disable:4530)
+
+ofstream* results=new ofstream;		// pointers to output streams for file output.
+ofstream* results2=new ofstream;		// pointers to output streams for file output.
+ofstream* results3=new ofstream;		// pointers to output streams for file output.
+
+int oldindellength;
+
+#ifdef INDELLOG
+  ofstream indellog("indellog.txt");
+#endif
+int lasttreeseed=0;
+vector<int> mymods;
+//////////////////////////////////////
+vector<vector<int> > mycodes;
+
+// pointer to a function used to produce P(t) from Q for method 1.
+// pointer needed to choose between functions for reversible and non-reversible substitution models
+// i.e. UNREST for NUCLEOTIDE uses a different function than all other reversible models.
+
+vector<vector<double> > (*Pt) (vector<vector<double> > Qvec, vector<double> &basefreqs,  double t);
+
+
+class site
+{
+	// every inserted site is represented as an instance of "site"
+public:
+	int base;			// state at that site
+	double rate;		// relative substitution rate used for e.g. gamma models
+	int siteclass;		// site class for site, used for codon site-models or discrete gamma
+	double subrate;		// substitution rate for site that depends on state held in base (for method 2)
+	double timeleft;	// if an insertion occurs at distance x into branch of length y then timeleft = y - x
+						// used by method 1 to distinguish from sites that were inserted on different branches 
+						
+	site (int b, double ra, int si, double r, double t)
+	{
+		base=b;
+		rate=ra;
+		siteclass=si;
+		subrate=r;
+		timeleft=t;
+	}
+};
+
+class insert
+{
+	// every site k in the core sequence has an instance of "insert" i_k say
+	// that mirrors it to hold information about inserted sequences.
+	
+public:
+	vector<site> insertvec; // all sites that are inserted after core position k are stored here 
+	int length;				// number of sites in insertvec
+	double subrate;			// total substitution rate for all sites in insertvec
+
+	insert(vector<site> mytempvec, int mylength, double mysubrate)
+	{
+		subrate=mysubrate;
+		length=mylength;
+		insertvec=mytempvec;
+	}
+};
+
+	
+class SUMS
+{
+	// an instance of SUMS is used in every simulation.
+	// for method 1 the vector<double> are never used.
+	// for method 2 they are used to choose site where substitutions occur
+	// both methods use the vector<int> for choosing where indels occur.
+
+public:
+
+	vector<double> CSsums1;				//substitution rates for each particular site in core sequence.
+	vector<double> CSsums10;			//group of 10 cumulative sums of elements
+	vector<double> CSsums100;			//group of 10 cumulative sums of sums10
+	vector<double> CSsums1000;			//group of 10 cumulative sums of sums100
+	vector<double> CSsums10000;			//group of 10 cumulative sums of sums1000
+	vector<double> CSsums100000;		//group of 10 cumulative sums of sums10000
+	vector<double> CSsums1000000;		//group of 10 cumulative sums of sums100000
+	vector<double> CSsums10000000;		//group of 10 cumulative sums of sums1000000
+	vector<double> CSsums100000000;		//group of 10 cumulative sums of sums10000000
+	vector<double> CSsums1000000000;	//group of 10 cumulative sums of sums100000000
+	vector<double> CSsums10000000000;	//group of 10 cumulative sums of sums1000000000
+	vector<double> CSsums;				//group of as many cumulative sums of sums10000000000 as there are.
+
+	vector<double> ISsums1;				//substitution rates for each particular site in inserted sites.
+	vector<double> ISsums10;			//group of 10 cumulative sums of elements
+	vector<double> ISsums100;			//group of 10 cumulative sums of sums10
+	vector<double> ISsums1000;			//group of 10 cumulative sums of sums100
+	vector<double> ISsums10000;			//group of 10 cumulative sums of sums1000
+	vector<double> ISsums100000;		//group of 10 cumulative sums of sums10000
+	vector<double> ISsums1000000;		//group of 10 cumulative sums of sums100000
+	vector<double> ISsums10000000;		//group of 10 cumulative sums of sums1000000
+	vector<double> ISsums100000000;		//group of 10 cumulative sums of sums10000000
+	vector<double> ISsums1000000000;	//group of 10 cumulative sums of sums100000000
+	vector<double> ISsums10000000000;	//group of 10 cumulative sums of sums1000000000
+	vector<double> ISsums;				//group of as many cumulative sums of sums10000000000 as there are.
+
+	vector<int> CIsums1;				//insertion rates for each particular site in core sequence.
+	vector<int> CIsums10;				//group of 10 cumulative sums of elements
+	vector<int> CIsums100;				//group of 10 cumulative sums of sums10
+	vector<int> CIsums1000;				//group of 10 cumulative sums of sums100
+	vector<int> CIsums10000;			//group of 10 cumulative sums of sums1000
+	vector<int> CIsums100000;			//group of 10 cumulative sums of sums10000
+	vector<int> CIsums1000000;			//group of 10 cumulative sums of sums100000
+	vector<int> CIsums10000000;			//group of 10 cumulative sums of sums1000000
+	vector<int> CIsums100000000;		//group of 10 cumulative sums of sums10000000
+	vector<int> CIsums1000000000;		//group of 10 cumulative sums of sums100000000
+	vector<int> CIsums10000000000;		//group of 10 cumulative sums of sums1000000000
+	vector<int> CIsums;					//group of as many cumulative sums of sums10000000000 as there are.
+
+	vector<int> IIsums1;				//insertion rates for each particular site in inserted sites.
+	vector<int> IIsums10;				//group of 10 cumulative sums of elements
+	vector<int> IIsums100;				//group of 10 cumulative sums of sums10
+	vector<int> IIsums1000;				//group of 10 cumulative sums of sums100
+	vector<int> IIsums10000;			//group of 10 cumulative sums of sums1000
+	vector<int> IIsums100000;			//group of 10 cumulative sums of sums10000
+	vector<int> IIsums1000000;			//group of 10 cumulative sums of sums100000
+	vector<int> IIsums10000000;			//group of 10 cumulative sums of sums1000000
+	vector<int> IIsums100000000;		//group of 10 cumulative sums of sums10000000
+	vector<int> IIsums1000000000;		//group of 10 cumulative sums of sums100000000
+	vector<int> IIsums10000000000;		//group of 10 cumulative sums of sums1000000000
+	vector<int> IIsums;					//group of as many cumulative sums of sums10000000000 as there are.
+
+	void myclear()
+	{
+		// simply clears all vectors above in an instnce of SUMS.
+		// used when the model changes from branch to branch
+
+		ISsums.clear();
+		ISsums1.clear();
+		ISsums10.clear();
+		ISsums100.clear();
+		ISsums1000.clear();
+		ISsums10000.clear();
+		ISsums100000.clear();
+		ISsums1000000.clear();
+		ISsums10000000.clear();
+		ISsums100000000.clear();
+		ISsums1000000000.clear();
+		ISsums10000000000.clear();
+
+		IIsums.clear();
+		IIsums1.clear();
+		IIsums10.clear();
+		IIsums100.clear();
+		IIsums1000.clear();
+		IIsums10000.clear();
+		IIsums100000.clear();
+		IIsums1000000.clear();
+		IIsums10000000.clear();
+		IIsums100000000.clear();
+		IIsums1000000000.clear();
+		IIsums10000000000.clear();
+
+		CSsums.clear();
+		CSsums1.clear();
+		CSsums10.clear();
+		CSsums100.clear();
+		CSsums1000.clear();
+		CSsums10000.clear();
+		CSsums100000.clear();
+		CSsums1000000.clear();
+		CSsums10000000.clear();
+		CSsums100000000.clear();
+		CSsums1000000000.clear();
+		CSsums10000000000.clear();
+
+		CIsums.clear();
+		CIsums1.clear();
+		CIsums10.clear();
+		CIsums100.clear();
+		CIsums1000.clear();
+		CIsums10000.clear();
+		CIsums100000.clear();
+		CIsums1000000.clear();
+		CIsums10000000.clear();
+		CIsums100000000.clear();
+		CIsums1000000000.clear();
+		CIsums10000000000.clear();
+	}
+};
+
+
+
+
+class RATES
+{
+	// an instance of RATES is used in each simulation to track and store changes in 
+	// substitution, insertion and deletion rates for inserted sites and core sites.
+	// the total rate is used to generate exponential waiting times
+	// the other rates are used to choose between different types of event, and
+	// to choose whether the event takes place in inserted or "core" sites
+
+public:
+	double totalrate;		// total event rate for all sites and all events
+	double corerate;		// total event rate for all core sites and all events
+	double coresubrate;		// total substitution rate for all core sites
+	double coreinsertrate;	// total insertion rate for all core sites
+	double coredeleterate;	// total deletion rate for all core sites
+	double insrate;			// total event rate for all inserted sites and all events
+	double inssubrate;		// total substitution rate for all inserted sites
+	double insinsertrate;	// total insertion rate for all inserted sites
+	double insdeleterate;	// total deletion rate for all inserted sites
+	
+	// at the root inslength = 0, and the others all equal the root length specified.
+	int rootlength;			// 
+	int corelength;			// this starts as rootlength but decreases with every core site deleted
+	int inslength;			// 
+	int totallength;		// 
+	int partitionlength;	// ... fill in later.
+
+	RATES()
+	{
+		totalrate=0;
+		corerate=0;
+		coresubrate=0;
+		coreinsertrate=0;
+		coredeleterate=0;
+
+		insrate=0;
+		inssubrate=0;
+		insinsertrate=0;
+		insdeleterate=0;
+
+		rootlength=0;
+		corelength=0;
+		inslength=0;
+		totallength=0;
+		partitionlength=0;
+	}
+};
+
+////////////////////////////////////////
+string masterfilename="control.txt";
+vector<model> mymodels;
+vector<int> siteclasses;
+vector<vector<int> > siteclassmodels;
+
+
+vector<vector<double> > totalratevecs;
+
+bool noinsertionsyet;
+vector<double> ratevec;
+vector<int> siteclassvec;
+
+int mypos;
+bool weareon;
+
+//ofstream hout("h.txt");
+#ifdef checksitesclass
+ofstream gout("g.txt");
+#endif
+				
+model* m;
+siteclass* s;
+branchclass* b;
+partitionclass* p;
+evolve* e;
+Tree* treeC;
+
+void changezipfrandoms()
+{
+		Zq1=(*m).q1;  
+		Zq2=(*m).q2 ;
+		ZHx0=(*m).Hx0; 
+		Zs=(*m).s ;
+		ZHimax=(*m).Himax;
+}
+
+vector<vector<int> >	 insPOS;				// for use inside TinsPOS
+vector<vector<int> >	 sequencesINT;			// for use inside TsequencesINT
+vector<vector<insert> >  insINT;				// for use inside TinsINT
+
+vector<vector<vector<int> > >  TinsPOS;			// holds *all* inserted site position information in a block.  
+vector<vector<vector<int> > >  TsequencesINT;	// holds *all* core sequence information in a block.  
+												// outside vector is for each partition
+												// middle vector is positions for each node on the tree for the partition
+												// internal vector is actual sequence information.
+
+vector<vector<vector<insert> > >  TinsINT;		// holds *all* core insertion information in a block.  
+												// outside vector is for each partition
+												// middle vector is positions for each node on the tree for the partition
+												// internal vector represents insertion information positions of insertions relative to core.
+												// internal vector is an actual insertion
+
+
+//Jump Vector for use when choosing new bases
+vector<vector<double> > JVec;
+
+// to store codon site class frequencies
+vector<double> Csitefreqs;
+
+// to store codon model information from control file
+vector<vector<double> > codoninfo; 
+
+// vector of jump matrices for each site class
+vector<vector<vector<double> > > matrixJVsites;	
+
+// vector of different matrixJVsites for each branch category
+vector<vector<vector<vector<double> > > > matrixJVbranches;	
+
+vector<double>  GDfreq;			// used in gamma rate variation
+vector<double>  GDrates;		// used in gamma rate variation
+
+double substitutioncount;	// counts the number of substitution events in a block
+double insertioncount;		// counts the number of insertion events in a block
+double insertiontotlength;	// tracks cumulative insertion length in a block
+double deletioncount;		// counts the number of deletion events in a block
+double deletiontotlength;	// tracks cumulative deletion length in a block
+
+string		originaltree;
+string		VersionNumber="1.03";
+
+
+int linecount		= 0;	// used to identify the line in the control file where an error occurs
+int deletionlength	= 0;	// tracks number of bases needing to be deleted when switching between core sequence and insertions
+
+//int breakonerror	= 1;	// should be left as 1 unless debugging		
+
+vector<double> defaultAAbasefreqs,  AAbasefreqs;	// Protein base frequencies vectors
+vector<double> defaultDNAbasefreqs, DNAbasefreqs;	// DNA base frequencies vectors
+vector<double> defaultCbasefreqs, Cbasefreqs;	// DNA base frequencies vectors
+
+// Valid characters for input and output, used for translation to and from integer representation
+string DU[4] ={"T","C","A","G"};
+string DL[4] ={"t","c","a","g"};
+string AU[20]={"A","R","N","D","C","Q","E","G","H","I","L","K","M","F","P","S","T","W","Y","V"};
+string AL[20]={"a","r","n","d","c","q","e","g","h","i","l","k","m","f","p","s","t","w","y","v"};
+
+
+string CDU[64]={
+"TTT","TTC","TTA","TTG","TCT","TCC","TCA","TCG","TAT","TAC","TAA","TAG","TGT","TGC","TGA","TGG",
+"CTT","CTC","CTA","CTG","CCT","CCC","CCA","CCG","CAT","CAC","CAA","CAG","CGT","CGC","CGA","CGG",
+"ATT","ATC","ATA","ATG","ACT","ACC","ACA","ACG","AAT","AAC","AAA","AAG","AGT","AGC","AGA","AGG",
+"GTT","GTC","GTA","GTG","GCT","GCC","GCA","GCG","GAT","GAC","GAA","GAG","GGT","GGC","GGA","GGG"};
+
+string CDL[64]={
+"ttt","ttc","tta","ttg","tct","tcc","tca","tcg","tat","tac","taa","tag","tgt","tgc","tga","tgg",
+"ctt","ctc","cta","ctg","cct","ccc","cca","ccg","cat","cac","caa","cag","cgt","cgc","cga","cgg",
+"att","atc","ata","atg","act","acc","aca","acg","aat","aac","aaa","aag","agt","agc","aga","agg",
+"gtt","gtc","gta","gtg","gct","gcc","gca","gcg","gat","gac","gaa","gag","ggt","ggc","gga","ggg"};
+
+vector<string> myDUletters(DU,DU+4);
+vector<string> myDLletters(DL,DL+4);
+vector<string> myAUletters(AU,AU+20);
+vector<string> myALletters(AL,AL+20);
+vector<string> myCDUletters(CDU,CDU+64);
+vector<string> myCDLletters(CDL,CDL+64);
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// A lot of the following variables are now defunct and not used - but some are still in use - I just haven't had the time to check which.  //
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+vector<string> commandblockvec;				// used to store a command block to append output files (e.g. MrBayes or PAUP block)
+vector<string> block;						// this will be used to store information about one particular block
+vector<string> taxanames;					// this stores the real taxon names and internal nodel labels
+vector<string> taxaspacenames;				// formatted taxanames
+vector<string> partonetaxanames;			// this stores the real taxon names and internal nodel labels for the first partition
+											// - used for comparison to make sure ordering of taxon names is same across partitions
+											// - and to make sure that the total number of taxa/taxa names is same across partitions
+vector<vector< string> > commandblocks;		// this will store the command blocks in total, as read from the control file
+
+	int NgamCAT;			// Number of categories for the discrete gamma rate variation 
+	int medianORmean;		// 1 = use medians, 0 = use means, to represent categories in discrete gamma rate variation
+	int rootlength;			// length of root sequence to be created or when given.
+	int reps;				// number of repetitions
+	int ntaxa;				// number of taxa
+	int mymodel;			// substitution model number
+	int startnodelabel;		// used in manipulation of guide tree
+
+	int dashlength;			// used to calculate length of true alignment;
+	int totallength;
+
+	int partitionsdone;  	// offset for block titles etc
+	int partitionnumber; 	// number of partitions for each repetition
+	int partitionstogo;		// number of partitions left to do.
+	int geneticCode;		// used for translation between amino acids and codons.
+
+	// which bool values reset, which ones don;t?
+
+	bool isitsites;
+	bool isitbranches;
+
+
+	bool insertionBFfrommodel;	// If true insertion base frequencies is same as model base frequencies, otherwise they come from ((*m).insertfreqs).
+	bool ECMbasefreqOVERRIDE;  	// Used for +F version of ECM codon models.  set to true, model base frequencies come from AAbasefreqs
+	bool AAbasefreqOVERRIDE;  	// Used for +F protein model.  set to true, model base frequencies come from AAbasefreqs
+	bool modelbasefreqs;		// set to true means that root base frequencies come from the model, if root sequence is created.
+	bool rootTOmodelOVERRIDE;	// if true, then model stationary base frequencies are determined from the given root sequence.
+	bool rootseqgiven;			// true if root sequence given, if false then rootTOmodelOVERRIDE above has no effect.
+	bool ratechange;			// whether changes to the site rate variation commands occurs in a block
+	bool codonrates;			// whether to used codon rates
+	bool paupblock;				// whether to print PAUP block or MrBayes block
+	bool warningprint;			// whether two taxa names are the same in the guide tree & a warning has been printed
+	bool printonlyroot;			// whether to print ancestral sequences.
+	bool sites;					// for defining sites and sites-branches models for codons
+	bool branches;				// for defining branches and branches-sites models for codons
+
+	double pinv;				// proportion of invariant sites, 0 for none, 1 for all.
+	double alpha;				// alpha value for gamma rate distribution
+//	double (*m).instodel;			// ratio of insertions to deletions e.g. 0.48 will give 48 insertions to every 52 deletions on average.
+//	double (*m).indeltosub;			// ratio of indels to substitutions, e.g. 0.01 gives 1 insertion/deletion event for every 99 substitutions on average
+//	double georate;				// rate parameter for the geometric distribution controlling indel lengths
+	double currenttreelength;	// amount of treelength in a given repetition that has been completed
+	double treelength;			// total treelength to be evolved in a given repetition, used with currenttreelength to calculate percentage complete.
+
+	string filenamestub;		// this is a unique file name for every block appended with the repetition number for the output files	
+	string paupblockname;		// filename for paupblock.
+	string nonamestree;			// all used in tree manipulation.
+	string origtreewithnodes;
+	string nonamestreewithnodes;
+	string workingtree;
+	string guidetree;
+	
+//	vector<double> ratevec;				// Used to store information on continuous/discrete gamme rate variation, & proportion of invariant sites
+	vector<double> usermodel;			// Used for user-defined Amino Acid substitution model
+//	vector<double> rootbasefreqs;		// base frequencies used to create root sequence if not using model base frequencies
+//	vector<double> INSERTIONbasefreqs;	// base frequencies used to choose inserted bases if not using model base frequencies
+//	vector<double> myrates;				// these are the rates used when estimating exponential waiting times
+
+//	vector<string> rootseqCHAR;			// alphabetical representation of root sequence
+//	vector<int> rootseqINT;				// numerical representation of root sequence
+	vector<int> partitionposition;		// partitionposition is used to correctly print sequence information when using partitions with different guide trees
+
+	double codonrate[3]={1,1,1};
+
+	
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+double smalldiff=0.0000000001;  //for comparing floating point values
+
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void printtitle(ofstream &LOG, string &title)
+{
+	// prints out block specific title for print settings function
+	int mysize=title.size();
+
+	LOG<<endl;
+	LOG<<"+"; for(int tg=-2; tg<mysize; tg++) LOG<<"-"; LOG<<"+"<<endl;
+	LOG<<"| "<<title<<" |"<<endl;
+	LOG<<"+"; for(int tg2=-2; tg2<mysize; tg2++) LOG<<"-"; LOG<<"+"<<endl;
+	LOG<<endl;
+}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+void format(string &tss, string &css, string &ass, string &gss, double t, double c, double a, double g) 
+{
+
+/*
+string format(double Value, int nPrecision)
+{
+	stringstream s;
+	s.width(nPrecision);
+	s <<  Value;
+         return s.str();
+}
+*/
+
+
+	stringstream ts,cs,as,gs; 
+//	int maxsize;
+
+	if(t==1.0) tss="1.0"; else if(t==0.0) tss="0.0"; else {ts<<t; ts.width(6); tss=ts.str(); }//cout<<tss<<endl;}
+	if(c==1.0) css="1.0"; else if(c==0.0) css="0.0"; else {cs<<c; cs.width(6); css=cs.str(); }//cout<<css<<endl;}
+	if(a==1.0) ass="1.0"; else if(a==0.0) ass="0.0"; else {as<<a; as.width(6); ass=as.str(); }//cout<<ass<<endl;}
+	if(g==1.0) gss="1.0"; else if(g==0.0) gss="0.0"; else {gs<<g; gs.width(6); gss=gs.str(); }//cout<<gss<<endl;}
+		
+
+/*
+	stringstream ts,cs,as,gs; 
+	int maxsize;
+
+	if(t==1.0) tss="1.0"; else if(t==0.0) tss="0.0"; else {ts<<t; tss=ts.str(); maxsize=tss.size();                         }//cout<<tss<<endl;}
+	if(c==1.0) css="1.0"; else if(c==0.0) css="0.0"; else {cs<<c; css=cs.str(); if(maxsize<css.size()) maxsize=css.size();  }//cout<<css<<endl;}
+	if(a==1.0) ass="1.0"; else if(a==0.0) ass="0.0"; else {as<<a; ass=as.str(); if(maxsize<ass.size()) maxsize=ass.size();  }//cout<<ass<<endl;}
+	if(g==1.0) gss="1.0"; else if(g==0.0) gss="0.0"; else {gs<<g; gss=gs.str(); if(maxsize<gss.size()) maxsize=gss.size();  }//cout<<gss<<endl;}
+		
+	for(int jh1=0; jh1<maxsize+1; jh1++) 
+	{
+		if(jh1>tss.size()) tss+="0"; 
+		if(jh1>css.size()) css+="0"; 
+		if(jh1>ass.size()) ass+="0"; 
+		if(jh1>gss.size()) gss+="0"; 
+	}
+*/
+}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+void chooseNEWbase(int &newbase,  vector<double> JVecRow)
+{
+	// choose new base according to jump matrix
+	myrand=mtrand1();
+
+	for(int i=0; i<JVecRow.size(); i++) {   if (myrand < JVecRow.at(i)) {newbase=i; break;}}
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+
+
+int returnNewSiteClass(/*vector<int> &siteclasscount, */ vector<double> siteprops, int po)
+{	
+	if(siteprops.empty())  {cout<<endl<<endl<<"ERROR 1 in returnNEWsiteClass"<<endl<<endl; return 0;} 
+	double rand=mtrand1(); //cout<<rate
+	int siteclass=-1;
+	for(int i1=0; i1<siteprops.size(); i1++) 
+	{
+		if(rand<siteprops.at(i1)) {siteclass=i1; break;}
+	}
+	//cout<<" "<<rate<<endl;
+	if(siteclass==-1) cout<<endl<<endl<<"ERROR 2 in returnNEWsiteClass"<<endl<<endl;
+
+	//(siteclasscount.at(siteclass))++;
+	
+	//if(po<50) cout<<po<<"  "<<siteclass<<endl;
+	return siteclass;
+}
+///////////////
+double returnNewSiteRate(int pos)
+{
+	double rate;
+
+	// this function sets the site rates for evolution of the core sequence.
+	// inserted bases will inherit the rate of the base  where the insertion occurred.
+
+	if(type==3)
+	{
+		//if(!sites) rate=1; else for(int gv1=0; gv1<Csitefreqs.size(); gv1++) if(mtrand1()<Csitefreqs.at(gv1)) rate=gv1; 
+		//for(int i1a=0; i1a<((*m).codoncatfreqs).size(); i1a++) cout<<((*m).codoncatfreqs).at(i1a)<<" "; cout<<endl; 
+		
+		rate=mtrand1(); //cout<<rate;
+		for(int i1=0; i1<((*m).cumfreqs).size(); i1++) 
+		{
+			if(rate<((*m).cumfreqs).at(i1)) {rate=i1; break;}
+
+		}
+		//cout<<" "<<rate<<endl;
+
+		return rate;
+	}
+	
+	double multiplier=1;
+	if(type==1)
+	{
+		//cout<<"Q"<<endl;
+		int codonpos=pos%3;
+		//cout<<"Q"<<endl;
+		multiplier=((*m).codonrates)[codonpos];
+
+		//cout<<"Q"<<endl;
+		//if(pos<50)	cout<<"multiplier "<<"  "<<pos<<"  "<<codonpos<<"  "<<multiplier<<endl;
+	}
+	if(codonrates) 
+	{
+		
+	}
+	else if((*m).alpha==0 && (*m).pinv==0)   // no gamma, no codon rates, no proportion invariant
+	{
+		// constant rates across whole sequence
+		rate=multiplier;
+	}
+	///////////////////////////	
+	else  // proportion invariant with either no gamma, discrete gamma, or continuous gamma
+	{
+		if((*m).alpha==0) 
+		{		
+			//this is proportion invariant
+			if(mtrand1()<(*m).pinv) rate=0; else rate=multiplier/(1- ((*m).pinv) );
+		}
+		else if((*m).alpha>0 && (*m).ngamcat==0)
+		{
+			//Continuous Gamma + Proportion invariant
+			if(mtrand1()<(*m).pinv) rate=0; else rate=rndgamma(  ((*m).alpha)/(  ((*m).alpha)* (1- ((*m).pinv) )  )  );
+		}
+		else if((*m).alpha>0 && (*m).ngamcat>0)
+		{
+			//Discrete Gamma + Proportion invariant
+			
+			if(mtrand1()>(*m).pinv)  rate=GDrates.at( (int)( mtrand1() * ((*m).ngamcat) ) )/(1-((*m).pinv));  else rate=0;
+
+		}
+		else (*LOG)<<"SetSite Rates error 1 - alpha or ngamcat is less than zero"<<endl;
+	}
+
+	return rate;
+}
+
+
+///////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+double returnsitesubrate(double rate, int siteclass, int currentbase)
+{
+	
+	
+	if(type==3)	return ( ( (*m).myratesvec).at(siteclass) ).at( currentbase ); 
+
+	else		return rate * (((*m).myrates).at(currentbase)); 
+
+//	cout<<"X"<<endl;
+//	if(type==3)	{cout<<"Y"<<endl; return ( ( (*m).myratesvec).at(siteclass) ).at( currentbase ); }
+//
+//	else		{cout<<"Z "<<((*m).myrates).size()<<"  "<<currentbase<<endl; return rate * (((*m).myrates).at(currentbase)); }
+		
+}
+
+int returnsiteclass()
+{
+	int i1;
+
+	double rate=mtrand1(); 
+				
+	for(i1=0; i1<((*m).cumfreqs).size(); i1++) 
+	{
+		if(rate<=((*m).cumfreqs).at(i1)) break; //{ ratevec.push_back(i1);   break;}
+	}
+
+	return i1;
+
+}
+double returnsiterate(int &rateclass, bool core)
+{
+	if((*m).continuousgamma) 
+	{
+		double rand=mtrand1();
+
+		rateclass=0;
+
+		if(rand<(*m).pinv) {if(core) corepinvcount++; else inspinvcount++; return 0;} 
+
+		else return rndgamma(  ((*m).alpha)  )/(  ((*m).alpha)* (1- ((*m).pinv) )  ) ;
+	}
+	else {rateclass=returnsiteclass(); 	double myrate=((*m).Rrates).at(rateclass); 
+	
+
+	if(myrate==0) {if(core) corepinvcount++; else inspinvcount++;} return myrate; }
+
+}
+
+
+
+void SetSiteRates2(RATES &rates, string name, int repnumber, int mysize)
+{
+	siteclassvec.clear(); ratevec.clear(); siteclassvec.reserve(rates.rootlength); ratevec.reserve(rates.rootlength);
+
+//	if(oldmethod)
+//	{
+//		if(type==3) for(int t1=0; t1<rates.rootlength; t1++) {siteclassvec.push_back(returnsiteclass()); ratevec.push_back(0);}
+		
+//		else for(int t1=0; t1<rates.rootlength; t1++) {int myclass; ratevec.push_back(returnsiterate(myclass,true)); siteclassvec.push_back(0);}
+//	}
+//	else
+//	{
+		if(type==3) 
+		{
+			if(fixtrueproportions)
+			{
+				// this option was just for me to use in one of my papers.
+				siteclassvec.push_back(0);		
+				for(int x=0; x<10; x++) for(int y=0; y<20; y++) siteclassvec.push_back(x);
+
+				for(int t1=0; t1<rates.rootlength; t1++) 
+				{
+				//	siteclassvec.push_back(returnsiteclass2()); 
+					ratevec.push_back(0);
+				}
+				cout<<rates.rootlength<<"  "<<ratevec.size()<<"  "<<siteclassvec.size()<<endl;
+			}
+			else for(int t1=0; t1<rates.rootlength; t1++) {siteclassvec.push_back(returnsiteclass()); ratevec.push_back(0);}
+		}
+		
+		else for(int t1=0; t1<rates.rootlength; t1++) {int myclass; ratevec.push_back(returnsiterate(myclass,true)); siteclassvec.push_back(myclass);}
+
+//	}
+		//	}
+
+
+//	cout<<"SetSiteRates 2 works like this...."<<endl;
+//	for(int k=0; k<things.size(); k++) cout<<things.at(k)<<"  "<<counts.at(k)<<endl;
+
+
+//	for(int k=0; k<things.size(); k++) cout<<returnsitesubrate( k, 0)<<"\t"<<returnsitesubrate( k, 1)<<"\t"<<returnsitesubrate( k, 2)<<"\t"<<returnsitesubrate( k, 3)<<"\t"<<endl;
+
+}
+
+
+//////////////////////////////////////////
+
+vector<double> makecumfreqs(vector<double> basefreqs)
+{
+	vector<double> boundaries; 
+	double s=0;
+	for(int yh=0; yh<basefreqs.size(); yh++) {s+=basefreqs.at(yh); /*cout<<"  W "<<basefreqs.at(yh)<<"  A  "<<s<<endl;*/ boundaries.push_back(s);}
+
+	if(boundaries.back()-1>0.00000001) cout<<"make seq error in sum to 1 on boundaries "<<boundaries.back()<<" " <<boundaries.back()+1<<" "<<boundaries.back()-1<<endl;
+
+	return boundaries;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+void makeseq2(int length,  vector<site> &myseq, double &sdiff, double timeleft)
+{
+	// this assigns to "myseq" a sequence of length "length" subject to the base frequencies in "basefreqs" in integer form
+
+	vector<double> boundaries2;
+
+	boundaries2=makecumfreqs((*m).insertfreqs);
+	
+	for(int yh2=0; yh2<length; yh2++)
+	{	
+		myrand=mtrand1(); 
+		bool wearenotdone=true;
+	
+		for(int yh3=0; yh3<boundaries2.size(); yh3++) if(myrand<=boundaries2.at(yh3) ) 
+		{			
+			wearenotdone=false;
+
+			double rate=-1; int siteclass=-1;
+			
+			if(type==3) siteclass=returnsiteclass(); else rate=returnsiterate(siteclass, false);
+
+			double sitesubrate; if(oldmethod) {sitesubrate=returnsitesubrate(rate, siteclass,yh3); sdiff+=sitesubrate;}
+
+			#ifndef myevolvedebugger
+
+			myseq.push_back(    site( yh3, rate, siteclass, sitesubrate, timeleft )    ); 
+			
+			#else
+			
+			myseq.push_back(    site( 81, rate, siteclass, sitesubrate, timeleft )    ); 
+
+			#endif
+			
+			break;
+
+		} 
+		if(wearenotdone) cout<<"NO BASE PICKED in makeseq2, last boundaries was "<<boundaries2.back()<<" myrand was "<<myrand<<" sdiff is "<<sdiff<<endl;
+	}
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void makeseq(int length2,  vector<int> &myseq)
+{
+	// this assigns to "myseq" a sequence of length "length" subject to the base frequencies in "basefreqs" in integer form
+
+	int length=length2-1;
+
+	vector<double> boundaries2;	
+//	cout<<boundaries2.size()<<endl;
+	if(isitbranches)	boundaries2=makecumfreqs((*b).rootbasefreqs);
+	else				boundaries2=makecumfreqs((*m).rootbasefreqs);
+
+//	cout<<boundaries2.size()<<endl;
+	myseq.push_back(-1);
+//	cout<<"LLL "<<length2<<" "<<length<<endl;
+	for(int yh2=0; yh2<length; yh2++)
+	{	
+		myrand=mtrand1(); 
+
+		for(int yh3=0; yh3<boundaries2.size(); yh3++) 
+		{
+			//cout<<"X "<<boundaries2.at(yh3)<<endl;
+			if( myrand<=boundaries2.at(yh3)) 
+			{
+			
+				//cout<<boundaries2.at(yh3)<<endl;
+				myseq.push_back(yh3); break;
+				
+			} 
+		}
+		
+	}
+
+
+//	cout<<"WOW "<<myseq.size()<<endl;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+vector<double> getbasefreqs(vector<int> &seq)
+{
+	// calculates the base frequencies of a given sequence in integer form
+	vector<double> basefreqs;
+	int mymax=4;
+	if(type==2) mymax=20;
+	if(type==3) mymax=64;
+	
+	basefreqs.assign(mymax,0);
+	for(int y2=1; y2<seq.size(); y2++) basefreqs.at(seq.at(y2))++; 
+	for(int y3=0; y3<mymax;      y3++) basefreqs.at(y3)/=seq.size();
+
+	return basefreqs;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void fromprintseq(vector<string> &seq, vector<int> &myseq)
+{
+	// translates alphabetical protein/dna sequence into integer representation
+	myseq.clear();
+	myseq.reserve(seq.size());
+
+	vector<string> myletters, myletters2;
+	int mysize;
+	
+	if(type==1) 
+	{
+		mysize=4;
+		myletters=myDUletters;
+		myletters2=myDLletters;
+	}
+	else if(type==2)
+	{
+		mysize=20;
+		myletters=myAUletters;
+		myletters2=myALletters;
+	}
+	else cout<<"error in fromprintseq"<<endl;
+
+
+	for(int gv1=0; gv1<seq.size(); gv1++) 
+	{
+		string bb=seq.at(gv1);
+		int minimatch=-1;
+		
+		for(int gv3=0; gv3<myletters.size(); gv3++) { if(bb==myletters.at(gv3)) {minimatch=gv3; break;} }
+	
+		if(minimatch==-1) for(int gv4=0; gv4<myletters2.size(); gv4++) { if(bb==myletters2.at(gv4)) {minimatch=gv4; break;} }
+
+		if(minimatch==-1) {cout<<"ERROR in fromprintseq"<<endl<<" ";} else{myseq.push_back(minimatch);}
+	
+	}
+		
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+string nowhitespace(string guidetree)
+{
+	//takes white space out of tree and checks number of right and left parentheses
+	char c;
+	int bracketright=0, bracketleft=0;
+	string guidetree2S;
+
+	for(int ghy11=0; ghy11<guidetree.size(); ghy11++)
+	{
+		// get rid of white space in tree
+		c=guidetree[ghy11]; 
+		if(c!=' ') guidetree2S+=c; 
+		
+		if(c==')') bracketright++; 
+		if(c=='(') bracketleft++;
+	}
+
+if(bracketleft!=bracketright) cout<<"ERROR ON GUIDE TREE - mismatch on number of brackets"<<endl<<" ";
+
+return guidetree2S;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int gettaxanames(int partitionnumber, string guidetree, vector<string> &taxanames)
+{
+	// called from the settreeup function
+  
+	// gets taxon names from guide tree and puts into vector
+	// also truncates filenames to 10 characters if output in Phylip truncated is chosen
+	// final vector entry is tree with the label integer n replacing taxon name placed in nth position of taxanames vector
+
+	char c3='q',c2='q',c1='q';
+	string taxaname, tempstring, guidetree3;
+	int taxanameon=0, maxnamesize=0;
+	taxanames.clear(); taxanames.push_back("ROOT");
+
+	for(int jh1=0; jh1<guidetree.size(); jh1++)   // get taxanames and replace them in tree;
+	{
+		c3=c2;c2=c1;c1=guidetree[jh1];
+		if(taxanameon==0) {if( c2=='(' || c2==',') {if(c1!='('){ taxanameon=1; taxaname="";}}}
+		if(taxanameon==1 && c1==':') {taxanameon=2;}
+		if(taxanameon==1) taxaname+=c1;
+		if(taxanameon==2) 
+		{
+			
+			taxanameon=0;
+			stringstream fd;
+
+			int minimatch=-1;
+
+			if(partitionnumber==0) {fd<<taxanames.size(); string fddd=fd.str(); guidetree3+=fddd; } 
+			else 
+			{
+				for(int gb2=0; gb2<partonetaxanames.size(); gb2++) {if(taxaname==partonetaxanames.at(gb2)) {minimatch=gb2; break;}}
+						 
+				if(minimatch==-1)
+				{
+					stringstream f; f<<partitionnumber+1; string r=f.str();
+					controlerrorprint2("[PARTITIONS]", (*p).name,"","Error with taxon "+taxaname+"\nIt was found in tree for partition "+r+" but not found in tree for partition 1",""	); 
+					(*LOG)<<guidetree<<endl;
+
+		//			(*LOG)<<endl<<endl<<" ERROR: Taxon "<<taxaname<<" in guide tree for partition "<<partitionnumber+1<<" not found in guide tree for partition 1"<<endl<<endl;
+		//			cout<<endl<<endl<<" ERROR: Taxon "<<taxaname<<" in guide tree for partition "<<partitionnumber+1<<" not found in guide tree for partition 1"<<endl<<endl;
+					return -1;
+				}		
+				else
+				{
+					fd<<minimatch; string fddd=fd.str(); guidetree3+=fddd; 
+				}
+			}
+			
+			// truncate filename if necessary
+			if(phylipnametruncate && taxaname.size()>10) {string tempstring2=taxaname; taxaname=""; for(int fv=0; fv<10; fv++) taxaname+=tempstring2[fv];}
+			if(phylipnametruncate && taxaname.size()<10) for(int fv=taxaname.size(); fv<10; fv++) taxaname+=" ";
+
+			taxanames.push_back(taxaname);
+			if(taxaname.size()>maxnamesize) maxnamesize=taxaname.size();
+					
+		}
+		if(taxanameon==0) guidetree3+=c1;
+	}
+	
+	taxanames.push_back(guidetree3);
+	
+	int partnowsize=taxanames.size()-1;
+
+	// check whether two taxa have the same name
+	for(int gn2=0; gn2<partnowsize; gn2++)
+	{
+		for(int gn3=0; gn3<partnowsize; gn3++)
+		{
+			if(gn3!=gn2) 
+				if(taxanames.at(gn2)==taxanames.at(gn3)) 
+				{
+					stringstream f; f<<partitionnumber+1; string r=f.str();
+	
+					if(phylipnametruncate) 
+					{
+						controlerrorprint2("[TREE]", (*treeC).name,"","Two taxa in partition "+r+" tree have the same name after truncation for PHYLIP format: "+(taxanames.at(gn2)),"");
+
+						(*LOG)<<guidetree<<endl; 
+						//(*LOG)<<endl<<endl<<" ERROR: two taxa in the partition "<<partitionnumber+1<<" guidetree have the same name after truncation for PHYLIP format: "<<taxanames.at(gn2)<<endl<<endl; 
+
+						return -1;
+					}
+					else 
+					{ 
+						controlerrorprint2("[TREE]", (*treeC).name,"","Two taxa in partition "+r+" tree have the same name: "+(taxanames.at(gn2)),"");
+						(*LOG)<<guidetree<<endl; 
+						//(*LOG)<<endl<<endl<<" ERROR: two taxa in the partition "<<partitionnumber+1<<" guidetree have the same name: "<<taxanames.at(gn2)<<endl<<endl; 
+						return -1;
+					}
+				}
+		}			
+	}
+
+	if(partitionnumber==0) 
+	{
+		partonetaxanames=taxanames;
+		taxaspacenames=taxanames;
+
+		// add white space to taxa names so that output lines up
+		for(int gn1=0; gn1<partnowsize; gn1++)
+		{
+			string tempname=taxanames.at(gn1);
+	
+			if(!phylipnametruncate) for(int fg=tempname.size(); fg<maxnamesize+5; fg++) tempname+=" ";
+	
+			taxaspacenames.at(gn1)=tempname;
+		}
+
+	}
+	else
+	{
+		// if performing a partitioned analysis check for consistency of taxa names and numbers
+		int partonesize=partonetaxanames.size()-1;
+
+		if(partonesize!=partnowsize) 
+		{ 
+			stringstream f; f<<partitionnumber+1; string r=f.str();
+			stringstream g; g<<partonesize-1;     string s=g.str();
+			stringstream h; h<<partnowsize-1;     string t=h.str();
+	
+			controlerrorprint2("[TREE]", (*treeC).name,"","Guide tree for partition 1 has "+s+" taxa\nGuide tree for partition "+r+" has "+t+" taxa.","");
+		
+//			(*LOG)<<endl<<endl<<" ERROR: Guide tree for partition 1 has "<<partonesize-1<<" taxa\n";
+//			(*LOG)<<            "        Guide tree for partition "<<partitionnumber+1<<" has "<<partnowsize-1<<" taxa"<<endl<<endl;
+		    return -1;
+		}		
+
+	}
+
+return 0;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+string addnodestostring(string mytree, int &nodelabel)
+{
+	// places internal node labels on tree
+	char c1='q',c='q';
+	
+	string workingtree;
+	
+	for(int gh11=0; gh11<mytree.size(); gh11++)
+	{
+		c1=c; c=mytree[gh11]; 
+		if(c1==')' && c==':' )
+		{
+			nodelabel++; workingtree+='N'; stringstream g; g<<nodelabel; string h=g.str(); workingtree+=h;
+		}
+
+		if(c!=' ' && c!=';') workingtree+=c; 
+
+	}
+
+	return workingtree;
+
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void getlabelstring(int &label, double &length,string &mystring)
+{
+	//gets tip label name and final length from terminal branch - used in evolvebranch
+	string labelstring, lengthstring;
+	int num=0;
+	char c=mystring[num];
+	while(c!=':'){labelstring+=c;  num++;c=mystring[num]; } 
+
+	c=mystring[num]; num++;
+	
+	while(num<mystring.size()){c=mystring[num]; num++; lengthstring+=c;} 
+
+	length=atof(lengthstring.c_str());		
+	label=atoi(labelstring.c_str());
+	
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void getmynewbits(int &label, double &length,string &mystring, vector<string> &mynewbits)
+{
+	//returns length to next node and strings of each daughter branch from that node - used in evolvebranch
+	string labelstring, lengthstring;
+	int bracketlevel=1;
+	string mynewstring;
+	for(int pi1=1; pi1<mystring.size(); pi1++)
+	{
+		char c=mystring[pi1];
+		
+		if(bracketlevel==-3) lengthstring+=c;
+		if(bracketlevel==-2 && c==':') bracketlevel=-3;
+		if(bracketlevel==-2) labelstring+=c;
+		if(bracketlevel==-1 && c=='N') bracketlevel=-2;
+
+		if(bracketlevel==1 && c==',')  { mynewbits.push_back(mynewstring); mynewstring="";}
+		else{if(bracketlevel>0) mynewstring+=c;}
+		if(c=='(') bracketlevel++;
+		if(c==')') bracketlevel--;
+			
+		if(bracketlevel==0) 
+		{
+			string mynewstring2;  for(int yhb=0; yhb<mynewstring.size()-1; yhb++) mynewstring2+=mynewstring[yhb];
+			
+			mynewbits.push_back(mynewstring2); mynewstring=""; bracketlevel=-1;
+		}	
+
+	}
+
+	length=atof(lengthstring.c_str());		
+	label=atoi(labelstring.c_str());
+	
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+vector<string> MAKEmyCAUletters(int partition, int taxon)
+{
+	
+	//int gencode=((*p).geneticcodes).at(partition);
+	int gencode=(mycodes.at(partition)).at(taxon);
+	
+	vector<string> output; 
+	for(int ig=0; ig<65; ig++) {string s; s+=GeneticCodeTable[gencode][ig]; output.push_back(s); } //cout<<s<<endl;}
+
+	return output;
+
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+vector<string> MAKEmyCALletters(int partition, int taxon)
+{
+	//int gencode=((*p).geneticcodes).at(partition);
+	int gencode=(mycodes.at(partition)).at(taxon);
+
+	vector<string> output;
+	for(int ig=0; ig<65; ig++) 
+	{
+
+		string s; s+=GeneticCodeTable[gencode][ig];
+		
+		     if(s=="A") s="a";
+		else if(s=="R") s="r";
+		else if(s=="N") s="n";
+		else if(s=="D") s="d";
+		else if(s=="C") s="c";
+		else if(s=="Q") s="q";
+		else if(s=="E") s="e";
+		else if(s=="G") s="g";
+		else if(s=="H") s="h";
+		else if(s=="I") s="i";
+		else if(s=="L") s="l";
+		else if(s=="K") s="k";
+		else if(s=="M") s="m";
+		else if(s=="F") s="f";
+		else if(s=="P") s="p";
+		else if(s=="S") s="s";
+		else if(s=="T") s="t";
+		else if(s=="W") s="w";
+		else if(s=="Y") s="y";
+		else if(s=="V") s="v";
+		else cout<< "GENETIC CODE ERROR IN MAKEmyCALletters()"<<endl;
+		output.push_back(s); 
+	} //cout<<s<<endl;}
+
+
+	return output;
+
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void makeprintseqINT(int partition, int expectedcount, vector<int> &inspos, vector<int> &tempintseq, vector<insert> &insertstuff, int whichseq, ofstream &results3, int whichresults) 
+{
+	int currentcount=0, seqnow;
+
+	// leaf and ancestral printing is kept seperate for speed
+
+	// translates core sequence to alphabetical form, includes insertion and prints to file.
+	string now, blank="-", insblank="-"; if( markdeletedinsertions) insblank="*";
+	vector<string> myletters, myletters2;
+
+	if(type==1) {myletters=myDUletters; if(insertaslowercase) myletters2=myDLletters; else myletters2=myletters;}
+	else 
+	{
+		if(type==2) {myletters=myAUletters; if(insertaslowercase) myletters2=myALletters;  else myletters2=myletters;}
+		else
+		{
+			if(type==3)
+			{
+				if(printcodonsasDNA) {myletters=myCDUletters; if(insertaslowercase) myletters2=myCDLletters;  else myletters2=myletters; } 
+				else {myletters=MAKEmyCAUletters(partition,whichseq);if(insertaslowercase) myletters2=MAKEmyCALletters(partition,whichseq); else myletters2=myletters;} 
+				blank="---";insblank="---"; if( markdeletedinsertions) insblank="***";
+			}
+			else cout<<"/nERROR in makeprintseq"<<endl<<" ";
+		}
+	}
+
+	// ancestral sequences
+
+
+	//eternal link
+	if(inspos.at(0)!=-1)
+	{
+		insert* ii=&(insertstuff.at(inspos.at(0)));
+
+		//if((*ii).length==0) continue;
+
+		vector<site>* s=&( (*ii).insertvec );
+
+		for(int j=0; j<(*s).size(); j++)
+		{	
+			#ifdef checkpinv
+				if(type==3) controlerrorprint2("[SIMULATION]", "","","Type should not be 3 when using checkpinv compiler option.","");
+				if(((*s).at(j)).rate==0) continue;
+			#endif
+
+			seqnow=((*s).at(j)).base;
+
+			if(seqnow==-1) {results3<<insblank;   currentcount++;}
+			#ifdef myevolvedebugger
+			else if(seqnow>89) {results3<<"0"; currentcount++;}
+			else if(seqnow>80) {results3<<seqnow-80; currentcount++;}
+			#endif
+			else {results3<<myletters2.at(seqnow); currentcount++;}
+		}
+	}
+
+
+	for(int i=1; i<tempintseq.size(); i++)
+	{	
+
+		#ifdef checkpinv
+			if(type==3) controlerrorprint2("[SIMULATION]", "","","Type should not be 3 when using checkpinv compiler option.","");
+			if(ratevec.at(i)!=0) {
+		#endif
+
+
+		seqnow=tempintseq.at(i);
+		
+		if(seqnow==-1) {results3<<blank; currentcount++;}  
+		#ifdef myevolvedebugger
+		else if(seqnow==90) {results3<<"0"; currentcount++;}
+		else if(seqnow>80) {results3<<seqnow-80; currentcount++;}
+		#endif
+		else {results3<<myletters.at(seqnow);  currentcount++;}	
+		
+		#ifdef checkpinv
+			}
+		#endif
+		
+		if(inspos.at(i)!=-1)
+		{
+			insert* ii=&(insertstuff.at(inspos.at(i)));
+
+			//if((*ii).length==0) continue;
+
+			vector<site>* s=&( (*ii).insertvec );
+
+			for(int j=0; j<(*s).size(); j++)
+			{
+				#ifdef checkpinv
+					if(type==3) controlerrorprint2("[SIMULATION]", "","","Type should not be 3 when using checkpinv compiler option.","");
+					if(((*s).at(j)).rate==0) continue;
+				#endif
+
+				seqnow=((*s).at(j)).base;
+
+				if(seqnow==-1) {results3<<insblank;   currentcount++;}
+				#ifdef myevolvedebugger
+				else if(seqnow>89) {results3<<"0"; currentcount++;}
+				else if(seqnow>80) {results3<<seqnow-80; currentcount++;}
+				#endif
+				else {results3<<myletters2.at(seqnow); currentcount++;}
+			}
+		}
+	}  
+//if(currentcount!=expectedcount) cout<<endl<<"ERROR in length of sequence in this file"<<endl<<"currentcount was "<<currentcount<<" and expectedcount is "<<expectedcount<<endl;
+}
+
+void makeprintseqLEAF(int partition, int expectedcount, vector<int> &inspos, vector<int> &tempintseq, vector<insert>  &insertstuff, int whichseq, ofstream &results, ofstream &results2,  int whichresults) 
+{
+
+	int currentcount=0, seqnow;
+	// leaf and ancestral printing is kept seperate for speed
+
+	// translates core sequence to alphabetical form, includes insertion and prints to file.
+		string now, blank="-", insblank="-"; if( markdeletedinsertions) insblank="*";
+	vector<string> myletters, myletters2;
+
+	if(type==1) {myletters=myDUletters; if(insertaslowercase) myletters2=myDLletters; else myletters2=myletters;}
+	else 
+	{
+		if(type==2) {myletters=myAUletters; if(insertaslowercase) myletters2=myALletters; else myletters2=myletters;}
+		else
+		{
+			if(type==3)
+			{
+				if(printcodonsasDNA) {myletters=myCDUletters; if(insertaslowercase) myletters2=myCDLletters; else myletters2=myletters; } 
+				else {myletters=MAKEmyCAUletters(partition,whichseq);if(insertaslowercase) myletters2=MAKEmyCALletters(partition,whichseq); else myletters2=myletters;} 
+				blank="---"; insblank="---"; if( markdeletedinsertions) insblank="***";
+			}
+			else cout<<"/nERROR in makeprintseq"<<endl<<" ";
+		}
+	}
+	// Leaf sequences
+
+	//eternal link
+	if(inspos.at(0)!=-1)
+	{
+		insert* ii=&(insertstuff.at(inspos.at(0)));
+
+		//	if((*ii).length==0) continue;
+
+		vector<site>* s=&( (*ii).insertvec );
+
+		for(int j=0; j<(*s).size(); j++)
+		{
+			#ifdef checkpinv
+				if(type==3) controlerrorprint2("[SIMULATION]","","","Type should not be 3 when using checkpinv compiler option.","");
+				if(((*s).at(j)).rate==0) continue;
+			#endif
+
+			seqnow=((*s).at(j)).base;
+
+			if(seqnow==-1) {results<<insblank; currentcount++;}
+			#ifdef myevolvedebugger
+			else if(seqnow>89) {results<<"0"; currentcount++;}
+			else if(seqnow>80) {results<<seqnow-80; currentcount++;}
+			#endif
+			else
+			{	
+				now=myletters2.at(seqnow);  
+				results<<now; results2<<now;  currentcount++;	
+			}
+		}
+	}
+
+
+
+
+	for(int i=1; i<tempintseq.size(); i++)
+	{
+		#ifdef checkpinv
+			if(type==3) controlerrorprint2("[SIMULATION]", "","","Type should not be 3 when using checkpinv compiler option.","");
+			if(ratevec.at(i)!=0) {
+		#endif
+
+
+		seqnow=tempintseq.at(i);
+		
+		if(seqnow==-1) {results<<blank;  currentcount++;}  
+		#ifdef myevolvedebugger
+		else if(seqnow==90) {results<<"0"; currentcount++;}
+			else if(seqnow>80)  {results<<seqnow-80; currentcount++;}
+		#endif
+		else
+		{	
+			now=myletters.at(seqnow); 	 	
+			results<<now; results2<<now; currentcount++;	
+		}
+
+		#ifdef checkpinv
+			}
+		#endif
+		
+
+		if(inspos.at(i)!=-1)
+		{
+			insert* ii=&(insertstuff.at(inspos.at(i)));
+
+		//	if((*ii).length==0) continue;
+
+			vector<site>* s=&( (*ii).insertvec );
+
+			for(int j=0; j<(*s).size(); j++)
+			{
+				#ifdef checkpinv
+					if(type==3) controlerrorprint2("[SIMULATION]", "","","Type should not be 3 when using checkpinv compiler option.","");
+					if(((*s).at(j)).rate==0) continue;
+				#endif
+
+				seqnow=((*s).at(j)).base;
+
+				if(seqnow==-1) {results<<insblank; currentcount++;}
+				#ifdef myevolvedebugger
+				else if(seqnow>89) {results<<"0"; currentcount++;}
+				else if(seqnow>80) {results<<seqnow-80; currentcount++;}
+				#endif
+				else
+				{	
+					now=myletters2.at(seqnow); 	
+					results<<now; results2<<now;  currentcount++;	
+				}
+			}
+		}
+	}  
+//if(currentcount!=expectedcount) cout<<endl<<"ERROR in length of sequence in this file"<<endl<<"currentcount was "<<currentcount<<" and expectedcount is "<<expectedcount<<endl;
+}
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void PrintProgress(int blocknumber, int totalblock, int repnumber, int totalrep, int percent, string extra)
+{
+	// screen output of progress when running
+	string extra2="                          ";
+	if(extra!="") extra2=extra;
+		//cout<<"\r";
+		cout<<endl;
+		cout<<"   Block "<<blocknumber<<"/"<<totalblock<<"  rep ";
+		if(repnumber<10 && totalrep>9) {cout<<" "; }
+		if(repnumber<100 && totalrep>99) {cout<<" ";}
+		if(repnumber<1000 && totalrep>999) {cout<<" ";}
+		cout<<repnumber<<"/"<<totalrep<<"  ";
+		if(percent<100) cout<<" ";
+		if(percent<10) cout<<" ";
+		if(extra=="") cout<<percent<<" % of treelength done.  ";
+		else cout<<extra2;
+	}
+
+void PrintProgress3(int blocknumber, int totalblock, int repnumber, int totalrep, int percent, string extra)
+{
+	// screen output of progress when running
+	string extra2="                          ";
+	if(extra!="") extra2=extra;
+		//cout<<"\r";
+		cout<<endl;
+		cout<<"   Block "<<blocknumber<<"/"<<totalblock<<"  rep ";
+		if(repnumber<10 && totalrep>9) {cout<<" "; }
+		if(repnumber<100 && totalrep>99) {cout<<" ";}
+		if(repnumber<1000 && totalrep>999) {cout<<" ";}
+		cout<<repnumber<<"/"<<totalrep<<"  ";
+		
+	}
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void PrintProgress2( int blocknumber, int numberofevolveblocks, int thisrep,  int reps, int printcount)
+{
+	// screen output of progress when running
+//	stringstream fd2;  fd2<<total-1; string fd2bit=fd2.str();
+
+	stringstream fd1;  fd1<<printcount; string fd1bit=fd1.str();
+
+	string mystring="Printing sequence "+fd1bit;
+	
+
+	
+	/*
+	string mystring="Printing sequence ";
+	if(total+1>9 && printcount<10) mystring+=" ";
+	if(total+1>99 && printcount<100) mystring+=" ";
+	if(total+1>999 && printcount<1000) mystring+=" ";
+
+	string endbit=fd1bit+" of "+fd2bit+"    ";
+	mystring+=endbit;
+	*/
+	
+//	cout<<"\t"<<mystring<<endl;
+	
+	PrintProgress( blocknumber,  numberofevolveblocks,  thisrep,  reps,  100, mystring);	
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+void sumrates(RATES &rates)
+{
+/*
+	rates.totallength = rates.corelength + rates.inslength;
+
+
+//specified this way when raw
+	rates.totalrate = rates.coresubrate	+ rates.inssubrate	+(  (rates.totallength -1)*((*m).insertrate + (*m).deleterate)  ) 	
+						
+						+ (  ((*m).deleterate)*((*m).dellength)  )  + (*m).insertrate - (*m).deleterate;
+
+*/
+/*
+//but these are specified in buildsums functions
+	x1=rates.coreinsertrate; x2=((*m).insertrate)*(rates.corelength); diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.00001) {cout<<"ERROR in core insertionrate in buildsums"<<endl; cout<<rates.coreinsertrate<<"  "<<(*m).insertrate<<"  "<<rates.corelength<<"  "<<((*m).insertrate)*(rates.corelength)<<endl;}
+	x1=rates.coredeleterate; x2=((*m).deleterate)*(rates.corelength-1); diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.00001) {cout<<"ERROR in core deletionrate in buildsums"<<endl;  cout<<rates.coredeleterate<<"  "<<(*m).deleterate<<"  "<<rates.corelength<<"  "<<((*m).deleterate)*(rates.corelength)<<endl;}
+	x1=rates.insinsertrate;  x2=((*m).insertrate)*(rates.inslength);  diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.00001) {cout<<"ERROR in ins insertionrate in buildsums"<<endl;  cout<<rates.insinsertrate <<"  "<<(*m).insertrate<<"  "<<rates.inslength<<"  "<<((*m).insertrate)*(rates.inslength)<<endl;}
+	x1=rates.insdeleterate;  x2=((*m).deleterate)*(rates.inslength);  diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.00001) {cout<<"ERROR in ins deletionrate in buildsums"<<endl;   cout<<rates.insdeleterate <<"  "<<(*m).deleterate<<"  "<<rates.inslength<<"  "<<((*m).deleterate)*(rates.inslength)<<endl;}
+
+  (rates.coredeleterate)+=(  ((*m).deleterate)*(((*m).dellength)-1)  );
+ 
+  */
+
+	//so we can just say:
+
+	rates.totalrate	= rates.coresubrate	+ rates.inssubrate + rates.coredeleterate + rates.insdeleterate + rates.coreinsertrate+ rates.insinsertrate;
+
+//	cout<<"**********"<<endl;
+//	cout<<"totalrate\t"<<rates.totalrate<<"\ncoresubrate\t"<<rates.coresubrate<<"\ninssubrate\t"<<rates.inssubrate<<"\ncoredeleterate\t";
+//	cout<<rates.coredeleterate<<"\ninsdeleterate\t"<<rates.insdeleterate<<"\ncoreinsertrate\t"<<rates.coreinsertrate<<"\ninsinsertrate\t"<<rates.insinsertrate<<endl;
+
+}
+
+////////////////////
+
+
+int buildsumsold(RATES &rates, SUMS &sums, vector<int> &fromseq, vector<insert> &fromins, vector<int> &inspos) 
+{
+	int i, j, y=0,  size=rates.rootlength-1, lastinslength=rates.inslength, lastcorelength=rates.corelength;
+	double x=0, z=0;
+
+
+
+	rates.insinsertrate=0;
+	rates.insdeleterate=0;
+	rates.inssubrate=0;		
+	rates.inslength=0;	  // not used in this method
+	rates.corelength=0;  // not used in this method
+	rates.coreinsertrate=0;
+	rates.coredeleterate=0;
+	rates.coresubrate=0;				
+	
+//	cout<<endl<<"1 "<<(sums.IDsums1).size()<<endl;
+//	cout<<endl<<"2 "<<(sums.IIsums1).size()<<endl;
+//	cout<<endl<<"3 "<<(sums.CDsums1).size()<<endl;
+//	cout<<endl<<"4 "<<(sums.CIsums1).size()<<endl;
+
+	sums.myclear();
+	
+//	cout<<endl<<"1 "<<(sums.IDsums1).size()<<endl;
+//	cout<<endl<<"2 "<<(sums.IIsums1).size()<<endl;
+//	cout<<endl<<"3 "<<(sums.CDsums1).size()<<endl;
+//	cout<<endl<<"4 "<<(sums.CIsums1).size()<<endl;
+
+	(sums.ISsums1).reserve(rates.rootlength);
+	(sums.IIsums1).reserve(rates.rootlength);
+	(sums.CSsums1).reserve(rates.rootlength);
+	(sums.CIsums1).reserve(rates.rootlength);
+
+	site* s;
+	insert* ii;
+	vector<site>* ss;
+
+	for(i=0; i<rates.rootlength; i++) 
+	{
+
+		if(inspos.at(i)==-1)
+		{
+			(sums.ISsums1).push_back(0);
+			(sums.IIsums1).push_back(0);
+		}
+		else
+		{
+			//deal with insertion information.
+		
+			ii=&(fromins.at(inspos.at(i)));
+
+			ss=&((*ii).insertvec);
+
+			int templength=(*ss).size();
+
+			(*ii).subrate=0;
+			(*ii).length=0;		
+
+			for(j=0; j<templength; j++)
+			{
+
+				s=&((*ss).at(j));
+
+				if( ((*s).base)==-1 ) (*s).subrate=0; 
+
+				else
+				{
+					((*ii).length)++;	
+					(*s).subrate   =returnsitesubrate((*s).rate, (*s).siteclass, (*s).base);
+					
+					((*ii).subrate)   +=(*s).subrate;
+					
+				}
+			}
+
+			rates.insinsertrate += (  ((*m).insertrate) * ((*ii).length)  );
+			rates.insdeleterate += (  ((*m).deleterate) * ((*ii).length)  ); 
+			
+			(sums.IIsums1).push_back((*ii).length);
+			(sums.ISsums1).push_back((*ii).subrate);
+
+
+			//end of dealing with insertion information
+		}
+			
+		if(i==0)
+		{
+						
+			rates.coreinsertrate+=(*m).insertrate;
+			(sums.CIsums1).push_back(1);
+			(sums.CSsums1).push_back(0);
+
+		}
+		else
+		{
+			int test=fromseq.at(i);
+
+			if(test==-1) {(sums.CIsums1).push_back(0); (sums.CSsums1).push_back(0);}
+
+			else
+			{
+				
+				(sums.CSsums1).push_back(  returnsitesubrate(  ratevec.at(i) , siteclassvec.at(i), test )  );
+
+
+				rates.coreinsertrate+=(*m).insertrate;
+				rates.coredeleterate+=(*m).deleterate;
+				
+				(sums.CIsums1).push_back(1);
+			}
+		}		
+
+		
+	}
+
+
+	size=(sums.ISsums1).size()-1;			for(i=0; i<size+1; i++){/*x+=(sums.IDsums1).at(i);			*/ y+=(sums.IIsums1).at(i);				z+=(sums.ISsums1).at(i);			if(i%10==9 || i==size) {/*(sums.IDsums10).push_back(x); x=0;		  */ (sums.IIsums10).push_back(y); y=0;			(sums.ISsums10).push_back(z); z=0;			} }
+	size=(sums.ISsums10).size()-1;			for(i=0; i<size+1; i++){/*x+=(sums.IDsums10).at(i);			*/ y+=(sums.IIsums10).at(i);			z+=(sums.ISsums10).at(i);			if(i%10==9 || i==size) {/*(sums.IDsums100).push_back(x); x=0;		  */ (sums.IIsums100).push_back(y); y=0;		(sums.ISsums100).push_back(z); z=0;			} }
+	size=(sums.ISsums100).size()-1;			for(i=0; i<size+1; i++){/*x+=(sums.IDsums100).at(i);		*/ y+=(sums.IIsums100).at(i);			z+=(sums.ISsums100).at(i);			if(i%10==9 || i==size) {/*(sums.IDsums1000).push_back(x); x=0;		  */ (sums.IIsums1000).push_back(y); y=0;		(sums.ISsums1000).push_back(z); z=0;		} }
+	size=(sums.ISsums1000).size()-1;	    for(i=0; i<size+1; i++){/*x+=(sums.IDsums1000).at(i);		*/ y+=(sums.IIsums1000).at(i);			z+=(sums.ISsums1000).at(i);			if(i%10==9 || i==size) {/*(sums.IDsums10000).push_back(x); x=0;		  */ (sums.IIsums10000).push_back(y); y=0;		(sums.ISsums10000).push_back(z); z=0;		} }
+	size=(sums.ISsums10000).size()-1;		for(i=0; i<size+1; i++){/*x+=(sums.IDsums10000).at(i);		*/ y+=(sums.IIsums10000).at(i);			z+=(sums.ISsums10000).at(i);		if(i%10==9 || i==size) {/*(sums.IDsums100000).push_back(x); x=0;	  */ (sums.IIsums100000).push_back(y); y=0;		(sums.ISsums100000).push_back(z); z=0;		} }
+	size=(sums.ISsums100000).size()-1;		for(i=0; i<size+1; i++){/*x+=(sums.IDsums100000).at(i);		*/ y+=(sums.IIsums100000).at(i);		z+=(sums.ISsums100000).at(i);		if(i%10==9 || i==size) {/*(sums.IDsums1000000).push_back(x); x=0;	  */ (sums.IIsums1000000).push_back(y); y=0;	(sums.ISsums1000000).push_back(z); z=0;		} }
+	size=(sums.ISsums1000000).size()-1;		for(i=0; i<size+1; i++){/*x+=(sums.IDsums1000000).at(i);	*/ y+=(sums.IIsums1000000).at(i);		z+=(sums.ISsums1000000).at(i);		if(i%10==9 || i==size) {/*(sums.IDsums10000000).push_back(x); x=0;	  */ (sums.IIsums10000000).push_back(y); y=0;	(sums.ISsums10000000).push_back(z); z=0;	} }
+	size=(sums.ISsums10000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.IDsums10000000).at(i);	*/ y+=(sums.IIsums10000000).at(i);		z+=(sums.ISsums10000000).at(i);		if(i%10==9 || i==size) {/*(sums.IDsums100000000).push_back(x); x=0;	  */ (sums.IIsums100000000).push_back(y); y=0;	(sums.ISsums100000000).push_back(z); z=0;	} }
+	size=(sums.ISsums100000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.IDsums100000000).at(i);	*/ y+=(sums.IIsums100000000).at(i);		z+=(sums.ISsums100000000).at(i);	if(i%10==9 || i==size) {/*(sums.IDsums1000000000).push_back(x); x=0;  */ (sums.IIsums1000000000).push_back(y); y=0;	(sums.ISsums1000000000).push_back(z); z=0;	} }
+	size=(sums.ISsums1000000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.IDsums1000000000).at(i);	*/ y+=(sums.IIsums1000000000).at(i);	z+=(sums.ISsums1000000000).at(i);	if(i%10==9 || i==size) {/*(sums.IDsums10000000000).push_back(x); x=0; */ (sums.IIsums10000000000).push_back(y); y=0;(sums.ISsums10000000000).push_back(z); z=0;	} }
+	size=(sums.ISsums10000000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.IDsums10000000000).at(i);*/ y+=(sums.IIsums10000000000).at(i);	z+=(sums.ISsums10000000000).at(i);	if(i%10==9 || i==size) {/*(sums.IDsums).push_back(x);  				  */ (sums.IIsums).push_back(y);  				(sums.ISsums).push_back(z); 		/*(rates.insdeleterate)+=x;  (rates.insinsertrate)+=y;*/ (rates.inslength)+=y;  (rates.inssubrate)+=z;  x=0; y=0; z=0;} }
+
+	size=(sums.CSsums1).size()-1;			for(i=0; i<size+1; i++){/*x+=(sums.CDsums1).at(i);			*/ y+=(sums.CIsums1).at(i);				z+=(sums.CSsums1).at(i);			if(i%10==9 || i==size) {/*(sums.CDsums10).push_back(x); x=0;		  */ (sums.CIsums10).push_back(y); y=0;			(sums.CSsums10).push_back(z); z=0;			} }
+	size=(sums.CSsums10).size()-1;			for(i=0; i<size+1; i++){/*x+=(sums.CDsums10).at(i);			*/ y+=(sums.CIsums10).at(i);			z+=(sums.CSsums10).at(i);			if(i%10==9 || i==size) {/*(sums.CDsums100).push_back(x); x=0;		  */ (sums.CIsums100).push_back(y); y=0;		(sums.CSsums100).push_back(z); z=0;			} }
+	size=(sums.CSsums100).size()-1;			for(i=0; i<size+1; i++){/*x+=(sums.CDsums100).at(i);		*/ y+=(sums.CIsums100).at(i);			z+=(sums.CSsums100).at(i);			if(i%10==9 || i==size) {/*(sums.CDsums1000).push_back(x); x=0;		  */ (sums.CIsums1000).push_back(y); y=0;		(sums.CSsums1000).push_back(z); z=0;		} }
+	size=(sums.CSsums1000).size()-1;	    for(i=0; i<size+1; i++){/*x+=(sums.CDsums1000).at(i);		*/ y+=(sums.CIsums1000).at(i);			z+=(sums.CSsums1000).at(i);			if(i%10==9 || i==size) {/*(sums.CDsums10000).push_back(x); x=0;		  */ (sums.CIsums10000).push_back(y); y=0;		(sums.CSsums10000).push_back(z); z=0;		} }
+	size=(sums.CSsums10000).size()-1;		for(i=0; i<size+1; i++){/*x+=(sums.CDsums10000).at(i);		*/ y+=(sums.CIsums10000).at(i);			z+=(sums.CSsums10000).at(i);		if(i%10==9 || i==size) {/*(sums.CDsums100000).push_back(x); x=0;	  */ (sums.CIsums100000).push_back(y); y=0;		(sums.CSsums100000).push_back(z); z=0;		} }
+	size=(sums.CSsums100000).size()-1;		for(i=0; i<size+1; i++){/*x+=(sums.CDsums100000).at(i);		*/ y+=(sums.CIsums100000).at(i);		z+=(sums.CSsums100000).at(i);		if(i%10==9 || i==size) {/*(sums.CDsums1000000).push_back(x); x=0;	  */ (sums.CIsums1000000).push_back(y); y=0;	(sums.CSsums1000000).push_back(z); z=0;		} }
+	size=(sums.CSsums1000000).size()-1;		for(i=0; i<size+1; i++){/*x+=(sums.CDsums1000000).at(i);	*/ y+=(sums.CIsums1000000).at(i);		z+=(sums.CSsums1000000).at(i);		if(i%10==9 || i==size) {/*(sums.CDsums10000000).push_back(x); x=0;	  */ (sums.CIsums10000000).push_back(y); y=0;	(sums.CSsums10000000).push_back(z); z=0;	} }
+	size=(sums.CSsums10000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.CDsums10000000).at(i);	*/ y+=(sums.CIsums10000000).at(i);		z+=(sums.CSsums10000000).at(i);		if(i%10==9 || i==size) {/*(sums.CDsums100000000).push_back(x); x=0;	  */ (sums.CIsums100000000).push_back(y); y=0;	(sums.CSsums100000000).push_back(z); z=0;	} }
+	size=(sums.CSsums100000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.CDsums100000000).at(i);	*/ y+=(sums.CIsums100000000).at(i);		z+=(sums.CSsums100000000).at(i);	if(i%10==9 || i==size) {/*(sums.CDsums1000000000).push_back(x); x=0;  */ (sums.CIsums1000000000).push_back(y); y=0;	(sums.CSsums1000000000).push_back(z); z=0;	} }
+	size=(sums.CSsums1000000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.CDsums1000000000).at(i);	*/ y+=(sums.CIsums1000000000).at(i);	z+=(sums.CSsums1000000000).at(i);	if(i%10==9 || i==size) {/*(sums.CDsums10000000000).push_back(x); x=0; */ (sums.CIsums10000000000).push_back(y); y=0;(sums.CSsums10000000000).push_back(z); z=0;	} }
+	size=(sums.CSsums10000000000).size()-1;	for(i=0; i<size+1; i++){/*x+=(sums.CDsums10000000000).at(i);*/ y+=(sums.CIsums10000000000).at(i);	z+=(sums.CSsums10000000000).at(i);	if(i%10==9 || i==size) {/*(sums.CDsums).push_back(x);  				  */ (sums.CIsums).push_back(y);  				(sums.CSsums).push_back(z); 		/*(rates.coredeleterate)+=x;  (rates.coreinsertrate)+=y;*/ (rates.corelength)+=y; (rates.coresubrate)+=z; x=0; y=0; z=0;} } 
+
+
+	rates.corerate=rates.coreinsertrate + rates.coredeleterate;
+
+	rates.insrate=rates.insinsertrate + rates.insdeleterate ;
+
+	double x1, x2, diff;
+
+	x1=rates.coreinsertrate; x2=((*m).insertrate)*double((rates.corelength));   diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in core insertionrate in buildsums"<<endl; cout<<rates.coreinsertrate<<"  "<<(*m).insertrate<<"  "<<rates.corelength<<"  "<<((*m).insertrate)*double((rates.corelength))<<endl;}
+	x1=rates.coredeleterate; x2=((*m).deleterate)*double((rates.corelength-1)); diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in core deletionrate in buildsums"<<endl;  cout<<rates.coredeleterate<<"  "<<(*m).deleterate<<"  "<<rates.corelength<<"  "<<((*m).deleterate)*double((rates.corelength))<<endl;}
+	x1=rates.insinsertrate;  x2=((*m).insertrate)*double((rates.inslength));    diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in ins insertionrate in buildsums"<<endl;  cout<<rates.insinsertrate <<"  "<<(*m).insertrate<<"  "<<rates.inslength<<"  "<<((*m).insertrate)*double((rates.inslength))<<endl;}
+	x1=rates.insdeleterate;  x2=((*m).deleterate)*double((rates.inslength));    diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in ins deletionrate in buildsums"<<endl;   cout<<rates.insdeleterate <<"  "<<(*m).deleterate<<"  "<<rates.inslength<<"  "<<((*m).deleterate)*double((rates.inslength))<<endl;}
+
+	if(lastinslength  != rates.inslength)  cout<<"ERROR in total inserted sites length in buildsums "<<endl<<"lastinslength was "<<lastinslength<<"  and rates.inslength was "<<rates.inslength<<endl;
+	
+//	double dd; dd=lastcorelength - rates.corelength; if(dd<0) dd=-dd;
+//	if(dd>0.0001) cout<<"ERROR in total core sequence length in buildsums "<<endl<<"lastcorelength was "<<lastcorelength<<"  and rates.corelength was "<<rates.corelength<<endl;
+		
+	(rates.coredeleterate)+=(  ((*m).deleterate)*(((*m).delmeansize)-1)  );
+	sumrates(rates);
+
+	/*
+	rates.corerate=rates.coreinsertrate + rates.coredeleterate + rates.coresubrate;
+
+	rates.insrate=rates.insinsertrate + rates.insdeleterate + rates.inssubrate;
+
+	//if(lastinslength  != rates.inslength)  cout<<"ERROR in total inserted sites length in buildsums "<<endl<<"lastinslength was "<<lastinslength<<"  and rates.inslength was "<<rates.inslength<<endl;
+	//if(lastcorelength != rates.corelength) cout<<"ERROR in total core sequence length in buildsums "<<endl<<"lastcorelength was "<<lastcorelength<<"  and rates.corelength was "<<rates.corelength<<endl;
+	
+	sumratesold(rates);
+
+//	cout<<rates.totalrate<<"  is the TOTAL rate"<<endl;
+*/
+	return 0;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ 
+
+int buildsumsnew(RATES &rates, SUMS &sums, vector<int> &fromseq, vector<insert> &fromins, vector<int> &inspos) 
+{
+	int i, j, y=0, size=rates.rootlength-1, lastinslength=rates.inslength, lastcorelength=rates.corelength;
+	double x=0;
+
+	rates.insinsertrate=0;
+	rates.insdeleterate=0;
+	rates.inssubrate=0;	// not used in this method		
+	rates.inslength=0;
+	rates.corelength=0;
+	rates.coreinsertrate=0;
+	rates.coredeleterate=0;
+	rates.coresubrate=0;	// not used in this method				
+	
+	sums.myclear();
+	
+	(sums.IIsums1).reserve(rates.rootlength);	
+	(sums.CIsums1).reserve(rates.rootlength);
+
+	
+	
+	site* s;
+	insert* ii;
+	vector<site>* ss;
+
+	for(i=0; i<rates.rootlength; i++) 
+	{
+		if(inspos.at(i)==-1) (sums.IIsums1).push_back(0);
+		else
+		{
+			//deal with insertion information.
+		
+			ii=&(fromins.at(inspos.at(i)));
+
+			ss=&((*ii).insertvec);
+
+			int templength=(*ss).size();
+	
+			(*ii).length=0;
+
+			for(j=0; j<templength; j++)
+			{
+				s=&((*ss).at(j));
+
+				if( ((*s).base)!=-1 ) ((*ii).length)++;
+
+			}
+
+			//(rates.inslength)+=((*ii).length);
+
+			rates.insinsertrate += (  ((*m).insertrate) * ((*ii).length)  );
+			rates.insdeleterate += (  ((*m).deleterate) * ((*ii).length)  ); 
+			
+			(sums.IIsums1).push_back((*ii).length);
+
+			//end of dealing with insertion information
+		}
+		
+		//deal with core information
+		
+		if(i==0)
+		{
+						
+			rates.coreinsertrate+=(*m).insertrate;
+			(sums.CIsums1).push_back(1);
+		}
+		else
+		{
+			//cout<<"Q"<<endl;
+			//cout<<"fromseq length "<<fromseq.size()<<" "<<i<<endl;
+
+			if(fromseq.at(i)==-1) (sums.CIsums1).push_back(0);
+
+			else
+			{
+				//cout<<"blah"<<endl;
+				rates.coreinsertrate+=(*m).insertrate;
+//cout<<"blah"<<endl;
+				rates.coredeleterate+=(*m).deleterate;
+//cout<<"blah"<<endl;				
+				(sums.CIsums1).push_back(1);
+			}
+		
+//			cout<<"Q"<<endl;
+		}		
+	}
+//		cout<<"           QWE 2"<<endl;
+
+	
+
+
+	size=(sums.IIsums1).size()-1;			for(i=0; i<size+1; i++){y+=(sums.IIsums1).at(i);			if(i%10==9 || i==size) {(sums.IIsums10).push_back(y); y=0;} }
+	size=(sums.IIsums10).size()-1;			for(i=0; i<size+1; i++){y+=(sums.IIsums10).at(i);			if(i%10==9 || i==size) {(sums.IIsums100).push_back(y); y=0;} }
+	size=(sums.IIsums100).size()-1;			for(i=0; i<size+1; i++){y+=(sums.IIsums100).at(i);			if(i%10==9 || i==size) {(sums.IIsums1000).push_back(y); y=0;} }
+	size=(sums.IIsums1000).size()-1;	    for(i=0; i<size+1; i++){y+=(sums.IIsums1000).at(i);			if(i%10==9 || i==size) {(sums.IIsums10000).push_back(y); y=0;} }
+	size=(sums.IIsums10000).size()-1;		for(i=0; i<size+1; i++){y+=(sums.IIsums10000).at(i);		if(i%10==9 || i==size) {(sums.IIsums100000).push_back(y); y=0;} }
+	size=(sums.IIsums100000).size()-1;		for(i=0; i<size+1; i++){y+=(sums.IIsums100000).at(i);		if(i%10==9 || i==size) {(sums.IIsums1000000).push_back(y); y=0;} }
+	size=(sums.IIsums1000000).size()-1;		for(i=0; i<size+1; i++){y+=(sums.IIsums1000000).at(i);		if(i%10==9 || i==size) {(sums.IIsums10000000).push_back(y); y=0;} }
+	size=(sums.IIsums10000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.IIsums10000000).at(i);		if(i%10==9 || i==size) {(sums.IIsums100000000).push_back(y); y=0;} }
+	size=(sums.IIsums100000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.IIsums100000000).at(i);	if(i%10==9 || i==size) {(sums.IIsums1000000000).push_back(y); y=0;} }
+	size=(sums.IIsums1000000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.IIsums1000000000).at(i);	if(i%10==9 || i==size) {(sums.IIsums10000000000).push_back(y); y=0;} }
+	size=(sums.IIsums10000000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.IIsums10000000000).at(i);	if(i%10==9 || i==size) {(sums.IIsums).push_back(y); (rates.inslength)+=y; y=0;} }
+//		cout<<"           QWE 3"<<endl;
+	size=(sums.CIsums1).size()-1;			for(i=0; i<size+1; i++){y+=(sums.CIsums1).at(i);			if(i%10==9 || i==size) {(sums.CIsums10).push_back(y); y=0;} }
+	size=(sums.CIsums10).size()-1;			for(i=0; i<size+1; i++){y+=(sums.CIsums10).at(i);			if(i%10==9 || i==size) {(sums.CIsums100).push_back(y); y=0;} }
+	size=(sums.CIsums100).size()-1;			for(i=0; i<size+1; i++){y+=(sums.CIsums100).at(i);			if(i%10==9 || i==size) {(sums.CIsums1000).push_back(y); y=0;} }
+	size=(sums.CIsums1000).size()-1;	    for(i=0; i<size+1; i++){y+=(sums.CIsums1000).at(i);			if(i%10==9 || i==size) {(sums.CIsums10000).push_back(y); y=0;} }
+	size=(sums.CIsums10000).size()-1;		for(i=0; i<size+1; i++){y+=(sums.CIsums10000).at(i);		if(i%10==9 || i==size) {(sums.CIsums100000).push_back(y); y=0;} }
+	size=(sums.CIsums100000).size()-1;		for(i=0; i<size+1; i++){y+=(sums.CIsums100000).at(i);		if(i%10==9 || i==size) {(sums.CIsums1000000).push_back(y); y=0;} }
+	size=(sums.CIsums1000000).size()-1;		for(i=0; i<size+1; i++){y+=(sums.CIsums1000000).at(i);		if(i%10==9 || i==size) {(sums.CIsums10000000).push_back(y); y=0;} }
+	size=(sums.CIsums10000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.CIsums10000000).at(i);		if(i%10==9 || i==size) {(sums.CIsums100000000).push_back(y); y=0;} }
+	size=(sums.CIsums100000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.CIsums100000000).at(i);	if(i%10==9 || i==size) {(sums.CIsums1000000000).push_back(y); y=0;} }
+	size=(sums.CIsums1000000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.CIsums1000000000).at(i);	if(i%10==9 || i==size) {(sums.CIsums10000000000).push_back(y); y=0;} }
+	size=(sums.CIsums10000000000).size()-1;	for(i=0; i<size+1; i++){y+=(sums.CIsums10000000000).at(i);	if(i%10==9 || i==size) {(sums.CIsums).push_back(y); (rates.corelength)+=y; y=0;} }
+//		cout<<"           QWE 4"<<endl;
+	rates.corerate=rates.coreinsertrate + rates.coredeleterate;
+
+	rates.insrate=rates.insinsertrate + rates.insdeleterate ;
+
+	double x1, x2, diff;
+
+	x1=rates.coreinsertrate; x2=((*m).insertrate)*double((rates.corelength))  ; diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in core insertionrate in buildsums"<<endl; cout<<rates.coreinsertrate<<"  "<<(*m).insertrate<<"  "<<rates.corelength<<"  "<<((*m).insertrate)*double((rates.corelength))<<endl;}
+	x1=rates.coredeleterate; x2=((*m).deleterate)*double((rates.corelength-1)); diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in core deletionrate in buildsums"<<endl;  cout<<rates.coredeleterate<<"  "<<(*m).deleterate<<"  "<<rates.corelength<<"  "<<((*m).deleterate)*double((rates.corelength))<<endl;}
+	x1=rates.insinsertrate;  x2=((*m).insertrate)*double((rates.inslength));    diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in ins insertionrate in buildsums"<<endl;  cout<<rates.insinsertrate <<"  "<<(*m).insertrate<<"  "<<rates.inslength<<"  "<<((*m).insertrate)*double((rates.inslength))<<endl;}
+	x1=rates.insdeleterate;  x2=((*m).deleterate)*double((rates.inslength));    diff=x2-x1; if(diff<0) diff=-diff; if(diff>0.001) {cout<<diff<<" "<<x1<<" "<<x2<<" ERROR in ins deletionrate in buildsums"<<endl;   cout<<rates.insdeleterate <<"  "<<(*m).deleterate<<"  "<<rates.inslength<<"  "<<((*m).deleterate)*double((rates.inslength))<<endl;}
+ 
+	if(lastinslength  != rates.inslength)  cout<<"ERROR in total inserted sites length in buildsums "<<endl<<"lastinslength was "<<lastinslength<<"  and rates.inslength was "<<rates.inslength<<endl;
+
+//	double dd; dd=lastcorelength - rates.corelength; if(dd<0) dd=-dd;
+//	if(dd>0.0001) cout<<"ERROR in total core sequence length in buildsums "<<endl<<"lastcorelength was "<<lastcorelength<<"  and rates.corelength was "<<rates.corelength<<endl;
+
+	//if(lastcorelength != rates.corelength-1) cout<<"ERROR in total core sequence length in buildsums "<<endl<<"lastcorelength was "<<lastcorelength<<"  and rates.corelength was "<<rates.corelength<<endl;
+	
+	(rates.coredeleterate)+=(  ((*m).deleterate)*(((*m).delmeansize)-1)  );
+
+	sumrates(rates);
+
+//	cout<<rates.totalrate<<"  is the TOTAL rate"<<endl;
+
+	return 0;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+int findpos1(int event, vector<int> &updatepositions, double unirand, SUMS &sum, double &S)
+{
+	// event 1 substitution in inserted sites
+	updatepositions.clear();
+
+	int pos1=-1, pos10=-1, pos100=-1, pos1000=-1, pos10000=-1, pos100000=-1, pos1000000=-1, pos10000000=-1, pos100000000=-1, pos1000000000=-1, pos=-1;
+
+	S=0;	double s=0;	int i,j;
+
+// substitution in inserted sites
+
+		for(i=0; i<(sum.ISsums).size(); i++)			{s=(sum.ISsums).at(i);			if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1000000000=i; break;}	else S+=s; } if(pos1000000000==-1) {cout<<"1 ERROR in findpos at event "<<event<<"  unirand-S-s = "<<setprecision(20)<< unirand-S-s<<"  "<<unirand<<"  "<<S<<"  "<<s<<endl; return -1;}
+		for(i=j; i<(sum.ISsums1000000000).size(); i++)	{s=(sum.ISsums1000000000).at(i);if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos100000000=i; break;}	else S+=s; } if(pos100000000==-1) {cout<<"2 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums100000000).size(); i++)	{s=(sum.ISsums100000000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos10000000=i; break;}	else S+=s; } if(pos10000000==-1) {cout<<"3 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums10000000).size(); i++)	{s=(sum.ISsums10000000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1000000=i; break;}	else S+=s; } if(pos1000000==-1) {cout<<"4 ERROR in findpos at event "<<event<<endl; return -1;}	
+		for(i=j; i<(sum.ISsums1000000).size(); i++)		{s=(sum.ISsums1000000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos100000=i; break;}		else S+=s; } if(pos100000==-1) {cout<<"5 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums100000).size(); i++)		{s=(sum.ISsums100000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos10000=i; break;}		else S+=s; } if(pos10000==-1) {cout<<"6 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums10000).size(); i++)		{s=(sum.ISsums10000).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1000=i; break;}		else S+=s; } if(pos1000==-1) {cout<<"7 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums1000).size(); i++)		{s=(sum.ISsums1000).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos100=i; break;}		else S+=s; } if(pos100==-1) {cout<<"8 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums100).size(); i++)			{s=(sum.ISsums100).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos10=i; break;}			else S+=s; } if(pos10==-1) {cout<<"9 ERROR in findpos at event "<<event<<endl; return -1;}
+ 		for(i=j; i<(sum.ISsums10).size(); i++)			{s=(sum.ISsums10).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1=i; break;}			else S+=s; } if(pos1==-1) {cout<<"10 ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.ISsums1).size(); i++)			{s=(sum.ISsums1).at(i);			if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos=i; break;}			else S+=s; } if(pos==-1) {cout<<"11 ERROR in findpos at event "<<event<<endl; return -1;}
+
+		//cout<<S<<"  "<<unirand<<"  "<<s+S<<"   WWWWWWWWWWWWWW"<<endl;
+
+		if(S-unirand>0 || unirand-s-S>0) cout<<"CHOOSING ERROR IN FINDPOS 1"<<endl;
+
+//		int g;
+//		cout<<"CHECK 1: unirand is "; s=0; for(g=0; g<(sum.ISsums1).size(); g++) if(unirand<s+(sum.ISsums1).at(g)) break; else s+=(sum.ISsums1).at(g);
+//		cout<<unirand<<"  g is "<<g<<"  pos is "<<pos<<"  "<<s+(sum.ISsums1).at(g)<<endl;
+
+		return pos;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+int findpos0(int event, vector<int> &updatepositions, double unirand, SUMS &sum, double &S)
+{
+	//event 0	substitution in core
+	updatepositions.clear();
+
+	int pos1=-1, pos10=-1, pos100=-1, pos1000=-1, pos10000=-1, pos100000=-1, pos1000000=-1, pos10000000=-1, pos100000000=-1, pos1000000000=-1, pos=-1;
+
+	S=0;    double s=0;  	int i,j;
+
+	// substitution in core sequence
+		for(i=0; i<(sum.CSsums).size(); i++)			{s=(sum.CSsums).at(i);			if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1000000000=i; break;}	else S+=s; } if(pos1000000000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums1000000000).size(); i++)	{s=(sum.CSsums1000000000).at(i);if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos100000000=i; break;}	else S+=s; } if(pos100000000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums100000000).size(); i++)	{s=(sum.CSsums100000000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos10000000=i; break;}	else S+=s; } if(pos10000000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums10000000).size(); i++)	{s=(sum.CSsums10000000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1000000=i; break;}	else S+=s; } if(pos1000000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}	
+		for(i=j; i<(sum.CSsums1000000).size(); i++)		{s=(sum.CSsums1000000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos100000=i; break;}		else S+=s; } if(pos100000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums100000).size(); i++)		{s=(sum.CSsums100000).at(i);	if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos10000=i; break;}		else S+=s; } if(pos10000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums10000).size(); i++)		{s=(sum.CSsums10000).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1000=i; break;}		else S+=s; } if(pos1000==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums1000).size(); i++)		{s=(sum.CSsums1000).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos100=i; break;}		else S+=s; } if(pos100==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums100).size(); i++)			{s=(sum.CSsums100).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos10=i; break;}			else S+=s; } if(pos10==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+ 		for(i=j; i<(sum.CSsums10).size(); i++)			{s=(sum.CSsums10).at(i);		if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos1=i; break;}			else S+=s; } if(pos1==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CSsums1).size(); i++)			{s=(sum.CSsums1).at(i);			if(unirand<=s+S) {j=10*i; updatepositions.push_back(i); pos=i; break;}			else S+=s; } if(pos==-1) {cout<<"ERROR in findpos at event "<<event<<endl; return -1;}
+
+		if(S-unirand>0 || unirand-s-S>0) cout<<"CHOOSING ERROR IN FINDPOS 0"<<endl;
+		
+		// not needed now as simply prevent random numbers that are "EXACTLY ZERO" to be used here for that reason.
+		//if(pos==0) pos=1; // guards against pseudo-random values of unirand that are exactly zero to machine precision
+		                   //  - in this case it is possible to choose the "imaginary" eternal link position
+		                   //  which we do not want to be possible!  this will not happend if unirand is non-zero.
+
+
+
+//		int g;
+//		cout<<"CHECK 0: unirand is "; s=0; for(g=0; g<(sum.CSsums1).size(); g++) if(unirand<s+(sum.CSsums1).at(g)) break; else s+=(sum.CSsums1).at(g);
+//		cout<<unirand<<"  g is "<<g<<"  pos is "<<pos<<"  "<<s+(sum.CSsums1).at(g)<<endl;
+
+		return pos;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+int findpos24(int event, vector<int> &updatepositions,  int mypos, SUMS &sum,  int &SI)
+{
+	// this is for event 2 or 4
+	//event numbers	// in core sequence sites: 0 for substitution, 2 for insertion, 4 for deletion
+					// in inserted sites:      1 for substitution, 3 for insertion, 5 for deletion
+
+
+	updatepositions.clear();
+
+	int pos1=-1, pos10=-1, pos100=-1, pos1000=-1, pos10000=-1, pos100000=-1, pos1000000=-1, pos10000000=-1, pos100000000=-1, pos1000000000=-1, pos=-1;
+
+	SI=0;
+
+	int i,j, si=0;
+
+	// indel in core sequence
+
+		for(i=0; i<(sum.CIsums).size(); i++)			{si=(sum.CIsums).at(i);				if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000000000=i; break;}	else SI+=si; } if(pos1000000000==-1) {cout<<"ERROR in findpos1 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums1000000000).size(); i++)	{si=(sum.CIsums1000000000).at(i);	if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100000000=i; break;}	else SI+=si; } if(pos100000000==-1) {cout<<"ERROR in findpos2 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums100000000).size(); i++)	{si=(sum.CIsums100000000).at(i);	if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10000000=i; break;}	else SI+=si; } if(pos10000000==-1) {cout<<"ERROR in findpos3 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums10000000).size(); i++)	{si=(sum.CIsums10000000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000000=i; break;}	else SI+=si; } if(pos1000000==-1) {cout<<"ERROR in findpos4 at event "<<event<<endl; return -1;}	
+		for(i=j; i<(sum.CIsums1000000).size(); i++)		{si=(sum.CIsums1000000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100000=i; break;}		else SI+=si; } if(pos100000==-1) {cout<<"ERROR in findpos5 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums100000).size(); i++)		{si=(sum.CIsums100000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10000=i; break;}		else SI+=si; } if(pos10000==-1) {cout<<"ERROR in findpos6 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums10000).size(); i++)		{si=(sum.CIsums10000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000=i; break;}		else SI+=si; } if(pos1000==-1) {cout<<"ERROR in findpos7 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums1000).size(); i++)		{si=(sum.CIsums1000).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100=i; break;}		else SI+=si; } if(pos100==-1) {cout<<"ERROR in findpos8 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums100).size(); i++)			{si=(sum.CIsums100).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10=i; break;}			else SI+=si; } if(pos10==-1) {cout<<"ERROR in findpos9 at event "<<event<<endl; return -1;}
+ 		for(i=j; i<(sum.CIsums10).size(); i++)			{si=(sum.CIsums10).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1=i; break;}			else SI+=si; } if(pos1==-1) {cout<<"ERROR in findpos10 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums1).size(); i++)			{si=(sum.CIsums1).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos=i; break;}			else SI+=si; } if(pos==-1) {cout<<"ERROR in findpos11 at event "<<event<<endl; return -1;}
+
+	//	int g;
+	//	cout<<"CHECK 1: mypos is "<<mypos<<"  "<<pos<<"  "; si=0; 
+	//	cout<<(sum.CIsums1).size()<<endl;
+	//	for(g=0; g<(sum.CIsums1).size(); g++) { if(mypos<si+(sum.CIsums1).at(g)) break; else si+=(sum.CIsums1).at(g);}
+	//	cout<<mypos<<"  -g is "<<g<<"  pos is "<<pos<<"  "<<si+(sum.CIsums1).at(g)<<endl;
+
+	return pos;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+int findpos35(int event, vector<int> &updatepositions,  int mypos, SUMS &sum,  int &SI)
+{
+	// this is for event 3 or 5
+	//event numbers	// in core sequence sites: 0 for substitution, 2 for insertion, 4 for deletion
+					// in inserted sites:      1 for substitution, 3 for insertion, 5 for deletion
+
+	updatepositions.clear();
+
+	int pos1=-1, pos10=-1, pos100=-1, pos1000=-1, pos10000=-1, pos100000=-1, pos1000000=-1, pos10000000=-1, pos100000000=-1, pos1000000000=-1, pos=-1;
+
+	SI=0;
+
+	int i,j, si=0;
+
+	//indel in inserted sites
+		for(i=0; i<(sum.IIsums).size(); i++)			{si=(sum.IIsums).at(i);				if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos1000000000=i; break;}	else SI+=si; } if(pos1000000000==-1) {cout<<"ERROR in findpos1 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums1000000000).size(); i++)	{si=(sum.IIsums1000000000).at(i);	if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos100000000=i; break;}	else SI+=si; } if(pos100000000==-1) {cout<<"ERROR in findpos2 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums100000000).size(); i++)	{si=(sum.IIsums100000000).at(i);	if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos10000000=i; break;}	else SI+=si; } if(pos10000000==-1) {cout<<"ERROR in findpos3 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums10000000).size(); i++)	{si=(sum.IIsums10000000).at(i);		if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos1000000=i; break;}	else SI+=si; } if(pos1000000==-1) {cout<<"ERROR in findpos4 at event "<<event<<endl; return -1;}	
+		for(i=j; i<(sum.IIsums1000000).size(); i++)		{si=(sum.IIsums1000000).at(i);		if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos100000=i; break;}		else SI+=si; } if(pos100000==-1) {cout<<"ERROR in findpos5 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums100000).size(); i++)		{si=(sum.IIsums100000).at(i);		if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos10000=i; break;}		else SI+=si; } if(pos10000==-1) {cout<<"ERROR in findpos6 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums10000).size(); i++)		{si=(sum.IIsums10000).at(i);		if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos1000=i; break;}		else SI+=si; } if(pos1000==-1) {cout<<"ERROR in findpos7 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums1000).size(); i++)		{si=(sum.IIsums1000).at(i);			if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos100=i; break;}		else SI+=si; } if(pos100==-1) {cout<<"ERROR in findpos8 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums100).size(); i++)			{si=(sum.IIsums100).at(i);			if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos10=i; break;}			else SI+=si; } if(pos10==-1) {cout<<"ERROR in findpos9 at event "<<event<<endl; return -1;}
+ 		for(i=j; i<(sum.IIsums10).size(); i++)			{si=(sum.IIsums10).at(i);			if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos1=i; break;}			else SI+=si; } if(pos1==-1) {cout<<"ERROR in findpos10 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums1).size(); i++)			{si=(sum.IIsums1).at(i);			if(mypos<=si+SI && si+SI!=0) {j=10*i; updatepositions.push_back(i); pos=i; break;}			else SI+=si; } if(pos==-1) {cout<<"ERROR in findpos11 at event "<<event<<endl; return -1;}
+
+	//	int g;
+	//	cout<<"CHECK 2: mypos is "; si=0; for(g=0; g<(sum.IIsums1).size(); g++) if(mypos<si+(sum.IIsums1).at(g)) break; else si+=(sum.IIsums1).at(g);
+	//	cout<<mypos<<"  g is "<<g<<"  pos is "<<pos <<"  "<<si+(sum.IIsums1).at(g)<<endl;
+
+	return pos;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+/*
+
+int findposnew(int event, vector<int> &updatepositions,  int mypos, SUMS &sum,  int &SI)
+{
+	//event numbers	// in core sequence sites: 0 for substitution, 2 for insertion, 4 for deletion
+					// in inserted sites:      1 for substitution, 3 for insertion, 5 for deletion
+
+
+	updatepositions.clear();
+
+	int pos1=-1;			//position in sums10		
+	int pos10=-1;			//position in sums100		
+	int pos100=-1;			//position in sums1000		
+	int pos1000=-1;			//position in sums10000		
+	int pos10000=-1;		//position in sums100000	
+	int pos100000=-1;		//position in sums1000000	
+	int pos1000000=-1;		//position in sums		
+	int pos10000000=-1;		//position in sums		
+	int pos100000000=-1;	//position in sums		
+	int pos1000000000=-1;	//position in sums		
+	int pos=-1;
+
+	SI=0;
+	int i,j, si=0;
+
+	
+	
+	if(event==2 || event==4) // indel in core sequence
+	{
+	//	cout<<"**** "<<(sum.CIsums).back()<<endl;
+
+		for(i=0; i<(sum.CIsums).size(); i++)			{si=(sum.CIsums).at(i);			  if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000000000=i; break;}	else SI+=si; } if(pos1000000000==-1) {cout<<"ERROR in findpos1 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums1000000000).size(); i++)	{si=(sum.CIsums1000000000).at(i);	if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100000000=i; break;}	else SI+=si; } if(pos100000000==-1) {cout<<"ERROR in findpos2 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums100000000).size(); i++)	{si=(sum.CIsums100000000).at(i);	if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10000000=i; break;}	else SI+=si; } if(pos10000000==-1) {cout<<"ERROR in findpos3 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums10000000).size(); i++)	{si=(sum.CIsums10000000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000000=i; break;}	else SI+=si; } if(pos1000000==-1) {cout<<"ERROR in findpos4 at event "<<event<<endl; return -1;}	
+		for(i=j; i<(sum.CIsums1000000).size(); i++)		{si=(sum.CIsums1000000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100000=i; break;}		else SI+=si; } if(pos100000==-1) {cout<<"ERROR in findpos5 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums100000).size(); i++)		{si=(sum.CIsums100000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10000=i; break;}		else SI+=si; } if(pos10000==-1) {cout<<"ERROR in findpos6 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums10000).size(); i++)		{si=(sum.CIsums10000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000=i; break;}		else SI+=si; } if(pos1000==-1) {cout<<"ERROR in findpos7 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums1000).size(); i++)		{si=(sum.CIsums1000).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100=i; break;}		else SI+=si; } if(pos100==-1) {cout<<"ERROR in findpos8 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums100).size(); i++)			{si=(sum.CIsums100).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10=i; break;}			else SI+=si; } if(pos10==-1) {cout<<"ERROR in findpos9 at event "<<event<<endl; return -1;}
+ 		for(i=j; i<(sum.CIsums10).size(); i++)			{si=(sum.CIsums10).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1=i; break;}			else SI+=si; } if(pos1==-1) {cout<<"ERROR in findpos10 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.CIsums1).size(); i++)			{si=(sum.CIsums1).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos=i; break;}			else SI+=si; } if(pos==-1) {cout<<"ERROR in findpos11 at event "<<event<<endl; return -1;}
+
+	//	int g;
+	//	cout<<"CHECK 1: mypos is "<<mypos<<"  "<<pos<<"  "; si=0; 
+	//	cout<<(sum.CIsums1).size()<<endl;
+	//	for(g=0; g<(sum.CIsums1).size(); g++) { if(mypos<si+(sum.CIsums1).at(g)) break; else si+=(sum.CIsums1).at(g);}
+	//	cout<<mypos<<"  g is "<<g<<"  pos is "<<pos<<"  "<<si+(sum.CIsums1).at(g)<<endl;
+	}
+	else if(event==3 || event==5) //indel in inserted sites
+	{
+
+		for(i=0; i<(sum.IIsums).size(); i++)			{si=(sum.IIsums).at(i);				if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000000000=i; break;}	else SI+=si; } if(pos1000000000==-1) {cout<<"ERROR in findpos1 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums1000000000).size(); i++)	{si=(sum.IIsums1000000000).at(i);	if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100000000=i; break;}	else SI+=si; } if(pos100000000==-1) {cout<<"ERROR in findpos2 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums100000000).size(); i++)	{si=(sum.IIsums100000000).at(i);	if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10000000=i; break;}	else SI+=si; } if(pos10000000==-1) {cout<<"ERROR in findpos3 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums10000000).size(); i++)	{si=(sum.IIsums10000000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000000=i; break;}	else SI+=si; } if(pos1000000==-1) {cout<<"ERROR in findpos4 at event "<<event<<endl; return -1;}	
+		for(i=j; i<(sum.IIsums1000000).size(); i++)		{si=(sum.IIsums1000000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100000=i; break;}		else SI+=si; } if(pos100000==-1) {cout<<"ERROR in findpos5 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums100000).size(); i++)		{si=(sum.IIsums100000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10000=i; break;}		else SI+=si; } if(pos10000==-1) {cout<<"ERROR in findpos6 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums10000).size(); i++)		{si=(sum.IIsums10000).at(i);		if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1000=i; break;}		else SI+=si; } if(pos1000==-1) {cout<<"ERROR in findpos7 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums1000).size(); i++)		{si=(sum.IIsums1000).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos100=i; break;}		else SI+=si; } if(pos100==-1) {cout<<"ERROR in findpos8 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums100).size(); i++)			{si=(sum.IIsums100).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos10=i; break;}			else SI+=si; } if(pos10==-1) {cout<<"ERROR in findpos9 at event "<<event<<endl; return -1;}
+ 		for(i=j; i<(sum.IIsums10).size(); i++)			{si=(sum.IIsums10).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos1=i; break;}			else SI+=si; } if(pos1==-1) {cout<<"ERROR in findpos10 at event "<<event<<endl; return -1;}
+		for(i=j; i<(sum.IIsums1).size(); i++)			{si=(sum.IIsums1).at(i);			if(mypos<=si+SI) {j=10*i; updatepositions.push_back(i); pos=i; break;}			else SI+=si; } if(pos==-1) {cout<<"ERROR in findpos11 at event "<<event<<endl; return -1;}
+
+	//	int g;
+	//	cout<<"CHECK 2: mypos is "; si=0; for(g=0; g<(sum.IIsums1).size(); g++) if(mypos<si+(sum.IIsums1).at(g)) break; else si+=(sum.IIsums1).at(g);
+	//	cout<<mypos<<"  g is "<<g<<"  pos is "<<pos <<"  "<<si+(sum.IIsums1).at(g)<<endl;
+
+	}
+	else cout<<"EVENT ERROR in findpos "<<event<<endl;
+
+	return pos;
+}
+*/
+///////////////////////////////////////////////////////////////////////////////////////////////////
+int chooseevent(RATES &rates)
+{
+	int event=-1;	// in core sequence sites: 0 for substitution, 2 for insertion, 4 for deletion
+					// in inserted sites:      1 for substitution, 3 for insertion, 5 for deletion
+
+	double temprate=rates.coreinsertrate;
+				
+	double rand=1; while(rand==1 || rand==0){rand=mtrand1();} // prevents against pseudo-random numbers that are exactly equal to 1 or 0 to machine precision
+			
+	rand*=(rates.totalrate);
+
+	if(rand<temprate) return 2; else temprate+=(rates.insinsertrate);
+	if(rand<temprate) return 3; else temprate+=(rates.coredeleterate);
+	if(rand<temprate) return 4; else temprate+=(rates.insdeleterate);
+	if(rand<temprate) return 5; else temprate+=(rates.coresubrate);
+	if(rand<temprate) return 0; else temprate+=(rates.inssubrate);
+	if(rand<temprate) return 1; else {cout<<"ERROR IN CHOOSEEVENT - random number was "<<rand<<"  and rates.totalrate was "<<rates.totalrate<<" and temprate was "<<temprate<<endl; return -1;}
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+int updatesubsums0(vector<int> updatepositions, double sdiff, SUMS &sums) 
+{
+	// substitution in core sequence
+	
+		((sums.CSsums).at(updatepositions.at(0)))+=sdiff;
+		((sums.CSsums1000000000).at(updatepositions.at(1)))+=sdiff;
+		((sums.CSsums100000000).at(updatepositions.at(2)))+=sdiff;
+		((sums.CSsums10000000).at(updatepositions.at(3)))+=sdiff;
+		((sums.CSsums1000000).at(updatepositions.at(4)))+=sdiff;
+		((sums.CSsums100000).at(updatepositions.at(5)))+=sdiff;
+		((sums.CSsums10000).at(updatepositions.at(6)))+=sdiff;
+		((sums.CSsums1000).at(updatepositions.at(7)))+=sdiff;
+		((sums.CSsums100).at(updatepositions.at(8)))+=sdiff;
+		((sums.CSsums10).at(updatepositions.at(9)))+=sdiff;
+		((sums.CSsums1).at(updatepositions.at(10)))+=sdiff;
+
+	return 0;
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+int updatesubsums1(vector<int> updatepositions, double sdiff, SUMS &sums) 
+{
+
+	// substitution in inserted sites
+	
+		((sums.ISsums).at(updatepositions.at(0)))+=sdiff;
+		((sums.ISsums1000000000).at(updatepositions.at(1)))+=sdiff;
+		((sums.ISsums100000000).at(updatepositions.at(2)))+=sdiff;
+		((sums.ISsums10000000).at(updatepositions.at(3)))+=sdiff;
+		((sums.ISsums1000000).at(updatepositions.at(4)))+=sdiff;
+		((sums.ISsums100000).at(updatepositions.at(5)))+=sdiff;
+		((sums.ISsums10000).at(updatepositions.at(6)))+=sdiff;
+		((sums.ISsums1000).at(updatepositions.at(7)))+=sdiff;
+		((sums.ISsums100).at(updatepositions.at(8)))+=sdiff;
+		((sums.ISsums10).at(updatepositions.at(9)))+=sdiff;
+		((sums.ISsums1).at(updatepositions.at(10)))+=sdiff;	
+	
+	return 0;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int updateindelsums24(vector<int> updatepositions, int idiff, SUMS &sums) 
+{
+	// indel in core sequence
+	
+		((sums.CIsums).at(updatepositions.at(0)))+=idiff;
+		((sums.CIsums1000000000).at(updatepositions.at(1)))+=idiff;
+		((sums.CIsums100000000).at(updatepositions.at(2)))+=idiff;
+		((sums.CIsums10000000).at(updatepositions.at(3)))+=idiff;
+		((sums.CIsums1000000).at(updatepositions.at(4)))+=idiff;
+		((sums.CIsums100000).at(updatepositions.at(5)))+=idiff;
+		((sums.CIsums10000).at(updatepositions.at(6)))+=idiff;
+		((sums.CIsums1000).at(updatepositions.at(7)))+=idiff;
+		((sums.CIsums100).at(updatepositions.at(8)))+=idiff;
+		((sums.CIsums10).at(updatepositions.at(9)))+=idiff;
+		((sums.CIsums1).at(updatepositions.at(10)))+=idiff;
+
+	return 0;
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int updateindelsums35(vector<int> updatepositions, int idiff, SUMS &sums) 
+{
+	// indel in inserted sites
+	
+		((sums.IIsums).at(updatepositions.at(0)))+=idiff;
+		((sums.IIsums1000000000).at(updatepositions.at(1)))+=idiff;
+		((sums.IIsums100000000).at(updatepositions.at(2)))+=idiff;
+		((sums.IIsums10000000).at(updatepositions.at(3)))+=idiff;
+		((sums.IIsums1000000).at(updatepositions.at(4)))+=idiff;
+		((sums.IIsums100000).at(updatepositions.at(5)))+=idiff;
+		((sums.IIsums10000).at(updatepositions.at(6)))+=idiff;
+		((sums.IIsums1000).at(updatepositions.at(7)))+=idiff;
+		((sums.IIsums100).at(updatepositions.at(8)))+=idiff;
+		((sums.IIsums10).at(updatepositions.at(9)))+=idiff;
+		((sums.IIsums1).at(updatepositions.at(10)))+=idiff;	
+
+	return 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void dodeletion(int inspos, SUMS &sums,  RATES &rates, vector<int> &newseqINT, 
+				vector<int> &updatepositions, vector<insert> &insINT2, vector<int> &insPOS2, int endlength, int indellength)
+{
+
+	//inspos = -1 is deletion beginning in core.
+	//          otherwise deletion starts at position inspos in the "insert" at that core position currentev.
+
+	// event 4 is deletion in core, event 5 is deletion in inserted sites
+
+	int coreindellength=0, insindellength=0;
+	//12345567
+	site* s;
+	insert* ii;  
+	vector<site>* ss; 
+
+	deletioncount++;
+
+	int idiff=0; 
+	
+	double csdiff=0, isdiff=0, diffs=0;
+
+	
+	int currentev=updatepositions.at(10);
+
+
+#ifdef INDELLOG
+	int tttt;
+	if(inspos==-1) {tttt=1; indellog<<"deletion in core\tlength\t"<<indellength<<"\tcore pos\t"<<currentev<<"\t";}
+	else           {tttt=2; indellog<<"deletion in ins\tlength\t"<<indellength<<"\tcore pos\t"<<currentev<<"\tins pos\t"<<inspos<<"\t";}
+#endif
+
+	while(indellength>0 && currentev!=endlength)
+	{
+		if(inspos==-1)
+		{
+			if(newseqINT.at(currentev)>-1)
+			{
+
+#ifdef INDELLOG
+	if(tttt==2) {tttt=-1; indellog<<"\tthat went out to core"<<endl;}
+	indellog<<" "<<newseqINT.at(currentev)<<" ";
+#endif
+
+				indellength--;
+
+				newseqINT.at(currentev)=-1;
+
+				if(oldmethod) 
+				{
+					diffs=-((sums.CSsums1).at(currentev)); 	
+					
+					csdiff+=diffs;
+					
+					updatesubsums0(updatepositions,  diffs, sums);
+
+				}
+
+
+				//idiff=-((sums.CIsums1).at(currentev));
+			
+				coreindellength--;
+							
+				updateindelsums24(updatepositions,  -1, sums);
+			}
+
+			inspos=0;
+		}
+
+		if(insPOS2.at(currentev)!=-1) 
+		{
+
+			//ii=&(insINT2.at(currentev));
+			ii=&(insINT2.at(insPOS2.at(currentev)));
+			
+			ss=&((*ii).insertvec);
+
+			//`ddiff=0;
+			idiff=0; diffs=0;
+
+			while(indellength>0 && inspos< (*ss).size()) //(*ii).length)
+			{
+				s=&((*ss).at(inspos));
+				inspos++;
+				
+				if((*s).base==-1) continue;
+
+				
+#ifdef INDELLOG
+	if(tttt==1) {tttt=-1; indellog<<"\tthat went into an insertion"<<endl;}
+		indellog<<" "<<(*s).base<<" ";
+#endif
+
+				(*s).base=-1;
+
+				if(oldmethod)
+				{
+					diffs-=((*s).subrate);
+	
+					((*s).subrate)=0;
+				}
+				
+				idiff--;
+				indellength--;
+			}
+
+
+			if(oldmethod)
+			{
+				((*ii).subrate)+=diffs;
+				
+				isdiff+=diffs;
+
+				updatesubsums1(updatepositions,  diffs, sums);
+			}
+
+			//indellength+=idiff;
+
+			((*ii).length)+=idiff;
+
+			insindellength+=idiff;
+								
+			updateindelsums35(updatepositions,  idiff, sums);
+		}
+
+		inspos=-1;
+		currentev++;
+		(updatepositions.at(10))++;
+
+		if(currentev%10==0)			(updatepositions.at(9))++; else continue;
+		if(currentev%100==0)		(updatepositions.at(8))++; else continue;
+		if(currentev%1000==0)		(updatepositions.at(7))++; else continue;
+		if(currentev%10000==0)		(updatepositions.at(6))++; else continue;
+		if(currentev%100000==0)		(updatepositions.at(5))++; else continue;
+		if(currentev%1000000==0)	(updatepositions.at(4))++; else continue;
+		if(currentev%10000000==0)	(updatepositions.at(3))++; else continue;
+		if(currentev%100000000==0)	(updatepositions.at(2))++; else continue;
+		if(currentev%1000000000==0)	(updatepositions.at(1))++; else continue;
+		//if(currentev%10000000000==0)(updatepositions.at(0))++; else continue;
+
+	}
+
+	(rates.coreinsertrate)+=(coreindellength*((*m).insertrate));
+	(rates.coredeleterate)+=(coreindellength*((*m).deleterate));
+				
+	(rates.insinsertrate) += (insindellength*((*m).insertrate));
+	(rates.insdeleterate) += (insindellength*((*m).deleterate));
+
+	(rates.corelength) +=coreindellength;
+	(rates.inslength)  +=insindellength;
+	
+	(rates.coresubrate)   +=csdiff;
+	(rates.inssubrate)    +=isdiff;
+
+	sumrates(rates);
+
+	#ifdef INDELLOG
+		indellog<<endl;
+	#endif
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+void doinsertion(double timeleft, int inspos, SUMS &sums, RATES &rates,   vector<int> &newseqINT,  vector<int> &updatepositions, vector<insert> &insINT2, 
+					vector<vector<insert> > &insINT, int label, vector<vector<int> > &insPOS,   vector<int> &insPOS2, int indellength)
+{
+	//inspos = -1 is insertion beginning in core.
+	//          otherwise insertion starts at position inspos in the "insert" at that core position currentev.
+
+	// event 2 is insertion in core, event 3 is insertion in inserted sites
+	// 2 is never really used.
+	// if "2" i.e. an insertion in core then insertion comes at beginning of vector at <insert> for that core positions.
+
+	site* s;
+	insert* ii;  
+	vector<site>* ss; 
+	vector<insert>* ivec;
+
+	double ddiff=0, sdiff=0;
+
+	
+	(rates.insinsertrate) += (indellength*((*m).insertrate));
+	(rates.insdeleterate) += (indellength*((*m).deleterate));
+
+	(rates.inslength)	  +=indellength;
+
+	dashlength+=indellength;
+	insertioncount++;
+
+	vector<site> insertseq;  
+
+	makeseq2(indellength, insertseq, sdiff, timeleft);
+
+	int currentev=updatepositions.at(10);
+
+	if(oldmethod) updatesubsums1(updatepositions,  sdiff, sums);
+	
+
+	updateindelsums35(updatepositions, indellength, sums);
+	
+//	vector<site> blank; for(int j=0; j<indellength; j++) blank.push_back(site(-1,-1,-1,-1,-1));
+
+	vector<site> blank=insertseq; for(int j=0; j<indellength; j++) {s=&(blank.at(j)); (*s).base=-1; (*s).subrate=0; (*s).timeleft=-1; }
+
+	if(insPOS2.at(currentev)==-1)
+	{
+
+	//	if(currentev==0) cout<<"BLBL "<<currentev<<"  "<<insINT2.size()<<"  "<<insPOS2.at(currentev)<<endl;
+
+		insPOS2.at(currentev)=insINT2.size();
+				
+	//	if(currentev==0) cout<<"BLBL "<<currentev<<"  "<<insINT2.size()<<"  "<<insPOS2.at(currentev)<<endl;
+
+		insINT2.push_back(insert(insertseq,indellength,sdiff));
+
+#ifdef INDELLOG
+ indellog<<"new insertion\tlength\t"<<indellength<<"\tcore pos\t"<<currentev<<"\t";
+ for(int j=0; j<indellength; j++) {s=&(insertseq.at(j)); indellog<<(*s).base; }
+ indellog<<endl;
+#endif
+
+	}
+	else
+	{
+		ii=&(insINT2.at(insPOS2.at(currentev)));
+
+		ss=&((*ii).insertvec);
+
+		((*ii).length)+=indellength;
+
+		((*ii).subrate)+=sdiff;
+
+		if(inspos==-1)	(*ss).insert( (*ss).end(),          insertseq.begin(), insertseq.end() );
+		else			(*ss).insert( (*ss).begin()+inspos, insertseq.begin(), insertseq.end() );
+
+
+#ifdef INDELLOG
+ indellog<<"insertion in insertion\tlength\t"<<indellength<<"\tcore pos\t"<<currentev<<"\tinsert pos\t"<<inspos<<endl;
+ for(int j=0; j<indellength; j++) {s=&(insertseq.at(j)); indellog<<(*s).base; }
+ indellog<<endl;
+#endif
+		
+	}
+
+	for(int i=0; i<insINT.size(); i++)
+	{
+		if(i==label) continue;
+
+		ivec=&(insINT.at(i)); if((*ivec).empty()) continue;
+		
+		vector<int>* myinsPOS=&(insPOS.at(i));
+
+		int* temp=&((*myinsPOS).at(currentev));
+
+		if((*temp)==-1) 
+		{		
+			(*temp)=(*ivec).size();
+
+			(*ivec).push_back(insert(blank,0,0)); 
+	
+		}
+		else
+		{		
+			ii=&((*ivec).at(*temp));
+
+			ss=&((*ii).insertvec);
+	
+			if(inspos==-1)	(*ss).insert( (*ss).end(),          blank.begin(), blank.end() );
+			else			(*ss).insert( (*ss).begin()+inspos, blank.begin(), blank.end() );
+	
+		}
+
+	}
+
+	(rates.inssubrate)    += sdiff;
+
+	sumrates(rates);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+void func(int branchID, double branchlength, RATES &rates, vector<int> &newseqINT, vector<insert > &insINT2, 
+		   SUMS &sums, vector<vector<insert > >  &insINT, int label, vector<int> &insPOS2, vector<vector<int> > &insPOS)
+{
+
+	//cout<<"Q "<<rates.totalrate<<endl;
+
+	/* EVENT */		// in core sequence sites: 0 for substitution, 2 for insertion, 4 for deletion
+					// in inserted sites:      1 for substitution, 3 for insertion, 5 for deletion
+
+
+//	cout<<"NEW BRANCH"<<endl;
+	vector<int> updatepositions;  
+
+	double currenttime=branchlength, lastlength;
+
+	double exprand=expmyrand(rates.totalrate);
+
+
+
+#ifdef checkingindelsubs
+	if(mytest)	exprand=0;
+ if(mytest) cout<<"MYTEST checkingindelsubs is on"<<endl;
+
+#endif
+
+	int lastevent=-1111, event=-1111, currentbase;
+	double testlength=currenttime-0.01;
+
+int goodcount=0, badcount=0;
+
+	site* s;
+	insert* ii;  
+	vector<site>* ss; 
+
+			
+
+
+//	cout<<"***********"<<endl;
+
+//	cout<<"branchID  "<<branchID<<endl;
+ //cout<<"parent ID is "<<parentID<<endl; 
+
+//	cout<<currenttime<<"  "<<exprand<<endl;
+#ifndef checkingindelsubs
+	if(oldmethod || (*m).insertrate!=0 || (*m).deleterate!=0  ) 
+#endif		
+#ifdef checkingindelsubs
+	if(mytest || oldmethod || (*m).insertrate!=0 || (*m).deleterate!=0  )
+#endif	
+
+	while(currenttime>exprand) 
+	{
+	
+		//cout<<currenttime<<"\t"<<exprand<<"\t"<<currenttime-exprand<<endl;
+
+		currenttime-=exprand; //(((*m).Rrates).at(  ratevec.at(currentev)  ));
+
+
+		double unirand=0, sdiff=0, dsumreached=0, ratepos;
+		int    intrand=0,   sumreached=0, indellength,  currentev=-99,  j, pos=-1, siteclass;
+
+		lastevent=event;
+		
+		
+		#ifdef checkingindelsubs
+			if(mytest) event=2; else 
+		#endif
+
+		event=chooseevent(rates);	// in core sequence sites: 2 for insertion, 4 for deletion
+										// in inserted sites:      3 for insertion, 5 for deletion
+		
+	//cout<<event<<endl;
+//		if(event!=0) cout<<"WO WO WO "<<event<<endl;
+
+	//	event=0;
+
+		
+		
+
+		if(event>1)
+		{
+			// choose indel length
+			
+			#ifdef fixedindels
+				indellength=fixedsize;
+			#endif
+
+			#ifdef checkingindelsubs1
+				if(mytest) indellength=rates.partitionlength;
+			#endif
+			#ifdef checkingindelsubs2
+				if(mytest) indellength=9;
+			#endif
+			#ifdef checkingindelsubs3
+				if(mytest) indellength=1;
+			#endif
+
+			#ifdef checkingindelsubs
+				if(!mytest) {
+			#endif
+
+			if(event<4) {indellength=(*m).insrandomsize( (*m).insI, (*m).insD, (*m).insV ); insertiontotlength+=indellength;}	//length of insertion
+			else	    {indellength=(*m).delrandomsize( (*m).delI, (*m).delD, (*m).delV ); deletiontotlength+=indellength; }	//length of deletion
+
+			#ifdef printmaxindelsize
+				if(maxindelsize<indellength) 
+				{
+					cout<<"************************************"<<endl;
+					cout<<"max was "<<maxindelsize<<" now it is "<<indellength<<endl;					
+					cout<<"************************************"<<endl;
+					maxindelsize=indellength;
+				}
+			#endif 
+
+
+			#ifdef checkingindelsubs
+				}
+			#endif
+			
+
+
+			int takeoff=0;
+			int inspos=-1;
+
+			if(event==2) 
+			{
+				double blahrand=1; while(blahrand==1 || blahrand==0){blahrand=mtrand1();} // prevents against pseudo-random numbers that are exactly equal to 1 or 0 to machine precision
+			
+				intrand=int( (rates.corelength)*blahrand ) ;	//position of insertion in core sequence
+
+
+
+				//else
+				currentev=findpos24(event, updatepositions, intrand, sums, sumreached); 
+
+			}
+			else if(event==4)
+			{
+				// if rates.corelength is 1 and rates.inslength=0 then every position in the core sequence has been deleted.
+				// "core deletions" still have a non-zero positive probability due to the possibility of
+				// deletions occuring before the core sequence and therefore deleting some of the beginning 
+				// of the core sequence.  If there is nothing to delete we just ignore this.
+
+				if(rates.corelength==1 && rates.inslength==0) continue;
+
+				// e.g. Real sequence has length 100, at positions 1,2,...,99,100 but rates.corelength is 101.  
+				//		Position 0 is a "fictitious" position in core sequence to allow "eternal link" for insertions.
+				//	    Let indellength be 5,
+				//		This means rates.corelength-1 +indellength-1 = 104  
+				//		So if x is the possible random numbers of int( (rates.corelength-1 +indellength-1)*mtrand1() )
+				//		 then x can be any of 0,1,....,103
+				//		So if intrand is the possible random numbers of int( (rates.corelength-1 +indellength-1)*mtrand1() )+1-indellength 
+				//		 then intrand can be any of -4,-3,-2,-1,0,1,2,....,99
+				//		IF intrand<0 then indellength+=intrand, and intrand=0, and inspos=0;
+				//		  i.e. intrand=-4, means *indellength is 1
+				//		  i.e. intrand=-3, means *indellength is 2
+				//		  i.e. intrand=-2, means *indellength is 3
+				//		  i.e. intrand=-1, means *indellength is 4
+				//		  so deletion begins at the beginning of the insertion before "real position" 1, 
+				// 			and has new length *indellength.
+				//		BUT IF intrand>=0, then we have 0<=intrand<=99
+				//		  and we know that position 0 is not allowed and that real sequence is 1,2,...,100
+				//        so intrand must be increased by 1 to get 1<=intrand<=100
+
+				double blahrand=1; while(blahrand==1 || blahrand==0){blahrand=mtrand1();} // prevents against pseudo-random numbers that are exactly equal to 1 or 0 to machine precision
+				oldindellength=indellength;
+				intrand=int( (rates.corelength-1 +indellength-1)*blahrand )+1-indellength ;  //position of deletion in core sequence
+///			deletiontotlength-=indellength;
+				if(intrand<0) {indellength+=intrand; currentev=0; inspos=0; updatepositions.assign(11,0);  } 
+				else { intrand++; currentev=findpos24(event, updatepositions, intrand, sums, sumreached);  }
+//			deletiontotlength+=indellength;
+
+			//	if(intrand==1 && indellength==1) cout<<"event 4 "<<intrand<<"  "<<indellength<<endl;
+
+
+			}
+			else 
+			{
+				double blahrand=1; intrand=0;
+				
+				while(blahrand==1){blahrand=mtrand1(); intrand=int( (rates.inslength)*blahrand );}// if(globalthisrep==327) cout<<"blahrand "<<blahrand<<"  rates.inslength "<<rates.inslength<<"  x "<<(rates.inslength)*blahrand <<"  intrand "<<intrand<<endl;}
+				
+				//while(intrand==rates.corelength) {intrand=int( (rates.corelength)*mtrand1() ) ;}  // prevents against pseudo-random numbers that are exactly equal to 1 to machine precision
+
+				//if(intrand==0)  {updatepositions.assign(11,0); inspos=0; currentev=0;}  else 
+				currentev=findpos35(event, updatepositions, intrand, sums, sumreached); 
+			}
+			
+
+			#ifdef checkingindelsubs1
+				intrand=0;
+				currentev=findpos24(event, updatepositions, intrand, sums, sumreached);
+				
+			#endif
+			#ifdef checkingindelsubs2
+				if(mytest) {cout<<"NOW NOW "<<newseqINT.size()<<endl; for(int p=0; p<newseqINT.size(); p++) { intrand=p; /*if(p%100==0) cout<<"P "<<p<<endl;*/ currentev=findpos24(event, updatepositions, intrand, sums, sumreached);	
+			#endif
+			#ifdef checkingindelsubs3
+				if(mytest) {for(int p=0; p<newseqINT.size(); p++) { intrand=p;/* if(p%100==0) cout<<"P "<<p<<endl; 	*/	currentev=findpos24(event, updatepositions, intrand, sums, sumreached);
+			#endif
+
+		//	cout<<"HERE XXXXXX "<<currentev<<"  OH MY "<<rates.corelength<<endl;
+
+		//	if(event==4 && intrand==1 && indellength==1) cout<<"HERE 1 "<<currentev<<"  OH MY "<<rates.corelength<<endl;
+			
+			if(currentev==-1) 
+			{
+				cout<<"((((((((((((((((((((((((((((((((((((((("<<endl<<updatepositions.size()<<endl;
+				cout<<"blah"<<endl;
+ 				cout<<"intrand was "<<intrand<<endl;
+				cout<<"indellength was "<<indellength<<endl;
+				cout<<"oldindellength was "<<oldindellength<<endl;
+				cout<<"rates.corelength was "<<rates.corelength<<endl;
+				cout<<"sum reached was "<<sumreached<<endl;
+				cout<<"(*m).delmeansize is   "<<(*m).delmeansize<<endl;
+				cout<<" IIsums.back was "<<(sums.IIsums).back()<<endl;
+				cout<<" CIsums.back was "<<(sums.CIsums).back()<<endl;
+				cout<<"rates.inslength was      "<<rates.inslength<<endl;
+				cout<<"rates.coreinsertrate was "<<rates.coreinsertrate<<endl;
+				cout<<"rates.coredeleterate was "<<rates.coredeleterate<<endl;
+				cout<<"rates.insinsertrate was  "<<rates.insinsertrate<<endl;
+				cout<<"rates.insdeleterate was  "<<rates.insdeleterate<<endl;
+				for(int kp=0; kp<(sums.CIsums1).size(); kp++) cout<<(sums.CIsums1).at(kp)<<" ";
+				cout<<"blah"<<endl;
+				for(int kq=0; kq<(sums.CIsums1).size(); kq++) cout<<newseqINT.at(kq)<<" ";
+				cout<<"blah"<<endl;
+				cout<<endl<<")))))))))))))))))))))))))))))))))"<<endl;
+			}
+
+		//	if(event==4 && intrand==1 && indellength==1) cout<<"HERE 1 "<<currentev<<"  last event was "<<lastevent<<endl;
+	//
+
+			if(event==3 || event==5) //indel in inserted sites
+			{
+				// find exact position
+				int test=0;
+
+				//if(intrand==currentev) (*LOG)<<"ERROR 1 IN EVENT "<<event<<" IN funcnew()"<<endl;
+		//		if(intrand==currentev) cout<<endl<<"ERROR 1a IN EVENT "<<event<<" IN funcnew()  "<<intrand<<"  "<<currentev<<endl;
+		//		if(intrand==insPOS2.at(currentev)) cout<<endl<<"ERROR 1b IN EVENT "<<event<<" IN funcnew()  "<<endl;
+
+		//		if(currentev==-1) cout<<"CURRENTEV is -1"<<endl;
+		//		if(currentev>insPOS2.size()) cout<<currentev<<" is currentev, which is bigger than insPOS2 size "<<insPOS2.size()<<endl;
+		//		if(insPOS2.at(currentev)==-1) cout<<"insPOS2.at(currentev) is -1 and currentev is "<<currentev<<"  and intrand is "<<intrand<<"  and Isumreached is "<<Isumreached<<endl;
+		//		if(insPOS2.at(currentev)>insINT2.size()) cout<<insPOS2.at(currentev)<<" is insPOS2.at(currentev), which is bigger than insINT2 size "<<insINT2.size()<<endl;
+
+		//		cout<<"BLAH 1  "<<rates.inslength<<endl;
+		//		cout<<currentev<<"  "<<insPOS2.size()<<endl;
+		//		cout<<insPOS2.at(currentev)<<"  "<<insINT2.size()<<endl;
+
+//				if(intrand==0) {inspos=0; }// cout<<"INTRAND "<<intrand<<"\tSUMREACHED "<<sumreached<<"\tINSPOS "<<inspos<<endl;}
+//				else
+//				{
+					ii=&(insINT2.at(insPOS2.at(currentev)));
+
+				//	cout<<"BLAH 2"<<endl;
+					ss=&((*ii).insertvec);
+
+				//	cout<<"BLAH 3"<<endl;
+					for(j=0; j<(*ss).size(); j++)
+					{
+
+						s=&((*ss).at(j));
+
+						if((*s).base!=-1) {if(intrand==0) {inspos=j; break;} else test++;}
+						if(intrand==test+sumreached) {inspos=j; break;}
+
+
+
+	
+ 
+					}
+				//	cout<<"INTRAND 2 "<<intrand<<"\tSUMREACHED 2 "<<sumreached<<"\tINSPOS "<<inspos<<endl;
+			//		cout<<"BLAH 4"<<endl;
+				//	//			(*LOG)<<"2 "<<intrand<<"  "<<inspos<<"  "<<test<<"  "<<Isumreached<<"  "<<test+Isumreached<<endl;
+					if(inspos==-1)  
+					{
+						cout<<"ERROR 2 IN EVENT "<<event<<" IN funcnew()"<<endl;
+						cout<<rates.inslength<<"  2 "<<intrand<<"  "<<currentev<<"  "<<inspos<<"  "<<test<<"  "<<sumreached<<"  "<<test+sumreached<<endl;
+
+						(*LOG)<<"ERROR 2 IN EVENT "<<event<<" IN funcnew()"<<endl;
+						(*LOG)<<rates.inslength<<"  2 "<<intrand<<"  "<<currentev<<"  "<<inspos<<"  "<<test<<"  "<<sumreached<<"  "<<test+sumreached<<endl;
+					}
+					//if(inspos==-1)  cout<<"ERROR 2 IN EVENT "<<event<<" IN funcnew()"<<endl;
+//				}
+			}
+
+
+		//	cout<<"HERE 2"<<endl;
+			if(event==2 || event==3) 
+				doinsertion(currenttime, inspos, sums, rates,  newseqINT,	updatepositions, insINT2, insINT, label, insPOS, insPOS2, indellength);
+		//	cout<<"HERE 3"<<endl;
+			if(event==4 || event==5) 
+				dodeletion(inspos, sums, rates, newseqINT, updatepositions, insINT2, insPOS2, newseqINT.size() /*rates.rootlength*/, indellength);
+//12345567
+			#ifdef checkingindelsubs1
+				if(mytest) mytest=false;
+			#endif
+
+		//	cout<<"HERE 4"<<endl;
+			sumrates(rates);
+
+			#ifdef checkingindelsubs2
+				}  mytest=false; }
+			#endif
+			#ifdef checkingindelsubs3
+				}  mytest=false; }
+			#endif
+				
+		} //end of indel bracket
+		
+		else if(event==0)
+		{
+			// substitution in core sequence
+
+			substitutioncount++;
+
+			double blahrand=1; while(blahrand==1 || blahrand==0){blahrand=mtrand1();} // prevents against pseudo-random numbers that are exactly equal to 1 or 0 to machine precision
+			
+			unirand=(rates.coresubrate)*blahrand;
+
+			currentev=findpos0(event, updatepositions, unirand,  sums, dsumreached); 
+
+			if(currentev==-1) {double yh=0; for(int fg=0; fg<sums.CSsums.size(); fg++) yh+=(sums.CSsums).at(fg);	cout<<endl<<endl<<" ERROR ERROR 0  yh total is "<<yh<<" as compared to "<<rates.coresubrate<<" rates and "<<unirand<<" unirand."<<endl<<"yh - rates "<<yh-rates.coresubrate<<" yh-unirand "<<yh-unirand<<" unirand - rates "<<unirand-rates.coresubrate<<endl; }
+
+			currentbase=newseqINT.at(currentev); 
+
+			ratepos=ratevec.at(currentev);  
+
+			siteclass=siteclassvec.at(currentev);
+
+	
+			sdiff-=returnsitesubrate(ratepos,siteclass, currentbase);
+
+
+			#ifndef myevolvedebugger
+
+				chooseNEWbase(currentbase, ( ((*m).Jvecs).at(siteclass)  ).at(currentbase)  );		// choose new base
+
+			#endif
+
+		
+			newseqINT.at(currentev)=currentbase;
+
+
+			sdiff+=returnsitesubrate(ratepos,siteclass, currentbase);
+		
+
+			updatesubsums0(updatepositions, sdiff, sums);
+
+			(rates.coresubrate)   +=sdiff;
+//			(rates.coreinsertrate)+=idiff;
+//			(rates.coredeleterate)+=ddiff;
+			(rates.totalrate)     +=sdiff;
+			
+		} 
+		else if(event==1)
+		{	
+			//substitution in inserted sites
+
+
+			substitutioncount++;
+				
+			double blahrand=1; while(blahrand==1 || blahrand==0){blahrand=mtrand1();} // prevents against pseudo-random numbers that are exactly equal to 1 or 0 to machine precision
+			
+			unirand=(rates.inssubrate)*blahrand;
+
+			currentev=findpos1(event, updatepositions, unirand, sums, dsumreached); 
+
+			if(currentev==-1) {double yh=0; for(int fg=0; fg<sums.ISsums.size(); fg++) yh+=(sums.ISsums).at(fg);	cout<<endl<<endl<<" ERROR ERROR 0  yh total is "<<yh<<" as compared to "<<rates.coresubrate<<" rates and "<<unirand<<" unirand."<<endl<<"yh - rates "<<yh-rates.inssubrate<<" yh-unirand "<<yh-unirand<<" unirand - rates "<<unirand-rates.inssubrate<<endl; }
+
+			ii=&(insINT2.at(insPOS2.at(currentev)));
+
+			ss=&((*ii).insertvec);
+
+			int templength=(*ss).size();
+
+			double odsumreached=dsumreached;
+
+			for(j=0; j<templength; j++)
+			{
+				s=&((*ss).at(j));
+				
+				dsumreached+=((*s).subrate);
+							
+				if(unirand<dsumreached) 
+				{
+					pos=j;
+
+					currentbase=(*s).base;
+
+					ratepos=(*s).rate;
+					siteclass=(*s).siteclass;
+
+					#ifndef myevolvedebugger
+					
+					sdiff-=returnsitesubrate(ratepos,siteclass, currentbase);
+				//	idiff-=((*m).insertrates).at(currentbase);
+				//	ddiff-=((*m).deleterates).at(currentbase);
+
+					chooseNEWbase(currentbase,(  ((*m).Jvecs).at(siteclass)  ).at(currentbase)  );		// choose new base
+
+					(*s).subrate=returnsitesubrate(ratepos,siteclass, currentbase);
+					
+					sdiff+=((*s).subrate);
+				//	idiff+=((*m).insertrates).at(currentbase);
+				//	ddiff+=((*m).deleterates).at(currentbase);
+					
+					#else
+
+					currentbase++;
+		
+					#endif
+
+					(*s).base=currentbase;
+						
+					updatesubsums1( updatepositions, sdiff,  sums);
+
+					((*ii).subrate)      +=sdiff;
+				//	((*ii).insertrate)   +=idiff;
+				//	((*ii).deleterate)   +=ddiff;
+					(rates.inssubrate)   +=sdiff;
+				//	(rates.insinsertrate)+=idiff;
+				//	(rates.insdeleterate)+=ddiff;
+					(rates.totalrate)    +=sdiff; //+idiff+ddiff;
+
+					break;
+				}
+			}
+
+			if(pos==-1) 
+			{
+				badcount++;
+			
+				/*
+				cout<<"*********************"<<endl;
+
+				//cout<<"unirand was "<<itwas1<<" and Dsumreached was "<<itwas2<<endl;
+				//cout<<dsumreached-((*s).subrate)<<" last but one "<<endl;
+				//cout<<endl<<endl<<" ERROR ERROR 1: dsumreached was "<<dsumreached<<"  and unirand was "<<unirand<<" rates.inssubrate was "<<rates.inssubrate<<endl<<endl; 
+				
+				//cout<<"**********************************"<<endl;
+
+				
+				double mynewsum=0;
+				for(j=0; j<templength; j++)
+				{
+					s=&((*ss).at(j));
+					
+					mynewsum+=((*s).subrate);
+				}
+				if((*ii).subrate!=mynewsum) cout<<" ii subrate then true sum "<<(*ii).subrate<<"  "<<mynewsum<<endl;
+
+
+				cout<<"unirand     "<<unirand<<endl;
+				cout<<"dsumreached "<<odsumreached<<endl;
+				cout<<"dsum + ii   "<<odsumreached+(*ii).subrate<<endl;
+				cout<<"dsum + mynewsum "<<odsumreached+mynewsum<<endl;
+				cout<<"end dsum "<<dsumreached<<endl;
+				cout<<"*********************"<<endl;
+				*/
+				
+
+			}
+			else goodcount++;
+
+		}
+		else cout<<"ERROR in choosing event for func"<<endl;
+
+		exprand=expmyrand(rates.totalrate); //*(((*m).Rrates).at(  ratevec.at(currentev)  )));	
+	//	cout<<"HERE 5"<<endl;
+	}
+
+	//do substitutions
+
+
+
+if (badcount!=0) cout<<"ERROR on branch with label "<<label<<" the goodcount is "<<goodcount<<" and the badcount is "<<badcount<<endl;  //else cout<<"IT IS OK on branch with label "<<label<<endl;
+
+
+	if(type==1 && (*m).modelnumber==16) Pt=&matexp; else Pt=&PMatQRev;
+
+//cout<<" GOT TO HERE on BRANCH "<<label<<endl;
+
+	if(!oldmethod)
+	{
+		///////////////////////////////////////////////////////////////////////////////////////////////
+		// new method substitutions
+		//////////////////////////////////////////////////////////////////////////////////////////////////
+
+		if(type!=3)
+		{
+			if((*m).continuousgamma)
+			{
+				//type is 1 or 2 and it is continuous gamma
+
+				vector<vector<double> > PMat;
+
+				for(int core=1; core<rates.rootlength; core++)
+				{
+
+					currentbase=newseqINT.at(core); 
+
+					if(ratevec.at(core)==0 || currentbase==-1) continue;
+
+
+					PMat=Pt((*m).Qvec, (*m).basefreqs, branchlength*ratevec.at(core)); 
+
+					chooseNEWbase(currentbase,PMat.at(currentbase));
+					
+					newseqINT.at(core)=currentbase;
+				}
+
+				for(int ins=0; ins<insINT2.size(); ins++) 
+				{
+					ss=&((insINT2.at(ins)).insertvec);
+
+					for(int j=0; j<(*ss).size(); j++)
+					{
+						s=&((*ss).at(j));
+
+						if((*s).base!=-1 && (*s).rate!=0) 
+						{
+							double lastleft=(*s).timeleft;
+							
+							if(lastleft ==-1) 
+							{
+								PMat=Pt((*m).Qvec, (*m).basefreqs, branchlength*((*s).rate)); 
+
+								chooseNEWbase((*s).base, PMat.at((*s).base));
+							}
+							else 						
+							{
+								PMat=Pt((*m).Qvec, (*m).basefreqs, lastleft*((*s).rate));  
+
+								chooseNEWbase((*s).base, PMat.at((*s).base));
+								
+								(*s).timeleft=-1;
+							}
+
+						}
+					}
+				}
+			}//end of: type is 1 or 2 and it is continuous gamma
+
+			else
+			{
+				//type is 1 or 2 and it is not continuous gamma
+
+				vector<vector<vector<double> > > PMat2, PMat, blank;  vector<vector<double> > blank2; blank.assign((*m).numberofsiteclasses, blank2);
+
+				for(int b=0; b<(*m).numberofsiteclasses; b++) PMat.push_back(Pt((*m).Qvec, (*m).basefreqs, (((*m).Rrates).at(b))*branchlength)); 
+
+				lastlength=-1;
+
+				for(int core=1; core<rates.rootlength; core++) 
+				{
+					currentbase=newseqINT.at(core); 
+
+					if(ratevec.at(core)==0 || currentbase==-1) continue;
+
+					chooseNEWbase(currentbase,(PMat.at(siteclassvec.at(core))).at(currentbase)); 
+					newseqINT.at(core)=currentbase;
+
+				}
+
+				for(int ins=0; ins<insINT2.size(); ins++) 
+				{
+					ss=&((insINT2.at(ins)).insertvec);
+
+					for(int j=0; j<(*ss).size(); j++)
+					{
+						s=&((*ss).at(j));
+
+						if((*s).base!=-1 && (*s).rate!=0) 
+						{
+							if((*s).timeleft ==-1) chooseNEWbase((*s).base, (PMat.at((*s).siteclass)).at((*s).base));
+
+							else if((*s).timeleft==lastlength) 
+							{
+								if((PMat2.at((*s).siteclass)).empty())
+								{
+									PMat2.at((*s).siteclass)=Pt((*m).Qvec, (*m).basefreqs, ((*s).rate)*lastlength);
+								}
+
+								chooseNEWbase(  (*s).base, (PMat2.at((*s).siteclass)).at((*s).base)  );
+			
+								(*s).timeleft=-1;
+							}
+							else 
+							{
+								lastlength=(*s).timeleft;
+
+								PMat2=blank;
+								
+								PMat2.at((*s).siteclass)=Pt((*m).Qvec, (*m).basefreqs, ((*s).rate)*lastlength) ;
+
+								chooseNEWbase(  (*s).base, (PMat2.at((*s).siteclass)).at((*s).base)  );
+
+								(*s).timeleft=-1;
+
+							}
+						}
+					}
+				}
+			}			
+		}
+		else 
+		{
+			vector<vector<vector<double> > > PMat2, PMat, blank;  vector<vector<double> > blank2; blank.assign((*m).numberofsiteclasses, blank2);
+			
+			for(int nc=0; nc<(*m).numberofsiteclasses; nc++) PMat.push_back(Pt(((*m).Qvecs).at(nc), (*m).basefreqs, branchlength)); 
+
+			lastlength=-1;
+
+			//vector<int> fgh; fgh.assign(5,0);
+			for(int core=1; core<rates.rootlength; core++) 
+			{
+				currentbase=newseqINT.at(core); 
+
+				if(currentbase==-1) continue;
+				
+				//int ghp=siteclassvec.at(core);  (fgh.at(ghp))++;
+				//int ghp=fgh.at(siteclassvec.at(core));  fgh.at(siteclassvec.at(core))=ghp+1;
+				
+				chooseNEWbase(currentbase,(PMat.at(siteclassvec.at(core))).at(currentbase)); 
+				
+				newseqINT.at(core)=currentbase;
+			}
+	
+
+
+			//fgh.assign(5,0);
+//			cout<<"insINT2.size() "<<insINT2.size()<<endl;
+			for(int ins=0; ins<insINT2.size(); ins++) 
+			{
+			
+				ss=&((insINT2.at(ins)).insertvec);
+
+//				cout<<"(*ss).size() "<<(*ss).size()<<endl;
+
+				for(int j=0; j<(*ss).size(); j++)
+				{
+					s=&((*ss).at(j));
+
+					if((*s).base!=-1) 
+					{
+						//(fgh.at((*s).siteclass))++;
+						if((*s).timeleft ==-1) chooseNEWbase((*s).base, (PMat.at((*s).siteclass)).at((*s).base));
+
+						else if((*s).timeleft==lastlength) 
+						{
+							if((PMat2.at((*s).siteclass)).empty())
+							{
+								PMat2.at((*s).siteclass)=Pt(((*m).Qvecs).at((*s).siteclass), (*m).basefreqs, lastlength);
+							}
+
+							chooseNEWbase(  (*s).base, (PMat2.at((*s).siteclass)).at((*s).base)  );
+		
+							(*s).timeleft=-1;
+						}
+						else 
+						{
+							lastlength=(*s).timeleft;
+
+							PMat2=blank;
+							
+							PMat2.at((*s).siteclass)=Pt(((*m).Qvecs).at((*s).siteclass), (*m).basefreqs, lastlength) ;
+
+							chooseNEWbase(  (*s).base, (PMat2.at((*s).siteclass)).at((*s).base)  );
+
+							(*s).timeleft=-1;
+
+						}
+					}
+				}
+			}
+
+		}
+	} // end of new method substitutions if
+
+	//buildsumsnew(rates, sums, newseqINT, insINT2, insPOS2);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+int findnext(vector<double> currenttime)
+{
+	
+	double max=0;
+	int maxpos=-1;
+
+	for(int yg=0; yg<currenttime.size(); yg++) 
+	{
+		double x=currenttime.at(yg);
+		if(x>max)	{max=x; maxpos=yg;}
+	}
+	return maxpos;
+}
+
+////////////////////
+// took "&" off of insPOS and insINT.  there is problem. on e.g. ((A,B)AB,(C,D)CD);  root to AB is ok, and AB to A is ok, but AB to B is wrong as insPOS and insINT changed
+
+void evolvebranch(vector<vector<int> > &insPOS, /*vector<int> &oldinsPOSin,*/ RATES rates, int parentID, int &branchID, int totalpartitions, int partitionnumber, vector<vector<insert > >  &insINT,  
+				 /* vector<insert> &oldinsIN,*/ int parentlabel,  vector<vector<int> > &sequencesINT,  string mystring,/* vector<int>  &oldseqIN, */ 
+				  int blocknumber, int repnumber, int totalblock, int totalrep,  SUMS sums)
+{
+	// this function performs the main structure of evolving a particular branch.
+	// if the branch is a tip it simply evolves the terminal branch length
+	// if the branch is internal it evolves to the next node and recursively calls itself on the daughter branches
+
+	int mymode=0, ev=0, label, newID=0;
+
+	
+
+#ifdef checkingindelsubs
+	if(parentlabel==0) mytest=true;
+#endif
+
+	int skip=0;
+	int myadjust=0;
+
+	double length;
+	vector<string> mynewbits;
+
+	if(mystring[0]!='(') mymode=-1;								// this means it is not a terminal branch e.g. (1:0.1,2:0.2):0.3 instead of A:0.1
+
+	if(mymode==-1)	getlabelstring(label,length,mystring);		// in this case the length would be 0.1 and the label would be "1"
+	else getmynewbits(label,length,mystring, mynewbits);		// in this case the length would be 0.3 and mynewbits would contain "1:0.1" and "2:0.2"
+
+	int siteclass=-1;
+
+	
+	// calculating tree length percent remaining to be evolved
+	currenttreelength-=length;
+	
+	int percent=int(100*(treelength-currenttreelength)/treelength);
+
+
+#ifdef INDELLOG
+	indellog<<"*********************************************************************************"<<endl;
+	indellog<<" branch label\t"<<label<<"\tparent:\t"<<parentlabel<<endl;
+	indellog<<"*********************************************************************************"<<endl;
+#endif
+
+
+	sequencesINT.at(label)=sequencesINT.at(parentlabel);
+
+	insINT.at(label)=insINT.at(parentlabel);
+
+	insPOS.at(label)=insPOS.at(parentlabel);
+	
+	/*
+	sequencesINT.at(label)=oldseqIN;
+
+	insINT.at(label)=oldinsIN;
+
+	insPOS.at(label)=oldinsPOSin;
+	*/
+	
+	//if(isitbranches) b=&(totalbranches.at( ((*p).mbsposvec).at(partitionnumber) ));
+
+	//cout<<"LABEL "<<label<<"    PARENTLABEL "<<parentlabel<<endl;
+
+
+
+		if(isitbranches) 
+		{
+			//branches model OR  sites-branches model
+			
+			int oldoldpos=((*b).modelpositions).at(branchID);
+		
+			
+			branchID++; newID=branchID;
+
+
+			double oldalpha=(*m).alpha;
+			bool oldcontinuousgamma=(*m).continuousgamma;
+
+			//cout<<"old alpha is "<<oldalpha<<endl;
+		
+
+			int oldpos=((*b).modelpositions).at(parentID);
+			
+	
+			int mypos=((*b).modelpositions).at(branchID);
+		
+			//cout<<totalmodels.size()<<"  "<<mypos<<endl;
+			m=&(totalmodels.at( mypos ));
+		
+
+			if(oldpos!=mypos || oldoldpos!=mypos)
+			{
+				changezipfrandoms();
+
+				if( ((*m).continuousgamma||oldcontinuousgamma) && oldalpha!=(*m).alpha) 
+				{
+					bool nothing=false; if((*m).alpha==0) nothing=true; //  if(((*m).Rrates).size()>0) nothing=true;
+
+					for(int t1=0; t1<rates.rootlength; t1++)
+					{
+						double rand=mtrand1();
+			
+						if(rand<(*m).pinv) ratevec.at(t1)=0; 
+						else 
+						{
+							if(nothing) ratevec.at(t1)=1/(1- ((*m).pinv) );
+							else ratevec.at(t1)=rndgamma(  ((*m).alpha)  )/(  ((*m).alpha)* (1- ((*m).pinv) )  );
+						}
+					}	
+
+
+
+					vector<insert>* ins=&(insINT.at(label));
+
+					for(int t2=0; t2<(*ins).size(); t2++)
+					{
+						insert* ii=&((*ins).at(t2));
+			
+						vector<site>* s=&( (*ii).insertvec );
+
+						for(int t3=0; t3<(*s).size(); t3++)
+						{
+							site* ss=&((*s).at(t3));
+
+							if(  (*ss).base >=0  ) 
+							{
+								double rand=mtrand1();
+				
+								if(rand<(*m).pinv) (*ss).rate=0; 
+								else
+								{ 
+									if(nothing) (*ss).rate=1/(1- ((*m).pinv) );
+									else (*ss).rate=rndgamma(  ((*m).alpha)  )/(  ((*m).alpha)* (1- ((*m).pinv) )  ) ;
+								}
+							}	
+						}
+					}
+
+				}
+				else if( type!=3 && oldalpha!=(*m).alpha )
+				{
+					mymods.push_back(mypos);
+
+					for(int t1=0; t1<rates.rootlength; t1++) {ratevec.at(t1)=((*m).Rrates).at(siteclassvec.at(t1));}
+
+
+					vector<insert>* ins=&(insINT.at(label));
+
+
+					for(int t2=0; t2<(*ins).size(); t2++)
+					{
+						insert* ii=&((*ins).at(t2));
+			
+						vector<site>* s=&( (*ii).insertvec );
+
+						for(int t3=0; t3<(*s).size(); t3++) 
+						{
+							site* ss=&((*s).at(t3));
+
+							if(  (*ss).base >=0  ) (*ss).rate=((*m).Rrates).at((*ss).siteclass);
+						}
+					}
+
+
+				} 
+			}//end of oldpos mypos if bracket
+
+		} //end of isitbranches if bracket
+
+		else branchID=0;
+
+		if(oldmethod)	buildsumsold(rates, sums, sequencesINT.at(label), insINT.at(label), insPOS.at(label));
+		else		buildsumsnew(rates, sums, sequencesINT.at(label), insINT.at(label), insPOS.at(label));
+			
+
+
+func(branchID, length, rates, sequencesINT.at(label), insINT.at(label),  sums, insINT, label, insPOS.at(label), insPOS); 
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+	deletionlength=0;  
+	// deletionlength is global int.  simply resetting values so that it does not carry over from 
+	// the end of one sequence to the beginning of the first daughter sequence.
+
+
+
+
+//	string fccc; if(totalpartitions>1) {stringstream fc; fc<<partitionnumber+1; string fcc=fc.str();  fccc="Partition "+fcc+"                         ";} 
+//	PrintProgress( blocknumber,  totalblock,  repnumber,  totalrep,  percent,fccc);	// print progress, percentage of treelength complete
+
+	if(mymode!=-1)
+	{
+		// mymode = -1 when terminal branch
+		// so this if bracket recursively calls evolvebranch on the daughter branches of the current branch
+		for(int asdf3=0; asdf3< mynewbits.size(); asdf3++)
+		{
+			string mynextbit=mynewbits.at(asdf3);
+			evolvebranch(insPOS, /*insPOS.at(label),*/ rates, newID, branchID, totalpartitions, partitionnumber, insINT, /*insINT.at(label),*/ label, sequencesINT,mynextbit, 
+			/*	sequencesINT.at(label),*/  blocknumber, repnumber, totalblock, totalrep, sums); 
+
+
+
+
+
+
+
+		}
+	}
+
+//	cout<<"HERE 1 "<<endl;
+//
+//segmentation fault with any gamma model except branches gamms
+//	if(isitbranches)
+
+//		if( !((*b).geneticcodefixed) )
+//		{
+	
+			(mycodes.at(partitionnumber)).at(label)=(*m).geneticcode;
+//		}
+
+//	cout<<"HERE 2 "<<endl;
+
+
+}  // end of evolvebranch function
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+int settreeup(int partitionnumber, string &originaltree, string &nonamestree, string &origtreewithnodes,  string &nonamestreewithnodes, int &startnodelabel, vector<string> &taxanames, int &ntaxa)
+{
+	// called at the end of the call control function
+
+	// this function takes the guide tree and creates a version with numbers instead of taxanames
+	// and adds interior node labels to a copy of the original tree and to a copy of the numbered tree
+	// a taxon name gets replace by "label" and an interior node is labelled N+"label" where "label"
+	// is a number corresponding to the position of that nodes' sequence in sequencesINT
+
+	origtreewithnodes=nonamestree=nonamestreewithnodes="";
+	int error=0;
+	int printon=0;
+
+	int bracketright=0, bracketleft=0;
+
+	originaltree=nowhitespace(originaltree);
+
+
+	if(printon==1) cout<<originaltree<<endl<<"dgfweg "<<endl<<" wegweg"; 
+
+	error=gettaxanames(partitionnumber, originaltree,taxanames);
+
+	ntaxa=taxanames.size()-2;
+	if(printon==1) for(int gn1=0; gn1<taxanames.size(); gn1++){cout<<gn1<<" "<<taxanames.at(gn1)<<endl<<" ";}
+	nonamestree=taxanames.at(taxanames.size()-1);
+	taxanames.pop_back();
+
+	startnodelabel=taxanames.size()-1;
+	origtreewithnodes=addnodestostring(originaltree,startnodelabel);
+
+	startnodelabel++;
+	//origtreewithnodes+='N'; stringstream sd; sd<<startnodelabel; string fv=sd.str(); origtreewithnodes+=fv; origtreewithnodes+=';';
+	origtreewithnodes+="ROOT;";
+
+	startnodelabel=taxanames.size()-1;
+	nonamestreewithnodes=addnodestostring(nonamestree,startnodelabel);
+
+	startnodelabel++;
+	nonamestreewithnodes+='N'; stringstream sd1; sd1<<startnodelabel; string fv1=sd1.str(); nonamestreewithnodes+=fv1; nonamestreewithnodes+=';';
+	//nonamestreewithnodes+="ROOT;";
+	
+
+	// add interior node labels to the taxa names list
+	for(int gn2=taxanames.size(); gn2<startnodelabel+1; gn2++)
+	{
+		stringstream gbh; gbh<<gn2; string gbhs=gbh.str();
+		string metaxa="N"+gbhs; taxanames.push_back(gbhs);
+	}
+
+
+
+	return error;
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void sorttreeout(vector<vector<int> > &insPOS, RATES &rates, vector<vector<insert > > &insINT, int mynodelabel, string workingtree, int currentrep, int &ntaxa, vector<string> &taxanames, 
+				 vector<vector<int> > &sequencesINT,  int blocknumber, int repnumber, int totalblock, int totalrep, int partitionnumber, int totalpartitions, 
+				SUMS &sums)
+
+{
+
+
+	// this function simply splits the tree into branches from the root and sends them off to be evolved one by one
+	string fccc; if(totalpartitions>1) {stringstream fc; fc<<partitionnumber+1; string fcc=fc.str();  fccc="Partition "+fcc+"                         ";} 
+
+//	PrintProgress( blocknumber,  totalblock,  repnumber,  totalrep,  0, fccc);
+
+	//	PrintProgress3( blocknumber,  totalblock,  repnumber,  totalrep,  0, fccc);
+
+	char c='Q'; 
+	int mybracketlevel=0;
+	string abranch;
+
+
+	int mylim=workingtree.size()-1;
+	int currentbranchnumber=0;
+
+	for(int yu1=1; yu1<mylim+1; yu1++)
+	{
+		// goes through guide tree and seperates into branches from root
+		c=workingtree[yu1];
+		if( (c==',' && mybracketlevel==0) || yu1==mylim) 
+		{	
+			////
+
+
+			// evolves a branch from root once parsing of that branch is complete
+			evolvebranch(insPOS, rates, currentbranchnumber,currentbranchnumber, totalpartitions, partitionnumber, insINT,
+				0, sequencesINT, abranch,  blocknumber, repnumber, totalblock, totalrep, sums);
+			
+			abranch="";											
+
+		}
+		else abranch+=c; 
+		
+		if(c==')') mybracketlevel--; else if(c=='(') mybracketlevel++;
+		
+	}
+
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void controlerrorprint(int blocknumber, string instring, int linecount, string myline)
+{
+	// this functions provides a framework for a standard output of an error to the screen and log file
+	// mostly it is just formatting the border of the error box and white space etc
+
+	cout<<"\r ERROR occurred in block "<<blocknumber<<".  See below for details or consult LOG.txt                       ";
+
+	vector<string> toprint;
+	
+	string startline="ERROR in command line number ";
+	stringstream fd1; fd1<<linecount; string fd1s=fd1.str();
+	startline+=fd1s; startline+=" of control file:";
+	
+	toprint.push_back(startline);
+
+	string tempstring;
+	char c;
+	int themaxsize=startline.size();
+	
+	for(int j0=0; j0<instring.size(); j0++) 
+	{
+		c=instring[j0]; 
+		if(c=='\n') 
+		{
+			toprint.push_back(tempstring);
+			if(themaxsize<tempstring.size()) themaxsize=tempstring.size();
+			tempstring="";
+		} 
+		else tempstring+=c;
+	} 
+	toprint.push_back(tempstring);if(themaxsize<tempstring.size()) themaxsize=tempstring.size();
+	
+	string endline="Last Input was: "; endline+=myline; if(themaxsize<endline.size()) themaxsize=endline.size(); toprint.push_back(endline);
+
+	cout<<endl<<endl; (*LOG)<<endl;
+
+	for(int i0=0; i0<toprint.size(); i0++)
+	{
+		string tempstring2=toprint.at(i0);
+		for(int h1=tempstring2.size(); h1<themaxsize; h1++) tempstring2+=" ";
+		toprint.at(i0)=tempstring2;
+	}
+
+	cout<<endl<<" +";  (*LOG)<<endl<<"+";  
+	for(int i1=0; i1<themaxsize+2; i1++) {cout<<"-"; (*LOG)<<"-";}
+	cout<<"+"<<endl;	(*LOG)<<"+"<<endl;
+	
+	for(int i2=0; i2<toprint.size(); i2++) {cout<<" | "<<toprint.at(i2)<<" |"<<endl; (*LOG)<<"| "<<toprint.at(i2)<<" |"<<endl;}
+	
+	cout<<" +"; (*LOG)<<"+"; 
+	for(int i3=0; i3<themaxsize+2; i3++) {cout<<"-"; (*LOG)<<"-";}
+	cout<<"+"<<endl<<endl;	(*LOG)<<"+"<<endl<<endl;
+
+	
+}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void printresultsout(int currentrep,  string filenamestub, int ntaxa, int mylength, vector<string> taxanames, int blocknumber,  int numberofevolveblocks,  int thisrep,  int reps, int numberofpartitions)
+{
+//	cout<<endl<<endl<<" Printing leaf sequences"<<endl;
+
+
+	// this function provides the skeleton structure of printing results to file.
+	// the actual translation of integer sequences to alphabetical ones, and the 
+	// printing to file of these sequences is performed by makeprintseq
+
+
+	int Mlength=mylength-numberofpartitions+dashlength; int lastlengthcount=Mlength;  
+	//string length; 
+	//stringstream L;
+
+	#ifdef checkpinv
+	int oldMlength=Mlength;
+	cout<<"LENGTH WAS "<<Mlength<<endl;
+	Mlength=Mlength-inspinvcount-corepinvcount;
+	cout<<" but now it is "<<Mlength;
+	cout<<" this means pinv of "<<double(oldMlength-Mlength)/double(oldMlength)<<endl;
+	#endif
+
+	/*
+
+	#ifdef checkpinv
+
+	cout<<endl<<" WARNING: checkpinv compiler option should not be used when indels are on"<<endl<<endl;
+	double inspinvcount=0, corepinvcount=0, instotalcount=0, coretotalcount=ratevec.size();
+
+	for(int i=1; i<ratevec.size(); i++) 
+	{
+		coretotalcount++;
+		if(ratevec.at(i)==0) corepinvcount++; 
+	}
+
+ 	(TinsPOS.at(j)).at(i), (TsequencesINT.at(j)).at(i), (TinsINT.at(j)).at(i),
+
+	for(int j=0; j<(TinsINT.at(
+	//eternal link
+	if(inspos.at(0)!=-1)
+	{
+		insert* ii=&(insertstuff.at(inspos.at(0)));
+
+		//if((*ii).length==0) continue;
+
+		vector<site>* s=&( (*ii).insertvec );
+
+		for(int j=0; j<(*s).size(); j++)
+		{	
+			#ifdef checkpinv
+				if(type==3) controlerrorprint2("[SIMULATION]", "","","Type should not be 3 when using checkpinv compiler option.","");
+				if(((*s).at(j)).rate==0) continue;
+			#endif
+
+			seqnow=((*s).at(j)).base;
+
+			if(seqnow==-1) {results3<<blank;   currentcount++;}
+
+
+	*/
+
+	if(printcodonsasDNA && type==3) Mlength*=3;
+
+	//L<<Mlength; length=L.str();
+
+	string filename1=filenamestub+"_TRUE_";			// true alignment
+	string filename2=filenamestub+"_";				// true unaligned sequences
+	string filename3=filenamestub+"_ANCESTRAL_";	// Ancestral sequences
+	string endbit=".";
+
+	if(fileperrep)
+	{
+		stringstream asdd; asdd<<currentrep; string currentrepS=asdd.str();
+
+		// choose file extension depending on desired output type
+		if(outputtype==1) endbit+=fastaextension; else if(outputtype==2) endbit+=phylipextension; else if(outputtype==3) endbit+=nexusextension;
+		filename1+=currentrepS; 
+		filename1+=endbit;
+		filename2+=currentrepS; 
+		filename2+="."; 
+		filename2+=fastaextension; //filename2+=endbit;   // unaligned sequences always output in FASTA format
+		filename3+=currentrepS; 
+		filename3+=endbit;
+
+	//	ofstream results(filename1.c_str());
+	//	ofstream results2(filename2.c_str());
+
+		(*results).close();  (*results2).close();
+		(*results).clear();  (*results2).clear();
+
+	//	(*results)=new ofstream;
+		(results)->open(filename1.c_str());   	
+	//	(*results2)=new ofstream;
+		(results2)->open(filename2.c_str());  	
+
+		(*results)<<paupstart;		
+	}
+
+	//results2<<" "; results3<<" ";
+	
+#ifdef INDELLOG
+	(*results)<<"*********************************************************************************"<<endl;
+	(*results)<<origtreewithnodes<<endl;
+	(*results)<<"*********************************************************************************"<<endl;
+#endif
+
+		if(outputtype==3)
+		{	
+			// header for nexus file format
+			(*results)<<"#NEXUS"<<endl<<endl<<"BEGIN DATA;"<<endl<<"   DIMENSIONS NTAX = "<<ntaxa<<"  NCHAR = "<<fixed<<setprecision(0)<<Mlength<<";"<<"   FORMAT DATATYPE = "; 
+			if(type==2) (*results)<<"PROTEIN"; else (*results)<<"DNA"; (*results)<<"  MISSING = ?  GAP = - ;"<<endl<<"   MATRIX"<<endl;
+		}
+
+		// header for phylip format
+		if(outputtype==2) (*results)<<ntaxa<<"  "<<fixed<<setprecision(0)<<Mlength<<""<<endl;
+		int printcount=0;
+		
+	//	int seqINTsize=sequencesINT.size();
+	//	(*results)<<"     "<<endl; (*results2)<<"     "<<endl;
+		for(int i=1; i<ntaxa+1; i++)
+		{	
+			
+			//Leaf sequences (true sequences in (*results2), and true alignment in results)
+			(*results2)<<">";
+			if(outputtype==1) (*results)<<">"; else if(outputtype==3) (*results)<<"   ";  
+			(*results)<<taxaspacenames.at(i);
+			(*results2)<<taxaspacenames.at(i);
+			if(outputtype==1) (*results)<<""<<endl; 
+			(*results2)<<""<<endl;
+				
+			printcount++;
+
+		//	PrintProgress2( blocknumber,  numberofevolveblocks,  thisrep,  reps, printcount);
+
+			for(int j=0; j<TsequencesINT.size(); j++) makeprintseqLEAF(j,lastlengthcount, (TinsPOS.at(j)).at(i), (TsequencesINT.at(j)).at(i), (TinsINT.at(j)).at(i), i, (*results), (*results2),  0) ;
+			(*results)<<"     "<<endl; (*results2)<<"     "<<endl;
+		}
+
+//cout<<endl;
+
+
+if(ancestralprint)
+{
+	if(ancestralfile)
+	{
+		//ofstream results3(filename3.c_str());
+		if(fileperrep)
+		{
+		//	(*results3)=new ofstream;
+			
+			(*results3).close(); (*results3).clear();
+			(results3)->open(filename3.c_str());
+		}
+
+			if(!printonlyroot)
+			{//cout<<endl<<" Printing ancestral sequences:"<<endl;
+				// This if loop will print the ancestral sequences into results3
+				// but only if there is one partition. 
+				// This is because a multi-partition simulation could have different underlying guide tree topologies
+				for(int i=ntaxa+1; i<(TsequencesINT.at(0)).size()-1; i++)
+				{	
+					//Ancestral Sequences into results3
+					//if(hf2!=seqINTsize-1)
+					//{
+						if(outputtype==1) (*results3)<<">"; 
+						(*results3)<<"N"<<i<<"\t";
+						if(outputtype==1) (*results3)<<""<<endl; 
+					
+						printcount++;
+
+				//		PrintProgress2( blocknumber,  numberofevolveblocks,  thisrep,  reps, printcount);
+						
+						for(int j=0; j<TsequencesINT.size(); j++) makeprintseqINT(j,lastlengthcount, (TinsPOS.at(j)).at(i), (TsequencesINT.at(j)).at(i),(TinsINT.at(j)).at(i),i,(*results3), 1); 
+						(*results3)<<"     "<<endl;
+
+					//}
+
+				}
+			}
+
+				//Root Sequnces
+		
+		if(outputtype==1) (*results3)<<">"; 
+		(*results3)<<"ROOT\t";
+		if(outputtype==1) (*results3)<<""<<endl; 
+
+		printcount++;
+//		PrintProgress2( blocknumber,  numberofevolveblocks,  thisrep,  reps, printcount);
+//		cout<<" Printing root."<<endl;
+		
+		for(int j=0; j<TsequencesINT.size(); j++) makeprintseqINT(j,lastlengthcount, (TinsPOS.at(j)).at(0), (TsequencesINT.at(j)).at(0),(TinsINT.at(j)).at(0),0,*results3, 1); 
+		(*results3)<<"     "<<endl;
+	}
+	else
+	{
+		// no seperate ancestral file, ancestral sequences go in main alignment file
+
+		int dsize=(taxaspacenames.at(1)).size();
+		if(!printonlyroot)
+		{
+		//	cout<<endl<<" Printing ancestral sequences:"<<endl;
+			// This if loop will print the ancestral sequences into (*results3)
+			// but only if there is one partition. 
+			// This is because a multi-partition simulation could have different underlying guide tree topologies
+			for(int i=ntaxa+1; i<(TsequencesINT.at(0)).size()-1; i++)
+			{	
+				//Ancestral Sequences into (*results3)
+				if(outputtype==1) (*results)<<">";
+				stringstream hg; hg<<i; string rf="N"+hg.str();  
+				//results<<"N"<<i<<"\t";
+				(*results)<<rf; for(int gv=0; gv<dsize-rf.size(); gv++) (*results)<<" ";
+				if(outputtype==1) (*results)<<""<<endl; 
+		
+				printcount++;
+		//		PrintProgress2( blocknumber,  numberofevolveblocks,  thisrep,  reps, printcount);
+				
+				for(int j=0; j<TsequencesINT.size(); j++) makeprintseqINT(j,lastlengthcount, (TinsPOS.at(j)).at(i), (TsequencesINT.at(j)).at(i),(TinsINT.at(j)).at(i),i,*results, 1); 
+				(*results)<<"     "<<endl;
+
+			}
+	
+		}
+			//Root Sequnces
+		
+		if(outputtype==1) (*results)<<">"; 
+		(*results)<<"ROOT";
+		for(int gv=0; gv<dsize-4; gv++) (*results)<<" ";
+				
+		if(outputtype==1) (*results)<<""<<endl; 
+
+		printcount++;
+		//PrintProgress2( blocknumber,  numberofevolveblocks,  thisrep,  reps, printcount);
+	//	cout<<" Printing root."<<endl;
+
+		for(int j=0; j<TsequencesINT.size(); j++) makeprintseqINT(j,lastlengthcount, (TinsPOS.at(j)).at(0), (TsequencesINT.at(j)).at(0),(TinsINT.at(j)).at(0),0,*results, 1); 
+		(*results)<<"     "<<endl;
+
+	}
+		
+	
+}
+
+
+		if(outputtype==3) (*results)<<"   ;"<<endl<<"END;"<<endl;
+
+//		(*results)<<"     "<<endl;(*results2)<<"     "<<endl;
+		
+		if(fileperrep) (*results)<<paupend; else (*results)<<paupmiddle;
+		
+		(*results)<<"     "<<endl;(*results2)<<"     "<<endl;
+		
+		
+
+
+}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+	
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////
+
+int printfreqs(vector<int> &seq)
+{
+	// calculates f3x4 frequencies from a sequence
+//	cout<<"WHERE2a"<<endl;
+	double mysize=double(seq.size());
+//	cout<<"WHERE2b"<<endl;
+	double counts[3][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0}};
+//	cout<<"WHERE2c"<<endl;
+	int i,y,stopcount=0;
+//	cout<<"WHERE2d"<<endl;
+	vector<int> stops=getstops((*m).geneticcode);
+
+	for(y=1; y<mysize; y++)
+	{
+//		cout<<y<<" y1"<<endl;
+		vector<string> CDU=myCDUletters;
+
+//		cout<<"mysize "<<mysize<<endl;
+//		cout<<seq.at(y)<<" seq.at(y)"<<endl;
+		
+//		cout<<"CDU.size() "<<CDU.size()<<endl;
+
+		int seqpos=seq.at(y);
+		
+		string cod=CDU.at(seqpos);
+
+		for(int k=0; k<stops.size(); k++) if(seqpos==stops.at(k)) {if(stopcount<10) cout<<"STOP CODON "<<seqpos<<"  "<<cod<<endl; stopcount++;}
+
+//		cout<< cod<<endl;
+//		cout<<y<<" y2"<<endl;
+		for(i=0; i<3; i++) 
+		{
+//			cout<<i<<" i1"<<endl;
+			if(cod[i]=='T') (counts[i][0])++;
+//			cout<<i<<" i2"<<endl;
+			if(cod[i]=='C') (counts[i][1])++;
+//			cout<<i<<" i3"<<endl;
+			if(cod[i]=='A') (counts[i][2])++;
+//			cout<<i<<" i4"<<endl;
+			if(cod[i]=='G') (counts[i][3])++;
+//			cout<<i<<" i5"<<endl;
+		}
+//		cout<<y<<" y3"<<endl;
+	}
+
+	cout<<"There were "<<stopcount<<" stop codons in total"<<endl;
+//	cout<<"WHERE2e"<<endl;
+	for(i=0; i<3; i++) {for(y=0; y<4; y++) cout<<(counts[i][y])/mysize<<"\t"; cout<<endl;}
+//	cout<<"WHERE2f"<<endl;
+return 0;
+}
+
+//////////////////////////////////////////
+void setuprootseq(RATES &rates,	vector<int> &rootseqINT, int partitionnumber, vector<vector<int> > &sequencesINT, vector<vector<int> > &insPOS, 
+				  vector<vector<insert > > &insINT, SUMS &sums)
+{
+
+	int mysize=taxanames.size();
+
+
+	vector<int> blank1;		blank1.reserve(rates.rootlength);	 
+	vector<insert> blank2;  //blank2.assign(rates.rootlength, insert());  
+
+	sequencesINT.clear();	sequencesINT.assign(mysize,blank1); 
+	insPOS.clear();			insPOS.assign(mysize,blank1); 
+	insINT.clear();			insINT.assign(mysize,blank2);
+
+	//for(int gn1=0; gn1<taxanames.size()+1; gn1++) {sequencesINT.push_back(blank1); insINT.push_back(blank2); 	cout<<"QWERTY   6-"<<gn1<<endl;}
+
+	if(partitionnumber==0) dashlength=0;	// reset the count of how many inserted characters have occurred - treewide
+
+
+#ifndef checkingindelsininsertions
+
+	if(rootseqINT.empty()) {//cout<<"rates.rootlength "<<rates.rootlength<<endl;
+		 makeseq(rates.rootlength, sequencesINT.at(0));  }
+	else 
+	{
+		(sequencesINT.at(0)).push_back(-1); 
+		(sequencesINT.at(0)).insert((sequencesINT.at(0)).end(), rootseqINT.begin(),rootseqINT.end());
+		rootseqINT.clear();
+	}
+
+	vector<site> blank; (insINT.at(0)).push_back(insert(blank,0,0));
+
+	(insPOS.at(0)).assign(rates.rootlength,-1);                  
+	
+/////////////////////
+	(insPOS.at(0)).at(0)=0;
+/////////////////////
+
+#else
+
+	vector<site> insertseq;  (insINT.at(0)).push_back(insert(insertseq,0,0)); (insPOS.at(0)).push_back(-1); 
+
+	 
+
+	int num=int(  double(rates.rootlength - 1)/double(10) );
+
+	for(int yg=0; yg<num; yg++) (sequencesINT.at(0)).push_back(-1);
+	
+	double sdiff=0,timeleft=0;
+	for(int pp=0; pp<num; pp++)
+	{
+		insertseq.clear(); sdiff=0;
+		makeseq2(10, insertseq, sdiff, timeleft);
+       
+		(insPOS.at(0)).push_back(pp);
+		(insINT.at(0)).push_back(insert(insertseq,10,sdiff));
+	}
+				
+	rates.corelength=1; rates.rootlength=rates.partitionlength=num; rates.inslength=10*num;
+
+
+
+//	cout<<(insPOS.at(0)).size()<<"  "<<(sequencesINT.at(0)).size()<<"  "<<(insINT.at(0)).size()<<endl;
+
+#endif	
+//	cout<<"WHEREww  "<<(sequencesINT.at(0)).size()<<endl;
+	if(oldmethod){ buildsumsold(rates, sums, sequencesINT.at(0), insINT.at(0), insPOS.at(0));	}
+	else         { buildsumsnew(rates, sums, sequencesINT.at(0), insINT.at(0), insPOS.at(0));	}
+
+//	cout<<"WHEREw"<<endl;
+}
+
+////////////////////////////////////////////////////////////////////////////////////
+
+void printinsertinfo()
+{
+	// if indels have occurred print the true information about them for a particular block
+
+	insertiontotlength/=insertioncount;
+	deletiontotlength/=deletioncount;
+	double T1=insertioncount+deletioncount;
+	double T2=T1+substitutioncount;
+	(*LOG)<<endl;
+
+	string tss,css,ass,gss;  format(tss,css,ass,gss,insertioncount/T1,deletioncount/T1,T1/T2,substitutioncount/T2);
+		
+	(*LOG)<<"  Actual Insertion : Deletion Ratio  "<<tss<<" : "<<css<<               "\t(Total indel rate = 1)"<<endl;
+	if(oldmethod) (*LOG)<<"  Actual Indel : Substitution Ratio  "<<ass<<" : "<<gss<< "\t(Total event rate = 1)"<<endl;
+	(*LOG)<<"  Actual average insertion length    "<<insertiontotlength<<endl;
+	(*LOG)<<"  Actual average deletion length     "<<deletiontotlength<<endl;
+	(*LOG)<<"  Number of insertion events         "<<insertioncount<<endl;
+	(*LOG)<<"  Number of deletion events          "<<deletioncount<<endl;
+	if(oldmethod) (*LOG)<<"  Number of substitution events      "<<substitutioncount<<endl;
+}
+
+////////////////////////////////////////////////////////////////////////////////////
+
+
+				
+
+void printoutrates(int &sitecount,int partition, ofstream &ratesout, vector<int> &inspos, vector<insert>  &insertstuff)
+{			
+
+//	ratesout<<"Site\tRate\tInserted?\tPartition"<<endl;
+
+	if(type!=3)
+	{
+		int i;
+		//eternal link
+		if(inspos.at(0)!=-1)
+		{
+			insert* ii=&(insertstuff.at(inspos.at(0)));
+
+			vector<site>* s=&( (*ii).insertvec );
+
+			for(int j=0; j<(*s).size(); j++) 
+			{
+				sitecount++; ratesout<<sitecount<<"\t"; 
+				if((*m).continuousgamma)  {} else ratesout<<((*s).at(j)).siteclass+1<<"\t"; 
+				ratesout<<((*s).at(j)).rate<<"\t"<<partition<<"\tINSERTION"<<endl;
+			}
+		}
+
+		vector<string> ratevec2,sitevec2,insYN; int maxsize=0,maxsize2=0,diff2, diff; 
+
+		for(i=1 ; i<ratevec.size(); i++)
+		{	
+			if(i!=0)
+			{
+				stringstream ds; ds<<ratevec.at(i);      string sd=ds.str(); diff=sd.size(); if(diff>maxsize) maxsize=diff; ratevec2.push_back(sd); insYN.push_back(" ");
+				stringstream dq; dq<<siteclassvec.at(i)+1; string sq=dq.str(); diff2=sq.size(); if(diff2>maxsize2) maxsize2=diff; sitevec2.push_back(sq); 
+			}
+
+			if(inspos.at(i)!=-1)
+			{
+				insert* ii=&(insertstuff.at(inspos.at(i)));
+
+			//	if((*ii).length==0) continue;
+
+				vector<site>* s=&( (*ii).insertvec );
+
+				for(int j=0; j<(*s).size(); j++) 
+				{
+					stringstream ds; ds<<((*s).at(j)).rate;      string sd=ds.str(); diff=sd.size(); if(diff>maxsize) maxsize=diff; ratevec2.push_back(sd); insYN.push_back("INSERTION");
+					stringstream dq; dq<<((*s).at(j)).siteclass+1; string sq=dq.str(); diff=sq.size(); if(diff2>maxsize2) maxsize2=diff; sitevec2.push_back(sq); 
+				}
+			}
+		}  
+
+
+		if((*m).continuousgamma) 
+		{
+			for(i=0; i<ratevec2.size(); i++) 
+			{	
+				sitecount++;
+				string s1=ratevec2.at(i); diff=maxsize-s1.size();   for(int l=0; l<diff; l++) s1+=" "; 
+				string s2=sitevec2.at(i); diff=maxsize2-s2.size();   for(int l2=0; l2<diff; l2++) s2+=" "; 
+				
+				ratesout<<sitecount<<"\t"<<s1<<"   \t"<<partition<<"\t"<<insYN.at(i)<<endl;
+			}  
+		}
+		else
+		{
+			for(i=0; i<ratevec2.size(); i++) 
+			{	
+				sitecount++;
+				string s1=ratevec2.at(i); diff=maxsize-s1.size();   for(int l=0; l<diff; l++) s1+=" "; 
+				string s2=sitevec2.at(i); diff=maxsize2-s2.size();   for(int l2=0; l2<diff; l2++) s2+=" "; 
+				
+				ratesout<<sitecount<<"\t"<<s2<<"\t"<<s1<<"   \t"<<partition<<"\t"<<insYN.at(i)<<endl;
+			}  
+		}
+	}
+	else
+	{
+		vector<double> myrates=(*m).myomegas;
+		//eternal link
+		if(inspos.at(0)!=-1)
+		{
+			insert* ii=&(insertstuff.at(inspos.at(0)));
+
+			vector<site>* s=&( (*ii).insertvec );
+			
+			//for(int j=0; j<(*s).size(); j++) {sitecount++; ratesout<<sitecount<<"\t"<<myrates.at(((*s).at(j)).siteclass)<<"\tY\t"<<partition<<endl;}
+			for(int j=0; j<(*s).size(); j++) {sitecount++; ratesout<<sitecount<<"\t"<<((*s).at(j)).siteclass<<"\t"<<partition<<"\tINSERTION"<<endl;}
+		}
+
+
+		for(int i=1; i<ratevec.size(); i++)
+		{	
+			sitecount++; 
+			
+			ratesout<<sitecount<<"\t"<<siteclassvec.at(i) <<"\t"<<partition<<endl;
+			
+			if(inspos.at(i)!=-1)
+			{
+				insert* ii=&(insertstuff.at(inspos.at(i)));
+
+			//	if((*ii).length==0) continue;
+
+				vector<site>* s=&( (*ii).insertvec );
+
+				for(int j=0; j<(*s).size(); j++) {sitecount++; ratesout<<sitecount<<"\t"<<((*s).at(j)).siteclass <<"\t"<<partition<<"\tINSERTION"<<endl;}
+			}
+		}  
+	}
+
+}
+
+
+/////////////////////////////////////   MAIN PROGRAM
+
+int main(int argc, char* argv[])
+{
+
+
+#ifdef checkindeldistributions	// used to check whether indel length distributions are consistent.
+
+	//creates control file for tests
+	ofstream x("controldist.txt");
+
+	x<<endl<<"// controldist"<<endl<<""<<endl<<"// Example control file to check indel length distributions."<<endl<<""<<endl<<"// Each indel model below will be read in and 10m indellengths will be calculated and timed"<<endl<<""<<endl<<"// results are output in lengthdist.txt and should be e.g. copy and pasted in excel for easy viewing"<<endl<<endl<<"[TYPE] CODON 1              // codon simulation using method 1"<<endl<<""<<endl<<"//MODEL decimal integer"<<endl<<"//USER filename"<<endl<<" [...]
+		
+	//creates user model for tests that should mirror one of the distributions calculated mathematically
+	ofstream y("userexample.txt");
+
+y<<"0.673643922711"<<endl<<"0.146287925004"<<endl<<"0.059820608527"<<endl<<"0.031697700931"<<endl<<"0.019358287305"<<endl<<"0.012933272346"<<endl<<"0.009193158625"<<endl<<"0.006837868923"<<endl<<"0.005265293128"<<endl<<"0.004166701951"<<endl<<"0.003371040086"<<endl<<"0.002777560301"<<endl<<"0.002323915321"<<endl<<"0.001969910312"<<endl<<"0.001688724636"<<endl<<"0.001461928529"<<endl<<"0.001276532822"<<endl<<"0.001123178093"<<endl<<"0.00099498778"<<endl<<"0.000886821517"<<endl<<"0.0007947 [...]
+y<<"0.000127297986"<<endl<<"0.000121256228"<<endl<<"0.000115611306"<<endl<<"0.000110329976"<<endl<<"0.000105382365"<<endl<<"0.000100741568"<<endl<<"0.000096383307"<<endl<<"0.000092285629"<<endl<<"0.000088428647"<<endl<<"0.000084794311"<<endl<<"0.000081366213"<<endl<<"0.000078129408"<<endl<<"0.000075070266"<<endl<<"0.000072176334"<<endl<<"0.000069436215"<<endl<<"0.000066839468"<<endl<<"0.00006437651"<<endl<<"0.000062038538"<<endl<<"0.000059817448"<<endl<<"0.000057705776"<<endl<<"0.0000556 [...]
+y<<"0.000024790492"<<endl<<"0.000024161311"<<endl<<"0.000023553777"<<endl<<"0.00002296694"<<endl<<"0.0000223999"<<endl<<"0.000021851807"<<endl<<"0.000021321853"<<endl<<"0.000020809272"<<endl<<"0.00002031334"<<endl<<"0.000019833367"<<endl<<"0.000019368698"<<endl<<"0.000018918712"<<endl<<"0.000018482817"<<endl<<"0.000018060452"<<endl<<"0.000017651082"<<endl<<"0.000017254198"<<endl<<"0.000016869315"<<endl<<"0.00001649597"<<endl<<"0.000016133724"<<endl<<"0.000015782156"<<endl<<"0.00001544086 [...]
+y<<"0.00000903743"<<endl<<"0.000008875258"<<endl<<"0.000008716922"<<endl<<"0.000008562306"<<endl<<"0.000008411299"<<endl<<"0.000008263796"<<endl<<"0.000008119692"<<endl<<"0.00000797889"<<endl<<"0.000007841294"<<endl<<"0.00000770681"<<endl<<"0.000007575351"<<endl<<"0.00000744683"<<endl<<"0.000007321164"<<endl<<"0.000007198273"<<endl<<"0.00000707808"<<endl<<"0.00000696051"<<endl<<"0.00000684549"<<endl<<"0.000006732951"<<endl<<"0.000006622826"<<endl<<"0.000006515048"<<endl<<"0.000006409555" [...]
+y<<"0.000004241137"<<endl<<"0.000004180591"<<endl<<"0.000004121149"<<endl<<"0.000004062787"<<endl<<"0.000004005479"<<endl<<"0.000003949202"<<endl<<"0.000003893932"<<endl<<"0.000003839647"<<endl<<"0.000003786326"<<endl<<"0.000003733946"<<endl<<"0.000003682487"<<endl<<"0.000003631928"<<endl<<"0.00000358225"<<endl<<"0.000003533434"<<endl<<"0.000003485462"<<endl<<"0.000003438314"<<endl<<"0.000003391973"<<endl<<"0.000003346422"<<endl<<"0.000003301644"<<endl<<"0.000003257622"<<endl<<"0.0000032 [...]
+y<<"0.000002277112"<<endl<<"0.000002249465"<<endl<<"0.000002222232"<<endl<<"0.000002195407"<<endl<<"0.000002168982"<<endl<<"0.000002142949"<<endl<<"0.000002117302"<<endl<<"0.000002092033"<<endl<<"0.000002067135"<<endl<<"0.000002042602"<<endl<<"0.000002018427"<<endl<<"0.000001994603"<<endl<<"0.000001971125"<<endl<<"0.000001947985"<<endl<<"0.000001925179"<<endl<<"0.0000019027"<<endl<<"0.000001880542"<<endl<<"0.0000018587"<<endl<<"0.000001837168"<<endl<<"0.00000181594"<<endl<<"0.00000179501 [...]
+y<<"0.000001326435"<<endl<<"0.000001312121"<<endl<<"0.000001297993"<<endl<<"0.000001284045"<<endl<<"0.000001270277"<<endl<<"0.000001256685"<<endl<<"0.000001243266"<<endl<<"0.000001230017"<<endl<<"0.000001216937"<<endl<<"0.000001204021"<<endl<<"0.000001191269"<<endl<<"0.000001178677"<<endl<<"0.000001166243"<<endl<<"0.000001153964"<<endl<<"0.000001141839"<<endl<<"0.000001129864"<<endl<<"0.000001118037"<<endl<<"0.000001106357"<<endl<<"0.000001094821"<<endl<<"0.000001083427"<<endl<<"0.000001 [...]
+y<<"0.000000814351"<<endl<<"0.000000806286"<<endl<<"0.000000798313"<<endl<<"0.000000790431"<<endl<<"0.000000782639"<<endl<<"0.000000774935"<<endl<<"0.000000767318"<<endl<<"0.000000759787"<<endl<<"0.00000075234"<<endl<<"0.000000744978"<<endl<<"0.000000737698"<<endl<<"0.0000007305"<<endl<<"0.000000723382"<<endl<<"0.000000716343"<<endl<<"0.000000709382"<<endl<<"0.000000702499"<<endl<<"0.000000695692"<<endl<<"0.00000068896"<<endl<<"0.000000682302"<<endl<<"0.000000675717"<<endl<<"0.0000006692 [...]
+y<<"0.000000522426"<<endl<<"0.000000517551"<<endl<<"0.000000512726"<<endl<<"0.000000507951"<<endl<<"0.000000503226"<<endl<<"0.000000498549"<<endl<<"0.000000493921"<<endl<<"0.00000048934"<<endl<<"0.000000484806"<<endl<<"0.000000480318"<<endl<<"0.000000475877"<<endl<<"0.00000047148"<<endl<<"0.000000467129"<<endl<<"0.000000462822"<<endl<<"0.000000458558"<<endl<<"0.000000454338"<<endl<<"0.00000045016"<<endl<<"0.000000446025"<<endl<<"0.000000441931"<<endl<<"0.000000437879"<<endl<<"0.000000433 [...]
+y<<"0.000000339341"<<endl<<"0.000000336297"<<endl<<"0.000000333282"<<endl<<"0.000000330297"<<endl<<"0.00000032734"<<endl<<"0.000000324411"<<endl<<"0.00000032151"<<endl<<"0.000000318637"<<endl<<"0.000000315791"<<endl<<"0.000000312972"<<endl<<"0.00000031018"<<endl<<"0.000000307414"<<endl<<"0.000000304674"<<endl<<"0.000000301961"<<endl<<"0.000000299272"<<endl<<"0.00000029661"<<endl<<"0.000000293972"<<endl<<"0.000000291359"<<endl<<"0.00000028877"<<endl<<"0.000000286206"<<endl<<"0.00000028366 [...]
+y<<"0.000000223283"<<endl<<"0.000000221321"<<endl<<"0.000000219377"<<endl<<"0.000000217451"<<endl<<"0.000000215541"<<endl<<"0.000000213649"<<endl<<"0.000000211774"<<endl<<"0.000000209916"<<endl<<"0.000000208074"<<endl<<"0.000000206249"<<endl<<"0.000000204441"<<endl<<"0.000000202648"<<endl<<"0.000000200872"<<endl<<"0.000000199111"<<endl<<"0.000000197366"<<endl<<"0.000000195636"<<endl<<"0.000000193922"<<endl<<"0.000000192224"<<endl<<"0.00000019054"<<endl<<"0.000000188871"<<endl<<"0.0000001 [...]
+y<<"0.00000014765"<<endl<<"0.000000146356"<<endl<<"0.000000145074"<<endl<<"0.000000143802"<<endl<<"0.000000142542"<<endl<<"0.000000141292"<<endl<<"0.000000140053"<<endl<<"0.000000138825"<<endl<<"0.000000137607"<<endl<<"0.0000001364"<<endl<<"0.000000135203"<<endl<<"0.000000134017"<<endl<<"0.00000013284"<<endl<<"0.000000131674"<<endl<<"0.000000130518"<<endl<<"0.000000129371"<<endl<<"0.000000128235"<<endl<<"0.000000127108"<<endl<<"0.00000012599"<<endl<<"0.000000124882"<<endl<<"0.00000012378 [...]
+y<<"0.000000098273"<<endl<<"0.000000097399"<<endl<<"0.000000096533"<<endl<<"0.000000095674"<<endl<<"0.000000094822"<<endl<<"0.000000093978"<<endl<<"0.00000009314"<<endl<<"0.00000009231"<<endl<<"0.000000091486"<<endl<<"0.00000009067"<<endl<<"0.00000008986"<<endl<<"0.000000089057"<<endl<<"0.00000008826"<<endl<<"0.000000087471"<<endl<<"0.000000086688"<<endl<<"0.000000085911"<<endl<<"0.000000085141"<<endl<<"0.000000084377"<<endl<<"0.00000008362"<<endl<<"0.000000082869"<<endl<<"0.000000082124 [...]
+y<<"0.000000064195"<<endl<<"0.000000063605"<<endl<<"0.000000063021"<<endl<<"0.000000062441"<<endl<<"0.000000061865"<<endl<<"0.000000061295"<<endl<<"0.000000060729"<<endl<<"0.000000060168"<<endl<<"0.000000059612"<<endl<<"0.00000005906"<<endl<<"0.000000058513"<<endl<<"0.00000005797"<<endl<<"0.000000057432"<<endl<<"0.000000056898"<<endl<<"0.000000056369"<<endl<<"0.000000055844"<<endl<<"0.000000055323"<<endl<<"0.000000054807"<<endl<<"0.000000054295"<<endl<<"0.000000053787"<<endl<<"0.00000005 [...]
+y<<"0.000000041157"<<endl<<"0.000000040758"<<endl<<"0.000000040363"<<endl<<"0.000000039971"<<endl<<"0.000000039582"<<endl<<"0.000000039196"<<endl<<"0.000000038813"<<endl<<"0.000000038434"<<endl<<"0.000000038058"<<endl<<"0.000000037685"<<endl<<"0.000000037315"<<endl<<"0.000000036948"<<endl<<"0.000000036585"<<endl<<"0.000000036224"<<endl<<"0.000000035866"<<endl<<"0.000000035512"<<endl<<"0.00000003516"<<endl<<"0.000000034811"<<endl<<"0.000000034465"<<endl<<"0.000000034122"<<endl<<"0.0000000 [...]
+y<<"0.00000002561"<<endl<<"0.000000025342"<<endl<<"0.000000025076"<<endl<<"0.000000024812"<<endl<<"0.000000024551"<<endl<<"0.000000024292"<<endl<<"0.000000024035"<<endl<<"0.000000023781"<<endl<<"0.000000023528"<<endl<<"0.000000023278"<<endl<<"0.00000002303"<<endl<<"0.000000022784"<<endl<<"0.00000002254"<<endl<<"0.000000022299"<<endl<<"0.000000022059"<<endl<<"0.000000021822"<<endl<<"0.000000021586"<<endl<<"0.000000021353"<<endl<<"0.000000021121"<<endl<<"0.000000020892"<<endl<<"0.000000020 [...]
+y<<"0.000000015226"<<endl<<"0.000000015048"<<endl<<"0.000000014873"<<endl<<"0.000000014699"<<endl<<"0.000000014526"<<endl<<"0.000000014355"<<endl<<"0.000000014186"<<endl<<"0.000000014018"<<endl<<"0.000000013851"<<endl<<"0.000000013686"<<endl<<"0.000000013523"<<endl<<"0.000000013361"<<endl<<"0.000000013201"<<endl<<"0.000000013042"<<endl<<"0.000000012885"<<endl<<"0.000000012729"<<endl<<"0.000000012574"<<endl<<"0.000000012421"<<endl<<"0.000000012269"<<endl<<"0.000000012119"<<endl<<"0.000000 [...]
+y<<"0.000000008556"<<endl<<"0.000000008441"<<endl<<"0.000000008328"<<endl<<"0.000000008215"<<endl<<"0.000000008103"<<endl<<"0.000000007993"<<endl<<"0.000000007884"<<endl<<"0.000000007775"<<endl<<"0.000000007668"<<endl<<"0.000000007562"<<endl<<"0.000000007457"<<endl<<"0.000000007353"<<endl<<"0.00000000725"<<endl<<"0.000000007148"<<endl<<"0.000000007048"<<endl<<"0.000000006948"<<endl<<"0.000000006849"<<endl<<"0.000000006751"<<endl<<"0.000000006654"<<endl<<"0.000000006559"<<endl<<"0.0000000 [...]
+y<<"0.000000004253"<<endl<<"0.000000004183"<<endl<<"0.000000004114"<<endl<<"0.000000004045"<<endl<<"0.000000003978"<<endl<<"0.000000003911"<<endl<<"0.000000003845"<<endl<<"0.00000000378"<<endl<<"0.000000003715"<<endl<<"0.000000003652"<<endl<<"0.000000003589"<<endl<<"0.000000003526"<<endl<<"0.000000003465"<<endl<<"0.000000003404"<<endl<<"0.000000003344"<<endl<<"0.000000003285"<<endl<<"0.000000003226"<<endl<<"0.000000003168"<<endl<<"0.000000003111"<<endl<<"0.000000003055"<<endl<<"0.0000000 [...]
+y<<"0.000000001736"<<endl<<"0.000000001697"<<endl<<"0.000000001659"<<endl<<"0.000000001622"<<endl<<"0.000000001585"<<endl<<"0.000000001549"<<endl<<"0.000000001513"<<endl<<"0.000000001478"<<endl<<"0.000000001444"<<endl<<"0.00000000141"<<endl<<"0.000000001376"<<endl<<"0.000000001343"<<endl<<"0.00000000131"<<endl<<"0.000000001278"<<endl<<"0.000000001247"<<endl<<"0.000000001216"<<endl<<"0.000000001185"<<endl<<"0.000000001155"<<endl<<"0.000000001125"<<endl<<"0.000000001096"<<endl<<"0.00000000 [...]
+y<<"0.000000000462"<<endl<<"0.000000000445"<<endl<<"0.000000000428"<<endl<<"0.000000000412"<<endl<<"0.000000000397"<<endl<<"0.000000000381"<<endl<<"0.000000000366"<<endl<<"0.000000000352"<<endl<<"0.000000000338"<<endl<<"0.000000000324"<<endl<<"0.00000000031"<<endl<<"0.000000000297"<<endl<<"0.000000000284"<<endl<<"0.000000000272"<<endl<<"0.00000000026"<<endl<<"0.000000000248"<<endl<<"0.000000000236"<<endl<<"0.000000000225"<<endl<<"0.000000000214"<<endl<<"0.000000000203"<<endl<<"0.00000000 [...]
+y<<"0.000000000025"<<endl<<"0.000000000022"<<endl<<"0.00000000002"<<endl<<"0.000000000017"<<endl<<"0.000000000015"<<endl<<"0.000000000012"<<endl<<"0.00000000001"<<endl<<"0.000000000008"<<endl<<"0.000000000007"<<endl<<"0.000000000005"<<endl<<"0.000000000004"<<endl<<"0.000000000003"<<endl<<"0.000000000002"<<endl<<"0.000000000001"<<endl<<"0.000000000001"<<endl<<"0"<<endl<<"0"<<endl<<"0"<<endl;
+
+	masterfilename="controldist.txt";
+	int isthereanerror=docontrol();
+
+	if( isthereanerror==-1) {return -1;}
+
+	ofstream iop("lengthdist.txt");
+
+	vector<string> names;
+	vector<vector<double> > lines;
+	vector<double> blank, means, means2;
+	vector<double> timestaken;
+	lines.assign(1000,blank);
+
+	int i, mygoal=10000000;
+
+	clock_t start, finish;
+   double  duration;
+
+   cout<<endl<<"FILES CREATED: controldist.txt , userexample.txt, lengthdist.txt"<<endl<<endl;
+	cout<<"CHECKING INSERTION LENGTH DISTRIBUTIONS"<<endl;
+	for(i=0; i<totalmodels.size(); i++)
+	{
+		cout<<i+1<<" models of "<<totalmodels.size()<<" done"<<endl;
+		//check insertion models
+
+	//	cout<<"WHERE 0 " <<endl;
+		vector<int> counts; counts.assign(1001,0);
+	
+	//	cout<<"WHERE 9"<<endl;					
+		m=&(totalmodels.at(i));
+
+		changezipfrandoms();
+	//	cout<<"WHERE 8 "<<endl;
+		int goal=mygoal;
+
+		int indellength;
+
+		start = clock(); int total=0; int mean=0;
+		while(goal--)
+		{
+	//	cout<<"WHERE 7"<<endl;
+			indellength=(*m).insrandomsize( (*m).insI, (*m).insD, (*m).insV );
+			total++; mean+=indellength;
+	//	cout<<"WHERE 6 "<<(*m).name<<endl;
+			if(indellength>1000) {goal++; continue;}
+			
+	//	cout<<"WHERE 5 "<<indellength<<endl;
+			(counts.at(indellength))++;
+			
+	//	cout<<"WHERE 4"<<endl;
+		}
+
+		
+		means.push_back(double(mean)/double(total)); means2.push_back((*m).delmeansize);
+		finish = clock();
+	   timestaken.push_back( (double)(finish - start) / CLOCKS_PER_SEC);
+
+	//	cout<<"WHERE 3"<<endl;
+		names.push_back(  ((*m).name)+"_ins"  );
+
+	//	cout<<"WHERE 2 "<<endl;
+		for(int j=0; j<lines.size(); j++) (lines.at(j)).push_back(double(counts.at(j))/double(total));
+	
+
+
+	//	cout<<"WHERE 1"<<endl;
+	}
+
+	cout<<endl<<"CHECKING DELETION LENGTH DISTRIBUTIONS"<<endl;
+	for(i=0; i<totalmodels.size(); i++)
+	{
+		cout<<i+1<<" models of "<<totalmodels.size()<<" done"<<endl;
+		//check insertion models
+
+		vector<int> counts; counts.assign(1001,0);
+						
+		m=&(totalmodels.at(i));
+	
+		changezipfrandoms();
+		int goal=mygoal;
+
+		int indellength;
+
+		start = clock(); int total=0; int mean=0;
+		while(goal--)
+		{
+			indellength=(*m).delrandomsize( (*m).delI, (*m).delD, (*m).delV );
+
+			total++; mean+=indellength;
+			if(indellength>1000) {goal++; continue;}
+			
+			(counts.at(indellength))++;
+		}
+
+		means.push_back(double(mean)/double(total)); means2.push_back((*m).delmeansize);
+		finish = clock();
+	    timestaken.push_back( (double)(finish - start) / CLOCKS_PER_SEC);
+
+		names.push_back(  ((*m).name)+"_del"  );
+		for(int j=0; j<lines.size(); j++) (lines.at(j)).push_back(double(counts.at(j))/double(total));
+
+	}
+
+	iop<<"time taken\t"; for(i=0; i<names.size(); i++) iop<<timestaken.at(i)<<"\t"; iop<<endl;
+	iop<<"model name\t"; for(i=0; i<names.size(); i++) iop<<names.at(i)<<"\t"; iop<<endl;
+	iop<<"mean length\t";for(i=0; i<means.size(); i++) iop<<means.at(i)<<"\t"; iop<<endl;
+	iop<<"true mean  \t";for(i=0; i<means.size(); i++) iop<<means2.at(i)<<"\t"; iop<<endl;
+
+	for(int j=0; j<lines.size(); j++) 
+	{
+		iop<<j<<"\t";
+		vector<double> bits=lines.at(j);
+		for(i=0; i<bits.size(); i++) iop<<bits.at(i)<<"\t"; 
+		iop<<endl;
+	}
+
+	cout<<endl<<"DONE!"<<endl<<endl;
+
+	return -1;  
+	
+#else	
+
+
+#ifdef runseedstillbreak   
+int myint;
+cout<<"please enter integer that seed should start from: "<<flush;
+cin>>myint;
+for(int qwerty=myint; qwerty<1000000; qwerty++)
+{
+mtrand1.seed( qwerty );
+
+
+cout<<"qwerty seed was "<<qwerty<<endl;
+totalmodels.clear();
+totalpartitions.clear();
+totalbranches.clear();
+totalevolve.clear();
+totaltrees.clear();
+totalmodelnames.clear();
+totalpartitionnames.clear();
+totalbranchesnames.clear();
+totaltreenames.clear();
+#endif
+
+ofstream treesout( ("trees"+simtime+".txt").c_str() );
+
+delete LOG;
+LOG = new ofstream;
+
+(*LOG).close(); 
+(*LOG).clear();
+
+(LOG)->open( ("LOG"+simtime+".txt").c_str());  	
+ #ifdef runseedstillbreak   
+
+(*LOG)<<"qwerty seed was "<<qwerty<<endl;
+#endif
+	// print some initial output to screen and (*LOG) files and set up some timing factors
+
+	start = clock();
+	time_t starttime, endtime, startofblock, endofblock; 
+	struct tm *timeinfo; time(&starttime); timeinfo=localtime(&starttime); 
+	(*LOG) <<"********************************************************************************"<<endl;
+	(*LOG)<<"INDELible V"<<VersionNumber<<" by Will Fletcher : Simulation began at: "<<asctime(timeinfo);
+	(*LOG)<<"********************************************************************************"<<endl;
+	cout<<endl<<" INDELible V"<<VersionNumber<<" by Will Fletcher: Simulation began at "<<asctime(timeinfo)<<endl<<endl;
+
+
+	int isthereanerror=docontrol();			// parse and process control file
+
+	if( isthereanerror==-1) // if parsing and processing of control file returns an error then quits.
+	{delete results; delete results2; delete results3; delete LOG; return -1;}
+
+	treesout<<"Tree file : INDELible V"<<VersionNumber<<" (best viewed cut and paste in e.g. excel)"<<endl<<endl;
+	treesout<<"N.B. Simulation blocks with no random trees will have their trees printed for the first replicate only."<<endl;
+	
+	if(ancestralprint) treesout<<endl<<"     Interior node labels on the trees match ancestral sequence labels in sequence files."<<endl;
+
+	treesout<<endl<<"FILE\tTREE\tNTAXA\tREP\tPART\tLENGTH\tDEPTH\tMAX PAIRWISE DISTANCE\tTREE STRING"<<endl;
+
+	int numberofevolveblocks=totalevolve.size();
+
+
+	for(int blocknumber=1; blocknumber<numberofevolveblocks+1; blocknumber++)
+	{
+
+
+		// cycles through every block of simulations defined in the control file
+
+		// get settings for this block
+		e=&(totalevolve.at(blocknumber-1));
+		reps=(*e).reps;
+		filenamestub=(*e).filenamestub;
+		p=&(totalpartitions.at(  (*e).partitionpos  ));
+
+
+		ntaxa=(*p).ntaxa;
+		bool therearerandomtrees=(*p).randomtrees;
+		vector<int> treeposvec=(*p).treeposvec;
+
+
+//		vector<bool> isitsitesv=(*p).isitsites;
+//		vector<bool> isitrandomv=(*p).isitrandomvec;
+		vector<bool> isitbranchesv=(*p).isitbranches;
+		int numberofpartitions=isitbranchesv.size();
+
+
+		string filename1=filenamestub+"_TRUE";			// true alignment
+		string filename2=filenamestub+"";				// true unaligned sequences
+		string filename3=filenamestub+"_ANCESTRAL";		// Ancestral sequences
+
+		// this sets up output files for the case where all replicates are printed to the same file.
+		string endbit=".";
+
+		// choose file extension depending on desired output type
+		if(outputtype==1) endbit+=fastaextension; else if(outputtype==2) endbit+=phylipextension; else if(outputtype==3) endbit+=nexusextension;
+
+		filename1+=endbit;
+		filename2+="."; filename2+=fastaextension;    // unaligned sequences always output in FASTA format
+		filename3+=endbit;
+
+	
+		if(!fileperrep)
+		{
+			if(ancestralprint && ancestralfile)
+			{
+			//	(*results3)=new ofstream;
+				(*results3).close();
+				(*results3).clear();  
+				(results3)->open(filename3.c_str());
+			}
+
+
+		//	(*results)=new ofstream;
+			(*results).close(); (*results2).close();
+			(*results).clear();  (*results2).clear();
+
+			(results)->open(filename1.c_str());  	
+			
+			(*results)<<paupstart;
+
+			//(*results2)=new ofstream;
+			(results2)->open(filename2.c_str());
+		}
+
+
+
+
+
+		startofblock=clock();
+
+		// Set everything in place
+		TsequencesINT.clear();  sequencesINT.clear();   TsequencesINT.assign(numberofpartitions,sequencesINT); 
+		TinsINT.clear();		insINT.clear();			TinsINT.assign(numberofpartitions,insINT);
+		TinsPOS.clear();		insPOS.clear();			TinsPOS.assign(numberofpartitions,insPOS);
+
+
+
+			ofstream ratesout;  
+
+
+			if(printrates) 
+			{
+					string ratefilename=filenamestub+"_RATES.txt";
+					ratesout.open(  ratefilename.c_str()  );
+					ratesout<<"Rates file : INDELible V"<<VersionNumber<<" "<<endl<<endl; // (best viewed cut and paste in e.g. excel)"<<endl<<endl;
+			}
+
+
+
+		for(int thisrep=1; thisrep<reps+1; thisrep++)
+		{
+			if(printrates) ratesout<<endl<<"Replicate: "<<thisrep<<endl;
+
+			globalthisrep=thisrep;
+
+			// this for loop performs the required number of replicates.
+
+			//(*LOG)<<endl<<"  * Block "<<blocknumber<<"\tReplicate "<<thisrep<<"\tFilename: "<<filenamestub<<"_TRUE"; if(fileperrep) (*LOG)<<"_"<<thisrep; (*LOG)<<endbit<<endl<<endl;
+
+			inspinvcount=corepinvcount=0;
+
+			if(thisrep==1)
+			{
+				substitutioncount	= 0;	// counts the number of substitution events in a block
+				insertioncount		= 0;	// counts the number of insertion events in a block
+				insertiontotlength	= 0;	// tracks cumulative insertion length in a block
+				deletioncount		= 0;	// counts the number of deletion events in a block
+				deletiontotlength	= 0;	// tracks cumulative deletion length in a block
+			}
+
+
+			
+			int sitecount=0;
+
+			///////////////////////////
+			// OLD POSITION OF PRINT RATES STUFF
+
+			// totallength = original root sequence length + dashlength ends up being length of sequences in true alignment
+			dashlength=0;
+
+			totallength=0;
+
+					
+			if(numberofpartitions>1) (*LOG)<<"  This dataset contains "<<numberofpartitions<<" partitions as follows:"<<endl<<endl<<"\tLength\tFrom\tTo\tModel\tPartition"<<endl;
+
+			int lastlength=0;
+
+			vector<int> partitionlengths; partitionlengths.push_back(0);
+
+			mycodes.clear(); vector<int> bl; bl.assign(ntaxa*200,0); mycodes.assign(numberofpartitions,bl);
+
+
+			for(int partitionnumber=0; partitionnumber<numberofpartitions; partitionnumber++)
+			{
+				// this loop cycles through the different partitions
+
+			//	if(partitionnumber>0) partitionboundariesL.push_back(partitionboundariesR.at(partitionnumber-1)+1);
+
+				weareon=false;
+	//			isitrandom   = isitrandomv.at(partitionnumber);
+	//			isitsites    = isitsitesv.at(partitionnumber);
+
+				// whether this partition contains a branch class or a model
+				isitbranches = isitbranchesv.at(partitionnumber);
+						
+				// guide tree set to become tree from treeposvec that matches the partition
+				treeC=&(totaltrees.at(   treeposvec.at(partitionnumber)   ));
+				
+				if(therearerandomtrees)
+				{
+					// if it is random tree then the tree in the class (*treeC) is relaced with new tree
+				
+					if((*treeC).treerandom) 	(*treeC).newrandom(thisrep);
+				}
+
+				originaltree=(*treeC).tree; 				
+				
+				// set tree length for percentage done calculations ------> not used any more.
+				currenttreelength=treelength=(*treeC).treelength;
+
+				// sorts out guide tree, adding node labels for navigation and storage
+				startnodelabel=0;
+				int error=settreeup(partitionnumber,originaltree, nonamestree, origtreewithnodes, nonamestreewithnodes, startnodelabel, taxanames, ntaxa); 
+				
+							
+				if(thisrep==1 && partitionnumber==0) treesout<<endl;
+
+				if(therearerandomtrees)
+				{
+					treesout<<filenamestub<<"\t"<<(*treeC).name<<"\t"<<ntaxa<<"\t"<<thisrep<<"\t"<<partitionnumber+1<<"\t"<<(*treeC).treelength<<"\t"<<(*treeC).treedepth<<"\t"<<(*treeC).max_distance<<"\t"; 
+					
+					if(ancestralprint) treesout<<origtreewithnodes<<endl; else treesout<<(*treeC).tree<<endl;
+
+				}
+				
+				if(!therearerandomtrees && thisrep==1)
+				{
+
+					treesout<<filenamestub<<"\t"<<(*treeC).name<<"\t"<<ntaxa<<"\t"<<thisrep<<"\t"<<partitionnumber+1<<"\t"<<(*treeC).treelength<<"\t"<<(*treeC).treedepth<<"\t"<<(*treeC).max_distance<<"\t"; 
+				//					treesout<<filenamestub<<"\t"<<(*treeC).name<<"\t"<<ntaxa<<"\t"<<thisrep<<"\t"<<partitionnumber+1<<"\t"<<(*treeC).treelength<<"\t"<<(*treeC).treedepth<<"\t"; 
+	//				treesout<<filenamestub<<"\t"<<(*treeC).name<<"\t"<<ntaxa<<"\t"<<thisrep<<"\t"<<partitionnumber+1<<"\t"<<(*treeC).treelength<<"\t-\t"; 
+					
+					if(ancestralprint) treesout<<origtreewithnodes<<endl; else treesout<<(*treeC).tree<<endl;
+				}
+
+
+
+				if(error==-1) return 0;
+
+				// create instances of SUMS and RATES to pass down and inherit through the recursive algorithms
+				SUMS sums;
+				RATES rates=RATES();
+				
+				// rates.partitionlength is set to and remains as user-specified root length for duration of simulation
+				rates.partitionlength=((*p).rootlengthvec).at(partitionnumber)+1;
+
+				// these others begin as rates.partitionlength but change during course of simulation
+				rates.corelength=rates.rootlength=rates.partitionlength;	
+		
+
+// these are used when checking that substitution works in inserted sites
+
+#ifdef checkingindelsubs1
+	// not used much... very slow, it makes core sequence 1 site long and creates one insertion of length rates.partitionlength
+	rates.corelength=rates.rootlength=rates.totallength=2;
+#endif
+#ifdef checkingindelsubs2
+	// creates starting situation where 10% of sites are core and 90% are inserted.
+	rates.corelength=rates.rootlength=rates.totallength=int(0.1*(rates.partitionlength))+1;
+#endif
+#ifdef checkingindelsubs3
+	// creates starting situation where 50% of sites are core and 50% are inserted.
+	rates.corelength=rates.rootlength=rates.totallength=int(0.5*(rates.partitionlength))+1;
+#endif
+
+
+
+				// this is position of model in totalmodels when not a branch class
+				// otherwise it is position of branchclass in total branches
+				mypos=((*p).mbsposvec).at(partitionnumber);
+
+				
+				// need to point to root model so that correct stationary frequencies are used for root sequence creation
+				if(isitbranches) 
+				{
+					  b=&(totalbranches.at( mypos ));
+
+					  m=&(totalmodels.at( ((*b).rootmodelpos) ));
+
+					  
+					  (mycodes.at(partitionnumber)).at(0)=(*m).geneticcode;
+
+				}
+				else  m=&(totalmodels.at( mypos ));
+
+				mymods.clear(); mymods.push_back(mypos);
+				// this is done once here to set up the definitions of constants used in Zipfian random number generation
+				changezipfrandoms();
+	
+
+				// set up site classes for codon site-models and relative rates for gamma/pinv distributions
+
+				// weareon=(*m).codonratestrue;						// one used for branch classes and 
+				// if(!weareon) weareon=(*m).codonratestrue;		// one used for models - not sure which
+				SetSiteRates2(rates, (*p).name, thisrep, rootlength);
+
+
+				// points to root sequence for this partition if defined by user rather than created in setuprootseq
+				vector<int>* myrootseq=&(  ((*p).rootseqints).at(partitionnumber)   );
+
+
+			// create root sequence if necessary and setup
+				setuprootseq(rates, *myrootseq, partitionnumber, TsequencesINT.at(partitionnumber), TinsPOS.at(partitionnumber), TinsINT.at(partitionnumber), sums);
+
+
+				#ifdef timewatch
+					startofevolution=clock();
+					(*LOG)<<endl<<"  * Set-up completed.    Time taken: "<<(double)(startofevolution-startofblock) / CLOCKS_PER_SEC <<" seconds."<<endl;
+				#endif			
+
+				// not currently used?
+				noinsertionsyet=true;
+				// do the evolving	
+				sorttreeout( TinsPOS.at(partitionnumber), rates, TinsINT.at(partitionnumber), startnodelabel, nonamestreewithnodes, thisrep, ntaxa, 
+					taxanames, TsequencesINT.at(partitionnumber), blocknumber, thisrep, numberofevolveblocks, reps, partitionnumber, 
+					numberofpartitions,  sums);
+
+
+				#ifdef timewatch
+					startofprinting=clock();
+					(*LOG)<<endl<<"  * Evolution completed. Time taken: "<<(double)(startofprinting - startofevolution) / CLOCKS_PER_SEC <<" seconds."<<endl;
+				#endif
+		
+				// updates total length for each partition
+				totallength+=rates.rootlength;
+
+
+				//random_shuffle(partitionpositions.begin(), partitionpositions.end()); /* shuffle elements --------> takes too long, so another method used */
+
+				//Tpartitionpositions.push_back(partitionpositions);
+
+				if(numberofpartitions>1) 
+				{
+					int R=totallength+dashlength-partitionnumber-1,bit=1;  partitionlengths.push_back(R);
+					
+					//if(printcodonsasDNA && type==3) {R*=3;bit=3;}
+
+					int L=lastlength+bit; lastlength=R;
+									
+					(*LOG)<<"\t"<<R-L+1<<"\t"<<L<<"\t"<<R<<"\t";
+					if(isitbranches) (*LOG)<<(*b).name; else (*LOG)<<(*m).name;
+					(*LOG)<<"\t"<<partitionnumber+1<<endl;
+				}
+
+
+				if(printrates) 
+				{
+					if(type!=3) 
+					{
+
+						if((*m).continuousgamma && isitbranches)  
+						{
+							ratesout<<endl<<"This partition uses continuous gamma rate variation and a non-homogenous model."<<endl;
+							ratesout<<      "The rates are not currently logged if alpha has changed on the tree. "<<endl;
+							ratesout<<      "The rates given below correspond to alpha="<<(*m).alpha<<" for model "<<(*m).name<<" only"<<endl<<endl;
+                            ratesout<<"Site\tRate\tPartition\tInserted?"<<endl; 
+
+							//ratesout<<endl<<"Partition "<<partitionnumber+1<<" uses  Rates are not logged for continuous gamma that changes over the tree. "<<endl<<"Please use discrete gamma if you need to know the specific rates for each site in a changing gamma model. "<<endl<<"Continuous gamma rates *are* logged for models where alpha does not change. Other parameters of the model may still change. "<<endl<<"If this is feature is a necessity for your work then use the [printallrates] command to log rate [...]
+						}
+						else 
+						{
+							if(isitbranches) 
+							{
+								ratesout<<endl<<"  N.B. For discrete gamma models that change over the tree, individual rates on"<<endl;
+								ratesout<<"       different branches can be calculated from the rates table below. "<<endl;
+								ratesout<<"       Just remember that the site *class* does not change over the tree."<<endl<<endl;
+					
+								int iii, jjj; m=&(totalmodels.at( mymods.at(0) )); int gg= ((*m).Rrates).size();
+								
+								ratesout<<"The columns below are the rates for the different classes under the different models."<<endl;
+								ratesout<< "The columns correspond to the following values of alpha used in the simulation:"<<endl<<endl;
+
+								for(iii=0; iii<mymods.size(); iii++)
+								{
+										m=&(totalmodels.at( mymods.at(iii) ));  ratesout<<(*m).alpha<<"    ";
+								}
+
+
+								ratesout<<endl<<endl<<"Class"<<endl;
+
+								vector<string> vs; vector<vector<string> >vvs; int maxsize=0;
+								for(jjj=0; jjj<gg; jjj++)
+								{	
+									vs.clear();
+									for(iii=0; iii<mymods.size(); iii++)
+									{
+										m=&(totalmodels.at( mymods.at(iii) ));
+
+										vector<double> rrates=(*m).Rrates;  
+										stringstream jh; jh<<rrates.at(jjj);  string fv=jh.str(); vs.push_back(fv); if(maxsize<fv.size()) maxsize=fv.size();
+									}
+									vvs.push_back(vs);
+								}
+
+								//cout<<"maxsize "<<maxsize<<endl;
+								for(jjj=0; jjj<gg; jjj++)
+								{	
+									ratesout<<jjj+1<<"\t";  vs=vvs.at(jjj);
+
+									for(iii=0; iii<mymods.size(); iii++)
+									{
+										string za=vs.at(iii);
+										ratesout<<za; for(int dc=0; dc<maxsize-za.size(); dc++) ratesout<<" "; ratesout<<"\t";
+									}
+									ratesout<<endl;
+								}
+								m=&(totalmodels.at( ((*b).rootmodelpos) )); 
+							}
+							else ratesout<<endl<<"alpha was "<<(*m).alpha<<" in this partition.";
+
+							if((*m).continuousgamma) ratesout<<endl<<endl<<"Site\tRate\tPartition\tInserted?"<<endl; else ratesout<<endl<<endl<<"Site\tClass\tRate\tPartition\tInserted?"<<endl;
+					
+						}
+					}
+					else if(partitionnumber==0)
+					{
+						ratesout<<"  N.B. Site classes are numbered from lowest to highest values of omega."<<endl;
+						ratesout<<"       The omegas are not given explicitly as they are permitted to change on different"<<endl; 
+						ratesout<<"       branches whereas the site classes are not allowed to change."<<endl;
+						ratesout<<"       Please consult your control file to find the corresponding omega values"<<endl<<endl;
+						ratesout<<"Site\tClass\tPartition\tInserted?"<<endl;
+						
+					}
+			
+					printoutrates(sitecount, partitionnumber+1, ratesout, (TinsPOS.at(partitionnumber)).at(0), (TinsINT.at(partitionnumber)).at(0) );
+
+				}
+
+
+
+
+
+
+
+			//	if(printrates) 
+			//	{
+			//		if((*m).continuousgamma && isitbranches && type!=3)  {}//ratesout<<"Rates are not logged for continuous gamma that changes over the tree. "<<endl<<"Please use discrete gamma if you need to know the specific rates for each site in a changing gamma model. "<<endl<<"Continuous gamma rates *are* logged for models where alpha does not change. Other parameters of the model may still change. "<<endl<<"If this is feature is a necessity for your work please contact me via the website for a [...]
+			//		else printoutrates(sitecount, partitionnumber+1, ratesout, (TinsPOS.at(partitionnumber)).at(0), (TinsINT.at(partitionnumber)).at(0) );
+			//	}
+			
+			} // end of for loop for partitions in a replicate
+
+
+
+			//if(numberofpartitions==1) (*LOG)<<endl<<"  "<<(*m).name<<"\twas the model used"<<endl;
+
+			//(*LOG)<<endl<<"  "<<totallength+dashlength-numberofpartitions<<"\tis true total alignment length."<<endl<<endl<<"--------------------------------------------------------------------"<<endl<<endl;
+
+			// print results to output files	
+#ifndef runseedstillbreak
+
+			printresultsout( thisrep,  filenamestub, ntaxa, totallength, taxanames, blocknumber, numberofevolveblocks,thisrep,reps,numberofpartitions);
+#endif
+
+				#ifdef timewatch
+					endofprinting=clock();
+					(*LOG)<<"  * Printing completed.  Time taken: "<<(double)(endofprinting - startofprinting) / CLOCKS_PER_SEC <<" seconds."<<endl;
+				#endif
+
+	
+
+		#ifdef printrepstoscreen
+			if(reps>1) cout<<"  * Block "<<blocknumber<<" - Replicate "<<thisrep<<" completed."<<endl;
+		#endif
+
+////////////////////////////////////////////////
+				#ifdef splittree
+					
+					// this compiler option is designed to split a 24 taxa tree into three 8 taxa trees at output to check that different parts of tree can evolve with different models.
+					// e.g. a 24 taxa tree where the three 8 taxa subtrees could be
+					// 1) GTR + continuous gamma with alpha = 0.5 + base frequencies 0.1 0.2 0.3 0.4
+					// 2) HKY + discrete gamma with alpha 2 + base frequencies 0.4 0.3 0.2 0.1
+					// 3) UNREST 
+
+					if(ntaxa!=24) {cout<<" WARNING: splittree compiler option only works on 24 taxa trees. No split done."<<endl<<endl; continue;} 
+
+					ofstream waste;
+					
+					if(!fileperrep && reps!=1) {cout<<"ERROR: splittree debug compile code is not meant to be used with fileperrep"<<endl<<"Please change the setting and re-try analysis"<<endl<<endl; return -1; }
+
+					if(outputtype!=2) {cout<<"ERROR: splittree debug compile code is only meant to be used with phylip format"<<endl<<endl; return -1;}
+
+
+					stringstream kk; kk<<thisrep; string gg=kk.str();
+										
+					string filename=filenamestub+"_TRUE_"+gg;
+
+					string endbit=".";  endbit+=phylipextension;
+
+					vector<string> myletters;
+
+					if(type==1) myletters=myDUletters; else if(type==2) myletters=myAUletters; else if(type==3) myletters=myCDUletters;
+
+
+					for(int a=1; a<4; a++)
+					{
+						stringstream dw; dw<<a; string dd=dw.str();  int myextra;
+
+						ofstream iff; iff.open( (filename+"_subtree"+dd+endbit).c_str() );
+
+						iff<<8<<"   "<<totallength+dashlength-numberofpartitions<<endl;
+
+						if(a==1) myextra=0; else if(a==2) myextra=8; else myextra=16;
+
+						for(int nx=1+myextra; nx<9+myextra; nx++)
+						{
+							iff<<taxaspacenames.at(nx);
+
+							for(int px=0; px<numberofpartitions; px++) makeprintseqLEAF(0, totallength+dashlength-numberofpartitions, (TinsPOS.at(px)).at(nx), (TsequencesINT.at(px)).at(nx), (TinsINT.at(px)).at(nx), nx, iff, waste,  0) ;
+							
+							iff<<endl;
+						}
+			
+
+					}		
+	
+					
+
+				#endif
+
+
+////////////////////////////////////////////////			
+				#ifdef rippartitions
+					
+					// this is designed to rip the partitions from a partitioned simulated dataset and spit them in to separate files 
+					// that can be subjected to separate analyses to check that the partition system works ok.  number of partitions unlimited for test.
+			
+					if(numberofpartitions==1) continue;
+
+					ofstream waste;
+
+					cout<<" WARNING: deletion rate > 0 in any model in any partition will probably"<<endl<<"          cause the rippartitions debug code to crash."<<endl<<endl; 
+					
+					if(!fileperrep) {cout<<"ERROR: rippartitions debug compile code is not meant to be used with fileperrep"<<endl<<"Please delete the file paupmiddle.txt and re-try analysis"<<endl<<endl; return -1; }
+
+					if(outputtype!=2) {cout<<"ERROR: rippartitions debug compile code is only meant to be used with phylip format"<<endl<<endl; return -1;}
+
+
+					stringstream kk; kk<<thisrep; string gg=kk.str();
+										
+					string filename=filenamestub+"_TRUE_"+gg;
+
+					string endbit=".";  endbit+=phylipextension;
+
+					vector<string> myletters;
+
+					if(type==1) myletters=myDUletters; else if(type==2) myletters=myAUletters; else if(type==3) myletters=myCDUletters;
+
+						
+						
+
+					for(int px=0; px<partitionlengths.size()-1; px++)
+					{
+						stringstream b; b<<px+1; string bb=b.str();
+
+						ofstream iff; iff.open( (filename+"_part"+bb+endbit).c_str() );
+
+						int L=partitionlengths.at(px),R=partitionlengths.at(px+1), partlength=R-L; if(type==3) partlength*=3;
+
+						iff<<ntaxa<<"   "<<partlength<<endl;
+						
+						for(int nx=1; nx<ntaxa+1; nx++)
+						{
+							iff<<taxaspacenames.at(nx);  	
+
+							makeprintseqLEAF(0, partlength,  (TinsPOS.at(px)).at(nx), (TsequencesINT.at(px)).at(nx), (TinsINT.at(px)).at(nx), nx, iff, waste,  0) ;
+
+							iff<<endl;
+						}					
+						
+					}
+		
+
+				#endif
+//////////////////////////////////////////////////////////////////
+
+
+
+		} // end of for loop for replicates in a block
+
+			if(printrates) ratesout.close();
+
+		
+		//prints out paupend if there is one file for all replicates.
+		if(!fileperrep) (*results)<<paupend<<endl; 
+
+#ifndef runseedstillbreak
+		// if indels have occurred print the true information about them for this block
+		if((*m).insertrate!=0 || (*m).deleterate!=0 ) printinsertinfo();
+#endif
+	//	cout<<clock()<<endl;
+	
+		endofblock=clock();
+		(*LOG)<<endl;
+		cout<<"  * Block "<<blocknumber<<" completed.   Time taken: "<<(double)(endofblock - startofblock) / CLOCKS_PER_SEC <<" seconds."<<endl;
+		 (*LOG)<<"  * Block "<<blocknumber<<" was completed in "<<(double)(endofblock - startofblock) / CLOCKS_PER_SEC <<" seconds."<<endl;
+
+	
+		(*LOG)<<endl<<"********************************************************************************"<<endl<<endl;
+	}// end of commandblocks for loop, i.e. blocks in a control file
+
+	(*results).close();	(*results2).close();	(*results3).close();
+
+		// print out final screen and log output and calculate simulation finish time etc
+
+		finish=clock();
+		time(&endtime); 		
+		timeinfo=localtime(&endtime);
+
+		if(numberofevolveblocks>1) cout<<"  * All blocks complete. Time taken: "<<(double)(finish - start) / CLOCKS_PER_SEC <<" seconds."<<endl<<endl;
+		cout<<"\n\n *** SIMULATION COMPLETED - PLEASE CONSULT OUTPUT FILES ***                                                                     "<<endl;
+
+	
+		(*LOG)<<"  * Simulation completed. Whole batch took: "<<(double)(finish - start) / CLOCKS_PER_SEC <<" seconds."<<endl<<endl;
+	
+		(*LOG)<<"INDELible V"<<VersionNumber<<" Simulations completed at: "<<asctime(timeinfo);
+
+		(*LOG)<<endl<<"********************************************************************************"<<endl<<endl;
+
+		cout<<endl<<endl<<" INDELible V"<<VersionNumber<<" Simulations completed at: "<<asctime(timeinfo)<<endl<<endl;
+
+#ifdef runseedstillbreak   
+} //endof qwerty for loop
+#endif
+
+
+		(*LOG)<<endl<<" Original Control File "<<endl;
+		(*LOG)<<endl<<"-----------------------"<<endl<<endl<<endl;
+
+
+		for(int bv=0; bv<originalcontrol.size()-1; bv++) (*LOG)<<originalcontrol.at(bv);
+
+	delete results; delete results2; delete results3; delete LOG;
+
+#endif
+  
+
+		return 0;
+}				
+
diff --git a/src/models.cpp b/src/models.cpp
new file mode 100644
index 0000000..cab0d9f
--- /dev/null
+++ b/src/models.cpp
@@ -0,0 +1,3579 @@
+/* 
+   INDELible V1.03
+    "A comprehensive and flexible simulator of molecular sequence evolution"
+    Copyright (C) 2009 William Fletcher
+
+    If using this software please cite the following reference:
+
+    Fletcher, W. and Yang, Z. 2009. 
+	"INDELible: a flexible simulator of biological sequence evolution." 
+	Mol. Biol. and Evol. (in press). 
+ 
+    If you need to contact me with any queries, questions, problems or (god-forbid) bugs
+    then please go to http://abacus.gene.ucl.ac.uk/software/indelible/bug.php
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    Please visit http://www.gnu.org/licenses/ for a full copy of the license.
+*/
+
+             
+
+#include <sstream>
+#include <string>
+#include <iostream>
+#include <vector>
+#include <fstream>  //???
+#include "paml.cpp"
+
+
+using namespace std;
+
+#pragma warning(disable:4786)	
+
+
+vector<vector<double> > totalusermodels;
+
+class indelmodel
+{
+	// all indel models conform to these parameters.
+	// not all are needed for each model
+	// but they must all be present for the pointer to the functions below to work.
+public:
+	double meansize;
+	int type;
+	int r;
+	double q;
+	double a;
+	double b;
+	int M;
+
+	vector<double> usermodel;
+
+	indelmodel()
+	{
+		//these settings chosen to cause a crash when indel model parameters not specified.
+		type=r=M=-1;
+		meansize=q=a=b=-1;		
+	}
+};
+
+
+// functions below are all of form int double vector<double>&
+// this is so generic pointer to these functions works
+
+int choosenewzipf(int M, double a, vector<double> &z) {int u; do {u=newZipf(a);} while(u>M || u<1); return u;} //do {u=newZipf(a);} while(u>M); return u;}
+int chooseoldzipf(int M, double a, vector<double> &z) {int u; do {u=oldZipf(a);} while(u>M || u<1); return u;} //do {u=oldZipf(a);} while(u>M); return u;}
+
+	int choosenewNB(int r, double q, vector<double> &z) {return randnegbin(r,q);}
+	int chooseoldNB(int r, double q, vector<double> &z) {return oldrandnegbin(r,q);}
+		
+	int userrandomsize(int x, double y, vector<double> &usermodel)
+	{
+		double myrand=mtrand1();
+
+		for(int i=0; i<usermodel.size(); i++) if(myrand<usermodel.at(i)) return i+1;
+
+		return usermodel.size();
+	}
+
+
+	int f(){return 1;}
+	int f2(double x, int y) {return int(x);}
+
+
+
+int type;	// 1 for NUCLEOTIDE, 2 for AMINOACID, 4 for CODON
+
+
+extern bool controldebug;
+
+extern void controlerrorprint2(string,string,string,string,string);
+
+
+const char GeneticCodeTable[24][65]={
+
+	// the following codes are as listed on genbank on October 2008
+
+	// 0 - NOTHING
+	"",
+	// 1  - The Standard Code
+	"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+    // 2  - The Vertebrate Mitochondrial Code
+    "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG",
+    // 3  - The Yeast Mitochondrial Code
+    "FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+    // 4  - The Mold, Protozoan, and Coelenterate Mitochondrial Code and the Mycoplasma/Spiroplasma Code
+	"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 5  - The Invertebrate Mitochondrial Code
+	"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG",
+	// 6  - The Ciliate, Dasycladacean and Hexamita Nuclear Code
+	"FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 7  - deleted
+	"",
+	// 8  - deleted
+	"",
+	// 9  - The Echinoderm and Flatworm Mitochondrial Code
+	"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
+	// 10 - The Euplotid Nuclear Code
+	"FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 11 - The Bacterial and Plant Plastid Code
+	"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 12 - The Alternative Yeast Nuclear Code
+	"FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 13 - The Ascidian Mitochondrial Code
+	"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG",
+	// 14 - The Alternative Flatworm Mitochondrial Code
+	"FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
+	// 15 - The Blepharisma Nuclear Code
+	"FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 16 - The Chlorophycean Mitochondrial Code
+	"FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 17 - deleted
+	"",
+	// 18 - deleted
+	"",
+	// 19 - deleted
+	"",
+	// 20 - deleted
+	"",
+	// 21 - The Trematode Mitochondrial Code 
+	"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
+	// 22 - The Scenedesmus obliquus mitochondrial Code 
+	"FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+	// 23 - The Thraustochytrium Mitochondrial Code
+	"FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG"
+};
+
+vector<int> allowedcodes(int gencode)
+{
+	vector<int> allowedlist;  
+
+	if(gencode==2 || gencode==6 || gencode ==14 || gencode==22 || gencode==23) allowedlist.push_back(gencode);
+
+	else if(gencode==15 || gencode==16) {allowedlist.push_back(15); allowedlist.push_back(16);}
+
+	else if(gencode==1 || gencode==11 || gencode==12) {allowedlist.push_back(1);allowedlist.push_back(11);allowedlist.push_back(12);}
+
+	else {allowedlist.push_back(3);allowedlist.push_back(4);allowedlist.push_back(5);allowedlist.push_back(9);
+	allowedlist.push_back(10);allowedlist.push_back(13);allowedlist.push_back(21);}
+
+	return allowedlist;
+}
+
+vector<int> getstops(int geneticcode)
+{
+	// finds the stops in genetic codes listed above
+
+	vector<int> stops; 
+
+	for(int i=0; i<64; i++) if(GeneticCodeTable[geneticcode][i]=='*') stops.push_back(i);
+
+	return stops;
+}
+
+void enforcestops(int geneticcode, vector<double> &basefreqs)
+{
+	// makes base frequencies of stop codons equal to zero
+
+	vector<int> stops=getstops(geneticcode);
+
+	for(int i=0; i<stops.size(); i++) basefreqs.at(stops.at(i))=0;
+}
+
+int querystops(int geneticcode, vector<double> &basefreqs)
+{
+	// returns non zero base frequencies at stop codons
+
+	vector<int> stops=getstops(geneticcode);
+
+	for(int i=0; i<stops.size(); i++) if(basefreqs.at(stops.at(i))!=0) return stops.at(i);
+
+	return -1;
+}
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+class model
+{
+	// this BIG class contains all details of substitution/indel model and all construtors etc
+public:
+
+	// parameters for indel model
+	double q1,  q2,  Hx0,  s,  Himax;
+	
+	double insD;
+	int insI;
+	vector<double> insV;
+
+	double delD;
+	int delI;
+	vector<double> delV;
+
+	double delmeansize;		// used in formula for total deletion rate
+	
+	// pointer for indel size generation
+	int (*delrandomsize)(int, double, vector<double>&) ;  
+	int (*insrandomsize)(int, double, vector<double>&) ;   
+	
+	// test function pointers
+	int (*pf)();
+	int (*pf2)(double, int);
+
+	// model name
+	string name;
+
+	int modelnumber;	//?
+	int geneticcode;
+
+	bool copiedmodel;			// whether the model is copied - defunct?
+	bool codonratestrue;		// whether model has different codon position specific relative rates
+	
+//	vector<double> insertrates;
+//	vector<double> deleterates;
+
+	double insertrate;			// relative instantaneous rate of insertion
+	double deleterate;			// relative instantaneous rate of deletion
+	double indelrate;			// relative instantaneous rate of insertion and deletion
+	double subrate;				// relative instantaneous rate of substitution (=1)
+
+	int modelpos;				// position in totalmodels
+	int type;					// nucleotide=1, aminoacid=2, codon=3
+	int error;				
+	int rootlength;				// ?
+	double alpha;				// alpha for gamma models
+	double pinv;			
+	int ngamcat;				// number of gamma categories for discrete gamma
+
+	double codonrates[3];		// relative substitution rates for codon positions
+
+	bool continuousgamma;		// whether this model has continuous gamma rate heterogeneity
+
+	int numberofsiteclasses;	// number of classes in codon sites model, or number of gamma categories too..
+
+	int medianORmean;			// 1 = use medians, 0 = use means, to represent categories in discrete gamma rate variation
+
+	vector<double> cumfreqs;	// cumulative frequencies for discrete gamma, or codon sites models	
+	vector<double> Rrates;		// relative rates for discrete gamma categories
+	vector<double> myomegas;	// different omegas for different site classes.
+
+	vector<double> rootbasefreqs;	// base frequencies used in root sequence creation if model at root
+	vector<double> basefreqs;		// stationary frequencies of model
+	vector<double> insertfreqs;		// frequencies used to generateinserted sequences
+	vector<double> myrates;			// vector of substitution rates "away" from a given state, used in method 2 jump chain
+
+	vector<vector<double> > myratesvec;		//vector of different "myrates" vectors for different site classes in codon site models
+
+	vector<int> ratevec;			// not used? ---> done in main skeleton file now.
+
+	vector<vector<double> > Jvec;	// transition matrix of the jump chain
+	vector<vector<double> > Qvec;	// transition probabilities
+
+	vector<double> scalefactors;	// used when scaling different Qvec from different site classes
+
+	vector<vector<vector<double> > > Jvecs;	///////   collection of Jvecs from different site classes
+	vector<vector<vector<double> > > Qvecs;	///////   collection of Qvecs from different site classes
+
+	model(int mymodelpos, int &mytype, string &myname, int &mymodelnumber, int &mygeneticcode,
+	bool &mycopiedmodel, double &myinsertrate, double &mydeleterate, double &myalpha, double &mypinv, 
+	int &myngamcat, double mycodonrates[], vector<double> &mybasefreqs, vector<double> &myrootbasefreqs, 
+	vector<double> &myinsertfreqs, vector<double> &myparams, vector<double> &aamodel, indelmodel &insertmodel,
+	indelmodel &deletemodel)
+	{
+		
+	
+		// set deletion model
+		delmeansize=deletemodel.meansize;
+
+		if(deletemodel.type == 0 || deletemodel.type == 3 || deletemodel.type == 12 ) 
+		{
+			delV=deletemodel.usermodel;
+			delrandomsize=&userrandomsize;
+		}
+		else if(deletemodel.type == 2 || deletemodel.type == 13) 
+		{
+			//Zipfian model
+
+			delI=deletemodel.M;   
+			delD=deletemodel.a;
+			
+			if(deletemodel.type==2) 
+			{
+				double v=1, q=delD;
+	
+				q1=1-q; q2=1/q1;
+	
+				Hx0 = H(0.5,q1,q2,v) - exp( log(v) * (-q) );
+	
+				s = 1 - H1( H(1.5,q1,q2,v) -exp( log(v+1) * (-q) )  ,q1,q2,v );
+
+				Himax = H( imax + 0.5 ,q1,q2,v);
+
+				delrandomsize=&choosenewzipf;
+			}
+			else					delrandomsize=&chooseoldzipf;
+		}
+		else if(deletemodel.type == 1 || deletemodel.type == 11) 
+		{
+			// Negative Binomial or Geometric
+
+			delI=deletemodel.r; 
+			delD=deletemodel.q;
+
+			if(deletemodel.type==1) delrandomsize=&choosenewNB;
+			else					delrandomsize=&chooseoldNB;
+		}
+
+
+		// set insertion model
+		if(insertmodel.type == 0 || insertmodel.type == 3 || insertmodel.type == 12 ) 
+		{
+			insV=insertmodel.usermodel;
+
+			insrandomsize=&userrandomsize;
+		}
+		else if(insertmodel.type == 2 || insertmodel.type == 13) 
+		{
+			//Zipfian model
+
+			insI=insertmodel.M; 
+			insD=insertmodel.a;
+
+			if(insertmodel.type==2) 
+			{
+				double v=1, q=insD;
+	
+				q1=1-q; q2=1/q1;
+	
+				Hx0 = H(0.5,q1,q2,v) - exp( log(v) * (-q) );
+	
+				s = 1 - H1( H(1.5,q1,q2,v) -exp( log(v+1) * (-q) )  ,q1,q2,v );
+
+				Himax = H( imax + 0.5 ,q1,q2,v);
+
+				insrandomsize=&choosenewzipf;
+			}
+			else					insrandomsize=&chooseoldzipf;
+		}
+		else if(insertmodel.type == 1 || insertmodel.type == 11) 
+		{
+			// Negative Binomial or Geometric
+
+			insI=insertmodel.r; 
+			insD=insertmodel.q;
+
+			if(insertmodel.type==1) insrandomsize=&choosenewNB;
+			else					insrandomsize=&chooseoldNB;
+		}
+
+
+
+						
+
+		continuousgamma=false;
+		numberofsiteclasses=1;
+
+		insertrate	=myinsertrate;
+		deleterate	=mydeleterate;
+		subrate=1;
+		//indelrate=insertrate+deleterate;
+		//subrate		=1-insertrate-deleterate;
+
+		modelpos=mymodelpos;
+
+		error=1;
+		type=mytype;
+		name=myname;
+		modelnumber=mymodelnumber;
+		geneticcode=mygeneticcode;
+		copiedmodel=mycopiedmodel;
+
+		alpha=myalpha;
+		pinv=mypinv;
+		ngamcat=myngamcat;
+
+		medianORmean=0;
+	
+		if(type!=3)
+		{
+			// set up discrete gamma and/or pinv --> actual rates are picked in SetSiteRates in main skeleton file.
+			if(alpha>0) 
+			{
+				if(ngamcat==0) {Rrates.push_back(1); cumfreqs.push_back(1);  continuousgamma=true;  }
+				else
+				{
+					DiscreteGamma(cumfreqs,Rrates,pinv, alpha,alpha,ngamcat,medianORmean);
+				}
+			}
+			else
+			{
+				if(pinv>0) {Rrates.push_back(0); Rrates.push_back(1/(1-pinv));  cumfreqs.push_back(pinv); cumfreqs.push_back(1); }
+				else {Rrates.push_back(1); cumfreqs.push_back(1); }
+			} 
+
+			numberofsiteclasses=Rrates.size();
+		}
+
+		// set up codon position specific relative substitution rates.
+		// has no effect if gamma model used - that supercedes this setting.
+
+		if( alpha==0 && (mycodonrates[0]!=1 || mycodonrates[1]!=1 || mycodonrates[2]!=1) ) codonratestrue=true; else codonratestrue=false;
+		codonrates[0]=mycodonrates[0];
+		codonrates[1]=mycodonrates[1];
+		codonrates[2]=mycodonrates[2];
+
+		if(type==1 && !copiedmodel)
+		{
+			// for DNA
+			if(mybasefreqs.empty()) 
+			{
+				// if base frequencies are empty
+				if(modelnumber%2==1 && modelnumber<16 ) //&& !copiedmodel)  
+				{
+					//when they shouldn't be give a warning
+					stringstream med; med<<modelnumber; string modelnumberX=med.str();
+					controlerrorprint2("[MODEL]",name,"basefreqs","A model with unequal base frequencies was chosen: model "+modelnumberX+"\nbut you have not specified base frequencies.  They will be equal.",""); 
+				}
+				// make equal frequencies either way
+				makeequalfreqs(type,basefreqs);
+			}
+			else
+			{
+				// if base frequencies are given
+				if(modelnumber%2==0 && modelnumber<16 ) // && !copiedmodel)  
+				{
+					// on a model that wants equal frequencies
+					// force frequencies to be equal and give warning
+					makeequalfreqs(type,basefreqs);
+					stringstream med; med<<modelnumber; string modelnumberX=med.str();
+					controlerrorprint2("[MODEL]",name,"basefreqs","A model with equal base frequencies was chosen: model "+modelnumberX+"\nbut you have specified base frequencies.  They will be set equal.",""); 
+				}
+				// otherwise set frequencies as given
+				else basefreqs=mybasefreqs;  
+			}
+			
+			
+		}
+
+		if(type==2 && !mybasefreqs.empty()) basefreqs=mybasefreqs;  // this will force +F models		
+
+		
+		if(type==3) 
+		{
+			if(mybasefreqs.empty()) makeequalfreqs(type,basefreqs);			// fequal frequencies
+
+			else if(mybasefreqs.size()==4) basefreqs=fx(mybasefreqs,1);		// f1x4 frequencies
+			
+			else if(mybasefreqs.size()==12) basefreqs=fx(mybasefreqs,3);	// f3x4 frequencies
+			
+			else if(mybasefreqs.size()==64) 								// fcodon frequencies
+			{
+				basefreqs=mybasefreqs;			
+
+				testmyfreqs(basefreqs,"[basefreq]");
+			}
+			else cout<<"INTERNAL ERROR 463"<<endl;
+
+		}
+			
+
+		
+		
+		// these make the correct Q matrix for a given type and model number
+				
+		// make Qvec and Jvec for nucleotide models
+		if(type==1) 
+		{
+
+		//	for(int y=0; y<Rrates.size(); y++)
+		//	{ 
+				Qvec=getDNA(name,myparams,basefreqs, modelnumber);   Qvecs.push_back(Qvec);
+				getJvec(0, /*Rrates.at(y)*/name,myrates,Qvec,Jvec,basefreqs); 
+				
+				if(Rrates.size()!=0) Jvecs.assign(Rrates.size(),Jvec); else Jvecs.push_back(Jvec);
+
+		//	}
+		}
+
+		// make Qvec and Jvec for amino acid models
+		if(type==2) 
+		{
+		//	for(int y=0; y<Rrates.size(); y++)
+		//	{ 
+				Qvec=getAA( name,myparams,basefreqs, modelnumber, aamodel); Qvecs.push_back(Qvec);
+				
+				getJvec(0,name,myrates,Qvec,Jvec,basefreqs); 
+				
+				if(Rrates.size()!=0) Jvecs.assign(Rrates.size(),Jvec); else Jvecs.push_back(Jvec);
+				
+		//	}
+		}
+
+		if(type==3) 
+		{
+			
+			/*
+			(*) Codon models for variable dN/dS ratios among sites
+				(com.nrate includes kappa & omega) (see also CDFdN_dS)
+
+				NSsites          npara
+
+				0  one-ratio     0:    one ratio for all sites
+				1  neutral       1:    p0 (w0=0, w1=1)
+				2  selection     3:    p0, p1, w2 (w0=0, w1=1)
+				3  discrete      2K-1: p0,p1,..., and w0,w1,...
+				4  freqs         K:    p's (w's are fixed)
+				5  gamma         2:    alpha, beta
+				6  2gamma        4:    p0, alpha1,beta1, alpha2=beta2
+				7  beta          2:    p_beta, q_beta
+				8  beta&w        4:    p0, p_beta, q_beta, w estimated
+				9  beta&gamma    5:    p0, p_beta, q_beta, alpha, beta
+			   10  beta&1+gamma  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+			   11  beta&1>normal 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+			   12  0&2normal     5:    p0, p1, mu2, s1, s2
+			   13  3normal       6:    p0, p1, mu2, s0, s1, s2
+			   14  M8a:beta&w=1  3:    p0, p_beta, q_beta, w=1 fixed
+			   15  M8a:beta&w>=1 4:    p0, p_beta, q_beta, w>=1 estimated
+
+
+			   */		
+
+			// CODON MODELS - numbered 0 to 15
+
+			// only 3 (M3) and 14, 15 are in proper use.  M0-M13 can all be expressed as M3
+
+			// 0 is the codon model of Goldman and Yang 1994 ; Goldman, N., and Z. Yang. 1994. A codon-based model of nucleotide substitution for protein-coding DNA sequences. Molecular Biology and Evolution 11:725-736.
+
+			// 1 to 13 are the codon sites-models of :Yang, Z., Nielsen, R., Goldman, N. and Pedersen, A-M. K. (2000) Codon-Substitution Models for Heterogeneous Selection Pressure at Amino Acid Sites. Genetics 155: 431-439 (May 2000)
+
+			// 14 and 15 are the empirical codon models ECM : Kosiol, C., Holmes, I. and Goldman, N. (2007) An Empirical Codon Model for Protein Sequence Evolution.  Molecular Biology and Evolution 24(7): 1464-1479.
+
+
+			if(modelnumber==14) 
+			{
+				Qvec=getECMr();
+				d(Qvec,scalefactors.at(0)); 
+				Qvecs.push_back(Qvec); 
+				getJvec(0,name,myrates,Qvec,Jvec,basefreqs); 
+				Jvecs.push_back(Jvec); 
+				cumfreqs.push_back(1);
+			}
+			else if(modelnumber==15) 
+			{
+				Qvec=getECMu();
+				d(Qvec,scalefactors.at(0));
+				Qvecs.push_back(Qvec); 
+				getJvec(0,name,myrates,Qvec,Jvec,basefreqs); 
+				Jvecs.push_back(Jvec); 
+				cumfreqs.push_back(1); 
+			}
+			else
+			{
+				// all other models  follow same pattern of generation.
+				// for each site class make the Qvec for that omega, and calculate the scale factor for that Qvec
+				// then calculate overall scale factor from the other scale factors and the proportions
+				// divide every Qvec for every site class by the overall scale factor.using d()
+				// then calculate Jvecs for each site class' Qvec
+
+				if(myparams.size()==0)
+				{
+					myparams.push_back(1); myparams.push_back(1);
+					controlerrorprint2("[MODEL]",name,"","No kappa/omega have been defined so they have been set equal to 1.","");
+				
+				}
+				double kappa=myparams.at(0);
+				double omega;
+
+				if(modelnumber==0) 
+				{
+					// (Goldman and Yang, 1994)  
+					
+					cumfreqs.push_back(1);
+					omega=myparams.at(1);  myomegas.push_back(omega);
+					Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega);
+					d(Qvec,scalefactors.at(0));
+					Qvecs.push_back(Qvec);
+
+					getJvec(0,name,myrates,Qvec,Jvec,basefreqs);
+					Jvecs.push_back(Jvec); 
+				}
+		
+				else if(modelnumber==1)
+				{
+					//cout<<myparams.at(1)<<" 1 1 "<<endl;
+					double p0=myparams.at(1), p1=1-p0;
+
+					cumfreqs.push_back(p0);
+					omega=myparams.at(2);   myomegas.push_back(omega);
+					Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);					
+
+					//cout<<1-myparams.at(1)<<" 1 2 "<<endl;
+					cumfreqs.push_back(p1);
+					omega=1;   myomegas.push_back(omega);
+					Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+
+					//double S=(p0*scalefactors.at(0))+(p1*scalefactors.at(1));
+
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) 
+					{
+						//ccout<<endl<<scalefactors.at(y1)<<"  "<<cumfreqs.at(y1)<<"  "<<scalefactors.at(y1)*cumfreqs.at(y1)<<endl;
+					
+						S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+					}
+					
+					d(Qvecs.at(0),S); getJvec(S,name,myrates,Qvecs.at(0),Jvec,basefreqs); Jvecs.push_back(Jvec); 					
+					d(Qvecs.at(1),S); getJvec(S,name,myrates,Qvecs.at(1),Jvec,basefreqs); Jvecs.push_back(Jvec); 					
+
+				}
+				else if(modelnumber==2)
+				{
+				//	cout<<myparams.at(1)<<" 1 1 "<<endl;
+				//	cout<<myparams.at(2)<<" 1 2 "<<endl;
+				//	cout<<myparams.at(3)<<" 1 3 "<<endl;
+				//	cout<<1-myparams.at(1)-myparams.at(2)<<" 1 4 "<<endl;
+
+
+					double p0=myparams.at(1), p1=myparams.at(2), p2=1-p0-p1;
+					cumfreqs.push_back(p0);
+					omega=myparams.at(3); //cout<<p0<<"  "<<omega<<endl; 
+					myomegas.push_back(omega);
+					Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);					
+
+					cumfreqs.push_back(p1);
+					omega=1;  //cout<<p1<<"  "<<omega<<endl;
+ 				    myomegas.push_back(omega);
+					Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);					
+
+					cumfreqs.push_back(p2);
+					omega=myparams.at(4); // cout<<p2<<"  "<<omega<<endl;
+				    myomegas.push_back(omega);
+					Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+					
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+
+					//for(int t1=0; t1<Qvecs.size(); t1++) {getJvec(S,name,myrates,Qvecs.at(t1),Jvec,basefreqs); Jvecs.push_back(Jvec); 	}	
+					d(Qvecs.at(0),S); getJvec(S,name,myrates,Qvecs.at(0),Jvec,basefreqs); Jvecs.push_back(Jvec); 
+					d(Qvecs.at(1),S); getJvec(S,name,myrates,Qvecs.at(1),Jvec,basefreqs); Jvecs.push_back(Jvec); 
+					d(Qvecs.at(2),S); getJvec(S,name,myrates,Qvecs.at(2),Jvec,basefreqs); Jvecs.push_back(Jvec); 
+
+				}
+				else if(modelnumber==3)
+				{
+
+					int mybit=myparams.size()/2; 
+					double sum=0;
+					for(int yf=1; yf<mybit; yf++)   
+					{
+						//cout<<yf<<" "<<"1"<<endl;
+						omega=myparams.at(yf+mybit-1);   myomegas.push_back(omega);
+						//cout<<yf<<" "<<"2 "<<myparams.at(yf+mybit-1)<<endl;
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+						
+										
+						//cout<<yf<<" "<<"3"<<endl;
+						sum+=myparams.at(yf);
+						//cout<<yf<<" "<<"4"<<endl;
+						cumfreqs.push_back(myparams.at(yf));
+						//cout<<yf<<" "<<"5 "<<myparams.at(yf)<<endl;
+					}
+	
+					if(sum<=1)
+					{
+						//cout<<"BLAH"<<endl;
+						omega=myparams.at(2*mybit-1);   myomegas.push_back(omega);
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+						
+					 					
+						cumfreqs.push_back(1-sum);
+						//cout<<"BLAH "<<1-sum<<" "<<omega<<endl;
+					}
+					else cout<<"Error in sum of category frequencies in codon model 3"<<endl;
+
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+					for(int yf0=0; yf0<Qvecs.size(); yf0++)   {d(Qvecs.at(yf0),S); getJvec(S,name,myrates,Qvecs.at(yf0),Jvec,basefreqs); Jvecs.push_back(Jvec); }
+				}
+
+
+
+
+				// model numbers 4 to 13 are not used any mor
+				// N.B.  THERE IS NO VECTOR OF DOUBLES CALLED myomegas IN THIS SECTION _ JUST IN CASE OF CRASHES
+				else if(modelnumber==4)
+				{
+
+					//as K-1 for 4, 2K-1 for 3, but is K and 2K because of kappa, difference of K
+					// for modelnumber 4, K=5 means size is 5 (kappa, p0, p1, p2, p3) with p4=1-p1-p2-p3 etc
+					double sum=0, mysize=myparams.size()-2;  // mysize is 3
+					for(int yf=1; yf<mysize+2; yf++)   //from 1 in the list (p0 after kappa) to mysize+2=5 goes up to p3
+					{
+						//cout<<yf<<" "<<"1"<<endl;
+						omega=(yf-1)/mysize;  //omega is 0, 1/3, 2/3. 1
+						//cout<<yf<<" "<<"2 "<<endl;
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+						
+							
+						//cout<<yf<<" "<<"3"<<endl;
+						sum+=myparams.at(yf);
+						//cout<<yf<<" "<<"4"<<endl;
+						cumfreqs.push_back(myparams.at(yf));
+						//cout<<yf<<" "<<"5 "<<myparams.at(yf)<<"  "<<omega<<endl;
+
+					}
+					if(sum<=1)
+					{
+						//cout<<"BLAH"<<endl;
+						omega=mysize; //omega is 3
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+						
+									
+						cumfreqs.push_back(1-sum);
+						//cout<<"BLAH "<<1-sum<<" "<<omega<<endl;
+
+					}
+					else cout<<"Error in sum of category frequencies in codon model 4"<<endl;
+				
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+					for(int yf0=0; yf0<Qvecs.size(); yf0++)   {d(Qvecs.at(yf0),S); getJvec(S,name,myrates,Qvecs.at(yf0),Jvec,basefreqs); Jvecs.push_back(Jvec); }
+
+				}
+				else 
+				{
+					if(modelnumber==12 || modelnumber==8)
+					{
+						if(modelnumber==12)
+						{
+							omega=0;
+							Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+							
+					 					
+							cumfreqs.push_back(myparams.at(1));
+							for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back((1-myparams.at(1))/double(ngamcat));
+						}
+						else
+						{
+							omega=myparams.at(4);
+							Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+							
+							 					
+							cumfreqs.push_back(1-myparams.at(1));
+							for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back(myparams.at(1)/double(ngamcat));
+						}
+					}
+					else cumfreqs.assign(ngamcat,1/double(ngamcat));
+ 
+					//for(int hfd=0; hfd<ngamcat; hfd++) cumfreqs.push_back(1/ngamcat);
+						
+					vector<double> output;
+
+					//double *mypar; mypar=new double[myparams.size()];
+					
+					double mypar[10]={0,0,0,0,0,0,0,0,0,0};
+
+					//mypar[0]=0;
+					for(int iu=1; iu<myparams.size(); iu++) {mypar[iu-1]=myparams.at(iu); }  
+
+					// this function of Ziheng's calculates the discrete rates for different site classes from the model parameters
+
+					DiscreteNSsites(mypar, ngamcat, modelnumber, output);
+
+					for(int i=0; i<ngamcat; i++)
+					{
+						omega=output.at(i);
+						Qvec=getCOD(name,basefreqs, modelnumber,kappa,omega); Qvecs.push_back(Qvec);
+											
+					}
+
+					double S=0; for(int y1=0; y1<cumfreqs.size(); y1++) S+=(scalefactors.at(y1)*cumfreqs.at(y1));
+					for(int yf0=0; yf0<Qvecs.size(); yf0++)   {d(Qvecs.at(yf0),S);  getJvec(S,name,myrates,Qvecs.at(yf0),Jvec,basefreqs); Jvecs.push_back(Jvec); }
+
+				}//end of model>4 bracket
+
+			} //end of solitary else bracket
+
+
+			//make cumfreqs cumulative;
+			double mysum=0;
+			vector<double> blah=cumfreqs;
+
+			numberofsiteclasses=cumfreqs.size();
+
+			for(int gfv=1; gfv<numberofsiteclasses; gfv++) cumfreqs.at(gfv)+=cumfreqs.at(gfv-1);
+				
+			for(int f=0; f<numberofsiteclasses; f++) Rrates.push_back(1);
+
+		}//end of type==3 bracket
+
+		// the Qvec/Jvec must be generated before the root/insert freqs are set in case the base frequencies come from 
+		// the model like in empirical sub models (codon/protein) or when using the UNREST model for DNA.
+
+		if(myrootbasefreqs.empty()) rootbasefreqs=basefreqs; else {rootbasefreqs=myrootbasefreqs; if(type==3) testmyfreqs(rootbasefreqs,"[rootbasefreq]"); }
+		
+		if(myinsertfreqs.empty()) insertfreqs=basefreqs; else {insertfreqs=myinsertfreqs; if(type==3) testmyfreqs(insertfreqs,"[ibasefreq]"); }
+	
+
+	}
+/////////////////////////////////////
+void changeQandJ(int numcats)
+{
+	Jvecs.assign(numcats,Jvec);	
+	Rrates.assign(numcats,1);
+	Qvecs.assign(numcats,Qvec);
+	myratesvec.assign(numcats,myrates);
+	numberofsiteclasses=numcats;
+}
+
+
+//////////////////////////////////////////////////////////////////
+
+
+private:
+
+
+void testmyfreqs(vector<double> &basefreqs, string mycommand)
+{
+	// this will point an error if there is a non-zero base frequency 
+	// for a stop codon depending on the genetic code used.
+	// It will not give an error when a zero is put by accident
+	// for a frequency not representing a stop codon.
+								
+	int wow=querystops(geneticcode, basefreqs);
+
+	if(wow!=-1) 
+	{
+		stringstream fs,fg1; fs<<wow; fg1<<geneticcode;  string fv=fs.str(), fg=fg1.str(); 
+		stringstream fs1; fs1<<basefreqs.at(wow);  string fv1=fs1.str(); 
+		controlerrorprint2("[MODEL]", name, mycommand, "Base frequencies are incorrect. For genetic code chosen: "+fg+"\nThe "+fv+"th stationary frequency should be zero not "+fv1+"\notherwise you might have stop codons in the middle of a sequence.",""); 
+
+		error=-1;
+	}
+}
+/////////////////////////////////////
+	void d(vector<vector<double> > &Q, double S) 
+	{
+		// multiply scale factor over Q matrix.
+
+		int i,j,s; 
+		if(type==2) s=20; else if(type==3) s=64; else s=4; 
+
+		for(i=0; i<s; i++)  for(j=0; j<s; j++)  ( (Q.at(i)).at(j) )/=S;
+	}
+/////////////////////////////////////
+
+
+vector<double> fx(vector<double> &basefreqs, int which)
+{
+	vector<double> newbasefreqs;
+
+	int i,j,k,l=0,m=0;  if(which==3) {l=4; m=8;}
+
+
+	for(i=0; i<4; i++) for(j=0; j<4; j++) for(k=0; k<4; k++) newbasefreqs.push_back(   (basefreqs.at(i)) * (basefreqs.at(j+l)) * (basefreqs.at(k+m))    );
+
+	enforcestops(geneticcode,newbasefreqs);
+
+	double tot;
+	tot=0; for(i=0; i<64; i++) tot+=(newbasefreqs.at(i)); //	cout<<"TOT "<<tot<<endl;
+	for(i=0; i<64; i++) (newbasefreqs.at(i))/=tot;
+	tot=0; for(i=0; i<64; i++) tot+=(newbasefreqs.at(i)); //	cout<<"TOT "<<tot<<endl;
+
+
+return newbasefreqs;
+
+
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+	void makeequalfreqs(int &type, vector<double> &tbasefreqs)
+	{
+		// makes equal stationary frequencies.
+		tbasefreqs.clear();
+
+			if(type==1)		for(int it=0; it<4; it++) tbasefreqs.push_back(0.25);
+		else if(type==2)	for(int it=0; it<20; it++) tbasefreqs.push_back(0.05);
+		else if(type==3) 
+		{
+			// for CODON the genetic code and the relevant stop codons must be considered.
+			vector<int> stops=getstops(geneticcode);
+
+			double y=stops.size();
+			double x=1/(64-y);
+			
+			for(int it=0; it<64; it++) {tbasefreqs.push_back(x);} //tbasefreqs.assign(64,0); ?? 
+
+			enforcestops(geneticcode,tbasefreqs);
+		}
+	}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+	void getJvec(double S, string name, vector<double> &myrates, vector<vector<double> > Qvec, vector<vector<double> > &Jvec, vector<double> &basefreqs)
+	{
+		// makes Jump Chain Transition Matrix from Q matrix = only used by method 2
+
+		int Qsize=Qvec.size();
+		int Qrowsize=(Qvec.at(0)).size();
+		int basesize=basefreqs.size();
+		int i,j;
+
+		vector<double> row;
+		Jvec=Qvec;
+
+		if(Qsize!=Qrowsize || Qsize!=basesize || Qrowsize!=basesize)
+		{controlerrorprint2("[MODEL]",name,"getJvec","mis-match in Q matrix and base frequency size",""); error=-1;}
+
+		// set rates from diagonal of matrix 
+		myrates.clear();
+		for (i=0; i<basesize; i++) {myrates.push_back((-1)*(Qvec.at(i)).at(i)); } //cout<<myrates.at(i)<<"\t"; } cout<<endl;
+
+		//create Jump matrix
+		for (i=0; i<basesize; i++)
+		{		
+			for (j=0; j<basesize; j++)
+			{
+				if(i!=j && myrates.at(i)!=0) (Jvec.at(i)).at(j) = (Qvec.at(i)).at(j)/myrates.at(i);
+				else{(Jvec.at(i)).at(j)=0;}
+			}
+		}
+
+		// turn into cumulative jump matrix
+		for (i=0; i<basesize; i++) for (j=1; j<basesize; j++) (Jvec.at(i)).at(j)+=(Jvec.at(i)).at(j-1);
+
+		// store rates for use in jump chain
+		myratesvec.push_back(myrates);
+
+	}
+
+////////////////////////////////
+
+vector<vector<double> > getDNA( string name, vector<double> nstnums, vector<double> &basefreqs, int mymodel)
+{
+	// function to make Q matrix for NUCLEOTIDE models
+
+	vector<vector<double> > myQvec;
+
+	double a=-1,b=-1,c=-1,d=-1,e=-1,f=-1,a1=-1,b1=-1,c1=-1,d1=-1,e1=-1,f1=-1;
+
+	double nstsize=nstnums.size()+1;
+
+	if(mymodel==0  || mymodel==1 ) 
+	{
+		/*
+			0 is JC69: Jukes, T. H. and Cantor, C. (1969) Evolution of protein molecules. pp. 21-132 in Mammalian Protein Metabolism, ed. M. N. Munro. Academic Press, New York.
+
+			1 is F81: Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a maximum likelihood approach. J. Mol. Evol., 17:368-376.
+
+		*/
+		a=b=c=d=e=f=1;
+	}
+	if(mymodel==2  || mymodel==3 ) 
+	{
+		/*
+			2 is K80: Kimura, M. (1980) A simple model for estimating evolutionary rates of base substitutions through comparative studies of nucleotide sequences. J. Mol. Evol. 16:111-120.
+
+			3 is HKY: Hasegawa, M., H. Kishino, and T. Yano. (1985) Dating of the human-ape splitting by a molecular clock of mitchondrial DNA. J. Mol. Evol. 22:160-174.
+
+		*/
+		//cout<<nstsize<<endl; cout<<nstnums.at(0)<<"Q"<<endl; if(nstnums.size()>1) cout<<nstnums.at(1)<<"Q"<<endl;
+		a=f=nstnums.at(0); if(nstsize==3) b=c=d=e=nstnums.at(1); else b=c=d=e=1;
+	}
+	if(mymodel==4  || mymodel==5 ) 
+	{
+		/*
+			4 is Tn93ef, 5 is Tn93   a.k.a. TrN
+
+			Tn93: Tamura, K. and Nei, M. (1993) Estimation of the number of nucleotide substitutions in the control region of mitochondrial DNA in humans and chimpanzees. Mol. Bio. Evol. 10:512-526. 
+		*/
+
+		a=nstnums.at(0);   if(nstsize==4) b=c=d=e=nstnums.at(2); else b=c=d=e=1; f=nstnums.at(1);
+	}
+	if(mymodel==6  || mymodel==7 ) 
+	{
+		/*
+			6 is K81, 7 is K81uf
+
+			K81: Kimura, M. (1981) Estimation of evolutionary distances between homologous nucleotide sequences. Proc. Natl. Acad. Sci. USA. 78:454-458. 
+		*/
+
+		a=f=1; b=e=nstnums.at(0); c=d=nstnums.at(1); if(nstsize==4) a=f=nstnums.at(2); 
+		//if(nstsize==4) {a=f=nstnums.at(0); b=e=nstnums.at(1); c=d=nstnums.at(2);} else {a=f=1; b=e=nstnums.at(0); c=d=nstnums.at(1);} 
+	}
+	if(mymodel==8  || mymodel==9 ) 
+	{
+		/*
+			8 is TIMef, 9 is TIM
+		*/
+
+		a=nstnums.at(0);   b=e=nstnums.at(1);     c=d=nstnums.at(2); f=1; if(nstsize==5) f=nstnums.at(3);
+	}
+	if(mymodel==10 || mymodel==11) 
+	{
+		/*
+			10 is TVMef, 11 is TVM
+		*/
+		
+		//if(nstsize==6) {a=f=nstnums.at(0); b=nstnums.at(1);       c=nstnums.at(2);   d=nstnums.at(3); e=nstnums.at(4);} else {a=f=1; b=nstnums.at(0); c=nstnums.at(1); d=nstnums.at(2); e=nstnums.at(3);}
+		a=f=1; b=nstnums.at(0); c=nstnums.at(1); d=nstnums.at(2); e=nstnums.at(3); if(nstsize==6) a=f=nstnums.at(4);
+	}
+	if(mymodel==12 || mymodel==13) 
+	{
+		/*
+			12 is SYM : Zharkikh, A. (1994) Estimation of evolutionary distances between nucleotide sequences. J. Mol. Evol. 39:315-329.
+
+			13 is GTR: 
+				Lanave, C., G. Preparata, C. Saccone, and G. Serio. (1984) A new method for calculating evolutionary substitution rates. J. Mol. Evol. 20:86-93. 
+				Tavare, S. (1986) Some probabilistic and statistical problems in the analysis of DNA sequences. Lec. Math. Life Sci. 17:57-86.
+		*/
+		a=nstnums.at(0);   b=nstnums.at(1);       c=nstnums.at(2);   d=nstnums.at(3); e=nstnums.at(4); f=1; if(nstsize==7) f=nstnums.at(5);
+	}
+				
+	if(mymodel==14 || mymodel==15) 
+	{
+		/*
+			14 is F84ef, 15 is F84
+			
+			Felsenstein, J. (1984) Distance Methods for inferring phylogenies: a justification.  Evolution. 38. 16-24.
+		*/
+
+		b=c=d=e=1; if(nstsize==3) b=c=d=e=nstnums.at(1);
+		double Kappa = nstnums.at(0);
+
+		double Pi_Y  = basefreqs.at(0)+basefreqs.at(1);
+		double Pi_R  = basefreqs.at(2)+basefreqs.at(3);
+						
+		a=(1+Kappa/Pi_Y)*b;  
+		f=(1+Kappa/Pi_R)*b;  
+					
+	}
+					
+/*	if(mymodel==16) 
+	{
+		//myinclude.at(10)=true;
+		double pi;
+		b=c=d=e=1; if(nstsize==4) b=c=d=e=nstnums.at(2);
+		a=f=b*nstnums.at(1); 
+		pi=nstnums.at(0);
+                        
+		basefreqs.at(0)=basefreqs.at(2)=(1-pi)/2;
+		basefreqs.at(1)=basefreqs.at(3)=pi/2;
+						
+	}
+					
+		if(mymodel==17) 
+*/
+		if(mymodel==16)
+		{
+			/*
+				16 is UNREST : Yang, Z. (1994) Estimating the pattern of nucleotide substitution. J Mol. Evol 39:105-111
+			*/
+
+			double denom,piT,piC,piA,piG;
+			double TC,TA,TG,CT,CA,CG,AT,AC,AG,GT,GC,GA;
+			
+			TC=nstnums.at(0);
+			TA=nstnums.at(1);
+			TG=nstnums.at(2);
+			CT=nstnums.at(3);
+			CA=nstnums.at(4);
+			CG=nstnums.at(5);
+			AT=nstnums.at(6);
+			AC=nstnums.at(7);
+			AG=nstnums.at(8);
+			GT=nstnums.at(9);  
+			GC=nstnums.at(10); 
+			GA=1;
+			if(nstsize==13) GA=nstnums.at(11); //cout<<TA<<endl;
+										
+			denom=((AT*CA*GA)+(AT*CG*GA)+(AC*CT*GA)+(AT*CT*GA)+(AT*CA*GC)+(AC*CT*GC)+(AG*CT*GC)+(AT*CT*GC)+(AG*CA*GT)+(AT*CA*GT)+(AC*CG*GT)+(AG*CG*GT)+(AT*CG*GT)+(AC*CT*GT)+(AG*CT*GT)+(AT*CT*GT)+(AG*CA*TA)+(AC*CG*TA)+(AG*CG*TA)+(AG*CT*TA)+(AC*GA*TA)+(CA*GA*TA)+(CG*GA*TA)+(CT*GA*TA)+(AC*GC*TA)+(AG*GC*TA)+(CA*GC*TA)+(CT*GC*TA)+(AC*GT*TA)+(CA*GT*TA)+(CG*GT*TA)+(CT*GT*TA)+(AG*CA*TC)+(AC*CG*TC)+(AG*CG*TC)+(AT*CG*TC)+(AC*GA*TC)+(AT*GA*TC)+(CA*GA*TC)+(CG*GA*TC)+(AC*GC*TC)+(AG*GC*TC)+(AT*GC*TC)+(CA*GC*TC [...]
+			piT=((AT*CA*GA)+(AT*CG*GA)+(AC*CT*GA)+(AT*CT*GA)+(AT*CA*GC)+(AC*CT*GC)+(AG*CT*GC)+(AT*CT*GC)+(AG*CA*GT)+(AT*CA*GT)+(AC*CG*GT)+(AG*CG*GT)+(AT*CG*GT)+(AC*CT*GT)+(AG*CT*GT)+(AT*CT*GT))/denom;
+			piC=((AC*GA*TA)+(AC*GC*TA)+(AG*GC*TA)+(AC*GT*TA)+(AC*GA*TC)+(AT*GA*TC)+(AC*GC*TC)+(AG*GC*TC)+(AT*GC*TC)+(AC*GT*TC)+(AG*GT*TC)+(AT*GT*TC)+(AC*GA*TG)+(AC*GC*TG)+(AG*GC*TG)+(AT*GC*TG))/denom;
+			piA=((CA*GA*TA)+(CG*GA*TA)+(CT*GA*TA)+(CA*GC*TA)+(CT*GC*TA)+(CA*GT*TA)+(CG*GT*TA)+(CT*GT*TA)+(CA*GA*TC)+(CG*GA*TC)+(CA*GC*TC)+(CA*GT*TC)+(CA*GA*TG)+(CG*GA*TG)+(CT*GA*TG)+(CA*GC*TG))/denom;
+			piG=((AG*CA*TA)+(AC*CG*TA)+(AG*CG*TA)+(AG*CT*TA)+(AG*CA*TC)+(AC*CG*TC)+(AG*CG*TC)+(AT*CG*TC)+(AG*CA*TG)+(AT*CA*TG)+(AC*CG*TG)+(AG*CG*TG)+(AT*CG*TG)+(AC*CT*TG)+(AG*CT*TG)+(AT*CT*TG))/denom;
+		
+			/*
+			               a = TC/piC;   b = TA/piA;   c = TG/piG;  
+			a1 = CT/piT;                 d = CA/piA;   e = CG/piG;  
+			b1 = AT/piT;  d1 = AC/piC;                 f = AG/piG;  
+			c1 = GT/piT;  e1 = GC/piC;  f1 = GA/piA;  
+			*/			
+		               a = TC;   b = TA;  c = TG;  
+			a1 = CT;             d = CA;  e = CG;  
+			b1 = AT;  d1 = AC;            f = AG;  
+			c1 = GT;  e1 = GC;  f1 = GA; 
+			
+			basefreqs.clear();
+			basefreqs.push_back(piT);  basefreqs.push_back(piC);
+			basefreqs.push_back(piA);  basefreqs.push_back(piG);
+					
+		
+		}
+					
+		if(mymodel!=16) 
+		{
+			// make matrix symmetrical if it is not UNREST
+			a1=a;b1=b;c1=c;d1=d;e1=e;f1=f;
+					
+			if(a==-1 || b==-1 || c==-1 || d==-1 || e==-1 || f==-1 || a1==-1 || b1==-1 || c1==-1 || d1==-1 || e1==-1 || f1==-1 )
+			{	controlerrorprint2(	"[MODEL]", name, "INT:makeQmatrix","DNA substitution parameter routine error - one or more values = -1",""); error=-1;}			
+		}
+				
+
+
+	// set entries of Q matrix.
+	vector<double> row; myQvec.clear();
+	row.clear(); row.push_back(0);	row.push_back(a);  row.push_back(b);  row.push_back(c); myQvec.push_back(row);
+	row.clear(); row.push_back(a1); row.push_back(0);  row.push_back(d);  row.push_back(e); myQvec.push_back(row);
+	row.clear(); row.push_back(b1); row.push_back(d1); row.push_back(0);  row.push_back(f); myQvec.push_back(row);
+	row.clear(); row.push_back(c1); row.push_back(e1); row.push_back(f1); row.push_back(0);	myQvec.push_back(row);
+
+	double sum = 0.0; int i,j;
+
+	if(mymodel!=16)	// these steps not necessary for UNREST
+	{
+		// rescale stationary frequencies, to make certain they sum to 1.0 
+		for (i=0; i<4; i++) sum += basefreqs.at(i); //cout<<basefreqs.at(i)<<" ";} cout<<endl;
+		if(sum!=1) for (i=0; i<4; i++) basefreqs.at(i) /= sum;
+
+		// multiply entries by stationary frequencies 
+		for (i=0; i<4; i++) for (j=0; j<4; j++) (myQvec.at(i)).at(j) *= basefreqs.at(j); //base freqs are same along a column. j is column
+	}
+	
+	// rescale, so branch lengths are in terms of expected number of substitutions per site 
+	double scaler = 0.0;
+
+	// calculate scale factor. note that Q_ii = 0 .
+	for (i=0; i<4; i++) for (j=0; j<4; j++)  scaler += basefreqs.at(i) * (myQvec.at(i)).at(j);
+
+	scaler = 1.0 / scaler;
+	
+	for (i=0; i<4; i++) for (j=0; j<4; j++) (myQvec.at(i)).at(j) *= scaler;
+		
+	//set diagonal of matrix
+	for( i=0; i<4; i++) {sum=0; for(j=0; j<4; j++) sum+=(myQvec.at(i)).at(j); (myQvec.at(i)).at(i)=-sum; }  //cout<<-sum<<endl;}
+
+	return myQvec;
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+
+vector<vector<double> > getAA( string name, vector<double> params, vector<double> &basefreqs, int modelnumber, vector<double> aamodel)
+{
+	// set Q matrix for AMINOACID substitution models
+
+	int			i, j; //, k;
+
+	double	diff;
+
+	vector<double> myrates;
+
+	double AAPi[20], AAmatrix[20][20], AAmatrixT[20][20], AAPiT[20];
+
+	/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 */
+	/* A R N D C Q E G H I L  K  M  F  P  S  T  W  Y  V  */ 
+
+	bool rootTOmodelOVERRIDE=false;	
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	if(aamodel.size()!=0)
+	{
+		// USER MODEL
+
+		for(i=0; i<20; i++) {AAmatrix[i][i]=0; AAPi[i]=0.05;}
+
+		// AAmatrix[i][j]
+		// 1,0
+		// 2,0  2,1
+		// 3,0  3,1  3,2
+
+		int k=0;
+
+		for(i=1; i<20; i++) for(j=0; j<i; j++) { AAmatrix[i][j]=AAmatrix[j][i]=aamodel.at(k); k++; }
+
+		if(aamodel.size()!=190) for(i=0; i<20; i++) {basefreqs.push_back(aamodel.at(k)); k++;}
+
+	}
+	else if(modelnumber==0)
+	{
+		/*poisson*/
+
+		for(i=0; i<20; i++){ AAPi[i]=0.05; for(j=0; j<20; j++){ if(i!=j) AAmatrix[i][j]=1; else AAmatrix[i][j]=0; }}  
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==1)
+	{
+
+	/* 
+		jones or JTT 
+
+		Jones, D.T., Taylor, W.R. & Thornton, J.M. (1992) The rapid generation of mutation data matrices from protein sequences. 
+		Comput. Applic. Biosci. 8, 275- 282.
+		
+	*/
+	AAmatrix[ 0][ 0] =   0; AAmatrix[ 0][ 1] =  58; AAmatrix[ 0][ 2] =  54; AAmatrix[ 0][ 3] =  81; AAmatrix[ 0][ 4] =  56; 
+	AAmatrix[ 0][ 5] =  57; AAmatrix[ 0][ 6] = 105; AAmatrix[ 0][ 7] = 179; AAmatrix[ 0][ 8] =  27; AAmatrix[ 0][ 9] =  36; 
+	AAmatrix[ 0][10] =  30; AAmatrix[ 0][11] =  35; AAmatrix[ 0][12] =  54; AAmatrix[ 0][13] =  15; AAmatrix[ 0][14] = 194; 
+	AAmatrix[ 0][15] = 378; AAmatrix[ 0][16] = 475; AAmatrix[ 0][17] =   9; AAmatrix[ 0][18] =  11; AAmatrix[ 0][19] = 298; 
+	AAmatrix[ 1][ 0] =  58; AAmatrix[ 1][ 1] =   0; AAmatrix[ 1][ 2] =  45; AAmatrix[ 1][ 3] =  16; AAmatrix[ 1][ 4] = 113; 
+	AAmatrix[ 1][ 5] = 310; AAmatrix[ 1][ 6] =  29; AAmatrix[ 1][ 7] = 137; AAmatrix[ 1][ 8] = 328; AAmatrix[ 1][ 9] =  22; 
+	AAmatrix[ 1][10] =  38; AAmatrix[ 1][11] = 646; AAmatrix[ 1][12] =  44; AAmatrix[ 1][13] =   5; AAmatrix[ 1][14] =  74; 
+	AAmatrix[ 1][15] = 101; AAmatrix[ 1][16] =  64; AAmatrix[ 1][17] = 126; AAmatrix[ 1][18] =  20; AAmatrix[ 1][19] =  17; 
+	AAmatrix[ 2][ 0] =  54; AAmatrix[ 2][ 1] =  45; AAmatrix[ 2][ 2] =   0; AAmatrix[ 2][ 3] = 528; AAmatrix[ 2][ 4] =  34; 
+	AAmatrix[ 2][ 5] =  86; AAmatrix[ 2][ 6] =  58; AAmatrix[ 2][ 7] =  81; AAmatrix[ 2][ 8] = 391; AAmatrix[ 2][ 9] =  47; 
+	AAmatrix[ 2][10] =  12; AAmatrix[ 2][11] = 263; AAmatrix[ 2][12] =  30; AAmatrix[ 2][13] =  10; AAmatrix[ 2][14] =  15; 
+	AAmatrix[ 2][15] = 503; AAmatrix[ 2][16] = 232; AAmatrix[ 2][17] =   8; AAmatrix[ 2][18] =  70; AAmatrix[ 2][19] =  16; 
+	AAmatrix[ 3][ 0] =  81; AAmatrix[ 3][ 1] =  16; AAmatrix[ 3][ 2] = 528; AAmatrix[ 3][ 3] =   0; AAmatrix[ 3][ 4] =  10; 
+	AAmatrix[ 3][ 5] =  49; AAmatrix[ 3][ 6] = 767; AAmatrix[ 3][ 7] = 130; AAmatrix[ 3][ 8] = 112; AAmatrix[ 3][ 9] =  11; 
+	AAmatrix[ 3][10] =   7; AAmatrix[ 3][11] =  26; AAmatrix[ 3][12] =  15; AAmatrix[ 3][13] =   4; AAmatrix[ 3][14] =  15; 
+	AAmatrix[ 3][15] =  59; AAmatrix[ 3][16] =  38; AAmatrix[ 3][17] =   4; AAmatrix[ 3][18] =  46; AAmatrix[ 3][19] =  31; 
+	AAmatrix[ 4][ 0] =  56; AAmatrix[ 4][ 1] = 113; AAmatrix[ 4][ 2] =  34; AAmatrix[ 4][ 3] =  10; AAmatrix[ 4][ 4] =   0; 
+	AAmatrix[ 4][ 5] =   9; AAmatrix[ 4][ 6] =   5; AAmatrix[ 4][ 7] =  59; AAmatrix[ 4][ 8] =  69; AAmatrix[ 4][ 9] =  17; 
+	AAmatrix[ 4][10] =  23; AAmatrix[ 4][11] =   7; AAmatrix[ 4][12] =  31; AAmatrix[ 4][13] =  78; AAmatrix[ 4][14] =  14; 
+	AAmatrix[ 4][15] = 223; AAmatrix[ 4][16] =  42; AAmatrix[ 4][17] = 115; AAmatrix[ 4][18] = 209; AAmatrix[ 4][19] =  62; 
+	AAmatrix[ 5][ 0] =  57; AAmatrix[ 5][ 1] = 310; AAmatrix[ 5][ 2] =  86; AAmatrix[ 5][ 3] =  49; AAmatrix[ 5][ 4] =   9; 
+	AAmatrix[ 5][ 5] =   0; AAmatrix[ 5][ 6] = 323; AAmatrix[ 5][ 7] =  26; AAmatrix[ 5][ 8] = 597; AAmatrix[ 5][ 9] =   9; 
+	AAmatrix[ 5][10] =  72; AAmatrix[ 5][11] = 292; AAmatrix[ 5][12] =  43; AAmatrix[ 5][13] =   4; AAmatrix[ 5][14] = 164; 
+	AAmatrix[ 5][15] =  53; AAmatrix[ 5][16] =  51; AAmatrix[ 5][17] =  18; AAmatrix[ 5][18] =  24; AAmatrix[ 5][19] =  20; 
+	AAmatrix[ 6][ 0] = 105; AAmatrix[ 6][ 1] =  29; AAmatrix[ 6][ 2] =  58; AAmatrix[ 6][ 3] = 767; AAmatrix[ 6][ 4] =   5; 
+	AAmatrix[ 6][ 5] = 323; AAmatrix[ 6][ 6] =   0; AAmatrix[ 6][ 7] = 119; AAmatrix[ 6][ 8] =  26; AAmatrix[ 6][ 9] =  12; 
+	AAmatrix[ 6][10] =   9; AAmatrix[ 6][11] = 181; AAmatrix[ 6][12] =  18; AAmatrix[ 6][13] =   5; AAmatrix[ 6][14] =  18; 
+	AAmatrix[ 6][15] =  30; AAmatrix[ 6][16] =  32; AAmatrix[ 6][17] =  10; AAmatrix[ 6][18] =   7; AAmatrix[ 6][19] =  45; 
+	AAmatrix[ 7][ 0] = 179; AAmatrix[ 7][ 1] = 137; AAmatrix[ 7][ 2] =  81; AAmatrix[ 7][ 3] = 130; AAmatrix[ 7][ 4] =  59; 
+	AAmatrix[ 7][ 5] =  26; AAmatrix[ 7][ 6] = 119; AAmatrix[ 7][ 7] =   0; AAmatrix[ 7][ 8] =  23; AAmatrix[ 7][ 9] =   6; 
+	AAmatrix[ 7][10] =   6; AAmatrix[ 7][11] =  27; AAmatrix[ 7][12] =  14; AAmatrix[ 7][13] =   5; AAmatrix[ 7][14] =  24; 
+	AAmatrix[ 7][15] = 201; AAmatrix[ 7][16] =  33; AAmatrix[ 7][17] =  55; AAmatrix[ 7][18] =   8; AAmatrix[ 7][19] =  47; 
+	AAmatrix[ 8][ 0] =  27; AAmatrix[ 8][ 1] = 328; AAmatrix[ 8][ 2] = 391; AAmatrix[ 8][ 3] = 112; AAmatrix[ 8][ 4] =  69; 
+	AAmatrix[ 8][ 5] = 597; AAmatrix[ 8][ 6] =  26; AAmatrix[ 8][ 7] =  23; AAmatrix[ 8][ 8] =   0; AAmatrix[ 8][ 9] =  16; 
+	AAmatrix[ 8][10] =  56; AAmatrix[ 8][11] =  45; AAmatrix[ 8][12] =  33; AAmatrix[ 8][13] =  40; AAmatrix[ 8][14] = 115; 
+	AAmatrix[ 8][15] =  73; AAmatrix[ 8][16] =  46; AAmatrix[ 8][17] =   8; AAmatrix[ 8][18] = 573; AAmatrix[ 8][19] =  11; 
+	AAmatrix[ 9][ 0] =  36; AAmatrix[ 9][ 1] =  22; AAmatrix[ 9][ 2] =  47; AAmatrix[ 9][ 3] =  11; AAmatrix[ 9][ 4] =  17; 
+	AAmatrix[ 9][ 5] =   9; AAmatrix[ 9][ 6] =  12; AAmatrix[ 9][ 7] =   6; AAmatrix[ 9][ 8] =  16; AAmatrix[ 9][ 9] =   0; 
+	AAmatrix[ 9][10] = 229; AAmatrix[ 9][11] =  21; AAmatrix[ 9][12] = 479; AAmatrix[ 9][13] =  89; AAmatrix[ 9][14] =  10; 
+	AAmatrix[ 9][15] =  40; AAmatrix[ 9][16] = 245; AAmatrix[ 9][17] =   9; AAmatrix[ 9][18] =  32; AAmatrix[ 9][19] = 961; 
+	AAmatrix[10][ 0] =  30; AAmatrix[10][ 1] =  38; AAmatrix[10][ 2] =  12; AAmatrix[10][ 3] =   7; AAmatrix[10][ 4] =  23; 
+	AAmatrix[10][ 5] =  72; AAmatrix[10][ 6] =   9; AAmatrix[10][ 7] =   6; AAmatrix[10][ 8] =  56; AAmatrix[10][ 9] = 229; 
+	AAmatrix[10][10] =   0; AAmatrix[10][11] =  14; AAmatrix[10][12] = 388; AAmatrix[10][13] = 248; AAmatrix[10][14] = 102; 
+	AAmatrix[10][15] =  59; AAmatrix[10][16] =  25; AAmatrix[10][17] =  52; AAmatrix[10][18] =  24; AAmatrix[10][19] = 180; 
+	AAmatrix[11][ 0] =  35; AAmatrix[11][ 1] = 646; AAmatrix[11][ 2] = 263; AAmatrix[11][ 3] =  26; AAmatrix[11][ 4] =   7; 
+	AAmatrix[11][ 5] = 292; AAmatrix[11][ 6] = 181; AAmatrix[11][ 7] =  27; AAmatrix[11][ 8] =  45; AAmatrix[11][ 9] =  21; 
+	AAmatrix[11][10] =  14; AAmatrix[11][11] =   0; AAmatrix[11][12] =  65; AAmatrix[11][13] =   4; AAmatrix[11][14] =  21; 
+	AAmatrix[11][15] =  47; AAmatrix[11][16] = 103; AAmatrix[11][17] =  10; AAmatrix[11][18] =   8; AAmatrix[11][19] =  14; 
+	AAmatrix[12][ 0] =  54; AAmatrix[12][ 1] =  44; AAmatrix[12][ 2] =  30; AAmatrix[12][ 3] =  15; AAmatrix[12][ 4] =  31; 
+	AAmatrix[12][ 5] =  43; AAmatrix[12][ 6] =  18; AAmatrix[12][ 7] =  14; AAmatrix[12][ 8] =  33; AAmatrix[12][ 9] = 479; 
+	AAmatrix[12][10] = 388; AAmatrix[12][11] =  65; AAmatrix[12][12] =   0; AAmatrix[12][13] =  43; AAmatrix[12][14] =  16; 
+	AAmatrix[12][15] =  29; AAmatrix[12][16] = 226; AAmatrix[12][17] =  24; AAmatrix[12][18] =  18; AAmatrix[12][19] = 323; 
+	AAmatrix[13][ 0] =  15; AAmatrix[13][ 1] =   5; AAmatrix[13][ 2] =  10; AAmatrix[13][ 3] =   4; AAmatrix[13][ 4] =  78; 
+	AAmatrix[13][ 5] =   4; AAmatrix[13][ 6] =   5; AAmatrix[13][ 7] =   5; AAmatrix[13][ 8] =  40; AAmatrix[13][ 9] =  89; 
+	AAmatrix[13][10] = 248; AAmatrix[13][11] =   4; AAmatrix[13][12] =  43; AAmatrix[13][13] =   0; AAmatrix[13][14] =  17; 
+	AAmatrix[13][15] =  92; AAmatrix[13][16] =  12; AAmatrix[13][17] =  53; AAmatrix[13][18] = 536; AAmatrix[13][19] =  62; 
+	AAmatrix[14][ 0] = 194; AAmatrix[14][ 1] =  74; AAmatrix[14][ 2] =  15; AAmatrix[14][ 3] =  15; AAmatrix[14][ 4] =  14; 
+	AAmatrix[14][ 5] = 164; AAmatrix[14][ 6] =  18; AAmatrix[14][ 7] =  24; AAmatrix[14][ 8] = 115; AAmatrix[14][ 9] =  10; 
+	AAmatrix[14][10] = 102; AAmatrix[14][11] =  21; AAmatrix[14][12] =  16; AAmatrix[14][13] =  17; AAmatrix[14][14] =   0; 
+	AAmatrix[14][15] = 285; AAmatrix[14][16] = 118; AAmatrix[14][17] =   6; AAmatrix[14][18] =  10; AAmatrix[14][19] =  23; 
+	AAmatrix[15][ 0] = 378; AAmatrix[15][ 1] = 101; AAmatrix[15][ 2] = 503; AAmatrix[15][ 3] =  59; AAmatrix[15][ 4] = 223; 
+	AAmatrix[15][ 5] =  53; AAmatrix[15][ 6] =  30; AAmatrix[15][ 7] = 201; AAmatrix[15][ 8] =  73; AAmatrix[15][ 9] =  40; 
+	AAmatrix[15][10] =  59; AAmatrix[15][11] =  47; AAmatrix[15][12] =  29; AAmatrix[15][13] =  92; AAmatrix[15][14] = 285; 
+	AAmatrix[15][15] =   0; AAmatrix[15][16] = 477; AAmatrix[15][17] =  35; AAmatrix[15][18] =  63; AAmatrix[15][19] =  38; 
+	AAmatrix[16][ 0] = 475; AAmatrix[16][ 1] =  64; AAmatrix[16][ 2] = 232; AAmatrix[16][ 3] =  38; AAmatrix[16][ 4] =  42; 
+	AAmatrix[16][ 5] =  51; AAmatrix[16][ 6] =  32; AAmatrix[16][ 7] =  33; AAmatrix[16][ 8] =  46; AAmatrix[16][ 9] = 245; 
+	AAmatrix[16][10] =  25; AAmatrix[16][11] = 103; AAmatrix[16][12] = 226; AAmatrix[16][13] =  12; AAmatrix[16][14] = 118; 
+	AAmatrix[16][15] = 477; AAmatrix[16][16] =   0; AAmatrix[16][17] =  12; AAmatrix[16][18] =  21; AAmatrix[16][19] = 112; 
+	AAmatrix[17][ 0] =   9; AAmatrix[17][ 1] = 126; AAmatrix[17][ 2] =   8; AAmatrix[17][ 3] =   4; AAmatrix[17][ 4] = 115; 
+	AAmatrix[17][ 5] =  18; AAmatrix[17][ 6] =  10; AAmatrix[17][ 7] =  55; AAmatrix[17][ 8] =   8; AAmatrix[17][ 9] =   9; 
+	AAmatrix[17][10] =  52; AAmatrix[17][11] =  10; AAmatrix[17][12] =  24; AAmatrix[17][13] =  53; AAmatrix[17][14] =   6; 
+	AAmatrix[17][15] =  35; AAmatrix[17][16] =  12; AAmatrix[17][17] =   0; AAmatrix[17][18] =  71; AAmatrix[17][19] =  25; 
+	AAmatrix[18][ 0] =  11; AAmatrix[18][ 1] =  20; AAmatrix[18][ 2] =  70; AAmatrix[18][ 3] =  46; AAmatrix[18][ 4] = 209; 
+	AAmatrix[18][ 5] =  24; AAmatrix[18][ 6] =   7; AAmatrix[18][ 7] =   8; AAmatrix[18][ 8] = 573; AAmatrix[18][ 9] =  32; 
+	AAmatrix[18][10] =  24; AAmatrix[18][11] =   8; AAmatrix[18][12] =  18; AAmatrix[18][13] = 536; AAmatrix[18][14] =  10; 
+	AAmatrix[18][15] =  63; AAmatrix[18][16] =  21; AAmatrix[18][17] =  71; AAmatrix[18][18] =   0; AAmatrix[18][19] =  16; 
+	AAmatrix[19][ 0] = 298; AAmatrix[19][ 1] =  17; AAmatrix[19][ 2] =  16; AAmatrix[19][ 3] =  31; AAmatrix[19][ 4] =  62; 
+	AAmatrix[19][ 5] =  20; AAmatrix[19][ 6] =  45; AAmatrix[19][ 7] =  47; AAmatrix[19][ 8] =  11; AAmatrix[19][ 9] = 961; 
+	AAmatrix[19][10] = 180; AAmatrix[19][11] =  14; AAmatrix[19][12] = 323; AAmatrix[19][13] =  62; AAmatrix[19][14] =  23; 
+	AAmatrix[19][15] =  38; AAmatrix[19][16] = 112; AAmatrix[19][17] =  25; AAmatrix[19][18] =  16; AAmatrix[19][19] =   0; 
+
+	AAPi[ 0] = 0.076748;
+	AAPi[ 1] = 0.051691;
+	AAPi[ 2] = 0.042645;
+	AAPi[ 3] = 0.051544;
+	AAPi[ 4] = 0.019803;
+	AAPi[ 5] = 0.040752;
+	AAPi[ 6] = 0.061830;
+	AAPi[ 7] = 0.073152;
+	AAPi[ 8] = 0.022944;
+	AAPi[ 9] = 0.053761;
+	AAPi[10] = 0.091904;
+	AAPi[11] = 0.058676;
+	AAPi[12] = 0.023826;
+	AAPi[13] = 0.040126;
+	AAPi[14] = 0.050901;
+	AAPi[15] = 0.068765;
+	AAPi[16] = 0.058565;
+	AAPi[17] = 0.014261;
+	AAPi[18] = 0.032102;
+	AAPi[19] = 0.066005;
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==2)
+	{
+
+	/* 
+		Jones DCMUT
+		
+		Kosiol, C., and Goldman, N. (2005) Different versions of the Dayhoff rate matrix. Molecular Biology and Evolution 22:193-199.
+	*/
+	AAmatrix[0][0]=0;			AAmatrix[0][1]=0.531678; 	AAmatrix[0][2]=0.557967; 	AAmatrix[0][3]=0.827445; 	AAmatrix[0][4]=0.574478; 	AAmatrix[0][5]=0.556725; 	AAmatrix[0][6]=1.066681; 	AAmatrix[0][7]=1.740159; 	AAmatrix[0][8]=0.21997; 	AAmatrix[0][9]=0.361684; 	AAmatrix[0][10]=0.310007; 	AAmatrix[0][11]=0.369437; 	AAmatrix[0][12]=0.469395; 	AAmatrix[0][13]=0.138293; 	AAmatrix[0][14]=1.959599; 	AAmatrix[0][15]=3.887095; 	AAmatrix[0][16]=4.582565; 	AAmatrix[0][17]=0.084329; 	AAmatrix[0][18]=0.1394 [...]
+	AAmatrix[1][0]=0.531678; 	AAmatrix[1][1]=0;			AAmatrix[1][2]=0.451095; 	AAmatrix[1][3]=0.154899; 	AAmatrix[1][4]=1.019843; 	AAmatrix[1][5]=3.021995; 	AAmatrix[1][6]=0.318483; 	AAmatrix[1][7]=1.359652; 	AAmatrix[1][8]=3.210671; 	AAmatrix[1][9]=0.239195; 	AAmatrix[1][10]=0.372261; 	AAmatrix[1][11]=6.529255; 	AAmatrix[1][12]=0.431045; 	AAmatrix[1][13]=0.065314; 	AAmatrix[1][14]=0.710489; 	AAmatrix[1][15]=1.001551; 	AAmatrix[1][16]=0.650282; 	AAmatrix[1][17]=1.257961; 	AAmatrix[1][18]=0.235 [...]
+	AAmatrix[2][0]=0.557967; 	AAmatrix[2][1]=0.451095; 	AAmatrix[2][2]=0; 			AAmatrix[2][3]=5.54953; 	AAmatrix[2][4]=0.313311; 	AAmatrix[2][5]=0.768834; 	AAmatrix[2][6]=0.578115; 	AAmatrix[2][7]=0.773313; 	AAmatrix[2][8]=4.025778; 	AAmatrix[2][9]=0.491003; 	AAmatrix[2][10]=0.137289; 	AAmatrix[2][11]=2.529517; 	AAmatrix[2][12]=0.33072; 	AAmatrix[2][13]=0.073481; 	AAmatrix[2][14]=0.121804; 	AAmatrix[2][15]=5.057964; 	AAmatrix[2][16]=2.351311; 	AAmatrix[2][17]=0.0277; 	AAmatrix[2][18]=0.700693 [...]
+	AAmatrix[3][0]=0.827445; 	AAmatrix[3][1]=0.154899; 	AAmatrix[3][2]=5.54953; 	AAmatrix[3][3]=0;			AAmatrix[3][4]=0.105625; 	AAmatrix[3][5]=0.521646; 	AAmatrix[3][6]=7.766557; 	AAmatrix[3][7]=1.272434; 	AAmatrix[3][8]=1.032342; 	AAmatrix[3][9]=0.115968; 	AAmatrix[3][10]=0.061486; 	AAmatrix[3][11]=0.282466; 	AAmatrix[3][12]=0.190001; 	AAmatrix[3][13]=0.032522; 	AAmatrix[3][14]=0.127164; 	AAmatrix[3][15]=0.589268; 	AAmatrix[3][16]=0.425159; 	AAmatrix[3][17]=0.057466; 	AAmatrix[3][18]=0.4539 [...]
+	AAmatrix[4][0]=0.574478; 	AAmatrix[4][1]=1.019843; 	AAmatrix[4][2]=0.313311; 	AAmatrix[4][3]=0.105625; 	AAmatrix[4][4]=0; 			AAmatrix[4][5]=0.091304; 	AAmatrix[4][6]=0.053907; 	AAmatrix[4][7]=0.546389; 	AAmatrix[4][8]=0.724998; 	AAmatrix[4][9]=0.150559; 	AAmatrix[4][10]=0.164593; 	AAmatrix[4][11]=0.049009; 	AAmatrix[4][12]=0.409202; 	AAmatrix[4][13]=0.678335; 	AAmatrix[4][14]=0.123653; 	AAmatrix[4][15]=2.155331; 	AAmatrix[4][16]=0.469823; 	AAmatrix[4][17]=1.104181; 	AAmatrix[4][18]=2.11 [...]
+	AAmatrix[5][0]=0.556725; 	AAmatrix[5][1]=3.021995; 	AAmatrix[5][2]=0.768834; 	AAmatrix[5][3]=0.521646; 	AAmatrix[5][4]=0.091304; 	AAmatrix[5][5]=0;			AAmatrix[5][6]=3.417706; 	AAmatrix[5][7]=0.231294; 	AAmatrix[5][8]=5.68408; 	AAmatrix[5][9]=0.07827; 	AAmatrix[5][10]=0.709004; 	AAmatrix[5][11]=2.966732; 	AAmatrix[5][12]=0.456901; 	AAmatrix[5][13]=0.045683; 	AAmatrix[5][14]=1.608126; 	AAmatrix[5][15]=0.548807; 	AAmatrix[5][16]=0.523825; 	AAmatrix[5][17]=0.172206; 	AAmatrix[5][18]=0.25474 [...]
+	AAmatrix[6][0]=1.066681; 	AAmatrix[6][1]=0.318483; 	AAmatrix[6][2]=0.578115; 	AAmatrix[6][3]=7.766557; 	AAmatrix[6][4]=0.053907; 	AAmatrix[6][5]=3.417706; 	AAmatrix[6][6]=0;			AAmatrix[6][7]=1.115632; 	AAmatrix[6][8]=0.243768; 	AAmatrix[6][9]=0.111773; 	AAmatrix[6][10]=0.097485; 	AAmatrix[6][11]=1.731684; 	AAmatrix[6][12]=0.175084; 	AAmatrix[6][13]=0.043829; 	AAmatrix[6][14]=0.191994; 	AAmatrix[6][15]=0.312449; 	AAmatrix[6][16]=0.331584; 	AAmatrix[6][17]=0.114381; 	AAmatrix[6][18]=0.063 [...]
+	AAmatrix[7][0]=1.740159; 	AAmatrix[7][1]=1.359652; 	AAmatrix[7][2]=0.773313; 	AAmatrix[7][3]=1.272434; 	AAmatrix[7][4]=0.546389; 	AAmatrix[7][5]=0.231294; 	AAmatrix[7][6]=1.115632; 	AAmatrix[7][7]=0; 			AAmatrix[7][8]=0.201696; 	AAmatrix[7][9]=0.053769; 	AAmatrix[7][10]=0.069492; 	AAmatrix[7][11]=0.26984; 	AAmatrix[7][12]=0.130379; 	AAmatrix[7][13]=0.050212; 	AAmatrix[7][14]=0.208081; 	AAmatrix[7][15]=1.874296; 	AAmatrix[7][16]=0.316862; 	AAmatrix[7][17]=0.54418; 	AAmatrix[7][18]=0.0525 [...]
+	AAmatrix[8][0]=0.21997; 	AAmatrix[8][1]=3.210671; 	AAmatrix[8][2]=4.025778; 	AAmatrix[8][3]=1.032342; 	AAmatrix[8][4]=0.724998; 	AAmatrix[8][5]=5.68408; 	AAmatrix[8][6]=0.243768; 	AAmatrix[8][7]=0.201696; 	AAmatrix[8][8]=0;			AAmatrix[8][9]=0.181788; 	AAmatrix[8][10]=0.540571; 	AAmatrix[8][11]=0.525096; 	AAmatrix[8][12]=0.32966; 	AAmatrix[8][13]=0.453428; 	AAmatrix[8][14]=1.141961; 	AAmatrix[8][15]=0.743458; 	AAmatrix[8][16]=0.477355; 	AAmatrix[8][17]=0.128193; 	AAmatrix[8][18]=5.8484;  [...]
+	AAmatrix[9][0]=0.361684; 	AAmatrix[9][1]=0.239195; 	AAmatrix[9][2]=0.491003; 	AAmatrix[9][3]=0.115968; 	AAmatrix[9][4]=0.150559; 	AAmatrix[9][5]=0.07827; 	AAmatrix[9][6]=0.111773; 	AAmatrix[9][7]=0.053769; 	AAmatrix[9][8]=0.181788; 	AAmatrix[9][9]=0;			AAmatrix[9][10]=2.335139; 	AAmatrix[9][11]=0.202562; 	AAmatrix[9][12]=4.831666; 	AAmatrix[9][13]=0.77709; 	AAmatrix[9][14]=0.09858; 	AAmatrix[9][15]=0.405119; 	AAmatrix[9][16]=2.553806; 	AAmatrix[9][17]=0.13451; 	AAmatrix[9][18]=0.303445; [...]
+	AAmatrix[10][0]=0.310007; 	AAmatrix[10][1]=0.372261; 	AAmatrix[10][2]=0.137289; 	AAmatrix[10][3]=0.061486; 	AAmatrix[10][4]=0.164593; 	AAmatrix[10][5]=0.709004; 	AAmatrix[10][6]=0.097485; 	AAmatrix[10][7]=0.069492; 	AAmatrix[10][8]=0.540571; 	AAmatrix[10][9]=2.335139; 	AAmatrix[10][10]=0; 		AAmatrix[10][11]=0.146481; 	AAmatrix[10][12]=3.856906; 	AAmatrix[10][13]=2.500294; 	AAmatrix[10][14]=1.060504; 	AAmatrix[10][15]=0.592511; 	AAmatrix[10][16]=0.272514; 	AAmatrix[10][17]=0.530324; 	AAm [...]
+	AAmatrix[11][0]=0.369437; 	AAmatrix[11][1]=6.529255; 	AAmatrix[11][2]=2.529517; 	AAmatrix[11][3]=0.282466; 	AAmatrix[11][4]=0.049009; 	AAmatrix[11][5]=2.966732; 	AAmatrix[11][6]=1.731684; 	AAmatrix[11][7]=0.26984; 	AAmatrix[11][8]=0.525096; 	AAmatrix[11][9]=0.202562; 	AAmatrix[11][10]=0.146481; 	AAmatrix[11][11]=0;			AAmatrix[11][12]=0.624581; 	AAmatrix[11][13]=0.024521; 	AAmatrix[11][14]=0.216345; 	AAmatrix[11][15]=0.474478; 	AAmatrix[11][16]=0.965641; 	AAmatrix[11][17]=0.089134; 	AAma [...]
+	AAmatrix[12][0]=0.469395; 	AAmatrix[12][1]=0.431045; 	AAmatrix[12][2]=0.33072; 	AAmatrix[12][3]=0.190001; 	AAmatrix[12][4]=0.409202; 	AAmatrix[12][5]=0.456901; 	AAmatrix[12][6]=0.175084; 	AAmatrix[12][7]=0.130379; 	AAmatrix[12][8]=0.32966; 	AAmatrix[12][9]=4.831666; 	AAmatrix[12][10]=3.856906; 	AAmatrix[12][11]=0.624581; 	AAmatrix[12][12]=0;			AAmatrix[12][13]=0.436181; 	AAmatrix[12][14]=0.164215; 	AAmatrix[12][15]=0.285564; 	AAmatrix[12][16]=2.114728; 	AAmatrix[12][17]=0.201334; 	AAmat [...]
+	AAmatrix[13][0]=0.138293; 	AAmatrix[13][1]=0.065314; 	AAmatrix[13][2]=0.073481; 	AAmatrix[13][3]=0.032522; 	AAmatrix[13][4]=0.678335; 	AAmatrix[13][5]=0.045683; 	AAmatrix[13][6]=0.043829; 	AAmatrix[13][7]=0.050212; 	AAmatrix[13][8]=0.453428; 	AAmatrix[13][9]=0.77709; 	AAmatrix[13][10]=2.500294; 	AAmatrix[13][11]=0.024521; 	AAmatrix[13][12]=0.436181; 	AAmatrix[13][13]=0;			AAmatrix[13][14]=0.148483; 	AAmatrix[13][15]=0.943971; 	AAmatrix[13][16]=0.138904; 	AAmatrix[13][17]=0.537922; 	AAma [...]
+	AAmatrix[14][0]=1.959599; 	AAmatrix[14][1]=0.710489; 	AAmatrix[14][2]=0.121804; 	AAmatrix[14][3]=0.127164; 	AAmatrix[14][4]=0.123653; 	AAmatrix[14][5]=1.608126; 	AAmatrix[14][6]=0.191994; 	AAmatrix[14][7]=0.208081; 	AAmatrix[14][8]=1.141961; 	AAmatrix[14][9]=0.09858; 	AAmatrix[14][10]=1.060504; 	AAmatrix[14][11]=0.216345; 	AAmatrix[14][12]=0.164215; 	AAmatrix[14][13]=0.148483; 	AAmatrix[14][14]=0;			AAmatrix[14][15]=2.788406; 	AAmatrix[14][16]=1.176961; 	AAmatrix[14][17]=0.069965; 	AAma [...]
+	AAmatrix[15][0]=3.887095; 	AAmatrix[15][1]=1.001551; 	AAmatrix[15][2]=5.057964; 	AAmatrix[15][3]=0.589268; 	AAmatrix[15][4]=2.155331; 	AAmatrix[15][5]=0.548807; 	AAmatrix[15][6]=0.312449; 	AAmatrix[15][7]=1.874296; 	AAmatrix[15][8]=0.743458; 	AAmatrix[15][9]=0.405119; 	AAmatrix[15][10]=0.592511; 	AAmatrix[15][11]=0.474478; 	AAmatrix[15][12]=0.285564; 	AAmatrix[15][13]=0.943971; 	AAmatrix[15][14]=2.788406; 	AAmatrix[15][15]=0;			AAmatrix[15][16]=4.777647; 	AAmatrix[15][17]=0.310927; 	AAm [...]
+	AAmatrix[16][0]=4.582565; 	AAmatrix[16][1]=0.650282; 	AAmatrix[16][2]=2.351311; 	AAmatrix[16][3]=0.425159; 	AAmatrix[16][4]=0.469823; 	AAmatrix[16][5]=0.523825; 	AAmatrix[16][6]=0.331584; 	AAmatrix[16][7]=0.316862; 	AAmatrix[16][8]=0.477355; 	AAmatrix[16][9]=2.553806; 	AAmatrix[16][10]=0.272514; 	AAmatrix[16][11]=0.965641; 	AAmatrix[16][12]=2.114728; 	AAmatrix[16][13]=0.138904; 	AAmatrix[16][14]=1.176961; 	AAmatrix[16][15]=4.777647; 	AAmatrix[16][16]=0;			AAmatrix[16][17]=0.080556; 	AAm [...]
+	AAmatrix[17][0]=0.084329; 	AAmatrix[17][1]=1.257961; 	AAmatrix[17][2]=0.0277; 	AAmatrix[17][3]=0.057466; 	AAmatrix[17][4]=1.104181; 	AAmatrix[17][5]=0.172206; 	AAmatrix[17][6]=0.114381; 	AAmatrix[17][7]=0.54418; 	AAmatrix[17][8]=0.128193; 	AAmatrix[17][9]=0.13451; 	AAmatrix[17][10]=0.530324; 	AAmatrix[17][11]=0.089134; 	AAmatrix[17][12]=0.201334; 	AAmatrix[17][13]=0.537922; 	AAmatrix[17][14]=0.069965; 	AAmatrix[17][15]=0.310927; 	AAmatrix[17][16]=0.080556; 	AAmatrix[17][17]=0;			AAmatri [...]
+	AAmatrix[18][0]=0.139492; 	AAmatrix[18][1]=0.235601; 	AAmatrix[18][2]=0.700693; 	AAmatrix[18][3]=0.453952; 	AAmatrix[18][4]=2.114852; 	AAmatrix[18][5]=0.254745; 	AAmatrix[18][6]=0.063452; 	AAmatrix[18][7]=0.0525; 	AAmatrix[18][8]=5.8484; 	AAmatrix[18][9]=0.303445; 	AAmatrix[18][10]=0.241094; 	AAmatrix[18][11]=0.087904; 	AAmatrix[18][12]=0.18987; 	AAmatrix[18][13]=5.484236; 	AAmatrix[18][14]=0.11385; 	AAmatrix[18][15]=0.628608; 	AAmatrix[18][16]=0.201094; 	AAmatrix[18][17]=0.747889; 	AAm [...]
+	AAmatrix[19][0]=2.924161; 	AAmatrix[19][1]=0.171995; 	AAmatrix[19][2]=0.164525; 	AAmatrix[19][3]=0.315261; 	AAmatrix[19][4]=0.621323; 	AAmatrix[19][5]=0.179771; 	AAmatrix[19][6]=0.465271; 	AAmatrix[19][7]=0.47014; 	AAmatrix[19][8]=0.121827; 	AAmatrix[19][9]=9.533943; 	AAmatrix[19][10]=1.761439; 	AAmatrix[19][11]=0.124066; 	AAmatrix[19][12]=3.038533; 	AAmatrix[19][13]=0.593478; 	AAmatrix[19][14]=0.211561; 	AAmatrix[19][15]=0.408532; 	AAmatrix[19][16]=1.14398; 	AAmatrix[19][17]=0.239697;  [...]
+
+		
+	AAPi[0]=0.076862; 
+	AAPi[1]=0.051057; 
+	AAPi[2]=0.042546; 
+	AAPi[3]=0.051269; 
+	AAPi[4]=0.020279; 
+	AAPi[5]=0.041061; 
+	AAPi[6]=0.06182; 
+	AAPi[7]=0.074714; 
+	AAPi[8]=0.022983; 
+	AAPi[9]=0.052569; 
+	AAPi[10]=0.091111; 
+	AAPi[11]=0.059498; 
+	AAPi[12]=0.023414; 
+	AAPi[13]=0.04053; 
+	AAPi[14]=0.050532; 
+	AAPi[15]=0.068225; 
+	AAPi[16]=0.058518; 
+	AAPi[17]=0.014336; 
+	AAPi[18]=0.032303; 
+	AAPi[19]=0.066374; 
+
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==3)
+	{
+
+	/* 
+		dayhoff 
+		
+		Dayhoff, M., Schwartz, R., & Orcutt, B. (1978) A model of evolutionary change in protein. Atlas of Protein Sequences and Structure, 5, 345--352
+	*/
+	AAmatrix[ 0][ 0] =   0; AAmatrix[ 0][ 1] =  27; AAmatrix[ 0][ 2] =  98; AAmatrix[ 0][ 3] = 120; AAmatrix[ 0][ 4] =  36; 
+	AAmatrix[ 0][ 5] =  89; AAmatrix[ 0][ 6] = 198; AAmatrix[ 0][ 7] = 240; AAmatrix[ 0][ 8] =  23; AAmatrix[ 0][ 9] =  65; 
+	AAmatrix[ 0][10] =  41; AAmatrix[ 0][11] =  26; AAmatrix[ 0][12] =  72; AAmatrix[ 0][13] =  18; AAmatrix[ 0][14] = 250; 
+	AAmatrix[ 0][15] = 409; AAmatrix[ 0][16] = 371; AAmatrix[ 0][17] =   0; AAmatrix[ 0][18] =  24; AAmatrix[ 0][19] = 208; 
+	AAmatrix[ 1][ 0] =  27; AAmatrix[ 1][ 1] =   0; AAmatrix[ 1][ 2] =  32; AAmatrix[ 1][ 3] =   0; AAmatrix[ 1][ 4] =  23; 
+	AAmatrix[ 1][ 5] = 246; AAmatrix[ 1][ 6] =   1; AAmatrix[ 1][ 7] =   9; AAmatrix[ 1][ 8] = 240; AAmatrix[ 1][ 9] =  64; 
+	AAmatrix[ 1][10] =  15; AAmatrix[ 1][11] = 464; AAmatrix[ 1][12] =  90; AAmatrix[ 1][13] =  14; AAmatrix[ 1][14] = 103; 
+	AAmatrix[ 1][15] = 154; AAmatrix[ 1][16] =  26; AAmatrix[ 1][17] = 201; AAmatrix[ 1][18] =   8; AAmatrix[ 1][19] =  24; 
+	AAmatrix[ 2][ 0] =  98; AAmatrix[ 2][ 1] =  32; AAmatrix[ 2][ 2] =   0; AAmatrix[ 2][ 3] = 905; AAmatrix[ 2][ 4] =   0; 
+	AAmatrix[ 2][ 5] = 103; AAmatrix[ 2][ 6] = 148; AAmatrix[ 2][ 7] = 139; AAmatrix[ 2][ 8] = 535; AAmatrix[ 2][ 9] =  77; 
+	AAmatrix[ 2][10] =  34; AAmatrix[ 2][11] = 318; AAmatrix[ 2][12] =   1; AAmatrix[ 2][13] =  14; AAmatrix[ 2][14] =  42; 
+	AAmatrix[ 2][15] = 495; AAmatrix[ 2][16] = 229; AAmatrix[ 2][17] =  23; AAmatrix[ 2][18] =  95; AAmatrix[ 2][19] =  15; 
+	AAmatrix[ 3][ 0] = 120; AAmatrix[ 3][ 1] =   0; AAmatrix[ 3][ 2] = 905; AAmatrix[ 3][ 3] =   0; AAmatrix[ 3][ 4] =   0; 
+	AAmatrix[ 3][ 5] = 134; AAmatrix[ 3][ 6] = 1153; AAmatrix[ 3][ 7] = 125; AAmatrix[ 3][ 8] =  86; AAmatrix[ 3][ 9] =  24; 
+	AAmatrix[ 3][10] =   0; AAmatrix[ 3][11] =  71; AAmatrix[ 3][12] =   0; AAmatrix[ 3][13] =   0; AAmatrix[ 3][14] =  13; 
+	AAmatrix[ 3][15] =  95; AAmatrix[ 3][16] =  66; AAmatrix[ 3][17] =   0; AAmatrix[ 3][18] =   0; AAmatrix[ 3][19] =  18; 
+	AAmatrix[ 4][ 0] =  36; AAmatrix[ 4][ 1] =  23; AAmatrix[ 4][ 2] =   0; AAmatrix[ 4][ 3] =   0; AAmatrix[ 4][ 4] =   0; 
+	AAmatrix[ 4][ 5] =   0; AAmatrix[ 4][ 6] =   0; AAmatrix[ 4][ 7] =  11; AAmatrix[ 4][ 8] =  28; AAmatrix[ 4][ 9] =  44; 
+	AAmatrix[ 4][10] =   0; AAmatrix[ 4][11] =   0; AAmatrix[ 4][12] =   0; AAmatrix[ 4][13] =   0; AAmatrix[ 4][14] =  19; 
+	AAmatrix[ 4][15] = 161; AAmatrix[ 4][16] =  16; AAmatrix[ 4][17] =   0; AAmatrix[ 4][18] =  96; AAmatrix[ 4][19] =  49; 
+	AAmatrix[ 5][ 0] =  89; AAmatrix[ 5][ 1] = 246; AAmatrix[ 5][ 2] = 103; AAmatrix[ 5][ 3] = 134; AAmatrix[ 5][ 4] =   0; 
+	AAmatrix[ 5][ 5] =   0; AAmatrix[ 5][ 6] = 716; AAmatrix[ 5][ 7] =  28; AAmatrix[ 5][ 8] = 606; AAmatrix[ 5][ 9] =  18; 
+	AAmatrix[ 5][10] =  73; AAmatrix[ 5][11] = 153; AAmatrix[ 5][12] = 114; AAmatrix[ 5][13] =   0; AAmatrix[ 5][14] = 153; 
+	AAmatrix[ 5][15] =  56; AAmatrix[ 5][16] =  53; AAmatrix[ 5][17] =   0; AAmatrix[ 5][18] =   0; AAmatrix[ 5][19] =  35; 
+	AAmatrix[ 6][ 0] = 198; AAmatrix[ 6][ 1] =   1; AAmatrix[ 6][ 2] = 148; AAmatrix[ 6][ 3] = 1153; AAmatrix[ 6][ 4] =   0; 
+	AAmatrix[ 6][ 5] = 716; AAmatrix[ 6][ 6] =   0; AAmatrix[ 6][ 7] =  81; AAmatrix[ 6][ 8] =  43; AAmatrix[ 6][ 9] =  61; 
+	AAmatrix[ 6][10] =  11; AAmatrix[ 6][11] =  83; AAmatrix[ 6][12] =  30; AAmatrix[ 6][13] =   0; AAmatrix[ 6][14] =  51; 
+	AAmatrix[ 6][15] =  79; AAmatrix[ 6][16] =  34; AAmatrix[ 6][17] =   0; AAmatrix[ 6][18] =  22; AAmatrix[ 6][19] =  37; 
+	AAmatrix[ 7][ 0] = 240; AAmatrix[ 7][ 1] =   9; AAmatrix[ 7][ 2] = 139; AAmatrix[ 7][ 3] = 125; AAmatrix[ 7][ 4] =  11; 
+	AAmatrix[ 7][ 5] =  28; AAmatrix[ 7][ 6] =  81; AAmatrix[ 7][ 7] =   0; AAmatrix[ 7][ 8] =  10; AAmatrix[ 7][ 9] =   0; 
+	AAmatrix[ 7][10] =   7; AAmatrix[ 7][11] =  27; AAmatrix[ 7][12] =  17; AAmatrix[ 7][13] =  15; AAmatrix[ 7][14] =  34; 
+	AAmatrix[ 7][15] = 234; AAmatrix[ 7][16] =  30; AAmatrix[ 7][17] =   0; AAmatrix[ 7][18] =   0; AAmatrix[ 7][19] =  54; 
+	AAmatrix[ 8][ 0] =  23; AAmatrix[ 8][ 1] = 240; AAmatrix[ 8][ 2] = 535; AAmatrix[ 8][ 3] =  86; AAmatrix[ 8][ 4] =  28; 
+	AAmatrix[ 8][ 5] = 606; AAmatrix[ 8][ 6] =  43; AAmatrix[ 8][ 7] =  10; AAmatrix[ 8][ 8] =   0; AAmatrix[ 8][ 9] =   7; 
+	AAmatrix[ 8][10] =  44; AAmatrix[ 8][11] =  26; AAmatrix[ 8][12] =   0; AAmatrix[ 8][13] =  48; AAmatrix[ 8][14] =  94; 
+	AAmatrix[ 8][15] =  35; AAmatrix[ 8][16] =  22; AAmatrix[ 8][17] =  27; AAmatrix[ 8][18] = 127; AAmatrix[ 8][19] =  44; 
+	AAmatrix[ 9][ 0] =  65; AAmatrix[ 9][ 1] =  64; AAmatrix[ 9][ 2] =  77; AAmatrix[ 9][ 3] =  24; AAmatrix[ 9][ 4] =  44; 
+	AAmatrix[ 9][ 5] =  18; AAmatrix[ 9][ 6] =  61; AAmatrix[ 9][ 7] =   0; AAmatrix[ 9][ 8] =   7; AAmatrix[ 9][ 9] =   0; 
+	AAmatrix[ 9][10] = 257; AAmatrix[ 9][11] =  46; AAmatrix[ 9][12] = 336; AAmatrix[ 9][13] = 196; AAmatrix[ 9][14] =  12; 
+	AAmatrix[ 9][15] =  24; AAmatrix[ 9][16] = 192; AAmatrix[ 9][17] =   0; AAmatrix[ 9][18] =  37; AAmatrix[ 9][19] = 889; 
+	AAmatrix[10][ 0] =  41; AAmatrix[10][ 1] =  15; AAmatrix[10][ 2] =  34; AAmatrix[10][ 3] =   0; AAmatrix[10][ 4] =   0; 
+	AAmatrix[10][ 5] =  73; AAmatrix[10][ 6] =  11; AAmatrix[10][ 7] =   7; AAmatrix[10][ 8] =  44; AAmatrix[10][ 9] = 257; 
+	AAmatrix[10][10] =   0; AAmatrix[10][11] =  18; AAmatrix[10][12] = 527; AAmatrix[10][13] = 157; AAmatrix[10][14] =  32; 
+	AAmatrix[10][15] =  17; AAmatrix[10][16] =  33; AAmatrix[10][17] =  46; AAmatrix[10][18] =  28; AAmatrix[10][19] = 175; 
+	AAmatrix[11][ 0] =  26; AAmatrix[11][ 1] = 464; AAmatrix[11][ 2] = 318; AAmatrix[11][ 3] =  71; AAmatrix[11][ 4] =   0; 
+	AAmatrix[11][ 5] = 153; AAmatrix[11][ 6] =  83; AAmatrix[11][ 7] =  27; AAmatrix[11][ 8] =  26; AAmatrix[11][ 9] =  46; 
+	AAmatrix[11][10] =  18; AAmatrix[11][11] =   0; AAmatrix[11][12] = 243; AAmatrix[11][13] =   0; AAmatrix[11][14] =  33; 
+	AAmatrix[11][15] =  96; AAmatrix[11][16] = 136; AAmatrix[11][17] =   0; AAmatrix[11][18] =  13; AAmatrix[11][19] =  10; 
+	AAmatrix[12][ 0] =  72; AAmatrix[12][ 1] =  90; AAmatrix[12][ 2] =   1; AAmatrix[12][ 3] =   0; AAmatrix[12][ 4] =   0; 
+	AAmatrix[12][ 5] = 114; AAmatrix[12][ 6] =  30; AAmatrix[12][ 7] =  17; AAmatrix[12][ 8] =   0; AAmatrix[12][ 9] = 336; 
+	AAmatrix[12][10] = 527; AAmatrix[12][11] = 243; AAmatrix[12][12] =   0; AAmatrix[12][13] =  92; AAmatrix[12][14] =  17; 
+	AAmatrix[12][15] =  62; AAmatrix[12][16] = 104; AAmatrix[12][17] =   0; AAmatrix[12][18] =   0; AAmatrix[12][19] = 258; 
+	AAmatrix[13][ 0] =  18; AAmatrix[13][ 1] =  14; AAmatrix[13][ 2] =  14; AAmatrix[13][ 3] =   0; AAmatrix[13][ 4] =   0; 
+	AAmatrix[13][ 5] =   0; AAmatrix[13][ 6] =   0; AAmatrix[13][ 7] =  15; AAmatrix[13][ 8] =  48; AAmatrix[13][ 9] = 196; 
+	AAmatrix[13][10] = 157; AAmatrix[13][11] =   0; AAmatrix[13][12] =  92; AAmatrix[13][13] =   0; AAmatrix[13][14] =  11; 
+	AAmatrix[13][15] =  46; AAmatrix[13][16] =  13; AAmatrix[13][17] =  76; AAmatrix[13][18] = 698; AAmatrix[13][19] =  12; 
+	AAmatrix[14][ 0] = 250; AAmatrix[14][ 1] = 103; AAmatrix[14][ 2] =  42; AAmatrix[14][ 3] =  13; AAmatrix[14][ 4] =  19; 
+	AAmatrix[14][ 5] = 153; AAmatrix[14][ 6] =  51; AAmatrix[14][ 7] =  34; AAmatrix[14][ 8] =  94; AAmatrix[14][ 9] =  12; 
+	AAmatrix[14][10] =  32; AAmatrix[14][11] =  33; AAmatrix[14][12] =  17; AAmatrix[14][13] =  11; AAmatrix[14][14] =   0; 
+	AAmatrix[14][15] = 245; AAmatrix[14][16] =  78; AAmatrix[14][17] =   0; AAmatrix[14][18] =   0; AAmatrix[14][19] =  48; 
+	AAmatrix[15][ 0] = 409; AAmatrix[15][ 1] = 154; AAmatrix[15][ 2] = 495; AAmatrix[15][ 3] =  95; AAmatrix[15][ 4] = 161; 
+	AAmatrix[15][ 5] =  56; AAmatrix[15][ 6] =  79; AAmatrix[15][ 7] = 234; AAmatrix[15][ 8] =  35; AAmatrix[15][ 9] =  24; 
+	AAmatrix[15][10] =  17; AAmatrix[15][11] =  96; AAmatrix[15][12] =  62; AAmatrix[15][13] =  46; AAmatrix[15][14] = 245; 
+	AAmatrix[15][15] =   0; AAmatrix[15][16] = 550; AAmatrix[15][17] =  75; AAmatrix[15][18] =  34; AAmatrix[15][19] =  30; 
+	AAmatrix[16][ 0] = 371; AAmatrix[16][ 1] =  26; AAmatrix[16][ 2] = 229; AAmatrix[16][ 3] =  66; AAmatrix[16][ 4] =  16; 
+	AAmatrix[16][ 5] =  53; AAmatrix[16][ 6] =  34; AAmatrix[16][ 7] =  30; AAmatrix[16][ 8] =  22; AAmatrix[16][ 9] = 192; 
+	AAmatrix[16][10] =  33; AAmatrix[16][11] = 136; AAmatrix[16][12] = 104; AAmatrix[16][13] =  13; AAmatrix[16][14] =  78; 
+	AAmatrix[16][15] = 550; AAmatrix[16][16] =   0; AAmatrix[16][17] =   0; AAmatrix[16][18] =  42; AAmatrix[16][19] = 157; 
+	AAmatrix[17][ 0] =   0; AAmatrix[17][ 1] = 201; AAmatrix[17][ 2] =  23; AAmatrix[17][ 3] =   0; AAmatrix[17][ 4] =   0; 
+	AAmatrix[17][ 5] =   0; AAmatrix[17][ 6] =   0; AAmatrix[17][ 7] =   0; AAmatrix[17][ 8] =  27; AAmatrix[17][ 9] =   0; 
+	AAmatrix[17][10] =  46; AAmatrix[17][11] =   0; AAmatrix[17][12] =   0; AAmatrix[17][13] =  76; AAmatrix[17][14] =   0; 
+	AAmatrix[17][15] =  75; AAmatrix[17][16] =   0; AAmatrix[17][17] =   0; AAmatrix[17][18] =  61; AAmatrix[17][19] =   0; 
+	AAmatrix[18][ 0] =  24; AAmatrix[18][ 1] =   8; AAmatrix[18][ 2] =  95; AAmatrix[18][ 3] =   0; AAmatrix[18][ 4] =  96; 
+	AAmatrix[18][ 5] =   0; AAmatrix[18][ 6] =  22; AAmatrix[18][ 7] =   0; AAmatrix[18][ 8] = 127; AAmatrix[18][ 9] =  37; 
+	AAmatrix[18][10] =  28; AAmatrix[18][11] =  13; AAmatrix[18][12] =   0; AAmatrix[18][13] = 698; AAmatrix[18][14] =   0; 
+	AAmatrix[18][15] =  34; AAmatrix[18][16] =  42; AAmatrix[18][17] =  61; AAmatrix[18][18] =   0; AAmatrix[18][19] =  28; 
+	AAmatrix[19][ 0] = 208; AAmatrix[19][ 1] =  24; AAmatrix[19][ 2] =  15; AAmatrix[19][ 3] =  18; AAmatrix[19][ 4] =  49; 
+	AAmatrix[19][ 5] =  35; AAmatrix[19][ 6] =  37; AAmatrix[19][ 7] =  54; AAmatrix[19][ 8] =  44; AAmatrix[19][ 9] = 889; 
+	AAmatrix[19][10] = 175; AAmatrix[19][11] =  10; AAmatrix[19][12] = 258; AAmatrix[19][13] =  12; AAmatrix[19][14] =  48; 
+	AAmatrix[19][15] =  30; AAmatrix[19][16] = 157; AAmatrix[19][17] =   0; AAmatrix[19][18] =  28; AAmatrix[19][19] =   0;
+
+	AAPi[ 0] = 0.087127;
+	AAPi[ 1] = 0.040904;
+	AAPi[ 2] = 0.040432;
+	AAPi[ 3] = 0.046872;
+	AAPi[ 4] = 0.033474;
+	AAPi[ 5] = 0.038255;
+	AAPi[ 6] = 0.049530;
+	AAPi[ 7] = 0.088612;
+	AAPi[ 8] = 0.033618;
+	AAPi[ 9] = 0.036886;
+	AAPi[10] = 0.085357;
+	AAPi[11] = 0.080482;
+	AAPi[12] = 0.014753;
+	AAPi[13] = 0.039772;
+	AAPi[14] = 0.050680;
+	AAPi[15] = 0.069577;
+	AAPi[16] = 0.058542;
+	AAPi[17] = 0.010494;
+	AAPi[18] = 0.029916;
+	AAPi[19] = 0.064718;
+
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==4)
+	{
+
+	/*
+		DayhoffDCMUT
+		
+		Kosiol, C., and Goldman, N. (2005) Different versions of the Dayhoff rate matrix. Molecular Biology and Evolution 22:193-199.
+	*/
+	AAmatrix[0][0] = 0;			AAmatrix[0][1] = 0.267828;	AAmatrix[0][2] = 0.984474;	AAmatrix[0][3] = 1.19981;	
+	AAmatrix[0][4] = 0.360016;	AAmatrix[0][5] = 0.887753;	AAmatrix[0][6] = 1.96117;	AAmatrix[0][7] = 2.38611;	
+	AAmatrix[0][8] = 0.228116;	AAmatrix[0][9] = 0.653416;	AAmatrix[0][10] = 0.406431;	AAmatrix[0][11] = 0.258635;	
+	AAmatrix[0][12] = 0.71784;	AAmatrix[0][13] = 0.183641;	AAmatrix[0][14] = 2.48592;	AAmatrix[0][15] = 4.05187;	
+	AAmatrix[0][16] = 3.68037;	AAmatrix[0][17] = 0;		AAmatrix[0][18] = 0.244139;	AAmatrix[0][19] = 2.05956;	
+	AAmatrix[1][0] = 0.267828;	AAmatrix[1][1] = 0;			AAmatrix[1][2] = 0.327059;	AAmatrix[1][3] = 0;	
+	AAmatrix[1][4] = 0.232374;	AAmatrix[1][5] = 2.43994;	AAmatrix[1][6] = 0;			AAmatrix[1][7] = 0.087791;	
+	AAmatrix[1][8] = 2.38315;	AAmatrix[1][9] = 0.632629;	AAmatrix[1][10] = 0.154924;	AAmatrix[1][11] = 4.61012;	
+	AAmatrix[1][12] = 0.896321;	AAmatrix[1][13] = 0.136906;	AAmatrix[1][14] = 1.02831;	AAmatrix[1][15] = 1.53159;	
+	AAmatrix[1][16] = 0.265745;	AAmatrix[1][17] = 2.00137;	AAmatrix[1][18] = 0.078012;	AAmatrix[1][19] = 0.240368;	
+	AAmatrix[2][0] = 0.984474;	AAmatrix[2][1] = 0.327059;	AAmatrix[2][2] = 0;			AAmatrix[2][3] = 8.93151;	
+	AAmatrix[2][4] = 0;			AAmatrix[2][5] = 1.02851;	AAmatrix[2][6] = 1.49341;	AAmatrix[2][7] = 1.38535;	
+	AAmatrix[2][8] = 5.29002;	AAmatrix[2][9] = 0.768024;	AAmatrix[2][10] = 0.341113;	AAmatrix[2][11] = 3.14837;	
+	AAmatrix[2][12] = 0;		AAmatrix[2][13] = 0.138503;	AAmatrix[2][14] = 0.419244;	AAmatrix[2][15] = 4.88589;	
+	AAmatrix[2][16] = 2.2717;	AAmatrix[2][17] = 0.224968;	AAmatrix[2][18] = 0.94694;	AAmatrix[2][19] = 0.158067;	
+	AAmatrix[3][0] = 1.19981;	AAmatrix[3][1] = 0;			AAmatrix[3][2] = 8.93151;	AAmatrix[3][3] = 0;	
+	AAmatrix[3][4] = 0;			AAmatrix[3][5] = 1.34855;	AAmatrix[3][6] = 11.3887;	AAmatrix[3][7] = 1.24098;	
+	AAmatrix[3][8] = 0.868241;	AAmatrix[3][9] = 0.239248;	AAmatrix[3][10] = 0;		AAmatrix[3][11] = 0.716913;	
+	AAmatrix[3][12] = 0;		AAmatrix[3][13] = 0;		AAmatrix[3][14] = 0.13394;	AAmatrix[3][15] = 0.956097;	
+	AAmatrix[3][16] = 0.66093;	AAmatrix[3][17] = 0;		AAmatrix[3][18] = 0;		AAmatrix[3][19] = 0.178316;	
+	AAmatrix[4][0] = 0.360016;	AAmatrix[4][1] = 0.232374;	AAmatrix[4][2] = 0;			AAmatrix[4][3] = 0;	
+	AAmatrix[4][4] = 0;			AAmatrix[4][5] = 0;			AAmatrix[4][6] = 0;			AAmatrix[4][7] = 0.107278;	
+	AAmatrix[4][8] = 0.282729;	AAmatrix[4][9] = 0.438074;	AAmatrix[4][10] = 0;		AAmatrix[4][11] = 0;	
+	AAmatrix[4][12] = 0;		AAmatrix[4][13] = 0;		AAmatrix[4][14] = 0.18755;	AAmatrix[4][15] = 1.59836;	
+	AAmatrix[4][16] = 0.162366;	AAmatrix[4][17] = 0;		AAmatrix[4][18] = 0.953164;	AAmatrix[4][19] = 0.484678;	
+	AAmatrix[5][0] = 0.887753;	AAmatrix[5][1] = 2.43994;	AAmatrix[5][2] = 1.02851;	AAmatrix[5][3] = 1.34855;	
+	AAmatrix[5][4] = 0;			AAmatrix[5][5] = 0;			AAmatrix[5][6] = 7.08602;	AAmatrix[5][7] = 0.281581;	
+	AAmatrix[5][8] = 6.01161;	AAmatrix[5][9] = 0.180393;	AAmatrix[5][10] = 0.730772;	AAmatrix[5][11] = 1.51908;	
+	AAmatrix[5][12] = 1.1275;	AAmatrix[5][13] = 0;		AAmatrix[5][14] = 1.52619;	AAmatrix[5][15] = 0.561828;	
+	AAmatrix[5][16] = 0.525651;	AAmatrix[5][17] = 0;		AAmatrix[5][18] = 0;		AAmatrix[5][19] = 0.346983;	
+	AAmatrix[6][0] = 1.96117;	AAmatrix[6][1] = 0;			AAmatrix[6][2] = 1.49341;	AAmatrix[6][3] = 11.3887;	
+	AAmatrix[6][4] = 0;			AAmatrix[6][5] = 7.08602;	AAmatrix[6][6] = 0;			AAmatrix[6][7] = 0.811907;	
+	AAmatrix[6][8] = 0.439469;	AAmatrix[6][9] = 0.609526;	AAmatrix[6][10] = 0.11288;	AAmatrix[6][11] = 0.830078;	
+	AAmatrix[6][12] = 0.304803;	AAmatrix[6][13] = 0;		AAmatrix[6][14] = 0.507003;	AAmatrix[6][15] = 0.793999;	
+	AAmatrix[6][16] = 0.340156;	AAmatrix[6][17] = 0;		AAmatrix[6][18] = 0.214717;	AAmatrix[6][19] = 0.36725;	
+	AAmatrix[7][0] = 2.38611;	AAmatrix[7][1] = 0.087791;	AAmatrix[7][2] = 1.38535;	AAmatrix[7][3] = 1.24098;	
+	AAmatrix[7][4] = 0.107278;	AAmatrix[7][5] = 0.281581;	AAmatrix[7][6] = 0.811907;	AAmatrix[7][7] = 0;	
+	AAmatrix[7][8] = 0.106802;	AAmatrix[7][9] = 0;			AAmatrix[7][10] = 0.071514;	AAmatrix[7][11] = 0.267683;	
+	AAmatrix[7][12] = 0.170372;	AAmatrix[7][13] = 0.153478;	AAmatrix[7][14] = 0.347153;	AAmatrix[7][15] = 2.32224;	
+	AAmatrix[7][16] = 0.306662;	AAmatrix[7][17] = 0;		AAmatrix[7][18] = 0;		AAmatrix[7][19] = 0.538165;	
+	AAmatrix[8][0] = 0.228116;	AAmatrix[8][1] = 2.38315;	AAmatrix[8][2] = 5.29002;	AAmatrix[8][3] = 0.868241;	
+	AAmatrix[8][4] = 0.282729;	AAmatrix[8][5] = 6.01161;	AAmatrix[8][6] = 0.439469;	AAmatrix[8][7] = 0.106802;	
+	AAmatrix[8][8] = 0;			AAmatrix[8][9] = 0.076981;	AAmatrix[8][10] = 0.443504;	AAmatrix[8][11] = 0.270475;	
+	AAmatrix[8][12] = 0;		AAmatrix[8][13] = 0.475927;	AAmatrix[8][14] = 0.933709;	AAmatrix[8][15] = 0.353643;	
+	AAmatrix[8][16] = 0.226333;	AAmatrix[8][17] = 0.270564;	AAmatrix[8][18] = 1.2654;	AAmatrix[8][19] = 0.438715;	
+	AAmatrix[9][0] = 0.653416;	AAmatrix[9][1] = 0.632629;	AAmatrix[9][2] = 0.768024;	AAmatrix[9][3] = 0.239248;	
+	AAmatrix[9][4] = 0.438074;	AAmatrix[9][5] = 0.180393;	AAmatrix[9][6] = 0.609526;	AAmatrix[9][7] = 0;	
+	AAmatrix[9][8] = 0.076981;	AAmatrix[9][9] = 0;			AAmatrix[9][10] = 2.55668;	AAmatrix[9][11] = 0.460857;	
+	AAmatrix[9][12] = 3.33273;	AAmatrix[9][13] = 1.95195;	AAmatrix[9][14] = 0.119152;	AAmatrix[9][15] = 0.247955;	
+	AAmatrix[9][16] = 1.90074;	AAmatrix[9][17] = 0;		AAmatrix[9][18] = 0.374834;	AAmatrix[9][19] = 8.81004;	
+	AAmatrix[10][0] = 0.406431;	AAmatrix[10][1] = 0.154924;	AAmatrix[10][2] = 0.341113;	AAmatrix[10][3] = 0;	
+	AAmatrix[10][4] = 0;		AAmatrix[10][5] = 0.730772;	AAmatrix[10][6] = 0.11288;	AAmatrix[10][7] = 0.071514;	
+	AAmatrix[10][8] = 0.443504;	AAmatrix[10][9] = 2.55668;	AAmatrix[10][10] = 0;		AAmatrix[10][11] = 0.180629;	
+	AAmatrix[10][12] = 5.23011;	AAmatrix[10][13] = 1.56516;	AAmatrix[10][14] = 0.316258;AAmatrix[10][15] = 0.171432;	
+	AAmatrix[10][16] = 0.33109;	AAmatrix[10][17] = 0.461776;AAmatrix[10][18] = 0.286572;AAmatrix[10][19] = 1.74516;	
+	AAmatrix[11][0] = 0.258635;	AAmatrix[11][1] = 4.61012;	AAmatrix[11][2] = 3.14837;	AAmatrix[11][3] = 0.716913;	
+	AAmatrix[11][4] = 0;		AAmatrix[11][5] = 1.51908;	AAmatrix[11][6] = 0.830078;	AAmatrix[11][7] = 0.267683;	
+	AAmatrix[11][8] = 0.270475;	AAmatrix[11][9] = 0.460857;	AAmatrix[11][10] = 0.180629;AAmatrix[11][11] = 0;	
+	AAmatrix[11][12] = 2.41174;	AAmatrix[11][13] = 0;		AAmatrix[11][14] = 0.335419;AAmatrix[11][15] = 0.954557;	
+	AAmatrix[11][16] = 1.3506;	AAmatrix[11][17] = 0;		AAmatrix[11][18] = 0.132142;AAmatrix[11][19] = 0.10385;	
+	AAmatrix[12][0] = 0.71784;	AAmatrix[12][1] = 0.896321;	AAmatrix[12][2] = 0;		AAmatrix[12][3] = 0;	
+	AAmatrix[12][4] = 0;		AAmatrix[12][5] = 1.1275;	AAmatrix[12][6] = 0.304803;	AAmatrix[12][7] = 0.170372;	
+	AAmatrix[12][8] = 0;		AAmatrix[12][9] = 3.33273;	AAmatrix[12][10] = 5.23011;	AAmatrix[12][11] = 2.41174;	
+	AAmatrix[12][12] = 0;		AAmatrix[12][13] = 0.92186;	AAmatrix[12][14] = 0.170205;AAmatrix[12][15] = 0.619951;	
+	AAmatrix[12][16] = 1.03153;	AAmatrix[12][17] = 0;		AAmatrix[12][18] = 0;		AAmatrix[12][19] = 2.56596;	
+	AAmatrix[13][0] = 0.183641;	AAmatrix[13][1] = 0.136906;	AAmatrix[13][2] = 0.138503;	AAmatrix[13][3] = 0;	
+	AAmatrix[13][4] = 0;		AAmatrix[13][5] = 0;		AAmatrix[13][6] = 0;		AAmatrix[13][7] = 0.153478;	
+	AAmatrix[13][8] = 0.475927;	AAmatrix[13][9] = 1.95195;	AAmatrix[13][10] = 1.56516;	AAmatrix[13][11] = 0;	
+	AAmatrix[13][12] = 0.92186;	AAmatrix[13][13] = 0;		AAmatrix[13][14] = 0.110506;AAmatrix[13][15] = 0.459901;	
+	AAmatrix[13][16] = 0.136655;AAmatrix[13][17] = 0.762354;AAmatrix[13][18] = 6.95263;	AAmatrix[13][19] = 0.123606;	
+	AAmatrix[14][0] = 2.48592;	AAmatrix[14][1] = 1.02831;	AAmatrix[14][2] = 0.419244;	AAmatrix[14][3] = 0.13394;	
+	AAmatrix[14][4] = 0.18755;	AAmatrix[14][5] = 1.52619;	AAmatrix[14][6] = 0.507003;	AAmatrix[14][7] = 0.347153;	
+	AAmatrix[14][8] = 0.933709;	AAmatrix[14][9] = 0.119152;	AAmatrix[14][10] = 0.316258;AAmatrix[14][11] = 0.335419;	
+	AAmatrix[14][12] = 0.170205;AAmatrix[14][13] = 0.110506;AAmatrix[14][14] = 0;		AAmatrix[14][15] = 2.4272;	
+	AAmatrix[14][16] = 0.782857;AAmatrix[14][17] = 0;		AAmatrix[14][18] = 0;		AAmatrix[14][19] = 0.485026;	
+	AAmatrix[15][0] = 4.05187;	AAmatrix[15][1] = 1.53159;	AAmatrix[15][2] = 4.88589;	AAmatrix[15][3] = 0.956097;	
+	AAmatrix[15][4] = 1.59836;	AAmatrix[15][5] = 0.561828;	AAmatrix[15][6] = 0.793999;	AAmatrix[15][7] = 2.32224;	
+	AAmatrix[15][8] = 0.353643;	AAmatrix[15][9] = 0.247955;	AAmatrix[15][10] = 0.171432;AAmatrix[15][11] = 0.954557;	
+	AAmatrix[15][12] = 0.619951;AAmatrix[15][13] = 0.459901;AAmatrix[15][14] = 2.4272;	AAmatrix[15][15] = 0;	
+	AAmatrix[15][16] = 5.43667;	AAmatrix[15][17] = 0.740819;AAmatrix[15][18] = 0.336289;AAmatrix[15][19] = 0.303836;	
+	AAmatrix[16][0] = 3.68037;	AAmatrix[16][1] = 0.265745;	AAmatrix[16][2] = 2.2717;	AAmatrix[16][3] = 0.66093;	
+	AAmatrix[16][4] = 0.162366;	AAmatrix[16][5] = 0.525651;	AAmatrix[16][6] = 0.340156;	AAmatrix[16][7] = 0.306662;	
+	AAmatrix[16][8] = 0.226333;	AAmatrix[16][9] = 1.90074;	AAmatrix[16][10] = 0.33109;	AAmatrix[16][11] = 1.3506;	
+	AAmatrix[16][12] = 1.03153;	AAmatrix[16][13] = 0.136655;AAmatrix[16][14] = 0.782857;AAmatrix[16][15] = 5.43667;	
+	AAmatrix[16][16] = 0;		AAmatrix[16][17] = 0;		AAmatrix[16][18] = 0.417839;AAmatrix[16][19] = 1.562;	
+	AAmatrix[17][0] = 0;		AAmatrix[17][1] = 2.00137;	AAmatrix[17][2] = 0.224968;	AAmatrix[17][3] = 0;	
+	AAmatrix[17][4] = 0;		AAmatrix[17][5] = 0;		AAmatrix[17][6] = 0;		AAmatrix[17][7] = 0;	
+	AAmatrix[17][8] = 0.270564;	AAmatrix[17][9] = 0;		AAmatrix[17][10] = 0.461776;AAmatrix[17][11] = 0;	
+	AAmatrix[17][12] = 0;		AAmatrix[17][13] = 0.762354;AAmatrix[17][14] = 0;		AAmatrix[17][15] = 0.740819;	
+	AAmatrix[17][16] = 0;		AAmatrix[17][17] = 0;		AAmatrix[17][18] = 0.60807;	AAmatrix[17][19] = 0;	
+	AAmatrix[18][0] = 0.244139;	AAmatrix[18][1] = 0.078012;	AAmatrix[18][2] = 0.94694;	AAmatrix[18][3] = 0;	
+	AAmatrix[18][4] = 0.953164;	AAmatrix[18][5] = 0;		AAmatrix[18][6] = 0.214717;	AAmatrix[18][7] = 0;	
+	AAmatrix[18][8] = 1.2654;	AAmatrix[18][9] = 0.374834;	AAmatrix[18][10] = 0.286572;AAmatrix[18][11] = 0.132142;	
+	AAmatrix[18][12] = 0;		AAmatrix[18][13] = 6.95263;	AAmatrix[18][14] = 0;		AAmatrix[18][15] = 0.336289;	
+	AAmatrix[18][16] = 0.417839;AAmatrix[18][17] = 0.60807;	AAmatrix[18][18] = 0;		AAmatrix[18][19] = 0.279379;	
+	AAmatrix[19][0] = 2.05956;	AAmatrix[19][1] = 0.240368;	AAmatrix[19][2] = 0.158067;	AAmatrix[19][3] = 0.178316;	
+	AAmatrix[19][4] = 0.484678;	AAmatrix[19][5] = 0.346983;	AAmatrix[19][6] = 0.36725;	AAmatrix[19][7] = 0.538165;	
+	AAmatrix[19][8] = 0.438715;	AAmatrix[19][9] = 8.81004;	AAmatrix[19][10] = 1.74516;	AAmatrix[19][11] = 0.10385;	
+	AAmatrix[19][12] = 2.56596;	AAmatrix[19][13] = 0.123606;AAmatrix[19][14] = 0.485026;AAmatrix[19][15] = 0.303836;	
+	AAmatrix[19][16] = 1.562;	AAmatrix[19][17] = 0;		AAmatrix[19][18] = 0.279379;AAmatrix[19][19] = 0;	
+
+	AAPi[0] = 0.087127;
+	AAPi[1] = 0.040904;
+	AAPi[2] = 0.040432;
+	AAPi[3] = 0.046872;
+	AAPi[4] = 0.033474;
+	AAPi[5] = 0.038255;
+	AAPi[6] = 0.04953;
+	AAPi[7] = 0.088612;
+	AAPi[8] = 0.033619;
+	AAPi[9] = 0.036886;
+	AAPi[10] = 0.085357;
+	AAPi[11] = 0.080481;
+	AAPi[12] = 0.014753;
+	AAPi[13] = 0.039772;
+	AAPi[14] = 0.05068;
+	AAPi[15] = 0.069577;
+	AAPi[16] = 0.058542;
+	AAPi[17] = 0.010494;
+	AAPi[18] = 0.029916;
+	AAPi[19] = 0.064718;
+
+
+	/*Dayhoff DCMUT Test*/
+	AAmatrixT[0][0] = 0;			AAmatrixT[0][1] = 26.7828;		AAmatrixT[0][2] = 98.4474;		AAmatrixT[0][3] = 119.981;	
+	AAmatrixT[0][4] = 36.0016;		AAmatrixT[0][5] = 88.7753;		AAmatrixT[0][6] = 196.117;		AAmatrixT[0][7] = 238.611;	
+	AAmatrixT[0][8] = 22.8116;		AAmatrixT[0][9] = 65.3416;		AAmatrixT[0][10] = 40.6431;		AAmatrixT[0][11] = 25.8635;	
+	AAmatrixT[0][12] = 71.784;		AAmatrixT[0][13] = 18.3641;		AAmatrixT[0][14] = 248.592;		AAmatrixT[0][15] = 405.187;	
+	AAmatrixT[0][16] = 368.036;		AAmatrixT[0][17] = 0;			AAmatrixT[0][18] = 24.4139;		AAmatrixT[0][19] = 205.956;	
+	AAmatrixT[1][0] = 26.7828;		AAmatrixT[1][1] = 0;			AAmatrixT[1][2] = 32.7059;		AAmatrixT[1][3] = 0;	
+	AAmatrixT[1][4] = 23.2374;		AAmatrixT[1][5] = 243.994;		AAmatrixT[1][6] = 0;			AAmatrixT[1][7] = 8.7791;	
+	AAmatrixT[1][8] = 238.315;		AAmatrixT[1][9] = 63.2629;		AAmatrixT[1][10] = 15.4924;		AAmatrixT[1][11] = 461.012;	
+	AAmatrixT[1][12] = 89.6321;		AAmatrixT[1][13] = 13.6906;		AAmatrixT[1][14] = 102.831;		AAmatrixT[1][15] = 153.159;	
+	AAmatrixT[1][16] = 26.5745;		AAmatrixT[1][17] = 200.137;		AAmatrixT[1][18] = 7.8012;		AAmatrixT[1][19] = 24.0368;	
+	AAmatrixT[2][0] = 98.4474;		AAmatrixT[2][1] = 32.7059;		AAmatrixT[2][2] = 0;			AAmatrixT[2][3] = 893.152;	
+	AAmatrixT[2][4] = 0;			AAmatrixT[2][5] = 102.851;		AAmatrixT[2][6] = 149.341;		AAmatrixT[2][7] = 138.535;	
+	AAmatrixT[2][8] = 529.002;		AAmatrixT[2][9] = 76.8024;		AAmatrixT[2][10] = 34.1113;		AAmatrixT[2][11] = 314.837;	
+	AAmatrixT[2][12] = 0;			AAmatrixT[2][13] = 13.8503;		AAmatrixT[2][14] = 41.9244;		AAmatrixT[2][15] = 488.589;	
+	AAmatrixT[2][16] = 227.17;		AAmatrixT[2][17] = 22.4968;		AAmatrixT[2][18] = 94.694;		AAmatrixT[2][19] = 15.8067;	
+	AAmatrixT[3][0] = 119.981;		AAmatrixT[3][1] = 0;			AAmatrixT[3][2] = 893.152;		AAmatrixT[3][3] = 0;	
+	AAmatrixT[3][4] = 0;			AAmatrixT[3][5] = 134.855;		AAmatrixT[3][6] = 1138.87;		AAmatrixT[3][7] = 124.098;	
+	AAmatrixT[3][8] = 86.8241;		AAmatrixT[3][9] = 23.9248;		AAmatrixT[3][10] = 0;			AAmatrixT[3][11] = 71.6913;	
+	AAmatrixT[3][12] = 0;			AAmatrixT[3][13] = 0;			AAmatrixT[3][14] = 13.394;		AAmatrixT[3][15] = 95.6097;	
+	AAmatrixT[3][16] = 66.093;		AAmatrixT[3][17] = 0;			AAmatrixT[3][18] = 0;			AAmatrixT[3][19] = 17.8316;	
+	AAmatrixT[4][0] = 36.0016;		AAmatrixT[4][1] = 23.2374;		AAmatrixT[4][2] = 0;			AAmatrixT[4][3] = 0;	
+	AAmatrixT[4][4] = 0;			AAmatrixT[4][5] = 0;			AAmatrixT[4][6] = 0;			AAmatrixT[4][7] = 10.7278;	
+	AAmatrixT[4][8] = 28.2729;		AAmatrixT[4][9] = 43.8074;		AAmatrixT[4][10] = 0;			AAmatrixT[4][11] = 0;	
+	AAmatrixT[4][12] = 0;			AAmatrixT[4][13] = 0;			AAmatrixT[4][14] = 18.755;		AAmatrixT[4][15] = 159.836;	
+	AAmatrixT[4][16] = 16.2366;		AAmatrixT[4][17] = 0;			AAmatrixT[4][18] = 95.3164;		AAmatrixT[4][19] = 48.4678;	
+	AAmatrixT[5][0] = 88.7753;		AAmatrixT[5][1] = 243.994;		AAmatrixT[5][2] = 102.851;		AAmatrixT[5][3] = 134.855;	
+	AAmatrixT[5][4] = 0;			AAmatrixT[5][5] = 0;			AAmatrixT[5][6] = 708.602;		AAmatrixT[5][7] = 28.1581;	
+	AAmatrixT[5][8] = 601.161;		AAmatrixT[5][9] = 18.0393;		AAmatrixT[5][10] = 73.0772;		AAmatrixT[5][11] = 151.908;	
+	AAmatrixT[5][12] = 112.75;		AAmatrixT[5][13] = 0;			AAmatrixT[5][14] = 152.619;		AAmatrixT[5][15] = 56.1828;	
+	AAmatrixT[5][16] = 52.5651;		AAmatrixT[5][17] = 0;			AAmatrixT[5][18] = 0;			AAmatrixT[5][19] = 34.6983;	
+	AAmatrixT[6][0] = 196.117;		AAmatrixT[6][1] = 0;			AAmatrixT[6][2] = 149.341;		AAmatrixT[6][3] = 1138.87;	
+	AAmatrixT[6][4] = 0;			AAmatrixT[6][5] = 708.602;		AAmatrixT[6][6] = 0;			AAmatrixT[6][7] = 81.1907;	
+	AAmatrixT[6][8] = 43.9469;		AAmatrixT[6][9] = 60.9526;		AAmatrixT[6][10] = 11.288;		AAmatrixT[6][11] = 83.0078;	
+	AAmatrixT[6][12] = 30.4803;		AAmatrixT[6][13] = 0;			AAmatrixT[6][14] = 50.7003;		AAmatrixT[6][15] = 79.3999;	
+	AAmatrixT[6][16] = 34.0156;		AAmatrixT[6][17] = 0;			AAmatrixT[6][18] = 21.4717;		AAmatrixT[6][19] = 36.725;	
+	AAmatrixT[7][0] = 238.611;		AAmatrixT[7][1] = 8.7791;		AAmatrixT[7][2] = 138.535;		AAmatrixT[7][3] = 124.098;	
+	AAmatrixT[7][4] = 10.7278;		AAmatrixT[7][5] = 28.1581;		AAmatrixT[7][6] = 81.1907;		AAmatrixT[7][7] = 0;	
+	AAmatrixT[7][8] = 10.6802;		AAmatrixT[7][9] = 0;			AAmatrixT[7][10] = 7.1514;		AAmatrixT[7][11] = 26.7683;	
+	AAmatrixT[7][12] = 17.0372;		AAmatrixT[7][13] = 15.3478;		AAmatrixT[7][14] = 34.7153;		AAmatrixT[7][15] = 232.224;	
+	AAmatrixT[7][16] = 30.6662;		AAmatrixT[7][17] = 0;			AAmatrixT[7][18] = 0;			AAmatrixT[7][19] = 53.8165;	
+	AAmatrixT[8][0] = 22.8116;		AAmatrixT[8][1] = 238.315;		AAmatrixT[8][2] = 529.002;		AAmatrixT[8][3] = 86.8241;	
+	AAmatrixT[8][4] = 28.2729;		AAmatrixT[8][5] = 601.161;		AAmatrixT[8][6] = 43.9469;		AAmatrixT[8][7] = 10.6802;	
+	AAmatrixT[8][8] = 0;			AAmatrixT[8][9] = 7.6981;		AAmatrixT[8][10] = 44.3504;		AAmatrixT[8][11] = 27.0475;	
+	AAmatrixT[8][12] = 0;			AAmatrixT[8][13] = 47.5927;		AAmatrixT[8][14] = 93.3709;		AAmatrixT[8][15] = 35.3643;	
+	AAmatrixT[8][16] = 22.6333;		AAmatrixT[8][17] = 27.0564;		AAmatrixT[8][18] = 126.54;		AAmatrixT[8][19] = 43.8715;	
+	AAmatrixT[9][0] = 65.3416;		AAmatrixT[9][1] = 63.2629;		AAmatrixT[9][2] = 76.8024;		AAmatrixT[9][3] = 23.9248;	
+	AAmatrixT[9][4] = 43.8074;		AAmatrixT[9][5] = 18.0393;		AAmatrixT[9][6] = 60.9526;		AAmatrixT[9][7] = 0;	
+	AAmatrixT[9][8] = 7.6981;		AAmatrixT[9][9] = 0;			AAmatrixT[9][10] = 255.668;		AAmatrixT[9][11] = 46.0857;	
+	AAmatrixT[9][12] = 333.273;		AAmatrixT[9][13] = 195.195;		AAmatrixT[9][14] = 11.9152;		AAmatrixT[9][15] = 24.7955;	
+	AAmatrixT[9][16] = 190.074;		AAmatrixT[9][17] = 0;			AAmatrixT[9][18] = 37.4834;		AAmatrixT[9][19] = 881.004;	
+	AAmatrixT[10][0] = 40.6431;		AAmatrixT[10][1] = 15.4924;		AAmatrixT[10][2] = 34.1113;		AAmatrixT[10][3] = 0;	
+	AAmatrixT[10][4] = 0;			AAmatrixT[10][5] = 73.0772;		AAmatrixT[10][6] = 11.288;		AAmatrixT[10][7] = 7.1514;	
+	AAmatrixT[10][8] = 44.3504;		AAmatrixT[10][9] = 255.668;		AAmatrixT[10][10] = 0;			AAmatrixT[10][11] = 18.0629;	
+	AAmatrixT[10][12] = 523.011;	AAmatrixT[10][13] = 156.516;	AAmatrixT[10][14] = 31.6258;	AAmatrixT[10][15] = 17.1432;	
+	AAmatrixT[10][16] = 33.109;		AAmatrixT[10][17] = 46.1776;	AAmatrixT[10][18] = 28.6572;	AAmatrixT[10][19] = 174.516;	
+	AAmatrixT[11][0] = 25.8635;		AAmatrixT[11][1] = 461.012;		AAmatrixT[11][2] = 314.837;		AAmatrixT[11][3] = 71.6913;	
+	AAmatrixT[11][4] = 0;			AAmatrixT[11][5] = 151.908;		AAmatrixT[11][6] = 83.0078;		AAmatrixT[11][7] = 26.7683;	
+	AAmatrixT[11][8] = 27.0475;		AAmatrixT[11][9] = 46.0857;		AAmatrixT[11][10] = 18.0629;	AAmatrixT[11][11] = 0;	
+	AAmatrixT[11][12] = 241.174;	AAmatrixT[11][13] = 0;			AAmatrixT[11][14] = 33.5419;	AAmatrixT[11][15] = 95.4557;	
+	AAmatrixT[11][16] = 135.06;		AAmatrixT[11][17] = 0;			AAmatrixT[11][18] = 13.2142;	AAmatrixT[11][19] = 10.385;	
+	AAmatrixT[12][0] = 71.784;		AAmatrixT[12][1] = 89.6321;		AAmatrixT[12][2] = 0;			AAmatrixT[12][3] = 0;	
+	AAmatrixT[12][4] = 0;			AAmatrixT[12][5] = 112.75;		AAmatrixT[12][6] = 30.4803;		AAmatrixT[12][7] = 17.0372;	
+	AAmatrixT[12][8] = 0;			AAmatrixT[12][9] = 333.273;		AAmatrixT[12][10] = 523.011;	AAmatrixT[12][11] = 241.174;	
+	AAmatrixT[12][12] = 0;			AAmatrixT[12][13] = 92.186;		AAmatrixT[12][14] = 17.0205;	AAmatrixT[12][15] = 61.9951;	
+	AAmatrixT[12][16] = 103.153;	AAmatrixT[12][17] = 0;			AAmatrixT[12][18] = 0;			AAmatrixT[12][19] = 256.596;	
+	AAmatrixT[13][0] = 18.3641;		AAmatrixT[13][1] = 13.6906;		AAmatrixT[13][2] = 13.8503;		AAmatrixT[13][3] = 0;	
+	AAmatrixT[13][4] = 0;			AAmatrixT[13][5] = 0;			AAmatrixT[13][6] = 0;			AAmatrixT[13][7] = 15.3478;	
+	AAmatrixT[13][8] = 47.5927;		AAmatrixT[13][9] = 195.195;		AAmatrixT[13][10] = 156.516;	AAmatrixT[13][11] = 0;	
+	AAmatrixT[13][12] = 92.186;		AAmatrixT[13][13] = 0;			AAmatrixT[13][14] = 11.0506;	AAmatrixT[13][15] = 45.9901;	
+	AAmatrixT[13][16] = 13.6655;	AAmatrixT[13][17] = 76.2354;	AAmatrixT[13][18] = 695.263;	AAmatrixT[13][19] = 12.3606;	
+	AAmatrixT[14][0] = 248.592;		AAmatrixT[14][1] = 102.831;		AAmatrixT[14][2] = 41.9244;		AAmatrixT[14][3] = 13.394;	
+	AAmatrixT[14][4] = 18.755;		AAmatrixT[14][5] = 152.619;		AAmatrixT[14][6] = 50.7003;		AAmatrixT[14][7] = 34.7153;	
+	AAmatrixT[14][8] = 93.3709;		AAmatrixT[14][9] = 11.9152;		AAmatrixT[14][10] = 31.6258;	AAmatrixT[14][11] = 33.5419;	
+	AAmatrixT[14][12] = 17.0205;	AAmatrixT[14][13] = 11.0506;	AAmatrixT[14][14] = 0;			AAmatrixT[14][15] = 242.72;	
+	AAmatrixT[14][16] = 78.2857;	AAmatrixT[14][17] = 0;			AAmatrixT[14][18] = 0;			AAmatrixT[14][19] = 48.5026;	
+	AAmatrixT[15][0] = 405.187;		AAmatrixT[15][1] = 153.159;		AAmatrixT[15][2] = 488.589;		AAmatrixT[15][3] = 95.6097;	
+	AAmatrixT[15][4] = 159.836;		AAmatrixT[15][5] = 56.1828;		AAmatrixT[15][6] = 79.3999;		AAmatrixT[15][7] = 232.224;	
+	AAmatrixT[15][8] = 35.3643;		AAmatrixT[15][9] = 24.7955;		AAmatrixT[15][10] = 17.1432;	AAmatrixT[15][11] = 95.4557;	
+	AAmatrixT[15][12] = 61.9951;	AAmatrixT[15][13] = 45.9901;	AAmatrixT[15][14] = 242.72;		AAmatrixT[15][15] = 0;	
+	AAmatrixT[15][16] = 543.667;	AAmatrixT[15][17] = 74.0819;	AAmatrixT[15][18] = 33.6289;	AAmatrixT[15][19] = 30.3836;	
+	AAmatrixT[16][0] = 368.036;		AAmatrixT[16][1] = 26.5745;		AAmatrixT[16][2] = 227.17;		AAmatrixT[16][3] = 66.093;	
+	AAmatrixT[16][4] = 16.2366;		AAmatrixT[16][5] = 52.5651;		AAmatrixT[16][6] = 34.0156;		AAmatrixT[16][7] = 30.6662;	
+	AAmatrixT[16][8] = 22.6333;		AAmatrixT[16][9] = 190.074;		AAmatrixT[16][10] = 33.109;		AAmatrixT[16][11] = 135.06;	
+	AAmatrixT[16][12] = 103.153;	AAmatrixT[16][13] = 13.6655;	AAmatrixT[16][14] = 78.2857;	AAmatrixT[16][15] = 543.667;	
+	AAmatrixT[16][16] = 0;			AAmatrixT[16][17] = 0;			AAmatrixT[16][18] = 41.7839;	AAmatrixT[16][19] = 156.2;	
+	AAmatrixT[17][0] = 0;			AAmatrixT[17][1] = 200.137;		AAmatrixT[17][2] = 22.4968;		AAmatrixT[17][3] = 0;	
+	AAmatrixT[17][4] = 0;			AAmatrixT[17][5] = 0;			AAmatrixT[17][6] = 0;			AAmatrixT[17][7] = 0;	
+	AAmatrixT[17][8] = 27.0564;		AAmatrixT[17][9] = 0;			AAmatrixT[17][10] = 46.1776;	AAmatrixT[17][11] = 0;	
+	AAmatrixT[17][12] = 0;			AAmatrixT[17][13] = 76.2354;	AAmatrixT[17][14] = 0;			AAmatrixT[17][15] = 74.0819;	
+	AAmatrixT[17][16] = 0;			AAmatrixT[17][17] = 0;			AAmatrixT[17][18] = 60.807;		AAmatrixT[17][19] = 0;	
+	AAmatrixT[18][0] = 24.4139;		AAmatrixT[18][1] = 7.8012;		AAmatrixT[18][2] = 94.694;		AAmatrixT[18][3] = 0;	
+	AAmatrixT[18][4] = 95.3164;		AAmatrixT[18][5] = 0;			AAmatrixT[18][6] = 21.4717;		AAmatrixT[18][7] = 0;	
+	AAmatrixT[18][8] = 126.54;		AAmatrixT[18][9] = 37.4834;		AAmatrixT[18][10] = 28.6572;	AAmatrixT[18][11] = 13.2142;	
+	AAmatrixT[18][12] = 0;			AAmatrixT[18][13] = 695.263;	AAmatrixT[18][14] = 0;			AAmatrixT[18][15] = 33.6289;	
+	AAmatrixT[18][16] = 41.7839;	AAmatrixT[18][17] = 60.807;		AAmatrixT[18][18] = 0;			AAmatrixT[18][19] = 27.9379;	
+	AAmatrixT[19][0] = 205.956;		AAmatrixT[19][1] = 24.0368;		AAmatrixT[19][2] = 15.8067;		AAmatrixT[19][3] = 17.8316;	
+	AAmatrixT[19][4] = 48.4678;		AAmatrixT[19][5] = 34.6983;		AAmatrixT[19][6] = 36.725;		AAmatrixT[19][7] = 53.8165;	
+	AAmatrixT[19][8] = 43.8715;		AAmatrixT[19][9] = 881.004;		AAmatrixT[19][10] = 174.516;	AAmatrixT[19][11] = 10.385;	
+	AAmatrixT[19][12] = 256.596;	AAmatrixT[19][13] = 12.3606;	AAmatrixT[19][14] = 48.5026;	AAmatrixT[19][15] = 30.3836;	
+	AAmatrixT[19][16] = 156.2;		AAmatrixT[19][17] = 0;			AAmatrixT[19][18] = 27.9379;	AAmatrixT[19][19] = 0;	
+
+	AAPiT[0] = 0.087127;
+	AAPiT[1] = 0.040904;
+	AAPiT[2] = 0.040432;
+	AAPiT[3] = 0.046872;
+	AAPiT[4] = 0.033474;
+	AAPiT[5] = 0.038255;
+	AAPiT[6] = 0.04953;
+	AAPiT[7] = 0.088612;
+	AAPiT[8] = 0.033619;
+	AAPiT[9] = 0.036886;
+	AAPiT[10] = 0.085357;
+	AAPiT[11] = 0.080481;
+	AAPiT[12] = 0.014753;
+	AAPiT[13] = 0.039772;
+	AAPiT[14] = 0.05068;
+	AAPiT[15] = 0.069577;
+	AAPiT[16] = 0.058542;
+	AAPiT[17] = 0.010494;
+	AAPiT[18] = 0.029916;
+	AAPiT[19] = 0.064718;
+	
+		for(int gb1=0; gb1<20; gb1++)
+		{
+			if(AAPiT[gb1]!=AAPiT[gb1]) {cout<<"ERROR in base frequency translation check in Jones-DCMUT model"<<endl; gb1--;}
+			
+			for(int gb2=0; gb2<20; gb2++)
+			{
+				if(AAmatrix[gb1][gb2]-AAmatrixT[gb1][gb2]/100>0.0001) {cout<<"ERROR in substitution matrix translation check in Jones-DCMUT model"<<endl; gb2--;}
+			}
+		}
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==5)
+	{
+
+	/* 
+		wag 
+		
+		Whelan, S. and Goldman, N. (2001)  A general empirical model of protein evolution derived from multiple protein families using a 
+		maximum-likelihood approach. Molecular Biology and Evolution 18:691-699
+	*/
+	AAmatrix[ 0][ 0] = 0.0000000; AAmatrix[ 1][ 0] = 0.5515710; AAmatrix[ 2][ 0] = 0.5098480; AAmatrix[ 3][ 0] = 0.7389980; AAmatrix[ 4][ 0] = 1.0270400; 
+	AAmatrix[ 5][ 0] = 0.9085980; AAmatrix[ 6][ 0] = 1.5828500; AAmatrix[ 7][ 0] = 1.4167200; AAmatrix[ 8][ 0] = 0.3169540; AAmatrix[ 9][ 0] = 0.1933350; 
+	AAmatrix[10][ 0] = 0.3979150; AAmatrix[11][ 0] = 0.9062650; AAmatrix[12][ 0] = 0.8934960; AAmatrix[13][ 0] = 0.2104940; AAmatrix[14][ 0] = 1.4385500; 
+	AAmatrix[15][ 0] = 3.3707900; AAmatrix[16][ 0] = 2.1211100; AAmatrix[17][ 0] = 0.1131330; AAmatrix[18][ 0] = 0.2407350; AAmatrix[19][ 0] = 2.0060100;
+	AAmatrix[ 0][ 1] = 0.5515710; AAmatrix[ 1][ 1] = 0.0000000; AAmatrix[ 2][ 1] = 0.6353460; AAmatrix[ 3][ 1] = 0.1473040; AAmatrix[ 4][ 1] = 0.5281910;  
+	AAmatrix[ 5][ 1] = 3.0355000; AAmatrix[ 6][ 1] = 0.4391570; AAmatrix[ 7][ 1] = 0.5846650; AAmatrix[ 8][ 1] = 2.1371500; AAmatrix[ 9][ 1] = 0.1869790;  
+	AAmatrix[10][ 1] = 0.4976710; AAmatrix[11][ 1] = 5.3514200; AAmatrix[12][ 1] = 0.6831620; AAmatrix[13][ 1] = 0.1027110; AAmatrix[14][ 1] = 0.6794890;  
+	AAmatrix[15][ 1] = 1.2241900; AAmatrix[16][ 1] = 0.5544130; AAmatrix[17][ 1] = 1.1639200; AAmatrix[18][ 1] = 0.3815330; AAmatrix[19][ 1] = 0.2518490;
+	AAmatrix[ 0][ 2] = 0.5098480; AAmatrix[ 1][ 2] = 0.6353460; AAmatrix[ 2][ 2] = 0.0000000; AAmatrix[ 3][ 2] = 5.4294200; AAmatrix[ 4][ 2] = 0.2652560;  
+	AAmatrix[ 5][ 2] = 1.5436400; AAmatrix[ 6][ 2] = 0.9471980; AAmatrix[ 7][ 2] = 1.1255600; AAmatrix[ 8][ 2] = 3.9562900; AAmatrix[ 9][ 2] = 0.5542360;  
+	AAmatrix[10][ 2] = 0.1315280; AAmatrix[11][ 2] = 3.0120100; AAmatrix[12][ 2] = 0.1982210; AAmatrix[13][ 2] = 0.0961621; AAmatrix[14][ 2] = 0.1950810;  
+	AAmatrix[15][ 2] = 3.9742300; AAmatrix[16][ 2] = 2.0300600; AAmatrix[17][ 2] = 0.0719167; AAmatrix[18][ 2] = 1.0860000; AAmatrix[19][ 2] = 0.1962460;
+	AAmatrix[ 0][ 3] = 0.7389980; AAmatrix[ 1][ 3] = 0.1473040; AAmatrix[ 2][ 3] = 5.4294200; AAmatrix[ 3][ 3] = 0.0000000; AAmatrix[ 4][ 3] = 0.0302949;  
+	AAmatrix[ 5][ 3] = 0.6167830; AAmatrix[ 6][ 3] = 6.1741600; AAmatrix[ 7][ 3] = 0.8655840; AAmatrix[ 8][ 3] = 0.9306760; AAmatrix[ 9][ 3] = 0.0394370;  
+	AAmatrix[10][ 3] = 0.0848047; AAmatrix[11][ 3] = 0.4798550; AAmatrix[12][ 3] = 0.1037540; AAmatrix[13][ 3] = 0.0467304; AAmatrix[14][ 3] = 0.4239840;  
+	AAmatrix[15][ 3] = 1.0717600; AAmatrix[16][ 3] = 0.3748660; AAmatrix[17][ 3] = 0.1297670; AAmatrix[18][ 3] = 0.3257110; AAmatrix[19][ 3] = 0.1523350;
+	AAmatrix[ 0][ 4] = 1.0270400; AAmatrix[ 1][ 4] = 0.5281910; AAmatrix[ 2][ 4] = 0.2652560; AAmatrix[ 3][ 4] = 0.0302949; AAmatrix[ 4][ 4] = 0.0000000;  
+	AAmatrix[ 5][ 4] = 0.0988179; AAmatrix[ 6][ 4] = 0.0213520; AAmatrix[ 7][ 4] = 0.3066740; AAmatrix[ 8][ 4] = 0.2489720; AAmatrix[ 9][ 4] = 0.1701350;  
+	AAmatrix[10][ 4] = 0.3842870; AAmatrix[11][ 4] = 0.0740339; AAmatrix[12][ 4] = 0.3904820; AAmatrix[13][ 4] = 0.3980200; AAmatrix[14][ 4] = 0.1094040;  
+	AAmatrix[15][ 4] = 1.4076600; AAmatrix[16][ 4] = 0.5129840; AAmatrix[17][ 4] = 0.7170700; AAmatrix[18][ 4] = 0.5438330; AAmatrix[19][ 4] = 1.0021400;
+	AAmatrix[ 0][ 5] = 0.9085980; AAmatrix[ 1][ 5] = 3.0355000; AAmatrix[ 2][ 5] = 1.5436400; AAmatrix[ 3][ 5] = 0.6167830; AAmatrix[ 4][ 5] = 0.0988179;  
+	AAmatrix[ 5][ 5] = 0.0000000; AAmatrix[ 6][ 5] = 5.4694700; AAmatrix[ 7][ 5] = 0.3300520; AAmatrix[ 8][ 5] = 4.2941100; AAmatrix[ 9][ 5] = 0.1139170;  
+	AAmatrix[10][ 5] = 0.8694890; AAmatrix[11][ 5] = 3.8949000; AAmatrix[12][ 5] = 1.5452600; AAmatrix[13][ 5] = 0.0999208; AAmatrix[14][ 5] = 0.9333720;  
+	AAmatrix[15][ 5] = 1.0288700; AAmatrix[16][ 5] = 0.8579280; AAmatrix[17][ 5] = 0.2157370; AAmatrix[18][ 5] = 0.2277100; AAmatrix[19][ 5] = 0.3012810;
+	AAmatrix[ 0][ 6] = 1.5828500; AAmatrix[ 1][ 6] = 0.4391570; AAmatrix[ 2][ 6] = 0.9471980; AAmatrix[ 3][ 6] = 6.1741600; AAmatrix[ 4][ 6] = 0.0213520;  
+	AAmatrix[ 5][ 6] = 5.4694700; AAmatrix[ 6][ 6] = 0.0000000; AAmatrix[ 7][ 6] = 0.5677170; AAmatrix[ 8][ 6] = 0.5700250; AAmatrix[ 9][ 6] = 0.1273950;  
+	AAmatrix[10][ 6] = 0.1542630; AAmatrix[11][ 6] = 2.5844300; AAmatrix[12][ 6] = 0.3151240; AAmatrix[13][ 6] = 0.0811339; AAmatrix[14][ 6] = 0.6823550;  
+	AAmatrix[15][ 6] = 0.7049390; AAmatrix[16][ 6] = 0.8227650; AAmatrix[17][ 6] = 0.1565570; AAmatrix[18][ 6] = 0.1963030; AAmatrix[19][ 6] = 0.5887310;
+	AAmatrix[ 0][ 7] = 1.4167200; AAmatrix[ 1][ 7] = 0.5846650; AAmatrix[ 2][ 7] = 1.1255600; AAmatrix[ 3][ 7] = 0.8655840; AAmatrix[ 4][ 7] = 0.3066740;  
+	AAmatrix[ 5][ 7] = 0.3300520; AAmatrix[ 6][ 7] = 0.5677170; AAmatrix[ 7][ 7] = 0.0000000; AAmatrix[ 8][ 7] = 0.2494100; AAmatrix[ 9][ 7] = 0.0304501;  
+	AAmatrix[10][ 7] = 0.0613037; AAmatrix[11][ 7] = 0.3735580; AAmatrix[12][ 7] = 0.1741000; AAmatrix[13][ 7] = 0.0499310; AAmatrix[14][ 7] = 0.2435700;  
+	AAmatrix[15][ 7] = 1.3418200; AAmatrix[16][ 7] = 0.2258330; AAmatrix[17][ 7] = 0.3369830; AAmatrix[18][ 7] = 0.1036040; AAmatrix[19][ 7] = 0.1872470;
+	AAmatrix[ 0][ 8] = 0.3169540; AAmatrix[ 1][ 8] = 2.1371500; AAmatrix[ 2][ 8] = 3.9562900; AAmatrix[ 3][ 8] = 0.9306760; AAmatrix[ 4][ 8] = 0.2489720;  
+	AAmatrix[ 5][ 8] = 4.2941100; AAmatrix[ 6][ 8] = 0.5700250; AAmatrix[ 7][ 8] = 0.2494100; AAmatrix[ 8][ 8] = 0.0000000; AAmatrix[ 9][ 8] = 0.1381900;  
+	AAmatrix[10][ 8] = 0.4994620; AAmatrix[11][ 8] = 0.8904320; AAmatrix[12][ 8] = 0.4041410; AAmatrix[13][ 8] = 0.6793710; AAmatrix[14][ 8] = 0.6961980;  
+	AAmatrix[15][ 8] = 0.7401690; AAmatrix[16][ 8] = 0.4733070; AAmatrix[17][ 8] = 0.2625690; AAmatrix[18][ 8] = 3.8734400; AAmatrix[19][ 8] = 0.1183580;
+	AAmatrix[ 0][ 9] = 0.1933350; AAmatrix[ 1][ 9] = 0.1869790; AAmatrix[ 2][ 9] = 0.5542360; AAmatrix[ 3][ 9] = 0.0394370; AAmatrix[ 4][ 9] = 0.1701350;  
+	AAmatrix[ 5][ 9] = 0.1139170; AAmatrix[ 6][ 9] = 0.1273950; AAmatrix[ 7][ 9] = 0.0304501; AAmatrix[ 8][ 9] = 0.1381900; AAmatrix[ 9][ 9] = 0.0000000;  
+	AAmatrix[10][ 9] = 3.1709700; AAmatrix[11][ 9] = 0.3238320; AAmatrix[12][ 9] = 4.2574600; AAmatrix[13][ 9] = 1.0594700; AAmatrix[14][ 9] = 0.0999288;  
+	AAmatrix[15][ 9] = 0.3194400; AAmatrix[16][ 9] = 1.4581600; AAmatrix[17][ 9] = 0.2124830; AAmatrix[18][ 9] = 0.4201700; AAmatrix[19][ 9] = 7.8213000;
+	AAmatrix[ 0][10] = 0.3979150; AAmatrix[ 1][10] = 0.4976710; AAmatrix[ 2][10] = 0.1315280; AAmatrix[ 3][10] = 0.0848047; AAmatrix[ 4][10] = 0.3842870;  
+	AAmatrix[ 5][10] = 0.8694890; AAmatrix[ 6][10] = 0.1542630; AAmatrix[ 7][10] = 0.0613037; AAmatrix[ 8][10] = 0.4994620; AAmatrix[ 9][10] = 3.1709700;  
+	AAmatrix[10][10] = 0.0000000; AAmatrix[11][10] = 0.2575550; AAmatrix[12][10] = 4.8540200; AAmatrix[13][10] = 2.1151700; AAmatrix[14][10] = 0.4158440;  
+	AAmatrix[15][10] = 0.3447390; AAmatrix[16][10] = 0.3266220; AAmatrix[17][10] = 0.6653090; AAmatrix[18][10] = 0.3986180; AAmatrix[19][10] = 1.8003400;
+	AAmatrix[ 0][11] = 0.9062650; AAmatrix[ 1][11] = 5.3514200; AAmatrix[ 2][11] = 3.0120100; AAmatrix[ 3][11] = 0.4798550; AAmatrix[ 4][11] = 0.0740339;  
+	AAmatrix[ 5][11] = 3.8949000; AAmatrix[ 6][11] = 2.5844300; AAmatrix[ 7][11] = 0.3735580; AAmatrix[ 8][11] = 0.8904320; AAmatrix[ 9][11] = 0.3238320;  
+	AAmatrix[10][11] = 0.2575550; AAmatrix[11][11] = 0.0000000; AAmatrix[12][11] = 0.9342760; AAmatrix[13][11] = 0.0888360; AAmatrix[14][11] = 0.5568960;  
+	AAmatrix[15][11] = 0.9671300; AAmatrix[16][11] = 1.3869800; AAmatrix[17][11] = 0.1375050; AAmatrix[18][11] = 0.1332640; AAmatrix[19][11] = 0.3054340;
+	AAmatrix[ 0][12] = 0.8934960; AAmatrix[ 1][12] = 0.6831620; AAmatrix[ 2][12] = 0.1982210; AAmatrix[ 3][12] = 0.1037540; AAmatrix[ 4][12] = 0.3904820;  
+	AAmatrix[ 5][12] = 1.5452600; AAmatrix[ 6][12] = 0.3151240; AAmatrix[ 7][12] = 0.1741000; AAmatrix[ 8][12] = 0.4041410; AAmatrix[ 9][12] = 4.2574600;  
+	AAmatrix[10][12] = 4.8540200; AAmatrix[11][12] = 0.9342760; AAmatrix[12][12] = 0.0000000; AAmatrix[13][12] = 1.1906300; AAmatrix[14][12] = 0.1713290;  
+	AAmatrix[15][12] = 0.4939050; AAmatrix[16][12] = 1.5161200; AAmatrix[17][12] = 0.5157060; AAmatrix[18][12] = 0.4284370; AAmatrix[19][12] = 2.0584500;
+	AAmatrix[ 0][13] = 0.2104940; AAmatrix[ 1][13] = 0.1027110; AAmatrix[ 2][13] = 0.0961621; AAmatrix[ 3][13] = 0.0467304; AAmatrix[ 4][13] = 0.3980200;  
+	AAmatrix[ 5][13] = 0.0999208; AAmatrix[ 6][13] = 0.0811339; AAmatrix[ 7][13] = 0.0499310; AAmatrix[ 8][13] = 0.6793710; AAmatrix[ 9][13] = 1.0594700;  
+	AAmatrix[10][13] = 2.1151700; AAmatrix[11][13] = 0.0888360; AAmatrix[12][13] = 1.1906300; AAmatrix[13][13] = 0.0000000; AAmatrix[14][13] = 0.1614440;  
+	AAmatrix[15][13] = 0.5459310; AAmatrix[16][13] = 0.1719030; AAmatrix[17][13] = 1.5296400; AAmatrix[18][13] = 6.4542800; AAmatrix[19][13] = 0.6498920;
+	AAmatrix[ 0][14] = 1.4385500; AAmatrix[ 1][14] = 0.6794890; AAmatrix[ 2][14] = 0.1950810; AAmatrix[ 3][14] = 0.4239840; AAmatrix[ 4][14] = 0.1094040;  
+	AAmatrix[ 5][14] = 0.9333720; AAmatrix[ 6][14] = 0.6823550; AAmatrix[ 7][14] = 0.2435700; AAmatrix[ 8][14] = 0.6961980; AAmatrix[ 9][14] = 0.0999288;  
+	AAmatrix[10][14] = 0.4158440; AAmatrix[11][14] = 0.5568960; AAmatrix[12][14] = 0.1713290; AAmatrix[13][14] = 0.1614440; AAmatrix[14][14] = 0.0000000;  
+	AAmatrix[15][14] = 1.6132800; AAmatrix[16][14] = 0.7953840; AAmatrix[17][14] = 0.1394050; AAmatrix[18][14] = 0.2160460; AAmatrix[19][14] = 0.3148870;
+	AAmatrix[ 0][15] = 3.3707900; AAmatrix[ 1][15] = 1.2241900; AAmatrix[ 2][15] = 3.9742300; AAmatrix[ 3][15] = 1.0717600; AAmatrix[ 4][15] = 1.4076600;  
+	AAmatrix[ 5][15] = 1.0288700; AAmatrix[ 6][15] = 0.7049390; AAmatrix[ 7][15] = 1.3418200; AAmatrix[ 8][15] = 0.7401690; AAmatrix[ 9][15] = 0.3194400;  
+	AAmatrix[10][15] = 0.3447390; AAmatrix[11][15] = 0.9671300; AAmatrix[12][15] = 0.4939050; AAmatrix[13][15] = 0.5459310; AAmatrix[14][15] = 1.6132800;  
+	AAmatrix[15][15] = 0.0000000; AAmatrix[16][15] = 4.3780200; AAmatrix[17][15] = 0.5237420; AAmatrix[18][15] = 0.7869930; AAmatrix[19][15] = 0.2327390;
+	AAmatrix[ 0][16] = 2.1211100; AAmatrix[ 1][16] = 0.5544130; AAmatrix[ 2][16] = 2.0300600; AAmatrix[ 3][16] = 0.3748660; AAmatrix[ 4][16] = 0.5129840;  
+	AAmatrix[ 5][16] = 0.8579280; AAmatrix[ 6][16] = 0.8227650; AAmatrix[ 7][16] = 0.2258330; AAmatrix[ 8][16] = 0.4733070; AAmatrix[ 9][16] = 1.4581600;  
+	AAmatrix[10][16] = 0.3266220; AAmatrix[11][16] = 1.3869800; AAmatrix[12][16] = 1.5161200; AAmatrix[13][16] = 0.1719030; AAmatrix[14][16] = 0.7953840;  
+	AAmatrix[15][16] = 4.3780200; AAmatrix[16][16] = 0.0000000; AAmatrix[17][16] = 0.1108640; AAmatrix[18][16] = 0.2911480; AAmatrix[19][16] = 1.3882300;
+	AAmatrix[ 0][17] = 0.1131330; AAmatrix[ 1][17] = 1.1639200; AAmatrix[ 2][17] = 0.0719167; AAmatrix[ 3][17] = 0.1297670; AAmatrix[ 4][17] = 0.7170700;  
+	AAmatrix[ 5][17] = 0.2157370; AAmatrix[ 6][17] = 0.1565570; AAmatrix[ 7][17] = 0.3369830; AAmatrix[ 8][17] = 0.2625690; AAmatrix[ 9][17] = 0.2124830;  
+	AAmatrix[10][17] = 0.6653090; AAmatrix[11][17] = 0.1375050; AAmatrix[12][17] = 0.5157060; AAmatrix[13][17] = 1.5296400; AAmatrix[14][17] = 0.1394050;  
+	AAmatrix[15][17] = 0.5237420; AAmatrix[16][17] = 0.1108640; AAmatrix[17][17] = 0.0000000; AAmatrix[18][17] = 2.4853900; AAmatrix[19][17] = 0.3653690;
+	AAmatrix[ 0][18] = 0.2407350; AAmatrix[ 1][18] = 0.3815330; AAmatrix[ 2][18] = 1.0860000; AAmatrix[ 3][18] = 0.3257110; AAmatrix[ 4][18] = 0.5438330;  
+	AAmatrix[ 5][18] = 0.2277100; AAmatrix[ 6][18] = 0.1963030; AAmatrix[ 7][18] = 0.1036040; AAmatrix[ 8][18] = 3.8734400; AAmatrix[ 9][18] = 0.4201700;  
+	AAmatrix[10][18] = 0.3986180; AAmatrix[11][18] = 0.1332640; AAmatrix[12][18] = 0.4284370; AAmatrix[13][18] = 6.4542800; AAmatrix[14][18] = 0.2160460;  
+	AAmatrix[15][18] = 0.7869930; AAmatrix[16][18] = 0.2911480; AAmatrix[17][18] = 2.4853900; AAmatrix[18][18] = 0.0000000; AAmatrix[19][18] = 0.3147300;
+	AAmatrix[ 0][19] = 2.0060100; AAmatrix[ 1][19] = 0.2518490; AAmatrix[ 2][19] = 0.1962460; AAmatrix[ 3][19] = 0.1523350; AAmatrix[ 4][19] = 1.0021400;  
+	AAmatrix[ 5][19] = 0.3012810; AAmatrix[ 6][19] = 0.5887310; AAmatrix[ 7][19] = 0.1872470; AAmatrix[ 8][19] = 0.1183580; AAmatrix[ 9][19] = 7.8213000;  
+	AAmatrix[10][19] = 1.8003400; AAmatrix[11][19] = 0.3054340; AAmatrix[12][19] = 2.0584500; AAmatrix[13][19] = 0.6498920; AAmatrix[14][19] = 0.3148870;  
+	AAmatrix[15][19] = 0.2327390; AAmatrix[16][19] = 1.3882300; AAmatrix[17][19] = 0.3653690; AAmatrix[18][19] = 0.3147300; AAmatrix[19][19] = 0.0000000;
+	AAPi[ 0] = 0.08662790;
+	AAPi[ 1] = 0.04397200;
+	AAPi[ 2] = 0.03908940;
+	AAPi[ 3] = 0.05704510;
+	AAPi[ 4] = 0.01930780;
+	AAPi[ 5] = 0.03672810;
+	AAPi[ 6] = 0.05805890;
+	AAPi[ 7] = 0.08325180;
+	AAPi[ 8] = 0.02443130;
+	AAPi[ 9] = 0.04846600;
+	AAPi[10] = 0.08620970;
+	AAPi[11] = 0.06202860;
+	AAPi[12] = 0.01950273;
+	AAPi[13] = 0.03843190;
+	AAPi[14] = 0.04576310;
+	AAPi[15] = 0.06951790;
+	AAPi[16] = 0.06101270;
+	AAPi[17] = 0.01438590;
+	AAPi[18] = 0.03527420;
+	AAPi[19] = 0.07089560;
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==6)
+	{
+
+	/* 
+		mtmam 
+		
+		Yang, Z., Nielsen, R. and Hasegawa, M. (1998) Models of amino acid substitution and applications to Mitochondrial 
+		protein evolution, Molecular Biology and Evolution 15:1600-1611.
+	*/
+	AAmatrix[ 0][ 0] =   0; AAmatrix[ 0][ 1] =  32; AAmatrix[ 0][ 2] =   2; AAmatrix[ 0][ 3] =  11; AAmatrix[ 0][ 4] =   0;
+	AAmatrix[ 0][ 5] =   0; AAmatrix[ 0][ 6] =   0; AAmatrix[ 0][ 7] =  78; AAmatrix[ 0][ 8] =   8; AAmatrix[ 0][ 9] =  75;
+	AAmatrix[ 0][10] =  21; AAmatrix[ 0][11] =   0; AAmatrix[ 0][12] =  76; AAmatrix[ 0][13] =   0; AAmatrix[ 0][14] =  53;
+	AAmatrix[ 0][15] = 342; AAmatrix[ 0][16] = 681; AAmatrix[ 0][17] =   5; AAmatrix[ 0][18] =   0; AAmatrix[ 0][19] = 398;
+	AAmatrix[ 1][ 0] =  32; AAmatrix[ 1][ 1] =   0; AAmatrix[ 1][ 2] =   4; AAmatrix[ 1][ 3] =   0; AAmatrix[ 1][ 4] = 186;
+	AAmatrix[ 1][ 5] = 246; AAmatrix[ 1][ 6] =   0; AAmatrix[ 1][ 7] =  18; AAmatrix[ 1][ 8] = 232; AAmatrix[ 1][ 9] =   0;
+	AAmatrix[ 1][10] =   6; AAmatrix[ 1][11] =  50; AAmatrix[ 1][12] =   0; AAmatrix[ 1][13] =   0; AAmatrix[ 1][14] =   9;
+	AAmatrix[ 1][15] =   3; AAmatrix[ 1][16] =   0; AAmatrix[ 1][17] =  16; AAmatrix[ 1][18] =   0; AAmatrix[ 1][19] =   0;
+	AAmatrix[ 2][ 0] =   2; AAmatrix[ 2][ 1] =   4; AAmatrix[ 2][ 2] =   0; AAmatrix[ 2][ 3] = 864; AAmatrix[ 2][ 4] =   0;
+	AAmatrix[ 2][ 5] =   8; AAmatrix[ 2][ 6] =   0; AAmatrix[ 2][ 7] =  47; AAmatrix[ 2][ 8] = 458; AAmatrix[ 2][ 9] =  19;
+	AAmatrix[ 2][10] =   0; AAmatrix[ 2][11] = 408; AAmatrix[ 2][12] =  21; AAmatrix[ 2][13] =   6; AAmatrix[ 2][14] =  33;
+	AAmatrix[ 2][15] = 446; AAmatrix[ 2][16] = 110; AAmatrix[ 2][17] =   6; AAmatrix[ 2][18] = 156; AAmatrix[ 2][19] =   0;
+	AAmatrix[ 3][ 0] =  11; AAmatrix[ 3][ 1] =   0; AAmatrix[ 3][ 2] = 864; AAmatrix[ 3][ 3] =   0; AAmatrix[ 3][ 4] =   0;
+	AAmatrix[ 3][ 5] =  49; AAmatrix[ 3][ 6] = 569; AAmatrix[ 3][ 7] =  79; AAmatrix[ 3][ 8] =  11; AAmatrix[ 3][ 9] =   0;
+	AAmatrix[ 3][10] =   0; AAmatrix[ 3][11] =   0; AAmatrix[ 3][12] =   0; AAmatrix[ 3][13] =   5; AAmatrix[ 3][14] =   2;
+	AAmatrix[ 3][15] =  16; AAmatrix[ 3][16] =   0; AAmatrix[ 3][17] =   0; AAmatrix[ 3][18] =   0; AAmatrix[ 3][19] =  10;
+	AAmatrix[ 4][ 0] =   0; AAmatrix[ 4][ 1] = 186; AAmatrix[ 4][ 2] =   0; AAmatrix[ 4][ 3] =   0; AAmatrix[ 4][ 4] =   0;
+	AAmatrix[ 4][ 5] =   0; AAmatrix[ 4][ 6] =   0; AAmatrix[ 4][ 7] =   0; AAmatrix[ 4][ 8] = 305; AAmatrix[ 4][ 9] =  41;
+	AAmatrix[ 4][10] =  27; AAmatrix[ 4][11] =   0; AAmatrix[ 4][12] =   0; AAmatrix[ 4][13] =   7; AAmatrix[ 4][14] =   0;
+	AAmatrix[ 4][15] = 347; AAmatrix[ 4][16] = 114; AAmatrix[ 4][17] =  65; AAmatrix[ 4][18] = 530; AAmatrix[ 4][19] =   0;
+	AAmatrix[ 5][ 0] =   0; AAmatrix[ 5][ 1] = 246; AAmatrix[ 5][ 2] =   8; AAmatrix[ 5][ 3] =  49; AAmatrix[ 5][ 4] =   0;
+	AAmatrix[ 5][ 5] =   0; AAmatrix[ 5][ 6] = 274; AAmatrix[ 5][ 7] =   0; AAmatrix[ 5][ 8] = 550; AAmatrix[ 5][ 9] =   0;
+	AAmatrix[ 5][10] =  20; AAmatrix[ 5][11] = 242; AAmatrix[ 5][12] =  22; AAmatrix[ 5][13] =   0; AAmatrix[ 5][14] =  51;
+	AAmatrix[ 5][15] =  30; AAmatrix[ 5][16] =   0; AAmatrix[ 5][17] =   0; AAmatrix[ 5][18] =  54; AAmatrix[ 5][19] =  33;
+	AAmatrix[ 6][ 0] =   0; AAmatrix[ 6][ 1] =   0; AAmatrix[ 6][ 2] =   0; AAmatrix[ 6][ 3] = 569; AAmatrix[ 6][ 4] =   0;
+	AAmatrix[ 6][ 5] = 274; AAmatrix[ 6][ 6] =   0; AAmatrix[ 6][ 7] =  22; AAmatrix[ 6][ 8] =  22; AAmatrix[ 6][ 9] =   0;
+	AAmatrix[ 6][10] =   0; AAmatrix[ 6][11] = 215; AAmatrix[ 6][12] =   0; AAmatrix[ 6][13] =   0; AAmatrix[ 6][14] =   0;
+	AAmatrix[ 6][15] =  21; AAmatrix[ 6][16] =   4; AAmatrix[ 6][17] =   0; AAmatrix[ 6][18] =   0; AAmatrix[ 6][19] =  20;
+	AAmatrix[ 7][ 0] =  78; AAmatrix[ 7][ 1] =  18; AAmatrix[ 7][ 2] =  47; AAmatrix[ 7][ 3] =  79; AAmatrix[ 7][ 4] =   0;
+	AAmatrix[ 7][ 5] =   0; AAmatrix[ 7][ 6] =  22; AAmatrix[ 7][ 7] =   0; AAmatrix[ 7][ 8] =   0; AAmatrix[ 7][ 9] =   0;
+	AAmatrix[ 7][10] =   0; AAmatrix[ 7][11] =   0; AAmatrix[ 7][12] =   0; AAmatrix[ 7][13] =   0; AAmatrix[ 7][14] =   0;
+	AAmatrix[ 7][15] = 112; AAmatrix[ 7][16] =   0; AAmatrix[ 7][17] =   0; AAmatrix[ 7][18] =   1; AAmatrix[ 7][19] =   5;
+	AAmatrix[ 8][ 0] =   8; AAmatrix[ 8][ 1] = 232; AAmatrix[ 8][ 2] = 458; AAmatrix[ 8][ 3] =  11; AAmatrix[ 8][ 4] = 305;
+	AAmatrix[ 8][ 5] = 550; AAmatrix[ 8][ 6] =  22; AAmatrix[ 8][ 7] =   0; AAmatrix[ 8][ 8] =   0; AAmatrix[ 8][ 9] =   0;
+	AAmatrix[ 8][10] =  26; AAmatrix[ 8][11] =   0; AAmatrix[ 8][12] =   0; AAmatrix[ 8][13] =   0; AAmatrix[ 8][14] =  53;
+	AAmatrix[ 8][15] =  20; AAmatrix[ 8][16] =   1; AAmatrix[ 8][17] =   0; AAmatrix[ 8][18] =1525; AAmatrix[ 8][19] =   0;
+	AAmatrix[ 9][ 0] =  75; AAmatrix[ 9][ 1] =   0; AAmatrix[ 9][ 2] =  19; AAmatrix[ 9][ 3] =   0; AAmatrix[ 9][ 4] =  41;
+	AAmatrix[ 9][ 5] =   0; AAmatrix[ 9][ 6] =   0; AAmatrix[ 9][ 7] =   0; AAmatrix[ 9][ 8] =   0; AAmatrix[ 9][ 9] =   0;
+	AAmatrix[ 9][10] = 232; AAmatrix[ 9][11] =   6; AAmatrix[ 9][12] = 378; AAmatrix[ 9][13] =  57; AAmatrix[ 9][14] =   5;
+	AAmatrix[ 9][15] =   0; AAmatrix[ 9][16] = 360; AAmatrix[ 9][17] =   0; AAmatrix[ 9][18] =  16; AAmatrix[ 9][19] =2220;
+	AAmatrix[10][ 0] =  21; AAmatrix[10][ 1] =   6; AAmatrix[10][ 2] =   0; AAmatrix[10][ 3] =   0; AAmatrix[10][ 4] =  27;
+	AAmatrix[10][ 5] =  20; AAmatrix[10][ 6] =   0; AAmatrix[10][ 7] =   0; AAmatrix[10][ 8] =  26; AAmatrix[10][ 9] = 232;
+	AAmatrix[10][10] =   0; AAmatrix[10][11] =   4; AAmatrix[10][12] = 609; AAmatrix[10][13] = 246; AAmatrix[10][14] =  43;
+	AAmatrix[10][15] =  74; AAmatrix[10][16] =  34; AAmatrix[10][17] =  12; AAmatrix[10][18] =  25; AAmatrix[10][19] = 100;
+	AAmatrix[11][ 0] =   0; AAmatrix[11][ 1] =  50; AAmatrix[11][ 2] = 408; AAmatrix[11][ 3] =   0; AAmatrix[11][ 4] =   0;
+	AAmatrix[11][ 5] = 242; AAmatrix[11][ 6] = 215; AAmatrix[11][ 7] =   0; AAmatrix[11][ 8] =   0; AAmatrix[11][ 9] =   6;
+	AAmatrix[11][10] =   4; AAmatrix[11][11] =   0; AAmatrix[11][12] =  59; AAmatrix[11][13] =   0; AAmatrix[11][14] =  18;
+	AAmatrix[11][15] =  65; AAmatrix[11][16] =  50; AAmatrix[11][17] =   0; AAmatrix[11][18] =  67; AAmatrix[11][19] =   0;
+	AAmatrix[12][ 0] =  76; AAmatrix[12][ 1] =   0; AAmatrix[12][ 2] =  21; AAmatrix[12][ 3] =   0; AAmatrix[12][ 4] =   0;
+	AAmatrix[12][ 5] =  22; AAmatrix[12][ 6] =   0; AAmatrix[12][ 7] =   0; AAmatrix[12][ 8] =   0; AAmatrix[12][ 9] = 378;
+	AAmatrix[12][10] = 609; AAmatrix[12][11] =  59; AAmatrix[12][12] =   0; AAmatrix[12][13] =  11; AAmatrix[12][14] =   0;
+	AAmatrix[12][15] =  47; AAmatrix[12][16] = 691; AAmatrix[12][17] =  13; AAmatrix[12][18] =   0; AAmatrix[12][19] = 832;
+	AAmatrix[13][ 0] =   0; AAmatrix[13][ 1] =   0; AAmatrix[13][ 2] =   6; AAmatrix[13][ 3] =   5; AAmatrix[13][ 4] =   7;
+	AAmatrix[13][ 5] =   0; AAmatrix[13][ 6] =   0; AAmatrix[13][ 7] =   0; AAmatrix[13][ 8] =   0; AAmatrix[13][ 9] =  57;
+	AAmatrix[13][10] = 246; AAmatrix[13][11] =   0; AAmatrix[13][12] =  11; AAmatrix[13][13] =   0; AAmatrix[13][14] =  17;
+	AAmatrix[13][15] =  90; AAmatrix[13][16] =   8; AAmatrix[13][17] =   0; AAmatrix[13][18] = 682; AAmatrix[13][19] =   6;
+	AAmatrix[14][ 0] =  53; AAmatrix[14][ 1] =   9; AAmatrix[14][ 2] =  33; AAmatrix[14][ 3] =   2; AAmatrix[14][ 4] =   0;
+	AAmatrix[14][ 5] =  51; AAmatrix[14][ 6] =   0; AAmatrix[14][ 7] =   0; AAmatrix[14][ 8] =  53; AAmatrix[14][ 9] =   5;
+	AAmatrix[14][10] =  43; AAmatrix[14][11] =  18; AAmatrix[14][12] =   0; AAmatrix[14][13] =  17; AAmatrix[14][14] =   0;
+	AAmatrix[14][15] = 202; AAmatrix[14][16] =  78; AAmatrix[14][17] =   7; AAmatrix[14][18] =   8; AAmatrix[14][19] =   0;
+	AAmatrix[15][ 0] = 342; AAmatrix[15][ 1] =   3; AAmatrix[15][ 2] = 446; AAmatrix[15][ 3] =  16; AAmatrix[15][ 4] = 347;
+	AAmatrix[15][ 5] =  30; AAmatrix[15][ 6] =  21; AAmatrix[15][ 7] = 112; AAmatrix[15][ 8] =  20; AAmatrix[15][ 9] =   0;
+	AAmatrix[15][10] =  74; AAmatrix[15][11] =  65; AAmatrix[15][12] =  47; AAmatrix[15][13] =  90; AAmatrix[15][14] = 202;
+	AAmatrix[15][15] =   0; AAmatrix[15][16] = 614; AAmatrix[15][17] =  17; AAmatrix[15][18] = 107; AAmatrix[15][19] =   0;
+	AAmatrix[16][ 0] = 681; AAmatrix[16][ 1] =   0; AAmatrix[16][ 2] = 110; AAmatrix[16][ 3] =   0; AAmatrix[16][ 4] = 114;
+	AAmatrix[16][ 5] =   0; AAmatrix[16][ 6] =   4; AAmatrix[16][ 7] =   0; AAmatrix[16][ 8] =   1; AAmatrix[16][ 9] = 360;
+	AAmatrix[16][10] =  34; AAmatrix[16][11] =  50; AAmatrix[16][12] = 691; AAmatrix[16][13] =   8; AAmatrix[16][14] =  78;
+	AAmatrix[16][15] = 614; AAmatrix[16][16] =   0; AAmatrix[16][17] =   0; AAmatrix[16][18] =   0; AAmatrix[16][19] = 237;
+	AAmatrix[17][ 0] =   5; AAmatrix[17][ 1] =  16; AAmatrix[17][ 2] =   6; AAmatrix[17][ 3] =   0; AAmatrix[17][ 4] =  65;
+	AAmatrix[17][ 5] =   0; AAmatrix[17][ 6] =   0; AAmatrix[17][ 7] =   0; AAmatrix[17][ 8] =   0; AAmatrix[17][ 9] =   0;
+	AAmatrix[17][10] =  12; AAmatrix[17][11] =   0; AAmatrix[17][12] =  13; AAmatrix[17][13] =   0; AAmatrix[17][14] =   7;
+	AAmatrix[17][15] =  17; AAmatrix[17][16] =   0; AAmatrix[17][17] =   0; AAmatrix[17][18] =  14; AAmatrix[17][19] =   0;
+	AAmatrix[18][ 0] =   0; AAmatrix[18][ 1] =   0; AAmatrix[18][ 2] = 156; AAmatrix[18][ 3] =   0; AAmatrix[18][ 4] = 530;
+	AAmatrix[18][ 5] =  54; AAmatrix[18][ 6] =   0; AAmatrix[18][ 7] =   1; AAmatrix[18][ 8] =1525; AAmatrix[18][ 9] =  16;
+	AAmatrix[18][10] =  25; AAmatrix[18][11] =  67; AAmatrix[18][12] =   0; AAmatrix[18][13] = 682; AAmatrix[18][14] =   8;
+	AAmatrix[18][15] = 107; AAmatrix[18][16] =   0; AAmatrix[18][17] =  14; AAmatrix[18][18] =   0; AAmatrix[18][19] =   0;
+	AAmatrix[19][ 0] = 398; AAmatrix[19][ 1] =   0; AAmatrix[19][ 2] =   0; AAmatrix[19][ 3] =  10; AAmatrix[19][ 4] =   0;
+	AAmatrix[19][ 5] =  33; AAmatrix[19][ 6] =  20; AAmatrix[19][ 7] =   5; AAmatrix[19][ 8] =   0; AAmatrix[19][ 9] =2220;
+	AAmatrix[19][10] = 100; AAmatrix[19][11] =   0; AAmatrix[19][12] = 832; AAmatrix[19][13] =   6; AAmatrix[19][14] =   0;
+	AAmatrix[19][15] =   0; AAmatrix[19][16] = 237; AAmatrix[19][17] =   0; AAmatrix[19][18] =   0; AAmatrix[19][19] =   0;
+
+	AAPi[ 0] = 0.0692;
+	AAPi[ 1] = 0.0184;
+	AAPi[ 2] = 0.0400;
+	AAPi[ 3] = 0.0186;
+	AAPi[ 4] = 0.0065;
+	AAPi[ 5] = 0.0238;
+	AAPi[ 6] = 0.0236;
+	AAPi[ 7] = 0.0557;
+	AAPi[ 8] = 0.0277;
+	AAPi[ 9] = 0.0905;
+	AAPi[10] = 0.1675;
+	AAPi[11] = 0.0221;
+	AAPi[12] = 0.0561;
+	AAPi[13] = 0.0611;
+	AAPi[14] = 0.0536;
+	AAPi[15] = 0.0725;
+	AAPi[16] = 0.0870;
+	AAPi[17] = 0.0293;
+	AAPi[18] = 0.0340;
+	AAPi[19] = 0.0428;
+	
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==7)
+	{
+
+	/*
+		Mtart
+		
+		Abascal, F., D. Posada, and R. Zardoya. (2007) MtArt: A new Model of amino acid replacement for Arthropoda. Mol. Biol. Evol. 24:1-5. 
+	*/
+	AAmatrix[0][0] = 0;			AAmatrix[0][1] = 0.2;		AAmatrix[0][2] = 0.2;		AAmatrix[0][3] = 0.6;	
+	AAmatrix[0][4] = 253.5;		AAmatrix[0][5] = 0.2;		AAmatrix[0][6] = 0.2;		AAmatrix[0][7] = 199.8;	
+	AAmatrix[0][8] = 0.2;		AAmatrix[0][9] = 25.7;		AAmatrix[0][10] = 3.7;		AAmatrix[0][11] = 0.2;	
+	AAmatrix[0][12] = 120.6;	AAmatrix[0][13] = 13.1;		AAmatrix[0][14] = 49.3;		AAmatrix[0][15] = 673;	
+	AAmatrix[0][16] = 243.9;	AAmatrix[0][17] = 0.2;		AAmatrix[0][18] = 1.2;		AAmatrix[0][19] = 339.9;	
+	AAmatrix[1][0] = 0.2;		AAmatrix[1][1] = 0;			AAmatrix[1][2] = 0.2;		AAmatrix[1][3] = 4.3;	
+	AAmatrix[1][4] = 35.5;		AAmatrix[1][5] = 154;		AAmatrix[1][6] = 0.2;		AAmatrix[1][7] = 0.2;	
+	AAmatrix[1][8] = 41.3;		AAmatrix[1][9] = 1.8;		AAmatrix[1][10] = 1.8;		AAmatrix[1][11] = 208.6;	
+	AAmatrix[1][12] = 5.2;		AAmatrix[1][13] = 4.7;		AAmatrix[1][14] = 0.2;		AAmatrix[1][15] = 2.7;	
+	AAmatrix[1][16] = 0.2;		AAmatrix[1][17] = 0.2;		AAmatrix[1][18] = 3.9;		AAmatrix[1][19] = 0.2;	
+	AAmatrix[2][0] = 0.2;		AAmatrix[2][1] = 0.2;		AAmatrix[2][2] = 0;			AAmatrix[2][3] = 500.2;	
+	AAmatrix[2][4] = 98.2;		AAmatrix[2][5] = 261.8;		AAmatrix[2][6] = 183;		AAmatrix[2][7] = 120.5;	
+	AAmatrix[2][8] = 179.5;		AAmatrix[2][9] = 21.3;		AAmatrix[2][10] = 12.6;		AAmatrix[2][11] = 467.3;	
+	AAmatrix[2][12] = 78.8;		AAmatrix[2][13] = 19.7;		AAmatrix[2][14] = 16.5;		AAmatrix[2][15] = 398.4;	
+	AAmatrix[2][16] = 165.9;	AAmatrix[2][17] = 7.7;		AAmatrix[2][18] = 251.2;	AAmatrix[2][19] = 22.6;	
+	AAmatrix[3][0] = 0.6;		AAmatrix[3][1] = 4.3;		AAmatrix[3][2] = 500.2;		AAmatrix[3][3] = 0;	
+	AAmatrix[3][4] = 10.6;		AAmatrix[3][5] = 0.2;		AAmatrix[3][6] = 861.8;		AAmatrix[3][7] = 12.5;	
+	AAmatrix[3][8] = 0.2;		AAmatrix[3][9] = 6.6;		AAmatrix[3][10] = 1.2;		AAmatrix[3][11] = 1.7;	
+	AAmatrix[3][12] = 0.2;		AAmatrix[3][13] = 0.2;		AAmatrix[3][14] = 0.2;		AAmatrix[3][15] = 44.4;	
+	AAmatrix[3][16] = 0.2;		AAmatrix[3][17] = 0.2;		AAmatrix[3][18] = 0.2;		AAmatrix[3][19] = 0.2;	
+	AAmatrix[4][0] = 253.5;		AAmatrix[4][1] = 35.5;		AAmatrix[4][2] = 98.2;		AAmatrix[4][3] = 10.6;	
+	AAmatrix[4][4] = 0;			AAmatrix[4][5] = 0.2;		AAmatrix[4][6] = 0.2;		AAmatrix[4][7] = 80.5;	
+	AAmatrix[4][8] = 12.4;		AAmatrix[4][9] = 63;		AAmatrix[4][10] = 78.7;		AAmatrix[4][11] = 0.2;	
+	AAmatrix[4][12] = 312.3;	AAmatrix[4][13] = 184.1;	AAmatrix[4][14] = 0.2;		AAmatrix[4][15] = 664.2;	
+	AAmatrix[4][16] = 182.8;	AAmatrix[4][17] = 21.6;		AAmatrix[4][18] = 72;		AAmatrix[4][19] = 350.4;	
+	AAmatrix[5][0] = 0.2;		AAmatrix[5][1] = 154;		AAmatrix[5][2] = 261.8;		AAmatrix[5][3] = 0.2;	
+	AAmatrix[5][4] = 0.2;		AAmatrix[5][5] = 0;			AAmatrix[5][6] = 261.6;		AAmatrix[5][7] = 2.6;	
+	AAmatrix[5][8] = 313.5;		AAmatrix[5][9] = 10.5;		AAmatrix[5][10] = 16.3;		AAmatrix[5][11] = 349.3;	
+	AAmatrix[5][12] = 67.3;		AAmatrix[5][13] = 0.2;		AAmatrix[5][14] = 39.3;		AAmatrix[5][15] = 52.4;	
+	AAmatrix[5][16] = 43.7;		AAmatrix[5][17] = 6.7;		AAmatrix[5][18] = 86.7;		AAmatrix[5][19] = 0.2;	
+	AAmatrix[6][0] = 0.2;		AAmatrix[6][1] = 0.2;		AAmatrix[6][2] = 183;		AAmatrix[6][3] = 861.8;	
+	AAmatrix[6][4] = 0.2;		AAmatrix[6][5] = 261.6;		AAmatrix[6][6] = 0;			AAmatrix[6][7] = 43.9;	
+	AAmatrix[6][8] = 15.2;		AAmatrix[6][9] = 6.8;		AAmatrix[6][10] = 1.7;		AAmatrix[6][11] = 106.3;	
+	AAmatrix[6][12] = 0.2;		AAmatrix[6][13] = 0.2;		AAmatrix[6][14] = 7.9;		AAmatrix[6][15] = 31.5;	
+	AAmatrix[6][16] = 43.4;		AAmatrix[6][17] = 11;		AAmatrix[6][18] = 7.7;		AAmatrix[6][19] = 13.6;	
+	AAmatrix[7][0] = 199.8;		AAmatrix[7][1] = 0.2;		AAmatrix[7][2] = 120.5;		AAmatrix[7][3] = 12.5;	
+	AAmatrix[7][4] = 80.5;		AAmatrix[7][5] = 2.6;		AAmatrix[7][6] = 43.9;		AAmatrix[7][7] = 0;	
+	AAmatrix[7][8] = 0.2;		AAmatrix[7][9] = 2.7;		AAmatrix[7][10] = 1.4;		AAmatrix[7][11] = 0.2;	
+	AAmatrix[7][12] = 55.7;		AAmatrix[7][13] = 0.8;		AAmatrix[7][14] = 0.2;		AAmatrix[7][15] = 226;	
+	AAmatrix[7][16] = 0.2;		AAmatrix[7][17] = 1.9;		AAmatrix[7][18] = 8.6;		AAmatrix[7][19] = 2.6;	
+	AAmatrix[8][0] = 0.2;		AAmatrix[8][1] = 41.3;		AAmatrix[8][2] = 179.5;		AAmatrix[8][3] = 0.2;	
+	AAmatrix[8][4] = 12.4;		AAmatrix[8][5] = 313.5;		AAmatrix[8][6] = 15.2;		AAmatrix[8][7] = 0.2;	
+	AAmatrix[8][8] = 0;			AAmatrix[8][9] = 0.2;		AAmatrix[8][10] = 5.5;		AAmatrix[8][11] = 0.2;	
+	AAmatrix[8][12] = 0.2;		AAmatrix[8][13] = 13.8;		AAmatrix[8][14] = 0.8;		AAmatrix[8][15] = 10.6;	
+	AAmatrix[8][16] = 18.6;		AAmatrix[8][17] = 0.2;		AAmatrix[8][18] = 191.4;	AAmatrix[8][19] = 0.2;	
+	AAmatrix[9][0] = 25.7;		AAmatrix[9][1] = 1.8;		AAmatrix[9][2] = 21.3;		AAmatrix[9][3] = 6.6;	
+	AAmatrix[9][4] = 63;		AAmatrix[9][5] = 10.5;		AAmatrix[9][6] = 6.8;		AAmatrix[9][7] = 2.7;	
+	AAmatrix[9][8] = 0.2;		AAmatrix[9][9] = 0;			AAmatrix[9][10] = 514.5;	AAmatrix[9][11] = 3.5;	
+	AAmatrix[9][12] = 514.8;	AAmatrix[9][13] = 117.9;	AAmatrix[9][14] = 0.2;		AAmatrix[9][15] = 7.2;	
+	AAmatrix[9][16] = 203.7;	AAmatrix[9][17] = 0.2;		AAmatrix[9][18] = 12.3;		AAmatrix[9][19] = 1854.5;	
+	AAmatrix[10][0] = 3.7;		AAmatrix[10][1] = 1.8;		AAmatrix[10][2] = 12.6;		AAmatrix[10][3] = 1.2;	
+	AAmatrix[10][4] = 78.7;		AAmatrix[10][5] = 16.3;		AAmatrix[10][6] = 1.7;		AAmatrix[10][7] = 1.4;	
+	AAmatrix[10][8] = 5.5;		AAmatrix[10][9] = 514.5;	AAmatrix[10][10] = 0;		AAmatrix[10][11] = 3.8;	
+	AAmatrix[10][12] = 885.5;	AAmatrix[10][13] = 262.6;	AAmatrix[10][14] = 12.2;	AAmatrix[10][15] = 8.2;	
+	AAmatrix[10][16] = 47.8;	AAmatrix[10][17] = 21.1;	AAmatrix[10][18] = 19.8;	AAmatrix[10][19] = 84.7;	
+	AAmatrix[11][0] = 0.2;		AAmatrix[11][1] = 208.6;	AAmatrix[11][2] = 467.3;	AAmatrix[11][3] = 1.7;	
+	AAmatrix[11][4] = 0.2;		AAmatrix[11][5] = 349.3;	AAmatrix[11][6] = 106.3;	AAmatrix[11][7] = 0.2;	
+	AAmatrix[11][8] = 0.2;		AAmatrix[11][9] = 3.5;		AAmatrix[11][10] = 3.8;		AAmatrix[11][11] = 0;	
+	AAmatrix[11][12] = 105.6;	AAmatrix[11][13] = 10.7;	AAmatrix[11][14] = 16.8;	AAmatrix[11][15] = 144.2;	
+	AAmatrix[11][16] = 69.5;	AAmatrix[11][17] = 16;		AAmatrix[11][18] = 117.1;	AAmatrix[11][19] = 26.1;	
+	AAmatrix[12][0] = 120.6;	AAmatrix[12][1] = 5.2;		AAmatrix[12][2] = 78.8;		AAmatrix[12][3] = 0.2;	
+	AAmatrix[12][4] = 312.3;	AAmatrix[12][5] = 67.3;		AAmatrix[12][6] = 0.2;		AAmatrix[12][7] = 55.7;	
+	AAmatrix[12][8] = 0.2;		AAmatrix[12][9] = 514.8;	AAmatrix[12][10] = 885.5;	AAmatrix[12][11] = 105.6;	
+	AAmatrix[12][12] = 0;		AAmatrix[12][13] = 321.6;	AAmatrix[12][14] = 5.3;		AAmatrix[12][15] = 111.7;	
+	AAmatrix[12][16] = 288.6;	AAmatrix[12][17] = 70.7;	AAmatrix[12][18] = 70.9;	AAmatrix[12][19] = 281.3;	
+	AAmatrix[13][0] = 13.1;		AAmatrix[13][1] = 4.7;		AAmatrix[13][2] = 19.7;		AAmatrix[13][3] = 0.2;	
+	AAmatrix[13][4] = 184.1;	AAmatrix[13][5] = 0.2;		AAmatrix[13][6] = 0.2;		AAmatrix[13][7] = 0.8;	
+	AAmatrix[13][8] = 13.8;		AAmatrix[13][9] = 117.9;	AAmatrix[13][10] = 262.6;	AAmatrix[13][11] = 10.7;	
+	AAmatrix[13][12] = 321.6;	AAmatrix[13][13] = 0;		AAmatrix[13][14] = 14.6;	AAmatrix[13][15] = 36.1;	
+	AAmatrix[13][16] = 13.5;	AAmatrix[13][17] = 53.7;	AAmatrix[13][18] = 791.6;	AAmatrix[13][19] = 51.9;	
+	AAmatrix[14][0] = 49.3;		AAmatrix[14][1] = 0.2;		AAmatrix[14][2] = 16.5;		AAmatrix[14][3] = 0.2;	
+	AAmatrix[14][4] = 0.2;		AAmatrix[14][5] = 39.3;		AAmatrix[14][6] = 7.9;		AAmatrix[14][7] = 0.2;	
+	AAmatrix[14][8] = 0.8;		AAmatrix[14][9] = 0.2;		AAmatrix[14][10] = 12.2;	AAmatrix[14][11] = 16.8;	
+	AAmatrix[14][12] = 5.3;		AAmatrix[14][13] = 14.6;	AAmatrix[14][14] = 0;		AAmatrix[14][15] = 86.5;	
+	AAmatrix[14][16] = 46.8;	AAmatrix[14][17] = 0.2;		AAmatrix[14][18] = 18.4;	AAmatrix[14][19] = 31.7;	
+	AAmatrix[15][0] = 673;		AAmatrix[15][1] = 2.7;		AAmatrix[15][2] = 398.4;	AAmatrix[15][3] = 44.4;	
+	AAmatrix[15][4] = 664.2;	AAmatrix[15][5] = 52.4;		AAmatrix[15][6] = 31.5;		AAmatrix[15][7] = 226;	
+	AAmatrix[15][8] = 10.6;		AAmatrix[15][9] = 7.2;		AAmatrix[15][10] = 8.2;		AAmatrix[15][11] = 144.2;	
+	AAmatrix[15][12] = 111.7;	AAmatrix[15][13] = 36.1;	AAmatrix[15][14] = 86.5;	AAmatrix[15][15] = 0;	
+	AAmatrix[15][16] = 660.4;	AAmatrix[15][17] = 2.4;		AAmatrix[15][18] = 30.5;	AAmatrix[15][19] = 60.6;	
+	AAmatrix[16][0] = 243.9;	AAmatrix[16][1] = 0.2;		AAmatrix[16][2] = 165.9;	AAmatrix[16][3] = 0.2;	
+	AAmatrix[16][4] = 182.8;	AAmatrix[16][5] = 43.7;		AAmatrix[16][6] = 43.4;		AAmatrix[16][7] = 0.2;	
+	AAmatrix[16][8] = 18.6;		AAmatrix[16][9] = 203.7;	AAmatrix[16][10] = 47.8;	AAmatrix[16][11] = 69.5;	
+	AAmatrix[16][12] = 288.6;	AAmatrix[16][13] = 13.5;	AAmatrix[16][14] = 46.8;	AAmatrix[16][15] = 660.4;	
+	AAmatrix[16][16] = 0;		AAmatrix[16][17] = 0.2;		AAmatrix[16][18] = 46;		AAmatrix[16][19] = 544.1;	
+	AAmatrix[17][0] = 0.2;		AAmatrix[17][1] = 0.2;		AAmatrix[17][2] = 7.7;		AAmatrix[17][3] = 0.2;	
+	AAmatrix[17][4] = 21.6;		AAmatrix[17][5] = 6.7;		AAmatrix[17][6] = 11;		AAmatrix[17][7] = 1.9;	
+	AAmatrix[17][8] = 0.2;		AAmatrix[17][9] = 0.2;		AAmatrix[17][10] = 21.1;	AAmatrix[17][11] = 16;	
+	AAmatrix[17][12] = 70.7;	AAmatrix[17][13] = 53.7;	AAmatrix[17][14] = 0.2;		AAmatrix[17][15] = 2.4;	
+	AAmatrix[17][16] = 0.2;		AAmatrix[17][17] = 0;		AAmatrix[17][18] = 37.7;	AAmatrix[17][19] = 0.2;	
+	AAmatrix[18][0] = 1.2;		AAmatrix[18][1] = 3.9;		AAmatrix[18][2] = 251.2;	AAmatrix[18][3] = 0.2;	
+	AAmatrix[18][4] = 72;		AAmatrix[18][5] = 86.7;		AAmatrix[18][6] = 7.7;		AAmatrix[18][7] = 8.6;	
+	AAmatrix[18][8] = 191.4;	AAmatrix[18][9] = 12.3;		AAmatrix[18][10] = 19.8;	AAmatrix[18][11] = 117.1;	
+	AAmatrix[18][12] = 70.9;	AAmatrix[18][13] = 791.6;	AAmatrix[18][14] = 18.4;	AAmatrix[18][15] = 30.5;	
+	AAmatrix[18][16] = 46;		AAmatrix[18][17] = 37.7;	AAmatrix[18][18] = 0;		AAmatrix[18][19] = 1.6;	
+	AAmatrix[19][0] = 339.9;	AAmatrix[19][1] = 0.2;		AAmatrix[19][2] = 22.6;		AAmatrix[19][3] = 0.2;	
+	AAmatrix[19][4] = 350.4;	AAmatrix[19][5] = 0.2;		AAmatrix[19][6] = 13.6;		AAmatrix[19][7] = 2.6;	
+	AAmatrix[19][8] = 0.2;		AAmatrix[19][9] = 1854.5;	AAmatrix[19][10] = 84.7;	AAmatrix[19][11] = 26.1;	
+	AAmatrix[19][12] = 281.3;	AAmatrix[19][13] = 51.9;	AAmatrix[19][14] = 31.7;	AAmatrix[19][15] = 60.6;	
+	AAmatrix[19][16] = 544.1;	AAmatrix[19][17] = 0.2;		AAmatrix[19][18] = 1.6;		AAmatrix[19][19] = 0;	
+
+	AAPi[0] = 0.054116;
+	AAPi[1] = 0.018227;
+	AAPi[2] = 0.039903;
+	AAPi[3] = 0.02016;
+	AAPi[4] = 0.009709;
+	AAPi[5] = 0.018781;
+	AAPi[6] = 0.024289;
+	AAPi[7] = 0.068183;
+	AAPi[8] = 0.024518;
+	AAPi[9] = 0.092639;
+	AAPi[10] = 0.148658;
+	AAPi[11] = 0.021718;
+	AAPi[12] = 0.061453;
+	AAPi[13] = 0.088668;
+	AAPi[14] = 0.041826;
+	AAPi[15] = 0.09103;
+	AAPi[16] = 0.049194;
+	AAPi[17] = 0.029786;
+	AAPi[18] = 0.039443;
+	AAPi[19] = 0.057701;
+
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==8)
+	{
+
+	/* 
+		mtrev24 
+		
+		Adachi, J. and Hasegawa, M. (1996) MOLPHY version 2.3: programs for molecular phylogenetics based on maximum likelihood.  
+		Computer Science Monographs of Institute of Statistical Mathematics 28:1-150.
+
+	*/
+	AAmatrix[ 0][ 0] =   0.00; AAmatrix[ 0][ 1] =  23.18; AAmatrix[ 0][ 2] =  26.95; AAmatrix[ 0][ 3] =  17.67; AAmatrix[ 0][ 4] =  59.93;
+	AAmatrix[ 0][ 5] =   1.90; AAmatrix[ 0][ 6] =   9.77; AAmatrix[ 0][ 7] = 120.71; AAmatrix[ 0][ 8] =  13.90; AAmatrix[ 0][ 9] =  96.49;
+	AAmatrix[ 0][10] =  25.46; AAmatrix[ 0][11] =   8.36; AAmatrix[ 0][12] = 141.88; AAmatrix[ 0][13] =   6.37; AAmatrix[ 0][14] =  54.31;
+	AAmatrix[ 0][15] = 387.86; AAmatrix[ 0][16] = 480.72; AAmatrix[ 0][17] =   1.90; AAmatrix[ 0][18] =   6.48; AAmatrix[ 0][19] = 195.06;
+	AAmatrix[ 1][ 0] =  23.18; AAmatrix[ 1][ 1] =   0.00; AAmatrix[ 1][ 2] =  13.24; AAmatrix[ 1][ 3] =   1.90; AAmatrix[ 1][ 4] = 103.33;
+	AAmatrix[ 1][ 5] = 220.99; AAmatrix[ 1][ 6] =   1.90; AAmatrix[ 1][ 7] =  23.03; AAmatrix[ 1][ 8] = 165.23; AAmatrix[ 1][ 9] =   1.90;
+	AAmatrix[ 1][10] =  15.58; AAmatrix[ 1][11] = 141.40; AAmatrix[ 1][12] =   1.90; AAmatrix[ 1][13] =   4.69; AAmatrix[ 1][14] =  23.64;
+	AAmatrix[ 1][15] =   6.04; AAmatrix[ 1][16] =   2.08; AAmatrix[ 1][17] =  21.95; AAmatrix[ 1][18] =   1.90; AAmatrix[ 1][19] =   7.64;
+	AAmatrix[ 2][ 0] =  26.95; AAmatrix[ 2][ 1] =  13.24; AAmatrix[ 2][ 2] =   0.00; AAmatrix[ 2][ 3] = 794.38; AAmatrix[ 2][ 4] =  58.94;
+	AAmatrix[ 2][ 5] = 173.56; AAmatrix[ 2][ 6] =  63.05; AAmatrix[ 2][ 7] =  53.30; AAmatrix[ 2][ 8] = 496.13; AAmatrix[ 2][ 9] =  27.10;
+	AAmatrix[ 2][10] =  15.16; AAmatrix[ 2][11] = 608.70; AAmatrix[ 2][12] =  65.41; AAmatrix[ 2][13] =  15.20; AAmatrix[ 2][14] =  73.31;
+	AAmatrix[ 2][15] = 494.39; AAmatrix[ 2][16] = 238.46; AAmatrix[ 2][17] =  10.68; AAmatrix[ 2][18] = 191.36; AAmatrix[ 2][19] =   1.90;
+	AAmatrix[ 3][ 0] =  17.67; AAmatrix[ 3][ 1] =   1.90; AAmatrix[ 3][ 2] = 794.38; AAmatrix[ 3][ 3] =   0.00; AAmatrix[ 3][ 4] =   1.90;
+	AAmatrix[ 3][ 5] =  55.28; AAmatrix[ 3][ 6] = 583.55; AAmatrix[ 3][ 7] =  56.77; AAmatrix[ 3][ 8] = 113.99; AAmatrix[ 3][ 9] =   4.34;
+	AAmatrix[ 3][10] =   1.90; AAmatrix[ 3][11] =   2.31; AAmatrix[ 3][12] =   1.90; AAmatrix[ 3][13] =   4.98; AAmatrix[ 3][14] =  13.43;
+	AAmatrix[ 3][15] =  69.02; AAmatrix[ 3][16] =  28.01; AAmatrix[ 3][17] =  19.86; AAmatrix[ 3][18] =  21.21; AAmatrix[ 3][19] =   1.90;
+	AAmatrix[ 4][ 0] =  59.93; AAmatrix[ 4][ 1] = 103.33; AAmatrix[ 4][ 2] =  58.94; AAmatrix[ 4][ 3] =   1.90; AAmatrix[ 4][ 4] =   0.00;
+	AAmatrix[ 4][ 5] =  75.24; AAmatrix[ 4][ 6] =   1.90; AAmatrix[ 4][ 7] =  30.71; AAmatrix[ 4][ 8] = 141.49; AAmatrix[ 4][ 9] =  62.73;
+	AAmatrix[ 4][10] =  25.65; AAmatrix[ 4][11] =   1.90; AAmatrix[ 4][12] =   6.18; AAmatrix[ 4][13] =  70.80; AAmatrix[ 4][14] =  31.26;
+	AAmatrix[ 4][15] = 277.05; AAmatrix[ 4][16] = 179.97; AAmatrix[ 4][17] =  33.60; AAmatrix[ 4][18] = 254.77; AAmatrix[ 4][19] =   1.90;
+	AAmatrix[ 5][ 0] =   1.90; AAmatrix[ 5][ 1] = 220.99; AAmatrix[ 5][ 2] = 173.56; AAmatrix[ 5][ 3] =  55.28; AAmatrix[ 5][ 4] =  75.24;
+	AAmatrix[ 5][ 5] =   0.00; AAmatrix[ 5][ 6] = 313.56; AAmatrix[ 5][ 7] =   6.75; AAmatrix[ 5][ 8] = 582.40; AAmatrix[ 5][ 9] =   8.34;
+	AAmatrix[ 5][10] =  39.70; AAmatrix[ 5][11] = 465.58; AAmatrix[ 5][12] =  47.37; AAmatrix[ 5][13] =  19.11; AAmatrix[ 5][14] = 137.29;
+	AAmatrix[ 5][15] =  54.11; AAmatrix[ 5][16] =  94.93; AAmatrix[ 5][17] =   1.90; AAmatrix[ 5][18] =  38.82; AAmatrix[ 5][19] =  19.00;
+	AAmatrix[ 6][ 0] =   9.77; AAmatrix[ 6][ 1] =   1.90; AAmatrix[ 6][ 2] =  63.05; AAmatrix[ 6][ 3] = 583.55; AAmatrix[ 6][ 4] =   1.90;
+	AAmatrix[ 6][ 5] = 313.56; AAmatrix[ 6][ 6] =   0.00; AAmatrix[ 6][ 7] =  28.28; AAmatrix[ 6][ 8] =  49.12; AAmatrix[ 6][ 9] =   3.31;
+	AAmatrix[ 6][10] =   1.90; AAmatrix[ 6][11] = 313.86; AAmatrix[ 6][12] =   1.90; AAmatrix[ 6][13] =   2.67; AAmatrix[ 6][14] =  12.83;
+	AAmatrix[ 6][15] =  54.71; AAmatrix[ 6][16] =  14.82; AAmatrix[ 6][17] =   1.90; AAmatrix[ 6][18] =  13.12; AAmatrix[ 6][19] =  21.14;
+	AAmatrix[ 7][ 0] = 120.71; AAmatrix[ 7][ 1] =  23.03; AAmatrix[ 7][ 2] =  53.30; AAmatrix[ 7][ 3] =  56.77; AAmatrix[ 7][ 4] =  30.71;
+	AAmatrix[ 7][ 5] =   6.75; AAmatrix[ 7][ 6] =  28.28; AAmatrix[ 7][ 7] =   0.00; AAmatrix[ 7][ 8] =   1.90; AAmatrix[ 7][ 9] =   5.98;
+	AAmatrix[ 7][10] =   2.41; AAmatrix[ 7][11] =  22.73; AAmatrix[ 7][12] =   1.90; AAmatrix[ 7][13] =   1.90; AAmatrix[ 7][14] =   1.90;
+	AAmatrix[ 7][15] = 125.93; AAmatrix[ 7][16] =  11.17; AAmatrix[ 7][17] =  10.92; AAmatrix[ 7][18] =   3.21; AAmatrix[ 7][19] =   2.53;
+	AAmatrix[ 8][ 0] =  13.90; AAmatrix[ 8][ 1] = 165.23; AAmatrix[ 8][ 2] = 496.13; AAmatrix[ 8][ 3] = 113.99; AAmatrix[ 8][ 4] = 141.49;
+	AAmatrix[ 8][ 5] = 582.40; AAmatrix[ 8][ 6] =  49.12; AAmatrix[ 8][ 7] =   1.90; AAmatrix[ 8][ 8] =   0.00; AAmatrix[ 8][ 9] =  12.26;
+	AAmatrix[ 8][10] =  11.49; AAmatrix[ 8][11] = 127.67; AAmatrix[ 8][12] =  11.97; AAmatrix[ 8][13] =  48.16; AAmatrix[ 8][14] =  60.97;
+	AAmatrix[ 8][15] =  77.46; AAmatrix[ 8][16] =  44.78; AAmatrix[ 8][17] =   7.08; AAmatrix[ 8][18] = 670.14; AAmatrix[ 8][19] =   1.90;
+	AAmatrix[ 9][ 0] =  96.49; AAmatrix[ 9][ 1] =   1.90; AAmatrix[ 9][ 2] =  27.10; AAmatrix[ 9][ 3] =   4.34; AAmatrix[ 9][ 4] =  62.73;
+	AAmatrix[ 9][ 5] =   8.34; AAmatrix[ 9][ 6] =   3.31; AAmatrix[ 9][ 7] =   5.98; AAmatrix[ 9][ 8] =  12.26; AAmatrix[ 9][ 9] =   0.00;
+	AAmatrix[ 9][10] = 329.09; AAmatrix[ 9][11] =  19.57; AAmatrix[ 9][12] = 517.98; AAmatrix[ 9][13] =  84.67; AAmatrix[ 9][14] =  20.63;
+	AAmatrix[ 9][15] =  47.70; AAmatrix[ 9][16] = 368.43; AAmatrix[ 9][17] =   1.90; AAmatrix[ 9][18] =  25.01; AAmatrix[ 9][19] =1222.94;
+	AAmatrix[10][ 0] =  25.46; AAmatrix[10][ 1] =  15.58; AAmatrix[10][ 2] =  15.16; AAmatrix[10][ 3] =   1.90; AAmatrix[10][ 4] =  25.65;
+	AAmatrix[10][ 5] =  39.70; AAmatrix[10][ 6] =   1.90; AAmatrix[10][ 7] =   2.41; AAmatrix[10][ 8] =  11.49; AAmatrix[10][ 9] = 329.09;
+	AAmatrix[10][10] =   0.00; AAmatrix[10][11] =  14.88; AAmatrix[10][12] = 537.53; AAmatrix[10][13] = 216.06; AAmatrix[10][14] =  40.10;
+	AAmatrix[10][15] =  73.61; AAmatrix[10][16] = 126.40; AAmatrix[10][17] =  32.44; AAmatrix[10][18] =  44.15; AAmatrix[10][19] =  91.67;
+	AAmatrix[11][ 0] =   8.36; AAmatrix[11][ 1] = 141.40; AAmatrix[11][ 2] = 608.70; AAmatrix[11][ 3] =   2.31; AAmatrix[11][ 4] =   1.90;
+	AAmatrix[11][ 5] = 465.58; AAmatrix[11][ 6] = 313.86; AAmatrix[11][ 7] =  22.73; AAmatrix[11][ 8] = 127.67; AAmatrix[11][ 9] =  19.57;
+	AAmatrix[11][10] =  14.88; AAmatrix[11][11] =   0.00; AAmatrix[11][12] =  91.37; AAmatrix[11][13] =   6.44; AAmatrix[11][14] =  50.10;
+	AAmatrix[11][15] = 105.79; AAmatrix[11][16] = 136.33; AAmatrix[11][17] =  24.00; AAmatrix[11][18] =  51.17; AAmatrix[11][19] =   1.90;
+	AAmatrix[12][ 0] = 141.88; AAmatrix[12][ 1] =   1.90; AAmatrix[12][ 2] =  65.41; AAmatrix[12][ 3] =   1.90; AAmatrix[12][ 4] =   6.18;
+	AAmatrix[12][ 5] =  47.37; AAmatrix[12][ 6] =   1.90; AAmatrix[12][ 7] =   1.90; AAmatrix[12][ 8] =  11.97; AAmatrix[12][ 9] = 517.98;
+	AAmatrix[12][10] = 537.53; AAmatrix[12][11] =  91.37; AAmatrix[12][12] =   0.00; AAmatrix[12][13] =  90.82; AAmatrix[12][14] =  18.84;
+	AAmatrix[12][15] = 111.16; AAmatrix[12][16] = 528.17; AAmatrix[12][17] =  21.71; AAmatrix[12][18] =  39.96; AAmatrix[12][19] = 387.54;
+	AAmatrix[13][ 0] =   6.37; AAmatrix[13][ 1] =   4.69; AAmatrix[13][ 2] =  15.20; AAmatrix[13][ 3] =   4.98; AAmatrix[13][ 4] =  70.80;
+	AAmatrix[13][ 5] =  19.11; AAmatrix[13][ 6] =   2.67; AAmatrix[13][ 7] =   1.90; AAmatrix[13][ 8] =  48.16; AAmatrix[13][ 9] =  84.67;
+	AAmatrix[13][10] = 216.06; AAmatrix[13][11] =   6.44; AAmatrix[13][12] =  90.82; AAmatrix[13][13] =   0.00; AAmatrix[13][14] =  17.31;
+	AAmatrix[13][15] =  64.29; AAmatrix[13][16] =  33.85; AAmatrix[13][17] =   7.84; AAmatrix[13][18] = 465.58; AAmatrix[13][19] =   6.35;
+	AAmatrix[14][ 0] =  54.31; AAmatrix[14][ 1] =  23.64; AAmatrix[14][ 2] =  73.31; AAmatrix[14][ 3] =  13.43; AAmatrix[14][ 4] =  31.26;
+	AAmatrix[14][ 5] = 137.29; AAmatrix[14][ 6] =  12.83; AAmatrix[14][ 7] =   1.90; AAmatrix[14][ 8] =  60.97; AAmatrix[14][ 9] =  20.63;
+	AAmatrix[14][10] =  40.10; AAmatrix[14][11] =  50.10; AAmatrix[14][12] =  18.84; AAmatrix[14][13] =  17.31; AAmatrix[14][14] =   0.00;
+	AAmatrix[14][15] = 169.90; AAmatrix[14][16] = 128.22; AAmatrix[14][17] =   4.21; AAmatrix[14][18] =  16.21; AAmatrix[14][19] =   8.23;
+	AAmatrix[15][ 0] = 387.86; AAmatrix[15][ 1] =   6.04; AAmatrix[15][ 2] = 494.39; AAmatrix[15][ 3] =  69.02; AAmatrix[15][ 4] = 277.05;
+	AAmatrix[15][ 5] =  54.11; AAmatrix[15][ 6] =  54.71; AAmatrix[15][ 7] = 125.93; AAmatrix[15][ 8] =  77.46; AAmatrix[15][ 9] =  47.70;
+	AAmatrix[15][10] =  73.61; AAmatrix[15][11] = 105.79; AAmatrix[15][12] = 111.16; AAmatrix[15][13] =  64.29; AAmatrix[15][14] = 169.90;
+	AAmatrix[15][15] =   0.00; AAmatrix[15][16] = 597.21; AAmatrix[15][17] =  38.58; AAmatrix[15][18] =  64.92; AAmatrix[15][19] =   1.90;
+	AAmatrix[16][ 0] = 480.72; AAmatrix[16][ 1] =   2.08; AAmatrix[16][ 2] = 238.46; AAmatrix[16][ 3] =  28.01; AAmatrix[16][ 4] = 179.97;
+	AAmatrix[16][ 5] =  94.93; AAmatrix[16][ 6] =  14.82; AAmatrix[16][ 7] =  11.17; AAmatrix[16][ 8] =  44.78; AAmatrix[16][ 9] = 368.43;
+	AAmatrix[16][10] = 126.40; AAmatrix[16][11] = 136.33; AAmatrix[16][12] = 528.17; AAmatrix[16][13] =  33.85; AAmatrix[16][14] = 128.22;
+	AAmatrix[16][15] = 597.21; AAmatrix[16][16] =   0.00; AAmatrix[16][17] =   9.99; AAmatrix[16][18] =  38.73; AAmatrix[16][19] = 204.54;
+	AAmatrix[17][ 0] =   1.90; AAmatrix[17][ 1] =  21.95; AAmatrix[17][ 2] =  10.68; AAmatrix[17][ 3] =  19.86; AAmatrix[17][ 4] =  33.60;
+	AAmatrix[17][ 5] =   1.90; AAmatrix[17][ 6] =   1.90; AAmatrix[17][ 7] =  10.92; AAmatrix[17][ 8] =   7.08; AAmatrix[17][ 9] =   1.90;
+	AAmatrix[17][10] =  32.44; AAmatrix[17][11] =  24.00; AAmatrix[17][12] =  21.71; AAmatrix[17][13] =   7.84; AAmatrix[17][14] =   4.21;
+	AAmatrix[17][15] =  38.58; AAmatrix[17][16] =   9.99; AAmatrix[17][17] =   0.00; AAmatrix[17][18] =  26.25; AAmatrix[17][19] =   5.37;
+	AAmatrix[18][ 0] =   6.48; AAmatrix[18][ 1] =   1.90; AAmatrix[18][ 2] = 191.36; AAmatrix[18][ 3] =  21.21; AAmatrix[18][ 4] = 254.77;
+	AAmatrix[18][ 5] =  38.82; AAmatrix[18][ 6] =  13.12; AAmatrix[18][ 7] =   3.21; AAmatrix[18][ 8] = 670.14; AAmatrix[18][ 9] =  25.01;
+	AAmatrix[18][10] =  44.15; AAmatrix[18][11] =  51.17; AAmatrix[18][12] =  39.96; AAmatrix[18][13] = 465.58; AAmatrix[18][14] =  16.21;
+	AAmatrix[18][15] =  64.92; AAmatrix[18][16] =  38.73; AAmatrix[18][17] =  26.25; AAmatrix[18][18] =   0.00; AAmatrix[18][19] =   1.90;
+	AAmatrix[19][ 0] = 195.06; AAmatrix[19][ 1] =   7.64; AAmatrix[19][ 2] =   1.90; AAmatrix[19][ 3] =   1.90; AAmatrix[19][ 4] =   1.90;
+	AAmatrix[19][ 5] =  19.00; AAmatrix[19][ 6] =  21.14; AAmatrix[19][ 7] =   2.53; AAmatrix[19][ 8] =   1.90; AAmatrix[19][ 9] =1222.94;
+	AAmatrix[19][10] =  91.67; AAmatrix[19][11] =   1.90; AAmatrix[19][12] = 387.54; AAmatrix[19][13] =   6.35; AAmatrix[19][14] =   8.23;
+	AAmatrix[19][15] =   1.90; AAmatrix[19][16] = 204.54; AAmatrix[19][17] =   5.37; AAmatrix[19][18] =   1.90; AAmatrix[19][19] =   0.00;
+
+	AAPi[ 0] = 0.072;
+	AAPi[ 1] = 0.019;
+	AAPi[ 2] = 0.039;
+	AAPi[ 3] = 0.019;
+	AAPi[ 4] = 0.006;
+	AAPi[ 5] = 0.025;
+	AAPi[ 6] = 0.024;
+	AAPi[ 7] = 0.056;
+	AAPi[ 8] = 0.028;
+	AAPi[ 9] = 0.088;
+	AAPi[10] = 0.168;
+	AAPi[11] = 0.023;
+	AAPi[12] = 0.054;
+	AAPi[13] = 0.061;
+	AAPi[14] = 0.054;
+	AAPi[15] = 0.072;
+	AAPi[16] = 0.086;
+	AAPi[17] = 0.029;
+	AAPi[18] = 0.033;
+	AAPi[19] = 0.043;
+	
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==9)
+	{
+
+	/* 
+		rtRev
+		
+		Dimmic M.W., J.S. Rest, D.P. Mindell, and D. Goldstein. (2002) RArtREV: An amino acid substitution matrix for inference 
+		of retrovirus and reverse transcriptase phylogeny. Journal of Molecular Evolution 55: 65-73.
+	*/
+	AAmatrix[ 0][ 0] =   0; AAmatrix[ 1][ 0] =  34; AAmatrix[ 2][ 0] =  51; AAmatrix[ 3][ 0] =  10; AAmatrix[ 4][ 0] = 439;
+	AAmatrix[ 5][ 0] =  32; AAmatrix[ 6][ 0] =  81; AAmatrix[ 7][ 0] = 135; AAmatrix[ 8][ 0] =  30; AAmatrix[ 9][ 0] =   1;
+	AAmatrix[10][ 0] =  45; AAmatrix[11][ 0] =  38; AAmatrix[12][ 0] = 235; AAmatrix[13][ 0] =   1; AAmatrix[14][ 0] =  97;
+	AAmatrix[15][ 0] = 460; AAmatrix[16][ 0] = 258; AAmatrix[17][ 0] =   5; AAmatrix[18][ 0] =  55; AAmatrix[19][ 0] = 197;
+	AAmatrix[ 0][ 1] =  34; AAmatrix[ 1][ 1] =   0; AAmatrix[ 2][ 1] =  35; AAmatrix[ 3][ 1] =  30; AAmatrix[ 4][ 1] =  92;
+	AAmatrix[ 5][ 1] = 221; AAmatrix[ 6][ 1] =  10; AAmatrix[ 7][ 1] =  41; AAmatrix[ 8][ 1] =  90; AAmatrix[ 9][ 1] =  24;
+	AAmatrix[10][ 1] =  18; AAmatrix[11][ 1] = 593; AAmatrix[12][ 1] =  57; AAmatrix[13][ 1] =   7; AAmatrix[14][ 1] =  24;
+	AAmatrix[15][ 1] = 102; AAmatrix[16][ 1] =  64; AAmatrix[17][ 1] =  13; AAmatrix[18][ 1] =  47; AAmatrix[19][ 1] =  29;
+	AAmatrix[ 0][ 2] =  51; AAmatrix[ 1][ 2] =  35; AAmatrix[ 2][ 2] =   0; AAmatrix[ 3][ 2] = 384; AAmatrix[ 4][ 2] = 128;
+	AAmatrix[ 5][ 2] = 236; AAmatrix[ 6][ 2] =  79; AAmatrix[ 7][ 2] =  94; AAmatrix[ 8][ 2] = 320; AAmatrix[ 9][ 2] =  35;
+	AAmatrix[10][ 2] =  15; AAmatrix[11][ 2] = 123; AAmatrix[12][ 2] =   1; AAmatrix[13][ 2] =  49; AAmatrix[14][ 2] =  33;
+	AAmatrix[15][ 2] = 294; AAmatrix[16][ 2] = 148; AAmatrix[17][ 2] =  16; AAmatrix[18][ 2] =  28; AAmatrix[19][ 2] =  21;
+	AAmatrix[ 0][ 3] =  10; AAmatrix[ 1][ 3] =  30; AAmatrix[ 2][ 3] = 384; AAmatrix[ 3][ 3] =   0; AAmatrix[ 4][ 3] =   1;
+	AAmatrix[ 5][ 3] =  78; AAmatrix[ 6][ 3] = 542; AAmatrix[ 7][ 3] =  61; AAmatrix[ 8][ 3] =  91; AAmatrix[ 9][ 3] =   1;
+	AAmatrix[10][ 3] =   5; AAmatrix[11][ 3] =  20; AAmatrix[12][ 3] =   1; AAmatrix[13][ 3] =   1; AAmatrix[14][ 3] =  55;
+	AAmatrix[15][ 3] = 136; AAmatrix[16][ 3] =  55; AAmatrix[17][ 3] =   1; AAmatrix[18][ 3] =   1; AAmatrix[19][ 3] =   6;
+	AAmatrix[ 0][ 4] = 439; AAmatrix[ 1][ 4] =  92; AAmatrix[ 2][ 4] = 128; AAmatrix[ 3][ 4] =   1; AAmatrix[ 4][ 4] =   0;
+	AAmatrix[ 5][ 4] =  70; AAmatrix[ 6][ 4] =   1; AAmatrix[ 7][ 4] =  48; AAmatrix[ 8][ 4] = 124; AAmatrix[ 9][ 4] = 104;
+	AAmatrix[10][ 4] = 110; AAmatrix[11][ 4] =  16; AAmatrix[12][ 4] = 156; AAmatrix[13][ 4] =  70; AAmatrix[14][ 4] =   1;
+	AAmatrix[15][ 4] =  75; AAmatrix[16][ 4] = 117; AAmatrix[17][ 4] =  55; AAmatrix[18][ 4] = 131; AAmatrix[19][ 4] = 295;
+	AAmatrix[ 0][ 5] =  32; AAmatrix[ 1][ 5] = 221; AAmatrix[ 2][ 5] = 236; AAmatrix[ 3][ 5] =  78; AAmatrix[ 4][ 5] =  70;
+	AAmatrix[ 5][ 5] =   0; AAmatrix[ 6][ 5] = 372; AAmatrix[ 7][ 5] =  18; AAmatrix[ 8][ 5] = 387; AAmatrix[ 9][ 5] =  33;
+	AAmatrix[10][ 5] =  54; AAmatrix[11][ 5] = 309; AAmatrix[12][ 5] = 158; AAmatrix[13][ 5] =   1; AAmatrix[14][ 5] =  68;
+	AAmatrix[15][ 5] = 225; AAmatrix[16][ 5] = 146; AAmatrix[17][ 5] =  10; AAmatrix[18][ 5] =  45; AAmatrix[19][ 5] =  36;
+	AAmatrix[ 0][ 6] =  81; AAmatrix[ 1][ 6] =  10; AAmatrix[ 2][ 6] =  79; AAmatrix[ 3][ 6] = 542; AAmatrix[ 4][ 6] =   1;
+	AAmatrix[ 5][ 6] = 372; AAmatrix[ 6][ 6] =   0; AAmatrix[ 7][ 6] =  70; AAmatrix[ 8][ 6] =  34; AAmatrix[ 9][ 6] =   1;
+	AAmatrix[10][ 6] =  21; AAmatrix[11][ 6] = 141; AAmatrix[12][ 6] =   1; AAmatrix[13][ 6] =   1; AAmatrix[14][ 6] =  52;
+	AAmatrix[15][ 6] =  95; AAmatrix[16][ 6] =  82; AAmatrix[17][ 6] =  17; AAmatrix[18][ 6] =   1; AAmatrix[19][ 6] =  35;
+	AAmatrix[ 0][ 7] = 135; AAmatrix[ 1][ 7] =  41; AAmatrix[ 2][ 7] =  94; AAmatrix[ 3][ 7] =  61; AAmatrix[ 4][ 7] =  48;
+	AAmatrix[ 5][ 7] =  18; AAmatrix[ 6][ 7] =  70; AAmatrix[ 7][ 7] =   0; AAmatrix[ 8][ 7] =  68; AAmatrix[ 9][ 7] =   1;
+	AAmatrix[10][ 7] =   3; AAmatrix[11][ 7] =  30; AAmatrix[12][ 7] =  37; AAmatrix[13][ 7] =   7; AAmatrix[14][ 7] =  17;
+	AAmatrix[15][ 7] = 152; AAmatrix[16][ 7] =   7; AAmatrix[17][ 7] =  23; AAmatrix[18][ 7] =  21; AAmatrix[19][ 7] =   3;
+	AAmatrix[ 0][ 8] =  30; AAmatrix[ 1][ 8] =  90; AAmatrix[ 2][ 8] = 320; AAmatrix[ 3][ 8] =  91; AAmatrix[ 4][ 8] = 124;
+	AAmatrix[ 5][ 8] = 387; AAmatrix[ 6][ 8] =  34; AAmatrix[ 7][ 8] =  68; AAmatrix[ 8][ 8] =   0; AAmatrix[ 9][ 8] =  34;
+	AAmatrix[10][ 8] =  51; AAmatrix[11][ 8] =  76; AAmatrix[12][ 8] = 116; AAmatrix[13][ 8] = 141; AAmatrix[14][ 8] =  44;
+	AAmatrix[15][ 8] = 183; AAmatrix[16][ 8] =  49; AAmatrix[17][ 8] =  48; AAmatrix[18][ 8] = 307; AAmatrix[19][ 8] =   1;
+	AAmatrix[ 0][ 9] =   1; AAmatrix[ 1][ 9] =  24; AAmatrix[ 2][ 9] =  35; AAmatrix[ 3][ 9] =   1; AAmatrix[ 4][ 9] = 104;
+	AAmatrix[ 5][ 9] =  33; AAmatrix[ 6][ 9] =   1; AAmatrix[ 7][ 9] =   1; AAmatrix[ 8][ 9] =  34; AAmatrix[ 9][ 9] =   0;
+	AAmatrix[10][ 9] = 385; AAmatrix[11][ 9] =  34; AAmatrix[12][ 9] = 375; AAmatrix[13][ 9] =  64; AAmatrix[14][ 9] =  10;
+	AAmatrix[15][ 9] =   4; AAmatrix[16][ 9] =  72; AAmatrix[17][ 9] =  39; AAmatrix[18][ 9] =  26; AAmatrix[19][ 9] =1048;
+	AAmatrix[ 0][10] =  45; AAmatrix[ 1][10] =  18; AAmatrix[ 2][10] =  15; AAmatrix[ 3][10] =   5; AAmatrix[ 4][10] = 110;
+	AAmatrix[ 5][10] =  54; AAmatrix[ 6][10] =  21; AAmatrix[ 7][10] =   3; AAmatrix[ 8][10] =  51; AAmatrix[ 9][10] = 385;
+	AAmatrix[10][10] =   0; AAmatrix[11][10] =  23; AAmatrix[12][10] = 581; AAmatrix[13][10] = 179; AAmatrix[14][10] =  22;
+	AAmatrix[15][10] =  24; AAmatrix[16][10] =  25; AAmatrix[17][10] =  47; AAmatrix[18][10] =  64; AAmatrix[19][10] = 112;
+	AAmatrix[ 0][11] =  38; AAmatrix[ 1][11] = 593; AAmatrix[ 2][11] = 123; AAmatrix[ 3][11] =  20; AAmatrix[ 4][11] =  16;
+	AAmatrix[ 5][11] = 309; AAmatrix[ 6][11] = 141; AAmatrix[ 7][11] =  30; AAmatrix[ 8][11] =  76; AAmatrix[ 9][11] =  34;
+	AAmatrix[10][11] =  23; AAmatrix[11][11] =   0; AAmatrix[12][11] = 134; AAmatrix[13][11] =  14; AAmatrix[14][11] =  43;
+	AAmatrix[15][11] =  77; AAmatrix[16][11] = 110; AAmatrix[17][11] =   6; AAmatrix[18][11] =   1; AAmatrix[19][11] =  19;
+	AAmatrix[ 0][12] = 235; AAmatrix[ 1][12] =  57; AAmatrix[ 2][12] =   1; AAmatrix[ 3][12] =   1; AAmatrix[ 4][12] = 156;
+	AAmatrix[ 5][12] = 158; AAmatrix[ 6][12] =   1; AAmatrix[ 7][12] =  37; AAmatrix[ 8][12] = 116; AAmatrix[ 9][12] = 375;
+	AAmatrix[10][12] = 581; AAmatrix[11][12] = 134; AAmatrix[12][12] =   0; AAmatrix[13][12] = 247; AAmatrix[14][12] =   1;
+	AAmatrix[15][12] =   1; AAmatrix[16][12] = 131; AAmatrix[17][12] = 111; AAmatrix[18][12] =  74; AAmatrix[19][12] = 236;
+	AAmatrix[ 0][13] =   1; AAmatrix[ 1][13] =   7; AAmatrix[ 2][13] =  49; AAmatrix[ 3][13] =   1; AAmatrix[ 4][13] =  70;
+	AAmatrix[ 5][13] =   1; AAmatrix[ 6][13] =   1; AAmatrix[ 7][13] =   7; AAmatrix[ 8][13] = 141; AAmatrix[ 9][13] =  64;
+	AAmatrix[10][13] = 179; AAmatrix[11][13] =  14; AAmatrix[12][13] = 247; AAmatrix[13][13] =   0; AAmatrix[14][13] =  11;
+	AAmatrix[15][13] =  20; AAmatrix[16][13] =  69; AAmatrix[17][13] = 182; AAmatrix[18][13] =1017; AAmatrix[19][13] =  92;
+	AAmatrix[ 0][14] =  97; AAmatrix[ 1][14] =  24; AAmatrix[ 2][14] =  33; AAmatrix[ 3][14] =  55; AAmatrix[ 4][14] =   1;
+	AAmatrix[ 5][14] =  68; AAmatrix[ 6][14] =  52; AAmatrix[ 7][14] =  17; AAmatrix[ 8][14] =  44; AAmatrix[ 9][14] =  10;
+	AAmatrix[10][14] =  22; AAmatrix[11][14] =  43; AAmatrix[12][14] =   1; AAmatrix[13][14] =  11; AAmatrix[14][14] =   0;
+	AAmatrix[15][14] = 134; AAmatrix[16][14] =  62; AAmatrix[17][14] =   9; AAmatrix[18][14] =  14; AAmatrix[19][14] =  25;
+	AAmatrix[ 0][15] = 460; AAmatrix[ 1][15] = 102; AAmatrix[ 2][15] = 294; AAmatrix[ 3][15] = 136; AAmatrix[ 4][15] =  75;
+	AAmatrix[ 5][15] = 225; AAmatrix[ 6][15] =  95; AAmatrix[ 7][15] = 152; AAmatrix[ 8][15] = 183; AAmatrix[ 9][15] =   4;
+	AAmatrix[10][15] =  24; AAmatrix[11][15] =  77; AAmatrix[12][15] =   1; AAmatrix[13][15] =  20; AAmatrix[14][15] = 134;
+	AAmatrix[15][15] =   0; AAmatrix[16][15] = 671; AAmatrix[17][15] =  14; AAmatrix[18][15] =  31; AAmatrix[19][15] =  39;
+	AAmatrix[ 0][16] = 258; AAmatrix[ 1][16] =  64; AAmatrix[ 2][16] = 148; AAmatrix[ 3][16] =  55; AAmatrix[ 4][16] = 117;
+	AAmatrix[ 5][16] = 146; AAmatrix[ 6][16] =  82; AAmatrix[ 7][16] =   7; AAmatrix[ 8][16] =  49; AAmatrix[ 9][16] =  72;
+	AAmatrix[10][16] =  25; AAmatrix[11][16] = 110; AAmatrix[12][16] = 131; AAmatrix[13][16] =  69; AAmatrix[14][16] =  62;
+	AAmatrix[15][16] = 671; AAmatrix[16][16] =   0; AAmatrix[17][16] =   1; AAmatrix[18][16] =  34; AAmatrix[19][16] = 196;
+	AAmatrix[ 0][17] =   5; AAmatrix[ 1][17] =  13; AAmatrix[ 2][17] =  16; AAmatrix[ 3][17] =   1; AAmatrix[ 4][17] =  55;
+	AAmatrix[ 5][17] =  10; AAmatrix[ 6][17] =  17; AAmatrix[ 7][17] =  23; AAmatrix[ 8][17] =  48; AAmatrix[ 9][17] =  39;
+	AAmatrix[10][17] =  47; AAmatrix[11][17] =   6; AAmatrix[12][17] = 111; AAmatrix[13][17] = 182; AAmatrix[14][17] =   9;
+	AAmatrix[15][17] =  14; AAmatrix[16][17] =   1; AAmatrix[17][17] =   0; AAmatrix[18][17] = 176; AAmatrix[19][17] =  26;
+	AAmatrix[ 0][18] =  55; AAmatrix[ 1][18] =  47; AAmatrix[ 2][18] =  28; AAmatrix[ 3][18] =   1; AAmatrix[ 4][18] = 131;
+	AAmatrix[ 5][18] =  45; AAmatrix[ 6][18] =   1; AAmatrix[ 7][18] =  21; AAmatrix[ 8][18] = 307; AAmatrix[ 9][18] =  26;
+	AAmatrix[10][18] =  64; AAmatrix[11][18] =   1; AAmatrix[12][18] =  74; AAmatrix[13][18] =1017; AAmatrix[14][18] =  14;
+	AAmatrix[15][18] =  31; AAmatrix[16][18] =  34; AAmatrix[17][18] = 176; AAmatrix[18][18] =   0; AAmatrix[19][18] =  59;
+	AAmatrix[ 0][19] = 197; AAmatrix[ 1][19] =  29; AAmatrix[ 2][19] =  21; AAmatrix[ 3][19] =   6; AAmatrix[ 4][19] = 295;
+	AAmatrix[ 5][19] =  36; AAmatrix[ 6][19] =  35; AAmatrix[ 7][19] =   3; AAmatrix[ 8][19] =   1; AAmatrix[ 9][19] =1048;
+	AAmatrix[10][19] = 112; AAmatrix[11][19] =  19; AAmatrix[12][19] = 236; AAmatrix[13][19] =  92; AAmatrix[14][19] =  25;
+	AAmatrix[15][19] =  39; AAmatrix[16][19] = 196; AAmatrix[17][19] =  26; AAmatrix[18][19] =  59; AAmatrix[19][19] =   0;
+	AAPi[ 0] = 0.0646;
+	AAPi[ 1] = 0.0453;
+	AAPi[ 2] = 0.0376;
+	AAPi[ 3] = 0.0422;
+	AAPi[ 4] = 0.0114;
+	AAPi[ 5] = 0.0606;
+	AAPi[ 6] = 0.0607;
+	AAPi[ 7] = 0.0639;
+	AAPi[ 8] = 0.0273;
+	AAPi[ 9] = 0.0679;
+	AAPi[10] = 0.1018;
+	AAPi[11] = 0.0751;
+	AAPi[12] = 0.0150;
+	AAPi[13] = 0.0287;
+	AAPi[14] = 0.0681;
+	AAPi[15] = 0.0488;
+	AAPi[16] = 0.0622;
+	AAPi[17] = 0.0251;
+	AAPi[18] = 0.0318;
+	AAPi[19] = 0.0619;
+	
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	
+	else
+	if(modelnumber==10)
+	{
+
+	/* 
+		cpRev 
+		
+		Adachi, J., P. J. Waddell, W. Martin, and M. Hasegawa. (2000) Plastid genome phylogeny and a model of amino acid 
+		substitution for proteins encoded by chloroplast DNA. Journal of Molecular Evolution 50:348-358.
+	*/
+	AAmatrix[ 0][ 0] =    0; AAmatrix[ 0][ 1] =  105; AAmatrix[ 0][ 2] =  227; AAmatrix[ 0][ 3] =  175; AAmatrix[ 0][ 4] =  669; 
+	AAmatrix[ 0][ 5] =  157; AAmatrix[ 0][ 6] =  499; AAmatrix[ 0][ 7] =  665; AAmatrix[ 0][ 8] =   66; AAmatrix[ 0][ 9] =  145; 
+	AAmatrix[ 0][10] =  197; AAmatrix[ 0][11] =  236; AAmatrix[ 0][12] =  185; AAmatrix[ 0][13] =   68; AAmatrix[ 0][14] =  490; 
+	AAmatrix[ 0][15] = 2440; AAmatrix[ 0][16] = 1340; AAmatrix[ 0][17] =   14; AAmatrix[ 0][18] =   56; AAmatrix[ 0][19] =  968; 
+	AAmatrix[ 1][ 0] =  105; AAmatrix[ 1][ 1] =    0; AAmatrix[ 1][ 2] =  357; AAmatrix[ 1][ 3] =   43; AAmatrix[ 1][ 4] =  823; 
+	AAmatrix[ 1][ 5] = 1745; AAmatrix[ 1][ 6] =  152; AAmatrix[ 1][ 7] =  243; AAmatrix[ 1][ 8] =  715; AAmatrix[ 1][ 9] =  136; 
+	AAmatrix[ 1][10] =  203; AAmatrix[ 1][11] = 4482; AAmatrix[ 1][12] =  125; AAmatrix[ 1][13] =   53; AAmatrix[ 1][14] =   87; 
+	AAmatrix[ 1][15] =  385; AAmatrix[ 1][16] =  314; AAmatrix[ 1][17] =  230; AAmatrix[ 1][18] =  323; AAmatrix[ 1][19] =   92; 
+	AAmatrix[ 2][ 0] =  227; AAmatrix[ 2][ 1] =  357; AAmatrix[ 2][ 2] =    0; AAmatrix[ 2][ 3] = 4435; AAmatrix[ 2][ 4] =  538; 
+	AAmatrix[ 2][ 5] =  768; AAmatrix[ 2][ 6] = 1055; AAmatrix[ 2][ 7] =  653; AAmatrix[ 2][ 8] = 1405; AAmatrix[ 2][ 9] =  168; 
+	AAmatrix[ 2][10] =  113; AAmatrix[ 2][11] = 2430; AAmatrix[ 2][12] =   61; AAmatrix[ 2][13] =   97; AAmatrix[ 2][14] =  173; 
+	AAmatrix[ 2][15] = 2085; AAmatrix[ 2][16] = 1393; AAmatrix[ 2][17] =   40; AAmatrix[ 2][18] =  754; AAmatrix[ 2][19] =   83; 
+	AAmatrix[ 3][ 0] =  175; AAmatrix[ 3][ 1] =   43; AAmatrix[ 3][ 2] = 4435; AAmatrix[ 3][ 3] =    0; AAmatrix[ 3][ 4] =   10; 
+	AAmatrix[ 3][ 5] =  400; AAmatrix[ 3][ 6] = 3691; AAmatrix[ 3][ 7] =  431; AAmatrix[ 3][ 8] =  331; AAmatrix[ 3][ 9] =   10; 
+	AAmatrix[ 3][10] =   10; AAmatrix[ 3][11] =  412; AAmatrix[ 3][12] =   47; AAmatrix[ 3][13] =   22; AAmatrix[ 3][14] =  170; 
+	AAmatrix[ 3][15] =  590; AAmatrix[ 3][16] =  266; AAmatrix[ 3][17] =   18; AAmatrix[ 3][18] =  281; AAmatrix[ 3][19] =   75; 
+	AAmatrix[ 4][ 0] =  669; AAmatrix[ 4][ 1] =  823; AAmatrix[ 4][ 2] =  538; AAmatrix[ 4][ 3] =   10; AAmatrix[ 4][ 4] =    0; 
+	AAmatrix[ 4][ 5] =   10; AAmatrix[ 4][ 6] =   10; AAmatrix[ 4][ 7] =  303; AAmatrix[ 4][ 8] =  441; AAmatrix[ 4][ 9] =  280; 
+	AAmatrix[ 4][10] =  396; AAmatrix[ 4][11] =   48; AAmatrix[ 4][12] =  159; AAmatrix[ 4][13] =  726; AAmatrix[ 4][14] =  285; 
+	AAmatrix[ 4][15] = 2331; AAmatrix[ 4][16] =  576; AAmatrix[ 4][17] =  435; AAmatrix[ 4][18] = 1466; AAmatrix[ 4][19] =  592; 
+	AAmatrix[ 5][ 0] =  157; AAmatrix[ 5][ 1] = 1745; AAmatrix[ 5][ 2] =  768; AAmatrix[ 5][ 3] =  400; AAmatrix[ 5][ 4] =   10; 
+	AAmatrix[ 5][ 5] =    0; AAmatrix[ 5][ 6] = 3122; AAmatrix[ 5][ 7] =  133; AAmatrix[ 5][ 8] = 1269; AAmatrix[ 5][ 9] =   92; 
+	AAmatrix[ 5][10] =  286; AAmatrix[ 5][11] = 3313; AAmatrix[ 5][12] =  202; AAmatrix[ 5][13] =   10; AAmatrix[ 5][14] =  323; 
+	AAmatrix[ 5][15] =  396; AAmatrix[ 5][16] =  241; AAmatrix[ 5][17] =   53; AAmatrix[ 5][18] =  391; AAmatrix[ 5][19] =   54; 
+	AAmatrix[ 6][ 0] =  499; AAmatrix[ 6][ 1] =  152; AAmatrix[ 6][ 2] = 1055; AAmatrix[ 6][ 3] = 3691; AAmatrix[ 6][ 4] =   10; 
+	AAmatrix[ 6][ 5] = 3122; AAmatrix[ 6][ 6] =    0; AAmatrix[ 6][ 7] =  379; AAmatrix[ 6][ 8] =  162; AAmatrix[ 6][ 9] =  148; 
+	AAmatrix[ 6][10] =   82; AAmatrix[ 6][11] = 2629; AAmatrix[ 6][12] =  113; AAmatrix[ 6][13] =  145; AAmatrix[ 6][14] =  185; 
+	AAmatrix[ 6][15] =  568; AAmatrix[ 6][16] =  369; AAmatrix[ 6][17] =   63; AAmatrix[ 6][18] =  142; AAmatrix[ 6][19] =  200; 
+	AAmatrix[ 7][ 0] =  665; AAmatrix[ 7][ 1] =  243; AAmatrix[ 7][ 2] =  653; AAmatrix[ 7][ 3] =  431; AAmatrix[ 7][ 4] =  303; 
+	AAmatrix[ 7][ 5] =  133; AAmatrix[ 7][ 6] =  379; AAmatrix[ 7][ 7] =    0; AAmatrix[ 7][ 8] =   19; AAmatrix[ 7][ 9] =   40; 
+	AAmatrix[ 7][10] =   20; AAmatrix[ 7][11] =  263; AAmatrix[ 7][12] =   21; AAmatrix[ 7][13] =   25; AAmatrix[ 7][14] =   28; 
+	AAmatrix[ 7][15] =  691; AAmatrix[ 7][16] =   92; AAmatrix[ 7][17] =   82; AAmatrix[ 7][18] =   10; AAmatrix[ 7][19] =   91; 
+	AAmatrix[ 8][ 0] =   66; AAmatrix[ 8][ 1] =  715; AAmatrix[ 8][ 2] = 1405; AAmatrix[ 8][ 3] =  331; AAmatrix[ 8][ 4] =  441; 
+	AAmatrix[ 8][ 5] = 1269; AAmatrix[ 8][ 6] =  162; AAmatrix[ 8][ 7] =   19; AAmatrix[ 8][ 8] =    0; AAmatrix[ 8][ 9] =   29; 
+	AAmatrix[ 8][10] =   66; AAmatrix[ 8][11] =  305; AAmatrix[ 8][12] =   10; AAmatrix[ 8][13] =  127; AAmatrix[ 8][14] =  152; 
+	AAmatrix[ 8][15] =  303; AAmatrix[ 8][16] =   32; AAmatrix[ 8][17] =   69; AAmatrix[ 8][18] = 1971; AAmatrix[ 8][19] =   25; 
+	AAmatrix[ 9][ 0] =  145; AAmatrix[ 9][ 1] =  136; AAmatrix[ 9][ 2] =  168; AAmatrix[ 9][ 3] =   10; AAmatrix[ 9][ 4] =  280; 
+	AAmatrix[ 9][ 5] =   92; AAmatrix[ 9][ 6] =  148; AAmatrix[ 9][ 7] =   40; AAmatrix[ 9][ 8] =   29; AAmatrix[ 9][ 9] =    0; 
+	AAmatrix[ 9][10] = 1745; AAmatrix[ 9][11] =  345; AAmatrix[ 9][12] = 1772; AAmatrix[ 9][13] =  454; AAmatrix[ 9][14] =  117; 
+	AAmatrix[ 9][15] =  216; AAmatrix[ 9][16] = 1040; AAmatrix[ 9][17] =   42; AAmatrix[ 9][18] =   89; AAmatrix[ 9][19] = 4797; 
+	AAmatrix[10][ 0] =  197; AAmatrix[10][ 1] =  203; AAmatrix[10][ 2] =  113; AAmatrix[10][ 3] =   10; AAmatrix[10][ 4] =  396; 
+	AAmatrix[10][ 5] =  286; AAmatrix[10][ 6] =   82; AAmatrix[10][ 7] =   20; AAmatrix[10][ 8] =   66; AAmatrix[10][ 9] = 1745; 
+	AAmatrix[10][10] =    0; AAmatrix[10][11] =  218; AAmatrix[10][12] = 1351; AAmatrix[10][13] = 1268; AAmatrix[10][14] =  219; 
+	AAmatrix[10][15] =  516; AAmatrix[10][16] =  156; AAmatrix[10][17] =  159; AAmatrix[10][18] =  189; AAmatrix[10][19] =  865; 
+	AAmatrix[11][ 0] =  236; AAmatrix[11][ 1] = 4482; AAmatrix[11][ 2] = 2430; AAmatrix[11][ 3] =  412; AAmatrix[11][ 4] =   48; 
+	AAmatrix[11][ 5] = 3313; AAmatrix[11][ 6] = 2629; AAmatrix[11][ 7] =  263; AAmatrix[11][ 8] =  305; AAmatrix[11][ 9] =  345; 
+	AAmatrix[11][10] =  218; AAmatrix[11][11] =    0; AAmatrix[11][12] =  193; AAmatrix[11][13] =   72; AAmatrix[11][14] =  302; 
+	AAmatrix[11][15] =  868; AAmatrix[11][16] =  918; AAmatrix[11][17] =   10; AAmatrix[11][18] =  247; AAmatrix[11][19] =  249; 
+	AAmatrix[12][ 0] =  185; AAmatrix[12][ 1] =  125; AAmatrix[12][ 2] =   61; AAmatrix[12][ 3] =   47; AAmatrix[12][ 4] =  159; 
+	AAmatrix[12][ 5] =  202; AAmatrix[12][ 6] =  113; AAmatrix[12][ 7] =   21; AAmatrix[12][ 8] =   10; AAmatrix[12][ 9] = 1772; 
+	AAmatrix[12][10] = 1351; AAmatrix[12][11] =  193; AAmatrix[12][12] =    0; AAmatrix[12][13] =  327; AAmatrix[12][14] =  100; 
+	AAmatrix[12][15] =   93; AAmatrix[12][16] =  645; AAmatrix[12][17] =   86; AAmatrix[12][18] =  215; AAmatrix[12][19] =  475; 
+	AAmatrix[13][ 0] =   68; AAmatrix[13][ 1] =   53; AAmatrix[13][ 2] =   97; AAmatrix[13][ 3] =   22; AAmatrix[13][ 4] =  726; 
+	AAmatrix[13][ 5] =   10; AAmatrix[13][ 6] =  145; AAmatrix[13][ 7] =   25; AAmatrix[13][ 8] =  127; AAmatrix[13][ 9] =  454; 
+	AAmatrix[13][10] = 1268; AAmatrix[13][11] =   72; AAmatrix[13][12] =  327; AAmatrix[13][13] =    0; AAmatrix[13][14] =   43; 
+	AAmatrix[13][15] =  487; AAmatrix[13][16] =  148; AAmatrix[13][17] =  468; AAmatrix[13][18] = 2370; AAmatrix[13][19] =  317; 
+	AAmatrix[14][ 0] =  490; AAmatrix[14][ 1] =   87; AAmatrix[14][ 2] =  173; AAmatrix[14][ 3] =  170; AAmatrix[14][ 4] =  285; 
+	AAmatrix[14][ 5] =  323; AAmatrix[14][ 6] =  185; AAmatrix[14][ 7] =   28; AAmatrix[14][ 8] =  152; AAmatrix[14][ 9] =  117; 
+	AAmatrix[14][10] =  219; AAmatrix[14][11] =  302; AAmatrix[14][12] =  100; AAmatrix[14][13] =   43; AAmatrix[14][14] =    0; 
+	AAmatrix[14][15] = 1202; AAmatrix[14][16] =  260; AAmatrix[14][17] =   49; AAmatrix[14][18] =   97; AAmatrix[14][19] =  122; 
+	AAmatrix[15][ 0] = 2440; AAmatrix[15][ 1] =  385; AAmatrix[15][ 2] = 2085; AAmatrix[15][ 3] =  590; AAmatrix[15][ 4] = 2331; 
+	AAmatrix[15][ 5] =  396; AAmatrix[15][ 6] =  568; AAmatrix[15][ 7] =  691; AAmatrix[15][ 8] =  303; AAmatrix[15][ 9] =  216; 
+	AAmatrix[15][10] =  516; AAmatrix[15][11] =  868; AAmatrix[15][12] =   93; AAmatrix[15][13] =  487; AAmatrix[15][14] = 1202; 
+	AAmatrix[15][15] =    0; AAmatrix[15][16] = 2151; AAmatrix[15][17] =   73; AAmatrix[15][18] =  522; AAmatrix[15][19] =  167; 
+	AAmatrix[16][ 0] = 1340; AAmatrix[16][ 1] =  314; AAmatrix[16][ 2] = 1393; AAmatrix[16][ 3] =  266; AAmatrix[16][ 4] =  576; 
+	AAmatrix[16][ 5] =  241; AAmatrix[16][ 6] =  369; AAmatrix[16][ 7] =   92; AAmatrix[16][ 8] =   32; AAmatrix[16][ 9] = 1040; 
+	AAmatrix[16][10] =  156; AAmatrix[16][11] =  918; AAmatrix[16][12] =  645; AAmatrix[16][13] =  148; AAmatrix[16][14] =  260; 
+	AAmatrix[16][15] = 2151; AAmatrix[16][16] =    0; AAmatrix[16][17] =   29; AAmatrix[16][18] =   71; AAmatrix[16][19] =  760; 
+	AAmatrix[17][ 0] =   14; AAmatrix[17][ 1] =  230; AAmatrix[17][ 2] =   40; AAmatrix[17][ 3] =   18; AAmatrix[17][ 4] =  435; 
+	AAmatrix[17][ 5] =   53; AAmatrix[17][ 6] =   63; AAmatrix[17][ 7] =   82; AAmatrix[17][ 8] =   69; AAmatrix[17][ 9] =   42; 
+	AAmatrix[17][10] =  159; AAmatrix[17][11] =   10; AAmatrix[17][12] =   86; AAmatrix[17][13] =  468; AAmatrix[17][14] =   49; 
+	AAmatrix[17][15] =   73; AAmatrix[17][16] =   29; AAmatrix[17][17] =    0; AAmatrix[17][18] =  346; AAmatrix[17][19] =   10; 
+	AAmatrix[18][ 0] =   56; AAmatrix[18][ 1] =  323; AAmatrix[18][ 2] =  754; AAmatrix[18][ 3] =  281; AAmatrix[18][ 4] = 1466; 
+	AAmatrix[18][ 5] =  391; AAmatrix[18][ 6] =  142; AAmatrix[18][ 7] =   10; AAmatrix[18][ 8] = 1971; AAmatrix[18][ 9] =   89; 
+	AAmatrix[18][10] =  189; AAmatrix[18][11] =  247; AAmatrix[18][12] =  215; AAmatrix[18][13] = 2370; AAmatrix[18][14] =   97; 
+	AAmatrix[18][15] =  522; AAmatrix[18][16] =   71; AAmatrix[18][17] =  346; AAmatrix[18][18] =    0; AAmatrix[18][19] =  119; 
+	AAmatrix[19][ 0] =  968; AAmatrix[19][ 1] =   92; AAmatrix[19][ 2] =   83; AAmatrix[19][ 3] =   75; AAmatrix[19][ 4] =  592; 
+	AAmatrix[19][ 5] =   54; AAmatrix[19][ 6] =  200; AAmatrix[19][ 7] =   91; AAmatrix[19][ 8] =   25; AAmatrix[19][ 9] = 4797; 
+	AAmatrix[19][10] =  865; AAmatrix[19][11] =  249; AAmatrix[19][12] =  475; AAmatrix[19][13] =  317; AAmatrix[19][14] =  122; 
+	AAmatrix[19][15] =  167; AAmatrix[19][16] =  760; AAmatrix[19][17] =   10; AAmatrix[19][18] =  119; AAmatrix[19][19] =    0; 
+
+	AAPi[0] = 0.076;
+	AAPi[1] = 0.062;
+	AAPi[2] = 0.041;
+	AAPi[3] = 0.037;
+	AAPi[4] = 0.009;
+	AAPi[5] = 0.038;
+	AAPi[6] = 0.049;
+	AAPi[7] = 0.084;
+	AAPi[8] = 0.025;
+	AAPi[9] = 0.081;
+	AAPi[10] = 0.101;
+	AAPi[11] = 0.050;
+	AAPi[12] = 0.022;
+	AAPi[13] = 0.051;
+	AAPi[14] = 0.043;
+	AAPi[15] = 0.062;
+	AAPi[16] = 0.054;
+	AAPi[17] = 0.018;
+	AAPi[18] = 0.031;
+	AAPi[19] = 0.066;
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==11)
+	{
+
+	/* 
+		VT model
+		
+		M�ller T, Vingron M (2000). Modeling amino acid replacement. J Computat Biol 7(6), 761-776
+	*/
+	AAmatrix[ 0][ 0] = 0.000000; AAmatrix[ 0][ 1] = 0.233108; AAmatrix[ 0][ 2] = 0.199097; AAmatrix[ 0][ 3] = 0.265145; AAmatrix[ 0][ 4] = 0.227333; 
+	AAmatrix[ 0][ 5] = 0.310084; AAmatrix[ 0][ 6] = 0.567957; AAmatrix[ 0][ 7] = 0.876213; AAmatrix[ 0][ 8] = 0.078692; AAmatrix[ 0][ 9] = 0.222972; 
+	AAmatrix[ 0][10] = 0.424630; AAmatrix[ 0][11] = 0.393245; AAmatrix[ 0][12] = 0.211550; AAmatrix[ 0][13] = 0.116646; AAmatrix[ 0][14] = 0.399143; 
+	AAmatrix[ 0][15] = 1.817198; AAmatrix[ 0][16] = 0.877877; AAmatrix[ 0][17] = 0.030309; AAmatrix[ 0][18] = 0.087061; AAmatrix[ 0][19] = 1.230985; 
+	AAmatrix[ 1][ 0] = 0.233108; AAmatrix[ 1][ 1] = 0.000000; AAmatrix[ 1][ 2] = 0.210797; AAmatrix[ 1][ 3] = 0.105191; AAmatrix[ 1][ 4] = 0.031726; 
+	AAmatrix[ 1][ 5] = 0.493763; AAmatrix[ 1][ 6] = 0.255240; AAmatrix[ 1][ 7] = 0.156945; AAmatrix[ 1][ 8] = 0.213164; AAmatrix[ 1][ 9] = 0.081510; 
+	AAmatrix[ 1][10] = 0.192364; AAmatrix[ 1][11] = 1.755838; AAmatrix[ 1][12] = 0.087930; AAmatrix[ 1][13] = 0.042569; AAmatrix[ 1][14] = 0.128480; 
+	AAmatrix[ 1][15] = 0.292327; AAmatrix[ 1][16] = 0.204109; AAmatrix[ 1][17] = 0.046417; AAmatrix[ 1][18] = 0.097010; AAmatrix[ 1][19] = 0.113146; 
+	AAmatrix[ 2][ 0] = 0.199097; AAmatrix[ 2][ 1] = 0.210797; AAmatrix[ 2][ 2] = 0.000000; AAmatrix[ 2][ 3] = 0.883422; AAmatrix[ 2][ 4] = 0.027495; 
+	AAmatrix[ 2][ 5] = 0.275700; AAmatrix[ 2][ 6] = 0.270417; AAmatrix[ 2][ 7] = 0.362028; AAmatrix[ 2][ 8] = 0.290006; AAmatrix[ 2][ 9] = 0.087225; 
+	AAmatrix[ 2][10] = 0.069245; AAmatrix[ 2][11] = 0.503060; AAmatrix[ 2][12] = 0.057420; AAmatrix[ 2][13] = 0.039769; AAmatrix[ 2][14] = 0.083956; 
+	AAmatrix[ 2][15] = 0.847049; AAmatrix[ 2][16] = 0.471268; AAmatrix[ 2][17] = 0.010459; AAmatrix[ 2][18] = 0.093268; AAmatrix[ 2][19] = 0.049824; 
+	AAmatrix[ 3][ 0] = 0.265145; AAmatrix[ 3][ 1] = 0.105191; AAmatrix[ 3][ 2] = 0.883422; AAmatrix[ 3][ 3] = 0.000000; AAmatrix[ 3][ 4] = 0.010313; 
+	AAmatrix[ 3][ 5] = 0.205842; AAmatrix[ 3][ 6] = 1.599461; AAmatrix[ 3][ 7] = 0.311718; AAmatrix[ 3][ 8] = 0.134252; AAmatrix[ 3][ 9] = 0.011720; 
+	AAmatrix[ 3][10] = 0.060863; AAmatrix[ 3][11] = 0.261101; AAmatrix[ 3][12] = 0.012182; AAmatrix[ 3][13] = 0.016577; AAmatrix[ 3][14] = 0.160063; 
+	AAmatrix[ 3][15] = 0.461519; AAmatrix[ 3][16] = 0.178197; AAmatrix[ 3][17] = 0.011393; AAmatrix[ 3][18] = 0.051664; AAmatrix[ 3][19] = 0.048769; 
+	AAmatrix[ 4][ 0] = 0.227333; AAmatrix[ 4][ 1] = 0.031726; AAmatrix[ 4][ 2] = 0.027495; AAmatrix[ 4][ 3] = 0.010313; AAmatrix[ 4][ 4] = 0.000000; 
+	AAmatrix[ 4][ 5] = 0.004315; AAmatrix[ 4][ 6] = 0.005321; AAmatrix[ 4][ 7] = 0.050876; AAmatrix[ 4][ 8] = 0.016695; AAmatrix[ 4][ 9] = 0.046398; 
+	AAmatrix[ 4][10] = 0.091709; AAmatrix[ 4][11] = 0.004067; AAmatrix[ 4][12] = 0.023690; AAmatrix[ 4][13] = 0.051127; AAmatrix[ 4][14] = 0.011137; 
+	AAmatrix[ 4][15] = 0.175270; AAmatrix[ 4][16] = 0.079511; AAmatrix[ 4][17] = 0.007732; AAmatrix[ 4][18] = 0.042823; AAmatrix[ 4][19] = 0.163831; 
+	AAmatrix[ 5][ 0] = 0.310084; AAmatrix[ 5][ 1] = 0.493763; AAmatrix[ 5][ 2] = 0.275700; AAmatrix[ 5][ 3] = 0.205842; AAmatrix[ 5][ 4] = 0.004315; 
+	AAmatrix[ 5][ 5] = 0.000000; AAmatrix[ 5][ 6] = 0.960976; AAmatrix[ 5][ 7] = 0.128660; AAmatrix[ 5][ 8] = 0.315521; AAmatrix[ 5][ 9] = 0.054602; 
+	AAmatrix[ 5][10] = 0.243530; AAmatrix[ 5][11] = 0.738208; AAmatrix[ 5][12] = 0.120801; AAmatrix[ 5][13] = 0.026235; AAmatrix[ 5][14] = 0.156570; 
+	AAmatrix[ 5][15] = 0.358017; AAmatrix[ 5][16] = 0.248992; AAmatrix[ 5][17] = 0.021248; AAmatrix[ 5][18] = 0.062544; AAmatrix[ 5][19] = 0.112027; 
+	AAmatrix[ 6][ 0] = 0.567957; AAmatrix[ 6][ 1] = 0.255240; AAmatrix[ 6][ 2] = 0.270417; AAmatrix[ 6][ 3] = 1.599461; AAmatrix[ 6][ 4] = 0.005321; 
+	AAmatrix[ 6][ 5] = 0.960976; AAmatrix[ 6][ 6] = 0.000000; AAmatrix[ 6][ 7] = 0.250447; AAmatrix[ 6][ 8] = 0.104458; AAmatrix[ 6][ 9] = 0.046589; 
+	AAmatrix[ 6][10] = 0.151924; AAmatrix[ 6][11] = 0.888630; AAmatrix[ 6][12] = 0.058643; AAmatrix[ 6][13] = 0.028168; AAmatrix[ 6][14] = 0.205134; 
+	AAmatrix[ 6][15] = 0.406035; AAmatrix[ 6][16] = 0.321028; AAmatrix[ 6][17] = 0.018844; AAmatrix[ 6][18] = 0.055200; AAmatrix[ 6][19] = 0.205868; 
+	AAmatrix[ 7][ 0] = 0.876213; AAmatrix[ 7][ 1] = 0.156945; AAmatrix[ 7][ 2] = 0.362028; AAmatrix[ 7][ 3] = 0.311718; AAmatrix[ 7][ 4] = 0.050876; 
+	AAmatrix[ 7][ 5] = 0.128660; AAmatrix[ 7][ 6] = 0.250447; AAmatrix[ 7][ 7] = 0.000000; AAmatrix[ 7][ 8] = 0.058131; AAmatrix[ 7][ 9] = 0.051089; 
+	AAmatrix[ 7][10] = 0.087056; AAmatrix[ 7][11] = 0.193243; AAmatrix[ 7][12] = 0.046560; AAmatrix[ 7][13] = 0.050143; AAmatrix[ 7][14] = 0.124492; 
+	AAmatrix[ 7][15] = 0.612843; AAmatrix[ 7][16] = 0.136266; AAmatrix[ 7][17] = 0.023990; AAmatrix[ 7][18] = 0.037568; AAmatrix[ 7][19] = 0.082579; 
+	AAmatrix[ 8][ 0] = 0.078692; AAmatrix[ 8][ 1] = 0.213164; AAmatrix[ 8][ 2] = 0.290006; AAmatrix[ 8][ 3] = 0.134252; AAmatrix[ 8][ 4] = 0.016695; 
+	AAmatrix[ 8][ 5] = 0.315521; AAmatrix[ 8][ 6] = 0.104458; AAmatrix[ 8][ 7] = 0.058131; AAmatrix[ 8][ 8] = 0.000000; AAmatrix[ 8][ 9] = 0.020039; 
+	AAmatrix[ 8][10] = 0.103552; AAmatrix[ 8][11] = 0.153323; AAmatrix[ 8][12] = 0.021157; AAmatrix[ 8][13] = 0.079807; AAmatrix[ 8][14] = 0.078892; 
+	AAmatrix[ 8][15] = 0.167406; AAmatrix[ 8][16] = 0.101117; AAmatrix[ 8][17] = 0.020009; AAmatrix[ 8][18] = 0.286027; AAmatrix[ 8][19] = 0.068575; 
+	AAmatrix[ 9][ 0] = 0.222972; AAmatrix[ 9][ 1] = 0.081510; AAmatrix[ 9][ 2] = 0.087225; AAmatrix[ 9][ 3] = 0.011720; AAmatrix[ 9][ 4] = 0.046398; 
+	AAmatrix[ 9][ 5] = 0.054602; AAmatrix[ 9][ 6] = 0.046589; AAmatrix[ 9][ 7] = 0.051089; AAmatrix[ 9][ 8] = 0.020039; AAmatrix[ 9][ 9] = 0.000000; 
+	AAmatrix[ 9][10] = 2.089890; AAmatrix[ 9][11] = 0.093181; AAmatrix[ 9][12] = 0.493845; AAmatrix[ 9][13] = 0.321020; AAmatrix[ 9][14] = 0.054797; 
+	AAmatrix[ 9][15] = 0.081567; AAmatrix[ 9][16] = 0.376588; AAmatrix[ 9][17] = 0.034954; AAmatrix[ 9][18] = 0.086237; AAmatrix[ 9][19] = 3.654430; 
+	AAmatrix[10][ 0] = 0.424630; AAmatrix[10][ 1] = 0.192364; AAmatrix[10][ 2] = 0.069245; AAmatrix[10][ 3] = 0.060863; AAmatrix[10][ 4] = 0.091709; 
+	AAmatrix[10][ 5] = 0.243530; AAmatrix[10][ 6] = 0.151924; AAmatrix[10][ 7] = 0.087056; AAmatrix[10][ 8] = 0.103552; AAmatrix[10][ 9] = 2.089890; 
+	AAmatrix[10][10] = 0.000000; AAmatrix[10][11] = 0.201204; AAmatrix[10][12] = 1.105667; AAmatrix[10][13] = 0.946499; AAmatrix[10][14] = 0.169784; 
+	AAmatrix[10][15] = 0.214977; AAmatrix[10][16] = 0.243227; AAmatrix[10][17] = 0.083439; AAmatrix[10][18] = 0.189842; AAmatrix[10][19] = 1.337571; 
+	AAmatrix[11][ 0] = 0.393245; AAmatrix[11][ 1] = 1.755838; AAmatrix[11][ 2] = 0.503060; AAmatrix[11][ 3] = 0.261101; AAmatrix[11][ 4] = 0.004067; 
+	AAmatrix[11][ 5] = 0.738208; AAmatrix[11][ 6] = 0.888630; AAmatrix[11][ 7] = 0.193243; AAmatrix[11][ 8] = 0.153323; AAmatrix[11][ 9] = 0.093181; 
+	AAmatrix[11][10] = 0.201204; AAmatrix[11][11] = 0.000000; AAmatrix[11][12] = 0.096474; AAmatrix[11][13] = 0.038261; AAmatrix[11][14] = 0.212302; 
+	AAmatrix[11][15] = 0.400072; AAmatrix[11][16] = 0.446646; AAmatrix[11][17] = 0.023321; AAmatrix[11][18] = 0.068689; AAmatrix[11][19] = 0.144587; 
+	AAmatrix[12][ 0] = 0.211550; AAmatrix[12][ 1] = 0.087930; AAmatrix[12][ 2] = 0.057420; AAmatrix[12][ 3] = 0.012182; AAmatrix[12][ 4] = 0.023690; 
+	AAmatrix[12][ 5] = 0.120801; AAmatrix[12][ 6] = 0.058643; AAmatrix[12][ 7] = 0.046560; AAmatrix[12][ 8] = 0.021157; AAmatrix[12][ 9] = 0.493845; 
+	AAmatrix[12][10] = 1.105667; AAmatrix[12][11] = 0.096474; AAmatrix[12][12] = 0.000000; AAmatrix[12][13] = 0.173052; AAmatrix[12][14] = 0.010363; 
+	AAmatrix[12][15] = 0.090515; AAmatrix[12][16] = 0.184609; AAmatrix[12][17] = 0.022019; AAmatrix[12][18] = 0.073223; AAmatrix[12][19] = 0.307309; 
+	AAmatrix[13][ 0] = 0.116646; AAmatrix[13][ 1] = 0.042569; AAmatrix[13][ 2] = 0.039769; AAmatrix[13][ 3] = 0.016577; AAmatrix[13][ 4] = 0.051127; 
+	AAmatrix[13][ 5] = 0.026235; AAmatrix[13][ 6] = 0.028168; AAmatrix[13][ 7] = 0.050143; AAmatrix[13][ 8] = 0.079807; AAmatrix[13][ 9] = 0.321020; 
+	AAmatrix[13][10] = 0.946499; AAmatrix[13][11] = 0.038261; AAmatrix[13][12] = 0.173052; AAmatrix[13][13] = 0.000000; AAmatrix[13][14] = 0.042564; 
+	AAmatrix[13][15] = 0.138119; AAmatrix[13][16] = 0.085870; AAmatrix[13][17] = 0.128050; AAmatrix[13][18] = 0.898663; AAmatrix[13][19] = 0.247329; 
+	AAmatrix[14][ 0] = 0.399143; AAmatrix[14][ 1] = 0.128480; AAmatrix[14][ 2] = 0.083956; AAmatrix[14][ 3] = 0.160063; AAmatrix[14][ 4] = 0.011137; 
+	AAmatrix[14][ 5] = 0.156570; AAmatrix[14][ 6] = 0.205134; AAmatrix[14][ 7] = 0.124492; AAmatrix[14][ 8] = 0.078892; AAmatrix[14][ 9] = 0.054797; 
+	AAmatrix[14][10] = 0.169784; AAmatrix[14][11] = 0.212302; AAmatrix[14][12] = 0.010363; AAmatrix[14][13] = 0.042564; AAmatrix[14][14] = 0.000000; 
+	AAmatrix[14][15] = 0.430431; AAmatrix[14][16] = 0.207143; AAmatrix[14][17] = 0.014584; AAmatrix[14][18] = 0.032043; AAmatrix[14][19] = 0.129315; 
+	AAmatrix[15][ 0] = 1.817198; AAmatrix[15][ 1] = 0.292327; AAmatrix[15][ 2] = 0.847049; AAmatrix[15][ 3] = 0.461519; AAmatrix[15][ 4] = 0.175270; 
+	AAmatrix[15][ 5] = 0.358017; AAmatrix[15][ 6] = 0.406035; AAmatrix[15][ 7] = 0.612843; AAmatrix[15][ 8] = 0.167406; AAmatrix[15][ 9] = 0.081567; 
+	AAmatrix[15][10] = 0.214977; AAmatrix[15][11] = 0.400072; AAmatrix[15][12] = 0.090515; AAmatrix[15][13] = 0.138119; AAmatrix[15][14] = 0.430431; 
+	AAmatrix[15][15] = 0.000000; AAmatrix[15][16] = 1.767766; AAmatrix[15][17] = 0.035933; AAmatrix[15][18] = 0.121979; AAmatrix[15][19] = 0.127700; 
+	AAmatrix[16][ 0] = 0.877877; AAmatrix[16][ 1] = 0.204109; AAmatrix[16][ 2] = 0.471268; AAmatrix[16][ 3] = 0.178197; AAmatrix[16][ 4] = 0.079511; 
+	AAmatrix[16][ 5] = 0.248992; AAmatrix[16][ 6] = 0.321028; AAmatrix[16][ 7] = 0.136266; AAmatrix[16][ 8] = 0.101117; AAmatrix[16][ 9] = 0.376588; 
+	AAmatrix[16][10] = 0.243227; AAmatrix[16][11] = 0.446646; AAmatrix[16][12] = 0.184609; AAmatrix[16][13] = 0.085870; AAmatrix[16][14] = 0.207143; 
+	AAmatrix[16][15] = 1.767766; AAmatrix[16][16] = 0.000000; AAmatrix[16][17] = 0.020437; AAmatrix[16][18] = 0.094617; AAmatrix[16][19] = 0.740372; 
+	AAmatrix[17][ 0] = 0.030309; AAmatrix[17][ 1] = 0.046417; AAmatrix[17][ 2] = 0.010459; AAmatrix[17][ 3] = 0.011393; AAmatrix[17][ 4] = 0.007732; 
+	AAmatrix[17][ 5] = 0.021248; AAmatrix[17][ 6] = 0.018844; AAmatrix[17][ 7] = 0.023990; AAmatrix[17][ 8] = 0.020009; AAmatrix[17][ 9] = 0.034954; 
+	AAmatrix[17][10] = 0.083439; AAmatrix[17][11] = 0.023321; AAmatrix[17][12] = 0.022019; AAmatrix[17][13] = 0.128050; AAmatrix[17][14] = 0.014584; 
+	AAmatrix[17][15] = 0.035933; AAmatrix[17][16] = 0.020437; AAmatrix[17][17] = 0.000000; AAmatrix[17][18] = 0.124746; AAmatrix[17][19] = 0.022134; 
+	AAmatrix[18][ 0] = 0.087061; AAmatrix[18][ 1] = 0.097010; AAmatrix[18][ 2] = 0.093268; AAmatrix[18][ 3] = 0.051664; AAmatrix[18][ 4] = 0.042823; 
+	AAmatrix[18][ 5] = 0.062544; AAmatrix[18][ 6] = 0.055200; AAmatrix[18][ 7] = 0.037568; AAmatrix[18][ 8] = 0.286027; AAmatrix[18][ 9] = 0.086237; 
+	AAmatrix[18][10] = 0.189842; AAmatrix[18][11] = 0.068689; AAmatrix[18][12] = 0.073223; AAmatrix[18][13] = 0.898663; AAmatrix[18][14] = 0.032043; 
+	AAmatrix[18][15] = 0.121979; AAmatrix[18][16] = 0.094617; AAmatrix[18][17] = 0.124746; AAmatrix[18][18] = 0.000000; AAmatrix[18][19] = 0.125733; 
+	AAmatrix[19][ 0] = 1.230985; AAmatrix[19][ 1] = 0.113146; AAmatrix[19][ 2] = 0.049824; AAmatrix[19][ 3] = 0.048769; AAmatrix[19][ 4] = 0.163831; 
+	AAmatrix[19][ 5] = 0.112027; AAmatrix[19][ 6] = 0.205868; AAmatrix[19][ 7] = 0.082579; AAmatrix[19][ 8] = 0.068575; AAmatrix[19][ 9] = 3.654430; 
+	AAmatrix[19][10] = 1.337571; AAmatrix[19][11] = 0.144587; AAmatrix[19][12] = 0.307309; AAmatrix[19][13] = 0.247329; AAmatrix[19][14] = 0.129315; 
+	AAmatrix[19][15] = 0.127700; AAmatrix[19][16] = 0.740372; AAmatrix[19][17] = 0.022134; AAmatrix[19][18] = 0.125733; AAmatrix[19][19] = 0.000000; 
+
+	AAPi[ 0] = 0.078837;
+	AAPi[ 1] = 0.051238;
+	AAPi[ 2] = 0.042313;
+	AAPi[ 3] = 0.053066;
+	AAPi[ 4] = 0.015175;
+	AAPi[ 5] = 0.036713;
+	AAPi[ 6] = 0.061924;
+	AAPi[ 7] = 0.070852;
+	AAPi[ 8] = 0.023082;
+	AAPi[ 9] = 0.062056;
+	AAPi[10] = 0.096371;
+	AAPi[11] = 0.057324;
+	AAPi[12] = 0.023771;
+	AAPi[13] = 0.043296;
+	AAPi[14] = 0.043911;
+	AAPi[15] = 0.063403;
+	AAPi[16] = 0.055897;
+	AAPi[17] = 0.013272;
+	AAPi[18] = 0.034399;
+	AAPi[19] = 0.073101;
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==12)
+	{
+
+	/* 
+		Blosum62 
+		
+		Henikoff, S., and J. G. Henikoff. (1992) Amino acid substitution matrices from protein blocks. Proc. Natl. Acad. Sci., U.S.A. 89:10915-10919.    
+
+	*/
+	AAmatrix[ 0][ 0] = 0.000000000000; AAmatrix[ 0][ 1] = 0.735790389698; AAmatrix[ 0][ 2] = 0.485391055466; AAmatrix[ 0][ 3] = 0.543161820899; AAmatrix[ 0][ 4] = 1.459995310470; 
+	AAmatrix[ 0][ 5] = 1.199705704602; AAmatrix[ 0][ 6] = 1.170949042800; AAmatrix[ 0][ 7] = 1.955883574960; AAmatrix[ 0][ 8] = 0.716241444998; AAmatrix[ 0][ 9] = 0.605899003687; 
+	AAmatrix[ 0][10] = 0.800016530518; AAmatrix[ 0][11] = 1.295201266783; AAmatrix[ 0][12] = 1.253758266664; AAmatrix[ 0][13] = 0.492964679748; AAmatrix[ 0][14] = 1.173275900924; 
+	AAmatrix[ 0][15] = 4.325092687057; AAmatrix[ 0][16] = 1.729178019485; AAmatrix[ 0][17] = 0.465839367725; AAmatrix[ 0][18] = 0.718206697586; AAmatrix[ 0][19] = 2.187774522005; 
+	AAmatrix[ 1][ 0] = 0.735790389698; AAmatrix[ 1][ 1] = 0.000000000000; AAmatrix[ 1][ 2] = 1.297446705134; AAmatrix[ 1][ 3] = 0.500964408555; AAmatrix[ 1][ 4] = 0.227826574209; 
+	AAmatrix[ 1][ 5] = 3.020833610064; AAmatrix[ 1][ 6] = 1.360574190420; AAmatrix[ 1][ 7] = 0.418763308518; AAmatrix[ 1][ 8] = 1.456141166336; AAmatrix[ 1][ 9] = 0.232036445142; 
+	AAmatrix[ 1][10] = 0.622711669692; AAmatrix[ 1][11] = 5.411115141489; AAmatrix[ 1][12] = 0.983692987457; AAmatrix[ 1][13] = 0.371644693209; AAmatrix[ 1][14] = 0.448133661718; 
+	AAmatrix[ 1][15] = 1.122783104210; AAmatrix[ 1][16] = 0.914665954563; AAmatrix[ 1][17] = 0.426382310122; AAmatrix[ 1][18] = 0.720517441216; AAmatrix[ 1][19] = 0.438388343772; 
+	AAmatrix[ 2][ 0] = 0.485391055466; AAmatrix[ 2][ 1] = 1.297446705134; AAmatrix[ 2][ 2] = 0.000000000000; AAmatrix[ 2][ 3] = 3.180100048216; AAmatrix[ 2][ 4] = 0.397358949897; 
+	AAmatrix[ 2][ 5] = 1.839216146992; AAmatrix[ 2][ 6] = 1.240488508640; AAmatrix[ 2][ 7] = 1.355872344485; AAmatrix[ 2][ 8] = 2.414501434208; AAmatrix[ 2][ 9] = 0.283017326278; 
+	AAmatrix[ 2][10] = 0.211888159615; AAmatrix[ 2][11] = 1.593137043457; AAmatrix[ 2][12] = 0.648441278787; AAmatrix[ 2][13] = 0.354861249223; AAmatrix[ 2][14] = 0.494887043702; 
+	AAmatrix[ 2][15] = 2.904101656456; AAmatrix[ 2][16] = 1.898173634533; AAmatrix[ 2][17] = 0.191482046247; AAmatrix[ 2][18] = 0.538222519037; AAmatrix[ 2][19] = 0.312858797993; 
+	AAmatrix[ 3][ 0] = 0.543161820899; AAmatrix[ 3][ 1] = 0.500964408555; AAmatrix[ 3][ 2] = 3.180100048216; AAmatrix[ 3][ 3] = 0.000000000000; AAmatrix[ 3][ 4] = 0.240836614802; 
+	AAmatrix[ 3][ 5] = 1.190945703396; AAmatrix[ 3][ 6] = 3.761625208368; AAmatrix[ 3][ 7] = 0.798473248968; AAmatrix[ 3][ 8] = 0.778142664022; AAmatrix[ 3][ 9] = 0.418555732462; 
+	AAmatrix[ 3][10] = 0.218131577594; AAmatrix[ 3][11] = 1.032447924952; AAmatrix[ 3][12] = 0.222621897958; AAmatrix[ 3][13] = 0.281730694207; AAmatrix[ 3][14] = 0.730628272998; 
+	AAmatrix[ 3][15] = 1.582754142065; AAmatrix[ 3][16] = 0.934187509431; AAmatrix[ 3][17] = 0.145345046279; AAmatrix[ 3][18] = 0.261422208965; AAmatrix[ 3][19] = 0.258129289418; 
+	AAmatrix[ 4][ 0] = 1.459995310470; AAmatrix[ 4][ 1] = 0.227826574209; AAmatrix[ 4][ 2] = 0.397358949897; AAmatrix[ 4][ 3] = 0.240836614802; AAmatrix[ 4][ 4] = 0.000000000000; 
+	AAmatrix[ 4][ 5] = 0.329801504630; AAmatrix[ 4][ 6] = 0.140748891814; AAmatrix[ 4][ 7] = 0.418203192284; AAmatrix[ 4][ 8] = 0.354058109831; AAmatrix[ 4][ 9] = 0.774894022794; 
+	AAmatrix[ 4][10] = 0.831842640142; AAmatrix[ 4][11] = 0.285078800906; AAmatrix[ 4][12] = 0.767688823480; AAmatrix[ 4][13] = 0.441337471187; AAmatrix[ 4][14] = 0.356008498769; 
+	AAmatrix[ 4][15] = 1.197188415094; AAmatrix[ 4][16] = 1.119831358516; AAmatrix[ 4][17] = 0.527664418872; AAmatrix[ 4][18] = 0.470237733696; AAmatrix[ 4][19] = 1.116352478606; 
+	AAmatrix[ 5][ 0] = 1.199705704602; AAmatrix[ 5][ 1] = 3.020833610064; AAmatrix[ 5][ 2] = 1.839216146992; AAmatrix[ 5][ 3] = 1.190945703396; AAmatrix[ 5][ 4] = 0.329801504630; 
+	AAmatrix[ 5][ 5] = 0.000000000000; AAmatrix[ 5][ 6] = 5.528919177928; AAmatrix[ 5][ 7] = 0.609846305383; AAmatrix[ 5][ 8] = 2.435341131140; AAmatrix[ 5][ 9] = 0.236202451204; 
+	AAmatrix[ 5][10] = 0.580737093181; AAmatrix[ 5][11] = 3.945277674515; AAmatrix[ 5][12] = 2.494896077113; AAmatrix[ 5][13] = 0.144356959750; AAmatrix[ 5][14] = 0.858570575674; 
+	AAmatrix[ 5][15] = 1.934870924596; AAmatrix[ 5][16] = 1.277480294596; AAmatrix[ 5][17] = 0.758653808642; AAmatrix[ 5][18] = 0.958989742850; AAmatrix[ 5][19] = 0.530785790125; 
+	AAmatrix[ 6][ 0] = 1.170949042800; AAmatrix[ 6][ 1] = 1.360574190420; AAmatrix[ 6][ 2] = 1.240488508640; AAmatrix[ 6][ 3] = 3.761625208368; AAmatrix[ 6][ 4] = 0.140748891814; 
+	AAmatrix[ 6][ 5] = 5.528919177928; AAmatrix[ 6][ 6] = 0.000000000000; AAmatrix[ 6][ 7] = 0.423579992176; AAmatrix[ 6][ 8] = 1.626891056982; AAmatrix[ 6][ 9] = 0.186848046932; 
+	AAmatrix[ 6][10] = 0.372625175087; AAmatrix[ 6][11] = 2.802427151679; AAmatrix[ 6][12] = 0.555415397470; AAmatrix[ 6][13] = 0.291409084165; AAmatrix[ 6][14] = 0.926563934846; 
+	AAmatrix[ 6][15] = 1.769893238937; AAmatrix[ 6][16] = 1.071097236007; AAmatrix[ 6][17] = 0.407635648938; AAmatrix[ 6][18] = 0.596719300346; AAmatrix[ 6][19] = 0.524253846338; 
+	AAmatrix[ 7][ 0] = 1.955883574960; AAmatrix[ 7][ 1] = 0.418763308518; AAmatrix[ 7][ 2] = 1.355872344485; AAmatrix[ 7][ 3] = 0.798473248968; AAmatrix[ 7][ 4] = 0.418203192284; 
+	AAmatrix[ 7][ 5] = 0.609846305383; AAmatrix[ 7][ 6] = 0.423579992176; AAmatrix[ 7][ 7] = 0.000000000000; AAmatrix[ 7][ 8] = 0.539859124954; AAmatrix[ 7][ 9] = 0.189296292376; 
+	AAmatrix[ 7][10] = 0.217721159236; AAmatrix[ 7][11] = 0.752042440303; AAmatrix[ 7][12] = 0.459436173579; AAmatrix[ 7][13] = 0.368166464453; AAmatrix[ 7][14] = 0.504086599527; 
+	AAmatrix[ 7][15] = 1.509326253224; AAmatrix[ 7][16] = 0.641436011405; AAmatrix[ 7][17] = 0.508358924638; AAmatrix[ 7][18] = 0.308055737035; AAmatrix[ 7][19] = 0.253340790190; 
+	AAmatrix[ 8][ 0] = 0.716241444998; AAmatrix[ 8][ 1] = 1.456141166336; AAmatrix[ 8][ 2] = 2.414501434208; AAmatrix[ 8][ 3] = 0.778142664022; AAmatrix[ 8][ 4] = 0.354058109831; 
+	AAmatrix[ 8][ 5] = 2.435341131140; AAmatrix[ 8][ 6] = 1.626891056982; AAmatrix[ 8][ 7] = 0.539859124954; AAmatrix[ 8][ 8] = 0.000000000000; AAmatrix[ 8][ 9] = 0.252718447885; 
+	AAmatrix[ 8][10] = 0.348072209797; AAmatrix[ 8][11] = 1.022507035889; AAmatrix[ 8][12] = 0.984311525359; AAmatrix[ 8][13] = 0.714533703928; AAmatrix[ 8][14] = 0.527007339151; 
+	AAmatrix[ 8][15] = 1.117029762910; AAmatrix[ 8][16] = 0.585407090225; AAmatrix[ 8][17] = 0.301248600780; AAmatrix[ 8][18] = 4.218953969389; AAmatrix[ 8][19] = 0.201555971750; 
+	AAmatrix[ 9][ 0] = 0.605899003687; AAmatrix[ 9][ 1] = 0.232036445142; AAmatrix[ 9][ 2] = 0.283017326278; AAmatrix[ 9][ 3] = 0.418555732462; AAmatrix[ 9][ 4] = 0.774894022794; 
+	AAmatrix[ 9][ 5] = 0.236202451204; AAmatrix[ 9][ 6] = 0.186848046932; AAmatrix[ 9][ 7] = 0.189296292376; AAmatrix[ 9][ 8] = 0.252718447885; AAmatrix[ 9][ 9] = 0.000000000000; 
+	AAmatrix[ 9][10] = 3.890963773304; AAmatrix[ 9][11] = 0.406193586642; AAmatrix[ 9][12] = 3.364797763104; AAmatrix[ 9][13] = 1.517359325954; AAmatrix[ 9][14] = 0.388355409206; 
+	AAmatrix[ 9][15] = 0.357544412460; AAmatrix[ 9][16] = 1.179091197260; AAmatrix[ 9][17] = 0.341985787540; AAmatrix[ 9][18] = 0.674617093228; AAmatrix[ 9][19] = 8.311839405458; 
+	AAmatrix[10][ 0] = 0.800016530518; AAmatrix[10][ 1] = 0.622711669692; AAmatrix[10][ 2] = 0.211888159615; AAmatrix[10][ 3] = 0.218131577594; AAmatrix[10][ 4] = 0.831842640142; 
+	AAmatrix[10][ 5] = 0.580737093181; AAmatrix[10][ 6] = 0.372625175087; AAmatrix[10][ 7] = 0.217721159236; AAmatrix[10][ 8] = 0.348072209797; AAmatrix[10][ 9] = 3.890963773304; 
+	AAmatrix[10][10] = 0.000000000000; AAmatrix[10][11] = 0.445570274261; AAmatrix[10][12] = 6.030559379572; AAmatrix[10][13] = 2.064839703237; AAmatrix[10][14] = 0.374555687471; 
+	AAmatrix[10][15] = 0.352969184527; AAmatrix[10][16] = 0.915259857694; AAmatrix[10][17] = 0.691474634600; AAmatrix[10][18] = 0.811245856323; AAmatrix[10][19] = 2.231405688913; 
+	AAmatrix[11][ 0] = 1.295201266783; AAmatrix[11][ 1] = 5.411115141489; AAmatrix[11][ 2] = 1.593137043457; AAmatrix[11][ 3] = 1.032447924952; AAmatrix[11][ 4] = 0.285078800906; 
+	AAmatrix[11][ 5] = 3.945277674515; AAmatrix[11][ 6] = 2.802427151679; AAmatrix[11][ 7] = 0.752042440303; AAmatrix[11][ 8] = 1.022507035889; AAmatrix[11][ 9] = 0.406193586642; 
+	AAmatrix[11][10] = 0.445570274261; AAmatrix[11][11] = 0.000000000000; AAmatrix[11][12] = 1.073061184332; AAmatrix[11][13] = 0.266924750511; AAmatrix[11][14] = 1.047383450722; 
+	AAmatrix[11][15] = 1.752165917819; AAmatrix[11][16] = 1.303875200799; AAmatrix[11][17] = 0.332243040634; AAmatrix[11][18] = 0.717993486900; AAmatrix[11][19] = 0.498138475304; 
+	AAmatrix[12][ 0] = 1.253758266664; AAmatrix[12][ 1] = 0.983692987457; AAmatrix[12][ 2] = 0.648441278787; AAmatrix[12][ 3] = 0.222621897958; AAmatrix[12][ 4] = 0.767688823480; 
+	AAmatrix[12][ 5] = 2.494896077113; AAmatrix[12][ 6] = 0.555415397470; AAmatrix[12][ 7] = 0.459436173579; AAmatrix[12][ 8] = 0.984311525359; AAmatrix[12][ 9] = 3.364797763104; 
+	AAmatrix[12][10] = 6.030559379572; AAmatrix[12][11] = 1.073061184332; AAmatrix[12][12] = 0.000000000000; AAmatrix[12][13] = 1.773855168830; AAmatrix[12][14] = 0.454123625103; 
+	AAmatrix[12][15] = 0.918723415746; AAmatrix[12][16] = 1.488548053722; AAmatrix[12][17] = 0.888101098152; AAmatrix[12][18] = 0.951682162246; AAmatrix[12][19] = 2.575850755315; 
+	AAmatrix[13][ 0] = 0.492964679748; AAmatrix[13][ 1] = 0.371644693209; AAmatrix[13][ 2] = 0.354861249223; AAmatrix[13][ 3] = 0.281730694207; AAmatrix[13][ 4] = 0.441337471187; 
+	AAmatrix[13][ 5] = 0.144356959750; AAmatrix[13][ 6] = 0.291409084165; AAmatrix[13][ 7] = 0.368166464453; AAmatrix[13][ 8] = 0.714533703928; AAmatrix[13][ 9] = 1.517359325954; 
+	AAmatrix[13][10] = 2.064839703237; AAmatrix[13][11] = 0.266924750511; AAmatrix[13][12] = 1.773855168830; AAmatrix[13][13] = 0.000000000000; AAmatrix[13][14] = 0.233597909629; 
+	AAmatrix[13][15] = 0.540027644824; AAmatrix[13][16] = 0.488206118793; AAmatrix[13][17] = 2.074324893497; AAmatrix[13][18] = 6.747260430801; AAmatrix[13][19] = 0.838119610178; 
+	AAmatrix[14][ 0] = 1.173275900924; AAmatrix[14][ 1] = 0.448133661718; AAmatrix[14][ 2] = 0.494887043702; AAmatrix[14][ 3] = 0.730628272998; AAmatrix[14][ 4] = 0.356008498769; 
+	AAmatrix[14][ 5] = 0.858570575674; AAmatrix[14][ 6] = 0.926563934846; AAmatrix[14][ 7] = 0.504086599527; AAmatrix[14][ 8] = 0.527007339151; AAmatrix[14][ 9] = 0.388355409206; 
+	AAmatrix[14][10] = 0.374555687471; AAmatrix[14][11] = 1.047383450722; AAmatrix[14][12] = 0.454123625103; AAmatrix[14][13] = 0.233597909629; AAmatrix[14][14] = 0.000000000000; 
+	AAmatrix[14][15] = 1.169129577716; AAmatrix[14][16] = 1.005451683149; AAmatrix[14][17] = 0.252214830027; AAmatrix[14][18] = 0.369405319355; AAmatrix[14][19] = 0.496908410676; 
+	AAmatrix[15][ 0] = 4.325092687057; AAmatrix[15][ 1] = 1.122783104210; AAmatrix[15][ 2] = 2.904101656456; AAmatrix[15][ 3] = 1.582754142065; AAmatrix[15][ 4] = 1.197188415094; 
+	AAmatrix[15][ 5] = 1.934870924596; AAmatrix[15][ 6] = 1.769893238937; AAmatrix[15][ 7] = 1.509326253224; AAmatrix[15][ 8] = 1.117029762910; AAmatrix[15][ 9] = 0.357544412460; 
+	AAmatrix[15][10] = 0.352969184527; AAmatrix[15][11] = 1.752165917819; AAmatrix[15][12] = 0.918723415746; AAmatrix[15][13] = 0.540027644824; AAmatrix[15][14] = 1.169129577716; 
+	AAmatrix[15][15] = 0.000000000000; AAmatrix[15][16] = 5.151556292270; AAmatrix[15][17] = 0.387925622098; AAmatrix[15][18] = 0.796751520761; AAmatrix[15][19] = 0.561925457442; 
+	AAmatrix[16][ 0] = 1.729178019485; AAmatrix[16][ 1] = 0.914665954563; AAmatrix[16][ 2] = 1.898173634533; AAmatrix[16][ 3] = 0.934187509431; AAmatrix[16][ 4] = 1.119831358516; 
+	AAmatrix[16][ 5] = 1.277480294596; AAmatrix[16][ 6] = 1.071097236007; AAmatrix[16][ 7] = 0.641436011405; AAmatrix[16][ 8] = 0.585407090225; AAmatrix[16][ 9] = 1.179091197260; 
+	AAmatrix[16][10] = 0.915259857694; AAmatrix[16][11] = 1.303875200799; AAmatrix[16][12] = 1.488548053722; AAmatrix[16][13] = 0.488206118793; AAmatrix[16][14] = 1.005451683149; 
+	AAmatrix[16][15] = 5.151556292270; AAmatrix[16][16] = 0.000000000000; AAmatrix[16][17] = 0.513128126891; AAmatrix[16][18] = 0.801010243199; AAmatrix[16][19] = 2.253074051176; 
+	AAmatrix[17][ 0] = 0.465839367725; AAmatrix[17][ 1] = 0.426382310122; AAmatrix[17][ 2] = 0.191482046247; AAmatrix[17][ 3] = 0.145345046279; AAmatrix[17][ 4] = 0.527664418872; 
+	AAmatrix[17][ 5] = 0.758653808642; AAmatrix[17][ 6] = 0.407635648938; AAmatrix[17][ 7] = 0.508358924638; AAmatrix[17][ 8] = 0.301248600780; AAmatrix[17][ 9] = 0.341985787540; 
+	AAmatrix[17][10] = 0.691474634600; AAmatrix[17][11] = 0.332243040634; AAmatrix[17][12] = 0.888101098152; AAmatrix[17][13] = 2.074324893497; AAmatrix[17][14] = 0.252214830027; 
+	AAmatrix[17][15] = 0.387925622098; AAmatrix[17][16] = 0.513128126891; AAmatrix[17][17] = 0.000000000000; AAmatrix[17][18] = 4.054419006558; AAmatrix[17][19] = 0.266508731426; 
+	AAmatrix[18][ 0] = 0.718206697586; AAmatrix[18][ 1] = 0.720517441216; AAmatrix[18][ 2] = 0.538222519037; AAmatrix[18][ 3] = 0.261422208965; AAmatrix[18][ 4] = 0.470237733696; 
+	AAmatrix[18][ 5] = 0.958989742850; AAmatrix[18][ 6] = 0.596719300346; AAmatrix[18][ 7] = 0.308055737035; AAmatrix[18][ 8] = 4.218953969389; AAmatrix[18][ 9] = 0.674617093228; 
+	AAmatrix[18][10] = 0.811245856323; AAmatrix[18][11] = 0.717993486900; AAmatrix[18][12] = 0.951682162246; AAmatrix[18][13] = 6.747260430801; AAmatrix[18][14] = 0.369405319355; 
+	AAmatrix[18][15] = 0.796751520761; AAmatrix[18][16] = 0.801010243199; AAmatrix[18][17] = 4.054419006558; AAmatrix[18][18] = 0.000000000000; AAmatrix[18][19] = 1.000000000000; 
+	AAmatrix[19][ 0] = 2.187774522005; AAmatrix[19][ 1] = 0.438388343772; AAmatrix[19][ 2] = 0.312858797993; AAmatrix[19][ 3] = 0.258129289418; AAmatrix[19][ 4] = 1.116352478606; 
+	AAmatrix[19][ 5] = 0.530785790125; AAmatrix[19][ 6] = 0.524253846338; AAmatrix[19][ 7] = 0.253340790190; AAmatrix[19][ 8] = 0.201555971750; AAmatrix[19][ 9] = 8.311839405458; 
+	AAmatrix[19][10] = 2.231405688913; AAmatrix[19][11] = 0.498138475304; AAmatrix[19][12] = 2.575850755315; AAmatrix[19][13] = 0.838119610178; AAmatrix[19][14] = 0.496908410676; 
+	AAmatrix[19][15] = 0.561925457442; AAmatrix[19][16] = 2.253074051176; AAmatrix[19][17] = 0.266508731426; AAmatrix[19][18] = 1.000000000000; AAmatrix[19][19] = 0.000000000000; 	
+
+	AAPi[ 0] = 0.074; 
+	AAPi[ 1] = 0.052; 
+	AAPi[ 2] = 0.045; 
+	AAPi[ 3] = 0.054;
+	AAPi[ 4] = 0.025; 
+	AAPi[ 5] = 0.034; 
+	AAPi[ 6] = 0.054; 
+	AAPi[ 7] = 0.074;
+	AAPi[ 8] = 0.026; 
+	AAPi[ 9] = 0.068; 
+	AAPi[10] = 0.099; 
+	AAPi[11] = 0.058;
+	AAPi[12] = 0.025; 
+	AAPi[13] = 0.047; 
+	AAPi[14] = 0.039; 
+	AAPi[15] = 0.057;
+	AAPi[16] = 0.051; 
+	AAPi[17] = 0.013; 
+	AAPi[18] = 0.032; 
+	AAPi[19] = 0.073;
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==13)
+	{
+
+	/* 
+		LG MODEL
+		
+		Le, S.Q. and Gascuel, O. (2008) LG: An Improved, General Amino-Acid Replacement Matrix. Molecular Biology and Evolution 25(7), 1307-1320 
+	*/
+
+
+	AAmatrix[0][1]= AAmatrix[1][0]=0.425093;
+	AAmatrix[0][2]= AAmatrix[2][0]=0.276818;  AAmatrix[1][2]= AAmatrix[2][1]=0.751878;
+	AAmatrix[0][3]= AAmatrix[3][0]=0.395144;  AAmatrix[1][3]= AAmatrix[3][1]=0.123954;  AAmatrix[2][3]= AAmatrix[3][2]=5.076149;
+	AAmatrix[0][4]= AAmatrix[4][0]=2.489084;  AAmatrix[1][4]= AAmatrix[4][1]=0.534551;  AAmatrix[2][4]= AAmatrix[4][2]=0.528768;  AAmatrix[3][4]= AAmatrix[4][3]=0.062556;
+	AAmatrix[0][5]= AAmatrix[5][0]=0.969894;  AAmatrix[1][5]= AAmatrix[5][1]=2.807908;  AAmatrix[2][5]= AAmatrix[5][2]=1.695752;  AAmatrix[3][5]= AAmatrix[5][3]=0.523386;  AAmatrix[4][5]= AAmatrix[5][4]=0.084808;
+	AAmatrix[0][6]= AAmatrix[6][0]=1.038545;  AAmatrix[1][6]= AAmatrix[6][1]=0.363970;  AAmatrix[2][6]= AAmatrix[6][2]=0.541712;  AAmatrix[3][6]= AAmatrix[6][3]=5.243870;  AAmatrix[4][6]= AAmatrix[6][4]=0.003499;  AAmatrix[5][6]= AAmatrix[6][5]=4.128591;
+	AAmatrix[0][7]= AAmatrix[7][0]=2.066040;  AAmatrix[1][7]= AAmatrix[7][1]=0.390192;  AAmatrix[2][7]= AAmatrix[7][2]=1.437645;  AAmatrix[3][7]= AAmatrix[7][3]=0.844926;  AAmatrix[4][7]= AAmatrix[7][4]=0.569265;  AAmatrix[5][7]= AAmatrix[7][5]=0.267959;  AAmatrix[6][7]= AAmatrix[7][6]=0.348847;
+	AAmatrix[0][8]= AAmatrix[8][0]=0.358858;  AAmatrix[1][8]= AAmatrix[8][1]=2.426601;  AAmatrix[2][8]= AAmatrix[8][2]=4.509238;  AAmatrix[3][8]= AAmatrix[8][3]=0.927114;  AAmatrix[4][8]= AAmatrix[8][4]=0.640543;  AAmatrix[5][8]= AAmatrix[8][5]=4.813505;  AAmatrix[6][8]= AAmatrix[8][6]=0.423881;  AAmatrix[7][8]= AAmatrix[8][7]=0.311484;
+	AAmatrix[0][9]= AAmatrix[9][0]=0.149830;  AAmatrix[1][9]= AAmatrix[9][1]=0.126991;  AAmatrix[2][9]= AAmatrix[9][2]=0.191503;  AAmatrix[3][9]= AAmatrix[9][3]=0.010690;  AAmatrix[4][9]= AAmatrix[9][4]=0.320627;  AAmatrix[5][9]= AAmatrix[9][5]=0.072854;  AAmatrix[6][9]= AAmatrix[9][6]=0.044265;  AAmatrix[7][9]= AAmatrix[9][7]=0.008705;  AAmatrix[8][9]= AAmatrix[9][8]=0.108882;
+	AAmatrix[0][10]=AAmatrix[10][0]=0.395337; AAmatrix[1][10]=AAmatrix[10][1]=0.301848; AAmatrix[2][10]=AAmatrix[10][2]=0.068427; AAmatrix[3][10]=AAmatrix[10][3]=0.015076; AAmatrix[4][10]=AAmatrix[10][4]=0.594007; AAmatrix[5][10]=AAmatrix[10][5]=0.582457; AAmatrix[6][10]=AAmatrix[10][6]=0.069673; AAmatrix[7][10]=AAmatrix[10][7]=0.044261; AAmatrix[8][10]=AAmatrix[10][8]=0.366317; AAmatrix[9][10]=AAmatrix[10][9]=4.145067;
+	AAmatrix[0][11]=AAmatrix[11][0]=0.536518; AAmatrix[1][11]=AAmatrix[11][1]=6.326067; AAmatrix[2][11]=AAmatrix[11][2]=2.145078; AAmatrix[3][11]=AAmatrix[11][3]=0.282959; AAmatrix[4][11]=AAmatrix[11][4]=0.013266; AAmatrix[5][11]=AAmatrix[11][5]=3.234294; AAmatrix[6][11]=AAmatrix[11][6]=1.807177; AAmatrix[7][11]=AAmatrix[11][7]=0.296636; AAmatrix[8][11]=AAmatrix[11][8]=0.697264; AAmatrix[9][11]=AAmatrix[11][9]=0.159069;  AAmatrix[10][11]=AAmatrix[11][10]=0.137500;
+	AAmatrix[0][12]=AAmatrix[12][0]=1.124035; AAmatrix[1][12]=AAmatrix[12][1]=0.484133; AAmatrix[2][12]=AAmatrix[12][2]=0.371004; AAmatrix[3][12]=AAmatrix[12][3]=0.025548; AAmatrix[4][12]=AAmatrix[12][4]=0.893680; AAmatrix[5][12]=AAmatrix[12][5]=1.672569; AAmatrix[6][12]=AAmatrix[12][6]=0.173735; AAmatrix[7][12]=AAmatrix[12][7]=0.139538; AAmatrix[8][12]=AAmatrix[12][8]=0.442472; AAmatrix[9][12]=AAmatrix[12][9]=4.273607;  AAmatrix[10][12]=AAmatrix[12][10]=6.312358; AAmatrix[11][12]=AAmatrix[ [...]
+	AAmatrix[0][13]=AAmatrix[13][0]=0.253701; AAmatrix[1][13]=AAmatrix[13][1]=0.052722; AAmatrix[2][13]=AAmatrix[13][2]=0.089525; AAmatrix[3][13]=AAmatrix[13][3]=0.017416; AAmatrix[4][13]=AAmatrix[13][4]=1.105251; AAmatrix[5][13]=AAmatrix[13][5]=0.035855; AAmatrix[6][13]=AAmatrix[13][6]=0.018811; AAmatrix[7][13]=AAmatrix[13][7]=0.089586; AAmatrix[8][13]=AAmatrix[13][8]=0.682139; AAmatrix[9][13]=AAmatrix[13][9]=1.112727;  AAmatrix[10][13]=AAmatrix[13][10]=2.592692; AAmatrix[11][13]=AAmatrix[ [...]
+	AAmatrix[0][14]=AAmatrix[14][0]=1.177651; AAmatrix[1][14]=AAmatrix[14][1]=0.332533; AAmatrix[2][14]=AAmatrix[14][2]=0.161787; AAmatrix[3][14]=AAmatrix[14][3]=0.394456; AAmatrix[4][14]=AAmatrix[14][4]=0.075382; AAmatrix[5][14]=AAmatrix[14][5]=0.624294; AAmatrix[6][14]=AAmatrix[14][6]=0.419409; AAmatrix[7][14]=AAmatrix[14][7]=0.196961; AAmatrix[8][14]=AAmatrix[14][8]=0.508851; AAmatrix[9][14]=AAmatrix[14][9]=0.078281;  AAmatrix[10][14]=AAmatrix[14][10]=0.249060; AAmatrix[11][14]=AAmatrix[ [...]
+	AAmatrix[0][15]=AAmatrix[15][0]=4.727182; AAmatrix[1][15]=AAmatrix[15][1]=0.858151; AAmatrix[2][15]=AAmatrix[15][2]=4.008358; AAmatrix[3][15]=AAmatrix[15][3]=1.240275; AAmatrix[4][15]=AAmatrix[15][4]=2.784478; AAmatrix[5][15]=AAmatrix[15][5]=1.223828; AAmatrix[6][15]=AAmatrix[15][6]=0.611973; AAmatrix[7][15]=AAmatrix[15][7]=1.739990; AAmatrix[8][15]=AAmatrix[15][8]=0.990012; AAmatrix[9][15]=AAmatrix[15][9]=0.064105;  AAmatrix[10][15]=AAmatrix[15][10]=0.182287; AAmatrix[11][15]=AAmatrix[ [...]
+	AAmatrix[0][16]=AAmatrix[16][0]=2.139501; AAmatrix[1][16]=AAmatrix[16][1]=0.578987; AAmatrix[2][16]=AAmatrix[16][2]=2.000679; AAmatrix[3][16]=AAmatrix[16][3]=0.425860; AAmatrix[4][16]=AAmatrix[16][4]=1.143480; AAmatrix[5][16]=AAmatrix[16][5]=1.080136; AAmatrix[6][16]=AAmatrix[16][6]=0.604545; AAmatrix[7][16]=AAmatrix[16][7]=0.129836; AAmatrix[8][16]=AAmatrix[16][8]=0.584262; AAmatrix[9][16]=AAmatrix[16][9]=1.033739;  AAmatrix[10][16]=AAmatrix[16][10]=0.302936; AAmatrix[11][16]=AAmatrix[ [...]
+	AAmatrix[0][17]=AAmatrix[17][0]=0.180717; AAmatrix[1][17]=AAmatrix[17][1]=0.593607; AAmatrix[2][17]=AAmatrix[17][2]=0.045376; AAmatrix[3][17]=AAmatrix[17][3]=0.029890; AAmatrix[4][17]=AAmatrix[17][4]=0.670128; AAmatrix[5][17]=AAmatrix[17][5]=0.236199; AAmatrix[6][17]=AAmatrix[17][6]=0.077852; AAmatrix[7][17]=AAmatrix[17][7]=0.268491; AAmatrix[8][17]=AAmatrix[17][8]=0.597054; AAmatrix[9][17]=AAmatrix[17][9]=0.111660;  AAmatrix[10][17]=AAmatrix[17][10]=0.619632; AAmatrix[11][17]=AAmatrix[ [...]
+	AAmatrix[0][18]=AAmatrix[18][0]=0.218959; AAmatrix[1][18]=AAmatrix[18][1]=0.314440; AAmatrix[2][18]=AAmatrix[18][2]=0.612025; AAmatrix[3][18]=AAmatrix[18][3]=0.135107; AAmatrix[4][18]=AAmatrix[18][4]=1.165532; AAmatrix[5][18]=AAmatrix[18][5]=0.257336; AAmatrix[6][18]=AAmatrix[18][6]=0.120037; AAmatrix[7][18]=AAmatrix[18][7]=0.054679; AAmatrix[8][18]=AAmatrix[18][8]=5.306834; AAmatrix[9][18]=AAmatrix[18][9]=0.232523;  AAmatrix[10][18]=AAmatrix[18][10]=0.299648; AAmatrix[11][18]=AAmatrix[ [...]
+	AAmatrix[0][19]=AAmatrix[19][0]=2.547870; AAmatrix[1][19]=AAmatrix[19][1]=0.170887; AAmatrix[2][19]=AAmatrix[19][2]=0.083688; AAmatrix[3][19]=AAmatrix[19][3]=0.037967; AAmatrix[4][19]=AAmatrix[19][4]=1.959291; AAmatrix[5][19]=AAmatrix[19][5]=0.210332; AAmatrix[6][19]=AAmatrix[19][6]=0.245034; AAmatrix[7][19]=AAmatrix[19][7]=0.076701; AAmatrix[8][19]=AAmatrix[19][8]=0.119013; AAmatrix[9][19]=AAmatrix[19][9]=10.649107; AAmatrix[10][19]=AAmatrix[19][10]=1.702745; AAmatrix[11][19]=AAmatrix[ [...]
+
+	AAPi[0]=0.079066; AAPi[1]=0.055941; AAPi[2]=0.041977; AAPi[3]=0.053052; AAPi[4]=0.012937; AAPi[5]=0.040767; AAPi[6]=0.071586; AAPi[7]=0.057337; AAPi[8]=0.022355; AAPi[9]=0.062157; AAPi[10]=0.099081; AAPi[11]=0.064600; AAPi[12]=0.022951; AAPi[13]=0.042302; AAPi[14]=0.044040; AAPi[15]=0.061197; AAPi[16]=0.053287; AAPi[17]=0.012066; AAPi[18]=0.034155; AAPi[19]=0.069147;
+
+	/*LG TEST*/
+	/* // old version of matrix
+	AAmatrixT[0][0] = 0;			AAmatrixT[0][1] = 0.449682;		AAmatrixT[0][2] = 0.267582;		AAmatrixT[0][3] = 0.401081;	
+	AAmatrixT[0][4] = 2.31284;		AAmatrixT[0][5] = 0.944706;		AAmatrixT[0][6] = 1.16436;		AAmatrixT[0][7] = 2.10185;	
+	AAmatrixT[0][8] = 0.341479;		AAmatrixT[0][9] = 0.122945;		AAmatrixT[0][10] = 0.391826;	AAmatrixT[0][11] = 0.556137;	
+	AAmatrixT[0][12] = 1.0503;		AAmatrixT[0][13] = 0.237746;	AAmatrixT[0][14] = 1.23291;		AAmatrixT[0][15] = 4.65523;	
+	AAmatrixT[0][16] = 1.98643;		AAmatrixT[0][17] = 0.179433;	AAmatrixT[0][18] = 0.223517;	AAmatrixT[0][19] = 2.36882;	
+	AAmatrixT[1][0] = 0.449682;		AAmatrixT[1][1] = 0;			AAmatrixT[1][2] = 0.827348;		AAmatrixT[1][3] = 0.132811;	
+	AAmatrixT[1][4] = 0.552587;		AAmatrixT[1][5] = 3.10941;		AAmatrixT[1][6] = 0.442407;		AAmatrixT[1][7] = 0.44398;	
+	AAmatrixT[1][8] = 2.65765;		AAmatrixT[1][9] = 0.134451;		AAmatrixT[1][10] = 0.33036;		AAmatrixT[1][11] = 7.11437;	
+	AAmatrixT[1][12] = 0.477124;	AAmatrixT[1][13] = 0.055544;	AAmatrixT[1][14] = 0.404818;	AAmatrixT[1][15] = 0.897892;	
+	AAmatrixT[1][16] = 0.579784;	AAmatrixT[1][17] = 0.701255;	AAmatrixT[1][18] = 0.342216;	AAmatrixT[1][19] = 0.173721;	
+	AAmatrixT[2][0] = 0.267582;		AAmatrixT[2][1] = 0.827348;		AAmatrixT[2][2] = 0;			AAmatrixT[2][3] = 5.921;	
+	AAmatrixT[2][4] = 0.522133;		AAmatrixT[2][5] = 1.87744;		AAmatrixT[2][6] = 0.599223;		AAmatrixT[2][7] = 1.56619;	
+	AAmatrixT[2][8] = 4.88956;		AAmatrixT[2][9] = 0.216069;		AAmatrixT[2][10] = 0.075149;	AAmatrixT[2][11] = 2.46334;	
+	AAmatrixT[2][12] = 0.370061;	AAmatrixT[2][13] = 0.090929;	AAmatrixT[2][14] = 0.19063;		AAmatrixT[2][15] = 4.29942;	
+	AAmatrixT[2][16] = 2.06149;		AAmatrixT[2][17] = 0.054722;	AAmatrixT[2][18] = 0.658002;	AAmatrixT[2][19] = 0.088856;	
+	AAmatrixT[3][0] = 0.401081;		AAmatrixT[3][1] = 0.132811;		AAmatrixT[3][2] = 5.921;		AAmatrixT[3][3] = 0;	
+	AAmatrixT[3][4] = 0.056428;		AAmatrixT[3][5] = 0.498202;		AAmatrixT[3][6] = 6.37423;		AAmatrixT[3][7] = 0.922928;	
+	AAmatrixT[3][8] = 0.982202;		AAmatrixT[3][9] = 0.010922;		AAmatrixT[3][10] = 0.017176;	AAmatrixT[3][11] = 0.278545;	
+	AAmatrixT[3][12] = 0.022762;	AAmatrixT[3][13] = 0.017714;	AAmatrixT[3][14] = 0.449817;	AAmatrixT[3][15] = 1.26822;	
+	AAmatrixT[3][16] = 0.405969;	AAmatrixT[3][17] = 0.046559;	AAmatrixT[3][18] = 0.147235;	AAmatrixT[3][19] = 0.03872;	
+	AAmatrixT[4][0] = 2.31284;		AAmatrixT[4][1] = 0.552587;		AAmatrixT[4][2] = 0.522133;		AAmatrixT[4][3] = 0.056428;	
+	AAmatrixT[4][4] = 0;			AAmatrixT[4][5] = 0.080602;		AAmatrixT[4][6] = 0.00133;		AAmatrixT[4][7] = 0.529114;	
+	AAmatrixT[4][8] = 0.593147;		AAmatrixT[4][9] = 0.262931;		AAmatrixT[4][10] = 0.541544;	AAmatrixT[4][11] = 0.003892;	
+	AAmatrixT[4][12] = 0.773189;	AAmatrixT[4][13] = 0.950511;	AAmatrixT[4][14] = 0.076565;	AAmatrixT[4][15] = 2.60597;	
+	AAmatrixT[4][16] = 0.993542;	AAmatrixT[4][17] = 0.659458;	AAmatrixT[4][18] = 1.09531;		AAmatrixT[4][19] = 1.74588;	
+	AAmatrixT[5][0] = 0.944706;		AAmatrixT[5][1] = 3.10941;		AAmatrixT[5][2] = 1.87744;		AAmatrixT[5][3] = 0.498202;	
+	AAmatrixT[5][4] = 0.080602;		AAmatrixT[5][5] = 0;			AAmatrixT[5][6] = 4.7998;		AAmatrixT[5][7] = 0.279365;	
+	AAmatrixT[5][8] = 5.178;		AAmatrixT[5][9] = 0.073719;		AAmatrixT[5][10] = 0.61329;		AAmatrixT[5][11] = 3.46677;	
+	AAmatrixT[5][12] = 1.65667;		AAmatrixT[5][13] = 0.033627;	AAmatrixT[5][14] = 0.69839;		AAmatrixT[5][15] = 1.2058;	
+	AAmatrixT[5][16] = 1.02734;		AAmatrixT[5][17] = 0.249044;	AAmatrixT[5][18] = 0.244886;	AAmatrixT[5][19] = 0.204644;	
+	AAmatrixT[6][0] = 1.16436;		AAmatrixT[6][1] = 0.442407;		AAmatrixT[6][2] = 0.599223;		AAmatrixT[6][3] = 6.37423;	
+	AAmatrixT[6][4] = 0.00133;		AAmatrixT[6][5] = 4.7998;		AAmatrixT[6][6] = 0;			AAmatrixT[6][7] = 0.407773;	
+	AAmatrixT[6][8] = 0.458209;		AAmatrixT[6][9] = 0.056153;		AAmatrixT[6][10] = 0.086633;	AAmatrixT[6][11] = 2.16893;	
+	AAmatrixT[6][12] = 0.183748;	AAmatrixT[6][13] = 0.024362;	AAmatrixT[6][14] = 0.523437;	AAmatrixT[6][15] = 0.667092;	
+	AAmatrixT[6][16] = 0.659097;	AAmatrixT[6][17] = 0.099542;	AAmatrixT[6][18] = 0.140547;	AAmatrixT[6][19] = 0.278624;	
+	AAmatrixT[7][0] = 2.10185;		AAmatrixT[7][1] = 0.44398;		AAmatrixT[7][2] = 1.56619;		AAmatrixT[7][3] = 0.922928;	
+	AAmatrixT[7][4] = 0.529114;		AAmatrixT[7][5] = 0.279365;		AAmatrixT[7][6] = 0.407773;		AAmatrixT[7][7] = 0;	
+	AAmatrixT[7][8] = 0.30432;		AAmatrixT[7][9] = 0.008454;		AAmatrixT[7][10] = 0.047556;	AAmatrixT[7][11] = 0.313114;	
+	AAmatrixT[7][12] = 0.137976;	AAmatrixT[7][13] = 0.080743;	AAmatrixT[7][14] = 0.226307;	AAmatrixT[7][15] = 1.78478;	
+	AAmatrixT[7][16] = 0.114336;	AAmatrixT[7][17] = 0.292882;	AAmatrixT[7][18] = 0.056885;	AAmatrixT[7][19] = 0.075577;	
+	AAmatrixT[8][0] = 0.341479;		AAmatrixT[8][1] = 2.65765;		AAmatrixT[8][2] = 4.88956;		AAmatrixT[8][3] = 0.982202;	
+	AAmatrixT[8][4] = 0.593147;		AAmatrixT[8][5] = 5.178;		AAmatrixT[8][6] = 0.458209;		AAmatrixT[8][7] = 0.30432;	
+	AAmatrixT[8][8] = 0;			AAmatrixT[8][9] = 0.106232;		AAmatrixT[8][10] = 0.363554;	AAmatrixT[8][11] = 0.682564;	
+	AAmatrixT[8][12] = 0.395265;	AAmatrixT[8][13] = 0.616582;	AAmatrixT[8][14] = 0.545492;	AAmatrixT[8][15] = 0.947402;	
+	AAmatrixT[8][16] = 0.526423;	AAmatrixT[8][17] = 0.559689;	AAmatrixT[8][18] = 5.44623;		AAmatrixT[8][19] = 0.108961;	
+	AAmatrixT[9][0] = 0.122945;		AAmatrixT[9][1] = 0.134451;		AAmatrixT[9][2] = 0.216069;		AAmatrixT[9][3] = 0.010922;	
+	AAmatrixT[9][4] = 0.262931;		AAmatrixT[9][5] = 0.073719;		AAmatrixT[9][6] = 0.056153;		AAmatrixT[9][7] = 0.008454;	
+	AAmatrixT[9][8] = 0.106232;		AAmatrixT[9][9] = 0;			AAmatrixT[9][10] = 3.80151;		AAmatrixT[9][11] = 0.173179;	
+	AAmatrixT[9][12] = 3.84902;		AAmatrixT[9][13] = 1.02066;		AAmatrixT[9][14] = 0.086269;	AAmatrixT[9][15] = 0.063251;	
+	AAmatrixT[9][16] = 0.992803;	AAmatrixT[9][17] = 0.121839;	AAmatrixT[9][18] = 0.238891;	AAmatrixT[9][19] = 9.41677;	
+	AAmatrixT[10][0] = 0.391826;	AAmatrixT[10][1] = 0.33036;		AAmatrixT[10][2] = 0.075149;	AAmatrixT[10][3] = 0.017176;	
+	AAmatrixT[10][4] = 0.541544;	AAmatrixT[10][5] = 0.61329;		AAmatrixT[10][6] = 0.086633;	AAmatrixT[10][7] = 0.047556;	
+	AAmatrixT[10][8] = 0.363554;	AAmatrixT[10][9] = 3.80151;		AAmatrixT[10][10] = 0;			AAmatrixT[10][11] = 0.145273;	
+	AAmatrixT[10][12] = 5.83627;	AAmatrixT[10][13] = 2.42627;	AAmatrixT[10][14] = 0.265077;	AAmatrixT[10][15] = 0.184361;	
+	AAmatrixT[10][16] = 0.286481;	AAmatrixT[10][17] = 0.649934;	AAmatrixT[10][18] = 0.292232;	AAmatrixT[10][19] = 1.51964;	
+	AAmatrixT[11][0] = 0.556137;	AAmatrixT[11][1] = 7.11437;		AAmatrixT[11][2] = 2.46334;		AAmatrixT[11][3] = 0.278545;	
+	AAmatrixT[11][4] = 0.003892;	AAmatrixT[11][5] = 3.46677;		AAmatrixT[11][6] = 2.16893;		AAmatrixT[11][7] = 0.313114;	
+	AAmatrixT[11][8] = 0.682564;	AAmatrixT[11][9] = 0.173179;	AAmatrixT[11][10] = 0.145273;	AAmatrixT[11][11] = 0;	
+	AAmatrixT[11][12] = 0.672252;	AAmatrixT[11][13] = 0.026721;	AAmatrixT[11][14] = 0.445474;	AAmatrixT[11][15] = 0.755746;	
+	AAmatrixT[11][16] = 1.15218;	AAmatrixT[11][17] = 0.047995;	AAmatrixT[11][18] = 0.138336;	AAmatrixT[11][19] = 0.184432;	
+	AAmatrixT[12][0] = 1.0503;		AAmatrixT[12][1] = 0.477124;	AAmatrixT[12][2] = 0.370061;	AAmatrixT[12][3] = 0.022762;	
+	AAmatrixT[12][4] = 0.773189;	AAmatrixT[12][5] = 1.65667;		AAmatrixT[12][6] = 0.183748;	AAmatrixT[12][7] = 0.137976;	
+	AAmatrixT[12][8] = 0.395265;	AAmatrixT[12][9] = 3.84902;		AAmatrixT[12][10] = 5.83627;	AAmatrixT[12][11] = 0.672252;	
+	AAmatrixT[12][12] = 0;			AAmatrixT[12][13] = 1.62617;	AAmatrixT[12][14] = 0.096861;	AAmatrixT[12][15] = 0.319101;	
+	AAmatrixT[12][16] = 1.86695;	AAmatrixT[12][17] = 0.660667;	AAmatrixT[12][18] = 0.436403;	AAmatrixT[12][19] = 1.59505;	
+	AAmatrixT[13][0] = 0.237746;	AAmatrixT[13][1] = 0.055544;	AAmatrixT[13][2] = 0.090929;	AAmatrixT[13][3] = 0.017714;	
+	AAmatrixT[13][4] = 0.950511;	AAmatrixT[13][5] = 0.033627;	AAmatrixT[13][6] = 0.024362;	AAmatrixT[13][7] = 0.080743;	
+	AAmatrixT[13][8] = 0.616582;	AAmatrixT[13][9] = 1.02066;		AAmatrixT[13][10] = 2.42627;	AAmatrixT[13][11] = 0.026721;	
+	AAmatrixT[13][12] = 1.62617;	AAmatrixT[13][13] = 0;			AAmatrixT[13][14] = 0.104849;	AAmatrixT[13][15] = 0.355654;	
+	AAmatrixT[13][16] = 0.145526;	AAmatrixT[13][17] = 2.42582;	AAmatrixT[13][18] = 7.59878;	AAmatrixT[13][19] = 0.578417;	
+	AAmatrixT[14][0] = 1.23291;		AAmatrixT[14][1] = 0.404818;	AAmatrixT[14][2] = 0.19063;		AAmatrixT[14][3] = 0.449817;	
+	AAmatrixT[14][4] = 0.076565;	AAmatrixT[14][5] = 0.69839;		AAmatrixT[14][6] = 0.523437;	AAmatrixT[14][7] = 0.226307;	
+	AAmatrixT[14][8] = 0.545492;	AAmatrixT[14][9] = 0.086269;	AAmatrixT[14][10] = 0.265077;	AAmatrixT[14][11] = 0.445474;	
+	AAmatrixT[14][12] = 0.096861;	AAmatrixT[14][13] = 0.104849;	AAmatrixT[14][14] = 0;			AAmatrixT[14][15] = 1.42481;	
+	AAmatrixT[14][16] = 0.592443;	AAmatrixT[14][17] = 0.118287;	AAmatrixT[14][18] = 0.109774;	AAmatrixT[14][19] = 0.302548;	
+	AAmatrixT[15][0] = 4.65523;		AAmatrixT[15][1] = 0.897892;	AAmatrixT[15][2] = 4.29942;		AAmatrixT[15][3] = 1.26822;	
+	AAmatrixT[15][4] = 2.60597;		AAmatrixT[15][5] = 1.2058;		AAmatrixT[15][6] = 0.667092;	AAmatrixT[15][7] = 1.78478;	
+	AAmatrixT[15][8] = 0.947402;	AAmatrixT[15][9] = 0.063251;	AAmatrixT[15][10] = 0.184361;	AAmatrixT[15][11] = 0.755746;	
+	AAmatrixT[15][12] = 0.319101;	AAmatrixT[15][13] = 0.355654;	AAmatrixT[15][14] = 1.42481;	AAmatrixT[15][15] = 0;	
+	AAmatrixT[15][16] = 6.26607;	AAmatrixT[15][17] = 0.267487;	AAmatrixT[15][18] = 0.407468;	AAmatrixT[15][19] = 0.062285;	
+	AAmatrixT[16][0] = 1.98643;		AAmatrixT[16][1] = 0.579784;	AAmatrixT[16][2] = 2.06149;		AAmatrixT[16][3] = 0.405969;	
+	AAmatrixT[16][4] = 0.993542;	AAmatrixT[16][5] = 1.02734;		AAmatrixT[16][6] = 0.659097;	AAmatrixT[16][7] = 0.114336;	
+	AAmatrixT[16][8] = 0.526423;	AAmatrixT[16][9] = 0.992803;	AAmatrixT[16][10] = 0.286481;	AAmatrixT[16][11] = 1.15218;	
+	AAmatrixT[16][12] = 1.86695;	AAmatrixT[16][13] = 0.145526;	AAmatrixT[16][14] = 0.592443;	AAmatrixT[16][15] = 6.26607;	
+	AAmatrixT[16][16] = 0;			AAmatrixT[16][17] = 0.144967;	AAmatrixT[16][18] = 0.236493;	AAmatrixT[16][19] = 1.94732;	
+	AAmatrixT[17][0] = 0.179433;	AAmatrixT[17][1] = 0.701255;	AAmatrixT[17][2] = 0.054722;	AAmatrixT[17][3] = 0.046559;	
+	AAmatrixT[17][4] = 0.659458;	AAmatrixT[17][5] = 0.249044;	AAmatrixT[17][6] = 0.099542;	AAmatrixT[17][7] = 0.292882;	
+	AAmatrixT[17][8] = 0.559689;	AAmatrixT[17][9] = 0.121839;	AAmatrixT[17][10] = 0.649934;	AAmatrixT[17][11] = 0.047995;	
+	AAmatrixT[17][12] = 0.660667;	AAmatrixT[17][13] = 2.42582;	AAmatrixT[17][14] = 0.118287;	AAmatrixT[17][15] = 0.267487;	
+	AAmatrixT[17][16] = 0.144967;	AAmatrixT[17][17] = 0;			AAmatrixT[17][18] = 3.34452;	AAmatrixT[17][19] = 0.201078;	
+	AAmatrixT[18][0] = 0.223517;	AAmatrixT[18][1] = 0.342216;	AAmatrixT[18][2] = 0.658002;	AAmatrixT[18][3] = 0.147235;	
+	AAmatrixT[18][4] = 1.09531;		AAmatrixT[18][5] = 0.244886;	AAmatrixT[18][6] = 0.140547;	AAmatrixT[18][7] = 0.056885;	
+	AAmatrixT[18][8] = 5.44623;		AAmatrixT[18][9] = 0.238891;	AAmatrixT[18][10] = 0.292232;	AAmatrixT[18][11] = 0.138336;	
+	AAmatrixT[18][12] = 0.436403;	AAmatrixT[18][13] = 7.59878;	AAmatrixT[18][14] = 0.109774;	AAmatrixT[18][15] = 0.407468;	
+	AAmatrixT[18][16] = 0.236493;	AAmatrixT[18][17] = 3.34452;	AAmatrixT[18][18] = 0;			AAmatrixT[18][19] = 0.235819;	
+	AAmatrixT[19][0] = 2.36882;		AAmatrixT[19][1] = 0.173721;	AAmatrixT[19][2] = 0.088856;	AAmatrixT[19][3] = 0.03872;	
+	AAmatrixT[19][4] = 1.74588;		AAmatrixT[19][5] = 0.204644;	AAmatrixT[19][6] = 0.278624;	AAmatrixT[19][7] = 0.075577;	
+	AAmatrixT[19][8] = 0.108961;	AAmatrixT[19][9] = 9.41677;		AAmatrixT[19][10] = 1.51964;	AAmatrixT[19][11] = 0.184432;	
+	AAmatrixT[19][12] = 1.59505;	AAmatrixT[19][13] = 0.578417;	AAmatrixT[19][14] = 0.302548;	AAmatrixT[19][15] = 0.062285;	
+	AAmatrixT[19][16] = 1.94732;	AAmatrixT[19][17] = 0.201078;	AAmatrixT[19][18] = 0.235819;	AAmatrixT[19][19] = 0;	
+
+	AAPiT[0] = 0.079611;
+	AAPiT[1] = 0.053191;
+	AAPiT[2] = 0.039948;
+	AAPiT[3] = 0.050634;
+	AAPiT[4] = 0.01359;
+	AAPiT[5] = 0.038611;
+	AAPiT[6] = 0.066539;
+	AAPiT[7] = 0.059913;
+	AAPiT[8] = 0.021738;
+	AAPiT[9] = 0.063589;
+	AAPiT[10] = 0.105134;
+	AAPiT[11] = 0.061845;
+	AAPiT[12] = 0.02299;
+	AAPiT[13] = 0.044365;
+	AAPiT[14] = 0.044909;
+	AAPiT[15] = 0.059477;
+	AAPiT[16] = 0.054114;
+	AAPiT[17] = 0.012588;
+	AAPiT[18] = 0.035709;
+	AAPiT[19] = 0.071505;
+	
+		for(int gb1=0; gb1<20; gb1++)
+		{
+			if(AAPiT[gb1]!=AAPiT[gb1]) {cout<<"ERROR in base frequency translation check in LG model"<<endl; gb1--;}
+			
+			for(int gb2=0; gb2<20; gb2++)
+			{
+				if(AAmatrix[gb1][gb2]!=AAmatrixT[gb1][gb2]) {cout<<"ERROR in substitution matrix translation check in LG model"<<endl; gb2--;}
+			}
+		}
+	*/
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==14)
+	{
+
+	
+	/*
+		HIVb
+		
+		Nickle DC, Heath L, Jensen MA, Gilbert PB, Mullins JI, Kosakovsky Pond SL. (2007) HIV-Specific Probabilistic Models 
+		of Protein Evolution. PLoS ONE. Jun 6;2:e503.
+	*/
+	AAmatrix[0][0] = 0;				AAmatrix[0][1] = 0.307507;		AAmatrix[0][2] = 0.005;			AAmatrix[0][3] = 1.45504;	
+	AAmatrix[0][4] = 0.123758;		AAmatrix[0][5] = 0.0551128;		AAmatrix[0][6] = 1.48135;		AAmatrix[0][7] = 2.13536;	
+	AAmatrix[0][8] = 0.0847613;		AAmatrix[0][9] = 0.005;			AAmatrix[0][10] = 0.215256;		AAmatrix[0][11] = 0.005;	
+	AAmatrix[0][12] = 0.0186643;	AAmatrix[0][13] = 0.0141269;	AAmatrix[0][14] = 2.12217;		AAmatrix[0][15] = 2.46633;	
+	AAmatrix[0][16] = 15.9183;		AAmatrix[0][17] = 0.005;		AAmatrix[0][18] = 0.005;		AAmatrix[0][19] = 7.61428;	
+	AAmatrix[1][0] = 0.307507;		AAmatrix[1][1] = 0;				AAmatrix[1][2] = 0.295543;		AAmatrix[1][3] = 0.005;	
+	AAmatrix[1][4] = 0.351721;		AAmatrix[1][5] = 3.4215;		AAmatrix[1][6] = 0.0749218;		AAmatrix[1][7] = 3.65345;	
+	AAmatrix[1][8] = 9.04044;		AAmatrix[1][9] = 0.677289;		AAmatrix[1][10] = 0.701427;		AAmatrix[1][11] = 20.45;	
+	AAmatrix[1][12] = 2.51394;		AAmatrix[1][13] = 0.005;		AAmatrix[1][14] = 1.28355;		AAmatrix[1][15] = 3.4791;	
+	AAmatrix[1][16] = 2.86868;		AAmatrix[1][17] = 0.991338;		AAmatrix[1][18] = 0.00991826;	AAmatrix[1][19] = 0.0812454;	
+	AAmatrix[2][0] = 0.005;			AAmatrix[2][1] = 0.295543;		AAmatrix[2][2] = 0;				AAmatrix[2][3] = 17.6612;	
+	AAmatrix[2][4] = 0.0860642;		AAmatrix[2][5] = 0.672052;		AAmatrix[2][6] = 0.0792633;		AAmatrix[2][7] = 0.323401;	
+	AAmatrix[2][8] = 7.64585;		AAmatrix[2][9] = 0.680565;		AAmatrix[2][10] = 0.005;		AAmatrix[2][11] = 7.90443;	
+	AAmatrix[2][12] = 0.005;		AAmatrix[2][13] = 0.005;		AAmatrix[2][14] = 0.00739578;	AAmatrix[2][15] = 13.1447;	
+	AAmatrix[2][16] = 6.88667;		AAmatrix[2][17] = 0.005;		AAmatrix[2][18] = 1.76417;		AAmatrix[2][19] = 0.026656;	
+	AAmatrix[3][0] = 1.45504;		AAmatrix[3][1] = 0.005;			AAmatrix[3][2] = 17.6612;		AAmatrix[3][3] = 0;	
+	AAmatrix[3][4] = 0.005;			AAmatrix[3][5] = 0.005;			AAmatrix[3][6] = 10.5872;		AAmatrix[3][7] = 2.83806;	
+	AAmatrix[3][8] = 1.9169;		AAmatrix[3][9] = 0.0176792;		AAmatrix[3][10] = 0.00876048;	AAmatrix[3][11] = 0.005;	
+	AAmatrix[3][12] = 0.005;		AAmatrix[3][13] = 0.005;		AAmatrix[3][14] = 0.0342658;	AAmatrix[3][15] = 0.52823;	
+	AAmatrix[3][16] = 0.274724;		AAmatrix[3][17] = 0.005;		AAmatrix[3][18] = 0.674653;		AAmatrix[3][19] = 1.04793;	
+	AAmatrix[4][0] = 0.123758;		AAmatrix[4][1] = 0.351721;		AAmatrix[4][2] = 0.0860642;		AAmatrix[4][3] = 0.005;	
+	AAmatrix[4][4] = 0;				AAmatrix[4][5] = 0.005;			AAmatrix[4][6] = 0.005;			AAmatrix[4][7] = 0.897871;	
+	AAmatrix[4][8] = 0.240073;		AAmatrix[4][9] = 0.005;			AAmatrix[4][10] = 0.129777;		AAmatrix[4][11] = 0.005;	
+	AAmatrix[4][12] = 0.005;		AAmatrix[4][13] = 9.29815;		AAmatrix[4][14] = 0.005;		AAmatrix[4][15] = 4.69314;	
+	AAmatrix[4][16] = 0.739969;		AAmatrix[4][17] = 2.63277;		AAmatrix[4][18] = 7.57932;		AAmatrix[4][19] = 0.420027;	
+	AAmatrix[5][0] = 0.0551128;		AAmatrix[5][1] = 3.4215;		AAmatrix[5][2] = 0.672052;		AAmatrix[5][3] = 0.005;	
+	AAmatrix[5][4] = 0.005;			AAmatrix[5][5] = 0;				AAmatrix[5][6] = 2.5602;		AAmatrix[5][7] = 0.0619137;	
+	AAmatrix[5][8] = 7.05545;		AAmatrix[5][9] = 0.005;			AAmatrix[5][10] = 1.49456;		AAmatrix[5][11] = 6.54737;	
+	AAmatrix[5][12] = 0.303676;		AAmatrix[5][13] = 0.005;		AAmatrix[5][14] = 4.47211;		AAmatrix[5][15] = 0.116311;	
+	AAmatrix[5][16] = 0.243589;		AAmatrix[5][17] = 0.026656;		AAmatrix[5][18] = 0.113033;		AAmatrix[5][19] = 0.0209153;	
+	AAmatrix[6][0] = 1.48135;		AAmatrix[6][1] = 0.0749218;		AAmatrix[6][2] = 0.0792633;		AAmatrix[6][3] = 10.5872;	
+	AAmatrix[6][4] = 0.005;			AAmatrix[6][5] = 2.5602;		AAmatrix[6][6] = 0;				AAmatrix[6][7] = 3.92775;	
+	AAmatrix[6][8] = 0.11974;		AAmatrix[6][9] = 0.00609079;	AAmatrix[6][10] = 0.005;		AAmatrix[6][11] = 4.61482;	
+	AAmatrix[6][12] = 0.175789;		AAmatrix[6][13] = 0.005;		AAmatrix[6][14] = 0.0120226;	AAmatrix[6][15] = 0.005;	
+	AAmatrix[6][16] = 0.289774;		AAmatrix[6][17] = 0.005;		AAmatrix[6][18] = 0.0792633;	AAmatrix[6][19] = 1.02847;	
+	AAmatrix[7][0] = 2.13536;		AAmatrix[7][1] = 3.65345;		AAmatrix[7][2] = 0.323401;		AAmatrix[7][3] = 2.83806;	
+	AAmatrix[7][4] = 0.897871;		AAmatrix[7][5] = 0.0619137;		AAmatrix[7][6] = 3.92775;		AAmatrix[7][7] = 0;	
+	AAmatrix[7][8] = 0.005;			AAmatrix[7][9] = 0.005;			AAmatrix[7][10] = 0.005;		AAmatrix[7][11] = 0.521705;	
+	AAmatrix[7][12] = 0.005;		AAmatrix[7][13] = 0.291561;		AAmatrix[7][14] = 0.005;		AAmatrix[7][15] = 4.38041;	
+	AAmatrix[7][16] = 0.369615;		AAmatrix[7][17] = 1.21674;		AAmatrix[7][18] = 0.005;		AAmatrix[7][19] = 0.953155;	
+	AAmatrix[8][0] = 0.0847613;		AAmatrix[8][1] = 9.04044;		AAmatrix[8][2] = 7.64585;		AAmatrix[8][3] = 1.9169;	
+	AAmatrix[8][4] = 0.240073;		AAmatrix[8][5] = 7.05545;		AAmatrix[8][6] = 0.11974;		AAmatrix[8][7] = 0.005;	
+	AAmatrix[8][8] = 0;				AAmatrix[8][9] = 0.103111;		AAmatrix[8][10] = 1.74171;		AAmatrix[8][11] = 0.005;	
+	AAmatrix[8][12] = 0.005;		AAmatrix[8][13] = 0.145558;		AAmatrix[8][14] = 2.45318;		AAmatrix[8][15] = 0.382747;	
+	AAmatrix[8][16] = 0.711594;		AAmatrix[8][17] = 0.0695179;	AAmatrix[8][18] = 18.6943;		AAmatrix[8][19] = 0.005;	
+	AAmatrix[9][0] = 0.005;			AAmatrix[9][1] = 0.677289;		AAmatrix[9][2] = 0.680565;		AAmatrix[9][3] = 0.0176792;	
+	AAmatrix[9][4] = 0.005;			AAmatrix[9][5] = 0.005;			AAmatrix[9][6] = 0.00609079;	AAmatrix[9][7] = 0.005;	
+	AAmatrix[9][8] = 0.103111;		AAmatrix[9][9] = 0;				AAmatrix[9][10] = 5.95879;		AAmatrix[9][11] = 0.322319;	
+	AAmatrix[9][12] = 11.2065;		AAmatrix[9][13] = 3.39836;		AAmatrix[9][14] = 0.0410593;	AAmatrix[9][15] = 1.21803;	
+	AAmatrix[9][16] = 8.61217;		AAmatrix[9][17] = 0.005;		AAmatrix[9][18] = 0.148168;		AAmatrix[9][19] = 17.7389;	
+	AAmatrix[10][0] = 0.215256;		AAmatrix[10][1] = 0.701427;		AAmatrix[10][2] = 0.005;		AAmatrix[10][3] = 0.00876048;	
+	AAmatrix[10][4] = 0.129777;		AAmatrix[10][5] = 1.49456;		AAmatrix[10][6] = 0.005;		AAmatrix[10][7] = 0.005;	
+	AAmatrix[10][8] = 1.74171;		AAmatrix[10][9] = 5.95879;		AAmatrix[10][10] = 0;			AAmatrix[10][11] = 0.0814995;	
+	AAmatrix[10][12] = 5.31961;		AAmatrix[10][13] = 8.52484;		AAmatrix[10][14] = 2.07757;		AAmatrix[10][15] = 0.927656;	
+	AAmatrix[10][16] = 0.0437673;	AAmatrix[10][17] = 0.748843;	AAmatrix[10][18] = 0.111986;	AAmatrix[10][19] = 1.41036;	
+	AAmatrix[11][0] = 0.005;		AAmatrix[11][1] = 20.45;		AAmatrix[11][2] = 7.90443;		AAmatrix[11][3] = 0.005;	
+	AAmatrix[11][4] = 0.005;		AAmatrix[11][5] = 6.54737;		AAmatrix[11][6] = 4.61482;		AAmatrix[11][7] = 0.521705;	
+	AAmatrix[11][8] = 0.005;		AAmatrix[11][9] = 0.322319;		AAmatrix[11][10] = 0.0814995;	AAmatrix[11][11] = 0;	
+	AAmatrix[11][12] = 1.28246;		AAmatrix[11][13] = 0.0342658;	AAmatrix[11][14] = 0.0313862;	AAmatrix[11][15] = 0.504111;	
+	AAmatrix[11][16] = 4.67142;		AAmatrix[11][17] = 0.005;		AAmatrix[11][18] = 0.005;		AAmatrix[11][19] = 0.265829;	
+	AAmatrix[12][0] = 0.0186643;	AAmatrix[12][1] = 2.51394;		AAmatrix[12][2] = 0.005;		AAmatrix[12][3] = 0.005;	
+	AAmatrix[12][4] = 0.005;		AAmatrix[12][5] = 0.303676;		AAmatrix[12][6] = 0.175789;		AAmatrix[12][7] = 0.005;	
+	AAmatrix[12][8] = 0.005;		AAmatrix[12][9] = 11.2065;		AAmatrix[12][10] = 5.31961;		AAmatrix[12][11] = 1.28246;	
+	AAmatrix[12][12] = 0;			AAmatrix[12][13] = 0.188025;	AAmatrix[12][14] = 0.005;		AAmatrix[12][15] = 0.005;	
+	AAmatrix[12][16] = 4.94026;		AAmatrix[12][17] = 0.089078;	AAmatrix[12][18] = 0.005;		AAmatrix[12][19] = 6.8532;	
+	AAmatrix[13][0] = 0.0141269;	AAmatrix[13][1] = 0.005;		AAmatrix[13][2] = 0.005;		AAmatrix[13][3] = 0.005;	
+	AAmatrix[13][4] = 9.29815;		AAmatrix[13][5] = 0.005;		AAmatrix[13][6] = 0.005;		AAmatrix[13][7] = 0.291561;	
+	AAmatrix[13][8] = 0.145558;		AAmatrix[13][9] = 3.39836;		AAmatrix[13][10] = 8.52484;		AAmatrix[13][11] = 0.0342658;	
+	AAmatrix[13][12] = 0.188025;	AAmatrix[13][13] = 0;			AAmatrix[13][14] = 0.005;		AAmatrix[13][15] = 0.956472;	
+	AAmatrix[13][16] = 0.0141269;	AAmatrix[13][17] = 0.829343;	AAmatrix[13][18] = 15.34;		AAmatrix[13][19] = 0.723274;	
+	AAmatrix[14][0] = 2.12217;		AAmatrix[14][1] = 1.28355;		AAmatrix[14][2] = 0.00739578;	AAmatrix[14][3] = 0.0342658;	
+	AAmatrix[14][4] = 0.005;		AAmatrix[14][5] = 4.47211;		AAmatrix[14][6] = 0.0120226;	AAmatrix[14][7] = 0.005;	
+	AAmatrix[14][8] = 2.45318;		AAmatrix[14][9] = 0.0410593;	AAmatrix[14][10] = 2.07757;		AAmatrix[14][11] = 0.0313862;	
+	AAmatrix[14][12] = 0.005;		AAmatrix[14][13] = 0.005;		AAmatrix[14][14] = 0;			AAmatrix[14][15] = 5.37762;	
+	AAmatrix[14][16] = 2.01417;		AAmatrix[14][17] = 0.0444506;	AAmatrix[14][18] = 0.0304381;	AAmatrix[14][19] = 0.005;	
+	AAmatrix[15][0] = 2.46633;		AAmatrix[15][1] = 3.4791;		AAmatrix[15][2] = 13.1447;		AAmatrix[15][3] = 0.52823;	
+	AAmatrix[15][4] = 4.69314;		AAmatrix[15][5] = 0.116311;		AAmatrix[15][6] = 0.005;		AAmatrix[15][7] = 4.38041;	
+	AAmatrix[15][8] = 0.382747;		AAmatrix[15][9] = 1.21803;		AAmatrix[15][10] = 0.927656;	AAmatrix[15][11] = 0.504111;	
+	AAmatrix[15][12] = 0.005;		AAmatrix[15][13] = 0.956472;	AAmatrix[15][14] = 5.37762;		AAmatrix[15][15] = 0;	
+	AAmatrix[15][16] = 8.93107;		AAmatrix[15][17] = 0.0248728;	AAmatrix[15][18] = 0.648024;	AAmatrix[15][19] = 0.0749218;	
+	AAmatrix[16][0] = 15.9183;		AAmatrix[16][1] = 2.86868;		AAmatrix[16][2] = 6.88667;		AAmatrix[16][3] = 0.274724;	
+	AAmatrix[16][4] = 0.739969;		AAmatrix[16][5] = 0.243589;		AAmatrix[16][6] = 0.289774;		AAmatrix[16][7] = 0.369615;	
+	AAmatrix[16][8] = 0.711594;		AAmatrix[16][9] = 8.61217;		AAmatrix[16][10] = 0.0437673;	AAmatrix[16][11] = 4.67142;	
+	AAmatrix[16][12] = 4.94026;		AAmatrix[16][13] = 0.0141269;	AAmatrix[16][14] = 2.01417;		AAmatrix[16][15] = 8.93107;	
+	AAmatrix[16][16] = 0;			AAmatrix[16][17] = 0.005;		AAmatrix[16][18] = 0.105652;	AAmatrix[16][19] = 0.709226;	
+	AAmatrix[17][0] = 0.005;		AAmatrix[17][1] = 0.991338;		AAmatrix[17][2] = 0.005;		AAmatrix[17][3] = 0.005;	
+	AAmatrix[17][4] = 2.63277;		AAmatrix[17][5] = 0.026656;		AAmatrix[17][6] = 0.005;		AAmatrix[17][7] = 1.21674;	
+	AAmatrix[17][8] = 0.0695179;	AAmatrix[17][9] = 0.005;		AAmatrix[17][10] = 0.748843;	AAmatrix[17][11] = 0.005;	
+	AAmatrix[17][12] = 0.089078;	AAmatrix[17][13] = 0.829343;	AAmatrix[17][14] = 0.0444506;	AAmatrix[17][15] = 0.0248728;	
+	AAmatrix[17][16] = 0.005;		AAmatrix[17][17] = 0;			AAmatrix[17][18] = 1.28022;		AAmatrix[17][19] = 0.005;	
+	AAmatrix[18][0] = 0.005;		AAmatrix[18][1] = 0.00991826;	AAmatrix[18][2] = 1.76417;		AAmatrix[18][3] = 0.674653;	
+	AAmatrix[18][4] = 7.57932;		AAmatrix[18][5] = 0.113033;		AAmatrix[18][6] = 0.0792633;	AAmatrix[18][7] = 0.005;	
+	AAmatrix[18][8] = 18.6943;		AAmatrix[18][9] = 0.148168;		AAmatrix[18][10] = 0.111986;	AAmatrix[18][11] = 0.005;	
+	AAmatrix[18][12] = 0.005;		AAmatrix[18][13] = 15.34;		AAmatrix[18][14] = 0.0304381;	AAmatrix[18][15] = 0.648024;	
+	AAmatrix[18][16] = 0.105652;	AAmatrix[18][17] = 1.28022;		AAmatrix[18][18] = 0;			AAmatrix[18][19] = 0.0410593;	
+	AAmatrix[19][0] = 7.61428;		AAmatrix[19][1] = 0.0812454;	AAmatrix[19][2] = 0.026656;		AAmatrix[19][3] = 1.04793;	
+	AAmatrix[19][4] = 0.420027;		AAmatrix[19][5] = 0.0209153;	AAmatrix[19][6] = 1.02847;		AAmatrix[19][7] = 0.953155;	
+	AAmatrix[19][8] = 0.005;		AAmatrix[19][9] = 17.7389;		AAmatrix[19][10] = 1.41036;		AAmatrix[19][11] = 0.265829;	
+	AAmatrix[19][12] = 6.8532;		AAmatrix[19][13] = 0.723274;	AAmatrix[19][14] = 0.005;		AAmatrix[19][15] = 0.0749218;	
+	AAmatrix[19][16] = 0.709226;	AAmatrix[19][17] = 0.005;		AAmatrix[19][18] = 0.0410593;	AAmatrix[19][19] = 0;	
+
+	AAPi[0] = 0.0604902;
+	AAPi[1] = 0.0660397;
+	AAPi[2] = 0.0441278;
+	AAPi[3] = 0.042109;
+	AAPi[4] = 0.0200759;
+	AAPi[5] = 0.0536065;
+	AAPi[6] = 0.0715674;
+	AAPi[7] = 0.0723082;
+	AAPi[8] = 0.0222939;
+	AAPi[9] = 0.0697306;
+	AAPi[10] = 0.0988511;
+	AAPi[11] = 0.0569682;
+	AAPi[12] = 0.0197683;
+	AAPi[13] = 0.0288094;
+	AAPi[14] = 0.0460253;
+	AAPi[15] = 0.0506043;
+	AAPi[16] = 0.0536368;
+	AAPi[17] = 0.0330116;
+	AAPi[18] = 0.0283502;
+	AAPi[19] = 0.0616252;
+
+	}
+	
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	else
+	if(modelnumber==15)
+	{
+
+	/*
+		HIVw
+		
+		Nickle DC, Heath L, Jensen MA, Gilbert PB, Mullins JI, Kosakovsky Pond SL. (2007) HIV-Specific Probabilistic Models 
+		of Protein Evolution. PLoS ONE. Jun 6;2:e503.
+	*/
+	AAmatrix[0][0] = 0;				AAmatrix[0][1] = 0.0744808;		AAmatrix[0][2] = 0.617509;		AAmatrix[0][3] = 4.43521;	
+	AAmatrix[0][4] = 0.167653;		AAmatrix[0][5] = 0.005;			AAmatrix[0][6] = 5.56325;		AAmatrix[0][7] = 1.8685;	
+	AAmatrix[0][8] = 0.005;			AAmatrix[0][9] = 0.005;			AAmatrix[0][10] = 0.16024;		AAmatrix[0][11] = 0.592784;	
+	AAmatrix[0][12] = 0.005;		AAmatrix[0][13] = 0.597923;		AAmatrix[0][14] = 1.00981;		AAmatrix[0][15] = 8.5942;	
+	AAmatrix[0][16] = 24.1422;		AAmatrix[0][17] = 0.005;		AAmatrix[0][18] = 0.005;		AAmatrix[0][19] = 24.8094;	
+	AAmatrix[1][0] = 0.0744808;		AAmatrix[1][1] = 0;				AAmatrix[1][2] = 0.16024;		AAmatrix[1][3] = 0.0674539;	
+	AAmatrix[1][4] = 2.86364;		AAmatrix[1][5] = 10.6746;		AAmatrix[1][6] = 0.0251632;		AAmatrix[1][7] = 13.4379;	
+	AAmatrix[1][8] = 6.84405;		AAmatrix[1][9] = 1.34069;		AAmatrix[1][10] = 0.586757;		AAmatrix[1][11] = 39.8897;	
+	AAmatrix[1][12] = 3.28652;		AAmatrix[1][13] = 0.005;		AAmatrix[1][14] = 0.404723;		AAmatrix[1][15] = 8.35024;	
+	AAmatrix[1][16] = 0.928203;		AAmatrix[1][17] = 5.96564;		AAmatrix[1][18] = 0.005;		AAmatrix[1][19] = 0.279425;	
+	AAmatrix[2][0] = 0.617509;		AAmatrix[2][1] = 0.16024;		AAmatrix[2][2] = 0;				AAmatrix[2][3] = 29.4087;	
+	AAmatrix[2][4] = 0.0604932;		AAmatrix[2][5] = 0.342068;		AAmatrix[2][6] = 0.201526;		AAmatrix[2][7] = 0.0604932;	
+	AAmatrix[2][8] = 8.59876;		AAmatrix[2][9] = 0.987028;		AAmatrix[2][10] = 0.005;		AAmatrix[2][11] = 10.6655;	
+	AAmatrix[2][12] = 0.201526;		AAmatrix[2][13] = 0.005;		AAmatrix[2][14] = 0.344848;		AAmatrix[2][15] = 14.5699;	
+	AAmatrix[2][16] = 4.54206;		AAmatrix[2][17] = 0.005;		AAmatrix[2][18] = 5.06475;		AAmatrix[2][19] = 0.0744808;	
+	AAmatrix[3][0] = 4.43521;		AAmatrix[3][1] = 0.0674539;		AAmatrix[3][2] = 29.4087;		AAmatrix[3][3] = 0;	
+	AAmatrix[3][4] = 0.005;			AAmatrix[3][5] = 0.005;			AAmatrix[3][6] = 12.1233;		AAmatrix[3][7] = 10.3969;	
+	AAmatrix[3][8] = 2.31779;		AAmatrix[3][9] = 0.145124;		AAmatrix[3][10] = 0.005;		AAmatrix[3][11] = 0.894313;	
+	AAmatrix[3][12] = 0.005;		AAmatrix[3][13] = 0.005;		AAmatrix[3][14] = 0.005;		AAmatrix[3][15] = 0.427881;	
+	AAmatrix[3][16] = 0.630395;		AAmatrix[3][17] = 0.005;		AAmatrix[3][18] = 2.28154;		AAmatrix[3][19] = 2.91786;	
+	AAmatrix[4][0] = 0.167653;		AAmatrix[4][1] = 2.86364;		AAmatrix[4][2] = 0.0604932;		AAmatrix[4][3] = 0.005;	
+	AAmatrix[4][4] = 0;				AAmatrix[4][5] = 0.005;			AAmatrix[4][6] = 0.005;			AAmatrix[4][7] = 0.0489798;	
+	AAmatrix[4][8] = 0.005;			AAmatrix[4][9] = 0.005;			AAmatrix[4][10] = 0.005;		AAmatrix[4][11] = 0.005;	
+	AAmatrix[4][12] = 0.005;		AAmatrix[4][13] = 0.362959;		AAmatrix[4][14] = 0.005;		AAmatrix[4][15] = 1.12195;	
+	AAmatrix[4][16] = 0.005;		AAmatrix[4][17] = 5.49894;		AAmatrix[4][18] = 8.34835;		AAmatrix[4][19] = 0.005;	
+	AAmatrix[5][0] = 0.005;			AAmatrix[5][1] = 10.6746;		AAmatrix[5][2] = 0.342068;		AAmatrix[5][3] = 0.005;	
+	AAmatrix[5][4] = 0.005;			AAmatrix[5][5] = 0;				AAmatrix[5][6] = 3.20656;		AAmatrix[5][7] = 0.0604932;	
+	AAmatrix[5][8] = 18.5465;		AAmatrix[5][9] = 0.0342252;		AAmatrix[5][10] = 2.89048;		AAmatrix[5][11] = 13.0705;	
+	AAmatrix[5][12] = 0.005;		AAmatrix[5][13] = 0.005;		AAmatrix[5][14] = 3.04502;		AAmatrix[5][15] = 0.16024;	
+	AAmatrix[5][16] = 0.203091;		AAmatrix[5][17] = 0.0443298;	AAmatrix[5][18] = 0.005;		AAmatrix[5][19] = 0.005;	
+	AAmatrix[6][0] = 5.56325;		AAmatrix[6][1] = 0.0251632;		AAmatrix[6][2] = 0.201526;		AAmatrix[6][3] = 12.1233;	
+	AAmatrix[6][4] = 0.005;			AAmatrix[6][5] = 3.20656;		AAmatrix[6][6] = 0;				AAmatrix[6][7] = 14.7801;	
+	AAmatrix[6][8] = 0.005;			AAmatrix[6][9] = 0.0390512;		AAmatrix[6][10] = 0.129839;		AAmatrix[6][11] = 23.9626;	
+	AAmatrix[6][12] = 0.005;		AAmatrix[6][13] = 0.005;		AAmatrix[6][14] = 0.005;		AAmatrix[6][15] = 0.005;	
+	AAmatrix[6][16] = 0.458743;		AAmatrix[6][17] = 0.005;		AAmatrix[6][18] = 0.005;		AAmatrix[6][19] = 2.19952;	
+	AAmatrix[7][0] = 1.8685;		AAmatrix[7][1] = 13.4379;		AAmatrix[7][2] = 0.0604932;		AAmatrix[7][3] = 10.3969;	
+	AAmatrix[7][4] = 0.0489798;		AAmatrix[7][5] = 0.0604932;		AAmatrix[7][6] = 14.7801;		AAmatrix[7][7] = 0;	
+	AAmatrix[7][8] = 0.005;			AAmatrix[7][9] = 0.005;			AAmatrix[7][10] = 0.0489798;	AAmatrix[7][11] = 0.279425;	
+	AAmatrix[7][12] = 0.0489798;	AAmatrix[7][13] = 0.005;		AAmatrix[7][14] = 0.005;		AAmatrix[7][15] = 6.27966;	
+	AAmatrix[7][16] = 0.0489798;	AAmatrix[7][17] = 2.8258;		AAmatrix[7][18] = 0.005;		AAmatrix[7][19] = 2.79622;	
+	AAmatrix[8][0] = 0.005;			AAmatrix[8][1] = 6.84405;		AAmatrix[8][2] = 8.59876;		AAmatrix[8][3] = 2.31779;	
+	AAmatrix[8][4] = 0.005;			AAmatrix[8][5] = 18.5465;		AAmatrix[8][6] = 0.005;			AAmatrix[8][7] = 0.005;	
+	AAmatrix[8][8] = 0;				AAmatrix[8][9] = 0.005;			AAmatrix[8][10] = 1.76382;		AAmatrix[8][11] = 0.22406;	
+	AAmatrix[8][12] = 0.005;		AAmatrix[8][13] = 0.005;		AAmatrix[8][14] = 13.9444;		AAmatrix[8][15] = 0.725157;	
+	AAmatrix[8][16] = 0.95956;		AAmatrix[8][17] = 0.005;		AAmatrix[8][18] = 47.4889;		AAmatrix[8][19] = 0.827479;	
+	AAmatrix[9][0] = 0.005;			AAmatrix[9][1] = 1.34069;		AAmatrix[9][2] = 0.987028;		AAmatrix[9][3] = 0.145124;	
+	AAmatrix[9][4] = 0.005;			AAmatrix[9][5] = 0.0342252;		AAmatrix[9][6] = 0.0390512;		AAmatrix[9][7] = 0.005;	
+	AAmatrix[9][8] = 0.005;			AAmatrix[9][9] = 0;				AAmatrix[9][10] = 9.10246;		AAmatrix[9][11] = 0.817481;	
+	AAmatrix[9][12] = 17.3064;		AAmatrix[9][13] = 1.48288;		AAmatrix[9][14] = 0.005;		AAmatrix[9][15] = 0.740091;	
+	AAmatrix[9][16] = 9.36345;		AAmatrix[9][17] = 0.005;		AAmatrix[9][18] = 0.114512;		AAmatrix[9][19] = 24.8231;	
+	AAmatrix[10][0] = 0.16024;		AAmatrix[10][1] = 0.586757;		AAmatrix[10][2] = 0.005;		AAmatrix[10][3] = 0.005;	
+	AAmatrix[10][4] = 0.005;		AAmatrix[10][5] = 2.89048;		AAmatrix[10][6] = 0.129839;		AAmatrix[10][7] = 0.0489798;	
+	AAmatrix[10][8] = 1.76382;		AAmatrix[10][9] = 9.10246;		AAmatrix[10][10] = 0;			AAmatrix[10][11] = 0.005;	
+	AAmatrix[10][12] = 11.3839;		AAmatrix[10][13] = 7.48781;		AAmatrix[10][14] = 9.83095;		AAmatrix[10][15] = 6.14396;	
+	AAmatrix[10][16] = 0.005;		AAmatrix[10][17] = 1.37031;		AAmatrix[10][18] = 0.005;		AAmatrix[10][19] = 2.95344;	
+	AAmatrix[11][0] = 0.592784;		AAmatrix[11][1] = 39.8897;		AAmatrix[11][2] = 10.6655;		AAmatrix[11][3] = 0.894313;	
+	AAmatrix[11][4] = 0.005;		AAmatrix[11][5] = 13.0705;		AAmatrix[11][6] = 23.9626;		AAmatrix[11][7] = 0.279425;	
+	AAmatrix[11][8] = 0.22406;		AAmatrix[11][9] = 0.817481;		AAmatrix[11][10] = 0.005;		AAmatrix[11][11] = 0;	
+	AAmatrix[11][12] = 4.09564;		AAmatrix[11][13] = 0.005;		AAmatrix[11][14] = 0.111928;	AAmatrix[11][15] = 0.005;	
+	AAmatrix[11][16] = 4.04802;		AAmatrix[11][17] = 0.005;		AAmatrix[11][18] = 0.005;		AAmatrix[11][19] = 0.128065;	
+	AAmatrix[12][0] = 0.005;		AAmatrix[12][1] = 3.28652;		AAmatrix[12][2] = 0.201526;		AAmatrix[12][3] = 0.005;	
+	AAmatrix[12][4] = 0.005;		AAmatrix[12][5] = 0.005;		AAmatrix[12][6] = 0.005;		AAmatrix[12][7] = 0.0489798;	
+	AAmatrix[12][8] = 0.005;		AAmatrix[12][9] = 17.3064;		AAmatrix[12][10] = 11.3839;		AAmatrix[12][11] = 4.09564;	
+	AAmatrix[12][12] = 0;			AAmatrix[12][13] = 0.005;		AAmatrix[12][14] = 0.005;		AAmatrix[12][15] = 0.392575;	
+	AAmatrix[12][16] = 7.41313;		AAmatrix[12][17] = 0.005;		AAmatrix[12][18] = 0.579198;	AAmatrix[12][19] = 14.7683;	
+	AAmatrix[13][0] = 0.597923;		AAmatrix[13][1] = 0.005;		AAmatrix[13][2] = 0.005;		AAmatrix[13][3] = 0.005;	
+	AAmatrix[13][4] = 0.362959;		AAmatrix[13][5] = 0.005;		AAmatrix[13][6] = 0.005;		AAmatrix[13][7] = 0.005;	
+	AAmatrix[13][8] = 0.005;		AAmatrix[13][9] = 1.48288;		AAmatrix[13][10] = 7.48781;		AAmatrix[13][11] = 0.005;	
+	AAmatrix[13][12] = 0.005;		AAmatrix[13][13] = 0;			AAmatrix[13][14] = 0.0342252;	AAmatrix[13][15] = 4.27939;	
+	AAmatrix[13][16] = 0.114512;	AAmatrix[13][17] = 0.005;		AAmatrix[13][18] = 4.12728;		AAmatrix[13][19] = 2.28;	
+	AAmatrix[14][0] = 1.00981;		AAmatrix[14][1] = 0.404723;		AAmatrix[14][2] = 0.344848;		AAmatrix[14][3] = 0.005;	
+	AAmatrix[14][4] = 0.005;		AAmatrix[14][5] = 3.04502;		AAmatrix[14][6] = 0.005;		AAmatrix[14][7] = 0.005;	
+	AAmatrix[14][8] = 13.9444;		AAmatrix[14][9] = 0.005;		AAmatrix[14][10] = 9.83095;		AAmatrix[14][11] = 0.111928;	
+	AAmatrix[14][12] = 0.005;		AAmatrix[14][13] = 0.0342252;	AAmatrix[14][14] = 0;			AAmatrix[14][15] = 14.249;	
+	AAmatrix[14][16] = 4.33701;		AAmatrix[14][17] = 0.005;		AAmatrix[14][18] = 0.005;		AAmatrix[14][19] = 0.005;	
+	AAmatrix[15][0] = 8.5942;		AAmatrix[15][1] = 8.35024;		AAmatrix[15][2] = 14.5699;		AAmatrix[15][3] = 0.427881;	
+	AAmatrix[15][4] = 1.12195;		AAmatrix[15][5] = 0.16024;		AAmatrix[15][6] = 0.005;		AAmatrix[15][7] = 6.27966;	
+	AAmatrix[15][8] = 0.725157;		AAmatrix[15][9] = 0.740091;		AAmatrix[15][10] = 6.14396;		AAmatrix[15][11] = 0.005;	
+	AAmatrix[15][12] = 0.392575;	AAmatrix[15][13] = 4.27939;		AAmatrix[15][14] = 14.249;		AAmatrix[15][15] = 0;	
+	AAmatrix[15][16] = 6.34079;		AAmatrix[15][17] = 1.10156;		AAmatrix[15][18] = 0.933142;	AAmatrix[15][19] = 0.862637;	
+	AAmatrix[16][0] = 24.1422;		AAmatrix[16][1] = 0.928203;		AAmatrix[16][2] = 4.54206;		AAmatrix[16][3] = 0.630395;	
+	AAmatrix[16][4] = 0.005;		AAmatrix[16][5] = 0.203091;		AAmatrix[16][6] = 0.458743;		AAmatrix[16][7] = 0.0489798;	
+	AAmatrix[16][8] = 0.95956;		AAmatrix[16][9] = 9.36345;		AAmatrix[16][10] = 0.005;		AAmatrix[16][11] = 4.04802;	
+	AAmatrix[16][12] = 7.41313;		AAmatrix[16][13] = 0.114512;	AAmatrix[16][14] = 4.33701;		AAmatrix[16][15] = 6.34079;	
+	AAmatrix[16][16] = 0;			AAmatrix[16][17] = 0.005;		AAmatrix[16][18] = 0.490608;	AAmatrix[16][19] = 0.005;	
+	AAmatrix[17][0] = 0.005;		AAmatrix[17][1] = 5.96564;		AAmatrix[17][2] = 0.005;		AAmatrix[17][3] = 0.005;	
+	AAmatrix[17][4] = 5.49894;		AAmatrix[17][5] = 0.0443298;	AAmatrix[17][6] = 0.005;		AAmatrix[17][7] = 2.8258;	
+	AAmatrix[17][8] = 0.005;		AAmatrix[17][9] = 0.005;		AAmatrix[17][10] = 1.37031;		AAmatrix[17][11] = 0.005;	
+	AAmatrix[17][12] = 0.005;		AAmatrix[17][13] = 0.005;		AAmatrix[17][14] = 0.005;		AAmatrix[17][15] = 1.10156;	
+	AAmatrix[17][16] = 0.005;		AAmatrix[17][17] = 0;			AAmatrix[17][18] = 0.005;		AAmatrix[17][19] = 0.005;	
+	AAmatrix[18][0] = 0.005;		AAmatrix[18][1] = 0.005;		AAmatrix[18][2] = 5.06475;		AAmatrix[18][3] = 2.28154;	
+	AAmatrix[18][4] = 8.34835;		AAmatrix[18][5] = 0.005;		AAmatrix[18][6] = 0.005;		AAmatrix[18][7] = 0.005;	
+	AAmatrix[18][8] = 47.4889;		AAmatrix[18][9] = 0.114512;		AAmatrix[18][10] = 0.005;		AAmatrix[18][11] = 0.005;	
+	AAmatrix[18][12] = 0.579198;	AAmatrix[18][13] = 4.12728;		AAmatrix[18][14] = 0.005;		AAmatrix[18][15] = 0.933142;	
+	AAmatrix[18][16] = 0.490608;	AAmatrix[18][17] = 0.005;		AAmatrix[18][18] = 0;			AAmatrix[18][19] = 1.35482;	
+	AAmatrix[19][0] = 24.8094;		AAmatrix[19][1] = 0.279425;		AAmatrix[19][2] = 0.0744808;	AAmatrix[19][3] = 2.91786;	
+	AAmatrix[19][4] = 0.005;		AAmatrix[19][5] = 0.005;		AAmatrix[19][6] = 2.19952;		AAmatrix[19][7] = 2.79622;	
+	AAmatrix[19][8] = 0.827479;		AAmatrix[19][9] = 24.8231;		AAmatrix[19][10] = 2.95344;		AAmatrix[19][11] = 0.128065;	
+	AAmatrix[19][12] = 14.7683;		AAmatrix[19][13] = 2.28;		AAmatrix[19][14] = 0.005;		AAmatrix[19][15] = 0.862637;	
+	AAmatrix[19][16] = 0.005;		AAmatrix[19][17] = 0.005;		AAmatrix[19][18] = 1.35482;		AAmatrix[19][19] = 0;	
+
+	AAPi[0] = 0.0377494;
+	AAPi[1] = 0.057321;
+	AAPi[2] = 0.0891129;
+	AAPi[3] = 0.0342034;
+	AAPi[4] = 0.0240105;
+	AAPi[5] = 0.0437824;
+	AAPi[6] = 0.0618606;
+	AAPi[7] = 0.0838496;
+	AAPi[8] = 0.0156076;
+	AAPi[9] = 0.0983641;
+	AAPi[10] = 0.0577867;
+	AAPi[11] = 0.0641682;
+	AAPi[12] = 0.0158419;
+	AAPi[13] = 0.0422741;
+	AAPi[14] = 0.0458601;
+	AAPi[15] = 0.0550846;
+	AAPi[16] = 0.0813774;
+	AAPi[17] = 0.019597;
+	AAPi[18] = 0.0205847;
+	AAPi[19] = 0.0515639;
+
+
+	}
+
+	else
+	if(modelnumber==16 )
+	{
+		// not used any more - see beginning of function
+
+		/*USER DEFINED SUBSTITUTION MODEL*/
+	}
+
+	else {cout<<"ERROR IN AMINO ACID MODEL NUMBER IN SETAARATES"<<endl; }
+
+
+	// now, check that the matrices are symmetrical 
+	for (i=0; i<20; i++)
+		{
+		for (j=i+1; j<20; j++)
+			{
+			diff = AAmatrix[i][j] - AAmatrix[j][i];
+			if (diff < 0.0)
+				diff = -diff;
+			if (diff > 0.001)
+				{
+					string errorout="ERROR: ";
+
+				
+					if(modelnumber==0)  errorout+="Poisson model ";
+					else if(modelnumber==1)  errorout+="Jones model ";
+					else if(modelnumber==2)  errorout+="Jones - DCMUT model ";
+					else if(modelnumber==3)  errorout+="Dayhoff model ";
+					else if(modelnumber==4)  errorout+="Dayhoff - DCMUT model ";
+					else if(modelnumber==5)  errorout+="WAG model ";
+					else if(modelnumber==6)  errorout+="Mtmam model ";
+					else if(modelnumber==7)  errorout+="Mtart model ";
+					else if(modelnumber==8)  errorout+="MtREV model ";
+					else if(modelnumber==9)  errorout+="rtREV model ";
+					else if(modelnumber==10) errorout+="cpREV model ";
+					else if(modelnumber==11) errorout+="Vt model ";
+					else if(modelnumber==12) errorout+="Blosum model ";
+					else if(modelnumber==13) errorout+="LG model ";
+					else if(modelnumber==14) errorout+="HIVb model ";
+					else if(modelnumber==15) errorout+="HIVw model ";
+					//else if(modelnumber==16) errorout+="User-defined PROTEIN model ";
+				
+
+					errorout+="is not symmetrical.";
+
+					controlerrorprint2("[MODEL]",name,"getAA(name)",errorout,"");
+					error=-1;
+				}
+			}
+		}
+
+
+	vector<double> row;
+	vector<vector<double> > blah;
+
+
+	bool dobase=false;
+	// if no base frequencies have been specified prior to this command
+	// then the model base frequencies will come from the empirical
+	// substitution model
+	if(basefreqs.empty()) dobase=true;
+
+	for(int gj1=0; gj1<20; gj1++)
+	{
+		if(dobase) basefreqs.push_back(AAPi[gj1]);
+		row.clear();
+		for(int gj2=0; gj2<20; gj2++) row.push_back(AAmatrix[gj1][gj2]);
+		blah.push_back(row);
+	}
+
+
+	// rescale stationary frequencies, to make certain they sum to 1.0 
+	double sum = 0.0;
+	for (i=0; i<20; i++) sum += basefreqs.at(i); //cout<<basefreqs.at(i)<<" ";} cout<<endl;
+	if(sum!=1) for (i=0; i<20; i++) basefreqs.at(i) /= sum;
+
+	// multiply entries by stationary frequencies 
+	for (i=0; i<20; i++) for (j=0; j<20; j++) (blah.at(i)).at(j) *= basefreqs.at(j);
+			
+	// rescale, so branch lengths are in terms of expected number of substitutions per site 
+	double scaler = 0.0;
+	for (i=0; i<20; i++)
+	{
+		for (j=i+1; j<20; j++)
+		{
+			scaler += basefreqs.at(i) * (blah.at(i)).at(j);
+			scaler += basefreqs.at(j) * (blah.at(j)).at(i);
+		}
+	}
+	scaler = 1.0 / scaler;
+	
+
+	for (i=0; i<20; i++) for (j=0; j<20; j++) (blah.at(i)).at(j) *= scaler;
+
+	//set diagonal of matrix
+	for( i=0; i<20; i++) {sum=0; for(j=0; j<20; j++) if(i!=j) sum+=(blah.at(i)).at(j); (blah.at(i)).at(i)=-sum; }
+
+//	for(int p1=0; p1<20; p1++)	for(int p2=0; p2<20; p2++) ccout<<(blah.at(p1)).at(p2)<<"\t"<<AAmatrix[p1][p2]<<endl;
+
+//	for(int p1=0; p1<20; p1++)	for(int p2=0; p2<20; p2++) if(AAmatrix[p1][p2]-(blah.at(p1)).at(p2)!=0) cout<<AAmatrix[p1][p2]-(blah.at(p1)).at(p2)<<"  "<<AAmatrix[p1][p2]<<" "<<(blah.at(p1)).at(p2)<<" "<<endl;
+
+	return blah;
+}
+////////////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////
+vector<vector<double> > getECMr()
+{
+	/*
+		Kosiol, C., Holmes, I. and Goldman, N. (2007) An Empirical Codon Model for Protein Sequence Evolution.  Molecular Biology and Evolution 24(7): 1464-1479.
+
+		Empirical codon substitution model where evolution is restricted to single nucleotide substitutions
+	*/
+	vector<vector<double> > myQvec;
+	vector<double> row;
+
+	double ECMrestQ[64][64]=
+		{{0,11.192024,1.31561,5.427076,1.658051,0,0,0,6.610894,0,0,0,3.347364,0,0,0,2.090751,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.682029,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.261813,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{11.192024,0,0.010896,4.756288,0,1.913571,0,0,0,5.17793,0,0,0,1.558523,0,0,0,2.266373,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.786043,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.923392,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{1.31561,0.010896,0,24.748755,0,0,2.952332,0,0,0,0,0,0,0,0,0,0,0,75.752638,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10.116588,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.36272,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{5.427076,4.756288,24.748755,0,0,0,0,8.126914,0,0,0,0,0,0,0,5.369644,0,0,0,20.877218,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.911096,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.022101,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{1.658051,0,0,0,0,13.889102,44.407955,17.057443,2.206054,0,0,0,6.191481,0,0,0,0,0,0,0,1.769355,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,38.2291,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.540052,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,1.913571,0,0,13.889102,0,13.681751,65.097021,0,5.615472,0,0,0,9.339206,0,0,0,0,0,0,0,2.704601,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.793595,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.675838,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,2.952332,0,44.407955,13.681751,0,12.991861,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.312811,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.033932,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9.880382,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,8.126914,17.057443,65.097021,12.991861,0,0,0,0,0,0,0,0,4.662001,0,0,0,0,0,0,0,1.30348,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17.103904,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21.863158,0,0,0,0,0,0,0,0}
+		,{6.610894,0,0,0,2.206054,0,0,0,0,19.942818,0,0,0.582084,0,0,0,0,0,0,0,0,0,0,0,3.444964,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.245405,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.367553,0,0,0,0,0,0,0}
+		,{0,5.17793,0,0,0,5.615472,0,0,19.942818,0,0,0,0,0.144278,0,0,0,0,0,0,0,0,0,0,0,7.087801,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.228361,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.294702,0,0,0,0,0,0}
+		,{3.347364,0,0,0,6.191481,0,0,0,0.582084,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,1.558523,0,0,0,9.339206,0,0,0,0.144278,44.777964,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,5.369644,0,0,0,4.662001,0,0,0.677177,0.073268,0,44.777964,0,0.677177,0,0,0,0,0,0,0,0,0,0,0,0,1.617091,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.719489,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.104727,0,0,0}
+		,{2.090751,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.073268,0,0,0,0,0,0,0,0,0,0,0,0,0,1.632945,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.047654,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.552851,0,0}
+		,{0,2.266373,0,0,0,0,0,0,0,0,0,0,0,8.905484,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,75.752638,0,0,0,0,0,0,0,0,0,0,56.803876,7.811205,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.026086,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.825082,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.810856}
+		,{0,0,0,20.877218,0,0,0,0,0,0,0,0,0,8.432339,22.078564,5.650116,0,8.905484,56.803876,8.432339,1.263838,0,0,0,1.583116,0,0,0,0.779565,0,0,0,4.301225,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.473623,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,1.769355,0,0,0,0,0,0,0,0,1.263838,0,0,0,0,7.811205,22.078564,0,1.389735,0,0,0,3.230751,0,0,0,2.25077,0,0,0,6.381841,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.914972,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,2.704601,0,0,0,0,0,0,0,0,1.389735,0,0,17.461627,0,5.650116,0,0,1.39368,0,0,0,7.419058,0,0,0,3.023939,0,0,0,5.134459,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.737489,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,3.312811,0,0,0,0,0,0,0,0,1.39368,0,35.480963,12.053827,0,0,0,0,0.477616,0,0,0,1.81254,0,0,0,1.462945,0,0,0,2.570123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.164805,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,1.30348,0,0,0,0,0,0,0,0,0.477616,8.407091,28.557939,11.295213,0,17.461627,35.480963,8.407091,1.021682,0,0,0,0.334165,0,0,0,0,0,0,0,6.578976,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.159185,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,3.444964,0,0,0,0,1.583116,0,0,0,1.021682,0,0,0,0,12.053827,28.557939,0,3.774544,0,0,0,1.699302,0,0,0,0,0,0,0,1.43455,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.120189,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,7.087801,0,0,0,0,3.230751,0,0,0,3.774544,0,0,28.08616,0,11.295213,0,0,5.381868,0,0,0,1.693662,0,0,0,0,0,0,0,0.925575,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.923972,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.419058,0,0,0,5.381868,0,3.44038,1.918904,0,0,0,0,1.794388,0,0,0,3.144296,0,0,0,0,0,0,0,1.23845,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.034856,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.81254,0,0,0,1.794388,1.086327,5.369463,14.959151,0,28.08616,3.44038,1.086327,3.019726,0,0,0,0,0,0,0,0,0,0,0,5.004762,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.383706,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,1.617091,0,0,0.779565,0,0,0,0.334165,0,0,0,3.019726,0,0,0,0,1.918904,5.369463,0,7.016899,0,0,0,0,0,0,0,0,0,0,0,4.105602,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.006827,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,1.632945,0,0,2.25077,0,0,0,1.699302,0,0,0,7.016899,0,0,14.603857,0,14.959151,0,0,6.415757,0,0,0,0,0,0,0,0,0,0,0,6.404436,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.485369,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.023939,0,0,0,1.693662,0,0,0,6.415757,0,99.459951,14.930266,0,0,0,0,19.920977,0,0,0,0,0,0,0,0,0,0,0,2.715692,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.686782,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,3.026086,0,0,0,1.462945,0,0,0,3.144296,0,0,0,19.920977,30.80475,79.48373,13.919752,0,14.603857,99.459951,30.80475,0,0,0,0,0,0,0,0,0,0,0,0,3.834666,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.04115,0,0,0}
+		,{1.682029,0,0,0,0,0,0,0,0,0,0,0,0,4.301225,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14.930266,79.48373,0,0,0,0,0,0,0,0,0,0,0,0,0,5.03363,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.25247,0,0}
+		,{0,0.786043,0,0,0,0,0,0,0,0,0,0,0,0,6.381841,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10.140728,0,13.919752,0,0,0,0,0,0,0,0,0,0,0,0,0,0,92.372238,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.091041,0}
+		,{0,0,10.116588,0,0,0,0,0,0,0,0,0,0,0,0,5.134459,0,0,0,0,0,0,0,0,0,0,0,0,0,18.2989,4.623936,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,133.296291,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.803738}
+		,{0,0,0,7.911096,0,0,0,0,0,0,0,0,0,0,0,0,2.570123,0,0,0,0,0,0,0,0,0,0,0,0,1.281784,1.303951,2.082128,0,10.140728,18.2989,1.281784,2.801564,0,0,0,0.501054,0,0,0,0.578118,0,0,0,7.096281,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,38.2291,0,0,0,0,0,0,0,0,0,0,0,0,6.578976,0,0,0,0,0,0,0,0,0,0,0,2.801564,0,0,0,0,4.623936,1.303951,0,2.231468,0,0,0,0.292691,0,0,0,0.437779,0,0,0,10.137337,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,15.793595,0,0,0,0,0,0,0,0,0,0,0,0,1.43455,0,0,0,0,0,0,0,0,0,0,0,2.231468,0,0,6.03574,0,2.082128,0,0,4.96235,0,0,0,2.64762,0,0,0,1.903175,0,0,0,25.294298,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,6.033932,0,0,0,0,0,0,0,0,0,0,0,0,0.925575,0,0,0,0,0,0,0,0,0,0,0,4.96235,0,28.307876,6.967655,0,0,0,0,8.155285,0,0,0,0.975074,0,0,0,2.231662,0,0,0,2.078444,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,17.103904,0,0,0,0,0,0,0,0,0,0,0,0,1.23845,0,0,0,0,0,0,0,0,0,0,0,8.155285,19.578982,38.414969,12.678802,0,6.03574,28.307876,19.578982,11.715476,0,0,0,39.399322,0,0,0,0,0,0,0,5.107629,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,2.245405,0,0,0,0,0,0,0,0,0,0,0,0,5.004762,0,0,0,0,0,0,0,0.501054,0,0,0,11.715476,0,0,0,0,6.967655,38.414969,0,2.13474,0,0,0,21.337943,0,0,0,0,0,0,0,2.312255,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0.228361,0,0,0,0,0,0,0,0,0,0,0,0,4.105602,0,0,0,0,0,0,0,0.292691,0,0,0,2.13474,0,0,13.863648,0,12.678802,0,0,3.91936,0,0,0,0.754055,0,0,0,0,0,0,0,3.064069,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.404436,0,0,0,0,0,0,0,2.64762,0,0,0,3.91936,0,4.929483,0.366267,0,0,0,0,5.869857,0,0,0,22.577271,0,0,0,0,0,0,0,25.461549,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.715692,0,0,0,0,0,0,0,0.975074,0,0,0,5.869857,1.010212,0.982893,10.762877,0,13.863648,4.929483,1.010212,16.623529,0,0,0,0,0,0,0,0,0,0,0,6.091654,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,4.719489,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.834666,0,0,0,0.578118,0,0,0,39.399322,0,0,0,16.623529,0,0,0,0,0.366267,0.982893,0,7.784768,0,0,0,0,0,0,0,0,0,0,0,3.686074,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,2.047654,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.03363,0,0,0,0.437779,0,0,0,21.337943,0,0,0,7.784768,0,0,26.637668,0,10.762877,0,0,8.423762,0,0,0,0,0,0,0,0,0,0,0,2.811398,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,92.372238,0,0,0,1.903175,0,0,0,0.754055,0,0,0,8.423762,0,1.792245,0.1209,0,0,0,0,21.000358,0,0,0,0,0,0,0,0,0,0,0,2.090641,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0.825082,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,133.296291,0,0,0,2.231662,0,0,0,22.577271,0,0,0,21.000358,3.324581,6.01197,36.292705,0,26.637668,1.792245,3.324581,0,0,0,0,0,0,0,0,0,0,0,0,10.59078,0,0,0}
+		,{2.261813,0,0,0,0,0,0,0,0,0,0,0,0,2.473623,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.096281,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.1209,6.01197,0,0,0,0,0,0,0,0,0,0,0,0,0,4.285543,0,0}
+		,{0,1.923392,0,0,0,0,0,0,0,0,0,0,0,0,5.914972,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10.137337,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.669955,0,36.292705,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.43241,0}
+		,{0,0,2.36272,0,0,0,0,0,0,0,0,0,0,0,0,3.737489,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.294298,0,0,0,0,0,0,0,0,0,0,0,0,0,26.045078,3.531461,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.388514}
+		,{0,0,0,2.022101,0,0,0,0,0,0,0,0,0,0,0,0,2.164805,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.078444,0,0,0,0,0,0,0,0,0,0,0,0,8.901167,21.657664,11.898141,0,6.669955,26.045078,8.901167,3.682092,0,0,0,0.352915,0,0,0,0.503385,0,0,0}
+		,{0,0,0,0,5.540052,0,0,0,0,0,0,0,0,0,0,0,0,1.159185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.107629,0,0,0,0,0,0,0,0,0,0,0,3.682092,0,0,0,0,3.531461,21.657664,0,4.308415,0,0,0,0.208522,0,0,0,0.542717,0,0}
+		,{0,0,0,0,0,7.675838,0,0,0,0,0,0,0,0,0,0,0,0,3.120189,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.312255,0,0,0,0,0,0,0,0,0,0,0,4.308415,0,0,6.516319,0,11.898141,0,0,6.291148,0,0,0,1.277861,0,0,0,0.702411,0}
+		,{0,0,0,0,0,0,9.880382,0,0,0,0,0,0,0,0,0,0,0,0,2.923972,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.064069,0,0,0,0,0,0,0,0,0,0,0,6.291148,0,21.910225,5.090423,0,0,0,0,6.166554,0,0,0,0.476105,0,0,0,0.302501}
+		,{0,0,0,0,0,0,0,21.863158,0,0,0,0,0,0,0,0,0,0,0,0,6.034856,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.461549,0,0,0,0,0,0,0,0,0,0,0,6.166554,5.512586,20.715347,9.529141,0,6.516319,21.910225,5.512586,0.693026,0,0,0,1.541379,0,0,0}
+		,{0,0,0,0,0,0,0,0,0.367553,0,0,0,0,0,0,0,0,0,0,0,0,0.383706,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.091654,0,0,0,0,0,0,0,0.352915,0,0,0,0.693026,0,0,0,0,5.090423,20.715347,0,1.866565,0,0,0,2.303487,0,0}
+		,{0,0,0,0,0,0,0,0,0,0.294702,0,0,0,0,0,0,0,0,0,0,0,0,3.006827,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.686074,0,0,0,0,0,0,0,0.208522,0,0,0,1.866565,0,0,10.605899,0,9.529141,0,0,2.774445,0,0,0,2.985093,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.485369,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.811398,0,0,0,0,0,0,0,1.277861,0,0,0,2.774445,0,2.71061,0.650088,0,0,0,0,9.441919,0,0,0,6.644971}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.686782,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.090641,0,0,0,0,0,0,0,0.476105,0,0,0,9.441919,1.296294,3.779053,10.15357,0,10.605899,2.71061,1.296294,1.042624,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,1.104727,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.04115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10.59078,0,0,0,0.503385,0,0,0,1.541379,0,0,0,1.042624,0,0,0,0,0.650088,3.779053,0,1.561629,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0.552851,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.25247,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.285543,0,0,0,0.542717,0,0,0,2.303487,0,0,0,1.561629,0,0,9.48852,0,10.15357,0,0,0.874,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.091041,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.43241,0,0,0,0.702411,0,0,0,2.985093,0,0,0,0.874,0,20.5181,4.120953,0,0,0,0,1.39381}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0.810856,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.803738,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.388514,0,0,0,0.302501,0,0,0,6.644971,0,0,0,1.39381,13.246936,18.064826,19.084271,0,9.48852,20.5181,13.246936}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.120953,18.064826}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19.084271}
+		,{0.022103,0,0.021383,0,0.016387,0,0.015425,0,0.01188,0,0.011131,0,0.00975,0,0.008956,0,0.015965,0,0.015782,0,0.006025,0,0.007029,0,0.01188,0,0.014467,0,0.017386,0,0.0076,0,0.028839,0,0.010007,0,0.0101,0,0.010642,0,0.011843,0,0.011097,0,0.011703,0,0.016076,0,0.020211,0,0.008311,0,0.014148,0,0.0048,0,0.007837,0,0.025576,0,0.023441,0,0.013551,0}};
+
+
+		double ECMrestPi[64]=
+		{0.022103,0.021383,0.016387,0.015425,0.01188,0.011131,0.00975,0.008956,0.015965,0.015782,0,0,0.006025,0.007029,0,0.01188,0.014467,0.017386,0.0076,0.028839,0.010007,0.0101,0.010642,0.011843,0.011097,0.011703,0.016076,0.020211,0.008311,0.014148,0.0048,0.007837,0.025576,0.023441,0.013551,0.020102,0.013424,0.020201,0.015528,0.012142,0.023006,0.020171,0.030001,0.026344,0.010142,0.011679,0.010372,0.008195,0.019047,0.018938,0.010901,0.022747,0.019005,0.028307,0.015908,0.018853,0.028198,0.0245 [...]
+
+
+		if(basefreqs.empty()) for(int gv3=0; gv3<64; gv3++) basefreqs.push_back(ECMrestPi[gv3]); 
+			
+		for(int gv1=0; gv1<64; gv1++) {row.clear(); {for(int gv2=0; gv2<64; gv2++) row.push_back(ECMrestQ[gv1][gv2]);} myQvec.push_back(row);}
+
+		return myQvec;
+}
+
+vector<vector<double> > getECMu()
+{
+	
+	/*
+		Kosiol, C., Holmes, I. and Goldman, N. (2007) An Empirical Codon Model for Protein Sequence Evolution.  Molecular Biology and Evolution 24(7): 1464-1479.
+
+		Empirical codon substitution model where doublet and triplet substitutions are allowed as well 
+	*/
+	vector<vector<double> > myQvec;
+	vector<double> row;
+		double ECMunrestQ[64][64]=
+		{{0,16.011531,2.395822,1.204356,0.773935,0.030074,0.27809,0.034137,4.317981,0.481042,0,0,0.733587,0.045951,0,0.786871,2.016257,0.083684,1.036474,0.07355,0.324368,0.00014,0.025217,0.004063,0.638696,0.000467,0.12632,0.00976,0.143832,0,0.030121,0.000934,1.119411,0.056038,1.075187,0.67937,0.497293,0.000093,0.079948,0.008032,0.263567,0.000093,0.148268,0.013122,0.225554,0.000093,0.140516,0.08331,0.86397,0.026338,0.565566,0.068927,0.483563,0.000093,0.109975,0.005884,0.064397,0,0.084945,0.0109 [...]
+		,{16.011531,0,0.151858,0.675537,0.052602,0.656004,0.056677,0.198277,0.503397,4.483501,0,0,0.076912,0.56162,0,1.183337,0.207692,2.30611,0.198558,1.341144,0.000141,0.285635,0.006558,0.079161,0.001312,0.761771,0.016628,0.107218,0.000094,0.200806,0.01602,0.027355,0.059956,1.006045,0.064968,0.800602,0.000141,0.371541,0.010539,0.036489,0.000094,0.143614,0.005996,0.043609,0.000047,0.166706,0.0126,0.056771,0.065905,0.946136,0.047403,0.371072,0.000234,0.512203,0.016535,0.074851,0,0.055366,0.006 [...]
+		,{2.395822,0.151858,0,18.541946,0.249707,0.011609,1.184813,0.010188,0.798582,0.033529,0,0,0.645571,0.040012,0,0.271072,12.035723,1.373823,27.219895,1.045943,0.001358,0,0.261069,0,0.026551,0.000123,0.576476,0,0.000741,0,0.136647,0,2.130663,0.042112,5.159075,1.418466,0.012473,0.000062,0.871568,0.000062,0.271628,0.00284,0.61266,0.000062,0.010929,0.000432,0.423774,0.000247,0.748196,0.00599,2.299543,0.024699,0.008892,0,1.041312,0,0.042112,0.000062,0.287373,0,0.000741,0,0.201112,0}
+		,{1.204356,0.675537,18.541946,0,0.27499,0.158873,0.611887,0.694091,0.337279,0.177833,0,0,0.395942,0.240632,0,0.632947,11.161511,5.651603,16.560966,12.455337,0.003499,0.000382,0.005535,0.112999,0.040275,0.002163,0.007508,0.250748,0.003054,0.000064,0.001527,0.127696,1.292935,0.478019,1.065537,3.062807,0.015652,0.00299,0.011134,0.586818,0.077878,0.060699,0.004963,0.33378,0.009289,0.00579,0.001718,0.506841,0.529619,0.140867,0.762425,1.108802,0.03563,0.001654,0.019406,0.220908,0.038557,0.00 [...]
+		,{0.773935,0.052602,0.249707,0.27499,0,23.65509,35.921779,11.510965,0.688169,0.069588,0,0,1.811753,0.138244,0,0.069758,0.277929,0.000085,0.000678,0,2.846677,0.101204,0.487542,0.021444,1.253945,0.000593,0.508308,0.049246,0.660622,0,0.006103,0.000085,0.172403,0,0.000424,0.093491,4.693944,0.196983,2.018483,0.361164,1.773102,0.00339,0.340991,0.156468,12.169045,0.094762,0.04789,0.063994,0.563995,0.000085,0.001356,0.000254,3.994417,0.111968,1.93135,0.103323,1.120532,0.000254,0.330481,0.04238 [...]
+		,{0.030074,0.656004,0.011609,0.158873,23.65509,0,15.982573,35.359077,0.047115,0.524116,0,0,0.343463,1.323765,0,0.081312,0.000186,0.342813,0.000186,0.001022,0.196358,2.487136,0.138742,0.371063,0.002137,1.144692,0.080383,0.423382,0.001208,0.685812,0.004089,0.004832,0,0.115975,0,0.042282,0.487317,3.82958,0.409721,1.562591,0.000929,1.118208,0.020909,0.25165,0.083636,10.892976,0.002044,0.028715,0.000186,0.396897,0.000279,0.001394,0.771771,3.45257,0.5585,1.262618,0.003717,1.023142,0.08568,0. [...]
+		,{0.27809,0.056677,1.184813,0.611887,35.921779,15.982573,0,17.424222,0.341791,0.070809,0,0,0.75198,0.121937,0,0.195833,0.000289,0.000096,0.496046,0,0.544474,0.072352,3.121656,0.064924,0.128111,0.01447,2.066955,0.002122,0.000579,0,0.557015,0,0.000386,0.000096,0.403435,0.246094,2.297807,0.150107,5.709933,0.516594,0.872084,0.187826,1.496628,0.004438,5.964323,1.049877,1.094736,0.009261,0.002219,0.000096,0.81372,0.000772,1.825878,0.084218,4.380679,0.150589,0.348448,0.007428,1.265487,0.00106 [...]
+		,{0.034137,0.198277,0.010188,0.694091,11.510965,35.359077,17.424222,0,0.058136,0.213967,0,0,0.143447,0.493179,0,0.410046,0,0.000344,0.000115,0.266943,0.078776,0.43252,0.151589,2.075226,0.07373,0.114551,0.002179,1.519211,0.00172,0.032106,0.003211,1.903571,0,0.000344,0,0.527005,0.199748,2.395833,0.349846,4.919174,0.040706,0.725836,0.000459,0.768607,0.681575,9.818281,0.000115,0.514392,0.000115,0.001261,0.000115,0.451899,0.250545,1.978448,0.505677,4.658653,0.117533,0.670108,0.002179,1.0291 [...]
+		,{4.317981,0.503397,0.798582,0.337279,0.688169,0.047115,0.341791,0.058136,0,24.177765,0,0,0.822999,0.068342,0,1.140051,0.485469,0.000116,0.01665,0.004815,0.337879,0.000116,0.03214,0.004177,3.088481,0.265766,0.486281,0.09207,0.534375,0.000116,0.043917,0.003713,0.352731,0.000116,0.573013,0.294368,0.599932,0.000116,0.208041,0.042119,0.74787,0.046586,0.467136,0.072867,0.50647,0.000116,0.424321,0.200499,0.571505,0.000116,0.236179,0.00963,0.370309,0.000058,0.176829,0.027035,0.223763,0.010037 [...]
+		,{0.481042,4.483501,0.033529,0.177833,0.069588,0.524116,0.070809,0.213967,24.177765,0,0,0,0.05486,0.628438,0,1.421996,0.000299,0.622089,0.011978,0.308859,0.000479,0.310416,0.025873,0.037372,0.340541,3.193996,0.079236,0.332396,0.001377,0.604541,0.051686,0.081931,0.00018,0.255975,0.025454,0.300354,0.000599,0.393545,0.053363,0.177757,0.042762,0.487814,0.042942,0.140864,0.00018,0.34689,0.060909,0.26951,0.000359,0.582801,0.06043,0.116309,0.000419,0.380788,0.034737,0.106187,0.015452,0.184704 [...]
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0.733587,0.076912,0.645571,0.395942,1.811753,0.343463,0.75198,0.143447,0.822999,0.05486,0,0,0,56.838378,0,0.264556,0.54324,0.000466,0.020649,0.002639,0.239715,0,0.002795,0.000155,0.634065,0.000155,0.163174,0.05791,0.726908,0.012886,0.232728,0.023909,0.431456,0.000311,0.069555,0.298091,1.089585,0.000776,0.415775,0.053874,0.360038,0.000932,0.099519,0.011489,2.007768,0.248099,0.144388,0.122186,1.598824,0.001087,0.754233,0.126844,1.899865,0.000466,0.806554,0.028567,0.099985,0,0.028878,0. [...]
+		,{0.045951,0.56162,0.040012,0.240632,0.138244,1.323765,0.121937,0.493179,0.068342,0.628438,0,0,56.838378,0,0,0.210115,0.000674,0.674176,0.021578,0.265948,0.00027,0.215779,0.01025,0.004585,0.001483,0.483076,0.032232,0.105597,0.077815,0.516927,0.16615,0.183143,0.000405,0.309643,0.012138,0.324613,0.001483,0.806071,0.061227,0.173298,0.000135,0.325422,0.004316,0.034794,0.181794,1.372357,0.030883,0.070533,0.004316,1.273908,0.086986,0.530278,0.011733,1.514097,0.297371,0.586111,0.000135,0.0716 [...]
+		,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+		,{0.786871,1.183337,0.271072,0.632947,0.069758,0.081312,0.195833,0.410046,1.140051,1.421996,0,0,0.264556,0.210115,0,0,0.010122,0.113701,0.017106,0.504866,0.061833,0.032564,0.070308,0.215788,0.195073,0.369273,0.055163,0.24749,0.019696,0.176476,0.146501,1.13591,0.078312,0.136849,0.170041,0.321642,0.035939,0.037822,0.060421,0.362681,0.074859,0.053908,0.051005,0.105226,0.139046,0.167138,0.145245,0.496706,0.038763,0.092044,0.058616,0.277072,0.03586,0.044178,0.031466,0.446015,0.028249,0.0663 [...]
+		,{2.016257,0.207692,12.035723,11.161511,0.277929,0.000186,0.000289,0,0.485469,0.000299,0,0,0.54324,0.000674,0,0.010122,0,15.874441,21.437257,4.802017,0.822643,0.026571,0.065669,0.007978,0.664866,0.058614,0.529045,0.079119,0.663877,0.016022,0.424607,0.039428,3.330793,0.39019,1.260239,1.22002,0.831215,0.000396,0.000857,0.000264,0.25938,0.00033,0.060922,0.039362,0.322807,0.00033,0.004747,0.00956,1.89715,0.105361,0.509595,0.091844,0.879741,0.000132,0.002374,0.000066,0.129492,0.000066,0.039 [...]
+		,{0.083684,2.30611,1.373823,5.651603,0.000085,0.342813,0.000096,0.000344,0.000116,0.622089,0,0,0.000466,0.674176,0,0.113701,15.874441,0,8.808275,15.484088,0.036254,0.648769,0.016609,0.118229,0.057328,0.617694,0.071794,0.422671,0.068758,0.544828,0.112395,0.640495,0.18401,3.765697,0.136148,1.434579,0.00006,0.89749,0.000119,0.000595,0,0.18788,0.002143,0.022384,0.00006,0.300513,0.00006,0.000952,0.072866,2.720153,0.03173,0.477439,0.000417,1.191514,0.000357,0.000893,0,0.135255,0.002679,0.010 [...]
+		,{1.036474,0.198558,27.219895,16.560966,0.000678,0.000186,0.496046,0.000115,0.01665,0.011978,0,0,0.020649,0.021578,0,0.017106,21.437257,8.808275,0,8.319767,0.181411,0.040087,1.07379,0.016442,0.438648,0.059927,1.205738,0.105449,0.134394,0.005436,0.918198,0.040902,1.328581,0.203017,4.40061,1.635281,0.004348,0.000679,0.94456,0.000408,0.019568,0.01454,0.43362,0.000679,0.009512,0.002718,0.409432,0.000951,0.555104,0.043756,2.047159,0.173122,0.004077,0.000136,0.741135,0,0.012366,0.001359,0.31 [...]
+		,{0.07355,1.341144,1.045943,12.455337,0,0.001022,0,0.266943,0.004815,0.308859,0,0,0.002639,0.265948,0,0.504866,4.802017,15.484088,8.319767,0,0.014388,0.149771,0.040917,0.495176,0.044742,0.330036,0.033372,0.703795,0.015019,0.563956,0.041969,0.794366,0.089308,2.469249,0.048882,2.236557,0.00007,0.073657,0.00007,0.733202,0.00014,0.034916,0.000035,0.133032,0.000105,0.0173,0,0.04032,0.01158,1.08517,0.020529,2.26249,0.000772,0.103766,0.000351,1.524024,0.000491,0.015686,0.00014,0.1763,0.000175 [...]
+		,{0.324368,0.000141,0.001358,0.003499,2.846677,0.196358,0.544474,0.078776,0.337879,0.000479,0,0,0.239715,0.00027,0,0.061833,0.822643,0.036254,0.181411,0.014388,0,23.496083,40.922701,10.291826,0.775254,0.061583,0.435109,0.107434,0.500433,0.002398,0.352807,0.00988,0.292855,0.000096,0.002014,0.081631,1.050363,0.044125,0.368538,0.079712,0.78734,0.000959,0.247195,0.220816,1.035015,0.001247,0.011511,0.060432,0.708395,0.000192,0.001151,0.000384,1.272426,0.022062,0.335924,0.014101,0.661776,0.0 [...]
+		,{0.00014,0.285635,0,0.000382,0.101204,2.487136,0.072352,0.43252,0.000116,0.310416,0,0,0,0.215779,0,0.032564,0.026571,0.648769,0.040087,0.149771,23.496083,0,15.426733,33.45378,0.091276,0.730306,0.074846,0.529594,0.124232,0.563799,0.154017,0.897101,0.000096,0.270274,0,0.008455,0.053805,0.870967,0.02623,0.435243,0.000192,0.532092,0.012394,0.303613,0.000288,1.337629,0.000384,0.033244,0.000192,0.76009,0.000192,0.001537,0.073021,1.394892,0.069754,0.417565,0.000769,0.976175,0.105112,0.294294 [...]
+		,{0.025217,0.006558,0.261069,0.005535,0.487542,0.138742,3.121656,0.151589,0.03214,0.025873,0,0,0.002795,0.01025,0,0.070308,0.065669,0.016609,1.07379,0.040917,40.922701,15.426733,0,15.127582,0.286252,0.089835,1.05204,0.184327,0.063413,0.001702,0.626603,0.0103,0.002597,0.000448,0.480521,0.042006,0.345545,0.027138,1.018005,0.083475,0.096104,0.074161,1.042457,0.012002,0.021048,0.005195,0.493508,0.009225,0.009225,0.000537,0.732111,0.000717,0.346978,0.013077,1.236457,0.017824,0.147873,0.0036 [...]
+		,{0.004063,0.079161,0,0.112999,0.021444,0.371063,0.064924,2.075226,0.004177,0.037372,0,0,0.000155,0.004585,0,0.215788,0.007978,0.118229,0.016442,0.495176,10.291826,33.45378,15.127582,0,0.054021,0.364129,0.063366,0.715716,0.044676,0.798346,0.091073,1.164525,0.000246,0.021723,0,0.193459,0.011476,0.527094,0.015001,0.962295,0.002705,0.095418,0.00041,0.561523,0.001066,0.104681,0,0.273876,0.000246,0.031642,0.000082,0.602428,0.013526,0.971148,0.087384,1.950083,0.03156,0.644235,0.00541,0.99033 [...]
+		,{0.638696,0.001312,0.026551,0.040275,1.253945,0.002137,0.128111,0.07373,3.088481,0.340541,0,0,0.634065,0.001483,0,0.195073,0.664866,0.057328,0.438648,0.044742,0.775254,0.091276,0.286252,0.054021,0,38.685701,2.473439,1.106179,2.460976,0.170088,1.35386,0.316372,0.193328,0.000469,0.040109,0.323588,0.898794,0.001125,0.082373,0.076938,2.691226,0.46097,0.899262,0.324525,1.293228,0.00506,0.411115,0.140943,0.338207,0.000375,0.019586,0.032237,0.42058,0.000562,0.039265,0.080124,0.746792,0.10092 [...]
+		,{0.000467,0.761771,0.000123,0.002163,0.000593,1.144692,0.01447,0.114551,0.265766,3.193996,0,0,0.000155,0.483076,0,0.369273,0.058614,0.617694,0.059927,0.330036,0.061583,0.730306,0.089835,0.364129,38.685701,0,0.751904,2.503268,0.277265,2.478358,0.526904,2.20843,0,0.127899,0.000272,0.163406,0.000272,0.969387,0.02192,0.10308,0.188587,2.203539,0.143479,0.571469,0.000453,1.282522,0.025544,0.169022,0.000091,0.491034,0.002808,0.044112,0.000091,0.696016,0.004982,0.190037,0.046739,0.975727,0.10 [...]
+		,{0.12632,0.016628,0.576476,0.007508,0.508308,0.080383,2.066955,0.002179,0.486281,0.079236,0,0,0.163174,0.032232,0,0.055163,0.529045,0.071794,1.205738,0.033372,0.435109,0.074846,1.05204,0.063366,2.473439,0.751904,0,17.923045,1.164262,0.14894,4.72584,0.299978,0.078926,0.010543,0.390087,0.443617,0.374419,0.066519,1.660885,0.002854,1.759732,0.377447,3.215817,0.461383,1.177718,0.232701,1.24214,0.003786,0.150804,0.006757,0.606945,0.000466,0.27295,0.018814,1.274118,0.001165,0.706782,0.121389 [...]
+		,{0.00976,0.107218,0,0.250748,0.049246,0.423382,0.002122,1.519211,0.09207,0.332396,0,0,0.05791,0.105597,0,0.24749,0.079119,0.422671,0.105449,0.703795,0.107434,0.529594,0.184327,0.715716,1.106179,2.503268,17.923045,0,0.340811,2.029914,0.61732,4.718199,0.003859,0.105885,0.000048,0.834976,0.029088,0.617464,0.001302,1.766961,0.206851,0.985145,0.285384,2.285052,0.083261,1.418383,0.000289,1.148387,0.0096,0.06932,0.000145,0.475496,0.040907,0.634927,0.002219,1.544626,0.130873,0.928319,0.536567 [...]
+		,{0.143832,0.000094,0.000741,0.003054,0.660622,0.001208,0.000579,0.00172,0.534375,0.001377,0,0,0.726908,0.077815,0,0.019696,0.663877,0.068758,0.134394,0.015019,0.500433,0.124232,0.063413,0.044676,2.460976,0.277265,1.164262,0.340811,0,27.244097,39.595443,12.868484,0.076434,0.000118,0,0.028736,0.344601,0.00106,0.000589,0.004593,0.682254,0.00318,1.769879,0.560831,0.772349,0.387941,17.450524,6.798629,0.336828,0.000589,0.000353,0.001413,0.324227,0.000236,0.000589,0.001531,0.162525,0.000236, [...]
+		,{0,0.200806,0,0.000064,0,0.685812,0,0.032106,0.000116,0.604541,0,0,0.012886,0.516927,0,0.176476,0.016022,0.544828,0.005436,0.563956,0.002398,0.563799,0.001702,0.798346,0.170088,2.478358,0.14894,2.029914,27.244097,0,12.677657,35.563093,0,0.238839,0,0.029786,0,1.481721,0,0.014243,0.000068,0.863191,0.296358,2.721043,0.018146,1.320875,1.113671,4.087042,0,0.648523,0,0.003287,0,1.610248,0.000068,0.083744,0,0.915505,0.025678,0.528692,0.004656,0.676049,0.000753,0.097165}
+		,{0.030121,0.01602,0.136647,0.001527,0.006103,0.004089,0.557015,0.003211,0.043917,0.051686,0,0,0.232728,0.16615,0,0.146501,0.424607,0.112395,0.918198,0.041969,0.352807,0.154017,0.626603,0.091073,1.35386,0.526904,4.72584,0.61732,39.595443,12.677657,0,30.574631,0.000416,0.001248,0.121855,0.015596,0.00104,0.002079,0.360575,0.002911,0.009981,0.016636,3.06551,0.034519,0.530881,0.354545,31.949764,15.287419,0.003743,0.001871,0.255147,0.000832,0.001871,0.000416,0.286547,0.000624,0.00707,0.0099 [...]
+		,{0.000934,0.027355,0,0.127696,0.000085,0.004832,0,1.903571,0.003713,0.081931,0,0,0.023909,0.183143,0,1.13591,0.039428,0.640495,0.040902,0.794366,0.00988,0.897101,0.0103,1.164525,0.316372,2.20843,0.299978,4.718199,12.868484,35.563093,30.574631,0,0,0.003064,0,0.40868,0,0.017774,0,2.985421,0.000981,0.065212,0.011032,3.8322,0.025006,1.360141,2.418859,18.531553,0,0.005026,0,0.701399,0,0.020471,0.000123,3.409178,0.000368,0.150527,0.000858,2.171984,0.011768,0.703728,0.010419,0.590833}
+		,{1.119411,0.059956,2.130663,1.292935,0.172403,0,0.000386,0,0.352731,0.00018,0,0,0.431456,0.000405,0,0.078312,3.330793,0.18401,1.328581,0.089308,0.292855,0.000096,0.002597,0.000246,0.193328,0,0.078926,0.003859,0.076434,0,0.000416,0,0,13.60931,16.415611,1.155098,1.266654,0.034573,0.296014,0.090674,0.239388,0.025405,0.221536,0.04144,0.359183,0.03114,0.116039,0.093542,6.546163,0.458622,2.581654,0.953353,0.536332,0.00004,0.002262,0.000081,0.066966,0,0.038612,0.003312,0.069995,0.000283,0.00 [...]
+		,{0.056038,1.006045,0.042112,0.478019,0,0.115975,0.000096,0.000344,0.000116,0.255975,0,0,0.000311,0.309643,0,0.136849,0.39019,3.765697,0.203017,2.469249,0.000096,0.270274,0.000448,0.021723,0.000469,0.127899,0.010543,0.105885,0.000118,0.238839,0.001248,0.003064,13.60931,0,5.784672,1.428293,0.075878,1.066285,0.048902,0.311759,0.014351,0.175491,0.02302,0.116405,0.018727,0.238533,0.012331,0.062369,0.575921,7.487816,0.313779,3.487342,0.000253,0.536362,0.000589,0.004629,0.000042,0.032447,0.0 [...]
+		,{1.075187,0.064968,5.159075,1.065537,0.000424,0,0.403435,0,0.573013,0.025454,0,0,0.069555,0.012138,0,0.170041,1.260239,0.136148,4.40061,0.048882,0.002014,0,0.480521,0,0.040109,0.000272,0.390087,0.000048,0,0,0.121855,0,16.415611,5.784672,0,2.230691,0.351882,0.016701,2.260424,0.154441,0.256283,0.020837,0.667397,0.056267,0.269862,0.021539,0.780008,0.317466,2.577578,0.154207,11.271062,0.911193,0.001795,0,0.983926,0.000078,0.001171,0,0.361403,0.000078,0.000156,0,0.194319,0.000078}
+		,{0.67937,0.800602,1.418466,3.062807,0.093491,0.042282,0.246094,0.527005,0.294368,0.300354,0,0,0.298091,0.324613,0,0.321642,1.22002,1.434579,1.635281,2.236557,0.081631,0.008455,0.042006,0.193459,0.323588,0.163406,0.443617,0.834976,0.028736,0.029786,0.015596,0.40868,1.155098,1.428293,2.230691,0,0.419831,0.433759,0.853779,1.376727,0.208924,0.21917,0.275355,0.497593,0.306375,0.304581,0.305714,0.90581,0.430124,0.350473,0.569076,1.399673,0.451134,0.169264,0.517896,0.837302,0.059065,0.011379 [...]
+		,{0.497293,0.000141,0.012473,0.015652,4.693944,0.487317,2.297807,0.199748,0.599932,0.000599,0,0,1.089585,0.001483,0,0.035939,0.831215,0.00006,0.004348,0.00007,1.050363,0.053805,0.345545,0.011476,0.898794,0.000272,0.374419,0.029088,0.344601,0,0.00104,0,1.266654,0.075878,0.351882,0.419831,0,13.991583,31.915858,12.116657,2.057449,0.296066,0.878163,0.291009,4.943439,0.622868,0.432918,0.309656,2.898791,0.001027,0.009008,0.003635,2.359362,0.038559,0.381796,0.023862,0.928969,0.000158,0.251423 [...]
+		,{0.000093,0.371541,0.000062,0.00299,0.196983,3.82958,0.150107,2.395833,0.000116,0.393545,0,0,0.000776,0.806071,0,0.037822,0.000396,0.89749,0.000679,0.073657,0.044125,0.870967,0.027138,0.527094,0.001125,0.969387,0.066519,0.617464,0.00106,1.481721,0.002079,0.017774,0.034573,1.066285,0.016701,0.433759,13.991583,0,8.373639,28.470047,0.067554,1.346385,0.089476,0.623366,0.275865,4.699375,0.021698,0.140701,0.00302,2.862216,0.001957,0.089643,0.120121,2.159328,0.077341,0.728891,0.000559,1.0134 [...]
+		,{0.079948,0.010539,0.871568,0.011134,2.018483,0.409721,5.709933,0.349846,0.208041,0.053363,0,0,0.415775,0.061227,0,0.060421,0.000857,0.000119,0.94456,0.00007,0.368538,0.02623,1.018005,0.015001,0.082373,0.02192,1.660885,0.001302,0.000589,0,0.360575,0,0.296014,0.048902,2.260424,0.853779,31.915858,8.373639,0,19.459275,1.243753,0.259909,1.523251,0.256174,2.397415,0.441084,1.316696,0.511968,0.05625,0.002515,3.879355,0.011433,0.324162,0.019665,2.735831,0.049848,0.092988,0.003354,1.164866,0. [...]
+		,{0.008032,0.036489,0.000062,0.586818,0.361164,1.562591,0.516594,4.919174,0.042119,0.177757,0,0,0.053874,0.173298,0,0.362681,0.000264,0.000595,0.000408,0.733202,0.079712,0.435243,0.083475,0.962295,0.076938,0.10308,0.002854,1.766961,0.004593,0.014243,0.002911,2.985421,0.090674,0.311759,0.154441,1.376727,12.116657,28.470047,19.459275,0,0.224397,0.822133,0.199589,1.144639,0.563566,2.871848,0.087905,0.765495,0.004868,0.010298,0.002528,3.0925,0.108501,0.498504,0.318574,2.866325,0.042595,0.0 [...]
+		,{0.263567,0.000094,0.271628,0.077878,1.773102,0.000929,0.872084,0.040706,0.74787,0.042762,0,0,0.360038,0.000135,0,0.074859,0.25938,0,0.019568,0.00014,0.78734,0.000192,0.096104,0.002705,2.691226,0.188587,1.759732,0.206851,0.682254,0.000068,0.009981,0.000981,0.239388,0.014351,0.256283,0.208924,2.057449,0.067554,1.243753,0.224397,0,17.634677,2.075154,0.524647,4.971507,0.643789,0.93684,0.454347,0.318595,0,0.008844,0.000628,0.64316,0.000045,0.08462,0.003771,3.529593,0.167041,0.975582,0.149 [...]
+		,{0.000093,0.143614,0.00284,0.060699,0.00339,1.118208,0.187826,0.725836,0.046586,0.487814,0,0,0.000932,0.325422,0,0.053908,0.00033,0.18788,0.01454,0.034916,0.000959,0.532092,0.074161,0.095418,0.46097,2.203539,0.377447,0.985145,0.00318,0.863191,0.016636,0.065212,0.025405,0.175491,0.020837,0.21917,0.296066,1.346385,0.259909,0.822133,17.634677,0,0.413957,1.038682,0.586685,4.127466,0.273855,0.600415,0.000295,0.215492,0.002362,0.013582,0.001329,0.565968,0.041435,0.068501,0.371685,2.729647,0 [...]
+		,{0.148268,0.005996,0.61266,0.004963,0.340991,0.020909,1.496628,0.000459,0.467136,0.042942,0,0,0.099519,0.004316,0,0.051005,0.060922,0.002143,0.43362,0.000035,0.247195,0.012394,1.042457,0.00041,0.899262,0.143479,3.215817,0.285384,1.769879,0.296358,3.06551,0.011032,0.221536,0.02302,0.667397,0.275355,0.878163,0.089476,1.523251,0.199589,2.075154,0.413957,0,12.931524,1.29386,0.334224,5.815294,1.868194,0.20148,0.00193,0.708204,0.000193,0.216244,0.0055,0.923644,0.000482,0.604859,0.053168,2.2 [...]
+		,{0.013122,0.043609,0.000062,0.33378,0.156468,0.25165,0.004438,0.768607,0.072867,0.140864,0,0,0.011489,0.034794,0,0.105226,0.039362,0.022384,0.000679,0.133032,0.220816,0.303613,0.012002,0.561523,0.324525,0.571469,0.461383,2.285052,0.560831,2.721043,0.034519,3.8322,0.04144,0.116405,0.056267,0.497593,0.291009,0.623366,0.256174,1.144639,0.524647,1.038682,12.931524,0,0.389004,0.928876,1.197614,7.316623,0.072138,0.056145,0.000524,0.311885,0.268662,0.373948,0.004382,0.759132,0.188097,0.42668 [...]
+		,{0.225554,0.000047,0.010929,0.009289,12.169045,0.083636,5.964323,0.681575,0.50647,0.00018,0,0,2.007768,0.181794,0,0.139046,0.322807,0.00006,0.009512,0.000105,1.035015,0.000288,0.021048,0.001066,1.293228,0.000453,1.177718,0.083261,0.772349,0.018146,0.530881,0.025006,0.359183,0.018727,0.269862,0.306375,4.943439,0.275865,2.397415,0.563566,4.971507,0.586685,1.29386,0.389004,0,28.579806,1.644621,1.477696,0.501456,0.000097,0.006305,0.001358,2.323091,0.000485,0.126382,0.006402,1.702817,0.000 [...]
+		,{0.000093,0.166706,0.000432,0.00579,0.094762,10.892976,1.049877,9.818281,0.000116,0.34689,0,0,0.248099,1.372357,0,0.167138,0.00033,0.300513,0.002718,0.0173,0.001247,1.337629,0.005195,0.104681,0.00506,1.282522,0.232701,1.418383,0.387941,1.320875,0.354545,1.360141,0.03114,0.238533,0.021539,0.304581,0.622868,4.699375,0.441084,2.871848,0.643789,4.127466,0.334224,0.928876,28.579806,0,0.403913,1.28699,0.000219,0.381287,0.000657,0.00416,0.005328,2.214735,0.063353,0.200205,0.012481,2.005334,0 [...]
+		,{0.140516,0.0126,0.423774,0.001718,0.04789,0.002044,1.094736,0.000115,0.424321,0.060909,0,0,0.144388,0.030883,0,0.145245,0.004747,0.00006,0.409432,0,0.011511,0.000384,0.493508,0,0.411115,0.025544,1.24214,0.000289,17.450524,1.113671,31.949764,2.418859,0.116039,0.012331,0.780008,0.305714,0.432918,0.021698,1.316696,0.087905,0.93684,0.273855,5.815294,1.197614,1.644621,0.403913,0,43.916187,0.032116,0.000205,0.560642,0.000103,0.013852,0,0.461729,0,0.030474,0.000718,0.668173,0.00041,0.037657 [...]
+		,{0.08331,0.056771,0.000247,0.506841,0.063994,0.028715,0.009261,0.514392,0.200499,0.26951,0,0,0.122186,0.070533,0,0.496706,0.00956,0.000952,0.000951,0.04032,0.060432,0.033244,0.009225,0.273876,0.140943,0.169022,0.003786,1.148387,6.798629,4.087042,15.287419,18.531553,0.093542,0.062369,0.317466,0.90581,0.309656,0.140701,0.511968,0.765495,0.454347,0.600415,1.868194,7.316623,1.477696,1.28699,43.916187,0,0.051709,0.002062,0.002062,0.314379,0.045374,0.001768,0.00442,0.187832,0.015763,0.00898 [...]
+		,{0.86397,0.065905,0.748196,0.529619,0.563995,0.000186,0.002219,0.000115,0.571505,0.000359,0,0,1.598824,0.004316,0,0.038763,1.89715,0.072866,0.555104,0.01158,0.708395,0.000192,0.009225,0.000246,0.338207,0.000091,0.150804,0.0096,0.336828,0,0.003743,0,6.546163,0.575921,2.577578,0.430124,2.898791,0.00302,0.05625,0.004868,0.318595,0.000295,0.20148,0.072138,0.501456,0.000219,0.032116,0.051709,0,10.956917,25.313949,8.832621,2.600428,0.046583,0.718719,0.054049,0.153418,0.004101,0.276499,0.049 [...]
+		,{0.026338,0.946136,0.00599,0.140867,0.000085,0.396897,0.000096,0.001261,0.000116,0.582801,0,0,0.001087,1.273908,0,0.092044,0.105361,2.720153,0.043756,1.08517,0.000192,0.76009,0.000537,0.031642,0.000375,0.491034,0.006757,0.06932,0.000589,0.648523,0.001871,0.005026,0.458622,7.487816,0.154207,0.350473,0.001027,2.862216,0.002515,0.010298,0,0.215492,0.00193,0.056145,0.000097,0.381287,0.000205,0.002062,10.956917,0,5.637509,18.744445,0.131929,2.620833,0.092405,0.968351,0.007112,0.119062,0.04 [...]
+		,{0.565566,0.047403,2.299543,0.762425,0.001356,0.000279,0.81372,0.000115,0.236179,0.06043,0,0,0.754233,0.086986,0,0.058616,0.509595,0.03173,2.047159,0.020529,0.001151,0.000192,0.732111,0.000082,0.019586,0.002808,0.606945,0.000145,0.000353,0,0.255147,0,2.581654,0.313779,11.271062,0.569076,0.009008,0.001957,3.879355,0.002528,0.008844,0.002362,0.708204,0.000524,0.006305,0.000657,0.560642,0.002062,25.313949,5.637509,0,13.945647,0.662578,0.028569,3.415722,0.081861,0.078381,0.006776,0.469281 [...]
+		,{0.068927,0.371072,0.024699,1.108802,0.000254,0.001394,0.000772,0.451899,0.00963,0.116309,0,0,0.126844,0.530278,0,0.277072,0.091844,0.477439,0.173122,2.26249,0.000384,0.001537,0.000717,0.602428,0.032237,0.044112,0.000466,0.475496,0.001413,0.003287,0.000832,0.701399,0.953353,3.487342,0.911193,1.399673,0.003635,0.089643,0.011433,3.0925,0.000628,0.013582,0.000193,0.311885,0.001358,0.00416,0.000103,0.314379,8.832621,18.744445,13.945647,0,0.152215,0.682579,0.415718,2.211488,0.011491,0.0412 [...]
+		,{0.483563,0.000234,0.008892,0.03563,3.994417,0.771771,1.825878,0.250545,0.370309,0.000419,0,0,1.899865,0.011733,0,0.03586,0.879741,0.000417,0.004077,0.000772,1.272426,0.073021,0.346978,0.013526,0.42058,0.000091,0.27295,0.040907,0.324227,0,0.001871,0,0.536332,0.000253,0.001795,0.451134,2.359362,0.120121,0.324162,0.108501,0.64316,0.001329,0.216244,0.268662,2.323091,0.005328,0.013852,0.045374,2.600428,0.131929,0.662578,0.152215,0,9.612709,24.400553,5.140068,0.396521,0.018617,0.502355,0.1 [...]
+		,{0.000093,0.512203,0,0.001654,0.111968,3.45257,0.084218,1.978448,0.000058,0.380788,0,0,0.000466,1.514097,0,0.044178,0.000132,1.191514,0.000136,0.103766,0.022062,1.394892,0.013077,0.971148,0.000562,0.696016,0.018814,0.634927,0.000236,1.610248,0.000416,0.020471,0.00004,0.536362,0,0.169264,0.038559,2.159328,0.019665,0.498504,0.000045,0.565968,0.0055,0.373948,0.000485,2.214735,0,0.001768,0.046583,2.620833,0.028569,0.682579,9.612709,0,6.74656,19.373137,0.01514,0.802516,0.140546,0.938586,0. [...]
+		,{0.109975,0.016535,1.041312,0.019406,1.93135,0.5585,4.380679,0.505677,0.176829,0.034737,0,0,0.806554,0.297371,0,0.031466,0.002374,0.000357,0.741135,0.000351,0.335924,0.069754,1.236457,0.087384,0.039265,0.004982,1.274118,0.002219,0.000589,0.000068,0.286547,0.000123,0.002262,0.000589,0.983926,0.517896,0.381796,0.077341,2.735831,0.318574,0.08462,0.041435,0.923644,0.004382,0.126382,0.063353,0.461729,0.00442,0.718719,0.092405,3.415722,0.415718,24.400553,6.74656,0,11.561124,0.18909,0.027912 [...]
+		,{0.005884,0.074851,0,0.220908,0.103323,1.262618,0.150589,4.658653,0.027035,0.106187,0,0,0.028567,0.586111,0,0.446015,0.000066,0.000893,0,1.524024,0.014101,0.417565,0.017824,1.950083,0.080124,0.190037,0.001165,1.544626,0.001531,0.083744,0.000624,3.409178,0.000081,0.004629,0.000078,0.837302,0.023862,0.728891,0.049848,2.866325,0.003771,0.068501,0.000482,0.759132,0.006402,0.200205,0,0.187832,0.054049,0.968351,0.081861,2.211488,5.140068,19.373137,11.561124,0,0.043198,0.702594,0.227527,1.25 [...]
+		,{0.064397,0,0.042112,0.038557,1.120532,0.003717,0.348448,0.117533,0.223763,0.015452,0,0,0.099985,0.000135,0,0.028249,0.129492,0,0.012366,0.000491,0.661776,0.000769,0.147873,0.03156,0.746792,0.046739,0.706782,0.130873,0.162525,0,0.00707,0.000368,0.066966,0.000042,0.001171,0.059065,0.928969,0.000559,0.092988,0.042595,3.529593,0.371685,0.604859,0.188097,1.702817,0.012481,0.030474,0.015763,0.153418,0.007112,0.078381,0.011491,0.396521,0.01514,0.18909,0.043198,0,14.214694,2.738552,1.091224, [...]
+		,{0,0.055366,0.000062,0.006808,0.000254,1.023142,0.007428,0.670108,0.010037,0.184704,0,0,0,0.071612,0,0.066384,0.000066,0.135255,0.001359,0.015686,0.000096,0.976175,0.003672,0.644235,0.100928,0.975727,0.121389,0.928319,0.000236,0.915505,0.009981,0.150527,0,0.032447,0,0.011379,0.000158,1.013424,0.003354,0.095207,0.167041,2.729647,0.053168,0.426684,0.000388,2.005334,0.000718,0.008986,0.004101,0.119062,0.006776,0.04128,0.018617,0.802516,0.027912,0.702594,14.214694,0,0.892903,3.195698,0.03 [...]
+		,{0.084945,0.006464,0.287373,0.005472,0.330481,0.08568,1.265487,0.002179,0.257122,0.043721,0,0,0.028878,0.003641,0,0.009966,0.03956,0.002679,0.313495,0.00014,0.184749,0.105112,0.890822,0.00541,0.452442,0.106069,3.081614,0.536567,0.034978,0.025678,0.440217,0.000858,0.038612,0.009174,0.361403,0.033994,0.251423,0.109664,1.164866,0.003464,0.975582,0.193544,2.258321,0.308851,0.832592,0.308372,0.668173,0.00442,0.276499,0.042565,0.469281,0.055025,0.502355,0.140546,0.905488,0.227527,2.738552,0 [...]
+		,{0.010974,0.034428,0,0.159955,0.04238,0.283432,0.001061,1.029128,0.042815,0.136432,0,0,0.014439,0.013216,0,0.137634,0.00422,0.010061,0.000136,0.1763,0.034437,0.294294,0.001791,0.99033,0.159217,0.566034,0.343314,3.036767,0.007891,0.528692,0.00104,2.171984,0.003312,0.031984,0.000078,0.262465,0.033581,0.360196,0.000838,1.447392,0.149578,0.372719,0.159248,1.563846,0.129098,0.822643,0.00041,1.19579,0.049842,0.245019,0.053017,0.362328,0.106257,0.938586,0.157605,1.251589,1.091224,3.195698,12 [...]
+		,{0.164659,0.000141,0.000741,0.003881,0.976185,0.001951,0.011673,0.007109,0.13094,0.00012,0,0,0.420899,0.045044,0,0.039313,0.169777,0.00006,0.000272,0.000175,0.418802,0.000288,0.002508,0.001312,0.388156,0.000091,0.042812,0.003377,0.241197,0.004656,0.042005,0.011768,0.069995,0,0.000156,0.027479,0.380374,0.000112,0.000534,0.000374,1.322234,0.005905,0.04873,0.021649,2.382451,0.326035,0.037657,0.047437,0.164143,0.016776,0.072521,0.024883,1.572808,0.086923,0.585071,0.083552,0.629243,0.03512 [...]
+		,{0,0.172889,0,0.000191,0.000085,0.880032,0.000289,0.356038,0.000058,0.127388,0,0,0.007608,0.309374,0,0.105305,0,0.240505,0,0.047268,0.000096,0.636916,0.00009,0.395771,0.000843,0.566759,0.016193,0.336277,0.021435,0.676049,0.008942,0.703728,0.000283,0.055425,0,0.018603,0,0.518903,0,0.006459,0.001122,1.110726,0.002863,0.176224,0.054025,2.392606,0.000821,0.012227,0.00205,0.201477,0.001557,0.051048,0.022214,1.797671,0.027973,1.398079,0.037461,1.228004,0.030585,0.239725,13.93595,0,5.214689, [...]
+		,{0.113991,0.018315,0.201112,0.001082,0.012121,0.001951,1.720919,0.00172,0.082323,0.029826,0,0,0.197641,0.061497,0,0.073682,0.00033,0.00006,0.165784,0.00007,0.003549,0.000384,0.556204,0.000164,0.097554,0.004982,0.551493,0.000289,0.01531,0.000753,0.247245,0.010419,0.000283,0.000084,0.194319,0.037724,0.002449,0.000112,0.46677,0.000187,0.909861,0.2804,0.713961,0.00176,1.179053,0.298738,0.938439,0.165587,0.080337,0.009773,0.324696,0.016839,0.658541,0.036022,1.693998,0.046588,0.375097,0.067 [...]
+		,{0.018773,0.032039,0,0.175861,0.002797,0.002974,0.003376,2.163175,0.007948,0.014314,0,0,0.105884,0.183952,0,0.381671,0.000066,0.000119,0,0.185038,0.001918,0.001441,0.001254,0.703092,0.08406,0.053714,0.003029,0.634203,0.043222,0.097165,0.143481,0.590833,0.000081,0.000295,0.000078,0.410199,0.000553,0.000447,0.00061,0.716441,0.194964,0.293884,0.001158,0.744,0.684968,1.149846,0.069567,1.558784,0.032177,0.064227,0.074536,0.276276,0.238907,0.496552,0.672077,1.526141,0.235747,0.403521,0.1369 [...]
+
+
+		double ECMunrestPi[64]=
+		{0.021414,0.021349,0.016195,0.015717,0.011798,0.010761,0.010366,0.008721,0.017237,0.016697,0,0,0.006441,0.007415,0,0.012744,0.015167,0.016798,0.007359,0.028497,0.010425,0.010408,0.011165,0.012199,0.010671,0.01104,0.017168,0.02073,0.008491,0.014604,0.004809,0.008158,0.024759,0.023762,0.012814,0.02118,0.012656,0.017882,0.01312,0.010682,0.022276,0.020321,0.03109,0.026699,0.01031,0.013701,0.009746,0.006788,0.01902,0.018419,0.010921,0.022626,0.018907,0.026817,0.016516,0.018288,0.02859,0.025 [...]
+
+		if(basefreqs.empty()) for(int gv3=0; gv3<64; gv3++) basefreqs.push_back(ECMunrestPi[gv3]); 
+			
+		for(int gv1=0; gv1<64; gv1++) {row.clear(); {for(int gv2=0; gv2<64; gv2++) row.push_back(ECMunrestQ[gv1][gv2]);} myQvec.push_back(row);}
+
+		return myQvec;
+}
+
+vector<vector<double> > getCOD(string &name, vector<double> &basefreqs, int mymodel, double kappa, double omega)
+{
+	//	make Q matrix for codon models
+
+	vector<vector<double> > myQvec;
+	vector<double> row;
+
+
+		for(int xh1=0; xh1<4; xh1++)
+		{for(int xh2=0; xh2<4; xh2++)
+		{for(int xh3=0; xh3<4; xh3++)
+		{
+
+		for(int yh1=0; yh1<4; yh1++)
+		{for(int yh2=0; yh2<4; yh2++)
+		{for(int yh3=0; yh3<4; yh3++)
+		{
+			int xcodonNumber  = (xh1<<4)+(xh2<<2)+xh3; //getCodonNumber2(xh1,xh2,xh3);
+			int ycodonNumber  = (yh1<<4)+(yh2<<2)+yh3; //getCodonNumber2(yh1,yh2,yh3);
+ 
+			double matrixrate=0;
+ 
+			char xcodon=GeneticCodeTable[geneticcode][xcodonNumber];
+			char ycodon=GeneticCodeTable[geneticcode][ycodonNumber];
+
+		    if(xcodon!='*' && ycodon!='*')
+			{				
+				if(yh1==xh1 && yh2==xh2 && yh3==xh3) matrixrate=0;
+
+				else 
+				if(yh1==xh1 && yh2==xh2)
+				{
+					if(xcodon!=ycodon) matrixrate=omega; else matrixrate=1; 
+//	 				if( (yh3==0 && xh3==1) || (yh3==1 && xh3==0) || (yh3==3 && xh3==2) || (yh3==2 && xh3==3) )  matrixrate*=kappa;
+					if((yh3+xh3-1)*(yh3+xh3-5)==0)  matrixrate*=kappa;  
+				}
+				else if(yh1==xh1 && yh3==xh3)
+				{
+					if(xcodon!=ycodon) matrixrate=omega; else matrixrate=1; 
+//					if( (yh2==0 && xh2==1) || (yh2==1 && xh2==0) || (yh2==3 && xh2==2) || (yh2==2 && xh2==3) )  matrixrate*=kappa;
+					if((yh2+xh2-1)*(yh2+xh2-5)==0)  matrixrate*=kappa;  
+				}
+				else if(yh2==xh2 && yh3==xh3) 
+				{
+					if(xcodon!=ycodon) matrixrate=omega; else matrixrate=1; 
+//	 				if( (yh1==0 && xh1==1) || (yh1==1 && xh1==0) || (yh1==3 && xh1==2) || (yh1==2 && xh1==3) )  matrixrate*=kappa;
+					if((yh1+xh1-1)*(yh1+xh1-5)==0)  matrixrate*=kappa;  
+				}
+			}
+			//else cout<<xcodon<<" "<<ycodon<<"     ";   
+			
+			row.push_back(matrixrate);
+			}}} // end of second for triple
+
+		myQvec.push_back(row);
+		row.clear();
+		}}} // end of first for triple
+		
+
+		
+
+
+
+		/*
+		// checks that the matrices are symmetrical 
+		for ( i=0; i<64; i++)
+		{						CPi[i]=mybasefreqs.at(i);
+		for (j=i+1; j<64; j++)
+		{ 
+			diff = Cmatrix[i][j] - Cmatrix[j][i];
+			if (diff < 0.0)
+				diff = -diff;
+			if (diff > 0.001)  
+				if(ECMrest)cout<<" ERROR: ECMrestCodon model is not symmetrical before frequencies.\n";
+				else if(ECMunrest)cout<<" ERROR: ECMunrest Codon model is not symmetrical before frequencies.\n";
+				else cout<<" ERROR: User Codon model is not symmetrical before frequencies.\n";
+				
+				
+			}
+		}
+		*/
+
+		int i,j;
+		// rescale stationary frequencies, to make certain they sum to 1.0 
+		double sum = 0.0;
+		for (i=0; i<64; i++) sum += basefreqs.at(i); //cout<<basefreqs.at(i)<<" ";} cout<<endl;
+		if(sum!=1) for (i=0; i<64; i++) basefreqs.at(i) /= sum;
+			
+		
+		// multiply entries by stationary frequencies 
+		for (i=0; i<64; i++) for (j=0; j<64; j++) (myQvec.at(i)).at(j) *= basefreqs.at(j);
+		
+
+		// rescale, so branch lengths are in terms of expected number of substitutions per site 
+		double scaler = 0.0;
+		for ( i=0; i<64; i++)
+		{
+			for ( j=i+1; j<64; j++)
+			{
+				scaler += basefreqs.at(i) * (myQvec.at(i)).at(j);
+				scaler += basefreqs.at(j) * (myQvec.at(j)).at(i);
+			}
+		}
+
+		//set diagonal of matrix
+		for( i=0; i<64; i++) {sum=0; for(j=0; j<64; j++) if(i!=j) sum+=(myQvec.at(i)).at(j); (myQvec.at(i)).at(i)=-sum; }
+		
+		scalefactors.push_back(scaler);
+
+	return myQvec;
+
+}
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+}; // end of modelclass
+
+///////////////////
+/*
+double main(int argc, char* argv[])
+{	
+
+	return 0;
+}
+
+
+*/
+
diff --git a/src/paml.cpp b/src/paml.cpp
new file mode 100644
index 0000000..34fc3a1
--- /dev/null
+++ b/src/paml.cpp
@@ -0,0 +1,2164 @@
+/* 
+   INDELible V1.03
+    "A comprehensive and flexible simulator of molecular sequence evolution"
+    Copyright (C) 2009 William Fletcher
+
+    If using this software please cite the following reference:
+
+    Fletcher, W. and Yang, Z. 2009. 
+	"INDELible: a flexible simulator of biological sequence evolution." 
+	Mol. Biol. and Evol. (in press). 
+
+    If you need to contact me with any queries, questions, problems or (god-forbid) bugs
+    then please go to http://abacus.gene.ucl.ac.uk/software/indelible/bug.php
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    Please visit http://www.gnu.org/licenses/ for a full copy of the license.
+*/
+
+
+
+
+// almost all the functions in this file were borrowed from PAML (by Ziheng Yang).
+
+// the code is for calculation of P(t) from Q
+
+// for calculation of random gamma rate variation
+
+// and for producing random trees through the birth/death process.
+
+
+#include <math.h>
+#include "randoms.cpp"
+#include <string>
+#include <sstream>
+#include <vector>
+#include "float.h"
+#include <iostream>
+#include <fstream>
+#include <time.h>
+
+#define square(a) ((a)*(a))
+#define min2(a,b) ((a)<(b)?(a):(b))
+#define max2(a,b) ((a)>(b)?(a):(b))
+
+extern double myrand;
+extern int idum;
+		
+using namespace std;
+
+#define FOR(i,n) for(i=0; i<n; i++)
+
+int identity (double x[], int n)
+{ int i,j;  FOR (i,n)  { FOR(j,n)  x[i*n+j]=0;  x[i*n+i]=1; }  return (0); }
+
+int zero (double x[], int n)
+{ int i; FOR (i,n) x[i]=0; return (0);}
+
+int NPMatUVRoot=0; 
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+int matby (double a[], double b[], double c[], int n,int m,int k)
+/* a[n*m], b[m*k], c[n*k]  ......  c = a*b  */
+{
+   int i,j,i1;
+   double t;
+   FOR (i,n)  FOR(j,k) {
+      for (i1=0,t=0; i1<m; i1++) t+=a[i*m+i1]*b[i1*k+j];
+      c[i*k+j] = t;
+   }
+   return (0);
+}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//int matexp (double Q[], double t, int n, /*int TimeSquare, */double space[])
+vector<vector<double> > matexp (vector<vector<double> > Qvec, vector<double> &basefreqs,  double t)
+{
+
+	// modified by WF
+
+	int TimeSquare=30,  n=basefreqs.size(), j;
+	vector<vector<double> > Pmat;
+	vector<double> row;
+/* 
+Method of calculating P(t) from Q using the repeated matrix squaring that is implemented in the PAML package (Yang, 1997). 
+
+  Yang, Z. (1997) PAML: a program for package for phylogenetic analysis by maximum likelihood. CABIOS 15: 555-556.
+
+  Original notes from ZY follows:
+  
+-----------------------------------
+
+  This calculates the matrix exponential P(t) = exp(t*Q).
+   Input: Q[] has the rate matrix, and t is the time or branch length.
+          TimeSquare is the number of times the matrix is squared and should 
+          be from 5 to 31.
+   Output: Q[] has the transition probability matrix, that is P(Qt).
+   space[n*n]: required working space.
+
+      P(t) = (I + Qt/m + (Qt/m)^2/2)^m, with m = 2^TimeSquare.
+
+   T[it=0] is the current matrix, and T[it=1] is the squared result matrix,
+   used to avoid copying matrices.
+   Use an even TimeSquare to avoid one round of matrix copying.
+*/
+
+
+
+
+		int it, i;
+
+		double Q[4096];  double space[8320]; double pi[64];
+
+
+	   	for(i=0; i<n; i++) 
+		{
+			pi[i]=basefreqs.at(i);
+
+			for(j=0; j<n; j++) Q[(i*n)+j]=(Qvec.at(i)).at(j); 
+		}
+	   
+
+
+	   double *T[2];
+
+	//   if(TimeSquare<2 || TimeSquare>31) error2("TimeSquare not good");
+
+	   T[0]=Q; T[1]=space;
+	   for(i=0; i<n*n; i++)  T[0][i] = ldexp( Q[i]*t, -TimeSquare );
+
+	   matby (T[0], T[0], T[1], n, n, n);
+	   for(i=0; i<n*n; i++)  T[0][i] += T[1][i]/2;
+	   for(i=0; i<n; i++)  T[0][i*n+i] ++;
+
+	   for(i=0,it=0; i<TimeSquare; i++) {
+		  it = !it;
+		  matby (T[1-it], T[1-it], T[it], n, n, n);
+	   }
+
+	   if(it==1) for(i=0;i<n*n;i++) Q[i]=T[1][i];
+
+		for(i=0; i<n; i++) 
+		{
+			for(j=0; j<n; j++) row.push_back(Q[(i*n)+j]);
+			for(j=1; j<n; j++) row.at(j)+=row.at(j-1);
+			double diff=row.at(n-1)-1; if(diff<0) diff=-diff;
+			if(diff>0.00001) {cout<<"matexp row didn't sum to 1 "<<diff<<endl; for(j=0; j<n;j++) cout<<row.at(j)<<"\t"; cout<<endl;cout<<endl;}
+			Pmat.push_back(row);
+			row.clear();
+		}
+
+
+   return Pmat;
+
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+void EigenSort(double d[], double U[], int n)
+{
+/* this sorts the eigen values d[] and rearrange the (right) eigen vectors U[]
+*/
+   int k,j,i;
+   double p;
+
+   for (i=0;i<n-1;i++) {
+      p=d[k=i];
+      for (j=i+1;j<n;j++)
+         if (d[j] >= p) p=d[k=j];
+      if (k != i) {
+         d[k]=d[i];
+         d[i]=p;
+         for (j=0;j<n;j++) {
+            p=U[j*n+i];
+            U[j*n+i]=U[j*n+k];
+            U[j*n+k]=p;
+         }
+      }
+   }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void HouseholderRealSym(double a[], int n, double d[], double e[])
+{
+/* This uses HouseholderRealSym transformation to reduce a real symmetrical matrix 
+   a[n*n] into a tridiagonal matrix represented by d and e.
+   d[] is the diagonal (eigends), and e[] the off-diagonal.
+*/
+   int m,k,j,i;
+   double scale,hh,h,g,f;
+
+   for (i=n-1;i>=1;i--) {
+      m=i-1;
+      h=scale=0;
+      if (m > 0) {
+         for (k=0;k<=m;k++)
+            scale += fabs(a[i*n+k]);
+         if (scale == 0)
+            e[i]=a[i*n+m];
+         else {
+            for (k=0;k<=m;k++) {
+               a[i*n+k] /= scale;
+               h += a[i*n+k]*a[i*n+k];
+            }
+            f=a[i*n+m];
+            g=(f >= 0 ? -sqrt(h) : sqrt(h));
+            e[i]=scale*g;
+            h -= f*g;
+            a[i*n+m]=f-g;
+            f=0;
+            for (j=0;j<=m;j++) {
+               a[j*n+i]=a[i*n+j]/h;
+               g=0;
+               for (k=0;k<=j;k++)
+                  g += a[j*n+k]*a[i*n+k];
+               for (k=j+1;k<=m;k++)
+                  g += a[k*n+j]*a[i*n+k];
+               e[j]=g/h;
+               f += e[j]*a[i*n+j];
+            }
+            hh=f/(h*2);
+            for (j=0;j<=m;j++) {
+               f=a[i*n+j];
+               e[j]=g=e[j]-hh*f;
+               for (k=0;k<=j;k++)
+                  a[j*n+k] -= (f*e[k]+g*a[i*n+k]);
+            }
+         }
+      } 
+      else
+         e[i]=a[i*n+m];
+      d[i]=h;
+   }
+   d[0]=e[0]=0;
+
+   /* Get eigenvectors */
+   for (i=0;i<n;i++) {
+      m=i-1;
+      if (d[i]) {
+         for (j=0;j<=m;j++) {
+            g=0;
+            for (k=0;k<=m;k++)
+               g += a[i*n+k]*a[k*n+j];
+            for (k=0;k<=m;k++)
+               a[k*n+j] -= g*a[k*n+i];
+         }
+      }
+      d[i]=a[i*n+i];
+      a[i*n+i]=1;
+      for (j=0;j<=m;j++) a[j*n+i]=a[i*n+j]=0;
+   }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int EigenTridagQLImplicit(double d[], double e[], int n, double z[])
+{
+/* This finds the eigen solution of a tridiagonal matrix represented by d and e.  
+   d[] is the diagonal (eigenvalues), e[] is the off-diagonal
+   z[n*n]: as input should have the identity matrix to get the eigen solution of the 
+   tridiagonal matrix, or the output from HouseholderRealSym() to get the 
+   eigen solution to the original real symmetric matrix.
+   z[n*n]: has the orthogonal matrix as output
+
+   Adapted from routine tqli in Numerical Recipes in C, with reference to
+   LAPACK fortran code.
+   Ziheng Yang, May 2001
+*/
+   int m,j,iter,niter=30, status=0, i,k;
+   double s,r,p,g,f,dd,c,b, aa,bb;
+
+   for (i=1;i<n;i++) e[i-1]=e[i];  e[n-1]=0;
+   for (j=0;j<n;j++) {
+      iter=0;
+      do {
+         for (m=j;m<n-1;m++) {
+            dd=fabs(d[m])+fabs(d[m+1]);
+            if (fabs(e[m])+dd == dd) break;  /* ??? */
+         }
+         if (m != j) {
+            if (iter++ == niter) {
+               status=-1;
+               break;
+            }
+            g=(d[j+1]-d[j])/(2*e[j]);
+
+            /* r=pythag(g,1); */
+
+            if((aa=fabs(g))>1)  r=aa*sqrt(1+1/(g*g));
+            else                r=sqrt(1+g*g);
+
+            g=d[m]-d[j]+e[j]/(g+SIGN(r,g));
+            s=c=1;
+            p=0;
+            for (i=m-1;i>=j;i--) {
+               f=s*e[i];
+               b=c*e[i];
+
+               /*  r=pythag(f,g);  */
+               aa=fabs(f); bb=fabs(g);
+               if(aa>bb)       { bb/=aa;  r=aa*sqrt(1+bb*bb); }
+               else if(bb==0)             r=0;
+               else            { aa/=bb;  r=bb*sqrt(1+aa*aa); }
+
+               e[i+1]=r;
+               if (r == 0) {
+                  d[i+1] -= p;
+                  e[m]=0;
+                  break;
+               }
+               s=f/r;
+               c=g/r;
+               g=d[i+1]-p;
+               r=(d[i]-g)*s+2*c*b;
+               d[i+1]=g+(p=s*r);
+               g=c*r-b;
+               for (k=0;k<n;k++) {
+                  f=z[k*n+i+1];
+                  z[k*n+i+1]=s*z[k*n+i]+c*f;
+                  z[k*n+i]=c*z[k*n+i]-s*f;
+               }
+            }
+            if (r == 0 && i >= j) continue;
+            d[j]-=p; e[j]=g; e[m]=0;
+         }
+      } while (m != j);
+   }
+   return(status);
+}
+
+#undef SIGN
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int eigenRealSym(double A[], int n, double Root[], double work[])
+{
+/* This finds the eigen solution of a real symmetrical matrix A[n*n].  In return, 
+   A has the right vectors and Root has the eigenvalues. 
+   work[n] is the working space.
+   The matrix is first reduced to a tridiagonal matrix using HouseholderRealSym(), 
+   and then using the QL algorithm with implicit shifts.  
+
+   Adapted from routine tqli in Numerical Recipes in C, with reference to LAPACK
+   Ziheng Yang, 23 May 2001
+*/
+   int status=0;
+   HouseholderRealSym(A, n, Root, work);
+   status=EigenTridagQLImplicit(Root, work, n, A);
+   EigenSort(Root, A, n);
+
+   return(status);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+int eigenQREV (double Q[], double pi[], int n, 
+               double Root[], double U[], double V[], double spacesqrtpi[])
+{
+/* 
+   This finds the eigen solution of the rate matrix Q for a time-reversible 
+   Markov process, using the algorithm for a real symmetric matrix.
+   Rate matrix Q = S * diag{pi} = U * diag{Root} * V, 
+   where S is symmetrical, all elements of pi are positive, and U*V = I.
+   space[n] is for storing sqrt(pi).
+
+   [U 0] [Q_0 0] [U^-1 0]    [Root  0]
+   [0 I] [0   0] [0    I]  = [0     0]
+
+   Ziheng Yang, 25 December 2001 (ref is CME/eigenQ.pdf)
+*/
+
+   int i,j, inew, jnew, nnew, status;
+   double *pi_sqrt=spacesqrtpi, mysmall=1e-100;
+
+   for(j=0,nnew=0; j<n; j++)
+      if(pi[j]>mysmall)
+         pi_sqrt[nnew++]=sqrt(pi[j]);
+
+   /* store in U the symmetrical matrix S = sqrt(D) * Q * sqrt(-D) */
+
+   if(nnew==n) {
+      for(i=0; i<n; i++)
+         for(j=0,U[i*n+i] = Q[i*n+i]; j<i; j++)
+            U[i*n+j] = U[j*n+i] = (Q[i*n+j] * pi_sqrt[i]/pi_sqrt[j]);
+
+      status=eigenRealSym(U, n, Root, V);
+      for(i=0;i<n;i++) for(j=0;j<n;j++)  V[i*n+j] = U[j*n+i] * pi_sqrt[j];
+      for(i=0;i<n;i++) for(j=0;j<n;j++)  U[i*n+j] /= pi_sqrt[i];
+   }
+   else {
+      for(i=0,inew=0; i<n; i++) {
+         if(pi[i]>mysmall) {
+            for(j=0,jnew=0; j<i; j++) 
+               if(pi[j]>mysmall) {
+                  U[inew*nnew+jnew] = U[jnew*nnew+inew] 
+                                    = Q[i*n+j] * pi_sqrt[inew]/pi_sqrt[jnew];
+                  jnew++;
+               }
+            U[inew*nnew+inew] = Q[i*n+i];
+            inew++;
+         }
+      }
+
+      status=eigenRealSym(U, nnew, Root, V);
+
+      for(i=n-1,inew=nnew-1; i>=0; i--)   /* construct Root */
+         Root[i] = (pi[i]>mysmall ? Root[inew--] : 0);
+      for(i=n-1,inew=nnew-1; i>=0; i--) {  /* construct V */
+         if(pi[i]>mysmall) {
+            for(j=n-1,jnew=nnew-1; j>=0; j--)
+               if(pi[j]>mysmall) {
+                  V[i*n+j] = U[jnew*nnew+inew]*pi_sqrt[jnew];
+                  jnew--;
+               }
+               else 
+                  V[i*n+j] = (i==j);
+            inew--;
+         }
+         else 
+            for(j=0; j<n; j++)  V[i*n+j] = (i==j);
+      }
+      for(i=n-1,inew=nnew-1; i>=0; i--) {  /* construct U */
+         if(pi[i]>mysmall) {
+            for(j=n-1,jnew=nnew-1;j>=0;j--)
+               if(pi[j]>mysmall) {
+                  U[i*n+j] = U[inew*nnew+jnew]/pi_sqrt[inew];
+                  jnew--;
+               }
+               else 
+                  U[i*n+j] = (i==j);
+            inew--;
+         }
+         else 
+            for(j=0;j<n;j++)
+               U[i*n+j] = (i==j);
+      }
+   }
+
+/*   This routine works on P(t) as well as Q. */
+/*
+   if(fabs(Root[0])>1e-10 && noisy) printf("Root[0] = %.5e\n",Root[0]);
+   Root[0]=0; 
+*/
+   return(status);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+int PMatUVRoot (double P[], double t, int n, double U[], double V[], double Root[])
+{
+/* P(t) = U * exp{Root*t} * V
+*/
+   int i,j,k;
+   double expt, uexpt, *pP;
+   double smallp = 0;
+
+   NPMatUVRoot++;
+   if (t<-0.1) printf ("\nt = %.5f in PMatUVRoot", t);
+   if (t<1e-100) { identity (P, n); return(0); }
+   for (k=0,zero(P,n*n); k<n; k++)
+      for (i=0,pP=P,expt=exp(t*Root[k]); i<n; i++)
+         for (j=0,uexpt=U[i*n+k]*expt; j<n; j++)
+            *pP++ += uexpt*V[k*n+j];
+
+   for(i=0;i<n*n;i++)  if(P[i]<smallp)  P[i]=0;
+
+#if (DEBUG>=5)
+      if (testTransP(P,n)) {
+         printf("\nP(%.6f) err in PMatUVRoot.\n", t);
+         exit(-1);
+      }
+#endif
+
+   return (0);
+}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//int PMatQRev(double Q[], double pi[], double t, int n, double space[])
+vector<vector<double> > PMatQRev(vector<vector<double> > Qvec, vector<double> &basefreqs, double t) 
+{
+/*
+ modified by WF
+
+  Calculates P(t) from Q using the eigenvalues and eigenroots of the rate matrix Q (Yang, 1995).  
+
+  Yang, Z. (1995) On the general reversible Markov-process model of nucleotide substitution: a reply to Saccone et al. Journal of Molecular Evolution 41:254-255.
+
+
+  Original notes from ZY follows:
+
+  -------------------------------
+
+   This calculates P(t) = exp(Q*t), where Q is the rate matrix for a 
+   time-reversible Markov process.
+
+   Q[] or P[] has the rate matrix as input, and P(t) in return.
+   space[n*n*2+n*2]  n*n*2+n*2=n*2*(n+1)  
+*/
+	int i, j, n=basefreqs.size();
+
+	vector<vector<double> > Pmat;
+	vector<double> row;
+
+
+			double Q[4096];  double space[8320]; double pi[64];
+
+	   	for(i=0; i<n; i++) 
+		{
+			pi[i]=basefreqs.at(i);
+
+			for(j=0; j<n; j++) Q[(i*n)+j]=(Qvec.at(i)).at(j); 
+		}
+
+		double *U=space, *V=U+n*n, *Root=V+n*n, *spacesqrtpi=Root+n;
+
+		eigenQREV(Q, pi, n, Root, U, V, spacesqrtpi);
+		PMatUVRoot(Q, t, n, U, V, Root);
+				
+		for(i=0; i<n; i++) 
+		{
+			for(j=0; j<n; j++) row.push_back(Q[(i*n)+j]);
+			for(j=1; j<n; j++) row.at(j)+=row.at(j-1);
+			double diff=row.at(n-1)-1; if(diff<0) diff=-diff;
+			if(diff>0.00001) {cout<<"Pmat row didn't sum to 1 "<<diff<<endl; for(j=0; j<n;j++) cout<<row.at(j)<<"\t"; cout<<endl;cout<<endl;}
+			Pmat.push_back(row);
+			row.clear();
+		}
+
+
+	return Pmat;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+//            ALL THE CODE BELOW IS FOR FOR PRODUCING RANDOM LABELLED HISTORIES                //
+//			  (AND BRANCH LENGTHS FROM BIRTH DEATH PROCESS) UNTIL STATED OTHERWISE             //
+//            IT HAS BEEN USED WITH KIND PERMISSION FROM ZIHENG YANG'S PAML SUITE              //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+				int LASTROUND;
+
+
+				#define FPN(file) fputc('\n', file)
+				#define F0 stdout
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				#define NS            5000
+				#define NBRANCH       (NS*2-2)
+				#define MAXNSONS      20
+				#define LSPNAME       50
+				#define NCODE         64
+				#define NCATG         40
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+				void error2 (string message)
+				{ cout<<"\nError thrown by PAML code:\n"<<message<<endl; exit(-1); }
+
+				static unsigned int z_rndu=137;
+				static unsigned int w_rndu=123456757;
+
+				void SetSeed (unsigned int seed)
+				{
+				   if(sizeof(int) != 4) 
+					  puts("oh-oh, we are in trouble.  int not 32-bit?");
+				   z_rndu=170*(seed%178)+137;
+				   w_rndu = seed*127773;
+				}
+
+
+				double rndu (void)
+				{
+					/* From Ripley (1987, page 46). 32-bit integer assumed */
+					   w_rndu = w_rndu*69069+1;
+					   return ldexp((double)w_rndu, -32);
+				}
+
+
+				/////////////////////////////////////////////////////////////////////////////////////////////////////
+				struct TREEB {
+				   int nbranch, nnode, root, branches[NBRANCH][2];
+				}  tree;
+				struct TREEN {
+				   int father, nson, sons[MAXNSONS], ibranch;
+				   double branch, age, omega, label, *conP;
+				   char *nodeStr, fossil;
+				}  *nodes;
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				void NodeToBranchSub (int inode)
+				{
+				   int i, ison;
+
+				   for(i=0; i<nodes[inode].nson; i++) {
+					  tree.branches[tree.nbranch][0] = inode;
+					  tree.branches[tree.nbranch][1] = ison = nodes[inode].sons[i];
+					  nodes[ison].ibranch = tree.nbranch++;
+					  if(nodes[ison].nson>0)  NodeToBranchSub(ison);
+				   }
+				}
+
+				void NodeToBranch (void)
+				{
+				   tree.nbranch=0;
+				   NodeToBranchSub (tree.root);
+				   if(tree.nnode != tree.nbranch+1)
+					  error2("nnode != nbranch + 1?");
+				}
+
+				void ClearNode (int inode)
+				{
+					// not sure what ZY's comment below means!!
+
+				/* a source of confusion. Try not to use this routine.
+				*/
+				   nodes[inode].father=nodes[inode].ibranch=-1;
+				   nodes[inode].nson=0;
+				   nodes[inode].branch=nodes[inode].age=0;
+				   /* nodes[inode].label=0; */
+				   /* nodes[inode].branch=0; clear node structure only, not branch lengths */
+				   /* FOR (i, com.ns) nodes[inode].sons[i]=-1; */
+				}
+
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				struct CommonInfo {
+				   char *z[2*NS-1], spname[NS][LSPNAME+1], daafile[96], cleandata, readpattern;
+				   int ns, ls, npatt, np, ntime, ncode, clock, rooted, model, icode;
+				   int seqtype, *pose, ncatG, NSsites, fix_omega;
+				   double *fpatt, kappa, omega, alpha, pi[64], *conP, daa[20*20];
+				   double freqK[NCATG], rK[NCATG];
+				   char *siteID;    /* used if ncatG>1 */
+				   double *siterates, omega_fix;   /* rates for gamma or omega for site or branch-site models */
+				   double *omegaBS, *QfactorBS;     /* omega IDs for branch-site models */
+				}  com;
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				int RandomLHistory (int rooted, double space[])
+				{
+				// Function from evolver.c in PAML
+				/* random coalescence tree, with each labeled history having equal probability.
+				   interior nodes are numbered ns, ns+1, ..., 2*ns-1-!rooted
+				*/
+				   int ns=com.ns, i, j, it=0, *nodea=(int*)space;
+				   double t;
+
+				   for (i=0; i<2*ns-1-!rooted; i++) ClearNode(i);
+
+				   for (i=0; i<ns; i++) nodea[i]=i;
+				   for (i=ns,t=0; i>(1+!rooted); i--) {
+					  nodes[it=2*ns-i].nson=2;
+					  j=(int)(i*rndu()); 
+					  nodes[nodea[j]].father=it; nodes[it].sons[0]=nodea[j];
+					  nodea[j]=nodea[i-1];
+					  j=(int)((i-1)*rndu()); 
+					  nodes[nodea[j]].father=it; nodes[it].sons[1]=nodea[j];
+					  nodea[j]=it;
+					  if (!rooted && i==3) {
+						 nodes[it].nson++; 
+						 nodes[nodea[1-j]].father=it; nodes[it].sons[2]=nodea[1-j];
+					  }
+				   }
+				   tree.root=it;  tree.nnode=ns*2-1-!rooted;
+				   NodeToBranch();
+				   return (0);
+				}
+
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				void BranchLengthBD(int rooted, double birth, double death, double sample, double mut)
+				{
+					// Function from evolver.c in PAML
+
+				/* Generate random branch lengths (nodes[].branch) using the birth and
+				   death process with species sampling, or the Yule (coalescent?) process
+				   if sample=0, when only parameter mut is used.
+				   Note: older interior nodes have larger node numbers, so root is at
+				   node com.ns*2-2 with time t[ns-2], while the youngest node is at 
+				   node com.ns with time t[0].  When unrooted=0, the root is removed with
+				   branch lengths adjusted.
+				   This works with the tree generated from RandomLHistory().
+				*/
+				   int i,j, it, imin,fixt0=1;
+				   double la=birth, mu=death, rho=sample, tmin, r, t[NS-1];
+				   double phi, eml, y;
+
+				   if (sample==0)  /* coalescent model.  Check this!!!  */
+					  for (i=com.ns,y=0; i>1; i--) 
+						  nodes[com.ns*2-i].age=y += -log(rndu())/(i*(i-1.)/2.)*mut/2;
+				   else  {         /* BD with sampling */
+					  if (fixt0) t[com.ns-2]=1;
+					  if (fabs(la-mu)>1e-6) {
+						 eml=exp(mu-la);  phi=(rho*la*(eml-1)+(mu-la)*eml)/(eml-1);
+						 for (i=0; i<com.ns-1-(fixt0); i++) {
+						   r=rndu(); t[i]=log((phi-r*rho*la)/(phi-r*rho*la+r*(la-mu)))/(mu-la);
+					   }
+					  }
+					  else  
+						 for (i=0; i<com.ns-1-(fixt0); i++) 
+							{ r=rndu();  t[i]=r/(1+la*rho*(1-r)); }
+					  /* bubble sort */
+					  for (i=0; i<com.ns-1-1; i++) {
+						 for (j=i+1,tmin=t[i],imin=i; j<com.ns-1; j++) 
+							if (tmin>t[j]) { tmin=t[j]; imin=j; }
+						 t[imin]=t[i];  t[i]=tmin;
+					  }
+					  for (i=com.ns; i>1; i--) nodes[com.ns*2-i].age=t[com.ns-i]*mut;
+				   }
+				   FOR (i,com.ns) nodes[i].age=0;
+				   for (i=0; i<tree.nnode; i++) 
+					  if (i!=tree.root) 
+						 nodes[i].branch=nodes[nodes[i].father].age-nodes[i].age;
+				   if (!rooted) {
+					  it=nodes[tree.root].sons[2];
+					  nodes[it].branch =
+						 2*nodes[2*com.ns-2].age-nodes[tree.root].age-nodes[it].age;
+				   }
+				}
+
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				FILE* fout;
+
+				//enum {PrBranch=1, PrNodeNum=2, PrLabel=4, PrAge=8} OutTreeOptions;
+				const int PrBranch=1; 
+				const int PrNodeNum=2; 
+				const int PrLabel=4; 
+				const int PrAge=8;
+				
+				string OutSubTreeN (string &subtree, FILE *fout, int inode, int spnames, int printopt) //, char *labelfmt)
+				{
+					// Function from evolver.c in PAML - modified by W.F.
+
+					subtree+="(";
+					string tempstring;
+				   int i,ison;
+
+				   //fputc ('(', fout);
+				   for(i=0; i<nodes[inode].nson; i++) {
+					  ison=nodes[inode].sons[i];
+					  if(nodes[ison].nson==0) {
+						 if(spnames) {
+							 if(printopt&PrNodeNum) {stringstream fd1; fd1<<ison+1; tempstring=fd1.str(); subtree+=tempstring;}//fprintf(fout, "%d_",ison+1);
+							subtree+=com.spname[ison]; //fprintf(tempout,"%s",com.spname[ison]);
+						 }
+						 else 
+						 {stringstream fd2; fd2<<ison+1; tempstring=fd2.str(); subtree+=tempstring;} //fprintf(tempout,"%d",ison+1);
+					  }
+					  else
+						 OutSubTreeN(subtree, fout, ison, spnames, printopt); //, labelfmt);
+
+					  if((printopt & PrNodeNum) && nodes[ison].nson) 
+						 {stringstream fd4; fd4<<ison+1; tempstring=fd4.str(); subtree+=tempstring;}//fprintf(tempout," %d ",ison+1);   /* fprintf(fout,"%d",ison+1-sptree.nspecies);  */
+					  if((printopt & PrLabel) && nodes[ison].label>0)
+						///////////////HERE
+					  {stringstream fd5; fd5<<nodes[ison].label; tempstring=fd5.str(); subtree+=tempstring;}  //subtree+=nodes[ison].label; //  {stringstream fd5; fd5<<nodes[ison].label; tempstring=fd5.str(); subtree+=tempstring;}  //fprintf(tempout, labelfmt, nodes[ison].label);
+					  if((printopt & PrAge) && nodes[ison].age) 
+						{stringstream fd6; fd6<<nodes[ison].age; tempstring=fd6.str(); subtree+=tempstring;} //fprintf(tempout, " @%.3f", nodes[ison].age);
+
+
+				/*  Add branch labels to be read by Rod Page's TreeView. */
+
+
+					  if((printopt & PrLabel) && nodes[ison].nodeStr) 
+						 subtree+=nodes[ison].nodeStr; //fprintf(tempout," '%s'", nodes[ison].nodeStr);
+
+					  if(printopt & PrBranch)  {stringstream fd7; fd7<<nodes[ison].branch; tempstring=fd7.str(); subtree+=':'; subtree+=tempstring;} //fprintf(tempout,": %.6f", nodes[ison].branch);
+
+					  if(i<nodes[inode].nson-1) subtree+=","; //fprintf(tempout,", ");
+				   }
+				   subtree+=")"; //fputc (')', fout);
+				 //  cout<<endl<<"WWAS"<<endl<<subtree<<endl<<"WWAS"<<endl;
+
+				   return subtree;
+				}
+
+
+
+
+
+				string OutaTreeN (FILE *fout, int spnames, int printopt)
+				{
+					// Function from evolver.c in PAML - modified by W.F.
+
+				/* 
+				   print the current tree.
+				*/
+					string subtree, tempstring;
+				   int i, intlabel=1;
+				   //char* labelfmt[2]={"#%.5f", "#%.0f"};
+
+				   if(printopt & PrLabel) {
+					  for(i=0;i<tree.nnode;i++) 
+						 if(nodes[i].label-(int)nodes[i].label != 0) intlabel=0;
+				   }
+
+				   OutSubTreeN(subtree, fout,tree.root,spnames,printopt); //labelfmt[intlabel]);
+				   if(printopt&PrNodeNum) {stringstream fd8; fd8<<tree.root+1; tempstring=fd8.str(); subtree+=tempstring;} //fprintf(tempout," %d ", tree.root+1);
+				   if((printopt & PrLabel) && nodes[tree.root].label>0) 
+					  {stringstream fd5; fd5<<nodes[tree.root].label; tempstring=fd5.str(); subtree+=tempstring;} //subtree+=nodes[tree.root].label;//fprintf(tempout, labelfmt[intlabel], nodes[tree.root].label);
+				   if((printopt & PrAge)  && nodes[tree.root].age) 
+					  {stringstream fd10; fd10<<nodes[tree.root].age; tempstring=fd10.str(); subtree+=tempstring;}//fprintf(tempout, " @%.3f", nodes[tree.root].age);
+
+				   if((printopt&PrBranch) && nodes[tree.root].branch>1e-8)
+					  {stringstream fd11; fd11<<nodes[tree.root].branch; tempstring=fd11.str(); subtree+=":"; subtree+=tempstring;}//fprintf(tempout,": %.6f", nodes[tree.root].branch);
+
+				   subtree+=";"; //fputc(';',tempout);
+				//   cout<<"AQA"<<subtree<<"AQA"<<endl;
+				   return subtree;
+				}
+
+
+				///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+				string newrandomtree(int ntaxa, double birth, double death, double sample, double mut, int randomseed, int option)
+				{
+					// Function written by W.F. adapting code from the main body of evolver.c in PAML
+					
+					// produces random trees using the birth-death process
+
+					// Yang and Rannala. (1997) Bayesian phylogenetic inference using DNA sequences: a Markov Chain Monte Carlo Method. Mol. Biol. Evol. 14:717-724.  
+
+
+
+					//ofstream tempout("temptree.txt");
+					//ns number of species
+					// option should be 1 for unrooted and 2 for rooted
+					double *space;
+					int ntree=1; // number of trees
+					int i=randomseed; //randomseed
+					com.ns=ntaxa;
+					string randomtree;
+
+						 if(com.ns>NS) error2 ("Too many species.  Raise NS.");
+						 if((space=(double*)malloc(10000*sizeof(double)))==NULL) error2("oom");
+
+					 int    rooted=!(option%2);
+					 int mynewseed= (int)(time(NULL))*(clock());
+						 SetSeed(i==-1? mynewseed:i); //(int)time(NULL):i);  //this is what ZY had - makes trees the same if created in quick succession
+						int BD=1; //use birth death process for branch lengths
+
+		//				cout<<(i==-1? mynewseed:i)<<"\t";
+   
+							if(com.ns<3) error2("no need to do this?");
+							i=(com.ns*2-1)*sizeof(struct TREEN);
+							if((nodes=(struct TREEN*)malloc(i))==NULL) error2("oom");
+   
+
+							for(i=0; i<com.ns; i++)          /* default spname */
+							   sprintf(com.spname[i],"S%d",i+1);
+
+							for(i=0;i<ntree;i++) {
+							   RandomLHistory (rooted, space);
+							   BranchLengthBD (1, birth, death, sample, mut);
+							   if(com.ns<20&&ntree<10) { randomtree=OutaTreeN(F0,0,BD); }
+							   else{randomtree=OutaTreeN(fout,1,BD);}
+							   //cout<<" Random Guide Tree set as: "<<endl<<" ";
+							  // cout<<randomtree<<endl<<endl;   
+							   //FPN(fout);
+							}
+
+					free(space);  free(nodes);
+
+					return randomtree;
+				}
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+//            ALL THE CODE BELOW IS FOR GAMMA RATE VARIATION UNTIL STATED OTHERWISE            //
+//            IT HAS BEEN USED WITH KIND PERMISSION FROM ZIHENG YANG'S PAML SUITE              //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+					
+
+				double LnGamma (double alpha);
+				double IncompleteGamma (double x, double alpha, double ln_gamma_alpha);
+				double PointNormal (double prob);
+				double PointChi2 (double prob, double v);
+
+					
+				double rndgamma1 (double s);
+				double rndgamma2 (double s);
+
+				double rndgamma (double s)
+				{
+					// continuous gamma called with this function
+
+					// 	Yang, Z. (1993) Maximum likelihood estimation of phylogeny from DNA sequences when substitution rates differ over sites. Molecular Biology and Evolution 10:1396-1401.
+
+
+					double	r=0.0;
+					myrand=mtrand1();
+					if (s <= 0.0)      
+						return 0;
+					else if (s < 1.0)  
+						r = rndgamma1 (s);
+					else if (s > 1.0)  
+						r = rndgamma2 (s);
+					else           
+						r =- log(myrand);
+					return (r);
+				}
+
+
+				double rndgamma1 (double s)
+				{
+
+					double			r, x=0.0;
+					double mysmall=1e-37;
+					double w;
+					static double	a, p, uf, ss=10.0, d;
+					
+					if (s!=ss) 
+						{
+						a  = 1.0-s;
+						p  = a/(a+s*exp(-a));
+						uf = p*pow(mysmall/a,s);
+						d  = a*log(a);
+						ss = s;
+						}
+					for (;;) 
+						{
+						r = mtrand1();
+						if (r > p)        
+							x = a-log((1.0-r)/(1.0-p)), w=a*log(x)-d;
+						else if (r>uf)  
+							x = a*pow(r/p,1/s), w=x;
+						else            
+							return (0.0);
+						r = mtrand1();
+						if (1.0-r <= w && r > 0.0)
+							if (r*(w+1.0) >= 1.0 || -log(r) <= w)  
+								continue;
+						break;
+						}
+					return (x);
+				}
+
+
+				double rndgamma2 (double s)
+				{
+
+					double			r ,d, f, g, x;
+					static double	b, h, ss=0;
+					
+					if (s!=ss) 
+						{
+						b  = s-1.0;
+						h  = sqrt(3.0*s-0.75);
+						ss = s;
+						}
+					for (;;) 
+						{
+						r = mtrand1();
+						g = r-r*r;
+						f = (r-0.5)*h/sqrt(g);
+						x = b+f;
+						if (x <= 0.0) 
+							continue;
+						r = mtrand1();
+						d = 64*r*r*g*g*g;
+						if (d*x < x-2.0*f*f || log(d) < 2*(b*log(x/b)-f))  
+							break;
+						}
+					return (x);
+				}
+
+
+double CDFNormal (double x)
+{
+//  Hill ID  (1973)  The normal integral.  Applied Statistics, 22:424-427.
+//    Algorithm AS 66.
+//    adapted by Z. Yang, March 1994.  Hill's routine is quite bad, and I 
+//    haven't consulted 
+//      Adams AG  (1969)  Algorithm 39.  Areas under the normal curve.
+//      Computer J. 12: 197-198.
+
+    int invers=0;
+    double p, limit=10, t=1.28, y=x*x/2;
+
+    if (x<0) {  invers=1;  x*=-1; }
+    if (x>limit)  return (invers?0:1);
+    if (x<1.28)  
+       p = .5 - x * (    .398942280444 - .399903438504 * y
+                   /(y + 5.75885480458 - 29.8213557808
+		   /(y + 2.62433121679 + 48.6959930692
+		   /(y + 5.92885724438))));
+    else 
+       p = 0.398942280385 * exp(-y) /
+           (x - 3.8052e-8 + 1.00000615302 /
+           (x + 3.98064794e-4 + 1.98615381364 /
+           (x - 0.151679116635 + 5.29330324926 /
+           (x + 4.8385912808 - 15.1508972451 /
+           (x + 0.742380924027 + 30.789933034 /
+           (x + 3.99019417011))))));
+
+    return  invers ? p : 1-p;
+}
+
+
+				double LnGamma (double alpha)
+				{
+				// returns ln(gamma(alpha)) for alpha>0, accurate to 10 decimal places.  
+				// Stirling's formula is used for the central polynomial part of the procedure.
+				// Pike MC & Hill ID (1966) Algorithm 291: Logarithm of the gamma function.
+				// Communications of the Association for Computing Machinery, 9:684
+				
+				   double x=alpha, f=0, z;
+
+				   if (x<7) {
+					  f=1;  z=x-1;
+					  while (++z<7)  f*=z;
+					  x=z;   f=-log(f);
+				   }
+				   z = 1/(x*x);
+				   return  f + (x-0.5)*log(x) - x + .918938533204673 
+					  + (((-.000595238095238*z+.000793650793651)*z-.002777777777778)*z
+						   +.083333333333333)/x;  
+				}
+
+
+double LnGammaFunction (double alpha)
+{
+/* returns ln(gamma(alpha)) for alpha>0, accurate to 10 decimal places.  
+   Stirling's formula is used for the central polynomial part of the procedure.
+   Pike MC & Hill ID (1966) Algorithm 291: Logarithm of the gamma function.
+   Communications of the Association for Computing Machinery, 9:684
+*/
+   double x=alpha, f=0, z;
+
+   if (x<7) {
+       f=1;  z=x-1;
+       while (++z<7)  f*=z;
+       x=z;   f=-log(f);
+   }
+   z = 1/(x*x);
+   return  f + (x-0.5)*log(x) - x + .918938533204673 
+          + (((-.000595238095238*z+.000793650793651)*z-.002777777777778)*z
+               +.083333333333333)/x;  
+}
+
+
+				double IncompleteGamma (double x, double alpha, double ln_gamma_alpha)
+				{
+				/* returns the incomplete gamma ratio I(x,alpha) where x is the upper 
+					   limit of the integration and alpha is the shape parameter.
+				   returns (-1) if in error
+				   ln_gamma_alpha = ln(Gamma(alpha)), is almost redundant.
+				   (1) series expansion     if (alpha>x || x<=1)
+				   (2) continued fraction   otherwise
+				   RATNEST FORTRAN by
+				   Bhattacharjee GP (1970) The incomplete gamma integral.  Applied Statistics,
+				   19: 285-287 (AS32)
+				*/
+				   int i;
+				   double p=alpha, g=ln_gamma_alpha;
+				   double accurate=1e-8, overflow=1e30;
+				   double factor, gin=0, rn=0, a=0,b=0,an=0,dif=0, term=0, pn[6];
+
+				   if (x==0) return (0);
+				   if (x<0 || p<=0) return (-1);
+
+				   factor=exp(p*log(x)-x-g);   
+				   if (x>1 && x>=p) goto l30;
+				   /* (1) series expansion */
+				   gin=1;  term=1;  rn=p;
+				 l20:
+				   rn++;
+				   term*=x/rn;   gin+=term;
+
+				   if (term > accurate) goto l20;
+				   gin*=factor/p;
+				   goto l50;
+				 l30:
+				   /* (2) continued fraction */
+				   a=1-p;   b=a+x+1;  term=0;
+				   pn[0]=1;  pn[1]=x;  pn[2]=x+1;  pn[3]=x*b;
+				   gin=pn[2]/pn[3];
+				 l32:
+				   a++;  b+=2;  term++;   an=a*term;
+				   for (i=0; i<2; i++) pn[i+4]=b*pn[i+2]-an*pn[i];
+				   if (pn[5] == 0) goto l35;
+				   rn=pn[4]/pn[5];   dif=fabs(gin-rn);
+				   if (dif>accurate) goto l34;
+				   if (dif<=accurate*rn) goto l42;
+				 l34:
+				   gin=rn;
+				 l35:
+				   for (i=0; i<4; i++) pn[i]=pn[i+2];
+				   if (fabs(pn[4]) < overflow) goto l32;
+				   for (i=0; i<4; i++) pn[i]/=overflow;
+				   goto l32;
+				 l42:
+				   gin=1-factor*gin;
+
+				 l50:
+				   return (gin);
+				}
+
+
+				/* functions concerning the CDF and percentage points of the gamma and
+				   Chi2 distribution
+				*/
+				double PointNormal (double prob)
+				{
+				/* returns z so that Prob{x<z}=prob where x ~ N(0,1) and (1e-12)<prob<1-(1e-12)
+				   returns (-9999) if in error
+				   Odeh RE & Evans JO (1974) The percentage points of the normal distribution.
+				   Applied Statistics 22: 96-97 (AS70)
+
+				   Newer methods:
+					 Wichura MJ (1988) Algorithm AS 241: the percentage points of the
+					   normal distribution.  37: 477-484.
+					 Beasley JD & Springer SG  (1977).  Algorithm AS 111: the percentage 
+					   points of the normal distribution.  26: 118-121.
+
+				*/
+				   double a0=-.322232431088, a1=-1, a2=-.342242088547, a3=-.0204231210245;
+				   double a4=-.453642210148e-4, b0=.0993484626060, b1=.588581570495;
+				   double b2=.531103462366, b3=.103537752850, b4=.0038560700634;
+				   double y, z=0, p=prob, p1;
+
+				   p1 = (p<0.5 ? p : 1-p);
+				   if (p1<1e-20) return (-9999);
+
+				   y = sqrt (log(1/(p1*p1)));   
+				   z = y + ((((y*a4+a3)*y+a2)*y+a1)*y+a0) / ((((y*b4+b3)*y+b2)*y+b1)*y+b0);
+				   return (p<0.5 ? -z : z);
+				}
+
+
+				double PointChi2 (double prob, double v)
+				{
+				/* returns z so that Prob{x<z}=prob where x is Chi2 distributed with df=v
+				   returns -1 if in error.   0.000002<prob<0.999998
+				   RATNEST FORTRAN by
+					   Best DJ & Roberts DE (1975) The percentage points of the 
+					   Chi2 distribution.  Applied Statistics 24: 385-388.  (AS91)
+				   Converted into C by Ziheng Yang, Oct. 1993.
+				*/
+				   double e=.5e-6, aa=.6931471805, p=prob, g;
+				   double xx, c, ch, a=0,q=0,p1=0,p2=0,t=0,x=0,b=0,s1,s2,s3,s4,s5,s6;
+
+				   if (p<.000002 || p>.999998 || v<=0) return (-1);
+
+				   g = LnGamma (v/2);
+				   xx=v/2;   c=xx-1;
+				   if (v >= -1.24*log(p)) goto l1;
+
+				   ch=pow((p*xx*exp(g+xx*aa)), 1/xx);
+				   if (ch-e<0) return (ch);
+				   goto l4;
+				l1:
+				   if (v>.32) goto l3;
+				   ch=0.4;   a=log(1-p);
+				l2:
+				   q=ch;  p1=1+ch*(4.67+ch);  p2=ch*(6.73+ch*(6.66+ch));
+				   t=-0.5+(4.67+2*ch)/p1 - (6.73+ch*(13.32+3*ch))/p2;
+				   ch-=(1-exp(a+g+.5*ch+c*aa)*p2/p1)/t;
+				   if (fabs(q/ch-1)-.01 <= 0) goto l4;
+				   else                       goto l2;
+  
+				l3: 
+				   x=PointNormal (p);
+				   p1=0.222222/v;   ch=v*pow((x*sqrt(p1)+1-p1), 3.0);
+				   if (ch>2.2*v+6)  ch=-2*(log(1-p)-c*log(.5*ch)+g);
+				l4:
+				   q=ch;   p1=.5*ch;
+				   if ((t=IncompleteGamma (p1, xx, g))<0) {
+					  return (-1);
+				   }
+				   p2=p-t;
+				   t=p2*exp(xx*aa+g+p1-c*log(ch));   
+				   b=t/ch;  a=0.5*t-b*c;
+
+				   s1=(210+a*(140+a*(105+a*(84+a*(70+60*a))))) / 420;
+				   s2=(420+a*(735+a*(966+a*(1141+1278*a))))/2520;
+				   s3=(210+a*(462+a*(707+932*a)))/2520;
+				   s4=(252+a*(672+1182*a)+c*(294+a*(889+1740*a)))/5040;
+				   s5=(84+264*a+c*(175+606*a))/2520;
+				   s6=(120+c*(346+127*c))/5040;
+				   ch+=t*(1+0.5*t*s1-b*c*(s1-b*(s2-b*(s3-b*(s4-b*(s5-b*s6))))));
+				   if (fabs(q/ch-1) > e) goto l4;
+
+				   return (ch);
+				}
+
+
+				#define PointGamma(prob,alpha,beta) PointChi2(prob,2.0*(alpha))/(2.0*(beta))
+
+	//DiscreteGamma(GDfreq,GDrates,(*m).pinv, (*m).alpha,(*m).alpha,(*m).ngamcat,medianORmean);  //makes discrete gamma frequencies etc..   
+
+	//Discrete Gamma + Proportion invariant
+			
+	//if(mtrand1()>(*m).pinv)  rate=GDrates.at( (int)( mtrand1() * ((*m).ngamcat) ) )/(1-((*m).pinv));  else rate=0;
+
+		
+				int DiscreteGamma (vector<double> &cumfreqK, vector<double> &rK, double pinv,
+					double alfa, double beta, int K, int median)
+				{
+
+				/* 
+				
+					Yang, Z. (1994) Maximum likelihood phylogenetic estimation from DNA sequences with variable rates over sites: approximate methods. Journal of Molecular Evolution 39:306-314.
+	
+					discretization of gamma distribution with equal proportions in each category
+				*/
+					vector<double> freqK;
+				   cumfreqK.assign(K,0);
+				   freqK.assign(K,0);
+				   rK.assign(K,0);
+				   int i;
+				   double gap05=1.0/(2.0*K), t, factor=alfa/beta*K, lnga1;
+
+				   if (median==1) {
+					  for (i=0; i<K; i++) rK.at(i)=PointGamma((i*2.0+1)*gap05, alfa, beta);
+					  for (i=0,t=0; i<K; i++) t+=rK.at(i);
+					  for (i=0; i<K; i++)     rK.at(i)*=factor/t;
+				   }
+				   else {
+					  lnga1=LnGamma(alfa+1);
+					  for (i=0; i<K-1; i++)
+					 freqK.at(i)=PointGamma((i+1.0)/K, alfa, beta);
+					  for (i=0; i<K-1; i++)
+					 freqK.at(i)=IncompleteGamma(freqK.at(i)*beta, alfa+1, lnga1);
+					  
+					  rK.at(0) = freqK[0]*factor/(1-pinv);
+					  rK.at(K-1) = (1-freqK.at(K-2))*factor/(1-pinv);
+					  for (i=1; i<K-1; i++)  rK.at(i) = (freqK.at(i)-freqK.at(i-1))*factor/(1-pinv);
+				   }
+				   for (i=0; i<K; i++) freqK.at(i)=(1.0 - pinv)/K;
+
+				   if(pinv>0) {rK.push_back(0); freqK.push_back(pinv); cumfreqK.push_back(pinv); }
+				   
+
+				   cumfreqK.at(0)=freqK.at(0);
+
+				   for(i=1; i<freqK.size(); i++) {cumfreqK.at(i)=freqK.at(i)+cumfreqK.at(i-1); }
+
+				   double diff=cumfreqK.back()-1; if(diff<0) diff=-diff;
+				   if(diff>0.00001) cout<<endl<<endl<<"diff is "<<diff<<"   ERROR IN DISCRETEGAMMA CUMFREQS"<<endl<<endl;
+//			cout<<"HERE"<<endl;
+				   return (0);
+				}
+
+					
+				double rndbeta(double p, double q)
+				{
+					double gamma1, gamma2;
+					gamma1=rndgamma(p);
+					gamma2=rndgamma(q);
+					return gamma1/(gamma1+gamma2);
+				}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	// code below is to do with codon models discrete rates... used by scipting function to set up M3
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////
+				
+const int NSnneutral=1;
+const int NSpselection=2;
+const int NSdiscrete=3;
+const int NSfreqs=4;
+const int NSgamma=5;
+const int NS2gamma=6;
+const int NSbeta=7;
+const int NSbetaw=8;
+const int NSbetagamma=9;
+const int NSbeta1gamma=10;
+const int NSbeta1normal=11;
+const int NS02normal=12;
+const int NS3normal=13;
+
+
+double PDFBeta(double x, double p, double q)
+{
+/* Returns pdf of beta(p,q)
+*/
+   double y, mysmall=1e-20;
+
+   if(x<mysmall || x>1-mysmall) 
+      error2("bad x in PDFbeta");
+
+   y = (p-1)*log(x) + (q-1)*log(1-x);
+   y-= LnGamma(p)+LnGamma(q)-LnGamma(p+q);
+
+   return(exp(y));
+}
+
+double CDFBeta(double x, double pin, double qin, double lnbeta)
+{
+/* Returns distribution function of the standard form of the beta distribution, 
+   that is, the incomplete beta ratio I_x(p,q).
+
+   lnbeta is log of the complete beta function; provide it if known,
+   and otherwise use 0.
+
+   This is called from InverseCDFBeta() in a root-finding loop.
+
+    This routine is a translation into C of a Fortran subroutine
+    by W. Fullerton of Los Alamos Scientific Laboratory.
+    Bosten and Battiste (1974).
+    Remark on Algorithm 179, CACM 17, p153, (1974).
+*/
+   double ans, c, finsum, p, ps, p1, q, term, xb, xi, y, mysmall=1e-15;
+   int n, i, ib;
+   static double eps = 0, alneps = 0, sml = 0, alnsml = 0;
+
+   if(x<mysmall)        return 0;
+   else if(x>1-mysmall) return 1;
+   if(pin<=0 || qin<=0)  { 
+      printf("p=%.4f q=%.4f: parameter outside range in CDFBeta",pin,qin); 
+      return (-1); 
+   }
+
+   if (eps == 0) {/* initialize machine constants ONCE */
+      eps = pow((double)FLT_RADIX, -(double)DBL_MANT_DIG);
+      alneps = log(eps);
+      sml = DBL_MIN;
+      alnsml = log(sml);
+   }
+   y = x;  p = pin;  q = qin;
+
+    /* swap tails if x is greater than the mean */
+   if (p / (p + q) < x) {
+      y = 1 - y;
+      p = qin;
+      q = pin;
+   }
+
+   if(lnbeta==0) lnbeta=LnGamma(p)+LnGamma(q)-LnGamma(p+q);
+
+   if ((p + q) * y / (p + 1) < eps) {  /* tail approximation */
+      ans = 0;
+      xb = p * log(max2(y, sml)) - log(p) - lnbeta;
+      if (xb > alnsml && y != 0)
+         ans = exp(xb);
+      if (y != x || p != pin)
+      ans = 1 - ans;
+   }
+   else {
+      /* evaluate the infinite sum first.  term will equal */
+      /* y^p / beta(ps, p) * (1 - ps)-sub-i * y^i / fac(i) */
+      ps = q - floor(q);
+      if (ps == 0)
+         ps = 1;
+
+      xb=LnGamma(ps)+LnGamma(p)-LnGamma(ps+p);
+      xb = p * log(y) - xb - log(p);
+
+      ans = 0;
+      if (xb >= alnsml) {
+         ans = exp(xb);
+         term = ans * p;
+         if (ps != 1) {
+            n = (int)max2(alneps/log(y), 4.0);
+         for(i=1 ; i<= n ; i++) {
+            xi = i;
+            term = term * (xi - ps) * y / xi;
+            ans = ans + term / (p + xi);
+         }
+      }
+   }
+
+   /* evaluate the finite sum. */
+   if (q > 1) {
+      xb = p * log(y) + q * log(1 - y) - lnbeta - log(q);
+      ib = (int) (xb/alnsml);  if(ib<0) ib=0;
+      term = exp(xb - ib * alnsml);
+      c = 1 / (1 - y);
+      p1 = q * c / (p + q - 1);
+
+      finsum = 0;
+      n = (int) q;
+      if (q == (double)n)
+         n = n - 1;
+         for(i=1 ; i<=n ; i++) {
+            if (p1 <= 1 && term / eps <= finsum)
+               break;
+            xi = i;
+            term = (q - xi + 1) * c * term / (p + q - xi);
+            if (term > 1) {
+               ib = ib - 1;
+               term = term * sml;
+            }
+            if (ib == 0)
+               finsum = finsum + term;
+         }
+         ans = ans + finsum;
+      }
+      if (y != x || p != pin)
+         ans = 1 - ans;
+      if(ans>1) ans=1;
+      if(ans<0) ans=0;
+   }
+   return ans;
+}
+
+double InverseCDFBeta(double prob, double p, double q, double lnbeta)
+{
+/* This calculates the inverseCDF of the beta distribution
+
+   Cran, G. W., K. J. Martin and G. E. Thomas (1977).
+   Remark AS R19 and Algorithm AS 109, Applied Statistics, 26(1), 111-114.
+   Remark AS R83 (v.39, 309-310) and correction (v.40(1) p.236).
+
+   My own implementation of the algorithm did not bracket the variable well.  
+   This version is Adpated from the pbeta and qbeta routines from 
+   "R : A Computer Language for Statistical Data Analysis".  It fails for 
+   extreme values of p and q as well, although it seems better than my 
+   previous version.
+   Ziheng Yang, May 2001
+*/
+   double fpu=3e-308, acu_min=1e-300, lower=fpu, upper=1-2.22e-16;
+   /* acu_min>= fpu: Minimal value for accuracy 'acu' which will depend on (a,p); */
+   int swap_tail, i_pb, i_inn, niterations=2000;
+   double a, adj, g, h, pp, prev=0, qq, r, s, t, tx=0, w, y, yprev;
+   double acu, xinbta;
+
+   if(prob<0 || prob>1 || p<0 || q<0) error2("out of range in InverseCDFBeta");
+
+   /* define accuracy and initialize */
+   xinbta = prob;
+
+   /* test for admissibility of parameters */
+   if(p<0 || q<0 || prob<0 || prob>1)  error2("beta par err");
+   if (prob == 0 || prob == 1)
+      return prob;
+
+   if(lnbeta==0) lnbeta=LnGamma(p)+LnGamma(q)-LnGamma(p+q);
+
+   /* change tail if necessary;  afterwards   0 < a <= 1/2    */
+   if (prob <= 0.5) {
+      a = prob;   pp = p; qq = q; swap_tail = 0;
+   }
+   else {
+      a = 1. - prob; pp = q; qq = p; swap_tail = 1;
+   }
+
+   /* calculate the initial approximation */
+   r = sqrt(-log(a * a));
+   y = r - (2.30753+0.27061*r)/(1.+ (0.99229+0.04481*r) * r);
+
+   if (pp > 1. && qq > 1.) {
+      r = (y * y - 3.) / 6.;
+      s = 1. / (pp*2. - 1.);
+      t = 1. / (qq*2. - 1.);
+      h = 2. / (s + t);
+      w = y * sqrt(h + r) / h - (t - s) * (r + 5./6. - 2./(3.*h));
+      xinbta = pp / (pp + qq * exp(w + w));
+   }
+   else {
+      r = qq*2.;
+      t = 1. / (9. * qq);
+      t = r * pow(1. - t + y * sqrt(t), 3.);
+      if (t <= 0.)
+         xinbta = 1. - exp((log((1. - a) * qq) + lnbeta) / qq);
+      else {
+         t = (4.*pp + r - 2.) / t;
+         if (t <= 1.)
+            xinbta = exp((log(a * pp) + lnbeta) / pp);
+         else
+            xinbta = 1. - 2./(t+1.);
+      }
+   }
+
+   /* solve for x by a modified newton-raphson method, using CDFBeta */
+   r = 1. - pp;
+   t = 1. - qq;
+   yprev = 0.;
+   adj = 1.;
+
+
+   
+/* Changes made by Ziheng to fix a bug in qbeta()
+   qbeta(0.25, 0.143891, 0.05) = 3e-308   wrong (correct value is 0.457227)
+*/
+   if(xinbta<=lower || xinbta>=upper)  xinbta=(a+.5)/2;
+
+   /* Desired accuracy should depend on (a,p)
+    * This is from Remark .. on AS 109, adapted.
+    * However, it's not clear if this is "optimal" for IEEE double prec.
+    * acu = fmax2(acu_min, pow(10., -25. - 5./(pp * pp) - 1./(a * a)));
+    * NEW: 'acu' accuracy NOT for squared adjustment, but simple;
+    * ---- i.e.,  "new acu" = sqrt(old acu)
+    */
+   acu = pow(10., -13. - 2.5/(pp * pp) - 0.5/(a * a));
+   acu = max2(acu, acu_min);
+
+   for (i_pb=0; i_pb<niterations; i_pb++) {
+      y = CDFBeta(xinbta, pp, qq, lnbeta);
+      y = (y - a) *
+         exp(lnbeta + r * log(xinbta) + t * log(1. - xinbta));
+      if (y * yprev <= 0)
+         prev = max2(fabs(adj),fpu);
+      for (i_inn=0,g=1; i_inn<niterations; i_inn++) {
+         adj = g * y;
+         if (fabs(adj) < prev) {
+            tx = xinbta - adj; /* trial new x */
+            if (tx >= 0. && tx <= 1.) {
+               if (prev <= acu || fabs(y) <= acu)   goto L_converged;
+               if (tx != 0. && tx != 1.)  break;
+            }
+         }
+         g /= 3.;
+      }
+      if (fabs(tx-xinbta)<fpu) 
+         goto L_converged;
+      xinbta = tx;
+      yprev = y;
+   }
+//   if(!PAML_RELEASE) 
+//    printf("\nInverseCDFBeta(%.2f, %.5f, %.5f) = %.6e\t%d rounds\n", 
+//     prob,p,q, (swap_tail ? 1. - xinbta : xinbta), niterations);
+
+   L_converged:
+   return (swap_tail ? 1. - xinbta : xinbta);
+}
+
+
+
+
+
+
+double LineSearch (double(*fun)(double x),double *f,double *x0,double xb[2],double step, double e)
+{
+/* linear search using quadratic interpolation 
+
+   From Wolfe M. A.  1978.  Numerical methods for unconstrained
+   optimization: An introduction.  Van Nostrand Reinhold Company, New York.
+   pp. 62-73.
+   step is used to find the bracket (a1,a2,a3)
+
+   This is the same routine as LineSearch2(), but I have not got time 
+   to test and improve it properly.  Ziheng note, September, 2002
+*/
+   int ii=0, maxround=100, i;
+   double factor=2, step1, percentUse=0;
+   double a0,a1,a2,a3,a4=-1,a5,a6, f0,f1,f2,f3,f4=-1,f5,f6;
+
+/* find a bracket (a1,a2,a3) with function values (f1,f2,f3)
+   so that a1<a2<a3 and f2<f1 and f2<f3
+*/
+
+   if(step<=0) return(*x0);
+   a0=a1=a2=a3=f0=f1=f2=f3=-1;
+   if(*x0<xb[0]||*x0>xb[1]) 
+      error2("err LineSearch: x0 out of range");
+   f2=f0=fun(a2=a0=*x0);
+   step1=min2(step,(a0-xb[0])/4);
+   step1=max2(step1,e);
+   for(i=0,a1=a0,f1=f0; ; i++) {
+      a1-=(step1*=factor); 
+      if(a1>xb[0]) {
+         f1=fun(a1);
+         if(f1>f2)  break;
+         else {
+            a3=a2; f3=f2; a2=a1; f2=f1;
+         }
+      }
+      else {
+         a1=xb[0];  f1=fun(a1);
+         if(f1<=f2) { a2=a1; f2=f1; }
+         break;
+      }
+
+      /* if(noisy>2) printf("\ta = %.6f\tf = %.6f %5d\n", a2, f2, NFunCall);
+      */
+
+   }
+
+   if(i==0) { /* *x0 is the best point during the previous search */
+      step1=min2(step,(xb[1]-a0)/4);
+      for(i=0,a3=a2,f3=f2; ; i++) {
+         a3+=(step1*=factor); 
+         if(a3<xb[1]) {
+            f3=fun(a3);
+            if(f3>f2)  break;
+            else 
+               { a1=a2; f1=f2; a2=a3; f2=f3; }
+         }
+         else {
+            a3=xb[1];  f3=fun(a3);
+            if(f3<f2) { a2=a3; f2=f3; }
+            break;
+         }
+
+//	 if(noisy>2) printf("\ta = %.6f\tf = %.6f %5d\n", a3, f3, NFunCall);
+
+      }
+   }
+
+   /* iteration by quadratic interpolation, fig 2.2.9-10 (pp 71-71) */
+   for (ii=0; ii<maxround; ii++) {
+      /* a4 is the minimum from the parabola over (a1,a2,a3)  */
+
+      if (a1>a2+1e-99 || a3<a2-1e-99 || f2>f1+1e-99 || f2>f3+1e-99) /* for linux */
+         { printf("\npoints out of order (ii=%d)!",ii+1); break; }
+
+      a4 = (a2-a3)*f1+(a3-a1)*f2+(a1-a2)*f3;
+      if (fabs(a4)>1e-100)
+         a4=((a2*a2-a3*a3)*f1+(a3*a3-a1*a1)*f2+(a1*a1-a2*a2)*f3)/(2*a4);
+      if (a4>a3 || a4<a1)  a4=(a1+a2)/2;  /* out of range */
+      else                 percentUse++;
+      f4=fun(a4);
+
+      /*
+      if (noisy>2) printf("\ta = %.6f\tf = %.6f %5d\n", a4, f4, NFunCall);
+      */
+
+      if (fabs(f2-f4)*(1+fabs(f2))<=e && fabs(a2-a4)*(1+fabs(a2))<=e)  break;
+
+      if (a1<=a4 && a4<=a2) {    /* fig 2.2.10 */
+         if (fabs(a2-a4)>.2*fabs(a1-a2)) {
+            if (f1>=f4 && f4<=f2) { a3=a2; a2=a4;  f3=f2; f2=f4; }
+            else { a1=a4; f1=f4; }
+         }
+         else {
+            if (f4>f2) {
+               a5=(a2+a3)/2; f5=fun(a5);
+               if (f5>f2) { a1=a4; a3=a5;  f1=f4; f3=f5; }
+               else       { a1=a2; a2=a5;  f1=f2; f2=f5; }
+            }
+            else {
+               a5=(a1+a4)/2; f5=fun(a5);
+               if (f5>=f4 && f4<=f2)
+                  { a3=a2; a2=a4; a1=a5;  f3=f2; f2=f4; f1=f5; }
+               else {
+                  a6=(a1+a5)/2; f6=fun(a6);
+                  if (f6>f5)
+                       { a1=a6; a2=a5; a3=a4;  f1=f6; f2=f5; f3=f4; }
+                  else { a2=a6; a3=a5;  f2=f6; f3=f5; }
+               }
+            }
+         }
+      }
+      else {                     /* fig 2.2.9 */
+         if (fabs(a2-a4)>.2*fabs(a2-a3)) {
+            if (f2>=f4 && f4<=f3) { a1=a2; a2=a4;  f1=f2; f2=f4; }
+            else                  { a3=a4; f3=f4; }
+         }
+         else {
+            if (f4>f2) {
+               a5=(a1+a2)/2; f5=fun(a5);
+               if (f5>f2) { a1=a5; a3=a4;  f1=f5; f3=f4; }
+               else       { a3=a2; a2=a5;  f3=f2; f2=f5; }
+            }
+            else {
+               a5=(a3+a4)/2; f5=fun(a5);
+               if (f2>=f4 && f4<=f5)
+                  { a1=a2; a2=a4; a3=a5;  f1=f2; f2=f4; f3=f5; }
+               else {
+                  a6=(a3+a5)/2; f6=fun(a6);
+                  if (f6>f5)
+                      { a1=a4; a2=a5; a3=a6;  f1=f4; f2=f5; f3=f6; }
+                  else { a1=a5; a2=a6;  f1=f5; f2=f6; }
+               }
+            }
+         }
+      }
+   }   /*  for (ii) */
+   if (f2<=f4)  { *f=f2; a4=a2; }
+   else           *f=f4;
+
+   return (*x0=(a4+a2)/2);
+}
+
+
+
+
+
+static double prob_InverseCDF, *par_InverseCDF;
+static double (*cdf_InverseCDF)(double x,double par[]);
+double diff_InverseCDF(double x);
+
+double diff_InverseCDF(double x)
+{
+// This is the difference between the given p and the CDF(x), the 
+// objective function to be minimized.
+
+   double px=(*cdf_InverseCDF)(x,par_InverseCDF);
+   return(square(prob_InverseCDF-px));
+}
+
+
+double InverseCDF(double(*cdf)(double x,double par[]),
+       double p,double x,double par[],double xb[2])
+{
+// Use x for initial value if in range
+
+//   int noisy0=noisy;
+   double sdiff,step=min2(0.05,(xb[1]-xb[0])/100), e=1e-15;
+
+//   noisy=0;
+   prob_InverseCDF=p;  par_InverseCDF=par; cdf_InverseCDF=cdf;
+   if(x<=xb[0]||x>=xb[1]) x=.5;
+   LineSearch(diff_InverseCDF, &sdiff, &x, xb, step, e);
+//   noisy=noisy0;
+
+   return(x);
+}
+
+#define CDFGamma(x,alpha,beta) IncompleteGamma((beta)*(x),alpha,LnGammaFunction(alpha))
+
+
+int matout (FILE *fout, double x[], int n, int m)
+{
+   int i,j;
+   for (i=0,FPN(fout); i<n; i++,FPN(fout)) 
+      FOR(j,m) fprintf(fout," %11.6f", x[i*m+j]);
+   return (0);
+}
+
+double CDFdN_dS(double x,double p[])
+{
+/* This calculates the CDF of the continuous dN/dS distribution over sites, 
+   to be used as argument to the routine InverseCDF().  When the distribution
+   has spikes, the spikes are ignored in this routine, and the scaling
+   is done outside this routine, for example, in DiscreteNSsites().
+   All parameters (par) for the w distribution are passed to this routine, 
+   although some (p0 for the spike at 0) are not used in this routine.  
+   Parameters are arranged in the following order:
+
+      NSgamma (2):       alpha, beta
+      NS2gamma (4):      p0, alpha1, beta1, alpha2 (=beta2)
+      NSbeta (2):        p_beta, q_beta
+      NSbetaw (4):       p0, p_beta, q_beta, w (if !com.fix_omega, not used here)
+      NSbetagamma (5):   p0, p_beta, q_beta, alpha, beta
+      NSbeta1gamma (5):  p0, p_beta, q_beta, alpha, beta (1+gamma)
+      NSbeta1normal (5): p0, p_beta, q_beta, mu, s (normal>1)
+      NS02normal (5):    p0, p1, mu2, s1, s2 (s are sigma's)
+      NS3normal (6):     p0, p1, mu2, s0, s1, s2 (s are sigma's)
+
+   Parameters p0 & p1 are transformed if (!LASTROUND)
+
+*/
+   double cdf=-1;
+   double z, f[3],mu[3]={0,1,2},sig[3]; /* 3normal: mu0=0 fixed. mu2 estimated */
+
+   switch(com.NSsites) {
+   case(NSgamma):  cdf=CDFGamma(x,p[0],p[1]);   break;
+   case(NS2gamma): 
+      cdf=p[0] *CDFGamma(x,p[1],p[2])+(1-p[0])*CDFGamma(x,p[3],p[3]);  break;
+   case(NSbeta):   cdf=CDFBeta(x,p[0],p[1],0);  break;
+   case(NSbetaw):  cdf=CDFBeta(x,p[1],p[2],0);  break;
+   case(NSbetagamma):
+      cdf=p[0]*CDFBeta(x,p[1],p[2],0)+(1-p[0])*CDFGamma(x,p[3],p[4]);  break;
+
+   case(NSbeta1gamma):
+      if(x<=1) cdf=p[0]*CDFBeta(x,p[1],p[2],0);
+      else     cdf=p[0]+(1-p[0])*CDFGamma(x-1,p[3],p[4]);
+      break;
+   case(NSbeta1normal):
+      if(x<=1) cdf=p[0]*CDFBeta(x,p[1],p[2],0);
+      else {
+         cdf=CDFNormal((p[3]-1)/p[4]);
+         if(cdf<1e-9) {
+            matout(F0,p,1,5);;
+            printf("PHI(%.6f)=%.6f\n",(p[3]-1)/p[4],cdf);  getchar();
+         }
+         cdf=p[0]+(1-p[0])*(1- CDFNormal((p[3]-x)/p[4])/cdf);
+      }
+      break;
+   case(NS02normal):
+      mu[2]=p[2]; sig[1]=p[3]; sig[2]=p[4];
+      f[1]=p[1];  f[2]=1-f[1];
+      cdf = 1 - f[1]* CDFNormal(-(x-mu[1])/sig[1])/CDFNormal(mu[1]/sig[1])
+              - f[2]* CDFNormal(-(x-mu[2])/sig[2])/CDFNormal(mu[2]/sig[2]);
+      break;
+   case(NS3normal):
+      mu[2]=p[2]; sig[0]=p[3]; sig[1]=p[4]; sig[2]=p[5];
+
+      if(LASTROUND) { f[0]=p[0]; f[1]=p[1]; }
+      else          { z=(f[0]=exp(p[0]))+(f[1]=exp(p[1]))+1; f[0]/=z; f[1]/=z;}
+      f[2]=1-f[0]-f[1];
+      cdf = 1 - f[0]* 2*CDFNormal(-x/sig[0])
+              - f[1]* CDFNormal(-(x-mu[1])/sig[1])/CDFNormal(mu[1]/sig[1])
+              - f[2]* CDFNormal(-(x-mu[2])/sig[2])/CDFNormal(mu[2]/sig[2]);
+      break;
+   }
+   return(cdf);
+}
+/*
+(*) Codon models for variable dN/dS ratios among sites
+    (com.nrate includes kappa & omega) (see also CDFdN_dS)
+
+    NSsites          npara
+
+    0  one-ratio     0:    one ratio for all sites
+    1  neutral       1:    p0 (w0=0, w1=1)
+    2  selection     3:    p0, p1, w2 (w0=0, w1=1)
+    3  discrete      2K-1: p0,p1,..., and w0,w1,...
+    4  freqs         K:    p's (w's are fixed)
+    5  gamma         2:    alpha, beta
+    6  2gamma        4:    p0, alpha1,beta1, alpha2=beta2
+    7  beta          2:    p_beta, q_beta
+    8  beta&w        4:    p0, p_beta, q_beta, w estimated
+    9  beta&gamma    5:    p0, p_beta, q_beta, alpha, beta
+   10  beta&1+gamma  5:    p0, p_beta, q_beta, alpha, beta (1+gamma used)
+   11  beta&1>normal 5:    p0, p_beta, q_beta, mu, s    (normal truncated w>1)
+   12  0&2normal     5:    p0, p1, mu2, s1, s2
+   13  3normal       6:    p0, p1, mu2, s0, s1, s2
+   14  M8a:beta&w=1  3:    p0, p_beta, q_beta, w=1 fixed
+   15  M8a:beta&w>=1 4:    p0, p_beta, q_beta, w>=1 estimated
+
+
+   */
+
+
+/*
+
+int DiscreteNSsites(vector<double> &params, int &ncatG, int &NSsites, vector<double> &output)//double a, double b, double c,double d) //double par[])
+{
+/* This discretizes the continuous distribution for dN/dS ratios among sites
+   and calculates freqK[] and rK[], using the median method.
+   par[] contains all paras in the w distribution.  par[0] is the 
+   proportion of beta if (NSsites==betaw), or the proportion of w=0 if 
+   (NSsites=NS02normal).
+   This routine uses NSsites, ncatG, freqK, rK.
+   betaw has ncatG-1 site classes in the beta distribution, and 02normal 
+   has ncatG-1 site classes in the mixed normal distribution.
+   See the function CDFdN_dS() for definitions of parameters.
+*/
+/*
+//	double par[4]={a,b,c,d};
+int thesize=params.size();
+double *par; par=new double[thesize];
+double *rK; rK=new double[thesize];
+double *freqK; freqK=new double[thesize];
+
+for(int gv=1; gv<params.size(); gv++) par[gv]=params.at(gv);
+for( gv=1; gv<params.size(); gv++) cout<<" WEWE "<<par[gv]<<endl;
+
+cout<<ncatG<<" EWEWE "<<NSsites<<endl;
+	int status=0, j,off, K=ncatG-(NSsites==NSbetaw || NSsites==NS02normal);
+
+double xb[2]={1e-7,99};  // bounds for omega.  
+   int K1=6, K2=4, UseK1K2=0;
+   double p01=0, p,w0, lnbeta;
+
+   if(NSsites==NSbeta || NSsites==NSbetaw) xb[1]=1;
+
+#ifdef NSSITES_K1_K2_CLASSES
+ //  cout<<"A"<<endl;
+   if((NSsites==NSgamma||NSsites==NS2gamma||NSsites>=NSbetagamma)){
+      K2=max2(K2,K/3);  K1=K-K2;  UseK1K2=1;
+      p01=CDFdN_dS(1.,par);
+
+      // printf("\nK:%3d%3d\t p01=%9.5f\n",K1,K2,p01); 
+      FOR(j,K) {
+         if(j<K1) { p=p01*(j*2.+1)/(2.*K1); w0=p; }
+         else     { p=p01+(1-p01)*((j-K1)*2.+1)/(2.*K2); w0=1.01+(j-K1)/K2; }
+         rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+         freqK[j]=(j<K1 ? p01/K1 : (1-p01)/K2); thread
+      }
+   }
+#endif
+
+   if(!UseK1K2) { // this is currently used 
+   cout<<"B"<<endl;
+      if(NSsites==NSbeta || NSsites==NSbetaw) {
+         off=(NSsites==NSbetaw);  // par[0] is proportion for beta for M8 
+         lnbeta=LnGamma(par[off])+LnGamma(par[off+1])-LnGamma(par[off]+par[off+1]);
+         for(j=0; j<K; j++) {
+            p=(j*2.+1)/(2.*K);
+            rK[j]=InverseCDFBeta(p, par[off], par[off+1], lnbeta);
+         }
+      }
+      else {
+   cout<<"C"<<endl;
+         FOR(j,K) {
+            p=(j*2.+1)/(2.*K);
+            w0=.01+j/K; if(rK[j]) w0=(w0+rK[j])/2;
+            rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+			cout<<"WDWD "<<InverseCDF(CDFdN_dS,p,w0,par,xb)<<endl;
+         }
+      }
+      FOR(j,K) freqK[j]=1./K;
+   }
+
+   if(NSsites==NSbetaw) {
+    //if(!fix_omega) rK[ncatG-1]=par[3];
+	   rK[ncatG-1]=par[3];
+    //else               rK[ncatG-1]=omega_fix;
+      freqK[K]=1-par[0]; FOR(j,K) freqK[j]*=par[0];
+   }
+   if(NSsites==NS02normal) {
+      for(j=K-1;j>=0;j--) // shift to right by 1 to make room for spike at 0
+         { rK[j+1]=rK[j]; freqK[j+1]=freqK[j];  }
+      rK[0]=0;  freqK[0]=par[0];
+      for(j=1;j<K+1;j++) freqK[j]*=(1-par[0]);
+   }
+
+   if(NSsites>=NSgamma){
+      if(!status && NSsites==NSbeta) 
+         for(j=1;j<ncatG;j++) if(rK[j]+1e-7<rK[j-1]) status=1;
+
+      if(status) {
+         printf("\nwarning: DiscreteNSsites\nparameters: ");
+         FOR(j,(NSsites==7?2:4)) printf(" %12.6f", par[j]);  FPN(F0);
+         FOR(j,ncatG)            printf("%13.5f", freqK[j]);  FPN(F0);
+         FOR(j,ncatG)            printf("%13.5e", rK[j]);  FPN(F0);
+      }
+   }
+
+   output.clear();
+   cout<<"WOWOWOWOW "<<ncatG<<endl;
+
+   for(int jk=0; jk<ncatG; jk++) 
+   {output.push_back(rK[jk]); cout<<rK[jk]<<" WEGFQEGEG"<<endl;}
+   
+   return(0);
+}*/
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// note from WF - not really used any more as options for models M4-M13 have been disabled.
+
+
+int DiscreteNSsites(double par[], int ngamcat, int model, vector<double> &output)
+{
+/* 
+Yang, Z., Nielsen, R., Goldman, N. and Pedersen, A-M. K. (2000) Codon-Substitution Models for Heterogeneous Selection Pressure at Amino Acid Sites. Genetics 155: 431-439 (May 2000)
+
+  
+  
+   This discretizes the continuous distribution for dN/dS ratios among sites
+   and calculates freqK[] and rK[], using the median method.
+   par[] contains all paras in the w distribution.  par[0] is the 
+   proportion of beta if (com.NSsites==betaw), or the proportion of w=0 if 
+   (com.NSsites=NS02normal).
+   This routine uses com.NSsites, com.ncatG, com.freqK, com.rK.
+   betaw has com.ncatG-1 site classes in the beta distribution, and 02normal 
+   has com.ncatG-1 site classes in the mixed normal distribution.
+   See the function CDFdN_dS() for definitions of parameters.
+*/
+//	cout<<"!!!!!!!!!! !"<<endl;
+	com.ncatG=ngamcat;
+	com.NSsites=model;
+
+   int status=0, j,off, K=com.ncatG-(com.NSsites==NSbetaw || com.NSsites==NS02normal);
+   //cout<<"KKKKKKKKKKKKKKKKKKK   "<<K<<"  "<<model<<endl;
+   double xb[2]={1e-7,99};  /* bounds for omega.  */
+   int K1=6, K2=4, UseK1K2=0;
+   double p01=0, p,w0, lnbeta;
+
+   if(com.NSsites==NSbeta || com.NSsites==NSbetaw) xb[1]=1;
+
+#ifdef NSSITES_K1_K2_CLASSES
+   if((com.NSsites==NSgamma||com.NSsites==NS2gamma||com.NSsites>=NSbetagamma)){
+      K2=max2(K2,K/3);  K1=K-K2;  UseK1K2=1;
+      p01=CDFdN_dS(1.,par);
+
+      /* printf("\nK:%3d%3d\t p01=%9.5f\n",K1,K2,p01); */
+      FOR(j,K) {
+         if(j<K1) { p=p01*(j*2.+1)/(2.*K1); w0=p; }
+         else     { p=p01+(1-p01)*((j-K1)*2.+1)/(2.*K2); w0=1.01+(j-K1)/K2; }
+         com.rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+         com.freqK[j]=(j<K1 ? p01/K1 : (1-p01)/K2); thread
+      }
+   }
+#endif
+
+   if(!UseK1K2) { /* this is currently used */
+      if(com.NSsites==NSbeta || com.NSsites==NSbetaw) {
+         off=(com.NSsites==NSbetaw);  /* par[0] is proportion for beta for M8 */
+         lnbeta=LnGamma(par[off])+LnGamma(par[off+1])-LnGamma(par[off]+par[off+1]);
+         for(j=0; j<K; j++) {
+            p=(j*2.+1)/(2.*K);
+            com.rK[j]=InverseCDFBeta(p, par[off], par[off+1], lnbeta);
+         }
+      }
+      else {
+         FOR(j,K) {
+            p=(j*2.+1)/(2.*K);
+            w0=.01+j/K; if(com.rK[j]) w0=(w0+com.rK[j])/2;
+            com.rK[j]=InverseCDF(CDFdN_dS,p,w0,par,xb);
+         }
+      }
+      FOR(j,K) com.freqK[j]=1./K;
+   }
+
+   if(com.NSsites==NSbetaw) {
+      if(!com.fix_omega) com.rK[com.ncatG-1]=par[3];
+      else               com.rK[com.ncatG-1]=com.omega_fix;
+      com.freqK[K]=1-par[0]; FOR(j,K) com.freqK[j]*=par[0];
+   }
+   if(com.NSsites==NS02normal) {
+      for(j=K-1;j>=0;j--) /* shift to right by 1 to make room for spike at 0*/
+         { com.rK[j+1]=com.rK[j]; com.freqK[j+1]=com.freqK[j];  }
+      com.rK[0]=0;  com.freqK[0]=par[0];
+      for(j=1;j<K+1;j++) com.freqK[j]*=(1-par[0]);
+   }
+
+   if(com.NSsites>=NSgamma){
+      if(!status && com.NSsites==NSbeta) 
+         for(j=1;j<com.ncatG;j++) if(com.rK[j]+1e-7<com.rK[j-1]) status=1;
+
+      if(status) {
+         printf("\nwarning: DiscreteNSsites\nparameters: ");
+         FOR(j,(com.NSsites==7?2:4)) printf(" %12.6f", par[j]);  FPN(F0);
+         FOR(j,com.ncatG)            printf("%13.5f", com.freqK[j]);  FPN(F0);
+         FOR(j,com.ncatG)            printf("%13.5e", com.rK[j]);  FPN(F0);
+      }
+   }
+
+   for(int i=0; i<ngamcat; i++) output.push_back(com.rK[i]);
+   return(0);
+}
+
+///////////////////
+// old testing of routines.......  from Jan 08 I think ....  delete?
+
+/*
+double main(int argc, char* argv[])
+{	
+vector<double> params;
+vector<double> output;
+params.push_back(0.2);
+params.push_back(0.2);
+params.push_back(0.2);
+params.push_back(0.2);
+params.push_back(0.2);
+
+//int ng=10;
+//int blah=5;
+//DiscreteNSsites(params,ng , blah, output);
+
+	double parameters[4]=
+	//{3,3,3,3}; //
+	{0.383,0.967,1.452,0.283};
+	
+	//int DiscreteNSsites(double par[], int ncatG, int NSsites, double rK[], double freqK[])
+DiscreteNSsites(parameters, 10, 6, output);
+
+   for(int i=0; i<10; i++) cout<<"qwdewf "<<output.at(i)<<endl;
+
+
+	//	parameters);
+cout<<"EEEEEEEEEEEEEEEEE"<<endl;
+//	cout<<com.rK[0]<<"\t"<<com.rK[1]<<"\t"<<com.rK[2]<<"\t"<<com.rK[3]<<"\t"<<com.rK[4]<<"\t"<<com.rK[5]<<"\t"<<com.rK[6]<<"\t"<<com.rK[7]<<"\t"<<com.rK[8]<<"\t"<<com.rK[9]<<endl;
+
+
+	return 0;
+}
+
+/*
+double main(int argc, char* argv[])
+{					
+	vector<double> freq,rK, freq1,rK1;
+	double alfa, beta;
+	int K=10, median=0, ig;
+	
+	alfa=0.967; beta=1.452;
+	DiscreteGamma (freq, rK,alfa, beta, K, median);
+
+	for( ig=0; ig<K; ig++) cout<<rK.at(ig)<<endl;
+
+	cout<<"*****************"<<endl ;
+	alfa=beta=0.283;
+	DiscreteGamma (freq1, rK1,alfa, beta, K, median);
+
+	for( ig=0; ig<K; ig++) cout<<rK1.at(ig)<<endl;
+
+	cout<<"*****************"<<endl;
+
+	for(ig=0; ig<K; ig++) cout<<0.383*rK.at(ig)+0.617*rK1.at(ig)<<endl;
+
+	cout<<"*****************"<<endl ;
+	alfa=0.967*0.383+0.617*0.283; beta=1.452*0.383+0.283*0.617;
+	DiscreteGamma (freq1, rK1,alfa, beta, K, median);
+
+	for( ig=0; ig<K; ig++) cout<<rK1.at(ig)<<endl;
+
+
+	
+	
+
+
+	com.NSsites=5;
+	double parameters[4]={3,3,3,3}; //0.383,0.967,1.452,0.283};
+
+	com.ncatG=10;
+	DiscreteNSsites(parameters);
+cout<<"EEEEEEEEEEEEEEEEE"<<endl;
+	cout<<com.rK[0]<<"\t"<<com.rK[1]<<"\t"<<com.rK[2]<<"\t"<<com.rK[3]<<"\t"<<com.rK[4]<<"\t"<<com.rK[5]<<"\t"<<com.rK[6]<<"\t"<<com.rK[7]<<"\t"<<com.rK[8]<<"\t"<<com.rK[9]<<endl;
+cout<<"EEEEEEEEEEEEEEEEE"<<endl;
+	DiscreteGamma (freq1, rK1,3, 3, 10, 0);
+
+	for( ig=0; ig<10; ig++) cout<<rK1.at(ig)<<"\t";
+
+	int a4,b4,c4,d4;
+	double a,b,c,d,a1,b1,c1,d1;
+	a1=0.383;
+	b1=0.967;
+	c1=1.452;
+	d1=0.283;
+/*
+	ofstream rout("bits.txt");
+	
+	a=a1; b=b1; c=c1; d=d1; //a=0.303; //a=0.38;
+a=a1;a+=0.0005;
+	for(a4=0; a4<101; a4++)
+	{b=b1;b+=0.0005;
+
+		a-=0.00001;
+	for(b4=0; b4<101; b4++)
+	{
+		c=c1;c+=0.0005;
+
+		b-=0.00001;
+	
+	for(c4=0; c4<101; c4++)
+	{
+d=d1;d+=0.0005;
+
+		c-=0.00001;
+
+	for(d4=0; d4<101; d4++)
+	{
+		d-=0.00001;
+		double diff;
+	
+		DiscreteNSsites(a,b,c,d); //parameters);
+		//for(ig=0; ig<10; ig++) cout<<com.rK[ig]<<endl;
+		double T[10]={0.0003,0.0135,0.0598,0.1424,0.2621,0.4267,0.6569,1.0037,1.6282,3.5598};
+		double x0=com.rK[0]; diff=T[0]-x0; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x1=com.rK[1]; diff=T[1]-x1; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x2=com.rK[2]; diff=T[2]-x2; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x3=com.rK[3]; diff=T[3]-x3; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x4=com.rK[4]; diff=T[4]-x4; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x5=com.rK[5]; diff=T[5]-x5; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x6=com.rK[6]; diff=T[6]-x6; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x7=com.rK[7]; diff=T[7]-x7; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x8=com.rK[8]; diff=T[8]-x8; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		double x9=com.rK[9]; diff=T[9]-x9; if(diff<0) diff=-diff; if(diff>0.00005) continue;
+		
+		rout<<a4<<"\t"<<b4<<"\t"<<c4<<"\t"<<d4<<"\t"<<com.rK[0]<<"\t"<<com.rK[1]<<"\t"<<com.rK[2]<<"\t"<<com.rK[3]<<"\t"<<com.rK[4]<<"\t"<<com.rK[5]<<"\t"<<com.rK[6]<<"\t"<<com.rK[7]<<"\t"<<com.rK[8]<<"\t"<<com.rK[9]<<endl;
+		cout<<a4<<"\t"<<b4<<"\t"<<c4<<"\t"<<d4<<"\t"<<com.rK[0]<<"\t"<<com.rK[1]<<"\t"<<com.rK[2]<<"\t"<<com.rK[3]<<"\t"<<com.rK[4]<<"\t"<<com.rK[5]<<"\t"<<com.rK[6]<<"\t"<<com.rK[7]<<"\t"<<com.rK[8]<<"\t"<<com.rK[9]<<endl;
+
+	}}}}
+*/
+/*	return 0;
+}
+*/
diff --git a/src/randoms.cpp b/src/randoms.cpp
new file mode 100644
index 0000000..504740b
--- /dev/null
+++ b/src/randoms.cpp
@@ -0,0 +1,184 @@
+/*  
+   INDELible V1.03
+    "A comprehensive and flexible simulator of molecular sequence evolution"
+    Copyright (C) 2009 William Fletcher
+
+    If using this software please cite the following reference:
+
+    Fletcher, W. and Yang, Z. 2009. 
+	"INDELible: a flexible simulator of biological sequence evolution." 
+	Mol. Biol. and Evol. (in press). 
+
+    If you need to contact me with any queries, questions, problems or (god-forbid) bugs
+    then please go to http://abacus.gene.ucl.ac.uk/software/indelible/bug.php
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    Please visit http://www.gnu.org/licenses/ for a full copy of the license.
+*/
+
+
+
+// uniform random numbers are produced using the code in this file.
+#include "MersenneTwister.h"
+
+MTRand mtrand1;
+MTRand mtrand2;
+	
+// needed for time monitoring
+
+#include <stdio.h>
+#include <stdlib.h>
+/*
+// time monitoring stuff works as below:
+
+clock_t start, finish;
+   double  duration;
+
+ // Measure the duration of an event. 
+   printf( "Time to do %ld empty loops is ", i );
+   start = clock();
+   while( i-- )
+      ;
+   finish = clock();
+   duration = (double)(finish - start) / CLOCKS_PER_SEC;
+   printf( "%2.1f seconds\n", duration );
+*/
+
+#include <time.h>        
+#include <math.h>
+//////////////////////////////////////////////////////////////
+
+double myrand;
+int idum;
+
+
+// exponential random number generation
+double expmyrand(double myrate)
+{
+	double dum;
+	do
+	dum=mtrand1();
+	while (dum ==0.0);
+	return -(log(dum)/myrate);
+}
+
+
+// geometric random number generation
+int oldgeomyrand(double p) 
+{
+	if(p==1) return 1;
+	else
+	{
+		double dum;
+		do
+		dum=mtrand1();
+		while (dum ==0.0);
+		return int(log(dum)/log(1-p));
+	}
+}
+
+// alternative parameterisation - for testing
+int geomyrand(double q)  
+{
+	if(q==0) return 1;
+	else
+	{
+		double dum;
+		do
+		dum=mtrand1();
+		while (dum ==0.0);
+		return int(log(dum)/log(q));
+	}
+}
+
+// negative binomial distribution
+int randnegbin(int r, double q)
+{
+	int u=0;
+	while(r--)
+		u += geomyrand(q);
+	return u+1;
+}
+
+// alternative parameterisation - for testing
+int oldrandnegbin(int r, double q)
+{
+	double p=1-q;
+	int u=0;
+	while(r--)
+		u += oldgeomyrand(p);
+	return u+1;
+}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+// Zipfian random number generation
+
+#define H(x,q1,q2,v) exp(q1*log(v+x))*q2
+
+#define H1(x,q1,q2,v) -v+exp(q2*log((1-q)*x))
+
+unsigned int imax = ~0;
+	
+	
+double Zq1,  Zq2,  ZHx0,  Zs,  ZHimax;
+
+int Zipf(double q, double v)
+{
+	// rejection-inversion method of H�rmann and Derflinger (1996) 
+	
+	// H�rmann, W. and G. Derflinger, G. (1996) Rejection-inversion to generate variates from monotone discrete distributions. ACM Transactions on Modelling and Computer Simulation, 6(3), 169-184 
+
+	// produces random zipf number from distribution with following unnormalised probability function:
+
+    // p_k = (v + k)^(-q)  where k=0,1,... and q>1, v>0
+
+	// at least twice as fast as method of Devroye Luc (1986) used in DAWG - see below
+	
+	double U, X, K;
+
+	do
+	{
+		U = mtrand1();
+
+		U = ZHimax + ( U * ( ZHx0 - ZHimax ) );
+
+		X = H1(U,Zq1,Zq2,v);
+
+		K = X + 0.5;
+
+		if( K - X <= Zs) return int(K+1);
+
+		else if ( U >= H(K+0.5,Zq1,Zq2,v) - exp(-1 * log(v + K) * q) ) return int(K+1);
+		
+	} while(true); 
+}
+#define newZipf(a) Zipf(a,1)
+  
+
+
+// algorithm from DAWG (Cartwright, 2005).
+// Draw from Zipf distribution, with parameter a > 1.0
+// Devroye Luc (1986) Non-uniform random variate generation.
+// Springer-Verlag: Berlin. p551
+
+int oldZipf(double a)
+{
+	double b = pow(2.0, a-1.0);
+	double x,t;
+	do {
+	 x = floor(pow(mtrand1(), -1.0/(a-1.0)));
+	 t = pow(1.0+1.0/x, a-1.0);
+	} while( mtrand1()*x*(t-1.0)*b > t*(b-1.0));
+	return (int)x;
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/indelible.git



More information about the debian-med-commit mailing list