]> git.donarmstrong.com Git - mrbayes.git/blob - src/model.c
fix path to libhmsbeagle
[mrbayes.git] / src / model.c
1 /*
2  *  MrBayes 3
3  *
4  *  (c) 2002-2013
5  *
6  *  John P. Huelsenbeck
7  *  Dept. Integrative Biology
8  *  University of California, Berkeley
9  *  Berkeley, CA 94720-3140
10  *  johnh@berkeley.edu
11  *
12  *  Fredrik Ronquist
13  *  Swedish Museum of Natural History
14  *  Box 50007
15  *  SE-10405 Stockholm, SWEDEN
16  *  fredrik.ronquist@nrm.se
17  *
18  *  With important contributions by
19  *
20  *  Paul van der Mark (paulvdm@sc.fsu.edu)
21  *  Maxim Teslenko (maxim.teslenko@nrm.se)
22  *
23  *  and by many users (run 'acknowledgments' to see more info)
24  *
25  * This program is free software; you can redistribute it and/or
26  * modify it under the terms of the GNU General Public License
27  * as published by the Free Software Foundation; either version 2
28  * of the License, or (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details (www.gnu.org).
34  *
35  */
36
37 #include "bayes.h"
38 #include "best.h"
39 #include "command.h"
40 #include "model.h"
41 #include "mcmc.h"
42 #include "proposal.h"
43 #include "sumpt.h"
44 #include "utils.h"
45 #if defined(__MWERKS__)
46 #include "SIOUX.h"
47 #endif
48
49 const char* const svnRevisionModelC = "$Rev: 1067 $";   /* Revision keyword which is expended/updated by svn on each commit/update */
50
51 #undef  DEBUG_ADDDUMMYCHARS
52 #undef  DEBUG_CONSTRAINTS
53 #undef  DEBUG_COMPRESSDATA
54 #undef  DEBUG_CPP
55
56 /* local prototypes */
57 int       AddDummyChars (void);
58 void      AllocateCppEvents (Param *p);
59 MCMCMove *AllocateMove (MoveType *moveType, Param *param);
60 int       AllocateNormalParams (void);
61 int       AllocateTreeParams (void);
62 void      CheckCharCodingType (Matrix *m, CharInfo *ci);
63 int       CheckExpandedModels (void);
64 int       CompressData (void);
65 int       InitializeChainTrees (Param *p, int from, int to, int isRooted);
66 int       FillBrlensSubParams (Param *param, int chn, int state);
67 void      FreeCppEvents (Param *p);
68 void      FreeMove (MCMCMove *mv);
69 void      GetPossibleAAs (int aaCode, int aa[]);
70 void      GetPossibleNucs (int nucCode, int nuc[]);
71 void      GetPossibleRestrictionSites (int resSiteCode, int *sites);
72 int       GetUserTreeFromName (int *index, char *treeName);
73 void      InitializeMcmcTrees (Param *p);
74 int       IsApplicable (Param *param);
75 int       IsApplicable_FiveTaxaOrMore (Param *param);
76 int       IsApplicable_FourTaxaOrMore (Param *param);
77 int       IsApplicable_ThreeTaxaOrMore (Param *param);
78 int       IsApplicableTreeAgeMove (Param *param);
79 int       IsModelSame (int whichParam, int part1, int part2, int *isApplic1, int *isApplic2);
80 int       LargestMovableSubtree(Param *treeParam);
81 int       NumActiveParts (void);
82 int       NumInformativeHardConstraints (ModelParams *mp);
83 int       NumNonExcludedChar (void);
84 int       NumStates (int part);
85 int       PrintCompMatrix (void);
86 int       PrintMatrix (void);
87 int       ProcessStdChars (RandLong *seed);
88 void      SetCode (int part);
89 int       SetModelParams (void);
90 int       SetPopSizeParam (Param *param, int chn, int state, PolyTree *pt);
91 int       SetRelaxedClockParam (Param *param, int chn, int state, PolyTree *pt);
92 int       SetUpLinkTable (void);
93 int       ShowMoves (int used);
94 int       ShowParameters (int showStartVals, int showMoves, int showAllAvailable);
95 int       UpdateCppEvolLength (int *nEvents, MrBFlt **pos, MrBFlt **rateMult, MrBFlt *evolLength, TreeNode *p, MrBFlt baseRate);
96
97 /* globals */
98 int             *activeParams[NUM_LINKED];              /* a table holding the parameter link status        */
99 int             localOutGroup;                          /* outgroup for non-excluded taxa                   */
100 Calibration     **localTaxonCalibration = NULL;         /* stores local taxon calibrations (ages)           */
101 char            **localTaxonNames = NULL;               /* points to names of non-excluded taxa             */
102 Model           *modelParams;                           /* holds model params                               */
103 ModelInfo       *modelSettings;                         /* stores important info on model params            */
104 MCMCMove        **moves;                                /* vector of pointers to applicable moves           */
105 int             numApplicableMoves;                     /* number of moves applicable to model parameters   */
106 int             numCurrentDivisions;                    /* number of partitions of data                     */
107 int             numGlobalChains;                        /* number of global chains                          */
108 int             numLocalTaxa;                           /* number of non-excluded taxa                      */
109 int             numLocalChar;                           /* number of non-excluded characters                */
110 int             numParams;                              /* number of parameters in model                    */
111 int             numTopologies;                          /* number of topologies for one chain and state     */
112 int             numTrees;                               /* number of trees for one chain and state          */
113 Param           *params;                                /* vector of parameters                             */
114 Param           *printParams;                           /* vector of subst model parameters to print        */
115 ShowmovesParams showmovesParams;                        /* holds parameters for Showmoves command           */
116 Param           *treePrintparams;                       /* vector of tree parameters to print               */
117 int             setUpAnalysisSuccess;                   /* Set to YES if analysis is set without error      */
118
119 /* globals used to describe and change the current model; allocated in AllocCharacters and SetPartition  */
120 int         *numVars;                                   /* number of variables in setting arrays         */
121 int         *activeParts;                               /* partitions changes should apply to            */
122 int         *linkTable[NUM_LINKED];                     /* how parameters are linked across parts        */
123 int         *tempLinkUnlink[NUM_LINKED];                /* for changing parameter linkage                */
124 int         *tempLinkUnlinkVec;                         /* for changing parameter linkage                */
125 MrBFlt      *tempNum;                                   /* vector of numbers used for setting arrays     */
126
127 /* Aamodel parameters */
128 MrBFlt          aaJones[20][20];             /* rates for Jones model                        */
129 MrBFlt          aaDayhoff[20][20];           /* rates for Dayhoff model                      */
130 MrBFlt          aaMtrev24[20][20];           /* rates for mtrev24 model                      */
131 MrBFlt          aaMtmam[20][20];             /* rates for mtmam model                        */
132 MrBFlt          aartREV[20][20];             /* rates for rtREV model                        */
133 MrBFlt          aaWAG[20][20];               /* rates for WAG model                          */
134 MrBFlt          aacpREV[20][20];             /* rates for aacpREV model                      */
135 MrBFlt          aaVt[20][20];                /* rates for VT model                           */
136 MrBFlt          aaBlosum[20][20];            /* rates for Blosum62 model                     */
137 MrBFlt          aaLG[20][20];                /* rates for LG model                           */
138 MrBFlt          jonesPi[20];                 /* stationary frequencies for Jones model       */
139 MrBFlt          dayhoffPi[20];               /* stationary frequencies for Dayhoff model     */
140 MrBFlt          mtrev24Pi[20];               /* stationary frequencies for mtrev24 model     */
141 MrBFlt          mtmamPi[20];                 /* stationary frequencies for mtmam model       */
142 MrBFlt          rtrevPi[20];                 /* stationary frequencies for rtREV model       */
143 MrBFlt          wagPi[20];                   /* stationary frequencies for WAG model         */
144 MrBFlt          cprevPi[20];                 /* stationary frequencies for aacpREV model     */
145 MrBFlt          vtPi[20];                    /* stationary frequencies for VT model          */
146 MrBFlt          blosPi[20];                  /* stationary frequencies for Blosum62 model    */
147 MrBFlt          lgPi[20];                    /* stationary frequencies for LG model          */
148
149 /* parser flags and variables */
150 int         fromI, toJ, foundDash, foundComma, foundEqual, foundBeta,
151             foundAaSetting, foundExp, modelIsFixed, linkNum, foundLeftPar,
152             foundFSNum[999], foundFSTime[999], tempNumStates, isNegative;
153 MrBFlt      tempStateFreqs[200], tempAaModelPrs[10];
154 char        colonPr[100], clockPr[30];
155
156 /* other local variables (this file) */
157 MrBFlt          empiricalFreqs[200];         /* emprical base frequencies for partition                 */
158 int             intValsRowSize = 0;          /* row size of intValues matrix                            */
159 int             *intValues = NULL;           /* stores int values of chain parameters                   */
160 Tree            **mcmcTree;                  /* pointers to trees for mcmc                              */
161 int             paramValsRowSize = 0;        /* row size of paramValues matrix                          */
162 MrBFlt          *paramValues = NULL;         /* stores actual values and subvalues of chain parameters  */
163 int             *relevantParts = NULL;       /* partitions that are affected by this move               */
164 Param           **subParamPtrs;              /* pointer to subparams for topology params                */
165 int             *stateSize;                  /* # states for each compressed char                       */
166 // int          foundCurly;
167 // char         *plotTokenP;                 /* plotToken[CMD_STRING_LENGTH];*/
168
169
170 /*-----------------------------------------------------------------------
171 |
172 |   AddDummyChars: Add dummy characters to relevant partitions
173 |
174 ------------------------------------------------------------------------*/
175 int AddDummyChars (void)
176 {
177     int         i, j, k, d, numIncompatible, numDeleted, numStdChars, oldRowSize,
178                 newRowSize, numDummyChars, newColumn, newChar, oldColumn, oldChar, 
179                 isCompat, *tempChar, numIncompatibleChars;
180     BitsLong    *tempMatrix, bitsLongOne = 1;
181     CLFlt       *tempSitesOfPat;
182     ModelInfo   *m;
183     ModelParams *mp;
184     CharInfo    cinfo;
185     Matrix      matrix;
186
187     /* set pointers to NULL */
188     tempMatrix = NULL;
189     tempSitesOfPat = NULL;
190     tempChar = NULL;
191
192     /* check how many dummy characters needed in total */
193     numDummyChars = 0;
194     numStdChars = 0;
195     for (d=0; d<numCurrentDivisions; d++)
196         {
197         m = &modelSettings[d];
198         mp = &modelParams[d];
199
200         m->numDummyChars = 0;
201
202         if (mp->dataType == RESTRICTION && !strcmp(mp->parsModel,"No"))
203             {
204             if (mp->coding & NOABSENCESITES)
205                 m->numDummyChars++;
206             if (mp->coding & NOPRESENCESITES)
207                 m->numDummyChars++;
208             if (mp->coding & NOSINGLETONABSENCE)
209                 m->numDummyChars += numLocalTaxa;
210             if (mp->coding & NOSINGLETONPRESENCE)
211                 m->numDummyChars += numLocalTaxa;
212             }
213
214         if (mp->dataType == STANDARD && !strcmp(mp->parsModel,"No"))
215             {
216             if (mp->coding & VARIABLE)
217                 m->numDummyChars += 2;
218             if (mp->coding & NOSINGLETONS)
219                 m->numDummyChars += 2*numLocalTaxa;
220             numStdChars += (m->numChars + m->numDummyChars);
221             }
222
223         numDummyChars += m->numDummyChars;
224         m->numChars += m->numDummyChars;
225         }
226
227     /* exit if dummy characters not needed */
228     if (numDummyChars == 0)
229         return NO_ERROR;
230
231     /* print original compressed matrix */
232 #   if  defined (DEBUG_ADDDUMMYCHARS)
233     MrBayesPrint ("Compressed matrix before adding dummy characters...\n");
234     PrintCompMatrix();
235 #   endif
236
237     /* set row sizes for old and new matrices */
238     oldRowSize = compMatrixRowSize;
239     compMatrixRowSize += numDummyChars;
240     newRowSize = compMatrixRowSize;
241     numCompressedChars += numDummyChars;
242
243     /* allocate space for new data */
244     tempMatrix = (BitsLong *) SafeCalloc (numLocalTaxa * newRowSize, sizeof(BitsLong));
245     tempSitesOfPat = (CLFlt *) SafeCalloc (numCompressedChars, sizeof(CLFlt));
246     tempChar = (int *) SafeCalloc (compMatrixRowSize, sizeof(int));
247     if (!tempMatrix || !tempSitesOfPat || !tempChar)
248         {
249         MrBayesPrint ("%s   Problem allocating temporary variables in AddDummyChars\n", spacer);
250         goto errorExit;
251         }
252
253     /* initialize indices */
254     oldChar = newChar = newColumn = numDeleted = 0;
255
256     /* set up matrix struct */
257     matrix.origin = compMatrix;
258     matrix.nRows = numLocalTaxa;
259     matrix.rowSize = oldRowSize;
260
261     /* loop over divisions */
262     for (d=0; d<numCurrentDivisions; d++)
263         {
264         m = &modelSettings[d];
265         mp = &modelParams[d];
266
267         /* insert the dummy characters first for each division */
268         if (m->numDummyChars > 0)
269             {
270             // MrBayesPrint("%s   Adding dummy characters (unobserved site patterns) for division %d\n", spacer, d+1);
271             // do not print this every time
272
273             for (k=0; k<2; k++)
274                 {
275                 if (((mp->coding & NOSINGLETONPRESENCE) && k == 0) || ((mp->coding & NOSINGLETONABSENCE) && k == 1))
276                     {
277                     for (i=0; i< numLocalTaxa; i++)
278                         {
279                         for (j=0; j<numLocalTaxa; j++)
280                             {
281                             if (j == i)
282                                 tempMatrix[pos(j,newColumn,newRowSize)] = (bitsLongOne << k) ^ 3;
283                             else
284                                 tempMatrix[pos(j,newColumn,newRowSize)] = bitsLongOne << k;
285                             }
286                         tempSitesOfPat[newChar] = 0;
287                         tempChar[newColumn] = -1;
288                         newChar++;
289                         newColumn++;
290                         }
291                     }
292                 }
293
294             if (mp->coding & NOABSENCESITES)
295                 {
296                 for (i=0; i<numLocalTaxa; i++)
297                     tempMatrix[pos(i,newColumn,newRowSize)] = 1;
298                 tempSitesOfPat[newChar] = 0;
299                 tempChar[newColumn] = -1;
300                 newChar++;
301                 newColumn++;
302                 }
303
304             if (mp->coding & NOPRESENCESITES)
305                 {
306                 for (i=0; i<numLocalTaxa; i++)
307                     tempMatrix[pos(i,newColumn,newRowSize)] = 2;
308                 tempSitesOfPat[newChar] = 0;
309                 tempChar[newColumn] = -1;
310                 newChar++;
311                 newColumn++;
312                 }
313             }
314
315         /* add the normal characters */
316         numIncompatible = numIncompatibleChars = 0;
317         for (oldColumn=m->compMatrixStart; oldColumn<m->compMatrixStop; oldColumn++)
318             {
319             isCompat = YES;
320             /* first check if the character is supposed to be present */
321             if (m->numDummyChars > 0)
322                 {
323                 /* set up matrix struct */
324                 matrix.column = oldColumn;
325                 /* set up charinfo struct */
326                 cinfo.dType = mp->dataType;
327                 cinfo.cType = charInfo[origChar[oldChar]].ctype;
328                 cinfo.nStates = charInfo[origChar[oldChar]].numStates;
329                 CheckCharCodingType(&matrix, &cinfo);
330
331                 if (mp->coding & VARIABLE)
332                     {
333                     if((mp->coding & VARIABLE) == VARIABLE && cinfo.variable == NO)
334                         {
335                         isCompat = NO;
336                         }
337                     else if((mp->coding & NOABSENCESITES) && cinfo.constant[0] == YES)
338                         {
339                         isCompat = NO;
340                         }
341                     else if((mp->coding & NOPRESENCESITES) && cinfo.constant[1] == YES)
342                         {
343                         isCompat = NO;
344                         }
345                     }
346                 if (mp->coding & NOSINGLETONS)
347                     {
348                     if((mp->coding & NOSINGLETONS) == NOSINGLETONS && cinfo.informative == NO && cinfo.variable == YES)
349                         {
350                         isCompat = NO;
351                         }
352                     else if((mp->coding & NOSINGLETONABSENCE) && cinfo.singleton[0] == YES && cinfo.informative == NO)
353                         {
354                         isCompat = NO;
355                         }
356                     else if((mp->coding & NOSINGLETONPRESENCE) && cinfo.singleton[1] == YES && cinfo.informative == NO)
357                         {
358                         isCompat = NO;
359                         }
360                     }
361                 }
362
363             if (isCompat == NO)
364                 {
365                 numIncompatible++;
366                 numIncompatibleChars += (int) numSitesOfPat[oldChar];
367                 oldChar++;
368                 }
369             else
370                 {
371                 /* add character */
372                 for (i=0; i<numLocalTaxa; i++)
373                     tempMatrix[pos(i,newColumn,newRowSize)] = compMatrix[pos(i,oldColumn,oldRowSize)];
374                 /* set indices */
375                 compCharPos[origChar[oldColumn]] = newChar;
376                 compColPos[origChar[oldColumn]] = newColumn;
377                 tempSitesOfPat[newChar] = numSitesOfPat[oldChar];
378                 tempChar[newColumn] = origChar[oldColumn];
379                 newColumn++;
380                 if ((oldColumn-m->compMatrixStart+1) % m->nCharsPerSite == 0)
381                     {
382                     newChar++;
383                     oldChar++;
384                     }
385                 }
386             }
387
388         /* print a warning if there are incompatible characters */
389         if (numIncompatible > 0)
390             {
391             m->numChars -= numIncompatible;
392             m->numUncompressedChars -= numIncompatibleChars;
393             numDeleted += numIncompatible;
394             if (numIncompatibleChars > 1)
395                 {
396                 MrBayesPrint ("%s   WARNING: There are %d characters incompatible with the specified\n", spacer, numIncompatibleChars);
397                 MrBayesPrint ("%s            coding bias. These characters will be excluded.\n", spacer);
398                 }
399             else
400                 {
401                 MrBayesPrint ("%s   WARNING: There is one character incompatible with the specified\n", spacer);
402                 MrBayesPrint ("%s            coding bias. This character will be excluded.\n", spacer);
403                 }
404             }
405
406         /* update division comp matrix and comp char pointers */
407         m->compCharStop = newChar;
408         m->compMatrixStop = newColumn;
409         m->compCharStart = newChar - m->numChars;
410         m->compMatrixStart = newColumn - m->nCharsPerSite * m->numChars;
411
412         }   /* next division */
413
414     /* compress matrix if necessary */
415     if (numDeleted > 0)
416         {
417         for (i=k=0; i<numLocalTaxa; i++)
418             {
419             for (j=0; j<newRowSize-numDeleted; j++)
420                 {
421                 tempMatrix[k++] = tempMatrix[j+i*newRowSize];
422                 }
423             }
424         numCompressedChars -= numDeleted;
425         compMatrixRowSize -= numDeleted;
426         }
427
428     /* free old data, set pointers to new data */
429     free (compMatrix);
430     free (numSitesOfPat);
431     free (origChar);
432     
433     compMatrix = tempMatrix;
434     numSitesOfPat = tempSitesOfPat;
435     origChar = tempChar;
436     
437     tempMatrix = NULL;
438     tempSitesOfPat = NULL;
439     tempChar = NULL;
440     
441     /* print new compressed matrix */
442 #   if  defined (DEBUG_ADDDUMMYCHARS)
443     MrBayesPrint ("After adding dummy characters...\n");
444     PrintCompMatrix();
445 #   endif
446
447     return NO_ERROR;
448
449     errorExit:
450         if (tempMatrix)
451             free (tempMatrix);
452         if (tempSitesOfPat)
453             free (tempSitesOfPat);
454         if (tempChar)
455             free (tempChar);
456
457         return ERROR;   
458 }
459
460
461 /* Allocate space for cpp events */
462 void AllocateCppEvents (Param *p)
463 {
464     int     i;
465
466     p->nEvents = (int **) SafeCalloc (2*numGlobalChains, sizeof (int *));
467     p->nEvents[0] = (int *) SafeCalloc (2*numGlobalChains*(2*numLocalTaxa), sizeof (int));
468     for (i=1; i<2*numGlobalChains; i++)
469         p->nEvents[i] = p->nEvents[i-1] + (2*numLocalTaxa);
470     p->position = (MrBFlt ***) SafeCalloc (2*numGlobalChains, sizeof (MrBFlt **));
471     p->position[0] = (MrBFlt **) SafeCalloc (2*numGlobalChains*(2*numLocalTaxa), sizeof (MrBFlt *));
472     for (i=1; i<2*numGlobalChains; i++)
473         p->position[i] = p->position[i-1] + (2*numLocalTaxa);
474     p->rateMult = (MrBFlt ***) SafeCalloc (2*numGlobalChains, sizeof (MrBFlt **));
475     p->rateMult[0] = (MrBFlt **) SafeCalloc (2*numGlobalChains*(2*numLocalTaxa), sizeof (MrBFlt *));
476     for (i=1; i<2*numGlobalChains; i++)
477         p->rateMult[i] = p->rateMult[i-1] + (2*numLocalTaxa);
478
479 }
480
481
482 /*----------------------------------------------------------------------------
483 |
484 |   AllocateMove: Allocate space for and initialize one applicable move
485 |
486 -----------------------------------------------------------------------------*/
487 MCMCMove *AllocateMove (MoveType *moveType, Param *param)
488 {
489     int         i, j, nameLength;
490     char        *partitionDescriptor = "";
491     MCMCMove    *temp;
492
493     if ((temp = (MCMCMove *) SafeCalloc (1, sizeof (MCMCMove))) == NULL)
494         return (NULL);
495
496     /* calculate length */
497     if (strcmp (moveType->paramName, "") == 0)
498         nameLength = (int) (strlen (moveType->shortName) + strlen (param->name)) + 10;
499     else
500         {
501         partitionDescriptor = param->name;
502         while (*partitionDescriptor != '\0')
503             {
504             if (*partitionDescriptor == '{')
505                 break;
506             partitionDescriptor++;
507             }
508         nameLength = (int) (strlen (moveType->shortName) + strlen (moveType->paramName) + strlen (partitionDescriptor)) + 10;
509         }
510     /* add length of names of subparams */
511     if (moveType->subParams == YES)
512         {
513         for (i=0; i<param->nSubParams; i++)
514             nameLength += (int)(strlen(param->subParams[i]->name)) + 1;
515         }
516
517     if ((temp->name = (char *) SafeCalloc (nameLength, sizeof (char))) == NULL)
518         {
519         free (temp);
520         return NULL;
521         }
522
523     if ((temp->nAccepted = (int *) SafeCalloc (5*numGlobalChains, sizeof (int))) == NULL)
524         {
525         free (temp->name);
526         free (temp);
527         return NULL;
528         }
529     temp->nTried       = temp->nAccepted + numGlobalChains;
530     temp->nBatches     = temp->nAccepted + 2*numGlobalChains;
531     temp->nTotAccepted = temp->nAccepted + 3*numGlobalChains;
532     temp->nTotTried    = temp->nAccepted + 4*numGlobalChains; 
533     
534     if ((temp->relProposalProb = (MrBFlt *) SafeCalloc (4*numGlobalChains, sizeof (MrBFlt))) == NULL)
535         {
536         free (temp->nAccepted);
537         free (temp->name);
538         free (temp);
539         return NULL;
540         }
541     temp->cumProposalProb = temp->relProposalProb + numGlobalChains;
542     temp->targetRate = temp->relProposalProb + 2*numGlobalChains;
543     temp->lastAcceptanceRate = temp->relProposalProb + 3*numGlobalChains;
544
545     if ((temp->tuningParam = (MrBFlt **) SafeCalloc (numGlobalChains, sizeof (MrBFlt *))) == NULL)
546         {
547         free (temp->relProposalProb);
548         free (temp->nAccepted);
549         free (temp->name);
550         free (temp);
551         return NULL;
552         }
553     if ((temp->tuningParam[0] = (MrBFlt *) SafeCalloc (moveType->numTuningParams*numGlobalChains, sizeof (MrBFlt))) == NULL)
554         {
555         free (temp->tuningParam);
556         free (temp->relProposalProb);
557         free (temp->nAccepted);
558         free (temp->name);
559         free (temp);
560         return NULL;
561         }
562     for (i=1; i<numGlobalChains; i++)
563         temp->tuningParam[i] = temp->tuningParam[0] + (i * moveType->numTuningParams);
564
565     /* set default values */
566     if (strcmp(moveType->paramName, "") != 0)
567         sprintf (temp->name, "%s(%s%s)", moveType->shortName, moveType->paramName, partitionDescriptor);
568     else
569         {
570         sprintf (temp->name, "%s(%s", moveType->shortName, param->name);
571         if (moveType->subParams == YES)
572             {
573             for (i=0; i<param->nSubParams; i++)
574                 {
575                 strcat(temp->name,",");
576                 strcat(temp->name,param->subParams[i]->name);
577                 }
578             }
579         strcat (temp->name,")");
580         }
581         
582     temp->moveType = moveType;
583     temp->moveFxn = moveType->moveFxn;
584     for (i=0; i<numGlobalChains; i++)
585         {
586         temp->relProposalProb[i] = moveType->relProposalProb;
587         temp->cumProposalProb[i] = 0.0;
588         temp->nAccepted[i] = 0;
589         temp->nTried[i] = 0;
590         temp->nBatches[i] = 0;
591         temp->nTotAccepted[i] = 0;
592         temp->nTotTried[i] = 0;
593         temp->targetRate[i] = moveType->targetRate;
594         temp->lastAcceptanceRate[i] = 0.0;
595         for (j=0; j<moveType->numTuningParams; j++)
596             temp->tuningParam[i][j] = moveType->tuningParam[j];
597         }
598     return (temp);
599 }
600
601
602 /*----------------------------------------------------------------------
603 |
604 |   AllocateNormalParams: Allocate space for normal parameters
605 |
606 -----------------------------------------------------------------------*/
607 int AllocateNormalParams (void)
608 {
609     int         i, k, nOfParams, nOfIntParams;
610     Param       *p;
611     
612     /* Count the number of param values and subvalues */
613     nOfParams = 0;
614     nOfIntParams = 0;
615     for (k=0; k<numParams; k++)
616         {
617         nOfParams += params[k].nValues;
618         nOfParams += params[k].nSubValues;
619         nOfIntParams += params[k].nIntValues;
620         }
621
622     /* Set row size and find total number of values */
623     paramValsRowSize = nOfParams;
624     intValsRowSize = nOfIntParams;
625     nOfParams *= (2 * numGlobalChains);
626     nOfIntParams *= (2 * numGlobalChains);
627
628     if (memAllocs[ALLOC_PARAMVALUES] == YES)
629         {
630         paramValues = (MrBFlt *) SafeRealloc ((void *) paramValues, nOfParams * sizeof (MrBFlt));
631         for (i=0; i<nOfParams; i++)
632             paramValues[i] = 0.0;
633         if (nOfIntParams > 0)
634             intValues = (int *) SafeRealloc ((void *) intValues, nOfIntParams * sizeof(int));
635         }
636     else
637         {
638         paramValues = (MrBFlt *) SafeCalloc (nOfParams, sizeof(MrBFlt));
639         if (nOfIntParams > 0)
640             intValues = (int *) SafeCalloc (nOfIntParams, sizeof(int));
641         else
642             intValues = NULL;
643         }
644     if (!paramValues || (nOfIntParams > 0 && !intValues))
645         {
646         MrBayesPrint ("%s   Problem allocating paramValues\n", spacer);
647         if (paramValues)
648             free (paramValues);
649         if (intValues)
650             free (intValues);
651         return ERROR;
652         }
653     else
654         memAllocs[ALLOC_PARAMVALUES] = YES;
655
656     /* set pointers to values for chain 1 state 0            */
657     /* this scheme keeps the chain and state values together */
658     nOfParams = 0;
659     nOfIntParams = 0;
660     for (k=0; k<numParams; k++)
661         {
662         p = &params[k];
663         if (p->nValues > 0)
664             p->values = paramValues + nOfParams;
665         else
666             p->values = NULL;
667         nOfParams += p->nValues;
668         if (p->nSubValues > 0)
669             p->subValues = paramValues + nOfParams;
670         else
671             p->subValues = NULL;
672         nOfParams += p->nSubValues;
673         if (p->nIntValues > 0)
674             p->intValues = intValues + nOfIntParams;
675         else
676             p->intValues = NULL;
677         nOfIntParams += p->nIntValues;
678         }
679     
680     /* allocate space for cpp events */
681     for (k=0; k<numParams; k++)
682         {
683         p = &params[k];
684         if (p->paramType == P_CPPEVENTS)
685            AllocateCppEvents(p);
686         }
687
688     return (NO_ERROR);
689 }
690
691
692 /*----------------------------------------------------------------------
693 |
694 |   AllocateTreeParams: Allocate space for tree parameters
695 |
696 -----------------------------------------------------------------------*/
697 int AllocateTreeParams (void)
698 {
699     int         i, j, k, n, nOfParams, nOfTrees, isRooted, numSubParamPtrs;
700     Param       *p, *q;
701
702     /* Count the number of trees and dated trees */
703     /* based on branch length parameters */
704     /*  One tree is needed for each brlen parameter.
705         A topology may apply to several trees; a topology parameter
706         contains pointers to all trees it applies to */
707     numTrees = 0;
708     numTopologies = 0;
709     for (k=0; k<numParams; k++)
710         {
711         if (params[k].paramType == P_BRLENS)
712             numTrees++;
713         else if (params[k].paramType == P_TOPOLOGY)
714             numTopologies++;
715         }
716
717     /* We need to add the trees that do not have any branch lengths */
718     /* that is, the pure parsimony model trees, and the species trees */
719     for (k=0; k<numParams; k++)
720         {
721         if (params[k].paramType == P_TOPOLOGY)
722             {
723             if (!strcmp(modelParams[params[k].relParts[0]].parsModel, "Yes"))
724                 numTrees++;
725             }
726         else if (params[k].paramType == P_SPECIESTREE)
727             {
728             numTopologies++;
729             numTrees++;
730             }
731         }
732
733     /* Finally add subparam pointers for relaxed clock parameters and species trees */
734     numSubParamPtrs = 0;
735     for (k=0; k<numParams; k++)
736         {
737         if (params[k].paramType == P_TOPOLOGY && params[k].paramId == TOPOLOGY_SPECIESTREE)
738             numSubParamPtrs += 1;
739         else if (params[k].paramType == P_BRLENS)
740             numSubParamPtrs += 1;
741         else if (params[k].paramType == P_CPPEVENTS)
742             numSubParamPtrs += 3;
743         else if (params[k].paramType == P_TK02BRANCHRATES)
744             numSubParamPtrs += 2;
745         else if (params[k].paramType == P_IGRBRANCHRATES)
746             numSubParamPtrs += 2;
747         else if (params[k].paramType == P_MIXEDBRCHRATES)
748             numSubParamPtrs += 2;
749         }
750         
751     /* Allocate space for trees and subparam pointers */
752     if (memAllocs[ALLOC_MCMCTREES] == YES)
753         {
754         free (subParamPtrs);
755         free (mcmcTree);
756         subParamPtrs = NULL;
757         mcmcTree = NULL;
758         memAllocs[ALLOC_MCMCTREES] = NO;
759         }
760     subParamPtrs = (Param **) SafeCalloc (numSubParamPtrs, sizeof (Param *));
761     mcmcTree = (Tree **) SafeCalloc (numTrees * 2 * numGlobalChains, sizeof (Tree *));
762     if (!subParamPtrs || !mcmcTree)
763         {
764         if (subParamPtrs) free (subParamPtrs);
765         if (mcmcTree) free (mcmcTree);
766         subParamPtrs = NULL;
767         mcmcTree = NULL;
768         MrBayesPrint ("%s   Problem allocating mcmc trees\n", spacer);
769         return (ERROR);
770         }
771     else
772         memAllocs[ALLOC_MCMCTREES] = YES;
773
774     /* Initialize number of subparams, just in case */
775     for (k=0; k<numParams; k++)
776         params[k].nSubParams = 0;
777     
778     /* Count number of trees (brlens) for each topology or species tree */
779     for (k=0; k<numParams; k++)
780         {
781         p = &params[k];
782         if (params[k].paramType == P_BRLENS)
783             {
784             q = modelSettings[p->relParts[0]].topology;
785             q->nSubParams++;
786             if (p->printParam == YES)
787                 q->nPrintSubParams++;
788             }
789         else if (params[k].paramType == P_TOPOLOGY)
790             {
791             q = modelSettings[p->relParts[0]].speciesTree;
792             if (q != NULL)
793                 q->nSubParams++;
794             }
795         }
796
797     /* Make sure there is also one subparam for a parsimony tree */
798     for (k=0; k<numParams; k++)
799         if (params[k].paramType == P_TOPOLOGY)
800             {
801             p = &params[k];
802             if (p->nSubParams == 0)
803                 p->nSubParams = 1;
804             }
805
806     /* Count subparams for relaxed clock parameters */
807     for (k=0; k<numParams; k++)
808         {
809         p = &params[k];
810         if (p->paramType == P_CPPEVENTS)
811             {
812             q = modelSettings[p->relParts[0]].cppRate;
813             q->nSubParams++;
814             q = modelSettings[p->relParts[0]].cppMultDev;
815             q->nSubParams++;
816             q = modelSettings[p->relParts[0]].brlens;
817             q->nSubParams++;
818             }
819         else if (p->paramType == P_TK02BRANCHRATES)
820             {
821             q = modelSettings[p->relParts[0]].tk02var;
822             q->nSubParams++;
823             q = modelSettings[p->relParts[0]].brlens;
824             q->nSubParams++;
825             }
826         else if (p->paramType == P_IGRBRANCHRATES)
827             {
828             q = modelSettings[p->relParts[0]].igrvar;
829             q->nSubParams++;
830             q = modelSettings[p->relParts[0]].brlens;
831             q->nSubParams++;
832             }
833         else if (p->paramType == P_MIXEDBRCHRATES)
834             {
835             q = modelSettings[p->relParts[0]].mixedvar;
836             q->nSubParams++;
837             q = modelSettings[p->relParts[0]].brlens;
838             q->nSubParams++;
839             }
840         }
841
842     /* set pointers to subparams */
843     nOfParams = 0;
844     for (k=0; k<numParams; k++)
845         {
846         p = &params[k];
847         if (p->nSubParams > 0)
848             {
849             p->subParams = subParamPtrs + nOfParams;
850             nOfParams += p->nSubParams;
851             }
852         }
853     assert (nOfParams == numSubParamPtrs);
854
855     /* Set brlens param pointers and tree values */
856     /* the scheme below keeps trees for the same state and chain together */
857     nOfTrees = 0;
858     for (k=0; k<numParams; k++)
859         {
860         p = &params[k];
861         if ((p->paramType == P_BRLENS) ||
862             (p->paramType == P_TOPOLOGY && p->paramId == TOPOLOGY_PARSIMONY_UNIFORM) ||
863             (p->paramType == P_TOPOLOGY && p->paramId == TOPOLOGY_PARSIMONY_CONSTRAINED) ||
864             (p->paramType == P_SPECIESTREE))
865             {
866             /* allocate space for trees and initialize trees */
867             p->treeIndex = nOfTrees;
868             p->tree = mcmcTree + nOfTrees;
869             nOfTrees++;
870             }
871         }
872
873     /* Set topology params and associated brlen subparams */
874     for (k=0; k<numParams; k++)
875         {
876         p = &params[k];
877         if (p->paramType == P_TOPOLOGY)
878             {
879             if (p->paramId == TOPOLOGY_PARSIMONY_UNIFORM ||
880                 p->paramId == TOPOLOGY_PARSIMONY_CONSTRAINED)
881                 /* pure parsimony topology case */
882                 {
883                 /* there is no brlen subparam */
884                 /* so let subparam point to the param itself */
885                 q = p->subParams[0] = p;
886                 /* p->tree and p->treeIndex have been set above */
887                 }
888             else
889                 {
890                 /* first set brlens pointers for any parsimony partitions */
891                 for (i=j=0; i<p->nRelParts; i++)
892                     {
893                     if (modelSettings[p->relParts[i]].parsModelId == YES)
894                         {
895                         modelSettings[p->relParts[i]].brlens = p;
896                         }
897                     }
898
899                 /* now proceed with pointer assignment */
900                 q = modelSettings[p->relParts[0]].brlens;
901                 n = 0;  /* number of stored subParams */
902                 i = 0;  /* relevant partition number  */
903                 while (i < p->nRelParts)
904                     {
905                     for (j=0; j<n; j++)
906                         if (q == p->subParams[j])
907                             break;
908                     
909                     if (j == n && q != p)   /* a new tree (brlens) for this topology */
910                         {
911                         p->subParams[n++] = q;
912                         }
913                     q = modelSettings[p->relParts[++i]].brlens;
914                     }
915                 
916                 p->tree = p->subParams[0]->tree;
917                 p->treeIndex = p->subParams[0]->treeIndex;
918                 }
919             }
920         else if (p->paramType == P_SPECIESTREE)
921             {
922             /* now proceed with pointer assignment */
923             q = modelSettings[p->relParts[0]].topology;
924             n = 0;  /* number of stored subParams */
925             i = 0;  /* relevant partition number  */
926             while (i < p->nRelParts)
927                 {
928                 for (j=0; j<n; j++)
929                     if (q == p->subParams[j])
930                         break;
931
932                 if (j == n && q != p)   /* a new topology for this species tree */
933                     {
934                     p->subParams[n++] = q;
935                     }
936                 q = modelSettings[p->relParts[++i]].topology;
937                 }
938             }
939         }
940
941     /* Check for constraints */
942     for (k=0; k<numParams; k++)
943         {
944         p = &params[k];
945         if (p->paramType == P_TOPOLOGY)
946             {
947             if (!strcmp(modelParams[p->relParts[0]].topologyPr, "Constraints"))
948                 {
949                 for (i=0; i<p->nSubParams; i++)
950                     {
951                     q = p->subParams[i];
952                     q->checkConstraints = YES;
953                     }
954                 }
955             else
956                 {
957                 for (i=0; i<p->nSubParams; i++)
958                     {
959                     q = p->subParams[i];
960                     q->checkConstraints = NO;
961                     }
962                 }
963             }
964         }
965
966     /* update paramId */
967     for (k=0; k<numParams; k++)
968         {
969         p = &params[k];
970         if (p->paramType == P_TOPOLOGY)
971             {
972             if (p->nSubParams > 1)
973                 {
974                 if (p->paramId == TOPOLOGY_NCL_UNIFORM_HOMO)
975                     p->paramId = TOPOLOGY_NCL_UNIFORM_HETERO;
976                 else if (p->paramId == TOPOLOGY_NCL_CONSTRAINED_HOMO)
977                     p->paramId = TOPOLOGY_NCL_CONSTRAINED_HETERO;
978                 else if (p->paramId == TOPOLOGY_NCL_FIXED_HOMO)
979                     p->paramId = TOPOLOGY_NCL_FIXED_HETERO;
980                 else
981                     {
982                     MrBayesPrint ("%s   A clock tree cannot have more than one set of branch lengths\n", spacer);
983                     printf ("nparam:%d paramid:%d",p->nSubParams,p->paramId);
984                     return (ERROR);
985                     }
986                 }
987             }
988         }
989
990     /* finally initialize trees */
991     for (k=0; k<numParams; k++)
992         {
993         p = &params[k];
994         if (p->paramType == P_BRLENS)
995             {
996             /* find type of tree */
997             if (!strcmp(modelParams[p->relParts[0]].brlensPr,"Clock"))
998                 isRooted = YES;
999             else
1000                 isRooted = NO;
1001
1002             if (InitializeChainTrees (p, 0, numGlobalChains, isRooted) == ERROR)
1003                 return (ERROR);
1004             }
1005         else if (p->paramType == P_SPECIESTREE)
1006             {
1007             if (InitializeChainTrees (p, 0, numGlobalChains, YES) == ERROR)
1008                 return (ERROR);
1009             }
1010         }
1011
1012     /* now initialize subparam pointers for relaxed clock models */
1013     /* use nSubParams to point to the next available subParam by first
1014        resetting all nSubParams to 0 */
1015     for (k=0; k<numParams; k++)
1016         {
1017         p = &params[k];
1018         if (p->paramType == P_CPPRATE ||
1019             p->paramType == P_CPPMULTDEV ||
1020             p->paramType == P_BRLENS ||
1021             p->paramType == P_TK02VAR ||
1022             p->paramType == P_IGRVAR ||
1023             p->paramType == P_MIXEDVAR)
1024             p->nSubParams = 0;
1025         }
1026     for (k=0; k<numParams; k++)
1027         {
1028         p = &params[k];
1029         if (p->paramType == P_CPPEVENTS)
1030             {
1031             q = modelSettings[p->relParts[0]].cppRate;
1032             q->subParams[q->nSubParams++] = p;
1033             q = modelSettings[p->relParts[0]].cppMultDev;
1034             q->subParams[q->nSubParams++] = p;
1035             q = modelSettings[p->relParts[0]].brlens;
1036             q->subParams[q->nSubParams++] = p;
1037             p->treeIndex = q->treeIndex;
1038             p->tree = q->tree;
1039             if (p->printParam == YES)
1040                 q->nPrintSubParams++;
1041             }
1042         else if (p->paramType == P_TK02BRANCHRATES)
1043             {
1044             q = modelSettings[p->relParts[0]].tk02var;
1045             q->subParams[q->nSubParams++] = p;
1046             q = modelSettings[p->relParts[0]].brlens;
1047             q->subParams[q->nSubParams++] = p;
1048             p->treeIndex = q->treeIndex;
1049             p->tree = q->tree;
1050             if (p->printParam == YES)
1051                 q->nPrintSubParams++;
1052             }
1053         else if (p->paramType == P_IGRBRANCHRATES)
1054             {
1055             q = modelSettings[p->relParts[0]].igrvar;
1056             q->subParams[q->nSubParams++] = p;
1057             q = modelSettings[p->relParts[0]].brlens;
1058             q->subParams[q->nSubParams++] = p;
1059             p->treeIndex = q->treeIndex;
1060             p->tree = q->tree;
1061             if (p->printParam == YES)
1062                 q->nPrintSubParams++;
1063             }
1064         else if (p->paramType == P_MIXEDBRCHRATES)
1065             {
1066             q = modelSettings[p->relParts[0]].mixedvar;
1067             q->subParams[q->nSubParams++] = p;
1068             q = modelSettings[p->relParts[0]].brlens;
1069             q->subParams[q->nSubParams++] = p;
1070             p->treeIndex = q->treeIndex;
1071             p->tree = q->tree;
1072             if (p->printParam == YES)
1073                 q->nPrintSubParams++;
1074             }
1075         }
1076
1077     return (NO_ERROR);
1078 }
1079
1080
1081 int AreDoublesEqual (MrBFlt x, MrBFlt y, MrBFlt tol)
1082 {
1083     if ((x - y) < -tol || (x - y) > tol)
1084         return (NO);
1085     else
1086         return (YES);
1087 }
1088
1089
1090 int ChangeNumChains (int from, int to)
1091 {
1092     int         i, i1, j, k, m, st, nRuns, fromIndex, toIndex, run, chn, *tempIntVals, nCppEventParams, *toEvents, *fromEvents;
1093     MCMCMove    **tempMoves, *fromMove, *toMove;
1094     Tree        **tempTrees;
1095     MrBFlt      *tempVals, **toRateMult, **toPosition, **fromRateMult, **fromPosition, *stdStateFreqsOld;
1096     Param       *p, *q, *cppEventParams = NULL;
1097     Tree        **oldMcmcTree, *tree;
1098
1099     if (from == to)
1100         return (NO_ERROR);
1101
1102     /* set new number of chains */
1103     chainParams.numChains = to;
1104     nRuns = chainParams.numRuns;
1105     numGlobalChains = chainParams.numRuns * chainParams.numChains;
1106
1107     /* Do the normal parameters */  
1108     /* first save old values */
1109     tempVals = paramValues;
1110     paramValues = NULL;
1111     tempIntVals = intValues;
1112     intValues = NULL;
1113     memAllocs[ALLOC_PARAMS] = NO;
1114     /* .. and old cpp events parameters */
1115     nCppEventParams = 0;
1116     for (i=0; i<numParams; i++)
1117         {
1118         p = &params[i];
1119         if (p->paramType == P_CPPEVENTS)
1120             nCppEventParams++;
1121         }
1122     cppEventParams = (Param *) SafeCalloc (nCppEventParams, sizeof(Param));
1123     for (i=0; i<nCppEventParams; i++)
1124         {
1125         cppEventParams[i].paramType = P_CPPEVENTS;
1126         AllocateCppEvents (&cppEventParams[i]);
1127         }
1128     for (i=j=0; i<numParams; i++)
1129         {
1130         p = &params[i];
1131         if (p->paramType == P_CPPEVENTS)
1132             {
1133             cppEventParams[j].nEvents = p->nEvents;
1134             p->nEvents = NULL;
1135             cppEventParams[j].position = p->position;
1136             p->position = NULL;
1137             cppEventParams[j].rateMult = p->rateMult;
1138             p->rateMult = NULL;
1139             j++;
1140             }
1141         }
1142     if (AllocateNormalParams () == ERROR)
1143         return (ERROR);
1144
1145     /* then fill all params */
1146     FillNormalParams (&globalSeed, 0, numGlobalChains);
1147     
1148     /* finally overwrite with old values if present */
1149     for (run=0; run<nRuns; run++)
1150         {
1151         for (chn=0; chn<from; chn++)
1152             {
1153             if (chn < to)
1154                 {
1155                 fromIndex = (run*from + chn)*2*paramValsRowSize;
1156                 toIndex = (run*to + chn)*2*paramValsRowSize;
1157                 for (i=0; i<2*paramValsRowSize; i++)
1158                     paramValues[toIndex++] = tempVals[fromIndex++];
1159                 fromIndex = (run*from + chn)*2*intValsRowSize;
1160                 toIndex = (run*to + chn)*2*intValsRowSize;
1161                 for (i=0; i<2*intValsRowSize; i++)
1162                     intValues[toIndex++] = tempIntVals[fromIndex++];
1163                 for (i=i1=0; i<numParams; i++)
1164                     {
1165                     p = &params[i];
1166                     if (p->paramType == P_CPPEVENTS)
1167                         {
1168                         fromIndex = 2*(run*from + chn);
1169                         toIndex = 2*(run*to + chn);
1170                         fromEvents = cppEventParams[i1].nEvents[fromIndex];
1171                         toEvents = p->nEvents[toIndex];
1172                         fromPosition = cppEventParams[i1].position[fromIndex];
1173                         toPosition = p->position[toIndex];
1174                         fromRateMult = cppEventParams[i1].rateMult[fromIndex];
1175                         toRateMult = p->rateMult[toIndex];
1176                         for (j=0; j<2*numLocalTaxa; j++)
1177                             {
1178                             toEvents[j] = fromEvents[j];
1179                             toPosition[j] = (MrBFlt *) SafeRealloc ((void *)toPosition[j], toEvents[j]*sizeof(MrBFlt));
1180                             toRateMult[j] = (MrBFlt *) SafeRealloc ((void *)toRateMult[j], toEvents[j]*sizeof(MrBFlt));
1181                             for (k=0; k<toEvents[j]; k++)
1182                                 {
1183                                 toPosition[j][k] = fromPosition[j][k];
1184                                 toRateMult[j][k] = fromRateMult[j][k];
1185                                 }
1186                             }
1187                         i1++;
1188                         }
1189                     }
1190                 assert (nCppEventParams==i1);
1191                 }
1192             }
1193         }
1194     
1195     /* and free up space */
1196     free (tempVals);
1197     if (intValsRowSize > 0)
1198         free (tempIntVals);
1199     for (i=0; i<nCppEventParams; i++)
1200         {
1201         numGlobalChains = chainParams.numRuns * from; /* Revert to the old value to clean old Cpp events in FreeCppEvents() */
1202         FreeCppEvents(&cppEventParams[i]);
1203         numGlobalChains = chainParams.numRuns * chainParams.numChains; /*Set to proper value again*/
1204         }
1205     if (nCppEventParams > 0)
1206         free (cppEventParams);
1207
1208     /* then do the trees (they cannot be done before the parameters because otherwise FillTreeParams will overwrite
1209        relaxed clock parameters that need to be saved) */
1210
1211     /* reallocate trees */
1212     tempTrees = (Tree **) SafeCalloc (2*nRuns*from*numTrees, sizeof(Tree *));
1213     for (i=0; i<2*nRuns*from*numTrees; i++)
1214         tempTrees[i] = mcmcTree[i];
1215     oldMcmcTree = mcmcTree;
1216     mcmcTree = (Tree **) SafeRealloc ((void *)(mcmcTree), 2 * (size_t)numGlobalChains * (size_t)numTrees * sizeof(Tree*));
1217     for (i=0; i<2*nRuns*to*numTrees; i++)
1218         mcmcTree[i] = NULL;
1219
1220     /* move the old trees over */
1221     for (run=0; run<nRuns; run++)
1222         {
1223         for (chn=0; chn<from; chn++)
1224             {
1225             if (chn >= to)
1226                 continue;
1227             /*Here we move only one tree per chain/state?! Should not we move numTrees??*/
1228             fromIndex = 2*(run*from + chn)  * numTrees;
1229             toIndex   = 2*(run*to   + chn)  * numTrees;
1230             for (k=0;k<2*numTrees;k++)
1231                 {
1232                 mcmcTree[toIndex+k]    = tempTrees[fromIndex+k];
1233                 tempTrees[fromIndex+k] = NULL;
1234                 }
1235             }
1236         }
1237
1238     /* remove any remaining old trees */
1239     for (i=0; i<2*nRuns*from*numTrees; i++)
1240         if (tempTrees[i] != NULL)
1241             FreeTree (tempTrees[i]);
1242     free (tempTrees);
1243
1244     /* now fill in the tree parameters */
1245     for (i=0; i<numParams; i++)
1246         {
1247         p = &params[i];
1248         if (p->paramType == P_TOPOLOGY)
1249             {
1250             p->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1251             for (j=0; j<p->nSubParams; j++)
1252                 {
1253                 q = p->subParams[j];
1254                 assert (q->paramType==P_BRLENS);
1255                 q->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1256                 if (to > from)
1257                     for (run=0; run<nRuns; run++)
1258                         {
1259                         /*rename old trees because each run has more chains*/
1260                         for (m=0; m<from; m++)
1261                             {
1262                             for (st=0; st<2; st++)
1263                                 {
1264                                 tree = GetTree (q,run*to + m, st);
1265                                 if (numTrees > 1)
1266                                     sprintf (tree->name, "mcmc.tree%d_%d", p->treeIndex+1, run*to + m +1);
1267                                 else /* if (numTrees == 1) */
1268                                     sprintf (tree->name, "mcmc.tree_%d", run*to + m +1);
1269                                 }
1270                             }
1271                         InitializeChainTrees (q, run*to + from, run*to + to , GetTree (q, 0, 0)->isRooted);
1272                         }
1273                 }
1274             }
1275         else if (p->paramType == P_CPPEVENTS || p->paramType == P_TK02BRANCHRATES || p->paramType == P_IGRBRANCHRATES || p->paramType == P_MIXEDBRCHRATES)
1276             p->tree += (mcmcTree - oldMcmcTree);
1277         else
1278             assert (p->paramType==P_BRLENS || p->tree==NULL);
1279         }
1280
1281     
1282     /* fill new tree parameters */
1283     if (to > from)
1284         {
1285         for (run=0; run<nRuns; run++)
1286             {
1287             for (chn=from; chn<to; chn++)
1288                 {
1289                 toIndex = run*to + chn;
1290                 FillTreeParams (&globalSeed, toIndex, toIndex+1);
1291                 }
1292             }
1293         }
1294
1295     /* fix stationary frequencies for standard data */
1296     if   (stdStateFreqsRowSize > 0)
1297         {
1298         assert (memAllocs[ALLOC_STDSTATEFREQS] == YES);
1299         stdStateFreqsOld=stdStateFreqs;
1300         stdStateFreqs = (MrBFlt *) SafeMalloc (2 * (size_t)stdStateFreqsRowSize * (size_t)numGlobalChains * sizeof (MrBFlt));
1301         if (!stdStateFreqs)
1302             {
1303             MrBayesPrint ("%s   Problem reallocating stdStateFreqs\n", spacer);
1304             return (ERROR);
1305             }
1306
1307         /* set pointers */
1308         for (k=0; k<numParams; k++)
1309             {
1310             p = &params[k];
1311             if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
1312                 continue;
1313             p->stdStateFreqs += stdStateFreqs-stdStateFreqsOld;
1314             }
1315         
1316         for (run=0; run<nRuns; run++)
1317             {
1318             /* copy old chains values*/
1319             for (chn=0; chn<from; chn++)
1320                 {
1321                 if (chn >= to)
1322                     break;
1323
1324                 fromIndex = 2*(run*from + chn)*stdStateFreqsRowSize;
1325                 toIndex = 2*(run*to + chn)*stdStateFreqsRowSize;
1326                 for (k=0;k<2*stdStateFreqsRowSize;k++)
1327                     {
1328                     stdStateFreqs[toIndex+k]=stdStateFreqsOld[fromIndex+k];
1329                     }
1330                 }
1331             /* set new chains */
1332             FillStdStateFreqs (run*to+from, run*to+to, &globalSeed);
1333             }
1334         free(stdStateFreqsOld);
1335     }
1336
1337     /* Do the moves */
1338     /* first allocate space and set up default moves */
1339     tempMoves = moves;
1340     moves = NULL;
1341     memAllocs[ALLOC_MOVES] = NO;
1342     SetMoves ();
1343     
1344     /* then overwrite with old values if present */
1345     for (i=0; i<numApplicableMoves; i++)
1346         {
1347         toMove = moves[i];
1348         fromMove = tempMoves[i];
1349         for (run=0; run<nRuns; run++)
1350             {
1351             for (chn=0; chn<from; chn++)
1352                 {
1353                 if (chn < to)
1354                     {
1355                     fromIndex = run*from + chn;
1356                     toIndex = run*to + chn;
1357                     toMove->relProposalProb[toIndex] = fromMove->relProposalProb[fromIndex];
1358                     for (j=0; j<toMove->moveType->numTuningParams; j++)
1359                         {
1360                         toMove->tuningParam[toIndex][j] = fromMove->tuningParam[fromIndex][j];
1361                         }
1362                     }
1363                 }
1364             }
1365         }
1366     
1367     /* and free up space */
1368     for (i=0; i<numApplicableMoves; i++)
1369         FreeMove (tempMoves[i]);
1370     free (tempMoves);
1371     
1372     return (NO_ERROR);
1373 }
1374
1375
1376 int ChangeNumRuns (int from, int to)
1377 {
1378     int         i, i1, j, k, n, nChains;
1379     Param       *p, *q;
1380     MoveType    *mvt;
1381     Tree        **oldMcmcTree;
1382     MrBFlt      *oldParamValues;
1383     MrBFlt      *stdStateFreqsOld;
1384     int         *oldintValues;
1385
1386     if (from == to)
1387         return (NO_ERROR);
1388
1389 #if 0
1390     for (i=0; i<numParams; i++)
1391         {
1392         p = &params[i];
1393         if (p->paramType == P_CPPEVENTS)
1394             {
1395             printf ("Trees before changing number of runs\n");
1396             for (j=0; j<numGlobalChains; j++)
1397                 {
1398                 printf ("Event tree for chain %d\n", j+1);
1399                 for (k=0; k<2*numLocalTaxa; k++)
1400                     {
1401                     printf ("%d -- %d:", k, p->nEvents[2*j][k]);
1402                     for (i1=0; i1<p->nEvents[2*j][k]; i1++)
1403                         {
1404                         if (i1 == 0)
1405                             printf (" (%lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1406                         else if (i1 == p->nEvents[2*j][k]-1)
1407                             printf (" %lf %lf)", p->position[2*j][k], p->rateMult[2*j][k]);
1408                         else
1409                             printf (" %lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1410                         }
1411                     printf ("\n");
1412                     }
1413                 for (k=0; k<2*numLocalTaxa; k++)
1414                     {
1415                     printf ("%d -- %d:", k, p->nEvents[2*j][k]);
1416                     for (i1=0; i1<p->nEvents[2*j+1][k]; i1++)
1417                         {
1418                         if (i1 == 0)
1419                             printf (" (%lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1420                         else if (i1 == p->nEvents[2*j][k]-1)
1421                             printf (" %lf %lf)", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1422                         else
1423                             printf (" %lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1424                         }
1425                     printf ("\n");
1426                     }
1427                 }
1428             }
1429         }
1430 #endif
1431
1432     /* set new number of runs */
1433     chainParams.numRuns = to;
1434     nChains = chainParams.numChains;
1435     numGlobalChains = chainParams.numRuns * chainParams.numChains;
1436
1437     /* do the trees, free tree's memory if we reduce number of trees. */
1438     for (i=to*2*nChains*numTrees; i<from*2*nChains*numTrees; i++)
1439         {
1440         FreeTree (mcmcTree[i]);
1441         }
1442     oldMcmcTree = mcmcTree;
1443     mcmcTree = (Tree **) SafeRealloc ((void *) mcmcTree, numTrees * 2 * numGlobalChains * sizeof (Tree *));
1444     if (mcmcTree == NULL)
1445         {
1446         memAllocs[ALLOC_MCMCTREES] = NO;
1447         MrBayesPrint ("%s   Problem reallocating mcmcTree\n", spacer);
1448         return (ERROR);
1449         }
1450
1451     for (i=from*2*nChains*numTrees; i<to*2*nChains*numTrees; i++)
1452         {
1453         mcmcTree[i]=NULL;
1454         }  
1455     /* then the cppevents parameters */
1456     for (i1=0; i1<numParams; i1++)
1457         {
1458         p = &params[i1];
1459         if (p->paramType == P_CPPEVENTS)
1460             {
1461             p->nEvents = (int **) SafeRealloc ((void *)p->nEvents, 2*numGlobalChains*sizeof (int *));
1462             p->nEvents[0] = (int *) SafeRealloc ((void *)p->nEvents[0], 2*numGlobalChains*(2*numLocalTaxa)*sizeof (int));
1463             for (i=1; i<2*numGlobalChains; i++)
1464                 p->nEvents[i] = p->nEvents[i-1] + (2*numLocalTaxa);
1465             if (from > to)
1466                 {
1467                 for (j=numGlobalChains; j<from*nChains; j++)
1468                     {
1469                     for (k=0; k<2*numLocalTaxa; k++)
1470                         {
1471                         free (p->position[2*j+0][k]);
1472                         p->position[2*j+0][k] = NULL;
1473                         free (p->rateMult[2*j+0][k]);
1474                         p->rateMult[2*j+0][k] = NULL;
1475                         }
1476                     }
1477                 }
1478             p->position = (MrBFlt ***) SafeRealloc ((void *)p->position, 2*numGlobalChains*sizeof (MrBFlt **));
1479             p->position[0] = (MrBFlt **) SafeRealloc ((void *)p->position[0], 2*numGlobalChains*(2*numLocalTaxa)*sizeof (MrBFlt *));
1480             for (i=1; i<2*numGlobalChains; i++)
1481                 p->position[i] = p->position[i-1] + (2*numLocalTaxa);
1482             p->rateMult = (MrBFlt ***) SafeRealloc ((void *)p->rateMult, 2*numGlobalChains*sizeof (MrBFlt **));
1483             p->rateMult[0] = (MrBFlt **) SafeRealloc ((void *)p->rateMult[0], 2*numGlobalChains*(2*numLocalTaxa)*sizeof (MrBFlt *));
1484             for (i=1; i<2*numGlobalChains; i++)
1485                 p->rateMult[i] = p->rateMult[i-1] + (2*numLocalTaxa);
1486             if (to > from)
1487                 {
1488                 for (j=from*nChains; j<numGlobalChains; j++)
1489                     {
1490                     for (k=0; k<2*numLocalTaxa; k++)
1491                         {
1492                         p->nEvents[2*j+0][k] = 0;
1493                         p->position[2*j+0][k] = NULL;
1494                         p->rateMult[2*j+0][k] = NULL;
1495                         p->nEvents[2*j+1][k] = 0;
1496                         p->position[2*j+1][k] = NULL;
1497                         p->rateMult[2*j+1][k] = NULL;
1498                         }
1499                     }
1500                 }
1501             }
1502         }
1503     /* and finally the normal parameters */
1504     oldParamValues = paramValues;
1505     paramValues = (MrBFlt *) SafeRealloc ((void *) paramValues, paramValsRowSize * 2 * numGlobalChains * sizeof (MrBFlt));
1506     oldintValues = intValues;
1507     intValues = (int *) SafeRealloc ((void *) intValues, intValsRowSize * 2 * numGlobalChains * sizeof (int));
1508     if (paramValues == NULL)
1509         {
1510         memAllocs[ALLOC_PARAMVALUES] = NO;
1511         MrBayesPrint ("%s   Problem reallocating paramValues\n", spacer);
1512         return (ERROR);
1513         }
1514     for (i=0; i<numParams; i++)
1515         {
1516         params[i].values += (paramValues - oldParamValues);
1517         params[i].subValues += (paramValues - oldParamValues);
1518         params[i].intValues += (intValues - oldintValues);
1519         }
1520
1521     /* fill new chains paramiters with appropriate values */
1522     if (to > from)
1523         FillNormalParams (&globalSeed, from*nChains, to*nChains);
1524
1525     /* now fill in the tree parameters */
1526     for (i=0; i<numParams; i++)
1527         {
1528         p = &params[i];
1529         if (p->paramType == P_TOPOLOGY)
1530             {
1531             p->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1532             for (j=0; j<p->nSubParams; j++)
1533                 {
1534                 q = p->subParams[j];
1535                 assert (q->paramType==P_BRLENS);
1536                 q->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1537                 InitializeChainTrees (q, from*nChains, to*nChains, GetTree (q, 0, 0)->isRooted);
1538                 }
1539             }
1540         else if (p->paramType == P_CPPEVENTS || p->paramType == P_TK02BRANCHRATES || p->paramType == P_IGRBRANCHRATES || p->paramType == P_MIXEDBRCHRATES)
1541             p->tree += (mcmcTree - oldMcmcTree);
1542         }
1543
1544     FillTreeParams (&globalSeed, from*nChains, to*nChains);
1545
1546     /* fix stationary frequencies for standard data */
1547     if (stdStateFreqsRowSize > 0)
1548         {
1549         assert (memAllocs[ALLOC_STDSTATEFREQS] == YES);
1550         stdStateFreqsOld=stdStateFreqs;
1551         stdStateFreqs = (MrBFlt *) SafeRealloc ((void *) stdStateFreqs, stdStateFreqsRowSize * 2 * numGlobalChains * sizeof (MrBFlt));
1552         if (!stdStateFreqs)
1553             {
1554             MrBayesPrint ("%s   Problem reallocating stdStateFreqs\n", spacer);
1555             return (ERROR);
1556             }
1557         
1558         /* set pointers */
1559         for (k=n=0; k<numParams; k++)
1560             {
1561             p = &params[k];
1562             if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
1563                 continue;
1564             p->stdStateFreqs += stdStateFreqs-stdStateFreqsOld;
1565             }
1566         
1567         FillStdStateFreqs (from*nChains, to*nChains, &globalSeed);
1568         }
1569
1570     /* do the moves */
1571     for (i=0; i<numApplicableMoves; i++)
1572         {
1573         mvt = moves[i]->moveType;
1574         moves[i]->tuningParam = (MrBFlt **) SafeRealloc ((void *) moves[i]->tuningParam, (size_t)numGlobalChains * sizeof (MrBFlt *));
1575         moves[i]->tuningParam[0] = (MrBFlt *) SafeRealloc ((void *) moves[i]->tuningParam[0], (size_t)numGlobalChains * (size_t)(mvt->numTuningParams) * sizeof (MrBFlt));
1576         for (j=1; j<numGlobalChains; j++)
1577             moves[i]->tuningParam[j] = moves[i]->tuningParam[0] + j * mvt->numTuningParams;
1578         moves[i]->relProposalProb = (MrBFlt *) SafeRealloc ((void *) moves[i]->relProposalProb, 4 * (size_t)numGlobalChains * sizeof (MrBFlt));
1579         moves[i]->cumProposalProb = moves[i]->relProposalProb + numGlobalChains;
1580         moves[i]->targetRate = moves[i]->relProposalProb + 2*numGlobalChains;
1581         moves[i]->lastAcceptanceRate = moves[i]->relProposalProb + 3*numGlobalChains;
1582         moves[i]->nAccepted = (int *) SafeRealloc ((void *) moves[i]->nAccepted, 5* (size_t)numGlobalChains * sizeof (int));
1583         moves[i]->nTried = moves[i]->nAccepted + numGlobalChains;
1584         moves[i]->nBatches = moves[i]->nAccepted + 2*numGlobalChains;
1585         moves[i]->nTotAccepted = moves[i]->nAccepted + 3*numGlobalChains;
1586         moves[i]->nTotTried    = moves[i]->nAccepted + 4*numGlobalChains;
1587         /* initialize all values to default */
1588         for (j=0; j<numGlobalChains; j++)
1589             {
1590             moves[i]->nAccepted[j] = 0;
1591             moves[i]->nTried[j] = 0;
1592             moves[i]->nBatches[j] = 0;
1593             moves[i]->nTotAccepted[j] = 0;
1594             moves[i]->nTotTried[j] = 0;
1595             moves[i]->relProposalProb[j] = mvt->relProposalProb;
1596             moves[i]->cumProposalProb[j] = 0.0;
1597             moves[i]->lastAcceptanceRate[j] = 0.0;
1598             for (k=0; k<mvt->numTuningParams; k++)
1599                 moves[i]->tuningParam[j][k] = mvt->tuningParam[k];
1600             moves[i]->targetRate[j] = mvt->targetRate;
1601             }
1602         }
1603
1604 #if 0
1605     for (i=0; i<numParams; i++)
1606         {
1607         p = &params[i];
1608         if (p->paramType == P_CPPEVENTS)
1609             {
1610             printf ("Trees after changing number of runs\n");
1611             for (j=0; j<numGlobalChains; j++)
1612                 {
1613                 printf ("Event tree for chain %d\n", j+1);
1614                 for (k=0; k<2*numLocalTaxa; k++)
1615                     {
1616                     printf ("%d -- %d:", k, p->nEvents[2*j][k]);
1617                     assert (p->nEvents[2*j] >= 0);
1618                     for (i1=0; i1<p->nEvents[2*j][k]; i1++)
1619                         {
1620                         if (i1 == 0)
1621                             printf (" (%lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1622                         else if (i1 == p->nEvents[2*j][k]-1)
1623                             printf (" %lf %lf)", p->position[2*j][k], p->rateMult[2*j][k]);
1624                         else
1625                             printf (" %lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1626                         }
1627                     printf ("\n");
1628                     }
1629                 for (k=0; k<2*numLocalTaxa; k++)
1630                     {
1631                     printf ("%d -- %d:", k, p->nEvents[2*j+1][k]);
1632                     assert (p->nEvents[2*j+1] >= 0);
1633                     for (i1=0; i1<p->nEvents[2*j+1][k]; i1++)
1634                         {
1635                         if (i1 == 0)
1636                             printf (" (%lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1637                         else if (i1 == p->nEvents[2*j][k]-1)
1638                             printf (" %lf %lf)", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1639                         else
1640                             printf (" %lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1641                         }
1642                     printf ("\n");
1643                     }
1644                 }
1645             }
1646         }
1647 #endif
1648
1649     return (NO_ERROR);
1650 }
1651
1652
1653 /*-----------------------------------------------------------
1654 |
1655 |   CheckCharCodingType: check if character is parsimony-
1656 |       informative, variable, or constant
1657 |
1658 -----------------------------------------------------------*/
1659 void CheckCharCodingType (Matrix *m, CharInfo *ci)
1660 {
1661     int         i, j, k, x, n1[10], n2[10], largest, smallest, numPartAmbig,
1662                 numConsidered, numInformative, lastInformative=0, uniqueBits,
1663                 newPoss, oldPoss;
1664     BitsLong    combinations[2048], *tempComb, *newComb, *oldComb, bitsLongOne=1;
1665
1666     /* set up comb pointers */
1667     oldComb = combinations;
1668     newComb = oldComb + 1024;
1669
1670     /* set counters to 0 */
1671     numPartAmbig = numConsidered = 0;
1672
1673     /* set variable and informative to yes */
1674     ci->variable = ci->informative = YES;
1675
1676     /* set constant to no and state counters to 0 for all states */
1677     for (i=0; i<10; i++)
1678         {
1679         ci->constant[i] = ci->singleton[i] = NO;
1680         n1[i] = n2[i] = 0;
1681         }
1682
1683     for (i=0; i<m->nRows; i++)
1684         {
1685         /* retrieve character */
1686         x = (int) m->origin[m->column + i*m->rowSize];
1687
1688         /* add it to counters if not all ambiguous */
1689         if (NBits(x) < ci->nStates)
1690             {
1691             numConsidered++;
1692             if (NBits(x) > 1)
1693                 numPartAmbig++;
1694             for (j=0; j<10; j++)
1695                 {
1696                 if (((bitsLongOne<<j) & x) != 0)
1697                     {   
1698                     n1[j]++;
1699                     if (NBits(x) == 1)
1700                         n2[j]++;
1701                     }
1702                 }
1703             }
1704         }
1705
1706     /* if the ambig counter for any state is equal to the number of considered
1707        states, then set constant for that state and set variable and informative to no */
1708     for (i=0; i<10; i++)
1709         {
1710         if (n1[i] == numConsidered)
1711             {
1712             ci->constant[i] = YES;
1713             ci->variable = ci->informative = NO;
1714             }
1715             else if (n1[i] == 1)
1716             {
1717             ci->singleton[i] = YES;
1718             }
1719         }
1720
1721     /* return if variable is no */
1722     if (ci->variable == NO)
1723         return;
1724
1725     /* the character is either (variable and uninformative) or informative */
1726     
1727     /* first consider unambiguous characters */
1728     /* find smallest and largest unambiguous state for this character */
1729     smallest = 9;
1730     largest = 0;
1731     for (i=0; i<10; i++)
1732         {
1733         if (n2[i] > 0)
1734             {
1735             if (i < smallest)
1736                 smallest = i;
1737             if (i > largest)
1738                 largest = i;
1739             }
1740         }
1741         
1742     /* count the number of informative states in the unambiguous codings */
1743     for (i=numInformative=0; i<10; i++)
1744         {
1745         if (ci->cType == ORD && n2[i] > 0 && i != smallest && i != largest)
1746             {   
1747             numInformative++;
1748             lastInformative = i;
1749             }
1750         else if (n2[i] > 1)
1751             {
1752             numInformative++;
1753             lastInformative = i;
1754             }
1755         }
1756
1757     /* set informative */
1758     if (numInformative > 1)
1759         ci->informative = YES;
1760     else
1761         ci->informative = NO;
1762
1763     
1764     /* we can return now unless informative is no and numPartAmbig is not 0 */
1765     if (!(numPartAmbig > 0 && ci->informative == NO))
1766         return;
1767
1768     /* check if partially ambiguous observations make this character informative
1769        after all */
1770     
1771     /* first set the bits for the taken states */
1772     x = 0;
1773     for (i=0; i<10; i++)
1774         {
1775         if (n2[i] > 0 && i != lastInformative)
1776             x |= (bitsLongOne<<i);
1777         }
1778     oldPoss = 1;
1779     oldComb[0] = x;
1780
1781     /* now go through all partambig chars and see if we can add them without
1782        making the character informative */
1783     for (i=0; i<m->nRows; i++)
1784         {
1785         x = (int) m->origin[m->column + i*m->rowSize];
1786         /* if partambig */ 
1787         if (NBits(x) > 1 && NBits(x) < ci->nStates)
1788             {
1789             /* remove lastInformative */
1790             x &= !(bitsLongOne<<lastInformative);
1791             /* reset newPoss */
1792             newPoss = 0;
1793             /* see if we can add it, store all possible combinations */
1794             for (j=0; j<oldPoss; j++)
1795                 {
1796                 uniqueBits = x & (!oldComb[j]);
1797                 for (k=0; k<10; k++)
1798                     {
1799                     if (((bitsLongOne<<k) & uniqueBits) != 0)
1800                         newComb[newPoss++] = oldComb[j] | (bitsLongOne<<k);
1801                     }
1802                 }
1803             /* break out if we could not add it */
1804             if (newPoss == 0)
1805                 break;
1806             
1807             /* prepare for next partAmbig */
1808             oldPoss = newPoss;
1809             tempComb = oldComb;
1810             oldComb = newComb;
1811             newComb = tempComb;
1812             }
1813         }
1814
1815     if (i < m->nRows)
1816         ci->informative = YES;
1817
1818     return;
1819 }
1820
1821
1822 /*-----------------------------------------------------------
1823 |
1824 |   CheckModel: check model and warn user if strange things
1825 |      are discovered.
1826 |
1827 -------------------------------------------------------------*/
1828 int CheckModel (void)
1829 {
1830     int         i, j, k, answer;
1831     Tree        *t = NULL;
1832     TreeNode    *p;
1833     
1834     /* there should only be one calibrated tree */
1835     for (i=0; i<numTrees; i++)
1836         {
1837         t = GetTreeFromIndex(i,0,0);
1838         if (t->isCalibrated == YES)
1839             break;
1840         }
1841     
1842     if (i < numTrees)
1843         {
1844         if (!strcmp(modelParams[t->relParts[0]].clockRatePr, "Fixed") && AreDoublesEqual(modelParams[t->relParts[0]].clockRateFix, 1.0, 1E-6) == YES)
1845             {
1846             MrBayesPrint("%s   WARNING: You have calibrated the tree but the clock rate is fixed to 1.0.\n", spacer);
1847             MrBayesPrint("%s      This means that time is measured in expected changes per time unit. If\n", spacer);
1848             MrBayesPrint("%s      the calibrations use a different time scale, you need to modify the model\n", spacer);
1849             MrBayesPrint("%s      by introducing a prior for the clock rate ('prset clockratepr').\n", spacer);
1850
1851             if (noWarn == NO)
1852                 {
1853                 answer = WantTo("Do you want to continue with the run regardless");
1854                 if (answer == YES)
1855                     {
1856                     MrBayesPrint("%s   Continuing with the run...\n\n", spacer);
1857                     }
1858                 else
1859                     {
1860                     MrBayesPrint("%s   Stopping the run...\n\n", spacer);
1861                     return (ERROR);
1862                     }
1863                 }
1864             }
1865         }
1866
1867     /* check coalescence model */
1868     for (i=0; i<numTrees; i++)
1869         {
1870         t = GetTreeFromIndex(i, 0, 0);
1871         if ((!strcmp(modelParams[t->relParts[0]].clockPr,"Coalescence") || !strcmp(modelParams[t->relParts[0]].clockPr,"Speciestreecoalescence"))
1872             && !strcmp(modelParams[t->relParts[0]].clockRatePr, "Fixed") && AreDoublesEqual(modelParams[t->relParts[0]].clockRateFix, 1.0, 1E-6) == YES)
1873             {
1874             MrBayesPrint("%s   WARNING: You are using a coalescent model but the clock rate is fixed to 1.0.\n", spacer);
1875             MrBayesPrint("%s      This is likely to be incorrect unless you have set the population size prior\n", spacer);
1876             MrBayesPrint("%s      ('prset popsizepr') to reflect an appropriate prior on theta. \n", spacer);
1877
1878             if (noWarn == NO)
1879                 {
1880                 answer = WantTo("Do you want to continue with the run regardless");
1881                 if (answer == YES)
1882                     {
1883                     MrBayesPrint("%s   Continuing with the run...\n\n", spacer);
1884                     }
1885                 else
1886                     {
1887                     MrBayesPrint("%s   Stopping the run...\n\n", spacer);
1888                     return (ERROR);
1889                     }
1890                 }
1891             }
1892         }
1893
1894     /* Check consistency of best model. First we guarantee that if one topology has
1895        a species tree prior, then all topologies have the same prior. Then we make
1896        sure that all clock trees have a coalescence prior. */
1897
1898     j = 0;
1899     for (i=0; i<numCurrentDivisions; i++)
1900         {
1901         if (!strcmp(modelParams[i].topologyPr, "Speciestree"))
1902             j++;
1903         }
1904
1905     if (j > 0)
1906         {
1907         if (j != numCurrentDivisions)
1908             {
1909             MrBayesPrint("%s   ERROR: If one gene tree has a speciestree prior then all\n", spacer);
1910             MrBayesPrint("%s          gene trees must have the same prior.\n", spacer);
1911             return (ERROR);
1912             }
1913         for (i=0; i<numTrees-1; i++)
1914             {
1915             t = GetTreeFromIndex(i,0,0);
1916             if (strcmp(modelParams[t->relParts[0]].clockPr,"Speciestreecoalescence") != 0)
1917                 {
1918                 MrBayesPrint("%s   ERROR: All gene trees must have a speciestreecoalescence prior\n", spacer);
1919                 MrBayesPrint("%s          if they fold into a species tree.\n", spacer);
1920                 return (ERROR);
1921                 }
1922             if (t->isCalibrated == YES)
1923                 {
1924                 for (k=0; k<t->nNodes-1; k++)
1925                     {
1926                     p = t->allDownPass[k];
1927                     if (p->calibration != NULL)
1928                         {
1929                         MrBayesPrint("%s   ERROR: Gene trees cannot be individually calibrated\n", spacer);
1930                         MrBayesPrint("%s          if they fold into a species tree.\n", spacer);
1931                         return (ERROR);
1932                         }
1933                     }
1934                 }
1935             }
1936         }
1937
1938     return NO_ERROR;
1939 }
1940
1941
1942 /*-----------------------------------------------------------
1943 |
1944 |   CheckExpandedModels: check data partitions that have
1945 |   the codon or doublet model specified
1946 |
1947 -------------------------------------------------------------*/
1948 int CheckExpandedModels (void)
1949 {
1950     int             c, d, i, t, s, s1, s2, s3, whichNuc, uniqueId, numCharsInPart, 
1951                     firstChar, lastChar, contiguousPart, badBreak, badExclusion,
1952                     nGone, nuc1, nuc2, nuc3, foundStopCodon, posNucs1[4], posNucs2[4], posNucs3[4],
1953                     oneGoodCodon, foundUnpaired, nPair, allCheckedOut;
1954     char            *tempStr;
1955     int             tempStrSize=100;
1956     ModelParams     *mp;
1957     
1958     tempStr = (char *) SafeMalloc((size_t)tempStrSize * sizeof(char));
1959     if (!tempStr)
1960         {
1961         MrBayesPrint ("%s   Problem allocating tempString (%d)\n", spacer, tempStrSize * sizeof(char));
1962         return (ERROR);
1963         }
1964
1965     /* first, set charId to 0 for all characters */
1966     for (i=0; i<numChar; i++)
1967         charInfo[i].charId = 0;
1968     
1969     /* loop over partitions */
1970     allCheckedOut = 0;
1971     uniqueId = 1;
1972     for (d=0; d<numCurrentDivisions; d++)
1973         {
1974         mp = &modelParams[d];
1975         
1976         if (mp->dataType == DNA || mp->dataType == RNA)
1977             {
1978             if (!strcmp(mp->nucModel,"Codon") || !strcmp(mp->nucModel,"Protein"))
1979                 {
1980                 /* start check that the codon model is appropriate for this partition */
1981                 
1982                 /* find first character in this partition */
1983                 for (c=0; c<numChar; c++)
1984                     {
1985                     if (partitionId[c][partitionNum] == d+1)
1986                         break;
1987                     }
1988                 firstChar = c;
1989                 /*printf ("   first character = %d\n", firstChar);*/
1990                 
1991                 /* find last character in this partition */
1992                 for (c=numChar-1; c>=0; c--)
1993                     {
1994                     if (partitionId[c][partitionNum] == d+1)
1995                         break;
1996                     }
1997                 lastChar = c;
1998                 /*printf ("   last character = %d\n", lastChar);*/
1999                 
2000                 /* check that the number of characters in partition is divisible by 3 */
2001                 numCharsInPart = 0;
2002                 for (c=firstChar; c<=lastChar; c++)
2003                     {
2004                     if (charInfo[c].isExcluded == YES || partitionId[c][partitionNum] != d+1)
2005                         continue;
2006                     numCharsInPart++;
2007                     }
2008                 /*printf ("   numCharsInPart = %d\n", numCharsInPart);*/
2009                 if (numCharsInPart % 3 != 0)
2010                     {
2011                     if (numCurrentDivisions == 1)
2012                         {
2013                         MrBayesPrint ("%s   The number of characters is not divisible by three.\n", spacer);
2014                         MrBayesPrint ("%s   You specified a %s model which requires triplets\n", spacer, mp->nucModel);
2015                         MrBayesPrint ("%s   However, you have %d characters.\n", spacer, numCharsInPart);
2016                         }
2017                     else
2018                         {
2019                         MrBayesPrint ("%s   The number of characters in partition %d is not\n", spacer, d+1);
2020                         MrBayesPrint ("%s   divisible by three. You specified a %s model\n", spacer, mp->nucModel);
2021                         MrBayesPrint ("%s   which requires triplets. \n", spacer);
2022                         MrBayesPrint ("%s   However, you have %d characters in this partition\n", spacer, numCharsInPart);
2023                         }
2024                     free (tempStr);
2025                     return (ERROR);
2026                     }
2027                 
2028                 /* check that all of the characters in the partition are contiguous */
2029                 contiguousPart = YES;
2030                 for (c=firstChar; c<=lastChar; c++)
2031                     {
2032                     if (charInfo[c].isExcluded == NO && partitionId[c][partitionNum] != d+1)
2033                         contiguousPart = NO;
2034                     }
2035                 if (contiguousPart == NO)
2036                     {
2037                     MrBayesPrint ("%s   Partition %d is not contiguous. You specified that\n", spacer, d+1);
2038                     MrBayesPrint ("%s   a %s model be used for this partition. However, there\n", spacer, mp->nucModel);
2039                     MrBayesPrint ("%s   is another partition that is between some of the characters\n", spacer);
2040                     MrBayesPrint ("%s   in this partition. \n", spacer);
2041                     free (tempStr);
2042                     return (ERROR);
2043                     }
2044                     
2045                 /* check that there is not a break inside a triplet of characters */
2046                 badBreak = NO;
2047                 whichNuc = 0;
2048                 for (c=firstChar; c<=lastChar; c++)
2049                     {
2050                     if (charInfo[c].isExcluded == NO)
2051                         continue;
2052                     whichNuc++;
2053                     if (charInfo[c].bigBreakAfter == YES && whichNuc != 3)
2054                         badBreak = YES;
2055                     if (whichNuc == 3)
2056                         whichNuc = 0;
2057                     }
2058                 if (badBreak == YES)
2059                     {
2060                     MrBayesPrint ("%s   You specified a databreak inside of a coding triplet.\n", spacer);
2061                     MrBayesPrint ("%s   This is a problem, as you imply that part of the codon\n", spacer);
2062                     MrBayesPrint ("%s   lies in one gene and the remainder in another gene. \n", spacer);
2063                     free (tempStr);
2064                     return (ERROR);
2065                     }
2066
2067                 /* make certain excluded characters are in triplets but allow frameshift exclusions first in sequence */
2068                 badExclusion = NO;
2069                 whichNuc = nGone = 0;
2070                 for (c=firstChar; c<=lastChar; c++)
2071                     if (charInfo[c].isExcluded == NO)
2072                         break;
2073                 for (; c<=lastChar; c++)
2074                     {
2075                     whichNuc++;
2076                     if (charInfo[c].isExcluded == YES)
2077                         nGone++;
2078                     if (whichNuc == 3)
2079                         {
2080                         if (nGone == 1 || nGone == 2)
2081                             badExclusion = YES;
2082                         whichNuc = nGone = 0;
2083                         }
2084                     }
2085                 if (badExclusion == YES)
2086                     {
2087                     MrBayesPrint ("%s   In excluding characters, you failed to remove all of the\n", spacer);
2088                     MrBayesPrint ("%s   sites of at least one codon. If you exclude sites, make \n", spacer);
2089                     MrBayesPrint ("%s   certain to exclude all of the sites in the codon(s). \n", spacer);
2090                     free (tempStr);
2091                     return (ERROR);
2092                     }
2093                 
2094                 /* check that there are no stop codons */
2095                 foundStopCodon = NO;
2096                 /* allow frameshifting exclusions in the beginning */
2097                 for (c=firstChar; c<=lastChar; c++)
2098                     if (charInfo[c].isExcluded == NO)
2099                         break;
2100                 for (; c<=lastChar; c+=3)
2101                     {
2102                     if (charInfo[c].isExcluded == NO)
2103                         {
2104                         for (t=0; t<numTaxa; t++)
2105                             {
2106                             if (taxaInfo[t].isDeleted == YES)
2107                                 continue;
2108                             nuc1 = matrix[pos(t,c+0,numChar)];
2109                             nuc2 = matrix[pos(t,c+1,numChar)];
2110                             nuc3 = matrix[pos(t,c+2,numChar)];
2111                             /*nucX is in range 0-15 to represent any possible set of states that nucleatide could be in*/
2112                             GetPossibleNucs (nuc1, posNucs1);
2113                             GetPossibleNucs (nuc2, posNucs2);
2114                             GetPossibleNucs (nuc3, posNucs3);
2115                             
2116                             oneGoodCodon = NO;
2117                             s = 0;
2118                             for (s1=0; s1<4; s1++)
2119                                 {
2120                                 for (s2=0; s2<4; s2++)
2121                                     {
2122                                     for (s3=0; s3<4; s3++)
2123                                         {
2124                                         if (posNucs1[s1] == 1 && posNucs2[s2] == 1 && posNucs3[s3] == 1)
2125                                             {
2126                                             if (mp->codon[s1*16 + s2*4 + s3] != 21)
2127                                                 oneGoodCodon = YES;
2128                                             }
2129                                         s++;
2130                                         }
2131                                     }
2132                                 }
2133                             if (oneGoodCodon == NO)
2134                                 {
2135                                 foundStopCodon = YES;
2136                                 MrBayesPrint ("%s   Stop codon: taxon %s, sites %d to %d (%c%c%c, %s code)\n", spacer, 
2137                                     taxaNames[t], c+1, c+3, WhichNuc (nuc1), WhichNuc (nuc2), WhichNuc (nuc3), mp->geneticCode);
2138                                 }
2139                             }
2140                         }
2141                     }               
2142                 if (foundStopCodon == YES)
2143                     {
2144                     MrBayesPrint ("%s   At least one stop codon was found. Stop codons are not\n", spacer);
2145                     MrBayesPrint ("%s   allowed under the codon models.  \n", spacer);
2146                     free (tempStr);
2147                     return (ERROR);
2148                     }
2149                 
2150                 /* everything checks out. Now we can initialize charId */
2151                 whichNuc = 0;
2152                 for (c=firstChar; c<=lastChar; c++)
2153                     {
2154                     whichNuc++;
2155                     charInfo[c].charId = uniqueId;
2156                     if (whichNuc == 3)
2157                         {
2158                         whichNuc = 0;
2159                         uniqueId++;
2160                         }
2161                     }
2162                 
2163                 allCheckedOut++;
2164                 /* end check that the codon model is appropriate for this partition */
2165                 }
2166             else if (!strcmp(mp->nucModel,"Doublet"))
2167                 {
2168                 /* start check that the doublet model is appropriate for this partition */
2169                 
2170                 /* Check that pairsId does not equal 0 for any of the characters in
2171                    the partition. If it does, then this means that at least one 
2172                    site was not appropriately paired. Remember, that pairsId is
2173                    initialized 1, 2, 3, ... for the first pair, second pair, etc. 
2174                    Also, check that every pair is only represented two times. */
2175                 foundUnpaired = NO;
2176                 for (c=0; c<numChar; c++)
2177                     {
2178                     if (partitionId[c][partitionNum] == d+1 && charInfo[c].pairsId == 0 && charInfo[c].isExcluded == NO)
2179                         foundUnpaired = YES;
2180                     }
2181                     
2182                 for (c=0; c<numChar; c++)
2183                     {
2184                     if (partitionId[c][partitionNum] == d+1 && charInfo[c].isExcluded == NO)
2185                         {
2186                         nPair = 1;
2187                         for (i=0; i<numChar; i++)
2188                             {
2189                             if (i != c && partitionId[i][partitionNum] == d+1 && charInfo[i].isExcluded == NO && charInfo[c].pairsId == charInfo[i].pairsId)
2190                                 nPair++;
2191                             }
2192                         if (nPair != 2)
2193                             foundUnpaired = YES;
2194                         }
2195                     }
2196                 if (foundUnpaired == YES)
2197                     {
2198                     if (numCurrentDivisions == 1)
2199                         {
2200                         MrBayesPrint ("%s   Found unpaired nucleotide sites. The doublet model\n", spacer);
2201                         MrBayesPrint ("%s   requires that all sites are paired. \n", spacer);
2202                         }
2203                     else
2204                         {
2205                         MrBayesPrint ("%s   Found unpaired nucleotide sites in partition %d.\n", spacer, d+1);
2206                         MrBayesPrint ("%s   The doublet model requires that all sites are paired. \n", spacer);
2207                         }
2208                     free (tempStr);
2209                     return (ERROR);
2210                     }
2211
2212                 /* everything checks out. Now we can initialize charId */
2213                 for (c=0; c<numChar; c++)
2214                     {
2215                     nuc1 = nuc2 = -1;
2216                     if (partitionId[c][partitionNum] == d+1 && charInfo[c].charId == 0)
2217                         {
2218                         nuc1 = c;
2219                         for (i=0; i<numChar; i++)
2220                             {
2221                             if (i != c && charInfo[i].charId == 0 && charInfo[c].pairsId == charInfo[i].pairsId)
2222                                 nuc2 = i;
2223                             }
2224                         if (nuc1 >= 0 && nuc2 >= 0)
2225                             {
2226                             charInfo[nuc1].charId = charInfo[nuc2].charId = uniqueId;
2227                             uniqueId++;
2228                             }
2229                         else
2230                             {
2231                             MrBayesPrint ("%s   Weird doublet problem in partition %d.\n", spacer, d+1);
2232                             free (tempStr);
2233                             return (ERROR);
2234                             }
2235                         }
2236                     }
2237                     
2238                 allCheckedOut++;
2239                 /* end check that the doublet model is appropriate for this partition */
2240                 }
2241             }
2242         }
2243         
2244     /*
2245     if (allCheckedOut > 0)
2246         MrBayesPrint ("%s   Codon/Doublet models successfully checked\n", spacer);
2247     */
2248         
2249 #   if 0
2250     for (c=0; c<numChar; c++)
2251             printf (" %d", charId[c]);
2252     printf ("\n");
2253 #   endif
2254
2255     free (tempStr);
2256     return (NO_ERROR);
2257 }
2258
2259 void CodingToString(int coding, char* string)
2260 {
2261     if(coding == ALL)
2262         strcpy(string, "All");
2263     else if(coding == INFORMATIVE)
2264         strcpy(string, "Informative");
2265     else if((coding & VARIABLE) == VARIABLE)
2266         {
2267         if (coding == VARIABLE)
2268             {
2269             strcpy(string, "Variable");
2270             }
2271         else if (coding & NOSINGLETONABSENCE)
2272             {
2273             strcpy(string, "Variable|Nosingletonabsence");
2274             }
2275         else if (coding & NOSINGLETONPRESENCE)
2276             {
2277             strcpy(string, "Variable|Nosingletonpresence");
2278             }
2279         }
2280     else if((coding & NOSINGLETONS) == NOSINGLETONS)
2281         {
2282         if (coding == NOSINGLETONS)
2283             {
2284             strcpy(string, "Nosingletons");
2285             }
2286         else if (coding & NOABSENCESITES)
2287             {
2288             strcpy(string, "Noabsencesites|Nosingletons");
2289             }
2290         else if (coding & NOPRESENCESITES)
2291             {
2292             strcpy(string, "Nopresencesites|Nosingletons");
2293             }
2294         }
2295     else if(coding == NOABSENCESITES)
2296         {
2297         strcpy(string, "Noabsencesites");
2298         }
2299     else if(coding == NOPRESENCESITES)
2300         {
2301         strcpy(string, "Nopresencesites");
2302         }
2303     else if(coding == NOSINGLETONABSENCE)
2304         {
2305         strcpy(string, "Nosingletonabsence");
2306         }
2307     else if(coding == NOSINGLETONPRESENCE)
2308         {
2309         strcpy(string, "Nosingletonpresence");
2310         }
2311     else if(coding == (NOABSENCESITES | NOSINGLETONABSENCE))
2312         {
2313         strcpy(string, "Noabsencesites|Nosingletonabsence");
2314         }
2315     else if(coding == (NOABSENCESITES | NOSINGLETONPRESENCE))
2316         {
2317         strcpy(string, "Noabsencesites|Nosingletonpresence");
2318         }
2319     else if(coding == (NOPRESENCESITES | NOSINGLETONABSENCE))
2320         {
2321         strcpy(string, "Nopresencesites|Nosingletonabsence");
2322         }
2323     else if(coding == (NOPRESENCESITES | NOSINGLETONPRESENCE))
2324         {
2325         strcpy(string, "Nopresencesites|Nosingletonpresence");
2326         }
2327 }
2328
2329
2330 /*-----------------------------------------------------------
2331 |
2332 |   CompressData: compress original data matrix
2333 |
2334 -------------------------------------------------------------*/
2335 int CompressData (void)
2336 {
2337     int             a, c, d, i, j, k, t, col[3], isSame, newRow, newColumn,
2338                     *isTaken, *tempSitesOfPat, *tempChar;
2339     BitsLong        *tempMatrix;
2340     ModelInfo       *m;
2341     ModelParams     *mp;
2342
2343 #   if defined DEBUG_COMPRESSDATA
2344     if (PrintMatrix() == ERROR)
2345         goto errorExit;
2346     getchar();
2347 #   endif
2348
2349     /* set all pointers that will be allocated locally to NULL */
2350     isTaken = NULL;
2351     tempMatrix = NULL;
2352     tempSitesOfPat = NULL;
2353     tempChar = NULL;
2354
2355     /* allocate indices pointing from original to compressed matrix */
2356     if (memAllocs[ALLOC_COMPCOLPOS] == YES)
2357         {
2358         free (compColPos);
2359         compColPos = NULL;
2360         memAllocs[ALLOC_COMPCOLPOS] = NO;
2361         }
2362     compColPos = (int *)SafeMalloc((size_t)numChar * sizeof(int));
2363     if (!compColPos)
2364         {
2365         MrBayesPrint ("%s   Problem allocating compColPos (%d)\n", spacer, numChar * sizeof(int));
2366         goto errorExit;
2367         }
2368     for (i=0; i<numChar; i++)
2369         compColPos[i] = 0;
2370     memAllocs[ALLOC_COMPCOLPOS] = YES;
2371
2372     if (memAllocs[ALLOC_COMPCHARPOS] == YES)
2373         {
2374         free (compCharPos);
2375         compCharPos = NULL;
2376         memAllocs[ALLOC_COMPCHARPOS] = NO;
2377         }
2378     compCharPos = (int *)SafeMalloc((size_t)numChar * sizeof(int));
2379     if (!compCharPos)
2380         {
2381         MrBayesPrint ("%s   Problem allocating compCharPos (%d)\n", spacer, numChar * sizeof(int));
2382         goto errorExit;
2383         }
2384     for (i=0; i<numChar; i++)
2385         compCharPos[i] = 0;
2386     memAllocs[ALLOC_COMPCHARPOS] = YES;
2387
2388     /* allocate space for temporary matrix, tempSitesOfPat,             */
2389     /* vector keeping track of whether a character has been compressed, */
2390     /* and vector indexing first original char for each compressed char */
2391     tempMatrix = (BitsLong *) SafeCalloc (numLocalTaxa * numLocalChar, sizeof(BitsLong));
2392     tempSitesOfPat = (int *) SafeCalloc (numLocalChar, sizeof(int));
2393     isTaken = (int *) SafeCalloc (numChar, sizeof(int));
2394     tempChar = (int *) SafeCalloc (numLocalChar, sizeof(int));
2395     if (!tempMatrix || !tempSitesOfPat || !isTaken || !tempChar)
2396         {
2397         MrBayesPrint ("%s   Problem allocating temporary variables in CompressData\n", spacer);
2398         goto errorExit;
2399         }
2400
2401     /* initialize isTaken */
2402     for (c=0; c<numChar; c++)
2403         isTaken[c] = NO;
2404
2405     /* set index to first empty column in temporary matrix */
2406     newColumn = 0;
2407
2408     /* initialize number of compressed characters */
2409     numCompressedChars = 0;
2410
2411     /* sort and compress data */
2412     for (d=0; d<numCurrentDivisions; d++)
2413         {
2414         /* set pointers to the model params and settings for this division */
2415         m = &modelSettings[d];
2416         mp = &modelParams[d];
2417
2418         /* set column offset for this division in compressed matrix */
2419         m->compMatrixStart = newColumn;
2420
2421         /* set compressed character offset for this division */
2422         m->compCharStart = numCompressedChars;
2423
2424         /* set number of compressed characters to 0 for this division */
2425         m->numChars = 0;
2426
2427         /* find the number of original characters per model site */
2428         m->nCharsPerSite = 1;
2429         if (mp->dataType == DNA || mp->dataType == RNA)
2430             {   
2431             if (!strcmp(mp->nucModel, "Doublet"))
2432                 m->nCharsPerSite = 2;
2433             if (!strcmp(mp->nucModel, "Codon") || !strcmp(mp->nucModel, "Protein"))
2434                 m->nCharsPerSite = 3;
2435             }
2436         
2437         /* sort and compress the characters for this division */
2438         for (c=0; c<numChar; c++)
2439             {
2440             if (charInfo[c].isExcluded == YES || partitionId[c][partitionNum] != d+1 || isTaken[c] == YES)
2441                 continue;
2442
2443             col[0] = c;
2444             isTaken[c] = YES;
2445             
2446             /* find additional columns if more than one character per model site      */
2447             /* return error if the number of matching characters is smaller or larger */
2448             /* than the actual number of characters per model site                    */
2449             if (m->nCharsPerSite > 1)
2450                 {
2451                 j = 1;
2452                 if (charInfo[c].charId == 0)
2453                     {
2454                     MrBayesPrint("%s   Character %d is not properly defined\n", spacer, c+1);
2455                     goto errorExit;
2456                     }
2457                 for (i=c+1; i<numChar; i++)
2458                     {
2459                     if (charInfo[i].charId == charInfo[c].charId)
2460                         {
2461                         if (j >= m->nCharsPerSite)
2462                             {
2463                             MrBayesPrint("%s   Too many matches in charId (division %d char %d)\n", spacer, d, numCompressedChars);
2464                             goto errorExit;
2465                             }
2466                         else
2467                             {
2468                             col[j++] = i;
2469                             isTaken[i] = YES;
2470                             }
2471                         }
2472                     }
2473                 if (j != m->nCharsPerSite)
2474                     {
2475                     MrBayesPrint ("%s   Too few matches in charId (division %d char %d)\n", spacer, d, numCompressedChars);
2476                     goto errorExit;
2477                     }
2478                 }
2479             
2480             /* add character to temporary matrix in column(s) at newColumn */
2481             for (t=newRow=0; t<numTaxa; t++)
2482                 {
2483                 if (taxaInfo[t].isDeleted == YES)
2484                     continue;
2485
2486                 for (k=0; k<m->nCharsPerSite; k++)
2487                     {
2488                     tempMatrix[pos(newRow,newColumn+k,numLocalChar)] = matrix[pos(t,col[k],numChar)];
2489                     }
2490                 newRow++;
2491                 }
2492             
2493             /* is it unique? */
2494             isSame = NO;
2495             if (mp->dataType != CONTINUOUS)
2496                 {
2497                 for (i=m->compMatrixStart; i<newColumn; i+=m->nCharsPerSite)
2498                     {
2499                     isSame = YES;
2500                     for (j=0; j<numLocalTaxa; j++)
2501                         {
2502                         for (k=0; k<m->nCharsPerSite; k++)
2503                             if (tempMatrix[pos(j,newColumn+k,numLocalChar)] != tempMatrix[pos(j,i+k,numLocalChar)])
2504                                 {
2505                                 isSame = NO;
2506                                 break;
2507                                 }
2508                         if (isSame == NO)
2509                             break;
2510                         }
2511                     if (isSame == YES)
2512                         break;
2513                     }
2514                 }
2515
2516             /* if subject to data augmentation, it is always unique */
2517             if (!strcmp(mp->augmentData, "Yes"))
2518                 {
2519                 for (k=0; k<m->nCharsPerSite; k++)
2520                     {
2521                     if (charInfo[col[k]].isMissAmbig == YES)
2522                         isSame = NO;
2523                     }
2524                 }
2525
2526             if (isSame == NO)
2527                 {
2528                 /* if it is unique then it should be added */
2529                 tempSitesOfPat[numCompressedChars] = 1;
2530                 for (k=0; k<m->nCharsPerSite; k++)
2531                     {
2532                     compColPos[col[k]] = newColumn + k;
2533                     compCharPos[col[k]] = numCompressedChars;
2534                     tempChar[newColumn + k] = col[k];
2535                     }
2536                 newColumn+=m->nCharsPerSite;
2537                 m->numChars++;
2538                 numCompressedChars++;
2539                 }
2540             else
2541                 {
2542                 /* if it is not unique then simply update tempSitesOfPat     */
2543                 /* calculate compressed character position and put it into a */
2544                 /* (i points to compressed column position)                  */
2545                 a = m->compCharStart + ((i - m->compMatrixStart) / m->nCharsPerSite);
2546                 tempSitesOfPat[a]++;
2547                 for (k=0; k<m->nCharsPerSite; k++)
2548                     {
2549                     compColPos[col[k]] = i;
2550                     compCharPos[col[k]] = a;
2551                     /* tempChar (pointing from compressed to uncompresed) */
2552                     /* can only be set for first pattern */
2553                     }
2554                 }
2555             }   /* next character */
2556             
2557         /* check that the partition has at least a single character */
2558         if (m->numChars <= 0)
2559             {
2560             MrBayesPrint ("%s   You must have at least one site in a partition. Partition %d\n", spacer, d+1);
2561             MrBayesPrint ("%s   has %d site patterns.\n", spacer, m->numChars);
2562             goto errorExit;
2563             }
2564
2565         m->compCharStop = m->compCharStart + m->numChars;
2566         m->compMatrixStop = newColumn;
2567
2568         } /* next division */
2569
2570     compMatrixRowSize = newColumn;
2571
2572     /* now we know the size, so we can allocate space for the compressed matrix ... */
2573     if (memAllocs[ALLOC_COMPMATRIX] == YES)
2574         {
2575         free (compMatrix);
2576         compMatrix = NULL;
2577         memAllocs[ALLOC_COMPMATRIX] = NO;
2578         }
2579     compMatrix = (BitsLong *) SafeCalloc (compMatrixRowSize * numLocalTaxa, sizeof(BitsLong));
2580     if (!compMatrix)
2581         {
2582         MrBayesPrint ("%s   Problem allocating compMatrix (%d)\n", spacer, compMatrixRowSize * numLocalTaxa * sizeof(BitsLong));
2583         goto errorExit;
2584         }
2585     memAllocs[ALLOC_COMPMATRIX] = YES;
2586     
2587     if (memAllocs[ALLOC_NUMSITESOFPAT] == YES)
2588         {
2589         free (numSitesOfPat);
2590         numSitesOfPat = NULL;
2591         memAllocs[ALLOC_NUMSITESOFPAT] = NO;
2592         }
2593     numSitesOfPat = (CLFlt *) SafeCalloc (numCompressedChars, sizeof(CLFlt));
2594     if (!numSitesOfPat)
2595         {
2596         MrBayesPrint ("%s   Problem allocating numSitesOfPat (%d)\n", spacer, numCompressedChars * sizeof(MrBFlt));
2597         goto errorExit;
2598         }
2599     memAllocs[ALLOC_NUMSITESOFPAT] = YES;
2600
2601     if (memAllocs[ALLOC_ORIGCHAR] == YES)
2602         {
2603         free (origChar);
2604         origChar = NULL;
2605         memAllocs[ALLOC_ORIGCHAR] = NO;
2606         }
2607     origChar = (int *)SafeMalloc((size_t)compMatrixRowSize * sizeof(int));
2608     if (!origChar)
2609         {
2610         MrBayesPrint ("%s   Problem allocating origChar (%d)\n", spacer, numCompressedChars * sizeof(int));
2611         goto errorExit;
2612         }
2613     memAllocs[ALLOC_ORIGCHAR] = YES;
2614
2615     /* ... and copy the data there */
2616     for (i=0; i<numLocalTaxa; i++)
2617         for (j=0; j<compMatrixRowSize; j++)
2618             compMatrix[pos(i,j,compMatrixRowSize)] = tempMatrix[pos(i,j,numLocalChar)];
2619
2620     for (i=0; i<numCompressedChars; i++)
2621         numSitesOfPat[i] = (CLFlt) tempSitesOfPat[i];
2622
2623     for (i=0; i<compMatrixRowSize; i++)
2624         origChar[i] = tempChar[i];
2625
2626 #   if defined (DEBUG_COMPRESSDATA)
2627     if (PrintCompMatrix() == ERROR)
2628         goto errorExit;
2629     getchar();
2630 #   endif
2631
2632     /* free the temporary variables */
2633     free (tempSitesOfPat);
2634     free (tempMatrix);
2635     free (isTaken);
2636     free (tempChar);
2637
2638     return NO_ERROR;
2639
2640     errorExit:
2641         if (tempMatrix)
2642             free (tempMatrix);
2643         if (tempSitesOfPat)
2644             free (tempSitesOfPat);
2645         if (isTaken)
2646             free (isTaken);
2647         if (tempChar)
2648             free (tempChar);
2649
2650         return ERROR;
2651 }
2652
2653
2654 int DataType (int part)
2655 {
2656     int     i;
2657
2658     for (i=0; i<numChar; i++)
2659         {
2660         if (partitionId[i][partitionNum] == part + 1)
2661             break;
2662         }
2663
2664     return (charInfo[i].charType);
2665 }
2666
2667
2668 int DoLink (void)
2669 {
2670     int         i, j, newLine;
2671     
2672     MrBayesPrint ("%s   Linking\n", spacer);
2673     
2674     /* update status of linkTable */
2675     for (j=0; j<NUM_LINKED; j++)
2676         {
2677         newLine = YES;
2678         for (i=0; i<numCurrentDivisions; i++)
2679             {
2680             if (tempLinkUnlink[j][i] == YES)
2681                 {
2682                 if (newLine == YES)
2683                     {
2684                     linkNum++;
2685                     newLine = NO;
2686                     }
2687                 linkTable[j][i] = linkNum;
2688                 }
2689             }
2690         }
2691     
2692 #   if 0
2693     for (j=0; j<NUM_LINKED; j++)
2694         {
2695         MrBayesPrint ("%s   ", spacer);
2696         for (i=0; i<numCurrentDivisions; i++)
2697             MrBayesPrint ("%d", linkTable[j][i]);
2698         MrBayesPrint ("\n");
2699         }
2700 #   endif
2701
2702     /* reinitialize the temporary table */
2703     for (j=0; j<NUM_LINKED; j++)
2704         for (i=0; i<numCurrentDivisions; i++)
2705             tempLinkUnlink[j][i] = NO;
2706
2707     /* set up parameters and moves */
2708     if (SetUpAnalysis (&globalSeed) == ERROR)
2709         return (ERROR);
2710     
2711     return (NO_ERROR);
2712 }
2713
2714
2715 int DoLinkParm (char *parmName, char *tkn)
2716 {
2717     int         i, j, tempInt;
2718
2719     if (defMatrix == NO)
2720         {
2721         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
2722         return (ERROR);
2723         }
2724         
2725     if (inValidCommand == YES)
2726         {
2727         for (j=0; j<NUM_LINKED; j++)
2728             for (i=0; i<numCurrentDivisions; i++)
2729                 tempLinkUnlink[j][i] = NO;
2730         inValidCommand = NO;
2731         }
2732
2733     if (expecting == Expecting(PARAMETER))
2734         {
2735         expecting = Expecting(EQUALSIGN);
2736         }
2737     else if (expecting == Expecting(EQUALSIGN))
2738         {
2739         expecting = Expecting(LEFTPAR);
2740         }
2741     else if (expecting == Expecting(LEFTPAR))
2742         {
2743         /* initialize tempLinkUnlinkVec to no */
2744         for (i=0; i<numCurrentDivisions; i++)
2745             tempLinkUnlinkVec[i] = NO;
2746         fromI = toJ = -1;
2747         foundDash = NO;
2748         expecting = Expecting(NUMBER) | Expecting(ALPHA);
2749         }
2750     else if (expecting == Expecting(RIGHTPAR))
2751         {
2752         if (fromI != -1)
2753             tempLinkUnlinkVec[fromI-1] = YES;
2754         /* now copy tempLinkUnlinkVec to appropriate row of tempLinkUnlink */
2755         if (!strcmp(parmName, "Tratio"))
2756             {
2757             for (i=0; i<numCurrentDivisions; i++)
2758                 tempLinkUnlink[P_TRATIO][i] = tempLinkUnlinkVec[i];
2759             }
2760         else if (!strcmp(parmName, "Revmat"))
2761             {
2762             for (i=0; i<numCurrentDivisions; i++)
2763                 tempLinkUnlink[P_REVMAT][i] = tempLinkUnlinkVec[i];
2764             }
2765         else if (!strcmp(parmName, "Omega"))
2766             {
2767             for (i=0; i<numCurrentDivisions; i++)
2768                 tempLinkUnlink[P_OMEGA][i] = tempLinkUnlinkVec[i];
2769             }
2770         else if (!strcmp(parmName, "Statefreq"))
2771             {
2772             for (i=0; i<numCurrentDivisions; i++)
2773                 tempLinkUnlink[P_PI][i] = tempLinkUnlinkVec[i];
2774             }
2775         else if (!strcmp(parmName, "Shape"))
2776             {
2777             for (i=0; i<numCurrentDivisions; i++)
2778                 tempLinkUnlink[P_SHAPE][i] = tempLinkUnlinkVec[i];
2779             }
2780         else if (!strcmp(parmName, "Pinvar"))
2781             {
2782             for (i=0; i<numCurrentDivisions; i++)
2783                 tempLinkUnlink[P_PINVAR][i] = tempLinkUnlinkVec[i];
2784             }
2785         else if (!strcmp(parmName, "Correlation"))
2786             {
2787             for (i=0; i<numCurrentDivisions; i++)
2788                 tempLinkUnlink[P_CORREL][i] = tempLinkUnlinkVec[i];
2789             }
2790         else if (!strcmp(parmName, "Ratemultiplier"))
2791             {
2792             for (i=0; i<numCurrentDivisions; i++)
2793                 tempLinkUnlink[P_RATEMULT][i] = tempLinkUnlinkVec[i];
2794             }
2795         else if (!strcmp(parmName, "Switchrates"))
2796             {
2797             for (i=0; i<numCurrentDivisions; i++)
2798                 tempLinkUnlink[P_SWITCH][i] = tempLinkUnlinkVec[i];
2799             }
2800         else if (!strcmp(parmName, "Topology"))
2801             {
2802             for (i=0; i<numCurrentDivisions; i++)
2803                 tempLinkUnlink[P_TOPOLOGY][i] = tempLinkUnlinkVec[i];
2804             }
2805         else if (!strcmp(parmName, "Brlens"))
2806             {
2807             for (i=0; i<numCurrentDivisions; i++)
2808                 tempLinkUnlink[P_BRLENS][i] = tempLinkUnlinkVec[i];
2809             }
2810         else if (!strcmp(parmName, "Speciationrate"))
2811             {
2812             for (i=0; i<numCurrentDivisions; i++)
2813                 tempLinkUnlink[P_SPECRATE][i] = tempLinkUnlinkVec[i];
2814             }
2815         else if (!strcmp(parmName, "Extinctionrate"))
2816             {
2817             for (i=0; i<numCurrentDivisions; i++)
2818                 tempLinkUnlink[P_EXTRATE][i] = tempLinkUnlinkVec[i];
2819             }
2820         else if (!strcmp(parmName, "Fossilizationrate")) 
2821             {
2822             for (i=0; i<numCurrentDivisions; i++)
2823                 tempLinkUnlink[P_FOSLRATE][i] = tempLinkUnlinkVec[i];
2824             }                                                             
2825         else if (!strcmp(parmName, "Popsize"))
2826             {
2827             for (i=0; i<numCurrentDivisions; i++)
2828                 tempLinkUnlink[P_POPSIZE][i] = tempLinkUnlinkVec[i];
2829             }
2830         else if (!strcmp(parmName, "Growthrate"))
2831             {
2832             for (i=0; i<numCurrentDivisions; i++)
2833                 tempLinkUnlink[P_GROWTH][i] = tempLinkUnlinkVec[i];
2834             } 
2835         else if (!strcmp(parmName, "Aamodel"))
2836             {
2837             for (i=0; i<numCurrentDivisions; i++)
2838                 tempLinkUnlink[P_AAMODEL][i] = tempLinkUnlinkVec[i];
2839             }
2840         else if (!strcmp(parmName, "Cpprate"))
2841             {
2842             for (i=0; i<numCurrentDivisions; i++)
2843                 tempLinkUnlink[P_CPPRATE][i] = tempLinkUnlinkVec[i];
2844             }
2845         else if (!strcmp(parmName, "Cppmultdev"))
2846             {
2847             for (i=0; i<numCurrentDivisions; i++)
2848                 tempLinkUnlink[P_CPPMULTDEV][i] = tempLinkUnlinkVec[i];
2849             }
2850         else if (!strcmp(parmName, "Cppevents"))
2851             {
2852             for (i=0; i<numCurrentDivisions; i++)
2853                 tempLinkUnlink[P_CPPEVENTS][i] = tempLinkUnlinkVec[i];
2854             }
2855         else if (!strcmp(parmName, "TK02var") || !strcmp(parmName, "Bmvar"))
2856             {
2857             for (i=0; i<numCurrentDivisions; i++)
2858                 tempLinkUnlink[P_TK02VAR][i] = tempLinkUnlinkVec[i];
2859             }
2860         else if (!strcmp(parmName, "TK02branchrates") || !strcmp(parmName, "Bmbranchrates"))
2861             {
2862             for (i=0; i<numCurrentDivisions; i++)
2863                 tempLinkUnlink[P_TK02BRANCHRATES][i] = tempLinkUnlinkVec[i];
2864             }
2865         else if (!strcmp(parmName, "Igrvar") || !strcmp(parmName, "Ibrvar"))
2866             {
2867             for (i=0; i<numCurrentDivisions; i++)
2868                 tempLinkUnlink[P_IGRVAR][i] = tempLinkUnlinkVec[i];
2869             }
2870         else if (!strcmp(parmName, "Igrbranchrates") || !strcmp(parmName, "Ibrbranchlens"))
2871             {
2872             for (i=0; i<numCurrentDivisions; i++)
2873                 tempLinkUnlink[P_IGRBRANCHRATES][i] = tempLinkUnlinkVec[i];
2874             }
2875         else if (!strcmp(parmName, "Mixedvar"))
2876             {
2877             for (i=0; i<numCurrentDivisions; i++)
2878                 tempLinkUnlink[P_MIXEDVAR][i] = tempLinkUnlinkVec[i];
2879             }
2880         else if (!strcmp(parmName, "Mixedbrchrates"))
2881             {
2882             for (i=0; i<numCurrentDivisions; i++)
2883                 tempLinkUnlink[P_MIXEDBRCHRATES][i] = tempLinkUnlinkVec[i];
2884             }
2885         else
2886             {
2887             MrBayesPrint ("%s   Couldn't find parameter %s to link\n", spacer, parmName);
2888             }
2889         
2890         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
2891         }
2892     else if (expecting == Expecting(COMMA))
2893         {
2894         foundComma = YES;
2895         expecting = Expecting(NUMBER);
2896         }
2897     else if (expecting == Expecting(ALPHA))
2898         {
2899         if (IsSame ("All", tkn) == DIFFERENT)
2900             {
2901             MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
2902             return (ERROR);
2903             }
2904         for (i=0; i<numCurrentDivisions; i++)
2905             tempLinkUnlinkVec[i] = YES;
2906         expecting  = Expecting(RIGHTPAR);
2907         }
2908     else if (expecting == Expecting(NUMBER))
2909         {
2910         sscanf (tkn, "%d", &tempInt);
2911         if (tempInt > numCurrentDivisions)
2912             {
2913             MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
2914             return (ERROR);
2915             }
2916         if (fromI == -1)
2917             fromI = tempInt;
2918         else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
2919             {
2920             toJ = tempInt;
2921             for (i=fromI-1; i<toJ; i++)
2922                 tempLinkUnlinkVec[i] = YES;
2923             fromI = toJ = -1;
2924             foundDash = NO;
2925             }
2926         else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
2927             {
2928             tempLinkUnlinkVec[fromI-1] = YES;
2929             fromI = tempInt;
2930             foundComma = NO;
2931             }
2932         expecting  = Expecting(COMMA);
2933         expecting |= Expecting(DASH);
2934         expecting |= Expecting(RIGHTPAR);
2935         }
2936     else if (expecting == Expecting(DASH))
2937         {
2938         foundDash = YES;
2939         expecting = Expecting(NUMBER);
2940         }
2941     else
2942         return (ERROR);
2943
2944     return (NO_ERROR);
2945 }
2946
2947
2948 int DoLset (void)
2949 {
2950     int         i, nApplied, lastActive=0;
2951     
2952     nApplied = NumActiveParts ();
2953     for (i=numCurrentDivisions-1; i>=0; i--)
2954         {
2955         if (activeParts[i] == YES)
2956             {
2957             lastActive = i;
2958             break;
2959             }
2960         }
2961             
2962     /* MrBayesPrint ("\n"); */
2963     if (numCurrentDivisions == 1)
2964         MrBayesPrint ("%s   Successfully set likelihood model parameters\n", spacer);
2965     else 
2966         {
2967         if (nApplied == numCurrentDivisions || nApplied == 0)
2968             {
2969             MrBayesPrint ("%s   Successfully set likelihood model parameters to all\n", spacer);
2970             MrBayesPrint ("%s      applicable data partitions \n", spacer);
2971             }
2972         else
2973             {
2974             MrBayesPrint ("%s   Successfully set likelihood model parameters to\n", spacer);
2975             if (nApplied == 1)
2976                 MrBayesPrint ("%s   partition", spacer);
2977             else
2978                 MrBayesPrint ("%s   partitions", spacer);
2979             for (i=0; i<numCurrentDivisions; i++)
2980                 {
2981                 if (activeParts[i] == YES)
2982                     {
2983                     if (i == lastActive && nApplied > 1)
2984                         MrBayesPrint (" and %d", i+1);
2985                     else
2986                         MrBayesPrint (" %d", i+1);
2987                     if (nApplied > 2 && i != lastActive)
2988                         MrBayesPrint (",");
2989                     }
2990                 }
2991             MrBayesPrint (" (if applicable)\n");
2992             }
2993         }
2994
2995     if (SetUpAnalysis (&globalSeed) == ERROR)
2996         return (ERROR);
2997     
2998     return (NO_ERROR);
2999 }
3000
3001
3002 int DoLsetParm (char *parmName, char *tkn)
3003 {
3004     int         i, j, tempInt, nApplied;
3005     char        tempStr[100];
3006
3007     if (defMatrix == NO)
3008         {
3009         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
3010         return (ERROR);
3011         }
3012     if (inValidCommand == YES)
3013         {
3014         for (i=0; i<numCurrentDivisions; i++)
3015             activeParts[i] = NO;
3016         inValidCommand = NO;
3017         }
3018
3019     if (expecting == Expecting(PARAMETER))
3020         {
3021         expecting = Expecting(EQUALSIGN);
3022         }
3023     else
3024         {
3025         /* set Applyto (Applyto) *************************************************************/
3026         if (!strcmp(parmName, "Applyto"))
3027             {
3028             if (expecting == Expecting(EQUALSIGN))
3029                 expecting = Expecting(LEFTPAR);
3030             else if (expecting == Expecting(LEFTPAR))
3031                 {
3032                 for (i=0; i<numCurrentDivisions; i++)
3033                     activeParts[i] = NO;
3034                 fromI = toJ = -1;
3035                 foundDash = NO;
3036                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
3037                 }
3038             else if (expecting == Expecting(RIGHTPAR))
3039                 {
3040                 if (fromI != -1)
3041                     activeParts[fromI-1] = YES;
3042                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3043                 }
3044             else if (expecting == Expecting(COMMA))
3045                 {
3046                 foundComma = YES;
3047                 expecting = Expecting(NUMBER);
3048                 }
3049             else if (expecting == Expecting(ALPHA))
3050                 {
3051                 if (IsSame ("All", tkn) == DIFFERENT)
3052                     {
3053                     MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
3054                     return (ERROR);
3055                     }
3056                 for (i=0; i<numCurrentDivisions; i++)
3057                     activeParts[i] = YES;
3058                 expecting  = Expecting(RIGHTPAR);
3059                 }
3060             else if (expecting == Expecting(NUMBER))
3061                 {
3062                 sscanf (tkn, "%d", &tempInt);
3063                 if (tempInt > numCurrentDivisions)
3064                     {
3065                     MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
3066                     return (ERROR);
3067                     }
3068                 if (fromI == -1)
3069                     fromI = tempInt;
3070                 else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
3071                     {
3072                     toJ = tempInt;
3073                     for (i=fromI-1; i<toJ; i++)
3074                         activeParts[i] = YES;
3075                     fromI = toJ = -1;
3076                     foundDash = NO;
3077                     }
3078                 else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
3079                     {
3080                     activeParts[fromI-1] = YES;
3081                     fromI = tempInt;
3082                     foundComma = NO;
3083                     }
3084                     
3085                 expecting  = Expecting(COMMA);
3086                 expecting |= Expecting(DASH);
3087                 expecting |= Expecting(RIGHTPAR);
3088                 }
3089             else if (expecting == Expecting(DASH))
3090                 {
3091                 foundDash = YES;
3092                 expecting = Expecting(NUMBER);
3093                 }
3094             else
3095                 return (ERROR);
3096             }
3097         /* set Nucmodel (nucModel) ************************************************************/
3098         else if (!strcmp(parmName, "Nucmodel"))
3099             {
3100             if (expecting == Expecting(EQUALSIGN))
3101                 expecting = Expecting(ALPHA);
3102             else if (expecting == Expecting(ALPHA))
3103                 {
3104                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3105                     {
3106                     nApplied = NumActiveParts ();
3107                     tempInt = NO;
3108                     for (i=0; i<numCurrentDivisions; i++)
3109                         {
3110                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3111                             {
3112                             strcpy(modelParams[i].nucModel, tempStr);
3113                             modelParams[i].nStates = NumStates (i);
3114                             
3115                             /* set state frequencies back to default */
3116                             strcpy(modelParams[i].stateFreqPr, "Dirichlet");
3117                             strcpy(modelParams[i].stateFreqsFixType, "Equal");
3118                             for (j=0; j<200; j++)
3119                                 {
3120                                 modelParams[i].stateFreqsFix[j] = 0.0;   
3121                                 modelParams[i].stateFreqsDir[j] = 1.0;
3122                                 }    
3123                             tempInt = YES;
3124                             if (nApplied == 0 && numCurrentDivisions == 1)
3125                                 MrBayesPrint ("%s   Setting Nucmodel to %s\n", spacer, modelParams[i].nucModel);
3126                             else
3127                                 MrBayesPrint ("%s   Setting Nucmodel to %s for partition %d\n", spacer, modelParams[i].nucModel, i+1);
3128                             }
3129                         }
3130                     if (tempInt == YES)
3131                         MrBayesPrint ("%s   Set state frequency prior to default\n", spacer);
3132                     }
3133                 else
3134                     {
3135                     MrBayesPrint ("%s   Invalid DNA substitution model\n", spacer);
3136                     return (ERROR);
3137                     }
3138                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3139                 }
3140             else
3141                 return (ERROR);
3142             }
3143         /* set Nst (nst) **********************************************************************/
3144         else if (!strcmp(parmName, "Nst"))
3145             {
3146             if (expecting == Expecting(EQUALSIGN))
3147                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
3148             else if (expecting == Expecting(NUMBER) || expecting == Expecting(ALPHA))
3149                 {
3150                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3151                     {
3152                     nApplied = NumActiveParts ();
3153                     for (i=0; i<numCurrentDivisions; i++)
3154                         {
3155                         if (activeParts[i] == YES || nApplied == 0)
3156                             {
3157                             if (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA)
3158                                 {
3159                                 strcpy(modelParams[i].nst, tempStr);
3160                                 if (nApplied == 0 && numCurrentDivisions == 1)
3161                                     MrBayesPrint ("%s   Setting Nst to %s\n", spacer, modelParams[i].nst);
3162                                 else
3163                                     MrBayesPrint ("%s   Setting Nst to %s for partition %d\n", spacer, modelParams[i].nst, i+1);
3164                                 }
3165                             else {
3166                                 if (nApplied == 0 && numCurrentDivisions == 1)
3167                                     MrBayesPrint ("%s   Nst =%s unchanged ", spacer, modelParams[i].nst);
3168                                 else
3169                                     MrBayesPrint ("%s   Nst =%s unchanged for partition %d ", spacer, modelParams[i].nst, i+1);
3170                                 MrBayesPrint ("because dataType is not DNA or RNA\n");
3171                                 }
3172                             }
3173                         }
3174                     }
3175                 else
3176                     {
3177                     MrBayesPrint ("%s   Invalid Nst argument\n", spacer);
3178                     return (ERROR);
3179                     }
3180                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3181                 }
3182             else
3183                 return (ERROR);
3184             }
3185         /* set Ncat (numGammaCats) ************************************************************/
3186         else if (!strcmp(parmName, "Ngammacat"))
3187             {
3188             if (expecting == Expecting(EQUALSIGN))
3189                 expecting = Expecting(NUMBER);
3190             else if (expecting == Expecting(NUMBER))
3191                 {
3192                 sscanf (tkn, "%d", &tempInt);
3193                 if (tempInt >= 2 && tempInt < MAX_GAMMA_CATS)
3194                     {
3195                     nApplied = NumActiveParts ();
3196                     for (i=0; i<numCurrentDivisions; i++)
3197                         {
3198                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3199                             {
3200                             modelParams[i].numGammaCats = tempInt;
3201                             if (nApplied == 0 && numCurrentDivisions == 1)
3202                                 MrBayesPrint ("%s   Setting Ngammacat to %d\n", spacer, modelParams[i].numGammaCats);
3203                             else
3204                                 MrBayesPrint ("%s   Setting Ngammacat to %d for partition %d\n", spacer, modelParams[i].numGammaCats, i+1);
3205                             }
3206                         }
3207                     }
3208                 else
3209                     {
3210                     MrBayesPrint ("%s   Invalid Ngammacat argument (should be between 2 and %d)\n", spacer, MAX_GAMMA_CATS);
3211                     return (ERROR);
3212                     }
3213                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3214                 }
3215             else
3216                 return (ERROR);
3217             }
3218         /* set Usegibbs (useGibbs) *************************************************************/
3219         else if (!strcmp(parmName, "Usegibbs"))
3220             {
3221             if (expecting == Expecting(EQUALSIGN))
3222                 expecting = Expecting(ALPHA);
3223             else if (expecting == Expecting(ALPHA))
3224                 {
3225                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3226                     {
3227                     nApplied = NumActiveParts ();
3228                     for (i=0; i<numCurrentDivisions; i++)
3229                         {
3230                         if (activeParts[i] == YES || nApplied == 0)
3231                             {
3232                             if (!strcmp(tempStr, "Yes"))
3233                                 {
3234                                 MrBayesPrint ("%s   Downsampling of site rates ('usegibbs = yes') disabled temporarily because of conflict with likelihood calculators\n", spacer);
3235                                 return (ERROR);
3236                                 strcpy(modelParams[i].useGibbs, "Yes");
3237                                 }
3238                             else
3239                                 {
3240                                 strcpy(modelParams[i].useGibbs, "No");
3241                                 }
3242
3243                             if (nApplied == 0 && numCurrentDivisions == 1)
3244                                 MrBayesPrint ("%s   Setting Usegibbs to %s (if applicable)\n", spacer, modelParams[i].useGibbs);
3245                             else
3246                                 MrBayesPrint ("%s   Setting Usegibbs to %s (if applicable) for partition %d\n", spacer, modelParams[i].useGibbs, i+1);
3247                             }
3248                         }
3249                     }
3250                 else
3251                     {
3252                     MrBayesPrint ("%s   Invalid argument for Usegibbs (using Gibbs sampling of discrete gamma)\n", spacer);
3253                     return (ERROR);
3254                     }
3255                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3256                 }
3257             else
3258                 return (ERROR);
3259             }           
3260         /* set Gibbsfreq (gibbsFreq) ************************************************************/
3261         else if (!strcmp(parmName, "Gibbsfreq"))
3262             {
3263             if (expecting == Expecting(EQUALSIGN))
3264                 expecting = Expecting(NUMBER);
3265             else if (expecting == Expecting(NUMBER))
3266                 {
3267                 sscanf (tkn, "%d", &tempInt);
3268                 if (tempInt >= 1 && tempInt <= 1000)
3269                     {
3270                     nApplied = NumActiveParts ();
3271                     for (i=0; i<numCurrentDivisions; i++)
3272                         {
3273                         if (activeParts[i] == YES || nApplied == 0)
3274                             {
3275                             modelParams[i].gibbsFreq = tempInt;
3276                             if (nApplied == 0 && numCurrentDivisions == 1)
3277                                 MrBayesPrint ("%s   Setting Gibbsfreq to %d\n", spacer, modelParams[i].gibbsFreq);
3278                             else
3279                                 MrBayesPrint ("%s   Setting Gibbsfreq to %d for partition %d\n", spacer, modelParams[i].gibbsFreq, i+1);
3280                             }
3281                         }
3282                     }
3283                 else
3284                     {
3285                     MrBayesPrint ("%s   Invalid Gibbsgammafreq argument (should be between 1 and 1000)\n", spacer);
3286                     return (ERROR);
3287                     }
3288                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3289                 }
3290             else
3291                 return (ERROR);
3292             }
3293         /* set NumM10GammaCats (numM10GammaCats) ************************************************************/
3294         else if (!strcmp(parmName, "NumM10GammaCats"))
3295             {
3296             if (expecting == Expecting(EQUALSIGN))
3297                 expecting = Expecting(NUMBER);
3298             else if (expecting == Expecting(NUMBER))
3299                 {
3300                 sscanf (tkn, "%d", &tempInt);
3301                 if (tempInt >= 2 && tempInt < MAX_GAMMA_CATS)
3302                     {
3303                     nApplied = NumActiveParts ();
3304                     for (i=0; i<numCurrentDivisions; i++)
3305                         {
3306                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3307                             {
3308                             modelParams[i].numM10GammaCats = tempInt;
3309                             if (nApplied == 0 && numCurrentDivisions == 1)
3310                                 MrBayesPrint ("%s   Setting NumM10GammaCats to %d\n", spacer, modelParams[i].numM10GammaCats);
3311                             else
3312                                 MrBayesPrint ("%s   Setting NumM10GammaCats to %d for partition %d\n", spacer, modelParams[i].numM10GammaCats, i+1);
3313                             }
3314                         }
3315                     }
3316                 else
3317                     {
3318                     MrBayesPrint ("%s   Invalid NumM10GammaCats argument (should be between 2 and %d)\n", spacer, MAX_GAMMA_CATS);
3319                     return (ERROR);
3320                     }
3321                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3322                 }
3323             else
3324                 return (ERROR);
3325             }
3326         /* set NumM10BetaCats (numM10BetaCats) ************************************************************/
3327         else if (!strcmp(parmName, "NumM10BetaCats"))
3328             {
3329             if (expecting == Expecting(EQUALSIGN))
3330                 expecting = Expecting(NUMBER);
3331             else if (expecting == Expecting(NUMBER))
3332                 {
3333                 sscanf (tkn, "%d", &tempInt);
3334                 if (tempInt >= 2 && tempInt < MAX_GAMMA_CATS)
3335                     {
3336                     nApplied = NumActiveParts ();
3337                     for (i=0; i<numCurrentDivisions; i++)
3338                         {
3339                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3340                             {
3341                             modelParams[i].numM10BetaCats = tempInt;
3342                             if (nApplied == 0 && numCurrentDivisions == 1)
3343                                 MrBayesPrint ("%s   Setting NumM10BetaCats to %d\n", spacer, modelParams[i].numM10BetaCats);
3344                             else
3345                                 MrBayesPrint ("%s   Setting NumM10BetaCats to %d for partition %d\n", spacer, modelParams[i].numM10BetaCats, i+1);
3346                             }
3347                         }
3348                     }
3349                 else
3350                     {
3351                     MrBayesPrint ("%s   Invalid NumM10GammaCats argument (should be between 2 and %d)\n", spacer, MAX_GAMMA_CATS);
3352                     return (ERROR);
3353                     }
3354                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3355                 }
3356             else
3357                 return (ERROR);
3358             }
3359         /* set Nbetacat (numBetaCats) *****************************************************/
3360         else if (!strcmp(parmName, "Nbetacat"))
3361             {
3362             if (expecting == Expecting(EQUALSIGN))
3363                 expecting = Expecting(NUMBER);
3364             else if (expecting == Expecting(NUMBER))
3365                 {
3366                 sscanf (tkn, "%d", &tempInt);
3367                 if (tempInt >= 2 && tempInt < MAX_GAMMA_CATS)
3368                     {
3369                     nApplied = NumActiveParts ();
3370                     for (i=0; i<numCurrentDivisions; i++)
3371                         {
3372                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
3373                             {
3374                             modelParams[i].numBetaCats = tempInt;
3375                             if (nApplied == 0 && numCurrentDivisions == 1)
3376                                 MrBayesPrint ("%s   Setting Nbetacat to %d\n", spacer, modelParams[i].numBetaCats);
3377                             else
3378                                 MrBayesPrint ("%s   Setting Nbetacat to %d for partition %d\n", spacer, modelParams[i].numBetaCats, i+1);
3379                             }
3380                         }
3381                     }
3382                 else
3383                     {
3384                     MrBayesPrint ("%s   Invalid Nbetacat argument (should be between 2 and %d)\n", spacer, MAX_GAMMA_CATS);
3385                     return (ERROR);
3386                     }
3387                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3388                 }
3389             else
3390                 return (ERROR);
3391             }
3392         /* set Aamodel (aaModel) **************************************************************/
3393         else if (!strcmp(parmName, "Aamodel"))
3394             {
3395             MrBayesPrint ("%s   Aamodel argument for lset deprecated.\n", spacer);
3396             MrBayesPrint ("%s   Use 'prset aamodelpr=fixed(<aamodel>)' instead.\n", spacer);
3397             return (ERROR);
3398             }
3399         /* set Parsmodel (useParsModel) *******************************************************/
3400         else if (!strcmp(parmName, "Parsmodel"))
3401             {
3402             if (expecting == Expecting(EQUALSIGN))
3403                 expecting = Expecting(ALPHA);
3404             else if (expecting == Expecting(ALPHA))
3405                 {
3406                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3407                     {
3408                     nApplied = NumActiveParts ();
3409                     for (i=0; i<numCurrentDivisions; i++)
3410                         {
3411                         if (activeParts[i] == YES || nApplied == 0)
3412                             {
3413                             if (!strcmp(tempStr, "Yes"))
3414                                 strcpy(modelParams[i].parsModel, "Yes");
3415                             else
3416                                 strcpy(modelParams[i].parsModel, "No");
3417
3418                             if (nApplied == 0 && numCurrentDivisions == 1)
3419                                 MrBayesPrint ("%s   Setting Parsmodel to %s\n", spacer, modelParams[i].parsModel);
3420                             else
3421                                 MrBayesPrint ("%s   Setting Parsmodel to %s for partition %d\n", spacer, modelParams[i].parsModel, i+1);
3422                             }
3423                         }
3424                     }
3425                 else
3426                     {
3427                     MrBayesPrint ("%s   Invalid argument for using (so-called) parsimony model\n", spacer);
3428                     return (ERROR);
3429                     }
3430                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3431                 }
3432             else
3433                 return (ERROR);
3434             }           
3435         /* set Augment (augmentData) **********************************************************/
3436         else if (!strcmp(parmName, "Augment"))
3437             {
3438             if (expecting == Expecting(EQUALSIGN))
3439                 expecting = Expecting(ALPHA);
3440             else if (expecting == Expecting(ALPHA))
3441                 {
3442                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3443                     {
3444                     nApplied = NumActiveParts ();
3445                     for (i=0; i<numCurrentDivisions; i++)
3446                         {
3447                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
3448                             {
3449                             if (!strcmp(tempStr, "Yes"))
3450                                 strcpy(modelParams[i].augmentData, "Yes");
3451                             else
3452                                 strcpy(modelParams[i].augmentData, "No");
3453
3454                             if (nApplied == 0 && numCurrentDivisions == 1)
3455                                 MrBayesPrint ("%s   Setting Augmentdata to %s\n", spacer, modelParams[i].augmentData);
3456                             else
3457                                 MrBayesPrint ("%s   Setting Augmentdata to %s for partition %d\n", spacer, modelParams[i].augmentData, i+1);
3458                             }
3459                         }
3460                     }
3461                 else
3462                     {
3463                     MrBayesPrint ("%s   Invalid argument for data augmentation\n", spacer);
3464                     return (ERROR);
3465                     }
3466                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3467                 }
3468             else
3469                 return (ERROR);
3470             }           
3471         /* set Omegavar (wVarModel) ***********************************************************/
3472         else if (!strcmp(parmName, "Omegavar"))
3473             {
3474             if (expecting == Expecting(EQUALSIGN))
3475                 expecting = Expecting(ALPHA);
3476             else if (expecting == Expecting(ALPHA))
3477                 {
3478                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3479                     {
3480                     nApplied = NumActiveParts ();
3481                     for (i=0; i<numCurrentDivisions; i++)
3482                         {
3483                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3484                             {
3485                             strcpy(modelParams[i].omegaVar, tempStr);
3486                             if (nApplied == 0 && numCurrentDivisions == 1)
3487                                 MrBayesPrint ("%s   Setting Omegavar to %s\n", spacer, modelParams[i].omegaVar);
3488                             else
3489                                 MrBayesPrint ("%s   Setting Omegavar to %s for partition %d\n", spacer, modelParams[i].omegaVar, i+1);
3490                             }
3491                         }
3492                     }
3493                 else
3494                     {
3495                     MrBayesPrint ("%s   Invalid omega variation argument\n", spacer);
3496                     return (ERROR);
3497                     }
3498                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3499                 }
3500             else
3501                 return (ERROR);
3502             }
3503         /* set Code (codeModel) ***************************************************************/
3504         else if (!strcmp(parmName, "Code"))
3505             {
3506             if (expecting == Expecting(EQUALSIGN))
3507                 expecting = Expecting(ALPHA);
3508             else if (expecting == Expecting(ALPHA))
3509                 {
3510                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3511                     {
3512                     nApplied = NumActiveParts ();
3513                     for (i=0; i<numCurrentDivisions; i++)
3514                         {
3515                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3516                             {
3517                             strcpy(modelParams[i].geneticCode, tempStr);
3518                             SetCode (i);
3519                             modelParams[i].nStates = NumStates (i);
3520                             if (nApplied == 0 && numCurrentDivisions == 1)
3521                                 MrBayesPrint ("%s   Setting Code to %s\n", spacer, modelParams[i].geneticCode);
3522                             else
3523                                 MrBayesPrint ("%s   Setting Code to %s for partition %d\n", spacer, modelParams[i].geneticCode, i+1);
3524                             }
3525                         }
3526                     }
3527                 else
3528                     {
3529                     MrBayesPrint ("%s   Invalid genetic code argument\n", spacer);
3530                     return (ERROR);
3531                     }
3532                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3533                 }
3534             else
3535                 return (ERROR);
3536             }
3537         /* set Ploidy (ploidy) ***************************************************************/
3538         else if (!strcmp(parmName, "Ploidy"))
3539             {
3540             if (expecting == Expecting(EQUALSIGN))
3541                 expecting = Expecting(ALPHA);
3542             else if (expecting == Expecting(ALPHA))
3543                 {
3544                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3545                     {
3546                     nApplied = NumActiveParts ();
3547                     for (i=0; i<numCurrentDivisions; i++)
3548                         {
3549                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3550                             {
3551                             strcpy(modelParams[i].ploidy, tempStr);
3552                             if (nApplied == 0 && numCurrentDivisions == 1)
3553                                 MrBayesPrint ("%s   Setting ploidy level to %s\n", spacer, modelParams[i].ploidy);
3554                             else
3555                                 MrBayesPrint ("%s   Setting ploidy level to %s for partition %d\n", spacer, modelParams[i].ploidy, i+1);
3556                             }
3557                         }
3558                     }
3559                 else
3560                     {
3561                     MrBayesPrint ("%s   Invalid ploidy level argument\n", spacer);
3562                     return (ERROR);
3563                     }
3564                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3565                 }
3566             else
3567                 return (ERROR);
3568             }
3569         /* set Rates (ratesModel) *************************************************************/
3570         else if (!strcmp(parmName, "Rates"))
3571             {
3572             if (expecting == Expecting(EQUALSIGN))
3573                 expecting = Expecting(ALPHA);
3574             else if (expecting == Expecting(ALPHA))
3575                 {
3576                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3577                     {
3578                     nApplied = NumActiveParts ();
3579                     for (i=0; i<numCurrentDivisions; i++)
3580                         {
3581                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
3582                             {
3583                             if (!strcmp(tempStr, "Adgamma") && (modelParams[i].dataType != DNA && modelParams[i].dataType != RNA && modelParams[i].dataType != PROTEIN))
3584                                 {
3585                                 /* we won't apply an adgamma model to anything but DNA, RNA, or PROTEIN data */
3586                                 }
3587                             else if ((!strcmp(tempStr, "Propinv") ||  !strcmp(tempStr, "Invgamma")) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
3588                                 {
3589                                 /* we will not apply pinvar to standard or restriction site data */
3590                                 }
3591                             else
3592                                 {
3593                                 strcpy(modelParams[i].ratesModel, tempStr);
3594                                 if (nApplied == 0 && numCurrentDivisions == 1)
3595                                     MrBayesPrint ("%s   Setting Rates to %s\n", spacer, modelParams[i].ratesModel);
3596                                 else
3597                                     MrBayesPrint ("%s   Setting Rates to %s for partition %d\n", spacer, modelParams[i].ratesModel, i+1);
3598                                 }
3599                             }
3600                         }
3601                     }
3602                 else
3603                     {
3604                     MrBayesPrint ("%s   Invalid Rates argument\n", spacer);
3605                     return (ERROR);
3606                     }
3607                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3608                 }
3609             else
3610                 return (ERROR);
3611             }
3612         /* set Covarion (covarionModel) *******************************************************/
3613         else if (!strcmp(parmName, "Covarion"))
3614             {
3615             if (expecting == Expecting(EQUALSIGN))
3616                 expecting = Expecting(ALPHA);
3617             else if (expecting == Expecting(ALPHA))
3618                 {
3619                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3620                     {
3621                     nApplied = NumActiveParts ();
3622                     for (i=0; i<numCurrentDivisions; i++)
3623                         {
3624                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
3625                             {
3626                             strcpy(modelParams[i].covarionModel, tempStr);
3627                             if (nApplied == 0 && numCurrentDivisions == 1)
3628                                 MrBayesPrint ("%s   Setting Covarion to %s\n", spacer, modelParams[i].covarionModel);
3629                             else
3630                                 MrBayesPrint ("%s   Setting Covarion to %s for partition %d\n", spacer, modelParams[i].covarionModel, i+1);
3631                             }
3632                         }
3633                     }
3634                 else
3635                     {
3636                     MrBayesPrint ("%s   Invalid Rates argument\n", spacer);
3637                     return (ERROR);
3638                     }
3639                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3640                 }
3641             else
3642                 return (ERROR);
3643             }
3644         /* set Coding (missingType) ***********************************************************/
3645         else if (!strcmp(parmName, "Coding"))
3646             {
3647             if (expecting == Expecting(EQUALSIGN))
3648                 {
3649                 for (i=0; i<numCurrentDivisions; i++)
3650                     modelParams[i].coding = ALL;
3651                 
3652                 expecting = Expecting(ALPHA);
3653                 }
3654             else if (expecting == Expecting(VERTICALBAR))
3655                 expecting = Expecting(ALPHA);
3656             else if (expecting == Expecting(ALPHA))
3657                 {
3658                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3659                     {
3660                     nApplied = NumActiveParts ();
3661                     for (i=0; i<numCurrentDivisions; i++)
3662                         {
3663                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD))
3664                             {
3665                             if(!strcmp(tempStr, "Nosingletons"))
3666                                 {
3667                                 modelParams[i].coding |= NOSINGLETONS;
3668                                 }
3669                             else if(!strcmp(tempStr, "Variable"))
3670                                 {
3671                                 modelParams[i].coding |= VARIABLE;
3672                                 }
3673                             else if(!strcmp(tempStr, "Informative"))
3674                                 {
3675                                 modelParams[i].coding |= INFORMATIVE;
3676                                 }
3677                             else
3678                                 {
3679                                 if(modelParams[i].dataType != RESTRICTION)
3680                                     {
3681                                     MrBayesPrint ("%s   Invalid coding for standard characters: %s\n", spacer, tempStr);
3682                                     return (ERROR);
3683                                     }
3684                                 
3685                                 if(!strcmp(tempStr, "Noabsencesites"))
3686                                     {
3687                                     modelParams[i].coding |= NOABSENCESITES;
3688                                     }
3689                                 else if(!strcmp(tempStr, "Nopresencesites"))
3690                                     {
3691                                     modelParams[i].coding |= NOPRESENCESITES;
3692                                     }
3693                                 else if(!strcmp(tempStr, "Nosingletonpresence"))
3694                                     {
3695                                     modelParams[i].coding |= NOSINGLETONPRESENCE;
3696                                     }
3697                                 else if(!strcmp(tempStr, "Nosingletonabsence"))
3698                                     {
3699                                     modelParams[i].coding |= NOSINGLETONABSENCE;
3700                                     }
3701                                 }
3702                             
3703                             CodingToString(modelParams[i].coding, modelParams[i].codingString);
3704                             
3705                             if (nApplied == 0 && numCurrentDivisions == 1)
3706                                 MrBayesPrint ("%s   Enabling Coding %s\n", spacer, tempStr);
3707                             else
3708                                 MrBayesPrint ("%s   Enabling Coding %s for partition %d\n", spacer, tempStr, i+1);
3709                             }
3710                         }
3711                     }
3712                 else
3713                     {
3714                     MrBayesPrint ("%s   Invalid argument for missing patterns\n", spacer);
3715                     return (ERROR);
3716                     }
3717                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON) | Expecting(VERTICALBAR);
3718                 }
3719             else
3720                 return (ERROR);
3721             }
3722                 
3723                 
3724                 
3725                 
3726         else
3727             return (ERROR);
3728         }
3729
3730     return (NO_ERROR);
3731 }
3732
3733
3734 int DoPlot (void)
3735 {
3736     int             i, n, nHeaders, burnin, len, longestHeader, whichIsX, whichIsY, numPlotted;
3737     char            temp[100], **headerNames = NULL;
3738     SumpFileInfo    fileInfo;
3739     ParameterSample *parameterSamples;
3740     
3741 #   if defined (MPI_ENABLED)
3742     if (proc_id != 0)
3743         return NO_ERROR;
3744 #   endif
3745     
3746     /* initialize values */
3747     headerNames = NULL;
3748     nHeaders = 0;
3749     parameterSamples = NULL;
3750     
3751     /* tell user we are ready to go */
3752     MrBayesPrint ("%s   Plotting parameters in file %s ...\n", spacer, plotParams.plotFileName);
3753     
3754     /* examine plot file */
3755     if (ExamineSumpFile (plotParams.plotFileName, &fileInfo, &headerNames, &nHeaders) == ERROR)
3756         return ERROR;
3757     
3758     /* Calculate burn in */
3759     burnin = fileInfo.firstParamLine - fileInfo.headerLine - 1;
3760     
3761     /* tell the user that everything is fine */
3762     MrBayesPrint ("%s   Found %d parameter lines in file \"%s\"\n", spacer, fileInfo.numRows + burnin, plotParams.plotFileName);
3763     if (burnin > 0)
3764         MrBayesPrint ("%s   Of the %d lines, %d of them will be summarized (starting at line %d)\n", spacer, fileInfo.numRows+burnin, fileInfo.numRows, fileInfo.firstParamLine);
3765     else
3766         MrBayesPrint ("%s   All %d lines will be summarized (starting at line %d)\n", spacer, fileInfo.numRows, fileInfo.firstParamLine);
3767     MrBayesPrint ("%s   (Only the last set of lines will be read, in case multiple\n", spacer);
3768     MrBayesPrint ("%s   parameter blocks are present in the same file.)\n", spacer);
3769     
3770     /* allocate space to hold parameter information */
3771     if (AllocateParameterSamples (&parameterSamples, 1, fileInfo.numRows, fileInfo.numColumns) == ERROR)
3772         goto errorExit;
3773     
3774     /* Now we read the file for real. First, rewind file pointer to beginning of file... */
3775     if (ReadParamSamples (plotParams.plotFileName, &fileInfo, parameterSamples, 0) == ERROR)
3776         goto errorExit;
3777     
3778     /* get length of longest header */
3779     longestHeader = 9; /* 9 is the length of the word "parameter" (for printing table) */
3780     for (i=0; i<nHeaders; i++)
3781         {
3782         len = (int) strlen(headerNames[i]);
3783         if (len > longestHeader)
3784             longestHeader = len;
3785         }
3786     
3787     /* print x-y plot of parameter vs. generation */
3788     whichIsX = -1;
3789     for (i=0; i<nHeaders; i++)
3790         {
3791         if (IsSame (headerNames[i], "Gen") == SAME)
3792             whichIsX = i;
3793         }
3794     
3795     if (whichIsX < 0)
3796         {
3797         MrBayesPrint ("%s   Could not find a column labelled \"Gen\" \n", spacer);
3798         goto errorExit;
3799         }
3800     
3801     numPlotted = 0;
3802     for (n=0; n<nHeaders; n++)
3803         {
3804         strcpy (temp, headerNames[n]);
3805         whichIsY = -1;
3806         if (!strcmp(plotParams.match, "Perfect"))
3807             {
3808             if (IsSame (temp, plotParams.parameter) == SAME)
3809                 whichIsY = n;
3810             }
3811         else if (!strcmp(plotParams.match, "All"))
3812             {
3813             whichIsY = n;
3814             }
3815         else
3816             {
3817             if (IsSame (temp, plotParams.parameter) == CONSISTENT_WITH)
3818                 whichIsY = n;
3819             }
3820         
3821         if (whichIsY >= 0 && whichIsX != whichIsY)
3822             {
3823             MrBayesPrint ("\n%s   Rough trace plot of parameter %s:\n", spacer, headerNames[whichIsY]);
3824             if (PrintPlot (parameterSamples[whichIsX].values[0], parameterSamples[whichIsY].values[0], fileInfo.numRows) == ERROR)
3825                 goto errorExit;
3826             numPlotted++;
3827             }
3828         }
3829     
3830     if (numPlotted == 0)
3831         {
3832         MrBayesPrint ("%s   Did not find any parameters matching \"%s\" to plot\n", spacer, plotParams.parameter);
3833         }
3834     
3835     /* free memory */
3836     for (i=0; i<nHeaders; i++)
3837         free (headerNames[i]);
3838     free(headerNames);
3839     FreeParameterSamples(parameterSamples);
3840     
3841     expecting = Expecting(COMMAND);
3842     
3843     return (NO_ERROR);
3844     
3845 errorExit:
3846     
3847     /* free memory */
3848     for (i=0; i<nHeaders; i++)
3849         free (headerNames[i]);
3850     free(headerNames);
3851     FreeParameterSamples(parameterSamples);
3852     
3853     expecting = Expecting(COMMAND);
3854     
3855     return (ERROR);
3856 }
3857
3858
3859 int DoPlotParm (char *parmName, char *tkn)
3860 {
3861     int         tempI;
3862     MrBFlt      tempD;
3863     char        tempStr[100];
3864     
3865     if (defMatrix == NO)
3866         {
3867         MrBayesPrint ("%s   A matrix must be specified before sumt can be used\n", spacer);
3868         return (ERROR);
3869         }
3870     
3871     if (expecting == Expecting(PARAMETER))
3872         {
3873         expecting = Expecting(EQUALSIGN);
3874         }
3875     else
3876         {
3877         if (!strcmp(parmName, "Xxxxxxxxxx"))
3878             {
3879             expecting  = Expecting(PARAMETER);
3880             expecting |= Expecting(SEMICOLON);
3881             }
3882         /* set Filename (plotParams.plotFileName) ***************************************************/
3883         else if (!strcmp(parmName, "Filename"))
3884             {
3885             if (expecting == Expecting(EQUALSIGN))
3886                 {
3887                 expecting = Expecting(ALPHA);
3888                 readWord = YES;
3889                 }
3890             else if (expecting == Expecting(ALPHA))
3891                 {
3892                 strcpy (plotParams.plotFileName, tkn);
3893                 MrBayesPrint ("%s   Setting plot filename to %s\n", spacer, plotParams.plotFileName);
3894                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3895                 }
3896             else
3897                 return (ERROR);
3898             }
3899         /* set Relburnin (chainParams.relativeBurnin) ********************************************************/
3900         else if (!strcmp(parmName, "Relburnin"))
3901             {
3902             if (expecting == Expecting(EQUALSIGN))
3903                 expecting = Expecting(ALPHA);
3904             else if (expecting == Expecting(ALPHA))
3905                 {
3906                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3907                     {
3908                     if (!strcmp(tempStr, "Yes"))
3909                         chainParams.relativeBurnin = YES;
3910                     else
3911                         chainParams.relativeBurnin = NO;
3912                     }
3913                 else
3914                     {
3915                     MrBayesPrint ("%s   Invalid argument for Relburnin\n", spacer);
3916                     return (ERROR);
3917                     }
3918                 if (chainParams.relativeBurnin == YES)
3919                     MrBayesPrint ("%s   Using relative burnin (a fraction of samples discarded).\n", spacer);
3920                 else
3921                     MrBayesPrint ("%s   Using absolute burnin (a fixed number of samples discarded).\n", spacer);
3922                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3923                 }
3924             else
3925                 {
3926                 return (ERROR);
3927                 }
3928             }
3929         /* set Burnin (chainParams.chainBurnIn) *******************************************************/
3930         else if (!strcmp(parmName, "Burnin"))
3931             {
3932             if (expecting == Expecting(EQUALSIGN))
3933                 expecting = Expecting(NUMBER);
3934             else if (expecting == Expecting(NUMBER))
3935                 {
3936                 sscanf (tkn, "%d", &tempI);
3937                 chainParams.chainBurnIn = tempI;
3938                 MrBayesPrint ("%s   Setting burnin to %d\n", spacer, chainParams.chainBurnIn);
3939                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3940                 }
3941             else
3942                 return (ERROR);
3943             }
3944         /* set Burninfrac (chainParams.burninFraction) ************************************************************/
3945         else if (!strcmp(parmName, "Burninfrac"))
3946             {
3947             if (expecting == Expecting(EQUALSIGN))
3948                 expecting = Expecting(NUMBER);
3949             else if (expecting == Expecting(NUMBER))
3950                 {
3951                 sscanf (tkn, "%lf", &tempD);
3952                 if (tempD < 0.01)
3953                     {
3954                     MrBayesPrint ("%s   Burnin fraction too low (< 0.01)\n", spacer);
3955                     return (ERROR);
3956                     }
3957                 if (tempD > 0.50)
3958                     {
3959                     MrBayesPrint ("%s   Burnin fraction too high (> 0.50)\n", spacer);
3960                     return (ERROR);
3961                     }
3962                 chainParams.burninFraction = tempD;
3963                 MrBayesPrint ("%s   Setting burnin fraction to %.2f\n", spacer, chainParams.burninFraction);
3964                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3965                 }
3966             else
3967                 {
3968                 return (ERROR);
3969                 }
3970             }
3971         /* set Parameter (plotParams.parameter) *******************************************************/
3972         else if (!strcmp(parmName, "Parameter"))
3973             {
3974             if (expecting == Expecting(EQUALSIGN))
3975                 {
3976                 expecting = Expecting(ALPHA);
3977                 readWord = YES;
3978                 }
3979             else if (expecting == Expecting(ALPHA))
3980                 {
3981                 strcpy (plotParams.parameter, tkn);
3982                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3983                 }
3984             else
3985                 return (ERROR);
3986             }
3987         /* set Parameter (plotParams.match) *******************************************************/
3988         else if (!strcmp(parmName, "Match"))
3989             {
3990             if (expecting == Expecting(EQUALSIGN))
3991                 expecting = Expecting(ALPHA);
3992             else if (expecting == Expecting(ALPHA))
3993                 {
3994                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3995                     strcpy (plotParams.match, tempStr);
3996                 else
3997                     return (ERROR);
3998                 
3999                 MrBayesPrint ("%s   Setting plot matching to %s\n", spacer, plotParams.match);
4000                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4001                 }
4002             else
4003                 return (ERROR);
4004             }
4005         
4006         else
4007             return (ERROR);
4008         }
4009     
4010     return (NO_ERROR);
4011 }
4012
4013
4014 int DoPropset (void)
4015 {
4016     MrBayesPrint ("%s   Successfully set proposal parameters\n", spacer);
4017     
4018     return (NO_ERROR);
4019 }
4020
4021
4022 int DoPropsetParm (char *parmName, char *tkn)
4023 {
4024     int                 i, j, k, nMatches, tempInt;
4025     MrBFlt              tempFloat;
4026     static MCMCMove     *mv = NULL;
4027     static MrBFlt       *theValue, theValueMin, theValueMax;
4028     static int          jump, runIndex, chainIndex;
4029     static char         *temp=NULL, *localTkn=NULL; /*freed at the end of the call*/
4030     static char         *tempName=NULL;         /*not freed at the end of the call*/
4031
4032     if (defMatrix == NO)
4033         {
4034         MrBayesPrint ("%s   A matrix must be specified before proposal parameters can be changed\n", spacer);
4035         return (ERROR);
4036         }
4037
4038     if (expecting == Expecting(PARAMETER))
4039         {
4040         if (!strcmp(parmName, "Xxxxxxxxxx"))
4041             {
4042             /* we expect a move name with possible run and chain specification as follows:
4043                <move_name>$<tuning_param_name>(<run>,<chain>)=<number>   -- apply to run <run> and chain <chain>
4044                <move_name>$<tuning_param_name>(,<chain>)=<number>        -- apply to chain <chain> for all runs
4045                <move_name>$<tuning_param_name>(<run>,)=<number>          -- apply to all chains of run <run>
4046                <move_name>$prob(<run>,<chain>)=<number>                  -- change relative proposal probability
4047                <move_name>$targetrate(<run>,<chain>)=<number>            -- change target acc rate for autotuning
4048
4049                the parsing is complicated by the fact that the move name can look something like:
4050                eTBR(Tau{all})
4051                eTBR(Tau{1,4,5})
4052                so we need to assemble the move name from several tokens that are parsed out separately;
4053                here we receive only the first part (before the left parenthesis)
4054             */
4055             
4056             /* copy to local move name */
4057             SafeStrcpy(&tempName, tkn);
4058             mv = NULL;
4059             foundComma = foundEqual = NO;
4060             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4061                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4062                 Expecting(DOLLAR);
4063             }
4064         else
4065             return (ERROR);
4066         }
4067     else if (expecting == Expecting(ALPHA))
4068         {
4069         if (mv == NULL)
4070             {
4071             /* we are still assembling the move name */
4072             SafeStrcat(&tempName, tkn);
4073             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4074                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4075                 Expecting(DOLLAR);
4076             }
4077         else
4078             {
4079             /* we have a parameter name; now find the parameter name, case insensitive */
4080             SafeStrcpy(&localTkn, tkn);
4081             for (i=0; i<(int)strlen(localTkn); i++)
4082                 localTkn[i] = tolower(localTkn[i]);
4083             nMatches = j = 0;
4084             for (i=0; i<mv->moveType->numTuningParams; i++)
4085                 {
4086                 SafeStrcpy(&temp, mv->moveType->shortTuningName[i]);
4087                 for (k=0; k<(int)strlen(temp); k++)
4088                     temp[k] = tolower(temp[k]);
4089                 if (strncmp(localTkn,temp,strlen(localTkn)) == 0)
4090                     {
4091                     j = i;
4092                     nMatches++;
4093                     }
4094                 }
4095             if (strncmp(localTkn,"prob",strlen(localTkn)) == 0)
4096                 {
4097                 j = -1;
4098                 nMatches++;
4099                 }
4100             else if (strncmp(localTkn,"targetrate",strlen(localTkn)) == 0)
4101                 {
4102                 j = -2;
4103                 nMatches++;
4104                 }
4105             if (nMatches == 0)
4106                 {
4107                 MrBayesPrint ("%s   Could not find move parameter to change '%s'\n", spacer, localTkn);  
4108                 return (ERROR);
4109                 }
4110             else if (nMatches > 1)
4111                 {
4112                 MrBayesPrint ("%s   Several move parameters matched the abbreviated name '%s'\n", spacer, localTkn);
4113                 return (ERROR);
4114                 }
4115             
4116             if (j == -1)
4117                 {
4118                 theValue = mv->relProposalProb;
4119                 theValueMin = 0.0;
4120                 theValueMax = 1000.0;
4121                 jump = 1;
4122                 }
4123             else if (j == -2)
4124                 {
4125                 theValue = mv->targetRate;
4126                 theValueMin = 0.10;
4127                 theValueMax = 0.70;
4128                 jump = 1;
4129                 }
4130             else
4131                 {
4132                 theValue = &mv->tuningParam[0][j];
4133                 theValueMin = mv->moveType->minimum[j];
4134                 theValueMax = mv->moveType->maximum[j];
4135                 jump = mv->moveType->numTuningParams;
4136                 }
4137             chainIndex = -1;
4138             runIndex = -1;
4139             expecting = Expecting(LEFTPAR) | Expecting(EQUALSIGN);
4140             }
4141         }
4142     else if (expecting == Expecting(LEFTCURL) || expecting == Expecting(RIGHTCURL))
4143         {
4144         /* we are still assembling the move name */
4145         SafeStrcat (&tempName, tkn);
4146         expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4147             Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4148             Expecting(DOLLAR);
4149         }
4150     else if (expecting == Expecting(DOLLAR))
4151         {
4152         /* we know that the name is complete now; find the move by its name, 
4153            case insensitive */
4154         SafeStrcpy(&localTkn, tempName);
4155         j=(int)strlen(localTkn);
4156         for (i=0; i<j; i++)
4157             localTkn[i] = tolower(localTkn[i]);
4158             
4159         /* find the move */
4160         nMatches = j = 0;
4161         for (i=0; i<numApplicableMoves; i++)
4162             {
4163             mv = moves[i];
4164             SafeStrcpy(&temp,mv->name);
4165             for (k=0; k<(int)strlen(temp); k++)
4166                 temp[k] = tolower(temp[k]);
4167             if (strncmp(temp,localTkn,strlen(localTkn)) == 0)
4168                 {
4169                 j = i;
4170                 nMatches++;
4171                 }
4172             }
4173         if (nMatches == 0)
4174             {
4175             MrBayesPrint ("%s   Could not find move '%s'\n", spacer, localTkn);   
4176             return (ERROR);
4177             }
4178         else if (nMatches > 1)
4179             {
4180             MrBayesPrint ("%s   Several moves matched the abbreviated name '%s'\n", spacer, localTkn);   
4181             return (ERROR);
4182             }
4183         else
4184             mv = moves[j];
4185
4186         foundComma = foundEqual = NO;
4187         expecting = Expecting(ALPHA);
4188         }
4189     else if (expecting == Expecting(LEFTPAR))
4190         {
4191         if (mv == NULL)
4192             {
4193             /* we are still assembling the move name */
4194             SafeStrcat (&tempName, tkn);
4195             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4196                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4197                 Expecting(DOLLAR);
4198             }
4199         else /* if (mv != NULL) */
4200             {
4201             /* we will be reading in run and chain indices */
4202             expecting = Expecting(NUMBER) | Expecting(COMMA);
4203             }
4204         }
4205     else if (expecting == Expecting(NUMBER))
4206         {
4207         if (mv == NULL)
4208             {
4209             /* we are still assembling the move name */
4210             SafeStrcat (&tempName, tkn);
4211             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4212                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4213                 Expecting(DOLLAR);
4214             }
4215         else if (foundEqual == YES)
4216             {
4217             sscanf (tkn, "%lf", &tempFloat);
4218             if (tempFloat < theValueMin || tempFloat > theValueMax)
4219                 {
4220                 MrBayesPrint ("%s   The value is out of range (min = %lf; max = %lf)\n", spacer, theValueMin, theValueMax);
4221                 return (ERROR);
4222                 }
4223             if (runIndex == -1 && chainIndex == -1)
4224                 {
4225                 for (i=0; i<chainParams.numRuns; i++)
4226                     {
4227                     for (j=0; j<chainParams.numChains; j++)
4228                         {
4229                         *theValue = tempFloat;
4230                         theValue += jump;
4231                         }
4232                     }
4233                 }
4234             else if (runIndex == -1 && chainIndex >= 0)
4235                 {
4236                 theValue += chainIndex*jump;
4237                 for (i=0; i<chainParams.numRuns; i++)
4238                     {
4239                     *theValue = tempFloat;
4240                     theValue += chainParams.numChains*jump;
4241                     }
4242                 }
4243             else if (runIndex >= 0 && chainIndex == -1)
4244                 {
4245                 theValue += runIndex*chainParams.numChains*jump;
4246                 for (i=0; i<chainParams.numChains; i++)
4247                     {
4248                     *theValue = tempFloat;
4249                     theValue += jump;
4250                     }
4251                 }
4252             else /* if (runIndex >= 0 && chainIndex >= 0) */
4253                 {
4254                 theValue[runIndex*chainParams.numChains*jump+chainIndex*jump] = tempFloat;
4255                 }
4256             expecting = Expecting (PARAMETER) | Expecting(SEMICOLON);
4257             }
4258         else /* if (foundEqual == NO) */
4259             {
4260             sscanf (tkn, "%d", &tempInt);
4261             if (foundComma == NO)
4262                 {
4263                 if (tempInt <= 0 || tempInt > chainParams.numRuns)
4264                     {
4265                     MrBayesPrint ("%s   Run index is out of range (min=1; max=%d)\n", spacer, chainParams.numRuns);
4266                     return (ERROR);
4267                     }
4268                 runIndex = tempInt - 1;
4269                 expecting = Expecting(COMMA);
4270                 }
4271             else
4272                 {
4273                 if (tempInt <= 0 || tempInt > chainParams.numChains)
4274                     {
4275                     MrBayesPrint ("%s   Chain index is out of range (min=1; max=%d)\n", spacer, chainParams.numChains);
4276                     return (ERROR);
4277                     }
4278                 chainIndex = tempInt - 1;
4279                 expecting = Expecting(RIGHTPAR);
4280                 }
4281             }
4282         }
4283     else if (expecting == Expecting(COMMA))
4284         {
4285         if (mv == NULL)
4286             {
4287             /* we are still assembling the move name */
4288             SafeStrcat (&tempName, tkn);
4289             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4290                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4291                 Expecting(DOLLAR);
4292             }
4293         else
4294             {
4295             /* we will be reading in chain index, if present */
4296             foundComma = YES;
4297             expecting = Expecting(RIGHTPAR) | Expecting(NUMBER);
4298             }
4299         }
4300     else if (expecting == Expecting(RIGHTPAR))
4301         {
4302         if (mv == NULL)
4303             {
4304             /* we are still assembling the move name */
4305             SafeStrcat (&tempName, tkn);
4306             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4307                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4308                 Expecting(DOLLAR);
4309             }
4310         else
4311             expecting = Expecting(EQUALSIGN);
4312         }
4313     else if (expecting == Expecting(EQUALSIGN))
4314         {
4315         foundEqual = YES;
4316         expecting = Expecting(NUMBER);
4317         }
4318     else
4319         return (ERROR);
4320
4321     SafeFree ((void **)&temp);
4322     SafeFree ((void **)&localTkn);
4323     return (NO_ERROR);
4324 }
4325
4326
4327 int DoPrset (void)
4328 {
4329     int         i, nApplied, lastActive=0;
4330
4331     nApplied = NumActiveParts ();
4332     for (i=numCurrentDivisions-1; i>=0; i--)
4333         {
4334         if (activeParts[i] == YES)
4335             {
4336             lastActive = i;
4337             break;
4338             }
4339         }
4340             
4341     if (numCurrentDivisions == 1)
4342         MrBayesPrint ("%s   Successfully set prior model parameters\n", spacer);
4343     else 
4344         {
4345         if (nApplied == numCurrentDivisions || nApplied == 0)
4346             {
4347             MrBayesPrint ("%s   Successfully set prior model parameters to all\n", spacer);
4348             MrBayesPrint ("%s   applicable data partitions \n", spacer);
4349             }
4350         else
4351             {
4352             MrBayesPrint ("%s   Successfully set prior model parameters to\n", spacer);
4353             if (nApplied == 1)
4354                 MrBayesPrint ("%s   partition", spacer);
4355             else
4356                 MrBayesPrint ("%s   partitions", spacer);
4357             for (i=0; i<numCurrentDivisions; i++)
4358                 {
4359                 if (activeParts[i] == YES)
4360                     {
4361                     if (i == lastActive && nApplied > 1)
4362                         MrBayesPrint (" and %d", i+1);
4363                     else
4364                         MrBayesPrint (" %d", i+1);
4365                     if (nApplied > 2 && i != lastActive)
4366                         MrBayesPrint (",");
4367                     }
4368                 }
4369             MrBayesPrint (" (if applicable)\n");
4370             }
4371         }
4372     
4373     if (SetUpAnalysis (&globalSeed) == ERROR)
4374         return (ERROR);
4375
4376     return (NO_ERROR);
4377 }
4378
4379
4380 int DoPrsetParm (char *parmName, char *tkn)
4381 {
4382     int         i, j, k, tempInt, nApplied, index, ns, flag=0;
4383     MrBFlt      tempD, sum;
4384     char        tempStr[100];
4385
4386     if (defMatrix == NO)
4387         {
4388         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
4389         return (ERROR);
4390         }
4391     if (inValidCommand == YES)
4392         {
4393         for (i=0; i<numCurrentDivisions; i++)
4394             activeParts[i] = NO;
4395         inValidCommand = NO;
4396         }
4397
4398     if (expecting == Expecting(PARAMETER))
4399         {
4400         expecting = Expecting(EQUALSIGN);
4401         }
4402     else
4403         {
4404         /* set Applyto (Applyto) *************************************************************/
4405         if (!strcmp(parmName, "Applyto"))
4406             {
4407             if (expecting == Expecting(EQUALSIGN))
4408                 expecting = Expecting(LEFTPAR);
4409             else if (expecting == Expecting(LEFTPAR))
4410                 {
4411                 for (i=0; i<numCurrentDivisions; i++)
4412                     activeParts[i] = NO;
4413                 fromI = toJ = -1;
4414                 foundDash = NO;
4415                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
4416                 }
4417             else if (expecting == Expecting(RIGHTPAR))
4418                 {
4419                 if (fromI != -1)
4420                     activeParts[fromI-1] = YES;
4421 #               if 0
4422                 for (i=0; i<numCurrentDivisions; i++)
4423                     MrBayesPrint("%d ", activeParts[i]);
4424                 MrBayesPrint ("\n");
4425 #               endif
4426                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4427                 }
4428             else if (expecting == Expecting(COMMA))
4429                 {
4430                 foundComma = YES;
4431                 expecting = Expecting(NUMBER);
4432                 }
4433             else if (expecting == Expecting(ALPHA))
4434                 {
4435                 if (IsSame ("All", tkn) == DIFFERENT)
4436                     {
4437                     MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
4438                     return (ERROR);
4439                     }
4440                 for (i=0; i<numCurrentDivisions; i++)
4441                     activeParts[i] = YES;
4442                 expecting  = Expecting(RIGHTPAR);
4443                 }
4444             else if (expecting == Expecting(NUMBER))
4445                 {
4446                 sscanf (tkn, "%d", &tempInt);
4447                 if (tempInt > numCurrentDivisions)
4448                     {
4449                     MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
4450                     return (ERROR);
4451                     }
4452                 if (fromI == -1)
4453                     fromI = tempInt;
4454                 else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
4455                     {
4456                     toJ = tempInt;
4457                     for (i=fromI-1; i<toJ; i++)
4458                         activeParts[i] = YES;
4459                     fromI = toJ = -1;
4460                     foundDash = NO;
4461                     }
4462                 else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
4463                     {
4464                     activeParts[fromI-1] = YES;
4465                     fromI = tempInt;
4466                     foundComma = NO;
4467                     }
4468                     
4469                 expecting  = Expecting(COMMA);
4470                 expecting |= Expecting(DASH);
4471                 expecting |= Expecting(RIGHTPAR);
4472                 }
4473             else if (expecting == Expecting(DASH))
4474                 {
4475                 foundDash = YES;
4476                 expecting = Expecting(NUMBER);
4477                 }
4478             else
4479                 return (ERROR);
4480             }
4481         /* set Tratiopr (tRatioPr) ************************************************************/
4482         else if (!strcmp(parmName, "Tratiopr"))
4483             {
4484             if (expecting == Expecting(EQUALSIGN))
4485                 expecting = Expecting(ALPHA);
4486             else if (expecting == Expecting(ALPHA))
4487                 {
4488                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4489                     {
4490                     nApplied = NumActiveParts ();
4491                     flag = 0;
4492                     for (i=0; i<numCurrentDivisions; i++)
4493                         {
4494                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4495                             {
4496                             strcpy(modelParams[i].tRatioPr, tempStr);
4497                             modelParams[i].tRatioDir[0] = modelParams[i].tRatioDir[1] = 1.0;
4498                             modelParams[i].tRatioFix = 1.0;
4499                             flag = 1;
4500                             }
4501                         }
4502                     if (flag == 0)
4503                         {
4504                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
4505                             Currently there is no active partition with such data.\n", spacer, parmName);
4506                         return (ERROR);
4507                         }
4508                     }
4509                 else
4510                     {
4511                     MrBayesPrint ("%s   Invalid Tratiopr argument \n", spacer);
4512                     return (ERROR);
4513                     }
4514                 expecting  = Expecting(LEFTPAR);
4515                 for (i=0; i<numCurrentDivisions; i++)
4516                     numVars[i] = 0;
4517                 }
4518             else if (expecting == Expecting(LEFTPAR))
4519                 {
4520                 expecting  = Expecting(NUMBER);
4521                 }
4522             else if (expecting == Expecting(NUMBER))
4523                 {
4524                 nApplied = NumActiveParts ();
4525                 for (i=0; i<numCurrentDivisions; i++)
4526                     {
4527                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4528                         {
4529                         if (!strcmp(modelParams[i].tRatioPr,"Beta"))
4530                             {
4531                             sscanf (tkn, "%lf", &tempD);
4532                             if (tempD > ALPHA_MAX)
4533                                 {
4534                                 MrBayesPrint ("%s   Beta parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
4535                                 return (ERROR);
4536                                 }
4537                             if (tempD < ALPHA_MIN)
4538                                 {
4539                                 MrBayesPrint ("%s   Beta parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
4540                                 return (ERROR);
4541                                 }
4542                             modelParams[i].tRatioDir[numVars[i]++] = tempD;
4543                             if (numVars[i] < 2)
4544                                 expecting = Expecting(COMMA);
4545                             else
4546                                 {
4547                                 if (nApplied == 0 && numCurrentDivisions == 1)
4548                                     MrBayesPrint ("%s   Setting Tratiopr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].tRatioDir[0], modelParams[i].tRatioDir[1]);
4549                                 else
4550                                     MrBayesPrint ("%s   Setting Tratiopr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].tRatioDir[0], modelParams[i].tRatioDir[1], i+1);
4551                                 expecting  = Expecting(RIGHTPAR);
4552                                 }
4553                             }
4554                         else if (!strcmp(modelParams[i].tRatioPr,"Fixed"))
4555                             {
4556                             sscanf (tkn, "%lf", &tempD);
4557                             modelParams[i].tRatioFix = tempD;
4558                             if (modelParams[i].tRatioFix > KAPPA_MAX)
4559                                 {
4560                                 MrBayesPrint ("%s   Tratio cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
4561                                 return (ERROR);
4562                                 }
4563                             if (modelParams[i].tRatioFix < 0.0)
4564                                 {
4565                                 MrBayesPrint ("%s   Tratio cannot be less than %1.2lf\n", spacer, 0.0);
4566                                 return (ERROR);
4567                                 }
4568                             if (nApplied == 0 && numCurrentDivisions == 1)
4569                                 MrBayesPrint ("%s   Setting Tratiopr to Fixed(%1.2lf)\n", spacer, modelParams[i].tRatioFix);
4570                             else
4571                                 MrBayesPrint ("%s   Setting Tratiopr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].tRatioFix, i+1);
4572                             expecting  = Expecting(RIGHTPAR);
4573                             }
4574                         }
4575                     }
4576                 }
4577             else if (expecting == Expecting(COMMA))
4578                 {
4579                 expecting  = Expecting(NUMBER);
4580                 }
4581             else if (expecting == Expecting(RIGHTPAR))
4582                 {
4583                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4584                 }
4585             else
4586                 return (ERROR);
4587             }
4588         /* set Revmatpr (revMatPr) ************************************************************/
4589         else if (!strcmp(parmName, "Revmatpr"))
4590             {
4591             if (expecting == Expecting(EQUALSIGN))
4592                 expecting = Expecting(ALPHA);
4593             else if (expecting == Expecting(ALPHA))
4594                 {
4595                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4596                     {
4597                     nApplied = NumActiveParts ();
4598                     flag = 0;
4599                     for (i=0; i<numCurrentDivisions; i++)
4600                         {
4601                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4602                             {
4603                             strcpy(modelParams[i].revMatPr, tempStr);
4604                             modelParams[i].revMatDir[0] = modelParams[i].revMatDir[1] = 1.0;
4605                             modelParams[i].revMatDir[2] = modelParams[i].revMatDir[3] = 1.0;
4606                             modelParams[i].revMatDir[4] = modelParams[i].revMatDir[5] = 1.0;
4607                             flag = 1;
4608                             }
4609                         }
4610                     if (flag == 0)
4611                         {
4612                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
4613                             Currently there is no active partition with such data.\n", spacer, parmName);
4614                         return (ERROR);
4615                         }
4616                     }
4617                 else
4618                     {
4619                     MrBayesPrint ("%s   Invalid Revmatpr argument\n", spacer);
4620                     return (ERROR);
4621                     }
4622                 expecting  = Expecting(LEFTPAR);
4623                 tempNumStates = 0;
4624                 }
4625             else if (expecting == Expecting(LEFTPAR))
4626                 {
4627                 expecting  = Expecting(NUMBER);
4628                 }
4629             else if (expecting == Expecting(NUMBER))
4630                 {
4631                 /* find out what type of prior is being set */
4632                 nApplied = NumActiveParts ();
4633                 for (i=0; i<numCurrentDivisions; i++)
4634                     {
4635                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4636                         strcpy (tempStr,modelParams[i].revMatPr);
4637                     }
4638                 /* find and store the number */
4639                 sscanf (tkn, "%lf", &tempD);
4640                 if (!strcmp(tempStr,"Dirichlet"))
4641                     {
4642                     if (tempD > ALPHA_MAX)
4643                         {
4644                         MrBayesPrint ("%s   Dirichlet parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
4645                         return (ERROR);
4646                         }
4647                     if (tempD < ALPHA_MIN)
4648                         {
4649                         MrBayesPrint ("%s   Dirichlet parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
4650                         return (ERROR);
4651                         }
4652                     }
4653                 else if (!strcmp(tempStr,"Fixed"))
4654                     {
4655                     if (tempD > KAPPA_MAX)
4656                         {
4657                         MrBayesPrint ("%s   Rate value cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
4658                         return (ERROR);
4659                         }
4660                     if (tempD < 0.0001)
4661                         {
4662                         MrBayesPrint ("%s   Rate value cannot be less than %1.2lf\n", spacer, 0.0001);
4663                         return (ERROR);
4664                         }
4665                     }
4666                 tempNum[tempNumStates++] = tempD;
4667                 if (tempNumStates == 1 && !strcmp(tempStr,"Dirichlet"))
4668                     expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
4669                 else if (tempNumStates < 6)
4670                     expecting  = Expecting(COMMA);
4671                 else
4672                     expecting = Expecting(RIGHTPAR);
4673                 }
4674             else if (expecting == Expecting(COMMA))
4675                 {
4676                 expecting  = Expecting(NUMBER);
4677                 }
4678             else if (expecting == Expecting(RIGHTPAR))
4679                 {
4680                 nApplied = NumActiveParts ();
4681                 for (i=0; i<numCurrentDivisions; i++)
4682                     {
4683                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4684                         {
4685                         if (!strcmp(modelParams[i].revMatPr,"Dirichlet"))
4686                             {
4687                             for (j=0; j<6; j++)
4688                                 {
4689                                 if (tempNumStates == 1)
4690                                     modelParams[i].revMatDir[j] = tempNum[0] / (MrBFlt) 6.0;
4691                                 else
4692                                     modelParams[i].revMatDir[j] = tempNum[j];
4693                                 }
4694
4695                             if (nApplied == 0 && numCurrentDivisions == 1)
4696                                 MrBayesPrint ("%s   Setting Revmatpr to Dirichlet(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer, 
4697                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
4698                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5]);
4699                             else
4700                                 MrBayesPrint ("%s   Setting Revmatpr to Dirichlet(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf) for partition %d\n", spacer, 
4701                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
4702                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5], i+1);
4703                             }
4704                         else if (!strcmp(modelParams[i].revMatPr,"Fixed"))
4705                             {
4706                             for (j=0; j<6; j++)
4707                                 modelParams[i].revMatFix[j] = tempNum[j];
4708                             if (nApplied == 0 && numCurrentDivisions == 1)
4709                                 MrBayesPrint ("%s   Setting Revmatpr to Fixed(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer, 
4710                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
4711                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5]);
4712                             else
4713                                 MrBayesPrint ("%s   Setting Revmatpr to Fixed(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf) for partition %d\n", spacer, 
4714                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
4715                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5], i+1);
4716                             }
4717                         }
4718                     }
4719                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4720                 }
4721             else
4722                 return (ERROR);
4723             }
4724         /* set Aarevmatpr (aaRevMatPr) ********************************************************/
4725         else if (!strcmp(parmName, "Aarevmatpr"))
4726             {
4727             if (expecting == Expecting(EQUALSIGN))
4728                 expecting = Expecting(ALPHA);
4729             else if (expecting == Expecting(ALPHA))
4730                 {
4731                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4732                     {
4733                     nApplied = NumActiveParts ();
4734                     flag = 0;
4735                     for (i=0; i<numCurrentDivisions; i++)
4736                         {
4737                         if ((activeParts[i] == YES || nApplied == 0) && modelSettings[i].dataType == PROTEIN)
4738                             {
4739                             strcpy(modelParams[i].aaRevMatPr, tempStr);
4740                             for (j=0; j<190; j++)
4741                                 modelParams[i].aaRevMatDir[j] = 1.0;
4742                             flag = 1;
4743                             }
4744                         }
4745                     if (flag == 0)
4746                         {
4747                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing PROTEIN.\
4748                             Currently there is no active partition with such data.\n", spacer, parmName);
4749                         return (ERROR);
4750                         }
4751                     }
4752                 else
4753                     {
4754                     MrBayesPrint ("%s   Invalid Aarevmatpr argument\n", spacer);
4755                     return (ERROR);
4756                     }
4757                 expecting  = Expecting(LEFTPAR);
4758                 tempNumStates = 0;
4759                 }
4760             else if (expecting == Expecting(LEFTPAR))
4761                 {
4762                 expecting  = Expecting(NUMBER);
4763                 }
4764             else if (expecting == Expecting(NUMBER))
4765                 {
4766                 /* find out what type of prior is being set */
4767                 nApplied = NumActiveParts ();
4768                 for (i=0; i<numCurrentDivisions; i++)
4769                     {
4770                     if ((activeParts[i] == YES || nApplied == 0) && modelSettings[i].dataType == PROTEIN)
4771                         strcpy (tempStr,modelParams[i].aaRevMatPr);
4772                     }
4773                 /* find and store the number */
4774                 sscanf (tkn, "%lf", &tempD);
4775                 if (!strcmp(tempStr,"Dirichlet"))
4776                     {
4777                     if (tempD > ALPHA_MAX)
4778                         {
4779                         MrBayesPrint ("%s   Dirichlet parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
4780                         return (ERROR);
4781                         }
4782                     if (tempD < ALPHA_MIN)
4783                         {
4784                         MrBayesPrint ("%s   Dirichlet parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
4785                         return (ERROR);
4786                         }
4787                     }
4788                 else if (!strcmp(tempStr,"Fixed"))
4789                     {
4790                     if (tempD > KAPPA_MAX)
4791                         {
4792                         MrBayesPrint ("%s   Rate value cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
4793                         return (ERROR);
4794                         }
4795                     if (tempD < 0.0001)
4796                         {
4797                         MrBayesPrint ("%s   Rate value cannot be less than %1.2lf\n", spacer, 0.0001);
4798                         return (ERROR);
4799                         }
4800                     }
4801                 tempStateFreqs[tempNumStates++] = tempD;
4802                 if (tempNumStates == 1 && !strcmp(tempStr,"Dirichlet"))
4803                     expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
4804                 else if (tempNumStates < 190)
4805                     expecting  = Expecting(COMMA);
4806                 else
4807                     expecting = Expecting(RIGHTPAR);
4808                 }
4809             else if (expecting == Expecting(COMMA))
4810                 {
4811                 expecting  = Expecting(NUMBER);
4812                 }
4813             else if (expecting == Expecting(RIGHTPAR))
4814                 {
4815                 nApplied = NumActiveParts ();
4816                 for (i=0; i<numCurrentDivisions; i++)
4817                     {
4818                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == PROTEIN)
4819                         {
4820                         if (!strcmp(modelParams[i].aaRevMatPr,"Dirichlet"))
4821                             {
4822                             for (j=0; j<190; j++)
4823                                 {
4824                                 if (tempNumStates == 1)
4825                                     modelParams[i].aaRevMatDir[j] = tempStateFreqs[0] / (MrBFlt) 190.0;
4826                                 else
4827                                     modelParams[i].aaRevMatDir[j] = tempStateFreqs[j];
4828                                 }
4829                             if (nApplied == 0 && numCurrentDivisions == 1)
4830                                 {
4831                                 for (j=0; j<190; j++)
4832                                     if (AreDoublesEqual(modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[j], 0.00001) == NO)
4833                                         break;
4834                                 if (j == 190)
4835                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(%1.2lf,%1.2lf,...)\n", spacer,
4836                                         modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[0]);
4837                                 else
4838                                     {
4839                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(\n", spacer);
4840                                     for (j=0; j<190; j++)
4841                                         {
4842                                         if (j % 10 == 0)
4843                                             MrBayesPrint ("%s      ", spacer);
4844                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatDir[j]);
4845                                         if (j == 189)
4846                                             MrBayesPrint (")\n");
4847                                         else if ((j+1) % 10 == 0)
4848                                             MrBayesPrint (",\n");
4849                                         else
4850                                             MrBayesPrint (",");
4851                                         }
4852                                     }
4853                                 }
4854                             else
4855                                 {
4856                                 for (j=0; j<190; j++)
4857                                     if (AreDoublesEqual(modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[j], 0.00001) == NO)
4858                                         break;
4859                                 if (j == 190)
4860                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(%1.2lf,%1.2lf,...) for partition %d\n",
4861                                         spacer, modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[0], i+1);
4862                                 else
4863                                     {
4864                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(\n", spacer);
4865                                     for (j=0; j<190; j++)
4866                                         {
4867                                         if (j % 10 == 0)
4868                                             MrBayesPrint ("%s      ", spacer);
4869                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatDir[j]);
4870                                         if (j == 189)
4871                                             MrBayesPrint (")\n");
4872                                         else if ((j+1) % 10 == 0)
4873                                             MrBayesPrint (",\n");
4874                                         else
4875                                             MrBayesPrint (",");
4876                                         }
4877                                     }
4878                                     MrBayesPrint ("%s      for partition %d\n", spacer, i+1);
4879                                 }
4880                             }
4881                         else if (!strcmp(modelParams[i].aaRevMatPr,"Fixed"))
4882                             {
4883                             for (j=0; j<190; j++)
4884                                 modelParams[i].aaRevMatFix[j] = tempStateFreqs[j];
4885                             if (nApplied == 0 && numCurrentDivisions == 1)
4886                                 {
4887                                 for (j=0; j<190; j++)
4888                                     if (AreDoublesEqual(modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[j], 0.00001) == NO)
4889                                         break;
4890                                 if (j == 190)
4891                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(%1.2lf,%1.2lf,...)\n", spacer, modelParams[i].aaRevMatFix[0],
4892                                         modelParams[i].aaRevMatFix[0]);
4893                                 else
4894                                     {
4895                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(\n", spacer);
4896                                     for (j=0; j<190; j++)
4897                                         {
4898                                         if (j % 10 == 0)
4899                                             MrBayesPrint ("%s      ", spacer);
4900                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatFix[j]);
4901                                         if (j == 189)
4902                                             MrBayesPrint (")\n");
4903                                         else if ((j+1) % 10 == 0)
4904                                             MrBayesPrint (",\n");
4905                                         else
4906                                             MrBayesPrint (",");
4907                                         }
4908                                     }
4909                                 }
4910                             else
4911                                 {
4912                                 for (j=0; j<190; j++)
4913                                     if (AreDoublesEqual(modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[j], 0.00001) == NO)
4914                                         break;
4915                                 if (j == 190)
4916                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(%1.2lf,%1.2lf,...) for partition %d\n", spacer,
4917                                         modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[0], i+1);
4918                                 else
4919                                     {
4920                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(\n", spacer);
4921                                     for (j=0; j<190; j++)
4922                                         {
4923                                         if (j % 10 == 0)
4924                                             MrBayesPrint ("%s      ", spacer);
4925                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatFix[j]);
4926                                         if (j == 189)
4927                                             MrBayesPrint (")\n");
4928                                         else if ((j+1) % 10 == 0)
4929                                             MrBayesPrint (",\n");
4930                                         else
4931                                             MrBayesPrint (",");
4932                                         }
4933                                     }
4934                                     MrBayesPrint ("%s      for partition %d\n", spacer, i+1);
4935                                 }
4936                             }
4937                         }
4938                     }
4939                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4940                 }
4941             else
4942                 return (ERROR);
4943             }
4944         /* set Revratepr (revSymDirPr) ****************************************************/
4945         else if (!strcmp(parmName, "Revratepr"))
4946             {
4947             if (expecting == Expecting(EQUALSIGN))
4948                 expecting = Expecting(ALPHA);
4949             else if (expecting == Expecting(ALPHA))
4950                 {
4951                 if (IsArgValid(tkn, tempStr) == ERROR)  /* we only allow symmetric dirichlet prior, so no need to store the value */
4952                     {
4953                     MrBayesPrint ("%s   Invalid Revratepr argument\n", spacer);
4954                     return (ERROR);
4955                     }
4956                 expecting  = Expecting(LEFTPAR);
4957                 for (i=0; i<numCurrentDivisions; i++)
4958                     numVars[i] = 0;
4959                 }
4960             else if (expecting == Expecting(LEFTPAR))
4961                 {
4962                 expecting  = Expecting(NUMBER);
4963                 }
4964             else if (expecting == Expecting(NUMBER))
4965                 {
4966                 nApplied = NumActiveParts ();
4967                 for (i=0; i<numCurrentDivisions; i++)
4968                     {
4969                     if (activeParts[i] == YES || nApplied == 0)
4970                         {
4971                         sscanf (tkn, "%lf", &tempD);
4972                         if (tempD <= 0.0)
4973                             {
4974                             MrBayesPrint ("%s   Symmetric Dirichlet parameter must be positive\n", spacer);
4975                             return (ERROR);
4976                             }
4977                         modelParams[i].revMatSymDir = tempD;
4978                         if (nApplied == 0 && numCurrentDivisions == 1)
4979                             MrBayesPrint ("%s   Setting Revratepr to Symmetric Dirichlet(%1.2lf)\n", spacer, modelParams[i].revMatSymDir);
4980                         else
4981                             MrBayesPrint ("%s   Setting Revratepr to Symmetric Dirichlet(%1.2lf) for partition %d\n", spacer, modelParams[i].revMatSymDir, i+1);
4982                         expecting  = Expecting(RIGHTPAR);
4983                         }
4984                     }
4985                 }
4986             else if (expecting == Expecting(RIGHTPAR))
4987                 {
4988                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4989                 }
4990             else
4991                 return (ERROR);
4992             }
4993         /* set Omegapr (omegaPr) **************************************************************/
4994         else if (!strcmp(parmName, "Omegapr"))
4995             {
4996             if (expecting == Expecting(EQUALSIGN))
4997                 expecting = Expecting(ALPHA);
4998             else if (expecting == Expecting(ALPHA))
4999                 {
5000                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5001                     {
5002                     nApplied = NumActiveParts ();
5003                     flag = 0;
5004                     for (i=0; i<numCurrentDivisions; i++)
5005                         {
5006                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5007                             {
5008                             strcpy(modelParams[i].omegaPr, tempStr);
5009                             modelParams[i].omegaDir[0] = modelParams[i].omegaDir[1] = 1.0;
5010                             modelParams[i].omegaFix = 1.0;
5011                             flag = 1;
5012                             }
5013                         }
5014                     if (flag == 0)
5015                         {
5016                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5017                             Currently there is no active partition with such data.\n", spacer, parmName);
5018                         return (ERROR);
5019                         }
5020                     }
5021                 else
5022                     {
5023                     MrBayesPrint ("%s   Invalid Omegapr argument\n", spacer);
5024                     return (ERROR);
5025                     }
5026                 expecting  = Expecting(LEFTPAR);
5027                 for (i=0; i<numCurrentDivisions; i++)
5028                     numVars[i] = 0;
5029                 }
5030             else if (expecting == Expecting(LEFTPAR))
5031                 {
5032                 expecting  = Expecting(NUMBER);
5033                 }
5034             else if (expecting == Expecting(NUMBER))
5035                 {
5036                 nApplied = NumActiveParts ();
5037                 for (i=0; i<numCurrentDivisions; i++)
5038                     {
5039                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5040                         {
5041                         if (!strcmp(modelParams[i].omegaPr,"Dirichlet"))
5042                             {
5043                             sscanf (tkn, "%lf", &tempD);
5044                             if (tempD > ALPHA_MAX)
5045                                 {
5046                                 MrBayesPrint ("%s   Dirichlet parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
5047                                 return (ERROR);
5048                                 }
5049                             if (tempD < ALPHA_MIN)
5050                                 {
5051                                 MrBayesPrint ("%s   Dirichlet parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
5052                                 return (ERROR);
5053                                 }
5054                             modelParams[i].omegaDir[numVars[i]++] = tempD;
5055                             if (numVars[i] == 1)
5056                                 expecting = Expecting(COMMA);
5057                             else
5058                                 {
5059                                 if (nApplied == 0 && numCurrentDivisions == 1)
5060                                     MrBayesPrint ("%s   Setting Omegapr to Dirichlet(%1.2lf,%1.2lf)\n", spacer, modelParams[i].omegaDir[0], modelParams[i].omegaDir[1]);
5061                                 else
5062                                     MrBayesPrint ("%s   Setting Omegapr to Dirichlet(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].omegaDir[0], modelParams[i].omegaDir[1], i+1);
5063                                 expecting  = Expecting(RIGHTPAR);
5064                                 }
5065                             }
5066                         else if (!strcmp(modelParams[i].omegaPr,"Fixed"))
5067                             {
5068                             sscanf (tkn, "%lf", &tempD);
5069                             modelParams[i].omegaFix = tempD;
5070                             if (modelParams[i].omegaFix > KAPPA_MAX)
5071                                 {
5072                                 MrBayesPrint ("%s   Omega ratio cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
5073                                 return (ERROR);
5074                                 }
5075                             if (modelParams[i].omegaFix < 0.0)
5076                                 {
5077                                 MrBayesPrint ("%s   Omega ratio cannot be less than %1.2lf\n", spacer, 0.0);
5078                                 return (ERROR);
5079                                 }
5080                             if (nApplied == 0 && numCurrentDivisions == 1)
5081                                 MrBayesPrint ("%s   Setting Omegapr to Fixed(%1.2lf)\n", spacer, modelParams[i].omegaFix);
5082                             else
5083                                 MrBayesPrint ("%s   Setting Omegapr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].omegaFix, i+1);
5084                             expecting  = Expecting(RIGHTPAR);
5085                             }
5086                         }
5087                     }
5088                 }
5089             else if (expecting == Expecting(COMMA))
5090                 {
5091                 expecting  = Expecting(NUMBER);
5092                 }
5093             else if (expecting == Expecting(RIGHTPAR))
5094                 {
5095                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5096                 }
5097             else
5098                 return (ERROR);
5099             }
5100         /* set Ny98omega1pr (ny98omega1pr) ********************************************************/
5101         else if (!strcmp(parmName, "Ny98omega1pr"))
5102             {
5103             if (expecting == Expecting(EQUALSIGN))
5104                 expecting = Expecting(ALPHA);
5105             else if (expecting == Expecting(ALPHA))
5106                 {
5107                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5108                     {
5109                     nApplied = NumActiveParts ();
5110                     flag = 0;
5111                     for (i=0; i<numCurrentDivisions; i++)
5112                         {
5113                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5114                             {
5115                             strcpy(modelParams[i].ny98omega1pr, tempStr);
5116                             flag = 1;
5117                             }
5118                         }
5119                     if (flag == 0)
5120                         {
5121                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5122                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5123                         return (ERROR);
5124                         }
5125                     }
5126                 else
5127                     {
5128                     MrBayesPrint ("%s   Invalid Ny98omega1pr argument\n", spacer);
5129                     return (ERROR);
5130                     }
5131                 expecting  = Expecting(LEFTPAR);
5132                 for (i=0; i<numCurrentDivisions; i++)
5133                     numVars[i] = 0;
5134                 }
5135             else if (expecting == Expecting(LEFTPAR))
5136                 {
5137                 expecting  = Expecting(NUMBER);
5138                 }
5139             else if (expecting == Expecting(NUMBER))
5140                 {
5141                 nApplied = NumActiveParts ();
5142                 for (i=0; i<numCurrentDivisions; i++)
5143                     {
5144                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5145                         {
5146                         if (!strcmp(modelParams[i].ny98omega1pr,"Beta"))
5147                             {
5148                             sscanf (tkn, "%lf", &tempD);
5149                             modelParams[i].ny98omega1Beta[numVars[i]++] = tempD;
5150                             if (numVars[i] == 1)
5151                                 expecting  = Expecting(COMMA);
5152                             else
5153                                 {
5154                                 if (modelParams[i].ny98omega1Beta[0] < 0 || modelParams[i].ny98omega1Beta[1] < 0)
5155                                     {
5156                                     MrBayesPrint ("%s   Beta parameter should be greater than 0\n", spacer);
5157                                     return (ERROR);
5158                                     }
5159                                 if (nApplied == 0 && numCurrentDivisions == 1)
5160                                     MrBayesPrint ("%s   Setting Ny98omega1pr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].ny98omega1Beta[0], modelParams[i].ny98omega1Beta[1]);
5161                                 else
5162                                     MrBayesPrint ("%s   Setting Ny98omega1pr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega1Beta[0], modelParams[i].ny98omega1Beta[1], i+1);
5163                                 expecting  = Expecting(RIGHTPAR);
5164                                 }
5165                             }
5166                         else if (!strcmp(modelParams[i].ny98omega1pr,"Fixed"))
5167                             {
5168                             sscanf (tkn, "%lf", &tempD);
5169                             modelParams[i].ny98omega1Fixed = tempD;
5170                             if (nApplied == 0 && numCurrentDivisions == 1)
5171                                 MrBayesPrint ("%s   Setting Ny98omega1pr to Fixed(%1.2lf)\n", spacer, modelParams[i].ny98omega1Fixed);
5172                             else
5173                                 MrBayesPrint ("%s   Setting Ny98omega1pr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega1Fixed, i+1);
5174                             expecting  = Expecting(RIGHTPAR);
5175                             }
5176                         }
5177                     }
5178                 }
5179             else if (expecting == Expecting(COMMA))
5180                 {
5181                 expecting  = Expecting(NUMBER);
5182                 }
5183             else if (expecting == Expecting(RIGHTPAR))
5184                 {
5185                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5186                 }
5187             else
5188                 return (ERROR);
5189             }
5190         /* set Ny98omega3pr (ny98omega3pr) ********************************************************/
5191         else if (!strcmp(parmName, "Ny98omega3pr"))
5192             {
5193             if (expecting == Expecting(EQUALSIGN))
5194                 expecting = Expecting(ALPHA);
5195             else if (expecting == Expecting(ALPHA))
5196                 {
5197                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5198                     {
5199                     nApplied = NumActiveParts ();
5200                     flag = 0;
5201                     for (i=0; i<numCurrentDivisions; i++)
5202                         {
5203                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5204                             {
5205                             strcpy(modelParams[i].ny98omega3pr, tempStr);
5206                             flag = 1;
5207                             }
5208                         }
5209                     if (flag == 0)
5210                         {
5211                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5212                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5213                         return (ERROR);
5214                         }
5215                     }
5216                 else
5217                     {
5218                     MrBayesPrint ("%s   Invalid Ny98omega3pr argument\n", spacer);
5219                     return (ERROR);
5220                     }
5221                 expecting  = Expecting(LEFTPAR);
5222                 for (i=0; i<numCurrentDivisions; i++)
5223                     numVars[i] = 0;
5224                 }
5225             else if (expecting == Expecting(LEFTPAR))
5226                 {
5227                 expecting  = Expecting(NUMBER);
5228                 }
5229             else if (expecting == Expecting(NUMBER))
5230                 {
5231                 nApplied = NumActiveParts ();
5232                 for (i=0; i<numCurrentDivisions; i++)
5233                     {
5234                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5235                         {
5236                         if (!strcmp(modelParams[i].ny98omega3pr,"Uniform"))
5237                             {
5238                             sscanf (tkn, "%lf", &tempD);
5239                             modelParams[i].ny98omega3Uni[numVars[i]++] = tempD;
5240                             if (numVars[i] == 1)
5241                                 expecting  = Expecting(COMMA);
5242                             else
5243                                 {
5244                                 if (modelParams[i].ny98omega3Uni[0] >= modelParams[i].ny98omega3Uni[1])
5245                                     {
5246                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5247                                     return (ERROR);
5248                                     }
5249                                 if (nApplied == 0 && numCurrentDivisions == 1)
5250                                     MrBayesPrint ("%s   Setting Ny98omega3pr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].ny98omega3Uni[0], modelParams[i].ny98omega3Uni[1]);
5251                                 else
5252                                     MrBayesPrint ("%s   Setting Ny98omega3pr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega3Uni[0], modelParams[i].ny98omega3Uni[1], i+1);
5253                                 expecting  = Expecting(RIGHTPAR);
5254                                 }
5255                             }
5256                         else if (!strcmp(modelParams[i].ny98omega3pr,"Exponential"))
5257                             {
5258                             sscanf (tkn, "%lf", &tempD);
5259                             modelParams[i].ny98omega3Exp = tempD;
5260                             if (nApplied == 0 && numCurrentDivisions == 1)
5261                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Exponential(%1.2lf)\n", spacer, modelParams[i].ny98omega3Exp);
5262                             else
5263                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega3Exp, i+1);
5264                             expecting  = Expecting(RIGHTPAR);
5265                             }
5266                         else if (!strcmp(modelParams[i].ny98omega3pr,"Fixed"))
5267                             {
5268                             sscanf (tkn, "%lf", &tempD);
5269                             modelParams[i].ny98omega3Fixed = tempD;
5270                             if (nApplied == 0 && numCurrentDivisions == 1)
5271                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Fixed(%1.2lf)\n", spacer, modelParams[i].ny98omega3Fixed);
5272                             else
5273                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega3Fixed, i+1);
5274                             expecting  = Expecting(RIGHTPAR);
5275                             }
5276                         }
5277                     }
5278                 }
5279             else if (expecting == Expecting(COMMA))
5280                 {
5281                 expecting  = Expecting(NUMBER);
5282                 }
5283             else if (expecting == Expecting(RIGHTPAR))
5284                 {
5285                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5286                 }
5287             else
5288                 return (ERROR);
5289             }
5290         /* set M3omegapr (m3omegapr) ********************************************************/
5291         else if (!strcmp(parmName, "M3omegapr"))
5292             {
5293             if (expecting == Expecting(EQUALSIGN))
5294                 expecting = Expecting(ALPHA);
5295             else if (expecting == Expecting(ALPHA))
5296                 {
5297                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5298                     {
5299                     nApplied = NumActiveParts ();
5300                     flag = 0;
5301                     for (i=0; i<numCurrentDivisions; i++)
5302                         {
5303                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5304                             {
5305                             strcpy(modelParams[i].m3omegapr, tempStr);
5306                             flag = 1;
5307                             }
5308                         }
5309                     if (flag == 0)
5310                         {
5311                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5312                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5313                         return (ERROR);
5314                         }
5315                     }
5316                 else
5317                     {
5318                     MrBayesPrint ("%s   Invalid M3omegapr argument\n", spacer);
5319                     return (ERROR);
5320                     }
5321                 for (i=0; i<numCurrentDivisions; i++)
5322                     {
5323                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5324                         {
5325                         if (!strcmp(modelParams[i].m3omegapr,"Exponential"))
5326                             {
5327                             if (nApplied == 0 && numCurrentDivisions == 1)
5328                                 MrBayesPrint ("%s   Setting M3omegapr to Exponential\n", spacer);
5329                             else
5330                                 MrBayesPrint ("%s   Setting M3omegapr to Exponential for partition %d\n", spacer, i+1);
5331                             expecting  = Expecting(RIGHTPAR);
5332                             }
5333                         }
5334                     }
5335                 if (!strcmp(tempStr,"Exponential"))
5336                     expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5337                 else
5338                     expecting  = Expecting(LEFTPAR);
5339                 for (i=0; i<numCurrentDivisions; i++)
5340                     numVars[i] = 0;
5341                 }
5342             else if (expecting == Expecting(LEFTPAR))
5343                 {
5344                 expecting  = Expecting(NUMBER);
5345                 }
5346             else if (expecting == Expecting(NUMBER))
5347                 {
5348                 nApplied = NumActiveParts ();
5349                 for (i=0; i<numCurrentDivisions; i++)
5350                     {
5351                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5352                         {
5353                         if (!strcmp(modelParams[i].m3omegapr,"Fixed"))
5354                             {
5355                             sscanf (tkn, "%lf", &tempD);
5356                             modelParams[i].m3omegaFixed[numVars[i]++] = tempD;
5357                             if (numVars[i] == 1 || numVars[i] == 2)
5358                                 expecting  = Expecting(COMMA);
5359                             else
5360                                 {
5361                                 if (modelParams[i].m3omegaFixed[0] >= modelParams[i].m3omegaFixed[1] || modelParams[i].m3omegaFixed[0] >= modelParams[i].m3omegaFixed[2] || modelParams[i].m3omegaFixed[1] >= modelParams[i].m3omegaFixed[2])
5362                                     {
5363                                     MrBayesPrint ("%s   The three omega values must be ordered, such that omega1 < omega2 < omega3\n", spacer);
5364                                     return (ERROR);
5365                                     }
5366                                 if (nApplied == 0 && numCurrentDivisions == 1)
5367                                     MrBayesPrint ("%s   Setting M3omegapr to Fixed(%1.2lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].m3omegaFixed[0], modelParams[i].m3omegaFixed[1], modelParams[i].m3omegaFixed[2]);
5368                                 else
5369                                     MrBayesPrint ("%s   Setting M3omegapr to Fixed(%1.2lf,%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m3omegaFixed[0], modelParams[i].m3omegaFixed[1], modelParams[i].m3omegaFixed[2], i+1);
5370                                 expecting  = Expecting(RIGHTPAR);
5371                                 }
5372                             }
5373                         }
5374                     }
5375                 }
5376             else if (expecting == Expecting(COMMA))
5377                 {
5378                 expecting  = Expecting(NUMBER);
5379                 }
5380             else if (expecting == Expecting(RIGHTPAR))
5381                 {
5382                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5383                 }
5384             else
5385                 return (ERROR);
5386             }
5387         /* set Codoncatfreqs (codonCatFreqPr) ********************************************************/
5388         else if (!strcmp(parmName, "Codoncatfreqs"))
5389             {
5390             if (expecting == Expecting(EQUALSIGN))
5391                 expecting = Expecting(ALPHA);
5392             else if (expecting == Expecting(ALPHA))
5393                 {
5394                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5395                     {
5396                     nApplied = NumActiveParts ();
5397                     flag = 0;
5398                     for (i=0; i<numCurrentDivisions; i++)
5399                         {
5400                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5401                             {
5402                             strcpy(modelParams[i].codonCatFreqPr, tempStr);
5403                             flag = 1;
5404                             }
5405                         }
5406                     if (flag == 0)
5407                         {
5408                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5409                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5410                         return (ERROR);
5411                         }
5412                     }
5413                 else
5414                     {
5415                     MrBayesPrint ("%s   Invalid Omegapurpr argument\n", spacer);
5416                     return (ERROR);
5417                     }
5418                 expecting  = Expecting(LEFTPAR);
5419                 for (i=0; i<numCurrentDivisions; i++)
5420                     numVars[i] = 0;
5421                 }
5422             else if (expecting == Expecting(LEFTPAR))
5423                 {
5424                 expecting  = Expecting(NUMBER);
5425                 }
5426             else if (expecting == Expecting(NUMBER))
5427                 {
5428                 nApplied = NumActiveParts ();
5429                 for (i=0; i<numCurrentDivisions; i++)
5430                     {
5431                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5432                         {
5433                         if (!strcmp(modelParams[i].codonCatFreqPr,"Dirichlet"))
5434                             {
5435                             sscanf (tkn, "%lf", &tempD);
5436                             modelParams[i].codonCatDir[numVars[i]++] = tempD;
5437                             if (numVars[i] == 1 || numVars[i] == 2)
5438                                 expecting  = Expecting(COMMA);
5439                             else
5440                                 {
5441                                 if (nApplied == 0 && numCurrentDivisions == 1)
5442                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Dirichlet(%1.2lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].codonCatDir[0], modelParams[i].codonCatDir[1], modelParams[i].codonCatDir[2]);
5443                                 else
5444                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Dirichlet(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].codonCatDir[0], modelParams[i].codonCatDir[1], modelParams[i].codonCatDir[2], i+1);
5445                                 expecting  = Expecting(RIGHTPAR);
5446                                 }
5447                             }
5448                         else if (!strcmp(modelParams[i].codonCatFreqPr,"Fixed"))
5449                             {
5450                             sscanf (tkn, "%lf", &tempD);
5451                             modelParams[i].codonCatFreqFix[numVars[i]++] = tempD;
5452                             if (numVars[i] == 1 || numVars[i] == 2)
5453                                 expecting  = Expecting(COMMA);
5454                             else
5455                                 {
5456                                 if (AreDoublesEqual (modelParams[i].codonCatFreqFix[0] + modelParams[i].codonCatFreqFix[1] + modelParams[i].codonCatFreqFix[2], (MrBFlt) 1.0, (MrBFlt) 0.001) == NO)
5457                                     {
5458                                     MrBayesPrint ("%s   Codon category frequencies must sum to 1\n", spacer);
5459                                     return (ERROR);
5460                                     }
5461                                 
5462                                 if (nApplied == 0 && numCurrentDivisions == 1)
5463                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Fixed(%1.2lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].codonCatFreqFix[0], modelParams[i].codonCatFreqFix[1], modelParams[i].codonCatFreqFix[2]);
5464                                 else
5465                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Fixed(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].codonCatFreqFix[0], modelParams[i].codonCatFreqFix[1], modelParams[i].codonCatFreqFix[2], i+1);
5466                                 expecting  = Expecting(RIGHTPAR);
5467                                 }
5468                             }
5469                         }
5470                     }
5471                 }
5472             else if (expecting == Expecting(COMMA))
5473                 {
5474                 expecting  = Expecting(NUMBER);
5475                 }
5476             else if (expecting == Expecting(RIGHTPAR))
5477                 {
5478                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5479                 }
5480             else
5481                 return (ERROR);
5482             }
5483
5484         /* set Shapepr (shapePr) **************************************************************/
5485         else if (!strcmp(parmName, "Shapepr"))
5486             {
5487             if (expecting == Expecting(EQUALSIGN))
5488                 expecting = Expecting(ALPHA);
5489             else if (expecting == Expecting(ALPHA))
5490                 {
5491                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5492                     {
5493                     nApplied = NumActiveParts ();
5494                     flag = 0;
5495                     for (i=0; i<numCurrentDivisions; i++)
5496                         {
5497                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN || modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD))
5498                             {
5499                             strcpy(modelParams[i].shapePr, tempStr);
5500                             flag = 1;
5501                             }
5502                         }
5503                     if (flag == 0)
5504                         {
5505                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of following type: DNA, RNA, PROTEIN, RESTRICTION, STANDARD.\
5506                             Currently there is no active partition with such data.\n", spacer, parmName);
5507                         return (ERROR);
5508                         }
5509                     }
5510                 else
5511                     {
5512                     MrBayesPrint ("%s   Invalid Shapepr argument\n", spacer);
5513                     return (ERROR);
5514                     }
5515                 expecting  = Expecting(LEFTPAR);
5516                 for (i=0; i<numCurrentDivisions; i++)
5517                     numVars[i] = 0;
5518                 }
5519             else if (expecting == Expecting(LEFTPAR))
5520                 {
5521                 expecting  = Expecting(NUMBER);
5522                 }
5523             else if (expecting == Expecting(NUMBER))
5524                 {
5525                 nApplied = NumActiveParts ();
5526                 for (i=0; i<numCurrentDivisions; i++)
5527                     {
5528                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN || modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD))
5529                         {
5530                         if (!strcmp(modelParams[i].shapePr,"Uniform"))
5531                             {
5532                             sscanf (tkn, "%lf", &tempD);
5533                             modelParams[i].shapeUni[numVars[i]++] = tempD;
5534                             if (numVars[i] == 1)
5535                                 expecting  = Expecting(COMMA);
5536                             else
5537                                 {
5538                                 if (modelParams[i].shapeUni[0] >= modelParams[i].shapeUni[1])
5539                                     {
5540                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5541                                     return (ERROR);
5542                                     }
5543                                 if (modelParams[i].shapeUni[1] > MAX_SHAPE_PARAM)
5544                                     {
5545                                     MrBayesPrint ("%s   Upper value for uniform cannot be greater than %1.2lf\n", spacer, MAX_SHAPE_PARAM);
5546                                     return (ERROR);
5547                                     }
5548                                 if (modelParams[i].shapeUni[0] < MIN_SHAPE_PARAM)
5549                                     {
5550                                     MrBayesPrint ("%s   Lower value for uniform cannot be less than %1.2lf\n", spacer, MIN_SHAPE_PARAM);
5551                                     return (ERROR);
5552                                     }
5553                                 if (nApplied == 0 && numCurrentDivisions == 1)
5554                                     MrBayesPrint ("%s   Setting Shapepr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].shapeUni[0], modelParams[i].shapeUni[1]);
5555                                 else
5556                                     MrBayesPrint ("%s   Setting Shapepr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].shapeUni[0], modelParams[i].shapeUni[1], i+1);
5557                                 expecting  = Expecting(RIGHTPAR);
5558                                 }
5559                             }
5560                         else if (!strcmp(modelParams[i].shapePr,"Exponential"))
5561                             {
5562                             sscanf (tkn, "%lf", &tempD);
5563                             modelParams[i].shapeExp = tempD;
5564                             if (nApplied == 0 && numCurrentDivisions == 1)
5565                                 MrBayesPrint ("%s   Setting Shapepr to Exponential(%1.2lf)\n", spacer, modelParams[i].shapeExp);
5566                             else
5567                                 MrBayesPrint ("%s   Setting Shapepr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].shapeExp, i+1);
5568                             expecting  = Expecting(RIGHTPAR);
5569                             }
5570                         else if (!strcmp(modelParams[i].shapePr,"Fixed"))
5571                             {
5572                             sscanf (tkn, "%lf", &tempD);
5573                             modelParams[i].shapeFix = tempD;
5574                             if (modelParams[i].shapeFix > MAX_SHAPE_PARAM)
5575                                 {
5576                                 MrBayesPrint ("%s   Shape parameter cannot be greater than %1.2lf\n", spacer, MAX_SHAPE_PARAM);
5577                                 return (ERROR);
5578                                 }
5579                             if (modelParams[i].shapeFix < MIN_SHAPE_PARAM)
5580                                 {
5581                                 MrBayesPrint ("%s   Shape parameter cannot be less than %1.2lf\n", spacer, MIN_SHAPE_PARAM);
5582                                 return (ERROR);
5583                                 }
5584                             if (nApplied == 0 && numCurrentDivisions == 1)
5585                                 MrBayesPrint ("%s   Setting Shapepr to Fixed(%1.2lf)\n", spacer, modelParams[i].shapeFix);
5586                             else
5587                                 MrBayesPrint ("%s   Setting Shapepr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].shapeFix, i+1);
5588                             expecting  = Expecting(RIGHTPAR);
5589                             }
5590                         }
5591                     }
5592                 }
5593             else if (expecting == Expecting(COMMA))
5594                 {
5595                 expecting  = Expecting(NUMBER);
5596                 }
5597             else if (expecting == Expecting(RIGHTPAR))
5598                 {
5599                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5600                 }
5601             else
5602                 return (ERROR);
5603             }
5604         /* set Pinvarpr (pInvarPr) ************************************************************/
5605         else if (!strcmp(parmName, "Pinvarpr"))
5606             {
5607             if (expecting == Expecting(EQUALSIGN))
5608                 expecting = Expecting(ALPHA);
5609             else if (expecting == Expecting(ALPHA))
5610                 {
5611                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5612                     {
5613                     nApplied = NumActiveParts ();
5614                     flag = 0;
5615                     for (i=0; i<numCurrentDivisions; i++)
5616                         {
5617                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
5618                             {
5619                             strcpy(modelParams[i].pInvarPr, tempStr);
5620                             flag = 1;
5621                             }
5622                         }
5623                     if (flag == 0)
5624                         {
5625                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA, PROTEIN.\
5626                             Currently there is no active partition with such data.\n", spacer, parmName);
5627                         return (ERROR);
5628                         }
5629                     }
5630                 else
5631                     {
5632                     MrBayesPrint ("%s   Invalid Pinvarpr argument\n", spacer);
5633                     return (ERROR);
5634                     }
5635                 expecting  = Expecting(LEFTPAR);
5636                 for (i=0; i<numCurrentDivisions; i++)
5637                     numVars[i] = 0;
5638                 }
5639             else if (expecting == Expecting(LEFTPAR))
5640                 {
5641                 expecting  = Expecting(NUMBER);
5642                 }
5643             else if (expecting == Expecting(NUMBER))
5644                 {
5645                 nApplied = NumActiveParts ();
5646                 for (i=0; i<numCurrentDivisions; i++)
5647                     {
5648                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
5649                         {
5650                         if (!strcmp(modelParams[i].pInvarPr,"Uniform"))
5651                             {
5652                             sscanf (tkn, "%lf", &tempD);
5653                             modelParams[i].pInvarUni[numVars[i]++] = tempD;
5654                             if (numVars[i] == 1)
5655                                 expecting  = Expecting(COMMA);
5656                             else
5657                                 {
5658                                 if (modelParams[i].pInvarUni[0] >= modelParams[i].pInvarUni[1])
5659                                     {
5660                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5661                                     return (ERROR);
5662                                     }
5663                                 if (modelParams[i].pInvarUni[1] > 1.0)
5664                                     {
5665                                     MrBayesPrint ("%s   Upper value for uniform should be less than or equal to 1.0\n", spacer);
5666                                     return (ERROR);
5667                                     }
5668                                 if (nApplied == 0 && numCurrentDivisions == 1)
5669                                     MrBayesPrint ("%s   Setting Pinvarpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].pInvarUni[0], modelParams[i].pInvarUni[1]);
5670                                 else
5671                                     MrBayesPrint ("%s   Setting Pinvarpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].pInvarUni[0], modelParams[i].pInvarUni[1], i+1);
5672                                 expecting  = Expecting(RIGHTPAR);
5673                                 }
5674                             }
5675                         else if (!strcmp(modelParams[i].pInvarPr,"Fixed"))
5676                             {
5677                             sscanf (tkn, "%lf", &tempD);
5678                             if (tempD > 1.0)
5679                                 {
5680                                 MrBayesPrint ("%s   Value for Pinvar should be in the interval (0, 1)\n", spacer);
5681                                 return (ERROR);
5682                                 }
5683                             modelParams[i].pInvarFix = tempD;
5684                             if (nApplied == 0 && numCurrentDivisions == 1)
5685                                 MrBayesPrint ("%s   Setting Pinvarpr to Fixed(%1.2lf)\n", spacer, modelParams[i].pInvarFix);
5686                             else
5687                                 MrBayesPrint ("%s   Setting Pinvarpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].pInvarFix, i+1);
5688                             expecting  = Expecting(RIGHTPAR);
5689                             }
5690                         }
5691                     }
5692                 }
5693             else if (expecting == Expecting(COMMA))
5694                 {
5695                 expecting  = Expecting(NUMBER);
5696                 }
5697             else if (expecting == Expecting(RIGHTPAR))
5698                 {
5699                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5700                 }
5701             else
5702                 return (ERROR);
5703             }
5704         /* set Ratecorrpr (adGammaCorPr) ******************************************************/
5705         else if (!strcmp(parmName, "Ratecorrpr"))
5706             {
5707             if (expecting == Expecting(EQUALSIGN))
5708                 expecting = Expecting(ALPHA);
5709             else if (expecting == Expecting(ALPHA))
5710                 {
5711                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5712                     {
5713                     nApplied = NumActiveParts ();
5714                     flag = 0;
5715                     for (i=0; i<numCurrentDivisions; i++)
5716                         {
5717                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5718                             {
5719                             strcpy(modelParams[i].adGammaCorPr, tempStr);
5720                             flag = 1;
5721                             }
5722                         }
5723                     if (flag == 0)
5724                         {
5725                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA.\
5726                             Currently there is no active partition with such data.\n", spacer, parmName);
5727                         return (ERROR);
5728                         }
5729                     }
5730                 else
5731                     {
5732                     MrBayesPrint ("%s   Invalid Ratecorrpr argument\n", spacer);
5733                     return (ERROR);
5734                     }
5735                 expecting  = Expecting(LEFTPAR);
5736                 for (i=0; i<numCurrentDivisions; i++)
5737                     numVars[i] = 0;
5738                 foundDash = NO;
5739                 }
5740             else if (expecting == Expecting(LEFTPAR))
5741                 {
5742                 expecting = Expecting(NUMBER) | Expecting(DASH);
5743                 }
5744             else if (expecting == Expecting(NUMBER))
5745                 {
5746                 nApplied = NumActiveParts ();
5747                 for (i=0; i<numCurrentDivisions; i++)
5748                     {
5749                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5750                         {
5751                         if (!strcmp(modelParams[i].adGammaCorPr,"Uniform"))
5752                             {
5753                             sscanf (tkn, "%lf", &tempD);
5754                             if (foundDash == YES)
5755                             tempD *= -1.0;
5756                             modelParams[i].corrUni[numVars[i]++] = tempD;
5757                             if (numVars[i] == 1)
5758                                 expecting  = Expecting(COMMA);
5759                             else
5760                                 {
5761                                 if (modelParams[i].corrUni[0] >= modelParams[i].corrUni[1])
5762                                     {
5763                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5764                                     return (ERROR);
5765                                     }
5766                                 if (modelParams[i].corrUni[1] > 1.0)
5767                                     {
5768                                     MrBayesPrint ("%s   Upper value for uniform should be less than or equal to 1.0\n", spacer);
5769                                     return (ERROR);
5770                                     }
5771                                 if (modelParams[i].corrUni[0] < -1.0)
5772                                     {
5773                                     MrBayesPrint ("%s   Lower value for uniform should be greater than or equal to -1.0\n", spacer);
5774                                     return (ERROR);
5775                                     }
5776                                 if (nApplied == 0 && numCurrentDivisions == 1)
5777                                     MrBayesPrint ("%s   Setting Ratecorrpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].corrUni[0], modelParams[i].corrUni[1]);
5778                                 else
5779                                     MrBayesPrint ("%s   Setting Ratecorrpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].corrUni[0], modelParams[i].corrUni[1], i+1);
5780                                 expecting  = Expecting(RIGHTPAR);
5781                                 }
5782                             }
5783                         else if (!strcmp(modelParams[i].adGammaCorPr,"Fixed"))
5784                             {
5785                             sscanf (tkn, "%lf", &tempD);
5786                             if (foundDash == YES)
5787                                 tempD *= -1.0;
5788                             if (tempD > 1.0 || tempD < -1.0)
5789                                 {
5790                                 MrBayesPrint ("%s   Value for Ratecorrpr should be in the interval (-1, +1)\n", spacer);
5791                                 return (ERROR);
5792                                 }
5793                             modelParams[i].corrFix = tempD;
5794                             if (nApplied == 0 && numCurrentDivisions == 1)
5795                                 MrBayesPrint ("%s   Setting Ratecorrpr to Fixed(%1.2lf)\n", spacer, modelParams[i].corrFix);
5796                             else
5797                                 MrBayesPrint ("%s   Setting Ratecorrpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].corrFix, i+1);
5798                             expecting  = Expecting(RIGHTPAR);
5799                             }
5800                         }
5801                     }
5802                 foundDash = NO;
5803                 }
5804             else if (expecting == Expecting(DASH))
5805                 {
5806                 foundDash = YES;
5807                 expecting  = Expecting(NUMBER);
5808                 }
5809             else if (expecting == Expecting(COMMA))
5810                 {
5811                 expecting  = Expecting(NUMBER) | Expecting(DASH);
5812                 }
5813             else if (expecting == Expecting(RIGHTPAR))
5814                 {
5815                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5816                 }
5817             else
5818                 return (ERROR);
5819             }
5820         /* set Browncorrpr (brownCorPr) ******************************************************/
5821         else if (!strcmp(parmName, "Browncorrpr"))
5822             {
5823             if (expecting == Expecting(EQUALSIGN))
5824                 expecting = Expecting(ALPHA);
5825             else if (expecting == Expecting(ALPHA))
5826                 {
5827                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5828                     {
5829                     nApplied = NumActiveParts ();
5830                     flag = 0;
5831                     for (i=0; i<numCurrentDivisions; i++)
5832                         {
5833                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
5834                             {
5835                             strcpy(modelParams[i].brownCorPr, tempStr);
5836                             flag = 1;
5837                             }
5838                         }
5839                     if (flag == 0)
5840                         {
5841                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing CONTINUOUS data.\
5842                             Currently there is no active partition with such data.\n", spacer, parmName);
5843                         return (ERROR);
5844                         }
5845                     }
5846                 else
5847                     {
5848                     MrBayesPrint ("%s   Invalid Browncorrpr argument\n", spacer);
5849                     return (ERROR);
5850                     }
5851                 expecting  = Expecting(LEFTPAR);
5852                 for (i=0; i<numCurrentDivisions; i++)
5853                     numVars[i] = 0;
5854                 foundDash = NO;
5855                 }
5856             else if (expecting == Expecting(LEFTPAR))
5857                 {
5858                 expecting = Expecting(NUMBER) | Expecting(DASH);
5859                 }
5860             else if (expecting == Expecting(NUMBER))
5861                 {
5862                 nApplied = NumActiveParts ();
5863                 for (i=0; i<numCurrentDivisions; i++)
5864                     {
5865                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
5866                         {
5867                         if (!strcmp(modelParams[i].brownCorPr,"Uniform"))
5868                             {
5869                             sscanf (tkn, "%lf", &tempD);
5870                             if (foundDash == YES)
5871                             tempD *= -1.0;
5872                             modelParams[i].brownCorrUni[numVars[i]++] = tempD;
5873                             if (numVars[i] == 1)
5874                                 expecting  = Expecting(COMMA);
5875                             else
5876                                 {
5877                                 if (modelParams[i].brownCorrUni[0] >= modelParams[i].brownCorrUni[1])
5878                                     {
5879                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5880                                     return (ERROR);
5881                                     }
5882                                 if (modelParams[i].brownCorrUni[1] > 1.0)
5883                                     {
5884                                     MrBayesPrint ("%s   Upper value for uniform should be less than or equal to 1.0\n", spacer);
5885                                     return (ERROR);
5886                                     }
5887                                 if (modelParams[i].brownCorrUni[0] < -1.0)
5888                                     {
5889                                     MrBayesPrint ("%s   Lower value for uniform should be greater than or equal to -1.0\n", spacer);
5890                                     return (ERROR);
5891                                     }
5892                                 if (nApplied == 0 && numCurrentDivisions == 1)
5893                                     MrBayesPrint ("%s   Setting Browncorrpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brownCorrUni[0], modelParams[i].brownCorrUni[1]);
5894                                 else
5895                                     MrBayesPrint ("%s   Setting Browncorrpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brownCorrUni[0], modelParams[i].brownCorrUni[1], i+1);
5896                                 expecting  = Expecting(RIGHTPAR);
5897                                 }
5898                             }
5899                         else if (!strcmp(modelParams[i].brownCorPr,"Fixed"))
5900                             {
5901                             sscanf (tkn, "%lf", &tempD);
5902                             if (foundDash == YES)
5903                                 tempD *= -1.0;
5904                             if (tempD > 1.0 || tempD < -1.0)
5905                                 {
5906                                 MrBayesPrint ("%s   Value for Browncorrpr should be in the interval (-1, +1)\n", spacer);
5907                                 return (ERROR);
5908                                 }
5909                             modelParams[i].brownCorrFix = tempD;
5910                             if (nApplied == 0 && numCurrentDivisions == 1)
5911                                 MrBayesPrint ("%s   Setting Browncorrpr to Fixed(%1.2lf)\n", spacer, modelParams[i].brownCorrFix);
5912                             else
5913                                 MrBayesPrint ("%s   Setting Browncorrpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].brownCorrFix, i+1);
5914                             expecting  = Expecting(RIGHTPAR);
5915                             }
5916                         }
5917                     }
5918                 foundDash = NO;
5919                 }
5920             else if (expecting == Expecting(DASH))
5921                 {
5922                 foundDash = YES;
5923                 expecting  = Expecting(NUMBER);
5924                 }
5925             else if (expecting == Expecting(COMMA))
5926                 {
5927                 expecting  = Expecting(NUMBER) | Expecting(DASH);
5928                 }
5929             else if (expecting == Expecting(RIGHTPAR))
5930                 {
5931                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5932                 }
5933             else
5934                 return (ERROR);
5935             }
5936         /* set Ratepr (ratePr) *****************************************************************/
5937         else if (!strcmp(parmName, "Ratepr"))
5938             {
5939             if (expecting == Expecting(EQUALSIGN))
5940                 expecting = Expecting(ALPHA);
5941             else if (expecting == Expecting(ALPHA))
5942                 {
5943                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5944                     {
5945                     nApplied = NumActiveParts ();
5946                     for (i=0; i<numCurrentDivisions; i++)
5947                         {
5948                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
5949                             {
5950                             if (!strcmp(tempStr,"Variable"))
5951                                 strcpy(modelParams[i].ratePr, "Dirichlet");
5952                             else
5953                                 strcpy(modelParams[i].ratePr, tempStr);
5954                             modelParams[i].ratePrDir = 1.0;
5955                             if (!strcmp(tempStr,"Variable") || !strcmp(tempStr,"Fixed"))
5956                                 {
5957                                 if (tempStr[0]=='V')
5958                                     strcat (tempStr," [Dirichlet(..,1,..)]");
5959                                 if (nApplied == 0 && numCurrentDivisions == 1)
5960                                     MrBayesPrint ("%s   Setting Ratepr to %s\n", spacer, tempStr);
5961                                 else
5962                                     MrBayesPrint ("%s   Setting Ratepr to %s for partition %d\n", spacer, tempStr, i+1);
5963                                 if (tempStr[0]=='V')
5964                                     strcpy (tempStr,"Variable");
5965                                 }
5966                             }
5967                         }
5968                     }
5969                 else
5970                     {
5971                     MrBayesPrint ("%s   Invalid Ratepr argument\n", spacer);
5972                     return (ERROR);
5973                     }
5974                 if (!strcmp(tempStr,"Fixed") || !strcmp(tempStr,"Variable"))
5975                     expecting  = Expecting(PARAMETER) | Expecting(SEMICOLON);
5976                 else
5977                     expecting = Expecting(LEFTPAR);
5978                 for (i=0; i<numCurrentDivisions; i++)
5979                     numVars[i] = 0;
5980                 }
5981             else if (expecting == Expecting(LEFTPAR))
5982                 {
5983                 expecting = Expecting (NUMBER);
5984                 }
5985             else if (expecting == Expecting(NUMBER))
5986                 {
5987                 /* find next partition to fill in */
5988                 nApplied = NumActiveParts ();
5989                 for (i=0; i<numCurrentDivisions; i++)
5990                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
5991                         break;
5992                 if (i == numCurrentDivisions)
5993                     {
5994                     MrBayesPrint ("%s   Could not find first ratemultiplier partition\n", spacer);
5995                     return (ERROR);
5996                     }
5997                 numVars[i] = 1;
5998                 /* read in the parameter */
5999                 sscanf (tkn, "%lf", &tempD);
6000                 if (tempD < ALPHA_MIN || tempD > ALPHA_MAX)
6001                     {
6002                     MrBayesPrint ("%s   Ratemultiplier Dirichlet parameter %lf out of range\n", spacer, tempD);
6003                     return (ERROR);
6004                     }
6005                 /* set the parameter */
6006                 modelParams[i].ratePrDir = tempD;               
6007                 /* check if all partitions have been filled in */
6008                 for (i=0; i<numCurrentDivisions; i++)
6009                     {
6010                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6011                         break;
6012                     }
6013                 /* set expecting accordingly so that we know what should be coming next */
6014                 if (i == numCurrentDivisions)
6015                     expecting = Expecting (RIGHTPAR);
6016                 else
6017                     expecting = Expecting (COMMA);
6018                 }
6019             else if (expecting == Expecting (COMMA))
6020                 expecting = Expecting (NUMBER);
6021             else if (expecting == Expecting (RIGHTPAR))
6022                 {
6023                 /* print message */
6024                 for (i=j=0; i<numCurrentDivisions; i++)
6025                     {
6026                     if (numVars[i] == 1)
6027                         {
6028                         j++;
6029                         if (j == 1)
6030                             {
6031                             MrBayesPrint ("%s   Setting Ratepr to Dirichlet(%1.2f",
6032                                 spacer, modelParams[i].ratePrDir);
6033                             }
6034                         else
6035                             MrBayesPrint(",%1.2f", modelParams[i].ratePrDir);
6036                         }
6037                     }
6038                 if (numCurrentDivisions == 1)
6039                     MrBayesPrint (")\n");
6040                 else
6041                     {
6042                     MrBayesPrint (") for partition");
6043                     if (j > 1)
6044                         MrBayesPrint ("s");
6045                     for (i=k=0; i<numCurrentDivisions; i++)
6046                         {
6047                         if (numVars[i] == 1)
6048                             {
6049                             k++;
6050                             if (k == j && j > 1)
6051                                 MrBayesPrint (", and %d", i+1);
6052                             else if (k == 1)
6053                                 MrBayesPrint (" %d", i+1);
6054                             else
6055                                 MrBayesPrint (", %d", i+1);
6056                             }
6057                         }
6058                     MrBayesPrint ("\n");
6059                     }
6060                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6061                 }
6062             else
6063                 return (ERROR);
6064             }
6065         /* set Generatepr (generatePr) *****************************************************************/
6066         else if (!strcmp(parmName, "Generatepr"))
6067             {
6068             if (expecting == Expecting(EQUALSIGN))
6069                 expecting = Expecting(ALPHA);
6070             else if (expecting == Expecting(ALPHA))
6071                 {
6072                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6073                     {
6074                     nApplied = NumActiveParts ();
6075                     for (i=0; i<numCurrentDivisions; i++)
6076                         {
6077                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6078                             {
6079                             if (!strcmp(tempStr,"Variable"))
6080                                 strcpy(modelParams[i].generatePr, "Dirichlet");
6081                             else
6082                                 strcpy(modelParams[i].generatePr, tempStr);
6083                             modelParams[i].generatePrDir = 1.0;
6084                             if (!strcmp(tempStr,"Variable") || !strcmp(tempStr,"Fixed"))
6085                                 {
6086                                 if (tempStr[0]=='V')
6087                                     strcat (tempStr," [Dirichlet(..,1,..)]");
6088                                 if (nApplied == 0 && numCurrentDivisions == 1)
6089                                     MrBayesPrint ("%s   Setting Generatepr to %s\n", spacer, tempStr);
6090                                 else
6091                                     MrBayesPrint ("%s   Setting Generatepr to %s for partition %d\n", spacer, tempStr, i+1);
6092                                 if (tempStr[0]=='V')
6093                                     strcpy (tempStr,"Variable");
6094                                 }
6095                             }
6096                         }
6097                     }
6098                 else
6099                     {
6100                     MrBayesPrint ("%s   Invalid Generatepr argument\n", spacer);
6101                     return (ERROR);
6102                     }
6103                 if (!strcmp(tempStr,"Fixed") || !strcmp(tempStr,"Variable"))
6104                     expecting  = Expecting(PARAMETER) | Expecting(SEMICOLON);
6105                 else
6106                     expecting = Expecting(LEFTPAR);
6107                 for (i=0; i<numCurrentDivisions; i++)
6108                     numVars[i] = 0;
6109                 }
6110             else if (expecting == Expecting(LEFTPAR))
6111                 {
6112                 expecting = Expecting (NUMBER);
6113                 }
6114             else if (expecting == Expecting(NUMBER))
6115                 {
6116                 /* find next partition to fill in */
6117                 nApplied = NumActiveParts ();
6118                 for (i=0; i<numCurrentDivisions; i++)
6119                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6120                         break;
6121                 if (i == numCurrentDivisions)
6122                     {
6123                     MrBayesPrint ("%s   Could not find first generate multiplier partition\n", spacer);
6124                     return (ERROR);
6125                     }
6126                 numVars[i] = 1;
6127                 /* read in the parameter */
6128                 sscanf (tkn, "%lf", &tempD);
6129                 if (tempD < ALPHA_MIN || tempD > ALPHA_MAX)
6130                     {
6131                     MrBayesPrint ("%s   Generate multiplier Dirichlet parameter %lf out of range\n", spacer, tempD);
6132                     return (ERROR);
6133                     }
6134                 /* set the parameter */
6135                 modelParams[i].generatePrDir = tempD;
6136                 /* check if all partitions have been filled in */
6137                 for (i=0; i<numCurrentDivisions; i++)
6138                     {
6139                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6140                         break;
6141                     }
6142                 /* set expecting accordingly so that we know what should be coming next */
6143                 if (i == numCurrentDivisions)
6144                     expecting = Expecting (RIGHTPAR);
6145                 else
6146                     expecting = Expecting (COMMA);
6147                 }
6148             else if (expecting == Expecting (COMMA))
6149                 expecting = Expecting (NUMBER);
6150             else if (expecting == Expecting (RIGHTPAR))
6151                 {
6152                 /* print message */
6153                 for (i=j=0; i<numCurrentDivisions; i++)
6154                     {
6155                     if (numVars[i] == 1)
6156                         {
6157                         j++;
6158                         if (j == 1)
6159                             {
6160                             MrBayesPrint ("%s   Setting Generatepr to Dirichlet(%1.2f",
6161                                           spacer, modelParams[i].generatePrDir);
6162                             }
6163                         else
6164                             MrBayesPrint(",%1.2f", modelParams[i].generatePrDir);
6165                         }
6166                     }
6167                 if (numCurrentDivisions == 1)
6168                     MrBayesPrint (")\n");
6169                 else
6170                     {
6171                     MrBayesPrint (") for partition");
6172                     if (j > 1)
6173                         MrBayesPrint ("s");
6174                     for (i=k=0; i<numCurrentDivisions; i++)
6175                         {
6176                         if (numVars[i] == 1)
6177                             {
6178                             k++;
6179                             if (k == j && j > 1)
6180                                 MrBayesPrint (", and %d", i+1);
6181                             else if (k == 1)
6182                                 MrBayesPrint (" %d", i+1);
6183                             else
6184                                 MrBayesPrint (", %d", i+1);
6185                             }
6186                         }
6187                     MrBayesPrint ("\n");
6188                     }
6189                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6190                 }
6191             else
6192                 return (ERROR);
6193             }
6194         /* set Covswitchpr (covSwitchPr) ******************************************************/
6195         else if (!strcmp(parmName, "Covswitchpr"))
6196             {
6197             if (expecting == Expecting(EQUALSIGN))
6198                 expecting = Expecting(ALPHA);
6199             else if (expecting == Expecting(ALPHA))
6200                 {
6201                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6202                     {
6203                     nApplied = NumActiveParts ();
6204                     flag = 0;
6205                     for (i=0; i<numCurrentDivisions; i++)
6206                         {
6207                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
6208                             {
6209                             strcpy(modelParams[i].covSwitchPr, tempStr);
6210                             flag = 1;
6211                             }
6212                         }
6213                     if (flag == 0)
6214                         {
6215                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA, PROTEIN.\
6216                             Currently there is no active partition with such data. ", spacer, parmName);
6217                         return (ERROR);
6218                         }
6219                     }
6220                 else
6221                     {
6222                     MrBayesPrint ("%s   Invalid Covswitchpr argument\n", spacer);
6223                     return (ERROR);
6224                     }
6225                 expecting  = Expecting(LEFTPAR);
6226                 for (i=0; i<numCurrentDivisions; i++)
6227                     numVars[i] = 0;
6228                 }
6229             else if (expecting == Expecting(LEFTPAR))
6230                 {
6231                 expecting  = Expecting(NUMBER);
6232                 }
6233             else if (expecting == Expecting(NUMBER))
6234                 {
6235                 nApplied = NumActiveParts ();
6236                 for (i=0; i<numCurrentDivisions; i++)
6237                     {
6238                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
6239                         {
6240                         if (!strcmp(modelParams[i].covSwitchPr,"Uniform"))
6241                             {
6242                             sscanf (tkn, "%lf", &tempD);
6243                             modelParams[i].covswitchUni[numVars[i]++] = tempD;
6244                             if (numVars[i] == 1)
6245                                 expecting  = Expecting(COMMA);
6246                             else
6247                                 {
6248                                 if (modelParams[i].covswitchUni[0] >= modelParams[i].covswitchUni[1])
6249                                     {
6250                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
6251                                     return (ERROR);
6252                                     }
6253                                 if (nApplied == 0 && numCurrentDivisions == 1)
6254                                     MrBayesPrint ("%s   Setting Covswitchpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].covswitchUni[0], modelParams[i].covswitchUni[1]);
6255                                 else
6256                                     MrBayesPrint ("%s   Setting Covswitchpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].covswitchUni[0], modelParams[i].covswitchUni[1], i+1);
6257                                 expecting  = Expecting(RIGHTPAR);
6258                                 }
6259                             }
6260                         else if (!strcmp(modelParams[i].covSwitchPr,"Exponential"))
6261                             {
6262                             sscanf (tkn, "%lf", &tempD);
6263                             modelParams[i].covswitchExp = tempD;
6264                             if (nApplied == 0 && numCurrentDivisions == 1)
6265                                 MrBayesPrint ("%s   Setting Covswitchpr to Exponential(%1.2lf)\n", spacer, modelParams[i].covswitchExp);
6266                             else
6267                                 MrBayesPrint ("%s   Setting Covswitchpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].covswitchExp, i+1);
6268                             expecting  = Expecting(RIGHTPAR);
6269                             }
6270                         else if (!strcmp(modelParams[i].covSwitchPr,"Fixed"))
6271                             {
6272                             sscanf (tkn, "%lf", &tempD);
6273                             modelParams[i].covswitchFix[numVars[i]++] = tempD;
6274                             if (numVars[i] == 1)
6275                                 expecting  = Expecting(COMMA);
6276                             else
6277                                 {
6278                                 if (nApplied == 0 && numCurrentDivisions == 1)
6279                                     MrBayesPrint ("%s   Setting Covswitchpr to Fixed(%1.4lf,%1.4lf)\n", spacer, modelParams[i].covswitchFix[0], modelParams[i].covswitchFix[1]);
6280                                 else
6281                                     MrBayesPrint ("%s   Setting Covswitchpr to Fixed(%1.4lf,%1.4lf) for partition %d\n", spacer, modelParams[i].covswitchFix[0], modelParams[i].covswitchFix[1], i+1);
6282                                 expecting  = Expecting(RIGHTPAR);
6283                                 }
6284                             }
6285                         }
6286                     }
6287                 }
6288             else if (expecting == Expecting(COMMA))
6289                 {
6290                 expecting  = Expecting(NUMBER);
6291                 }
6292             else if (expecting == Expecting(RIGHTPAR))
6293                 {
6294                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6295                 }
6296             else
6297                 return (ERROR);
6298             }
6299         /* set Symdirihyperpr (symPiPr) ******************************************************/
6300         else if (!strcmp(parmName, "Symdirihyperpr"))
6301             {
6302             if (expecting == Expecting(EQUALSIGN))
6303                 {
6304                 foundBeta = NO;
6305                 expecting = Expecting(ALPHA);
6306                 }
6307             else if (expecting == Expecting(ALPHA))
6308                 {
6309                 if (foundBeta == NO)
6310                     {
6311                     /* expecting to see Uniform, Exponential, or Fixed */
6312                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6313                         {
6314                         nApplied = NumActiveParts ();
6315                         flag = 0;
6316                         for (i=0; i<numCurrentDivisions; i++)
6317                             {
6318                             if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
6319                                 {
6320                                 strcpy(modelParams[i].symPiPr, tempStr);
6321                                 flag = 1;
6322                                 }
6323                             }
6324                         if (flag == 0)
6325                             {
6326                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing data", spacer, parmName);
6327                             MrBayesPrint ("  of at least one of the following type: STANDARD, RESTRICTION.");
6328                             MrBayesPrint ("Currently there is no active partition with such data. ");
6329                             return (ERROR);
6330                             }
6331                         }
6332                     else
6333                         {
6334                         MrBayesPrint ("%s   Invalid Symdirihyperpr argument\n", spacer);
6335                         return (ERROR);
6336                         }
6337                     expecting  = Expecting(LEFTPAR);
6338                     for (i=0; i<numCurrentDivisions; i++)
6339                         numVars[i] = 0;
6340                     foundBeta = YES;    
6341                     }   
6342                 else
6343                     {
6344                     /* expecting infinity */
6345                     if (IsSame("Infinity", tkn) == SAME || IsSame("Infinity", tkn) == CONSISTENT_WITH)
6346                         {
6347                         nApplied = NumActiveParts ();
6348                         for (i=0; i<numCurrentDivisions; i++)
6349                             {
6350                             if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
6351                                 {
6352                                 if (!strcmp(modelParams[i].symPiPr, "Fixed"))
6353                                     {
6354                                     modelParams[i].symBetaFix = -1;
6355                                     if (nApplied == 0 && numCurrentDivisions == 1)
6356                                         MrBayesPrint ("%s   Setting Symdirihyperpr to Beta(Infinity)\n", spacer);
6357                                     else
6358                                         MrBayesPrint ("%s   Setting Symdirihyperpr to Beta(Infinity) for partition %d\n", spacer, i+1);
6359                                     expecting  = Expecting(RIGHTPAR);
6360                                     }
6361                                 else
6362                                     {
6363                                     MrBayesPrint ("%s   Problem setting Symdirihyperpr\n", spacer);
6364                                     return (ERROR);
6365                                     }
6366                                 }
6367                             }
6368                         expecting  = Expecting(RIGHTPAR);
6369                         }
6370                     }       
6371                 }
6372             else if (expecting == Expecting(LEFTPAR))
6373                 {
6374                 expecting  = Expecting(NUMBER) | Expecting(ALPHA);
6375                 }
6376             else if (expecting == Expecting(NUMBER))
6377                 {
6378                 nApplied = NumActiveParts ();
6379                 for (i=0; i<numCurrentDivisions; i++)
6380                     {
6381                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
6382                         {
6383                         if (!strcmp(modelParams[i].symPiPr,"Fixed"))
6384                             {
6385                             sscanf (tkn, "%lf", &tempD);
6386                             modelParams[i].symBetaFix = tempD;
6387                             if (nApplied == 0 && numCurrentDivisions == 1)
6388                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Fixed(%1.2lf)\n", spacer, modelParams[i].symBetaFix);
6389                             else
6390                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].symBetaFix, i+1);
6391                             expecting  = Expecting(RIGHTPAR);
6392                             }
6393                         else if (!strcmp(modelParams[i].symPiPr,"Exponential"))
6394                             {
6395                             sscanf (tkn, "%lf", &tempD);
6396                             modelParams[i].symBetaExp = tempD;
6397                             if (nApplied == 0 && numCurrentDivisions == 1)
6398                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Exponential(%1.2lf)\n", spacer, modelParams[i].symBetaExp);
6399                             else
6400                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].symBetaExp, i+1);
6401                             expecting  = Expecting(RIGHTPAR);
6402                             }
6403                         else if (!strcmp(modelParams[i].symPiPr,"Uniform"))
6404                             {
6405                             sscanf (tkn, "%lf", &tempD);
6406                             modelParams[i].symBetaUni[numVars[i]++] = tempD;
6407                             if (numVars[i] == 1)    
6408                                 expecting = Expecting(COMMA);
6409                             else
6410                                 {
6411                                 if (modelParams[i].symBetaUni[0] >= modelParams[i].symBetaUni[1])
6412                                     {
6413                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
6414                                     return (ERROR);
6415                                     }
6416                                 if (nApplied == 0 && numCurrentDivisions == 1)
6417                                     MrBayesPrint ("%s   Setting Symdirihyperpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].symBetaUni[0], modelParams[i].symBetaUni[1]);
6418                                 else
6419                                     MrBayesPrint ("%s   Setting Symdirihyperpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].symBetaUni[0], modelParams[i].symBetaUni[1], i+1);
6420                                 expecting  = Expecting(RIGHTPAR);
6421                                 }
6422                             }
6423                         else
6424                             {
6425                             MrBayesPrint ("%s   Problem setting Symdirihyperpr\n", spacer);
6426                             return (ERROR);
6427                             }
6428                         }
6429                     }
6430                 }
6431             else if (expecting == Expecting(COMMA))
6432                 {
6433                 expecting  = Expecting(NUMBER);
6434                 }
6435             else if (expecting == Expecting(RIGHTPAR))
6436                 {
6437                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6438                 }
6439             else
6440                 return (ERROR);
6441             }
6442         /* set Statefreqpr (stateFreqPr) ******************************************************/
6443         else if (!strcmp(parmName, "Statefreqpr"))
6444             {
6445             if (expecting == Expecting(EQUALSIGN))
6446                 expecting = Expecting(ALPHA);
6447             else if (expecting == Expecting(ALPHA))
6448                 {
6449                 if (IsSame ("Equal", tkn) == DIFFERENT && IsSame ("Empirical", tkn) == DIFFERENT)
6450                     {
6451                     /* the user wants to specify a dirichlet or fixed prior */
6452                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6453                         {
6454                         nApplied = NumActiveParts ();
6455                         for (i=0; i<numCurrentDivisions; i++)
6456                             {
6457                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6458                                 strcpy(modelParams[i].stateFreqPr, tempStr);
6459                             }
6460                         /* if (flag == 0)
6461                             {
6462                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing CONTINUOUS data.\
6463                             Currently there is no active partition with such data. ", spacer, parmName);
6464                             return (ERROR);
6465                             } */
6466                         }
6467                     else
6468                         {
6469                         MrBayesPrint ("%s   Invalid Statefreqpr argument\n", spacer);
6470                         return (ERROR);
6471                         }
6472                     /* TODO: Here we set flat dirichlet parameters */
6473                     expecting  = Expecting(LEFTPAR);
6474                     }
6475                 else
6476                     {
6477                     /* the user wants equal or empirical state frequencies */
6478                     nApplied = NumActiveParts ();
6479                     if (IsSame ("Equal", tkn) == SAME || IsSame ("Equal", tkn) == CONSISTENT_WITH)
6480                         {
6481                         for (i=0; i<numCurrentDivisions; i++)
6482                             {
6483                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6484                                 strcpy(modelParams[i].stateFreqsFixType, "Equal");
6485                             }
6486                         }
6487                     else if (IsSame ("Empirical", tkn) == SAME || IsSame ("Empirical", tkn) == CONSISTENT_WITH)
6488                         {
6489                         for (i=0; i<numCurrentDivisions; i++)
6490                             {
6491                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6492                                 strcpy(modelParams[i].stateFreqsFixType, "Empirical");
6493                             }
6494                         }
6495                     else
6496                         {
6497                         MrBayesPrint ("%s   Invalid Statefreqpr delimiter\n", spacer);
6498                         return (ERROR);
6499                         }
6500                     expecting  = Expecting(RIGHTPAR);
6501                     }
6502                 }
6503             else if (expecting == Expecting(LEFTPAR))
6504                 {
6505                 tempNumStates = 0;
6506                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
6507                 }
6508             else if (expecting == Expecting(NUMBER))
6509                 {
6510                 nApplied = NumActiveParts ();
6511                 sscanf (tkn, "%lf", &tempD);
6512                 tempStateFreqs[tempNumStates++] = tempD;
6513                 for (i=0; i<numCurrentDivisions; i++)
6514                     {
6515                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6516                         if (!strcmp(modelParams[i].stateFreqPr,"Fixed"))
6517                             strcpy(modelParams[i].stateFreqsFixType, "User");
6518                     }
6519                 expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
6520                 }
6521             else if (expecting == Expecting(COMMA))
6522                 {
6523                 expecting  = Expecting(NUMBER);
6524                 }
6525             else if (expecting == Expecting(RIGHTPAR))
6526                 {
6527                 nApplied = NumActiveParts ();
6528                 for (i=0; i<numCurrentDivisions; i++)
6529                     {
6530                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6531                         {
6532                         ns = NumStates(i);
6533                         if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
6534                             {
6535                             if (tempNumStates == 1)
6536                                 {
6537                                 for (j=0; j<ns; j++)
6538                                     modelParams[i].stateFreqsDir[j] = tempStateFreqs[0] / ns;
6539                                 MrBayesPrint ("%s   Setting Statefreqpr to Dirichlet(", spacer);
6540                                 for (j=0; j<ns; j++)
6541                                     {
6542                                     MrBayesPrint("%1.2lf", modelParams[i].stateFreqsDir[j]);
6543                                     if (j == ns - 1)
6544                                         MrBayesPrint (")");
6545                                     else
6546                                         MrBayesPrint (","); 
6547                                     }   
6548                                 if (nApplied == 0 && numCurrentDivisions == 1)
6549                                     MrBayesPrint ("\n");
6550                                 else
6551                                     MrBayesPrint (" for partition %d\n", i+1); 
6552                                 modelParams[i].numDirParams = ns;
6553                                 }
6554                             else
6555                                 {
6556                                 if (tempNumStates != ns)
6557                                     {
6558                                     MrBayesPrint ("%s   Found %d dirichlet parameters but expecting %d\n", spacer, tempNumStates, modelParams[i].nStates);
6559                                     return (ERROR);
6560                                     }
6561                                 else
6562                                     {
6563                                     modelParams[i].numDirParams = ns;
6564                                     for (j=0; j<ns; j++)
6565                                         modelParams[i].stateFreqsDir[j] = tempStateFreqs[j];
6566                                     MrBayesPrint ("%s   Setting Statefreqpr to Dirichlet(", spacer);
6567                                     for (j=0; j<ns; j++)
6568                                         {
6569                                         MrBayesPrint("%1.2lf", modelParams[i].stateFreqsDir[j]);
6570                                         if (j == ns - 1)
6571                                             MrBayesPrint (")");
6572                                         else
6573                                             MrBayesPrint (","); 
6574                                         }   
6575                                     if (nApplied == 0 && numCurrentDivisions == 1)
6576                                         MrBayesPrint ("\n");
6577                                     else
6578                                         MrBayesPrint (" for partition %d\n", i+1); 
6579                                     }
6580                                 }
6581                             }
6582                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed"))
6583                             {
6584                             if (tempNumStates == 0)
6585                                 {
6586                                 if (!strcmp(modelParams[i].stateFreqsFixType, "Equal"))
6587                                     MrBayesPrint ("%s   Setting Statefreqpr to Fixed(Equal)", spacer);
6588                                 else if (!strcmp(modelParams[i].stateFreqsFixType, "Empirical"))
6589                                     MrBayesPrint ("%s   Setting Statefreqpr to Fixed(Empirical)", spacer);
6590                                 if (nApplied == 0 && numCurrentDivisions == 1)
6591                                     MrBayesPrint ("\n");
6592                                 else
6593                                     MrBayesPrint (" for partition %d\n", i+1); 
6594                                 }
6595                             else 
6596                                 {
6597                                 if (tempNumStates == ns)
6598                                     {
6599                                     sum = 0.0;
6600                                     for (j=0; j<ns; j++)
6601                                         sum += tempStateFreqs[j];
6602                                     if (AreDoublesEqual (sum, (MrBFlt) 1.0, (MrBFlt) 0.001) == NO)
6603                                         {
6604                                         MrBayesPrint ("%s   State frequencies do not sum to 1.0\n", spacer);
6605                                         return (ERROR);
6606                                         }
6607                                     strcpy(modelParams[i].stateFreqsFixType, "User");
6608                                     for (j=0; j<ns; j++)
6609                                         modelParams[i].stateFreqsFix[j] = tempStateFreqs[j];
6610                                     MrBayesPrint ("%s   Setting Statefreqpr to Fixed(", spacer);
6611                                     for (j=0; j<ns; j++)
6612                                         {
6613                                         MrBayesPrint("%1.2lf", modelParams[i].stateFreqsFix[j]);
6614                                         if (j == ns - 1)
6615                                             MrBayesPrint (")");
6616                                         else
6617                                             MrBayesPrint (","); 
6618                                         }   
6619                                     if (nApplied == 0 && numCurrentDivisions == 1)
6620                                         MrBayesPrint ("\n");
6621                                     else
6622                                         MrBayesPrint (" for partition %d\n", i+1); 
6623                                     }
6624                                 else
6625                                     {
6626                                     MrBayesPrint ("%s   Found %d state frequencies but expecting %d\n", spacer, tempNumStates, modelParams[i].nStates);
6627                                     return (ERROR);
6628                                     }
6629                                 }
6630                                 
6631                             }
6632                         }
6633                     }
6634                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6635                 }
6636             else
6637                 return (ERROR);
6638             }
6639         /* set Topologypr (topologyPr) ********************************************************/
6640         else if (!strcmp(parmName, "Topologypr"))
6641             {
6642             if (expecting == Expecting(EQUALSIGN))
6643                 {
6644                 foundEqual = YES;
6645                 expecting = Expecting(ALPHA);
6646                 }
6647             else if (expecting == Expecting(ALPHA))
6648                 {
6649                 if (foundEqual == YES)
6650                     {
6651                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6652                         {
6653                         /* set topology prior */
6654                         nApplied = NumActiveParts ();
6655                         for (i=0; i<numCurrentDivisions; i++)
6656                             {
6657                             if (activeParts[i] == YES || nApplied == 0)
6658                                 {
6659                                 strcpy(modelParams[i].topologyPr, tempStr);
6660                                 /* erase previous constraints, if any */
6661                                 for (j=0; j<numDefinedConstraints; j++)
6662                                     modelParams[i].activeConstraints[j] = NO;
6663                                 if (nApplied == 0 && numCurrentDivisions == 1)
6664                                     MrBayesPrint ("%s   Setting Topologypr to %s\n", spacer, modelParams[i].topologyPr);
6665                                 else
6666                                     MrBayesPrint ("%s   Setting Topologypr to %s for partition %d\n", spacer, modelParams[i].topologyPr, i+1);
6667                                 /* adjust branch length prior if necessary */
6668                                 if (strcmp(modelParams[i].topologyPr,"Fixed") != 0 && strcmp(modelParams[i].brlensPr,"Fixed") == 0)
6669                                     {
6670                                     MrBayesPrint ("%s   Resetting Brlenspr to default\n", spacer);
6671                                     if (strcmp(modelParams[i].clockPr,"Clock") == 0)
6672                                         strcpy(modelParams[i].brlensPr, "Uniform");
6673                                     else
6674                                         strcpy(modelParams[i].brlensPr, defaultModel.brlensPr);
6675                                     }
6676                                 }
6677                             }
6678                         }
6679                     else
6680                         {
6681                         MrBayesPrint ("%s   Invalid Topologypr argument\n", spacer);
6682                         return (ERROR);
6683                         }
6684                     /* make sure we know what to do next */
6685                     if (!strcmp(tempStr, "Uniform") || !strcmp(tempStr, "Speciestree"))
6686                         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6687                     else
6688                         expecting = Expecting(LEFTPAR);
6689                     foundEqual = NO;
6690                     }
6691                 else
6692                     {
6693                     /* find out whether we need a tree name or constraint name */
6694                     nApplied = NumActiveParts ();
6695                     for (i=0; i<numCurrentDivisions; i++)
6696                         if (activeParts[i] == YES || nApplied == 0)
6697                             break;
6698
6699                     if (foundDash == YES)   /* we must be collecting constraint numbers */
6700                         {
6701                         MrBayesPrint ("%s   Expecting a number\n", spacer);
6702                         return (ERROR);
6703                         }
6704                     if (!strcmp(modelParams[i].topologyPr,"Constraints"))
6705                         {
6706                         /* find constraint number */
6707                         if (CheckString (constraintNames, numDefinedConstraints, tkn, &index) == ERROR)
6708                             {
6709                             MrBayesPrint ("%s   Could not find constraint named %s\n", spacer, tkn);
6710                             return (ERROR);
6711                             }
6712                         tempActiveConstraints[index] = YES;
6713                         expecting = Expecting(RIGHTPAR);
6714                         expecting |= Expecting(COMMA);
6715                         }
6716                     else
6717                         {
6718                         /* find tree number */
6719                         if (GetUserTreeFromName (&index, tkn) == ERROR)
6720                             {
6721                             MrBayesPrint ("%s   Could not set fixed topology from user tree '%s'\n", spacer, tkn);
6722                             return (ERROR);
6723                             }
6724                         fromI = index + 1;        /* fromI is used to hold the index of the user tree, 1-based */
6725                         expecting = Expecting(RIGHTPAR);
6726                         }
6727                     }
6728                 }
6729             else if (expecting == Expecting(LEFTPAR))
6730                 {
6731                 for (i=0; i<numDefinedConstraints; i++)
6732                     tempActiveConstraints[i] = NO;
6733                 fromI = toJ = -1;
6734                 foundDash = foundComma = NO;
6735                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
6736                 }
6737             else if (expecting == Expecting(NUMBER))
6738                 {
6739                 /* find out whether we need a tree number or constraint number */
6740                 nApplied = NumActiveParts ();
6741                 for (i=0; i<numCurrentDivisions; i++)
6742                     if (activeParts[i] == YES || nApplied == 0)
6743                         break;
6744
6745                 if (!strcmp(modelParams[i].topologyPr,"Constraints"))
6746                     {
6747                     if (numDefinedConstraints == 0)
6748                         {
6749                         MrBayesPrint ("%s   No constraints have been defined\n", spacer);
6750                         return (ERROR);
6751                         }
6752                     sscanf (tkn, "%d", &tempInt);
6753                     if (tempInt > numDefinedConstraints)
6754                         {
6755                         MrBayesPrint ("%s   Constraint number is too large\n", spacer);
6756                         return (ERROR);
6757                         }
6758                     if (fromI == -1)
6759                         {
6760                         if (foundDash == YES)
6761                             {
6762                             MrBayesPrint ("%s   Unexpected dash\n", spacer);
6763                             return (ERROR);
6764                             }
6765                         fromI = tempInt;
6766                         tempActiveConstraints[fromI-1] = YES;
6767                         }
6768                     else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
6769                         {
6770                         toJ = tempInt;
6771                         //for (i=fromI-1; i<toJ; i++)
6772                         for (i=fromI; i<toJ; i++)
6773                             tempActiveConstraints[i] = YES;
6774                         fromI = toJ = -1;
6775                         foundDash = NO;
6776                         }
6777                     else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
6778                         {
6779                         fromI = tempInt;
6780                         tempActiveConstraints[fromI-1] = YES;
6781                         foundComma = NO;
6782                         }
6783                     expecting  = Expecting(COMMA);
6784                     expecting |= Expecting(DASH);
6785                     expecting |= Expecting(RIGHTPAR);
6786                     }
6787                 else /* if (!strcmp(modelParams[i].topologyPr,"Fixed")) */
6788                     {
6789                     if (numUserTrees == 0)
6790                         {
6791                         MrBayesPrint ("%s   No user trees have been defined\n", spacer);
6792                         return (ERROR);
6793                         }
6794                     sscanf (tkn, "%d", &tempInt);
6795                     if (tempInt > numUserTrees)
6796                         {
6797                         MrBayesPrint ("%s   Tree number is too large\n", spacer);
6798                         return (ERROR);
6799                         }
6800                     if (tempInt < 1)
6801                         {
6802                         MrBayesPrint ("%s   Tree number is too small\n", spacer);
6803                         return (ERROR);
6804                         }
6805                     fromI = tempInt;
6806                     expecting = Expecting(RIGHTPAR);    /* only one tree number acceptable */
6807                     }
6808                 }
6809             else if (expecting == Expecting(COMMA))
6810                 {
6811                 foundComma = YES;
6812                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
6813                 }
6814             else if (expecting == Expecting(DASH))
6815                 {
6816                 foundDash = YES;
6817                 expecting = Expecting(NUMBER);
6818                 }
6819             else if (expecting == Expecting(RIGHTPAR))
6820                 {
6821                 /* find out whether we need a tree number or constraint number(s) */
6822                 nApplied = NumActiveParts ();
6823                 for (i=0; i<numCurrentDivisions; i++)
6824                     if (activeParts[i] == YES || nApplied == 0)
6825                         break;
6826
6827                 if (!strcmp(modelParams[i].topologyPr,"Constraints"))
6828                     {
6829                     /* set constraints */
6830                     for (i=0; i<numCurrentDivisions; i++)
6831                         {
6832                         if (activeParts[i] == YES || nApplied == 0)
6833                             {
6834                             modelParams[i].numActiveConstraints = 0;
6835                             for (j=0; j<numDefinedConstraints; j++)
6836                                 {
6837                                 if (tempActiveConstraints[j] == YES)
6838                                     {
6839                                     modelParams[i].activeConstraints[j] = YES;
6840                                     modelParams[i].numActiveConstraints++;
6841                                     }
6842                                 else
6843                                     modelParams[i].activeConstraints[j] = NO;
6844                                 }
6845                             if (modelParams[i].numActiveConstraints == 0)
6846                                 {
6847                                 MrBayesPrint ("%s   No constraints have been defined\n", spacer);
6848                                 return (ERROR);
6849                                 }
6850                             }
6851                         }
6852                     }
6853                 else /* if (!strcmp(modelParams[i].topologyPr,"Constraints")) */
6854                     {
6855                     /* set start tree index */
6856                     for (i=0; i<numCurrentDivisions; i++)
6857                         {
6858                         if (activeParts[i] == YES || nApplied == 0)
6859                             modelParams[i].topologyFix = fromI-1;
6860                         }
6861                     }
6862 #               if 0
6863                 for (i=0; i<numCurrentDivisions; i++)
6864                     {
6865                     MrBayesPrint ("%4d -- ", i+1);
6866                     for (j=0; j<numDefinedConstraints; j++)
6867                         MrBayesPrint (" %d", modelParams[i].activeConstraints[j]);
6868                     MrBayesPrint ("\n");
6869                     }
6870 #               endif               
6871                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6872                 }
6873             else
6874                 return (ERROR);
6875             }
6876         /* set Nodeagepr (nodeAgePr) ********************************************************/
6877         else if (!strcmp(parmName, "Nodeagepr"))
6878             {
6879             if (expecting == Expecting(EQUALSIGN))
6880                 expecting = Expecting(ALPHA);
6881             else if (expecting == Expecting(ALPHA))
6882                 {
6883                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6884                     {
6885                     nApplied = NumActiveParts ();
6886                     for (i=0; i<numCurrentDivisions; i++)
6887                         {
6888                         if (activeParts[i] == YES || nApplied == 0)
6889                             {
6890                             strcpy(modelParams[i].nodeAgePr, tempStr);
6891                             if (nApplied == 0 && numCurrentDivisions == 1)
6892                                 MrBayesPrint ("%s   Setting Nodeagepr to %s\n", spacer, modelParams[i].nodeAgePr);
6893                             else
6894                                 MrBayesPrint ("%s   Setting Nodeagepr to %s for partition %d\n", spacer, modelParams[i].nodeAgePr, i+1);
6895                             }
6896                         }
6897                     }
6898                 else
6899                     {
6900                     MrBayesPrint ("%s   Invalid Nodeagepr argument\n", spacer);
6901                     return (ERROR);
6902                     }
6903                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6904                 }
6905             else
6906                 return (ERROR);
6907             }
6908         /* set Clockvarpr (clockVarPr) ********************************************************/
6909         else if (!strcmp(parmName, "Clockvarpr"))
6910             {
6911             if (expecting == Expecting(EQUALSIGN))
6912                 expecting = Expecting(ALPHA);
6913             else if (expecting == Expecting(ALPHA))
6914                 {
6915                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6916                     {
6917                     if (strcmp(tempStr, "Bm") == 0)
6918                         strcpy(tempStr, "TK02");
6919                     else if (strcmp(tempStr, "Ibr") == 0)
6920                         strcpy(tempStr, "Igr");
6921                     nApplied = NumActiveParts ();
6922                     for (i=0; i<numCurrentDivisions; i++)
6923                         {
6924                         if (activeParts[i] == YES || nApplied == 0)
6925                             {
6926                             strcpy(modelParams[i].clockVarPr, tempStr);
6927                             if (nApplied == 0 && numCurrentDivisions == 1)
6928                                 MrBayesPrint ("%s   Setting Clockvarpr to %s\n", spacer, modelParams[i].clockVarPr);
6929                             else
6930                                 MrBayesPrint ("%s   Setting Clockvarpr to %s for partition %d\n", spacer, modelParams[i].clockVarPr, i+1);
6931                             }
6932                         }
6933                     }
6934                 else
6935                     {
6936                     MrBayesPrint ("%s   Invalid Clockvarpr argument\n", spacer);
6937                     return (ERROR);
6938                     }
6939                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6940                 }
6941             else
6942                 return (ERROR);
6943             }
6944         /* set Brlenspr (brlensPr) ************************************************************/
6945         else if (!strcmp(parmName, "Brlenspr"))
6946             {
6947             if (expecting == Expecting(EQUALSIGN))
6948                 {
6949                 for (i=0; i<numCurrentDivisions; i++)
6950                     numVars[i] = NO;
6951                 foundEqual = YES;
6952                 foundLeftPar = NO;
6953                 expecting = Expecting(ALPHA);
6954                 }
6955             else if (expecting == Expecting(ALPHA))
6956                 {
6957                 if (foundEqual == YES)
6958                     {
6959                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6960                         {
6961                         strcpy (colonPr, tempStr);
6962                         nApplied = NumActiveParts ();
6963                         for (i=0; i<numCurrentDivisions; i++)
6964                             if (activeParts[i] == YES || nApplied == 0)
6965                                 strcpy(modelParams[i].brlensPr, tempStr);
6966                         }
6967                     else
6968                         {
6969                         MrBayesPrint ("%s   Invalid Brlenspr argument\n", spacer);
6970                         return (ERROR);
6971                         }
6972                     foundEqual = NO;
6973                     if (!strcmp(colonPr,"Fixed"))
6974                         expecting = Expecting(LEFTPAR);
6975                     else
6976                         expecting = Expecting(COLON);
6977                     }
6978                 else if (foundLeftPar == YES)
6979                     {
6980                     /*process argument of fixed() prior*/
6981                     /* find tree number */
6982                     if (GetUserTreeFromName (&tempInt, tkn) == ERROR)
6983                         {
6984                         MrBayesPrint ("%s   Could not set fixed branch lengths from the user tree '%s'\n", spacer, tkn);
6985                         return (ERROR);
6986                         }
6987                     fromI = tempInt + 1;        /* fromI is used to hold the index of the user tree, 1-based */
6988                     expecting = Expecting(RIGHTPAR);
6989                     foundLeftPar = NO;
6990                     }
6991                 else
6992                     {
6993                     if (!strcmp(colonPr, "Unconstrained"))
6994                         {
6995                         /* have unconstrained branch lengths, which we expect to have a uniform or exponential distribution */
6996                         nApplied = NumActiveParts ();
6997                         if (IsSame ("Uniform", tkn) == SAME || IsSame ("Uniform", tkn) == CONSISTENT_WITH)
6998                             {
6999                             for (i=0; i<numCurrentDivisions; i++)
7000                                 if (activeParts[i] == YES || nApplied == 0)
7001                                     strcpy(modelParams[i].unconstrainedPr, "Uniform");
7002                             }
7003                         else if (IsSame ("Exponential", tkn) == SAME || IsSame ("Exponential", tkn) == CONSISTENT_WITH)
7004                             {
7005                             for (i=0; i<numCurrentDivisions; i++)
7006                                 if (activeParts[i] == YES || nApplied == 0)
7007                                     strcpy(modelParams[i].unconstrainedPr, "Exponential");
7008                             }
7009                         else if (IsSame ("GammaDirichlet", tkn) == SAME || IsSame ("GammaDirichlet", tkn) == CONSISTENT_WITH)
7010                             {
7011                             for (i=0; i<numCurrentDivisions; i++)
7012                                 if (activeParts[i] == YES || nApplied == 0)
7013                                     strcpy(modelParams[i].unconstrainedPr, "GammaDir");
7014                             }
7015                         else if (IsSame ("invGamDirichlet", tkn) == SAME || IsSame ("invGamDirichlet", tkn) == CONSISTENT_WITH)
7016                             {
7017                             for (i=0; i<numCurrentDivisions; i++)
7018                                 if (activeParts[i] == YES || nApplied == 0)
7019                                     strcpy(modelParams[i].unconstrainedPr, "invGamDir");
7020                             }
7021                         else if (IsSame ("twoExponential", tkn) == SAME || IsSame ("twoExponential", tkn) == CONSISTENT_WITH)
7022                             {
7023                             for (i=0; i<numCurrentDivisions; i++)
7024                                 if (activeParts[i] == YES || nApplied == 0)
7025                                     strcpy(modelParams[i].unconstrainedPr, "twoExp");
7026                             }
7027                         else
7028                             {
7029                             MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
7030                             return (ERROR);
7031                             }
7032                         expecting  = Expecting(LEFTPAR);
7033                         }
7034                     else if (!strcmp(colonPr, "Clock"))
7035                         {
7036                         /* otherwise we have a clock constraint and expect uniform, birthdeath, coalescence or fixed prior */
7037                         nApplied = NumActiveParts ();
7038                         if (IsSame ("Uniform", tkn) == SAME || IsSame ("Uniform", tkn) == CONSISTENT_WITH)
7039                             {
7040                             strcpy (clockPr, "Uniform");
7041                             for (i=0; i<numCurrentDivisions; i++)
7042                                 {
7043                                 if (activeParts[i] == YES || nApplied == 0)
7044                                     strcpy(modelParams[i].clockPr, "Uniform");
7045                                 if (nApplied == 0 && numCurrentDivisions == 1)
7046                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Uniform\n", spacer);
7047                                 else
7048                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Uniform for partition %d\n", spacer, i+1);
7049                                 }
7050                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7051                             }
7052                         else if (IsSame ("Birthdeath", tkn) == SAME || IsSame ("Birthdeath", tkn) == CONSISTENT_WITH)
7053                             {
7054                             strcpy (clockPr, "Birthdeath");
7055                             for (i=0; i<numCurrentDivisions; i++)
7056                                 {
7057                                 if (activeParts[i] == YES || nApplied == 0)
7058                                     strcpy(modelParams[i].clockPr, "Birthdeath");
7059                                 if (nApplied == 0 && numCurrentDivisions == 1)
7060                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Birthdeath\n", spacer);
7061                                 else
7062                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Birthdeath for partition %d\n", spacer, i+1);
7063                                 }
7064                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7065                             }
7066                         else if (IsSame ("Coalescence", tkn) == SAME || IsSame ("Coalescence", tkn) == CONSISTENT_WITH)
7067                             {
7068                             strcpy (clockPr, "Coalescence");
7069                             for (i=0; i<numCurrentDivisions; i++)
7070                                 {
7071                                 if (activeParts[i] == YES || nApplied == 0)
7072                                     strcpy(modelParams[i].clockPr, "Coalescence");
7073                                 if (nApplied == 0 && numCurrentDivisions == 1)
7074                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Coalescence\n", spacer);
7075                                 else
7076                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Coalescence for partition %d\n", spacer, i+1);
7077                                 }
7078                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7079                             }
7080                         else if (IsSame ("Speciestreecoalescence", tkn) == SAME || IsSame ("Speciestreecoalescence", tkn) == CONSISTENT_WITH)
7081                             {
7082                             strcpy (clockPr, "Speciestreecoalescence");
7083                             for (i=0; i<numCurrentDivisions; i++)
7084                                 {
7085                                 if (activeParts[i] == YES || nApplied == 0)
7086                                     strcpy(modelParams[i].clockPr, "Speciestreecoalescence");
7087                                 if (nApplied == 0 && numCurrentDivisions == 1)
7088                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Speciestreecoalescence\n", spacer);
7089                                 else
7090                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Speciestreecoalescence for partition %d\n", spacer, i+1);
7091                                 }
7092                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7093                             }
7094                         else if (IsSame ("Fossilization", tkn) == SAME || IsSame ("Fossilization", tkn) == CONSISTENT_WITH)
7095                             {
7096                             strcpy (clockPr, "Fossilization");
7097                             for (i=0; i<numCurrentDivisions; i++)
7098                                 {
7099                                 if (activeParts[i] == YES || nApplied == 0)
7100                                     strcpy(modelParams[i].clockPr, "Fossilization");
7101                                 if (nApplied == 0 && numCurrentDivisions == 1)
7102                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Fossilization\n", spacer);
7103                                 else
7104                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Fossilization for partition %d\n", spacer, i+1);
7105                                 }
7106                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7107                             }
7108                         else if (IsSame ("Fixed", tkn) == SAME || IsSame ("Fixed", tkn) == CONSISTENT_WITH)
7109                             {
7110                             strcpy (clockPr, "Fixed");
7111                             for (i=0; i<numCurrentDivisions; i++)
7112                                 {
7113                                 if (activeParts[i] == YES || nApplied == 0)
7114                                     strcpy(modelParams[i].clockPr, "Fixed");
7115                                 }
7116                             expecting = Expecting(LEFTPAR);     /* Proceed with tree name */
7117                             }
7118                         else
7119                             {
7120                             MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
7121                             return (ERROR);
7122                             }
7123                         }
7124                     else
7125                         {
7126                         MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
7127                         return (ERROR);
7128                         }
7129                     }
7130                 }
7131             else if (expecting == Expecting(LEFTPAR))
7132                 {
7133                 foundLeftPar = YES;
7134                 expecting  = Expecting(NUMBER);
7135                 if (!strcmp(colonPr,"Fixed") || (!strcmp(colonPr,"Clock") && !strcmp(clockPr,"Fixed")))
7136                     {
7137                     expecting |= Expecting(ALPHA);
7138                     }
7139                 else
7140                     {
7141                     for (i=0; i<numCurrentDivisions; i++)
7142                         numVars[i] = 0;
7143                     }
7144                 }
7145             else if (expecting == Expecting(NUMBER))
7146                 {
7147                 if (!strcmp(colonPr, "Unconstrained"))
7148                     {
7149                     /* have unconstrained branch lengths */
7150                     nApplied = NumActiveParts ();
7151                     for (i=0; i<numCurrentDivisions; i++)
7152                         {
7153                         if (activeParts[i] == YES || nApplied == 0)
7154                             {
7155                             if (!strcmp(modelParams[i].unconstrainedPr,"Uniform"))
7156                                 {
7157                                 sscanf (tkn, "%lf", &tempD);
7158                                 modelParams[i].brlensUni[numVars[i]++] = tempD;
7159                                 if (numVars[i] == 1)
7160                                     expecting  = Expecting(COMMA);
7161                                 else
7162                                     {
7163                                     if (modelParams[i].brlensUni[0] > 0.000001)
7164                                         {
7165                                         MrBayesPrint ("%s   Lower value for uniform must equal 0.0\n", spacer);
7166                                         return (ERROR);
7167                                         }
7168                                     if (modelParams[i].brlensUni[0] >= modelParams[i].brlensUni[1])
7169                                         {
7170                                         MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
7171                                         return (ERROR);
7172                                         }
7173                                     if (nApplied == 0 && numCurrentDivisions == 1)
7174                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlensUni[0], modelParams[i].brlensUni[1]);
7175                                     else
7176                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlensUni[0], modelParams[i].brlensUni[1], i+1);
7177                                     expecting  = Expecting(RIGHTPAR);
7178                                     }
7179                                 }
7180                             else if (!strcmp(modelParams[i].unconstrainedPr,"Exponential"))
7181                                 {
7182                                 sscanf (tkn, "%lf", &tempD);
7183                                 modelParams[i].brlensExp = tempD;
7184                                 if (modelParams[i].brlensExp <= 0.0)
7185                                     {
7186                                     MrBayesPrint ("%s   Value for exponential must > 0.0\n", spacer);
7187                                     return (ERROR);
7188                                     }
7189                                 if (nApplied == 0 && numCurrentDivisions == 1)
7190                                     MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Exponential(%1.2lf)\n", spacer, modelParams[i].brlensExp);
7191                                 else
7192                                     MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].brlensExp, i+1);
7193                                 expecting  = Expecting(RIGHTPAR);
7194                                 }
7195                             else if (!strcmp(modelParams[i].unconstrainedPr,"GammaDir"))
7196                                 {
7197                                 sscanf (tkn, "%lf", &tempD);
7198                                 modelParams[i].brlensDir[numVars[i]++] = tempD;
7199                                 if (numVars[i] == 1 || numVars[i] == 2 || numVars[i] == 3)
7200                                     expecting  = Expecting(COMMA);
7201                                 else
7202                                     {
7203                                     if (modelParams[i].brlensDir[0] <= 0.0 || modelParams[i].brlensDir[1] <= 0.0 || modelParams[i].brlensDir[2] <= 0.0 || modelParams[i].brlensDir[3] <= 0.0)
7204                                         {
7205                                         MrBayesPrint ("%s   alphaT & betaT & a & c for GammaDir prior must > 0.0\n", spacer);
7206                                         return (ERROR);
7207                                         }
7208                                     if (nApplied == 0 && numCurrentDivisions == 1)
7209                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:GammaDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3]);
7210                                     else
7211                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:GammaDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3], i+1);
7212                                     expecting  = Expecting(RIGHTPAR);
7213                                     }
7214                                 }
7215                             else if (!strcmp(modelParams[i].unconstrainedPr,"invGamDir"))
7216                                 {
7217                                 sscanf (tkn, "%lf", &tempD);
7218                                 modelParams[i].brlensDir[numVars[i]++] = tempD;
7219                                 if (numVars[i] == 1 || numVars[i] == 2 || numVars[i] == 3)
7220                                     expecting  = Expecting(COMMA);
7221                                 else
7222                                     {
7223                                     if (modelParams[i].brlensDir[0] <= 2.0 || modelParams[i].brlensDir[1] <= 0.0 || modelParams[i].brlensDir[2] <= 0.0 || modelParams[i].brlensDir[3] <= 0.0)
7224                                         {
7225                                         MrBayesPrint ("%s   alphaT must > 2.0, betaT & a & c for invGamDir prior must > 0.0\n", spacer);
7226                                         return (ERROR);
7227                                         }
7228                                     if (nApplied == 0 && numCurrentDivisions == 1)
7229                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:invGamDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3]);
7230                                     else
7231                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:invGamDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3], i+1);
7232                                     expecting  = Expecting(RIGHTPAR);
7233                                     }
7234                                 }
7235                             else if (!strcmp(modelParams[i].unconstrainedPr,"twoExp"))
7236                                 {
7237                                     sscanf (tkn, "%lf", &tempD);
7238                                     modelParams[i].brlens2Exp[numVars[i]++] = tempD;
7239                                     if (numVars[i] == 1)
7240                                         expecting  = Expecting(COMMA);
7241                                     else
7242                                     {
7243                                         if (modelParams[i].brlens2Exp[0] <= 0.0 || modelParams[i].brlens2Exp[1] <= 0.0)
7244                                             {
7245                                             MrBayesPrint ("%s   Values for the two exponentials must > 0.0\n", spacer);
7246                                             return (ERROR);
7247                                             }
7248                                         if (nApplied == 0 && numCurrentDivisions == 1)
7249                                             MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:twoExp(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlens2Exp[0], modelParams[i].brlens2Exp[1]);
7250                                         else
7251                                             MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:twoExp(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlens2Exp[0], modelParams[i].brlens2Exp[1], i+1);
7252                                         expecting  = Expecting(RIGHTPAR);
7253                                     }
7254                                 }
7255                             }
7256                         }
7257                     }
7258                 else if (!strcmp(colonPr,"Fixed") || !strcmp(colonPr,"Clock"))
7259                     {
7260                     sscanf (tkn, "%d", &tempInt);
7261                     if (tempInt < 1 || tempInt > numUserTrees)
7262                         {
7263                         MrBayesPrint ("%s   Tree needs to be in the range %d to %d\n", spacer, 1, numUserTrees);
7264                         return (ERROR);
7265                         }
7266                     fromI = tempInt;
7267                     expecting = Expecting(RIGHTPAR);
7268                     }
7269                 foundLeftPar = NO;
7270                 }
7271             else if (expecting == Expecting(COLON))
7272                 {
7273                 expecting  = Expecting(ALPHA);
7274                 }
7275             else if (expecting == Expecting(COMMA))
7276                 {
7277                 expecting  = Expecting(NUMBER);
7278                 }
7279             else if (expecting == Expecting(RIGHTPAR))
7280                 {
7281                 if (!strcmp(colonPr,"Fixed") || (!strcmp(colonPr,"Clock") && !strcmp(clockPr,"Fixed")))
7282                     {
7283                     /* index of a tree which set up branch lengths*/
7284                     nApplied = NumActiveParts ();
7285                     for (i=0; i<numCurrentDivisions; i++)
7286                         {
7287                         if (activeParts[i] == YES || nApplied == 0)
7288                             modelParams[i].brlensFix = fromI-1;
7289                         if (!strcmp(colonPr,"Fixed"))
7290                             {
7291                             if (nApplied == 0 && numCurrentDivisions == 1)
7292                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s)\n", spacer, userTree[fromI-1]->name);
7293                             else
7294                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s) for partition %d\n", spacer, userTree[fromI-1]->name, i+1);
7295                             }
7296                         else
7297                             {
7298                             if (nApplied == 0 && numCurrentDivisions == 1)
7299                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s)\n", spacer, userTree[fromI-1]->name);
7300                             else
7301                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s) for partition %d\n", spacer, userTree[fromI-1]->name, i+1);
7302                             }
7303                         }
7304                     }
7305                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7306                 }
7307             else
7308                 return (ERROR);
7309             }
7310         /* set Speciationpr (speciationPr) *************************************************/
7311         else if (!strcmp(parmName, "Speciationpr"))
7312             {
7313             if (expecting == Expecting(EQUALSIGN))
7314                 expecting = Expecting(ALPHA);
7315             else if (expecting == Expecting(ALPHA))
7316                 {
7317                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7318                     {
7319                     nApplied = NumActiveParts ();
7320                     for (i=0; i<numCurrentDivisions; i++)
7321                         if (activeParts[i] == YES || nApplied == 0)
7322                             strcpy(modelParams[i].speciationPr, tempStr);
7323                     }
7324                 else
7325                     {
7326                     MrBayesPrint ("%s   Invalid Speciationpr argument\n", spacer);
7327                     return (ERROR);
7328                     }
7329                 expecting  = Expecting(LEFTPAR);
7330                 for (i=0; i<numCurrentDivisions; i++)
7331                     numVars[i] = 0;
7332                 }
7333             else if (expecting == Expecting(LEFTPAR))
7334                 {
7335                 expecting  = Expecting(NUMBER);
7336                 }
7337             else if (expecting == Expecting(NUMBER))
7338                 {
7339                 nApplied = NumActiveParts ();
7340                 for (i=0; i<numCurrentDivisions; i++)
7341                     {
7342                     if (activeParts[i] == YES || nApplied == 0)
7343                         {
7344                         if (!strcmp(modelParams[i].speciationPr,"Uniform"))
7345                             {
7346                             sscanf (tkn, "%lf", &tempD);
7347                             modelParams[i].speciationUni[numVars[i]++] = tempD;
7348                             if (numVars[i] == 1)
7349                                 expecting  = Expecting(COMMA);
7350                             else
7351                                 {
7352                                 if (modelParams[i].speciationUni[0] >= modelParams[i].speciationUni[1])
7353                                     {
7354                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
7355                                     return (ERROR);
7356                                     }
7357                                 if (nApplied == 0 && numCurrentDivisions == 1)
7358                                     MrBayesPrint ("%s   Setting Speciationpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].speciationUni[0], modelParams[i].speciationUni[1]);
7359                                 else
7360                                     MrBayesPrint ("%s   Setting Speciationpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].speciationUni[0], modelParams[i].speciationUni[1], i+1);
7361                                 expecting  = Expecting(RIGHTPAR);
7362                                 }
7363                             }
7364                         else if (!strcmp(modelParams[i].speciationPr,"Exponential"))
7365                             {
7366                             sscanf (tkn, "%lf", &tempD);
7367                             if (tempD <= 0.0)
7368                                 {
7369                                 MrBayesPrint ("%s   Exponential parameter must be positive\n", spacer);
7370                                 return (ERROR);
7371                                 }
7372                             modelParams[i].speciationExp = tempD;
7373                             if (nApplied == 0 && numCurrentDivisions == 1)
7374                                 MrBayesPrint ("%s   Setting Speciationpr to Exponential(%1.2lf)\n", spacer, modelParams[i].speciationExp);
7375                             else
7376                                 MrBayesPrint ("%s   Setting Speciationpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].speciationExp, i+1);
7377                             expecting  = Expecting(RIGHTPAR);
7378                             }
7379                         else if (!strcmp(modelParams[i].speciationPr,"Fixed"))
7380                             {
7381                             sscanf (tkn, "%lf", &tempD);
7382                             if (tempD <= 0.0)
7383                                 {
7384                                 MrBayesPrint ("%s   Net speciation rate must be positive\n", spacer);
7385                                 return (ERROR);
7386                                 }
7387                             modelParams[i].speciationFix = tempD;
7388                             if (nApplied == 0 && numCurrentDivisions == 1)
7389                                 MrBayesPrint ("%s   Setting Speciationpr to Fixed(%1.2lf)\n", spacer, modelParams[i].speciationFix);
7390                             else
7391                                 MrBayesPrint ("%s   Setting Speciationpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].speciationFix, i+1);
7392                             expecting  = Expecting(RIGHTPAR);
7393                             }
7394                         }
7395                     }
7396                 }
7397             else if (expecting == Expecting(COMMA))
7398                 {
7399                 expecting  = Expecting(NUMBER);
7400                 }
7401             else if (expecting == Expecting(RIGHTPAR))
7402                 {
7403                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7404                 }
7405             else
7406                 return (ERROR);
7407             }
7408         /* set Extinctionpr (extinctionPr) *************************************************/
7409         else if (!strcmp(parmName, "Extinctionpr"))
7410             {
7411             if (expecting == Expecting(EQUALSIGN))
7412                 expecting = Expecting(ALPHA);
7413             else if (expecting == Expecting(ALPHA))
7414                 {
7415                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7416                     {
7417                     nApplied = NumActiveParts ();
7418                     for (i=0; i<numCurrentDivisions; i++)
7419                         if (activeParts[i] == YES || nApplied == 0)
7420                             strcpy(modelParams[i].extinctionPr, tempStr);
7421                     }
7422                 else
7423                     {
7424                     MrBayesPrint ("%s   Invalid Extinctionpr argument\n", spacer);
7425                     return (ERROR);
7426                     }
7427                 expecting  = Expecting(LEFTPAR);
7428                 for (i=0; i<numCurrentDivisions; i++)
7429                     numVars[i] = 0;
7430                 }
7431             else if (expecting == Expecting(LEFTPAR))
7432                 {
7433                 expecting  = Expecting(NUMBER);
7434                 }
7435             else if (expecting == Expecting(NUMBER))
7436                 {
7437                 nApplied = NumActiveParts ();
7438                 for (i=0; i<numCurrentDivisions; i++)
7439                     {
7440                     if (activeParts[i] == YES || nApplied == 0)
7441                         {
7442                         if (!strcmp(modelParams[i].extinctionPr,"Beta"))
7443                             {
7444                             sscanf (tkn, "%lf", &tempD);
7445                             if (tempD <= 0.0)
7446                                 {
7447                                 MrBayesPrint ("%s   Beta parameter must be positive\n", spacer);
7448                                 return (ERROR);
7449                                 }
7450                             modelParams[i].extinctionBeta[numVars[i]++] = tempD;
7451                             if (numVars[i] == 1)
7452                                 expecting  = Expecting(COMMA);
7453                             else
7454                                 {
7455                                 if (nApplied == 0 && numCurrentDivisions == 1)
7456                                     MrBayesPrint ("%s   Setting Extinctionpr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].extinctionBeta[0], modelParams[i].extinctionBeta[1]);
7457                                 else
7458                                     MrBayesPrint ("%s   Setting Extinctionpr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].extinctionBeta[0], modelParams[i].extinctionBeta[1], i+1);
7459                                 expecting  = Expecting(RIGHTPAR);
7460                                 }
7461                             }
7462                         else if (!strcmp(modelParams[i].extinctionPr,"Fixed"))
7463                             {
7464                             sscanf (tkn, "%lf", &tempD);
7465                             if (tempD < 0.0 || tempD >= 1.0)
7466                                 {
7467                                 MrBayesPrint ("%s   Relative extinction rate must be in range [0,1)\n", spacer);
7468                                 return (ERROR);
7469                                 }
7470                             modelParams[i].extinctionFix = tempD;
7471                             if (nApplied == 0 && numCurrentDivisions == 1)
7472                                 MrBayesPrint ("%s   Setting Extinctionpr to Fixed(%1.2lf)\n", spacer, modelParams[i].extinctionFix);
7473                             else
7474                                 MrBayesPrint ("%s   Setting Extinctionpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].extinctionFix, i+1);
7475                             expecting  = Expecting(RIGHTPAR);
7476                             }
7477                         }
7478                     }
7479                 }
7480             else if (expecting == Expecting(COMMA))
7481                 {
7482                 expecting  = Expecting(NUMBER);
7483                 }
7484             else if (expecting == Expecting(RIGHTPAR))
7485                 {
7486                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7487                 }
7488             else
7489                 return (ERROR);
7490             }
7491         /* set Fossilizationpr (fossilizationPr) */
7492         else if (!strcmp(parmName, "Fossilizationpr"))
7493             {
7494             if (expecting == Expecting(EQUALSIGN))
7495                 expecting = Expecting(ALPHA);
7496             else if (expecting == Expecting(ALPHA))
7497                 {
7498                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7499                     {
7500                     nApplied = NumActiveParts ();
7501                     for (i=0; i<numCurrentDivisions; i++)
7502                         if (activeParts[i] == YES || nApplied == 0)
7503                             strcpy(modelParams[i].fossilizationPr, tempStr);
7504                     }
7505                 else
7506                     {
7507                     MrBayesPrint ("%s   Invalid Fossilization argument\n", spacer);
7508                     return (ERROR);
7509                     }
7510                 expecting  = Expecting(LEFTPAR);
7511                 for (i=0; i<numCurrentDivisions; i++)
7512                     numVars[i] = 0;
7513                 }
7514             else if (expecting == Expecting(LEFTPAR))
7515                 {
7516                 expecting  = Expecting(NUMBER);
7517                 }
7518             else if (expecting == Expecting(NUMBER))
7519                 {
7520                 nApplied = NumActiveParts ();
7521                 for (i=0; i<numCurrentDivisions; i++)
7522                     {
7523                     if (activeParts[i] == YES || nApplied == 0)
7524                         {
7525                         if (!strcmp(modelParams[i].fossilizationPr,"Beta"))
7526                             {
7527                             sscanf (tkn, "%lf", &tempD);
7528                             if (tempD <= 0.0)
7529                                 {
7530                                 MrBayesPrint ("%s   Beta parameter must be positive\n", spacer);
7531                                 return (ERROR);
7532                                 }
7533                             modelParams[i].fossilizationBeta[numVars[i]++] = tempD;
7534                             if (numVars[i] == 1)
7535                                 expecting  = Expecting(COMMA);
7536                             else
7537                                 {
7538                                 if (nApplied == 0 && numCurrentDivisions == 1)
7539                                     MrBayesPrint ("%s   Setting Fossilizationpr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].fossilizationBeta[0], modelParams[i].fossilizationBeta[1]);
7540                                 else
7541                                     MrBayesPrint ("%s   Setting Fossilizationpr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].fossilizationBeta[0], modelParams[i].fossilizationBeta[1], i+1);
7542                                 expecting  = Expecting(RIGHTPAR);
7543                                 }
7544                             }
7545                         else if (!strcmp(modelParams[i].fossilizationPr,"Fixed"))
7546                             {
7547                             sscanf (tkn, "%lf", &tempD);
7548                             if (tempD < 0.0 || tempD > 1.0)
7549                                 {
7550                                 MrBayesPrint ("%s   Relative fossilization rate must be in the range (0,1]\n", spacer);
7551                                 return (ERROR);
7552                                 }
7553                             modelParams[i].fossilizationFix = tempD;
7554                             if (nApplied == 0 && numCurrentDivisions == 1)
7555                                 MrBayesPrint ("%s   Setting Fossilizationpr to Fixed(%1.2lf)\n", spacer, modelParams[i].fossilizationFix);
7556                             else
7557                                 MrBayesPrint ("%s   Setting Fossilizationpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].fossilizationFix, i+1);
7558                             expecting  = Expecting(RIGHTPAR);
7559                             }
7560                         }
7561                     }
7562                 }
7563             else if (expecting == Expecting(COMMA))
7564                 {
7565                 expecting  = Expecting(NUMBER);
7566                 }
7567             else if (expecting == Expecting(RIGHTPAR))
7568                 {
7569                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7570                 }
7571             else
7572                 return (ERROR);
7573             }
7574         /* set SampleStrat (sampleStrat) ***************************************************/
7575         else if (!strcmp(parmName, "Samplestrat"))
7576             {
7577             if (expecting == Expecting(EQUALSIGN))
7578                 {
7579                 expecting = Expecting(ALPHA);
7580                 }
7581             else if (expecting == Expecting(ALPHA))
7582                 {
7583                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7584                     {
7585                     nApplied = NumActiveParts ();
7586                     for (i=0; i<numCurrentDivisions; i++)
7587                         {
7588                         if (activeParts[i] == YES || nApplied == 0)
7589                             {
7590                             strcpy(modelParams[i].sampleStrat, tempStr);
7591                             if (nApplied == 0 && numCurrentDivisions == 1)
7592                                 MrBayesPrint ("%s   Setting SampleStrat to %s\n", spacer, modelParams[i].sampleStrat);
7593                             else
7594                                 MrBayesPrint ("%s   Setting SampleStrat to %s for partition %d\n", spacer, modelParams[i].sampleStrat, i+1);
7595                             if (!strcmp(modelParams[i].sampleStrat,"Random") || !strcmp(modelParams[i].sampleStrat,"Diversity"))
7596                                 {
7597                                 foundFSNum[i] = foundFSTime[i] = NO;
7598                                 modelParams[i].sampleFSNum = 0;
7599                                 numVars[i] = 0;
7600                                 expecting  = Expecting(NUMBER);
7601                                 expecting |= Expecting(PARAMETER);
7602                                 expecting |= Expecting(SEMICOLON);
7603                                 }
7604                             else
7605                                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7606                             }
7607                         }
7608                     }
7609                 else
7610                     {
7611                     MrBayesPrint ("%s   Invalid Samplestrat argument\n", spacer);
7612                     return (ERROR);
7613                     }
7614                 }
7615             else if (expecting == Expecting(NUMBER))
7616                 {
7617                 nApplied = NumActiveParts ();
7618                 for (i=0; i<numCurrentDivisions; i++)
7619                     {
7620                     if (activeParts[i] == YES || nApplied == 0)
7621                         {
7622                         if (foundFSNum[i] == NO)
7623                             {
7624                             sscanf (tkn, "%d", &tempInt);
7625                             if (tempInt <= 0)
7626                                 {
7627                                 MrBayesPrint ("%s   Number of fossil slice sampling events must be > 0\n", spacer);
7628                                 return (ERROR);
7629                                 }
7630                             modelParams[i].sampleFSNum = tempInt;
7631                             if (memAllocs[ALLOC_SAMPLEFOSSILSLICE] == YES)
7632                                 {
7633                                 free(modelParams[i].sampleFSProb);
7634                                 free(modelParams[i].sampleFSTime);
7635                                 }
7636                             modelParams[i].sampleFSTime = (MrBFlt *) SafeMalloc ((size_t)tempInt * sizeof(MrBFlt));
7637                             modelParams[i].sampleFSProb = (MrBFlt *) SafeMalloc ((size_t)tempInt * sizeof(MrBFlt));
7638                             memAllocs[ALLOC_SAMPLEFOSSILSLICE] = YES;
7639                             foundFSNum[i] = YES;
7640                             expecting  = Expecting(COLON);
7641                             }
7642                         else if (foundFSTime[i] == NO)
7643                             {
7644                             sscanf (tkn, "%lf", &tempD);
7645                             if (tempD <= 0.0)
7646                                 {
7647                                 MrBayesPrint ("%s   Time of fossil slice sampling events must be > 0.\n", spacer);
7648                                 return (ERROR);
7649                                 }
7650                             if (numVars[i] > 0 && modelParams[i].sampleFSTime[numVars[i]-1] < tempD)
7651                                 {
7652                                 MrBayesPrint ("%s   Time of fossil slice sampling events must be in decreasing order\n", spacer);
7653                                 return (ERROR);
7654                                 }
7655                             modelParams[i].sampleFSTime[numVars[i]] = tempD;
7656                             foundFSTime[i] = YES;
7657                             expecting  = Expecting(NUMBER);
7658                             }
7659                         else
7660                             {
7661                             sscanf (tkn, "%lf", &tempD);
7662                             if (tempD < 0.0 || tempD > 1.0)
7663                                 {
7664                                 MrBayesPrint ("%s   Prob of fossil slice sampling events must be in [0,1]\n", spacer);
7665                                 return (ERROR);
7666                                 }
7667                             modelParams[i].sampleFSProb[numVars[i]] = tempD;
7668                             foundFSTime[i] = NO;
7669                             expecting  = Expecting(COMMA);
7670                             if (nApplied == 0 && numCurrentDivisions == 1)
7671                                 MrBayesPrint ("%s   Setting %d FSTime FSProb to %1.2lf %1.6lf\n", spacer, numVars[i]+1,
7672                                               modelParams[i].sampleFSTime[numVars[i]], modelParams[i].sampleFSProb[numVars[i]]);
7673                             else
7674                                 MrBayesPrint ("%s   Setting %d FSTime FSProb to %1.2lf %1.6lf for partition %d\n", spacer, numVars[i]+1,
7675                                               modelParams[i].sampleFSTime[numVars[i]], modelParams[i].sampleFSProb[numVars[i]], i+1);
7676                             numVars[i]++;
7677                             if (numVars[i] == modelParams[i].sampleFSNum)
7678                                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7679                             }
7680                         }
7681                     }
7682                 }
7683             else if (expecting == Expecting(COLON) || expecting == Expecting(COMMA))
7684                 {
7685                 expecting  = Expecting(NUMBER);
7686                 }
7687             else
7688                 {
7689                 return (ERROR);
7690                 }
7691             }
7692         /* set Sampleprob (sampleProb) *****************************************************/
7693         else if (!strcmp(parmName, "Sampleprob"))
7694             {
7695             if (expecting == Expecting(EQUALSIGN))
7696                 expecting = Expecting(NUMBER);
7697             else if (expecting == Expecting(NUMBER))
7698                 {
7699                 nApplied = NumActiveParts ();
7700                 for (i=0; i<numCurrentDivisions; i++)
7701                     {
7702                     if ((activeParts[i] == YES || nApplied == 0))
7703                         {
7704                         sscanf (tkn, "%lf", &tempD);
7705                         if (tempD <= 0.0 || tempD > 1.0)
7706                             {
7707                             MrBayesPrint ("%s   Sampleprob should be in range (0,1]\n", spacer);
7708                             return (ERROR);
7709                             }
7710                         modelParams[i].sampleProb = tempD;
7711                         if (nApplied == 0 && numCurrentDivisions == 1)
7712                             MrBayesPrint ("%s   Setting Sampleprob to %1.8lf\n", spacer, modelParams[i].sampleProb);
7713                         else
7714                             MrBayesPrint ("%s   Setting Sampleprob to %1.8lf for partition %d\n", spacer, modelParams[i].sampleProb, i+1);
7715                         }
7716                     }
7717                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7718                 }
7719             else
7720                 return (ERROR);
7721             }
7722         /* set Treeagepr (treeAgePr) *******************************************************/
7723         else if (!strcmp(parmName, "Treeagepr"))
7724             {
7725             if (expecting == Expecting(EQUALSIGN))
7726                 expecting = Expecting(ALPHA);
7727             else if (expecting == Expecting(ALPHA))
7728                 {
7729                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7730                     {
7731                     nApplied = NumActiveParts ();
7732                     for (i=0; i<numCurrentDivisions; i++)
7733                         if (activeParts[i] == YES || nApplied == 0)
7734                             {
7735                             strcpy(modelParams[i].treeAgePr.name, tempStr);
7736                             if (!strcmp(tempStr,"Fixed"))
7737                                 modelParams[i].treeAgePr.prior = fixed;
7738                             else if (!strcmp(tempStr,"Uniform"))
7739                                 modelParams[i].treeAgePr.prior = uniform;
7740                             else if (!strcmp(tempStr,"Offsetexponential"))
7741                                 modelParams[i].treeAgePr.prior = offsetExponential;
7742                             else if (!strcmp(tempStr,"Truncatednormal"))
7743                                 modelParams[i].treeAgePr.prior = truncatedNormal;
7744                             else if (!strcmp(tempStr,"Lognormal"))
7745                                 modelParams[i].treeAgePr.prior = logNormal;
7746                             else if (!strcmp(tempStr,"Offsetlognormal"))
7747                                 modelParams[i].treeAgePr.prior = offsetLogNormal;
7748                             else if (!strcmp(tempStr,"Gamma"))
7749                                 modelParams[i].treeAgePr.prior = standardGamma;
7750                             else if (!strcmp(tempStr,"Offsetgamma"))
7751                                 modelParams[i].treeAgePr.prior = offsetGamma;
7752                             }
7753                     }
7754                 else
7755                     {
7756                     MrBayesPrint ("%s   Invalid Treeagepr argument\n", spacer);
7757                     return (ERROR);
7758                     }
7759                 expecting  = Expecting(LEFTPAR);
7760                 for (i=0; i<numCurrentDivisions; i++)
7761                     numVars[i] = 0;
7762                 }
7763             else if (expecting == Expecting(LEFTPAR))
7764                 {
7765                 nApplied = NumActiveParts ();
7766                 for (i=0; i<numCurrentDivisions; i++)
7767                     if (activeParts[i] == YES || nApplied == 0)
7768                         strcat(modelParams[i].treeAgePr.name, "(");
7769                 expecting  = Expecting(NUMBER);
7770                 }
7771             else if (expecting == Expecting(NUMBER))
7772                 {
7773                 sscanf (tkn, "%lf", &tempD);
7774                 sprintf (tempStr, "%1.2lf", tempD);
7775                 nApplied = NumActiveParts ();
7776                 for (i=0; i<numCurrentDivisions; i++)
7777                     {
7778                     if (activeParts[i] == YES || nApplied == 0)
7779                         {
7780                         if (numVars[i] == 0 && tempD < 0.0)
7781                             {
7782                             if (modelParams[i].treeAgePr.prior == uniform ||
7783                                 modelParams[i].treeAgePr.prior == offsetExponential ||
7784                                 modelParams[i].treeAgePr.prior == truncatedNormal ||
7785                                 modelParams[i].treeAgePr.prior == offsetLogNormal ||
7786                                 modelParams[i].treeAgePr.prior == offsetGamma)
7787                                 MrBayesPrint("%s   Minimum, offset or truncation point must be nonnegative\n", spacer);
7788                             else if (modelParams[i].treeAgePr.prior == fixed)
7789                                 MrBayesPrint("%s   Fixed age must be nonnegative\n", spacer);
7790                             else
7791                                 MrBayesPrint("%s   Mean must be nonnegative\n", spacer);
7792                             break;
7793                             }
7794                         else if (numVars[i] == 1)
7795                             {
7796                             if (modelParams[i].treeAgePr.prior == uniform && tempD <= modelParams[i].treeAgePr.priorParams[0])
7797                                 {
7798                                 MrBayesPrint("%s   Max of uniform distribution must be larger than min\n", spacer);
7799                                 break;
7800                                 }
7801                             else if ((modelParams[i].treeAgePr.prior == standardGamma || modelParams[i].treeAgePr.prior == logNormal) && tempD <= 0.0)
7802                                 {
7803                                 MrBayesPrint("%s   Standard deviation must be positive\n", spacer);
7804                                 break;
7805                                 }
7806                             else if ((modelParams[i].treeAgePr.prior == offsetExponential ||
7807                                       modelParams[i].treeAgePr.prior == offsetGamma ||
7808                                       modelParams[i].treeAgePr.prior == offsetLogNormal) && tempD <= modelParams[i].treeAgePr.priorParams[0])
7809                                 {
7810                                 MrBayesPrint("%s   Mean must be larger than offset\n", spacer);
7811                                 break;
7812                                 }
7813                             }
7814                         else if (numVars[i] == 2 && tempD <= 0.0)
7815                             {
7816                             MrBayesPrint("%s   Standard deviation must be positive\n", spacer);
7817                             break;
7818                             }
7819                         modelParams[i].treeAgePr.priorParams[numVars[i]++] = tempD;
7820                         sprintf (tempStr, "%1.2lf", tempD);
7821                         strcat(modelParams[i].treeAgePr.name, tempStr);
7822                         if (modelParams[i].treeAgePr.prior == fixed || numVars[i] == 3)
7823                             expecting = Expecting(RIGHTPAR);
7824                         else if (numVars[i] == 1)
7825                             expecting = Expecting(COMMA);
7826                         else if (modelParams[i].treeAgePr.prior == standardGamma ||
7827                                  modelParams[i].treeAgePr.prior == uniform ||
7828                                  modelParams[i].treeAgePr.prior == offsetExponential ||
7829                                  modelParams[i].treeAgePr.prior == logNormal)
7830                             expecting = Expecting(RIGHTPAR);
7831                         else
7832                             expecting = Expecting(COMMA);
7833                         }
7834                     }
7835                 if (i < numCurrentDivisions)
7836                     {
7837                     /* An error occurred. Reset calibrations and bail out */
7838                     nApplied = NumActiveParts ();
7839                     for (i=0; i<numCurrentDivisions; i++)
7840                         {
7841                         if (activeParts[i] == YES || nApplied == 0)
7842                             {
7843                             strcpy(modelParams[i].treeAgePr.name, "Gamma(1.00,1.00)");
7844                             modelParams[i].treeAgePr.prior = standardGamma;
7845                             modelParams[i].treeAgePr.priorParams[0] = 1.0;
7846                             modelParams[i].treeAgePr.priorParams[1] = 1.0;
7847                             modelParams[i].treeAgePr.priorParams[2] = -1.0;
7848                             modelParams[i].treeAgePr.min = 0.0;
7849                             modelParams[i].treeAgePr.max = POS_INFINITY;
7850                             }
7851                         }
7852                     return (ERROR);
7853                     }
7854                 }
7855             else if (expecting == Expecting(COMMA))
7856                 {
7857                 nApplied = NumActiveParts ();
7858                 for (i=0; i<numCurrentDivisions; i++)
7859                     if (activeParts[i] == YES || nApplied == 0)
7860                         strcat(modelParams[i].treeAgePr.name, ",");
7861                 expecting  = Expecting(NUMBER);
7862                 }
7863             else if (expecting == Expecting(RIGHTPAR))
7864                 {
7865                 nApplied = NumActiveParts ();
7866                 for (i=0; i<numCurrentDivisions; i++)
7867                     {
7868                     if (activeParts[i] == YES || nApplied == 0)
7869                         {
7870                         strcat(modelParams[i].treeAgePr.name, ")");
7871                         MrBayesPrint ("%s   Setting Treeagepr to %s\n", spacer, modelParams[i].treeAgePr.name);
7872
7873                         if (modelParams[i].treeAgePr.prior == fixed)
7874                             {
7875                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbFix;
7876                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioFix;
7877                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
7878                             modelParams[i].treeAgePr.max           = modelParams[i].treeAgePr.priorParams[0];
7879                             }
7880                         else if (modelParams[i].treeAgePr.prior == uniform)
7881                             {
7882                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbUniform;
7883                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioUniform;
7884                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
7885                             modelParams[i].treeAgePr.max           = modelParams[i].treeAgePr.priorParams[1];
7886                             }
7887                         else if (modelParams[i].treeAgePr.prior == offsetExponential)
7888                             {
7889                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbOffsetExponential_Param_Offset_Mean;
7890                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioOffsetExponential_Param_Offset_Mean;
7891                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
7892                             modelParams[i].treeAgePr.max           = POS_INFINITY;
7893                             }
7894                         else if (modelParams[i].treeAgePr.prior == truncatedNormal)
7895                             {
7896                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbTruncatedNormal_Param_Trunc_Mean_Sd;
7897                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioTruncatedNormal_Param_Trunc_Mean_Sd;
7898                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
7899                             modelParams[i].treeAgePr.max           = POS_INFINITY;
7900                             }
7901                         else if (modelParams[i].treeAgePr.prior == logNormal)
7902                             {
7903                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbLognormal_Param_Mean_Sd;
7904                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioLognormal_Param_Mean_Sd;
7905                             modelParams[i].treeAgePr.min           = 0.0;
7906                             modelParams[i].treeAgePr.max           = POS_INFINITY;
7907                             }
7908                         else if (modelParams[i].treeAgePr.prior == offsetLogNormal)
7909                             {
7910                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbOffsetLognormal_Param_Offset_Mean_Sd;
7911                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioOffsetLognormal_Param_Offset_Mean_Sd;
7912                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
7913                             modelParams[i].treeAgePr.max           = POS_INFINITY;
7914                             }
7915                         else if (modelParams[i].treeAgePr.prior == standardGamma)
7916                             {
7917                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbGamma_Param_Mean_Sd;
7918                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioGamma_Param_Mean_Sd;
7919                             modelParams[i].treeAgePr.min           = 0.0;
7920                             modelParams[i].treeAgePr.max           = POS_INFINITY;
7921                             }
7922                         else if (modelParams[i].treeAgePr.prior == offsetGamma)
7923                             {
7924                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbOffsetGamma_Param_Offset_Mean_Sd;
7925                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioOffsetGamma_Param_Offset_Mean_Sd;
7926                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
7927                             modelParams[i].treeAgePr.max           = POS_INFINITY;
7928                             }
7929                         }
7930                     }
7931                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7932                 }
7933             else
7934                 return (ERROR);
7935             }
7936         /* set Clockratepr (clockRatePr) ****************************************************/
7937         else if (!strcmp(parmName, "Clockratepr"))
7938             {
7939             if (expecting == Expecting(EQUALSIGN))
7940                 {
7941                 foundDash = NO;
7942                 expecting = Expecting(ALPHA);
7943                 }
7944             else if (expecting == Expecting(ALPHA))
7945                 {
7946                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7947                     {
7948                     nApplied = NumActiveParts ();
7949                     for (i=0; i<numCurrentDivisions; i++)
7950                         {
7951                         if (activeParts[i] == YES || nApplied == 0)
7952                             strcpy(modelParams[i].clockRatePr, tempStr);
7953                         }
7954                     }
7955                 else
7956                     {
7957                     MrBayesPrint ("%s   Invalid Clockratepr argument\n", spacer);
7958                     return (ERROR);
7959                     }
7960                 expecting  = Expecting(LEFTPAR);
7961                 for (i=0; i<numCurrentDivisions; i++)
7962                     numVars[i] = 0;
7963                 }
7964             else if (expecting == Expecting(LEFTPAR))
7965                 {
7966                 expecting  = Expecting(NUMBER);
7967                 expecting |= Expecting(DASH);   /* negative numbers possible */
7968                 }
7969             else if (expecting == Expecting(DASH))
7970                 {
7971                 foundDash = YES;
7972                 expecting = Expecting(NUMBER);
7973                 }
7974             else if (expecting == Expecting(NUMBER))
7975                 {
7976                 sscanf (tkn, "%lf", &tempD);
7977                 if (foundDash == YES)
7978                     {
7979                     foundDash = NO;
7980                     tempD *= -1.0;
7981                     }
7982                 nApplied = NumActiveParts ();
7983                 for (i=0; i<numCurrentDivisions; i++)
7984                     {
7985                     if (activeParts[i] == YES || nApplied == 0)
7986                         {
7987                         if (!strcmp(modelParams[i].clockRatePr,"Normal"))
7988                             {
7989                             if (tempD <= 0.0)
7990                                 {
7991                                 if (numVars[i] == 0)
7992                                     MrBayesPrint ("%s   Mean of the normal must be positive\n", spacer);
7993                                 else if (numVars[i] == 1)
7994                                     MrBayesPrint ("%s   Standard deviation of the normal must be positive\n", spacer);
7995                                 return (ERROR);
7996                                 }
7997                             modelParams[i].clockRateNormal[numVars[i]] = tempD;
7998                             numVars[i]++;
7999                             if (numVars[i] == 1)
8000                                 expecting  = Expecting(COMMA);
8001                             else
8002                                 {
8003                                 if (nApplied == 0 || numCurrentDivisions == 1)
8004                                     MrBayesPrint ("%s   Setting Clockratepr to Normal(%1.6lf,%1.6lf)\n", spacer, modelParams[i].clockRateNormal[0], modelParams[i].clockRateNormal[1]);
8005                                 else
8006                                     MrBayesPrint ("%s   Setting Clockratepr to Normal(%1.6lf,%1.6lf) for partition %d\n", spacer, modelParams[i].clockRateNormal[0], modelParams[i].clockRateNormal[1], i+1);
8007                                 expecting  = Expecting(RIGHTPAR);
8008                                 }
8009                             }
8010                         else if (!strcmp(modelParams[i].clockRatePr,"Lognormal"))
8011                             {
8012                             modelParams[i].clockRateLognormal[numVars[i]] = tempD;
8013                             numVars[i]++;
8014                             if (numVars[i] == 1)
8015                                 expecting  = Expecting(COMMA);
8016                             else
8017                                 {
8018                                 if (nApplied == 0 || numCurrentDivisions == 1)
8019                                     MrBayesPrint ("%s   Setting Clockratepr to Lognormal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].clockRateLognormal[0], modelParams[i].clockRateLognormal[1]);
8020                                 else
8021                                     MrBayesPrint ("%s   Setting Clockratepr to Lognormal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].clockRateLognormal[0], modelParams[i].clockRateLognormal[1], i+1);
8022                                 expecting  = Expecting(RIGHTPAR);
8023                                 }
8024                             }
8025                         else if (!strcmp(modelParams[i].clockRatePr,"Exponential"))
8026                             {
8027                             if (tempD <= 0.0)
8028                                 {
8029                                 MrBayesPrint ("%s   Rate of the exponential must be positive\n", spacer);
8030                                 return (ERROR);
8031                                 }
8032                             modelParams[i].clockRateExp = tempD;
8033                             numVars[i]++;
8034                             if (nApplied == 0 || numCurrentDivisions == 1)
8035                                 MrBayesPrint ("%s   Setting Clockratepr to Exponential(%1.2lf)\n", spacer, modelParams[i].clockRateExp);
8036                             else
8037                                 MrBayesPrint ("%s   Setting Clockratepr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].clockRateExp, i+1);
8038                             expecting  = Expecting(RIGHTPAR);
8039                             }
8040                         else if (!strcmp(modelParams[i].clockRatePr,"Gamma"))
8041                             {
8042                             if (tempD <= 0.0)
8043                                 {
8044                                 if (numVars[i] == 0)
8045                                     MrBayesPrint ("%s   Shape of the gamma must be positive\n", spacer);
8046                                 else if (numVars[i] == 1)
8047                                     MrBayesPrint ("%s   Rate (inverse scale) of the gamma must be positive\n", spacer);
8048                                 return (ERROR);
8049                                 }
8050                             modelParams[i].clockRateGamma[numVars[i]] = tempD;
8051                             numVars[i]++;
8052                             if (numVars[i] == 1)
8053                                 expecting  = Expecting(COMMA);
8054                             else
8055                                 {
8056                                 if (nApplied == 0 || numCurrentDivisions == 1)
8057                                     MrBayesPrint ("%s   Setting Clockratepr to Gamma(%1.2lf,%1.2lf)\n", spacer, modelParams[i].clockRateGamma[0], modelParams[i].clockRateGamma[1]);
8058                                 else
8059                                     MrBayesPrint ("%s   Setting Clockratepr to Gamma(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].clockRateGamma[0], modelParams[i].clockRateGamma[1], i+1);
8060                                 expecting  = Expecting(RIGHTPAR);
8061                                 }
8062                             }
8063                         else if (!strcmp(modelParams[i].clockRatePr,"Fixed"))
8064                             {
8065                             if (tempD <= 0.0)
8066                                 {
8067                                 MrBayesPrint ("%s   Fixed clock rate must be positive\n", spacer);
8068                                 return (ERROR);
8069                                 }
8070                             modelParams[i].clockRateFix = tempD;
8071                             numVars[i]++;
8072                             if (nApplied == 0 || numCurrentDivisions == 1)
8073                                 MrBayesPrint ("%s   Setting Clockratepr to Fixed(%1.6lf)\n", spacer, modelParams[i].clockRateFix);
8074                             else
8075                                 MrBayesPrint ("%s   Setting Clockratepr to Fixed(%1.6lf) for partition %d\n", spacer, modelParams[i].clockRateFix, i+1);
8076                             for (k=0; k<numGlobalChains; k++)
8077                                 {
8078                                 if (UpdateClockRate(tempD, k) == ERROR) 
8079                                     return (ERROR);
8080                                 }
8081                             expecting  = Expecting(RIGHTPAR);
8082                             }
8083                         }
8084                     }
8085                 }
8086             else if (expecting == Expecting(COMMA))
8087                 {
8088                 expecting  = Expecting(NUMBER);
8089                 }
8090             else if (expecting == Expecting(RIGHTPAR))
8091                 {
8092                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8093                 }
8094             else
8095                 return (ERROR);
8096             }
8097         /* set Popsizepr (popSizePr) **************************************************************/
8098         else if (!strcmp(parmName, "Popsizepr"))
8099             {
8100             if (expecting == Expecting(EQUALSIGN))
8101                 expecting = Expecting(ALPHA);
8102             else if (expecting == Expecting(ALPHA))
8103                 {
8104                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8105                     {
8106                     nApplied = NumActiveParts ();
8107                     for (i=0; i<numCurrentDivisions; i++)
8108                         {
8109                         if (activeParts[i] == YES || nApplied == 0)
8110                             strcpy(modelParams[i].popSizePr, tempStr);
8111                         }
8112                     }
8113                 else
8114                     {
8115                     MrBayesPrint ("%s   Invalid Popsizepr argument\n", spacer);
8116                     return (ERROR);
8117                     }
8118                 expecting  = Expecting(LEFTPAR);
8119                 for (i=0; i<numCurrentDivisions; i++)
8120                     numVars[i] = 0;
8121                 }
8122             else if (expecting == Expecting(LEFTPAR))
8123                 {
8124                 expecting  = Expecting(NUMBER);
8125                 }
8126             else if (expecting == Expecting(NUMBER))
8127                 {
8128                 nApplied = NumActiveParts ();
8129                 for (i=0; i<numCurrentDivisions; i++)
8130                     {
8131                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
8132                         {
8133                         if (!strcmp(modelParams[i].popSizePr,"Uniform"))
8134                             {
8135                             sscanf (tkn, "%lf", &tempD);
8136                             modelParams[i].popSizeUni[numVars[i]++] = tempD;
8137                             if (numVars[i] == 1)
8138                                 {
8139                                 if (tempD <= 0.0)
8140                                     {
8141                                     MrBayesPrint ("%s   Lower value for Uniform must be a positive number\n", spacer);
8142                                     return (ERROR);
8143                                     }
8144                                 expecting  = Expecting(COMMA);
8145                                 }
8146                             else
8147                                 {
8148                                 if (modelParams[i].popSizeUni[0] >= modelParams[i].popSizeUni[1])
8149                                     {
8150                                     MrBayesPrint ("%s   Lower value for Uniform should be greater than upper value\n", spacer);
8151                                     return (ERROR);
8152                                     }
8153                                 if (nApplied == 0 && numCurrentDivisions == 1)
8154                                     MrBayesPrint ("%s   Setting Popsizepr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeUni[0], modelParams[i].popSizeUni[1]);
8155                                 else
8156                                     MrBayesPrint ("%s   Setting Popsizepr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeUni[0], modelParams[i].popSizeUni[1], i+1);
8157                                 expecting  = Expecting(RIGHTPAR);
8158                                 }
8159                             }
8160                         else if (!strcmp(modelParams[i].popSizePr,"Lognormal"))
8161                             {
8162                             sscanf (tkn, "%lf", &tempD);
8163                             modelParams[i].popSizeLognormal[numVars[i]++] = tempD;
8164                             if (numVars[i] == 1)
8165                                 {
8166                                 expecting  = Expecting(COMMA);
8167                                 }
8168                             else
8169                                 {
8170                                 if (modelParams[i].popSizeLognormal[1] <= 0.0)
8171                                     {
8172                                     MrBayesPrint ("%s   Standard deviation of Lognormal must be a positive number\n", spacer);
8173                                     return (ERROR);
8174                                     }
8175                                 if (nApplied == 0 && numCurrentDivisions == 1)
8176                                     MrBayesPrint ("%s   Setting Popsizepr to Lognormal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeLognormal[0], modelParams[i].popSizeLognormal[1]);
8177                                 else
8178                                     MrBayesPrint ("%s   Setting Popsizepr to Lognormal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeLognormal[0], modelParams[i].popSizeLognormal[1], i+1);
8179                                 expecting  = Expecting(RIGHTPAR);
8180                                 }
8181                             }
8182                         else if (!strcmp(modelParams[i].popSizePr,"Normal"))
8183                             {
8184                             sscanf (tkn, "%lf", &tempD);
8185                             modelParams[i].popSizeNormal[numVars[i]++] = tempD;
8186                             if (numVars[i] == 1)
8187                                 {
8188                                 if (modelParams[i].popSizeNormal[0] <= 0.0)
8189                                     {
8190                                     MrBayesPrint ("%s   Mean of Truncated Normal must be a positive number\n", spacer);
8191                                     return (ERROR);
8192                                     }
8193                                 expecting  = Expecting(COMMA);
8194                                 }
8195                             else
8196                                 {
8197                                 if (modelParams[i].popSizeNormal[1] <= 0.0)
8198                                     {
8199                                     MrBayesPrint ("%s   Standard deviation of Truncated Normal must be a positive number\n", spacer);
8200                                     return (ERROR);
8201                                     }
8202                                 if (nApplied == 0 && numCurrentDivisions == 1)
8203                                     MrBayesPrint ("%s   Setting Popsizepr to Truncated Normal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeNormal[0], modelParams[i].popSizeNormal[1]);
8204                                 else
8205                                     MrBayesPrint ("%s   Setting Popsizepr to Truncated Normal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeNormal[0], modelParams[i].popSizeNormal[1], i+1);
8206                                 expecting  = Expecting(RIGHTPAR);
8207                                 }
8208                             }
8209                         else if (!strcmp(modelParams[i].popSizePr,"Gamma"))
8210                             {
8211                             sscanf (tkn, "%lf", &tempD);
8212                             modelParams[i].popSizeGamma[numVars[i]++] = tempD;
8213                             if (numVars[i] == 1)
8214                                 {
8215                                 if (modelParams[i].popSizeGamma[0] <= 0.0)
8216                                     {
8217                                     MrBayesPrint ("%s   Shape (alpha) of Gamma must be a positive number\n", spacer);
8218                                     return (ERROR);
8219                                     }
8220                                 expecting  = Expecting(COMMA);
8221                                 }
8222                             else
8223                                 {
8224                                 if (modelParams[i].popSizeGamma[1] <= 0.0)
8225                                     {
8226                                     MrBayesPrint ("%s   Rate (beta) of Gamma must be a positive number\n", spacer);
8227                                     return (ERROR);
8228                                     }
8229                                 if (nApplied == 0 && numCurrentDivisions == 1)
8230                                     MrBayesPrint ("%s   Setting Popsizepr to Gamma(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeGamma[0], modelParams[i].popSizeGamma[1]);
8231                                 else
8232                                     MrBayesPrint ("%s   Setting Popsizepr to Gamma(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeGamma[0], modelParams[i].popSizeGamma[1], i+1);
8233                                 expecting  = Expecting(RIGHTPAR);
8234                                 }
8235                             }
8236                         else if (!strcmp(modelParams[i].popSizePr,"Fixed"))
8237                             {
8238                             sscanf (tkn, "%lf", &tempD);
8239                             if (AreDoublesEqual(tempD, 0.0, ETA)==YES)
8240                                 {
8241                                 MrBayesPrint ("%s   Popsizepr cannot be fixed to 0.0\n", spacer);
8242                                 return (ERROR);
8243                                 }
8244                             modelParams[i].popSizeFix = tempD;
8245                             if (nApplied == 0 && numCurrentDivisions == 1)
8246                                 MrBayesPrint ("%s   Setting Popsizepr to Fixed(%1.5lf)\n", spacer, modelParams[i].popSizeFix);
8247                             else
8248                                 MrBayesPrint ("%s   Setting Popsizepr to Fixed(%1.5lf) for partition %d\n", spacer, modelParams[i].popSizeFix, i+1);
8249                             expecting  = Expecting(RIGHTPAR);
8250                             }
8251                         }
8252                     }
8253                 }
8254             else if (expecting == Expecting(COMMA))
8255                 {
8256                 expecting  = Expecting(NUMBER);
8257                 }
8258             else if (expecting == Expecting(RIGHTPAR))
8259                 {
8260                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8261                 }
8262             else
8263                 return (ERROR);
8264             }
8265         /* set Popvarpr (popVarPr) **************************************************************/
8266         else if (!strcmp(parmName, "Popvarpr"))
8267             {
8268             if (expecting == Expecting(EQUALSIGN))
8269                 expecting = Expecting(ALPHA);
8270             else if (expecting == Expecting(ALPHA))
8271                 {
8272                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8273                     {
8274                     nApplied = NumActiveParts ();
8275                     for (i=0; i<numCurrentDivisions; i++)
8276                         {
8277                         if (activeParts[i] == YES || nApplied == 0)
8278                             {
8279                             strcpy(modelParams[i].popVarPr, tempStr);
8280                         
8281                             if (nApplied == 0 && numCurrentDivisions == 1)
8282                                 MrBayesPrint ("%s   Setting Popvarpr to %s\n", spacer, modelParams[i].popVarPr);
8283                             else
8284                                 MrBayesPrint ("%s   Setting Popvarpr to %s for partition %d\n", spacer, modelParams[i].popVarPr, i+1);
8285                             }
8286                         }
8287                     expecting  = Expecting(PARAMETER) | Expecting(SEMICOLON);
8288                     }
8289                 else
8290                     {
8291                     MrBayesPrint ("%s   Invalid Popvarpr argument\n", spacer);
8292                     return (ERROR);
8293                     }
8294                 }
8295             else
8296                 return (ERROR);
8297             }
8298         /* set Compound Poisson Process rate prior (cppRatePr) *********************************************************/
8299         else if (!strcmp(parmName, "Cppratepr"))
8300             {
8301             if (expecting == Expecting(EQUALSIGN))
8302                 expecting = Expecting(ALPHA);
8303             else if (expecting == Expecting(ALPHA))
8304                 {
8305                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8306                     {
8307                     nApplied = NumActiveParts ();
8308                     for (i=0; i<numCurrentDivisions; i++)
8309                         {
8310                         if (activeParts[i] == YES || nApplied == 0)
8311                             strcpy(modelParams[i].cppRatePr, tempStr);
8312                         }
8313                     }
8314                 else
8315                     {
8316                     MrBayesPrint ("%s   Invalid Cppratepr argument\n", spacer);
8317                     return (ERROR);
8318                     }
8319                 expecting  = Expecting(LEFTPAR);
8320                 for (i=0; i<numCurrentDivisions; i++)
8321                     numVars[i] = 0;
8322                 }
8323             else if (expecting == Expecting(LEFTPAR))
8324                 {
8325                 expecting  = Expecting(NUMBER);
8326                 }
8327             else if (expecting == Expecting(NUMBER))
8328                 {
8329                 nApplied = NumActiveParts ();
8330                 for (i=0; i<numCurrentDivisions; i++)
8331                     {
8332                     if (activeParts[i] == YES || nApplied == 0)
8333                         {
8334                         if (!strcmp(modelParams[i].cppRatePr,"Exponential"))
8335                             {
8336                             sscanf (tkn, "%lf", &tempD);
8337                             modelParams[i].cppRateExp = tempD;
8338                             if (nApplied == 0 && numCurrentDivisions == 1)
8339                                 MrBayesPrint ("%s   Setting Cppratepr to Exponential(%1.2lf)\n", spacer, modelParams[i].cppRateExp);
8340                             else
8341                                 MrBayesPrint ("%s   Setting Cppratepr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].cppRateExp, i+1);
8342                             expecting  = Expecting(RIGHTPAR);
8343                             }
8344                         else if (!strcmp(modelParams[i].cppRatePr,"Fixed"))
8345                             {
8346                             sscanf (tkn, "%lf", &tempD);
8347                             if (tempD < CPPLAMBDA_MIN || tempD > CPPLAMBDA_MAX)
8348                                 {
8349                                 MrBayesPrint ("%s   CPP rate must be in the range %f - %f\n", spacer, CPPLAMBDA_MIN, CPPLAMBDA_MAX);
8350                                 return (ERROR);
8351                                 }
8352                             modelParams[i].cppRateFix = tempD;
8353                             if (nApplied == 0 && numCurrentDivisions == 1)
8354                                 MrBayesPrint ("%s   Setting Cppratepr to Fixed(%1.2lf)\n", spacer, modelParams[i].cppRateFix);
8355                             else
8356                                 MrBayesPrint ("%s   Setting Cppratepr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].cppRateFix, i+1);
8357                             expecting  = Expecting(RIGHTPAR);
8358                             }
8359                         }
8360                     }
8361                 }
8362             else if (expecting == Expecting(COMMA))
8363                 {
8364                 expecting  = Expecting(NUMBER);
8365                 }
8366             else if (expecting == Expecting(RIGHTPAR))
8367                 {
8368                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8369                 }
8370             else
8371                 return (ERROR);
8372             }
8373         /* set Compound Poisson Process rate multiplier standard deviation (log scale) ***********************/
8374         else if (!strcmp(parmName, "Cppmultdevpr"))
8375             {
8376             if (expecting == Expecting(EQUALSIGN))
8377                 expecting = Expecting(ALPHA);
8378             else if (expecting == Expecting(ALPHA))
8379                 {
8380                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8381                     {
8382                     nApplied = NumActiveParts ();
8383                     for (i=0; i<numCurrentDivisions; i++)
8384                         {
8385                         if (activeParts[i] == YES || nApplied == 0)
8386                             strcpy(modelParams[i].cppMultDevPr, tempStr);
8387                         }
8388                     }
8389                 else
8390                     {
8391                     MrBayesPrint ("%s   Invalid Cppmultdevpr argument\n", spacer);
8392                     return (ERROR);
8393                     }
8394                 expecting  = Expecting(LEFTPAR);
8395                 for (i=0; i<numCurrentDivisions; i++)
8396                     numVars[i] = 0;
8397                 }
8398             else if (expecting == Expecting(LEFTPAR))
8399                 {
8400                 expecting  = Expecting(NUMBER);
8401                 }
8402             else if (expecting == Expecting(NUMBER))
8403                 {
8404                 nApplied = NumActiveParts ();
8405                 for (i=0; i<numCurrentDivisions; i++)
8406                     {
8407                     if (activeParts[i] == YES || nApplied == 0)
8408                         {
8409                         if (!strcmp(modelParams[i].cppMultDevPr,"Fixed"))
8410                             {
8411                             sscanf (tkn, "%lf", &tempD);
8412                             if (tempD < POSREAL_MIN || tempD > POSREAL_MAX)
8413                                 {
8414                                 MrBayesPrint ("%s   The log standard deviation of rate multipliers must be in the range %f - %f\n", spacer, POSREAL_MIN, POSREAL_MAX);
8415                                 return (ERROR);
8416                                 }
8417                             modelParams[i].cppMultDevFix = tempD;
8418                             if (nApplied == 0 && numCurrentDivisions == 1)
8419                                 MrBayesPrint ("%s   Setting Cppmultdevpr to Fixed(%1.2lf)\n", spacer, modelParams[i].cppMultDevFix);
8420                             else
8421                                 MrBayesPrint ("%s   Setting Cppmultdevpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].cppMultDevFix, i+1);
8422                             expecting  = Expecting(RIGHTPAR);
8423                             }
8424                         }
8425                     }
8426                 }
8427             else if (expecting == Expecting(COMMA))
8428                 {
8429                 expecting  = Expecting(NUMBER);
8430                 }
8431             else if (expecting == Expecting(RIGHTPAR))
8432                 {
8433                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8434                 }
8435             else
8436                 return (ERROR);
8437             }
8438         /* set prior for variance of lognormal of autocorrelated rates (tk02varPr) ***********************/
8439         else if (!strcmp(parmName, "TK02varpr") || !strcmp(parmName,"Bmvarpr"))
8440             {
8441             if (expecting == Expecting(EQUALSIGN))
8442                 expecting = Expecting(ALPHA);
8443             else if (expecting == Expecting(ALPHA))
8444                 {
8445                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8446                     {
8447                     nApplied = NumActiveParts ();
8448                     for (i=0; i<numCurrentDivisions; i++)
8449                         {
8450                         if (activeParts[i] == YES || nApplied == 0)
8451                             strcpy(modelParams[i].tk02varPr, tempStr);
8452                         }
8453                     }
8454                 else
8455                     {
8456                     MrBayesPrint ("%s   Invalid TK02varpr argument\n", spacer);
8457                     return (ERROR);
8458                     }
8459                 expecting  = Expecting(LEFTPAR);
8460                 for (i=0; i<numCurrentDivisions; i++)
8461                     numVars[i] = 0;
8462                 }
8463             else if (expecting == Expecting(LEFTPAR))
8464                 {
8465                 expecting  = Expecting(NUMBER);
8466                 }
8467             else if (expecting == Expecting(NUMBER))
8468                 {
8469                 nApplied = NumActiveParts ();
8470                 for (i=0; i<numCurrentDivisions; i++)
8471                     {
8472                     if (activeParts[i] == YES || nApplied == 0)
8473                         {
8474                         if (!strcmp(modelParams[i].tk02varPr,"Uniform"))
8475                             {
8476                             sscanf (tkn, "%lf", &tempD);
8477                             modelParams[i].tk02varUni[numVars[i]++] = tempD;
8478                             if (numVars[i] == 1)
8479                                 expecting  = Expecting(COMMA);
8480                             else
8481                                 {
8482                                 if (modelParams[i].tk02varUni[0] >= modelParams[i].tk02varUni[1])
8483                                     {
8484                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8485                                     return (ERROR);
8486                                     }
8487                                 if (nApplied == 0 && numCurrentDivisions == 1)
8488                                     MrBayesPrint ("%s   Setting TK02varpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].tk02varUni[0], modelParams[i].tk02varUni[1]);
8489                                 else
8490                                     MrBayesPrint ("%s   Setting TK02varpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].tk02varUni[0], modelParams[i].tk02varUni[1], i+1);
8491                                 expecting  = Expecting(RIGHTPAR);
8492                                 }
8493                             }
8494                         else if (!strcmp(modelParams[i].tk02varPr,"Exponential"))
8495                             {
8496                             sscanf (tkn, "%lf", &tempD);
8497                             modelParams[i].tk02varExp = tempD;
8498                             if (nApplied == 0 && numCurrentDivisions == 1)
8499                                 MrBayesPrint ("%s   Setting TK02varpr to Exponential(%1.2lf)\n", spacer, modelParams[i].tk02varExp);
8500                             else
8501                                 MrBayesPrint ("%s   Setting TK02varpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].tk02varExp, i+1);
8502                             expecting  = Expecting(RIGHTPAR);
8503                             }
8504                         else if (!strcmp(modelParams[i].tk02varPr,"Fixed"))
8505                             {
8506                             sscanf (tkn, "%lf", &tempD);
8507                             if (tempD < TK02VAR_MIN || tempD > TK02VAR_MAX)
8508                                 {
8509                                 MrBayesPrint ("%s   Ratevar (nu) must be in the range %f - %f\n", spacer, TK02VAR_MIN, TK02VAR_MAX);
8510                                 return (ERROR);
8511                                 }
8512                             modelParams[i].tk02varFix = tempD;
8513                             if (nApplied == 0 && numCurrentDivisions == 1)
8514                                 MrBayesPrint ("%s   Setting TK02varpr to Fixed(%1.2lf)\n", spacer, modelParams[i].tk02varFix);
8515                             else
8516                                 MrBayesPrint ("%s   Setting TK02varpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].tk02varFix, i+1);
8517                             expecting  = Expecting(RIGHTPAR);
8518                             }
8519                         }
8520                     }
8521                 }
8522             else if (expecting == Expecting(COMMA))
8523                 {
8524                 expecting  = Expecting(NUMBER);
8525                 }
8526             else if (expecting == Expecting(RIGHTPAR))
8527                 {
8528                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8529                 }
8530             else
8531                 return (ERROR);
8532             }
8533         /* set prior for shape of independent branch rate gamma distribution (igrvarPr) ***********************/
8534         else if (!strcmp(parmName, "Igrvarpr") || !strcmp(parmName, "Ibrvarpr"))
8535             {
8536             if (expecting == Expecting(EQUALSIGN))
8537                 expecting = Expecting(ALPHA);
8538             else if (expecting == Expecting(ALPHA))
8539                 {
8540                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8541                     {
8542                     nApplied = NumActiveParts ();
8543                     for (i=0; i<numCurrentDivisions; i++)
8544                         {
8545                         if (activeParts[i] == YES || nApplied == 0)
8546                             strcpy(modelParams[i].igrvarPr, tempStr);
8547                         }
8548                     }
8549                 else
8550                     {
8551                     MrBayesPrint ("%s   Invalid Igrvarpr argument\n", spacer);
8552                     return (ERROR);
8553                     }
8554                 expecting  = Expecting(LEFTPAR);
8555                 for (i=0; i<numCurrentDivisions; i++)
8556                     numVars[i] = 0;
8557                 }
8558             else if (expecting == Expecting(LEFTPAR))
8559                 {
8560                 expecting  = Expecting(NUMBER);
8561                 }
8562             else if (expecting == Expecting(NUMBER))
8563                 {
8564                 nApplied = NumActiveParts ();
8565                 for (i=0; i<numCurrentDivisions; i++)
8566                     {
8567                     if (activeParts[i] == YES || nApplied == 0)
8568                         {
8569                         if (!strcmp(modelParams[i].igrvarPr,"Uniform"))
8570                             {
8571                             sscanf (tkn, "%lf", &tempD);
8572                             modelParams[i].igrvarUni[numVars[i]++] = tempD;
8573                             if (numVars[i] == 1)
8574                                 expecting  = Expecting(COMMA);
8575                             else
8576                                 {
8577                                 if (modelParams[i].igrvarUni[0] >= modelParams[i].igrvarUni[1])
8578                                     {
8579                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8580                                     return (ERROR);
8581                                     }
8582                                 if (nApplied == 0 && numCurrentDivisions == 1)
8583                                     MrBayesPrint ("%s   Setting Igrvarpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].igrvarUni[0], modelParams[i].igrvarUni[1]);
8584                                 else
8585                                     MrBayesPrint ("%s   Setting Igrvarpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].igrvarUni[0], modelParams[i].igrvarUni[1], i+1);
8586                                 expecting  = Expecting(RIGHTPAR);
8587                                 }
8588                             }
8589                         else if (!strcmp(modelParams[i].igrvarPr,"Exponential"))
8590                             {
8591                             sscanf (tkn, "%lf", &tempD);
8592                             modelParams[i].igrvarExp = tempD;
8593                             if (nApplied == 0 && numCurrentDivisions == 1)
8594                                 MrBayesPrint ("%s   Setting Igrvarpr to Exponential(%1.2lf)\n", spacer, modelParams[i].igrvarExp);
8595                             else
8596                                 MrBayesPrint ("%s   Setting Igrvarpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].igrvarExp, i+1);
8597                             expecting  = Expecting(RIGHTPAR);
8598                             }
8599                         else if (!strcmp(modelParams[i].igrvarPr,"Fixed"))
8600                             {
8601                             sscanf (tkn, "%lf", &tempD);
8602                             if (tempD < IGRVAR_MIN || tempD > IGRVAR_MAX)
8603                                 {
8604                                 MrBayesPrint ("%s   Igrvar must be in the range %f - %f\n", spacer, IGRVAR_MIN, IGRVAR_MAX);
8605                                 return (ERROR);
8606                                 }
8607                             modelParams[i].igrvarFix = tempD;
8608                             if (nApplied == 0 && numCurrentDivisions == 1)
8609                                 MrBayesPrint ("%s   Setting Igrvarpr to Fixed(%1.2lf)\n", spacer, modelParams[i].igrvarFix);
8610                             else
8611                                 MrBayesPrint ("%s   Setting Igrvarpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].igrvarFix, i+1);
8612                             expecting  = Expecting(RIGHTPAR);
8613                             }
8614                         }
8615                     }
8616                 }
8617             else if (expecting == Expecting(COMMA))
8618                 {
8619                 expecting  = Expecting(NUMBER);
8620                 }
8621             else if (expecting == Expecting(RIGHTPAR))
8622                 {
8623                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8624                 }
8625             else
8626                 return (ERROR);
8627             }
8628         /* set prior for variance of mixed relaxed clock model (mixedvarPr) ***********************/
8629         else if (!strcmp(parmName, "Mixedvarpr"))
8630             {
8631             if (expecting == Expecting(EQUALSIGN))
8632                 expecting = Expecting(ALPHA);
8633             else if (expecting == Expecting(ALPHA))
8634                 {
8635                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8636                     {
8637                     nApplied = NumActiveParts ();
8638                     for (i=0; i<numCurrentDivisions; i++)
8639                         {
8640                         if (activeParts[i] == YES || nApplied == 0)
8641                             strcpy(modelParams[i].mixedvarPr, tempStr);
8642                         }
8643                     }
8644                 else
8645                     {
8646                     MrBayesPrint ("%s   Invalid Mixedvarpr argument\n", spacer);
8647                     return (ERROR);
8648                     }
8649                 expecting  = Expecting(LEFTPAR);
8650                 for (i=0; i<numCurrentDivisions; i++)
8651                     numVars[i] = 0;
8652                 }
8653             else if (expecting == Expecting(LEFTPAR))
8654                 {
8655                 expecting  = Expecting(NUMBER);
8656                 }
8657             else if (expecting == Expecting(NUMBER))
8658                 {
8659                 nApplied = NumActiveParts ();
8660                 for (i=0; i<numCurrentDivisions; i++)
8661                     {
8662                     if (activeParts[i] == YES || nApplied == 0)
8663                         {
8664                         if (!strcmp(modelParams[i].mixedvarPr,"Uniform"))
8665                             {
8666                             sscanf (tkn, "%lf", &tempD);
8667                             modelParams[i].mixedvarUni[numVars[i]++] = tempD;
8668                             if (numVars[i] == 1)
8669                                 expecting  = Expecting(COMMA);
8670                             else
8671                                 {
8672                                 if (modelParams[i].mixedvarUni[0] >= modelParams[i].mixedvarUni[1])
8673                                     {
8674                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8675                                     return (ERROR);
8676                                     }
8677                                 if (nApplied == 0 && numCurrentDivisions == 1)
8678                                     MrBayesPrint ("%s   Setting Mixedvarpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].mixedvarUni[0], modelParams[i].mixedvarUni[1]);
8679                                 else
8680                                     MrBayesPrint ("%s   Setting Mixedvarpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].mixedvarUni[0], modelParams[i].mixedvarUni[1], i+1);
8681                                 expecting  = Expecting(RIGHTPAR);
8682                                 }
8683                             }
8684                         else if (!strcmp(modelParams[i].mixedvarPr,"Exponential"))
8685                             {
8686                             sscanf (tkn, "%lf", &tempD);
8687                             modelParams[i].mixedvarExp = tempD;
8688                             if (nApplied == 0 && numCurrentDivisions == 1)
8689                                 MrBayesPrint ("%s   Setting Mixedvarpr to Exponential(%1.2lf)\n", spacer, modelParams[i].mixedvarExp);
8690                             else
8691                                 MrBayesPrint ("%s   Setting Mixedvarpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].mixedvarExp, i+1);
8692                             expecting  = Expecting(RIGHTPAR);
8693                             }
8694                         else if (!strcmp(modelParams[i].mixedvarPr,"Fixed"))
8695                             {
8696                             sscanf (tkn, "%lf", &tempD);
8697                             if (tempD < IGRVAR_MIN || tempD > IGRVAR_MAX || tempD < TK02VAR_MIN || tempD > TK02VAR_MAX)
8698                                 {
8699                                 MrBayesPrint ("%s   Mixedvar must be in the range %f - %f\n", spacer, IGRVAR_MIN, IGRVAR_MAX);
8700                                 return (ERROR);
8701                                 }
8702                             modelParams[i].mixedvarFix = tempD;
8703                             if (nApplied == 0 && numCurrentDivisions == 1)
8704                                 MrBayesPrint ("%s   Setting Mixedvarpr to Fixed(%1.2lf)\n", spacer, modelParams[i].mixedvarFix);
8705                             else
8706                                 MrBayesPrint ("%s   Setting Mixedvarpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].mixedvarFix, i+1);
8707                             expecting  = Expecting(RIGHTPAR);
8708                             }
8709                         }
8710                     }
8711                 }
8712             else if (expecting == Expecting(COMMA))
8713                 {
8714                 expecting  = Expecting(NUMBER);
8715                 }
8716             else if (expecting == Expecting(RIGHTPAR))
8717                 {
8718                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8719                 }
8720             else
8721                 return (ERROR);
8722             }
8723         /* set Growthpr (growthPr) **************************************************************/
8724         else if (!strcmp(parmName, "Growthpr"))
8725             {
8726             if (expecting == Expecting(EQUALSIGN))
8727                 {
8728                 expecting = Expecting(ALPHA);
8729                 isNegative = NO;
8730                 }
8731             else if (expecting == Expecting(ALPHA))
8732                 {
8733                 isNegative = NO;
8734                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8735                     {
8736                     nApplied = NumActiveParts ();
8737                     for (i=0; i<numCurrentDivisions; i++)
8738                         {
8739                         if (activeParts[i] == YES || nApplied == 0)
8740                             strcpy(modelParams[i].growthPr, tempStr);
8741                         }
8742                     }
8743                 else
8744                     {
8745                     MrBayesPrint ("%s   Invalid Growthpr argument\n", spacer);
8746                     return (ERROR);
8747                     }
8748                 expecting  = Expecting(LEFTPAR);
8749                 for (i=0; i<numCurrentDivisions; i++)
8750                     numVars[i] = 0;
8751                 }
8752             else if (expecting == Expecting(LEFTPAR))
8753                 {
8754                 expecting  = Expecting(NUMBER) | Expecting(DASH);
8755                 }
8756             else if (expecting == Expecting(DASH))
8757                 {
8758                 expecting  = Expecting(NUMBER);
8759                 isNegative = YES;
8760                 }
8761             else if (expecting == Expecting(NUMBER))
8762                 {
8763                 nApplied = NumActiveParts ();
8764                 for (i=0; i<numCurrentDivisions; i++)
8765                     {
8766                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
8767                         {
8768                         if (!strcmp(modelParams[i].growthPr,"Uniform"))
8769                             {
8770                             sscanf (tkn, "%lf", &tempD);
8771                             if (isNegative == YES)
8772                                 tempD *= -1.0;
8773                             modelParams[i].growthUni[numVars[i]++] = tempD;
8774                             if (numVars[i] == 1)
8775                                 expecting  = Expecting(COMMA);
8776                             else
8777                                 {
8778                                 if (modelParams[i].growthUni[0] >= modelParams[i].growthUni[1])
8779                                     {
8780                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8781                                     return (ERROR);
8782                                     }
8783                                 if (nApplied == 0 && numCurrentDivisions == 1)
8784                                     MrBayesPrint ("%s   Setting Growthpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].growthUni[0], modelParams[i].growthUni[1]);
8785                                 else
8786                                     MrBayesPrint ("%s   Setting Growthpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].growthUni[0], modelParams[i].growthUni[1], i+1);
8787                                 expecting  = Expecting(RIGHTPAR);
8788                                 }
8789                             }
8790                         else if (!strcmp(modelParams[i].growthPr,"Normal"))
8791                             {
8792                             sscanf (tkn, "%lf", &tempD);
8793                             if (isNegative == YES)
8794                                 tempD *= -1.0;
8795                             modelParams[i].growthNorm[numVars[i]++] = tempD;
8796                             if (numVars[i] == 1)
8797                                 expecting  = Expecting(COMMA);
8798                             else
8799                                 {
8800                                 if (modelParams[i].growthNorm[1] < 0.0)
8801                                     {
8802                                     MrBayesPrint ("%s   Variance for normal distribution should be greater than zero\n", spacer);
8803                                     return (ERROR);
8804                                     }
8805                                 if (nApplied == 0 && numCurrentDivisions == 1)
8806                                     MrBayesPrint ("%s   Setting Growthpr to Normal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].growthNorm[0], modelParams[i].growthNorm[1]);
8807                                 else
8808                                     MrBayesPrint ("%s   Setting Growthpr to Normal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].growthNorm[0], modelParams[i].growthNorm[1], i+1);
8809                                 expecting  = Expecting(RIGHTPAR);
8810                                 }
8811                             }
8812                         else if (!strcmp(modelParams[i].growthPr,"Exponential"))
8813                             {
8814                             sscanf (tkn, "%lf", &tempD);
8815                             modelParams[i].growthExp = tempD;
8816                             if (nApplied == 0 && numCurrentDivisions == 1)
8817                                 MrBayesPrint ("%s   Setting Growthpr to Exponential(%1.2lf)\n", spacer, modelParams[i].growthExp);
8818                             else
8819                                 MrBayesPrint ("%s   Setting Growthpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].growthExp, i+1);
8820                             expecting  = Expecting(RIGHTPAR);
8821                             }
8822                         else if (!strcmp(modelParams[i].growthPr,"Fixed"))
8823                             {
8824                             sscanf (tkn, "%lf", &tempD);
8825                             if (isNegative == YES)
8826                                 tempD *= -1.0;
8827                             modelParams[i].growthFix = tempD;
8828                             if (nApplied == 0 && numCurrentDivisions == 1)
8829                                 MrBayesPrint ("%s   Setting Growthpr to Fixed(%1.2lf)\n", spacer, modelParams[i].growthFix);
8830                             else
8831                                 MrBayesPrint ("%s   Setting Growthpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].growthFix, i+1);
8832                             expecting  = Expecting(RIGHTPAR);
8833                             }
8834                         }
8835                     }
8836                 isNegative = NO;
8837                 }
8838             else if (expecting == Expecting(COMMA))
8839                 {
8840                 expecting  = Expecting(NUMBER);
8841                 }
8842             else if (expecting == Expecting(RIGHTPAR))
8843                 {
8844                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8845                 }
8846             else
8847                 return (ERROR);
8848             }
8849         /* set Aamodelpr (aaModelPr) **************************************************************/
8850         else if (!strcmp(parmName, "Aamodelpr"))
8851             {
8852             if (expecting == Expecting(EQUALSIGN))
8853                 {
8854                 expecting = Expecting(ALPHA);
8855                 foundAaSetting = foundExp = modelIsFixed = foundDash = NO;
8856                 fromI = 0;
8857                 for (i=0; i<10; i++)
8858                     tempAaModelPrs[i] = 0.0;
8859                 }
8860             else if (expecting == Expecting(ALPHA))
8861                 {
8862                 if (foundAaSetting == NO)
8863                     {
8864                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
8865                         {
8866                         nApplied = NumActiveParts ();
8867                         for (i=0; i<numCurrentDivisions; i++)
8868                             {
8869                             if ((activeParts[i] == YES || nApplied == 0))
8870                                 {
8871                                 strcpy(modelParams[i].aaModelPr, tempStr);
8872                                 if (!strcmp(modelParams[i].aaModelPr, "Mixed"))
8873                                     {
8874                                     if (nApplied == 0 && numCurrentDivisions == 1)
8875                                         MrBayesPrint ("%s   Setting Aamodelpr to %s\n", spacer, modelParams[i].aaModelPr);
8876                                     else
8877                                         MrBayesPrint ("%s   Setting Aamodelpr to %s for partition %d\n", spacer, modelParams[i].aaModelPr, i+1);
8878                                     }
8879                                 }
8880                             }
8881                         }
8882                     else
8883                         {
8884                         MrBayesPrint ("%s   Invalid Aamodelpr argument\n", spacer);
8885                         return (ERROR);
8886                         }
8887                     foundAaSetting = YES;
8888                     if (!strcmp(tempStr, "Fixed"))
8889                         {
8890                         modelIsFixed = YES;
8891                         expecting = Expecting(LEFTPAR);
8892                         }
8893                     else
8894                         {
8895                         expecting = Expecting(LEFTPAR) | Expecting(PARAMETER) | Expecting(SEMICOLON);
8896                         }
8897                     }
8898                 else
8899                     {
8900                     if (modelIsFixed == YES)
8901                         {
8902                         if (IsSame ("Poisson", tkn) == SAME      || IsSame ("Poisson", tkn) == CONSISTENT_WITH)
8903                             strcpy (tempStr, "Poisson");
8904                         else if (IsSame ("Equalin", tkn) == SAME || IsSame ("Equalin", tkn) == CONSISTENT_WITH)
8905                             strcpy (tempStr, "Equalin");
8906                         else if (IsSame ("Jones", tkn) == SAME   || IsSame ("Jones", tkn) == CONSISTENT_WITH)
8907                             strcpy (tempStr, "Jones");
8908                         else if (IsSame ("Dayhoff", tkn) == SAME || IsSame ("Dayhoff", tkn) == CONSISTENT_WITH)
8909                             strcpy (tempStr, "Dayhoff");
8910                         else if (IsSame ("Mtrev", tkn) == SAME   || IsSame ("Mtrev", tkn) == CONSISTENT_WITH)
8911                             strcpy (tempStr, "Mtrev");
8912                         else if (IsSame ("Mtmam", tkn) == SAME   || IsSame ("Mtmam", tkn) == CONSISTENT_WITH)
8913                             strcpy (tempStr, "Mtmam");
8914                         else if (IsSame ("Wag", tkn) == SAME     || IsSame ("Wag", tkn) == CONSISTENT_WITH)
8915                             strcpy (tempStr, "Wag");
8916                         else if (IsSame ("Rtrev", tkn) == SAME   || IsSame ("Rtrev", tkn) == CONSISTENT_WITH)
8917                             strcpy (tempStr, "Rtrev");
8918                         else if (IsSame ("Cprev", tkn) == SAME   || IsSame ("Cprev", tkn) == CONSISTENT_WITH)
8919                             strcpy (tempStr, "Cprev");
8920                         else if (IsSame ("Vt", tkn) == SAME      || IsSame ("Vt", tkn) == CONSISTENT_WITH)
8921                             strcpy (tempStr, "Vt");
8922                         else if (IsSame ("Blosum", tkn) == SAME  || IsSame ("Blosum", tkn) == CONSISTENT_WITH)
8923                             strcpy (tempStr, "Blosum");
8924                         else if (IsSame ("Blossum", tkn) == SAME || IsSame ("Blossum", tkn) == CONSISTENT_WITH)
8925                             strcpy (tempStr, "Blosum");
8926                         else if (IsSame ("LG", tkn) == SAME      || IsSame ("LG", tkn) == CONSISTENT_WITH)
8927                             strcpy (tempStr, "LG");
8928                         else if (IsSame ("Gtr", tkn) == SAME     || IsSame ("Gtr", tkn) == CONSISTENT_WITH)
8929                             strcpy (tempStr, "Gtr");
8930                         else
8931                             {
8932                             MrBayesPrint ("%s   Invalid amino acid model\n", spacer);
8933                             return (ERROR);
8934                             }
8935                         nApplied = NumActiveParts ();
8936                         for (i=0; i<numCurrentDivisions; i++)
8937                             {
8938                             if ((activeParts[i] == YES || nApplied == 0))
8939                                 {
8940                                 if (!strcmp(modelParams[i].aaModelPr, "Fixed"))
8941                                     {
8942                                     strcpy(modelParams[i].aaModel, tempStr);
8943                                     if (nApplied == 0 && numCurrentDivisions == 1)
8944                                         MrBayesPrint ("%s   Setting Aamodelpr to Fixed(%s)\n", spacer, modelParams[i].aaModel);
8945                                     else
8946                                         MrBayesPrint ("%s   Setting Aamodelpr to Fixed(%s) for partition %d\n", spacer, modelParams[i].aaModel, i+1);
8947                                     }
8948                                 else
8949                                     {
8950                                     MrBayesPrint ("%s   You cannot assign an amino acid matrix for mixed models\n", spacer);
8951                                     return (ERROR);
8952                                     }
8953                                 }
8954                             }
8955                         expecting = Expecting(RIGHTPAR);
8956                         }
8957                     else
8958                         {
8959                         if (IsSame ("Exponential", tkn) == SAME || IsSame ("Exponential", tkn) == CONSISTENT_WITH)
8960                             {
8961                             foundExp = YES;
8962                             expecting = Expecting(LEFTPAR);
8963                             }
8964                         else    
8965                             {
8966                             MrBayesPrint ("%s   Invalid argument \"%s\"\n", spacer, tkn);
8967                             return (ERROR);
8968                             }
8969                         }
8970
8971                     }
8972                 }
8973             else if (expecting == Expecting(NUMBER))
8974                 {
8975                 sscanf (tkn, "%lf", &tempD);
8976                 if (fromI >= 10)
8977                     {
8978                     MrBayesPrint ("%s   Too many arguments in Aamodelpr\n", spacer);
8979                     return (ERROR);
8980                     }
8981                 if (modelIsFixed == NO)
8982                     {
8983                     if (foundExp == YES)
8984                         {
8985                         if (foundDash == YES)
8986                             tempAaModelPrs[fromI++] = -tempD;
8987                         else
8988                             tempAaModelPrs[fromI++] = tempD;
8989                         expecting  = Expecting(RIGHTPAR);
8990                         }
8991                     else
8992                         {
8993                         if (foundDash == YES)
8994                             {
8995                             MrBayesPrint ("%s   Unexpected \"-\" in Aamodelpr\n", spacer);
8996                             return (ERROR);
8997                             }
8998                         else
8999                             {
9000                             if (tempD <= 0.000000000001)
9001                                 tempAaModelPrs[fromI++] = -1000000000;
9002                             else
9003                                 tempAaModelPrs[fromI++] = (MrBFlt) log(tempD);
9004                             }
9005                         expecting  = Expecting(COMMA) | Expecting(RIGHTPAR);
9006                         }
9007                     foundDash = NO;
9008                     }
9009                 else
9010                     {
9011                     MrBayesPrint ("%s   Not expecting a number\n", spacer);
9012                     return (ERROR);
9013                     }
9014                 }
9015             else if (expecting == Expecting(LEFTPAR))
9016                 {
9017                 if (modelIsFixed == YES)
9018                     expecting  = Expecting(ALPHA);
9019                 else
9020                     {
9021                     if (foundExp == YES)
9022                         expecting  = Expecting(NUMBER) | Expecting(DASH);
9023                     else
9024                         expecting  = Expecting(NUMBER) | Expecting(ALPHA);
9025                     }
9026                 }
9027             else if (expecting == Expecting(RIGHTPAR))
9028                 {
9029                 if (modelIsFixed == YES)
9030                     expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9031                 else
9032                     {
9033                     if (foundExp == YES)
9034                         {
9035                         foundExp = NO;
9036                         expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
9037                         }
9038                     else    
9039                         {
9040                         if (fromI < 10)
9041                             {
9042                             MrBayesPrint ("%s   Too few arguments in Aamodelpr\n", spacer);
9043                             return (ERROR);
9044                             }
9045                         nApplied = NumActiveParts ();
9046                         for (i=0; i<numCurrentDivisions; i++)
9047                             {
9048                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == PROTEIN)
9049                                 {
9050                                 if (!strcmp(modelParams[i].aaModelPr, "Fixed"))
9051                                     {
9052                                     MrBayesPrint ("%s   You cannot assign model prior probabilities for a fixed amino acid model\n", spacer);
9053                                     return (ERROR);
9054                                     }
9055                                 else
9056                                     {
9057                                     for (j=0; j<10; j++)
9058                                         modelParams[i].aaModelPrProbs[j] = tempAaModelPrs[j];
9059                                     }
9060                                 }
9061                             }
9062                         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9063                         }
9064                     }               
9065                 }
9066             else if (expecting == Expecting(DASH))
9067                 {
9068                 if (foundExp == YES)
9069                     {
9070                     foundDash = YES;
9071                     expecting  = Expecting(NUMBER);
9072                     }
9073                 else
9074                     {
9075                     MrBayesPrint ("%s   Invalid argument \"%s\"\n", spacer, tkn);
9076                     return (ERROR);
9077                     }
9078                 }
9079             else if (expecting == Expecting(COMMA))
9080                 {
9081                 if (modelIsFixed == YES)
9082                     {
9083                     MrBayesPrint ("%s   Not expecting \"%s\"\n", spacer, tkn);
9084                     return (ERROR);
9085                     }
9086                 else
9087                     expecting  = Expecting(NUMBER) | Expecting(ALPHA);
9088                 }
9089             else
9090                 return (ERROR);
9091             }       
9092         /* set Brownscalepr (brownScalesPr) ****************************************************/
9093         else if (!strcmp(parmName, "Brownscalepr"))
9094             {
9095             if (expecting == Expecting(EQUALSIGN))
9096                 expecting = Expecting(ALPHA);
9097             else if (expecting == Expecting(ALPHA))
9098                 {
9099                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9100                     {
9101                     nApplied = NumActiveParts ();
9102                     flag = 0;
9103                     for (i=0; i<numCurrentDivisions; i++)
9104                         {
9105                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
9106                             {
9107                             strcpy(modelParams[i].brownScalesPr, tempStr);
9108                             flag = 1;
9109                             }
9110                         }
9111                     if (flag == 0)
9112                             {
9113                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing CONTINUOUS data.\
9114                             Currently there is no active partition with such data. ", spacer, parmName);
9115                             return (ERROR);
9116                             }
9117                     }
9118                 else
9119                     {
9120                     MrBayesPrint ("%s   Invalid Brownscalepr argument\n", spacer);
9121                     return (ERROR);
9122                     }
9123                 expecting  = Expecting(LEFTPAR);
9124                 for (i=0; i<numCurrentDivisions; i++)
9125                     numVars[i] = 0;
9126                 }
9127             else if (expecting == Expecting(LEFTPAR))
9128                 {
9129                 expecting  = Expecting(NUMBER);
9130                 }
9131             else if (expecting == Expecting(NUMBER))
9132                 {
9133                 nApplied = NumActiveParts ();
9134                 for (i=0; i<numCurrentDivisions; i++)
9135                     {
9136                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
9137                         {
9138                         if (!strcmp(modelParams[i].brownScalesPr,"Uniform"))
9139                             {
9140                             sscanf (tkn, "%lf", &tempD);
9141                             modelParams[i].brownScalesUni[numVars[i]++] = tempD;
9142                             if (numVars[i] == 1)
9143                                 expecting  = Expecting(COMMA);
9144                             else
9145                                 {
9146                                 if (modelParams[i].brownScalesUni[0] >= modelParams[i].brownScalesUni[1])
9147                                     {
9148                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
9149                                     return (ERROR);
9150                                     }
9151                                 if (nApplied == 0 && numCurrentDivisions == 1)
9152                                     MrBayesPrint ("%s   Setting Brownscalepr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brownScalesUni[0], modelParams[i].brownScalesUni[1]);
9153                                 else
9154                                     MrBayesPrint ("%s   Setting Brownscalepr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brownScalesUni[0], modelParams[i].brownScalesUni[1], i+1);
9155                                 expecting  = Expecting(RIGHTPAR);
9156                                 }
9157                             }
9158                         else if (!strcmp(modelParams[i].brownScalesPr,"Gamma"))
9159                             {
9160                             sscanf (tkn, "%lf", &tempD);
9161                             modelParams[i].brownScalesGamma[numVars[i]++] = tempD;
9162                             if (numVars[i] == 1)
9163                                 expecting  = Expecting(COMMA);
9164                             else
9165                                 {
9166                                 if (nApplied == 0 && numCurrentDivisions == 1)
9167                                     MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=%1.2lf Var=%1.2lf\n", spacer, modelParams[i].brownScalesGamma[0], modelParams[i].brownScalesGamma[1]);
9168                                 else
9169                                     MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=%1.2lf Var=%1.2lf for partition %d\n", spacer, modelParams[i].brownScalesGamma[0], modelParams[i].brownScalesGamma[1], i+1);
9170                                 expecting  = Expecting(RIGHTPAR);
9171                                 }
9172                             }
9173                         else if (!strcmp(modelParams[i].brownScalesPr,"Gammamean"))
9174                             {
9175                             sscanf (tkn, "%lf", &tempD);
9176                             modelParams[i].brownScalesGammaMean = tempD;
9177                             if (nApplied == 0 && numCurrentDivisions == 1)
9178                                 MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=<char. ave.> Var=%1.2lf\n", spacer, modelParams[i].brownScalesGammaMean);
9179                             else
9180                                 MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=<char.ave.> Var=%1.2lf for partition %d\n", spacer, modelParams[i].brownScalesGammaMean, i+1);
9181                             expecting  = Expecting(RIGHTPAR);
9182                             }
9183                         else if (!strcmp(modelParams[i].brownScalesPr,"Fixed"))
9184                             {
9185                             sscanf (tkn, "%lf", &tempD);
9186                             modelParams[i].brownScalesFix = tempD;
9187                             if (nApplied == 0 && numCurrentDivisions == 1)
9188                                 MrBayesPrint ("%s   Setting Brownscalepr to Fixed(%1.2lf)\n", spacer, modelParams[i].brownScalesFix);
9189                             else
9190                                 MrBayesPrint ("%s   Setting Brownscalepr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].brownScalesFix, i+1);
9191                             expecting  = Expecting(RIGHTPAR);
9192                             }
9193                         }
9194                     }
9195                 }
9196             else if (expecting == Expecting(COMMA))
9197                 {
9198                 expecting  = Expecting(NUMBER);
9199                 }
9200             else if (expecting == Expecting(RIGHTPAR))
9201                 {
9202                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9203                 }
9204             else
9205                 return (ERROR);
9206             }
9207         /* set M10betapr (m10betapr) ********************************************************/
9208         else if (!strcmp(parmName, "M10betapr"))
9209             {
9210             if (expecting == Expecting(EQUALSIGN))
9211                 expecting = Expecting(ALPHA);
9212             else if (expecting == Expecting(ALPHA))
9213                 {
9214                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9215                     {
9216                     nApplied = NumActiveParts ();
9217                     flag = 0;
9218                     for (i=0; i<numCurrentDivisions; i++)
9219                         {
9220                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9221                             {
9222                             strcpy(modelParams[i].m10betapr, tempStr);
9223                             flag = 1;
9224                             }
9225                         }
9226                     if (flag == 0)
9227                             {
9228                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA.\
9229                             Currently there is no active partition with such data. ", spacer, parmName);
9230                             return (ERROR);
9231                             }
9232                     }
9233                 else
9234                     {
9235                     MrBayesPrint ("%s   Invalid M10betapr argument\n", spacer);
9236                     return (ERROR);
9237                     }
9238                 expecting  = Expecting(LEFTPAR);
9239                 for (i=0; i<numCurrentDivisions; i++)
9240                     numVars[i] = 0;
9241                 }
9242             else if (expecting == Expecting(LEFTPAR))
9243                 {
9244                 expecting  = Expecting(NUMBER);
9245                 }
9246             else if (expecting == Expecting(NUMBER))
9247                 {
9248                 nApplied = NumActiveParts ();
9249                 for (i=0; i<numCurrentDivisions; i++)
9250                     {
9251                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9252                         {
9253                         if (!strcmp(modelParams[i].m10betapr,"Uniform"))
9254                             {
9255                             sscanf (tkn, "%lf", &tempD);
9256                             modelParams[i].m10betaUni[numVars[i]++] = tempD;
9257                             if (numVars[i] == 1)
9258                                 expecting  = Expecting(COMMA);
9259                             else
9260                                 {
9261                                 if (modelParams[i].m10betaUni[0] >= modelParams[i].m10betaUni[1])
9262                                     {
9263                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
9264                                     return (ERROR);
9265                                     }
9266                                 if (nApplied == 0 && numCurrentDivisions == 1)
9267                                     MrBayesPrint ("%s   Setting M10betapr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10betaUni[0], modelParams[i].m10betaUni[1]);
9268                                 else
9269                                     MrBayesPrint ("%s   Setting M10betapr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10betaUni[0], modelParams[i].m10betaUni[1], i+1);
9270                                 expecting  = Expecting(RIGHTPAR);
9271                                 }
9272                             }
9273                         else if (!strcmp(modelParams[i].m10betapr,"Exponential"))
9274                             {
9275                             sscanf (tkn, "%lf", &tempD);
9276                             modelParams[i].m10betaExp = tempD;
9277                             if (nApplied == 0 && numCurrentDivisions == 1)
9278                                 MrBayesPrint ("%s   Setting M10betapr to Exponential(%1.2lf)\n", spacer, modelParams[i].m10betaExp);
9279                             else
9280                                 MrBayesPrint ("%s   Setting M10betapr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].m10betaExp, i+1);
9281                             expecting  = Expecting(RIGHTPAR);
9282                             }
9283                         else if (!strcmp(modelParams[i].m10betapr,"Fixed"))
9284                             {
9285                             sscanf (tkn, "%lf", &tempD);
9286                             modelParams[i].m10betaFix[numVars[i]++] = tempD;
9287                             if (numVars[i] == 1)
9288                                 expecting  = Expecting(COMMA);
9289                             else
9290                                 {
9291                                 if (nApplied == 0 && numCurrentDivisions == 1)
9292                                     MrBayesPrint ("%s   Setting M10betapr to Fixed(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10betaFix[0], modelParams[i].m10betaFix[1]);
9293                                 else
9294                                     MrBayesPrint ("%s   Setting M10betapr to Fixed(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10betaFix[0], modelParams[i].m10betaFix[1], i+1);
9295                                 expecting  = Expecting(RIGHTPAR);
9296                                 }
9297                             }
9298                         }
9299                     }
9300                 }
9301             else if (expecting == Expecting(COMMA))
9302                 {
9303                 expecting  = Expecting(NUMBER);
9304                 }
9305             else if (expecting == Expecting(RIGHTPAR))
9306                 {
9307                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9308                 }
9309             else
9310                 return (ERROR);
9311             }
9312         /* set M10gammapr (m10gammapr) ********************************************************/
9313         else if (!strcmp(parmName, "M10gammapr"))
9314             {
9315             if (expecting == Expecting(EQUALSIGN))
9316                 expecting = Expecting(ALPHA);
9317             else if (expecting == Expecting(ALPHA))
9318                 {
9319                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9320                     {
9321                     nApplied = NumActiveParts ();
9322                     flag = 0;
9323                     for (i=0; i<numCurrentDivisions; i++)
9324                         {
9325                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9326                             {
9327                             strcpy(modelParams[i].m10gammapr, tempStr);
9328                             flag = 1;
9329                             }
9330                         }
9331                     if (flag == 0)
9332                             {
9333                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA.\
9334                             Currently there is no active partition with such data. ", spacer, parmName);
9335                             return (ERROR);
9336                             }
9337                     }
9338                 else
9339                     {
9340                     MrBayesPrint ("%s   Invalid M10gammapr argument\n", spacer);
9341                     return (ERROR);
9342                     }
9343                 expecting  = Expecting(LEFTPAR);
9344                 for (i=0; i<numCurrentDivisions; i++)
9345                     numVars[i] = 0;
9346                 }
9347             else if (expecting == Expecting(LEFTPAR))
9348                 {
9349                 expecting  = Expecting(NUMBER);
9350                 }
9351             else if (expecting == Expecting(NUMBER))
9352                 {
9353                 nApplied = NumActiveParts ();
9354                 for (i=0; i<numCurrentDivisions; i++)
9355                     {
9356                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9357                         {
9358                         if (!strcmp(modelParams[i].m10gammapr,"Uniform"))
9359                             {
9360                             sscanf (tkn, "%lf", &tempD);
9361                             modelParams[i].m10gammaUni[numVars[i]++] = tempD;
9362                             if (numVars[i] == 1)
9363                                 expecting  = Expecting(COMMA);
9364                             else
9365                                 {
9366                                 if (modelParams[i].m10gammaUni[0] >= modelParams[i].m10gammaUni[1])
9367                                     {
9368                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
9369                                     return (ERROR);
9370                                     }
9371                                 if (nApplied == 0 && numCurrentDivisions == 1)
9372                                     MrBayesPrint ("%s   Setting M10gammapr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10gammaUni[0], modelParams[i].m10gammaUni[1]);
9373                                 else
9374                                     MrBayesPrint ("%s   Setting M10gammapr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10gammaUni[0], modelParams[i].m10gammaUni[1], i+1);
9375                                 expecting  = Expecting(RIGHTPAR);
9376                                 }
9377                             }
9378                         else if (!strcmp(modelParams[i].m10gammapr,"Exponential"))
9379                             {
9380                             sscanf (tkn, "%lf", &tempD);
9381                             modelParams[i].m10gammaExp = tempD;
9382                             if (nApplied == 0 && numCurrentDivisions == 1)
9383                                 MrBayesPrint ("%s   Setting M10gammapr to Exponential(%1.2lf)\n", spacer, modelParams[i].m10gammaExp);
9384                             else
9385                                 MrBayesPrint ("%s   Setting M10gammapr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].m10gammaExp, i+1);
9386                             expecting  = Expecting(RIGHTPAR);
9387                             }
9388                         else if (!strcmp(modelParams[i].m10gammapr,"Fixed"))
9389                             {
9390                             sscanf (tkn, "%lf", &tempD);
9391                             modelParams[i].m10gammaFix[numVars[i]++] = tempD;
9392                             if (numVars[i] == 1)
9393                                 expecting  = Expecting(COMMA);
9394                             else
9395                                 {
9396                                 if (nApplied == 0 && numCurrentDivisions == 1)
9397                                     MrBayesPrint ("%s   Setting M10gammapr to Fixed(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10gammaFix[0], modelParams[i].m10gammaFix[1]);
9398                                 else
9399                                     MrBayesPrint ("%s   Setting M10gammapr to Fixed(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10gammaFix[0], modelParams[i].m10gammaFix[1], i+1);
9400                                 expecting  = Expecting(RIGHTPAR);
9401                                 }
9402                             }
9403                         }
9404                     }
9405                 }
9406             else if (expecting == Expecting(COMMA))
9407                 {
9408                 expecting  = Expecting(NUMBER);
9409                 }
9410             else if (expecting == Expecting(RIGHTPAR))
9411                 {
9412                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9413                 }
9414             else
9415                 return (ERROR);
9416             }
9417
9418         else
9419             return (ERROR);
9420         }
9421
9422     return (NO_ERROR);
9423 }
9424
9425
9426 int DoQuit (void)
9427 {
9428     int         i;
9429     char        tempName[100];
9430     
9431     /* free information for model and matrix */
9432     FreeModel ();
9433     FreeMatrix ();
9434     
9435     SafeFclose (&logFileFp);
9436     logToFile = NO;
9437     
9438     /* check to see if any memory has not been freed */
9439     for (i=0; i<NUM_ALLOCS; i++)
9440         {
9441         if (memAllocs[i] == YES)
9442             {
9443             MrBayesPrint ("   WARNING: Memory (%d) has not been freed\n", i);
9444             if (mode == INTERACTIVE && quitOnError == NO)
9445                 {
9446                 MrBayesPrint ("%s   Hit return key to continue  ", spacer);
9447                 fflush (stdin);
9448                 if (fgets (tempName, 100, stdin) == NULL)
9449                     {
9450                     printf ("Error in function: %s at line: %d in file: %s", __FUNCTION__, __LINE__, __FILE__);
9451                     }
9452                 }
9453             }
9454         }
9455     
9456     /* free modelIndicatorParams and modelElementNames */
9457     for (i=0; i<203; i++)
9458         free (modelElementNames[1][i]);
9459     for (i=0; i<3; i++)
9460         free (modelElementNames[i]);
9461     free (modelElementNames);
9462     free (modelIndicatorParams);
9463     
9464     MrBayesPrint ("   Quitting program\n\n");
9465     
9466     /* If we quit while reading a mrbayes block, then we need to make certain
9467      that we return a NO_ERROR_QUIT so we can break out of DoExecute cleanly,
9468      and dealloc "s" there. */
9469     if (inMrbayesBlock == YES)
9470         {
9471         inMrbayesBlock = NO;
9472         return (NO_ERROR_QUIT);
9473         }
9474     
9475     return (NO_ERROR);
9476 }
9477
9478
9479 int DoReport (void)
9480 {
9481     /* TODO: smart update */
9482     if (SetUpAnalysis (&globalSeed) == ERROR)
9483         return (ERROR);
9484     return (NO_ERROR);
9485 }
9486
9487
9488 int DoReportParm (char *parmName, char *tkn)
9489 {
9490     int         i, tempInt, nApplied;
9491     char        tempStr[100];
9492
9493     if (defMatrix == NO)
9494         {
9495         MrBayesPrint ("%s   A matrix must be specified before the report settings can be altered\n", spacer);
9496         return (ERROR);
9497         }
9498     if (inValidCommand == YES)
9499         {
9500         for (i=0; i<numCurrentDivisions; i++)
9501             activeParts[i] = NO;
9502         inValidCommand = NO;
9503         }
9504
9505     if (expecting == Expecting(PARAMETER))
9506         {
9507         expecting = Expecting(EQUALSIGN);
9508         }
9509     else
9510         {
9511         /* set Applyto (Applyto) *************************************************************/
9512         if (!strcmp(parmName, "Applyto"))
9513             {
9514             if (expecting == Expecting(EQUALSIGN))
9515                 expecting = Expecting(LEFTPAR);
9516             else if (expecting == Expecting(LEFTPAR))
9517                 {
9518                 for (i=0; i<numCurrentDivisions; i++)
9519                     activeParts[i] = NO;
9520                 fromI = toJ = -1;
9521                 foundDash = NO;
9522                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
9523                 }
9524             else if (expecting == Expecting(RIGHTPAR))
9525                 {
9526                 if (fromI != -1)
9527                     activeParts[fromI-1] = YES;
9528                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9529                 }
9530             else if (expecting == Expecting(COMMA))
9531                 {
9532                 foundComma = YES;
9533                 expecting = Expecting(NUMBER);
9534                 }
9535             else if (expecting == Expecting(ALPHA))
9536                 {
9537                 if (IsSame ("All", tkn) == DIFFERENT)
9538                     {
9539                     MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
9540                     return (ERROR);
9541                     }
9542                 for (i=0; i<numCurrentDivisions; i++)
9543                     activeParts[i] = YES;
9544                 expecting  = Expecting(RIGHTPAR);
9545                 }
9546             else if (expecting == Expecting(NUMBER))
9547                 {
9548                 sscanf (tkn, "%d", &tempInt);
9549                 if (tempInt > numCurrentDivisions)
9550                     {
9551                     MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
9552                     return (ERROR);
9553                     }
9554                 if (fromI == -1)
9555                     fromI = tempInt;
9556                 else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
9557                     {
9558                     toJ = tempInt;
9559                     for (i=fromI-1; i<toJ; i++)
9560                         activeParts[i] = YES;
9561                     fromI = toJ = -1;
9562                     foundDash = NO;
9563                     }
9564                 else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
9565                     {
9566                     activeParts[fromI-1] = YES;
9567                     fromI = tempInt;
9568                     foundComma = NO;
9569                     }
9570                     
9571                 expecting  = Expecting(COMMA);
9572                 expecting |= Expecting(DASH);
9573                 expecting |= Expecting(RIGHTPAR);
9574                 }
9575             else if (expecting == Expecting(DASH))
9576                 {
9577                 foundDash = YES;
9578                 expecting = Expecting(NUMBER);
9579                 }
9580             else
9581                 return (ERROR);
9582             }
9583         /* set report format of tratio ***************************************************/
9584         else if (!strcmp(parmName, "Tratio"))
9585             {
9586             if (expecting == Expecting(EQUALSIGN))
9587                 expecting = Expecting (ALPHA);
9588             else if (expecting == Expecting(ALPHA))
9589                 {
9590                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9591                     {
9592                     nApplied = NumActiveParts ();
9593                     tempInt = NO;
9594                     for (i=0; i<numCurrentDivisions; i++)
9595                         {
9596                         /* check that data type is correct; we do not know yet if the user will specify
9597                         a nst=2 model so we cannot check that tratio is an active parameter */
9598                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9599                             {
9600                             strcpy(modelParams[i].tratioFormat, tempStr);
9601                             if (nApplied == 0 && numCurrentDivisions == 1)
9602                                 MrBayesPrint ("%s   Setting transition/transversion rate ratio (tratio) format to %s\n", spacer, modelParams[i].tratioFormat);
9603                             else
9604                                 MrBayesPrint ("%s   Setting transition/transversion rate ratio (tratio) format to %s for partition %d\n", spacer, modelParams[i].tratioFormat, i+1);
9605                             }
9606                         }
9607                     }
9608                 else
9609                     {
9610                     MrBayesPrint ("%s   Invalid transition/transversion rate ratio (tratio) format \n", spacer);
9611                     return (ERROR);
9612                     }
9613                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9614                 }
9615             else
9616                 return (ERROR);
9617             }
9618         /* set report format of revmat ***************************************************/
9619         else if (!strcmp(parmName, "Revmat"))
9620             {
9621             if (expecting == Expecting(EQUALSIGN))
9622                 expecting = Expecting (ALPHA);
9623             else if (expecting == Expecting(ALPHA))
9624                 {
9625                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9626                     {
9627                     nApplied = NumActiveParts ();
9628                     tempInt = NO;
9629                     for (i=0; i<numCurrentDivisions; i++)
9630                         {
9631                         /* check that data type is correct; we do not know yet if the user will specify
9632                            a nst=6 model so we cannot check that revmat is an active parameter */
9633                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9634                             {
9635                             strcpy(modelParams[i].revmatFormat, tempStr);
9636                             if (nApplied == 0 && numCurrentDivisions == 1)
9637                                 MrBayesPrint ("%s   Setting reversible rate matrix (revmat) format to %s\n", spacer, modelParams[i].revmatFormat);
9638                             else
9639                                 MrBayesPrint ("%s   Setting reversible rate matrix (revmat) format to %s for partition %d\n", spacer, modelParams[i].revmatFormat, i+1);
9640                             }
9641                         }
9642                     }
9643                 else
9644                     {
9645                     MrBayesPrint ("%s   Invalid reversible rate matrix (revmat) format \n", spacer);
9646                     return (ERROR);
9647                     }
9648                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9649                 }
9650             else
9651                 return (ERROR);
9652             }
9653         /* set report format of ratemult *************************************************/
9654         else if (!strcmp(parmName, "Ratemult"))
9655             {
9656             if (expecting == Expecting(EQUALSIGN))
9657                 expecting = Expecting (ALPHA);
9658             else if (expecting == Expecting(ALPHA))
9659                 {
9660                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9661                     {
9662                     nApplied = NumActiveParts ();
9663                     tempInt = NO;
9664                     for (i=0; i<numCurrentDivisions; i++)
9665                         {
9666                         /* we do not know yet if the user will specify variable rates across partitions 
9667                            so only check that we have more than one partition in the model */
9668                         if ((activeParts[i] == YES || nApplied == 0) && numCurrentDivisions > 1)
9669                             {
9670                             strcpy(modelParams[i].ratemultFormat, tempStr);
9671                             if (nApplied == 0 && numCurrentDivisions == 1)
9672                                 MrBayesPrint ("%s   Setting rate multiplier (ratemult) format to %s\n", spacer, modelParams[i].ratemultFormat);
9673                             else
9674                                 MrBayesPrint ("%s   Setting rate multiplier (ratemult) format to %s for partition %d\n", spacer, modelParams[i].ratemultFormat, i+1);
9675                             }
9676                         }
9677                     }
9678                 else
9679                     {
9680                     MrBayesPrint ("%s   Invalid rate multiplier (ratemult) format \n", spacer);
9681                     return (ERROR);
9682                     }
9683                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9684                 }
9685             else
9686                 return (ERROR);
9687             }
9688         /* set report format of tree ***************************************************/
9689         else if (!strcmp(parmName, "Tree"))
9690             {
9691             if (expecting == Expecting(EQUALSIGN))
9692                 expecting = Expecting (ALPHA);
9693             else if (expecting == Expecting(ALPHA))
9694                 {
9695                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9696                     {
9697                     nApplied = NumActiveParts ();
9698                     tempInt = NO;
9699                     for (i=0; i<numCurrentDivisions; i++)
9700                         {
9701                         strcpy(modelParams[i].treeFormat, tempStr);
9702                         if (nApplied == 0 && numCurrentDivisions == 1)
9703                             MrBayesPrint ("%s   Setting tree report format to %s\n", spacer, modelParams[i].treeFormat);
9704                         else
9705                             MrBayesPrint ("%s   Setting tree report format to %s for partition %d\n", spacer, modelParams[i].treeFormat, i+1);
9706                         }
9707                     }
9708                 else
9709                     {
9710                     MrBayesPrint ("%s   Invalid tree report format \n", spacer);
9711                     return (ERROR);
9712                     }
9713                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9714                 }
9715             else
9716                 return (ERROR);
9717             }
9718         /* set inferancstates ***********************************************************/
9719         else if (!strcmp(parmName, "Ancstates"))
9720             {
9721             if (expecting == Expecting(EQUALSIGN))
9722                 expecting = Expecting (ALPHA);
9723             else if (expecting == Expecting(ALPHA))
9724                 {
9725                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9726                     {
9727                     nApplied = NumActiveParts ();
9728                     for (i=0; i<numCurrentDivisions; i++)
9729                         {
9730                         if (activeParts[i] == YES || nApplied == 0)
9731                             {
9732                             strcpy(modelParams[i].inferAncStates,tempStr);
9733                             if (!strcmp(tempStr,"Yes"))
9734                                 {
9735                                 if (nApplied == 0 && numCurrentDivisions == 1)
9736                                     MrBayesPrint ("%s   Reporting ancestral states (if applicable)\n", spacer);
9737                                 else
9738                                     MrBayesPrint ("%s   Reporting ancestral states for partition %d (if applicable)\n", spacer, i+1);
9739                                 }
9740                             else
9741                                 {
9742                                 if (nApplied == 0 && numCurrentDivisions == 1)
9743                                     MrBayesPrint ("%s   Not reporting ancestral states\n", spacer);
9744                                 else
9745                                     MrBayesPrint ("%s   Not reporting ancestral states for partition %d\n", spacer, i+1);
9746                                 }
9747                             }
9748                         }
9749                     }
9750                 else
9751                     {
9752                     MrBayesPrint ("%s   Invalid ancstates option\n", spacer);
9753                     return (ERROR);
9754                     }
9755                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9756                 }
9757             else
9758                 return (ERROR);
9759             }
9760         /* set inferSiteRates ***************************************************************/
9761         else if (!strcmp(parmName, "Siterates"))
9762             {
9763             if (expecting == Expecting(EQUALSIGN))
9764                 expecting = Expecting (ALPHA);
9765             else if (expecting == Expecting(ALPHA))
9766                 {
9767                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9768                     {
9769                     nApplied = NumActiveParts ();
9770                     for (i=0; i<numCurrentDivisions; i++)
9771                         {
9772                         if (activeParts[i] == YES || nApplied == 0)
9773                             {
9774                             strcpy (modelParams[i].inferSiteRates, tempStr);
9775                             if (!strcmp(tempStr,"Yes"))
9776                                 {
9777                                 if (nApplied == 0 && numCurrentDivisions == 1)
9778                                     MrBayesPrint ("%s   Reporting site rates (if applicable)\n", spacer);
9779                                 else
9780                                     MrBayesPrint ("%s   Reporting site rates for partition %d (if applicable)\n", spacer, i+1);
9781                                 }
9782                             else
9783                                 {
9784                                 if (nApplied == 0 && numCurrentDivisions == 1)
9785                                     MrBayesPrint ("%s   Not reporting site rates\n", spacer);
9786                                 else
9787                                     MrBayesPrint ("%s   Not reporting site rates for partition %d\n", spacer, i+1);
9788                                 }
9789                             }
9790                         }
9791                     }
9792                 else
9793                     {
9794                     MrBayesPrint ("%s   Invalid siterates option\n", spacer);
9795                     return (ERROR);
9796                     }
9797                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9798                 }
9799             else
9800                 return (ERROR);
9801             }
9802         /* set inferpossel *************************************************************/
9803         else if (!strcmp(parmName, "Possel"))
9804             {
9805             if (expecting == Expecting(EQUALSIGN))
9806                 expecting = Expecting (ALPHA);
9807             else if (expecting == Expecting(ALPHA))
9808                 {
9809                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9810                     {
9811                     nApplied = NumActiveParts ();
9812                     for (i=0; i<numCurrentDivisions; i++)
9813                         {
9814                         if (activeParts[i] == YES || nApplied == 0)
9815                             {
9816                             strcpy (modelParams[i].inferPosSel, tempStr);
9817                             if (!strcmp(tempStr, "Yes"))
9818                                 {
9819                                 if (nApplied == 0 && numCurrentDivisions == 1)
9820                                     MrBayesPrint ("%s   Reporting positive selection (if applicable)\n", spacer);
9821                                 else
9822                                     MrBayesPrint ("%s   Reporting positive selection for partition %d (if applicable)\n", spacer, i+1);
9823                                 }
9824                             else
9825                                 {
9826                                 if (nApplied == 0 && numCurrentDivisions == 1)
9827                                     MrBayesPrint ("%s   Not reporting positive selection\n", spacer);
9828                                 else
9829                                     MrBayesPrint ("%s   Not reporting positive selection for partition %d\n", spacer, i+1);
9830                                 }
9831                             }
9832                         }
9833                     }
9834                 else
9835                     {
9836                     MrBayesPrint ("%s   Invalid possel option\n", spacer);
9837                     return (ERROR);
9838                     }
9839                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9840                 }
9841             else
9842                 return (ERROR);
9843             }
9844         /* set inferSiteOmegas *************************************************************/
9845         else if (!strcmp(parmName, "Siteomega"))
9846             {
9847             if (expecting == Expecting(EQUALSIGN))
9848                 expecting = Expecting (ALPHA);
9849             else if (expecting == Expecting(ALPHA))
9850                 {
9851                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9852                     {
9853                     nApplied = NumActiveParts ();
9854                     for (i=0; i<numCurrentDivisions; i++)
9855                         {
9856                         if (activeParts[i] == YES || nApplied == 0)
9857                             {
9858                             strcpy (modelParams[i].inferSiteOmegas, tempStr);
9859                             if (!strcmp(tempStr, "Yes"))
9860                                 {
9861                                 if (nApplied == 0 && numCurrentDivisions == 1)
9862                                     MrBayesPrint ("%s   Reporting site omega values (if applicable)\n", spacer);
9863                                 else
9864                                     MrBayesPrint ("%s   Reporting site omega values for partition %d (if applicable)\n", spacer, i+1);
9865                                 }
9866                             else
9867                                 {
9868                                 if (nApplied == 0 && numCurrentDivisions == 1)
9869                                     MrBayesPrint ("%s   Not reporting site omega values\n", spacer);
9870                                 else
9871                                     MrBayesPrint ("%s   Not reporting site omega values for partition %d\n", spacer, i+1);
9872                                 }
9873                             }
9874                         }
9875                     }
9876                 else
9877                     {
9878                     MrBayesPrint ("%s   Invalid siteomega option\n", spacer);
9879                     return (ERROR);
9880                     }
9881                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9882                 }
9883             else
9884                 return (ERROR);
9885             }
9886         else
9887             {
9888             return (ERROR);
9889             }
9890         }
9891
9892     return (NO_ERROR);      
9893 }
9894
9895
9896 int DoStartvals (void)
9897 {
9898     MrBayesPrint ("%s   Successfully set starting values\n", spacer);
9899     /*
9900     for (i=0; i<numParams; i++)
9901         assert (IsTreeConsistent(&params[i], 0, 0) == YES);
9902     */
9903     return (NO_ERROR);
9904 }
9905
9906
9907 int DoStartvalsParm (char *parmName, char *tkn)
9908 {
9909     int                 i, j, k, nMatches, tempInt, treeIndex, chainId, ret;
9910     MrBFlt              tempFloat, *value, *subValue;
9911     Tree                *theTree, *usrTree;
9912     PolyTree            *thePolyTree;
9913     MrBFlt              minRate, maxRate, clockRate;
9914     static Param        *param = NULL;
9915     static MrBFlt       *theValue, theValueMin, theValueMax;
9916     static int          useSubvalues, useStdStateFreqs, useIntValues, numExpectedValues, nValuesRead, runIndex, chainIndex, foundName, foundDash;
9917     static char         *temp=NULL, *tempName=NULL;
9918
9919     if (defMatrix == NO)
9920         {
9921         MrBayesPrint ("%s   A matrix must be specified before starting values can be changed\n", spacer);
9922         return (ERROR);
9923         }
9924
9925     if (expecting == Expecting(PARAMETER))
9926         {
9927         if (!strcmp(parmName, "Xxxxxxxxxx"))
9928             {
9929             /* we expect a parameter name with possible run and chain specification as follows:
9930                <param_name>(<run>,<chain>)=(<number>,...)   -- apply to run <run> and chain <chain>
9931                <param_name>(,<chain>)=(<number>,...)        -- apply to chain <chain> for all runs
9932                <param_name>(<run>,)=(<number>,...)          -- apply to run <run> for all chains
9933
9934                topology and branch length parameters are specified like
9935                <param_name>(<run>,<chain>)=<tree_name>|<Newick_tree_spec>
9936
9937                parameter names will often be followed by partition specifiers like:
9938                pi{all}
9939                pinvar{1,4,5}
9940                so we need to assemble the parameter name from several tokens that are parsed out separately;
9941                here we receive only the first part (before the left curly, if present)
9942             */
9943             
9944             /* copy to local parameter name */
9945             SafeStrcpy (&tempName, tkn);
9946             param = NULL;
9947             runIndex = chainIndex = -1;
9948             useSubvalues = NO;
9949             useIntValues = NO;
9950             useStdStateFreqs = NO;
9951             foundComma = foundEqual = foundName = foundDash = NO;
9952             expecting = Expecting(LEFTCURL) | Expecting(LEFTPAR) |  Expecting(EQUALSIGN);
9953             }
9954         else
9955             return (ERROR);
9956         }
9957     else if (expecting == Expecting(ALPHA))
9958         {
9959         if (param == NULL)
9960             {
9961             /* we are still assembling the parameter name */
9962             SafeStrcat (&tempName, tkn);
9963             expecting = Expecting(RIGHTCURL) | Expecting(COMMA) | Expecting(LEFTPAR) | Expecting(EQUALSIGN);
9964             }
9965         else
9966             {
9967             /* we have a tree name; now find the tree based on name, case insensitive */
9968             if (GetUserTreeFromName (&treeIndex, tkn) == ERROR || treeIndex == -1)
9969                 {
9970                 MrBayesPrint ("%s   Error in finding user tree\n", spacer);
9971                 return (ERROR);
9972                 }
9973
9974             /* set the tree parameter */
9975             for (i=0; i<chainParams.numRuns; i++)
9976                 {
9977                 if (runIndex != -1 && i != runIndex)
9978                     continue;
9979                 for (j=0; j<chainParams.numChains; j++)
9980                     {
9981                     if (chainIndex != -1 && j != chainIndex)
9982                         continue;
9983                     chainId = i*chainParams.numChains + j;
9984                     if (param->paramType != P_POPSIZE)
9985                         {
9986                         if (param->paramType == P_TOPOLOGY || param->paramType == P_BRLENS || param->paramType == P_SPECIESTREE)
9987                             {
9988                             /* topology or brlens or speciestree params */
9989                             theTree = GetTree (param, chainId, 0);
9990                             usrTree = GetTree (param, chainId, 1); /* use as scratch space */
9991                             }
9992                         else
9993                             {
9994                             /* relaxed clock params */
9995                             theTree = GetTree (modelSettings[param->relParts[0]].brlens, chainId, 0);
9996                             usrTree = GetTree (modelSettings[param->relParts[0]].brlens, chainId, 1);
9997                             }
9998                         CopyToTreeFromTree (usrTree, theTree);
9999                         if (param->paramType == P_SPECIESTREE)
10000                             thePolyTree = AllocatePolyTree(numSpecies);
10001                         else
10002                             thePolyTree = AllocatePolyTree (numTaxa);
10003                         CopyToPolyTreeFromPolyTree (thePolyTree, userTree[treeIndex]);
10004                         if (param->paramType == P_SPECIESTREE)
10005                             {
10006                             ResetIntNodeIndices(thePolyTree);
10007                             }
10008                         else
10009                             {
10010                             PrunePolyTree (thePolyTree);
10011                             ResetTipIndices(thePolyTree);
10012                             }
10013                         RandResolve (NULL, thePolyTree, &globalSeed, theTree->isRooted);
10014                         GetPolyDownPass(thePolyTree);
10015                         ResetIntNodeIndices(thePolyTree);
10016                         if (param->paramType == P_SPECIESTREE)
10017                             {
10018                             ret=CopyToSpeciesTreeFromPolyTree (usrTree, thePolyTree);
10019                             }
10020                         else
10021                             ret=CopyToTreeFromPolyTree (usrTree, thePolyTree);
10022                         FreePolyTree (thePolyTree);
10023                         if (ret==ERROR)
10024                             return ERROR;
10025                         }
10026                     else
10027                         {
10028                         /* param->paramType == P_POPSIZE */
10029                         theTree = GetTree (modelSettings[param->relParts[0]].speciesTree, chainId, 0);
10030                         usrTree = GetTree (modelSettings[param->relParts[0]].speciesTree, chainId, 1);
10031                         CopyToTreeFromTree (usrTree, theTree);
10032                         thePolyTree = AllocatePolyTree(numSpecies);
10033                         CopyToPolyTreeFromPolyTree (thePolyTree, userTree[treeIndex]);
10034                         ResetIntNodeIndices(thePolyTree);
10035                         RandResolve (NULL, thePolyTree, &globalSeed, theTree->isRooted);
10036                         CopyToSpeciesTreeFromPolyTree (usrTree, thePolyTree);
10037                         FreePolyTree (thePolyTree);
10038                         }
10039                     if (param->paramType == P_TOPOLOGY)
10040                         {
10041                         if (theTree->checkConstraints == YES && CheckSetConstraints (usrTree) == ERROR)
10042                             {
10043                             MrBayesPrint ("%s   Could not set the constraints for topology parameter '%s'\n", spacer, param->name);
10044                             return (ERROR);
10045                             }
10046                         if (ResetTopologyFromTree (theTree, usrTree) == ERROR)
10047                             {
10048                             MrBayesPrint ("%s   Could not set the topology parameter '%s'\n", spacer, param->name);
10049                             return (ERROR);
10050                             }
10051                         if (theTree->checkConstraints == YES && CheckSetConstraints (theTree)==ERROR)
10052                             {
10053                             MrBayesPrint ("%s   Could not set the constraints for topology parameter '%s'\n", spacer, param->name);
10054                             return (ERROR);
10055                             }
10056                         FillTopologySubParams (param, chainId, 0, &globalSeed);
10057                         //MrBayesPrint ("%s   Branch lengths and relaxed clock subparameters of a parameter '%s' are reset.\n", spacer, param->name);
10058                         if (param->paramId == TOPOLOGY_SPECIESTREE)
10059                             FillSpeciesTreeParams(&globalSeed, chainId, chainId+1);
10060                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10061                         }
10062                     else if (param->paramType == P_BRLENS)
10063                         {
10064                         if (usrTree->allDownPass[0]->length == 0.0 && param->paramId != BRLENS_CLOCK_FOSSIL)
10065                             {
10066                             MrBayesPrint ("%s   User tree '%s' does not have branch lengths so it cannot be used in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10067                             return (ERROR);
10068                             }
10069                         if (AreTopologiesSame (theTree, usrTree) == NO)
10070                             {
10071                             MrBayesPrint ("%s   Topology of user tree '%s' wrong in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10072                             return (ERROR);
10073                             }
10074                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10075                         /* reset node depths to ensure that non-dated tips have node depth 0.0 */
10076                         /* if (usrTree->isClock == YES)
10077                             SetNodeDepths(usrTree);  */
10078                         if (ResetBrlensFromTree (theTree, usrTree) == ERROR)
10079                             {
10080                             MrBayesPrint ("%s   Could not set parameter '%s' from user tree '%s'\n", spacer, param->name, userTree[treeIndex]->name);
10081                             return (ERROR);
10082                             }
10083                         if (theTree->isClock == YES && modelParams[theTree->relParts[0]].treeAgePr.prior == fixed)
10084                             {
10085                             if (!strcmp(modelParams[theTree->relParts[0]].clockPr,"Uniform")
10086                                 || !strcmp(modelParams[theTree->relParts[0]].clockPr,"Fossilization"))
10087                                 ResetRootHeight (theTree, modelParams[theTree->relParts[0]].treeAgePr.priorParams[0]);
10088                             }
10089                         /* the test will find suitable clock rate and ages of nodes in theTree */
10090                         if (theTree->isClock == YES && IsClockSatisfied (theTree,0.001) == NO)
10091                             {
10092                             MrBayesPrint ("%s   Non-calibrated tips are not at the same level after setting up starting tree branch lengthes(%s) from user tree '%s'.\n",
10093                                           spacer, param->name, userTree[treeIndex]->name);
10094                             ShowNodes(theTree->root,0,YES);
10095                             return (ERROR);
10096                             }
10097                         if (theTree->isCalibrated == YES && IsCalibratedClockSatisfied (theTree, &minRate,&maxRate, 0.001) == NO)
10098                             {
10099                             MrBayesPrint ("%s   Problem setting calibrated tree parameters\n", spacer);
10100                             return (ERROR);
10101                             }
10102                         if (theTree->isCalibrated == YES && !strcmp(modelParams[theTree->relParts[0]].clockRatePr, "Fixed"))
10103                             {
10104                             clockRate = modelParams[theTree->relParts[0]].clockRateFix;
10105                             if ((clockRate < minRate && AreDoublesEqual (clockRate, minRate , 0.001) == NO) || (clockRate > maxRate && AreDoublesEqual (clockRate, maxRate , 0.001) == NO))
10106                                 {
10107                                 MrBayesPrint("%s   Fixed branch lengths do not satisfy fixed clockrate\n", spacer);
10108                                 return (ERROR);
10109                                 }
10110                             }
10111                         theTree->fromUserTree=YES;
10112                         
10113                         FillBrlensSubParams (param, chainId, 0);
10114                         //MrBayesPrint ("%s   Rrelaxed clock subparamiters of a parameter '%s' are reset.\n", spacer, param->name);
10115                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10116                         if (param->paramId == BRLENS_CLOCK_SPCOAL)
10117                             FillSpeciesTreeParams(&globalSeed, chainId, chainId+1);
10118                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10119                         }
10120                     else if (param->paramType == P_CPPEVENTS || param->paramType == P_TK02BRANCHRATES ||
10121                              param->paramType == P_IGRBRANCHRATES || param->paramType == P_MIXEDBRCHRATES)
10122                         {
10123                         if (theTree->isCalibrated == YES && theTree->fromUserTree == NO)
10124                             { /* if theTree is not set from user tree then we can not garanty that branch lenghts will stay the same
10125                                  by the time we start mcmc run because of clockrate adjustment. */
10126                             MrBayesPrint ("%s    Set starting values for branch lengthes first before setting starting values of relaxed parameters!\n", spacer);
10127                             return (ERROR);
10128                             }
10129                         if (theTree->isCalibrated == NO && IsClockSatisfied (usrTree, 0.001) == NO) // user tree is not calibrated so do not check it if calibration is in place
10130                             {
10131                             MrBayesPrint ("%s   Branch lengths of the user tree '%s' do not satisfy clock in setting parameter '%s'\n", spacer, userTree[treeIndex], param->name);
10132                             ShowNodes(usrTree->root,0,YES);
10133                             return (ERROR);
10134                             }
10135                         if (AreTopologiesSame (theTree, usrTree) == NO)
10136                             {
10137                             MrBayesPrint ("%s   Topology of user tree '%s' is wrong in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10138                             return (ERROR);
10139                             }
10140                         if (SetRelaxedClockParam (param, chainId, 0, userTree[treeIndex]) == ERROR)
10141                             {
10142                             MrBayesPrint ("%s   Could not set parameter '%s' from user tree '%s'\n", spacer, param->name, userTree[treeIndex]->name);
10143                             return (ERROR);
10144                             }
10145                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10146                         }
10147                     else if (param->paramType == P_POPSIZE)
10148                         {
10149                         if (AreTopologiesSame (theTree, usrTree) == NO)
10150                             {
10151                             MrBayesPrint ("%s   Topology of user tree '%s' is wrong in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10152                             return (ERROR);
10153                             }
10154                         if (SetPopSizeParam (param, chainId, 0, userTree[treeIndex]) == ERROR)
10155                             {
10156                             MrBayesPrint ("%s   Could not set parameter '%s' from user tree '%s'\n", spacer, param->name, userTree[treeIndex]->name);
10157                             return (ERROR);
10158                             }
10159                         }
10160                     else if (param->paramType == P_SPECIESTREE)
10161                         {
10162                         if (IsSpeciesTreeConsistent (usrTree, chainId) == NO)
10163                             {
10164                             MrBayesPrint ("%s   User-specified species tree '%s' is inconsistent with gene trees\n", spacer, userTree[treeIndex]->name);
10165                             return (ERROR);
10166                             }
10167                         if (CopyToTreeFromTree (theTree, usrTree) == ERROR)
10168                             {
10169                             MrBayesPrint ("%s   Could not set the species tree parameter '%s'\n", spacer, param->name);
10170                             return (ERROR);
10171                             }
10172                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10173                         }
10174                     }
10175                 }
10176             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10177             }
10178         }
10179     else if (expecting == Expecting(LEFTCURL))
10180         {
10181         /* we are still assembling the parameter name */
10182         SafeStrcat (&tempName, tkn);
10183         expecting = Expecting(NUMBER) | Expecting(ALPHA) | Expecting(LEFTPAR) | Expecting(EQUALSIGN);
10184         }
10185     else if (expecting == Expecting(RIGHTCURL))
10186         {
10187         /* we are still assembling the parameter name */
10188         SafeStrcat (&tempName, tkn);
10189         foundComma = NO; /*! if there was a comma in the partition part, we should reset this variable. Otherwise we can't parse something like A{1,2}(3,4) */
10190         expecting = Expecting(LEFTPAR) | Expecting(EQUALSIGN);
10191         }
10192     else if (expecting == Expecting(LEFTPAR))
10193         {
10194         if (foundEqual == NO)
10195             {
10196             foundName = YES;    /* we found the name */
10197             /* we will be reading in run and chain indices */
10198             expecting = Expecting(NUMBER) | Expecting(COMMA);
10199             }
10200         else
10201             {
10202             expecting = Expecting(NUMBER);
10203             expecting |= Expecting(DASH);
10204             }
10205         }
10206     else if (expecting == Expecting(DASH))
10207         {
10208         foundDash = YES;
10209         expecting = Expecting(NUMBER);
10210         }
10211     else if (expecting == Expecting(NUMBER))
10212         {
10213         if (foundName == NO)
10214             {
10215             /* we are still assembling the parameter name */
10216             SafeStrcat (&tempName, tkn);
10217             expecting = Expecting(COMMA) | Expecting(LEFTPAR) | Expecting(RIGHTCURL) | Expecting(EQUALSIGN);
10218             }
10219         else if (foundEqual == YES)
10220             {
10221             theValueMin = param->min;
10222             theValueMax = param->max;
10223
10224             /* we are reading in a parameter value */
10225             if (param->paramType==P_OMEGA && nValuesRead==numExpectedValues && useSubvalues == NO)
10226                 {
10227                 /* continue with subvalues */
10228                 nValuesRead = 0;
10229                 numExpectedValues = param->nSubValues/2;
10230                 useSubvalues = YES;
10231                 theValueMin = ETA;
10232                 theValueMax = 1.0;
10233                 }
10234             if (param->paramType==P_OMEGA && nValuesRead==numExpectedValues && useSubvalues == NO)
10235                 {
10236                 /* continue with subvalues */
10237                 nValuesRead = 0;
10238                 numExpectedValues = param->nSubValues/2;
10239                 useSubvalues = YES;
10240                 theValueMin = ETA;
10241                 theValueMax = 1.0;
10242                 }
10243             if (param->nIntValues > 0 && nValuesRead==numExpectedValues && useIntValues == NO)
10244                 {
10245                 /* continue with intValues */
10246                 nValuesRead = 0;
10247                 numExpectedValues = param->nIntValues;
10248                 useIntValues = YES;
10249                 }
10250             if (param->paramType==P_PI && modelSettings[param->relParts[0]].dataType == STANDARD && param->paramId != SYMPI_EQUAL
10251                 && nValuesRead==numExpectedValues && useStdStateFreqs == NO)
10252                 {
10253                 /* we have read alpha_symdir, continue with multistate char state freqs */
10254                 nValuesRead = 0;
10255                 numExpectedValues = param->nStdStateFreqs;
10256                 if (param->hasBinaryStd == YES)
10257                     numExpectedValues -= 2 * modelSettings[param->relParts[0]].numBetaCats;
10258                 useStdStateFreqs = YES;
10259                 theValueMin = ETA;
10260                 theValueMax = 1.0;
10261                 }
10262             nValuesRead++;
10263             if (nValuesRead > numExpectedValues)
10264                 {
10265                 if (param->paramType == P_OMEGA)
10266                     MrBayesPrint ("%s   Only %d values were expected for parameter '%s'\n", spacer, param->nValues+param->nSubValues/2, param->name);
10267                 else if (param->nIntValues > 0)   
10268                     MrBayesPrint ("%s   Only %d values were expected for parameter '%s'\n", spacer, param->nValues+param->nIntValues, param->name);
10269                 else
10270                     MrBayesPrint ("%s   Only %d values were expected for parameter '%s'\n", spacer, numExpectedValues, param->name);
10271                 return (ERROR);
10272                 }
10273             if (useIntValues == YES)
10274                 sscanf (tkn, "%d", &tempInt);
10275             else
10276                 sscanf (tkn, "%lf", &tempFloat);
10277             if (foundDash == YES)
10278                 {
10279                 if (useIntValues == NO)
10280                     tempFloat = -tempFloat;
10281                 else
10282                     tempInt = -tempInt;
10283                 foundDash = NO;
10284                 }
10285             if (useIntValues == NO && (tempFloat < theValueMin || tempFloat > theValueMax))
10286                 {
10287                 MrBayesPrint ("%s   The value is out of range (min = %lf; max = %lf)\n", spacer, theValueMin, theValueMax);
10288                 return (ERROR);
10289                 }
10290             for (i=0; i<chainParams.numRuns; i++)
10291                 {
10292                 if (runIndex != -1 && runIndex != i)
10293                     continue;
10294                 for (j=0; j<chainParams.numChains; j++)
10295                     {
10296                     if (chainIndex != -1 && chainIndex != j)
10297                         continue;
10298                     if (useIntValues == YES)
10299                         {
10300                         GetParamIntVals (param, i*chainParams.numChains+j, 0)[nValuesRead-1] = tempInt;
10301                         }
10302                     else
10303                         {
10304                         if (useSubvalues == NO && useStdStateFreqs == NO)
10305                             theValue = GetParamVals (param, i*chainParams.numChains+j, 0);
10306                         else if (useSubvalues == YES)
10307                             theValue = GetParamSubVals (param, i*chainParams.numChains+j, 0);
10308                         else if (useStdStateFreqs == YES)
10309                             {
10310                             theValue = GetParamStdStateFreqs (param, i*chainParams.numChains+j, 0);
10311                             if (param->hasBinaryStd == YES)
10312                                 theValue += 2 * modelSettings[param->relParts[0]].numBetaCats;
10313                             }
10314                         else
10315                             return (ERROR);
10316                         if (param->paramType == P_CLOCKRATE)
10317                             {
10318                             if (UpdateClockRate(tempFloat, i*chainParams.numChains+j) == ERROR) 
10319                                 {
10320                                 return (ERROR);
10321                                 }
10322                             }
10323                         theValue[nValuesRead-1] = tempFloat;
10324                         }
10325                     }
10326                 }
10327             expecting = Expecting (COMMA) | Expecting(RIGHTPAR);
10328             }
10329         else /* if (foundEqual == NO) */
10330             {
10331             sscanf (tkn, "%d", &tempInt);
10332             if (foundComma == NO)
10333                 {
10334                 if (tempInt <= 0 || tempInt > chainParams.numRuns)
10335                     {
10336                     MrBayesPrint ("%s   Run index is out of range (min=1; max=%d)\n", spacer, chainParams.numRuns);
10337                     return (ERROR);
10338                     }
10339                 runIndex = tempInt - 1;
10340                 expecting = Expecting(COMMA);
10341                 }
10342             else
10343                 {
10344                 if (tempInt <= 0 || tempInt > chainParams.numChains)
10345                     {
10346                     MrBayesPrint ("%s   Chain index is out of range (min=1; max=%d)\n", spacer, chainParams.numChains);
10347                     return (ERROR);
10348                     }
10349                 chainIndex = tempInt - 1;
10350                 foundComma = NO;
10351                 expecting = Expecting(RIGHTPAR);
10352                 }
10353             }
10354         }
10355     else if (expecting == Expecting(COMMA))
10356         {
10357         if (foundEqual == YES)
10358             {
10359             /* we expect another parameter value */
10360             expecting = Expecting(NUMBER);
10361             }
10362         else /* if (foundEqual == NO) */
10363             {
10364             /* we will be reading in chain index, if present */
10365             foundComma = YES;
10366             expecting = Expecting(RIGHTPAR) | Expecting(NUMBER); 
10367             /* if the comma is in a list of partitions (so between { and }) we have to add the comma to the parameter name */
10368             if (param == NULL && strchr(tempName, '}')==NULL && strchr(tempName, '{')!=NULL) 
10369               SafeStrcat (&tempName, ",");
10370             }
10371         }
10372     else if (expecting == Expecting(RIGHTPAR))
10373         {
10374         if (foundEqual == NO)
10375             {
10376             /* this is the end of the run and chain specification */
10377             expecting = Expecting(EQUALSIGN);
10378             }
10379         else /* if (foundEqual == YES) */
10380             {
10381             /* this is the end of the parameter values */
10382             if (nValuesRead != numExpectedValues)
10383                 {
10384                 MrBayesPrint ("%s   Expected %d values but only found %d values for parameter '%s'\n", spacer, numExpectedValues, nValuesRead, param->name);
10385                 return (ERROR);
10386                 }
10387             /* Post processing needed for some parameters */
10388             if (param->paramType == P_SHAPE || param->paramType == P_CORREL)
10389                 {
10390                 for (i=0; i<chainParams.numRuns; i++)
10391                     {
10392                     if (runIndex != -1 && runIndex != i)
10393                         continue;
10394                     for (j=0; j<chainParams.numChains; j++)
10395                         {
10396                         if (chainIndex != -1 && chainIndex != j)
10397                             continue;
10398                         value = GetParamVals(param,i*chainParams.numChains+j,0);
10399                         subValue = GetParamSubVals(param,i*chainParams.numChains+j,0);
10400                         if (param->paramType == P_SHAPE && !strncmp(param->name, "Alpha", 5))
10401                             {
10402                             if (DiscreteGamma (subValue, value[0], value[0], param->nSubValues, 0) == ERROR)
10403                                 return (ERROR);
10404                             }
10405                         else if (param->paramType == P_SHAPE && !strncmp(param->name, "Sigma", 5))
10406                             {
10407                             if( DiscreteLogNormal(subValue, value[0], param->nSubValues, 1) == ERROR)
10408                                 return (ERROR);
10409                             }
10410                         else if (param->paramType == P_CORREL)
10411                             {
10412                             if (AutodGamma (subValue, value[0], (int)(sqrt(param->nSubValues) + 0.5)) == ERROR)
10413                                 return (ERROR);
10414                             }
10415                         }
10416                     }
10417                 }
10418             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10419             }
10420         }
10421     else if (expecting == Expecting(EQUALSIGN))
10422         {
10423         foundEqual = YES;
10424         foundName = YES;
10425
10426         /* we now know that the name is complete; try to find the parameter with this name (case insensitive) */
10427         for (i=0; i<(int)strlen(tempName); i++)
10428             tempName[i] = tolower(tempName[i]);
10429         
10430         /* first check exact matches */
10431         nMatches = j = 0;
10432         for (i=0; i<numParams; i++)
10433             {
10434             param = &params[i];
10435             SafeStrcpy (&temp, param->name);
10436             for (k=0; k<(int)(strlen(temp)); k++)
10437                 temp[k] = tolower(temp[k]);
10438             if (strcmp(tempName,temp) == 0)
10439                 {
10440                 j = i;
10441                 nMatches++;
10442                 }
10443             }
10444         /* now check unambiguous abbreviation matches */
10445         if (nMatches == 0)
10446             {
10447             nMatches = j = 0;
10448             for (i=0; i<numParams; i++)
10449                 {
10450                 param = &params[i];
10451                 SafeStrcpy (&temp, param->name);
10452                 for (k=0; k<(int)strlen(temp); k++)
10453                     temp[k] = tolower(temp[k]);
10454                 if (strncmp(tempName,temp,strlen(tempName)) == 0)
10455                     {
10456                     j = i;
10457                     nMatches++;
10458                     }
10459                 }
10460             }
10461
10462         if (nMatches == 0)
10463             {
10464             extern char *tokenP;
10465             MrBayesPrint ("%s   Could not find parameter '%s': ignoring values\n", spacer, tempName);
10466             while (*tokenP && *tokenP++!=')') {}; 
10467             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10468             return (*tokenP ? NO_ERROR:ERROR);
10469             }
10470         else if (nMatches > 1)
10471             {
10472             MrBayesPrint ("%s   Several parameters matched the abbreviated name '%s'\n", spacer, tempName);
10473             return (ERROR);
10474             }
10475             
10476         param = &params[j];
10477         if (param->printParam == NO && !(param->paramType == P_TOPOLOGY && strcmp(modelParams[param->relParts[0]].topologyPr,"Fixed")!=0)
10478                                     && !(param->paramType == P_CPPEVENTS)
10479                                     && !(param->paramType == P_TK02BRANCHRATES)
10480                                     && !(param->paramType == P_IGRBRANCHRATES)
10481                                     && !(param->paramType == P_MIXEDBRCHRATES)
10482                                     && !(param->paramType == P_POPSIZE && param->nValues > 1))
10483             {
10484             MrBayesPrint ("%s   The parameter '%s' is fixed so the starting value cannot be set\n", spacer, param->name);
10485             return (ERROR);
10486             }
10487         if (param->paramType == P_BRLENS || param->paramType == P_TOPOLOGY || param->paramType == P_CPPEVENTS ||
10488             param->paramType == P_TK02BRANCHRATES || param->paramType == P_IGRBRANCHRATES || param->paramType == P_MIXEDBRCHRATES ||
10489             param->paramType == P_SPECIESTREE || (param->paramType == P_POPSIZE && param->nValues > 1))
10490             {
10491             /* all these parameters are set from a tree */
10492             expecting = Expecting (ALPHA);
10493             }
10494         else
10495             /* run of the mill character */
10496             {
10497             theValueMin = param->min;
10498             theValueMax = param->max;
10499             if ((param->paramType == P_PI && modelParams[param->relParts[0]].dataType != STANDARD))
10500                 {
10501                 useSubvalues = YES;
10502                 useIntValues = NO;
10503                 numExpectedValues = param->nSubValues;
10504                 }
10505             else if (param->nValues == 0 && param->nIntValues > 0)
10506                 {
10507                 useSubvalues = NO;
10508                 useIntValues = YES;
10509                 numExpectedValues = param->nIntValues;
10510                 }
10511             else if (param->nValues > 0)
10512                 {
10513                 useSubvalues = NO;
10514                 useIntValues = NO;
10515                 numExpectedValues = param->nValues;
10516                 }
10517             else
10518                 {
10519                 MrBayesPrint ("%s   Not expecting any values for parameter '%s'\n", spacer, param->name);
10520                 return (ERROR);
10521                 }
10522             nValuesRead = 0;
10523             expecting = Expecting(LEFTPAR);
10524             }
10525         }
10526     else
10527         return (ERROR);
10528
10529     SafeFree ((void **)&temp);
10530     return (NO_ERROR);
10531 }
10532
10533
10534 int DoUnlink (void)
10535 {
10536     int         i, j;
10537     
10538     MrBayesPrint ("%s   Unlinking\n", spacer);
10539     
10540     /* update status of linkTable */
10541     for (j=0; j<NUM_LINKED; j++)
10542         {
10543         for (i=0; i<numCurrentDivisions; i++)
10544             {
10545             if (tempLinkUnlink[j][i] == YES)
10546                 {
10547                 linkTable[j][i] = ++linkNum;
10548                 }
10549             }
10550         }
10551     
10552 #   if 0
10553     for (j=0; j<NUM_LINKED; j++)
10554         {
10555         MrBayesPrint ("%s   ", spacer);
10556         for (i=0; i<numCurrentDivisions; i++)
10557             MrBayesPrint ("%d", linkTable[j][i]);
10558         MrBayesPrint ("\n");
10559         }
10560 #   endif
10561
10562     /* reinitialize the temporary table */
10563     for (j=0; j<NUM_LINKED; j++)
10564         for (i=0; i<numCurrentDivisions; i++)
10565             tempLinkUnlink[j][i] = NO;
10566
10567     /* set up parameters and moves */
10568     if (SetUpAnalysis (&globalSeed) == ERROR)
10569         return (ERROR);
10570
10571     return (NO_ERROR);
10572 }
10573
10574
10575 int DoShowMcmcTrees (void)
10576 {
10577     int         run, chain, chainIndex, i;
10578     Tree        *t;
10579
10580     for (run=0; run<chainParams.numRuns; run++)
10581         {
10582         for (chain=0; chain<chainParams.numChains; chain++)
10583             {
10584             chainIndex = run*chainParams.numChains + chain;
10585             for (i=0; i<numTrees; i++)
10586                 {
10587                 t = GetTreeFromIndex (i, chainIndex, 0);
10588                 if (t->isRooted == YES)
10589                     MrBayesPrint ("\n   Tree '%s' [rooted]:\n\n", t->name);
10590                 else
10591                     MrBayesPrint ("\n   Tree '%s' [unrooted]:\n\n", t->name);
10592                 if (ShowTree (t) == ERROR)
10593                     return (ERROR);
10594                 else
10595                     MrBayesPrint ("\n");
10596                 }
10597             }
10598         }
10599
10600     return (NO_ERROR);
10601 }
10602
10603
10604 int DoShowModel (void)
10605 {
10606     if (defMatrix == NO)
10607         {
10608         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
10609         return (ERROR);
10610         }
10611
10612     if (ShowModel() == ERROR)
10613         return (ERROR);
10614
10615     return (NO_ERROR);
10616 }
10617
10618
10619 int DoShowMoves (void)
10620 {
10621     if (defMatrix == NO)
10622         {
10623         MrBayesPrint ("%s   A matrix must be specified before moves can be assigned\n", spacer);
10624         return (ERROR);
10625         }
10626
10627     MrBayesPrint ("%s   Moves that will be used by MCMC sampler (rel. proposal prob. > 0.0):\n\n", spacer);
10628     if (ShowMoves(YES) == ERROR)
10629         return (ERROR);
10630
10631     if (showmovesParams.allavailable == YES)
10632         {
10633         MrBayesPrint ("%s   Other available moves (rel. proposal prob. = 0.0):\n\n", spacer);
10634         if (ShowMoves(NO) == ERROR)
10635             return (ERROR);
10636         }
10637     else
10638         MrBayesPrint ("%s   Use 'Showmoves allavailable=yes' to see a list of all available moves\n", spacer);
10639
10640     return (NO_ERROR);
10641 }
10642
10643
10644 int DoShowmovesParm (char *parmName, char *tkn)
10645 {
10646     char    tempStr[100];
10647     
10648     if (expecting == Expecting(PARAMETER))
10649         {
10650         expecting = Expecting(EQUALSIGN);
10651         }
10652     else
10653         {
10654         /* set Allavailable **********************************************************/
10655         if (!strcmp(parmName, "Allavailable"))
10656             {
10657             if (expecting == Expecting(EQUALSIGN))
10658                 expecting = Expecting(ALPHA);
10659             else if (expecting == Expecting(ALPHA))
10660                 {
10661                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
10662                     {
10663                     if (!strcmp(tempStr, "Yes"))
10664                         showmovesParams.allavailable = YES;
10665                     else
10666                         showmovesParams.allavailable = NO;
10667                     }
10668                 else
10669                     {
10670                     MrBayesPrint ("%s   Invalid argument for allavailable\n", spacer);
10671                     return (ERROR);
10672                     }
10673                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10674                 }
10675             else
10676                 return (ERROR);
10677             }
10678         else
10679             return (ERROR);
10680
10681         }
10682         
10683     return (NO_ERROR);
10684 }
10685
10686
10687 int DoShowParams (void)
10688 {
10689     if (defMatrix == NO)
10690         {
10691         MrBayesPrint ("%s   A matrix must be specified before model parameters can be shown\n", spacer);
10692         return (ERROR);
10693         }
10694
10695     if (ShowParameters(YES, YES, YES) == ERROR)
10696         return (ERROR);
10697
10698     return (NO_ERROR);
10699 }
10700
10701
10702 /*------------------------------------------------------------------------
10703 |
10704 |   FillNormalParams: Allocate and fill in non-tree parameters
10705 |
10706 -------------------------------------------------------------------------*/
10707 int FillNormalParams (RandLong *seed, int fromChain, int toChain)
10708 {
10709     int         i, j, k, chn, tempInt, *intValue;
10710     MrBFlt      *bs, *value, *subValue, scaler;
10711     Tree        *tree;
10712     Param       *p;
10713     ModelInfo   *m;
10714     ModelParams *mp;
10715
10716     /* fill in values for nontree params for state 0 of chains */
10717     for (chn=fromChain; chn<toChain; chn++)
10718         {
10719         for (k=0; k<numParams; k++)
10720             {
10721             p  = &params[k];
10722             mp = &modelParams[p->relParts[0]];
10723             m  = &modelSettings[p->relParts[0]];
10724
10725             /* find model settings and nStates, pInvar, invar cond likes */
10726
10727             value = GetParamVals (p, chn, 0);
10728             subValue = GetParamSubVals (p, chn, 0);
10729             intValue = GetParamIntVals (p, chn, 0);
10730
10731             if (p->paramType == P_TRATIO)
10732                 {
10733                 /* Fill in tratios **************************************************************************************/
10734                 if (p->paramId == TRATIO_DIR)
10735                     value[0] = 1.0;
10736                 else if (p->paramId == TRATIO_FIX)
10737                     value[0] = mp->tRatioFix;
10738                 }
10739             else if (p->paramType == P_REVMAT)
10740                 {
10741                 /* Fill in revMat ***************************************************************************************/
10742                 /* rates are stored in order, AC or AR first, using the Dirichlet parameterization */
10743                 if (p->paramId == REVMAT_DIR)
10744                     {
10745                     for (j=0; j<p->nValues; j++)
10746                         value[j] = 1.0 / (MrBFlt) (p->nValues);
10747                     }
10748                 else if (p->paramId == REVMAT_FIX)
10749                     {
10750                     scaler = 0.0;
10751                     if (m->dataType == PROTEIN)
10752                         {
10753                         for (j=0; j<190; j++)
10754                             scaler += (value[j] = mp->aaRevMatFix[j]);
10755                         for (j=0; j<190; j++)
10756                             value[j] /= scaler;
10757                         }
10758                     else
10759                         {
10760                         for (j=0; j<6; j++)
10761                             scaler += (value[j] = mp->revMatFix[j]);
10762                         for (j=0; j<6; j++)
10763                             value[j] /= scaler;
10764                         }
10765                     }
10766                 else if (p->paramId == REVMAT_MIX)
10767                     {
10768                     for (j=0; j<6; j++)
10769                         {
10770                         value[j] = 1.0 / 6.0;
10771                         intValue[j] = 0;
10772                         }
10773                     }
10774                 }
10775             else if (p->paramType == P_OMEGA)
10776                 {
10777                 /* Fill in omega ****************************************************************************************/
10778                 if (p->nValues == 1)
10779                     {
10780                     if (p->paramId == OMEGA_DIR)
10781                         value[0] = 1.0;
10782                     else if (p->paramId == OMEGA_FIX)
10783                         value[0] = mp->omegaFix;
10784                     }
10785                 else
10786                     {
10787                     if (!strcmp(mp->omegaVar, "Ny98"))
10788                         {
10789                         if (p->paramId == OMEGA_BUD || p->paramId == OMEGA_BUF || p->paramId == OMEGA_BED ||
10790                             p->paramId == OMEGA_BEF || p->paramId == OMEGA_BFD || p->paramId == OMEGA_BFF)
10791                             value[0] = RandomNumber(seed);
10792                         else if (p->paramId == OMEGA_FUD || p->paramId == OMEGA_FUF || p->paramId == OMEGA_FED ||
10793                                  p->paramId == OMEGA_FEF || p->paramId == OMEGA_FFD || p->paramId == OMEGA_FFF)
10794                             value[0] = mp->ny98omega1Fixed;
10795                         value[1] = 1.0;
10796                         if (p->paramId == OMEGA_BUD || p->paramId == OMEGA_BUF || p->paramId == OMEGA_FUD ||
10797                             p->paramId == OMEGA_FUF)
10798                             value[2] = mp->ny98omega3Uni[0] + RandomNumber(seed) * (mp->ny98omega3Uni[1] - mp->ny98omega3Uni[0]);
10799                         else if (p->paramId == OMEGA_BED || p->paramId == OMEGA_BEF || p->paramId == OMEGA_FED ||
10800                                  p->paramId == OMEGA_FEF)
10801                             value[2] =  (1.0 - (1.0/mp->ny98omega3Exp) * log(RandomNumber(seed)));
10802                         else
10803                             value[2] = mp->ny98omega3Fixed;
10804                         if (p->paramId == OMEGA_BUD || p->paramId == OMEGA_BED || p->paramId == OMEGA_BFD || 
10805                             p->paramId == OMEGA_FUD || p->paramId == OMEGA_FED || p->paramId == OMEGA_FFD) 
10806                             {
10807                             subValue[3] = mp->codonCatDir[0];
10808                             subValue[4] = mp->codonCatDir[1];
10809                             subValue[5] = mp->codonCatDir[2];
10810                             DirichletRandomVariable (&subValue[3], &subValue[0], 3, seed);
10811                             }
10812                         else
10813                             {
10814                             subValue[0] = mp->codonCatFreqFix[0];
10815                             subValue[1] = mp->codonCatFreqFix[1];
10816                             subValue[2] = mp->codonCatFreqFix[2];
10817                             subValue[3] = 0.0;
10818                             subValue[4] = 0.0;
10819                             subValue[5] = 0.0;
10820                             }
10821                         }
10822                     else if (!strcmp(mp->omegaVar, "M3"))
10823                         {
10824                         if (p->paramId == OMEGA_FD || p->paramId == OMEGA_FF)
10825                             {
10826                             value[0] = mp->m3omegaFixed[0];
10827                             value[1] = mp->m3omegaFixed[1];
10828                             value[2] = mp->m3omegaFixed[2];
10829                             }
10830                         else
10831                             {
10832                             value[0] =  0.1;
10833                             value[1] =  1.0;
10834                             value[2] =  3.0;
10835                             }
10836                         if (p->paramId == OMEGA_ED || p->paramId == OMEGA_FD) 
10837                             {
10838                             subValue[3] = mp->codonCatDir[0];
10839                             subValue[4] = mp->codonCatDir[1];
10840                             subValue[5] = mp->codonCatDir[2];
10841                             DirichletRandomVariable (&subValue[3], &subValue[0], 3, seed);
10842                             }
10843                         else
10844                             {
10845                             subValue[0] = mp->codonCatFreqFix[0];
10846                             subValue[1] = mp->codonCatFreqFix[1];
10847                             subValue[2] = mp->codonCatFreqFix[2];
10848                             subValue[3] = 0.0;
10849                             subValue[4] = 0.0;
10850                             subValue[5] = 0.0;
10851                             }
10852                         }
10853                     else if (!strcmp(mp->omegaVar, "M10"))
10854                         {
10855                         if (p->paramId == OMEGA_10UUB || p->paramId == OMEGA_10UEB || p->paramId == OMEGA_10UFB ||
10856                             p->paramId == OMEGA_10EUB || p->paramId == OMEGA_10EEB || p->paramId == OMEGA_10EFB ||
10857                             p->paramId == OMEGA_10FUB || p->paramId == OMEGA_10FEB || p->paramId == OMEGA_10FFB) 
10858                             {
10859                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 2] = mp->codonCatDir[0];
10860                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 3] = mp->codonCatDir[1];
10861                             DirichletRandomVariable (&subValue[mp->numM10BetaCats + mp->numM10GammaCats + 2], &subValue[mp->numM10BetaCats + mp->numM10GammaCats + 0], 2, seed);
10862                             }
10863                         else
10864                             {
10865                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 0] = mp->codonCatFreqFix[0];
10866                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 1] = mp->codonCatFreqFix[1];
10867                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 2] = 0.0;
10868                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 3] = 0.0;
10869                             }
10870                             
10871                         for (i=0; i<mp->numM10BetaCats; i++)
10872                             subValue[i] = subValue[mp->numM10BetaCats + mp->numM10GammaCats + 0] / mp->numM10BetaCats;
10873                         for (i=mp->numM10BetaCats; i<mp->numM10BetaCats+mp->numM10GammaCats; i++)
10874                             subValue[i] = subValue[mp->numM10BetaCats + mp->numM10GammaCats + 1] / mp->numM10GammaCats;
10875
10876                         if (p->paramId == OMEGA_10FUB || p->paramId == OMEGA_10FUF || p->paramId == OMEGA_10FEB ||
10877                             p->paramId == OMEGA_10FEF || p->paramId == OMEGA_10FFB || p->paramId == OMEGA_10FFF)
10878                             {
10879                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 4] = mp->m10betaFix[0];
10880                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 5] = mp->m10betaFix[1];
10881                             }
10882                         else
10883                             {
10884                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 4] = 1.0;
10885                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 5] = 1.0;
10886                             }
10887
10888                         if (p->paramId == OMEGA_10UFB || p->paramId == OMEGA_10UFF || p->paramId == OMEGA_10EFB ||
10889                             p->paramId == OMEGA_10EFF || p->paramId == OMEGA_10FFB || p->paramId == OMEGA_10FFF)
10890                             {
10891                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 6] = mp->m10gammaFix[0];
10892                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 7] = mp->m10gammaFix[1];
10893                             }
10894                         else
10895                             {
10896                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 6] = 1.0;
10897                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 7] = 1.0;
10898                             }
10899                             
10900                         BetaBreaks (subValue[mp->numM10BetaCats + mp->numM10GammaCats + 4], subValue[mp->numM10BetaCats + mp->numM10GammaCats + 5], &value[0], mp->numM10BetaCats);
10901                         if (DiscreteGamma (&value[mp->numM10BetaCats], subValue[mp->numM10BetaCats + mp->numM10GammaCats + 6],
10902                                            subValue[mp->numM10BetaCats + mp->numM10GammaCats + 7], mp->numM10GammaCats, 0) == ERROR)
10903                             return (ERROR);
10904                         for (i=0; i<mp->numM10GammaCats; i++)
10905                             value[mp->numM10BetaCats + i] += 1.0;
10906                         }
10907                     }
10908                 }
10909             else if (p->paramType == P_PI)
10910                 {
10911                 /* Fill in state frequencies ****************************************************************************/
10912                 /* note that standard chars are mainly dealt with in ProcessStdChars in mcmc.c */
10913                 if (p->paramId == SYMPI_UNI || p->paramId == SYMPI_UNI_MS)
10914                     value[0] = 1.0;
10915                 else if (p->paramId == SYMPI_EXP || p->paramId == SYMPI_EXP_MS)
10916                     value[0] = 1.0;
10917
10918                 else if (p->paramId == SYMPI_FIX || p->paramId == SYMPI_FIX_MS)
10919                     value[0] = mp->symBetaFix;
10920
10921                 else if (p->paramId == PI_DIR)
10922                     {
10923                     if (mp->numDirParams != mp->nStates && mp->numDirParams != 0)
10924                         {
10925                         MrBayesPrint ("%s   Mismatch between number of dirichlet parameters (%d) and the number of states (%d)\n", spacer, mp->numDirParams, m->numStates);
10926                         return ERROR;
10927                         }
10928
10929                     /* if user has not set dirichlet parameters, go with default */
10930                     /* overall variance equals number of states */
10931                     if (mp->numDirParams == 0)
10932                         for (i=0; i<mp->nStates; i++)
10933                             value[i] = mp->stateFreqsDir[i] = 1.0;
10934                     else
10935                         for (i=0; i<m->numStates; i++)
10936                             value[i] = mp->stateFreqsDir[i];
10937
10938                     /* now fill in subvalues */
10939                     for (i=0; i<m->numStates; i++)
10940                         subValue[i] = 1.0 / mp->nStates;
10941                     }
10942
10943                 else if (p->paramId == PI_USER)
10944                     {
10945                     for (i=0; i<m->numStates; i++)
10946                         subValue[i] =  mp->stateFreqsFix[i];
10947                     }
10948                     
10949                 else if (p->paramId == PI_FIXED)
10950                     {
10951                     if (!strcmp(mp->aaModelPr, "Fixed"))
10952                         {
10953                         if (!strcmp(mp->aaModel, "Jones"))
10954                             {
10955                             for (i=0; i<mp->nStates; i++)
10956                                 subValue[i] = jonesPi[i];
10957                             }
10958                         else if (!strcmp(mp->aaModel, "Dayhoff"))
10959                             {
10960                             for (i=0; i<mp->nStates; i++)
10961                                 subValue[i] = dayhoffPi[i];
10962                             }
10963                         else if (!strcmp(mp->aaModel, "Mtrev"))
10964                             {
10965                             for (i=0; i<mp->nStates; i++)
10966                                 subValue[i] = mtrev24Pi[i];
10967                             }
10968                         else if (!strcmp(mp->aaModel, "Mtmam"))
10969                             {
10970                             for (i=0; i<mp->nStates; i++)
10971                                 subValue[i] = mtmamPi[i];
10972                             }
10973                         else if (!strcmp(mp->aaModel, "Wag"))
10974                             {
10975                             for (i=0; i<mp->nStates; i++)
10976                                 subValue[i] = wagPi[i];
10977                             }
10978                         else if (!strcmp(mp->aaModel, "Rtrev"))
10979                             {
10980                             for (i=0; i<mp->nStates; i++)
10981                                 subValue[i] = rtrevPi[i];
10982                             }
10983                         else if (!strcmp(mp->aaModel, "Cprev"))
10984                             {
10985                             for (i=0; i<mp->nStates; i++)
10986                                 subValue[i] = cprevPi[i];
10987                             }
10988                         else if (!strcmp(mp->aaModel, "Vt"))
10989                             {
10990                             for (i=0; i<mp->nStates; i++)
10991                                 subValue[i] = vtPi[i];
10992                             }
10993                         else if (!strcmp(mp->aaModel, "Blosum"))
10994                             {
10995                             for (i=0; i<mp->nStates; i++)
10996                                 subValue[i] = blosPi[i];
10997                             }
10998                         else if (!strcmp(mp->aaModel, "LG"))
10999                             {
11000                             for (i=0; i<mp->nStates; i++)
11001                                 subValue[i] = lgPi[i];
11002                             }
11003                         }
11004                     }
11005
11006                 else if (p->paramId == PI_EMPIRICAL)
11007                     {
11008                     if (GetEmpiricalFreqs (p->relParts, p->nRelParts) == ERROR)
11009                         return (ERROR);
11010                     for (i=0; i<mp->nStates; i++)
11011                         subValue[i] = empiricalFreqs[i];
11012                     }
11013
11014                 else if (p->paramId == PI_EQUAL)
11015                     {
11016                     for (i=0; i<mp->nStates; i++)
11017                         subValue[i] = 1.0 / mp->nStates;
11018                     }
11019                 }
11020             else if (p->paramType == P_SHAPE)
11021                 {
11022                 /* Fill in shape values ********************************************************************************/
11023                 /* first get hyperprior */
11024                 if (p->paramId == SHAPE_UNI)
11025                     {
11026                     value[0] = 1.0;
11027                     if (value[0] < mp->shapeUni[0] || value[0] > mp->shapeUni[1])
11028                         value[0] = mp->shapeUni[0] + (mp->shapeUni[1] - mp->shapeUni[0]) *  0.5;
11029                     }
11030                 else if (p->paramId == SHAPE_EXP)
11031                     value[0] = 1.0;  // was 100.0
11032                 else if (p->paramId == SHAPE_FIX)
11033                     value[0] = mp->shapeFix;
11034                 /* now fill in rates */
11035                 if (!strcmp(mp->ratesModel, "LNorm"))
11036                     {
11037                     if (DiscreteLogNormal (subValue, value[0], mp->numGammaCats, 1) == ERROR)
11038                         return (ERROR);
11039                     }
11040                 else  /* gamma rate */
11041                     {
11042                     if (DiscreteGamma (subValue, value[0], value[0], mp->numGammaCats, 0) == ERROR)
11043                         return (ERROR);
11044                     }
11045                 }
11046             else if (p->paramType == P_PINVAR)
11047                 {
11048                 /* Fill in pInvar ***************************************************************************************/
11049                 if (p->paramId == PINVAR_UNI)
11050                     value[0] = 0.0;
11051
11052                 else if (p->paramId == PINVAR_FIX)
11053                     value[0] =  mp->pInvarFix;
11054                 }
11055             else if (p->paramType == P_CORREL)
11056                 {
11057                 /* Fill in correlation parameter of adgamma model *******************************************************/
11058                 if (p->paramId == CORREL_UNI)
11059                     value[0] = 0.0;
11060
11061                 else if (p->paramId == CORREL_FIX)
11062                     value[0] =  mp->corrFix;
11063                 
11064                 /* Fill in correlation matrices */
11065                 AutodGamma (subValue, value[0], mp->numGammaCats);
11066                 }
11067             else if (p->paramType == P_SWITCH)
11068                 {
11069                 /* Fill in switchRates for covarion model ***************************************************************/
11070                 for (j=0; j<2; j++)
11071                     {
11072                     if (p->paramId == SWITCH_UNI)
11073                         value[j] = RandomNumber(seed) * (mp->covswitchUni[1] - mp->covswitchUni[0]) + mp->covswitchUni[0];
11074
11075                     else if (p->paramId == SWITCH_EXP)
11076                         value[j] = -(1.0/mp->covswitchExp) * log(RandomNumber(seed));
11077
11078                     else if (p->paramId == SWITCH_FIX)
11079                         value[j] = mp->covswitchFix[j];
11080                     }
11081                 }
11082             else if (p->paramType == P_RATEMULT)
11083                 {
11084                 /* Fill in division rates *****************************************************************************/
11085                 for (j=0; j<p->nValues; j++)
11086                     {
11087                     value[j] = 1.0;
11088                     /* fill in more info about the divisions if this is a true rate multiplier
11089                        and not a base rate */
11090                     if (p->nSubValues > 0)
11091                         {
11092                         /* num uncompressed chars */
11093                         subValue[j] = (modelSettings[p->relParts[j]].numUncompressedChars);
11094                         /* Dirichlet parameters */
11095                         subValue[p->nValues + j] = modelParams[p->relParts[j]].ratePrDir;
11096                         }
11097                     }
11098                 }
11099             else if (p->paramType == P_GENETREERATE)
11100                 {
11101                 /* Fill in division rates *****************************************************************************/
11102                 for (j=0; j<p->nValues; j++)
11103                     {
11104                     value[j] = 1.0;
11105                     /* Dirichlet parameters fixed to 1.0 for now; ignored if the rate is fixed */
11106                     subValue[p->nValues + j] = 1.0;
11107                     /* Get number of uncompressed chars from tree */
11108                     tree = GetTreeFromIndex(j, 0, 0);
11109                     subValue[j] = 0.0;
11110                     for (i=0; i<tree->nRelParts; i++)  /* num uncompressed chars */
11111                         subValue[j] += modelSettings[tree->relParts[i]].numUncompressedChars;
11112                     }
11113                 }
11114             else if (p->paramType == P_SPECRATE)
11115                 {
11116                 /* Fill in speciation rates *****************************************************************************/
11117                 for (j=0; j<p->nValues; j++)
11118                     {
11119                     if (p->paramId == SPECRATE_FIX)
11120                         value[j] = mp->speciationFix;
11121                     else
11122                         value[j] = 0.1;
11123                     }
11124                 }
11125             else if (p->paramType == P_EXTRATE)
11126                 {
11127                 /* Fill in extinction rates *****************************************************************************/
11128                 for (j=0; j<p->nValues; j++)
11129                     {
11130                     if (p->paramId == EXTRATE_FIX)
11131                         value[j] = mp->extinctionFix;
11132                     else
11133                         value[j] = 0.8;
11134                     }
11135                 }
11136             else if (p->paramType == P_FOSLRATE)
11137                 {
11138                 /* Fill in fossilization rates */
11139                 for (j=0; j<p->nValues; j++)
11140                     {
11141                     if (p->paramId == FOSLRATE_FIX)
11142                         value[j] = mp->fossilizationFix;
11143                     else
11144                         value[j] = 0.2;
11145                     }
11146                 }
11147             else if (p->paramType == P_GROWTH)
11148                 {
11149                 /* Fill in growth rate ****************************************************************************************/
11150                 if (p->paramId == GROWTH_FIX)
11151                     value[0] = mp->growthFix;
11152                 else
11153                     value[0] = 1.0;
11154                 }
11155             else if (p->paramType == P_POPSIZE)
11156                 {
11157                 /* Fill in population size ****************************************************************************************/
11158                 for (j=0; j<p->nValues; j++)
11159                     {
11160                     if (p->paramId == POPSIZE_UNI)
11161                         value[j] = RandomNumber(seed) * (mp->popSizeUni[1] - mp->popSizeUni[0]) + mp->popSizeUni[0];
11162                     else if (p->paramId == POPSIZE_LOGNORMAL)
11163                         value[j] = exp(mp->popSizeLognormal[0]);
11164                     else if (p->paramId == POPSIZE_NORMAL)
11165                         value[j] = mp->popSizeNormal[0];
11166                     else if (p->paramId == POPSIZE_GAMMA)
11167                         value[j] = mp->popSizeGamma[0] / mp->popSizeGamma[1];
11168                     else if (p->paramId == POPSIZE_FIX)
11169                         value[j] = mp->popSizeFix;
11170                     }
11171                 }
11172             else if (p->paramType == P_AAMODEL)
11173                 {
11174                 /* Fill in theta ****************************************************************************************/
11175                 if (p->paramId == AAMODEL_MIX)
11176                     {
11177                     /* amino acid model ID's
11178                         AAMODEL_POISSON         0
11179                         AAMODEL_JONES           1
11180                         AAMODEL_DAY             2
11181                         AAMODEL_MTREV           3
11182                         AAMODEL_MTMAM           4
11183                         AAMODEL_WAG             5
11184                         AAMODEL_RTREV           6 
11185                         AAMODEL_CPREV           7 
11186                         AAMODEL_VT              8
11187                         AAMODEL_BLOSUM          9 */
11188
11189                     /* set the amino acid model  (the meaning of the numbers is defined) */
11190                     tempInt = (int)(RandomNumber(seed) * 10);
11191                     value[0] = tempInt;
11192                     
11193                     /* we need to make certain that the aa frequencies are filled in correctly */
11194                     bs = GetParamSubVals (m->stateFreq, chn, 0);
11195                     if (tempInt == AAMODEL_POISSON)
11196                         {
11197                         for (i=0; i<mp->nStates; i++)
11198                             bs[i] =  (1.0 / 20.0);
11199                         }
11200                     else if (tempInt == AAMODEL_JONES)
11201                         {
11202                         for (i=0; i<mp->nStates; i++)
11203                             bs[i] = jonesPi[i];
11204                         }
11205                     else if (tempInt == AAMODEL_DAY)
11206                         {
11207                         for (i=0; i<mp->nStates; i++)
11208                             bs[i] = dayhoffPi[i];
11209                         }
11210                     else if (tempInt == AAMODEL_MTREV)
11211                         {
11212                         for (i=0; i<mp->nStates; i++)
11213                             bs[i] = mtrev24Pi[i];
11214                         }
11215                     else if (tempInt == AAMODEL_MTMAM)
11216                         {
11217                         for (i=0; i<mp->nStates; i++)
11218                             bs[i] = mtmamPi[i];
11219                         }
11220                     else if (tempInt == AAMODEL_WAG)
11221                         {
11222                         for (i=0; i<mp->nStates; i++)
11223                             bs[i] = wagPi[i];
11224                         }
11225                     else if (tempInt == AAMODEL_RTREV)
11226                         {
11227                         for (i=0; i<mp->nStates; i++)
11228                             bs[i] = rtrevPi[i];
11229                         }
11230                     else if (tempInt == AAMODEL_CPREV)
11231                         {
11232                         for (i=0; i<mp->nStates; i++)
11233                             bs[i] = cprevPi[i];
11234                         }
11235                     else if (tempInt == AAMODEL_VT)
11236                         {
11237                         for (i=0; i<mp->nStates; i++)
11238                             bs[i] = vtPi[i];
11239                         }
11240                     else if (tempInt == AAMODEL_BLOSUM)
11241                         {
11242                         for (i=0; i<mp->nStates; i++)
11243                             bs[i] = blosPi[i];
11244                         }
11245                         
11246                     for (i=0; i<p->nSubValues; i++)
11247                         {
11248                         subValue[i] = mp->aaModelPrProbs[i];
11249                         }
11250                     }
11251                 }
11252             else if (p->paramType == P_CPPRATE)
11253                 {
11254                 /* Fill in lambda (cpp rate) ********************************************************************************************/
11255                 if (p->paramId == CPPRATE_EXP)
11256                     value[0] = -(1.0/mp->cppRateExp) * log(RandomNumber(seed));
11257                 else if (p->paramId == CPPRATE_FIX)
11258                     value[0] = mp->cppRateFix;
11259                 }
11260             else if (p->paramType == P_CPPMULTDEV)
11261                 {
11262                 /* Fill in log standard deviation (for relaxed clock rate multiplier) ***********************************************************/
11263                 if (p->paramId == CPPMULTDEV_FIX)
11264                     value[0] = mp->cppMultDevFix;
11265                 }
11266             else if (p->paramType == P_CPPEVENTS)
11267                 {
11268                 /* We fill in these when we fill in tree params **************************************************************************/
11269                 }
11270             else if (p->paramType == P_TK02VAR)
11271                 {
11272                 /* Fill in variance of relaxed clock lognormal **************************************************************************/
11273                 if (p->paramId == TK02VAR_UNI)
11274                     value[0] = RandomNumber(seed) * (mp->tk02varUni[1] - mp->tk02varUni[0]) + mp->tk02varUni[0];
11275                 else if (p->paramId == TK02VAR_EXP)
11276                     value[0] = 2.0/(mp->tk02varExp);
11277                 else if (p->paramId == TK02VAR_FIX)
11278                     value[0] = mp->tk02varFix;
11279                 }
11280             else if (p->paramType == P_TK02BRANCHRATES)
11281                 {
11282                 /* We fill in these when we fill in tree params **************************************************************************/
11283                 }
11284             else if (p->paramType == P_IGRVAR)
11285                 {
11286                 /* Fill in variance of relaxed clock lognormal **************************************************************************/
11287                 if (p->paramId == IGRVAR_UNI)
11288                     value[0] = RandomNumber(seed) * (mp->igrvarUni[1] - mp->igrvarUni[0]) + mp->igrvarUni[0];
11289                 else if (p->paramId == IGRVAR_EXP)
11290                     value[0] = 1.0/(mp->igrvarExp);
11291                 else if (p->paramId == IGRVAR_FIX)
11292                     value[0] = mp->igrvarFix;
11293                 }
11294             else if (p->paramType == P_IGRBRANCHRATES)
11295                 {
11296                 /* We fill in these when we fill in tree params **************************************************************************/
11297                 }
11298             else if (p->paramType == P_MIXEDVAR)
11299                 {
11300                 /* Fill in variance of mixed relaxed clock **************************************************************************/
11301                 if (p->paramId == MIXEDVAR_UNI)
11302                     value[0] = RandomNumber(seed) * (mp->mixedvarUni[1] - mp->mixedvarUni[0]) + mp->mixedvarUni[0];
11303                 else if (p->paramId == MIXEDVAR_EXP)
11304                     value[0] = 1.0/(mp->mixedvarExp);
11305                 else if (p->paramId == MIXEDVAR_FIX)
11306                     value[0] = mp->mixedvarFix;
11307                 }
11308             else if (p->paramType == P_MIXEDBRCHRATES)
11309                 {
11310                 /* initialize the mixed relaxed clock model to TK02 or IGR */
11311                 intValue[0] = (RandomNumber(seed) <0.5) ? RCL_TK02 : RCL_IGR;
11312                 /* We fill in the rest when we fill in tree params **************************************************************************/
11313                 }
11314             else if (p->paramType == P_CLOCKRATE)
11315                 {
11316                 /* Fill in base rate of molecular clock **************************************************************************/
11317                 if (p->paramId == CLOCKRATE_FIX)
11318                     value[0] = mp->clockRateFix;
11319                 else if (p->paramId == CLOCKRATE_NORMAL)
11320                     value[0] = mp->clockRateNormal[0];
11321                 else if (p->paramId == CLOCKRATE_LOGNORMAL)
11322                     value[0] = exp(mp->clockRateLognormal[0]);
11323                 else if (p->paramId == CLOCKRATE_EXP)
11324                     value[0] = 1.0/(mp->clockRateExp);
11325                 else if (p->paramId == CLOCKRATE_GAMMA)
11326                     value[0] = mp->clockRateGamma[0]/mp->clockRateGamma[1];
11327                 }
11328             }   /* next param */
11329         }   /* next chain */
11330
11331     return NO_ERROR;
11332 }
11333
11334     
11335 int FillRelPartsString (Param *p, char **relPartString)
11336 {
11337     int         i, n, filledString;
11338     char        *tempStr;
11339     int             tempStrSize=50;
11340
11341     tempStr = (char *) SafeMalloc((size_t)tempStrSize * sizeof(char));
11342     if (!tempStr)
11343         {
11344         MrBayesPrint ("%s   Problem allocating tempString (%d)\n", spacer, tempStrSize * sizeof(char));
11345         return (ERROR);
11346         }
11347
11348     if (numCurrentDivisions == 1)
11349         {
11350         filledString = NO;
11351         SafeStrcpy (relPartString, "");
11352         }
11353     else
11354         {
11355         filledString = YES;
11356         if (p->nRelParts == numCurrentDivisions)
11357             {
11358             SafeStrcpy (relPartString, "{all}");
11359             }
11360         else
11361             {
11362             SafeStrcpy (relPartString, "{");
11363             for (i=n=0; i<p->nRelParts; i++)
11364                 {
11365                 n++;
11366                 SafeSprintf (&tempStr, &tempStrSize, "%d", p->relParts[i] + 1);
11367                 SafeStrcat (relPartString, tempStr);
11368                 if (n < p->nRelParts)
11369                     SafeStrcat (relPartString, ",");
11370                 }
11371             SafeStrcat (relPartString, "}");
11372             }
11373         }
11374     free (tempStr);
11375     return (filledString);
11376 }
11377
11378
11379 /*--------------------------------------------------------------
11380  |
11381  |  FillStdStateFreqs: fills stationary frequencies for standard data divisions of chains  in range [chfrom, chto)
11382  |
11383  ---------------------------------------------------------------*/
11384 void FillStdStateFreqs (int chfrom, int chto, RandLong *seed)
11385 {
11386     int     chn, n, i, j, k, b, c, nb, index;
11387     MrBFlt  *subValue, sum, symDir[10];
11388     Param   *p;
11389     
11390     for (chn=chfrom; chn<chto; chn++)
11391         {
11392         for (k=0; k<numParams; k++)
11393             {
11394             p = &params[k];
11395             if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
11396                 continue;
11397             subValue = GetParamStdStateFreqs (p, chn, 0);
11398             if (p->paramId == SYMPI_EQUAL)
11399                 {
11400                 for (n=index=0; n<9; n++)
11401                     {
11402                     for (i=0; i<p->nRelParts; i++)
11403                         if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
11404                             break;
11405                     if (i < p->nRelParts)
11406                         {
11407                         for (j=0; j<(n+2); j++)
11408                             {
11409                             subValue[index++] = (1.0 / (n + 2));
11410                             }
11411                         }
11412                     }
11413                 for (n=9; n<13; n++)
11414                     {
11415                     for (i=0; i<p->nRelParts; i++)
11416                         if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
11417                             break;
11418                     if (i < p->nRelParts)
11419                         {
11420                         for (j=0; j<(n-6); j++)
11421                             {
11422                             subValue[index++] = (1.0 / (n - 6));
11423                             }
11424                         }
11425                     }
11426                 }
11427             
11428             /* Deal with transition asymmetry for standard characters */
11429             /* First, fill in stationary frequencies for beta categories if needed; */
11430             /* discard category frequencies (assume equal) */
11431             if (p->paramId == SYMPI_FIX || p->paramId == SYMPI_UNI || p->paramId == SYMPI_EXP ||
11432                 p->paramId == SYMPI_FIX_MS || p->paramId == SYMPI_UNI_MS || p->paramId == SYMPI_EXP_MS)
11433                 {
11434                 if (p->hasBinaryStd == YES)
11435                     {
11436                     nb=modelParams[p->relParts[0]].numBetaCats;
11437                     BetaBreaks (p->values[0], p->values[0], subValue, nb);
11438                     b = 2*nb;
11439                     for (i=b-2; i>0; i-=2)
11440                         {
11441                         subValue[i] = subValue[i/2];
11442                         }
11443                     for (i=1; i<b; i+=2)
11444                         {
11445                         subValue[i] = (1.0 - subValue[i-1]);
11446                         }
11447                     subValue += (2 * nb);
11448                     }
11449                 
11450                 /* Then fill in state frequencies for multistate chars, one set for each */
11451                 for (i=0; i<10; i++)
11452                     symDir[i] = p->values[0];
11453                 
11454                 for (c=0; c<p->nSympi; c++)
11455                     {
11456                     /* now fill in subvalues */
11457                     DirichletRandomVariable (symDir, subValue, p->sympinStates[c], seed);
11458                     sum = 0.0;
11459                     for (i=0; i<p->sympinStates[c]; i++)
11460                         {
11461                         if (subValue[i] < 0.0001)
11462                             subValue[i] = 0.0001;
11463                         sum += subValue[i];
11464                         }
11465                     for (i=0; i<modelParams[p->relParts[0]].nStates; i++)
11466                         subValue[i] /= sum;
11467                     subValue += p->sympinStates[c];
11468                     }
11469                 }
11470             }   /* next parameter */
11471         }   /* next chain */
11472 }
11473
11474
11475 /* FillTopologySubParams: Fill subparams (brlens) for a topology */
11476 int FillTopologySubParams (Param *param, int chn, int state, RandLong *seed)
11477 {
11478     int         i,returnVal;
11479     Tree        *tree, *tree1;
11480     Param       *q;
11481     MrBFlt      clockRate;
11482     PolyTree    *sourceTree;
11483     MrBFlt      minRate,maxRate;
11484
11485     tree = GetTree (param, chn, state);
11486     
11487     for (i=1; i<param->nSubParams; i++)
11488         {
11489         q = param->subParams[i];
11490         tree1 = GetTree (q, chn, state);
11491         if (CopyToTreeFromTree(tree1, tree) == ERROR)
11492             return (ERROR);
11493         }
11494     for (i=0; i<param->nSubParams; i++)
11495         {
11496         q = param->subParams[i];
11497         tree = GetTree (q, chn, state);
11498         if (q->paramId == BRLENS_FIXED || q->paramId == BRLENS_CLOCK_FIXED)
11499             {
11500             if (param->paramId == TOPOLOGY_NCL_FIXED ||
11501                 param->paramId == TOPOLOGY_NCL_FIXED_HOMO ||
11502                 param->paramId == TOPOLOGY_NCL_FIXED_HETERO ||
11503                 param->paramId == TOPOLOGY_CL_FIXED  ||
11504                 param->paramId == TOPOLOGY_RCL_FIXED ||
11505                 param->paramId == TOPOLOGY_CCL_FIXED ||
11506                 param->paramId == TOPOLOGY_RCCL_FIXED||
11507                 param->paramId == TOPOLOGY_FIXED)
11508                 {
11509                 sourceTree = AllocatePolyTree(numTaxa);
11510                 CopyToPolyTreeFromPolyTree (sourceTree, userTree[modelParams[q->relParts[0]].brlensFix]);
11511                 PrunePolyTree (sourceTree);
11512                 ResetTipIndices (sourceTree);
11513                 ResetIntNodeIndices (sourceTree);
11514                 if (tree->isRooted != sourceTree->isRooted)
11515                     {
11516                     MrBayesPrint("%s   Cannot set fixed branch lengths because of mismatch in rootedness", spacer);
11517                     FreePolyTree (sourceTree);
11518                     return (ERROR);
11519                     }
11520                 if (CopyToTreeFromPolyTree(tree,sourceTree) == ERROR)
11521                     {
11522                     MrBayesPrint("%s   Problem setting fixed branch lengths", spacer);
11523                     FreePolyTree (sourceTree);
11524                     return (ERROR);
11525                     }
11526                 FreePolyTree (sourceTree);
11527                 if (tree->isClock == YES && IsClockSatisfied(tree, 0.0001) == NO)
11528                     {
11529                     MrBayesPrint("%s   Fixed branch lengths do not satisfy clock", spacer);
11530                     return (ERROR);
11531                     }
11532                 if (tree->isCalibrated == YES && IsCalibratedClockSatisfied(tree,&minRate,&maxRate, 0.0001) == NO)
11533                     {
11534                     MrBayesPrint("%s   Fixed branch lengths do not satisfy calibrations", spacer);
11535                     return (ERROR);
11536                     }
11537                 if (tree->isCalibrated == YES && !strcmp(modelParams[tree->relParts[0]].clockRatePr, "Fixed"))
11538                     {
11539                     clockRate = modelParams[tree->relParts[0]].clockRateFix;
11540                     if ((clockRate < minRate && AreDoublesEqual (clockRate, minRate , 0.0001) == NO) ||
11541                         (clockRate > maxRate && AreDoublesEqual (clockRate, maxRate , 0.0001) == NO))
11542                         {
11543                         MrBayesPrint("%s   Fixed branch lengths do not satisfy fixed clockrate", spacer);
11544                         return (ERROR);
11545                         }
11546                     }
11547
11548                 tree->fromUserTree=YES;
11549                 returnVal = NO_ERROR;
11550                 }
11551             else
11552                 {
11553                 MrBayesPrint("%s   Fixed branch lengths can only be used for a fixed topology\n", spacer);
11554                 return (ERROR);
11555                 }
11556             }
11557         else if (tree->isCalibrated == YES || (tree->isClock == YES && (!strcmp(modelParams[tree->relParts[0]].clockPr,"Uniform") ||
11558                                                                         !strcmp(modelParams[tree->relParts[0]].clockPr,"Fossilization"))))
11559             {
11560             assert (tree->isClock == YES);
11561             clockRate = *GetParamVals(modelSettings[tree->relParts[0]].clockRate, chn, state);
11562             returnVal = InitCalibratedBrlens (tree, clockRate, seed);
11563             if (IsClockSatisfied (tree,0.0001) == NO)
11564                 {
11565                 MrBayesPrint ("%s   Branch lengths of the tree does not satisfy clock\n",  spacer);
11566                 return (ERROR);
11567                 }
11568             tree->fromUserTree=NO;
11569             }
11570         else if (tree->isClock == YES)
11571             returnVal = InitClockBrlens (tree);
11572         else
11573             returnVal = InitBrlens (tree, 0.02);
11574
11575         if (returnVal == ERROR)
11576             return (ERROR);
11577
11578         if (FillBrlensSubParams (q, chn, state) == ERROR)
11579             return (ERROR);
11580         }
11581
11582     return (NO_ERROR);
11583 }
11584
11585
11586 /* FillBrlensSubParams: Fill any relaxed clock subparams of a brlens param */
11587 int FillBrlensSubParams (Param *param, int chn, int state)
11588 {
11589     int         i, j, *nEvents;
11590     MrBFlt      *brlen, *branchRate, **position, **rateMult;
11591     Tree        *tree;
11592     TreeNode    *p;
11593     Param       *q;
11594
11595     tree = GetTree (param, chn, state);
11596     
11597     for (i=0; i<param->nSubParams; i++)
11598         {
11599         q = param->subParams[i];
11600         if (q->paramType == P_CPPEVENTS)
11601             {
11602             nEvents = q->nEvents[2*chn+state];
11603             position = q->position[2*chn+state];
11604             rateMult = q->rateMult[2*chn+state];
11605             brlen = GetParamSubVals (q, chn, state);
11606             for (j=0; j<tree->nNodes-1; j++)
11607                 {
11608                 p = tree->allDownPass[j];
11609                 if (nEvents[p->index] != 0)
11610                     {
11611                     free (position[p->index]);
11612                     position[p->index] = NULL;
11613                     free (rateMult[p->index]);
11614                     rateMult[p->index] = NULL;
11615                     }
11616                 nEvents[p->index] = 0;
11617                 assert (j==tree->nNodes-2 || fabs(p->length - (p->anc->nodeDepth - p->nodeDepth)) < 0.000001);
11618                 brlen[p->index] = p->length;
11619                 }
11620             }
11621         else if (q->paramType == P_TK02BRANCHRATES || q->paramType == P_IGRBRANCHRATES || q->paramType == P_MIXEDBRCHRATES)
11622             {
11623             branchRate = GetParamVals (q, chn, state);
11624             brlen = GetParamSubVals (q, chn, state);
11625             for (j=0; j<tree->nNodes-1; j++)
11626                 {
11627                 p = tree->allDownPass[j];
11628                 assert (j==tree->nNodes-2 || fabs(p->length - (p->anc->nodeDepth - p->nodeDepth)) < 0.000001);
11629                 branchRate[p->index] = 1.0;
11630                 brlen[p->index] = p->length;
11631                 }
11632             }
11633         }
11634
11635     return (NO_ERROR);
11636 }
11637
11638
11639 /* Note: In PruneConstraintPartitions() we can not relay on specific rootnes of a tree since different partitions
11640    may theoreticly have different clock models, while constraints apply to all partitions/trees */
11641 int PruneConstraintPartitions()
11642 {
11643     int             i, j, constraintId, nLongsNeeded;
11644     
11645     nLongsNeeded = (numLocalTaxa - 1) / nBitsInALong + 1;
11646
11647     for (constraintId=0; constraintId<numDefinedConstraints; constraintId++)
11648         {
11649         definedConstraintPruned[constraintId] = (BitsLong *) SafeRealloc ((void *)definedConstraintPruned[constraintId], nLongsNeeded*sizeof(BitsLong));
11650         if (!definedConstraintPruned[constraintId])
11651             {
11652             MrBayesPrint ("%s   Problems allocating constraintPartition in PruneConstraintPartitions", spacer);
11653             return (ERROR);
11654             }
11655
11656         /* initialize bits in partition to add; get rid of deleted taxa in the process */
11657         ClearBits(definedConstraintPruned[constraintId], nLongsNeeded);
11658         for (i=j=0; i<numTaxa; i++)
11659             {
11660             if (taxaInfo[i].isDeleted == YES)
11661                 continue;
11662             if (IsBitSet(i, definedConstraint[constraintId]) == YES)
11663                 SetBit(j, definedConstraintPruned[constraintId]);
11664             j++;
11665             }
11666         assert (j == numLocalTaxa);
11667
11668         if (definedConstraintsType[constraintId] == PARTIAL)
11669             {
11670             definedConstraintTwoPruned[constraintId] = (BitsLong *) SafeRealloc ((void *)definedConstraintTwoPruned[constraintId], nLongsNeeded*sizeof(BitsLong));
11671             if (!definedConstraintTwoPruned[constraintId])
11672                 {
11673                 MrBayesPrint ("%s   Problems allocating constraintPartition in PruneConstraintPartitions", spacer);
11674                 return (ERROR);
11675                 }
11676
11677             /* initialize bits in partition to add; get rid of deleted taxa in the process */
11678             ClearBits(definedConstraintTwoPruned[constraintId], nLongsNeeded);
11679             for (i=j=0; i<numTaxa; i++)
11680                 {
11681                 if (taxaInfo[i].isDeleted == YES)
11682                     continue;
11683                 if (IsBitSet(i, definedConstraintTwo[constraintId]) == YES)
11684                     SetBit(j, definedConstraintTwoPruned[constraintId]);
11685                 j++;
11686                 }
11687             assert (j == numLocalTaxa);
11688             }
11689         else if (definedConstraintsType[constraintId] == NEGATIVE || (definedConstraintsType[constraintId] == HARD))
11690             {
11691             /* Here we create definedConstraintTwoPruned[constraintId] which is complemente of definedConstraintPruned[constraintId] */
11692             definedConstraintTwoPruned[constraintId] = (BitsLong *) SafeRealloc ((void *)definedConstraintTwoPruned[constraintId], nLongsNeeded*sizeof(BitsLong));
11693             if (!definedConstraintTwoPruned[constraintId])
11694                 {
11695                 MrBayesPrint ("%s   Problems allocating constraintPartition in PruneConstraintPartitions", spacer);
11696                 return (ERROR);
11697                 }
11698
11699             /* initialize bits in partition to add; get rid of deleted taxa in the process */
11700             ClearBits(definedConstraintTwoPruned[constraintId], nLongsNeeded);
11701             for (i=j=0; i<numTaxa; i++)
11702                 {
11703                 if (taxaInfo[i].isDeleted == YES)
11704                     continue;
11705                 if (IsBitSet(i, definedConstraint[constraintId]) == NO)
11706                     SetBit(j, definedConstraintTwoPruned[constraintId]);
11707                 j++;
11708                 }
11709             assert (j == numLocalTaxa);         
11710             }
11711     }
11712     
11713     return NO_ERROR;
11714 }
11715
11716
11717 int DoesTreeSatisfyConstraints(Tree *t)
11718 {
11719     int         i, k, numTaxa, nLongsNeeded;
11720     TreeNode    *p;
11721     int         CheckFirst, CheckSecond; /*Flag indicating wheather corresponding set(first/second) of partial constraint has to be checked*/
11722 #   if defined (DEBUG_CONSTRAINTS)
11723     int         locks_count=0;
11724 #   endif
11725
11726     if (t->checkConstraints == NO)
11727         return YES;
11728     /* get some handy numbers */
11729     numTaxa = t->nNodes - t->nIntNodes - (t->isRooted == YES ? 1 : 0);
11730     nLongsNeeded = (numTaxa - 1) / nBitsInALong + 1;
11731
11732     if (t->bitsets == NULL)
11733         {
11734         AllocateTreePartitions(t);
11735         }
11736     else
11737         {
11738         ResetTreePartitions(t);  /*Inefficient function, rewrite faster version*/
11739         }
11740 #   if defined (DEBUG_CONSTRAINTS)
11741     for (i=0; i<t->nIntNodes; i++)
11742         {
11743         p = t->intDownPass[i];
11744         if (p->isLocked == YES)
11745             {
11746             if (IsUnionEqThird (definedConstraintPruned[p->lockID], definedConstraintPruned[p->lockID], p->partition, nLongsNeeded) == NO && IsUnionEqThird (definedConstraintTwoPruned[p->lockID], definedConstraintTwoPruned[p->lockID], p->partition, nLongsNeeded) == NO)
11747                 {
11748                 printf ("DEBUG ERROR: Locked node does not represent right partition. \n");
11749                 return ABORT;
11750                 }
11751             else
11752                 {
11753                 locks_count++;
11754                 }
11755             }
11756         }
11757
11758     if (locks_count != t->nLocks)
11759         {
11760         printf ("DEBUG ERROR: locks_count:%d should be locks_count:%d\n", locks_count, t->nLocks);
11761         return ABORT;
11762         }
11763 #   endif
11764
11765     for (k=0; k<numDefinedConstraints; k++)
11766         {
11767 #   if defined (DEBUG_CONSTRAINTS)
11768         if (t->constraints[k] == YES && definedConstraintsType[k] == HARD)
11769             {
11770             if (t->isRooted == YES)
11771                 {
11772                 CheckFirst = YES;
11773                 CheckSecond = NO; 
11774                 }
11775             else
11776                 {
11777                 /*exactly one of next two will be YES*/
11778                 CheckFirst = IsBitSet(localOutGroup, definedConstraintPruned[k])==YES ? NO : YES;
11779                 CheckSecond = IsBitSet(localOutGroup, definedConstraintTwoPruned[k])==YES ? NO : YES;
11780                 assert ((CheckFirst^CheckSecond)==1);
11781                 }
11782
11783             for (i=0; i<t->nIntNodes; i++)
11784                 {
11785                 p = t->intDownPass[i];
11786                 if (p->anc != NULL)
11787                     {
11788                     if (CheckFirst==YES &&  IsPartNested(definedConstraintPruned[k], p->partition, nLongsNeeded) && IsPartNested(p->partition,definedConstraintPruned[k], nLongsNeeded))
11789                         break;
11790                     if (CheckSecond==YES &&  IsPartNested(definedConstraintTwoPruned[k], p->partition, nLongsNeeded) && IsPartNested(p->partition, definedConstraintTwoPruned[k], nLongsNeeded))
11791                         break;
11792                     }
11793                 }
11794
11795             if (i==t->nIntNodes)
11796                 {
11797                 printf ("DEBUG ERROR: Hard constraint is not satisfied. \n");
11798                 return ABORT;
11799                 //assert (0);
11800                 }
11801             }
11802 #   endif
11803
11804         if (t->constraints[k] == NO || definedConstraintsType[k] == HARD)
11805             continue;
11806
11807         if (definedConstraintsType[k] == PARTIAL)
11808             {
11809             /* alternative way
11810             if (t->isRooted == NO && !IsBitSet(localOutGroup, definedConstraintPruned[k]))
11811                 {
11812                 m = FirstTaxonInPartition (constraintPartition, nLongsNeeded);
11813                 for (i=0; t->nodes[i].index != m; i++)
11814                     ;
11815                 p = &t->nodes[i];
11816
11817                 p=p->anc;
11818                 while (!IsPartNested(definedConstraintPruned[k], p->partition, nLongsNeeded))
11819                     p=p->anc;
11820
11821                 if (IsSectionEmpty(definedConstraintTwoPruned[k], p->partition, nLongsNeeded))
11822                     continue;
11823                 }
11824             */
11825             if (t->isRooted == YES)
11826                 {
11827                 CheckFirst = YES;
11828                 CheckSecond = NO; /* In rooted case even if we have a node with partition fully containing second set and not containing the first set it would not satisfy the constraint */
11829                 }
11830             else
11831                 {
11832                 if (NumBits(definedConstraintPruned[k], nLongsNeeded) == 1 || NumBits(definedConstraintTwoPruned[k], nLongsNeeded) == 1)
11833                     continue;
11834                 /*one or two of the next two statments will be YES*/
11835                 CheckFirst = IsBitSet(localOutGroup, definedConstraintPruned[k])==YES ? NO : YES;
11836                 CheckSecond = IsBitSet(localOutGroup, definedConstraintTwoPruned[k])==YES ? NO : YES;
11837                 assert ((CheckFirst|CheckSecond)==1);
11838                 }
11839             for (i=0; i<t->nIntNodes; i++)
11840                 {
11841                 p = t->intDownPass[i];
11842                 if (p->anc != NULL)
11843                     { 
11844                     if (CheckFirst== YES && IsPartNested(definedConstraintPruned[k], p->partition, nLongsNeeded) && IsSectionEmpty(definedConstraintTwoPruned[k], p->partition, nLongsNeeded))
11845                         break;
11846                     if (CheckSecond==YES && IsPartNested(definedConstraintTwoPruned[k], p->partition, nLongsNeeded) && IsSectionEmpty(definedConstraintPruned[k], p->partition, nLongsNeeded))
11847                         break;
11848                     }
11849                 }
11850             if (i==t->nIntNodes)
11851                 return NO;
11852             }
11853         else
11854             {
11855             assert (definedConstraintsType[k] == NEGATIVE);
11856             if (t->isRooted == YES)
11857                 {
11858                 CheckFirst = YES;
11859                 CheckSecond = NO; 
11860                 }
11861             else
11862                 {
11863                 /*exactly one of next two will be YES*/
11864                 CheckFirst = IsBitSet(localOutGroup, definedConstraintPruned[k])==YES ? NO : YES;
11865                 CheckSecond = IsBitSet(localOutGroup, definedConstraintTwoPruned[k])==YES ? NO : YES;
11866                 assert ((CheckFirst^CheckSecond)==1);
11867                 }
11868
11869             for (i=0; i<t->nIntNodes; i++)
11870                 {
11871                 p = t->intDownPass[i];
11872                 if (p->anc != NULL)
11873                     {
11874                     if (CheckFirst==YES && AreBitfieldsEqual(definedConstraintPruned[k], p->partition, nLongsNeeded))
11875                         break;
11876                     if (CheckSecond==YES && AreBitfieldsEqual(definedConstraintTwoPruned[k], p->partition, nLongsNeeded))
11877                         break;
11878                     }
11879                 }
11880             if (i!=t->nIntNodes)
11881                 return NO;
11882             }
11883         }
11884     
11885     return YES;
11886 }
11887
11888
11889 /*------------------------------------------------------------------
11890 |
11891 |   FillTreeParams: Fill in trees and branch lengths
11892 |                   
11893 |   Note: Should be run after FillNormalParams because
11894 |   clockrate needs to be set if calibrated tree needs
11895 |   to be filled.
11896 |
11897 ------------------------------------------------------------------*/
11898 int FillTreeParams (RandLong *seed, int fromChain, int toChain)
11899 {
11900     int         i, k, chn, nTaxa, tmp;
11901     Param       *p, *q;
11902     Tree        *tree;
11903     PolyTree    *constraintTree;
11904     PolyTree    *constraintTreeRef;
11905
11906     if (PruneConstraintPartitions() == ERROR)
11907         return ERROR;
11908
11909     /* Build starting trees for state 0 */
11910     for (chn=fromChain; chn<toChain; chn++)
11911         {
11912         for (k=0; k<numParams; k++)
11913             {
11914             p = &params[k];
11915             if (p->paramType == P_TOPOLOGY)
11916                 {
11917                 q = p->subParams[0];
11918                 tree = GetTree (q, chn, 0);
11919                 if (tree->isRooted == YES)
11920                     nTaxa = tree->nNodes - tree->nIntNodes - 1;
11921                 else
11922                     nTaxa = tree->nNodes - tree->nIntNodes;
11923                 
11924                 /* fixed topology */
11925                 if (p->paramId == TOPOLOGY_NCL_FIXED ||
11926                     p->paramId == TOPOLOGY_NCL_FIXED_HOMO ||
11927                     p->paramId == TOPOLOGY_NCL_FIXED_HETERO ||
11928                     p->paramId == TOPOLOGY_CL_FIXED  ||
11929                     p->paramId == TOPOLOGY_RCL_FIXED ||
11930                     p->paramId == TOPOLOGY_CCL_FIXED ||
11931                     p->paramId == TOPOLOGY_RCCL_FIXED||
11932                     p->paramId == TOPOLOGY_FIXED     ||
11933                     p->paramId == TOPOLOGY_PARSIMONY_FIXED)
11934                     {
11935                     constraintTree = AllocatePolyTree (numTaxa);
11936                     CopyToPolyTreeFromPolyTree (constraintTree, userTree[modelParams[p->relParts[0]].topologyFix]);
11937                     PrunePolyTree (constraintTree);
11938                     ResetTipIndices(constraintTree);
11939                     ResetIntNodeIndices(constraintTree);
11940                     RandResolve (NULL, constraintTree, seed, constraintTree->isRooted);
11941                     if (tree->nIntNodes != constraintTree->nIntNodes)
11942                         {
11943                         if (tree->isRooted != constraintTree->isRooted)
11944                             {
11945                             MrBayesPrint ("%s   Could not fix topology because user tree '%s' differs in rootedness with the model tree.\n", spacer,
11946                                           userTree[modelParams[p->relParts[0]].topologyFix]->name);
11947                             MrBayesPrint ("%s   The user tree %s is%srooted, while expected model tree is%srooted.\n", spacer,
11948                                           userTree[modelParams[p->relParts[0]].topologyFix]->name, (constraintTree->isRooted?" ":" not "), (tree->isRooted?" ":" not "));
11949                             MrBayesPrint ("%s   Check brlenspr is set correctly before fixing topology.\n", spacer);
11950                             }
11951                         else
11952                             MrBayesPrint ("%s   Could not fix topology because user tree '%s' is not fully resolved.\n",
11953                                                 spacer, userTree[modelParams[p->relParts[0]].topologyFix]->name);
11954                         FreePolyTree (constraintTree);
11955                         return (ERROR);
11956                         }
11957                     if (CopyToTreeFromPolyTree(tree, constraintTree) == ERROR)
11958                         {
11959                         MrBayesPrint ("%s   Could not fix topology according to user tree '%s'\n", spacer, userTree[modelParams[p->relParts[0]].topologyFix]->name);
11960                         FreePolyTree (constraintTree);
11961                         return (ERROR);
11962                         }
11963                     FreePolyTree (constraintTree);
11964                     }
11965                 /* constrained topology */
11966                 else if (tree->nConstraints > 0)
11967                     {
11968                     constraintTreeRef = AllocatePolyTree (nTaxa);
11969                     if (!constraintTreeRef)
11970                         return (ERROR);
11971                     if (BuildConstraintTree (tree, constraintTreeRef, localTaxonNames) == ERROR)
11972                         {
11973                         FreePolyTree (constraintTreeRef);
11974                         return (ERROR);
11975                         }
11976                     if (AllocatePolyTreePartitions (constraintTreeRef) == ERROR)
11977                         return (ERROR);
11978
11979                     constraintTree = AllocatePolyTree (nTaxa);
11980                     if (!constraintTree)
11981                         return (ERROR);
11982                     if (AllocatePolyTreePartitions (constraintTree) == ERROR)
11983                         return (ERROR);
11984
11985                     for (i=0;i<100;i++)
11986                         {
11987                         CopyToPolyTreeFromPolyTree(constraintTree,constraintTreeRef);
11988                         tmp = RandResolve (tree, constraintTree, &globalSeed, tree->isRooted);
11989                         if (tmp != NO_ERROR)
11990                             {
11991                             if (tmp  == ERROR)
11992                                 {
11993                                 FreePolyTree (constraintTree);
11994                                 return (ERROR);
11995                                 }
11996                             else
11997                                 {   
11998                                 assert (tmp  == ABORT);
11999                                 continue;
12000                                 }
12001                             }
12002                    
12003                         CopyToTreeFromPolyTree(tree, constraintTree);
12004                         if (DoesTreeSatisfyConstraints(tree)==YES)
12005                             break;
12006                         }
12007 #   if defined (DEBUG_CONSTRAINTS)
12008                     if (theTree->checkConstraints == YES && CheckConstraints (tree) == ERROR)
12009                         {
12010                         printf ("Error in constraints of starting tree\n");
12011                         getchar();
12012                         }
12013 #   endif
12014                     FreePolyTree (constraintTree);
12015                     FreePolyTree (constraintTreeRef);
12016                     if (i==100)
12017                         {
12018                         MrBayesPrint ("%s   Could not build a starting tree satisfying all constraints\n", spacer);                     
12019                         return (ERROR);
12020                         }
12021                     }
12022                 /* random topology */
12023                 else
12024                     {
12025                     if (tree->isRooted == YES)
12026                         {
12027                         if (BuildRandomRTopology (tree, &globalSeed) == ERROR)
12028                             return (ERROR);
12029                         }
12030                     else
12031                         {
12032                         if (BuildRandomUTopology (tree, &globalSeed) == ERROR)
12033                             return (ERROR);
12034                         if (MoveCalculationRoot (tree, localOutGroup) == ERROR)
12035                             return (ERROR);
12036                         }
12037                     }
12038                 
12039                 if (LabelTree (tree, localTaxonNames) == ERROR)
12040                     return (ERROR);
12041                 if (q == p)
12042                     continue;   /* this is a parsimony tree without branch lengths */
12043                 if (InitializeTreeCalibrations (tree) == ERROR)
12044                     return (ERROR);
12045                 if (FillTopologySubParams(p, chn, 0, seed)== ERROR)
12046                     return (ERROR);
12047                 }
12048             }
12049         }
12050
12051     if (numTopologies > 1 && !strcmp(modelParams[0].topologyPr,"Speciestree"))
12052         {
12053         if (FillSpeciesTreeParams(seed, fromChain, toChain) == ERROR)
12054             return (ERROR);
12055         }
12056
12057     return (NO_ERROR);
12058 }
12059
12060
12061 void FreeCppEvents (Param *p)
12062 {
12063     int i, j;
12064     
12065     if (p->paramType != P_CPPEVENTS)
12066         return;
12067
12068     if (p->nEvents != NULL)
12069         {
12070         free (p->nEvents[0]);
12071         free (p->nEvents);
12072         for (i=0; i<numGlobalChains; i++)
12073             {
12074             for (j=0; j<2*numLocalTaxa; j++)
12075                 {
12076                 free (p->position[2*i][j]);
12077                 free (p->rateMult[2*i][j]);
12078                 free (p->position[2*i+1][j]);
12079                 free (p->rateMult[2*i+1][j]);
12080                 }
12081             }
12082         free (p->position[0]);
12083         free (p->position);
12084         free (p->rateMult[0]);
12085         free (p->rateMult);
12086         p->nEvents = NULL;
12087         p->position = NULL;
12088         p->rateMult = NULL;
12089         }
12090 }
12091
12092
12093 int FreeModel (void)
12094 {
12095     int     i;
12096     Param   *p;
12097     
12098     if (memAllocs[ALLOC_MODEL] == YES)
12099         {
12100         for (i=0; i<numCurrentDivisions; i++)
12101             {
12102             free (modelParams[i].activeConstraints);
12103             if (memAllocs[ALLOC_SAMPLEFOSSILSLICE] == YES)
12104                 {
12105                 free(modelParams[i].sampleFSProb);
12106                 free(modelParams[i].sampleFSTime);
12107                 memAllocs[ALLOC_SAMPLEFOSSILSLICE] = NO;
12108                 }
12109             }
12110         free (modelParams);
12111         free (modelSettings);
12112         memAllocs[ALLOC_MODEL] = NO;
12113         }
12114     if (memAllocs[ALLOC_MOVES] == YES)
12115         {
12116         for (i=0; i<numApplicableMoves; i++)
12117             FreeMove (moves[i]);
12118         free (moves);
12119         moves = NULL;
12120         numApplicableMoves = 0;
12121         memAllocs[ALLOC_MOVES] = NO;
12122         }
12123     if (memAllocs[ALLOC_COMPMATRIX] == YES)
12124         {
12125         free (compMatrix);
12126         memAllocs[ALLOC_COMPMATRIX] = NO;
12127         }
12128     if (memAllocs[ALLOC_NUMSITESOFPAT] == YES)
12129         {
12130         free (numSitesOfPat);
12131         memAllocs[ALLOC_NUMSITESOFPAT] = NO;
12132         }
12133     if (memAllocs[ALLOC_COMPCOLPOS] == YES)
12134         {
12135         free (compColPos);
12136         memAllocs[ALLOC_COMPCOLPOS] = NO;
12137         }
12138     if (memAllocs[ALLOC_COMPCHARPOS] == YES)
12139         {
12140         free (compCharPos);
12141         memAllocs[ALLOC_COMPCHARPOS] = NO;
12142         }
12143     if (memAllocs[ALLOC_ORIGCHAR] == YES)
12144         {
12145         free (origChar);
12146         memAllocs[ALLOC_ORIGCHAR] = NO;
12147         }
12148     if (memAllocs[ALLOC_STDTYPE] == YES)
12149         {
12150         free (stdType);
12151         memAllocs[ALLOC_STDTYPE] = NO;
12152         }
12153     if (memAllocs[ALLOC_STDSTATEFREQS] == YES)
12154         {
12155         free (stdStateFreqs);
12156         stdStateFreqs = NULL;
12157         memAllocs[ALLOC_STDSTATEFREQS] = NO;
12158         }
12159     if (memAllocs[ALLOC_PARAMVALUES] == YES)
12160         {
12161         for (i=0; i<numParams; i++)
12162             {
12163             p = &params[i];
12164             if (p->paramType == P_CPPEVENTS)
12165                 FreeCppEvents(p);
12166             }
12167         free (paramValues);
12168         paramValues = NULL;
12169         free (intValues);
12170         intValues = NULL;
12171         paramValsRowSize = intValsRowSize = 0;
12172         memAllocs[ALLOC_PARAMVALUES] = NO;
12173         }
12174     if (memAllocs[ALLOC_PARAMS] == YES)
12175         {
12176         for (i=0; i<numParams; i++)
12177             {
12178             SafeFree ((void **)&params[i].name);
12179             if (params[i].paramHeader)
12180                 {
12181                 free (params[i].paramHeader);
12182                 params[i].paramHeader = NULL;
12183                 }
12184             }
12185         free (params);
12186         free (relevantParts);
12187         params = NULL;
12188         relevantParts = NULL;
12189         numParams = 0;
12190         memAllocs[ALLOC_PARAMS] = NO;
12191         }
12192     if (memAllocs[ALLOC_MCMCTREES] == YES)
12193         {
12194         free (mcmcTree);
12195         free (subParamPtrs);
12196         mcmcTree = NULL;
12197         subParamPtrs = NULL;
12198         memAllocs[ALLOC_MCMCTREES] = NO;
12199         }
12200     if (memAllocs[ALLOC_SYMPIINDEX] == YES)
12201         {
12202         free (sympiIndex);
12203         memAllocs[ALLOC_SYMPIINDEX] = NO;
12204         }
12205     if (memAllocs[ALLOC_LOCTAXANAMES] == YES)
12206         {
12207         free (localTaxonNames);
12208         memAllocs[ALLOC_LOCTAXANAMES] = NO;
12209         }
12210     if (memAllocs[ALLOC_LOCALTAXONCALIBRATION] == YES)
12211         {
12212         free (localTaxonCalibration);
12213         memAllocs[ALLOC_LOCALTAXONCALIBRATION] = NO;
12214         }
12215
12216     return (NO_ERROR);
12217 }
12218
12219
12220 void FreeMove (MCMCMove *mv)
12221 {
12222     free (mv->tuningParam[0]);
12223     free (mv->tuningParam);
12224     free (mv->relProposalProb);
12225     free (mv->nAccepted);
12226     free (mv->name);
12227     free (mv);
12228 }
12229
12230
12231 /* Compute empirical state freq are return it in global array empiricalFreqs[] */
12232 int GetEmpiricalFreqs (int *relParts, int nRelParts)
12233 {
12234     int             i, j, k, m, n, thePartition, nuc[20], ns, temp, isDNA, isProtein, firstRel;
12235     MrBFlt          freqN[20], sum, sumN[20]/*, rawCounts[20]*/;
12236
12237     isDNA = isProtein = NO;
12238     ns = 0;
12239     firstRel = 0;
12240     for (i=0; i<nRelParts; i++)
12241         {
12242         thePartition = relParts[i];
12243         if (i == 0)
12244             {
12245             if (modelParams[thePartition].dataType == DNA || modelParams[i].dataType == RNA)
12246                 {
12247                 isDNA = YES;
12248                 ns = 4;
12249                 }
12250             else if (modelParams[thePartition].dataType == PROTEIN)
12251                 {
12252                 isProtein = YES;
12253                 ns = 20;
12254                 }
12255             else if (modelParams[thePartition].dataType == RESTRICTION)
12256                 {
12257                 ns = 2;
12258                 }
12259             else
12260                 {
12261                 MrBayesPrint ("%s   Cannot get empirical state frequencies for this datatype (%d)\n", spacer, modelSettings[i].dataType);
12262                 return (ERROR);
12263                 }
12264             firstRel = thePartition;
12265             }
12266         else
12267             {
12268             if (modelParams[thePartition].dataType == DNA || modelParams[i].dataType == RNA)
12269                 temp = 4;
12270             else if (modelParams[thePartition].dataType == PROTEIN)
12271                 temp = 20;
12272             else if (modelParams[thePartition].dataType == RESTRICTION)
12273                 temp = 2;
12274             else
12275                 {
12276                 MrBayesPrint ("%s   Unknown data type in GetEmpiricalFreqs\n", spacer);
12277                 return (ERROR);
12278                 }
12279             if (ns != temp)
12280                 {
12281                 MrBayesPrint ("%s   Averaging state frequencies over partitions with different data types\n", spacer);
12282                 return (ERROR);
12283                 }
12284             }
12285         }
12286     if (ns == 0)
12287         {
12288         MrBayesPrint ("%s   Could not find a relevant partition\n", spacer);
12289         return (ERROR);
12290         }
12291
12292     for (i=0; i<200; i++)
12293         empiricalFreqs[i] = 0.0;
12294     
12295     for (m=0; m<ns; m++)
12296         freqN[m] =  1.0 / ns;
12297         
12298     /* for (m=0; m<ns; m++)
12299        rawCounts[m] = 0.0; NEVER USED */
12300         
12301     for (m=0; m<ns; m++)
12302         sumN[m] = 0.0;
12303     for (k=0; k<nRelParts; k++)
12304         {
12305         thePartition = relParts[k];
12306         for (i=0; i<numTaxa; i++)
12307             {
12308             if (taxaInfo[i].isDeleted == NO)
12309                 {
12310                 for (j=0; j<numChar; j++)
12311                     {
12312                     if (charInfo[j].isExcluded == NO && partitionId[j][partitionNum] - 1 == thePartition)
12313                         {
12314                         if (isDNA == YES)
12315                             GetPossibleNucs (matrix[pos(i,j,numChar)], nuc);
12316                         else if (isProtein == YES)
12317                             GetPossibleAAs (matrix[pos(i,j,numChar)], nuc);
12318                         else
12319                             GetPossibleRestrictionSites (matrix[pos(i,j,numChar)], nuc);
12320                         sum = 0.0;
12321                         for (m=0; m<ns; m++)
12322                             sum += freqN[m] * nuc[m];
12323                         for (m=0; m<ns; m++)
12324                             sumN[m] += freqN[m] * nuc[m] / sum;
12325                         }
12326                     }
12327                 }
12328             }
12329         }
12330     sum = 0.0;
12331     for (m=0; m<ns; m++)
12332         sum += sumN[m];
12333     for (m=0; m<ns; m++)
12334         freqN[m] = sumN[m] / sum;
12335
12336     if (modelParams[firstRel].dataType == DNA || modelParams[firstRel].dataType == RNA)
12337         {
12338         if (!strcmp(modelParams[firstRel].nucModel, "4by4"))
12339             {
12340             for (m=0; m<ns; m++)
12341                 empiricalFreqs[m] = freqN[m];
12342             }
12343         else if (!strcmp(modelParams[firstRel].nucModel, "Doublet"))
12344             {
12345             i = 0;
12346             for (m=0; m<ns; m++)
12347                 for (n=0; n<ns; n++)
12348                     empiricalFreqs[i++] = freqN[m] * freqN[n];
12349             }
12350         else
12351             {
12352             if (!strcmp(modelParams[firstRel].geneticCode, "Universal"))
12353                 {
12354                 for (i=0; i<61; i++)
12355                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12356                 }
12357             else if (!strcmp(modelParams[firstRel].geneticCode, "Vertmt"))
12358                 {
12359                 for (i=0; i<60; i++)
12360                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12361                 }
12362             else if (!strcmp(modelParams[firstRel].geneticCode, "Invermt"))
12363                 {
12364                 for (i=0; i<62; i++)
12365                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12366                 }
12367             else if (!strcmp(modelParams[firstRel].geneticCode, "Mycoplasma"))
12368                 {
12369                 for (i=0; i<62; i++)
12370                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12371                 }
12372             else if (!strcmp(modelParams[firstRel].geneticCode, "Yeast"))
12373                 {
12374                 for (i=0; i<62; i++)
12375                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12376                 }
12377             else if (!strcmp(modelParams[firstRel].geneticCode, "Ciliate"))
12378                 {
12379                 for (i=0; i<63; i++)
12380                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12381                 }
12382             else if (!strcmp(modelParams[firstRel].geneticCode, "Echinoderm"))
12383                 {
12384                 for (i=0; i<62; i++)
12385                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12386                 }
12387             else if (!strcmp(modelParams[firstRel].geneticCode, "Euplotid"))
12388                 {
12389                 for (i=0; i<62; i++)
12390                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12391                 }
12392             else if (!strcmp(modelParams[firstRel].geneticCode, "Metmt"))
12393                 {
12394                 for (i=0; i<62; i++)
12395                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12396                 }
12397             sum = 0.0;
12398             for (i=0; i<64; i++)
12399                 sum += empiricalFreqs[i];
12400             for (i=0; i<64; i++)
12401                 empiricalFreqs[i] /= sum;
12402             
12403             }
12404         }
12405     else
12406         {
12407         for (m=0; m<ns; m++)
12408             empiricalFreqs[m] = freqN[m];
12409         }
12410         
12411     return (NO_ERROR);
12412 }
12413
12414
12415 int GetNumDivisionChars (void)
12416 {
12417     int         c, d, n;
12418     ModelInfo   *m;
12419
12420     /* count number of characters in each division */
12421     for (d=0; d<numCurrentDivisions; d++)
12422         {
12423         m = &modelSettings[d];
12424         
12425         n = 0;
12426         for (c=0; c<numChar; c++)
12427             {
12428             if (charInfo[c].isExcluded == NO && partitionId[c][partitionNum] == d+1)
12429                 n++;
12430             }
12431         if (m->dataType == DNA || m->dataType == RNA)
12432             {
12433             if (m->nucModelId == NUCMODEL_DOUBLET)
12434                 n *= 2;
12435             else if (m->nucModelId == NUCMODEL_CODON)
12436                 n *= 3;
12437             }
12438
12439         m->numUncompressedChars = n;
12440         }
12441     
12442     return (NO_ERROR);
12443 }
12444
12445
12446 int *GetParamIntVals (Param *parm, int chain, int state)
12447 {
12448     return parm->intValues + (2 * chain + state) * intValsRowSize;
12449 }
12450
12451
12452 MrBFlt  *GetParamStdStateFreqs (Param *parm, int chain, int state)
12453 {
12454     return parm->stdStateFreqs + (2 * chain + state) * stdStateFreqsRowSize;
12455 }
12456
12457
12458 MrBFlt  *GetParamSubVals (Param *parm, int chain, int state)
12459 {
12460     return parm->subValues + (2 * chain + state) * paramValsRowSize;
12461 }
12462
12463
12464 MrBFlt  *GetParamVals (Param *parm, int chain, int state)
12465 {
12466     return parm->values + (2 * chain + state) * paramValsRowSize;
12467 }
12468
12469
12470 void GetPossibleAAs (int aaCode, int aa[])
12471 {
12472     int     m;
12473     
12474     for (m=0; m<20; m++)
12475         aa[m] = 0;
12476         
12477     if (aaCode > 0 && aaCode <= 20)
12478         aa[aaCode-1] = 1;
12479     else
12480         {
12481         for (m=0; m<20; m++)
12482             aa[m] = 1;
12483         }
12484
12485 #   if 0
12486     printf ("%2d -- ", aaCode);
12487     for (m=0; m<20; m++)
12488         printf ("%d", aa[m]);
12489     printf ("\n");
12490 #   endif
12491 }
12492
12493
12494 void GetPossibleNucs (int nucCode, int nuc[])
12495 {
12496     if (nucCode == 1)
12497         {
12498         nuc[0] = 1;
12499         nuc[1] = 0;
12500         nuc[2] = 0;
12501         nuc[3] = 0;
12502         }
12503     else if (nucCode == 2)
12504         {
12505         nuc[0] = 0;
12506         nuc[1] = 1;
12507         nuc[2] = 0;
12508         nuc[3] = 0;
12509         }
12510     else if (nucCode == 3)
12511         {
12512         nuc[0] = 1;
12513         nuc[1] = 1;
12514         nuc[2] = 0;
12515         nuc[3] = 0;
12516         }
12517     else if (nucCode == 4)
12518         {
12519         nuc[0] = 0;
12520         nuc[1] = 0;
12521         nuc[2] = 1;
12522         nuc[3] = 0;
12523         }
12524     else if (nucCode == 5)
12525         {
12526         nuc[0] = 1;
12527         nuc[1] = 0;
12528         nuc[2] = 1;
12529         nuc[3] = 0;
12530         }
12531     else if (nucCode == 6)
12532         {
12533         nuc[0] = 0;
12534         nuc[1] = 1;
12535         nuc[2] = 1;
12536         nuc[3] = 0;
12537         }
12538     else if (nucCode == 7)
12539         {
12540         nuc[0] = 1;
12541         nuc[1] = 1;
12542         nuc[2] = 1;
12543         nuc[3] = 0;
12544         }
12545     else if (nucCode == 8)
12546         {
12547         nuc[0] = 0;
12548         nuc[1] = 0;
12549         nuc[2] = 0;
12550         nuc[3] = 1;
12551         }
12552     else if (nucCode == 9)
12553         {
12554         nuc[0] = 1;
12555         nuc[1] = 0;
12556         nuc[2] = 0;
12557         nuc[3] = 1;
12558         }
12559     else if (nucCode == 10)
12560         {
12561         nuc[0] = 0;
12562         nuc[1] = 1;
12563         nuc[2] = 0;
12564         nuc[3] = 1;
12565         }
12566     else if (nucCode == 11)
12567         {
12568         nuc[0] = 1;
12569         nuc[1] = 1;
12570         nuc[2] = 0;
12571         nuc[3] = 1;
12572         }
12573     else if (nucCode == 12)
12574         {
12575         nuc[0] = 0;
12576         nuc[1] = 0;
12577         nuc[2] = 1;
12578         nuc[3] = 1;
12579         }
12580     else if (nucCode == 13)
12581         {
12582         nuc[0] = 1;
12583         nuc[1] = 0;
12584         nuc[2] = 1;
12585         nuc[3] = 1;
12586         }
12587     else if (nucCode == 14)
12588         {
12589         nuc[0] = 0;
12590         nuc[1] = 1;
12591         nuc[2] = 1;
12592         nuc[3] = 1;
12593         }
12594     else
12595         {
12596         nuc[0] = 1;
12597         nuc[1] = 1;
12598         nuc[2] = 1;
12599         nuc[3] = 1;
12600         }
12601 }
12602
12603
12604 void GetPossibleRestrictionSites (int resSiteCode, int *sites)
12605 {
12606     int     m;
12607     
12608     for (m=0; m<2; m++)
12609         sites[m] = 0;
12610         
12611     if (resSiteCode == 1)
12612         sites[0] = 1;
12613     else if (resSiteCode == 2)
12614         sites[1] = 1;
12615     else
12616         sites[0] = sites[1] = 1;
12617
12618 #   if 0
12619     printf ("%2d -- ", aaCode);
12620     for (m=0; m<20; m++)
12621         printf ("%d", aa[m]);
12622     printf ("\n");
12623 #   endif
12624 }
12625
12626
12627 Tree *GetTree (Param *parm, int chain, int state)
12628 {
12629     return mcmcTree[parm->treeIndex + ((2 * chain + state) * numTrees)];
12630 }
12631
12632
12633 Tree *GetTreeFromIndex (int index, int chain, int state)
12634 {
12635     return mcmcTree[index + ((2 * chain + state) * numTrees)];
12636 }
12637
12638
12639 /*-----------------------------------------------------------
12640 |
12641 |   GetUserTreeFromName: Do case-insensitive search for user
12642 |      tree, return index if match, -1 and ERROR if error
12643 |
12644 ------------------------------------------------------------*/
12645 int GetUserTreeFromName (int *index, char *treeName)
12646 {
12647     int     i, j, k, nMatches;
12648     char    localName[100], temp[100];
12649
12650     (*index) = -1;  /* appropriate return if no match */
12651
12652     if ((int)strlen(treeName) > 99)
12653         {
12654         MrBayesPrint ("%s   Too many characters in tree name\n", spacer);
12655         return (ERROR);
12656         }
12657
12658     strcpy (localName, treeName);
12659     for (i=0; i<(int)strlen(localName); i++)
12660         localName[i] = tolower(localName[i]);
12661
12662     nMatches = j = 0;
12663     for (i=0; i<numUserTrees; i++)
12664         {
12665         strcpy (temp, userTree[i]->name);
12666         for (k=0; k<(int)strlen(temp); k++)
12667             temp[k] = tolower(temp[k]);
12668         if (strcmp(localName,temp) == 0)
12669             {
12670             j = i;
12671             nMatches++;
12672             }
12673         }
12674     if (nMatches==0)
12675         {
12676         for (i=0; i<numUserTrees; i++)
12677             {
12678             strcpy (temp, userTree[i]->name);
12679             for (k=0; k<(int)strlen(temp); k++)
12680                 temp[k] = tolower(temp[k]);
12681             if (strncmp(localName,temp,strlen(localName)) == 0)
12682                 {
12683                 j = i;
12684                 nMatches++;
12685                 }
12686             }
12687         }
12688     if (nMatches == 0)
12689         {
12690         MrBayesPrint ("%s   Could not find tree '%s'\n", spacer, localName);  
12691         return (ERROR);
12692         }
12693     else if (nMatches > 1)
12694         {
12695         MrBayesPrint ("%s   Several trees matched the abbreviated name '%s'\n", spacer, localName);
12696         return (ERROR);
12697         }
12698     else
12699         {
12700         (*index) = j;
12701         return (NO_ERROR);
12702         }
12703 }
12704
12705
12706 /*----------------------------------------------------------------------
12707  |
12708  |   InitializeChainTrees: 'Constructor' for chain trees
12709  |
12710  -----------------------------------------------------------------------*/
12711 int InitializeChainTrees (Param *p, int from, int to, int isRooted)
12712 {
12713     int     i, st, isCalibrated, isClock, nTaxa, numActiveHardConstraints=0;
12714     Tree    *tree, **treeHandle;
12715     Model   *mp;
12716     
12717     mp = &modelParams[p->relParts[0]];
12718     
12719     if (p->paramType == P_SPECIESTREE)
12720         nTaxa = numSpecies;
12721     else
12722         nTaxa = numLocalTaxa;
12723     
12724     /* figure out whether the trees are clock */
12725     if (!strcmp(mp->brlensPr,"Clock"))
12726         isClock = YES;
12727     else
12728         isClock = NO;
12729     
12730     /* figure out whether the trees are calibrated */
12731     if (!strcmp(mp->brlensPr,"Clock") && (strcmp(mp->nodeAgePr,"Calibrated") == 0 || strcmp(mp->clockRatePr,"Fixed") != 0 ||
12732                                           (strcmp(mp->clockRatePr, "Fixed") == 0 && AreDoublesEqual(mp->clockRateFix, 1.0, 1E-6) == NO)))
12733         isCalibrated = YES;
12734     else
12735         isCalibrated = NO;
12736     
12737     if (p->checkConstraints == YES)
12738         {
12739         for (i=0; i<numDefinedConstraints; i++)
12740             {
12741             if (mp->activeConstraints[i] == YES && definedConstraintsType[i] == HARD)
12742                 numActiveHardConstraints++;
12743             }
12744         }
12745     
12746     /* allocate space for and construct the trees */
12747     /* NOTE: The memory allocation scheme used here must match GetTree and GetTreeFromIndex */
12748     for (i=from; i<to; i++)
12749         {
12750         treeHandle = mcmcTree + p->treeIndex + 2*i*numTrees;
12751         if (*treeHandle)
12752             free(*treeHandle);
12753         if ((*treeHandle = AllocateTree (nTaxa)) == NULL)
12754             {
12755             MrBayesPrint ("%s   Problem allocating mcmc trees\n", spacer);
12756             return (ERROR);
12757             }
12758         treeHandle = mcmcTree + p->treeIndex + (2*i + 1)*numTrees;
12759         if (*treeHandle)
12760             free(*treeHandle);
12761         if ((*treeHandle = AllocateTree (nTaxa)) == NULL)
12762             {
12763             MrBayesPrint ("%s   Problem allocating mcmc trees\n", spacer);
12764             return (ERROR);
12765             }
12766         }
12767     
12768     /* initialize the trees */
12769     for (i=from; i<to; i++)
12770         {
12771         for (st=0; st<2; st++)
12772             {
12773             tree = GetTree (p, i, st);
12774             if (numTrees > 1)
12775                 sprintf (tree->name, "mcmc.tree%d_%d", p->treeIndex+1, i+1);
12776             else /* if (numTrees == 1) */
12777                 sprintf (tree->name, "mcmc.tree_%d", i+1);
12778             tree->nRelParts = p->nRelParts;
12779             tree->relParts = p->relParts;
12780             tree->isRooted = isRooted;
12781             tree->isClock = isClock;
12782             tree->isCalibrated = isCalibrated;
12783             if (p->paramType == P_SPECIESTREE)
12784                 {
12785                 tree->nNodes = 2*numSpecies;
12786                 tree->nIntNodes = numSpecies - 1;
12787                 }
12788             else if (tree->isRooted == YES)
12789                 {
12790                 tree->nNodes = 2*numLocalTaxa;
12791                 tree->nIntNodes = numLocalTaxa - 1;
12792                 }
12793             else /* if (tree->isRooted == NO) */
12794                 {
12795                 tree->nNodes = 2*numLocalTaxa - 2;
12796                 tree->nIntNodes = numLocalTaxa - 2;
12797                 }
12798             if (p->checkConstraints == YES)
12799                 {
12800                 tree->checkConstraints = YES;
12801                 tree->nLocks = NumInformativeHardConstraints(mp);
12802                 tree->nConstraints = mp->numActiveConstraints;  /* nConstraints is number of constraints to check */
12803                 tree->constraints = mp->activeConstraints;
12804                 }
12805             else
12806                 {
12807                 tree->checkConstraints = NO;
12808                 tree->nConstraints = tree->nLocks = 0;
12809                 tree->constraints = NULL;
12810                 }
12811             }
12812         }
12813     
12814     return (NO_ERROR);
12815 }
12816
12817
12818 int InitializeLinks (void)
12819 {
12820     int         i, j;
12821     
12822     linkNum = 0;
12823     for (i=0; i<NUM_LINKED; i++)
12824         {
12825         for (j=0; j<numCurrentDivisions; j++)
12826             linkTable[i][j] = linkNum;
12827         }
12828
12829     return (NO_ERROR);
12830 }
12831
12832
12833 /* InitializeTreeCalibrations: Set calibrations for tree nodes */
12834 int InitializeTreeCalibrations (Tree *t)
12835 {
12836     int         i;
12837     TreeNode    *p;
12838     
12839     if (t->isCalibrated == NO)
12840         return (NO_ERROR);
12841     
12842     /* Set tip calibrations */
12843     for (i=0; i<t->nNodes; i++)
12844         {
12845         p = t->allDownPass[i];
12846         if (p->left == NULL && p->right == NULL && localTaxonCalibration[p->index]->prior != unconstrained)
12847             {
12848             p->isDated = YES;
12849             p->calibration = localTaxonCalibration[p->index];
12850             p->age = p->calibration->min;
12851             }
12852         else if (p->left == NULL && p->right == NULL)
12853             {
12854             p->isDated = NO;
12855             p->calibration = NULL;
12856             p->age = -1.0;
12857             } 
12858         }
12859
12860     /* Initialize interior calibrations */
12861     if (CheckSetConstraints(t) == ERROR)
12862         return (ERROR);
12863
12864     return (NO_ERROR);
12865 }
12866
12867
12868 int IsApplicable (Param *param)
12869 {
12870     if (param == NULL)
12871         return NO;
12872
12873     return YES;
12874 }
12875
12876
12877 int IsApplicable_ThreeTaxaOrMore (Param *param)
12878 {
12879     if (LargestMovableSubtree (param) >= 3)
12880         return YES;
12881     else
12882         return NO;
12883 }
12884
12885
12886 int IsApplicable_FourTaxaOrMore (Param *param)
12887 {
12888     if (LargestMovableSubtree (param) >= 4)
12889         return YES;
12890     else
12891         return NO;
12892 }
12893
12894
12895 int IsApplicable_FiveTaxaOrMore (Param *param)
12896 {
12897     if (LargestMovableSubtree (param) >= 5)
12898         return YES;
12899     else
12900         return NO;
12901 }
12902
12903
12904 int IsApplicable_TreeAgeMove (Param *param)
12905 {
12906     Tree        *t;
12907     TreeNode    *p;
12908
12909     if (param == NULL)
12910         return NO;
12911
12912     if (param->paramType != P_BRLENS)
12913         return NO;
12914     
12915     t = GetTree (param, 0, 0);
12916
12917     p = t->root->left;
12918     if (p->isDated == NO)
12919         return NO;
12920     if (p->calibration->prior == fixed)
12921         return NO;
12922     else
12923         return YES;
12924 }
12925
12926
12927 int IsApplicable_AncestralFossil (Param *param)
12928 {
12929     ModelParams *mp = &modelParams[param->relParts[0]];
12930
12931     if (!strcmp(mp->sampleStrat, "FossilTip"))
12932         return NO;
12933     else if (mp->fossilizationFix == 0.0)
12934         return NO;
12935     else  /* fossils may be ancestors of other fossils or extant species */
12936         return YES;
12937 }
12938
12939
12940 int IsModelSame (int whichParam, int part1, int part2, int *isApplic1, int *isApplic2)
12941 {
12942     int         i, isSame, isFirstNucleotide, isSecondNucleotide, isFirstProtein, isSecondProtein, nDiff, temp1, temp2;
12943
12944     isSame = YES;
12945     *isApplic1 = YES;
12946     *isApplic2 = YES;
12947
12948     /* We cannot rely on SetModelInfo being called first so we need to be smart in figuring out model data type by looking at several model params */
12949     isFirstNucleotide = isSecondNucleotide = NO;
12950     if ((modelParams[part1].dataType == DNA || modelParams[part1].dataType == RNA) && strcmp(modelParams[part1].nucModel,"Protein") != 0)
12951         isFirstNucleotide = YES;
12952     if ((modelParams[part2].dataType == DNA || modelParams[part2].dataType == RNA) && strcmp(modelParams[part2].nucModel,"Protein") != 0)
12953         isSecondNucleotide = YES;       
12954     isFirstProtein = isSecondProtein = NO;
12955     if (modelParams[part1].dataType == PROTEIN || ((modelParams[part1].dataType == DNA || modelParams[part1].dataType == RNA) && !strcmp(modelParams[part1].nucModel,"Protein")))
12956         isFirstProtein = YES;
12957     if (modelParams[part2].dataType == PROTEIN || ((modelParams[part2].dataType == DNA || modelParams[part2].dataType == RNA) && !strcmp(modelParams[part2].nucModel,"Protein")))
12958         isSecondProtein = YES;      
12959     
12960     if (whichParam == P_TRATIO)
12961         {
12962         /* Check the ti/tv rate ratio for partitions 1 and 2. */
12963
12964         /* Check if the model is parsimony for either partition */
12965         if (!strcmp(modelParams[part1].parsModel, "Yes"))
12966             *isApplic1 = NO; /* part1 has a parsimony model and tratio does not apply */
12967         if (!strcmp(modelParams[part2].parsModel, "Yes"))
12968             *isApplic2 = NO; /* part2 has a parsimony model and tratio does not apply */
12969         
12970         /* Check that the data are nucleotide for both partitions 1 and 2 */
12971         if (isFirstNucleotide == NO)
12972             *isApplic1 = NO; /* part1 is not nucleotide data so tratio does not apply */
12973         if (isSecondNucleotide == NO)
12974             *isApplic2 = NO; /* part2 is not nucleotide data so tratio does not apply */
12975         
12976         /* check that nst=2 for both partitions */
12977         if (strcmp(modelParams[part1].nst, "2"))
12978             *isApplic1 = NO; /* part1 does not have nst=2 and tratio does not apply */
12979         if (strcmp(modelParams[part2].nst, "2"))
12980             *isApplic2 = NO; /* part2 does not have nst=2 and tratio does not apply */
12981         
12982         /* Check if part1 & part2 are restriction */
12983         if (modelParams[part1].dataType == RESTRICTION)
12984             *isApplic1 = NO;
12985         if (modelParams[part2].dataType == RESTRICTION)
12986             *isApplic2 = NO;
12987
12988         /* If Nst = 2 for both part1 and part2, we now need to check if the prior is the same for both. */
12989         if (!strcmp(modelParams[part1].tRatioPr,"Beta") && !strcmp(modelParams[part2].tRatioPr,"Beta"))
12990             {
12991             if (AreDoublesEqual (modelParams[part1].tRatioDir[0], modelParams[part2].tRatioDir[0], (MrBFlt) 0.00001) == NO)
12992                 isSame = NO;
12993             if (AreDoublesEqual (modelParams[part1].tRatioDir[1], modelParams[part2].tRatioDir[1], (MrBFlt) 0.00001) == NO)
12994                 isSame = NO;
12995             }
12996         else if (!strcmp(modelParams[part1].tRatioPr,"Fixed") && !strcmp(modelParams[part2].tRatioPr,"Fixed"))
12997             {
12998             if (AreDoublesEqual (modelParams[part1].tRatioFix, modelParams[part2].tRatioFix, (MrBFlt) 0.00001) == NO)
12999                 isSame = NO;
13000             }
13001         else
13002             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13003
13004         /* Check to see if tratio is inapplicable for either partition. */
13005         if ((*isApplic1) == NO || (*isApplic2) == NO)
13006             isSame = NO; /* if tratio is inapplicable for either partition, then the parameter cannot be the same */
13007         }
13008     else if (whichParam == P_REVMAT)
13009         {
13010         /* Check the GTR rates for partitions 1 and 2. */
13011         
13012         /* Check if the model is parsimony for either partition */
13013         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13014             *isApplic1 = NO; /* part1 has a parsimony model and GTR rates do not apply */
13015         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13016             *isApplic2 = NO; /* part2 has a parsimony model and GTR rates do not apply */
13017
13018         /* Check that the data are nucleotide or protein for both partitions 1 and 2 */
13019         if (isFirstNucleotide == NO && isFirstProtein == NO)
13020             *isApplic1 = NO; /* part1 is not nucleotide or protein data so GTR rates do not apply */
13021         if (isSecondNucleotide == NO && isSecondProtein == NO)
13022             *isApplic2 = NO; /* part2 is not nucleotide or protein data so GTR rates do not apply */
13023
13024         /* check that nst=6 or mixed for both partitions if nucleotide */
13025         if (isFirstNucleotide == YES && strcmp(modelParams[part1].nst, "6") && strcmp(modelParams[part1].nst, "Mixed"))
13026             *isApplic1 = NO; /* part1 does not have nst=6/Mixed and GTR rates do not apply */
13027         if (isSecondNucleotide == YES && strcmp(modelParams[part2].nst, "6") && strcmp(modelParams[part2].nst, "Mixed"))
13028             *isApplic2 = NO; /* part2 does not have nst=6/Mixed and GTR rates do not apply */
13029             
13030         /* check that model is GTR for both partitions if protein */
13031         if (isFirstProtein == YES && (strcmp(modelParams[part1].aaModel,"Gtr")!=0 || strcmp(modelParams[part1].aaModelPr,"Fixed")!=0))
13032             *isApplic1 = NO;
13033         if (isSecondProtein == YES && (strcmp(modelParams[part2].aaModel,"Gtr")!=0 || strcmp(modelParams[part2].aaModelPr,"Fixed")!=0))
13034             *isApplic2 = NO;
13035
13036         /* check that data type is the same for both partitions */
13037         if (isFirstNucleotide == YES && isSecondNucleotide == NO)
13038             isSame = NO;
13039         if (isFirstProtein == YES && isSecondProtein == NO)
13040             isSame = NO;
13041
13042         /* GTR applies to both part1 and part2. We now need to check if the prior is the same for both. */
13043         if (isFirstNucleotide == YES)
13044             {
13045             if (strcmp(modelParams[part1].nst, modelParams[part2].nst) != 0)
13046                 isSame = NO;
13047             if (!strcmp(modelParams[part1].nst,"Mixed"))
13048                 {
13049                 if (AreDoublesEqual (modelParams[part1].revMatSymDir, modelParams[part2].revMatSymDir, (MrBFlt) 0.00001) == NO)
13050                     isSame = NO;
13051                 }
13052             else if (!strcmp(modelParams[part1].nst,"6") && !strcmp(modelParams[part1].revMatPr,"Dirichlet") && !strcmp(modelParams[part2].revMatPr,"Dirichlet"))
13053                 {
13054                 for (i=0; i<6; i++)
13055                     {
13056                     if (AreDoublesEqual (modelParams[part1].revMatDir[i], modelParams[part2].revMatDir[i], (MrBFlt) 0.00001) == NO)
13057                         isSame = NO;
13058                     }
13059                 }
13060             else if (!strcmp(modelParams[part1].nst,"6") && !strcmp(modelParams[part1].revMatPr,"Fixed") && !strcmp(modelParams[part2].revMatPr,"Fixed"))
13061                 {
13062                 for (i=0; i<6; i++)
13063                     {
13064                     if (AreDoublesEqual (modelParams[part1].revMatFix[i], modelParams[part2].revMatFix[i], (MrBFlt) 0.00001) == NO)
13065                         isSame = NO;
13066                     }
13067                 }
13068             else
13069                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13070             }
13071         else /* if (isFirstProtein == YES) */
13072             {
13073             if (!strcmp(modelParams[part1].aaRevMatPr,"Dirichlet") && !strcmp(modelParams[part2].aaRevMatPr,"Dirichlet"))
13074                 {
13075                 for (i=0; i<190; i++)
13076                     {
13077                     if (AreDoublesEqual (modelParams[part1].aaRevMatDir[i], modelParams[part2].aaRevMatDir[i], (MrBFlt) 0.00001) == NO)
13078                         isSame = NO;
13079                     }
13080                 }
13081             else if (!strcmp(modelParams[part1].aaRevMatPr,"Fixed") && !strcmp(modelParams[part2].aaRevMatPr,"Fixed"))
13082                 {
13083                 for (i=0; i<190; i++)
13084                     {
13085                     if (AreDoublesEqual (modelParams[part1].aaRevMatFix[i], modelParams[part2].aaRevMatFix[i], (MrBFlt) 0.00001) == NO)
13086                         isSame = NO;
13087                     }
13088                 }
13089             else
13090                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13091             }
13092
13093         /* Check to see if the GTR rates are inapplicable for either partition. */
13094         if ((*isApplic1) == NO || (*isApplic2) == NO)
13095             isSame = NO; /* if GTR rates are inapplicable for either partition, then the parameter cannot be the same */
13096         }
13097     else if (whichParam == P_OMEGA)
13098         {
13099         /* Check the nonsynonymous/synonymous rate ratio for partitions 1 and 2. */
13100         
13101         /* Check if the model is parsimony for either partition */
13102         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13103             *isApplic1 = NO; /* part1 has a parsimony model and nonsynonymous/synonymous rate ratio does not apply */
13104         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13105             *isApplic2 = NO; /* part2 has a parsimony model and nonsynonymous/synonymous rate ratio does not apply */
13106         
13107         /* Check that the data are nucleotide for both partitions 1 and 2 */
13108         if (isFirstNucleotide == NO)
13109             *isApplic1 = NO; /* part1 is not nucleotide data so a nonsynonymous/synonymous rate ratio does not apply */
13110         if (isSecondNucleotide == NO)
13111             *isApplic2 = NO; /* part2 is not nucleotide data so a nonsynonymous/synonymous rate ratio does not apply */
13112         
13113         /* Check that the model structure is the same for both. The nucmodel should be "codon". */
13114         if (strcmp(modelParams[part1].nucModel, "Codon"))
13115             *isApplic1 = NO; /* part1 does not have Nucmodel = Codon and nonsynonymous/synonymous rate ratio does not apply */
13116         if (strcmp(modelParams[part2].nucModel, "Codon"))
13117             *isApplic2 = NO; /* part2 does not have Nucmodel = Codon and nonsynonymous/synonymous rate ratio does not apply */
13118         
13119         /* Assuming that Nucmodel = Codon for both part1 and part2, we now need to check if the prior is the
13120            same for both. */
13121         if (!strcmp(modelParams[part1].omegaVar, "M3") && !strcmp(modelParams[part2].omegaVar, "M3"))
13122             {
13123             if (!strcmp(modelParams[part1].m3omegapr, "Exponential") && !strcmp(modelParams[part2].m3omegapr, "Exponential"))
13124                 {
13125                 }
13126             else if (!strcmp(modelParams[part1].m3omegapr, "Fixed") && !strcmp(modelParams[part1].m3omegapr, "Fixed"))
13127                 {
13128                 if (AreDoublesEqual (modelParams[part1].m3omegaFixed[0], modelParams[part2].m3omegaFixed[0], (MrBFlt) 0.00001) == NO)
13129                     isSame = NO;
13130                 if (AreDoublesEqual (modelParams[part1].m3omegaFixed[1], modelParams[part2].m3omegaFixed[1], (MrBFlt) 0.00001) == NO)
13131                     isSame = NO;
13132                 }
13133             else
13134                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13135
13136             if (!strcmp(modelParams[part1].codonCatFreqPr, "Dirichlet") && !strcmp(modelParams[part2].codonCatFreqPr, "Dirichlet"))
13137                 {
13138                 if (AreDoublesEqual (modelParams[part1].codonCatDir[0], modelParams[part2].codonCatDir[0], (MrBFlt) 0.00001) == NO)
13139                     isSame = NO;
13140                 if (AreDoublesEqual (modelParams[part1].codonCatDir[1], modelParams[part2].codonCatDir[1], (MrBFlt) 0.00001) == NO)
13141                     isSame = NO;
13142                 if (AreDoublesEqual (modelParams[part1].codonCatDir[2], modelParams[part2].codonCatDir[2], (MrBFlt) 0.00001) == NO)
13143                     isSame = NO;
13144                 }
13145             else if (!strcmp(modelParams[part1].codonCatFreqPr, "Fixed") && !strcmp(modelParams[part1].codonCatFreqPr, "Fixed"))
13146                 {
13147                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[0], modelParams[part2].codonCatFreqFix[0], (MrBFlt) 0.00001) == NO)
13148                     isSame = NO;
13149                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[1], modelParams[part2].codonCatFreqFix[1], (MrBFlt) 0.00001) == NO)
13150                     isSame = NO;
13151                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[2], modelParams[part2].codonCatFreqFix[2], (MrBFlt) 0.00001) == NO)
13152                     isSame = NO;
13153                 }
13154             else
13155                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13156             }
13157         else if (!strcmp(modelParams[part1].omegaVar, "M10") && !strcmp(modelParams[part2].omegaVar, "M10"))
13158             {           
13159             if (!strcmp(modelParams[part1].codonCatFreqPr, "Dirichlet") && !strcmp(modelParams[part2].codonCatFreqPr, "Dirichlet"))
13160                 {
13161                 if (AreDoublesEqual (modelParams[part1].codonCatDir[0], modelParams[part2].codonCatDir[0], (MrBFlt) 0.00001) == NO)
13162                     isSame = NO;
13163                 if (AreDoublesEqual (modelParams[part1].codonCatDir[1], modelParams[part2].codonCatDir[1], (MrBFlt) 0.00001) == NO)
13164                     isSame = NO;
13165                 }
13166             else if (!strcmp(modelParams[part1].codonCatFreqPr, "Fixed") && !strcmp(modelParams[part1].codonCatFreqPr, "Fixed"))
13167                 {
13168                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[0], modelParams[part2].codonCatFreqFix[0], (MrBFlt) 0.00001) == NO)
13169                     isSame = NO;
13170                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[1], modelParams[part2].codonCatFreqFix[1], (MrBFlt) 0.00001) == NO)
13171                     isSame = NO;
13172                 }
13173             else
13174                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13175             }
13176         else if (!strcmp(modelParams[part1].omegaVar, "Ny98") && !strcmp(modelParams[part2].omegaVar, "Ny98"))
13177             {
13178             if (!strcmp(modelParams[part1].ny98omega1pr, "Beta") && !strcmp(modelParams[part2].ny98omega1pr, "Beta"))
13179                 {
13180                 if (AreDoublesEqual (modelParams[part1].ny98omega1Beta[0], modelParams[part2].ny98omega1Beta[0], (MrBFlt) 0.00001) == NO)
13181                     isSame = NO;
13182                 if (AreDoublesEqual (modelParams[part1].ny98omega1Beta[1], modelParams[part2].ny98omega1Beta[1], (MrBFlt) 0.00001) == NO)
13183                     isSame = NO;
13184                 }
13185             else if (!strcmp(modelParams[part1].ny98omega1pr, "Fixed") && !strcmp(modelParams[part1].ny98omega1pr, "Fixed"))
13186                 {
13187                 if (AreDoublesEqual (modelParams[part1].ny98omega1Fixed, modelParams[part2].ny98omega1Fixed, (MrBFlt) 0.00001) == NO)
13188                     isSame = NO;
13189                 }
13190             else
13191                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13192             if (!strcmp(modelParams[part1].ny98omega3pr, "Uniform") && !strcmp(modelParams[part2].ny98omega3pr, "Uniform"))
13193                 {
13194                 if (AreDoublesEqual (modelParams[part1].ny98omega3Uni[0], modelParams[part2].ny98omega3Uni[0], (MrBFlt) 0.00001) == NO)
13195                     isSame = NO;
13196                 if (AreDoublesEqual (modelParams[part1].ny98omega3Uni[1], modelParams[part2].ny98omega3Uni[1], (MrBFlt) 0.00001) == NO)
13197                     isSame = NO;
13198                 }
13199             else if (!strcmp(modelParams[part1].ny98omega3pr, "Exponential") && !strcmp(modelParams[part1].ny98omega3pr, "Exponential"))
13200                 {
13201                 if (AreDoublesEqual (modelParams[part1].ny98omega3Exp, modelParams[part2].ny98omega3Exp, (MrBFlt) 0.00001) == NO)
13202                     isSame = NO;
13203                 }
13204             else if (!strcmp(modelParams[part1].ny98omega3pr, "Fixed") && !strcmp(modelParams[part1].ny98omega3pr, "Fixed"))
13205                 {
13206                 if (AreDoublesEqual (modelParams[part1].ny98omega3Fixed, modelParams[part2].ny98omega3Fixed, (MrBFlt) 0.00001) == NO)
13207                     isSame = NO;
13208                 }
13209             else
13210                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13211             if (!strcmp(modelParams[part1].codonCatFreqPr, "Dirichlet") && !strcmp(modelParams[part2].codonCatFreqPr, "Dirichlet"))
13212                 {
13213                 if (AreDoublesEqual (modelParams[part1].codonCatDir[0], modelParams[part2].codonCatDir[0], (MrBFlt) 0.00001) == NO)
13214                     isSame = NO;
13215                 if (AreDoublesEqual (modelParams[part1].codonCatDir[1], modelParams[part2].codonCatDir[1], (MrBFlt) 0.00001) == NO)
13216                     isSame = NO;
13217                 if (AreDoublesEqual (modelParams[part1].codonCatDir[2], modelParams[part2].codonCatDir[2], (MrBFlt) 0.00001) == NO)
13218                     isSame = NO;
13219                 }
13220             else if (!strcmp(modelParams[part1].codonCatFreqPr, "Fixed") && !strcmp(modelParams[part1].codonCatFreqPr, "Fixed"))
13221                 {
13222                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[0], modelParams[part2].codonCatFreqFix[0], (MrBFlt) 0.00001) == NO)
13223                     isSame = NO;
13224                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[1], modelParams[part2].codonCatFreqFix[1], (MrBFlt) 0.00001) == NO)
13225                     isSame = NO;
13226                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[2], modelParams[part2].codonCatFreqFix[2], (MrBFlt) 0.00001) == NO)
13227                     isSame = NO;
13228                 }
13229             else
13230                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13231             }
13232         else if (!strcmp(modelParams[part1].omegaVar, "Equal") && !strcmp(modelParams[part2].omegaVar, "Equal"))
13233             {
13234             if (!strcmp(modelParams[part1].omegaPr,"Dirichlet") && !strcmp(modelParams[part2].omegaPr,"Dirichlet"))
13235                 {
13236                 if (AreDoublesEqual (modelParams[part1].omegaDir[0], modelParams[part2].omegaDir[0], (MrBFlt) 0.00001) == NO)
13237                     isSame = NO;
13238                 if (AreDoublesEqual (modelParams[part1].omegaDir[1], modelParams[part2].omegaDir[1], (MrBFlt) 0.00001) == NO)
13239                     isSame = NO;
13240                 }
13241             else if (!strcmp(modelParams[part1].omegaPr,"Fixed") && !strcmp(modelParams[part2].omegaPr,"Fixed"))
13242                 {
13243                 if (AreDoublesEqual (modelParams[part1].omegaFix, modelParams[part2].omegaFix, (MrBFlt) 0.00001) == NO)
13244                     isSame = NO;
13245                 }
13246             else
13247                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13248             }
13249         else
13250             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13251         
13252         /* Check to see if omega is inapplicable for either partition. */
13253         if ((*isApplic1) == NO || (*isApplic2) == NO)
13254             isSame = NO; /* if omega is inapplicable for either partition, then the parameter cannot be the same */
13255         }
13256     else if (whichParam == P_PI)
13257         {
13258         /* Check the state frequencies for partitions 1 and 2. */
13259         
13260         /* Check if the model is parsimony for either partition */
13261         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13262             *isApplic1 = NO; /* part1 has a parsimony model and state frequencies do not apply */
13263         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13264             *isApplic2 = NO; /* part2 has a parsimony model and state frequencies do not apply */
13265
13266         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13267         if (modelParams[part1].dataType == CONTINUOUS)
13268             *isApplic1 = NO; /* state frequencies do not make sense for part1 */
13269         if (modelParams[part2].dataType == CONTINUOUS)
13270             *isApplic2 = NO; /* state frequencies do not make sense for part2 */
13271             
13272         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13273         if (isFirstNucleotide != isSecondNucleotide)
13274             isSame = NO; /* data are not both nucleotide or both note nucleotide */
13275         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13276             isSame = NO; /* data are not the same */
13277
13278         /* Check that the model structure is the same for both partitions */
13279         if (strcmp(modelParams[part1].nucModel, modelParams[part2].nucModel))
13280             isSame = NO; /* the nucleotide models are different */
13281         if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel) && !(!strcmp(modelParams[part1].nucModel, "Codon") && !strcmp(modelParams[part2].nucModel, "Codon")))
13282             isSame = NO; /* the models have different covarion struture */
13283             
13284         /* If both partitions have nucmodel=codon, then we also have to make certain that the same genetic code is used. */
13285         if (!strcmp(modelParams[part1].nucModel, "Codon") && !strcmp(modelParams[part2].nucModel, "Codon"))
13286             {
13287             if (strcmp(modelParams[part1].geneticCode, modelParams[part2].geneticCode))
13288                 isSame = NO; /* the models have different genetic codes */
13289             }
13290         
13291         /* Let's see if the prior is the same. */
13292         if (modelParams[part1].dataType == STANDARD && modelParams[part2].dataType == STANDARD)
13293             {
13294             /* The data are morphological (STANDARD). The state frequencies are specified by a
13295                symmetric beta distribution, the parameter of which needs to be the same to apply to both
13296                partitions. Note that symPiPr = -1 is equivalent to setting the variance to 0.0. */
13297             if (!strcmp(modelParams[part1].symPiPr,"Uniform") && !strcmp(modelParams[part2].symPiPr,"Uniform"))
13298                 {
13299                 if (AreDoublesEqual (modelParams[part1].symBetaUni[0], modelParams[part2].symBetaUni[0], (MrBFlt) 0.00001) == NO)
13300                     isSame = NO;
13301                 if (AreDoublesEqual (modelParams[part1].symBetaUni[1], modelParams[part2].symBetaUni[1], (MrBFlt) 0.00001) == NO)
13302                     isSame = NO;
13303                 if (modelParams[part1].numBetaCats != modelParams[part2].numBetaCats)
13304                     isSame = NO;    /* can't link because the discrete beta approximation is different */
13305                 }
13306             else if (!strcmp(modelParams[part1].symPiPr,"Exponential") && !strcmp(modelParams[part2].symPiPr,"Exponential"))
13307                 {
13308                 if (AreDoublesEqual (modelParams[part1].symBetaExp, modelParams[part2].symBetaExp, (MrBFlt) 0.00001) == NO)
13309                     isSame = NO;
13310                 if (modelParams[part1].numBetaCats != modelParams[part2].numBetaCats)
13311                     isSame = NO;    /* can't link because the discrete beta approximation is different */
13312                 }
13313             else if (!strcmp(modelParams[part1].symPiPr,"Fixed") && !strcmp(modelParams[part2].symPiPr,"Fixed"))
13314                 {
13315                 if (AreDoublesEqual (modelParams[part1].symBetaFix, modelParams[part2].symBetaFix, (MrBFlt) 0.00001) == NO)
13316                     isSame = NO;
13317                 if (AreDoublesEqual (modelParams[part1].symBetaFix, (MrBFlt) -1.0, (MrBFlt) 0.00001) == NO && modelParams[part1].numBetaCats != modelParams[part2].numBetaCats)
13318                     isSame = NO;    /* can't link because the discrete beta approximation is different */
13319                 }
13320             else
13321                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13322             }
13323         if (modelSettings[part1].dataType == PROTEIN && modelSettings[part2].dataType == PROTEIN)
13324             {
13325             /* We are dealing with protein data. */
13326             if (!strcmp(modelParams[part1].aaModelPr, modelParams[part2].aaModelPr))
13327                 {
13328                 if (!strcmp(modelParams[part1].aaModelPr, "Fixed"))
13329                     {
13330                     /* only have a single, fixed, amino acid rate matrix */
13331                     if (!strcmp(modelParams[part1].aaModel, modelParams[part2].aaModel))
13332                         {}
13333                     else
13334                         isSame = NO; /* we have different amino acid models, and the state frequencies must be different */
13335                     /* if we have an equalin model or Gtr model, then we need to check the prior on the state frequencies */
13336                     if (!strcmp(modelParams[part1].aaModel, "Equalin") || !strcmp(modelParams[part1].aaModel, "Gtr"))
13337                         {
13338                         if (!strcmp(modelParams[part1].stateFreqPr, modelParams[part2].stateFreqPr))
13339                             {
13340                             /* the prior form is the same */
13341                             if (!strcmp(modelParams[part1].stateFreqPr, "Dirichlet")) /* both prior models must be dirichlet */
13342                                 {
13343                                 for (i=0; i<modelParams[part1].nStates; i++)
13344                                     if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13345                                         isSame = NO; /* the dirichlet parameters are different */
13346                                 }
13347                             else /* both prior models must be fixed */
13348                                 {
13349                                 if (!strcmp(modelParams[part1].stateFreqsFixType, modelParams[part2].stateFreqsFixType))
13350                                     {
13351                                     /* if (!strcmp(modelParams[part1].stateFreqsFixType, "Empirical"))
13352                                         isSame = NO;     Even though it is unlikely that the empirical values for both partitions are exactly the same, we will
13353                                                          allow isSame to equal YES. This means pooled base frequencies are used to determine the empirical
13354                                                          base frequencies. The user can still unlink this parameter. */
13355                                     if (!strcmp(modelParams[part1].stateFreqsFixType, "User"))
13356                                         {
13357                                         for (i=0; i<modelParams[part1].nStates; i++)
13358                                             if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13359                                                 isSame = NO; /* the user-specified base frequencies are different */
13360                                         }
13361                                     /* if the frequencies were both fixed to "equal", we are golden, and they are the same */
13362                                     }
13363                                 else
13364                                     isSame = NO; /* the fixed parameters must be the same. The only other possibility is that the
13365                                                     user specified equal or empirical for one partition and then specified specific
13366                                                     numbers (user) for the other _and_ happened to set the user values to the equal
13367                                                     or empirical values. We ignore this possibility. */
13368                                 }
13369                             }
13370                         }
13371                     }
13372                 else
13373                     {
13374                     /* averaging over models */
13375                     if (linkTable[P_AAMODEL][part1] != linkTable[P_AAMODEL][part2])
13376                         isSame = NO; /* the amino acid model is mixed, but independently estimated */
13377                     }
13378                 }
13379             }
13380         else
13381             {
13382             /* Otherwise, we are dealing with RESTRICTION or NUCLEOTIDE data. The dirichlet should be the same
13383                for both partitions. */
13384             if (!strcmp(modelParams[part1].stateFreqPr, modelParams[part2].stateFreqPr))
13385                 {
13386                 /* the prior form is the same */
13387                 if (!strcmp(modelParams[part1].stateFreqPr, "Dirichlet")) /* both prior models must be dirichlet */
13388                     {
13389                     for (i=0; i<modelParams[part1].nStates; i++)
13390                         if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13391                             isSame = NO; /* the dirichlet parameters are different */
13392                     }
13393                 else /* both prior models must be fixed */
13394                     {
13395                     if (!strcmp(modelParams[part1].stateFreqsFixType, modelParams[part2].stateFreqsFixType))
13396                         {
13397                         /* if (!strcmp(modelParams[part1].stateFreqsFixType, "Empirical"))
13398                             isSame = NO;     Even though it is unlikely that the empirical values for both partitions are exactly the same, we will
13399                                              allow isSame to equal YES. This means pooled base frequencies are used to determine the empirical
13400                                              base frequencies. The user can still unlink this parameter. */
13401                         if (!strcmp(modelParams[part1].stateFreqsFixType, "User"))
13402                             {
13403                             for (i=0; i<modelParams[part1].nStates; i++)
13404                                 if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13405                                     isSame = NO; /* the user-specified base frequencies are different */
13406                             }
13407                         /* if the frequencies were both fixed to "equal", we are golden, and they are the same */
13408                         }
13409                     else
13410                         isSame = NO; /* the fixed parameters must be the same. The only other possibility is that the
13411                                         user specified equal or empirical for one partition and then specified specific
13412                                         numbers (user) for the other _and_ happened to set the user values to the equal
13413                                         or empirical values. We ignore this possibility. */
13414                     }
13415                 }
13416             }
13417
13418         /* Check to see if the state frequencies are inapplicable for either partition. */
13419         if ((*isApplic1) == NO || (*isApplic2) == NO)
13420             isSame = NO; /* if the state frequencies are inapplicable for either partition, then the parameter cannot be the same */
13421         }
13422     else if (whichParam == P_SHAPE)
13423         {
13424         /* Check the shape parameter for partitions 1 and 2. */
13425         
13426         /* Check if the model is parsimony for either partition */
13427         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13428             *isApplic1 = NO; /* part1 has a parsimony model and shape parameter does not apply */
13429         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13430             *isApplic2 = NO; /* part2 has a parsimony model and shape parameter does not apply */
13431
13432         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13433         if (modelParams[part1].dataType == CONTINUOUS)
13434             *isApplic1 = NO; /* the shape parameter does not make sense for part1 */
13435         if (modelParams[part2].dataType == CONTINUOUS)
13436             *isApplic2 = NO; /* the shape parameter does not make sense for part2 */
13437
13438         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13439         if (isFirstNucleotide != isSecondNucleotide)
13440             isSame = NO; /* data are not both nucleotide */
13441         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13442             isSame = NO; /* data are not the same */
13443
13444         /* Let's check that the shape parameter is even relevant for the two partitions */
13445         if (!strcmp(modelParams[part1].ratesModel, "Equal") || !strcmp(modelParams[part1].ratesModel, "Propinv"))
13446             *isApplic1 = NO; /* the shape parameter does not make sense for part1 */
13447         if (!strcmp(modelParams[part2].ratesModel, "Equal") || !strcmp(modelParams[part2].ratesModel, "Propinv"))
13448             *isApplic2 = NO; /* the shape parameter does not make sense for part2 */
13449         
13450         /* We may have a nucleotide model. Make certain the models are not of type codon. */
13451         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13452             *isApplic1 = NO; /* we have a codon model for part1, and a shape parameter does not apply */
13453         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13454             *isApplic2 = NO;/* we have a codon model for part2, and a shape parameter does not apply */
13455
13456         /* Check that the model structure is the same for both partitions */
13457         if ((!strcmp(modelParams[part1].nucModel, "4by4") || !strcmp(modelParams[part1].nucModel, "Doublet")) && !strcmp(modelParams[part2].nucModel, "Codon"))
13458             isSame = NO; /* the nucleotide models are incompatible with the same shape parameter */
13459         if ((!strcmp(modelParams[part2].nucModel, "4by4") || !strcmp(modelParams[part2].nucModel, "Doublet")) && !strcmp(modelParams[part1].nucModel, "Codon"))
13460             isSame = NO; /* the nucleotide models are incompatible with the same shape parameter */
13461         /* if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13462             isSame = NO; */ /* the models have different covarion struture */
13463         /* NOTE: Perhaps we should allow the possiblity that the shape parameter is the same for the case
13464                  where one partition has a covarion model but the other does not and both datatypes are the same. */
13465         
13466         /* Check that the number of rate categories is the same */
13467         if (modelParams[part1].numGammaCats != modelParams[part2].numGammaCats)
13468             isSame = NO; /* the number of rate categories is not the same, so we cannot set the parameter to be equal for both partitions */
13469
13470         /* Check that the priors are the same. */
13471         if (!strcmp(modelParams[part1].shapePr,"Uniform") && !strcmp(modelParams[part2].shapePr,"Uniform"))
13472             {
13473             if (AreDoublesEqual (modelParams[part1].shapeUni[0], modelParams[part2].shapeUni[0], (MrBFlt) 0.00001) == NO)
13474                 isSame = NO;
13475             if (AreDoublesEqual (modelParams[part1].shapeUni[1], modelParams[part2].shapeUni[1], (MrBFlt) 0.00001) == NO)
13476                 isSame = NO;
13477             }
13478         else if (!strcmp(modelParams[part1].shapePr,"Exponential") && !strcmp(modelParams[part2].shapePr,"Exponential"))
13479             {
13480             if (AreDoublesEqual (modelParams[part1].shapeExp, modelParams[part2].shapeExp, (MrBFlt) 0.00001) == NO)
13481                 isSame = NO;
13482             }
13483         else if (!strcmp(modelParams[part1].shapePr,"Fixed") && !strcmp(modelParams[part2].shapePr,"Fixed"))
13484             {
13485             if (AreDoublesEqual (modelParams[part1].shapeFix, modelParams[part2].shapeFix, (MrBFlt) 0.00001) == NO)
13486                 isSame = NO;
13487             }
13488         else
13489             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13490         
13491         /* Check to see if the shape parameter is inapplicable for either partition. */
13492         if ((*isApplic1) == NO || (*isApplic2) == NO)
13493             isSame = NO; /* if the shape parameter is inapplicable for either partition, then the parameter cannot be the same */
13494         }
13495     else if (whichParam == P_PINVAR)
13496         {
13497         /* Check the proportion of invariable sites parameter for partitions 1 and 2. */
13498         
13499         /* Check if the model is parsimony for either partition */
13500         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13501             *isApplic1 = NO; /* part1 has a parsimony model and proportion of invariable sites parameter does not apply */
13502         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13503             *isApplic2 = NO; /* part2 has a parsimony model and proportion of invariable sites parameter does not apply */
13504
13505         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13506         if (modelParams[part1].dataType == CONTINUOUS)
13507             *isApplic1 = NO; /* the proportion of invariable sites parameter does not make sense for part1 */
13508         if (modelParams[part2].dataType == CONTINUOUS)
13509             *isApplic2 = NO; /* the proportion of invariable sites parameter does not make sense for part2 */
13510
13511         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13512         if (isFirstNucleotide != isSecondNucleotide)
13513             isSame = NO; /* data are not both nucleotide */
13514         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13515             isSame = NO; /* data are not the same */
13516
13517         /* Let's check that proportion of invariable sites parameter is even relevant for the two partitions */
13518         if (!strcmp(modelParams[part1].ratesModel, "Equal") || !strcmp(modelParams[part1].ratesModel, "Gamma") ||
13519             !strcmp(modelParams[part1].ratesModel, "LNorm") || !strcmp(modelParams[part1].ratesModel, "Adgamma"))
13520             *isApplic1 = NO; /* the proportion of invariable sites parameter does not make sense for part1 */
13521         if (!strcmp(modelParams[part2].ratesModel, "Equal") || !strcmp(modelParams[part2].ratesModel, "Gamma") ||
13522             !strcmp(modelParams[part2].ratesModel, "LNorm") || !strcmp(modelParams[part2].ratesModel, "Adgamma"))
13523             *isApplic2 = NO; /* the proportion of invariable sites parameter does not make sense for part2 */
13524             
13525         /* It is not sensible to have a covarion model and a proportion of invariable sites */
13526         if (!strcmp(modelParams[part1].covarionModel, "Yes"))
13527             *isApplic1 = NO;
13528         if (!strcmp(modelParams[part2].covarionModel, "Yes"))
13529             *isApplic2 = NO;
13530         
13531         /* We have a nucleotide model. Make certain the models are not of type codon. */
13532         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13533             *isApplic1 = NO; /* we have a codon model for part1, and a proportion of invariable sites parameter does not apply */
13534         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13535             *isApplic2 = NO;/* we have a codon model for part2, and a proportion of invariable sites parameter does not apply */
13536
13537         /* Check that the model structure is the same for both partitions */
13538         if (strcmp(modelParams[part1].nucModel, modelParams[part2].nucModel))
13539             isSame = NO; /* the nucleotide models are different */
13540         if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13541             isSame = NO; /* the models have different covarion struture */
13542         
13543         /* check the priors */
13544         if (!strcmp(modelParams[part1].pInvarPr,"Uniform") && !strcmp(modelParams[part2].pInvarPr,"Uniform"))
13545             {
13546             if (AreDoublesEqual (modelParams[part1].pInvarUni[0], modelParams[part2].pInvarUni[0], (MrBFlt) 0.00001) == NO)
13547                 isSame = NO;
13548             if (AreDoublesEqual (modelParams[part1].pInvarUni[1], modelParams[part2].pInvarUni[1], (MrBFlt) 0.00001) == NO)
13549                 isSame = NO;
13550             }
13551         else if (!strcmp(modelParams[part1].pInvarPr,"Fixed") && !strcmp(modelParams[part2].pInvarPr,"Fixed"))
13552             {
13553             if (AreDoublesEqual (modelParams[part1].pInvarFix, modelParams[part2].pInvarFix, (MrBFlt) 0.00001) == NO)
13554                 isSame = NO;
13555             }
13556         else
13557             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13558         
13559         /* Check to see if the switching rates are inapplicable for either partition. */
13560         if ((*isApplic1) == NO || (*isApplic2) == NO)
13561             isSame = NO; /* if the switching rates are inapplicable for either partition, then the parameter cannot be the same */
13562         }
13563     else if (whichParam == P_CORREL)
13564         {
13565         /* Check the autocorrelation parameter for gamma rates on partitions 1 and 2. */
13566         
13567         /* Check if the model is parsimony for either partition */
13568         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13569             *isApplic1 = NO; /* part1 has a parsimony model and autocorrelation parameter does not apply */
13570         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13571             *isApplic2 = NO; /* part2 has a parsimony model and autocorrelation parameter does not apply */
13572
13573         /* Check that the data are either DNA, RNA, or PROTEIN for partitions 1 and 2 */
13574         if (modelSettings[part1].dataType != DNA && modelSettings[part1].dataType != RNA && modelSettings[part1].dataType != PROTEIN)
13575             *isApplic1 = NO; /* the switching rates do not make sense for part1 */
13576         if (modelSettings[part2].dataType != DNA && modelSettings[part2].dataType != RNA && modelSettings[part2].dataType != PROTEIN)
13577             *isApplic2 = NO; /* the switching rates do not make sense for part2 */
13578             
13579         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid). */
13580         if (isFirstNucleotide != isSecondNucleotide)
13581             isSame = NO; /* one or the other is nucleotide, so they cannot be the same */
13582         else if (modelSettings[part1].dataType != modelSettings[part2].dataType && isFirstNucleotide == NO)
13583             isSame = NO; /* data are not both nucleotide or both amino acid */
13584
13585         /* Let's check that autocorrelation parameter is even relevant for the two partitions */
13586         if (strcmp(modelParams[part1].ratesModel, "Adgamma"))
13587             *isApplic1 = NO; /* the autocorrelation parameter does not make sense for part1 */
13588         if (strcmp(modelParams[part2].ratesModel, "Adgamma"))
13589             *isApplic2 = NO; /* the autocorrelation parameter does not make sense for part2 */
13590
13591         /* Assuming that we have a nucleotide model, make certain the models are not of type codon. */
13592         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13593             *isApplic1 = NO; /* we have a codon model for part1, and a autocorrelation parameter does not apply */
13594         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13595             *isApplic2 = NO; /* we have a codon model for part2, and a autocorrelation parameter does not apply */
13596         
13597         /* Check that the model structure is the same for both partitions */
13598         if (strcmp(modelParams[part1].nucModel, modelParams[part2].nucModel))
13599             isSame = NO; /* the nucleotide models are different */
13600         if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13601             isSame = NO; /* the models have different covarion struture */
13602
13603         /* Check the priors for both partitions. */
13604         if (!strcmp(modelParams[part1].adGammaCorPr,"Uniform") && !strcmp(modelParams[part2].adGammaCorPr,"Uniform"))
13605             {
13606             if (AreDoublesEqual (modelParams[part1].corrUni[0], modelParams[part2].corrUni[0], (MrBFlt) 0.00001) == NO)
13607                 isSame = NO;
13608             if (AreDoublesEqual (modelParams[part1].corrUni[1], modelParams[part2].corrUni[1], (MrBFlt) 0.00001) == NO)
13609                 isSame = NO;
13610             }
13611         else if (!strcmp(modelParams[part1].adGammaCorPr,"Fixed") && !strcmp(modelParams[part2].adGammaCorPr,"Fixed"))
13612             {
13613             if (AreDoublesEqual (modelParams[part1].corrFix, modelParams[part2].corrFix, (MrBFlt) 0.00001) == NO)
13614                 isSame = NO;
13615             }
13616         else
13617             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13618
13619         /* Check to see if the switching rates are inapplicable for either partition. */
13620         if ((*isApplic1) == NO || (*isApplic2) == NO)
13621             isSame = NO; /* if the switching rates are inapplicable for either partition, then the parameter cannot be the same */
13622         }
13623     else if (whichParam == P_SWITCH)
13624         {
13625         /* Check the covarion switching rates on partitions 1 and 2. */
13626         
13627         /* Check if the model is parsimony for either partition */
13628         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13629             *isApplic1 = NO; /* part1 has a parsimony model and switching rates do not apply */
13630         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13631             *isApplic2 = NO; /* part2 has a parsimony model and switching rates do not apply */
13632         
13633         /* Check that the data are either DNA, RNA, or PROTEIN for partitions 1 and 2 */
13634         if (modelSettings[part1].dataType != DNA && modelSettings[part1].dataType != RNA && modelSettings[part1].dataType != PROTEIN)
13635             *isApplic1 = NO; /* the switching rates do not make sense for part1 */
13636         if (modelSettings[part2].dataType != DNA && modelSettings[part2].dataType != RNA && modelSettings[part2].dataType != PROTEIN)
13637             *isApplic2 = NO; /* the switching rates do not make sense for part2 */
13638             
13639         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid). */
13640         if (isFirstNucleotide != isSecondNucleotide)
13641             isSame = NO; /* one or the other is nucleotide, so they cannot be the same */
13642         else if (modelSettings[part1].dataType != modelSettings[part2].dataType && isFirstNucleotide == NO)
13643             isSame = NO; /* data are not both nucleotide or both amino acid */
13644
13645         /* Lets check that covarion model has been selected for partitions 1 and 2 */
13646         if (!strcmp(modelParams[part1].covarionModel, "No"))
13647             *isApplic1 = NO; /* the switching rates do not make sense for part1 */
13648         if (!strcmp(modelParams[part2].covarionModel, "No"))
13649             *isApplic2 = NO; /* the switching rates do not make sense for part2 */
13650
13651         /* If we have a nucleotide model make certain the models are not of type codon or doublet. */
13652         if (!strcmp(modelParams[part1].nucModel, "Codon") || !strcmp(modelParams[part1].nucModel, "Doublet"))
13653             *isApplic1 = NO; /* we have a codon model for part1, and a covarion switch parameter does not apply */
13654         if (!strcmp(modelParams[part2].nucModel, "Codon") || !strcmp(modelParams[part2].nucModel, "Doublet"))
13655             *isApplic2 = NO; /* we have a codon model for part2, and a covarion switch parameter does not apply */
13656
13657         /* Check that the priors are the same. */
13658         if (!strcmp(modelParams[part1].covSwitchPr,"Uniform") && !strcmp(modelParams[part2].covSwitchPr,"Uniform"))
13659             {
13660             if (AreDoublesEqual (modelParams[part1].covswitchUni[0], modelParams[part2].covswitchUni[0], (MrBFlt) 0.00001) == NO)
13661                 isSame = NO;
13662             if (AreDoublesEqual (modelParams[part1].covswitchUni[1], modelParams[part2].covswitchUni[1], (MrBFlt) 0.00001) == NO)
13663                 isSame = NO;
13664             }
13665         else if (!strcmp(modelParams[part1].covSwitchPr,"Exponential") && !strcmp(modelParams[part2].covSwitchPr,"Exponential"))
13666             {
13667             if (AreDoublesEqual (modelParams[part1].covswitchExp, modelParams[part2].covswitchExp, (MrBFlt) 0.00001) == NO)
13668                 isSame = NO;
13669             }
13670         else if (!strcmp(modelParams[part1].covSwitchPr,"Fixed") && !strcmp(modelParams[part2].covSwitchPr,"Fixed"))
13671             {
13672             if (AreDoublesEqual (modelParams[part1].covswitchFix[0], modelParams[part2].covswitchFix[0], (MrBFlt) 0.00001) == NO)
13673                 isSame = NO;
13674             if (AreDoublesEqual (modelParams[part1].covswitchFix[1], modelParams[part2].covswitchFix[1], (MrBFlt) 0.00001) == NO)
13675                 isSame = NO;
13676             }
13677         else
13678             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13679
13680         /* Check to see if the switching rates are inapplicable for either partition. */
13681         if ((*isApplic1) == NO || (*isApplic2) == NO)
13682             isSame = NO; /* if the switching rates are inapplicable for either partition, then the parameter cannot be the same */
13683         }
13684     else if (whichParam == P_RATEMULT)
13685         {
13686         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
13687            silly and doesn't take this information into account) and a rate multiplier is nonsensical. */
13688         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13689             *isApplic1 = NO; 
13690         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13691             *isApplic2 = NO; 
13692         
13693         /* Check that the branch lengths are at least proportional. */
13694         if (IsModelSame (P_BRLENS, part1, part2, &temp1, &temp2) == NO)
13695             isSame = NO;
13696         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
13697             isSame = NO;
13698
13699         /* See if the rate prior is the same for the partitions */
13700         if (strcmp(modelParams[part1].ratePr, modelParams[part2].ratePr) != 0)
13701             isSame = NO;
13702
13703         /* Check to see if rate multipliers are inapplicable for either partition. */
13704         if ((*isApplic1) == NO || (*isApplic2) == NO)
13705             isSame = NO; 
13706             
13707         }
13708     else if (whichParam == P_TOPOLOGY)
13709         {
13710         /* Check the topology for partitions 1 and 2. */
13711         
13712         /* If the prior is different, then the topologies cannot be the same. */
13713         if (strcmp(modelParams[part1].topologyPr, modelParams[part2].topologyPr))
13714             isSame = NO;
13715
13716         /* If both partitions have topologies constrained, then we need to make certain that the constraints are the same. */
13717         /* This also guarantees that any calibrations will be the same. */
13718         if (!strcmp(modelParams[part1].topologyPr, "Constraints") && !strcmp(modelParams[part2].topologyPr, "Constraints"))
13719             {
13720             if (modelParams[part1].numActiveConstraints != modelParams[part2].numActiveConstraints)
13721                 isSame = NO;
13722             else
13723                 {
13724                 nDiff = 0;
13725                 for (i=0; i<numDefinedConstraints; i++)
13726                     if (modelParams[part1].activeConstraints[i] != modelParams[part2].activeConstraints[i])
13727                         nDiff++;
13728                 if (nDiff != 0)
13729                     isSame = NO;
13730                 }
13731             }
13732         }
13733     else if (whichParam == P_BRLENS)
13734         {
13735         /* Check the branch lengths for partitions 1 and 2. */
13736
13737         /* First, if the topologies are different, the same branch lengths cannot apply. */
13738         if (IsModelSame (P_TOPOLOGY, part1, part2, &temp1, &temp2) == NO)
13739             isSame = NO;
13740         if (linkTable[P_TOPOLOGY][part1] != linkTable[P_TOPOLOGY][part2])
13741             isSame = NO;
13742
13743         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
13744            silly and doesn't take this information into account). */
13745         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13746             *isApplic1 = NO; 
13747         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13748             *isApplic2 = NO;
13749
13750         /* Check to see if the branch lengths are inapplicable for either partition. */
13751         if ((*isApplic1) == NO || (*isApplic2) == NO)
13752             isSame = NO;
13753
13754         /* Make sure the branch lengths have the same priors and are not unlinked */
13755         if (*isApplic1 == YES && *isApplic2 == YES)
13756             {
13757             /* We are dealing with real branch lengths (not parsimony) for both partitions */
13758             
13759             /* The branch length prior should be the same */
13760             if (strcmp(modelParams[part1].brlensPr, modelParams[part2].brlensPr))
13761                 isSame = NO;
13762                 
13763             /* if both partitions have unconstrained brlens, then we need to check that the priors on the branch lengths are the same */
13764             if (!strcmp(modelParams[part1].brlensPr, "Unconstrained") && !strcmp(modelParams[part2].brlensPr, "Unconstrained"))
13765                 {
13766                 if (strcmp(modelParams[part1].unconstrainedPr, modelParams[part2].unconstrainedPr))
13767                     isSame = NO;
13768                 else
13769                     {
13770                     if (!strcmp(modelParams[part1].unconstrainedPr, "Uniform"))
13771                         {
13772                         if (AreDoublesEqual (modelParams[part1].brlensUni[0], modelParams[part2].brlensUni[0], (MrBFlt) 0.00001) == NO)
13773                             isSame = NO;
13774                         if (AreDoublesEqual (modelParams[part1].brlensUni[1], modelParams[part2].brlensUni[1], (MrBFlt) 0.00001) == NO)
13775                             isSame = NO;
13776                         }
13777                     else if (!strcmp(modelParams[part1].unconstrainedPr, "Exponential"))
13778                         {
13779                         if (AreDoublesEqual (modelParams[part1].brlensExp, modelParams[part2].brlensExp, (MrBFlt) 0.00001) == NO)
13780                             isSame = NO;
13781                         }
13782                     else if (!strcmp(modelParams[part1].unconstrainedPr, "twoExp"))
13783                         {
13784                             if (AreDoublesEqual (modelParams[part1].brlens2Exp[0], modelParams[part2].brlens2Exp[0], (MrBFlt) 0.00001) == NO)
13785                                 isSame = NO;
13786                             if (AreDoublesEqual (modelParams[part1].brlens2Exp[1], modelParams[part2].brlens2Exp[1], (MrBFlt) 0.00001) == NO)
13787                                 isSame = NO;
13788                         }
13789                     else
13790                         {
13791                         if (AreDoublesEqual (modelParams[part1].brlensDir[0], modelParams[part2].brlensDir[0], (MrBFlt) 0.00001) == NO)  
13792                             isSame = NO;
13793                         if (AreDoublesEqual (modelParams[part1].brlensDir[1], modelParams[part2].brlensDir[1], (MrBFlt) 0.00001) == NO) 
13794                             isSame = NO;
13795                         if (AreDoublesEqual (modelParams[part1].brlensDir[2], modelParams[part2].brlensDir[2], (MrBFlt) 0.00001) == NO)  
13796                             isSame = NO;
13797                         if (AreDoublesEqual (modelParams[part1].brlensDir[3], modelParams[part2].brlensDir[3], (MrBFlt) 0.00001) == NO) 
13798                             isSame = NO;
13799                         }   
13800                     }
13801                 }
13802             
13803             /* if both partitions have clock brlens, then we need to check that the priors on the clock are the same */
13804             if (!strcmp(modelParams[part1].brlensPr, "Clock") && !strcmp(modelParams[part2].brlensPr, "Clock"))
13805                 {
13806                 if (strcmp(modelParams[part1].clockPr, modelParams[part2].clockPr))
13807                     isSame = NO;
13808                 else
13809                     {
13810                     if (!strcmp(modelParams[part1].clockPr, "Birthdeath"))
13811                         {
13812                         if (!strcmp(modelParams[part1].speciationPr,"Uniform") && !strcmp(modelParams[part2].speciationPr,"Uniform"))
13813                             {
13814                             if (AreDoublesEqual (modelParams[part1].speciationUni[0], modelParams[part2].speciationUni[0], (MrBFlt) 0.00001) == NO)
13815                                 isSame = NO;
13816                             if (AreDoublesEqual (modelParams[part1].speciationUni[1], modelParams[part2].speciationUni[1], (MrBFlt) 0.00001) == NO)
13817                                 isSame = NO;
13818                             }
13819                         else if (!strcmp(modelParams[part1].speciationPr,"Exponential") && !strcmp(modelParams[part2].speciationPr,"Exponential"))
13820                             {
13821                             if (AreDoublesEqual (modelParams[part1].speciationExp, modelParams[part2].speciationExp, (MrBFlt) 0.00001) == NO)
13822                                 isSame = NO;
13823                             }
13824                         else if (!strcmp(modelParams[part1].speciationPr,"Fixed") && !strcmp(modelParams[part2].speciationPr,"Fixed"))
13825                             {
13826                             if (AreDoublesEqual (modelParams[part1].speciationFix, modelParams[part2].speciationFix, (MrBFlt) 0.00001) == NO)
13827                                 isSame = NO;
13828                             }
13829                         else
13830                             isSame = NO;
13831
13832                         if (!strcmp(modelParams[part1].extinctionPr,"Beta") && !strcmp(modelParams[part2].extinctionPr,"Beta"))
13833                             {
13834                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[0], modelParams[part2].extinctionBeta[0], (MrBFlt) 0.00001) == NO)
13835                                 isSame = NO;
13836                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[1], modelParams[part2].extinctionBeta[1], (MrBFlt) 0.00001) == NO)
13837                                 isSame = NO;
13838                             }
13839                         else if (!strcmp(modelParams[part1].extinctionPr,"Fixed") && !strcmp(modelParams[part2].extinctionPr,"Fixed"))
13840                             {
13841                             if (AreDoublesEqual (modelParams[part1].extinctionFix, modelParams[part2].extinctionFix, (MrBFlt) 0.00001) == NO)
13842                                 isSame = NO;
13843                             }
13844                         else
13845                             isSame = NO;
13846
13847                         if (AreDoublesEqual (modelParams[part1].sampleProb, modelParams[part2].sampleProb, 0.00001) == NO)
13848                             isSame = NO;
13849                         if (strcmp(modelParams[part1].sampleStrat,modelParams[part2].sampleStrat))
13850                             isSame = NO;
13851                         }
13852                     else if (!strcmp(modelParams[part1].clockPr, "Coalescence") || !strcmp(modelParams[part1].clockPr, "Speciestreecoalescence"))
13853                         {
13854                         if (!strcmp(modelParams[part1].popSizePr,"Uniform") && !strcmp(modelParams[part2].popSizePr,"Uniform"))
13855                             {
13856                             if (AreDoublesEqual (modelParams[part1].popSizeUni[0], modelParams[part2].popSizeUni[0], (MrBFlt) 0.00001) == NO)
13857                                 isSame = NO;
13858                             if (AreDoublesEqual (modelParams[part1].popSizeUni[1], modelParams[part2].popSizeUni[1], (MrBFlt) 0.00001) == NO)
13859                                 isSame = NO;
13860                             }
13861                         else if (!strcmp(modelParams[part1].popSizePr,"Lognormal") && !strcmp(modelParams[part2].popSizePr,"Lognormal"))
13862                             {
13863                             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[0], modelParams[part2].popSizeLognormal[0], (MrBFlt) 0.00001) == NO)
13864                                 isSame = NO;
13865                             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[1], modelParams[part2].popSizeLognormal[1], (MrBFlt) 0.00001) == NO)
13866                                 isSame = NO;
13867                             }
13868                         else if (!strcmp(modelParams[part1].popSizePr,"Normal") && !strcmp(modelParams[part2].popSizePr,"Normal"))
13869                             {
13870                             if (AreDoublesEqual (modelParams[part1].popSizeNormal[0], modelParams[part2].popSizeNormal[0], (MrBFlt) 0.00001) == NO)
13871                                 isSame = NO;
13872                             if (AreDoublesEqual (modelParams[part1].popSizeNormal[1], modelParams[part2].popSizeNormal[1], (MrBFlt) 0.00001) == NO)
13873                                 isSame = NO;
13874                             }
13875                         else if (!strcmp(modelParams[part1].popSizePr,"Gamma") && !strcmp(modelParams[part2].popSizePr,"Gamma"))
13876                             {
13877                             if (AreDoublesEqual (modelParams[part1].popSizeGamma[0], modelParams[part2].popSizeGamma[0], (MrBFlt) 0.00001) == NO)
13878                                 isSame = NO;
13879                             if (AreDoublesEqual (modelParams[part1].popSizeGamma[1], modelParams[part2].popSizeGamma[1], (MrBFlt) 0.00001) == NO)
13880                                 isSame = NO;
13881                             }
13882                         else if (!strcmp(modelParams[part1].popSizePr,"Fixed") && !strcmp(modelParams[part2].popSizePr,"Fixed"))
13883                             {
13884                             if (AreDoublesEqual (modelParams[part1].popSizeFix, modelParams[part2].popSizeFix, (MrBFlt) 0.00001) == NO)
13885                                 isSame = NO;
13886                             }
13887                         else
13888                             isSame = NO;
13889
13890                         if (strcmp(modelParams[part1].ploidy, modelParams[part2].ploidy) != 0)
13891                             isSame = NO;
13892                         }
13893                     if (strcmp(modelParams[part1].clockPr, "Uniform") == 0 && strcmp(modelParams[part1].nodeAgePr, "Calibrated") != 0)
13894                         {
13895                         if (modelParams[part1].treeAgePr.prior != modelParams[part2].treeAgePr.prior)
13896                             isSame = NO;
13897                         if (modelParams[part1].treeAgePr.prior == fixed)
13898                             {
13899                             if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[0], modelParams[part2].treeAgePr.priorParams[0], (MrBFlt) 0.00001) == NO)
13900                                 isSame = NO;
13901                             }
13902                         else if (modelParams[part1].treeAgePr.prior == offsetLogNormal ||
13903                             modelParams[part1].treeAgePr.prior == truncatedNormal ||
13904                             modelParams[part1].treeAgePr.prior == offsetGamma)
13905                             {
13906                             for (i=0; i<3; i++)
13907                                 {
13908                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
13909                                     isSame = NO;
13910                                 }
13911                             }
13912                         else
13913                             {
13914                             for (i=0; i<2; i++)
13915                                 {
13916                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
13917                                     isSame = NO;
13918                                 }
13919                             }
13920                         }
13921                     else if (strcmp(modelParams[part1].clockPr, "Fossilization") == 0)
13922                         {
13923                         if (modelParams[part1].treeAgePr.prior != modelParams[part2].treeAgePr.prior)
13924                             isSame = NO;
13925                         if (modelParams[part1].treeAgePr.prior == fixed)
13926                             {
13927                             if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[0], modelParams[part2].treeAgePr.priorParams[0], (MrBFlt) 0.00001) == NO)
13928                                 isSame = NO;
13929                             }
13930                         else if (modelParams[part1].treeAgePr.prior == offsetLogNormal ||
13931                             modelParams[part1].treeAgePr.prior == truncatedNormal ||
13932                             modelParams[part1].treeAgePr.prior == offsetGamma)
13933                             {
13934                             for (i=0; i<3; i++)
13935                                 {
13936                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
13937                                     isSame = NO;
13938                                 }
13939                             }
13940                         else
13941                             {
13942                             for (i=0; i<2; i++)
13943                                 {
13944                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
13945                                     isSame = NO;
13946                                 }
13947                             }
13948                         
13949                         if (!strcmp(modelParams[part1].speciationPr,"Uniform") && !strcmp(modelParams[part2].speciationPr,"Uniform"))
13950                             {
13951                             if (AreDoublesEqual (modelParams[part1].speciationUni[0], modelParams[part2].speciationUni[0], (MrBFlt) 0.00001) == NO)
13952                                 isSame = NO;
13953                             if (AreDoublesEqual (modelParams[part1].speciationUni[1], modelParams[part2].speciationUni[1], (MrBFlt) 0.00001) == NO)
13954                                 isSame = NO;
13955                             }
13956                         else if (!strcmp(modelParams[part1].speciationPr,"Exponential") && !strcmp(modelParams[part2].speciationPr,"Exponential"))
13957                             {
13958                             if (AreDoublesEqual (modelParams[part1].speciationExp, modelParams[part2].speciationExp, (MrBFlt) 0.00001) == NO)
13959                                 isSame = NO;
13960                             }
13961                         else if (!strcmp(modelParams[part1].speciationPr,"Fixed") && !strcmp(modelParams[part2].speciationPr,"Fixed"))
13962                             {
13963                             if (AreDoublesEqual (modelParams[part1].speciationFix, modelParams[part2].speciationFix, (MrBFlt) 0.00001) == NO)
13964                                 isSame = NO;
13965                             }
13966                         else
13967                             isSame = NO;
13968                         
13969                         if (!strcmp(modelParams[part1].extinctionPr,"Beta") && !strcmp(modelParams[part2].extinctionPr,"Beta"))
13970                             {
13971                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[0], modelParams[part2].extinctionBeta[0], (MrBFlt) 0.00001) == NO)
13972                                 isSame = NO;
13973                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[1], modelParams[part2].extinctionBeta[1], (MrBFlt) 0.00001) == NO)
13974                                 isSame = NO;
13975                             }
13976                         else if (!strcmp(modelParams[part1].extinctionPr,"Fixed") && !strcmp(modelParams[part2].extinctionPr,"Fixed"))
13977                             {
13978                             if (AreDoublesEqual (modelParams[part1].extinctionFix, modelParams[part2].extinctionFix, (MrBFlt) 0.00001) == NO)
13979                                 isSame = NO;
13980                             }
13981                         else
13982                             isSame = NO;
13983                         
13984                         if (!strcmp(modelParams[part1].fossilizationPr,"Beta") && !strcmp(modelParams[part2].fossilizationPr,"Beta"))
13985                             {
13986                             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[0], modelParams[part2].fossilizationBeta[0], (MrBFlt) 0.00001) == NO)
13987                                 isSame = NO;
13988                             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[1], modelParams[part2].fossilizationBeta[1], (MrBFlt) 0.00001) == NO)
13989                                 isSame = NO;
13990                             }
13991                         else if (!strcmp(modelParams[part1].fossilizationPr,"Fixed") && !strcmp(modelParams[part2].fossilizationPr,"Fixed"))
13992                             {
13993                             if (AreDoublesEqual (modelParams[part1].fossilizationFix, modelParams[part2].fossilizationFix, (MrBFlt) 0.00001) == NO)
13994                                 isSame = NO;
13995                             }
13996                         else
13997                             isSame = NO;
13998                         
13999                         if (AreDoublesEqual (modelParams[part1].sampleProb, modelParams[part2].sampleProb, 0.00001) == NO)
14000                             isSame = NO;
14001                         if (strcmp(modelParams[part1].sampleStrat,modelParams[part2].sampleStrat))
14002                             isSame = NO;
14003                         }
14004                     }
14005
14006                 /* if the same clock prior, we need to check calibrations */
14007                 if (strcmp(modelParams[part1].nodeAgePr,modelParams[part2].nodeAgePr) != 0)
14008                     isSame = NO;
14009                 
14010                 /* If fixed clock brlens, check if the brlens come from the same tree */
14011                 if (!strcmp(modelParams[part1].clockPr, "Fixed") && !strcmp(modelParams[part2].clockPr, "Fixed"))
14012                     {
14013                     if (modelParams[part1].brlensFix != modelParams[part2].brlensFix)
14014                         isSame = NO;
14015                     }
14016                 }
14017             /* If fixed brlens, check if the brlens come from the same tree */
14018             if (!strcmp(modelParams[part1].brlensPr, "Fixed") && !strcmp(modelParams[part2].brlensPr, "Fixed"))
14019                 {
14020                 if (modelParams[part1].brlensFix != modelParams[part2].brlensFix)
14021                     isSame = NO;
14022                 }
14023             }
14024         }
14025     else if (whichParam == P_SPECRATE)
14026         {
14027         /* Check the speciation rates for partitions 1 and 2. */
14028
14029         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14030            silly and doesn't take this information into account) and a speciation rate cannot be estimated. */
14031         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14032             *isApplic1 = NO; 
14033         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14034             *isApplic2 = NO; 
14035             
14036         /* Check that the branch length prior is a clock:birthdeath or clock:fossilization for both partitions. */
14037         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14038             *isApplic1 = NO;
14039         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14040             *isApplic2 = NO;
14041         if (strcmp(modelParams[part1].clockPr, "Birthdeath") != 0 && strcmp(modelParams[part1].clockPr, "Fossilization") != 0)
14042             *isApplic1 = NO;
14043         if (strcmp(modelParams[part2].clockPr, "Birthdeath") != 0 && strcmp(modelParams[part2].clockPr, "Fossilization") != 0)
14044             *isApplic2 = NO;
14045         
14046         /* Now, check that the prior on the speciation rates are the same. */
14047         if (!strcmp(modelParams[part1].speciationPr,"Uniform") && !strcmp(modelParams[part2].speciationPr,"Uniform"))
14048             {
14049             if (AreDoublesEqual (modelParams[part1].speciationUni[0], modelParams[part2].speciationUni[0], (MrBFlt) 0.00001) == NO)
14050                 isSame = NO;
14051             if (AreDoublesEqual (modelParams[part1].speciationUni[1], modelParams[part2].speciationUni[1], (MrBFlt) 0.00001) == NO)
14052                 isSame = NO;
14053             }
14054         else if (!strcmp(modelParams[part1].speciationPr,"Exponential") && !strcmp(modelParams[part2].speciationPr,"Exponential"))
14055             {
14056             if (AreDoublesEqual (modelParams[part1].speciationExp, modelParams[part2].speciationExp, (MrBFlt) 0.00001) == NO)
14057                 isSame = NO;
14058             }
14059         else if (!strcmp(modelParams[part1].speciationPr,"Fixed") && !strcmp(modelParams[part2].speciationPr,"Fixed"))
14060             {
14061             if (AreDoublesEqual (modelParams[part1].speciationFix, modelParams[part2].speciationFix, (MrBFlt) 0.00001) == NO)
14062                 isSame = NO;
14063             }
14064         else
14065             isSame = NO;
14066         
14067         /* Check to see if the speciation rates are inapplicable for either partition. */
14068         if ((*isApplic1) == NO || (*isApplic2) == NO)
14069             isSame = NO;
14070         }
14071     else if (whichParam == P_EXTRATE)
14072         {
14073         /* Check the extinction rates for partitions 1 and 2. */
14074
14075         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14076            silly and doesn't take this information into account) and a extinction rate cannot be estimated. */
14077         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14078             *isApplic1 = NO; 
14079         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14080             *isApplic2 = NO; 
14081             
14082         /* Check that the branch length prior is a clock:birthdeath or clock:fossilization for both partitions. */
14083         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14084             *isApplic1 = NO;
14085         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14086             *isApplic2 = NO;
14087         if (strcmp(modelParams[part1].clockPr, "Birthdeath")!= 0 && strcmp(modelParams[part1].clockPr, "Fossilization") != 0)
14088             *isApplic1 = NO;
14089         if (strcmp(modelParams[part2].clockPr, "Birthdeath")!= 0 && strcmp(modelParams[part2].clockPr, "Fossilization") != 0)
14090             *isApplic2 = NO;
14091         
14092         /* Now, check that the prior on the extinction rates are the same. */
14093         if (!strcmp(modelParams[part1].extinctionPr,"Beta") && !strcmp(modelParams[part2].extinctionPr,"Beta"))
14094             {
14095             if (AreDoublesEqual (modelParams[part1].extinctionBeta[0], modelParams[part2].extinctionBeta[0], (MrBFlt) 0.00001) == NO)
14096                 isSame = NO;
14097             if (AreDoublesEqual (modelParams[part1].extinctionBeta[1], modelParams[part2].extinctionBeta[1], (MrBFlt) 0.00001) == NO)
14098                 isSame = NO;
14099             }
14100         else if (!strcmp(modelParams[part1].extinctionPr,"Fixed") && !strcmp(modelParams[part2].extinctionPr,"Fixed"))
14101             {
14102             if (AreDoublesEqual (modelParams[part1].extinctionFix, modelParams[part2].extinctionFix, (MrBFlt) 0.00001) == NO)
14103                 isSame = NO;
14104             }
14105         else
14106             isSame = NO;
14107         
14108         /* Check to see if the extinction rates are inapplicable for either partition. */
14109         if ((*isApplic1) == NO || (*isApplic2) == NO)
14110             isSame = NO;
14111         }
14112     else if (whichParam == P_FOSLRATE)
14113         {
14114         /* Check the fossilization rates for partitions 1 and 2. */
14115         
14116         /* Check if the model is parsimony for either partition. */
14117         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14118             *isApplic1 = NO;
14119         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14120             *isApplic2 = NO;
14121         
14122         /* Check that the branch length prior is a clock:birthdeath or clock:fossilization for both partitions. */
14123         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14124             *isApplic1 = NO;
14125         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14126             *isApplic2 = NO;
14127         if (strcmp(modelParams[part1].clockPr, "Fossilization") != 0)
14128             *isApplic1 = NO;
14129         if (strcmp(modelParams[part2].clockPr, "Fossilization") != 0)
14130             *isApplic2 = NO;
14131         
14132         /* Now, check that the prior on the fossilization rates are the same. */
14133         if (!strcmp(modelParams[part1].fossilizationPr,"Beta") && !strcmp(modelParams[part2].fossilizationPr,"Beta"))
14134             {
14135             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[0], modelParams[part2].fossilizationBeta[0], (MrBFlt) 0.00001) == NO)
14136                 isSame = NO;
14137             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[1], modelParams[part2].fossilizationBeta[1], (MrBFlt) 0.00001) == NO)
14138                 isSame = NO;
14139             }
14140         else if (!strcmp(modelParams[part1].fossilizationPr,"Fixed") && !strcmp(modelParams[part2].fossilizationPr,"Fixed"))
14141             {
14142             if (AreDoublesEqual (modelParams[part1].fossilizationFix, modelParams[part2].fossilizationFix, (MrBFlt) 0.00001) == NO)
14143                 isSame = NO;
14144             }
14145         else
14146             isSame = NO;
14147         
14148         /* Check to see if the fossilization rates are inapplicable for either partition. */
14149         if ((*isApplic1) == NO || (*isApplic2) == NO)
14150             isSame = NO;
14151         }
14152     else if (whichParam == P_POPSIZE)
14153         {
14154         /* Check population size for partitions 1 and 2. */
14155
14156         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14157            silly and doesn't take this information into account) and population size cannot be estimated. */
14158         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14159             *isApplic1 = NO; 
14160         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14161             *isApplic2 = NO; 
14162             
14163         /* Check that the branch length prior is a clock:coalescence or clock:speciestreecoalescence for both partitions. */
14164         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14165             *isApplic1 = NO;
14166         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14167             *isApplic2 = NO;
14168         if (strcmp(modelParams[part1].clockPr, "Coalescence") != 0 && strcmp(modelParams[part1].clockPr, "Speciestreecoalescence") != 0)
14169             *isApplic1 = NO;
14170         if (strcmp(modelParams[part2].clockPr, "Coalescence") != 0 && strcmp(modelParams[part2].clockPr, "Speciestreecoalescence") != 0)
14171             *isApplic2 = NO;
14172         
14173         /* Now, check that the prior on population size is the same. */
14174         if (!strcmp(modelParams[part1].popSizePr,"Uniform") && !strcmp(modelParams[part2].popSizePr,"Uniform"))
14175             {
14176             if (AreDoublesEqual (modelParams[part1].popSizeUni[0], modelParams[part2].popSizeUni[0], (MrBFlt) 0.00001) == NO)
14177                 isSame = NO;
14178             if (AreDoublesEqual (modelParams[part1].popSizeUni[1], modelParams[part2].popSizeUni[1], (MrBFlt) 0.00001) == NO)
14179                 isSame = NO;
14180             }
14181         else if (!strcmp(modelParams[part1].popSizePr,"Lognormal") && !strcmp(modelParams[part2].popSizePr,"Lognormal"))
14182             {
14183             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[0], modelParams[part2].popSizeLognormal[0], (MrBFlt) 0.00001) == NO)
14184                 isSame = NO;
14185             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[1], modelParams[part2].popSizeLognormal[1], (MrBFlt) 0.00001) == NO)
14186                 isSame = NO;
14187             }
14188         else if (!strcmp(modelParams[part1].popSizePr,"Normal") && !strcmp(modelParams[part2].popSizePr,"Normal"))
14189             {
14190             if (AreDoublesEqual (modelParams[part1].popSizeNormal[0], modelParams[part2].popSizeNormal[0], (MrBFlt) 0.00001) == NO)
14191                 isSame = NO;
14192             if (AreDoublesEqual (modelParams[part1].popSizeNormal[1], modelParams[part2].popSizeNormal[1], (MrBFlt) 0.00001) == NO)
14193                 isSame = NO;
14194             }
14195         else if (!strcmp(modelParams[part1].popSizePr,"Gamma") && !strcmp(modelParams[part2].popSizePr,"Gamma"))
14196             {
14197             if (AreDoublesEqual (modelParams[part1].popSizeGamma[0], modelParams[part2].popSizeGamma[0], (MrBFlt) 0.00001) == NO)
14198                 isSame = NO;
14199             if (AreDoublesEqual (modelParams[part1].popSizeGamma[1], modelParams[part2].popSizeGamma[1], (MrBFlt) 0.00001) == NO)
14200                 isSame = NO;
14201             }
14202         else if (!strcmp(modelParams[part1].popSizePr,"Fixed") && !strcmp(modelParams[part2].popSizePr,"Fixed"))
14203             {
14204             if (AreDoublesEqual (modelParams[part1].popSizeFix, modelParams[part2].popSizeFix, (MrBFlt) 0.00001) == NO)
14205                 isSame = NO;
14206             }
14207         else
14208             isSame = NO;
14209         
14210         /* Check to see if population size is inapplicable for either partition. */
14211         if ((*isApplic1) == NO || (*isApplic2) == NO)
14212             isSame = NO;
14213         }
14214     else if (whichParam == P_GROWTH)
14215         {
14216         /* Check growth rate for partitions 1 and 2. */
14217
14218         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14219            silly and doesn't take this information into account) and growth rate cannot be estimated. */
14220         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14221             *isApplic1 = NO; 
14222         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14223             *isApplic2 = NO; 
14224             
14225         /* Check that the branch length prior is a clock:coalescence for both partitions. */
14226         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14227             *isApplic1 = NO;
14228         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14229             *isApplic2 = NO;
14230         if (strcmp(modelParams[part1].clockPr, "Coalescence"))
14231             *isApplic1 = NO;
14232         if (strcmp(modelParams[part2].clockPr, "Coalescence"))
14233             *isApplic2 = NO;
14234         
14235         /* Now, check that the prior on growth rate is the same. */
14236         if (!strcmp(modelParams[part1].growthPr,"Uniform") && !strcmp(modelParams[part2].growthPr,"Uniform"))
14237             {
14238             if (AreDoublesEqual (modelParams[part1].growthUni[0], modelParams[part2].growthUni[0], (MrBFlt) 0.00001) == NO)
14239                 isSame = NO;
14240             if (AreDoublesEqual (modelParams[part1].growthUni[1], modelParams[part2].growthUni[1], (MrBFlt) 0.00001) == NO)
14241                 isSame = NO;
14242             }
14243         else if (!strcmp(modelParams[part1].growthPr,"Exponential") && !strcmp(modelParams[part2].growthPr,"Exponential"))
14244             {
14245             if (AreDoublesEqual (modelParams[part1].growthExp, modelParams[part2].growthExp, (MrBFlt) 0.00001) == NO)
14246                 isSame = NO;
14247             }
14248         else if (!strcmp(modelParams[part1].growthPr,"Fixed") && !strcmp(modelParams[part2].growthPr,"Fixed"))
14249             {
14250             if (AreDoublesEqual (modelParams[part1].growthFix, modelParams[part2].growthFix, (MrBFlt) 0.00001) == NO)
14251                 isSame = NO;
14252             }
14253         else
14254             isSame = NO;
14255         
14256         /* Check to see if growth rate is inapplicable for either partition. */
14257         if ((*isApplic1) == NO || (*isApplic2) == NO)
14258             isSame = NO; 
14259         }
14260     else if (whichParam == P_AAMODEL)
14261         {
14262         /* Check the amino acid model settings for partitions 1 and 2. */
14263
14264         /* Check if the model is parsimony for either partition */
14265         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14266             *isApplic1 = NO; /* part1 has a parsimony model and aamodel does not apply */
14267         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14268             *isApplic2 = NO; /* part2 has a parsimony model and aamodel does not apply */
14269         
14270         /* Check that the data are protein for both partitions 1 and 2 */
14271         if (isFirstProtein == NO)
14272             *isApplic1 = NO; /* part1 is not amino acid data so tratio does not apply */
14273         if (isSecondProtein == NO)
14274             *isApplic2 = NO; /* part2 is not amino acid data so tratio does not apply */
14275             
14276         /* If the model is fixed for a partition, then it is not a free parameter and
14277            we set it to isApplic = NO */
14278         if (!strcmp(modelParams[part1].aaModelPr,"Fixed"))
14279             *isApplic1 = NO; 
14280         if (!strcmp(modelParams[part2].aaModelPr,"Fixed"))
14281             *isApplic2 = NO;
14282
14283         /* We now need to check if the prior is the same for both. */
14284         if (!strcmp(modelParams[part1].aaModelPr,"Mixed") && !strcmp(modelParams[part2].aaModelPr,"Mixed"))
14285             {
14286             }
14287         else if (!strcmp(modelParams[part1].aaModelPr,"Fixed") && !strcmp(modelParams[part2].aaModelPr,"Fixed"))
14288             {
14289             if (strcmp(modelParams[part1].aaModel,modelParams[part2].aaModel))
14290                 isSame = NO;
14291             }
14292         else
14293             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
14294
14295         /* Check to see if amino acid model is inapplicable for either partition. */
14296         if ((*isApplic1) == NO || (*isApplic2) == NO)
14297             isSame = NO; /* if tratio is inapplicable for either partition, then the parameter cannot be the same */
14298         }
14299     else if (whichParam == P_BRCORR)
14300         {
14301         /* Check the correlation parameter for brownian motion 1 and 2. */
14302         
14303         /* Check that the data are either CONTINUOUS for partitions 1 and 2 */
14304         if (modelParams[part1].dataType != CONTINUOUS)
14305             *isApplic1 = NO; /* the correlation parameter does not make sense for part1 */
14306         if (modelParams[part2].dataType != CONTINUOUS)
14307             *isApplic2 = NO; /* the correlation parameter does not make sense for part2 */
14308             
14309         /* Now, check that the data are the same. */
14310         if (modelParams[part1].dataType != modelParams[part2].dataType)
14311             isSame = NO; /* data are not both continuous */
14312
14313         /* Check the priors for both partitions. */
14314         if (!strcmp(modelParams[part1].brownCorPr,"Uniform") && !strcmp(modelParams[part2].brownCorPr,"Uniform"))
14315             {
14316             if (AreDoublesEqual (modelParams[part1].brownCorrUni[0], modelParams[part2].brownCorrUni[0], (MrBFlt) 0.00001) == NO)
14317                 isSame = NO;
14318             if (AreDoublesEqual (modelParams[part1].brownCorrUni[1], modelParams[part2].brownCorrUni[1], (MrBFlt) 0.00001) == NO)
14319                 isSame = NO;
14320             }
14321         else if (!strcmp(modelParams[part1].brownCorPr,"Fixed") && !strcmp(modelParams[part2].brownCorPr,"Fixed"))
14322             {
14323             if (AreDoublesEqual (modelParams[part1].brownCorrFix, modelParams[part2].brownCorrFix, (MrBFlt) 0.00001) == NO)
14324                 isSame = NO;
14325             }
14326         else
14327             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
14328
14329         /* Check to see if the correlation parameters are inapplicable for either partition. */
14330         if ((*isApplic1) == NO || (*isApplic2) == NO)
14331             isSame = NO; /* if the correlation parameters are inapplicable for either partition, then the parameter cannot be the same */
14332         }
14333     else if (whichParam == P_BRSIGMA)
14334         {
14335         /* Check the sigma parameter for brownian motion 1 and 2. */
14336         
14337         /* Check that the data are either CONTINUOUS for partitions 1 and 2 */
14338         if (modelParams[part1].dataType != CONTINUOUS)
14339             *isApplic1 = NO; /* the sigma parameter does not make sense for part1 */
14340         if (modelParams[part2].dataType != CONTINUOUS)
14341             *isApplic2 = NO; /* the sigma parameter does not make sense for part2 */
14342             
14343         /* Now, check that the data are the same. */
14344         if (modelParams[part1].dataType != modelParams[part2].dataType)
14345             isSame = NO; /* data are not both continuous */
14346
14347         /* Check the priors for both partitions. */
14348         if (!strcmp(modelParams[part1].brownScalesPr,"Uniform") && !strcmp(modelParams[part2].brownScalesPr,"Uniform"))
14349             {
14350             if (AreDoublesEqual (modelParams[part1].brownScalesUni[0], modelParams[part2].brownScalesUni[0], (MrBFlt) 0.00001) == NO)
14351                 isSame = NO;
14352             if (AreDoublesEqual (modelParams[part1].brownScalesUni[1], modelParams[part2].brownScalesUni[1], (MrBFlt) 0.00001) == NO)
14353                 isSame = NO;
14354             }
14355         else if (!strcmp(modelParams[part1].brownScalesPr,"Fixed") && !strcmp(modelParams[part2].brownScalesPr,"Fixed"))
14356             {
14357             if (AreDoublesEqual (modelParams[part1].brownScalesFix, modelParams[part2].brownScalesFix, (MrBFlt) 0.00001) == NO)
14358                 isSame = NO;
14359             }
14360         else if (!strcmp(modelParams[part1].brownScalesPr,"Gamma") && !strcmp(modelParams[part2].brownScalesPr,"Gamma"))
14361             {
14362             if (AreDoublesEqual (modelParams[part1].brownScalesGamma[0], modelParams[part2].brownScalesGamma[0], (MrBFlt) 0.00001) == NO)
14363                 isSame = NO;
14364             if (AreDoublesEqual (modelParams[part1].brownScalesGamma[1], modelParams[part2].brownScalesGamma[1], (MrBFlt) 0.00001) == NO)
14365                 isSame = NO;
14366             }
14367         else if (!strcmp(modelParams[part1].brownScalesPr,"Gammamean") && !strcmp(modelParams[part2].brownScalesPr,"Gammamean"))
14368             {
14369             if (AreDoublesEqual (modelParams[part1].brownScalesGammaMean, modelParams[part2].brownScalesGammaMean, (MrBFlt) 0.00001) == NO)
14370                 isSame = NO;
14371             }
14372         else
14373             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
14374
14375         /* Check to see if the sigma parameters are inapplicable for either partition. */
14376         if ((*isApplic1) == NO || (*isApplic2) == NO)
14377             isSame = NO; /* if the sigma parameters are inapplicable for either partition, then the parameter cannot be the same */
14378         }
14379     else if (whichParam == P_CPPRATE)
14380         {
14381         /* Check cpp rate for partitions 1 and 2. */
14382     
14383         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14384         silly and doesn't take this information into account) and cpp rate cannot be estimated. */
14385         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14386             *isApplic1 = NO; 
14387         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14388             *isApplic2 = NO;
14389
14390         /* Check that the branch length prior is clock for both partitions. */
14391         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14392             *isApplic1 = NO;
14393         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14394             *isApplic2 = NO;
14395
14396         /* Check that the clock rate prior is cpp for both partitions */
14397         if (strcmp(modelParams[part1].clockVarPr, "Cpp"))
14398             *isApplic1 = NO;
14399         if (strcmp(modelParams[part2].clockVarPr, "Cpp"))
14400             *isApplic2 = NO;
14401         
14402         /* Now, check that the prior on cpp rate is the same. */
14403         if (!strcmp(modelParams[part1].cppRatePr,"Exponential") && !strcmp(modelParams[part2].cppRatePr,"Exponential"))
14404             {
14405             if (AreDoublesEqual (modelParams[part1].cppRateExp, modelParams[part2].cppRateExp, (MrBFlt) 0.00001) == NO)
14406                 isSame = NO;
14407             }
14408         else if (!strcmp(modelParams[part1].cppRatePr,"Fixed") && !strcmp(modelParams[part2].cppRatePr,"Fixed"))
14409             {
14410             if (AreDoublesEqual (modelParams[part1].cppRateFix, modelParams[part2].cppRateFix, (MrBFlt) 0.00001) == NO)
14411                 isSame = NO;
14412             }
14413         else
14414             isSame = NO;
14415     
14416         /* Check to see if cpp rate is inapplicable for either partition. */
14417         if ((*isApplic1) == NO || (*isApplic2) == NO)
14418             isSame = NO;    
14419         }
14420     else if (whichParam == P_CPPMULTDEV)
14421         {
14422         /* Check cpp multiplier deviation prior for partitions 1 and 2. */
14423         
14424         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14425         silly and doesn't take this information into account) and this parameter is inapplicable. */
14426         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14427             *isApplic1 = NO; 
14428         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14429             *isApplic2 = NO; 
14430         
14431         /* Check that the branch length prior is clock for both partitions. */
14432         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14433             *isApplic1 = NO;
14434         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14435             *isApplic2 = NO;
14436
14437         /* Check that the clock rate prior is cpp for both partitions */
14438         if (strcmp(modelParams[part1].clockVarPr, "Cpp"))
14439             *isApplic1 = NO;
14440         if (strcmp(modelParams[part2].clockVarPr, "Cpp"))
14441             *isApplic2 = NO;
14442         
14443         /* Now, check that the prior on sigma is the same. */
14444         if (!strcmp(modelParams[part1].cppMultDevPr,"Fixed") && !strcmp(modelParams[part2].cppMultDevPr,"Fixed"))
14445             {
14446             if (AreDoublesEqual (modelParams[part1].cppMultDevFix, modelParams[part2].cppMultDevFix, (MrBFlt) 0.00001) == NO)
14447                 isSame = NO;
14448             }
14449         else
14450             isSame = NO;
14451         
14452         /* Check to see if cpp multiplier sigma is inapplicable for either partition. */
14453         if ((*isApplic1) == NO || (*isApplic2) == NO)
14454             isSame = NO;    
14455         }
14456     else if (whichParam == P_CPPEVENTS)
14457         {
14458         /* Check cpp events for partitions 1 and 2. */
14459     
14460         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14461         silly and doesn't take this information into account) and cpp events are inapplicable. */
14462         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14463             *isApplic1 = NO; 
14464         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14465             *isApplic2 = NO;
14466
14467         /* Check that the branch length prior is clock for both partitions. */
14468         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14469             *isApplic1 = NO;
14470         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14471             *isApplic2 = NO;
14472
14473         /* Check that the clock rate prior is cpp for both partitions */
14474         if (strcmp(modelParams[part1].clockVarPr, "Cpp"))
14475             *isApplic1 = NO;
14476         if (strcmp(modelParams[part2].clockVarPr, "Cpp"))
14477             *isApplic2 = NO;
14478         
14479         /* Now, check that the cpp parameter is the same */
14480         if (IsModelSame (P_CPPRATE, part1, part2, &temp1, &temp2) == NO)
14481             isSame = NO;
14482         if (linkTable[P_CPPRATE][part1] != linkTable[P_CPPRATE][part2])
14483             isSame = NO;
14484     
14485         /* ... and that the psigamma parameter is the same */
14486         if (IsModelSame (P_CPPMULTDEV, part1, part2, &temp1, &temp2) == NO)
14487             isSame = NO;
14488         if (linkTable[P_CPPMULTDEV][part1] != linkTable[P_CPPRATE][part2])
14489             isSame = NO;
14490     
14491         /* Not same if branch lengths are not the same */
14492         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14493             isSame = NO;
14494         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14495             isSame = NO;
14496
14497         /* Set isSame to NO if cpp events are inapplicable for either partition. */
14498         if ((*isApplic1) == NO || (*isApplic2) == NO)
14499             isSame = NO;
14500         }
14501     else if (whichParam == P_TK02VAR)
14502         {
14503         /* Check prior for variance of rate autocorrelation for partitions 1 and 2. */
14504         
14505         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14506         silly and doesn't take this information into account) and ratevar is inapplicable. */
14507         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14508             *isApplic1 = NO; 
14509         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14510             *isApplic2 = NO; 
14511         
14512         /* Check that the branch length prior is clock for both partitions. */
14513         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14514             *isApplic1 = NO;
14515         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14516             *isApplic2 = NO;
14517
14518         /* Check that the clock rate prior is tk02 for both partitions */
14519         if (strcmp(modelParams[part1].clockVarPr, "TK02"))
14520             *isApplic1 = NO;
14521         if (strcmp(modelParams[part2].clockVarPr, "TK02"))
14522             *isApplic2 = NO;
14523         
14524         /* Now, check that the prior on tk02 variance is the same. */
14525         if (!strcmp(modelParams[part1].tk02varPr,"Uniform") && !strcmp(modelParams[part2].tk02varPr,"Uniform"))
14526             {
14527             if (AreDoublesEqual (modelParams[part1].tk02varUni[0], modelParams[part2].tk02varUni[0], (MrBFlt) 0.00001) == NO)
14528                 isSame = NO;
14529             if (AreDoublesEqual (modelParams[part1].tk02varUni[1], modelParams[part2].tk02varUni[1], (MrBFlt) 0.00001) == NO)
14530                 isSame = NO;
14531             }
14532         else if (!strcmp(modelParams[part1].tk02varPr,"Exponential") && !strcmp(modelParams[part2].tk02varPr,"Exponential"))
14533             {
14534             if (AreDoublesEqual (modelParams[part1].tk02varExp, modelParams[part2].tk02varExp, (MrBFlt) 0.00001) == NO)
14535                 isSame = NO;
14536             }
14537         else if (!strcmp(modelParams[part1].tk02varPr,"Fixed") && !strcmp(modelParams[part2].tk02varPr,"Fixed"))
14538             {
14539             if (AreDoublesEqual (modelParams[part1].tk02varFix, modelParams[part2].tk02varFix, (MrBFlt) 0.00001) == NO)
14540                 isSame = NO;
14541             }
14542         else
14543             isSame = NO;
14544         
14545         /* Check to see if tk02 variance is inapplicable for either partition. */
14546         if ((*isApplic1) == NO || (*isApplic2) == NO)
14547             isSame = NO;    
14548         }
14549     else if (whichParam == P_TK02BRANCHRATES)
14550         {
14551         /* Check TK02 relaxed clock branch rates for partitions 1 and 2. */
14552     
14553         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14554         silly and doesn't take this information into account) and tk02 relaxed clock branch rates are inapplicable. */
14555         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14556             *isApplic1 = NO; 
14557         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14558             *isApplic2 = NO;
14559
14560         /* Check that the branch length prior is clock for both partitions. */
14561         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14562             *isApplic1 = NO;
14563         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14564             *isApplic2 = NO;
14565
14566         /* Check that the clock rate prior is tk02 for both partitions */
14567         if (strcmp(modelParams[part1].clockVarPr, "TK02"))
14568             *isApplic1 = NO;
14569         if (strcmp(modelParams[part2].clockVarPr, "TK02"))
14570             *isApplic2 = NO;
14571         
14572         /* Now, check that the tk02 variance parameter is the same */
14573         if (IsModelSame (P_TK02VAR, part1, part2, &temp1, &temp2) == NO)
14574             isSame = NO;
14575         if (linkTable[P_TK02VAR][part1] != linkTable[P_TK02VAR][part2])
14576             isSame = NO;
14577
14578         /* Not same if branch lengths are not the same */
14579         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14580             isSame = NO;
14581         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14582             isSame = NO;
14583
14584         /* Set isSame to NO if tk02 branch rates are inapplicable for either partition. */
14585         if ((*isApplic1) == NO || (*isApplic2) == NO)
14586             isSame = NO;
14587         }
14588     else if (whichParam == P_IGRVAR)
14589         {
14590         /* Check prior for igr shape for partitions 1 and 2. */
14591         
14592         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14593         silly and doesn't take this information into account) and igr shape is inapplicable. */
14594         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14595             *isApplic1 = NO; 
14596         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14597             *isApplic2 = NO; 
14598         
14599         /* Check that the branch length prior is clock for both partitions. */
14600         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14601             *isApplic1 = NO;
14602         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14603             *isApplic2 = NO;
14604
14605         /* Check that the clock rate prior is igr for both partitions */
14606         if (strcmp(modelParams[part1].clockVarPr, "Igr"))
14607             *isApplic1 = NO;
14608         if (strcmp(modelParams[part2].clockVarPr, "Igr"))
14609             *isApplic2 = NO;
14610         
14611         /* Now, check that the prior on igr shape is the same. */
14612         if (!strcmp(modelParams[part1].igrvarPr,"Uniform") && !strcmp(modelParams[part2].igrvarPr,"Uniform"))
14613             {
14614             if (AreDoublesEqual (modelParams[part1].igrvarUni[0], modelParams[part2].igrvarUni[0], (MrBFlt) 0.00001) == NO)
14615                 isSame = NO;
14616             if (AreDoublesEqual (modelParams[part1].igrvarUni[1], modelParams[part2].igrvarUni[1], (MrBFlt) 0.00001) == NO)
14617                 isSame = NO;
14618             }
14619         else if (!strcmp(modelParams[part1].igrvarPr,"Exponential") && !strcmp(modelParams[part2].igrvarPr,"Exponential"))
14620             {
14621             if (AreDoublesEqual (modelParams[part1].igrvarExp, modelParams[part2].igrvarExp, (MrBFlt) 0.00001) == NO)
14622                 isSame = NO;
14623             }
14624         else if (!strcmp(modelParams[part1].igrvarPr,"Fixed") && !strcmp(modelParams[part2].igrvarPr,"Fixed"))
14625             {
14626             if (AreDoublesEqual (modelParams[part1].igrvarFix, modelParams[part2].igrvarFix, (MrBFlt) 0.00001) == NO)
14627                 isSame = NO;
14628             }
14629         else
14630             isSame = NO;
14631         
14632         /* Check to see if igr variance is inapplicable for either partition. */
14633         if ((*isApplic1) == NO || (*isApplic2) == NO)
14634             isSame = NO;    
14635         }
14636     else if (whichParam == P_IGRBRANCHRATES)
14637         {
14638         /* Check IGR relaxed clock branch rates for partitions 1 and 2. */
14639     
14640         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14641         silly and doesn't take this information into account) and igr relaxed clock branch rates are inapplicable. */
14642         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14643             *isApplic1 = NO; 
14644         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14645             *isApplic2 = NO;
14646
14647         /* Check that the branch length prior is clock for both partitions. */
14648         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14649             *isApplic1 = NO;
14650         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14651             *isApplic2 = NO;
14652
14653         /* Check that the clock rate prior is igr for both partitions */
14654         if (strcmp(modelParams[part1].clockVarPr, "Igr"))
14655             *isApplic1 = NO;
14656         if (strcmp(modelParams[part2].clockVarPr, "Igr"))
14657             *isApplic2 = NO;
14658         
14659         /* Now, check that the igr shape parameter is the same */
14660         if (IsModelSame (P_IGRVAR, part1, part2, &temp1, &temp2) == NO)
14661             isSame = NO;
14662         if (linkTable[P_IGRVAR][part1] != linkTable[P_IGRVAR][part2])
14663             isSame = NO;
14664     
14665         /* Not same if branch lengths are not the same */
14666         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14667             isSame = NO;
14668         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14669             isSame = NO;
14670
14671         /* Set isSame to NO if igr branch rates are inapplicable for either partition. */
14672         if ((*isApplic1) == NO || (*isApplic2) == NO)
14673             isSame = NO;
14674         }
14675     else if (whichParam == P_MIXEDVAR)
14676         {
14677         /* Check prior for mixed var for partitions 1 and 2. */
14678         
14679         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14680          silly and doesn't take this information into account) and variance is inapplicable. */
14681         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14682             *isApplic1 = NO;
14683         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14684             *isApplic2 = NO;
14685         
14686         /* Check that the branch length prior is clock for both partitions. */
14687         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14688             *isApplic1 = NO;
14689         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14690             *isApplic2 = NO;
14691         
14692         /* Check that the clock rate prior is mixed for both partitions */
14693         if (strcmp(modelParams[part1].clockVarPr, "Mixed"))
14694             *isApplic1 = NO;
14695         if (strcmp(modelParams[part2].clockVarPr, "Mixed"))
14696             *isApplic2 = NO;
14697         
14698         /* Now, check that the prior on var mixed is the same. */
14699         if (!strcmp(modelParams[part1].mixedvarPr,"Uniform") && !strcmp(modelParams[part2].mixedvarPr,"Uniform"))
14700             {
14701             if (AreDoublesEqual (modelParams[part1].mixedvarUni[0], modelParams[part2].mixedvarUni[0], (MrBFlt) 0.00001) == NO)
14702                 isSame = NO;
14703             if (AreDoublesEqual (modelParams[part1].mixedvarUni[1], modelParams[part2].mixedvarUni[1], (MrBFlt) 0.00001) == NO)
14704                 isSame = NO;
14705             }
14706         else if (!strcmp(modelParams[part1].mixedvarPr,"Exponential") && !strcmp(modelParams[part2].mixedvarPr,"Exponential"))
14707             {
14708             if (AreDoublesEqual (modelParams[part1].mixedvarExp, modelParams[part2].mixedvarExp, (MrBFlt) 0.00001) == NO)
14709                 isSame = NO;
14710             }
14711         else if (!strcmp(modelParams[part1].mixedvarPr,"Fixed") && !strcmp(modelParams[part2].mixedvarPr,"Fixed"))
14712             {
14713             if (AreDoublesEqual (modelParams[part1].mixedvarFix, modelParams[part2].mixedvarFix, (MrBFlt) 0.00001) == NO)
14714                 isSame = NO;
14715             }
14716         else
14717             isSame = NO;
14718         
14719         /* Check to see if variance is inapplicable for either partition. */
14720         if ((*isApplic1) == NO || (*isApplic2) == NO)
14721             isSame = NO;
14722         }
14723     else if (whichParam == P_MIXEDBRCHRATES)
14724         {
14725         /* Check mixed relaxed clock branch rates for partitions 1 and 2. */
14726         
14727         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14728          silly and doesn't take this information into account) and relaxed clock branch rates are inapplicable. */
14729         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14730             *isApplic1 = NO;
14731         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14732             *isApplic2 = NO;
14733         
14734         /* Check that the branch length prior is clock for both partitions. */
14735         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14736             *isApplic1 = NO;
14737         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14738             *isApplic2 = NO;
14739         
14740         /* Check that the clock rate prior is mixed for both partitions */
14741         if (strcmp(modelParams[part1].clockVarPr, "Mixed"))
14742             *isApplic1 = NO;
14743         if (strcmp(modelParams[part2].clockVarPr, "Mixed"))
14744             *isApplic2 = NO;
14745         
14746         /* Now, check that the var parameter is the same */
14747         if (IsModelSame (P_MIXEDVAR, part1, part2, &temp1, &temp2) == NO)
14748             isSame = NO;
14749         if (linkTable[P_MIXEDVAR][part1] != linkTable[P_MIXEDVAR][part2])
14750             isSame = NO;
14751         
14752         /* Not same if branch lengths are not the same */
14753         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14754             isSame = NO;
14755         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14756             isSame = NO;
14757         
14758         /* Set isSame to NO if mixed branch rates are inapplicable for either partition. */
14759         if ((*isApplic1) == NO || (*isApplic2) == NO)
14760             isSame = NO;
14761         }
14762     else if (whichParam == P_CLOCKRATE)
14763         {
14764         /* Check base substitution rates of clock tree for partitions 1 and 2. */
14765     
14766         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14767         silly and doesn't take this information into account) and clock branch rates are inapplicable. */
14768         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14769             *isApplic1 = NO; 
14770         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14771             *isApplic2 = NO;
14772
14773         /* Check that the branch length prior is clock for both partitions. */
14774         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14775             *isApplic1 = NO;
14776         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14777             *isApplic2 = NO;
14778
14779         /* Set isSame to NO if base substitution rate parameter is inapplicable for either partition. */
14780         if ((*isApplic1) == NO || (*isApplic2) == NO)
14781             isSame = NO;
14782         }
14783     else if (whichParam == P_SPECIESTREE)
14784         {
14785         /* Species tree; check that it is used in both partitions */
14786         if (strcmp(modelParams[part1].topologyPr, "Speciestree") != 0)
14787             *isApplic1 = NO;
14788         if (strcmp(modelParams[part2].topologyPr, "Speciestree") != 0)
14789             *isApplic2 = NO;
14790
14791         /* Not same if inapplicable to either partition */
14792         if ((*isApplic1) == NO || (*isApplic2) == NO)
14793             isSame = NO;
14794         }
14795     else if (whichParam == P_GENETREERATE)
14796         {
14797         /* Gene tree rate; check that it is used in both partitions */
14798         if (strcmp(modelParams[part1].topologyPr, "Speciestree") != 0)
14799             *isApplic1 = NO;
14800         if (strcmp(modelParams[part2].topologyPr, "Speciestree") != 0)
14801             *isApplic2 = NO;
14802
14803         /* Not same if inapplicable to either partition */
14804         if ((*isApplic1) == NO || (*isApplic2) == NO)
14805             isSame = NO;
14806         }
14807     else
14808         {
14809         MrBayesPrint ("%s   Could not find parameter in IsModelSame\n", spacer);
14810         return (NO);
14811         }
14812     
14813     return (isSame);
14814 }
14815
14816
14817 int LargestMovableSubtree(Param *treeParam)
14818 {
14819     int         i, j, k, a, nLongsNeeded, numPartitions, largestSubtree;
14820     BitsLong    **constraintPartition, *subtreePartition, *testPartition, *mask;
14821     ModelParams *mp;
14822
14823     mp = &modelParams[treeParam->relParts[0]];
14824
14825     if (treeParam->paramType == P_SPECIESTREE)
14826         return numLocalTaxa;    /* no constraints allowed in species tree; set constraints in gene trees instead */
14827     
14828     /* This is difficult because we cannot rely on the tree being initialized.
14829        We need to retrieve the bitfields ourselves and figure out what they mean. */
14830     nLongsNeeded = ((numLocalTaxa - 1) / nBitsInALong) + 1;
14831     subtreePartition = (BitsLong *) SafeCalloc(3*nLongsNeeded, sizeof(BitsLong));
14832     constraintPartition = (BitsLong **) SafeCalloc (numDefinedConstraints+1, sizeof(BitsLong *));
14833     constraintPartition[0] = (BitsLong *) SafeCalloc ((numDefinedConstraints+1)*nLongsNeeded, sizeof(BitsLong));
14834     for (i=1; i<numDefinedConstraints+1; i++)
14835         constraintPartition[i] = constraintPartition[i-1] + nLongsNeeded;
14836     testPartition = subtreePartition + nLongsNeeded;
14837     mask = testPartition + nLongsNeeded;
14838     
14839     /* set mask (needed to take care of unused bits when flipping partitions) */
14840     for (i=0; i<numLocalTaxa; i++)
14841         SetBit (i, mask);
14842     
14843     /* retrieve partitions */
14844     numPartitions = 0;
14845     for (a=0; a<numDefinedConstraints; a++)
14846         {
14847         if (mp->activeConstraints[a] == NO || definedConstraintsType[a] != HARD)
14848             continue;
14849         
14850         /* set bits in partition under consideration */
14851         ClearBits(constraintPartition[numPartitions], nLongsNeeded);
14852         for (i=j=0; i<numTaxa; i++)
14853             {
14854             if (taxaInfo[i].isDeleted == YES)
14855                 continue;
14856             if (IsBitSet(i, definedConstraint[a]) == YES)
14857                 SetBit(j, constraintPartition[numPartitions]);
14858             j++;
14859             }
14860         
14861         /* make sure outgroup is outside constrained partition (marked 0) */
14862         if (strcmp(mp->brlensPr,"Clock") != 0 && IsBitSet(localOutGroup, constraintPartition[numPartitions]) == YES)
14863             FlipBits(constraintPartition[numPartitions], nLongsNeeded, mask);
14864         
14865         /* skip partition if uninformative */
14866         k = NumBits(constraintPartition[numPartitions], nLongsNeeded);
14867         if (k == 0 || k == 1)
14868             continue;
14869         
14870         numPartitions++;
14871         }
14872     
14873     /* Add all-species partition */
14874     CopyBits(constraintPartition[numPartitions], mask, nLongsNeeded);
14875     numPartitions++;
14876     
14877     /* Now we have all constraints. Calculate the movable subtree for each */
14878     largestSubtree = 0;
14879     for (i=0; i<numPartitions; i++)
14880         {
14881         CopyBits (subtreePartition, constraintPartition[i], nLongsNeeded);
14882         k = 0;
14883         for (j=0; j<numPartitions; j++)
14884             {
14885             if (j==i)
14886                 continue;
14887             if (IsPartNested(constraintPartition[j], constraintPartition[i], nLongsNeeded))
14888                 {
14889                 k++;    /* add one for clade we are removing from subtreePartition */
14890                 CopyBits (testPartition, constraintPartition[j], nLongsNeeded);
14891                 FlipBits (testPartition, nLongsNeeded, mask);
14892                 for (k=0; k<nLongsNeeded; k++)
14893                     subtreePartition[k] = subtreePartition[k] & testPartition[k];
14894                 }
14895             }
14896         k += NumBits (subtreePartition, nLongsNeeded);  /* add remaming free tips in subtreePartition */
14897         /* add calculation root if an unrooted tree and we are dealing with the root partition */
14898         if (strcmp(mp->brlensPr,"Clock") != 0 && NumBits (constraintPartition[i], nLongsNeeded) == numLocalTaxa - 1)
14899             k++;
14900         if (k > largestSubtree)
14901             largestSubtree = k;
14902         }
14903
14904     free(subtreePartition);
14905     free(constraintPartition[0]);
14906     free(constraintPartition);
14907    
14908     return largestSubtree;
14909 }
14910
14911
14912 int Link (void)
14913 {
14914     int         i, j;
14915     
14916     for (j=0; j<NUM_LINKED; j++)
14917         {
14918         MrBayesPrint ("%4d -- ", j+1);
14919         for (i=0; i<numCurrentDivisions; i++)
14920             MrBayesPrint (" %2d", tempLinkUnlink[j][i]);
14921         MrBayesPrint ("\n");
14922         }
14923         
14924     return (NO_ERROR);
14925 }
14926
14927
14928 int NumActiveParts (void)
14929 {
14930     int     i, nApplied;
14931     
14932     nApplied = 0;
14933     for (i=0; i<numCurrentDivisions; i++)
14934         if (activeParts[i] == YES)
14935             nApplied++;
14936
14937     return (nApplied);
14938 }
14939
14940
14941 int NumInformativeHardConstraints (ModelParams *mp)
14942 {
14943     int             i, j, k, a, numInformativeHardConstraints, nLongsNeeded;
14944     BitsLong        *constraintPartition, *mask;
14945        
14946     numInformativeHardConstraints = 0;
14947     
14948     nLongsNeeded = ((numLocalTaxa - 1) / nBitsInALong) + 1;
14949     constraintPartition = (BitsLong *) SafeCalloc (2*nLongsNeeded, sizeof(BitsLong));
14950     if (!constraintPartition)
14951         {
14952             MrBayesPrint ("%s   Problems allocating constraintPartition", spacer);
14953             return ERROR;
14954         }
14955     mask = constraintPartition + nLongsNeeded;
14956
14957     /* set mask (needed to take care of unused bits when flipping partitions) */
14958     for (i=0; i<numLocalTaxa; i++)
14959         SetBit (i, mask);
14960         
14961     for (a=0; a<numDefinedConstraints; a++)
14962         {
14963         if (mp->activeConstraints[a] == NO || definedConstraintsType[a] != HARD)
14964             continue;
14965             
14966         /* set bits in partition to add */
14967         ClearBits(constraintPartition, nLongsNeeded);
14968         for (i=j=0; i<numTaxa; i++)
14969             {
14970                 if (taxaInfo[i].isDeleted == YES)
14971                     continue;
14972                 if (IsBitSet(i, definedConstraint[a]) == YES)
14973                     SetBit(j, constraintPartition);
14974                 j++;
14975             }
14976             
14977         /* make sure outgroup is outside constrained partition (marked 0) */
14978         if (strcmp(mp->brlensPr,"Clock") != 0 && IsBitSet(localOutGroup, constraintPartition) == YES)
14979             FlipBits(constraintPartition, nLongsNeeded, mask);
14980             
14981         /* skip partition if uninformative */
14982         k = NumBits(constraintPartition, nLongsNeeded);
14983         if (k == 0 || k == 1)
14984             continue;
14985
14986         numInformativeHardConstraints++;
14987         }
14988         
14989     return numInformativeHardConstraints;
14990 }
14991
14992
14993 int NumNonExcludedChar (void)
14994 {
14995     int     i, n;
14996     
14997     /* count number of non-excluded characters */
14998     n = 0;
14999     for (i=0; i<numChar; i++)
15000         {
15001         if (charInfo[i].isExcluded == NO)
15002             {
15003             n++;
15004             }
15005         }
15006     
15007     return n;
15008 }
15009
15010
15011 int NumStates (int part)
15012 {
15013     if (modelParams[part].dataType == DNA || modelParams[part].dataType == RNA)
15014         {
15015         if (!strcmp(modelParams[part].nucModel, "4by4"))
15016             return (4);
15017         else if (!strcmp(modelParams[part].nucModel, "Doublet"))
15018             return (16);
15019         else if (!strcmp(modelParams[part].nucModel, "Protein"))
15020             return (20);
15021         else
15022             {
15023             if (!strcmp(modelParams[part].geneticCode, "Universal"))
15024                 return (61);
15025             else if (!strcmp(modelParams[part].geneticCode, "Vertmt"))
15026                 return (60);
15027             else if (!strcmp(modelParams[part].geneticCode, "Invermt"))
15028                 return (62);
15029             else if (!strcmp(modelParams[part].geneticCode, "Mycoplasma"))
15030                 return (62);
15031             else if (!strcmp(modelParams[part].geneticCode, "Yeast"))
15032                 return (62);
15033             else if (!strcmp(modelParams[part].geneticCode, "Ciliate"))
15034                 return (63);
15035             else if (!strcmp(modelParams[part].geneticCode, "Echinoderm"))
15036                 return (62);
15037             else if (!strcmp(modelParams[part].geneticCode, "Euplotid"))
15038                 return (62);
15039             else if (!strcmp(modelParams[part].geneticCode, "Metmt"))
15040                 return (62);
15041             }
15042         }
15043     else if (modelParams[part].dataType == PROTEIN)
15044         {
15045         return (20);
15046         }
15047     else if (modelParams[part].dataType == RESTRICTION)
15048         {
15049         return (2);
15050         }
15051     else if (modelParams[part].dataType == STANDARD)
15052         {
15053         return (10);
15054         }
15055         
15056     return (-1);
15057 }
15058
15059
15060 /*-----------------------------------------------------------------------
15061 |
15062 |   PrintCompMatrix: Print compressed matrix
15063 |
15064 ------------------------------------------------------------------------*/
15065 int PrintCompMatrix (void)
15066 {
15067     int             i, j, k, c, d;
15068     ModelInfo       *m;
15069     ModelParams     *mp;
15070     char            tempName[100];
15071     char            (*whichChar)(int);
15072
15073     if (!compMatrix)
15074         return ERROR;
15075
15076     whichChar = &WhichNuc;
15077     
15078     for (d=0; d<numCurrentDivisions; d++)
15079         {
15080         m = &modelSettings[d];
15081         mp = &modelParams[d];
15082
15083         if (mp->dataType == DNA || mp->dataType == RNA)
15084             whichChar = &WhichNuc;
15085         if (mp->dataType == PROTEIN)
15086             whichChar = &WhichAA;
15087         if (mp->dataType == RESTRICTION)
15088             whichChar = &WhichRes;
15089         if (mp->dataType == STANDARD)
15090             whichChar = &WhichStand;
15091
15092         MrBayesPrint ("\nCompressed matrix for division %d\n\n", d+1);
15093         
15094         k = 66;
15095         if (mp->dataType == CONTINUOUS)
15096             k /= 4;
15097
15098         for (c=m->compMatrixStart; c<m->compMatrixStop; c+=k)
15099             {
15100             for (i=0; i<numLocalTaxa; i++)
15101                 {
15102                 strcpy (tempName, localTaxonNames[i]);
15103                 MrBayesPrint ("%-10.10s   ", tempName);
15104                 for (j=c; j<c+k; j++)
15105                     {
15106                     if (j >= m->compMatrixStop)
15107                         break;
15108                     if (mp->dataType == CONTINUOUS)
15109                         MrBayesPrint ("%3d ", compMatrix[pos(i,j,compMatrixRowSize)]);
15110                     else
15111                         MrBayesPrint ("%c", whichChar((int)compMatrix[pos(i,j,compMatrixRowSize)]));
15112                     }
15113                 MrBayesPrint("\n");
15114                 }
15115             MrBayesPrint("\nNo. sites    ");
15116             for (j=c; j<c+k; j++)
15117                 {
15118                 if (j >= m->compMatrixStop)
15119                     break;
15120                 i = (int) numSitesOfPat[m->compCharStart + (0*numCompressedChars) + (j - m->compMatrixStart)/m->nCharsPerSite]; /* NOTE: We are printing the unadulterated site pat nums */
15121                 if (i>9)
15122                     i = 'A' + i - 10;
15123                 else
15124                     i = '0' + i;
15125                 if (mp->dataType == CONTINUOUS)
15126                     MrBayesPrint("   %c ", i);
15127                 else
15128                     {
15129                     if ((j-m->compMatrixStart) % m->nCharsPerSite == 0)
15130                         MrBayesPrint ("%c", i);
15131                     else
15132                         MrBayesPrint(" ");
15133                     }
15134                 }
15135             MrBayesPrint ("\nOrig. char   ");
15136             for (j=c; j<c+k; j++)
15137                 {
15138                 if (j >= m->compMatrixStop)
15139                     break;
15140                 i = origChar[j];
15141                 if (i>9)
15142                     i = '0' + (i % 10);
15143                 else
15144                     i = '0' +i;
15145                 if (mp->dataType == CONTINUOUS)
15146                     MrBayesPrint("   %c ", i);
15147                 else
15148                     MrBayesPrint ("%c", i);
15149                 }
15150
15151             if (mp->dataType == STANDARD && m->nStates != NULL)
15152                 {
15153                 MrBayesPrint ("\nNo. states   ");
15154                 for (j=c; j<c+k; j++)
15155                     {
15156                     if (j >= m->compMatrixStop)
15157                         break;
15158                     i = m->nStates[j-m->compCharStart];
15159                     MrBayesPrint ("%d", i);
15160                     }
15161                 MrBayesPrint ("\nCharType     ");
15162                 for (j=c; j<c+k; j++)
15163                     {
15164                     if (j >= m->compMatrixStop)
15165                         break;
15166                     i = m->cType[j-m->compMatrixStart];
15167                     if (i == ORD)
15168                         MrBayesPrint ("%c", 'O');
15169                     else if (i == UNORD)
15170                         MrBayesPrint ("%c", 'U');
15171                     else
15172                         MrBayesPrint ("%c", 'I');
15173                     }
15174                 MrBayesPrint ("\ntiIndex      ");
15175                 for (j=c; j<c+k; j++)
15176                     {
15177                     if (j >= m->compMatrixStop)
15178                         break;
15179                     i = m->tiIndex[j-m->compCharStart];
15180                     MrBayesPrint ("%d", i % 10);
15181                     }
15182                 MrBayesPrint ("\nbsIndex      ");
15183                 for (j=c; j<c+k; j++)
15184                     {
15185                     if (j >= m->compMatrixStop)
15186                         break;
15187                     i = m->bsIndex[j-m->compCharStart];
15188                     MrBayesPrint ("%d", i % 10);
15189                     }
15190                 }
15191             MrBayesPrint ("\n\n");
15192             }
15193         MrBayesPrint ("Press return to continue\n");
15194         getchar();
15195         }   /* next division */
15196
15197     return NO_ERROR;
15198 }
15199
15200
15201 /*----------------------------------------------------------------------
15202 |
15203 |   PrintMatrix: Print data matrix
15204 |
15205 |
15206 ------------------------------------------------------------------------*/
15207 int PrintMatrix (void)
15208 {
15209     int             i, j=0, c, printWidth, nextColumn;
15210
15211     if (!matrix)
15212         return ERROR;
15213     
15214     MrBayesPrint ("\nData matrix\n\n");
15215     
15216     printWidth = 79;
15217
15218     for (c=0; c<numChar; c=j)
15219         {
15220         for (i=0; i<numTaxa; i++)
15221             {
15222             MrBayesPrint ("%-10.10s   ", taxaNames[i]);
15223             j = c;
15224             for (nextColumn=13; nextColumn < printWidth; nextColumn++)
15225                 {
15226                 if (j >= numChar)
15227                     break;
15228                 if (charInfo[j].charType == CONTINUOUS && nextColumn < printWidth - 3)
15229                     break;
15230                 if (charInfo[j].charType == CONTINUOUS)
15231                     {   
15232                     MrBayesPrint ("%3d ", matrix[pos(i,j,numChar)]);
15233                     nextColumn += 3;
15234                     }
15235                 else if (charInfo[j].charType == DNA || charInfo[j].charType == RNA)
15236                     MrBayesPrint ("%c", WhichNuc(matrix[pos(i,j,numChar)]));
15237                 else if (charInfo[j].charType == PROTEIN)
15238                     MrBayesPrint ("%c", WhichAA(matrix[pos(i,j,numChar)]));
15239                 else if (charInfo[j].charType == RESTRICTION)
15240                     MrBayesPrint ("%c", WhichRes(matrix[pos(i,j,numChar)]));
15241                 else if (charInfo[j].charType == STANDARD)
15242                     MrBayesPrint ("%c", WhichStand(matrix[pos(i,j,numChar)]));
15243                 j++;
15244                 }
15245             MrBayesPrint("\n");
15246             }
15247         MrBayesPrint ("\n");
15248         }
15249
15250     return NO_ERROR;
15251 }
15252
15253
15254 /*--------------------------------------------------------------
15255 |
15256 |   ProcessStdChars: process standard characters
15257 |
15258 ---------------------------------------------------------------*/
15259 int ProcessStdChars (RandLong *seed)
15260 {
15261     int             c, d, i, j, k, n, ts, index, numStandardChars, origCharPos, *bsIndex;
15262     char            piHeader[30];
15263     ModelInfo       *m;
15264     ModelParams     *mp=NULL;
15265     Param           *p;
15266
15267     /* set character type, no. states, ti index and bs index for standard characters */
15268     /* first calculate how many standard characters we have */
15269     numStandardChars = 0;
15270     for (d=0; d<numCurrentDivisions; d++)
15271         {
15272         mp = &modelParams[d];
15273         m = &modelSettings[d];
15274
15275         if (mp->dataType != STANDARD)
15276             continue;
15277
15278         numStandardChars += m->numChars;
15279         }
15280     
15281     /* return if there are no standard characters */
15282     if (numStandardChars == 0)
15283         return (NO_ERROR);
15284
15285     /* we are still here so we have standard characters and need to deal with them */
15286     
15287     /* first allocate space for stdType, stateSize, tiIndex, bsIndex */
15288     if (memAllocs[ALLOC_STDTYPE] == YES)
15289         {
15290         free (stdType);
15291         stdType = NULL;
15292         memAllocs[ALLOC_STDTYPE] = NO;
15293         }
15294     stdType = (int *)SafeCalloc(4 * (size_t)numStandardChars, sizeof(int));
15295     if (!stdType)
15296         {
15297         MrBayesPrint ("%s   Problem allocating stdType (%d ints)\n", 4 * numStandardChars);
15298         return ERROR;
15299         }
15300     memAllocs[ALLOC_STDTYPE] = YES;
15301     stateSize = stdType + numStandardChars;
15302     tiIndex = stateSize + numStandardChars;
15303     bsIndex = tiIndex + numStandardChars;
15304
15305     /* then fill in stdType and stateSize, set pointers */
15306     /* also fill in isTiNeeded for each division and tiIndex for each character */
15307     for (d=j=0; d<numCurrentDivisions; d++)
15308         {
15309         mp = &modelParams[d];
15310         m = &modelSettings[d];
15311         
15312         if (mp->dataType != STANDARD)
15313             continue;
15314
15315         m->cType = stdType + j;
15316         m->nStates = stateSize + j;
15317         m->tiIndex = tiIndex + j;
15318         m->bsIndex = bsIndex + j;
15319
15320         m->cijkLength = 0;
15321         m->nCijkParts = 0;
15322         for (c=0; c<m->numChars; c++)
15323             {
15324             if (origChar[c+m->compMatrixStart] < 0)
15325                 {
15326                 /* this is a dummy character */
15327                 m->cType[c] = UNORD;
15328                 m->nStates[c] = 2;
15329                 }
15330             else
15331                 {
15332                 /* this is an ordinary character */
15333                 m->cType[c] = charInfo[origChar[c + m->compMatrixStart]].ctype;
15334                 m->nStates[c] = charInfo[origChar[c + m->compMatrixStart]].numStates;
15335                 }
15336             
15337             /* check ctype settings */
15338             if (m->nStates[c] < 2)
15339                 {
15340                 MrBayesPrint ("%s   WARNING: Compressed character %d (original character %d) of division %d has less \n", spacer, c+m->compCharStart,origChar[c+m->compCharStart]+1, d+1);
15341                 MrBayesPrint ("%s            than two observed states; it will be assumed to have two states.\n", spacer);
15342                 m->nStates[c] = 2;
15343                 }
15344             if (m->nStates[c] > 6 && m->cType[c] != UNORD)
15345                 {
15346                 MrBayesPrint ("%s   Only unordered model supported for characters with more than 6 states\n", spacer);
15347                 return ERROR;
15348                 }
15349             if (m->nStates[c] == 2 && m->cType[c] == ORD)
15350                 m->cType[c] = UNORD;
15351             if (m->cType[c] == IRREV)
15352                 {
15353                 MrBayesPrint ("%s   Irreversible model not yet supported\n", spacer);
15354                 return ERROR;
15355                 }
15356             
15357             /* find max number of states */
15358             if (m->nStates[c] > m->numModelStates)
15359                 m->numModelStates = m->nStates[c];
15360
15361             /* update Cijk info */
15362             if (strcmp(mp->symPiPr,"Fixed") != 0 || AreDoublesEqual(mp->symBetaFix, -1.0, 0.00001) == NO)
15363                 {
15364                 /* Asymmetry between stationary state frequencies -- we need one cijk and eigenvalue
15365                     set for each multistate character */
15366                 if (m->nStates[c] > 2 && (m->cType[c] == UNORD || m->cType[c] == ORD))
15367                     {
15368                     ts = m->nStates[c];
15369                     m->cijkLength += (ts * ts * ts) + (2 * ts);
15370                     m->nCijkParts++;
15371                     }
15372                 }
15373
15374             /* set the ti probs needed */
15375             if (m->stateFreq->nValues == 0 || m->nStates[c] == 2)
15376                 {
15377                 if (m->cType[c] == UNORD)
15378                     m->isTiNeeded[m->nStates[c]-2] = YES;
15379                 if (m->cType[c] == ORD)
15380                     m->isTiNeeded[m->nStates[c]+6] = YES;
15381                 if (m->cType[c] == IRREV)
15382                     m->isTiNeeded[m->nStates[c]+11] = YES;
15383                 }
15384             }
15385
15386         /* set ti index for each compressed character first         */
15387         /* set bs index later (below)                               */
15388
15389         /* set base index, valid for binary chars */
15390         m->tiIndex[c] = 0;
15391
15392         /* first adjust for unordered characters */
15393         for (k=0; k<9; k++)
15394             {
15395             if (m->isTiNeeded [k] == NO)
15396                 continue;
15397
15398             for (c=0; c<m->numChars; c++)
15399                 {
15400                 if (m->cType[c] != UNORD || m->nStates[c] > k + 2)
15401                     {
15402                     m->tiIndex[c] += (k + 2) * (k + 2) * m->numGammaCats;
15403                     }
15404                 }
15405             }
15406
15407         /* second for ordered characters */
15408         for (k=9; k<13; k++)
15409             {
15410             if (m->isTiNeeded [k] == NO)
15411                 continue;
15412
15413             for (c=0; c<m->numChars; c++)
15414                 {
15415                 if (m->cType[c] == IRREV || (m->cType[c] == ORD && m->nStates[c] > k - 6))
15416                     {
15417                     m->tiIndex[c] += (k - 6) * (k - 6) * m->numGammaCats;
15418                     }
15419                 }
15420             }
15421
15422         /* third for irrev characters */
15423         for (k=13; k<18; k++)
15424             {
15425             if (m->isTiNeeded [k] == NO)
15426                 continue;
15427
15428             for (c=0; c<m->numChars; c++)
15429                 {
15430                 if (m->cType[c] == IRREV && m->nStates[c] > k - 11)
15431                     {
15432                     m->tiIndex[c] += (k - 11) * (k - 11) * m->numGammaCats;
15433                     }
15434                 }
15435             }
15436
15437         /* finally take beta cats into account in tiIndex        */
15438         /* the beta cats will only be used for binary characters */
15439         /* multistate characters get their ti indices reset here */
15440         if (m->numBetaCats > 1 && m->isTiNeeded[0] == YES)
15441             {
15442             k = 4 * m->numBetaCats * m->numGammaCats;   /* offset for binary character ti probs */
15443             for (c=0; c<m->numChars; c++)
15444                 {
15445                 if (m->nStates[c] > 2)
15446                     {
15447                     m->tiIndex[c] = k;
15448                     k += m->nStates[c] * m->nStates[c] * m->numGammaCats;
15449                     }
15450                 }
15451             }
15452         j += m->numChars;
15453         }
15454     
15455     /* deal with bsIndex */
15456     for (k=0; k<numParams; k++)
15457         {
15458         p = &params[k];
15459         if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
15460             continue;
15461         p->nSympi = 0;
15462         p->hasBinaryStd = NO;
15463         for (i=0; i<p->nRelParts; i++)
15464             if (modelSettings[p->relParts[i]].isTiNeeded[0] == YES)
15465                 break;
15466         if (i < p->nRelParts)
15467             p->hasBinaryStd = YES;
15468         if (p->paramId == SYMPI_EQUAL)
15469             {
15470             /* calculate the number of state frequencies needed */
15471             /* also set bsIndex appropriately                   */
15472             for (n=index=0; n<9; n++)
15473                 {
15474                 for (i=0; i<p->nRelParts; i++)
15475                     if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
15476                         break;
15477                 if (i < p->nRelParts)
15478                     {
15479                     for (i=0; i<p->nRelParts; i++)
15480                         {
15481                         m = &modelSettings[p->relParts[i]];
15482                         for (c=0; c<m->numChars; c++)
15483                             {
15484                             if (m->cType[c] != UNORD || m->nStates[c] > n + 2)
15485                                 {
15486                                 m->bsIndex[c] += (n + 2);
15487                                 }
15488                             }
15489                         }
15490                     index += (n + 2);
15491                     }
15492                 }
15493             for (n=9; n<13; n++)
15494                 {
15495                 for (i=0; i<p->nRelParts; i++)
15496                     if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
15497                         break;
15498                 if (i < p->nRelParts)
15499                     {
15500                     for (i=0; i<p->nRelParts; i++)
15501                         {
15502                         m = &modelSettings[p->relParts[i]];
15503                         for (c=0; c<m->numChars; c++)
15504                             {
15505                             if (m->cType[c] == ORD && m->nStates[c] > n - 6)
15506                                 {
15507                                 m->bsIndex[c] += (n - 6);
15508                                 }
15509                             }
15510                         }
15511                     index += (n - 6);
15512                     }
15513                 }
15514             p->nStdStateFreqs = index;
15515             }
15516         else
15517             {
15518             /* if not equal we need space for beta category frequencies */
15519             index = 0;
15520             if (p->hasBinaryStd == YES)
15521                 index += (2 * modelSettings[p->relParts[0]].numBetaCats);
15522             /* as well as one set of frequencies for each multistate character */
15523             for (i=0; i<p->nRelParts; i++)
15524                 {
15525                 m = &modelSettings[p->relParts[i]];
15526                 for (c=0; c<m->numChars; c++)
15527                     {
15528                     if (m->nStates[c] > 2 && (m->cType[c] == UNORD || m->cType[c] == ORD))
15529                         {
15530                         m->bsIndex[c] = index;
15531                         index += m->nStates[c];
15532                         p->nSympi++;
15533                         }
15534                     }
15535                 }
15536             }
15537         p->nStdStateFreqs = index;
15538         }
15539     
15540     /* allocate space for bsIndex, sympiIndex, stdStateFreqs; then fill */
15541
15542     /* first count number of sympis needed */
15543     for (k=n=i=0; k<numParams; k++)
15544         {
15545         p = &params[k];
15546         n += p->nSympi;     /* nsympi calculated above */
15547         }
15548     
15549     /* then allocate and fill in */
15550     if (n > 0)
15551         {
15552         if (memAllocs[ALLOC_SYMPIINDEX] == YES)
15553             {
15554             sympiIndex = (int *) SafeRealloc ((void *) sympiIndex, 3*n * sizeof (int));
15555             for (i=0; i<3*n; i++)
15556                 sympiIndex[i] = 0;
15557             }
15558         else
15559             sympiIndex = (int *) SafeCalloc (3*n, sizeof (int));
15560         if (!sympiIndex)
15561             {
15562             MrBayesPrint ("%s   Problem allocating sympiIndex\n", spacer);
15563             return (ERROR);
15564             }
15565         else
15566             memAllocs[ALLOC_SYMPIINDEX] = YES;
15567         
15568         /* set up sympi pointers and fill sympiIndex */
15569         for (k=i=0; k<numParams; k++)
15570             {
15571             p = &params[k];
15572             if (p->nSympi > 0)
15573                 {
15574                 p->printParam = YES;    /* print even if fixed alpha_symdir */
15575                 index = 0;
15576                 p->sympiBsIndex = sympiIndex + i;
15577                 p->sympinStates = sympiIndex + i + n;
15578                 p->sympiCType = sympiIndex + i + (2 * n);
15579                 for (j=0; j<p->nRelParts; j++)
15580                     {                       
15581                     m = &modelSettings[p->relParts[j]];
15582                     for (c=0; c<m->numChars; c++)
15583                         {
15584                         if (m->nStates[c] > 2 && (m->cType[c] == UNORD || m->cType[c] == ORD))
15585                             {
15586                             p->sympinStates[index] = m->nStates[c];
15587                             p->sympiBsIndex[index] = m->bsIndex[c];
15588                             p->sympiCType[index] = m->cType[c];
15589                             origCharPos = origChar[m->compCharStart + c];
15590                             for (ts=0; ts<m->nStates[c]; ts++)
15591                                 {
15592                                 sprintf (piHeader, "\tpi_%d(%d)", origCharPos+1, ts);
15593                                 SafeStrcat(&p->paramHeader, piHeader);
15594                                 }
15595                             index++;
15596                             }
15597                         }
15598                     }
15599                 assert (index == p->nSympi);
15600                 i += p->nSympi;
15601                 }
15602             }
15603         assert (i == n);
15604         }
15605     
15606     /* count space needed for state frequencies */
15607     for (k=n=0; k<numParams; k++)
15608         {
15609         p = &params[k];
15610         if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
15611             continue;
15612         n += p->nStdStateFreqs;
15613         }
15614     
15615     stdStateFreqsRowSize = n;
15616     
15617     /* allocate space */
15618     if (memAllocs[ALLOC_STDSTATEFREQS] == YES)
15619         {
15620         free (stdStateFreqs);
15621         stdStateFreqs = NULL;
15622         memAllocs[ALLOC_STDSTATEFREQS] = NO;
15623         }
15624     stdStateFreqs = (MrBFlt *) SafeCalloc (n * 2 * numGlobalChains, sizeof (MrBFlt));
15625     if (!stdStateFreqs)
15626         {
15627         MrBayesPrint ("%s   Problem allocating stdStateFreqs in ProcessStdChars\n", spacer);
15628         return (ERROR);
15629         }
15630     else
15631         memAllocs[ALLOC_STDSTATEFREQS] = YES;
15632     
15633     /* set pointers */
15634     for (k=n=0; k<numParams; k++)
15635         {
15636         p = &params[k];
15637         if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
15638             continue;
15639         p->stdStateFreqs = stdStateFreqs + n;
15640         n += p->nStdStateFreqs;
15641         }
15642     
15643     FillStdStateFreqs (0 , numGlobalChains, seed);
15644
15645     return (NO_ERROR);
15646 }
15647
15648
15649 int SetAARates (void)
15650 {
15651     int         i, j;
15652     MrBFlt      diff, sum, scaler;
15653     
15654     /* A R N D C Q E G H I L K M F P S T W Y V */
15655
15656     /* jones */
15657     aaJones[ 0][ 0] =   0; aaJones[ 0][ 1] =  58; aaJones[ 0][ 2] =  54; aaJones[ 0][ 3] =  81; aaJones[ 0][ 4] =  56; 
15658     aaJones[ 0][ 5] =  57; aaJones[ 0][ 6] = 105; aaJones[ 0][ 7] = 179; aaJones[ 0][ 8] =  27; aaJones[ 0][ 9] =  36; 
15659     aaJones[ 0][10] =  30; aaJones[ 0][11] =  35; aaJones[ 0][12] =  54; aaJones[ 0][13] =  15; aaJones[ 0][14] = 194; 
15660     aaJones[ 0][15] = 378; aaJones[ 0][16] = 475; aaJones[ 0][17] =   9; aaJones[ 0][18] =  11; aaJones[ 0][19] = 298; 
15661     aaJones[ 1][ 0] =  58; aaJones[ 1][ 1] =   0; aaJones[ 1][ 2] =  45; aaJones[ 1][ 3] =  16; aaJones[ 1][ 4] = 113; 
15662     aaJones[ 1][ 5] = 310; aaJones[ 1][ 6] =  29; aaJones[ 1][ 7] = 137; aaJones[ 1][ 8] = 328; aaJones[ 1][ 9] =  22; 
15663     aaJones[ 1][10] =  38; aaJones[ 1][11] = 646; aaJones[ 1][12] =  44; aaJones[ 1][13] =   5; aaJones[ 1][14] =  74; 
15664     aaJones[ 1][15] = 101; aaJones[ 1][16] =  64; aaJones[ 1][17] = 126; aaJones[ 1][18] =  20; aaJones[ 1][19] =  17; 
15665     aaJones[ 2][ 0] =  54; aaJones[ 2][ 1] =  45; aaJones[ 2][ 2] =   0; aaJones[ 2][ 3] = 528; aaJones[ 2][ 4] =  34; 
15666     aaJones[ 2][ 5] =  86; aaJones[ 2][ 6] =  58; aaJones[ 2][ 7] =  81; aaJones[ 2][ 8] = 391; aaJones[ 2][ 9] =  47; 
15667     aaJones[ 2][10] =  12; aaJones[ 2][11] = 263; aaJones[ 2][12] =  30; aaJones[ 2][13] =  10; aaJones[ 2][14] =  15; 
15668     aaJones[ 2][15] = 503; aaJones[ 2][16] = 232; aaJones[ 2][17] =   8; aaJones[ 2][18] =  70; aaJones[ 2][19] =  16; 
15669     aaJones[ 3][ 0] =  81; aaJones[ 3][ 1] =  16; aaJones[ 3][ 2] = 528; aaJones[ 3][ 3] =   0; aaJones[ 3][ 4] =  10; 
15670     aaJones[ 3][ 5] =  49; aaJones[ 3][ 6] = 767; aaJones[ 3][ 7] = 130; aaJones[ 3][ 8] = 112; aaJones[ 3][ 9] =  11; 
15671     aaJones[ 3][10] =   7; aaJones[ 3][11] =  26; aaJones[ 3][12] =  15; aaJones[ 3][13] =   4; aaJones[ 3][14] =  15; 
15672     aaJones[ 3][15] =  59; aaJones[ 3][16] =  38; aaJones[ 3][17] =   4; aaJones[ 3][18] =  46; aaJones[ 3][19] =  31; 
15673     aaJones[ 4][ 0] =  56; aaJones[ 4][ 1] = 113; aaJones[ 4][ 2] =  34; aaJones[ 4][ 3] =  10; aaJones[ 4][ 4] =   0; 
15674     aaJones[ 4][ 5] =   9; aaJones[ 4][ 6] =   5; aaJones[ 4][ 7] =  59; aaJones[ 4][ 8] =  69; aaJones[ 4][ 9] =  17; 
15675     aaJones[ 4][10] =  23; aaJones[ 4][11] =   7; aaJones[ 4][12] =  31; aaJones[ 4][13] =  78; aaJones[ 4][14] =  14; 
15676     aaJones[ 4][15] = 223; aaJones[ 4][16] =  42; aaJones[ 4][17] = 115; aaJones[ 4][18] = 209; aaJones[ 4][19] =  62; 
15677     aaJones[ 5][ 0] =  57; aaJones[ 5][ 1] = 310; aaJones[ 5][ 2] =  86; aaJones[ 5][ 3] =  49; aaJones[ 5][ 4] =   9; 
15678     aaJones[ 5][ 5] =   0; aaJones[ 5][ 6] = 323; aaJones[ 5][ 7] =  26; aaJones[ 5][ 8] = 597; aaJones[ 5][ 9] =   9; 
15679     aaJones[ 5][10] =  72; aaJones[ 5][11] = 292; aaJones[ 5][12] =  43; aaJones[ 5][13] =   4; aaJones[ 5][14] = 164; 
15680     aaJones[ 5][15] =  53; aaJones[ 5][16] =  51; aaJones[ 5][17] =  18; aaJones[ 5][18] =  24; aaJones[ 5][19] =  20; 
15681     aaJones[ 6][ 0] = 105; aaJones[ 6][ 1] =  29; aaJones[ 6][ 2] =  58; aaJones[ 6][ 3] = 767; aaJones[ 6][ 4] =   5; 
15682     aaJones[ 6][ 5] = 323; aaJones[ 6][ 6] =   0; aaJones[ 6][ 7] = 119; aaJones[ 6][ 8] =  26; aaJones[ 6][ 9] =  12; 
15683     aaJones[ 6][10] =   9; aaJones[ 6][11] = 181; aaJones[ 6][12] =  18; aaJones[ 6][13] =   5; aaJones[ 6][14] =  18; 
15684     aaJones[ 6][15] =  30; aaJones[ 6][16] =  32; aaJones[ 6][17] =  10; aaJones[ 6][18] =   7; aaJones[ 6][19] =  45; 
15685     aaJones[ 7][ 0] = 179; aaJones[ 7][ 1] = 137; aaJones[ 7][ 2] =  81; aaJones[ 7][ 3] = 130; aaJones[ 7][ 4] =  59; 
15686     aaJones[ 7][ 5] =  26; aaJones[ 7][ 6] = 119; aaJones[ 7][ 7] =   0; aaJones[ 7][ 8] =  23; aaJones[ 7][ 9] =   6; 
15687     aaJones[ 7][10] =   6; aaJones[ 7][11] =  27; aaJones[ 7][12] =  14; aaJones[ 7][13] =   5; aaJones[ 7][14] =  24; 
15688     aaJones[ 7][15] = 201; aaJones[ 7][16] =  33; aaJones[ 7][17] =  55; aaJones[ 7][18] =   8; aaJones[ 7][19] =  47; 
15689     aaJones[ 8][ 0] =  27; aaJones[ 8][ 1] = 328; aaJones[ 8][ 2] = 391; aaJones[ 8][ 3] = 112; aaJones[ 8][ 4] =  69; 
15690     aaJones[ 8][ 5] = 597; aaJones[ 8][ 6] =  26; aaJones[ 8][ 7] =  23; aaJones[ 8][ 8] =   0; aaJones[ 8][ 9] =  16; 
15691     aaJones[ 8][10] =  56; aaJones[ 8][11] =  45; aaJones[ 8][12] =  33; aaJones[ 8][13] =  40; aaJones[ 8][14] = 115; 
15692     aaJones[ 8][15] =  73; aaJones[ 8][16] =  46; aaJones[ 8][17] =   8; aaJones[ 8][18] = 573; aaJones[ 8][19] =  11; 
15693     aaJones[ 9][ 0] =  36; aaJones[ 9][ 1] =  22; aaJones[ 9][ 2] =  47; aaJones[ 9][ 3] =  11; aaJones[ 9][ 4] =  17; 
15694     aaJones[ 9][ 5] =   9; aaJones[ 9][ 6] =  12; aaJones[ 9][ 7] =   6; aaJones[ 9][ 8] =  16; aaJones[ 9][ 9] =   0; 
15695     aaJones[ 9][10] = 229; aaJones[ 9][11] =  21; aaJones[ 9][12] = 479; aaJones[ 9][13] =  89; aaJones[ 9][14] =  10; 
15696     aaJones[ 9][15] =  40; aaJones[ 9][16] = 245; aaJones[ 9][17] =   9; aaJones[ 9][18] =  32; aaJones[ 9][19] = 961; 
15697     aaJones[10][ 0] =  30; aaJones[10][ 1] =  38; aaJones[10][ 2] =  12; aaJones[10][ 3] =   7; aaJones[10][ 4] =  23; 
15698     aaJones[10][ 5] =  72; aaJones[10][ 6] =   9; aaJones[10][ 7] =   6; aaJones[10][ 8] =  56; aaJones[10][ 9] = 229; 
15699     aaJones[10][10] =   0; aaJones[10][11] =  14; aaJones[10][12] = 388; aaJones[10][13] = 248; aaJones[10][14] = 102; 
15700     aaJones[10][15] =  59; aaJones[10][16] =  25; aaJones[10][17] =  52; aaJones[10][18] =  24; aaJones[10][19] = 180; 
15701     aaJones[11][ 0] =  35; aaJones[11][ 1] = 646; aaJones[11][ 2] = 263; aaJones[11][ 3] =  26; aaJones[11][ 4] =   7; 
15702     aaJones[11][ 5] = 292; aaJones[11][ 6] = 181; aaJones[11][ 7] =  27; aaJones[11][ 8] =  45; aaJones[11][ 9] =  21; 
15703     aaJones[11][10] =  14; aaJones[11][11] =   0; aaJones[11][12] =  65; aaJones[11][13] =   4; aaJones[11][14] =  21; 
15704     aaJones[11][15] =  47; aaJones[11][16] = 103; aaJones[11][17] =  10; aaJones[11][18] =   8; aaJones[11][19] =  14; 
15705     aaJones[12][ 0] =  54; aaJones[12][ 1] =  44; aaJones[12][ 2] =  30; aaJones[12][ 3] =  15; aaJones[12][ 4] =  31; 
15706     aaJones[12][ 5] =  43; aaJones[12][ 6] =  18; aaJones[12][ 7] =  14; aaJones[12][ 8] =  33; aaJones[12][ 9] = 479; 
15707     aaJones[12][10] = 388; aaJones[12][11] =  65; aaJones[12][12] =   0; aaJones[12][13] =  43; aaJones[12][14] =  16; 
15708     aaJones[12][15] =  29; aaJones[12][16] = 226; aaJones[12][17] =  24; aaJones[12][18] =  18; aaJones[12][19] = 323; 
15709     aaJones[13][ 0] =  15; aaJones[13][ 1] =   5; aaJones[13][ 2] =  10; aaJones[13][ 3] =   4; aaJones[13][ 4] =  78; 
15710     aaJones[13][ 5] =   4; aaJones[13][ 6] =   5; aaJones[13][ 7] =   5; aaJones[13][ 8] =  40; aaJones[13][ 9] =  89; 
15711     aaJones[13][10] = 248; aaJones[13][11] =   4; aaJones[13][12] =  43; aaJones[13][13] =   0; aaJones[13][14] =  17; 
15712     aaJones[13][15] =  92; aaJones[13][16] =  12; aaJones[13][17] =  53; aaJones[13][18] = 536; aaJones[13][19] =  62; 
15713     aaJones[14][ 0] = 194; aaJones[14][ 1] =  74; aaJones[14][ 2] =  15; aaJones[14][ 3] =  15; aaJones[14][ 4] =  14; 
15714     aaJones[14][ 5] = 164; aaJones[14][ 6] =  18; aaJones[14][ 7] =  24; aaJones[14][ 8] = 115; aaJones[14][ 9] =  10; 
15715     aaJones[14][10] = 102; aaJones[14][11] =  21; aaJones[14][12] =  16; aaJones[14][13] =  17; aaJones[14][14] =   0; 
15716     aaJones[14][15] = 285; aaJones[14][16] = 118; aaJones[14][17] =   6; aaJones[14][18] =  10; aaJones[14][19] =  23; 
15717     aaJones[15][ 0] = 378; aaJones[15][ 1] = 101; aaJones[15][ 2] = 503; aaJones[15][ 3] =  59; aaJones[15][ 4] = 223; 
15718     aaJones[15][ 5] =  53; aaJones[15][ 6] =  30; aaJones[15][ 7] = 201; aaJones[15][ 8] =  73; aaJones[15][ 9] =  40; 
15719     aaJones[15][10] =  59; aaJones[15][11] =  47; aaJones[15][12] =  29; aaJones[15][13] =  92; aaJones[15][14] = 285; 
15720     aaJones[15][15] =   0; aaJones[15][16] = 477; aaJones[15][17] =  35; aaJones[15][18] =  63; aaJones[15][19] =  38; 
15721     aaJones[16][ 0] = 475; aaJones[16][ 1] =  64; aaJones[16][ 2] = 232; aaJones[16][ 3] =  38; aaJones[16][ 4] =  42; 
15722     aaJones[16][ 5] =  51; aaJones[16][ 6] =  32; aaJones[16][ 7] =  33; aaJones[16][ 8] =  46; aaJones[16][ 9] = 245; 
15723     aaJones[16][10] =  25; aaJones[16][11] = 103; aaJones[16][12] = 226; aaJones[16][13] =  12; aaJones[16][14] = 118; 
15724     aaJones[16][15] = 477; aaJones[16][16] =   0; aaJones[16][17] =  12; aaJones[16][18] =  21; aaJones[16][19] = 112; 
15725     aaJones[17][ 0] =   9; aaJones[17][ 1] = 126; aaJones[17][ 2] =   8; aaJones[17][ 3] =   4; aaJones[17][ 4] = 115; 
15726     aaJones[17][ 5] =  18; aaJones[17][ 6] =  10; aaJones[17][ 7] =  55; aaJones[17][ 8] =   8; aaJones[17][ 9] =   9; 
15727     aaJones[17][10] =  52; aaJones[17][11] =  10; aaJones[17][12] =  24; aaJones[17][13] =  53; aaJones[17][14] =   6; 
15728     aaJones[17][15] =  35; aaJones[17][16] =  12; aaJones[17][17] =   0; aaJones[17][18] =  71; aaJones[17][19] =  25; 
15729     aaJones[18][ 0] =  11; aaJones[18][ 1] =  20; aaJones[18][ 2] =  70; aaJones[18][ 3] =  46; aaJones[18][ 4] = 209; 
15730     aaJones[18][ 5] =  24; aaJones[18][ 6] =   7; aaJones[18][ 7] =   8; aaJones[18][ 8] = 573; aaJones[18][ 9] =  32; 
15731     aaJones[18][10] =  24; aaJones[18][11] =   8; aaJones[18][12] =  18; aaJones[18][13] = 536; aaJones[18][14] =  10; 
15732     aaJones[18][15] =  63; aaJones[18][16] =  21; aaJones[18][17] =  71; aaJones[18][18] =   0; aaJones[18][19] =  16; 
15733     aaJones[19][ 0] = 298; aaJones[19][ 1] =  17; aaJones[19][ 2] =  16; aaJones[19][ 3] =  31; aaJones[19][ 4] =  62; 
15734     aaJones[19][ 5] =  20; aaJones[19][ 6] =  45; aaJones[19][ 7] =  47; aaJones[19][ 8] =  11; aaJones[19][ 9] = 961; 
15735     aaJones[19][10] = 180; aaJones[19][11] =  14; aaJones[19][12] = 323; aaJones[19][13] =  62; aaJones[19][14] =  23; 
15736     aaJones[19][15] =  38; aaJones[19][16] = 112; aaJones[19][17] =  25; aaJones[19][18] =  16; aaJones[19][19] =   0;
15737
15738     jonesPi[ 0] = 0.076748;
15739     jonesPi[ 1] = 0.051691;
15740     jonesPi[ 2] = 0.042645;
15741     jonesPi[ 3] = 0.051544;
15742     jonesPi[ 4] = 0.019803;
15743     jonesPi[ 5] = 0.040752;
15744     jonesPi[ 6] = 0.061830;
15745     jonesPi[ 7] = 0.073152;
15746     jonesPi[ 8] = 0.022944;
15747     jonesPi[ 9] = 0.053761;
15748     jonesPi[10] = 0.091904;
15749     jonesPi[11] = 0.058676;
15750     jonesPi[12] = 0.023826;
15751     jonesPi[13] = 0.040126;
15752     jonesPi[14] = 0.050901;
15753     jonesPi[15] = 0.068765;
15754     jonesPi[16] = 0.058565;
15755     jonesPi[17] = 0.014261;
15756     jonesPi[18] = 0.032102;
15757     jonesPi[19] = 0.066005;
15758
15759     /* dayhoff */
15760     aaDayhoff[ 0][ 0] =   0; aaDayhoff[ 0][ 1] =  27; aaDayhoff[ 0][ 2] =  98; aaDayhoff[ 0][ 3] = 120; aaDayhoff[ 0][ 4] =  36; 
15761     aaDayhoff[ 0][ 5] =  89; aaDayhoff[ 0][ 6] = 198; aaDayhoff[ 0][ 7] = 240; aaDayhoff[ 0][ 8] =  23; aaDayhoff[ 0][ 9] =  65; 
15762     aaDayhoff[ 0][10] =  41; aaDayhoff[ 0][11] =  26; aaDayhoff[ 0][12] =  72; aaDayhoff[ 0][13] =  18; aaDayhoff[ 0][14] = 250; 
15763     aaDayhoff[ 0][15] = 409; aaDayhoff[ 0][16] = 371; aaDayhoff[ 0][17] =   0; aaDayhoff[ 0][18] =  24; aaDayhoff[ 0][19] = 208; 
15764     aaDayhoff[ 1][ 0] =  27; aaDayhoff[ 1][ 1] =   0; aaDayhoff[ 1][ 2] =  32; aaDayhoff[ 1][ 3] =   0; aaDayhoff[ 1][ 4] =  23; 
15765     aaDayhoff[ 1][ 5] = 246; aaDayhoff[ 1][ 6] =   1; aaDayhoff[ 1][ 7] =   9; aaDayhoff[ 1][ 8] = 240; aaDayhoff[ 1][ 9] =  64; 
15766     aaDayhoff[ 1][10] =  15; aaDayhoff[ 1][11] = 464; aaDayhoff[ 1][12] =  90; aaDayhoff[ 1][13] =  14; aaDayhoff[ 1][14] = 103; 
15767     aaDayhoff[ 1][15] = 154; aaDayhoff[ 1][16] =  26; aaDayhoff[ 1][17] = 201; aaDayhoff[ 1][18] =   8; aaDayhoff[ 1][19] =  24; 
15768     aaDayhoff[ 2][ 0] =  98; aaDayhoff[ 2][ 1] =  32; aaDayhoff[ 2][ 2] =   0; aaDayhoff[ 2][ 3] = 905; aaDayhoff[ 2][ 4] =   0; 
15769     aaDayhoff[ 2][ 5] = 103; aaDayhoff[ 2][ 6] = 148; aaDayhoff[ 2][ 7] = 139; aaDayhoff[ 2][ 8] = 535; aaDayhoff[ 2][ 9] =  77; 
15770     aaDayhoff[ 2][10] =  34; aaDayhoff[ 2][11] = 318; aaDayhoff[ 2][12] =   1; aaDayhoff[ 2][13] =  14; aaDayhoff[ 2][14] =  42; 
15771     aaDayhoff[ 2][15] = 495; aaDayhoff[ 2][16] = 229; aaDayhoff[ 2][17] =  23; aaDayhoff[ 2][18] =  95; aaDayhoff[ 2][19] =  15; 
15772     aaDayhoff[ 3][ 0] = 120; aaDayhoff[ 3][ 1] =   0; aaDayhoff[ 3][ 2] = 905; aaDayhoff[ 3][ 3] =   0; aaDayhoff[ 3][ 4] =   0; 
15773     aaDayhoff[ 3][ 5] = 134; aaDayhoff[ 3][ 6] = 1153; aaDayhoff[ 3][ 7] = 125; aaDayhoff[ 3][ 8] =  86; aaDayhoff[ 3][ 9] =  24; 
15774     aaDayhoff[ 3][10] =   0; aaDayhoff[ 3][11] =  71; aaDayhoff[ 3][12] =   0; aaDayhoff[ 3][13] =   0; aaDayhoff[ 3][14] =  13; 
15775     aaDayhoff[ 3][15] =  95; aaDayhoff[ 3][16] =  66; aaDayhoff[ 3][17] =   0; aaDayhoff[ 3][18] =   0; aaDayhoff[ 3][19] =  18; 
15776     aaDayhoff[ 4][ 0] =  36; aaDayhoff[ 4][ 1] =  23; aaDayhoff[ 4][ 2] =   0; aaDayhoff[ 4][ 3] =   0; aaDayhoff[ 4][ 4] =   0; 
15777     aaDayhoff[ 4][ 5] =   0; aaDayhoff[ 4][ 6] =   0; aaDayhoff[ 4][ 7] =  11; aaDayhoff[ 4][ 8] =  28; aaDayhoff[ 4][ 9] =  44; 
15778     aaDayhoff[ 4][10] =   0; aaDayhoff[ 4][11] =   0; aaDayhoff[ 4][12] =   0; aaDayhoff[ 4][13] =   0; aaDayhoff[ 4][14] =  19; 
15779     aaDayhoff[ 4][15] = 161; aaDayhoff[ 4][16] =  16; aaDayhoff[ 4][17] =   0; aaDayhoff[ 4][18] =  96; aaDayhoff[ 4][19] =  49; 
15780     aaDayhoff[ 5][ 0] =  89; aaDayhoff[ 5][ 1] = 246; aaDayhoff[ 5][ 2] = 103; aaDayhoff[ 5][ 3] = 134; aaDayhoff[ 5][ 4] =   0; 
15781     aaDayhoff[ 5][ 5] =   0; aaDayhoff[ 5][ 6] = 716; aaDayhoff[ 5][ 7] =  28; aaDayhoff[ 5][ 8] = 606; aaDayhoff[ 5][ 9] =  18; 
15782     aaDayhoff[ 5][10] =  73; aaDayhoff[ 5][11] = 153; aaDayhoff[ 5][12] = 114; aaDayhoff[ 5][13] =   0; aaDayhoff[ 5][14] = 153; 
15783     aaDayhoff[ 5][15] =  56; aaDayhoff[ 5][16] =  53; aaDayhoff[ 5][17] =   0; aaDayhoff[ 5][18] =   0; aaDayhoff[ 5][19] =  35; 
15784     aaDayhoff[ 6][ 0] = 198; aaDayhoff[ 6][ 1] =   1; aaDayhoff[ 6][ 2] = 148; aaDayhoff[ 6][ 3] = 1153; aaDayhoff[ 6][ 4] =   0; 
15785     aaDayhoff[ 6][ 5] = 716; aaDayhoff[ 6][ 6] =   0; aaDayhoff[ 6][ 7] =  81; aaDayhoff[ 6][ 8] =  43; aaDayhoff[ 6][ 9] =  61; 
15786     aaDayhoff[ 6][10] =  11; aaDayhoff[ 6][11] =  83; aaDayhoff[ 6][12] =  30; aaDayhoff[ 6][13] =   0; aaDayhoff[ 6][14] =  51; 
15787     aaDayhoff[ 6][15] =  79; aaDayhoff[ 6][16] =  34; aaDayhoff[ 6][17] =   0; aaDayhoff[ 6][18] =  22; aaDayhoff[ 6][19] =  37; 
15788     aaDayhoff[ 7][ 0] = 240; aaDayhoff[ 7][ 1] =   9; aaDayhoff[ 7][ 2] = 139; aaDayhoff[ 7][ 3] = 125; aaDayhoff[ 7][ 4] =  11; 
15789     aaDayhoff[ 7][ 5] =  28; aaDayhoff[ 7][ 6] =  81; aaDayhoff[ 7][ 7] =   0; aaDayhoff[ 7][ 8] =  10; aaDayhoff[ 7][ 9] =   0; 
15790     aaDayhoff[ 7][10] =   7; aaDayhoff[ 7][11] =  27; aaDayhoff[ 7][12] =  17; aaDayhoff[ 7][13] =  15; aaDayhoff[ 7][14] =  34; 
15791     aaDayhoff[ 7][15] = 234; aaDayhoff[ 7][16] =  30; aaDayhoff[ 7][17] =   0; aaDayhoff[ 7][18] =   0; aaDayhoff[ 7][19] =  54; 
15792     aaDayhoff[ 8][ 0] =  23; aaDayhoff[ 8][ 1] = 240; aaDayhoff[ 8][ 2] = 535; aaDayhoff[ 8][ 3] =  86; aaDayhoff[ 8][ 4] =  28; 
15793     aaDayhoff[ 8][ 5] = 606; aaDayhoff[ 8][ 6] =  43; aaDayhoff[ 8][ 7] =  10; aaDayhoff[ 8][ 8] =   0; aaDayhoff[ 8][ 9] =   7; 
15794     aaDayhoff[ 8][10] =  44; aaDayhoff[ 8][11] =  26; aaDayhoff[ 8][12] =   0; aaDayhoff[ 8][13] =  48; aaDayhoff[ 8][14] =  94; 
15795     aaDayhoff[ 8][15] =  35; aaDayhoff[ 8][16] =  22; aaDayhoff[ 8][17] =  27; aaDayhoff[ 8][18] = 127; aaDayhoff[ 8][19] =  44; 
15796     aaDayhoff[ 9][ 0] =  65; aaDayhoff[ 9][ 1] =  64; aaDayhoff[ 9][ 2] =  77; aaDayhoff[ 9][ 3] =  24; aaDayhoff[ 9][ 4] =  44; 
15797     aaDayhoff[ 9][ 5] =  18; aaDayhoff[ 9][ 6] =  61; aaDayhoff[ 9][ 7] =   0; aaDayhoff[ 9][ 8] =   7; aaDayhoff[ 9][ 9] =   0; 
15798     aaDayhoff[ 9][10] = 257; aaDayhoff[ 9][11] =  46; aaDayhoff[ 9][12] = 336; aaDayhoff[ 9][13] = 196; aaDayhoff[ 9][14] =  12; 
15799     aaDayhoff[ 9][15] =  24; aaDayhoff[ 9][16] = 192; aaDayhoff[ 9][17] =   0; aaDayhoff[ 9][18] =  37; aaDayhoff[ 9][19] = 889; 
15800     aaDayhoff[10][ 0] =  41; aaDayhoff[10][ 1] =  15; aaDayhoff[10][ 2] =  34; aaDayhoff[10][ 3] =   0; aaDayhoff[10][ 4] =   0; 
15801     aaDayhoff[10][ 5] =  73; aaDayhoff[10][ 6] =  11; aaDayhoff[10][ 7] =   7; aaDayhoff[10][ 8] =  44; aaDayhoff[10][ 9] = 257; 
15802     aaDayhoff[10][10] =   0; aaDayhoff[10][11] =  18; aaDayhoff[10][12] = 527; aaDayhoff[10][13] = 157; aaDayhoff[10][14] =  32; 
15803     aaDayhoff[10][15] =  17; aaDayhoff[10][16] =  33; aaDayhoff[10][17] =  46; aaDayhoff[10][18] =  28; aaDayhoff[10][19] = 175; 
15804     aaDayhoff[11][ 0] =  26; aaDayhoff[11][ 1] = 464; aaDayhoff[11][ 2] = 318; aaDayhoff[11][ 3] =  71; aaDayhoff[11][ 4] =   0; 
15805     aaDayhoff[11][ 5] = 153; aaDayhoff[11][ 6] =  83; aaDayhoff[11][ 7] =  27; aaDayhoff[11][ 8] =  26; aaDayhoff[11][ 9] =  46; 
15806     aaDayhoff[11][10] =  18; aaDayhoff[11][11] =   0; aaDayhoff[11][12] = 243; aaDayhoff[11][13] =   0; aaDayhoff[11][14] =  33; 
15807     aaDayhoff[11][15] =  96; aaDayhoff[11][16] = 136; aaDayhoff[11][17] =   0; aaDayhoff[11][18] =  13; aaDayhoff[11][19] =  10; 
15808     aaDayhoff[12][ 0] =  72; aaDayhoff[12][ 1] =  90; aaDayhoff[12][ 2] =   1; aaDayhoff[12][ 3] =   0; aaDayhoff[12][ 4] =   0; 
15809     aaDayhoff[12][ 5] = 114; aaDayhoff[12][ 6] =  30; aaDayhoff[12][ 7] =  17; aaDayhoff[12][ 8] =   0; aaDayhoff[12][ 9] = 336; 
15810     aaDayhoff[12][10] = 527; aaDayhoff[12][11] = 243; aaDayhoff[12][12] =   0; aaDayhoff[12][13] =  92; aaDayhoff[12][14] =  17; 
15811     aaDayhoff[12][15] =  62; aaDayhoff[12][16] = 104; aaDayhoff[12][17] =   0; aaDayhoff[12][18] =   0; aaDayhoff[12][19] = 258; 
15812     aaDayhoff[13][ 0] =  18; aaDayhoff[13][ 1] =  14; aaDayhoff[13][ 2] =  14; aaDayhoff[13][ 3] =   0; aaDayhoff[13][ 4] =   0; 
15813     aaDayhoff[13][ 5] =   0; aaDayhoff[13][ 6] =   0; aaDayhoff[13][ 7] =  15; aaDayhoff[13][ 8] =  48; aaDayhoff[13][ 9] = 196; 
15814     aaDayhoff[13][10] = 157; aaDayhoff[13][11] =   0; aaDayhoff[13][12] =  92; aaDayhoff[13][13] =   0; aaDayhoff[13][14] =  11; 
15815     aaDayhoff[13][15] =  46; aaDayhoff[13][16] =  13; aaDayhoff[13][17] =  76; aaDayhoff[13][18] = 698; aaDayhoff[13][19] =  12; 
15816     aaDayhoff[14][ 0] = 250; aaDayhoff[14][ 1] = 103; aaDayhoff[14][ 2] =  42; aaDayhoff[14][ 3] =  13; aaDayhoff[14][ 4] =  19; 
15817     aaDayhoff[14][ 5] = 153; aaDayhoff[14][ 6] =  51; aaDayhoff[14][ 7] =  34; aaDayhoff[14][ 8] =  94; aaDayhoff[14][ 9] =  12; 
15818     aaDayhoff[14][10] =  32; aaDayhoff[14][11] =  33; aaDayhoff[14][12] =  17; aaDayhoff[14][13] =  11; aaDayhoff[14][14] =   0; 
15819     aaDayhoff[14][15] = 245; aaDayhoff[14][16] =  78; aaDayhoff[14][17] =   0; aaDayhoff[14][18] =   0; aaDayhoff[14][19] =  48; 
15820     aaDayhoff[15][ 0] = 409; aaDayhoff[15][ 1] = 154; aaDayhoff[15][ 2] = 495; aaDayhoff[15][ 3] =  95; aaDayhoff[15][ 4] = 161; 
15821     aaDayhoff[15][ 5] =  56; aaDayhoff[15][ 6] =  79; aaDayhoff[15][ 7] = 234; aaDayhoff[15][ 8] =  35; aaDayhoff[15][ 9] =  24; 
15822     aaDayhoff[15][10] =  17; aaDayhoff[15][11] =  96; aaDayhoff[15][12] =  62; aaDayhoff[15][13] =  46; aaDayhoff[15][14] = 245; 
15823     aaDayhoff[15][15] =   0; aaDayhoff[15][16] = 550; aaDayhoff[15][17] =  75; aaDayhoff[15][18] =  34; aaDayhoff[15][19] =  30; 
15824     aaDayhoff[16][ 0] = 371; aaDayhoff[16][ 1] =  26; aaDayhoff[16][ 2] = 229; aaDayhoff[16][ 3] =  66; aaDayhoff[16][ 4] =  16; 
15825     aaDayhoff[16][ 5] =  53; aaDayhoff[16][ 6] =  34; aaDayhoff[16][ 7] =  30; aaDayhoff[16][ 8] =  22; aaDayhoff[16][ 9] = 192; 
15826     aaDayhoff[16][10] =  33; aaDayhoff[16][11] = 136; aaDayhoff[16][12] = 104; aaDayhoff[16][13] =  13; aaDayhoff[16][14] =  78; 
15827     aaDayhoff[16][15] = 550; aaDayhoff[16][16] =   0; aaDayhoff[16][17] =   0; aaDayhoff[16][18] =  42; aaDayhoff[16][19] = 157; 
15828     aaDayhoff[17][ 0] =   0; aaDayhoff[17][ 1] = 201; aaDayhoff[17][ 2] =  23; aaDayhoff[17][ 3] =   0; aaDayhoff[17][ 4] =   0; 
15829     aaDayhoff[17][ 5] =   0; aaDayhoff[17][ 6] =   0; aaDayhoff[17][ 7] =   0; aaDayhoff[17][ 8] =  27; aaDayhoff[17][ 9] =   0; 
15830     aaDayhoff[17][10] =  46; aaDayhoff[17][11] =   0; aaDayhoff[17][12] =   0; aaDayhoff[17][13] =  76; aaDayhoff[17][14] =   0; 
15831     aaDayhoff[17][15] =  75; aaDayhoff[17][16] =   0; aaDayhoff[17][17] =   0; aaDayhoff[17][18] =  61; aaDayhoff[17][19] =   0; 
15832     aaDayhoff[18][ 0] =  24; aaDayhoff[18][ 1] =   8; aaDayhoff[18][ 2] =  95; aaDayhoff[18][ 3] =   0; aaDayhoff[18][ 4] =  96; 
15833     aaDayhoff[18][ 5] =   0; aaDayhoff[18][ 6] =  22; aaDayhoff[18][ 7] =   0; aaDayhoff[18][ 8] = 127; aaDayhoff[18][ 9] =  37; 
15834     aaDayhoff[18][10] =  28; aaDayhoff[18][11] =  13; aaDayhoff[18][12] =   0; aaDayhoff[18][13] = 698; aaDayhoff[18][14] =   0; 
15835     aaDayhoff[18][15] =  34; aaDayhoff[18][16] =  42; aaDayhoff[18][17] =  61; aaDayhoff[18][18] =   0; aaDayhoff[18][19] =  28; 
15836     aaDayhoff[19][ 0] = 208; aaDayhoff[19][ 1] =  24; aaDayhoff[19][ 2] =  15; aaDayhoff[19][ 3] =  18; aaDayhoff[19][ 4] =  49; 
15837     aaDayhoff[19][ 5] =  35; aaDayhoff[19][ 6] =  37; aaDayhoff[19][ 7] =  54; aaDayhoff[19][ 8] =  44; aaDayhoff[19][ 9] = 889; 
15838     aaDayhoff[19][10] = 175; aaDayhoff[19][11] =  10; aaDayhoff[19][12] = 258; aaDayhoff[19][13] =  12; aaDayhoff[19][14] =  48; 
15839     aaDayhoff[19][15] =  30; aaDayhoff[19][16] = 157; aaDayhoff[19][17] =   0; aaDayhoff[19][18] =  28; aaDayhoff[19][19] =   0;
15840
15841     dayhoffPi[ 0] = 0.087127;
15842     dayhoffPi[ 1] = 0.040904;
15843     dayhoffPi[ 2] = 0.040432;
15844     dayhoffPi[ 3] = 0.046872;
15845     dayhoffPi[ 4] = 0.033474;
15846     dayhoffPi[ 5] = 0.038255;
15847     dayhoffPi[ 6] = 0.049530;
15848     dayhoffPi[ 7] = 0.088612;
15849     dayhoffPi[ 8] = 0.033618;
15850     dayhoffPi[ 9] = 0.036886;
15851     dayhoffPi[10] = 0.085357;
15852     dayhoffPi[11] = 0.080482;
15853     dayhoffPi[12] = 0.014753;
15854     dayhoffPi[13] = 0.039772;
15855     dayhoffPi[14] = 0.050680;
15856     dayhoffPi[15] = 0.069577;
15857     dayhoffPi[16] = 0.058542;
15858     dayhoffPi[17] = 0.010494;
15859     dayhoffPi[18] = 0.029916;
15860     dayhoffPi[19] = 0.064718;
15861
15862     /* mtrev24 */
15863     aaMtrev24[ 0][ 0] =   0.00; aaMtrev24[ 0][ 1] =  23.18; aaMtrev24[ 0][ 2] =  26.95; aaMtrev24[ 0][ 3] =  17.67; aaMtrev24[ 0][ 4] =  59.93;
15864     aaMtrev24[ 0][ 5] =   1.90; aaMtrev24[ 0][ 6] =   9.77; aaMtrev24[ 0][ 7] = 120.71; aaMtrev24[ 0][ 8] =  13.90; aaMtrev24[ 0][ 9] =  96.49;
15865     aaMtrev24[ 0][10] =  25.46; aaMtrev24[ 0][11] =   8.36; aaMtrev24[ 0][12] = 141.88; aaMtrev24[ 0][13] =   6.37; aaMtrev24[ 0][14] =  54.31;
15866     aaMtrev24[ 0][15] = 387.86; aaMtrev24[ 0][16] = 480.72; aaMtrev24[ 0][17] =   1.90; aaMtrev24[ 0][18] =   6.48; aaMtrev24[ 0][19] = 195.06;
15867     aaMtrev24[ 1][ 0] =  23.18; aaMtrev24[ 1][ 1] =   0.00; aaMtrev24[ 1][ 2] =  13.24; aaMtrev24[ 1][ 3] =   1.90; aaMtrev24[ 1][ 4] = 103.33;
15868     aaMtrev24[ 1][ 5] = 220.99; aaMtrev24[ 1][ 6] =   1.90; aaMtrev24[ 1][ 7] =  23.03; aaMtrev24[ 1][ 8] = 165.23; aaMtrev24[ 1][ 9] =   1.90;
15869     aaMtrev24[ 1][10] =  15.58; aaMtrev24[ 1][11] = 141.40; aaMtrev24[ 1][12] =   1.90; aaMtrev24[ 1][13] =   4.69; aaMtrev24[ 1][14] =  23.64;
15870     aaMtrev24[ 1][15] =   6.04; aaMtrev24[ 1][16] =   2.08; aaMtrev24[ 1][17] =  21.95; aaMtrev24[ 1][18] =   1.90; aaMtrev24[ 1][19] =   7.64;
15871     aaMtrev24[ 2][ 0] =  26.95; aaMtrev24[ 2][ 1] =  13.24; aaMtrev24[ 2][ 2] =   0.00; aaMtrev24[ 2][ 3] = 794.38; aaMtrev24[ 2][ 4] =  58.94;
15872     aaMtrev24[ 2][ 5] = 173.56; aaMtrev24[ 2][ 6] =  63.05; aaMtrev24[ 2][ 7] =  53.30; aaMtrev24[ 2][ 8] = 496.13; aaMtrev24[ 2][ 9] =  27.10;
15873     aaMtrev24[ 2][10] =  15.16; aaMtrev24[ 2][11] = 608.70; aaMtrev24[ 2][12] =  65.41; aaMtrev24[ 2][13] =  15.20; aaMtrev24[ 2][14] =  73.31;
15874     aaMtrev24[ 2][15] = 494.39; aaMtrev24[ 2][16] = 238.46; aaMtrev24[ 2][17] =  10.68; aaMtrev24[ 2][18] = 191.36; aaMtrev24[ 2][19] =   1.90;
15875     aaMtrev24[ 3][ 0] =  17.67; aaMtrev24[ 3][ 1] =   1.90; aaMtrev24[ 3][ 2] = 794.38; aaMtrev24[ 3][ 3] =   0.00; aaMtrev24[ 3][ 4] =   1.90;
15876     aaMtrev24[ 3][ 5] =  55.28; aaMtrev24[ 3][ 6] = 583.55; aaMtrev24[ 3][ 7] =  56.77; aaMtrev24[ 3][ 8] = 113.99; aaMtrev24[ 3][ 9] =   4.34;
15877     aaMtrev24[ 3][10] =   1.90; aaMtrev24[ 3][11] =   2.31; aaMtrev24[ 3][12] =   1.90; aaMtrev24[ 3][13] =   4.98; aaMtrev24[ 3][14] =  13.43;
15878     aaMtrev24[ 3][15] =  69.02; aaMtrev24[ 3][16] =  28.01; aaMtrev24[ 3][17] =  19.86; aaMtrev24[ 3][18] =  21.21; aaMtrev24[ 3][19] =   1.90;
15879     aaMtrev24[ 4][ 0] =  59.93; aaMtrev24[ 4][ 1] = 103.33; aaMtrev24[ 4][ 2] =  58.94; aaMtrev24[ 4][ 3] =   1.90; aaMtrev24[ 4][ 4] =   0.00;
15880     aaMtrev24[ 4][ 5] =  75.24; aaMtrev24[ 4][ 6] =   1.90; aaMtrev24[ 4][ 7] =  30.71; aaMtrev24[ 4][ 8] = 141.49; aaMtrev24[ 4][ 9] =  62.73;
15881     aaMtrev24[ 4][10] =  25.65; aaMtrev24[ 4][11] =   1.90; aaMtrev24[ 4][12] =   6.18; aaMtrev24[ 4][13] =  70.80; aaMtrev24[ 4][14] =  31.26;
15882     aaMtrev24[ 4][15] = 277.05; aaMtrev24[ 4][16] = 179.97; aaMtrev24[ 4][17] =  33.60; aaMtrev24[ 4][18] = 254.77; aaMtrev24[ 4][19] =   1.90;
15883     aaMtrev24[ 5][ 0] =   1.90; aaMtrev24[ 5][ 1] = 220.99; aaMtrev24[ 5][ 2] = 173.56; aaMtrev24[ 5][ 3] =  55.28; aaMtrev24[ 5][ 4] =  75.24;
15884     aaMtrev24[ 5][ 5] =   0.00; aaMtrev24[ 5][ 6] = 313.56; aaMtrev24[ 5][ 7] =   6.75; aaMtrev24[ 5][ 8] = 582.40; aaMtrev24[ 5][ 9] =   8.34;
15885     aaMtrev24[ 5][10] =  39.70; aaMtrev24[ 5][11] = 465.58; aaMtrev24[ 5][12] =  47.37; aaMtrev24[ 5][13] =  19.11; aaMtrev24[ 5][14] = 137.29;
15886     aaMtrev24[ 5][15] =  54.11; aaMtrev24[ 5][16] =  94.93; aaMtrev24[ 5][17] =   1.90; aaMtrev24[ 5][18] =  38.82; aaMtrev24[ 5][19] =  19.00;
15887     aaMtrev24[ 6][ 0] =   9.77; aaMtrev24[ 6][ 1] =   1.90; aaMtrev24[ 6][ 2] =  63.05; aaMtrev24[ 6][ 3] = 583.55; aaMtrev24[ 6][ 4] =   1.90;
15888     aaMtrev24[ 6][ 5] = 313.56; aaMtrev24[ 6][ 6] =   0.00; aaMtrev24[ 6][ 7] =  28.28; aaMtrev24[ 6][ 8] =  49.12; aaMtrev24[ 6][ 9] =   3.31;
15889     aaMtrev24[ 6][10] =   1.90; aaMtrev24[ 6][11] = 313.86; aaMtrev24[ 6][12] =   1.90; aaMtrev24[ 6][13] =   2.67; aaMtrev24[ 6][14] =  12.83;
15890     aaMtrev24[ 6][15] =  54.71; aaMtrev24[ 6][16] =  14.82; aaMtrev24[ 6][17] =   1.90; aaMtrev24[ 6][18] =  13.12; aaMtrev24[ 6][19] =  21.14;
15891     aaMtrev24[ 7][ 0] = 120.71; aaMtrev24[ 7][ 1] =  23.03; aaMtrev24[ 7][ 2] =  53.30; aaMtrev24[ 7][ 3] =  56.77; aaMtrev24[ 7][ 4] =  30.71;
15892     aaMtrev24[ 7][ 5] =   6.75; aaMtrev24[ 7][ 6] =  28.28; aaMtrev24[ 7][ 7] =   0.00; aaMtrev24[ 7][ 8] =   1.90; aaMtrev24[ 7][ 9] =   5.98;
15893     aaMtrev24[ 7][10] =   2.41; aaMtrev24[ 7][11] =  22.73; aaMtrev24[ 7][12] =   1.90; aaMtrev24[ 7][13] =   1.90; aaMtrev24[ 7][14] =   1.90;
15894     aaMtrev24[ 7][15] = 125.93; aaMtrev24[ 7][16] =  11.17; aaMtrev24[ 7][17] =  10.92; aaMtrev24[ 7][18] =   3.21; aaMtrev24[ 7][19] =   2.53;
15895     aaMtrev24[ 8][ 0] =  13.90; aaMtrev24[ 8][ 1] = 165.23; aaMtrev24[ 8][ 2] = 496.13; aaMtrev24[ 8][ 3] = 113.99; aaMtrev24[ 8][ 4] = 141.49;
15896     aaMtrev24[ 8][ 5] = 582.40; aaMtrev24[ 8][ 6] =  49.12; aaMtrev24[ 8][ 7] =   1.90; aaMtrev24[ 8][ 8] =   0.00; aaMtrev24[ 8][ 9] =  12.26;
15897     aaMtrev24[ 8][10] =  11.49; aaMtrev24[ 8][11] = 127.67; aaMtrev24[ 8][12] =  11.97; aaMtrev24[ 8][13] =  48.16; aaMtrev24[ 8][14] =  60.97;
15898     aaMtrev24[ 8][15] =  77.46; aaMtrev24[ 8][16] =  44.78; aaMtrev24[ 8][17] =   7.08; aaMtrev24[ 8][18] = 670.14; aaMtrev24[ 8][19] =   1.90;
15899     aaMtrev24[ 9][ 0] =  96.49; aaMtrev24[ 9][ 1] =   1.90; aaMtrev24[ 9][ 2] =  27.10; aaMtrev24[ 9][ 3] =   4.34; aaMtrev24[ 9][ 4] =  62.73;
15900     aaMtrev24[ 9][ 5] =   8.34; aaMtrev24[ 9][ 6] =   3.31; aaMtrev24[ 9][ 7] =   5.98; aaMtrev24[ 9][ 8] =  12.26; aaMtrev24[ 9][ 9] =   0.00;
15901     aaMtrev24[ 9][10] = 329.09; aaMtrev24[ 9][11] =  19.57; aaMtrev24[ 9][12] = 517.98; aaMtrev24[ 9][13] =  84.67; aaMtrev24[ 9][14] =  20.63;
15902     aaMtrev24[ 9][15] =  47.70; aaMtrev24[ 9][16] = 368.43; aaMtrev24[ 9][17] =   1.90; aaMtrev24[ 9][18] =  25.01; aaMtrev24[ 9][19] =1222.94;
15903     aaMtrev24[10][ 0] =  25.46; aaMtrev24[10][ 1] =  15.58; aaMtrev24[10][ 2] =  15.16; aaMtrev24[10][ 3] =   1.90; aaMtrev24[10][ 4] =  25.65;
15904     aaMtrev24[10][ 5] =  39.70; aaMtrev24[10][ 6] =   1.90; aaMtrev24[10][ 7] =   2.41; aaMtrev24[10][ 8] =  11.49; aaMtrev24[10][ 9] = 329.09;
15905     aaMtrev24[10][10] =   0.00; aaMtrev24[10][11] =  14.88; aaMtrev24[10][12] = 537.53; aaMtrev24[10][13] = 216.06; aaMtrev24[10][14] =  40.10;
15906     aaMtrev24[10][15] =  73.61; aaMtrev24[10][16] = 126.40; aaMtrev24[10][17] =  32.44; aaMtrev24[10][18] =  44.15; aaMtrev24[10][19] =  91.67;
15907     aaMtrev24[11][ 0] =   8.36; aaMtrev24[11][ 1] = 141.40; aaMtrev24[11][ 2] = 608.70; aaMtrev24[11][ 3] =   2.31; aaMtrev24[11][ 4] =   1.90;
15908     aaMtrev24[11][ 5] = 465.58; aaMtrev24[11][ 6] = 313.86; aaMtrev24[11][ 7] =  22.73; aaMtrev24[11][ 8] = 127.67; aaMtrev24[11][ 9] =  19.57;
15909     aaMtrev24[11][10] =  14.88; aaMtrev24[11][11] =   0.00; aaMtrev24[11][12] =  91.37; aaMtrev24[11][13] =   6.44; aaMtrev24[11][14] =  50.10;
15910     aaMtrev24[11][15] = 105.79; aaMtrev24[11][16] = 136.33; aaMtrev24[11][17] =  24.00; aaMtrev24[11][18] =  51.17; aaMtrev24[11][19] =   1.90;
15911     aaMtrev24[12][ 0] = 141.88; aaMtrev24[12][ 1] =   1.90; aaMtrev24[12][ 2] =  65.41; aaMtrev24[12][ 3] =   1.90; aaMtrev24[12][ 4] =   6.18;
15912     aaMtrev24[12][ 5] =  47.37; aaMtrev24[12][ 6] =   1.90; aaMtrev24[12][ 7] =   1.90; aaMtrev24[12][ 8] =  11.97; aaMtrev24[12][ 9] = 517.98;
15913     aaMtrev24[12][10] = 537.53; aaMtrev24[12][11] =  91.37; aaMtrev24[12][12] =   0.00; aaMtrev24[12][13] =  90.82; aaMtrev24[12][14] =  18.84;
15914     aaMtrev24[12][15] = 111.16; aaMtrev24[12][16] = 528.17; aaMtrev24[12][17] =  21.71; aaMtrev24[12][18] =  39.96; aaMtrev24[12][19] = 387.54;
15915     aaMtrev24[13][ 0] =   6.37; aaMtrev24[13][ 1] =   4.69; aaMtrev24[13][ 2] =  15.20; aaMtrev24[13][ 3] =   4.98; aaMtrev24[13][ 4] =  70.80;
15916     aaMtrev24[13][ 5] =  19.11; aaMtrev24[13][ 6] =   2.67; aaMtrev24[13][ 7] =   1.90; aaMtrev24[13][ 8] =  48.16; aaMtrev24[13][ 9] =  84.67;
15917     aaMtrev24[13][10] = 216.06; aaMtrev24[13][11] =   6.44; aaMtrev24[13][12] =  90.82; aaMtrev24[13][13] =   0.00; aaMtrev24[13][14] =  17.31;
15918     aaMtrev24[13][15] =  64.29; aaMtrev24[13][16] =  33.85; aaMtrev24[13][17] =   7.84; aaMtrev24[13][18] = 465.58; aaMtrev24[13][19] =   6.35;
15919     aaMtrev24[14][ 0] =  54.31; aaMtrev24[14][ 1] =  23.64; aaMtrev24[14][ 2] =  73.31; aaMtrev24[14][ 3] =  13.43; aaMtrev24[14][ 4] =  31.26;
15920     aaMtrev24[14][ 5] = 137.29; aaMtrev24[14][ 6] =  12.83; aaMtrev24[14][ 7] =   1.90; aaMtrev24[14][ 8] =  60.97; aaMtrev24[14][ 9] =  20.63;
15921     aaMtrev24[14][10] =  40.10; aaMtrev24[14][11] =  50.10; aaMtrev24[14][12] =  18.84; aaMtrev24[14][13] =  17.31; aaMtrev24[14][14] =   0.00;
15922     aaMtrev24[14][15] = 169.90; aaMtrev24[14][16] = 128.22; aaMtrev24[14][17] =   4.21; aaMtrev24[14][18] =  16.21; aaMtrev24[14][19] =   8.23;
15923     aaMtrev24[15][ 0] = 387.86; aaMtrev24[15][ 1] =   6.04; aaMtrev24[15][ 2] = 494.39; aaMtrev24[15][ 3] =  69.02; aaMtrev24[15][ 4] = 277.05;
15924     aaMtrev24[15][ 5] =  54.11; aaMtrev24[15][ 6] =  54.71; aaMtrev24[15][ 7] = 125.93; aaMtrev24[15][ 8] =  77.46; aaMtrev24[15][ 9] =  47.70;
15925     aaMtrev24[15][10] =  73.61; aaMtrev24[15][11] = 105.79; aaMtrev24[15][12] = 111.16; aaMtrev24[15][13] =  64.29; aaMtrev24[15][14] = 169.90;
15926     aaMtrev24[15][15] =   0.00; aaMtrev24[15][16] = 597.21; aaMtrev24[15][17] =  38.58; aaMtrev24[15][18] =  64.92; aaMtrev24[15][19] =   1.90;
15927     aaMtrev24[16][ 0] = 480.72; aaMtrev24[16][ 1] =   2.08; aaMtrev24[16][ 2] = 238.46; aaMtrev24[16][ 3] =  28.01; aaMtrev24[16][ 4] = 179.97;
15928     aaMtrev24[16][ 5] =  94.93; aaMtrev24[16][ 6] =  14.82; aaMtrev24[16][ 7] =  11.17; aaMtrev24[16][ 8] =  44.78; aaMtrev24[16][ 9] = 368.43;
15929     aaMtrev24[16][10] = 126.40; aaMtrev24[16][11] = 136.33; aaMtrev24[16][12] = 528.17; aaMtrev24[16][13] =  33.85; aaMtrev24[16][14] = 128.22;
15930     aaMtrev24[16][15] = 597.21; aaMtrev24[16][16] =   0.00; aaMtrev24[16][17] =   9.99; aaMtrev24[16][18] =  38.73; aaMtrev24[16][19] = 204.54;
15931     aaMtrev24[17][ 0] =   1.90; aaMtrev24[17][ 1] =  21.95; aaMtrev24[17][ 2] =  10.68; aaMtrev24[17][ 3] =  19.86; aaMtrev24[17][ 4] =  33.60;
15932     aaMtrev24[17][ 5] =   1.90; aaMtrev24[17][ 6] =   1.90; aaMtrev24[17][ 7] =  10.92; aaMtrev24[17][ 8] =   7.08; aaMtrev24[17][ 9] =   1.90;
15933     aaMtrev24[17][10] =  32.44; aaMtrev24[17][11] =  24.00; aaMtrev24[17][12] =  21.71; aaMtrev24[17][13] =   7.84; aaMtrev24[17][14] =   4.21;
15934     aaMtrev24[17][15] =  38.58; aaMtrev24[17][16] =   9.99; aaMtrev24[17][17] =   0.00; aaMtrev24[17][18] =  26.25; aaMtrev24[17][19] =   5.37;
15935     aaMtrev24[18][ 0] =   6.48; aaMtrev24[18][ 1] =   1.90; aaMtrev24[18][ 2] = 191.36; aaMtrev24[18][ 3] =  21.21; aaMtrev24[18][ 4] = 254.77;
15936     aaMtrev24[18][ 5] =  38.82; aaMtrev24[18][ 6] =  13.12; aaMtrev24[18][ 7] =   3.21; aaMtrev24[18][ 8] = 670.14; aaMtrev24[18][ 9] =  25.01;
15937     aaMtrev24[18][10] =  44.15; aaMtrev24[18][11] =  51.17; aaMtrev24[18][12] =  39.96; aaMtrev24[18][13] = 465.58; aaMtrev24[18][14] =  16.21;
15938     aaMtrev24[18][15] =  64.92; aaMtrev24[18][16] =  38.73; aaMtrev24[18][17] =  26.25; aaMtrev24[18][18] =   0.00; aaMtrev24[18][19] =   1.90;
15939     aaMtrev24[19][ 0] = 195.06; aaMtrev24[19][ 1] =   7.64; aaMtrev24[19][ 2] =   1.90; aaMtrev24[19][ 3] =   1.90; aaMtrev24[19][ 4] =   1.90;
15940     aaMtrev24[19][ 5] =  19.00; aaMtrev24[19][ 6] =  21.14; aaMtrev24[19][ 7] =   2.53; aaMtrev24[19][ 8] =   1.90; aaMtrev24[19][ 9] =1222.94;
15941     aaMtrev24[19][10] =  91.67; aaMtrev24[19][11] =   1.90; aaMtrev24[19][12] = 387.54; aaMtrev24[19][13] =   6.35; aaMtrev24[19][14] =   8.23;
15942     aaMtrev24[19][15] =   1.90; aaMtrev24[19][16] = 204.54; aaMtrev24[19][17] =   5.37; aaMtrev24[19][18] =   1.90; aaMtrev24[19][19] =   0.00;
15943
15944     mtrev24Pi[ 0] = 0.072;
15945     mtrev24Pi[ 1] = 0.019;
15946     mtrev24Pi[ 2] = 0.039;
15947     mtrev24Pi[ 3] = 0.019;
15948     mtrev24Pi[ 4] = 0.006;
15949     mtrev24Pi[ 5] = 0.025;
15950     mtrev24Pi[ 6] = 0.024;
15951     mtrev24Pi[ 7] = 0.056;
15952     mtrev24Pi[ 8] = 0.028;
15953     mtrev24Pi[ 9] = 0.088;
15954     mtrev24Pi[10] = 0.168;
15955     mtrev24Pi[11] = 0.023;
15956     mtrev24Pi[12] = 0.054;
15957     mtrev24Pi[13] = 0.061;
15958     mtrev24Pi[14] = 0.054;
15959     mtrev24Pi[15] = 0.072;
15960     mtrev24Pi[16] = 0.086;
15961     mtrev24Pi[17] = 0.029;
15962     mtrev24Pi[18] = 0.033;
15963     mtrev24Pi[19] = 0.043;
15964     
15965     /* mtmam */
15966     aaMtmam[ 0][ 0] =   0; aaMtmam[ 0][ 1] =  32; aaMtmam[ 0][ 2] =   2; aaMtmam[ 0][ 3] =  11; aaMtmam[ 0][ 4] =   0;
15967     aaMtmam[ 0][ 5] =   0; aaMtmam[ 0][ 6] =   0; aaMtmam[ 0][ 7] =  78; aaMtmam[ 0][ 8] =   8; aaMtmam[ 0][ 9] =  75;
15968     aaMtmam[ 0][10] =  21; aaMtmam[ 0][11] =   0; aaMtmam[ 0][12] =  76; aaMtmam[ 0][13] =   0; aaMtmam[ 0][14] =  53;
15969     aaMtmam[ 0][15] = 342; aaMtmam[ 0][16] = 681; aaMtmam[ 0][17] =   5; aaMtmam[ 0][18] =   0; aaMtmam[ 0][19] = 398;
15970     aaMtmam[ 1][ 0] =  32; aaMtmam[ 1][ 1] =   0; aaMtmam[ 1][ 2] =   4; aaMtmam[ 1][ 3] =   0; aaMtmam[ 1][ 4] = 186;
15971     aaMtmam[ 1][ 5] = 246; aaMtmam[ 1][ 6] =   0; aaMtmam[ 1][ 7] =  18; aaMtmam[ 1][ 8] = 232; aaMtmam[ 1][ 9] =   0;
15972     aaMtmam[ 1][10] =   6; aaMtmam[ 1][11] =  50; aaMtmam[ 1][12] =   0; aaMtmam[ 1][13] =   0; aaMtmam[ 1][14] =   9;
15973     aaMtmam[ 1][15] =   3; aaMtmam[ 1][16] =   0; aaMtmam[ 1][17] =  16; aaMtmam[ 1][18] =   0; aaMtmam[ 1][19] =   0;
15974     aaMtmam[ 2][ 0] =   2; aaMtmam[ 2][ 1] =   4; aaMtmam[ 2][ 2] =   0; aaMtmam[ 2][ 3] = 864; aaMtmam[ 2][ 4] =   0;
15975     aaMtmam[ 2][ 5] =   8; aaMtmam[ 2][ 6] =   0; aaMtmam[ 2][ 7] =  47; aaMtmam[ 2][ 8] = 458; aaMtmam[ 2][ 9] =  19;
15976     aaMtmam[ 2][10] =   0; aaMtmam[ 2][11] = 408; aaMtmam[ 2][12] =  21; aaMtmam[ 2][13] =   6; aaMtmam[ 2][14] =  33;
15977     aaMtmam[ 2][15] = 446; aaMtmam[ 2][16] = 110; aaMtmam[ 2][17] =   6; aaMtmam[ 2][18] = 156; aaMtmam[ 2][19] =   0;
15978     aaMtmam[ 3][ 0] =  11; aaMtmam[ 3][ 1] =   0; aaMtmam[ 3][ 2] = 864; aaMtmam[ 3][ 3] =   0; aaMtmam[ 3][ 4] =   0;
15979     aaMtmam[ 3][ 5] =  49; aaMtmam[ 3][ 6] = 569; aaMtmam[ 3][ 7] =  79; aaMtmam[ 3][ 8] =  11; aaMtmam[ 3][ 9] =   0;
15980     aaMtmam[ 3][10] =   0; aaMtmam[ 3][11] =   0; aaMtmam[ 3][12] =   0; aaMtmam[ 3][13] =   5; aaMtmam[ 3][14] =   2;
15981     aaMtmam[ 3][15] =  16; aaMtmam[ 3][16] =   0; aaMtmam[ 3][17] =   0; aaMtmam[ 3][18] =   0; aaMtmam[ 3][19] =  10;
15982     aaMtmam[ 4][ 0] =   0; aaMtmam[ 4][ 1] = 186; aaMtmam[ 4][ 2] =   0; aaMtmam[ 4][ 3] =   0; aaMtmam[ 4][ 4] =   0;
15983     aaMtmam[ 4][ 5] =   0; aaMtmam[ 4][ 6] =   0; aaMtmam[ 4][ 7] =   0; aaMtmam[ 4][ 8] = 305; aaMtmam[ 4][ 9] =  41;
15984     aaMtmam[ 4][10] =  27; aaMtmam[ 4][11] =   0; aaMtmam[ 4][12] =   0; aaMtmam[ 4][13] =   7; aaMtmam[ 4][14] =   0;
15985     aaMtmam[ 4][15] = 347; aaMtmam[ 4][16] = 114; aaMtmam[ 4][17] =  65; aaMtmam[ 4][18] = 530; aaMtmam[ 4][19] =   0;
15986     aaMtmam[ 5][ 0] =   0; aaMtmam[ 5][ 1] = 246; aaMtmam[ 5][ 2] =   8; aaMtmam[ 5][ 3] =  49; aaMtmam[ 5][ 4] =   0;
15987     aaMtmam[ 5][ 5] =   0; aaMtmam[ 5][ 6] = 274; aaMtmam[ 5][ 7] =   0; aaMtmam[ 5][ 8] = 550; aaMtmam[ 5][ 9] =   0;
15988     aaMtmam[ 5][10] =  20; aaMtmam[ 5][11] = 242; aaMtmam[ 5][12] =  22; aaMtmam[ 5][13] =   0; aaMtmam[ 5][14] =  51;
15989     aaMtmam[ 5][15] =  30; aaMtmam[ 5][16] =   0; aaMtmam[ 5][17] =   0; aaMtmam[ 5][18] =  54; aaMtmam[ 5][19] =  33;
15990     aaMtmam[ 6][ 0] =   0; aaMtmam[ 6][ 1] =   0; aaMtmam[ 6][ 2] =   0; aaMtmam[ 6][ 3] = 569; aaMtmam[ 6][ 4] =   0;
15991     aaMtmam[ 6][ 5] = 274; aaMtmam[ 6][ 6] =   0; aaMtmam[ 6][ 7] =  22; aaMtmam[ 6][ 8] =  22; aaMtmam[ 6][ 9] =   0;
15992     aaMtmam[ 6][10] =   0; aaMtmam[ 6][11] = 215; aaMtmam[ 6][12] =   0; aaMtmam[ 6][13] =   0; aaMtmam[ 6][14] =   0;
15993     aaMtmam[ 6][15] =  21; aaMtmam[ 6][16] =   4; aaMtmam[ 6][17] =   0; aaMtmam[ 6][18] =   0; aaMtmam[ 6][19] =  20;
15994     aaMtmam[ 7][ 0] =  78; aaMtmam[ 7][ 1] =  18; aaMtmam[ 7][ 2] =  47; aaMtmam[ 7][ 3] =  79; aaMtmam[ 7][ 4] =   0;
15995     aaMtmam[ 7][ 5] =   0; aaMtmam[ 7][ 6] =  22; aaMtmam[ 7][ 7] =   0; aaMtmam[ 7][ 8] =   0; aaMtmam[ 7][ 9] =   0;
15996     aaMtmam[ 7][10] =   0; aaMtmam[ 7][11] =   0; aaMtmam[ 7][12] =   0; aaMtmam[ 7][13] =   0; aaMtmam[ 7][14] =   0;
15997     aaMtmam[ 7][15] = 112; aaMtmam[ 7][16] =   0; aaMtmam[ 7][17] =   0; aaMtmam[ 7][18] =   1; aaMtmam[ 7][19] =   5;
15998     aaMtmam[ 8][ 0] =   8; aaMtmam[ 8][ 1] = 232; aaMtmam[ 8][ 2] = 458; aaMtmam[ 8][ 3] =  11; aaMtmam[ 8][ 4] = 305;
15999     aaMtmam[ 8][ 5] = 550; aaMtmam[ 8][ 6] =  22; aaMtmam[ 8][ 7] =   0; aaMtmam[ 8][ 8] =   0; aaMtmam[ 8][ 9] =   0;
16000     aaMtmam[ 8][10] =  26; aaMtmam[ 8][11] =   0; aaMtmam[ 8][12] =   0; aaMtmam[ 8][13] =   0; aaMtmam[ 8][14] =  53;
16001     aaMtmam[ 8][15] =  20; aaMtmam[ 8][16] =   1; aaMtmam[ 8][17] =   0; aaMtmam[ 8][18] =1525; aaMtmam[ 8][19] =   0;
16002     aaMtmam[ 9][ 0] =  75; aaMtmam[ 9][ 1] =   0; aaMtmam[ 9][ 2] =  19; aaMtmam[ 9][ 3] =   0; aaMtmam[ 9][ 4] =  41;
16003     aaMtmam[ 9][ 5] =   0; aaMtmam[ 9][ 6] =   0; aaMtmam[ 9][ 7] =   0; aaMtmam[ 9][ 8] =   0; aaMtmam[ 9][ 9] =   0;
16004     aaMtmam[ 9][10] = 232; aaMtmam[ 9][11] =   6; aaMtmam[ 9][12] = 378; aaMtmam[ 9][13] =  57; aaMtmam[ 9][14] =   5;
16005     aaMtmam[ 9][15] =   0; aaMtmam[ 9][16] = 360; aaMtmam[ 9][17] =   0; aaMtmam[ 9][18] =  16; aaMtmam[ 9][19] =2220;
16006     aaMtmam[10][ 0] =  21; aaMtmam[10][ 1] =   6; aaMtmam[10][ 2] =   0; aaMtmam[10][ 3] =   0; aaMtmam[10][ 4] =  27;
16007     aaMtmam[10][ 5] =  20; aaMtmam[10][ 6] =   0; aaMtmam[10][ 7] =   0; aaMtmam[10][ 8] =  26; aaMtmam[10][ 9] = 232;
16008     aaMtmam[10][10] =   0; aaMtmam[10][11] =   4; aaMtmam[10][12] = 609; aaMtmam[10][13] = 246; aaMtmam[10][14] =  43;
16009     aaMtmam[10][15] =  74; aaMtmam[10][16] =  34; aaMtmam[10][17] =  12; aaMtmam[10][18] =  25; aaMtmam[10][19] = 100;
16010     aaMtmam[11][ 0] =   0; aaMtmam[11][ 1] =  50; aaMtmam[11][ 2] = 408; aaMtmam[11][ 3] =   0; aaMtmam[11][ 4] =   0;
16011     aaMtmam[11][ 5] = 242; aaMtmam[11][ 6] = 215; aaMtmam[11][ 7] =   0; aaMtmam[11][ 8] =   0; aaMtmam[11][ 9] =   6;
16012     aaMtmam[11][10] =   4; aaMtmam[11][11] =   0; aaMtmam[11][12] =  59; aaMtmam[11][13] =   0; aaMtmam[11][14] =  18;
16013     aaMtmam[11][15] =  65; aaMtmam[11][16] =  50; aaMtmam[11][17] =   0; aaMtmam[11][18] =  67; aaMtmam[11][19] =   0;
16014     aaMtmam[12][ 0] =  76; aaMtmam[12][ 1] =   0; aaMtmam[12][ 2] =  21; aaMtmam[12][ 3] =   0; aaMtmam[12][ 4] =   0;
16015     aaMtmam[12][ 5] =  22; aaMtmam[12][ 6] =   0; aaMtmam[12][ 7] =   0; aaMtmam[12][ 8] =   0; aaMtmam[12][ 9] = 378;
16016     aaMtmam[12][10] = 609; aaMtmam[12][11] =  59; aaMtmam[12][12] =   0; aaMtmam[12][13] =  11; aaMtmam[12][14] =   0;
16017     aaMtmam[12][15] =  47; aaMtmam[12][16] = 691; aaMtmam[12][17] =  13; aaMtmam[12][18] =   0; aaMtmam[12][19] = 832;
16018     aaMtmam[13][ 0] =   0; aaMtmam[13][ 1] =   0; aaMtmam[13][ 2] =   6; aaMtmam[13][ 3] =   5; aaMtmam[13][ 4] =   7;
16019     aaMtmam[13][ 5] =   0; aaMtmam[13][ 6] =   0; aaMtmam[13][ 7] =   0; aaMtmam[13][ 8] =   0; aaMtmam[13][ 9] =  57;
16020     aaMtmam[13][10] = 246; aaMtmam[13][11] =   0; aaMtmam[13][12] =  11; aaMtmam[13][13] =   0; aaMtmam[13][14] =  17;
16021     aaMtmam[13][15] =  90; aaMtmam[13][16] =   8; aaMtmam[13][17] =   0; aaMtmam[13][18] = 682; aaMtmam[13][19] =   6;
16022     aaMtmam[14][ 0] =  53; aaMtmam[14][ 1] =   9; aaMtmam[14][ 2] =  33; aaMtmam[14][ 3] =   2; aaMtmam[14][ 4] =   0;
16023     aaMtmam[14][ 5] =  51; aaMtmam[14][ 6] =   0; aaMtmam[14][ 7] =   0; aaMtmam[14][ 8] =  53; aaMtmam[14][ 9] =   5;
16024     aaMtmam[14][10] =  43; aaMtmam[14][11] =  18; aaMtmam[14][12] =   0; aaMtmam[14][13] =  17; aaMtmam[14][14] =   0;
16025     aaMtmam[14][15] = 202; aaMtmam[14][16] =  78; aaMtmam[14][17] =   7; aaMtmam[14][18] =   8; aaMtmam[14][19] =   0;
16026     aaMtmam[15][ 0] = 342; aaMtmam[15][ 1] =   3; aaMtmam[15][ 2] = 446; aaMtmam[15][ 3] =  16; aaMtmam[15][ 4] = 347;
16027     aaMtmam[15][ 5] =  30; aaMtmam[15][ 6] =  21; aaMtmam[15][ 7] = 112; aaMtmam[15][ 8] =  20; aaMtmam[15][ 9] =   0;
16028     aaMtmam[15][10] =  74; aaMtmam[15][11] =  65; aaMtmam[15][12] =  47; aaMtmam[15][13] =  90; aaMtmam[15][14] = 202;
16029     aaMtmam[15][15] =   0; aaMtmam[15][16] = 614; aaMtmam[15][17] =  17; aaMtmam[15][18] = 107; aaMtmam[15][19] =   0;
16030     aaMtmam[16][ 0] = 681; aaMtmam[16][ 1] =   0; aaMtmam[16][ 2] = 110; aaMtmam[16][ 3] =   0; aaMtmam[16][ 4] = 114;
16031     aaMtmam[16][ 5] =   0; aaMtmam[16][ 6] =   4; aaMtmam[16][ 7] =   0; aaMtmam[16][ 8] =   1; aaMtmam[16][ 9] = 360;
16032     aaMtmam[16][10] =  34; aaMtmam[16][11] =  50; aaMtmam[16][12] = 691; aaMtmam[16][13] =   8; aaMtmam[16][14] =  78;
16033     aaMtmam[16][15] = 614; aaMtmam[16][16] =   0; aaMtmam[16][17] =   0; aaMtmam[16][18] =   0; aaMtmam[16][19] = 237;
16034     aaMtmam[17][ 0] =   5; aaMtmam[17][ 1] =  16; aaMtmam[17][ 2] =   6; aaMtmam[17][ 3] =   0; aaMtmam[17][ 4] =  65;
16035     aaMtmam[17][ 5] =   0; aaMtmam[17][ 6] =   0; aaMtmam[17][ 7] =   0; aaMtmam[17][ 8] =   0; aaMtmam[17][ 9] =   0;
16036     aaMtmam[17][10] =  12; aaMtmam[17][11] =   0; aaMtmam[17][12] =  13; aaMtmam[17][13] =   0; aaMtmam[17][14] =   7;
16037     aaMtmam[17][15] =  17; aaMtmam[17][16] =   0; aaMtmam[17][17] =   0; aaMtmam[17][18] =  14; aaMtmam[17][19] =   0;
16038     aaMtmam[18][ 0] =   0; aaMtmam[18][ 1] =   0; aaMtmam[18][ 2] = 156; aaMtmam[18][ 3] =   0; aaMtmam[18][ 4] = 530;
16039     aaMtmam[18][ 5] =  54; aaMtmam[18][ 6] =   0; aaMtmam[18][ 7] =   1; aaMtmam[18][ 8] =1525; aaMtmam[18][ 9] =  16;
16040     aaMtmam[18][10] =  25; aaMtmam[18][11] =  67; aaMtmam[18][12] =   0; aaMtmam[18][13] = 682; aaMtmam[18][14] =   8;
16041     aaMtmam[18][15] = 107; aaMtmam[18][16] =   0; aaMtmam[18][17] =  14; aaMtmam[18][18] =   0; aaMtmam[18][19] =   0;
16042     aaMtmam[19][ 0] = 398; aaMtmam[19][ 1] =   0; aaMtmam[19][ 2] =   0; aaMtmam[19][ 3] =  10; aaMtmam[19][ 4] =   0;
16043     aaMtmam[19][ 5] =  33; aaMtmam[19][ 6] =  20; aaMtmam[19][ 7] =   5; aaMtmam[19][ 8] =   0; aaMtmam[19][ 9] =2220;
16044     aaMtmam[19][10] = 100; aaMtmam[19][11] =   0; aaMtmam[19][12] = 832; aaMtmam[19][13] =   6; aaMtmam[19][14] =   0;
16045     aaMtmam[19][15] =   0; aaMtmam[19][16] = 237; aaMtmam[19][17] =   0; aaMtmam[19][18] =   0; aaMtmam[19][19] =   0;
16046
16047     mtmamPi[ 0] = 0.0692;
16048     mtmamPi[ 1] = 0.0184;
16049     mtmamPi[ 2] = 0.0400;
16050     mtmamPi[ 3] = 0.0186;
16051     mtmamPi[ 4] = 0.0065;
16052     mtmamPi[ 5] = 0.0238;
16053     mtmamPi[ 6] = 0.0236;
16054     mtmamPi[ 7] = 0.0557;
16055     mtmamPi[ 8] = 0.0277;
16056     mtmamPi[ 9] = 0.0905;
16057     mtmamPi[10] = 0.1675;
16058     mtmamPi[11] = 0.0221;
16059     mtmamPi[12] = 0.0561;
16060     mtmamPi[13] = 0.0611;
16061     mtmamPi[14] = 0.0536;
16062     mtmamPi[15] = 0.0725;
16063     mtmamPi[16] = 0.0870;
16064     mtmamPi[17] = 0.0293;
16065     mtmamPi[18] = 0.0340;
16066     mtmamPi[19] = 0.0428;
16067     
16068     /* rtRev */
16069     aartREV[ 0][ 0] =   0; aartREV[ 1][ 0] =  34; aartREV[ 2][ 0] =  51; aartREV[ 3][ 0] =  10; aartREV[ 4][ 0] = 439;
16070     aartREV[ 5][ 0] =  32; aartREV[ 6][ 0] =  81; aartREV[ 7][ 0] = 135; aartREV[ 8][ 0] =  30; aartREV[ 9][ 0] =   1;
16071     aartREV[10][ 0] =  45; aartREV[11][ 0] =  38; aartREV[12][ 0] = 235; aartREV[13][ 0] =   1; aartREV[14][ 0] =  97;
16072     aartREV[15][ 0] = 460; aartREV[16][ 0] = 258; aartREV[17][ 0] =   5; aartREV[18][ 0] =  55; aartREV[19][ 0] = 197;
16073     aartREV[ 0][ 1] =  34; aartREV[ 1][ 1] =   0; aartREV[ 2][ 1] =  35; aartREV[ 3][ 1] =  30; aartREV[ 4][ 1] =  92;
16074     aartREV[ 5][ 1] = 221; aartREV[ 6][ 1] =  10; aartREV[ 7][ 1] =  41; aartREV[ 8][ 1] =  90; aartREV[ 9][ 1] =  24;
16075     aartREV[10][ 1] =  18; aartREV[11][ 1] = 593; aartREV[12][ 1] =  57; aartREV[13][ 1] =   7; aartREV[14][ 1] =  24;
16076     aartREV[15][ 1] = 102; aartREV[16][ 1] =  64; aartREV[17][ 1] =  13; aartREV[18][ 1] =  47; aartREV[19][ 1] =  29;
16077     aartREV[ 0][ 2] =  51; aartREV[ 1][ 2] =  35; aartREV[ 2][ 2] =   0; aartREV[ 3][ 2] = 384; aartREV[ 4][ 2] = 128;
16078     aartREV[ 5][ 2] = 236; aartREV[ 6][ 2] =  79; aartREV[ 7][ 2] =  94; aartREV[ 8][ 2] = 320; aartREV[ 9][ 2] =  35;
16079     aartREV[10][ 2] =  15; aartREV[11][ 2] = 123; aartREV[12][ 2] =   1; aartREV[13][ 2] =  49; aartREV[14][ 2] =  33;
16080     aartREV[15][ 2] = 294; aartREV[16][ 2] = 148; aartREV[17][ 2] =  16; aartREV[18][ 2] =  28; aartREV[19][ 2] =  21;
16081     aartREV[ 0][ 3] =  10; aartREV[ 1][ 3] =  30; aartREV[ 2][ 3] = 384; aartREV[ 3][ 3] =   0; aartREV[ 4][ 3] =   1;
16082     aartREV[ 5][ 3] =  78; aartREV[ 6][ 3] = 542; aartREV[ 7][ 3] =  61; aartREV[ 8][ 3] =  91; aartREV[ 9][ 3] =   1;
16083     aartREV[10][ 3] =   5; aartREV[11][ 3] =  20; aartREV[12][ 3] =   1; aartREV[13][ 3] =   1; aartREV[14][ 3] =  55;
16084     aartREV[15][ 3] = 136; aartREV[16][ 3] =  55; aartREV[17][ 3] =   1; aartREV[18][ 3] =   1; aartREV[19][ 3] =   6;
16085     aartREV[ 0][ 4] = 439; aartREV[ 1][ 4] =  92; aartREV[ 2][ 4] = 128; aartREV[ 3][ 4] =   1; aartREV[ 4][ 4] =   0;
16086     aartREV[ 5][ 4] =  70; aartREV[ 6][ 4] =   1; aartREV[ 7][ 4] =  48; aartREV[ 8][ 4] = 124; aartREV[ 9][ 4] = 104;
16087     aartREV[10][ 4] = 110; aartREV[11][ 4] =  16; aartREV[12][ 4] = 156; aartREV[13][ 4] =  70; aartREV[14][ 4] =   1;
16088     aartREV[15][ 4] =  75; aartREV[16][ 4] = 117; aartREV[17][ 4] =  55; aartREV[18][ 4] = 131; aartREV[19][ 4] = 295;
16089     aartREV[ 0][ 5] =  32; aartREV[ 1][ 5] = 221; aartREV[ 2][ 5] = 236; aartREV[ 3][ 5] =  78; aartREV[ 4][ 5] =  70;
16090     aartREV[ 5][ 5] =   0; aartREV[ 6][ 5] = 372; aartREV[ 7][ 5] =  18; aartREV[ 8][ 5] = 387; aartREV[ 9][ 5] =  33;
16091     aartREV[10][ 5] =  54; aartREV[11][ 5] = 309; aartREV[12][ 5] = 158; aartREV[13][ 5] =   1; aartREV[14][ 5] =  68;
16092     aartREV[15][ 5] = 225; aartREV[16][ 5] = 146; aartREV[17][ 5] =  10; aartREV[18][ 5] =  45; aartREV[19][ 5] =  36;
16093     aartREV[ 0][ 6] =  81; aartREV[ 1][ 6] =  10; aartREV[ 2][ 6] =  79; aartREV[ 3][ 6] = 542; aartREV[ 4][ 6] =   1;
16094     aartREV[ 5][ 6] = 372; aartREV[ 6][ 6] =   0; aartREV[ 7][ 6] =  70; aartREV[ 8][ 6] =  34; aartREV[ 9][ 6] =   1;
16095     aartREV[10][ 6] =  21; aartREV[11][ 6] = 141; aartREV[12][ 6] =   1; aartREV[13][ 6] =   1; aartREV[14][ 6] =  52;
16096     aartREV[15][ 6] =  95; aartREV[16][ 6] =  82; aartREV[17][ 6] =  17; aartREV[18][ 6] =   1; aartREV[19][ 6] =  35;
16097     aartREV[ 0][ 7] = 135; aartREV[ 1][ 7] =  41; aartREV[ 2][ 7] =  94; aartREV[ 3][ 7] =  61; aartREV[ 4][ 7] =  48;
16098     aartREV[ 5][ 7] =  18; aartREV[ 6][ 7] =  70; aartREV[ 7][ 7] =   0; aartREV[ 8][ 7] =  68; aartREV[ 9][ 7] =   1;
16099     aartREV[10][ 7] =   3; aartREV[11][ 7] =  30; aartREV[12][ 7] =  37; aartREV[13][ 7] =   7; aartREV[14][ 7] =  17;
16100     aartREV[15][ 7] = 152; aartREV[16][ 7] =   7; aartREV[17][ 7] =  23; aartREV[18][ 7] =  21; aartREV[19][ 7] =   3;
16101     aartREV[ 0][ 8] =  30; aartREV[ 1][ 8] =  90; aartREV[ 2][ 8] = 320; aartREV[ 3][ 8] =  91; aartREV[ 4][ 8] = 124;
16102     aartREV[ 5][ 8] = 387; aartREV[ 6][ 8] =  34; aartREV[ 7][ 8] =  68; aartREV[ 8][ 8] =   0; aartREV[ 9][ 8] =  34;
16103     aartREV[10][ 8] =  51; aartREV[11][ 8] =  76; aartREV[12][ 8] = 116; aartREV[13][ 8] = 141; aartREV[14][ 8] =  44;
16104     aartREV[15][ 8] = 183; aartREV[16][ 8] =  49; aartREV[17][ 8] =  48; aartREV[18][ 8] = 307; aartREV[19][ 8] =   1;
16105     aartREV[ 0][ 9] =   1; aartREV[ 1][ 9] =  24; aartREV[ 2][ 9] =  35; aartREV[ 3][ 9] =   1; aartREV[ 4][ 9] = 104;
16106     aartREV[ 5][ 9] =  33; aartREV[ 6][ 9] =   1; aartREV[ 7][ 9] =   1; aartREV[ 8][ 9] =  34; aartREV[ 9][ 9] =   0;
16107     aartREV[10][ 9] = 385; aartREV[11][ 9] =  34; aartREV[12][ 9] = 375; aartREV[13][ 9] =  64; aartREV[14][ 9] =  10;
16108     aartREV[15][ 9] =   4; aartREV[16][ 9] =  72; aartREV[17][ 9] =  39; aartREV[18][ 9] =  26; aartREV[19][ 9] =1048;
16109     aartREV[ 0][10] =  45; aartREV[ 1][10] =  18; aartREV[ 2][10] =  15; aartREV[ 3][10] =   5; aartREV[ 4][10] = 110;
16110     aartREV[ 5][10] =  54; aartREV[ 6][10] =  21; aartREV[ 7][10] =   3; aartREV[ 8][10] =  51; aartREV[ 9][10] = 385;
16111     aartREV[10][10] =   0; aartREV[11][10] =  23; aartREV[12][10] = 581; aartREV[13][10] = 179; aartREV[14][10] =  22;
16112     aartREV[15][10] =  24; aartREV[16][10] =  25; aartREV[17][10] =  47; aartREV[18][10] =  64; aartREV[19][10] = 112;
16113     aartREV[ 0][11] =  38; aartREV[ 1][11] = 593; aartREV[ 2][11] = 123; aartREV[ 3][11] =  20; aartREV[ 4][11] =  16;
16114     aartREV[ 5][11] = 309; aartREV[ 6][11] = 141; aartREV[ 7][11] =  30; aartREV[ 8][11] =  76; aartREV[ 9][11] =  34;
16115     aartREV[10][11] =  23; aartREV[11][11] =   0; aartREV[12][11] = 134; aartREV[13][11] =  14; aartREV[14][11] =  43;
16116     aartREV[15][11] =  77; aartREV[16][11] = 110; aartREV[17][11] =   6; aartREV[18][11] =   1; aartREV[19][11] =  19;
16117     aartREV[ 0][12] = 235; aartREV[ 1][12] =  57; aartREV[ 2][12] =   1; aartREV[ 3][12] =   1; aartREV[ 4][12] = 156;
16118     aartREV[ 5][12] = 158; aartREV[ 6][12] =   1; aartREV[ 7][12] =  37; aartREV[ 8][12] = 116; aartREV[ 9][12] = 375;
16119     aartREV[10][12] = 581; aartREV[11][12] = 134; aartREV[12][12] =   0; aartREV[13][12] = 247; aartREV[14][12] =   1;
16120     aartREV[15][12] =   1; aartREV[16][12] = 131; aartREV[17][12] = 111; aartREV[18][12] =  74; aartREV[19][12] = 236;
16121     aartREV[ 0][13] =   1; aartREV[ 1][13] =   7; aartREV[ 2][13] =  49; aartREV[ 3][13] =   1; aartREV[ 4][13] =  70;
16122     aartREV[ 5][13] =   1; aartREV[ 6][13] =   1; aartREV[ 7][13] =   7; aartREV[ 8][13] = 141; aartREV[ 9][13] =  64;
16123     aartREV[10][13] = 179; aartREV[11][13] =  14; aartREV[12][13] = 247; aartREV[13][13] =   0; aartREV[14][13] =  11;
16124     aartREV[15][13] =  20; aartREV[16][13] =  69; aartREV[17][13] = 182; aartREV[18][13] =1017; aartREV[19][13] =  92;
16125     aartREV[ 0][14] =  97; aartREV[ 1][14] =  24; aartREV[ 2][14] =  33; aartREV[ 3][14] =  55; aartREV[ 4][14] =   1;
16126     aartREV[ 5][14] =  68; aartREV[ 6][14] =  52; aartREV[ 7][14] =  17; aartREV[ 8][14] =  44; aartREV[ 9][14] =  10;
16127     aartREV[10][14] =  22; aartREV[11][14] =  43; aartREV[12][14] =   1; aartREV[13][14] =  11; aartREV[14][14] =   0;
16128     aartREV[15][14] = 134; aartREV[16][14] =  62; aartREV[17][14] =   9; aartREV[18][14] =  14; aartREV[19][14] =  25;
16129     aartREV[ 0][15] = 460; aartREV[ 1][15] = 102; aartREV[ 2][15] = 294; aartREV[ 3][15] = 136; aartREV[ 4][15] =  75;
16130     aartREV[ 5][15] = 225; aartREV[ 6][15] =  95; aartREV[ 7][15] = 152; aartREV[ 8][15] = 183; aartREV[ 9][15] =   4;
16131     aartREV[10][15] =  24; aartREV[11][15] =  77; aartREV[12][15] =   1; aartREV[13][15] =  20; aartREV[14][15] = 134;
16132     aartREV[15][15] =   0; aartREV[16][15] = 671; aartREV[17][15] =  14; aartREV[18][15] =  31; aartREV[19][15] =  39;
16133     aartREV[ 0][16] = 258; aartREV[ 1][16] =  64; aartREV[ 2][16] = 148; aartREV[ 3][16] =  55; aartREV[ 4][16] = 117;
16134     aartREV[ 5][16] = 146; aartREV[ 6][16] =  82; aartREV[ 7][16] =   7; aartREV[ 8][16] =  49; aartREV[ 9][16] =  72;
16135     aartREV[10][16] =  25; aartREV[11][16] = 110; aartREV[12][16] = 131; aartREV[13][16] =  69; aartREV[14][16] =  62;
16136     aartREV[15][16] = 671; aartREV[16][16] =   0; aartREV[17][16] =   1; aartREV[18][16] =  34; aartREV[19][16] = 196;
16137     aartREV[ 0][17] =   5; aartREV[ 1][17] =  13; aartREV[ 2][17] =  16; aartREV[ 3][17] =   1; aartREV[ 4][17] =  55;
16138     aartREV[ 5][17] =  10; aartREV[ 6][17] =  17; aartREV[ 7][17] =  23; aartREV[ 8][17] =  48; aartREV[ 9][17] =  39;
16139     aartREV[10][17] =  47; aartREV[11][17] =   6; aartREV[12][17] = 111; aartREV[13][17] = 182; aartREV[14][17] =   9;
16140     aartREV[15][17] =  14; aartREV[16][17] =   1; aartREV[17][17] =   0; aartREV[18][17] = 176; aartREV[19][17] =  26;
16141     aartREV[ 0][18] =  55; aartREV[ 1][18] =  47; aartREV[ 2][18] =  28; aartREV[ 3][18] =   1; aartREV[ 4][18] = 131;
16142     aartREV[ 5][18] =  45; aartREV[ 6][18] =   1; aartREV[ 7][18] =  21; aartREV[ 8][18] = 307; aartREV[ 9][18] =  26;
16143     aartREV[10][18] =  64; aartREV[11][18] =   1; aartREV[12][18] =  74; aartREV[13][18] =1017; aartREV[14][18] =  14;
16144     aartREV[15][18] =  31; aartREV[16][18] =  34; aartREV[17][18] = 176; aartREV[18][18] =   0; aartREV[19][18] =  59;
16145     aartREV[ 0][19] = 197; aartREV[ 1][19] =  29; aartREV[ 2][19] =  21; aartREV[ 3][19] =   6; aartREV[ 4][19] = 295;
16146     aartREV[ 5][19] =  36; aartREV[ 6][19] =  35; aartREV[ 7][19] =   3; aartREV[ 8][19] =   1; aartREV[ 9][19] =1048;
16147     aartREV[10][19] = 112; aartREV[11][19] =  19; aartREV[12][19] = 236; aartREV[13][19] =  92; aartREV[14][19] =  25;
16148     aartREV[15][19] =  39; aartREV[16][19] = 196; aartREV[17][19] =  26; aartREV[18][19] =  59; aartREV[19][19] =   0;
16149     rtrevPi[ 0] = 0.0646;
16150     rtrevPi[ 1] = 0.0453;
16151     rtrevPi[ 2] = 0.0376;
16152     rtrevPi[ 3] = 0.0422;
16153     rtrevPi[ 4] = 0.0114;
16154     rtrevPi[ 5] = 0.0606;
16155     rtrevPi[ 6] = 0.0607;
16156     rtrevPi[ 7] = 0.0639;
16157     rtrevPi[ 8] = 0.0273;
16158     rtrevPi[ 9] = 0.0679;
16159     rtrevPi[10] = 0.1018;
16160     rtrevPi[11] = 0.0751;
16161     rtrevPi[12] = 0.0150;
16162     rtrevPi[13] = 0.0287;
16163     rtrevPi[14] = 0.0681;
16164     rtrevPi[15] = 0.0488;
16165     rtrevPi[16] = 0.0622;
16166     rtrevPi[17] = 0.0251;
16167     rtrevPi[18] = 0.0318;
16168     rtrevPi[19] = 0.0619;
16169     
16170     /* wag */
16171     aaWAG[ 0][ 0] = 0.0000000; aaWAG[ 1][ 0] = 0.5515710; aaWAG[ 2][ 0] = 0.5098480; aaWAG[ 3][ 0] = 0.7389980; aaWAG[ 4][ 0] = 1.0270400; 
16172     aaWAG[ 5][ 0] = 0.9085980; aaWAG[ 6][ 0] = 1.5828500; aaWAG[ 7][ 0] = 1.4167200; aaWAG[ 8][ 0] = 0.3169540; aaWAG[ 9][ 0] = 0.1933350; 
16173     aaWAG[10][ 0] = 0.3979150; aaWAG[11][ 0] = 0.9062650; aaWAG[12][ 0] = 0.8934960; aaWAG[13][ 0] = 0.2104940; aaWAG[14][ 0] = 1.4385500; 
16174     aaWAG[15][ 0] = 3.3707900; aaWAG[16][ 0] = 2.1211100; aaWAG[17][ 0] = 0.1131330; aaWAG[18][ 0] = 0.2407350; aaWAG[19][ 0] = 2.0060100;
16175     aaWAG[ 0][ 1] = 0.5515710; aaWAG[ 1][ 1] = 0.0000000; aaWAG[ 2][ 1] = 0.6353460; aaWAG[ 3][ 1] = 0.1473040; aaWAG[ 4][ 1] = 0.5281910;  
16176     aaWAG[ 5][ 1] = 3.0355000; aaWAG[ 6][ 1] = 0.4391570; aaWAG[ 7][ 1] = 0.5846650; aaWAG[ 8][ 1] = 2.1371500; aaWAG[ 9][ 1] = 0.1869790;  
16177     aaWAG[10][ 1] = 0.4976710; aaWAG[11][ 1] = 5.3514200; aaWAG[12][ 1] = 0.6831620; aaWAG[13][ 1] = 0.1027110; aaWAG[14][ 1] = 0.6794890;  
16178     aaWAG[15][ 1] = 1.2241900; aaWAG[16][ 1] = 0.5544130; aaWAG[17][ 1] = 1.1639200; aaWAG[18][ 1] = 0.3815330; aaWAG[19][ 1] = 0.2518490;
16179     aaWAG[ 0][ 2] = 0.5098480; aaWAG[ 1][ 2] = 0.6353460; aaWAG[ 2][ 2] = 0.0000000; aaWAG[ 3][ 2] = 5.4294200; aaWAG[ 4][ 2] = 0.2652560;  
16180     aaWAG[ 5][ 2] = 1.5436400; aaWAG[ 6][ 2] = 0.9471980; aaWAG[ 7][ 2] = 1.1255600; aaWAG[ 8][ 2] = 3.9562900; aaWAG[ 9][ 2] = 0.5542360;  
16181     aaWAG[10][ 2] = 0.1315280; aaWAG[11][ 2] = 3.0120100; aaWAG[12][ 2] = 0.1982210; aaWAG[13][ 2] = 0.0961621; aaWAG[14][ 2] = 0.1950810;  
16182     aaWAG[15][ 2] = 3.9742300; aaWAG[16][ 2] = 2.0300600; aaWAG[17][ 2] = 0.0719167; aaWAG[18][ 2] = 1.0860000; aaWAG[19][ 2] = 0.1962460;
16183     aaWAG[ 0][ 3] = 0.7389980; aaWAG[ 1][ 3] = 0.1473040; aaWAG[ 2][ 3] = 5.4294200; aaWAG[ 3][ 3] = 0.0000000; aaWAG[ 4][ 3] = 0.0302949;  
16184     aaWAG[ 5][ 3] = 0.6167830; aaWAG[ 6][ 3] = 6.1741600; aaWAG[ 7][ 3] = 0.8655840; aaWAG[ 8][ 3] = 0.9306760; aaWAG[ 9][ 3] = 0.0394370;  
16185     aaWAG[10][ 3] = 0.0848047; aaWAG[11][ 3] = 0.4798550; aaWAG[12][ 3] = 0.1037540; aaWAG[13][ 3] = 0.0467304; aaWAG[14][ 3] = 0.4239840;  
16186     aaWAG[15][ 3] = 1.0717600; aaWAG[16][ 3] = 0.3748660; aaWAG[17][ 3] = 0.1297670; aaWAG[18][ 3] = 0.3257110; aaWAG[19][ 3] = 0.1523350;
16187     aaWAG[ 0][ 4] = 1.0270400; aaWAG[ 1][ 4] = 0.5281910; aaWAG[ 2][ 4] = 0.2652560; aaWAG[ 3][ 4] = 0.0302949; aaWAG[ 4][ 4] = 0.0000000;  
16188     aaWAG[ 5][ 4] = 0.0988179; aaWAG[ 6][ 4] = 0.0213520; aaWAG[ 7][ 4] = 0.3066740; aaWAG[ 8][ 4] = 0.2489720; aaWAG[ 9][ 4] = 0.1701350;  
16189     aaWAG[10][ 4] = 0.3842870; aaWAG[11][ 4] = 0.0740339; aaWAG[12][ 4] = 0.3904820; aaWAG[13][ 4] = 0.3980200; aaWAG[14][ 4] = 0.1094040;  
16190     aaWAG[15][ 4] = 1.4076600; aaWAG[16][ 4] = 0.5129840; aaWAG[17][ 4] = 0.7170700; aaWAG[18][ 4] = 0.5438330; aaWAG[19][ 4] = 1.0021400;
16191     aaWAG[ 0][ 5] = 0.9085980; aaWAG[ 1][ 5] = 3.0355000; aaWAG[ 2][ 5] = 1.5436400; aaWAG[ 3][ 5] = 0.6167830; aaWAG[ 4][ 5] = 0.0988179;  
16192     aaWAG[ 5][ 5] = 0.0000000; aaWAG[ 6][ 5] = 5.4694700; aaWAG[ 7][ 5] = 0.3300520; aaWAG[ 8][ 5] = 4.2941100; aaWAG[ 9][ 5] = 0.1139170;  
16193     aaWAG[10][ 5] = 0.8694890; aaWAG[11][ 5] = 3.8949000; aaWAG[12][ 5] = 1.5452600; aaWAG[13][ 5] = 0.0999208; aaWAG[14][ 5] = 0.9333720;  
16194     aaWAG[15][ 5] = 1.0288700; aaWAG[16][ 5] = 0.8579280; aaWAG[17][ 5] = 0.2157370; aaWAG[18][ 5] = 0.2277100; aaWAG[19][ 5] = 0.3012810;
16195     aaWAG[ 0][ 6] = 1.5828500; aaWAG[ 1][ 6] = 0.4391570; aaWAG[ 2][ 6] = 0.9471980; aaWAG[ 3][ 6] = 6.1741600; aaWAG[ 4][ 6] = 0.0213520;  
16196     aaWAG[ 5][ 6] = 5.4694700; aaWAG[ 6][ 6] = 0.0000000; aaWAG[ 7][ 6] = 0.5677170; aaWAG[ 8][ 6] = 0.5700250; aaWAG[ 9][ 6] = 0.1273950;  
16197     aaWAG[10][ 6] = 0.1542630; aaWAG[11][ 6] = 2.5844300; aaWAG[12][ 6] = 0.3151240; aaWAG[13][ 6] = 0.0811339; aaWAG[14][ 6] = 0.6823550;  
16198     aaWAG[15][ 6] = 0.7049390; aaWAG[16][ 6] = 0.8227650; aaWAG[17][ 6] = 0.1565570; aaWAG[18][ 6] = 0.1963030; aaWAG[19][ 6] = 0.5887310;
16199     aaWAG[ 0][ 7] = 1.4167200; aaWAG[ 1][ 7] = 0.5846650; aaWAG[ 2][ 7] = 1.1255600; aaWAG[ 3][ 7] = 0.8655840; aaWAG[ 4][ 7] = 0.3066740;  
16200     aaWAG[ 5][ 7] = 0.3300520; aaWAG[ 6][ 7] = 0.5677170; aaWAG[ 7][ 7] = 0.0000000; aaWAG[ 8][ 7] = 0.2494100; aaWAG[ 9][ 7] = 0.0304501;  
16201     aaWAG[10][ 7] = 0.0613037; aaWAG[11][ 7] = 0.3735580; aaWAG[12][ 7] = 0.1741000; aaWAG[13][ 7] = 0.0499310; aaWAG[14][ 7] = 0.2435700;  
16202     aaWAG[15][ 7] = 1.3418200; aaWAG[16][ 7] = 0.2258330; aaWAG[17][ 7] = 0.3369830; aaWAG[18][ 7] = 0.1036040; aaWAG[19][ 7] = 0.1872470;
16203     aaWAG[ 0][ 8] = 0.3169540; aaWAG[ 1][ 8] = 2.1371500; aaWAG[ 2][ 8] = 3.9562900; aaWAG[ 3][ 8] = 0.9306760; aaWAG[ 4][ 8] = 0.2489720;  
16204     aaWAG[ 5][ 8] = 4.2941100; aaWAG[ 6][ 8] = 0.5700250; aaWAG[ 7][ 8] = 0.2494100; aaWAG[ 8][ 8] = 0.0000000; aaWAG[ 9][ 8] = 0.1381900;  
16205     aaWAG[10][ 8] = 0.4994620; aaWAG[11][ 8] = 0.8904320; aaWAG[12][ 8] = 0.4041410; aaWAG[13][ 8] = 0.6793710; aaWAG[14][ 8] = 0.6961980;  
16206     aaWAG[15][ 8] = 0.7401690; aaWAG[16][ 8] = 0.4733070; aaWAG[17][ 8] = 0.2625690; aaWAG[18][ 8] = 3.8734400; aaWAG[19][ 8] = 0.1183580;
16207     aaWAG[ 0][ 9] = 0.1933350; aaWAG[ 1][ 9] = 0.1869790; aaWAG[ 2][ 9] = 0.5542360; aaWAG[ 3][ 9] = 0.0394370; aaWAG[ 4][ 9] = 0.1701350;  
16208     aaWAG[ 5][ 9] = 0.1139170; aaWAG[ 6][ 9] = 0.1273950; aaWAG[ 7][ 9] = 0.0304501; aaWAG[ 8][ 9] = 0.1381900; aaWAG[ 9][ 9] = 0.0000000;  
16209     aaWAG[10][ 9] = 3.1709700; aaWAG[11][ 9] = 0.3238320; aaWAG[12][ 9] = 4.2574600; aaWAG[13][ 9] = 1.0594700; aaWAG[14][ 9] = 0.0999288;  
16210     aaWAG[15][ 9] = 0.3194400; aaWAG[16][ 9] = 1.4581600; aaWAG[17][ 9] = 0.2124830; aaWAG[18][ 9] = 0.4201700; aaWAG[19][ 9] = 7.8213000;
16211     aaWAG[ 0][10] = 0.3979150; aaWAG[ 1][10] = 0.4976710; aaWAG[ 2][10] = 0.1315280; aaWAG[ 3][10] = 0.0848047; aaWAG[ 4][10] = 0.3842870;  
16212     aaWAG[ 5][10] = 0.8694890; aaWAG[ 6][10] = 0.1542630; aaWAG[ 7][10] = 0.0613037; aaWAG[ 8][10] = 0.4994620; aaWAG[ 9][10] = 3.1709700;  
16213     aaWAG[10][10] = 0.0000000; aaWAG[11][10] = 0.2575550; aaWAG[12][10] = 4.8540200; aaWAG[13][10] = 2.1151700; aaWAG[14][10] = 0.4158440;  
16214     aaWAG[15][10] = 0.3447390; aaWAG[16][10] = 0.3266220; aaWAG[17][10] = 0.6653090; aaWAG[18][10] = 0.3986180; aaWAG[19][10] = 1.8003400;
16215     aaWAG[ 0][11] = 0.9062650; aaWAG[ 1][11] = 5.3514200; aaWAG[ 2][11] = 3.0120100; aaWAG[ 3][11] = 0.4798550; aaWAG[ 4][11] = 0.0740339;  
16216     aaWAG[ 5][11] = 3.8949000; aaWAG[ 6][11] = 2.5844300; aaWAG[ 7][11] = 0.3735580; aaWAG[ 8][11] = 0.8904320; aaWAG[ 9][11] = 0.3238320;  
16217     aaWAG[10][11] = 0.2575550; aaWAG[11][11] = 0.0000000; aaWAG[12][11] = 0.9342760; aaWAG[13][11] = 0.0888360; aaWAG[14][11] = 0.5568960;  
16218     aaWAG[15][11] = 0.9671300; aaWAG[16][11] = 1.3869800; aaWAG[17][11] = 0.1375050; aaWAG[18][11] = 0.1332640; aaWAG[19][11] = 0.3054340;
16219     aaWAG[ 0][12] = 0.8934960; aaWAG[ 1][12] = 0.6831620; aaWAG[ 2][12] = 0.1982210; aaWAG[ 3][12] = 0.1037540; aaWAG[ 4][12] = 0.3904820;  
16220     aaWAG[ 5][12] = 1.5452600; aaWAG[ 6][12] = 0.3151240; aaWAG[ 7][12] = 0.1741000; aaWAG[ 8][12] = 0.4041410; aaWAG[ 9][12] = 4.2574600;  
16221     aaWAG[10][12] = 4.8540200; aaWAG[11][12] = 0.9342760; aaWAG[12][12] = 0.0000000; aaWAG[13][12] = 1.1906300; aaWAG[14][12] = 0.1713290;  
16222     aaWAG[15][12] = 0.4939050; aaWAG[16][12] = 1.5161200; aaWAG[17][12] = 0.5157060; aaWAG[18][12] = 0.4284370; aaWAG[19][12] = 2.0584500;
16223     aaWAG[ 0][13] = 0.2104940; aaWAG[ 1][13] = 0.1027110; aaWAG[ 2][13] = 0.0961621; aaWAG[ 3][13] = 0.0467304; aaWAG[ 4][13] = 0.3980200;  
16224     aaWAG[ 5][13] = 0.0999208; aaWAG[ 6][13] = 0.0811339; aaWAG[ 7][13] = 0.0499310; aaWAG[ 8][13] = 0.6793710; aaWAG[ 9][13] = 1.0594700;  
16225     aaWAG[10][13] = 2.1151700; aaWAG[11][13] = 0.0888360; aaWAG[12][13] = 1.1906300; aaWAG[13][13] = 0.0000000; aaWAG[14][13] = 0.1614440;  
16226     aaWAG[15][13] = 0.5459310; aaWAG[16][13] = 0.1719030; aaWAG[17][13] = 1.5296400; aaWAG[18][13] = 6.4542800; aaWAG[19][13] = 0.6498920;
16227     aaWAG[ 0][14] = 1.4385500; aaWAG[ 1][14] = 0.6794890; aaWAG[ 2][14] = 0.1950810; aaWAG[ 3][14] = 0.4239840; aaWAG[ 4][14] = 0.1094040;  
16228     aaWAG[ 5][14] = 0.9333720; aaWAG[ 6][14] = 0.6823550; aaWAG[ 7][14] = 0.2435700; aaWAG[ 8][14] = 0.6961980; aaWAG[ 9][14] = 0.0999288;  
16229     aaWAG[10][14] = 0.4158440; aaWAG[11][14] = 0.5568960; aaWAG[12][14] = 0.1713290; aaWAG[13][14] = 0.1614440; aaWAG[14][14] = 0.0000000;  
16230     aaWAG[15][14] = 1.6132800; aaWAG[16][14] = 0.7953840; aaWAG[17][14] = 0.1394050; aaWAG[18][14] = 0.2160460; aaWAG[19][14] = 0.3148870;
16231     aaWAG[ 0][15] = 3.3707900; aaWAG[ 1][15] = 1.2241900; aaWAG[ 2][15] = 3.9742300; aaWAG[ 3][15] = 1.0717600; aaWAG[ 4][15] = 1.4076600;  
16232     aaWAG[ 5][15] = 1.0288700; aaWAG[ 6][15] = 0.7049390; aaWAG[ 7][15] = 1.3418200; aaWAG[ 8][15] = 0.7401690; aaWAG[ 9][15] = 0.3194400;  
16233     aaWAG[10][15] = 0.3447390; aaWAG[11][15] = 0.9671300; aaWAG[12][15] = 0.4939050; aaWAG[13][15] = 0.5459310; aaWAG[14][15] = 1.6132800;  
16234     aaWAG[15][15] = 0.0000000; aaWAG[16][15] = 4.3780200; aaWAG[17][15] = 0.5237420; aaWAG[18][15] = 0.7869930; aaWAG[19][15] = 0.2327390;
16235     aaWAG[ 0][16] = 2.1211100; aaWAG[ 1][16] = 0.5544130; aaWAG[ 2][16] = 2.0300600; aaWAG[ 3][16] = 0.3748660; aaWAG[ 4][16] = 0.5129840;  
16236     aaWAG[ 5][16] = 0.8579280; aaWAG[ 6][16] = 0.8227650; aaWAG[ 7][16] = 0.2258330; aaWAG[ 8][16] = 0.4733070; aaWAG[ 9][16] = 1.4581600;  
16237     aaWAG[10][16] = 0.3266220; aaWAG[11][16] = 1.3869800; aaWAG[12][16] = 1.5161200; aaWAG[13][16] = 0.1719030; aaWAG[14][16] = 0.7953840;  
16238     aaWAG[15][16] = 4.3780200; aaWAG[16][16] = 0.0000000; aaWAG[17][16] = 0.1108640; aaWAG[18][16] = 0.2911480; aaWAG[19][16] = 1.3882300;
16239     aaWAG[ 0][17] = 0.1131330; aaWAG[ 1][17] = 1.1639200; aaWAG[ 2][17] = 0.0719167; aaWAG[ 3][17] = 0.1297670; aaWAG[ 4][17] = 0.7170700;  
16240     aaWAG[ 5][17] = 0.2157370; aaWAG[ 6][17] = 0.1565570; aaWAG[ 7][17] = 0.3369830; aaWAG[ 8][17] = 0.2625690; aaWAG[ 9][17] = 0.2124830;  
16241     aaWAG[10][17] = 0.6653090; aaWAG[11][17] = 0.1375050; aaWAG[12][17] = 0.5157060; aaWAG[13][17] = 1.5296400; aaWAG[14][17] = 0.1394050;  
16242     aaWAG[15][17] = 0.5237420; aaWAG[16][17] = 0.1108640; aaWAG[17][17] = 0.0000000; aaWAG[18][17] = 2.4853900; aaWAG[19][17] = 0.3653690;
16243     aaWAG[ 0][18] = 0.2407350; aaWAG[ 1][18] = 0.3815330; aaWAG[ 2][18] = 1.0860000; aaWAG[ 3][18] = 0.3257110; aaWAG[ 4][18] = 0.5438330;  
16244     aaWAG[ 5][18] = 0.2277100; aaWAG[ 6][18] = 0.1963030; aaWAG[ 7][18] = 0.1036040; aaWAG[ 8][18] = 3.8734400; aaWAG[ 9][18] = 0.4201700;  
16245     aaWAG[10][18] = 0.3986180; aaWAG[11][18] = 0.1332640; aaWAG[12][18] = 0.4284370; aaWAG[13][18] = 6.4542800; aaWAG[14][18] = 0.2160460;  
16246     aaWAG[15][18] = 0.7869930; aaWAG[16][18] = 0.2911480; aaWAG[17][18] = 2.4853900; aaWAG[18][18] = 0.0000000; aaWAG[19][18] = 0.3147300;
16247     aaWAG[ 0][19] = 2.0060100; aaWAG[ 1][19] = 0.2518490; aaWAG[ 2][19] = 0.1962460; aaWAG[ 3][19] = 0.1523350; aaWAG[ 4][19] = 1.0021400;  
16248     aaWAG[ 5][19] = 0.3012810; aaWAG[ 6][19] = 0.5887310; aaWAG[ 7][19] = 0.1872470; aaWAG[ 8][19] = 0.1183580; aaWAG[ 9][19] = 7.8213000;  
16249     aaWAG[10][19] = 1.8003400; aaWAG[11][19] = 0.3054340; aaWAG[12][19] = 2.0584500; aaWAG[13][19] = 0.6498920; aaWAG[14][19] = 0.3148870;  
16250     aaWAG[15][19] = 0.2327390; aaWAG[16][19] = 1.3882300; aaWAG[17][19] = 0.3653690; aaWAG[18][19] = 0.3147300; aaWAG[19][19] = 0.0000000;
16251     wagPi[ 0] = 0.08662790;
16252     wagPi[ 1] = 0.04397200;
16253     wagPi[ 2] = 0.03908940;
16254     wagPi[ 3] = 0.05704510;
16255     wagPi[ 4] = 0.01930780;
16256     wagPi[ 5] = 0.03672810;
16257     wagPi[ 6] = 0.05805890;
16258     wagPi[ 7] = 0.08325180;
16259     wagPi[ 8] = 0.02443130;
16260     wagPi[ 9] = 0.04846600;
16261     wagPi[10] = 0.08620970;
16262     wagPi[11] = 0.06202860;
16263     wagPi[12] = 0.01950273;
16264     wagPi[13] = 0.03843190;
16265     wagPi[14] = 0.04576310;
16266     wagPi[15] = 0.06951790;
16267     wagPi[16] = 0.06101270;
16268     wagPi[17] = 0.01438590;
16269     wagPi[18] = 0.03527420;
16270     wagPi[19] = 0.07089560;
16271
16272     /* cpRev */
16273     aacpREV[ 0][ 0] =    0; aacpREV[ 0][ 1] =  105; aacpREV[ 0][ 2] =  227; aacpREV[ 0][ 3] =  175; aacpREV[ 0][ 4] =  669; 
16274     aacpREV[ 0][ 5] =  157; aacpREV[ 0][ 6] =  499; aacpREV[ 0][ 7] =  665; aacpREV[ 0][ 8] =   66; aacpREV[ 0][ 9] =  145; 
16275     aacpREV[ 0][10] =  197; aacpREV[ 0][11] =  236; aacpREV[ 0][12] =  185; aacpREV[ 0][13] =   68; aacpREV[ 0][14] =  490; 
16276     aacpREV[ 0][15] = 2440; aacpREV[ 0][16] = 1340; aacpREV[ 0][17] =   14; aacpREV[ 0][18] =   56; aacpREV[ 0][19] =  968; 
16277     aacpREV[ 1][ 0] =  105; aacpREV[ 1][ 1] =    0; aacpREV[ 1][ 2] =  357; aacpREV[ 1][ 3] =   43; aacpREV[ 1][ 4] =  823; 
16278     aacpREV[ 1][ 5] = 1745; aacpREV[ 1][ 6] =  152; aacpREV[ 1][ 7] =  243; aacpREV[ 1][ 8] =  715; aacpREV[ 1][ 9] =  136; 
16279     aacpREV[ 1][10] =  203; aacpREV[ 1][11] = 4482; aacpREV[ 1][12] =  125; aacpREV[ 1][13] =   53; aacpREV[ 1][14] =   87; 
16280     aacpREV[ 1][15] =  385; aacpREV[ 1][16] =  314; aacpREV[ 1][17] =  230; aacpREV[ 1][18] =  323; aacpREV[ 1][19] =   92; 
16281     aacpREV[ 2][ 0] =  227; aacpREV[ 2][ 1] =  357; aacpREV[ 2][ 2] =    0; aacpREV[ 2][ 3] = 4435; aacpREV[ 2][ 4] =  538; 
16282     aacpREV[ 2][ 5] =  768; aacpREV[ 2][ 6] = 1055; aacpREV[ 2][ 7] =  653; aacpREV[ 2][ 8] = 1405; aacpREV[ 2][ 9] =  168; 
16283     aacpREV[ 2][10] =  113; aacpREV[ 2][11] = 2430; aacpREV[ 2][12] =   61; aacpREV[ 2][13] =   97; aacpREV[ 2][14] =  173; 
16284     aacpREV[ 2][15] = 2085; aacpREV[ 2][16] = 1393; aacpREV[ 2][17] =   40; aacpREV[ 2][18] =  754; aacpREV[ 2][19] =   83; 
16285     aacpREV[ 3][ 0] =  175; aacpREV[ 3][ 1] =   43; aacpREV[ 3][ 2] = 4435; aacpREV[ 3][ 3] =    0; aacpREV[ 3][ 4] =   10; 
16286     aacpREV[ 3][ 5] =  400; aacpREV[ 3][ 6] = 3691; aacpREV[ 3][ 7] =  431; aacpREV[ 3][ 8] =  331; aacpREV[ 3][ 9] =   10; 
16287     aacpREV[ 3][10] =   10; aacpREV[ 3][11] =  412; aacpREV[ 3][12] =   47; aacpREV[ 3][13] =   22; aacpREV[ 3][14] =  170; 
16288     aacpREV[ 3][15] =  590; aacpREV[ 3][16] =  266; aacpREV[ 3][17] =   18; aacpREV[ 3][18] =  281; aacpREV[ 3][19] =   75; 
16289     aacpREV[ 4][ 0] =  669; aacpREV[ 4][ 1] =  823; aacpREV[ 4][ 2] =  538; aacpREV[ 4][ 3] =   10; aacpREV[ 4][ 4] =    0; 
16290     aacpREV[ 4][ 5] =   10; aacpREV[ 4][ 6] =   10; aacpREV[ 4][ 7] =  303; aacpREV[ 4][ 8] =  441; aacpREV[ 4][ 9] =  280; 
16291     aacpREV[ 4][10] =  396; aacpREV[ 4][11] =   48; aacpREV[ 4][12] =  159; aacpREV[ 4][13] =  726; aacpREV[ 4][14] =  285; 
16292     aacpREV[ 4][15] = 2331; aacpREV[ 4][16] =  576; aacpREV[ 4][17] =  435; aacpREV[ 4][18] = 1466; aacpREV[ 4][19] =  592; 
16293     aacpREV[ 5][ 0] =  157; aacpREV[ 5][ 1] = 1745; aacpREV[ 5][ 2] =  768; aacpREV[ 5][ 3] =  400; aacpREV[ 5][ 4] =   10; 
16294     aacpREV[ 5][ 5] =    0; aacpREV[ 5][ 6] = 3122; aacpREV[ 5][ 7] =  133; aacpREV[ 5][ 8] = 1269; aacpREV[ 5][ 9] =   92; 
16295     aacpREV[ 5][10] =  286; aacpREV[ 5][11] = 3313; aacpREV[ 5][12] =  202; aacpREV[ 5][13] =   10; aacpREV[ 5][14] =  323; 
16296     aacpREV[ 5][15] =  396; aacpREV[ 5][16] =  241; aacpREV[ 5][17] =   53; aacpREV[ 5][18] =  391; aacpREV[ 5][19] =   54; 
16297     aacpREV[ 6][ 0] =  499; aacpREV[ 6][ 1] =  152; aacpREV[ 6][ 2] = 1055; aacpREV[ 6][ 3] = 3691; aacpREV[ 6][ 4] =   10; 
16298     aacpREV[ 6][ 5] = 3122; aacpREV[ 6][ 6] =    0; aacpREV[ 6][ 7] =  379; aacpREV[ 6][ 8] =  162; aacpREV[ 6][ 9] =  148; 
16299     aacpREV[ 6][10] =   82; aacpREV[ 6][11] = 2629; aacpREV[ 6][12] =  113; aacpREV[ 6][13] =  145; aacpREV[ 6][14] =  185; 
16300     aacpREV[ 6][15] =  568; aacpREV[ 6][16] =  369; aacpREV[ 6][17] =   63; aacpREV[ 6][18] =  142; aacpREV[ 6][19] =  200; 
16301     aacpREV[ 7][ 0] =  665; aacpREV[ 7][ 1] =  243; aacpREV[ 7][ 2] =  653; aacpREV[ 7][ 3] =  431; aacpREV[ 7][ 4] =  303; 
16302     aacpREV[ 7][ 5] =  133; aacpREV[ 7][ 6] =  379; aacpREV[ 7][ 7] =    0; aacpREV[ 7][ 8] =   19; aacpREV[ 7][ 9] =   40; 
16303     aacpREV[ 7][10] =   20; aacpREV[ 7][11] =  263; aacpREV[ 7][12] =   21; aacpREV[ 7][13] =   25; aacpREV[ 7][14] =   28; 
16304     aacpREV[ 7][15] =  691; aacpREV[ 7][16] =   92; aacpREV[ 7][17] =   82; aacpREV[ 7][18] =   10; aacpREV[ 7][19] =   91; 
16305     aacpREV[ 8][ 0] =   66; aacpREV[ 8][ 1] =  715; aacpREV[ 8][ 2] = 1405; aacpREV[ 8][ 3] =  331; aacpREV[ 8][ 4] =  441; 
16306     aacpREV[ 8][ 5] = 1269; aacpREV[ 8][ 6] =  162; aacpREV[ 8][ 7] =   19; aacpREV[ 8][ 8] =    0; aacpREV[ 8][ 9] =   29; 
16307     aacpREV[ 8][10] =   66; aacpREV[ 8][11] =  305; aacpREV[ 8][12] =   10; aacpREV[ 8][13] =  127; aacpREV[ 8][14] =  152; 
16308     aacpREV[ 8][15] =  303; aacpREV[ 8][16] =   32; aacpREV[ 8][17] =   69; aacpREV[ 8][18] = 1971; aacpREV[ 8][19] =   25; 
16309     aacpREV[ 9][ 0] =  145; aacpREV[ 9][ 1] =  136; aacpREV[ 9][ 2] =  168; aacpREV[ 9][ 3] =   10; aacpREV[ 9][ 4] =  280; 
16310     aacpREV[ 9][ 5] =   92; aacpREV[ 9][ 6] =  148; aacpREV[ 9][ 7] =   40; aacpREV[ 9][ 8] =   29; aacpREV[ 9][ 9] =    0; 
16311     aacpREV[ 9][10] = 1745; aacpREV[ 9][11] =  345; aacpREV[ 9][12] = 1772; aacpREV[ 9][13] =  454; aacpREV[ 9][14] =  117; 
16312     aacpREV[ 9][15] =  216; aacpREV[ 9][16] = 1040; aacpREV[ 9][17] =   42; aacpREV[ 9][18] =   89; aacpREV[ 9][19] = 4797; 
16313     aacpREV[10][ 0] =  197; aacpREV[10][ 1] =  203; aacpREV[10][ 2] =  113; aacpREV[10][ 3] =   10; aacpREV[10][ 4] =  396; 
16314     aacpREV[10][ 5] =  286; aacpREV[10][ 6] =   82; aacpREV[10][ 7] =   20; aacpREV[10][ 8] =   66; aacpREV[10][ 9] = 1745; 
16315     aacpREV[10][10] =    0; aacpREV[10][11] =  218; aacpREV[10][12] = 1351; aacpREV[10][13] = 1268; aacpREV[10][14] =  219; 
16316     aacpREV[10][15] =  516; aacpREV[10][16] =  156; aacpREV[10][17] =  159; aacpREV[10][18] =  189; aacpREV[10][19] =  865; 
16317     aacpREV[11][ 0] =  236; aacpREV[11][ 1] = 4482; aacpREV[11][ 2] = 2430; aacpREV[11][ 3] =  412; aacpREV[11][ 4] =   48; 
16318     aacpREV[11][ 5] = 3313; aacpREV[11][ 6] = 2629; aacpREV[11][ 7] =  263; aacpREV[11][ 8] =  305; aacpREV[11][ 9] =  345; 
16319     aacpREV[11][10] =  218; aacpREV[11][11] =    0; aacpREV[11][12] =  193; aacpREV[11][13] =   72; aacpREV[11][14] =  302; 
16320     aacpREV[11][15] =  868; aacpREV[11][16] =  918; aacpREV[11][17] =   10; aacpREV[11][18] =  247; aacpREV[11][19] =  249; 
16321     aacpREV[12][ 0] =  185; aacpREV[12][ 1] =  125; aacpREV[12][ 2] =   61; aacpREV[12][ 3] =   47; aacpREV[12][ 4] =  159; 
16322     aacpREV[12][ 5] =  202; aacpREV[12][ 6] =  113; aacpREV[12][ 7] =   21; aacpREV[12][ 8] =   10; aacpREV[12][ 9] = 1772; 
16323     aacpREV[12][10] = 1351; aacpREV[12][11] =  193; aacpREV[12][12] =    0; aacpREV[12][13] =  327; aacpREV[12][14] =  100; 
16324     aacpREV[12][15] =   93; aacpREV[12][16] =  645; aacpREV[12][17] =   86; aacpREV[12][18] =  215; aacpREV[12][19] =  475; 
16325     aacpREV[13][ 0] =   68; aacpREV[13][ 1] =   53; aacpREV[13][ 2] =   97; aacpREV[13][ 3] =   22; aacpREV[13][ 4] =  726; 
16326     aacpREV[13][ 5] =   10; aacpREV[13][ 6] =  145; aacpREV[13][ 7] =   25; aacpREV[13][ 8] =  127; aacpREV[13][ 9] =  454; 
16327     aacpREV[13][10] = 1268; aacpREV[13][11] =   72; aacpREV[13][12] =  327; aacpREV[13][13] =    0; aacpREV[13][14] =   43; 
16328     aacpREV[13][15] =  487; aacpREV[13][16] =  148; aacpREV[13][17] =  468; aacpREV[13][18] = 2370; aacpREV[13][19] =  317; 
16329     aacpREV[14][ 0] =  490; aacpREV[14][ 1] =   87; aacpREV[14][ 2] =  173; aacpREV[14][ 3] =  170; aacpREV[14][ 4] =  285; 
16330     aacpREV[14][ 5] =  323; aacpREV[14][ 6] =  185; aacpREV[14][ 7] =   28; aacpREV[14][ 8] =  152; aacpREV[14][ 9] =  117; 
16331     aacpREV[14][10] =  219; aacpREV[14][11] =  302; aacpREV[14][12] =  100; aacpREV[14][13] =   43; aacpREV[14][14] =    0; 
16332     aacpREV[14][15] = 1202; aacpREV[14][16] =  260; aacpREV[14][17] =   49; aacpREV[14][18] =   97; aacpREV[14][19] =  122; 
16333     aacpREV[15][ 0] = 2440; aacpREV[15][ 1] =  385; aacpREV[15][ 2] = 2085; aacpREV[15][ 3] =  590; aacpREV[15][ 4] = 2331; 
16334     aacpREV[15][ 5] =  396; aacpREV[15][ 6] =  568; aacpREV[15][ 7] =  691; aacpREV[15][ 8] =  303; aacpREV[15][ 9] =  216; 
16335     aacpREV[15][10] =  516; aacpREV[15][11] =  868; aacpREV[15][12] =   93; aacpREV[15][13] =  487; aacpREV[15][14] = 1202; 
16336     aacpREV[15][15] =    0; aacpREV[15][16] = 2151; aacpREV[15][17] =   73; aacpREV[15][18] =  522; aacpREV[15][19] =  167; 
16337     aacpREV[16][ 0] = 1340; aacpREV[16][ 1] =  314; aacpREV[16][ 2] = 1393; aacpREV[16][ 3] =  266; aacpREV[16][ 4] =  576; 
16338     aacpREV[16][ 5] =  241; aacpREV[16][ 6] =  369; aacpREV[16][ 7] =   92; aacpREV[16][ 8] =   32; aacpREV[16][ 9] = 1040; 
16339     aacpREV[16][10] =  156; aacpREV[16][11] =  918; aacpREV[16][12] =  645; aacpREV[16][13] =  148; aacpREV[16][14] =  260; 
16340     aacpREV[16][15] = 2151; aacpREV[16][16] =    0; aacpREV[16][17] =   29; aacpREV[16][18] =   71; aacpREV[16][19] =  760; 
16341     aacpREV[17][ 0] =   14; aacpREV[17][ 1] =  230; aacpREV[17][ 2] =   40; aacpREV[17][ 3] =   18; aacpREV[17][ 4] =  435; 
16342     aacpREV[17][ 5] =   53; aacpREV[17][ 6] =   63; aacpREV[17][ 7] =   82; aacpREV[17][ 8] =   69; aacpREV[17][ 9] =   42; 
16343     aacpREV[17][10] =  159; aacpREV[17][11] =   10; aacpREV[17][12] =   86; aacpREV[17][13] =  468; aacpREV[17][14] =   49; 
16344     aacpREV[17][15] =   73; aacpREV[17][16] =   29; aacpREV[17][17] =    0; aacpREV[17][18] =  346; aacpREV[17][19] =   10; 
16345     aacpREV[18][ 0] =   56; aacpREV[18][ 1] =  323; aacpREV[18][ 2] =  754; aacpREV[18][ 3] =  281; aacpREV[18][ 4] = 1466; 
16346     aacpREV[18][ 5] =  391; aacpREV[18][ 6] =  142; aacpREV[18][ 7] =   10; aacpREV[18][ 8] = 1971; aacpREV[18][ 9] =   89; 
16347     aacpREV[18][10] =  189; aacpREV[18][11] =  247; aacpREV[18][12] =  215; aacpREV[18][13] = 2370; aacpREV[18][14] =   97; 
16348     aacpREV[18][15] =  522; aacpREV[18][16] =   71; aacpREV[18][17] =  346; aacpREV[18][18] =    0; aacpREV[18][19] =  119; 
16349     aacpREV[19][ 0] =  968; aacpREV[19][ 1] =   92; aacpREV[19][ 2] =   83; aacpREV[19][ 3] =   75; aacpREV[19][ 4] =  592; 
16350     aacpREV[19][ 5] =   54; aacpREV[19][ 6] =  200; aacpREV[19][ 7] =   91; aacpREV[19][ 8] =   25; aacpREV[19][ 9] = 4797; 
16351     aacpREV[19][10] =  865; aacpREV[19][11] =  249; aacpREV[19][12] =  475; aacpREV[19][13] =  317; aacpREV[19][14] =  122; 
16352     aacpREV[19][15] =  167; aacpREV[19][16] =  760; aacpREV[19][17] =   10; aacpREV[19][18] =  119; aacpREV[19][19] =    0;
16353
16354     cprevPi[0] = 0.076;
16355     cprevPi[1] = 0.062;
16356     cprevPi[2] = 0.041;
16357     cprevPi[3] = 0.037;
16358     cprevPi[4] = 0.009;
16359     cprevPi[5] = 0.038;
16360     cprevPi[6] = 0.049;
16361     cprevPi[7] = 0.084;
16362     cprevPi[8] = 0.025;
16363     cprevPi[9] = 0.081;
16364     cprevPi[10] = 0.101;
16365     cprevPi[11] = 0.050;
16366     cprevPi[12] = 0.022;
16367     cprevPi[13] = 0.051;
16368     cprevPi[14] = 0.043;
16369     cprevPi[15] = 0.062;
16370     cprevPi[16] = 0.054;
16371     cprevPi[17] = 0.018;
16372     cprevPi[18] = 0.031;
16373     cprevPi[19] = 0.066;
16374     
16375     /* VT model */
16376     aaVt[ 0][ 0] = 0.000000; aaVt[ 0][ 1] = 0.233108; aaVt[ 0][ 2] = 0.199097; aaVt[ 0][ 3] = 0.265145; aaVt[ 0][ 4] = 0.227333; 
16377     aaVt[ 0][ 5] = 0.310084; aaVt[ 0][ 6] = 0.567957; aaVt[ 0][ 7] = 0.876213; aaVt[ 0][ 8] = 0.078692; aaVt[ 0][ 9] = 0.222972; 
16378     aaVt[ 0][10] = 0.424630; aaVt[ 0][11] = 0.393245; aaVt[ 0][12] = 0.211550; aaVt[ 0][13] = 0.116646; aaVt[ 0][14] = 0.399143; 
16379     aaVt[ 0][15] = 1.817198; aaVt[ 0][16] = 0.877877; aaVt[ 0][17] = 0.030309; aaVt[ 0][18] = 0.087061; aaVt[ 0][19] = 1.230985; 
16380     aaVt[ 1][ 0] = 0.233108; aaVt[ 1][ 1] = 0.000000; aaVt[ 1][ 2] = 0.210797; aaVt[ 1][ 3] = 0.105191; aaVt[ 1][ 4] = 0.031726; 
16381     aaVt[ 1][ 5] = 0.493763; aaVt[ 1][ 6] = 0.255240; aaVt[ 1][ 7] = 0.156945; aaVt[ 1][ 8] = 0.213164; aaVt[ 1][ 9] = 0.081510; 
16382     aaVt[ 1][10] = 0.192364; aaVt[ 1][11] = 1.755838; aaVt[ 1][12] = 0.087930; aaVt[ 1][13] = 0.042569; aaVt[ 1][14] = 0.128480; 
16383     aaVt[ 1][15] = 0.292327; aaVt[ 1][16] = 0.204109; aaVt[ 1][17] = 0.046417; aaVt[ 1][18] = 0.097010; aaVt[ 1][19] = 0.113146; 
16384     aaVt[ 2][ 0] = 0.199097; aaVt[ 2][ 1] = 0.210797; aaVt[ 2][ 2] = 0.000000; aaVt[ 2][ 3] = 0.883422; aaVt[ 2][ 4] = 0.027495; 
16385     aaVt[ 2][ 5] = 0.275700; aaVt[ 2][ 6] = 0.270417; aaVt[ 2][ 7] = 0.362028; aaVt[ 2][ 8] = 0.290006; aaVt[ 2][ 9] = 0.087225; 
16386     aaVt[ 2][10] = 0.069245; aaVt[ 2][11] = 0.503060; aaVt[ 2][12] = 0.057420; aaVt[ 2][13] = 0.039769; aaVt[ 2][14] = 0.083956; 
16387     aaVt[ 2][15] = 0.847049; aaVt[ 2][16] = 0.471268; aaVt[ 2][17] = 0.010459; aaVt[ 2][18] = 0.093268; aaVt[ 2][19] = 0.049824; 
16388     aaVt[ 3][ 0] = 0.265145; aaVt[ 3][ 1] = 0.105191; aaVt[ 3][ 2] = 0.883422; aaVt[ 3][ 3] = 0.000000; aaVt[ 3][ 4] = 0.010313; 
16389     aaVt[ 3][ 5] = 0.205842; aaVt[ 3][ 6] = 1.599461; aaVt[ 3][ 7] = 0.311718; aaVt[ 3][ 8] = 0.134252; aaVt[ 3][ 9] = 0.011720; 
16390     aaVt[ 3][10] = 0.060863; aaVt[ 3][11] = 0.261101; aaVt[ 3][12] = 0.012182; aaVt[ 3][13] = 0.016577; aaVt[ 3][14] = 0.160063; 
16391     aaVt[ 3][15] = 0.461519; aaVt[ 3][16] = 0.178197; aaVt[ 3][17] = 0.011393; aaVt[ 3][18] = 0.051664; aaVt[ 3][19] = 0.048769; 
16392     aaVt[ 4][ 0] = 0.227333; aaVt[ 4][ 1] = 0.031726; aaVt[ 4][ 2] = 0.027495; aaVt[ 4][ 3] = 0.010313; aaVt[ 4][ 4] = 0.000000; 
16393     aaVt[ 4][ 5] = 0.004315; aaVt[ 4][ 6] = 0.005321; aaVt[ 4][ 7] = 0.050876; aaVt[ 4][ 8] = 0.016695; aaVt[ 4][ 9] = 0.046398; 
16394     aaVt[ 4][10] = 0.091709; aaVt[ 4][11] = 0.004067; aaVt[ 4][12] = 0.023690; aaVt[ 4][13] = 0.051127; aaVt[ 4][14] = 0.011137; 
16395     aaVt[ 4][15] = 0.175270; aaVt[ 4][16] = 0.079511; aaVt[ 4][17] = 0.007732; aaVt[ 4][18] = 0.042823; aaVt[ 4][19] = 0.163831; 
16396     aaVt[ 5][ 0] = 0.310084; aaVt[ 5][ 1] = 0.493763; aaVt[ 5][ 2] = 0.275700; aaVt[ 5][ 3] = 0.205842; aaVt[ 5][ 4] = 0.004315; 
16397     aaVt[ 5][ 5] = 0.000000; aaVt[ 5][ 6] = 0.960976; aaVt[ 5][ 7] = 0.128660; aaVt[ 5][ 8] = 0.315521; aaVt[ 5][ 9] = 0.054602; 
16398     aaVt[ 5][10] = 0.243530; aaVt[ 5][11] = 0.738208; aaVt[ 5][12] = 0.120801; aaVt[ 5][13] = 0.026235; aaVt[ 5][14] = 0.156570; 
16399     aaVt[ 5][15] = 0.358017; aaVt[ 5][16] = 0.248992; aaVt[ 5][17] = 0.021248; aaVt[ 5][18] = 0.062544; aaVt[ 5][19] = 0.112027; 
16400     aaVt[ 6][ 0] = 0.567957; aaVt[ 6][ 1] = 0.255240; aaVt[ 6][ 2] = 0.270417; aaVt[ 6][ 3] = 1.599461; aaVt[ 6][ 4] = 0.005321; 
16401     aaVt[ 6][ 5] = 0.960976; aaVt[ 6][ 6] = 0.000000; aaVt[ 6][ 7] = 0.250447; aaVt[ 6][ 8] = 0.104458; aaVt[ 6][ 9] = 0.046589; 
16402     aaVt[ 6][10] = 0.151924; aaVt[ 6][11] = 0.888630; aaVt[ 6][12] = 0.058643; aaVt[ 6][13] = 0.028168; aaVt[ 6][14] = 0.205134; 
16403     aaVt[ 6][15] = 0.406035; aaVt[ 6][16] = 0.321028; aaVt[ 6][17] = 0.018844; aaVt[ 6][18] = 0.055200; aaVt[ 6][19] = 0.205868; 
16404     aaVt[ 7][ 0] = 0.876213; aaVt[ 7][ 1] = 0.156945; aaVt[ 7][ 2] = 0.362028; aaVt[ 7][ 3] = 0.311718; aaVt[ 7][ 4] = 0.050876; 
16405     aaVt[ 7][ 5] = 0.128660; aaVt[ 7][ 6] = 0.250447; aaVt[ 7][ 7] = 0.000000; aaVt[ 7][ 8] = 0.058131; aaVt[ 7][ 9] = 0.051089; 
16406     aaVt[ 7][10] = 0.087056; aaVt[ 7][11] = 0.193243; aaVt[ 7][12] = 0.046560; aaVt[ 7][13] = 0.050143; aaVt[ 7][14] = 0.124492; 
16407     aaVt[ 7][15] = 0.612843; aaVt[ 7][16] = 0.136266; aaVt[ 7][17] = 0.023990; aaVt[ 7][18] = 0.037568; aaVt[ 7][19] = 0.082579; 
16408     aaVt[ 8][ 0] = 0.078692; aaVt[ 8][ 1] = 0.213164; aaVt[ 8][ 2] = 0.290006; aaVt[ 8][ 3] = 0.134252; aaVt[ 8][ 4] = 0.016695; 
16409     aaVt[ 8][ 5] = 0.315521; aaVt[ 8][ 6] = 0.104458; aaVt[ 8][ 7] = 0.058131; aaVt[ 8][ 8] = 0.000000; aaVt[ 8][ 9] = 0.020039; 
16410     aaVt[ 8][10] = 0.103552; aaVt[ 8][11] = 0.153323; aaVt[ 8][12] = 0.021157; aaVt[ 8][13] = 0.079807; aaVt[ 8][14] = 0.078892; 
16411     aaVt[ 8][15] = 0.167406; aaVt[ 8][16] = 0.101117; aaVt[ 8][17] = 0.020009; aaVt[ 8][18] = 0.286027; aaVt[ 8][19] = 0.068575; 
16412     aaVt[ 9][ 0] = 0.222972; aaVt[ 9][ 1] = 0.081510; aaVt[ 9][ 2] = 0.087225; aaVt[ 9][ 3] = 0.011720; aaVt[ 9][ 4] = 0.046398; 
16413     aaVt[ 9][ 5] = 0.054602; aaVt[ 9][ 6] = 0.046589; aaVt[ 9][ 7] = 0.051089; aaVt[ 9][ 8] = 0.020039; aaVt[ 9][ 9] = 0.000000; 
16414     aaVt[ 9][10] = 2.089890; aaVt[ 9][11] = 0.093181; aaVt[ 9][12] = 0.493845; aaVt[ 9][13] = 0.321020; aaVt[ 9][14] = 0.054797; 
16415     aaVt[ 9][15] = 0.081567; aaVt[ 9][16] = 0.376588; aaVt[ 9][17] = 0.034954; aaVt[ 9][18] = 0.086237; aaVt[ 9][19] = 3.654430; 
16416     aaVt[10][ 0] = 0.424630; aaVt[10][ 1] = 0.192364; aaVt[10][ 2] = 0.069245; aaVt[10][ 3] = 0.060863; aaVt[10][ 4] = 0.091709; 
16417     aaVt[10][ 5] = 0.243530; aaVt[10][ 6] = 0.151924; aaVt[10][ 7] = 0.087056; aaVt[10][ 8] = 0.103552; aaVt[10][ 9] = 2.089890; 
16418     aaVt[10][10] = 0.000000; aaVt[10][11] = 0.201204; aaVt[10][12] = 1.105667; aaVt[10][13] = 0.946499; aaVt[10][14] = 0.169784; 
16419     aaVt[10][15] = 0.214977; aaVt[10][16] = 0.243227; aaVt[10][17] = 0.083439; aaVt[10][18] = 0.189842; aaVt[10][19] = 1.337571; 
16420     aaVt[11][ 0] = 0.393245; aaVt[11][ 1] = 1.755838; aaVt[11][ 2] = 0.503060; aaVt[11][ 3] = 0.261101; aaVt[11][ 4] = 0.004067; 
16421     aaVt[11][ 5] = 0.738208; aaVt[11][ 6] = 0.888630; aaVt[11][ 7] = 0.193243; aaVt[11][ 8] = 0.153323; aaVt[11][ 9] = 0.093181; 
16422     aaVt[11][10] = 0.201204; aaVt[11][11] = 0.000000; aaVt[11][12] = 0.096474; aaVt[11][13] = 0.038261; aaVt[11][14] = 0.212302; 
16423     aaVt[11][15] = 0.400072; aaVt[11][16] = 0.446646; aaVt[11][17] = 0.023321; aaVt[11][18] = 0.068689; aaVt[11][19] = 0.144587; 
16424     aaVt[12][ 0] = 0.211550; aaVt[12][ 1] = 0.087930; aaVt[12][ 2] = 0.057420; aaVt[12][ 3] = 0.012182; aaVt[12][ 4] = 0.023690; 
16425     aaVt[12][ 5] = 0.120801; aaVt[12][ 6] = 0.058643; aaVt[12][ 7] = 0.046560; aaVt[12][ 8] = 0.021157; aaVt[12][ 9] = 0.493845; 
16426     aaVt[12][10] = 1.105667; aaVt[12][11] = 0.096474; aaVt[12][12] = 0.000000; aaVt[12][13] = 0.173052; aaVt[12][14] = 0.010363; 
16427     aaVt[12][15] = 0.090515; aaVt[12][16] = 0.184609; aaVt[12][17] = 0.022019; aaVt[12][18] = 0.073223; aaVt[12][19] = 0.307309; 
16428     aaVt[13][ 0] = 0.116646; aaVt[13][ 1] = 0.042569; aaVt[13][ 2] = 0.039769; aaVt[13][ 3] = 0.016577; aaVt[13][ 4] = 0.051127; 
16429     aaVt[13][ 5] = 0.026235; aaVt[13][ 6] = 0.028168; aaVt[13][ 7] = 0.050143; aaVt[13][ 8] = 0.079807; aaVt[13][ 9] = 0.321020; 
16430     aaVt[13][10] = 0.946499; aaVt[13][11] = 0.038261; aaVt[13][12] = 0.173052; aaVt[13][13] = 0.000000; aaVt[13][14] = 0.042564; 
16431     aaVt[13][15] = 0.138119; aaVt[13][16] = 0.085870; aaVt[13][17] = 0.128050; aaVt[13][18] = 0.898663; aaVt[13][19] = 0.247329; 
16432     aaVt[14][ 0] = 0.399143; aaVt[14][ 1] = 0.128480; aaVt[14][ 2] = 0.083956; aaVt[14][ 3] = 0.160063; aaVt[14][ 4] = 0.011137; 
16433     aaVt[14][ 5] = 0.156570; aaVt[14][ 6] = 0.205134; aaVt[14][ 7] = 0.124492; aaVt[14][ 8] = 0.078892; aaVt[14][ 9] = 0.054797; 
16434     aaVt[14][10] = 0.169784; aaVt[14][11] = 0.212302; aaVt[14][12] = 0.010363; aaVt[14][13] = 0.042564; aaVt[14][14] = 0.000000; 
16435     aaVt[14][15] = 0.430431; aaVt[14][16] = 0.207143; aaVt[14][17] = 0.014584; aaVt[14][18] = 0.032043; aaVt[14][19] = 0.129315; 
16436     aaVt[15][ 0] = 1.817198; aaVt[15][ 1] = 0.292327; aaVt[15][ 2] = 0.847049; aaVt[15][ 3] = 0.461519; aaVt[15][ 4] = 0.175270; 
16437     aaVt[15][ 5] = 0.358017; aaVt[15][ 6] = 0.406035; aaVt[15][ 7] = 0.612843; aaVt[15][ 8] = 0.167406; aaVt[15][ 9] = 0.081567; 
16438     aaVt[15][10] = 0.214977; aaVt[15][11] = 0.400072; aaVt[15][12] = 0.090515; aaVt[15][13] = 0.138119; aaVt[15][14] = 0.430431; 
16439     aaVt[15][15] = 0.000000; aaVt[15][16] = 1.767766; aaVt[15][17] = 0.035933; aaVt[15][18] = 0.121979; aaVt[15][19] = 0.127700; 
16440     aaVt[16][ 0] = 0.877877; aaVt[16][ 1] = 0.204109; aaVt[16][ 2] = 0.471268; aaVt[16][ 3] = 0.178197; aaVt[16][ 4] = 0.079511; 
16441     aaVt[16][ 5] = 0.248992; aaVt[16][ 6] = 0.321028; aaVt[16][ 7] = 0.136266; aaVt[16][ 8] = 0.101117; aaVt[16][ 9] = 0.376588; 
16442     aaVt[16][10] = 0.243227; aaVt[16][11] = 0.446646; aaVt[16][12] = 0.184609; aaVt[16][13] = 0.085870; aaVt[16][14] = 0.207143; 
16443     aaVt[16][15] = 1.767766; aaVt[16][16] = 0.000000; aaVt[16][17] = 0.020437; aaVt[16][18] = 0.094617; aaVt[16][19] = 0.740372; 
16444     aaVt[17][ 0] = 0.030309; aaVt[17][ 1] = 0.046417; aaVt[17][ 2] = 0.010459; aaVt[17][ 3] = 0.011393; aaVt[17][ 4] = 0.007732; 
16445     aaVt[17][ 5] = 0.021248; aaVt[17][ 6] = 0.018844; aaVt[17][ 7] = 0.023990; aaVt[17][ 8] = 0.020009; aaVt[17][ 9] = 0.034954; 
16446     aaVt[17][10] = 0.083439; aaVt[17][11] = 0.023321; aaVt[17][12] = 0.022019; aaVt[17][13] = 0.128050; aaVt[17][14] = 0.014584; 
16447     aaVt[17][15] = 0.035933; aaVt[17][16] = 0.020437; aaVt[17][17] = 0.000000; aaVt[17][18] = 0.124746; aaVt[17][19] = 0.022134; 
16448     aaVt[18][ 0] = 0.087061; aaVt[18][ 1] = 0.097010; aaVt[18][ 2] = 0.093268; aaVt[18][ 3] = 0.051664; aaVt[18][ 4] = 0.042823; 
16449     aaVt[18][ 5] = 0.062544; aaVt[18][ 6] = 0.055200; aaVt[18][ 7] = 0.037568; aaVt[18][ 8] = 0.286027; aaVt[18][ 9] = 0.086237; 
16450     aaVt[18][10] = 0.189842; aaVt[18][11] = 0.068689; aaVt[18][12] = 0.073223; aaVt[18][13] = 0.898663; aaVt[18][14] = 0.032043; 
16451     aaVt[18][15] = 0.121979; aaVt[18][16] = 0.094617; aaVt[18][17] = 0.124746; aaVt[18][18] = 0.000000; aaVt[18][19] = 0.125733; 
16452     aaVt[19][ 0] = 1.230985; aaVt[19][ 1] = 0.113146; aaVt[19][ 2] = 0.049824; aaVt[19][ 3] = 0.048769; aaVt[19][ 4] = 0.163831; 
16453     aaVt[19][ 5] = 0.112027; aaVt[19][ 6] = 0.205868; aaVt[19][ 7] = 0.082579; aaVt[19][ 8] = 0.068575; aaVt[19][ 9] = 3.654430; 
16454     aaVt[19][10] = 1.337571; aaVt[19][11] = 0.144587; aaVt[19][12] = 0.307309; aaVt[19][13] = 0.247329; aaVt[19][14] = 0.129315; 
16455     aaVt[19][15] = 0.127700; aaVt[19][16] = 0.740372; aaVt[19][17] = 0.022134; aaVt[19][18] = 0.125733; aaVt[19][19] = 0.000000;
16456
16457     vtPi[ 0] = 0.078837;
16458     vtPi[ 1] = 0.051238;
16459     vtPi[ 2] = 0.042313;
16460     vtPi[ 3] = 0.053066;
16461     vtPi[ 4] = 0.015175;
16462     vtPi[ 5] = 0.036713;
16463     vtPi[ 6] = 0.061924;
16464     vtPi[ 7] = 0.070852;
16465     vtPi[ 8] = 0.023082;
16466     vtPi[ 9] = 0.062056;
16467     vtPi[10] = 0.096371;
16468     vtPi[11] = 0.057324;
16469     vtPi[12] = 0.023771;
16470     vtPi[13] = 0.043296;
16471     vtPi[14] = 0.043911;
16472     vtPi[15] = 0.063403;
16473     vtPi[16] = 0.055897;
16474     vtPi[17] = 0.013272;
16475     vtPi[18] = 0.034399;
16476     vtPi[19] = 0.073101;
16477     
16478     /* Blosum62 */
16479     aaBlosum[ 0][ 0] = 0.000000000000; aaBlosum[ 0][ 1] = 0.735790389698; aaBlosum[ 0][ 2] = 0.485391055466; aaBlosum[ 0][ 3] = 0.543161820899; aaBlosum[ 0][ 4] = 1.459995310470; 
16480     aaBlosum[ 0][ 5] = 1.199705704602; aaBlosum[ 0][ 6] = 1.170949042800; aaBlosum[ 0][ 7] = 1.955883574960; aaBlosum[ 0][ 8] = 0.716241444998; aaBlosum[ 0][ 9] = 0.605899003687; 
16481     aaBlosum[ 0][10] = 0.800016530518; aaBlosum[ 0][11] = 1.295201266783; aaBlosum[ 0][12] = 1.253758266664; aaBlosum[ 0][13] = 0.492964679748; aaBlosum[ 0][14] = 1.173275900924; 
16482     aaBlosum[ 0][15] = 4.325092687057; aaBlosum[ 0][16] = 1.729178019485; aaBlosum[ 0][17] = 0.465839367725; aaBlosum[ 0][18] = 0.718206697586; aaBlosum[ 0][19] = 2.187774522005; 
16483     aaBlosum[ 1][ 0] = 0.735790389698; aaBlosum[ 1][ 1] = 0.000000000000; aaBlosum[ 1][ 2] = 1.297446705134; aaBlosum[ 1][ 3] = 0.500964408555; aaBlosum[ 1][ 4] = 0.227826574209; 
16484     aaBlosum[ 1][ 5] = 3.020833610064; aaBlosum[ 1][ 6] = 1.360574190420; aaBlosum[ 1][ 7] = 0.418763308518; aaBlosum[ 1][ 8] = 1.456141166336; aaBlosum[ 1][ 9] = 0.232036445142; 
16485     aaBlosum[ 1][10] = 0.622711669692; aaBlosum[ 1][11] = 5.411115141489; aaBlosum[ 1][12] = 0.983692987457; aaBlosum[ 1][13] = 0.371644693209; aaBlosum[ 1][14] = 0.448133661718; 
16486     aaBlosum[ 1][15] = 1.122783104210; aaBlosum[ 1][16] = 0.914665954563; aaBlosum[ 1][17] = 0.426382310122; aaBlosum[ 1][18] = 0.720517441216; aaBlosum[ 1][19] = 0.438388343772; 
16487     aaBlosum[ 2][ 0] = 0.485391055466; aaBlosum[ 2][ 1] = 1.297446705134; aaBlosum[ 2][ 2] = 0.000000000000; aaBlosum[ 2][ 3] = 3.180100048216; aaBlosum[ 2][ 4] = 0.397358949897; 
16488     aaBlosum[ 2][ 5] = 1.839216146992; aaBlosum[ 2][ 6] = 1.240488508640; aaBlosum[ 2][ 7] = 1.355872344485; aaBlosum[ 2][ 8] = 2.414501434208; aaBlosum[ 2][ 9] = 0.283017326278; 
16489     aaBlosum[ 2][10] = 0.211888159615; aaBlosum[ 2][11] = 1.593137043457; aaBlosum[ 2][12] = 0.648441278787; aaBlosum[ 2][13] = 0.354861249223; aaBlosum[ 2][14] = 0.494887043702; 
16490     aaBlosum[ 2][15] = 2.904101656456; aaBlosum[ 2][16] = 1.898173634533; aaBlosum[ 2][17] = 0.191482046247; aaBlosum[ 2][18] = 0.538222519037; aaBlosum[ 2][19] = 0.312858797993; 
16491     aaBlosum[ 3][ 0] = 0.543161820899; aaBlosum[ 3][ 1] = 0.500964408555; aaBlosum[ 3][ 2] = 3.180100048216; aaBlosum[ 3][ 3] = 0.000000000000; aaBlosum[ 3][ 4] = 0.240836614802; 
16492     aaBlosum[ 3][ 5] = 1.190945703396; aaBlosum[ 3][ 6] = 3.761625208368; aaBlosum[ 3][ 7] = 0.798473248968; aaBlosum[ 3][ 8] = 0.778142664022; aaBlosum[ 3][ 9] = 0.418555732462; 
16493     aaBlosum[ 3][10] = 0.218131577594; aaBlosum[ 3][11] = 1.032447924952; aaBlosum[ 3][12] = 0.222621897958; aaBlosum[ 3][13] = 0.281730694207; aaBlosum[ 3][14] = 0.730628272998; 
16494     aaBlosum[ 3][15] = 1.582754142065; aaBlosum[ 3][16] = 0.934187509431; aaBlosum[ 3][17] = 0.145345046279; aaBlosum[ 3][18] = 0.261422208965; aaBlosum[ 3][19] = 0.258129289418; 
16495     aaBlosum[ 4][ 0] = 1.459995310470; aaBlosum[ 4][ 1] = 0.227826574209; aaBlosum[ 4][ 2] = 0.397358949897; aaBlosum[ 4][ 3] = 0.240836614802; aaBlosum[ 4][ 4] = 0.000000000000; 
16496     aaBlosum[ 4][ 5] = 0.329801504630; aaBlosum[ 4][ 6] = 0.140748891814; aaBlosum[ 4][ 7] = 0.418203192284; aaBlosum[ 4][ 8] = 0.354058109831; aaBlosum[ 4][ 9] = 0.774894022794; 
16497     aaBlosum[ 4][10] = 0.831842640142; aaBlosum[ 4][11] = 0.285078800906; aaBlosum[ 4][12] = 0.767688823480; aaBlosum[ 4][13] = 0.441337471187; aaBlosum[ 4][14] = 0.356008498769; 
16498     aaBlosum[ 4][15] = 1.197188415094; aaBlosum[ 4][16] = 1.119831358516; aaBlosum[ 4][17] = 0.527664418872; aaBlosum[ 4][18] = 0.470237733696; aaBlosum[ 4][19] = 1.116352478606; 
16499     aaBlosum[ 5][ 0] = 1.199705704602; aaBlosum[ 5][ 1] = 3.020833610064; aaBlosum[ 5][ 2] = 1.839216146992; aaBlosum[ 5][ 3] = 1.190945703396; aaBlosum[ 5][ 4] = 0.329801504630; 
16500     aaBlosum[ 5][ 5] = 0.000000000000; aaBlosum[ 5][ 6] = 5.528919177928; aaBlosum[ 5][ 7] = 0.609846305383; aaBlosum[ 5][ 8] = 2.435341131140; aaBlosum[ 5][ 9] = 0.236202451204; 
16501     aaBlosum[ 5][10] = 0.580737093181; aaBlosum[ 5][11] = 3.945277674515; aaBlosum[ 5][12] = 2.494896077113; aaBlosum[ 5][13] = 0.144356959750; aaBlosum[ 5][14] = 0.858570575674; 
16502     aaBlosum[ 5][15] = 1.934870924596; aaBlosum[ 5][16] = 1.277480294596; aaBlosum[ 5][17] = 0.758653808642; aaBlosum[ 5][18] = 0.958989742850; aaBlosum[ 5][19] = 0.530785790125; 
16503     aaBlosum[ 6][ 0] = 1.170949042800; aaBlosum[ 6][ 1] = 1.360574190420; aaBlosum[ 6][ 2] = 1.240488508640; aaBlosum[ 6][ 3] = 3.761625208368; aaBlosum[ 6][ 4] = 0.140748891814; 
16504     aaBlosum[ 6][ 5] = 5.528919177928; aaBlosum[ 6][ 6] = 0.000000000000; aaBlosum[ 6][ 7] = 0.423579992176; aaBlosum[ 6][ 8] = 1.626891056982; aaBlosum[ 6][ 9] = 0.186848046932; 
16505     aaBlosum[ 6][10] = 0.372625175087; aaBlosum[ 6][11] = 2.802427151679; aaBlosum[ 6][12] = 0.555415397470; aaBlosum[ 6][13] = 0.291409084165; aaBlosum[ 6][14] = 0.926563934846; 
16506     aaBlosum[ 6][15] = 1.769893238937; aaBlosum[ 6][16] = 1.071097236007; aaBlosum[ 6][17] = 0.407635648938; aaBlosum[ 6][18] = 0.596719300346; aaBlosum[ 6][19] = 0.524253846338; 
16507     aaBlosum[ 7][ 0] = 1.955883574960; aaBlosum[ 7][ 1] = 0.418763308518; aaBlosum[ 7][ 2] = 1.355872344485; aaBlosum[ 7][ 3] = 0.798473248968; aaBlosum[ 7][ 4] = 0.418203192284; 
16508     aaBlosum[ 7][ 5] = 0.609846305383; aaBlosum[ 7][ 6] = 0.423579992176; aaBlosum[ 7][ 7] = 0.000000000000; aaBlosum[ 7][ 8] = 0.539859124954; aaBlosum[ 7][ 9] = 0.189296292376; 
16509     aaBlosum[ 7][10] = 0.217721159236; aaBlosum[ 7][11] = 0.752042440303; aaBlosum[ 7][12] = 0.459436173579; aaBlosum[ 7][13] = 0.368166464453; aaBlosum[ 7][14] = 0.504086599527; 
16510     aaBlosum[ 7][15] = 1.509326253224; aaBlosum[ 7][16] = 0.641436011405; aaBlosum[ 7][17] = 0.508358924638; aaBlosum[ 7][18] = 0.308055737035; aaBlosum[ 7][19] = 0.253340790190; 
16511     aaBlosum[ 8][ 0] = 0.716241444998; aaBlosum[ 8][ 1] = 1.456141166336; aaBlosum[ 8][ 2] = 2.414501434208; aaBlosum[ 8][ 3] = 0.778142664022; aaBlosum[ 8][ 4] = 0.354058109831; 
16512     aaBlosum[ 8][ 5] = 2.435341131140; aaBlosum[ 8][ 6] = 1.626891056982; aaBlosum[ 8][ 7] = 0.539859124954; aaBlosum[ 8][ 8] = 0.000000000000; aaBlosum[ 8][ 9] = 0.252718447885; 
16513     aaBlosum[ 8][10] = 0.348072209797; aaBlosum[ 8][11] = 1.022507035889; aaBlosum[ 8][12] = 0.984311525359; aaBlosum[ 8][13] = 0.714533703928; aaBlosum[ 8][14] = 0.527007339151; 
16514     aaBlosum[ 8][15] = 1.117029762910; aaBlosum[ 8][16] = 0.585407090225; aaBlosum[ 8][17] = 0.301248600780; aaBlosum[ 8][18] = 4.218953969389; aaBlosum[ 8][19] = 0.201555971750; 
16515     aaBlosum[ 9][ 0] = 0.605899003687; aaBlosum[ 9][ 1] = 0.232036445142; aaBlosum[ 9][ 2] = 0.283017326278; aaBlosum[ 9][ 3] = 0.418555732462; aaBlosum[ 9][ 4] = 0.774894022794; 
16516     aaBlosum[ 9][ 5] = 0.236202451204; aaBlosum[ 9][ 6] = 0.186848046932; aaBlosum[ 9][ 7] = 0.189296292376; aaBlosum[ 9][ 8] = 0.252718447885; aaBlosum[ 9][ 9] = 0.000000000000; 
16517     aaBlosum[ 9][10] = 3.890963773304; aaBlosum[ 9][11] = 0.406193586642; aaBlosum[ 9][12] = 3.364797763104; aaBlosum[ 9][13] = 1.517359325954; aaBlosum[ 9][14] = 0.388355409206; 
16518     aaBlosum[ 9][15] = 0.357544412460; aaBlosum[ 9][16] = 1.179091197260; aaBlosum[ 9][17] = 0.341985787540; aaBlosum[ 9][18] = 0.674617093228; aaBlosum[ 9][19] = 8.311839405458; 
16519     aaBlosum[10][ 0] = 0.800016530518; aaBlosum[10][ 1] = 0.622711669692; aaBlosum[10][ 2] = 0.211888159615; aaBlosum[10][ 3] = 0.218131577594; aaBlosum[10][ 4] = 0.831842640142; 
16520     aaBlosum[10][ 5] = 0.580737093181; aaBlosum[10][ 6] = 0.372625175087; aaBlosum[10][ 7] = 0.217721159236; aaBlosum[10][ 8] = 0.348072209797; aaBlosum[10][ 9] = 3.890963773304; 
16521     aaBlosum[10][10] = 0.000000000000; aaBlosum[10][11] = 0.445570274261; aaBlosum[10][12] = 6.030559379572; aaBlosum[10][13] = 2.064839703237; aaBlosum[10][14] = 0.374555687471; 
16522     aaBlosum[10][15] = 0.352969184527; aaBlosum[10][16] = 0.915259857694; aaBlosum[10][17] = 0.691474634600; aaBlosum[10][18] = 0.811245856323; aaBlosum[10][19] = 2.231405688913; 
16523     aaBlosum[11][ 0] = 1.295201266783; aaBlosum[11][ 1] = 5.411115141489; aaBlosum[11][ 2] = 1.593137043457; aaBlosum[11][ 3] = 1.032447924952; aaBlosum[11][ 4] = 0.285078800906; 
16524     aaBlosum[11][ 5] = 3.945277674515; aaBlosum[11][ 6] = 2.802427151679; aaBlosum[11][ 7] = 0.752042440303; aaBlosum[11][ 8] = 1.022507035889; aaBlosum[11][ 9] = 0.406193586642; 
16525     aaBlosum[11][10] = 0.445570274261; aaBlosum[11][11] = 0.000000000000; aaBlosum[11][12] = 1.073061184332; aaBlosum[11][13] = 0.266924750511; aaBlosum[11][14] = 1.047383450722; 
16526     aaBlosum[11][15] = 1.752165917819; aaBlosum[11][16] = 1.303875200799; aaBlosum[11][17] = 0.332243040634; aaBlosum[11][18] = 0.717993486900; aaBlosum[11][19] = 0.498138475304; 
16527     aaBlosum[12][ 0] = 1.253758266664; aaBlosum[12][ 1] = 0.983692987457; aaBlosum[12][ 2] = 0.648441278787; aaBlosum[12][ 3] = 0.222621897958; aaBlosum[12][ 4] = 0.767688823480; 
16528     aaBlosum[12][ 5] = 2.494896077113; aaBlosum[12][ 6] = 0.555415397470; aaBlosum[12][ 7] = 0.459436173579; aaBlosum[12][ 8] = 0.984311525359; aaBlosum[12][ 9] = 3.364797763104; 
16529     aaBlosum[12][10] = 6.030559379572; aaBlosum[12][11] = 1.073061184332; aaBlosum[12][12] = 0.000000000000; aaBlosum[12][13] = 1.773855168830; aaBlosum[12][14] = 0.454123625103; 
16530     aaBlosum[12][15] = 0.918723415746; aaBlosum[12][16] = 1.488548053722; aaBlosum[12][17] = 0.888101098152; aaBlosum[12][18] = 0.951682162246; aaBlosum[12][19] = 2.575850755315; 
16531     aaBlosum[13][ 0] = 0.492964679748; aaBlosum[13][ 1] = 0.371644693209; aaBlosum[13][ 2] = 0.354861249223; aaBlosum[13][ 3] = 0.281730694207; aaBlosum[13][ 4] = 0.441337471187; 
16532     aaBlosum[13][ 5] = 0.144356959750; aaBlosum[13][ 6] = 0.291409084165; aaBlosum[13][ 7] = 0.368166464453; aaBlosum[13][ 8] = 0.714533703928; aaBlosum[13][ 9] = 1.517359325954; 
16533     aaBlosum[13][10] = 2.064839703237; aaBlosum[13][11] = 0.266924750511; aaBlosum[13][12] = 1.773855168830; aaBlosum[13][13] = 0.000000000000; aaBlosum[13][14] = 0.233597909629; 
16534     aaBlosum[13][15] = 0.540027644824; aaBlosum[13][16] = 0.488206118793; aaBlosum[13][17] = 2.074324893497; aaBlosum[13][18] = 6.747260430801; aaBlosum[13][19] = 0.838119610178; 
16535     aaBlosum[14][ 0] = 1.173275900924; aaBlosum[14][ 1] = 0.448133661718; aaBlosum[14][ 2] = 0.494887043702; aaBlosum[14][ 3] = 0.730628272998; aaBlosum[14][ 4] = 0.356008498769; 
16536     aaBlosum[14][ 5] = 0.858570575674; aaBlosum[14][ 6] = 0.926563934846; aaBlosum[14][ 7] = 0.504086599527; aaBlosum[14][ 8] = 0.527007339151; aaBlosum[14][ 9] = 0.388355409206; 
16537     aaBlosum[14][10] = 0.374555687471; aaBlosum[14][11] = 1.047383450722; aaBlosum[14][12] = 0.454123625103; aaBlosum[14][13] = 0.233597909629; aaBlosum[14][14] = 0.000000000000; 
16538     aaBlosum[14][15] = 1.169129577716; aaBlosum[14][16] = 1.005451683149; aaBlosum[14][17] = 0.252214830027; aaBlosum[14][18] = 0.369405319355; aaBlosum[14][19] = 0.496908410676; 
16539     aaBlosum[15][ 0] = 4.325092687057; aaBlosum[15][ 1] = 1.122783104210; aaBlosum[15][ 2] = 2.904101656456; aaBlosum[15][ 3] = 1.582754142065; aaBlosum[15][ 4] = 1.197188415094; 
16540     aaBlosum[15][ 5] = 1.934870924596; aaBlosum[15][ 6] = 1.769893238937; aaBlosum[15][ 7] = 1.509326253224; aaBlosum[15][ 8] = 1.117029762910; aaBlosum[15][ 9] = 0.357544412460; 
16541     aaBlosum[15][10] = 0.352969184527; aaBlosum[15][11] = 1.752165917819; aaBlosum[15][12] = 0.918723415746; aaBlosum[15][13] = 0.540027644824; aaBlosum[15][14] = 1.169129577716; 
16542     aaBlosum[15][15] = 0.000000000000; aaBlosum[15][16] = 5.151556292270; aaBlosum[15][17] = 0.387925622098; aaBlosum[15][18] = 0.796751520761; aaBlosum[15][19] = 0.561925457442; 
16543     aaBlosum[16][ 0] = 1.729178019485; aaBlosum[16][ 1] = 0.914665954563; aaBlosum[16][ 2] = 1.898173634533; aaBlosum[16][ 3] = 0.934187509431; aaBlosum[16][ 4] = 1.119831358516; 
16544     aaBlosum[16][ 5] = 1.277480294596; aaBlosum[16][ 6] = 1.071097236007; aaBlosum[16][ 7] = 0.641436011405; aaBlosum[16][ 8] = 0.585407090225; aaBlosum[16][ 9] = 1.179091197260; 
16545     aaBlosum[16][10] = 0.915259857694; aaBlosum[16][11] = 1.303875200799; aaBlosum[16][12] = 1.488548053722; aaBlosum[16][13] = 0.488206118793; aaBlosum[16][14] = 1.005451683149; 
16546     aaBlosum[16][15] = 5.151556292270; aaBlosum[16][16] = 0.000000000000; aaBlosum[16][17] = 0.513128126891; aaBlosum[16][18] = 0.801010243199; aaBlosum[16][19] = 2.253074051176; 
16547     aaBlosum[17][ 0] = 0.465839367725; aaBlosum[17][ 1] = 0.426382310122; aaBlosum[17][ 2] = 0.191482046247; aaBlosum[17][ 3] = 0.145345046279; aaBlosum[17][ 4] = 0.527664418872; 
16548     aaBlosum[17][ 5] = 0.758653808642; aaBlosum[17][ 6] = 0.407635648938; aaBlosum[17][ 7] = 0.508358924638; aaBlosum[17][ 8] = 0.301248600780; aaBlosum[17][ 9] = 0.341985787540; 
16549     aaBlosum[17][10] = 0.691474634600; aaBlosum[17][11] = 0.332243040634; aaBlosum[17][12] = 0.888101098152; aaBlosum[17][13] = 2.074324893497; aaBlosum[17][14] = 0.252214830027; 
16550     aaBlosum[17][15] = 0.387925622098; aaBlosum[17][16] = 0.513128126891; aaBlosum[17][17] = 0.000000000000; aaBlosum[17][18] = 4.054419006558; aaBlosum[17][19] = 0.266508731426; 
16551     aaBlosum[18][ 0] = 0.718206697586; aaBlosum[18][ 1] = 0.720517441216; aaBlosum[18][ 2] = 0.538222519037; aaBlosum[18][ 3] = 0.261422208965; aaBlosum[18][ 4] = 0.470237733696; 
16552     aaBlosum[18][ 5] = 0.958989742850; aaBlosum[18][ 6] = 0.596719300346; aaBlosum[18][ 7] = 0.308055737035; aaBlosum[18][ 8] = 4.218953969389; aaBlosum[18][ 9] = 0.674617093228; 
16553     aaBlosum[18][10] = 0.811245856323; aaBlosum[18][11] = 0.717993486900; aaBlosum[18][12] = 0.951682162246; aaBlosum[18][13] = 6.747260430801; aaBlosum[18][14] = 0.369405319355; 
16554     aaBlosum[18][15] = 0.796751520761; aaBlosum[18][16] = 0.801010243199; aaBlosum[18][17] = 4.054419006558; aaBlosum[18][18] = 0.000000000000; aaBlosum[18][19] = 1.000000000000; 
16555     aaBlosum[19][ 0] = 2.187774522005; aaBlosum[19][ 1] = 0.438388343772; aaBlosum[19][ 2] = 0.312858797993; aaBlosum[19][ 3] = 0.258129289418; aaBlosum[19][ 4] = 1.116352478606; 
16556     aaBlosum[19][ 5] = 0.530785790125; aaBlosum[19][ 6] = 0.524253846338; aaBlosum[19][ 7] = 0.253340790190; aaBlosum[19][ 8] = 0.201555971750; aaBlosum[19][ 9] = 8.311839405458; 
16557     aaBlosum[19][10] = 2.231405688913; aaBlosum[19][11] = 0.498138475304; aaBlosum[19][12] = 2.575850755315; aaBlosum[19][13] = 0.838119610178; aaBlosum[19][14] = 0.496908410676; 
16558     aaBlosum[19][15] = 0.561925457442; aaBlosum[19][16] = 2.253074051176; aaBlosum[19][17] = 0.266508731426; aaBlosum[19][18] = 1.000000000000; aaBlosum[19][19] = 0.000000000000;
16559
16560     blosPi[ 0] = 0.074; 
16561     blosPi[ 1] = 0.052; 
16562     blosPi[ 2] = 0.045; 
16563     blosPi[ 3] = 0.054;
16564     blosPi[ 4] = 0.025; 
16565     blosPi[ 5] = 0.034; 
16566     blosPi[ 6] = 0.054; 
16567     blosPi[ 7] = 0.074;
16568     blosPi[ 8] = 0.026; 
16569     blosPi[ 9] = 0.068; 
16570     blosPi[10] = 0.099; 
16571     blosPi[11] = 0.058;
16572     blosPi[12] = 0.025; 
16573     blosPi[13] = 0.047; 
16574     blosPi[14] = 0.039; 
16575     blosPi[15] = 0.057;
16576     blosPi[16] = 0.051; 
16577     blosPi[17] = 0.013; 
16578     blosPi[18] = 0.032; 
16579     blosPi[19] = 0.073;
16580
16581     /* LG */
16582     aaLG[ 0][ 0] = 0.000000; aaLG[ 0][ 1] = 0.425093; aaLG[ 0][ 2] = 0.276818; aaLG[ 0][ 3] = 0.395144; aaLG[ 0][ 4] = 2.489084;
16583     aaLG[ 0][ 5] = 0.969894; aaLG[ 0][ 6] = 1.038545; aaLG[ 0][ 7] = 2.066040; aaLG[ 0][ 8] = 0.358858; aaLG[ 0][ 9] = 0.149830;
16584     aaLG[ 0][10] = 0.395337; aaLG[ 0][11] = 0.536518; aaLG[ 0][12] = 1.124035; aaLG[ 0][13] = 0.253701; aaLG[ 0][14] = 1.177651;
16585     aaLG[ 0][15] = 4.727182; aaLG[ 0][16] = 2.139501; aaLG[ 0][17] = 0.180717; aaLG[ 0][18] = 0.218959; aaLG[ 0][19] = 2.547870;
16586     aaLG[ 1][ 0] = 0.425093; aaLG[ 1][ 1] = 0.000000; aaLG[ 1][ 2] = 0.751878; aaLG[ 1][ 3] = 0.123954; aaLG[ 1][ 4] = 0.534551;
16587     aaLG[ 1][ 5] = 2.807908; aaLG[ 1][ 6] = 0.363970; aaLG[ 1][ 7] = 0.390192; aaLG[ 1][ 8] = 2.426601; aaLG[ 1][ 9] = 0.126991;
16588     aaLG[ 1][10] = 0.301848; aaLG[ 1][11] = 6.326067; aaLG[ 1][12] = 0.484133; aaLG[ 1][13] = 0.052722; aaLG[ 1][14] = 0.332533;
16589     aaLG[ 1][15] = 0.858151; aaLG[ 1][16] = 0.578987; aaLG[ 1][17] = 0.593607; aaLG[ 1][18] = 0.314440; aaLG[ 1][19] = 0.170887;
16590     aaLG[ 2][ 0] = 0.276818; aaLG[ 2][ 1] = 0.751878; aaLG[ 2][ 2] = 0.000000; aaLG[ 2][ 3] = 5.076149; aaLG[ 2][ 4] = 0.528768;
16591     aaLG[ 2][ 5] = 1.695752; aaLG[ 2][ 6] = 0.541712; aaLG[ 2][ 7] = 1.437645; aaLG[ 2][ 8] = 4.509238; aaLG[ 2][ 9] = 0.191503;
16592     aaLG[ 2][10] = 0.068427; aaLG[ 2][11] = 2.145078; aaLG[ 2][12] = 0.371004; aaLG[ 2][13] = 0.089525; aaLG[ 2][14] = 0.161787;
16593     aaLG[ 2][15] = 4.008358; aaLG[ 2][16] = 2.000679; aaLG[ 2][17] = 0.045376; aaLG[ 2][18] = 0.612025; aaLG[ 2][19] = 0.083688;
16594     aaLG[ 3][ 0] = 0.395144; aaLG[ 3][ 1] = 0.123954; aaLG[ 3][ 2] = 5.076149; aaLG[ 3][ 3] = 0.000000; aaLG[ 3][ 4] = 0.062556;
16595     aaLG[ 3][ 5] = 0.523386; aaLG[ 3][ 6] = 5.243870; aaLG[ 3][ 7] = 0.844926; aaLG[ 3][ 8] = 0.927114; aaLG[ 3][ 9] = 0.010690;
16596     aaLG[ 3][10] = 0.015076; aaLG[ 3][11] = 0.282959; aaLG[ 3][12] = 0.025548; aaLG[ 3][13] = 0.017416; aaLG[ 3][14] = 0.394456;
16597     aaLG[ 3][15] = 1.240275; aaLG[ 3][16] = 0.425860; aaLG[ 3][17] = 0.029890; aaLG[ 3][18] = 0.135107; aaLG[ 3][19] = 0.037967;
16598     aaLG[ 4][ 0] = 2.489084; aaLG[ 4][ 1] = 0.534551; aaLG[ 4][ 2] = 0.528768; aaLG[ 4][ 3] = 0.062556; aaLG[ 4][ 4] = 0.000000;
16599     aaLG[ 4][ 5] = 0.084808; aaLG[ 4][ 6] = 0.003499; aaLG[ 4][ 7] = 0.569265; aaLG[ 4][ 8] = 0.640543; aaLG[ 4][ 9] = 0.320627;
16600     aaLG[ 4][10] = 0.594007; aaLG[ 4][11] = 0.013266; aaLG[ 4][12] = 0.893680; aaLG[ 4][13] = 1.105251; aaLG[ 4][14] = 0.075382;
16601     aaLG[ 4][15] = 2.784478; aaLG[ 4][16] = 1.143480; aaLG[ 4][17] = 0.670128; aaLG[ 4][18] = 1.165532; aaLG[ 4][19] = 1.959291;
16602     aaLG[ 5][ 0] = 0.969894; aaLG[ 5][ 1] = 2.807908; aaLG[ 5][ 2] = 1.695752; aaLG[ 5][ 3] = 0.523386; aaLG[ 5][ 4] = 0.084808;
16603     aaLG[ 5][ 5] = 0.000000; aaLG[ 5][ 6] = 4.128591; aaLG[ 5][ 7] = 0.267959; aaLG[ 5][ 8] = 4.813505; aaLG[ 5][ 9] = 0.072854;
16604     aaLG[ 5][10] = 0.582457; aaLG[ 5][11] = 3.234294; aaLG[ 5][12] = 1.672569; aaLG[ 5][13] = 0.035855; aaLG[ 5][14] = 0.624294;
16605     aaLG[ 5][15] = 1.223828; aaLG[ 5][16] = 1.080136; aaLG[ 5][17] = 0.236199; aaLG[ 5][18] = 0.257336; aaLG[ 5][19] = 0.210332;
16606     aaLG[ 6][ 0] = 1.038545; aaLG[ 6][ 1] = 0.363970; aaLG[ 6][ 2] = 0.541712; aaLG[ 6][ 3] = 5.243870; aaLG[ 6][ 4] = 0.003499;
16607     aaLG[ 6][ 5] = 4.128591; aaLG[ 6][ 6] = 0.000000; aaLG[ 6][ 7] = 0.348847; aaLG[ 6][ 8] = 0.423881; aaLG[ 6][ 9] = 0.044265;
16608     aaLG[ 6][10] = 0.069673; aaLG[ 6][11] = 1.807177; aaLG[ 6][12] = 0.173735; aaLG[ 6][13] = 0.018811; aaLG[ 6][14] = 0.419409;
16609     aaLG[ 6][15] = 0.611973; aaLG[ 6][16] = 0.604545; aaLG[ 6][17] = 0.077852; aaLG[ 6][18] = 0.120037; aaLG[ 6][19] = 0.245034;
16610     aaLG[ 7][ 0] = 2.066040; aaLG[ 7][ 1] = 0.390192; aaLG[ 7][ 2] = 1.437645; aaLG[ 7][ 3] = 0.844926; aaLG[ 7][ 4] = 0.569265;
16611     aaLG[ 7][ 5] = 0.267959; aaLG[ 7][ 6] = 0.348847; aaLG[ 7][ 7] = 0.000000; aaLG[ 7][ 8] = 0.311484; aaLG[ 7][ 9] = 0.008705;
16612     aaLG[ 7][10] = 0.044261; aaLG[ 7][11] = 0.296636; aaLG[ 7][12] = 0.139538; aaLG[ 7][13] = 0.089586; aaLG[ 7][14] = 0.196961;
16613     aaLG[ 7][15] = 1.739990; aaLG[ 7][16] = 0.129836; aaLG[ 7][17] = 0.268491; aaLG[ 7][18] = 0.054679; aaLG[ 7][19] = 0.076701;
16614     aaLG[ 8][ 0] = 0.358858; aaLG[ 8][ 1] = 2.426601; aaLG[ 8][ 2] = 4.509238; aaLG[ 8][ 3] = 0.927114; aaLG[ 8][ 4] = 0.640543;
16615     aaLG[ 8][ 5] = 4.813505; aaLG[ 8][ 6] = 0.423881; aaLG[ 8][ 7] = 0.311484; aaLG[ 8][ 8] = 0.000000; aaLG[ 8][ 9] = 0.108882;
16616     aaLG[ 8][10] = 0.366317; aaLG[ 8][11] = 0.697264; aaLG[ 8][12] = 0.442472; aaLG[ 8][13] = 0.682139; aaLG[ 8][14] = 0.508851;
16617     aaLG[ 8][15] = 0.990012; aaLG[ 8][16] = 0.584262; aaLG[ 8][17] = 0.597054; aaLG[ 8][18] = 5.306834; aaLG[ 8][19] = 0.119013;
16618     aaLG[ 9][ 0] = 0.149830; aaLG[ 9][ 1] = 0.126991; aaLG[ 9][ 2] = 0.191503; aaLG[ 9][ 3] = 0.010690; aaLG[ 9][ 4] = 0.320627;
16619     aaLG[ 9][ 5] = 0.072854; aaLG[ 9][ 6] = 0.044265; aaLG[ 9][ 7] = 0.008705; aaLG[ 9][ 8] = 0.108882; aaLG[ 9][ 9] = 0.000000;
16620     aaLG[ 9][10] = 4.145067; aaLG[ 9][11] = 0.159069; aaLG[ 9][12] = 4.273607; aaLG[ 9][13] = 1.112727; aaLG[ 9][14] = 0.078281;
16621     aaLG[ 9][15] = 0.064105; aaLG[ 9][16] = 1.033739; aaLG[ 9][17] = 0.111660; aaLG[ 9][18] = 0.232523; aaLG[ 9][19] = 10.649107;
16622     aaLG[10][ 0] = 0.395337; aaLG[10][ 1] = 0.301848; aaLG[10][ 2] = 0.068427; aaLG[10][ 3] = 0.015076; aaLG[10][ 4] = 0.594007;
16623     aaLG[10][ 5] = 0.582457; aaLG[10][ 6] = 0.069673; aaLG[10][ 7] = 0.044261; aaLG[10][ 8] = 0.366317; aaLG[10][ 9] = 4.145067;
16624     aaLG[10][10] = 0.000000; aaLG[10][11] = 0.137500; aaLG[10][12] = 6.312358; aaLG[10][13] = 2.592692; aaLG[10][14] = 0.249060;
16625     aaLG[10][15] = 0.182287; aaLG[10][16] = 0.302936; aaLG[10][17] = 0.619632; aaLG[10][18] = 0.299648; aaLG[10][19] = 1.702745;
16626     aaLG[11][ 0] = 0.536518; aaLG[11][ 1] = 6.326067; aaLG[11][ 2] = 2.145078; aaLG[11][ 3] = 0.282959; aaLG[11][ 4] = 0.013266;
16627     aaLG[11][ 5] = 3.234294; aaLG[11][ 6] = 1.807177; aaLG[11][ 7] = 0.296636; aaLG[11][ 8] = 0.697264; aaLG[11][ 9] = 0.159069;
16628     aaLG[11][10] = 0.137500; aaLG[11][11] = 0.000000; aaLG[11][12] = 0.656604; aaLG[11][13] = 0.023918; aaLG[11][14] = 0.390322;
16629     aaLG[11][15] = 0.748683; aaLG[11][16] = 1.136863; aaLG[11][17] = 0.049906; aaLG[11][18] = 0.131932; aaLG[11][19] = 0.185202;
16630     aaLG[12][ 0] = 1.124035; aaLG[12][ 1] = 0.484133; aaLG[12][ 2] = 0.371004; aaLG[12][ 3] = 0.025548; aaLG[12][ 4] = 0.893680;
16631     aaLG[12][ 5] = 1.672569; aaLG[12][ 6] = 0.173735; aaLG[12][ 7] = 0.139538; aaLG[12][ 8] = 0.442472; aaLG[12][ 9] = 4.273607;
16632     aaLG[12][10] = 6.312358; aaLG[12][11] = 0.656604; aaLG[12][12] = 0.000000; aaLG[12][13] = 1.798853; aaLG[12][14] = 0.099849;
16633     aaLG[12][15] = 0.346960; aaLG[12][16] = 2.020366; aaLG[12][17] = 0.696175; aaLG[12][18] = 0.481306; aaLG[12][19] = 1.898718;
16634     aaLG[13][ 0] = 0.253701; aaLG[13][ 1] = 0.052722; aaLG[13][ 2] = 0.089525; aaLG[13][ 3] = 0.017416; aaLG[13][ 4] = 1.105251;
16635     aaLG[13][ 5] = 0.035855; aaLG[13][ 6] = 0.018811; aaLG[13][ 7] = 0.089586; aaLG[13][ 8] = 0.682139; aaLG[13][ 9] = 1.112727;
16636     aaLG[13][10] = 2.592692; aaLG[13][11] = 0.023918; aaLG[13][12] = 1.798853; aaLG[13][13] = 0.000000; aaLG[13][14] = 0.094464;
16637     aaLG[13][15] = 0.361819; aaLG[13][16] = 0.165001; aaLG[13][17] = 2.457121; aaLG[13][18] = 7.803902; aaLG[13][19] = 0.654683;
16638     aaLG[14][ 0] = 1.177651; aaLG[14][ 1] = 0.332533; aaLG[14][ 2] = 0.161787; aaLG[14][ 3] = 0.394456; aaLG[14][ 4] = 0.075382;
16639     aaLG[14][ 5] = 0.624294; aaLG[14][ 6] = 0.419409; aaLG[14][ 7] = 0.196961; aaLG[14][ 8] = 0.508851; aaLG[14][ 9] = 0.078281;
16640     aaLG[14][10] = 0.249060; aaLG[14][11] = 0.390322; aaLG[14][12] = 0.099849; aaLG[14][13] = 0.094464; aaLG[14][14] = 0.000000;
16641     aaLG[14][15] = 1.338132; aaLG[14][16] = 0.571468; aaLG[14][17] = 0.095131; aaLG[14][18] = 0.089613; aaLG[14][19] = 0.296501;
16642     aaLG[15][ 0] = 4.727182; aaLG[15][ 1] = 0.858151; aaLG[15][ 2] = 4.008358; aaLG[15][ 3] = 1.240275; aaLG[15][ 4] = 2.784478;
16643     aaLG[15][ 5] = 1.223828; aaLG[15][ 6] = 0.611973; aaLG[15][ 7] = 1.739990; aaLG[15][ 8] = 0.990012; aaLG[15][ 9] = 0.064105;
16644     aaLG[15][10] = 0.182287; aaLG[15][11] = 0.748683; aaLG[15][12] = 0.346960; aaLG[15][13] = 0.361819; aaLG[15][14] = 1.338132;
16645     aaLG[15][15] = 0.000000; aaLG[15][16] = 6.472279; aaLG[15][17] = 0.248862; aaLG[15][18] = 0.400547; aaLG[15][19] = 0.098369;
16646     aaLG[16][ 0] = 2.139501; aaLG[16][ 1] = 0.578987; aaLG[16][ 2] = 2.000679; aaLG[16][ 3] = 0.425860; aaLG[16][ 4] = 1.143480;
16647     aaLG[16][ 5] = 1.080136; aaLG[16][ 6] = 0.604545; aaLG[16][ 7] = 0.129836; aaLG[16][ 8] = 0.584262; aaLG[16][ 9] = 1.033739;
16648     aaLG[16][10] = 0.302936; aaLG[16][11] = 1.136863; aaLG[16][12] = 2.020366; aaLG[16][13] = 0.165001; aaLG[16][14] = 0.571468;
16649     aaLG[16][15] = 6.472279; aaLG[16][16] = 0.000000; aaLG[16][17] = 0.140825; aaLG[16][18] = 0.245841; aaLG[16][19] = 2.188158;
16650     aaLG[17][ 0] = 0.180717; aaLG[17][ 1] = 0.593607; aaLG[17][ 2] = 0.045376; aaLG[17][ 3] = 0.029890; aaLG[17][ 4] = 0.670128;
16651     aaLG[17][ 5] = 0.236199; aaLG[17][ 6] = 0.077852; aaLG[17][ 7] = 0.268491; aaLG[17][ 8] = 0.597054; aaLG[17][ 9] = 0.111660;
16652     aaLG[17][10] = 0.619632; aaLG[17][11] = 0.049906; aaLG[17][12] = 0.696175; aaLG[17][13] = 2.457121; aaLG[17][14] = 0.095131;
16653     aaLG[17][15] = 0.248862; aaLG[17][16] = 0.140825; aaLG[17][17] = 0.000000; aaLG[17][18] = 3.151815; aaLG[17][19] = 0.189510;
16654     aaLG[18][ 0] = 0.218959; aaLG[18][ 1] = 0.314440; aaLG[18][ 2] = 0.612025; aaLG[18][ 3] = 0.135107; aaLG[18][ 4] = 1.165532;
16655     aaLG[18][ 5] = 0.257336; aaLG[18][ 6] = 0.120037; aaLG[18][ 7] = 0.054679; aaLG[18][ 8] = 5.306834; aaLG[18][ 9] = 0.232523;
16656     aaLG[18][10] = 0.299648; aaLG[18][11] = 0.131932; aaLG[18][12] = 0.481306; aaLG[18][13] = 7.803902; aaLG[18][14] = 0.089613;
16657     aaLG[18][15] = 0.400547; aaLG[18][16] = 0.245841; aaLG[18][17] = 3.151815; aaLG[18][18] = 0.000000; aaLG[18][19] = 0.249313;
16658     aaLG[19][ 0] = 2.547870; aaLG[19][ 1] = 0.170887; aaLG[19][ 2] = 0.083688; aaLG[19][ 3] = 0.037967; aaLG[19][ 4] = 1.959291;
16659     aaLG[19][ 5] = 0.210332; aaLG[19][ 6] = 0.245034; aaLG[19][ 7] = 0.076701; aaLG[19][ 8] = 0.119013; aaLG[19][ 9] = 10.649107;
16660     aaLG[19][10] = 1.702745; aaLG[19][11] = 0.185202; aaLG[19][12] = 1.898718; aaLG[19][13] = 0.654683; aaLG[19][14] = 0.296501;
16661     aaLG[19][15] = 0.098369; aaLG[19][16] = 2.188158; aaLG[19][17] = 0.189510; aaLG[19][18] = 0.249313; aaLG[19][19] = 0.000000;
16662
16663     lgPi[0] = 0.079066;  lgPi[1] = 0.055941;  lgPi[2] = 0.041977;  lgPi[3] = 0.053052;
16664     lgPi[4] = 0.012937;  lgPi[5] = 0.040767;  lgPi[6] = 0.071586;  lgPi[7] = 0.057337;
16665     lgPi[8] = 0.022355;  lgPi[9] = 0.062157;  lgPi[10] = 0.099081; lgPi[11] = 0.064600;
16666     lgPi[12] = 0.022951; lgPi[13] = 0.042302; lgPi[14] = 0.044040; lgPi[15] = 0.061197;
16667     lgPi[16] = 0.053287; lgPi[17] = 0.012066; lgPi[18] = 0.034155; lgPi[19] = 0.069147;
16668
16669     /* now, check that the matrices are symmetrical */
16670     for (i=0; i<20; i++)
16671         {
16672         for (j=i+1; j<20; j++)
16673             {
16674             diff = aaJones[i][j] - aaJones[j][i];
16675             if (diff < 0.0)
16676                 diff = -diff;
16677             if (diff > 0.001)
16678                 {
16679                 MrBayesPrint ("%s   ERROR: Jones model is not symmetrical.\n");
16680                 return (ERROR);
16681                 }
16682             }
16683         }
16684     for (i=0; i<20; i++)
16685         {
16686         for (j=i+1; j<20; j++)
16687             {
16688             diff = aaDayhoff[i][j] - aaDayhoff[j][i];
16689             if (diff < 0.0)
16690                 diff = -diff;
16691             if (diff > 0.001)
16692                 {
16693                 MrBayesPrint ("%s   ERROR: Dayhoff model is not symmetrical.\n");
16694                 return (ERROR);
16695                 }
16696             }
16697         }
16698     for (i=0; i<20; i++)
16699         {
16700         for (j=i+1; j<20; j++)
16701             {
16702             diff = aaMtrev24[i][j] - aaMtrev24[j][i];
16703             if (diff < 0.0)
16704                 diff = -diff;
16705             if (diff > 0.001)
16706                 {
16707                 MrBayesPrint ("%s   ERROR: mtrev24 model is not symmetrical.\n");
16708                 return (ERROR);
16709                 }
16710             }
16711         }
16712     for (i=0; i<20; i++)
16713         {
16714         for (j=i+1; j<20; j++)
16715             {
16716             diff = aaMtmam[i][j] - aaMtmam[j][i];
16717             if (diff < 0.0)
16718                 diff = -diff;
16719             if (diff > 0.001)
16720                 {
16721                 MrBayesPrint ("%s   ERROR: mtmam model is not symmetrical.\n");
16722                 return (ERROR);
16723                 }
16724             }
16725         }
16726     for (i=0; i<20; i++)
16727         {
16728         for (j=i+1; j<20; j++)
16729             {
16730             diff = aartREV[i][j] - aartREV[j][i];
16731             if (diff < 0.0)
16732                 diff = -diff;
16733             if (diff > 0.001)
16734                 {
16735                 MrBayesPrint ("%s   ERROR: aartREV model is not symmetrical.\n");
16736                 return (ERROR);
16737                 }
16738             }
16739         }
16740     for (i=0; i<20; i++)
16741         {
16742         for (j=i+1; j<20; j++)
16743             {
16744             diff = aaWAG[i][j] - aaWAG[j][i];
16745             if (diff < 0.0)
16746                 diff = -diff;
16747             if (diff > 0.001)
16748                 {
16749                 MrBayesPrint ("%s   ERROR: aaWAG model is not symmetrical.\n");
16750                 return (ERROR);
16751                 }
16752             }
16753         }
16754     for (i=0; i<20; i++)
16755         {
16756         for (j=i+1; j<20; j++)
16757             {
16758             diff = aacpREV[i][j] - aacpREV[j][i];
16759             if (diff < 0.0)
16760                 diff = -diff;
16761             if (diff > 0.001)
16762                 {
16763                 MrBayesPrint ("%s   ERROR: cpREV model is not symmetrical.\n");
16764                 return (ERROR);
16765                 }
16766             }
16767         }
16768     for (i=0; i<20; i++)
16769         {
16770         for (j=i+1; j<20; j++)
16771             {
16772             diff = aaVt[i][j] - aaVt[j][i];
16773             if (diff < 0.0)
16774                 diff = -diff;
16775             if (diff > 0.001)
16776                 {
16777                 MrBayesPrint ("%s   ERROR: Vt model is not symmetrical.\n");
16778                 return (ERROR);
16779                 }
16780             }
16781         }
16782     for (i=0; i<20; i++)
16783         {
16784         for (j=i+1; j<20; j++)
16785             {
16786             diff = aaBlosum[i][j] - aaBlosum[j][i];
16787             if (diff < 0.0)
16788                 diff = -diff;
16789             if (diff > 0.001)
16790                 {
16791                 MrBayesPrint ("%s   ERROR: Blosum model is not symmetrical.\n");
16792                 return (ERROR);
16793                 }
16794             }
16795         }
16796     for (i=0; i<20; i++)
16797         {
16798         for (j=i+1; j<20; j++)
16799             {
16800             diff = aaLG[i][j] - aaLG[j][i];
16801             if (diff < 0.0)
16802                 diff = -diff;
16803             if (diff > 0.001)
16804                 {
16805                 MrBayesPrint ("%s   ERROR: LG model is not symmetrical.\n");
16806                 return (ERROR);
16807                 }
16808             }
16809         }
16810     
16811     /* rescale stationary frequencies, to make certain they sum to 1.0 */
16812     sum = 0.0;
16813     for (i=0; i<20; i++)
16814         sum += jonesPi[i];
16815     for (i=0; i<20; i++)
16816         jonesPi[i] /= sum;
16817     sum = 0.0;
16818     for (i=0; i<20; i++)
16819         sum += dayhoffPi[i];
16820     for (i=0; i<20; i++)
16821         dayhoffPi[i] /= sum;
16822     sum = 0.0;
16823     for (i=0; i<20; i++)
16824         sum += mtrev24Pi[i];
16825     for (i=0; i<20; i++)
16826         mtrev24Pi[i] /= sum;
16827     sum = 0.0;
16828     for (i=0; i<20; i++)
16829         sum += mtmamPi[i];
16830     for (i=0; i<20; i++)
16831         mtmamPi[i] /= sum;
16832     sum = 0.0;
16833     for (i=0; i<20; i++)
16834         sum += rtrevPi[i];
16835     for (i=0; i<20; i++)
16836         rtrevPi[i] /= sum;
16837     sum = 0.0;
16838     for (i=0; i<20; i++)
16839         sum += wagPi[i];
16840     for (i=0; i<20; i++)
16841         wagPi[i] /= sum;
16842     sum = 0.0;
16843     for (i=0; i<20; i++)
16844         sum += cprevPi[i];
16845     for (i=0; i<20; i++)
16846         cprevPi[i] /= sum;
16847     sum = 0.0;
16848     for (i=0; i<20; i++)
16849         sum += vtPi[i];
16850     for (i=0; i<20; i++)
16851         vtPi[i] /= sum;
16852     sum = 0.0;
16853     for (i=0; i<20; i++)
16854         sum += blosPi[i];
16855     for (i=0; i<20; i++)
16856         blosPi[i] /= sum;
16857     sum = 0.0;
16858     for (i=0; i<20; i++)
16859         sum += lgPi[i];
16860     for (i=0; i<20; i++)
16861         lgPi[i] /= sum;
16862     
16863     /* multiply entries by amino acid frequencies */
16864     for (i=0; i<20; i++)
16865         {
16866         for (j=0; j<20; j++)
16867             {
16868             aaJones[i][j]   *= jonesPi[j];
16869             aaDayhoff[i][j] *= dayhoffPi[j];
16870             aaMtrev24[i][j] *= mtrev24Pi[j];
16871             aaMtmam[i][j]   *= mtmamPi[j];
16872             aartREV[i][j]   *= rtrevPi[j];
16873             aaWAG[i][j]     *= wagPi[j];
16874             aacpREV[i][j]   *= cprevPi[j];
16875             aaVt[i][j]      *= vtPi[j];
16876             aaBlosum[i][j]  *= blosPi[j];
16877             aaLG[i][j]      *= lgPi[j];
16878             }
16879         }
16880         
16881     /* rescale, so branch lengths are in terms of expected number of
16882        amino acid substitutions per site */
16883     scaler = 0.0;
16884     for (i=0; i<20; i++)
16885         {
16886         for (j=i+1; j<20; j++)
16887             {
16888             scaler += jonesPi[i] * aaJones[i][j];
16889             scaler += jonesPi[j] * aaJones[j][i];
16890             }
16891         }
16892     scaler = 1.0 / scaler;
16893     for (i=0; i<20; i++)
16894         for (j=0; j<20; j++)
16895             aaJones[i][j] *= scaler;
16896     scaler = 0.0;
16897     for (i=0; i<20; i++)
16898         {
16899         for (j=i+1; j<20; j++)
16900             {
16901             scaler += dayhoffPi[i] * aaDayhoff[i][j];
16902             scaler += dayhoffPi[j] * aaDayhoff[j][i];
16903             }
16904         }
16905     scaler = 1.0 / scaler;
16906     for (i=0; i<20; i++)
16907         for (j=0; j<20; j++)
16908             aaDayhoff[i][j] *= scaler;
16909     scaler = 0.0;
16910     for (i=0; i<20; i++)
16911         {
16912         for (j=i+1; j<20; j++)
16913             {
16914             scaler += mtrev24Pi[i] * aaMtrev24[i][j];
16915             scaler += mtrev24Pi[j] * aaMtrev24[j][i];
16916             }
16917         }
16918     scaler = 1.0 / scaler;
16919     for (i=0; i<20; i++)
16920         for (j=0; j<20; j++)
16921             aaMtrev24[i][j] *= scaler;
16922     scaler = 0.0;
16923     for (i=0; i<20; i++)
16924         {
16925         for (j=i+1; j<20; j++)
16926             {
16927             scaler += mtmamPi[i] * aaMtmam[i][j];
16928             scaler += mtmamPi[j] * aaMtmam[j][i];
16929             }
16930         }
16931     scaler = 1.0 / scaler;
16932     for (i=0; i<20; i++)
16933         for (j=0; j<20; j++)
16934             aaMtmam[i][j] *= scaler;
16935     scaler = 0.0;
16936     for (i=0; i<20; i++)
16937         {
16938         for (j=i+1; j<20; j++)
16939             {
16940             scaler += rtrevPi[i] * aartREV[i][j];
16941             scaler += rtrevPi[j] * aartREV[j][i];
16942             }
16943         }
16944     scaler = 1.0 / scaler;
16945     for (i=0; i<20; i++)
16946         for (j=0; j<20; j++)
16947             aartREV[i][j] *= scaler;
16948     scaler = 0.0;
16949     for (i=0; i<20; i++)
16950         {
16951         for (j=i+1; j<20; j++)
16952             {
16953             scaler += wagPi[i] * aaWAG[i][j];
16954             scaler += wagPi[j] * aaWAG[j][i];
16955             }
16956         }
16957     scaler = 1.0 / scaler;
16958     for (i=0; i<20; i++)
16959         for (j=0; j<20; j++)
16960             aaWAG[i][j] *= scaler;
16961     scaler = 0.0;
16962     for (i=0; i<20; i++)
16963         {
16964         for (j=i+1; j<20; j++)
16965             {
16966             scaler += cprevPi[i] * aacpREV[i][j];
16967             scaler += cprevPi[j] * aacpREV[j][i];
16968             }
16969         }
16970     scaler = 1.0 / scaler;
16971     for (i=0; i<20; i++)
16972         for (j=0; j<20; j++)
16973             aacpREV[i][j] *= scaler;
16974     scaler = 0.0;
16975     for (i=0; i<20; i++)
16976         {
16977         for (j=i+1; j<20; j++)
16978             {
16979             scaler += vtPi[i] * aaVt[i][j];
16980             scaler += vtPi[j] * aaVt[j][i];
16981             }
16982         }
16983     scaler = 1.0 / scaler;
16984     for (i=0; i<20; i++)
16985         for (j=0; j<20; j++)
16986             aaVt[i][j] *= scaler;
16987     scaler = 0.0;
16988     for (i=0; i<20; i++)
16989         {
16990         for (j=i+1; j<20; j++)
16991             {
16992             scaler += blosPi[i] * aaBlosum[i][j];
16993             scaler += blosPi[j] * aaBlosum[j][i];
16994             }
16995         }
16996     scaler = 1.0 / scaler;
16997     for (i=0; i<20; i++)
16998         for (j=0; j<20; j++)
16999             aaBlosum[i][j] *= scaler;
17000     scaler = 0.0;
17001     for (i=0; i<20; i++)
17002         {
17003         for (j=i+1; j<20; j++)
17004             {
17005             scaler += lgPi[i] * aaLG[i][j];
17006             scaler += lgPi[j] * aaLG[j][i];
17007             }
17008         }
17009     scaler = 1.0 / scaler;
17010     for (i=0; i<20; i++)
17011         for (j=0; j<20; j++)
17012             aaLG[i][j] *= scaler;
17013     
17014     /* set diagonal of matrix */
17015     for (i=0; i<20; i++)
17016         {
17017         sum = 0.0;
17018         for (j=0; j<20; j++)
17019             {
17020             if (i != j)
17021                 sum += aaJones[i][j];
17022             }
17023         aaJones[i][i] = -sum;
17024         }
17025     for (i=0; i<20; i++)
17026         {
17027         sum = 0.0;
17028         for (j=0; j<20; j++)
17029             {
17030             if (i != j)
17031                 sum += aaDayhoff[i][j];
17032             }
17033         aaDayhoff[i][i] = -sum;
17034         }
17035     for (i=0; i<20; i++)
17036         {
17037         sum = 0.0;
17038         for (j=0; j<20; j++)
17039             {
17040             if (i != j)
17041                 sum += aaMtrev24[i][j];
17042             }
17043         aaMtrev24[i][i] = -sum;
17044         }
17045     for (i=0; i<20; i++)
17046         {
17047         sum = 0.0;
17048         for (j=0; j<20; j++)
17049             {
17050             if (i != j)
17051                 sum += aaMtmam[i][j];
17052             }
17053         aaMtmam[i][i] = -sum;
17054         }
17055     for (i=0; i<20; i++)
17056         {
17057         sum = 0.0;
17058         for (j=0; j<20; j++)
17059             {
17060             if (i != j)
17061                 sum += aartREV[i][j];
17062             }
17063         aartREV[i][i] = -sum;
17064         }
17065     for (i=0; i<20; i++)
17066         {
17067         sum = 0.0;
17068         for (j=0; j<20; j++)
17069             {
17070             if (i != j)
17071                 sum += aaWAG[i][j];
17072             }
17073         aaWAG[i][i] = -sum;
17074         }
17075     for (i=0; i<20; i++)
17076         {
17077         sum = 0.0;
17078         for (j=0; j<20; j++)
17079             {
17080             if (i != j)
17081                 sum += aacpREV[i][j];
17082             }
17083         aacpREV[i][i] = -sum;
17084         }
17085     for (i=0; i<20; i++)
17086         {
17087         sum = 0.0;
17088         for (j=0; j<20; j++)
17089             {
17090             if (i != j)
17091                 sum += aaVt[i][j];
17092             }
17093         aaVt[i][i] = -sum;
17094         }
17095     for (i=0; i<20; i++)
17096         {
17097         sum = 0.0;
17098         for (j=0; j<20; j++)
17099             {
17100             if (i != j)
17101                 sum += aaBlosum[i][j];
17102             }
17103         aaBlosum[i][i] = -sum;
17104         }
17105     for (i=0; i<20; i++)
17106         {
17107         sum = 0.0;
17108         for (j=0; j<20; j++)
17109             {
17110             if (i != j)
17111                 sum += aaLG[i][j];
17112             }
17113         aaLG[i][i] = -sum;
17114         }
17115
17116 #   if 0
17117     for (i=0; i<20; i++)
17118         {
17119         MrBayesPrint ("%s   ", spacer);
17120         for (j=0; j<20; j++)
17121             {
17122             if (aaLG[i][j] < 0.0)
17123                 MrBayesPrint ("%1.3lf ", aaLG[i][j]);
17124             else
17125                 MrBayesPrint (" %1.3lf ", aaLG[i][j]);
17126             }
17127         MrBayesPrint ("\n");
17128         }
17129 #   endif
17130
17131     return (NO_ERROR);
17132 }
17133
17134
17135 void SetCode (int part)
17136 {
17137     int     i, s, s1, s2, s3, ns;
17138     
17139     modelParams[part].codon[ 0] = 12; /* AAA Lys */
17140     modelParams[part].codon[ 1] =  3; /* AAC Asn */
17141     modelParams[part].codon[ 2] = 12; /* AAG Lys */
17142     modelParams[part].codon[ 3] =  3; /* AAT Asn */
17143     modelParams[part].codon[ 4] = 17; /* ACA Thr */
17144     modelParams[part].codon[ 5] = 17; /* ACC Thr */
17145     modelParams[part].codon[ 6] = 17; /* ACG Thr */
17146     modelParams[part].codon[ 7] = 17; /* ACT Thr */
17147     modelParams[part].codon[ 8] =  2; /* AGA Arg */
17148     modelParams[part].codon[ 9] = 16; /* AGC Ser */
17149     modelParams[part].codon[10] =  2; /* AGG Arg */
17150     modelParams[part].codon[11] = 16; /* AGT Ser */
17151     modelParams[part].codon[12] = 10; /* ATA Ile */
17152     modelParams[part].codon[13] = 10; /* ATC Ile */
17153     modelParams[part].codon[14] = 13; /* ATG Met */
17154     modelParams[part].codon[15] = 10; /* ATT Ile */
17155     modelParams[part].codon[16] =  6; /* CAA Gln */
17156     modelParams[part].codon[17] =  9; /* CAC His */
17157     modelParams[part].codon[18] =  6; /* CAG Gln */
17158     modelParams[part].codon[19] =  9; /* CAT His */
17159     modelParams[part].codon[20] = 15; /* CCA Pro */
17160     modelParams[part].codon[21] = 15; /* CCC Pro */
17161     modelParams[part].codon[22] = 15; /* CCG Pro */
17162     modelParams[part].codon[23] = 15; /* CCT Pro */
17163     modelParams[part].codon[24] =  2; /* CGA Arg */
17164     modelParams[part].codon[25] =  2; /* CGC Arg */
17165     modelParams[part].codon[26] =  2; /* CGG Arg */
17166     modelParams[part].codon[27] =  2; /* CGT Arg */
17167     modelParams[part].codon[28] = 11; /* CTA Leu */
17168     modelParams[part].codon[29] = 11; /* CTC Leu */
17169     modelParams[part].codon[30] = 11; /* CTG Leu */
17170     modelParams[part].codon[31] = 11; /* CTT Leu */
17171     modelParams[part].codon[32] =  7; /* GAA Glu */
17172     modelParams[part].codon[33] =  4; /* GAC Asp */
17173     modelParams[part].codon[34] =  7; /* GAG Glu */
17174     modelParams[part].codon[35] =  4; /* GAT Asp */
17175     modelParams[part].codon[36] =  1; /* GCA Ala */
17176     modelParams[part].codon[37] =  1; /* GCC Ala */
17177     modelParams[part].codon[38] =  1; /* GCG Ala */
17178     modelParams[part].codon[39] =  1; /* GCT Ala */
17179     modelParams[part].codon[40] =  8; /* GGA Gly */
17180     modelParams[part].codon[41] =  8; /* GGC Gly */
17181     modelParams[part].codon[42] =  8; /* GGG Gly */
17182     modelParams[part].codon[43] =  8; /* GGT Gly */
17183     modelParams[part].codon[44] = 20; /* GTA Val */
17184     modelParams[part].codon[45] = 20; /* GTC Val */
17185     modelParams[part].codon[46] = 20; /* GTG Val */
17186     modelParams[part].codon[47] = 20; /* GTT Val */
17187     modelParams[part].codon[48] = 21; /* TAA Stop*/
17188     modelParams[part].codon[49] = 19; /* TAC Tyr */
17189     modelParams[part].codon[50] = 21; /* TAG Stop*/
17190     modelParams[part].codon[51] = 19; /* TAT Tyr */
17191     modelParams[part].codon[52] = 16; /* TCA Ser */
17192     modelParams[part].codon[53] = 16; /* TCC Ser */
17193     modelParams[part].codon[54] = 16; /* TCG Ser */
17194     modelParams[part].codon[55] = 16; /* TCT Ser */
17195     modelParams[part].codon[56] = 21; /* TGA Stop*/
17196     modelParams[part].codon[57] =  5; /* TGC Cys */
17197     modelParams[part].codon[58] = 18; /* TGG Trp */
17198     modelParams[part].codon[59] =  5; /* TGT Cys */
17199     modelParams[part].codon[60] = 11; /* TTA Leu */
17200     modelParams[part].codon[61] = 14; /* TTC Phe */
17201     modelParams[part].codon[62] = 11; /* TTG Leu */
17202     modelParams[part].codon[63] = 14; /* TTT Phe */
17203     
17204     if (!strcmp(modelParams[part].geneticCode, "Vertmt"))
17205         {
17206         /* UGA: Ter -> Trp
17207            AUA: Ile -> Met
17208            AGA: Arg -> Ter
17209            AGG: Arg -> Ter */
17210         modelParams[part].codon[ 8] = 21; /* AGA Stop */
17211         modelParams[part].codon[10] = 21; /* AGG Stop */
17212         modelParams[part].codon[12] = 13; /* ATA Met  */
17213         modelParams[part].codon[56] = 18; /* TGA Trp  */
17214         }
17215     if (!strcmp(modelParams[part].geneticCode, "Invermt"))
17216         {
17217         /* UGA: Ter -> Trp
17218            AUA: Ile -> Met
17219            AGA: Arg -> Ser
17220            AGG: Arg -> Ser */
17221         modelParams[part].codon[ 8] = 16; /* AGA Ser */
17222         modelParams[part].codon[10] = 16; /* AGG Ser */
17223         modelParams[part].codon[12] = 13; /* ATA Met */
17224         modelParams[part].codon[56] = 18; /* TGA Trp */
17225         }
17226     else if (!strcmp(modelParams[part].geneticCode, "Mycoplasma"))
17227         {
17228         /* UGA: Ter -> Trp */
17229         modelParams[part].codon[56] = 18; /* TGA Trp */
17230         }
17231     else if (!strcmp(modelParams[part].geneticCode, "Yeast"))
17232         {
17233         /* UGA: Ter -> Trp
17234            AUA: Ile -> Met
17235            CUA: Leu -> Thr
17236            CUC: Leu -> Thr
17237            CUG: Leu -> Thr
17238            CUU: Leu -> Thr */
17239         modelParams[part].codon[12] = 13; /* ATA Met */
17240         modelParams[part].codon[28] = 17; /* CTA Thr */
17241         modelParams[part].codon[29] = 17; /* CTC Thr */
17242         modelParams[part].codon[30] = 17; /* CTG Thr */
17243         modelParams[part].codon[31] = 17; /* CTT Thr */
17244         modelParams[part].codon[56] = 18; /* TGA Trp */
17245         }
17246     else if (!strcmp(modelParams[part].geneticCode, "Ciliate"))
17247         {
17248         /* UAA: Ter -> Gln
17249            UAG: Ter -> Gln */
17250         modelParams[part].codon[48] =  6; /* TAA Gln */
17251         modelParams[part].codon[50] =  6; /* TAG Gln */
17252         }
17253     else if (!strcmp(modelParams[part].geneticCode, "Echinoderm"))
17254         {
17255         /* AAA: Lys -> Asn
17256            AGA: Arg -> Ser
17257            AGG: Arg -> Ser
17258            UGA: Ter -> Trp */
17259         modelParams[part].codon[ 0] = 3;  /* AAA Asn */
17260         modelParams[part].codon[ 8] = 16; /* AGA Ser */
17261         modelParams[part].codon[10] = 16; /* AGG Ser */
17262         modelParams[part].codon[56] = 18; /* TGA Trp */
17263         }
17264     else if (!strcmp(modelParams[part].geneticCode, "Euplotid"))
17265         {
17266         /* UGA: Ter -> Cys */
17267         modelParams[part].codon[56] = 5;  /* TGA Cys */
17268         }
17269     else if (!strcmp(modelParams[part].geneticCode, "Metmt"))
17270         {
17271         /* UGA: Ter -> Trp
17272            AUA: Ile -> Met
17273            AGA: Arg -> Ser
17274            AGG: Arg -> Ser */
17275         modelParams[part].codon[ 8] = 16; /* AGA Ser */
17276         modelParams[part].codon[10] = 16; /* AGG Ser */
17277         modelParams[part].codon[12] = 13; /* ATA Met */
17278         modelParams[part].codon[56] = 18; /* TGA Trp */
17279         }
17280     else
17281         {
17282         }
17283     
17284     ns = 0;
17285     for (i=0; i<64; i++)
17286         {
17287         if (modelParams[part].codon[i] != 21)
17288             ns++;
17289         }
17290     /* printf ("ns = %d\n", ns); */
17291     
17292     s = 0;
17293     for (s1=0; s1<4; s1++)
17294         for (s2=0; s2<4; s2++)
17295             for (s3=0; s3<4; s3++)
17296                 if (modelParams[part].codon[s1*16 + s2*4 + s3] != 21)
17297                     {
17298                     modelParams[part].codonNucs[s][0] = s1;
17299                     modelParams[part].codonNucs[s][1] = s2;
17300                     modelParams[part].codonNucs[s][2] = s3;
17301                     modelParams[part].codonAAs[s] = modelParams[part].codon[s1*16 + s2*4 + s3];
17302                     s++;
17303                     }
17304 }
17305
17306
17307 int SetLocalTaxa (void)
17308 {
17309     int         i, j;
17310     
17311     /* free memory if allocated */
17312     if (memAllocs[ALLOC_LOCTAXANAMES] == YES)
17313         {
17314         free (localTaxonNames);
17315         localTaxonNames = NULL;
17316         memAllocs[ALLOC_LOCTAXANAMES] = NO;
17317         }
17318     if (memAllocs[ALLOC_LOCALTAXONCALIBRATION] == YES)
17319         {
17320         free (localTaxonCalibration);
17321         localTaxonCalibration = NULL;
17322         memAllocs[ALLOC_LOCALTAXONCALIBRATION] = NO;
17323         }
17324     
17325     /* count number of non-excluded taxa */
17326     numLocalTaxa = 0;
17327     for (i=0; i<numTaxa; i++)
17328         {
17329         if (taxaInfo[i].isDeleted == NO)
17330             numLocalTaxa++;
17331         }
17332         
17333     /* allocate memory */
17334     localTaxonNames = (char **)SafeCalloc((size_t)numLocalTaxa, sizeof(char *));
17335     if (!localTaxonNames)
17336         return (ERROR);
17337     memAllocs[ALLOC_LOCTAXANAMES] = YES;
17338
17339     localTaxonCalibration = (Calibration **)SafeCalloc((size_t)numLocalTaxa, sizeof(Calibration *));
17340     if (!localTaxonCalibration)
17341         return (ERROR);
17342     memAllocs[ALLOC_LOCALTAXONCALIBRATION] = YES;
17343         
17344     /* point to names and calibrations of non-excluded taxa */
17345     localOutGroup = 0;
17346     for (i=j=0; i<numTaxa; i++)
17347         {
17348         if (taxaInfo[i].isDeleted == NO)
17349             {
17350             localTaxonNames[j] = taxaNames[i];
17351             localTaxonCalibration[j] = &tipCalibration[i];
17352             if (i == outGroupNum)
17353                 localOutGroup = j;
17354             j++;
17355             }
17356         }
17357
17358 #   if 0
17359     /* show non-excluded taxa */
17360     for (i=0; i<numLocalTaxa; i++)
17361         MrBayesPrint ("%s   %4d %s\n", spacer, i+1, localTaxonNames[i]);
17362 #   endif
17363         
17364     return (NO_ERROR);
17365 }
17366
17367
17368 /*----------------------------------------------------------------------------
17369 |
17370 |   SetModelDefaults: This function will set up model defaults in modelParams.
17371 |       It will also initialize parameters and moves by calling SetUpAnalysis.
17372 |
17373 -----------------------------------------------------------------------------*/
17374 int SetModelDefaults (void)
17375 {
17376     int         j;
17377
17378     MrBayesPrint ("%s   Setting model defaults\n", spacer);
17379     MrBayesPrint ("%s   Seed (for generating default start values) = %d\n", spacer, globalSeed);
17380
17381     if (InitializeLinks () == ERROR)
17382         {
17383         MrBayesPrint ("%s   Problem initializing link table\n", spacer);
17384         return (ERROR);
17385         }
17386
17387     /* Check that models are allocated */
17388     if (memAllocs[ALLOC_MODEL] == NO)
17389         {
17390         MrBayesPrint ("%s   Model not allocated in SetModelDefaults\n", spacer);
17391         return (ERROR);
17392         }
17393
17394     /* model parameters */
17395     for (j=0; j<numCurrentDivisions; j++)
17396         {
17397         modelParams[j] = defaultModel;                      /* start with default settings */
17398         
17399         modelParams[j].dataType = DataType (j);             /* data type for partition                      */
17400
17401         if (modelParams[j].dataType == STANDARD)
17402             {   /* set default ascertainment bias for partition */
17403             modelParams[j].coding = VARIABLE;
17404             strcpy(modelParams[j].codingString, "Variable"); 
17405             }
17406         else if (modelParams[j].dataType == RESTRICTION)
17407             {
17408             modelParams[j].coding = NOABSENCESITES;
17409             strcpy(modelParams[j].codingString, "Noabsencesites");   
17410             }
17411         else
17412             {
17413             modelParams[j].coding = ALL;
17414             strcpy(modelParams[j].codingString, "All");
17415             }
17416
17417         SetCode (j);
17418         modelParams[j].nStates = NumStates (j);             /* number of states for partition             */
17419
17420         modelParams[j].activeConstraints = (int *) SafeCalloc(numDefinedConstraints, sizeof(int));  /* allocate space for active constraints (yes/no) */
17421         }
17422
17423     return (NO_ERROR);
17424 }
17425
17426
17427 /*----------------------------------------------------------------------------
17428 |
17429 |   SetModelInfo: This function will set up model info using model
17430 |       params
17431 |
17432 -----------------------------------------------------------------------------*/
17433 int SetModelInfo (void)
17434 {
17435     int             i, j, chn, ts;
17436     ModelParams     *mp;
17437     ModelInfo       *m;
17438     
17439     /* wipe all model settings */
17440     inferSiteRates = NO;
17441     inferAncStates = NO;
17442     inferSiteOmegas = NO;
17443
17444     for (i=0; i<numCurrentDivisions; i++)
17445         {
17446         m = &modelSettings[i];
17447
17448         /* make certain that we set this intentionally to "NO" so we 
17449            calculate cijk information and calculate cond likes when needed */
17450         m->upDateCijk = YES;
17451         m->upDateCl = YES;
17452         m->upDateAll = YES;
17453
17454         /* make certain that we start with a parsimony branch length of zero */
17455         for (j=0; j<MAX_CHAINS; j++)
17456             m->parsTreeLength[j*2] = m->parsTreeLength[j*2+1] = 0.0;
17457
17458         m->tRatio = NULL;
17459         m->revMat = NULL;
17460         m->omega = NULL;
17461         m->stateFreq = NULL;
17462         m->shape = NULL;
17463         m->pInvar = NULL;
17464         m->correlation = NULL;
17465         m->switchRates = NULL;
17466         m->rateMult = NULL;
17467         m->topology = NULL;
17468         m->brlens = NULL;
17469         m->speciationRates = NULL;
17470         m->extinctionRates = NULL;
17471         m->fossilizationRates = NULL;
17472         m->popSize = NULL;
17473         m->aaModel = NULL;
17474         m->cppRate = NULL;
17475         m->cppEvents = NULL;
17476         m->cppMultDev = NULL;
17477         m->tk02var = NULL;
17478         m->tk02BranchRates = NULL;
17479         m->igrvar = NULL;
17480         m->igrBranchRates = NULL;
17481         m->mixedvar = NULL;
17482         m->mixedBrchRates = NULL;
17483         m->clockRate = NULL;
17484
17485         m->CondLikeDown = NULL;
17486         m->CondLikeRoot = NULL;
17487         m->CondLikeScaler = NULL;
17488         m->Likelihood = NULL;
17489         m->TiProbs = NULL;
17490
17491         m->CondLikeUp = NULL;
17492         m->StateCode = NULL;
17493         m->PrintAncStates = NULL;
17494         m->PrintSiteRates = NULL;
17495         
17496         m->printPosSel = NO;
17497         m->printAncStates = NO;
17498         m->printSiteRates = NO;
17499
17500         m->nStates = NULL;
17501         m->bsIndex = NULL;
17502         m->cType = NULL;
17503         m->tiIndex = NULL;
17504
17505         m->gibbsGamma = NO;
17506         m->gibbsFreq = 0;
17507
17508         m->parsimonyBasedMove = NO;
17509
17510 #   if defined (BEAGLE_ENABLED)
17511         m->beagleInstance = -1;               /* beagle instance                              */
17512         m->logLikelihoods = NULL;             /* array of log likelihoods from Beagle         */
17513         m->inRates = NULL;                    /* array of category rates for Beagle           */
17514         m->branchLengths = NULL;              /* array of branch lengths for Beagle           */
17515         m->tiProbIndices = NULL;              /* array of trans prob indices for Beagle       */
17516         m->inWeights = NULL;                  /* array of weights for Beagle root likelihood  */
17517         m->bufferIndices = NULL;              /* array of partial indices for root likelihood */
17518         m->childBufferIndices = NULL;         /* array of child partial indices (unrooted)    */
17519         m->childTiProbIndices = NULL;         /* array of child ti prob indices (unrooted)    */
17520         m->cumulativeScaleIndices = NULL;     /* array of cumulative scale indices            */
17521 #   endif
17522
17523         /* likelihood calculator flags */
17524         m->useSSE = NO;                       /* use SSE code for this partition?             */
17525         m->useBeagle = NO;                    /* use Beagle for this partition?               */
17526
17527         /* set all memory pointers to NULL */
17528         m->parsSets = NULL;
17529         m->numParsSets = 0;
17530         m->parsNodeLens = NULL;
17531         m->numParsNodeLens = 0;
17532
17533         m->condLikes = NULL;
17534         m->tiProbs = NULL;
17535         m->scalers = NULL;
17536         m->numCondLikes = 0;
17537         m->numTiProbs = 0;
17538         m->numScalers = 0;
17539
17540         m->condLikeIndex = NULL;
17541         m->condLikeScratchIndex = NULL;
17542         m->tiProbsIndex = NULL;
17543         m->tiProbsScratchIndex = NULL;
17544         m->nodeScalerIndex = NULL;
17545         m->nodeScalerScratchIndex = NULL;
17546         m->siteScalerIndex = NULL;
17547         m->siteScalerScratchIndex = -1;
17548
17549         m->cijks = NULL;
17550         m->nCijkParts = 0;
17551         m->cijkIndex = NULL;
17552         m->cijkScratchIndex = -1;
17553         }
17554
17555     /* set state of all chains to zero */
17556     for (chn=0; chn<numGlobalChains; chn++)
17557         state[chn] = 0;
17558
17559     /* fill in modelSettings info with some basic model characteristics */
17560     for (i=0; i<numCurrentDivisions; i++)
17561         {
17562         mp = &modelParams[i];
17563         m = &modelSettings[i];
17564         
17565         if (!strcmp(mp->nucModel,"Protein") && (mp->dataType == DNA || mp->dataType == RNA))
17566             m->dataType = PROTEIN;
17567         else
17568             m->dataType = mp->dataType;
17569
17570         /* nuc model structure */
17571         if (!strcmp(mp->nucModel, "4by4"))
17572             m->nucModelId = NUCMODEL_4BY4;
17573         else if (!strcmp(mp->nucModel, "Doublet"))
17574             m->nucModelId = NUCMODEL_DOUBLET;
17575         else if (!strcmp(mp->nucModel, "Protein"))
17576             m->nucModelId = NUCMODEL_AA;
17577         else /* if (!strcmp(mp->nucModelId, "Codon")) */
17578             m->nucModelId = NUCMODEL_CODON;
17579             
17580         /* model nst */
17581         if (!strcmp(mp->nst, "1"))
17582             m->nst = 1;
17583         else if (!strcmp(mp->nst, "2"))
17584             m->nst = 2;
17585         else if (!strcmp(mp->nst, "6"))
17586             m->nst = 6;
17587         else
17588             m->nst = NST_MIXED;
17589             
17590         /* We set the aa model here. We have two options. First, the model
17591            could be fixed, in which case mp->aaModel has been set. We then
17592            go ahead and also set the model settings. Second, the model
17593            could be mixed. In this case, the amino acid matrix is considered
17594            a parameter, and we will deal with it below. It doesn't hurt
17595            to set it here anyway (it will be overwritten later). */
17596         if (!strcmp(mp->aaModelPr, "Fixed"))
17597             {
17598             if (!strcmp(mp->aaModel, "Poisson"))
17599                 m->aaModelId = AAMODEL_POISSON;
17600             else if (!strcmp(mp->aaModel, "Equalin"))
17601                 m->aaModelId = AAMODEL_EQ;
17602             else if (!strcmp(mp->aaModel, "Jones"))
17603                 m->aaModelId = AAMODEL_JONES;
17604             else if (!strcmp(mp->aaModel, "Dayhoff"))
17605                 m->aaModelId = AAMODEL_DAY;
17606             else if (!strcmp(mp->aaModel, "Mtrev"))
17607                 m->aaModelId = AAMODEL_MTREV;
17608             else if (!strcmp(mp->aaModel, "Mtmam"))
17609                 m->aaModelId = AAMODEL_MTMAM;
17610             else if (!strcmp(mp->aaModel, "Wag"))
17611                 m->aaModelId = AAMODEL_WAG;
17612             else if (!strcmp(mp->aaModel, "Rtrev"))
17613                 m->aaModelId = AAMODEL_RTREV;
17614             else if (!strcmp(mp->aaModel, "Cprev"))
17615                 m->aaModelId = AAMODEL_CPREV;
17616             else if (!strcmp(mp->aaModel, "Vt"))
17617                 m->aaModelId = AAMODEL_VT;
17618             else if (!strcmp(mp->aaModel, "Blosum"))
17619                 m->aaModelId = AAMODEL_BLOSUM;
17620             else if (!strcmp(mp->aaModel, "LG"))
17621                 m->aaModelId = AAMODEL_LG;
17622             else if (!strcmp(mp->aaModel, "Gtr"))
17623                 m->aaModelId = AAMODEL_GTR;
17624             else
17625                 {
17626                 MrBayesPrint ("%s   Uncertain amino acid model\n", spacer);
17627                 return (ERROR);
17628                 }
17629             }
17630         else
17631             m->aaModelId = -1;
17632             
17633         /* parsimony model? */
17634         if (!strcmp(mp->parsModel, "Yes"))
17635             m->parsModelId = YES;
17636         else
17637             m->parsModelId = NO;
17638
17639         /* number of gamma categories */
17640         if (activeParams[P_SHAPE][i] > 0)
17641             m->numGammaCats = mp->numGammaCats;
17642         else
17643             m->numGammaCats = 1;
17644
17645         /* number of beta categories */
17646         if (mp->dataType == STANDARD && !(AreDoublesEqual(mp->symBetaFix, -1.0, 0.00001) == YES && !strcmp(mp->symPiPr,"Fixed")))
17647             m->numBetaCats = mp->numBetaCats;
17648         else
17649             m->numBetaCats = 1;
17650
17651         /* number of omega categories */
17652         if ((mp->dataType == DNA || mp->dataType == RNA) && (!strcmp(mp->omegaVar, "Ny98") || !strcmp(mp->omegaVar, "M3")) && !strcmp(mp->nucModel, "Codon"))
17653             {
17654             m->numOmegaCats = 3;
17655             m->numGammaCats = 1; /* if we are here, then we cannot have gamma or beta variation */
17656             m->numBetaCats = 1;
17657             }
17658         else if ((mp->dataType == DNA || mp->dataType == RNA) && !strcmp(mp->omegaVar, "M10") && !strcmp(mp->nucModel, "Codon"))
17659             {
17660             m->numOmegaCats = mp->numM10BetaCats + mp->numM10GammaCats;
17661             m->numGammaCats = 1; /* if we are here, then we cannot have gamma or beta variation */
17662             m->numBetaCats = 1;
17663             }
17664         else
17665             m->numOmegaCats = 1;
17666
17667         /* number of transition matrices depends on numGammaCats, numBetaCats, and numOmegaCats */
17668         m->numTiCats = m->numGammaCats * m->numBetaCats * m->numOmegaCats;
17669
17670         /* TODO: check that numStates and numModelStates are set
17671             appropriately for codon and doublet models */
17672
17673         /* number of observable states */
17674         if (m->dataType == STANDARD)
17675             m->numStates = 0;   /* zero, meaining variable */
17676         else if (!strcmp(mp->nucModel,"Protein") && (mp->dataType == DNA || mp->dataType == RNA))
17677             m->numStates = 20;
17678         else
17679             m->numStates = mp->nStates;
17680         
17681         /* number of model states including hidden ones */
17682         if ((mp->dataType == DNA || mp->dataType == RNA) && !strcmp (mp->covarionModel, "Yes") && !strcmp(mp->nucModel, "4by4"))
17683             m->numModelStates = mp->nStates * 2;
17684         else if (m->dataType == PROTEIN && !strcmp (mp->covarionModel, "Yes"))
17685             m->numModelStates = mp->nStates * 2;
17686         else if ((mp->dataType == DNA || mp->dataType == RNA) && !strcmp(mp->nucModel,"Protein") && !strcmp (mp->covarionModel, "Yes"))
17687             m->numModelStates = 20 * 2;
17688         else if (mp->dataType == CONTINUOUS)
17689             m->numModelStates = 0;
17690         else if (mp->dataType == STANDARD)
17691             {
17692             /* use max possible for now; we don't know what chars will be included */
17693             m->numModelStates = 10;
17694             }
17695         else
17696             m->numModelStates = m->numStates;
17697             
17698         /* Fill in some information for calculating cijk. We will use m->cijkLength to 
17699            figure out if we need to diagonalize Q to calculate transition probabilities.
17700            If cijkLength = 0, then we won't bother. We use cijkLength later in this function. */
17701         m->cijkLength = 0;
17702         m->nCijkParts = 1;
17703         if (m->dataType == PROTEIN)
17704             {
17705             ts = m->numModelStates;
17706             m->cijkLength = (ts * ts * ts) + (2 * ts);
17707             if (!strcmp (mp->covarionModel, "Yes"))
17708                 {
17709                 m->cijkLength *= m->numGammaCats;
17710                 m->nCijkParts = m->numGammaCats;
17711                 }
17712             }
17713         else if (m->dataType == STANDARD)
17714             {
17715             /* set to 0 for now, update in ProcessStdChars */
17716             m->nCijkParts = 0;
17717             }
17718         else if (m->dataType == DNA || m->dataType == RNA)
17719             {
17720             if (m->nucModelId == NUCMODEL_4BY4)
17721                 {
17722                 if (!strcmp (mp->covarionModel, "No") && m->nst != 6 && m->nst != 203)
17723                     m->cijkLength = 0;
17724                 else
17725                     {
17726                     ts = m->numModelStates;
17727                     m->cijkLength = (ts * ts * ts) + (2 * ts);
17728                     }
17729                 if (!strcmp (mp->covarionModel, "Yes"))
17730                     {
17731                     m->cijkLength *= m->numGammaCats;
17732                     m->nCijkParts = m->numGammaCats;
17733                     }
17734                 }
17735             else if (m->nucModelId == NUCMODEL_DOUBLET)
17736                 {
17737                 ts = m->numModelStates;
17738                 m->cijkLength = (ts * ts * ts) + (2 * ts);
17739                 }
17740             else if (m->nucModelId == NUCMODEL_CODON)
17741                 {
17742                 ts = m->numModelStates;
17743                 m->cijkLength = (ts * ts * ts) + (2 * ts);
17744                 m->cijkLength *= m->numOmegaCats;
17745                 m->nCijkParts = m->numOmegaCats;
17746                 }
17747             else
17748                 {
17749                 MrBayesPrint ("%s   BUG: Inconsistent model. Please report this as a bug.\n");
17750                 return ERROR;
17751                 }
17752             }
17753
17754         /* check if we should calculate ancestral states */
17755         if (!strcmp(mp->inferAncStates,"Yes"))
17756             {
17757             if (m->dataType == PROTEIN && !strcmp(mp->covarionModel, "No"))
17758                 m->printAncStates = YES;
17759             else if (m->dataType == DNA || m->dataType == RNA)
17760                 {
17761                 if (!strcmp(mp->nucModel,"4by4") && !strcmp(mp->covarionModel, "No"))
17762                     m->printAncStates = YES;
17763                 if (!strcmp(mp->nucModel,"Doublet"))
17764                     m->printAncStates = YES;
17765                 if (!strcmp(mp->nucModel,"Codon") && !strcmp(mp->omegaVar,"Equal"))
17766                     m->printAncStates = YES;
17767                 }
17768             else if (m->dataType == STANDARD || m->dataType == RESTRICTION)
17769                 m->printAncStates = YES;
17770             if (m->printAncStates == YES)
17771                 inferAncStates = YES;
17772             else
17773                 MrBayesPrint ("%s   Print out of ancestral states is not applicable for devision %d.\n",spacer,i);
17774             }
17775
17776         /* check if we should calculate site rates */
17777         if (!strcmp(mp->inferSiteRates,"Yes"))
17778             {
17779             if (m->numGammaCats > 1)
17780                 {
17781                 m->printSiteRates = YES;
17782                 inferSiteRates = YES;
17783                 }
17784             }
17785
17786         /* check if we should calculate positive selection */
17787         if (!strcmp(mp->inferPosSel, "Yes"))
17788             {
17789             if (m->numOmegaCats > 1)
17790                 {
17791                 m->printPosSel = YES;
17792                 inferPosSel = YES;
17793                 }
17794             }
17795
17796         /* check if we should calculate site omegas */
17797         if (!strcmp(mp->inferSiteOmegas, "Yes"))
17798             {
17799             if (m->numOmegaCats > 1)
17800                 {
17801                 m->printSiteOmegas = YES;
17802                 inferSiteOmegas = YES;
17803                 }
17804             }
17805         /* check if we should use gibbs sampling of gamma (don't use it with pinvar or invgamma) */
17806         if (!strcmp(mp->useGibbs,"Yes") && (m->numGammaCats > 1))
17807             {
17808             if (m->dataType == DNA || m->dataType == RNA || m->dataType == PROTEIN)
17809                 {
17810                 if (activeParams[P_CORREL][i] <= 0 && m->printSiteRates == NO && activeParams[P_PINVAR][i] <= 0)
17811                     {
17812                     m->gibbsGamma = YES;
17813                     m->gibbsFreq = mp->gibbsFreq;
17814                     }
17815                 }
17816             }
17817         }
17818
17819     return (NO_ERROR);  
17820 }
17821
17822
17823 /*-----------------------------------------------------------------
17824 |
17825 |   SetModelParams: Set up parameter structs for all model
17826 |       parameters, including trees
17827 |
17828 |----------------------------------------------------------------*/
17829 int SetModelParams (void)
17830 {
17831     int             c, i, j, k, n, n1, n2, *isPartTouched, numRelParts, nRelParts, areAllPartsParsimony,
17832                     nClockBrlens, nRelaxedBrlens, nCalibratedBrlens;
17833     char            tempCodon[15], tempMult[15], *tempStr,temp[30];
17834     char static     *partString=NULL; /* mad static to avoid posible memory leak on return ERROR if it would be introduced later */
17835     Param           *p;
17836     ModelParams     *mp;
17837     ModelInfo       *m;
17838     int             tempStrSize = 300;
17839
17840     tempStr = (char *) SafeMalloc((size_t)tempStrSize * sizeof(char));
17841     isPartTouched = (int *) SafeMalloc ((size_t)numCurrentDivisions * sizeof (int));
17842     if (!tempStr || !isPartTouched)
17843         {
17844         MrBayesPrint ("%s   Problem allocating tempString (%d) or isPartTouched (%d)\n", spacer,
17845             tempStrSize * sizeof(char), numCurrentDivisions * sizeof(int));
17846         return (ERROR);
17847         }
17848
17849 #   if defined DEBUG_SETCHAINPARAMS
17850     /* only for debugging */
17851     MrBFlt      lnPriorRatio = 0.0, lnProposalRatio = 0.0;
17852 #   endif
17853
17854     /* allocate space for parameters */
17855     if (memAllocs[ALLOC_PARAMS] == YES)
17856         {
17857         for (i=0; i<numParams; i++)
17858             {
17859             SafeFree ((void **)&params[i].name);
17860             if (params[i].paramHeader)
17861                 {
17862                 free (params[i].paramHeader);
17863                 params[i].paramHeader = NULL;
17864                 }
17865             }
17866         free (params);
17867         free (relevantParts);
17868         params = NULL;
17869         relevantParts = NULL;
17870         memAllocs[ALLOC_PARAMS] = NO;
17871         }
17872
17873     /* wipe all chain parameter information */
17874     numParams = 0;
17875     numTrees = 0;
17876     chainHasAdgamma = NO;
17877
17878     /* figure out number of parameters */
17879     /* this relies on activeParams[j][i] being set to 1, 2, ..., numParams */
17880     /* which is taken care of in SetUpLinkTable () */
17881     nRelParts = 0;
17882     for (j=0; j<NUM_LINKED; j++)
17883         {
17884         for (i=0; i<numCurrentDivisions; i++)
17885             {
17886             if (activeParams[j][i] > numParams)
17887                 numParams = activeParams[j][i];
17888             if (activeParams[j][i] > 0)
17889                 nRelParts++;
17890             }
17891         }
17892
17893     params = (Param *) SafeMalloc (numParams * sizeof(Param));
17894     relevantParts = (int *) SafeMalloc (nRelParts * sizeof(int));
17895     if (!params || !relevantParts)
17896         {
17897         MrBayesPrint ("%s   Problem allocating params and relevantParts\n", spacer);
17898         if (params)
17899             free (params);
17900         if (relevantParts)
17901             free (relevantParts);
17902         free (tempStr);
17903         return ERROR;
17904         }
17905     else
17906         memAllocs[ALLOC_PARAMS] = YES;
17907
17908     /* fill in info on each parameter */
17909     nRelParts = 0;  /* now cumulative number of relevant partitions */
17910     for (k=0; k<numParams; k++)
17911         {
17912         p = &params[k];
17913
17914         /* find affected partitions */
17915         numRelParts = 0;
17916         for (j=0; j<NUM_LINKED; j++)
17917             {
17918             for (i=0; i<numCurrentDivisions; i++)
17919                 {
17920                 if (activeParams[j][i] == k + 1)
17921                     {
17922                     numRelParts++;
17923                     isPartTouched[i] = YES;
17924                     }
17925                 else
17926                     isPartTouched[i] = NO;
17927                 }
17928             if (numRelParts > 0)
17929                 break;
17930             }
17931
17932         /* find pointer to modelParams and modelSettings of first relevant partition */
17933         /* this will be handy later on */
17934         for (i=0; i<numCurrentDivisions; i++)
17935             if (isPartTouched[i] == YES)
17936                 break;
17937         mp = &modelParams[i];
17938         m  = &modelSettings[i];
17939         
17940         /* Set default min and max */
17941         p->min = p->max = NEG_INFINITY;
17942
17943         /* Parameter nValues and nSubValues, which are needed for memory allocation
17944            are calculated for each case in the code below. nSympi, however, is
17945            only used for one special type of parameter and it therefore makes
17946            sense to initialize it to 0 here. The same applies to hasBinaryStd
17947            and nIntValues. To be safe, we set all to 0 here. */
17948         p->nValues = 0;
17949         p->nSubValues = 0;
17950         p->nIntValues = 0;
17951         p->nSympi = 0;
17952         p->hasBinaryStd = NO;
17953         
17954         /* should this parameter be printed to a file? */
17955         p->printParam = NO;
17956
17957         /* set print subparams to 0 */
17958         p->nPrintSubParams = 0;
17959         
17960         /* check constraints for tree parameter ? */
17961         p->checkConstraints = NO;
17962
17963         /* set index number of parameter */
17964         p->index = k;
17965         
17966         /* set prior function to NULL */
17967         p->LnPriorRatio = NULL;
17968
17969         /* set prior paramters to NULL */
17970         p->priorParams = NULL;
17971
17972         /* set affectsLikelihood to NO */
17973         p->affectsLikelihood = NO;
17974
17975         /* set cpp event pointers to NULL */
17976         p->nEvents = NULL;
17977         p->position = NULL;
17978         p->rateMult = NULL;
17979
17980         /* set header and name to NULL */
17981         p->paramHeader = NULL;
17982         p->name = NULL;
17983
17984         /* set up relevant partitions */
17985         p->nRelParts = numRelParts;
17986         p->relParts = relevantParts + nRelParts;
17987         nRelParts += numRelParts;
17988         for (i=n=0; i<numCurrentDivisions; i++)
17989             if (isPartTouched[i] == YES)
17990                 p->relParts[n++] = i;
17991
17992         /* get partition descriptor */
17993         SafeStrcat(&partString,"");
17994         FillRelPartsString (p, &partString);
17995             
17996         /* set up information for parameter */
17997         if (j == P_TRATIO)
17998             {
17999             /* Set up tratio ****************************************************************************************/
18000             p->paramType = P_TRATIO;
18001             p->nValues = 1;         /* we store only the ratio */
18002             p->nSubValues = 0;
18003             p->min = 0.0;
18004             p->max = POS_INFINITY;
18005             for (i=0; i<numCurrentDivisions; i++)
18006                 if (isPartTouched[i] == YES)
18007                     modelSettings[i].tRatio = p;
18008     
18009             p->paramTypeName = "Transition and transversion rates";
18010             SafeStrcat(&p->name, "Tratio");
18011             SafeStrcat(&p->name, partString);
18012
18013             /* find the parameter x prior type */
18014             if (!strcmp(mp->tRatioPr,"Beta"))
18015                 {
18016                 p->paramId = TRATIO_DIR;
18017                 }
18018             else
18019                 p->paramId = TRATIO_FIX;
18020                 
18021             if (p->paramId != TRATIO_FIX)
18022                 p->printParam = YES;
18023             if (!strcmp(mp->tratioFormat,"Ratio"))
18024                 {
18025                 /* report ti/tv ratio */
18026                 SafeStrcat (&p->paramHeader,"kappa");
18027                 SafeStrcat (&p->paramHeader, partString);
18028                 }
18029             else
18030                 {
18031                 /* report prop. of ratesum (Dirichlet) */
18032                 SafeStrcat (&p->paramHeader,"ti");
18033                 SafeStrcat (&p->paramHeader, partString);
18034                 SafeStrcat (&p->paramHeader, "\ttv");
18035                 SafeStrcat (&p->paramHeader, partString);
18036                 }
18037             }
18038         else if (j == P_REVMAT)
18039             {
18040             /* Set up revMat ****************************************************************************************/
18041             p->paramType = P_REVMAT;
18042             if (m->dataType == PROTEIN)
18043                 p->nValues = 190;
18044             else
18045                 p->nValues = 6;
18046             p->nSubValues = 0;
18047             if (!strcmp(mp->nst, "Mixed"))
18048                 p->nIntValues = 6;
18049             else
18050                 p->nIntValues = 0;
18051             p->min = 0.0;
18052             p->max = 1.0;       /* adjust later for REVMAT_MIX, see a few lines below */
18053             for (i=0; i<numCurrentDivisions; i++)
18054                 if (isPartTouched[i] == YES)
18055                     modelSettings[i].revMat = p;
18056
18057             p->paramTypeName = "Rates of reversible rate matrix";
18058             SafeStrcat(&p->name, "Revmat");
18059             SafeStrcat(&p->name, partString);
18060
18061             /* find the parameter x prior type */
18062             if (m->dataType == PROTEIN)
18063                 {
18064                 if (!strcmp(mp->aaRevMatPr,"Dirichlet"))
18065                     p->paramId = REVMAT_DIR;
18066                 else
18067                     p->paramId = REVMAT_FIX;
18068                 if (p->paramId != REVMAT_FIX)
18069                     p->printParam = YES;
18070
18071                 for (n1=0; n1<20; n1++)
18072                     {
18073                     for (n2=n1+1; n2<20; n2++)
18074                         {
18075                         if (n1==0 && n2==1)
18076                             {
18077                             sprintf (temp, "r(%c<->%c)", StateCode_AA(n1), StateCode_AA(n2));
18078                             SafeStrcat (&p->paramHeader, temp);
18079                             SafeStrcat (&p->paramHeader, partString);
18080                             }
18081                         else
18082                             {
18083                             sprintf (temp, "\tr(%c<->%c)", StateCode_AA(n1), StateCode_AA(n2));
18084                             SafeStrcat (&p->paramHeader, temp);
18085                             SafeStrcat (&p->paramHeader, partString);
18086                             }
18087                         }
18088                     }
18089                 }
18090             else
18091                 {
18092                 if (!strcmp(mp->nst, "Mixed"))
18093                     {
18094                     p->paramId = REVMAT_MIX;
18095                     p->max = 1E6;   /* some large value */
18096                     }
18097                 else if (!strcmp(mp->revMatPr,"Dirichlet"))
18098                     p->paramId = REVMAT_DIR;
18099                 else
18100                     p->paramId = REVMAT_FIX;
18101                 if (p->paramId != REVMAT_FIX)
18102                     p->printParam = YES;
18103
18104                 for (n1=0; n1<4; n1++)
18105                     {
18106                     for (n2=n1+1; n2<4; n2++)
18107                         {
18108                         if (n1==0 && n2==1)
18109                             {
18110                             sprintf (temp, "r(%c<->%c)", StateCode_NUC4(n1), StateCode_NUC4(n2));
18111                             SafeStrcat (&p->paramHeader, temp);
18112                             SafeStrcat (&p->paramHeader, partString);
18113                             }
18114                         else
18115                             {
18116                             sprintf (temp, "\tr(%c<->%c)", StateCode_NUC4(n1), StateCode_NUC4(n2));
18117                             SafeStrcat (&p->paramHeader, temp);
18118                             SafeStrcat (&p->paramHeader, partString);
18119                             }
18120                         }
18121                     }
18122                 if (p->paramId == REVMAT_MIX)
18123                     {
18124                     sprintf (temp, "\tgtrsubmodel");
18125                     SafeStrcat (&p->paramHeader, temp);
18126                     SafeStrcat (&p->paramHeader, partString);
18127                     sprintf (temp, "\tk_revmat");
18128                     SafeStrcat (&p->paramHeader, temp);
18129                     SafeStrcat (&p->paramHeader, partString);
18130                     }
18131                 }
18132             }
18133         else if (j == P_OMEGA)
18134             {
18135             /* Set up omega *****************************************************************************************/
18136             p->paramType = P_OMEGA;
18137             p->min = 0.0;
18138             p->max = POS_INFINITY;
18139             if (!strcmp(mp->omegaVar, "M3"))
18140                 {
18141                 p->nValues = 3;         /* omega values */
18142                 p->nSubValues = 6;      /* category frequencies plus cache */
18143                 for (i=0; i<numCurrentDivisions; i++)
18144                     if (isPartTouched[i] == YES)
18145                         modelSettings[i].omega = p;
18146             
18147                 /* find the parameter x prior type */
18148                 if (!strcmp(mp->m3omegapr, "Exponential")      && !strcmp(mp->codonCatFreqPr, "Fixed"))
18149                     p->paramId = OMEGA_EF;
18150                 else if (!strcmp(mp->m3omegapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18151                     p->paramId = OMEGA_ED;
18152                 else if (!strcmp(mp->m3omegapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18153                     p->paramId = OMEGA_FF;
18154                 else if (!strcmp(mp->m3omegapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18155                     p->paramId = OMEGA_FD;
18156
18157                 if (p->paramId != OMEGA_FF)
18158                     p->printParam = YES;
18159
18160                 SafeStrcat (&p->paramHeader, "omega(1)");
18161                 SafeStrcat (&p->paramHeader, partString);
18162                 SafeStrcat (&p->paramHeader, "\tomega(2)");
18163                 SafeStrcat (&p->paramHeader, partString);
18164                 SafeStrcat (&p->paramHeader, "\tomega(3)");
18165                 SafeStrcat (&p->paramHeader, partString);
18166                     
18167                 SafeStrcat (&p->paramHeader, "\tpi(1)");
18168                 SafeStrcat (&p->paramHeader, partString);
18169                 SafeStrcat (&p->paramHeader, "\tpi(2)");
18170                 SafeStrcat (&p->paramHeader, partString);
18171                 SafeStrcat (&p->paramHeader, "\tpi(3)");
18172                 SafeStrcat (&p->paramHeader, partString);
18173                 }
18174             else if (!strcmp(mp->omegaVar, "M10"))
18175                 {
18176                 p->nValues = mp->numM10BetaCats + mp->numM10GammaCats;
18177                 p->nSubValues = mp->numM10BetaCats + mp->numM10GammaCats + 8;
18178                 for (i=0; i<numCurrentDivisions; i++)
18179                     if (isPartTouched[i] == YES)
18180                         modelSettings[i].omega = p;
18181
18182                 /* find the parameter x prior type */
18183                 if      (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18184                     p->paramId = OMEGA_10UUB;
18185                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18186                     p->paramId = OMEGA_10UUF;
18187                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18188                     p->paramId = OMEGA_10UEB;
18189                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18190                     p->paramId = OMEGA_10UEF;
18191                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18192                     p->paramId = OMEGA_10UFB;
18193                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18194                     p->paramId = OMEGA_10UFF;
18195                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18196                     p->paramId = OMEGA_10EUB;
18197                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18198                     p->paramId = OMEGA_10EUF;
18199                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18200                     p->paramId = OMEGA_10EEB;
18201                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18202                     p->paramId = OMEGA_10EEF;
18203                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18204                     p->paramId = OMEGA_10EFB;
18205                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18206                     p->paramId = OMEGA_10EFF;
18207                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18208                     p->paramId = OMEGA_10FUB;
18209                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18210                     p->paramId = OMEGA_10FUF;
18211                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18212                     p->paramId = OMEGA_10FEB;
18213                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18214                     p->paramId = OMEGA_10FEF;
18215                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18216                     p->paramId = OMEGA_10FFB;
18217                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18218                     p->paramId = OMEGA_10FFF;
18219
18220                 if (p->paramId != OMEGA_10FFF)
18221                     p->printParam = YES;
18222                 for (i=0; i<p->nValues; i++)
18223                     {
18224                     if (i==0)
18225                         sprintf (temp, "omega(%d)", i+1);
18226                     else
18227                         sprintf (temp, "\tomega(%d)", i+1);
18228                     SafeStrcat (&p->paramHeader, temp);
18229                     SafeStrcat (&p->paramHeader, partString);
18230                     }
18231                 SafeStrcat (&p->paramHeader, "\tbeta(alpha)");
18232                 SafeStrcat (&p->paramHeader, partString);
18233                 SafeStrcat (&p->paramHeader, "\tbeta(beta)");
18234                 SafeStrcat (&p->paramHeader, partString);
18235                 SafeStrcat (&p->paramHeader, "\tgamma(alpha)");
18236                 SafeStrcat (&p->paramHeader, partString);
18237                 SafeStrcat (&p->paramHeader, "\tgamma(beta)");
18238                 SafeStrcat (&p->paramHeader, partString);
18239                 SafeStrcat (&p->paramHeader, "\tpi(1)");
18240                 SafeStrcat (&p->paramHeader, partString);
18241                 SafeStrcat (&p->paramHeader, "\tpi(2)");
18242                 SafeStrcat (&p->paramHeader, partString);
18243                 }
18244             else if (!strcmp(mp->omegaVar, "Ny98"))
18245                 {
18246                 p->nValues = 3;     /* omega values */
18247                 p->nSubValues = 6;  /* omega category frequencies plus cache */
18248                 for (i=0; i<numCurrentDivisions; i++)
18249                     if (isPartTouched[i] == YES)
18250                         modelSettings[i].omega = p;
18251             
18252                 /* find the parameter x prior type */
18253                 if      (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18254                     p->paramId = OMEGA_BUD;
18255                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18256                     p->paramId = OMEGA_BUF;
18257                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18258                     p->paramId = OMEGA_BED;
18259                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18260                     p->paramId = OMEGA_BEF;
18261                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18262                     p->paramId = OMEGA_BFD;
18263                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18264                     p->paramId = OMEGA_BFF;
18265                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18266                     p->paramId = OMEGA_FUD;
18267                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18268                     p->paramId = OMEGA_FUF;
18269                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18270                     p->paramId = OMEGA_FED;
18271                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18272                     p->paramId = OMEGA_FEF;
18273                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18274                     p->paramId = OMEGA_FFD;
18275                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18276                     p->paramId = OMEGA_FFF;
18277                 
18278                 if (p->paramId != OMEGA_FFF)
18279                     p->printParam = YES;
18280                 SafeStrcat (&p->paramHeader, "omega(-)");
18281                 SafeStrcat (&p->paramHeader, partString);
18282                 SafeStrcat (&p->paramHeader, "\tomega(N)");
18283                 SafeStrcat (&p->paramHeader, partString);
18284                 SafeStrcat (&p->paramHeader, "\tomega(+)");
18285                 SafeStrcat (&p->paramHeader, partString);
18286                     
18287                 SafeStrcat (&p->paramHeader, "\tpi(-)");
18288                 SafeStrcat (&p->paramHeader, partString);
18289                 SafeStrcat (&p->paramHeader, "\tpi(N)");
18290                 SafeStrcat (&p->paramHeader, partString);
18291                 SafeStrcat (&p->paramHeader, "\tpi(+)");
18292                 SafeStrcat (&p->paramHeader, partString);
18293                 }
18294             else
18295                 {
18296                 p->nValues = 1;
18297                 p->nSubValues = 0;
18298                 for (i=0; i<numCurrentDivisions; i++)
18299                     if (isPartTouched[i] == YES)
18300                         modelSettings[i].omega = p;
18301
18302                 /* find the parameter x prior type */
18303                 if (!strcmp(mp->omegaPr,"Dirichlet"))
18304                     p->paramId = OMEGA_DIR;
18305                 else
18306                     p->paramId = OMEGA_FIX;
18307
18308                 if (p->paramId != OMEGA_FIX)
18309                     p->printParam = YES;
18310                 SafeStrcat (&p->paramHeader, "omega");
18311                 SafeStrcat (&p->paramHeader, partString);
18312                 }
18313             p->paramTypeName = "Positive selection (omega) model";
18314             SafeStrcat(&p->name, "Omega");
18315             SafeStrcat(&p->name, partString);           
18316             }
18317         else if (j == P_PI)
18318             {
18319             /* Set up state frequencies *****************************************************************************/
18320             p->paramType = P_PI;
18321             p->min = 0.0;
18322             p->max = 1.0;
18323             for (i=0; i<numCurrentDivisions; i++)
18324                 if (isPartTouched[i] == YES)
18325                     modelSettings[i].stateFreq = p;
18326
18327             if (mp->dataType == STANDARD)
18328                 {
18329                 p->paramTypeName = "Symmetric diricihlet/beta distribution alpha_i parameter";
18330                 SafeStrcat(&p->name, "Alpha_symdir");
18331                 /* boundaries for alpha_i */
18332                 p->min = ETA;
18333                 p->max = POS_INFINITY;
18334                 }
18335             else
18336                 {
18337                 p->paramTypeName = "Stationary state frequencies";
18338                 SafeStrcat(&p->name, "Pi");
18339                 }
18340             SafeStrcat(&p->name, partString);
18341
18342             /* find the parameter x prior type */
18343             /* and the number of values and subvalues needed */
18344             if (mp->dataType == STANDARD)
18345                 {
18346                 /* find number of model states */
18347                 m->numModelStates = 2;
18348                 for (c=0; c<numChar; c++)
18349                     {
18350                     for (i=0; i<p->nRelParts; i++)
18351                         {
18352                         if (partitionId[c][partitionNum] == p->relParts[i] + 1 && charInfo[c].numStates > m->numModelStates)
18353                             m->numModelStates = charInfo[c].numStates;
18354                         }
18355                     }
18356                 for (i=0; i<p->nRelParts; i++)
18357                     modelSettings[p->relParts[i]].numModelStates = m->numModelStates;
18358
18359                 /* symmetric hyperprior with only one variable (0 if equal) */
18360                 p->nValues = 1;     /* set to 0 below for the SYMPI_EQUAL model */
18361                 if (!strcmp(mp->symPiPr,"Uniform"))
18362                     {
18363                     if (m->numModelStates > 2) 
18364                         p->paramId = SYMPI_UNI_MS;
18365                     else
18366                         p->paramId = SYMPI_UNI;
18367                     }
18368                 else if (!strcmp(mp->symPiPr,"Exponential"))
18369                     {
18370                     if (m->numModelStates > 2)
18371                         p->paramId = SYMPI_EXP_MS;
18372                     else
18373                         p->paramId = SYMPI_EXP;
18374                     }
18375                 else if (!strcmp(mp->symPiPr,"Fixed"))
18376                     {
18377                     if (AreDoublesEqual(mp->symBetaFix, -1.0, 0.00001) == YES)
18378                         {
18379                         p->paramId = SYMPI_EQUAL;
18380                         p->nValues = 0;
18381                         }
18382                     else
18383                         {
18384                         if (m->numModelStates > 2) 
18385                             p->paramId = SYMPI_FIX_MS;
18386                         else
18387                             p->paramId = SYMPI_FIX;
18388                         }
18389                     }
18390                 p->nSubValues = 0;  /* store state frequencies in p->stdStateFreqs */
18391                 if (p->paramId == SYMPI_EXP || p->paramId == SYMPI_EXP_MS || p->paramId == SYMPI_UNI || p->paramId == SYMPI_UNI_MS)
18392                     p->printParam = YES;
18393                 SafeStrcat (&p->paramHeader, "alpha_symdir");
18394                 SafeStrcat (&p->paramHeader, partString);
18395                 /* further processing done in ProcessStdChars */
18396                 }
18397             else
18398                 {
18399                 /* deal with all models except standard */
18400                 /* no hyperprior or fixed to one value, set default to 0  */
18401                 p->nValues = 0;
18402                 /* one subvalue for each state */
18403                 p->nSubValues = mp->nStates;    /* mp->nStates is set to 20 if DNA || RNA && nucmodel==PROTEIN */
18404                 if (!strcmp(mp->stateFreqPr, "Dirichlet"))
18405                     {
18406                     p->paramId = PI_DIR;
18407                     p->nValues = mp->nStates;
18408                     }
18409                 else if (!strcmp(mp->stateFreqPr, "Fixed") && !strcmp(mp->stateFreqsFixType,"User"))
18410                     p->paramId = PI_USER;
18411                 else if (!strcmp(mp->stateFreqPr, "Fixed") && !strcmp(mp->stateFreqsFixType,"Empirical"))
18412                     p->paramId = PI_EMPIRICAL;
18413                 else if (!strcmp(mp->stateFreqPr, "Fixed") && !strcmp(mp->stateFreqsFixType,"Equal"))
18414                     {
18415                     p->paramId = PI_EQUAL;
18416                     }
18417                     
18418                 if (m->dataType == PROTEIN)
18419                     {
18420                     if (!strcmp(mp->aaModelPr, "Fixed"))
18421                         {
18422                         if (!strcmp(mp->aaModel, "Poisson"))
18423                             p->paramId = PI_EQUAL;
18424                         else if (!strcmp(mp->aaModel, "Equalin") || !strcmp(mp->aaModel, "Gtr"))
18425                             {
18426                             /* p->paramId stays to what it was set to above */
18427                             }
18428                         else
18429                             p->paramId = PI_FIXED;
18430                         }
18431                     else
18432                         p->paramId = PI_FIXED;
18433                     }
18434                     
18435                 if (p->paramId == PI_DIR)
18436                     p->printParam = YES;
18437                 if (m->dataType == DNA || m->dataType == RNA)
18438                     {
18439                     if (!strcmp(mp->nucModel, "4by4"))
18440                         {
18441                         sprintf (temp, "pi(%c)", StateCode_NUC4(0));
18442                         SafeStrcat (&p->paramHeader,temp);
18443                         SafeStrcat (&p->paramHeader,partString);
18444                         for (n1=1; n1<4; n1++)
18445                             {
18446                             sprintf (temp, "\tpi(%c)", StateCode_NUC4(n1));
18447                             SafeStrcat (&p->paramHeader,temp);
18448                             SafeStrcat (&p->paramHeader,partString);
18449                             }
18450                         }
18451                     else if (!strcmp(mp->nucModel, "Doublet"))
18452                         {
18453                         State_DOUBLET(tempCodon,0);
18454                         sprintf (temp, "pi(%s)", tempCodon);
18455                         SafeStrcat (&p->paramHeader,temp);
18456                         SafeStrcat (&p->paramHeader,partString);
18457                         for (n1=1; n1<16; n1++)
18458                             {
18459                             State_DOUBLET(tempCodon,n1);
18460                             sprintf (temp, "\tpi(%s)", tempCodon);
18461                             SafeStrcat (&p->paramHeader,temp);
18462                             SafeStrcat (&p->paramHeader,partString);
18463                             }
18464                         }
18465                     else if (!strcmp(mp->nucModel, "Codon"))
18466                         {
18467                         for (c=0; c<p->nSubValues; c++)
18468                             {
18469                             if (mp->codonNucs[c][0] == 0)
18470                                 strcpy (tempCodon, "pi(A");
18471                             else if (mp->codonNucs[c][0] == 1)
18472                                 strcpy (tempCodon, "pi(C");
18473                             else if (mp->codonNucs[c][0] == 2)
18474                                 strcpy (tempCodon, "pi(G");
18475                             else
18476                                 strcpy (tempCodon, "pi(T");
18477                             if (mp->codonNucs[c][1] == 0)
18478                                 strcat (tempCodon, "A");
18479                             else if (mp->codonNucs[c][1] == 1)
18480                                 strcat (tempCodon, "C");
18481                             else if (mp->codonNucs[c][1] == 2)
18482                                 strcat (tempCodon, "G");
18483                             else
18484                                 strcat (tempCodon, "T");
18485                             if (mp->codonNucs[c][2] == 0)
18486                                 strcat (tempCodon, "A)");
18487                             else if (mp->codonNucs[c][2] == 1)
18488                                 strcat (tempCodon, "C)");
18489                             else if (mp->codonNucs[c][2] == 2)
18490                                 strcat (tempCodon, "G)");
18491                             else
18492                                 strcat (tempCodon, "T)");
18493                             if (c == 0)
18494                                 {
18495                                 SafeStrcat (&p->paramHeader, tempCodon);
18496                                 SafeStrcat (&p->paramHeader, partString);
18497                                 }
18498                             else
18499                                 {
18500                                 SafeStrcat (&p->paramHeader, "\t");
18501                                 SafeStrcat (&p->paramHeader, tempCodon);
18502                                 SafeStrcat (&p->paramHeader, partString);
18503                                 }
18504                             }
18505                         }
18506                     }
18507                 else if (m->dataType == PROTEIN)
18508                     {
18509                     if (FillRelPartsString (p, &partString) == YES)
18510                         {
18511                         SafeSprintf (&tempStr, &tempStrSize, "pi(Ala)%s\tpi(Arg)%s\tpi(Asn)%s\tpi(Asp)%s\tpi(Cys)%s\tpi(Gln)%s\tpi(Glu)%s\tpi(Gly)%s\tpi(His)%s\tpi(Ile)%s\tpi(Leu)%s\tpi(Lys)%s\tpi(Met)%s\tpi(Phe)%s\tpi(Pro)%s\tpi(Ser)%s\tpi(Thr)%s\tpi(Trp)%s\tpi(Tyr)%s\tpi(Val)%s",
18512                         partString, partString, partString, partString, partString, partString, partString, partString, partString, partString,
18513                         partString, partString, partString, partString, partString, partString, partString, partString, partString, partString);
18514                         SafeStrcat (&p->paramHeader, tempStr);
18515                         }
18516                     else
18517                         SafeStrcat (&p->paramHeader, "pi(Ala)\tpi(Arg)\tpi(Asn)\tpi(Asp)\tpi(Cys)\tpi(Gln)\tpi(Glu)\tpi(Gly)\tpi(His)\tpi(Ile)\tpi(Leu)\tpi(Lys)\tpi(Met)\tpi(Phe)\tpi(Pro)\tpi(Ser)\tpi(Thr)\tpi(Trp)\tpi(Tyr)\tpi(Val)");
18518                     }
18519                 else if (mp->dataType == RESTRICTION)
18520                     {
18521                     if (FillRelPartsString (p, &partString) == YES)
18522                         {
18523                         SafeSprintf (&tempStr, &tempStrSize, "pi(0)%s\tpi(1)%s", partString, partString);
18524                         SafeStrcat (&p->paramHeader, tempStr);
18525                         }
18526                     else
18527                         SafeStrcat (&p->paramHeader, "pi(0)\tpi(1)");
18528                     }
18529                 else
18530                     {
18531                     MrBayesPrint ("%s   Unknown data type in SetModelParams\n", spacer);
18532                     }
18533                 }
18534             }
18535         else if (j == P_SHAPE)
18536             {
18537             /* Set up shape parameter of gamma/lnorm *****************************************************************/
18538             p->paramType = P_SHAPE;
18539             p->nValues = 1;
18540             p->nSubValues = mp->numGammaCats;
18541             p->min = 1E-5;
18542             p->max = 100;
18543             for (i=0; i<numCurrentDivisions; i++)
18544                 if (isPartTouched[i] == YES)
18545                     modelSettings[i].shape = p;
18546             if(!strcmp(mp->ratesModel, "LNorm"))
18547                 {
18548                 p->paramTypeName = "SD of scaled lognormal distribution of site rates";
18549                 SafeStrcat(&p->name, "Sigma");
18550                 SafeStrcat (&p->paramHeader, "sigma");
18551                 }
18552             else
18553                 {
18554                 p->paramTypeName = "Shape of scaled gamma distribution of site rates";
18555                 SafeStrcat(&p->name, "Alpha");
18556                 SafeStrcat (&p->paramHeader, "alpha");
18557                 }
18558             SafeStrcat(&p->name, partString);
18559             SafeStrcat (&p->paramHeader, partString);
18560
18561             /* find the parameter x prior type */
18562             mp = &modelParams[p->relParts[0]];
18563             if (!strcmp(mp->shapePr,"Uniform"))
18564                 p->paramId = SHAPE_UNI;
18565             else if (!strcmp(mp->shapePr,"Exponential"))
18566                 p->paramId = SHAPE_EXP;
18567             else
18568                 p->paramId = SHAPE_FIX;
18569                 
18570             if (p->paramId != SHAPE_FIX)
18571                 p->printParam = YES;
18572             }
18573         else if (j == P_PINVAR)
18574             {
18575             /* Set up proportion of invariable sites ****************************************************************/
18576             p->paramType = P_PINVAR;
18577             p->nValues = 1;
18578             p->nSubValues = 0;
18579             p->min = 0.0;
18580             p->max = 1.0;
18581             for (i=0; i<numCurrentDivisions; i++)
18582                 if (isPartTouched[i] == YES)
18583                     modelSettings[i].pInvar = p;
18584
18585             p->paramTypeName = "Proportion of invariable sites";
18586             SafeStrcat(&p->name, "Pinvar");
18587             SafeStrcat(&p->name, partString);
18588
18589             /* find the parameter x prior type */
18590             if (!strcmp(mp->pInvarPr,"Uniform"))
18591                 p->paramId = PINVAR_UNI;
18592             else
18593                 p->paramId = PINVAR_FIX;
18594                 
18595             if (p->paramId != PINVAR_FIX)
18596                 p->printParam = YES;
18597             SafeStrcat (&p->paramHeader, "pinvar");
18598             SafeStrcat (&p->paramHeader, partString);
18599             }
18600         else if (j == P_CORREL)
18601             {
18602             /* Set up correlation parameter of adgamma model ********************************************************/
18603             p->paramType = P_CORREL;
18604             p->nValues = 1;
18605             p->nSubValues = mp->numGammaCats * mp->numGammaCats;
18606             p->min = -1.0;
18607             p->max = 1.0;
18608             for (i=0; i<numCurrentDivisions; i++)
18609                 if (isPartTouched[i] == YES)
18610                     modelSettings[i].correlation = p;
18611
18612             p->paramTypeName = "Autocorrelation of gamma distribution of site rates";
18613             SafeStrcat(&p->name, "Rho");
18614             SafeStrcat(&p->name, partString);
18615             chainHasAdgamma = YES;
18616
18617             /* find the parameter x prior type */
18618             if (!strcmp(mp->adGammaCorPr,"Uniform"))
18619                 p->paramId = CORREL_UNI;
18620             else
18621                 p->paramId = CORREL_FIX;
18622
18623             if (p->paramId != CORREL_FIX)
18624                 p->printParam = YES;
18625             SafeStrcat (&p->paramHeader, "rho");
18626             SafeStrcat (&p->paramHeader, partString);
18627             }
18628         else if (j == P_SWITCH)
18629             {
18630             /* Set up switchRates for covarion model ****************************************************************/
18631             p->paramType = P_SWITCH;
18632             p->nValues = 2;
18633             p->nSubValues = mp->numGammaCats * mp->numGammaCats;
18634             p->min = 0.0;
18635             p->max = POS_INFINITY;
18636             for (i=0; i<numCurrentDivisions; i++)
18637                 if (isPartTouched[i] == YES)
18638                     modelSettings[i].switchRates = p;
18639
18640             p->paramTypeName = "Switch rates of covarion model";
18641             SafeStrcat(&p->name, "s_cov");
18642             SafeStrcat(&p->name, partString);
18643
18644             /* find the parameter x prior type */
18645             if (!strcmp(mp->covSwitchPr,"Uniform"))
18646                 p->paramId = SWITCH_UNI;
18647             else if (!strcmp(mp->covSwitchPr,"Exponential"))
18648                 p->paramId = SWITCH_EXP;
18649             else
18650                 p->paramId = SWITCH_FIX;
18651                 
18652             if (p->paramId != SWITCH_FIX)
18653                 p->printParam = YES;
18654
18655             SafeStrcat (&p->paramHeader, "s(off->on)");
18656             SafeStrcat (&p->paramHeader, partString);
18657             SafeStrcat (&p->paramHeader, "\ts(on->off)");
18658             SafeStrcat (&p->paramHeader, partString);
18659             }
18660         else if (j == P_RATEMULT)
18661             {
18662             /* Set up rateMult for partition specific rates ***********************************************************/
18663             p->paramType = P_RATEMULT;
18664             if (!strcmp(mp->ratePr,"Fixed"))
18665                 {
18666                 p->nValues = 1;
18667                 p->nSubValues = 0;
18668                 }
18669             else
18670                 {
18671                 p->nValues = p->nRelParts = numRelParts; /* keep scaled division rates in value                        */
18672                 p->nSubValues = p->nValues * 2;          /* keep number of uncompressed chars for scaling in subValue  */
18673                 }                                        /* also keep Dirichlet prior parameters here                  */
18674             p->min = POS_MIN;
18675             p->max = POS_INFINITY;
18676             for (i=0; i<numCurrentDivisions; i++)
18677                 if (isPartTouched[i] == YES)
18678                     modelSettings[i].rateMult = p;
18679
18680             p->paramTypeName = "Partition-specific rate multiplier";
18681             SafeStrcat(&p->name, "Ratemultiplier");
18682             SafeStrcat(&p->name, partString);
18683
18684             /* find the parameter x prior type */
18685             if (p->nSubValues == 0)
18686                 p->paramId = RATEMULT_FIX;
18687             else
18688                 p->paramId = RATEMULT_DIR;
18689
18690             if (p->paramId != RATEMULT_FIX)
18691                 p->printParam = YES;
18692             for (i=0; i<numCurrentDivisions; i++)
18693                 {
18694                 if (isPartTouched[i] == YES)
18695                     {
18696                     sprintf (tempMult, "m{%d}", i+1);
18697                     if (i == 0)
18698                         SafeStrcat (&p->paramHeader, tempMult);
18699                     else
18700                         {
18701                         SafeStrcat (&p->paramHeader, "\t");
18702                         SafeStrcat (&p->paramHeader, tempMult);
18703                         }
18704                     }
18705                 }
18706             }
18707         else if (j == P_GENETREERATE)
18708             {
18709             /* Set up rateMult for gene specific rates ****************************************************************/
18710             p->paramType = P_GENETREERATE;
18711             p->nValues = p->nRelParts = numRelParts;    /* keep scaled division rates in value                        */
18712             p->nSubValues = p->nValues * 2;             /* keep number of uncompressed chars for scaling in subValue  */
18713                                                         /* also keep Dirichlet prior parameters here                  */
18714             p->min = POS_MIN;
18715             p->max = POS_INFINITY;
18716             for (i=0; i<numCurrentDivisions; i++)
18717                 if (isPartTouched[i] == YES)
18718                     modelSettings[i].geneTreeRateMult = p;
18719
18720             p->paramTypeName = "Gene-specific rate multiplier";
18721             SafeStrcat(&p->name, "Generatemult");
18722             SafeStrcat(&p->name, partString);
18723
18724             /* find the parameter x prior type */
18725             if (strcmp(mp->generatePr,"Fixed") == 0)
18726                 p->paramId = GENETREERATEMULT_FIX;
18727             else
18728                 p->paramId = GENETREERATEMULT_DIR;
18729
18730             if (p->paramId == GENETREERATEMULT_FIX)
18731                 p->printParam = NO;
18732             else
18733                 p->printParam = YES;
18734
18735             for (i=0; i<numCurrentDivisions; i++)
18736                 {
18737                 if (isPartTouched[i] == YES)
18738                     {
18739                     sprintf (tempMult, "g_m{%d}", i+1);
18740                     if (i == 0)
18741                         SafeStrcat (&p->paramHeader, tempMult);
18742                     else
18743                         {
18744                         SafeStrcat (&p->paramHeader, "\t");
18745                         SafeStrcat (&p->paramHeader, tempMult);
18746                         }
18747                     }
18748                 }
18749             }
18750         else if (j == P_TOPOLOGY)
18751             {
18752             /* Set up topology **************************************************************************************/
18753             p->paramType = P_TOPOLOGY;
18754             p->nValues = 0;
18755             p->nSubValues = 0;
18756             p->min = NEG_INFINITY;  /* NA */
18757             p->max = NEG_INFINITY;  /* NA */
18758             for (i=0; i<numCurrentDivisions; i++)
18759                 if (isPartTouched[i] == YES)
18760                     modelSettings[i].topology = p;
18761
18762             p->paramTypeName = "Topology";
18763             SafeStrcat(&p->name, "Tau");
18764             SafeStrcat(&p->name, partString);
18765                     
18766             /* check that the model is not parsimony for all of the relevant partitions */
18767             areAllPartsParsimony = YES;
18768             for (i=0; i<p->nRelParts; i++)
18769                 {
18770                 if (modelSettings[p->relParts[i]].parsModelId == NO)
18771                     areAllPartsParsimony = NO;
18772                 }
18773
18774             /* check if topology is clock or nonclock */
18775             nClockBrlens = 0;
18776             nCalibratedBrlens = 0;
18777             nRelaxedBrlens = 0;
18778             if (areAllPartsParsimony == NO)
18779                 {
18780                 for (i=0; i<p->nRelParts; i++)
18781                     {
18782                     if (!strcmp(modelParams[p->relParts[i]].brlensPr, "Clock"))
18783                         {
18784                         nClockBrlens++;
18785                         if (strcmp(modelParams[p->relParts[i]].clockVarPr,"Strict") != 0)  /* not strict */
18786                             nRelaxedBrlens++;
18787                         if (!strcmp(modelParams[p->relParts[i]].nodeAgePr,"Calibrated"))
18788                             nCalibratedBrlens++;
18789                         }
18790                     }
18791                 }
18792             
18793             /* now find the parameter x prior type */
18794             if (areAllPartsParsimony == YES)
18795                 {
18796                 if (!strcmp(mp->topologyPr, "Uniform"))
18797                     p->paramId = TOPOLOGY_PARSIMONY_UNIFORM;
18798                 else if (!strcmp(mp->topologyPr,"Constraints"))
18799                     p->paramId = TOPOLOGY_PARSIMONY_CONSTRAINED;
18800                 else
18801                     p->paramId = TOPOLOGY_PARSIMONY_FIXED;
18802                 /* For this case, we also need to set the brlens ptr of the relevant partitions
18803                    so that it points to the topology parameter, since the rest of the
18804                    program will try to access the tree through this pointer. In FillTreeParams,
18805                    we will make sure that a pure parsimony topology parameter contains a pointer
18806                    to the relevant tree (like a brlens parameter would normally) */
18807                 for (i=0; i<p->nRelParts; i++)
18808                     modelSettings[p->relParts[i]].brlens = p;
18809                 }
18810             else
18811                 {
18812                 /* we assume for now that there is only one branch length; we will correct this
18813                    later in AllocateTreeParams if there are more than one set of branch lengths,
18814                    which is only possible for non-clock trees */
18815                 if (!strcmp(mp->topologyPr, "Speciestree"))
18816                     p->paramId = TOPOLOGY_SPECIESTREE;
18817                 else if (!strcmp(mp->topologyPr, "Uniform") && nClockBrlens == 0)
18818                     p->paramId = TOPOLOGY_NCL_UNIFORM_HOMO;
18819                 else if (!strcmp(mp->topologyPr,"Constraints") && nClockBrlens == 0)
18820                     p->paramId = TOPOLOGY_NCL_CONSTRAINED_HOMO;
18821                 else if (!strcmp(mp->topologyPr,"Fixed") && nClockBrlens == 0)
18822                     p->paramId = TOPOLOGY_NCL_FIXED_HOMO;
18823                 /* all below have clock branch lengths */
18824                 else if (!strcmp(mp->topologyPr, "Uniform") && nRelaxedBrlens == 0)
18825                     {
18826                     if (nCalibratedBrlens >= 1)
18827                         p->paramId = TOPOLOGY_CCL_UNIFORM;
18828                     else
18829                         p->paramId = TOPOLOGY_CL_UNIFORM;
18830                     }
18831                 else if (!strcmp(mp->topologyPr,"Constraints") && nRelaxedBrlens == 0)
18832                     {
18833                     if (nCalibratedBrlens >= 1)
18834                         p->paramId = TOPOLOGY_CCL_CONSTRAINED;
18835                     else
18836                         p->paramId = TOPOLOGY_CL_CONSTRAINED;
18837                     }
18838                 else if (!strcmp(mp->topologyPr,"Fixed") && nRelaxedBrlens == 0)
18839                     {
18840                     if (nCalibratedBrlens >= 1)
18841                         p->paramId = TOPOLOGY_CCL_FIXED;
18842                     else
18843                         p->paramId = TOPOLOGY_CL_FIXED;
18844                     }
18845                 /* all below have relaxed clock branch lengths */
18846                 else if (!strcmp(mp->topologyPr, "Uniform"))
18847                     {
18848                     if (nCalibratedBrlens >= 1)
18849                         p->paramId = TOPOLOGY_RCCL_UNIFORM;
18850                     else
18851                         p->paramId = TOPOLOGY_RCL_UNIFORM;
18852                     }
18853                 else if (!strcmp(mp->topologyPr,"Constraints"))
18854                     {
18855                     if (nCalibratedBrlens >= 1)
18856                         p->paramId = TOPOLOGY_RCCL_CONSTRAINED;
18857                     else
18858                         p->paramId = TOPOLOGY_RCL_CONSTRAINED;
18859                     }
18860                 else if (!strcmp(mp->topologyPr,"Fixed"))
18861                     {
18862                     if (nCalibratedBrlens >= 1)
18863                         p->paramId = TOPOLOGY_RCCL_FIXED;
18864                     else
18865                         p->paramId = TOPOLOGY_RCL_FIXED;
18866                     }
18867                 }
18868
18869             /* should we print the topology? */
18870             for (i=0; i<p->nRelParts; i++)
18871                 if (strcmp(modelParams[p->relParts[i]].treeFormat,"Topology") != 0)
18872                     break;
18873             if (i == p->nRelParts)
18874                 p->printParam = YES;
18875             else
18876                 p->printParam = NO;
18877             /* but always print parsimony topology */
18878             if (areAllPartsParsimony == YES)
18879                 p->printParam = YES;
18880             /* and never print fixed topologies */
18881             if (p->paramId == TOPOLOGY_RCL_FIXED ||
18882                 p->paramId == TOPOLOGY_RCCL_FIXED ||
18883                 p->paramId == TOPOLOGY_CL_FIXED ||
18884                 p->paramId == TOPOLOGY_CCL_FIXED ||
18885                 p->paramId == TOPOLOGY_NCL_FIXED ||
18886                 p->paramId == TOPOLOGY_PARSIMONY_FIXED)
18887                 p->printParam = NO;
18888             }
18889         else if (j == P_BRLENS)
18890             {
18891             /* Set up branch lengths ********************************************************************************/
18892             p->paramType = P_BRLENS;
18893             p->nValues = 0;
18894             p->nSubValues = 0;
18895             p->min = 0.0;
18896             p->max = POS_INFINITY;
18897             for (i=0; i<numCurrentDivisions; i++)
18898                 if (isPartTouched[i] == YES)
18899                     modelSettings[i].brlens = p;
18900
18901             p->paramTypeName = "Branch lengths";
18902             SafeStrcat(&p->name, "V");
18903             SafeStrcat(&p->name, partString);
18904
18905             /* find the parameter x prior type */
18906             if (modelSettings[p->relParts[0]].parsModelId == YES)
18907                 p->paramId = BRLENS_PARSIMONY;
18908             else
18909                 {
18910                 if (!strcmp(mp->brlensPr, "Clock"))
18911                     {
18912                     if (!strcmp(mp->clockPr,"Uniform"))
18913                         p->paramId = BRLENS_CLOCK_UNI;
18914                     else if (!strcmp(mp->clockPr,"Coalescence"))
18915                         p->paramId = BRLENS_CLOCK_COAL;
18916                     else if (!strcmp(mp->clockPr,"Birthdeath"))
18917                         p->paramId = BRLENS_CLOCK_BD;
18918                     else if (!strcmp(mp->clockPr,"Speciestreecoalescence"))
18919                         p->paramId = BRLENS_CLOCK_SPCOAL;
18920                     else if (!strcmp(mp->clockPr,"Fossilization"))
18921                         p->paramId = BRLENS_CLOCK_FOSSIL;
18922                     else if (!strcmp(mp->clockPr,"Fixed"))
18923                         p->paramId = BRLENS_CLOCK_FIXED;
18924                     }
18925                 else if (!strcmp(mp->brlensPr, "Unconstrained"))
18926                     {
18927                     if (!strcmp(mp->unconstrainedPr,"Uniform"))
18928                         p->paramId = BRLENS_UNI;
18929                     else if (!strcmp(mp->unconstrainedPr,"Exponential"))
18930                         p->paramId = BRLENS_EXP;
18931                     else if (!strcmp(mp->unconstrainedPr,"GammaDir"))
18932                         p->paramId = BRLENS_GamDir;
18933                     else if (!strcmp(mp->unconstrainedPr,"invGamDir"))
18934                         p->paramId = BRLENS_iGmDir;
18935                     else if (!strcmp(mp->unconstrainedPr,"twoExp"))
18936                         p->paramId = BRLENS_twoExp;
18937                     }
18938                 else if (!strcmp(mp->brlensPr,"Fixed"))
18939                     {
18940                     p->paramId = BRLENS_FIXED;
18941                     }
18942                 }
18943
18944             /* should we print the branch lengths? */
18945             for (i=0; i<p->nRelParts; i++)
18946                 if (strcmp(modelParams[p->relParts[i]].treeFormat,"Topology") != 0)
18947                     break;
18948             if (i < p->nRelParts)
18949                 p->printParam = YES;
18950             else
18951                 p->printParam = NO;
18952             }
18953         else if (j == P_SPECIESTREE)
18954             {
18955             /* Set up species tree **************************************************************************************/
18956             p->paramType = P_SPECIESTREE;
18957             p->nValues = 0;
18958             p->nSubValues = 0;
18959             p->min = NEG_INFINITY;  /* NA */
18960             p->max = NEG_INFINITY;  /* NA */
18961             for (i=0; i<numCurrentDivisions; i++)
18962                 if (isPartTouched[i] == YES)
18963                     modelSettings[i].speciesTree = p;
18964
18965             p->paramTypeName = "Species tree";
18966             SafeStrcat(&p->name, "Spt");
18967             SafeStrcat(&p->name, partString);
18968                     
18969             /* check that the model is not parsimony for all of the relevant partitions */
18970             areAllPartsParsimony = YES;
18971             for (i=0; i<p->nRelParts; i++)
18972                 {
18973                 if (modelSettings[p->relParts[i]].parsModelId == NO)
18974                     areAllPartsParsimony = NO;
18975                 }
18976             
18977             /* find the parameter x prior type */
18978             p->paramId = SPECIESTREE_UNIFORM;
18979
18980             /* should we print the tree? */
18981             p->printParam = YES;
18982             }
18983         else if (j == P_SPECRATE)
18984             {
18985             /* Set up speciation rate ******************************************************************************/
18986             p->paramType = P_SPECRATE;
18987             if (!strcmp(mp->clockPr,"Fossilization"))
18988                 p->nValues = mp->sampleFSNum +1;  // rate in each time interval
18989             else
18990                 p->nValues = 1;
18991             p->nSubValues = 0;
18992             p->min = POS_MIN;
18993             p->max = POS_INFINITY;
18994             for (i=0; i<numCurrentDivisions; i++)
18995                 if (isPartTouched[i] == YES)
18996                     modelSettings[i].speciationRates = p;
18997
18998             p->paramTypeName = "Speciation rate";
18999             SafeStrcat(&p->name, "Net_speciation");
19000             SafeStrcat(&p->name, partString);
19001
19002             /* find the parameter x prior type */
19003             if (!strcmp(mp->speciationPr,"Uniform"))
19004                 p->paramId = SPECRATE_UNI;
19005             else if (!strcmp(mp->speciationPr,"Exponential"))
19006                 p->paramId = SPECRATE_EXP;
19007             else
19008                 p->paramId = SPECRATE_FIX;
19009
19010             if (p->paramId != SPECRATE_FIX)
19011                 p->printParam = YES;
19012                 
19013             if (p->nValues == 1)
19014                 {
19015                 SafeStrcat (&p->paramHeader, "net_speciation");
19016                 SafeStrcat (&p->paramHeader, partString);
19017                 }
19018             else for (i = 0; i < p->nValues; i++)
19019                 {
19020                 sprintf (tempStr, "\tnet_speciation_%d", i+1);
19021                 SafeStrcat (&p->paramHeader, tempStr);
19022                 SafeStrcat (&p->paramHeader, partString);
19023                 }
19024             }
19025         else if (j == P_EXTRATE)
19026             {
19027             /* Set up extinction rates ******************************************************************************/
19028             p->paramType = P_EXTRATE;
19029             if (!strcmp(mp->clockPr,"Fossilization"))
19030                 p->nValues = mp->sampleFSNum +1;  // rate in each time interval
19031             else
19032                 p->nValues = 1;
19033             p->nSubValues = 0;
19034             p->min = 0.0;
19035             p->max = 1.0;
19036             for (i=0; i<numCurrentDivisions; i++)
19037                 if (isPartTouched[i] == YES)
19038                     modelSettings[i].extinctionRates = p;
19039
19040             p->paramTypeName = "Extinction rate";
19041             SafeStrcat(&p->name, "Relative_extinction");
19042             SafeStrcat(&p->name, partString);
19043
19044             /* find the parameter x prior type */
19045             if (!strcmp(mp->extinctionPr,"Beta"))
19046                 p->paramId = EXTRATE_BETA;
19047             else
19048                 p->paramId = EXTRATE_FIX;
19049
19050             if (p->paramId != EXTRATE_FIX)
19051                 p->printParam = YES;
19052                 
19053             if (p->nValues == 1)
19054                 {
19055                 SafeStrcat (&p->paramHeader, "relative_extinction");
19056                 SafeStrcat (&p->paramHeader, partString);
19057                 }
19058             else for (i = 0; i < p->nValues; i++)
19059                 {
19060                 sprintf (tempStr, "\trelative_extinction_%d", i+1);
19061                 SafeStrcat (&p->paramHeader, tempStr);
19062                 SafeStrcat (&p->paramHeader, partString);
19063                 }
19064             }
19065         else if (j == P_FOSLRATE)
19066             {
19067             /* Set up fossilization rates */
19068             p->paramType = P_FOSLRATE;
19069             p->nValues = mp->sampleFSNum +1;  // rate in each time interval
19070             p->nSubValues = 0;
19071             p->min = 0.0;
19072             p->max = 1.0;
19073             for (i=0; i<numCurrentDivisions; i++)
19074                 if (isPartTouched[i] == YES)
19075                     modelSettings[i].fossilizationRates = p;
19076             
19077             p->paramTypeName = "Fossilization rate";
19078             SafeStrcat(&p->name, "Relative_fossilization");
19079             SafeStrcat(&p->name, partString);
19080             
19081             /* find the parameter x prior type */
19082             if (!strcmp(mp->fossilizationPr,"Beta"))
19083                 p->paramId = FOSLRATE_BETA;
19084             else
19085                 p->paramId = FOSLRATE_FIX;
19086             
19087             if (p->paramId != FOSLRATE_FIX)
19088                 p->printParam = YES;
19089             
19090             if (p->nValues == 1)
19091                 {
19092                 SafeStrcat (&p->paramHeader, "relative_fossilization");
19093                 SafeStrcat (&p->paramHeader, partString);
19094                 }
19095             else for (i = 0; i < p->nValues; i++)
19096                 {
19097                 sprintf (tempStr, "\trelative_fossilization_%d", i+1);
19098                 SafeStrcat (&p->paramHeader, tempStr);
19099                 SafeStrcat (&p->paramHeader, partString);
19100                 }
19101             }
19102         else if (j == P_POPSIZE)
19103             {
19104             /* Set up population size *****************************************************************************************/
19105             p->paramType = P_POPSIZE;
19106             if (!strcmp(mp->topologyPr,"Speciestree") && !strcmp(mp->popVarPr, "Variable"))
19107                 p->nValues = 2 * numSpecies;
19108             else
19109                 p->nValues = 1;
19110             p->nSubValues = 0;
19111             p->min = POS_MIN;
19112             p->max = POS_INFINITY;
19113             for (i=0; i<numCurrentDivisions; i++)
19114                 if (isPartTouched[i] == YES)
19115                     modelSettings[i].popSize = p;
19116
19117             p->paramTypeName = "Coalescent process population size parameter";
19118             SafeStrcat(&p->name, "Popsize");
19119             SafeStrcat(&p->name, partString);
19120
19121             /* find the parameter x prior type */
19122             if (!strcmp(mp->popSizePr,"Uniform"))
19123                 {
19124                 p->paramId      = POPSIZE_UNI;
19125                 p->LnPriorRatio = &LnProbRatioUniform;
19126                 p->priorParams  = mp->popSizeUni;
19127                 p->LnPriorProb  = &LnPriorProbUniform;
19128                 }
19129             else if (!strcmp(mp->popSizePr,"Normal"))
19130                 {
19131                 p->paramId      = POPSIZE_NORMAL;
19132                 p->LnPriorRatio = &LnProbRatioTruncatedNormal;
19133                 p->priorParams  = mp->popSizeNormal;
19134                 p->LnPriorProb  = &LnPriorProbTruncatedNormal;
19135                 }
19136             else if (!strcmp(mp->popSizePr,"Lognormal"))
19137                 {
19138                 p->paramId      = POPSIZE_LOGNORMAL;
19139                 p->LnPriorRatio = &LnProbRatioLognormal;
19140                 p->priorParams  = mp->popSizeLognormal;
19141                 p->LnPriorProb  = &LnPriorProbLognormal;
19142                 }
19143             else if (!strcmp(mp->popSizePr,"Gamma"))
19144                 {
19145                 p->paramId      = POPSIZE_GAMMA;
19146                 p->LnPriorRatio = &LnProbRatioGamma;
19147                 p->priorParams  = mp->popSizeGamma;
19148                 p->LnPriorProb  = &LnPriorProbGamma;
19149                 }
19150             else
19151                 {
19152                 p->paramId      = POPSIZE_FIX;
19153                 p->LnPriorRatio = NULL;
19154                 p->priorParams  = &mp->popSizeFix;
19155                 p->LnPriorProb  = &LnPriorProbFix;
19156                 }
19157
19158             if (p->paramId != POPSIZE_FIX && p->nValues == 1)
19159                 p->printParam = YES;
19160             SafeStrcat (&p->paramHeader, "popsize");
19161             SafeStrcat (&p->paramHeader, partString);
19162             }
19163         else if (j == P_GROWTH)
19164             {
19165             /* Set up growth rate ************************************************************************************/
19166             p->paramType = P_GROWTH;
19167             p->nValues = 1;
19168             p->nSubValues = 0;
19169             p->min = 0.0;
19170             p->max = POS_INFINITY;
19171             for (i=0; i<numCurrentDivisions; i++)
19172                 if (isPartTouched[i] == YES)
19173                     modelSettings[i].growthRate = p;
19174
19175             p->paramTypeName = "Population growth rate";
19176             SafeStrcat(&p->name, "R_pop");
19177             SafeStrcat(&p->name, partString);
19178
19179             /* find the parameter x prior type */
19180             if (!strcmp(mp->growthPr,"Uniform"))
19181                 {
19182                 p->paramId = GROWTH_UNI;
19183                 p->priorParams = mp->growthUni;
19184                 p->min = mp->growthUni[0];
19185                 p->max = mp->growthUni[1];
19186                 p->LnPriorRatio = &LnProbRatioUniform;
19187                 p->LnPriorProb = &LnPriorProbUniform;
19188                 }
19189             else if (!strcmp(mp->growthPr,"Exponential"))
19190                 {
19191                 p->paramId = GROWTH_EXP;
19192                 p->priorParams = &mp->growthExp;
19193                 p->min = GROWTH_MIN;
19194                 p->max = GROWTH_MAX;
19195                 p->LnPriorRatio = &LnProbRatioExponential;
19196                 p->LnPriorProb = &LnPriorProbExponential;
19197                 }
19198             else if (!strcmp(mp->growthPr,"Normal"))
19199                 {
19200                 p->paramId = GROWTH_NORMAL;
19201                 p->priorParams = mp->growthNorm;
19202                 p->min = GROWTH_MIN;
19203                 p->max = GROWTH_MAX;
19204                 p->LnPriorRatio = &LnProbRatioTruncatedNormal;
19205                 p->LnPriorProb = &LnPriorProbTruncatedNormal;
19206                 }
19207             else
19208                 p->paramId = GROWTH_FIX;
19209                 {
19210                 p->paramId = GROWTH_FIX;
19211                 p->priorParams = &mp->growthFix;
19212                 p->min = p->max = mp->growthFix;
19213                 p->LnPriorRatio = &LnProbRatioFix;
19214                 p->LnPriorProb = &LnPriorProbFix;
19215                 }
19216
19217             if (p->paramId != GROWTH_FIX)
19218                 p->printParam = YES;
19219             SafeStrcat (&p->paramHeader, "growthRate");
19220             SafeStrcat (&p->paramHeader, partString);
19221             }
19222         else if (j == P_AAMODEL)
19223             {
19224             /* Set up aamodel *****************************************************************************************/
19225             p->paramType = P_AAMODEL;
19226             p->nValues = 1;
19227             p->nSubValues = 10;
19228             p->min = 0;
19229             p->max = 9;
19230             for (i=0; i<numCurrentDivisions; i++)
19231                 if (isPartTouched[i] == YES)
19232                     modelSettings[i].aaModel = p;
19233
19234             p->paramTypeName = "Aminoacid model";
19235             SafeStrcat(&p->name, "Aamodel");
19236             SafeStrcat(&p->name, partString);
19237
19238             /* find the parameter x prior type */
19239             if (!strcmp(mp->aaModelPr,"Mixed"))
19240                 p->paramId = AAMODEL_MIX;
19241             else
19242                 p->paramId = AAMODEL_FIX;
19243
19244             if (p->paramId != AAMODEL_FIX)
19245                 p->printParam = YES;
19246             SafeStrcat (&p->paramHeader, "aamodel");
19247             SafeStrcat (&p->paramHeader, partString);
19248             }
19249         else if (j == P_CPPRATE)
19250             {
19251             /* Set up cpprate *****************************************************************************************/
19252             p->paramType = P_CPPRATE;
19253             p->nValues = 1;
19254             p->nSubValues = 0;
19255             p->min = 0.0;
19256             p->max = POS_INFINITY;
19257             for (i=0; i<numCurrentDivisions; i++)
19258                 if (isPartTouched[i] == YES)
19259                     modelSettings[i].cppRate = p;
19260
19261             p->paramTypeName = "Rate of rate-multiplying compound Poisson process";
19262             SafeStrcat(&p->name, "Lambda_cpp");
19263             SafeStrcat(&p->name, partString);
19264                     
19265             /* find the parameter x prior type */
19266             if (!strcmp(mp->cppRatePr,"Exponential"))
19267                 p->paramId = CPPRATE_EXP;
19268             else
19269                 p->paramId = CPPRATE_FIX;
19270             
19271             if (p->paramId != CPPRATE_FIX)
19272                 p->printParam = YES;
19273             SafeStrcat (&p->paramHeader, "cppRate");
19274             SafeStrcat (&p->paramHeader, partString);
19275             }
19276         else if (j == P_CPPMULTDEV)
19277             {
19278             /* Set up sigma of cpp rate multipliers *****************************************************************************************/
19279             p->paramType = P_CPPMULTDEV;
19280             p->nValues = 1;
19281             p->nSubValues = 0;
19282             p->min = 0.0;
19283             p->max = POS_INFINITY;
19284             for (i=0; i<numCurrentDivisions; i++)
19285                 if (isPartTouched[i] == YES)
19286                     modelSettings[i].cppMultDev = p;
19287
19288             p->paramTypeName = "Standard deviation (log) of CPP rate multipliers";
19289             SafeStrcat(&p->name, "Sigma_cpp");
19290             SafeStrcat(&p->name, partString);
19291                     
19292             /* find the parameter x prior type */
19293             if (!strcmp(mp->cppMultDevPr,"Fixed"))
19294                 p->paramId = CPPMULTDEV_FIX;
19295             
19296             if (p->paramId != CPPMULTDEV_FIX)
19297                 p->printParam = YES;
19298             SafeStrcat (&p->paramHeader, "sigma_cpp");
19299             SafeStrcat (&p->paramHeader, partString);
19300             }
19301         else if (j == P_CPPEVENTS)
19302             {
19303             /* Set up cpp events parameter *****************************************************************************************/
19304             p->paramType = P_CPPEVENTS;
19305             p->nValues = 0;
19306             p->nSubValues = 2*numLocalTaxa;     /* keep effective branch lengths here (for all nodes to be on the safe side) */
19307             p->min = 1E-6;
19308             p->max = POS_INFINITY;
19309             for (i=0; i<numCurrentDivisions; i++)
19310                 if (isPartTouched[i] == YES)
19311                     modelSettings[i].cppEvents = p;
19312
19313             p->paramTypeName = "Events of rate-multiplying compound Poisson process";
19314             SafeStrcat(&p->name, "CppEvents");
19315             SafeStrcat(&p->name, partString);
19316             
19317             /* find the parameter x prior type */
19318             p->paramId = CPPEVENTS;
19319             
19320             /* should we print values to .p file? */
19321             p->printParam = NO;
19322             
19323             SafeStrcat (&p->paramHeader, "cppEvents");
19324             SafeStrcat (&p->paramHeader, partString);
19325             }
19326         else if (j == P_TK02VAR)
19327             {
19328             /* Set up tk02 relaxed clock variance parameter *****************************************************************************************/
19329             p->paramType = P_TK02VAR;
19330             p->nValues = 1;
19331             p->nSubValues = 0;
19332             p->min = 1E-6;
19333             p->max = POS_INFINITY;
19334             for (i=0; i<numCurrentDivisions; i++)
19335                 if (isPartTouched[i] == YES)
19336                     modelSettings[i].tk02var = p;
19337
19338             p->paramTypeName = "Variance of lognormal distribution of branch rates";
19339             SafeStrcat(&p->name, "TK02var");
19340             SafeStrcat(&p->name, partString);
19341             
19342             /* find the parameter x prior type */
19343             if (!strcmp(mp->tk02varPr,"Uniform"))
19344                 p->paramId = TK02VAR_UNI;
19345             else if (!strcmp(mp->tk02varPr,"Exponential"))
19346                 p->paramId = TK02VAR_EXP;
19347             else
19348                 p->paramId = TK02VAR_FIX;
19349             
19350             if (p->paramId != TK02VAR_FIX)
19351                 p->printParam = YES;
19352             SafeStrcat (&p->paramHeader, "tk02var");
19353             SafeStrcat (&p->paramHeader, partString);
19354             }
19355         else if (j == P_TK02BRANCHRATES)
19356             {
19357             /* Set up tk02 relaxed clock rates parameter *****************************************************************************************/
19358             p->paramType = P_TK02BRANCHRATES;
19359             p->nValues = 2*numLocalTaxa;     /* use to hold the branch rates; we need one rate for the root */
19360             p->nSubValues = 2*numLocalTaxa;  /* use to hold the effective branch lengths */
19361             p->min = RATE_MIN;
19362             p->max = RATE_MAX;
19363             for (i=0; i<numCurrentDivisions; i++)
19364                 if (isPartTouched[i] == YES)
19365                     modelSettings[i].tk02BranchRates = p;
19366             
19367             p->paramTypeName = "Branch rates of TK02 relaxed clock";
19368             SafeStrcat(&p->name, "TK02Brlens");
19369             SafeStrcat(&p->name, partString);
19370             
19371             /* find the parameter x prior type */
19372             p->paramId = TK02BRANCHRATES;
19373             
19374             /* should we print values to .p file? */
19375             p->printParam = NO;
19376
19377             SafeStrcat (&p->paramHeader, "tk02_brlens");
19378             SafeStrcat (&p->paramHeader, partString);
19379             }
19380         else if (j == P_IGRVAR)
19381             {
19382             /* Set up igr relaxed clock variance parameter *****************************************************************************************/
19383             p->paramType = P_IGRVAR;
19384             p->nValues = 1;
19385             p->nSubValues = 0;
19386             p->min = 1E-6;
19387             p->max = POS_INFINITY;
19388             for (i=0; i<numCurrentDivisions; i++)
19389                 if (isPartTouched[i] == YES)
19390                     modelSettings[i].igrvar = p;
19391
19392             p->paramTypeName = "Variance increase of igr model branch lenths";
19393             SafeStrcat(&p->name, "Igrvar");
19394             SafeStrcat(&p->name, partString);
19395             
19396             /* find the parameter x prior type */
19397             if (!strcmp(mp->igrvarPr,"Uniform"))
19398                 p->paramId = IGRVAR_UNI;
19399             else if (!strcmp(mp->igrvarPr,"Exponential"))
19400                 p->paramId = IGRVAR_EXP;
19401             else
19402                 p->paramId = IGRVAR_FIX;
19403             
19404             if (p->paramId != IGRVAR_FIX)
19405                 p->printParam = YES;
19406             SafeStrcat (&p->paramHeader, "igrvar");
19407             SafeStrcat (&p->paramHeader, partString);
19408             }
19409         else if (j == P_IGRBRANCHRATES)
19410             {
19411             /* Set up igr relaxed clock rates parameter *****************************************************************************************/
19412             p->paramType = P_IGRBRANCHRATES;
19413             p->nValues = 2*numLocalTaxa;     /* use to hold the branch rates; we need one rate for the root */
19414             p->nSubValues = 2*numLocalTaxa;  /* use to hold the effective branch lengths */
19415             p->min = RATE_MIN;
19416             p->max = RATE_MAX;
19417             for (i=0; i<numCurrentDivisions; i++)
19418                 if (isPartTouched[i] == YES)
19419                     modelSettings[i].igrBranchRates = p;
19420             
19421             p->paramTypeName = "Branch lengths of IGR relaxed clock";
19422             SafeStrcat(&p->name, "IgrBrlens");
19423             SafeStrcat(&p->name, partString);
19424             
19425             /* find the parameter x prior type */
19426             p->paramId = IGRBRANCHRATES;
19427             
19428             /* should we print values to .p file? */
19429             p->printParam = NO;
19430
19431             SafeStrcat (&p->paramHeader, "igr_brlens");
19432             SafeStrcat (&p->paramHeader, partString);
19433             }
19434         else if (j == P_MIXEDVAR)
19435             {
19436             /* Set up mixed relaxed clock variance parameter *****************************************************************************************/
19437             p->paramType = P_MIXEDVAR;
19438             p->nValues = 1;
19439             p->nSubValues = 0;
19440             p->min = 1E-6;
19441             p->max = POS_INFINITY;
19442             for (i=0; i<numCurrentDivisions; i++)
19443                 if (isPartTouched[i] == YES)
19444                     modelSettings[i].mixedvar = p;
19445             
19446             p->paramTypeName = "Variance shared for mixed relaxed clock moodel";
19447             SafeStrcat(&p->name, "Mixedvar");
19448             SafeStrcat(&p->name, partString);
19449             
19450             /* find the parameter x prior type */
19451             if (!strcmp(mp->mixedvarPr,"Uniform"))
19452                 p->paramId = MIXEDVAR_UNI;
19453             else if (!strcmp(mp->mixedvarPr,"Exponential"))
19454                 p->paramId = MIXEDVAR_EXP;
19455             else
19456                 p->paramId = MIXEDVAR_FIX;
19457             
19458             if (p->paramId != MIXEDVAR_FIX)
19459                 p->printParam = YES;
19460             SafeStrcat (&p->paramHeader, "mixedvar");
19461             SafeStrcat (&p->paramHeader, partString);
19462             }
19463         else if (j == P_MIXEDBRCHRATES)
19464             {
19465             /* Set up mixed relaxed clock rates parameter *****************************************************************************************/
19466             p->paramType = P_MIXEDBRCHRATES;
19467             p->nValues = 2*numLocalTaxa;     /* use to hold the branch rates; we need one rate for the root */
19468             p->nSubValues = 2*numLocalTaxa;  /* use to hold the effective branch lengths */
19469             p->nIntValues = 1;               /* use to hold the model indicator: TK02 or IGR */
19470             p->min = RATE_MIN;
19471             p->max = RATE_MAX;
19472             for (i=0; i<numCurrentDivisions; i++)
19473                 if (isPartTouched[i] == YES)
19474                     modelSettings[i].mixedBrchRates = p;
19475             
19476             p->paramTypeName = "Branch rates of mixed relaxed clock";
19477             SafeStrcat(&p->name, "MixedBrlens");
19478             SafeStrcat(&p->name, partString);
19479             
19480             /* find the parameter x prior type */
19481             p->paramId = MIXEDBRCHRATES;
19482             
19483             /* how to print model indicator (0 or 1) to .p file? */
19484             p->printParam = NO;
19485             
19486             SafeStrcat (&p->paramHeader, "mixed_brlens");
19487             SafeStrcat (&p->paramHeader, partString);
19488             }
19489         else if (j == P_CLOCKRATE)
19490             {
19491             /* Set up clockRate ****************************************************************************************/
19492             p->paramType = P_CLOCKRATE;
19493             p->nValues = 1;
19494             p->nSubValues = 0;
19495             p->min = POS_MIN;
19496             p->max = POS_INFINITY;
19497             for (i=0; i<numCurrentDivisions; i++)
19498                 if (isPartTouched[i] == YES)
19499                     modelSettings[i].clockRate = p;
19500     
19501             p->paramTypeName = "Base rate of clock";
19502             SafeStrcat(&p->name, "Clockrate");
19503             SafeStrcat(&p->name, partString);
19504
19505             /* parameter does affect likelihoods */
19506             p->affectsLikelihood = YES;
19507             
19508             /* find the parameter x prior type */
19509             if (!strcmp(mp->clockRatePr,"Normal"))
19510                 {
19511                 p->paramId      = CLOCKRATE_NORMAL;
19512                 p->LnPriorRatio = &LnProbRatioTruncatedNormal;
19513                 p->priorParams  = mp->clockRateNormal;
19514                 p->LnPriorProb  = &LnPriorProbTruncatedNormal;
19515                 }
19516             else if (!strcmp(mp->clockRatePr,"Lognormal"))
19517                 {
19518                 p->paramId      = CLOCKRATE_LOGNORMAL;
19519                 p->LnPriorRatio = &LnProbRatioLognormal;
19520                 p->priorParams  = mp->clockRateLognormal;
19521                 p->LnPriorProb  = &LnPriorProbLognormal;
19522                 }
19523             else if (!strcmp(mp->clockRatePr,"Exponential"))
19524                 {
19525                 p->paramId      = CLOCKRATE_EXP;
19526                 p->LnPriorRatio = &LnProbRatioExponential;
19527                 p->priorParams  = &mp->clockRateExp;
19528                 p->LnPriorProb  = &LnPriorProbExponential;
19529                 }
19530             else if (!strcmp(mp->clockRatePr,"Gamma"))
19531                 {
19532                 p->paramId      = CLOCKRATE_GAMMA;
19533                 p->LnPriorRatio = &LnProbRatioGamma;
19534                 p->priorParams  = mp->clockRateGamma;
19535                 p->LnPriorProb  = &LnPriorProbGamma;
19536                 }
19537             else
19538                 {
19539                 p->paramId      = CLOCKRATE_FIX;
19540                 p->LnPriorRatio = NULL;
19541                 p->priorParams  = &mp->clockRateFix;
19542                 p->LnPriorProb  = &LnPriorProbFix;
19543                 }
19544                 
19545             SafeStrcat (&p->paramHeader, "clockrate");
19546             SafeStrcat (&p->paramHeader, partString);
19547             if (p->paramId != CLOCKRATE_FIX)
19548                 p->printParam = YES;
19549             }
19550         }
19551     free (tempStr);
19552     free (isPartTouched);
19553     SafeFree ((void **)&partString);
19554
19555     return (NO_ERROR);
19556 }
19557
19558
19559 /*----------------------------------------------------------------------------
19560 |
19561 |   SetMoves: This function will set up the applicable moves that could
19562 |       potentially be used in updating the model parameters
19563 |
19564 -----------------------------------------------------------------------------*/
19565 int SetMoves (void)
19566 {
19567     int         i, j, k, moveIndex;
19568     Param       *param;
19569     
19570     /* free up previous moves if any */
19571     if (memAllocs[ALLOC_MOVES] == YES)
19572         {
19573         for (i=0; i<numApplicableMoves; i++)
19574             FreeMove (moves[i]);
19575         free (moves);
19576         moves = NULL;
19577         memAllocs[ALLOC_MOVES] = NO;
19578         }
19579
19580     /* set up applicable moves                                   */
19581     /* each combination of moveType and param is a separate move */
19582     
19583     /* first count applicable moves */
19584     numApplicableMoves = 0;
19585     for (k=0; k<numParams; k++)
19586         {
19587         param = &params[k];
19588         for (i=0; i<NUM_MOVE_TYPES; i++)
19589             {
19590             if (moveTypes[i].level > userLevel)
19591                 continue;
19592             if (moveTypes[i].isApplicable(param) == NO)
19593                 continue;
19594             for (j=0; j<moveTypes[i].nApplicable; j++)
19595                 if (moveTypes[i].applicableTo[j] == param->paramId)
19596                     {
19597                     numApplicableMoves++;
19598                     break;
19599                     }
19600             }
19601         }
19602
19603     /* then allocate space for move pointers */
19604     moves = (MCMCMove **) SafeMalloc (numApplicableMoves * sizeof (MCMCMove *));
19605     if (!moves)
19606         {
19607         MrBayesPrint ("%s   Problem allocating moves\n", spacer);
19608         return (ERROR);
19609         }
19610     memAllocs[ALLOC_MOVES] = YES;
19611
19612     /* finally allocate space for and set move defaults */
19613     moveIndex = 0;
19614     for (k=0; k<numParams; k++)
19615         {
19616         param = &params[k];
19617         for (i=0; i<NUM_MOVE_TYPES; i++)
19618             {   
19619             if (moveTypes[i].level > userLevel)
19620                 continue;
19621             if (moveTypes[i].isApplicable(param) == NO)
19622                 continue;
19623             for (j=0; j<moveTypes[i].nApplicable; j++)
19624                 {
19625                 if (moveTypes[i].applicableTo[j] == param->paramId)
19626                     {
19627                     if ((moves[moveIndex] = AllocateMove (&moveTypes[i], param)) == NULL)
19628                         break;
19629                     else
19630                         {
19631                         moves[moveIndex]->parm = param;
19632                         moveIndex++;
19633                         break;
19634                         }
19635                     }
19636                 }
19637             }
19638         }
19639
19640     if (moveIndex < numApplicableMoves)
19641         {
19642         for (i=0; i<moveIndex; i++)
19643             FreeMove (moves[i]);
19644         free (moves);
19645         memAllocs[ALLOC_MOVES] = NO;
19646         MrBayesPrint ("%s   Problem setting moves\n", spacer);
19647         return (ERROR);
19648         }
19649
19650     return (NO_ERROR);
19651 }
19652
19653
19654 /** SetPopSizeParam: Set population size values for a species tree from an input tree */
19655 int SetPopSizeParam (Param *param, int chn, int state, PolyTree *pt)
19656 {
19657     int         i, j, k, nLongsNeeded;
19658     MrBFlt      *values;
19659     Tree        *speciesTree;
19660     PolyNode    *pp;
19661     TreeNode    *p=NULL;
19662
19663     nLongsNeeded = 1 + (pt->nNodes - pt->nIntNodes - 1) / nBitsInALong;
19664
19665     /* Get pointer to values to be set */
19666     values = GetParamVals (param, chn, state);
19667
19668     /* Get species tree */
19669     speciesTree = GetTree (modelSettings[param->relParts[0]].speciesTree, chn, state);
19670
19671     /* Set them based on index of matching partitions */
19672     AllocatePolyTreePartitions(pt);
19673     AllocateTreePartitions(speciesTree);
19674     for (i=0; i<pt->nNodes; i++)
19675         {
19676         pp = pt->allDownPass[i];
19677         for (j=0; j<speciesTree->nNodes-1; j++)
19678             {
19679             p = speciesTree->allDownPass[j];
19680             for (k=0; k<nLongsNeeded; k++)
19681                 {
19682                 if (pp->partition[k] != p->partition[k])
19683                     break;
19684                 }
19685             if (k == nLongsNeeded)
19686                 break;
19687             }
19688         if (j == speciesTree->nNodes - 1)
19689             {
19690             MrBayesPrint ("%s   Non-matching partitions when setting population size parameter", spacer);
19691             FreePolyTreePartitions(pt);
19692             FreeTreePartitions(speciesTree);
19693             return (ERROR);
19694             }
19695         values[p->index] = pt->popSize[pp->index];
19696     }
19697
19698     FreePolyTreePartitions(pt);
19699     FreeTreePartitions(speciesTree);
19700     
19701     return (NO_ERROR);
19702 }
19703
19704
19705 /* SetRelaxedClockParam: set values for a relaxed clock param from an input tree */
19706 int SetRelaxedClockParam (Param *param, int chn, int state, PolyTree *pt)
19707 {
19708     int         i, j, k, *nEvents=NULL, *nEventsP=NULL, nLongsNeeded, isEventSet;
19709     MrBFlt       *effectiveBranchLengthP=NULL, *branchRate=NULL,
19710                 **position=NULL, **rateMult=NULL, **positionP=NULL, **rateMultP=NULL,
19711                 baseRate;
19712     Tree        *t;
19713     PolyNode    *pp;
19714     TreeNode    *p=NULL, *q;
19715
19716     nLongsNeeded = 1 + (numLocalTaxa - 1) / nBitsInALong;
19717
19718     /* set pointers to the right set of values */
19719     isEventSet = NO;
19720     if (param->paramType == P_CPPEVENTS)
19721         {
19722         /* find the right event set */
19723         for (i=0; i<pt->nESets; i++)
19724             {
19725             if (!strcmp(param->name,pt->eSetName[i]))
19726                 break;
19727             }
19728         if (i == pt->nESets)
19729             {
19730             for (i=0; i<pt->nBSets; i++)
19731                 if (!strcmp(param->name,pt->bSetName[i]))
19732                     break;
19733
19734             if (i == pt->nBSets)
19735                 return (NO_ERROR);
19736             else
19737                 isEventSet = NO;
19738             }
19739         else
19740             isEventSet = YES;
19741
19742         if (isEventSet == YES)
19743             {
19744             nEventsP  = pt->nEvents[i];
19745             positionP = pt->position[i];
19746             rateMultP = pt->rateMult[i];
19747             }
19748         else
19749             effectiveBranchLengthP = pt->effectiveBrLen[i];
19750
19751         nEvents  = param->nEvents[2*chn+state];
19752         position = param->position[2*chn+state];
19753         rateMult = param->rateMult[2*chn+state];
19754         }
19755     else if (param->paramType == P_TK02BRANCHRATES || param->paramType == P_IGRBRANCHRATES || param->paramType == P_MIXEDBRCHRATES)
19756         {
19757         /* find the right effective branch length set */
19758         for (i=0; i<pt->nBSets; i++)
19759             if (!strcmp(param->name,pt->bSetName[i]))
19760                 break;
19761         if (i == pt->nBSets)
19762             return (NO_ERROR);
19763
19764         effectiveBranchLengthP = pt->effectiveBrLen[i];
19765         branchRate = GetParamVals (param, chn, state);
19766         }
19767
19768     t = GetTree (param, chn, state);
19769     AllocatePolyTreePartitions (pt);
19770     AllocateTreePartitions (t);
19771     
19772     for (i=pt->nNodes-1; i>=0; i--)
19773         {
19774         pp = pt->allDownPass[i];
19775         for (j=0; j<t->nNodes; j++)
19776             {
19777             p = t->allDownPass[j];
19778             for (k=0; k<nLongsNeeded; k++)
19779                 if (p->partition[k] != pp->partition[k])
19780                     break;
19781             if (k == nLongsNeeded)
19782                 break;  /* match */
19783             }
19784         if (param->paramType == P_CPPEVENTS)
19785             {
19786             if (isEventSet == NO)
19787                 {
19788                 if (nEvents[p->index] != 1)
19789                     {
19790                     position[p->index] = (MrBFlt *) SafeRealloc ((void *) position[p->index], 1*sizeof(MrBFlt));
19791                     rateMult[p->index] = (MrBFlt *) SafeRealloc ((void *) rateMult[p->index], 1*sizeof(MrBFlt));
19792                     nEvents [p->index] = 1;
19793                     }
19794                 position[p->index][0] = 0.5;
19795                 if (p->anc->anc == NULL)
19796                     rateMult[p->index][0] = 1.0;
19797                 else
19798                     {
19799                     baseRate = 1.0;
19800                     q = p->anc;
19801                     while (q->anc != NULL)
19802                         {
19803                         baseRate *= rateMult[q->index][0];
19804                         q = q->anc;
19805                         }
19806                     rateMult[p->index][0] = 2.0 * effectiveBranchLengthP[pp->index] / (p->length * baseRate) - 1.0;
19807                     }
19808                 }
19809             else
19810                 {
19811                 if (nEvents[p->index] != nEventsP[pp->index])
19812                     {
19813                     if (nEventsP[pp->index] == 0)
19814                         {
19815                         free (position[p->index]);
19816                         free (rateMult[p->index]);
19817                         }
19818                     else
19819                         {
19820                         position[p->index] = (MrBFlt *) SafeRealloc ((void *) position[p->index], nEventsP[pp->index]*sizeof(MrBFlt));
19821                         rateMult[p->index] = (MrBFlt *) SafeRealloc ((void *) rateMult[p->index], nEventsP[pp->index]*sizeof(MrBFlt));
19822                         }
19823                     nEvents[p->index] = nEventsP[pp->index];
19824                     }
19825                 for (j=0; j<nEventsP[pp->index]; j++)
19826                     {
19827                     position[p->index][j] = positionP[pp->index][j];
19828                     rateMult[p->index][j] = rateMultP[pp->index][j];
19829                     }
19830                 }
19831             }
19832         else if (param->paramType == P_TK02BRANCHRATES ||
19833                  (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_TK02))
19834             {
19835             if (p->anc->anc == NULL)
19836                 branchRate[p->index] = 1.0;
19837             else if (p->length > 0.0)
19838                 branchRate[p->index] = 2.0 * effectiveBranchLengthP[pp->index] / p->length - branchRate[p->anc->index];
19839             else
19840                 branchRate[p->index] = branchRate[p->anc->index];
19841             }
19842         else if (param->paramType == P_IGRBRANCHRATES ||
19843                  (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_IGR))
19844             {
19845             if (p->length > 0.0)
19846                 branchRate[p->index] = effectiveBranchLengthP[pp->index] / p->length;
19847             else
19848                 branchRate[p->index] = branchRate[p->anc->index];
19849             }  // we are now reading effective branch length for TK02 and IGR
19850         }
19851
19852     if (param->paramType == P_CPPEVENTS)
19853         {
19854         if (UpdateCppEvolLengths (param, t->root->left, chn) == ERROR)
19855             return (ERROR);
19856         }
19857     else if (param->paramType == P_TK02BRANCHRATES ||
19858              (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_TK02))
19859         {
19860         if (UpdateTK02EvolLengths (param, t, chn) == ERROR)
19861             return (ERROR);
19862         }
19863     else if (param->paramType == P_IGRBRANCHRATES ||
19864              (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_IGR))
19865         {
19866         if (UpdateIgrBrachLengths (param, t, chn) == ERROR)
19867             return (ERROR);
19868         }
19869
19870     FreePolyTreePartitions (pt);
19871     FreeTreePartitions (t);
19872
19873     return (NO_ERROR);
19874 }
19875
19876
19877 /*------------------------------------------------------------------------
19878 |
19879 |   SetUpAnalysis: Set parameters and moves
19880 |
19881 ------------------------------------------------------------------------*/
19882 int SetUpAnalysis (RandLong *seed)
19883 {
19884     setUpAnalysisSuccess=NO;
19885
19886     /* calculate number of characters and taxa */
19887     numLocalChar = NumNonExcludedChar ();
19888
19889     /* we are checking later to make sure no partition is without characters */
19890     SetLocalTaxa ();
19891     if (numLocalTaxa <= 2)
19892         {
19893         MrBayesPrint ("%s   There must be at least two included taxa, now there is %s\n", spacer,
19894             numLocalTaxa == 0 ? "none" : "only one");
19895         return (ERROR);
19896         }
19897
19898     /* calculate number of global chains */
19899     numGlobalChains = chainParams.numRuns * chainParams.numChains;
19900
19901     /* Set up link table */
19902     if (SetUpLinkTable () == ERROR)
19903         return (ERROR);
19904     
19905     /* Check that the settings for doublet or codon models are correct. */
19906     if (CheckExpandedModels() == ERROR)
19907         return (ERROR);
19908
19909     /* Set up model info */
19910     if (SetModelInfo() == ERROR) 
19911         return (ERROR);
19912     
19913     /* Calculate number of (uncompressed) characters for each division */
19914     if (GetNumDivisionChars() == ERROR)
19915         return (ERROR);
19916
19917     /* Compress data and calculate some things needed for setting up params. */
19918     if (CompressData() == ERROR)
19919         return (ERROR);
19920
19921     /* Add dummy characters, if needed. */
19922     if (AddDummyChars() == ERROR)
19923         return (ERROR);
19924
19925     /* Set up parameters for the chain. */
19926     if (SetModelParams () == ERROR)
19927         return (ERROR);
19928     
19929     /* Allocate normal params */
19930     if (AllocateNormalParams () == ERROR)
19931         return (ERROR);
19932     
19933     /* Allocate tree params */
19934     if (AllocateTreeParams () == ERROR)
19935         return (ERROR);
19936     
19937     /* Set default number of trees for sumt to appropriate number */
19938     sumtParams.numTrees = numTrees;
19939
19940     /* Fill in normal parameters */
19941     if (FillNormalParams (seed, 0, numGlobalChains) == ERROR) 
19942         return (ERROR);
19943
19944     /* Process standard characters (calculates bsIndex, tiIndex, and more). */
19945     if (ProcessStdChars(seed) == ERROR)
19946         return (ERROR);
19947
19948     /* Fill in trees */
19949     if (FillTreeParams (seed, 0, numGlobalChains) == ERROR)
19950         return (ERROR);
19951     
19952     /* Set the applicable moves that could be used by the chain. */
19953     if (SetMoves () == ERROR)
19954         return (ERROR);
19955     
19956     setUpAnalysisSuccess=YES;
19957     
19958     return (NO_ERROR);
19959 }
19960
19961
19962 int SetUpLinkTable (void)
19963 {
19964     int         i, j, k, m, paramCount, isApplicable1, isApplicable2,
19965                 isFirst, isSame;
19966     int         *check, *modelId;
19967
19968     check = (int *) SafeMalloc (2 * (size_t)numCurrentDivisions * sizeof (int));
19969     if (!check)
19970         {
19971         MrBayesPrint ("%s   Problem allocating check (%d)\n", spacer, 2 * numCurrentDivisions * sizeof(int));
19972         return (ERROR);
19973         }
19974     modelId = check + numCurrentDivisions;
19975
19976     for (j=0; j<NUM_LINKED; j++)
19977         for (i=0; i<numCurrentDivisions; i++)
19978             activeParams[j][i] = 0;
19979     
19980     if (numCurrentDivisions > 1)
19981         {
19982         paramCount = 0;
19983         for (j=0; j<NUM_LINKED; j++) /* loop over parameters */
19984             {
19985             isFirst = YES;
19986             for (i=0; i<numCurrentDivisions; i++)
19987                 modelId[i] = 0;     
19988             for (i=0; i<numCurrentDivisions-1; i++) /* loop over partitions */
19989                 {
19990                 for (k=i+1; k<numCurrentDivisions; k++)
19991                     {
19992                     if (IsModelSame (j, i, k, &isApplicable1, &isApplicable2) == NO || linkTable[j][i] != linkTable[j][k])
19993                         {
19994                         /* we cannot link the parameters */
19995                         if (isApplicable1 == NO)
19996                             modelId[i] = -1;
19997                         if (isApplicable2 == NO)
19998                             modelId[k] = -1;
19999                         if (isApplicable1 == YES)
20000                             {
20001                             if (isFirst == YES && modelId[i] == 0)
20002                                 {
20003                                 modelId[i] = ++paramCount;
20004                                 isFirst = NO;
20005                                 }
20006                             else
20007                                 {
20008                                 if (modelId[i] == 0)
20009                                     modelId[i] = ++paramCount;
20010                                 }
20011                             }
20012                         if (modelId[k] == 0 && isApplicable2 == YES)
20013                             modelId[k] = ++paramCount;
20014                         }
20015                     else
20016                         {
20017                         /* we can link the parameters */
20018                         if (isFirst == YES)
20019                             {
20020                             if (modelId[i] == 0)
20021                                 modelId[i] = ++paramCount;
20022                             isFirst = NO;
20023                             }
20024                         else
20025                             {
20026                             if (modelId[i] == 0)
20027                                 modelId[i] = ++paramCount;
20028                             }
20029                         modelId[k] = modelId[i];
20030                         }
20031                     }
20032                 }
20033             for (i=0; i<numCurrentDivisions; i++)
20034                 activeParams[j][i] = modelId[i];
20035             }
20036         }
20037     else
20038         {
20039         /* if we have only one partition, then we do things a bit differently */
20040         paramCount = 0;
20041         for (j=0; j<NUM_LINKED; j++) /* loop over parameters */
20042             {
20043             IsModelSame (j, 0, 0, &isApplicable1, &isApplicable2);
20044             if (isApplicable1 == YES)
20045                 activeParams[j][0] = ++paramCount;
20046             else
20047                 activeParams[j][0] = -1;
20048             }
20049         }
20050         
20051     /* Check that the same report format is specified for all partitions with the same rate multiplier */
20052     for (i=0; i<numCurrentDivisions; i++)
20053         check[i] = NO;
20054     for (i=0; i<numCurrentDivisions; i++)
20055         {
20056         m = activeParams[P_RATEMULT][i];
20057         if (m == -1 || check[i] == YES)
20058             continue;
20059         isSame = YES;
20060         for (j=i+1; j<numCurrentDivisions; j++)
20061             {
20062             if (activeParams[P_RATEMULT][j] == m)
20063                 {
20064                 check[i] = YES;
20065                 if (strcmp(modelParams[i].ratemultFormat,modelParams[j].ratemultFormat)!= 0)
20066                     {
20067                     isSame = NO;
20068                     strcpy (modelParams[j].ratemultFormat, modelParams[i].ratemultFormat);
20069                     }
20070                 }
20071             }
20072         if (isSame == NO)
20073             {
20074             MrBayesPrint ("%s   WARNING: Report format for ratemult (parameter %d) varies across partitions.\n", spacer);
20075             MrBayesPrint ("%s      MrBayes will use the format for the first partition, which is %s.\n", spacer, modelParams[i].ratemultFormat);
20076             }
20077         }
20078        
20079     /* probably a good idea to clean up link table here */
20080     paramCount = 0;
20081     for (j=0; j<NUM_LINKED; j++)
20082         {
20083         for (i=0; i<numCurrentDivisions; i++)
20084             check[i] = NO;
20085         for (i=0; i<numCurrentDivisions; i++)
20086             {
20087             if (check[i] == NO && activeParams[j][i] > 0)
20088                 {
20089                 m = activeParams[j][i];
20090                 paramCount++;
20091                 for (k=i; k<numCurrentDivisions; k++)
20092                     {
20093                     if (check[k] == NO && activeParams[j][k] == m)
20094                         {
20095                         activeParams[j][k] = paramCount;
20096                         check[k] = YES;
20097                         }
20098                     }
20099                 }
20100             }
20101         }
20102
20103     free (check);
20104
20105     return (NO_ERROR);
20106 }
20107
20108
20109 /*------------------------------------------------------------------------
20110 |
20111 |   SetUpMoveTypes: Set up structs holding info on each move type
20112 |
20113 ------------------------------------------------------------------------*/
20114 void SetUpMoveTypes (void)
20115 {
20116     /* Register the move type here when new move functions are added 
20117        Remember to check that the number of move types does not exceed NUM_MOVE_TYPES
20118        defined in bayes.h.         */
20119     int         i;
20120     MoveType    *mt;
20121
20122     /* reset move types */
20123     for (i=0; i<NUM_MOVE_TYPES; i++)
20124         {
20125         mt = &moveTypes[i];
20126         mt->level = DEVELOPER;
20127         mt->numTuningParams = 0;
20128         mt->minimum[0] = mt->minimum[1] = -1000000000.0;
20129         mt->maximum[0] = mt->maximum[1] =  1000000000.0;
20130         mt->tuningParam[0] = mt->tuningParam[1] = 0.0;
20131         mt->nApplicable = 0;
20132         mt->name = mt->tuningName[0] = mt->tuningName[1] = "";
20133         mt->paramName = "";
20134         mt->subParams = NO;
20135         mt->relProposalProb = 0.0;
20136         mt->parsimonyBased = NO;
20137         mt->isApplicable = &IsApplicable;
20138         mt->Autotune = NULL;
20139         mt->targetRate = -1.0;
20140         }
20141
20142     /* Moves are in alphabetic order after parameter name, which matches the name of a move function if
20143        there is a separate move function for the parameter. See proposal.h for declaration of move functions.
20144        Since 2010-10-04, some parameters use generalized move functions and do not have their own. */
20145     
20146     i = 0;
20147
20148     /* Move_Aamodel */
20149     mt = &moveTypes[i++];
20150     mt->name = "Uniform random pick";
20151     mt->shortName = "Uniform";
20152     mt->applicableTo[0] = AAMODEL_MIX;
20153     mt->nApplicable = 1;
20154     mt->moveFxn = &Move_Aamodel;
20155     mt->relProposalProb = 1.0;
20156     mt->numTuningParams = 0;
20157     mt->parsimonyBased = NO;
20158     mt->level = STANDARD_USER;
20159     
20160     /* Move_Adgamma */
20161     mt = &moveTypes[i++];
20162     mt->name = "Sliding window";
20163     mt->shortName = "Slider";
20164     mt->tuningName[0] = "Sliding window size";
20165     mt->shortTuningName[0] = "delta";
20166     mt->applicableTo[0] = CORREL_UNI;
20167     mt->nApplicable = 1;
20168     mt->moveFxn = &Move_Adgamma;
20169     mt->relProposalProb = 1.0;
20170     mt->numTuningParams = 1;
20171     mt->tuningParam[0] = 0.5;  /* window size */
20172     mt->minimum[0] = 0.001;
20173     mt->maximum[0] = 1.999;
20174     mt->parsimonyBased = NO;
20175     mt->level = STANDARD_USER;
20176     mt->Autotune = &AutotuneSlider;
20177     mt->targetRate = 0.25;
20178
20179     /* Move_Beta */
20180     mt = &moveTypes[i++];
20181     mt->name = "Multiplier";
20182     mt->shortName = "Multiplier";
20183     mt->tuningName[0] = "Multiplier tuning parameter";
20184     mt->shortTuningName[0] = "lambda";
20185     mt->applicableTo[0] = SYMPI_UNI;
20186     mt->applicableTo[1] = SYMPI_EXP;
20187     mt->applicableTo[2] = SYMPI_UNI_MS;
20188     mt->applicableTo[3] = SYMPI_EXP_MS;
20189     mt->nApplicable = 4;
20190     mt->moveFxn = &Move_Beta;
20191     mt->relProposalProb = 1.0;
20192     mt->numTuningParams = 1;
20193     mt->tuningParam[0] = 2.0 * log (1.5);  /* so-called lambda */
20194     mt->minimum[0] = 0.0001;
20195     mt->maximum[0] = 20.0;
20196     mt->parsimonyBased = NO;
20197     mt->level = STANDARD_USER;
20198     mt->Autotune = &AutotuneMultiplier;
20199     mt->targetRate = 0.25;
20200
20201     /* Move_BrLen */
20202     mt = &moveTypes[i++];
20203     mt->name = "Random brlen hit with multiplier";
20204     mt->shortName = "Multiplier";
20205     mt->tuningName[0] = "Multiplier tuning parameter";
20206     mt->shortTuningName[0] = "lambda";  
20207     mt->applicableTo[0] = BRLENS_UNI;
20208     mt->applicableTo[1] = BRLENS_EXP;
20209     mt->applicableTo[2] = BRLENS_GamDir;
20210     mt->applicableTo[3] = BRLENS_iGmDir;
20211     mt->applicableTo[4] = BRLENS_twoExp;
20212     mt->nApplicable = 5;  // was 2
20213     mt->moveFxn = &Move_BrLen;
20214     mt->relProposalProb = 20.0;
20215     mt->numTuningParams = 1;
20216     mt->tuningParam[0] = 2.0 * log (2.0);  /* lambda */
20217     mt->minimum[0] = 0.0001;
20218     mt->maximum[0] = 20.0;  /* change it smaller to avoid overflow in the exp function, same for following "smaller" */
20219     mt->parsimonyBased = NO;
20220     mt->level = STANDARD_USER;
20221     mt->Autotune = &AutotuneMultiplier;
20222     mt->targetRate = 0.25;
20223
20224     /* Move_ClockRate_M */
20225     mt = &moveTypes[i++];
20226     mt->name = "Multiplier";
20227     mt->shortName = "Multiplier";
20228     mt->tuningName[0] = "Multiplier tuning parameter";
20229     mt->shortTuningName[0] = "lambda";
20230     mt->applicableTo[0] = CLOCKRATE_NORMAL;
20231     mt->applicableTo[1] = CLOCKRATE_LOGNORMAL;
20232     mt->applicableTo[2] = CLOCKRATE_GAMMA;
20233     mt->applicableTo[3] = CLOCKRATE_EXP;
20234     mt->nApplicable = 4;
20235     mt->moveFxn = &Move_ClockRate_M;
20236     mt->relProposalProb = 2.0;
20237     mt->numTuningParams = 1;
20238     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
20239     mt->minimum[0] = 0.0001;
20240     mt->maximum[0] = 20.0;                 /* smaller */
20241     mt->parsimonyBased = NO;
20242     mt->level = STANDARD_USER;
20243     mt->Autotune = &AutotuneMultiplier;
20244     mt->targetRate = 0.25;
20245
20246     /* Move_Extinction */
20247     mt = &moveTypes[i++];
20248     mt->name = "Sliding window";
20249     mt->shortName = "Slider";
20250     mt->tuningName[0] = "Sliding window size";
20251     mt->shortTuningName[0] = "delta";
20252     mt->applicableTo[0] = EXTRATE_BETA;
20253     mt->nApplicable = 1;
20254     mt->moveFxn = &Move_Extinction;
20255     mt->relProposalProb = 3.0;
20256     mt->numTuningParams = 1;
20257     mt->tuningParam[0] = 0.1;  /* window size */
20258     mt->minimum[0] = 0.00001;
20259     mt->maximum[0] = 20.0;
20260     mt->parsimonyBased = NO;
20261     mt->level = STANDARD_USER;
20262     mt->Autotune = &AutotuneSlider;
20263     mt->targetRate = 0.25;
20264
20265     /* Move_Fossilization */
20266     mt = &moveTypes[i++];
20267     mt->name = "Sliding window";
20268     mt->shortName = "Slider";
20269     mt->tuningName[0] = "Sliding window size";
20270     mt->shortTuningName[0] = "delta";
20271     mt->applicableTo[0] = FOSLRATE_BETA;
20272     mt->nApplicable = 1;
20273     mt->moveFxn = &Move_Fossilization;
20274     mt->relProposalProb = 3.0;
20275     mt->numTuningParams = 1;
20276     mt->tuningParam[0] = 0.1;  /* window size */
20277     mt->minimum[0] = 0.00001;
20278     mt->maximum[0] = 20.0;
20279     mt->parsimonyBased = NO;
20280     mt->level = STANDARD_USER;
20281     mt->Autotune = &AutotuneSlider;
20282     mt->targetRate = 0.25;
20283
20284     /* Move_AddBranch, for fossilization prior */
20285     mt = &moveTypes[i++];
20286     mt->name = "Add branch for FossilizedBD";
20287     mt->shortName = "AddBranch";
20288     // mt->subParams = YES;
20289     mt->applicableTo[0] = BRLENS_CLOCK_FOSSIL;
20290     mt->nApplicable = 1;
20291     mt->moveFxn = &Move_AddBranch;
20292     mt->relProposalProb = 10.0;
20293     mt->numTuningParams = 0;
20294     mt->parsimonyBased = NO;
20295     mt->level =STANDARD_USER;
20296     mt->isApplicable = &IsApplicable_AncestralFossil;
20297
20298     /* Move_DelBranch, for fossilization prior */
20299     mt = &moveTypes[i++];
20300     mt->name = "Delete branch for FossilizedBD";
20301     mt->shortName = "DelBranch";
20302     // mt->subParams = YES;
20303     mt->applicableTo[0] = BRLENS_CLOCK_FOSSIL;
20304     mt->nApplicable = 1;
20305     mt->moveFxn = &Move_DelBranch;
20306     mt->relProposalProb = 10.0;
20307     mt->numTuningParams = 0;
20308     mt->parsimonyBased = NO;
20309     mt->level =STANDARD_USER;
20310     mt->isApplicable = &IsApplicable_AncestralFossil;
20311
20312     /* Move_ExtSPR */
20313     mt = &moveTypes[i++];
20314     mt->name = "Extending SPR";
20315     mt->shortName = "ExtSPR";
20316     mt->subParams = YES;
20317     mt->tuningName[0] = "Extension probability";
20318     mt->shortTuningName[0] = "p_ext";
20319     mt->tuningName[1] = "Multiplier tuning parameter";
20320     mt->shortTuningName[1] = "lambda";
20321     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20322     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20323     mt->nApplicable = 2;
20324     mt->moveFxn = &Move_ExtSPR;
20325     mt->relProposalProb = 5.0;
20326     mt->numTuningParams = 2;
20327     mt->tuningParam[0] = 0.5; /* extension probability */
20328     mt->tuningParam[1] = 2.0 * log (1.05);   /* lambda */
20329     mt->minimum[0] = 0.00001;
20330     mt->maximum[0] = 0.99999;
20331     mt->minimum[1] = 0.00001;
20332     mt->maximum[1] = 100.0;
20333     mt->parsimonyBased = NO;
20334     mt->level = STANDARD_USER;
20335     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20336
20337     /* Move_ExtSPR1 */
20338     mt = &moveTypes[i++];
20339     mt->name = "Extending SPR variant 1";
20340     mt->shortName = "ExtSPR1";
20341     mt->subParams = YES;
20342     mt->tuningName[0] = "Extension probability";
20343     mt->shortTuningName[0] = "p_ext";
20344     mt->tuningName[1] = "Multiplier tuning parameter";
20345     mt->shortTuningName[1] = "lambda";
20346     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20347     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20348     mt->nApplicable = 2;
20349     mt->moveFxn = &Move_ExtSPR1;
20350     mt->relProposalProb = 0.0;
20351     mt->numTuningParams = 2;
20352     mt->tuningParam[0] = 0.5; /* extension probability */
20353     mt->tuningParam[1] = 2.0 * log (1.05);   /* lambda */
20354     mt->minimum[0] = 0.00001;
20355     mt->maximum[0] = 0.99999;
20356     mt->minimum[1] = 0.00001;
20357     mt->maximum[1] = 100.0;
20358     mt->parsimonyBased = NO;
20359     mt->level = DEVELOPER;
20360     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
20361
20362     /* Move_ExtSPRClock */
20363     mt = &moveTypes[i++];
20364     mt->name = "Extending SPR for clock trees";
20365     mt->shortName = "ExtSprClock";
20366     mt->subParams = YES;
20367     mt->tuningName[0] = "Extension probability";
20368     mt->shortTuningName[0] = "p_ext";
20369     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20370     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20371     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20372     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20373     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
20374     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
20375     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
20376     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
20377     mt->nApplicable = 8;
20378     mt->moveFxn = &Move_ExtSPRClock;
20379     mt->relProposalProb = 10.0;
20380     mt->numTuningParams = 1;
20381     mt->tuningParam[0] = 0.5; /* extension probability */
20382     mt->minimum[0] = 0.00001;
20383     mt->maximum[0] = 0.99999;
20384     mt->parsimonyBased = NO;
20385     mt->level = STANDARD_USER;
20386     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20387
20388     /* Move_ExtSS */
20389     mt = &moveTypes[i++];
20390     mt->name = "Extending subtree swapper";
20391     mt->shortName = "ExtSS";
20392     mt->subParams = YES;
20393     mt->tuningName[0] = "Extension probability";
20394     mt->shortTuningName[0] = "p_ext";
20395     mt->tuningName[1] = "Multiplier tuning parameter";
20396     mt->shortTuningName[1] = "lambda";
20397     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20398     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20399     mt->nApplicable = 2;
20400     mt->moveFxn = &Move_ExtSS;
20401     mt->relProposalProb = 0.0;
20402     mt->numTuningParams = 2;
20403     mt->tuningParam[0] = 0.5; /* extension probability */
20404     mt->tuningParam[1] = 2.0 * log (1.05); /* lambda */
20405     mt->minimum[0] = 0.00001;
20406     mt->maximum[0] = 0.99999;
20407     mt->minimum[1] = 0.00001;
20408     mt->maximum[1] = 100.0;
20409     mt->parsimonyBased = NO;
20410     mt->level = STANDARD_USER;
20411     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20412
20413     /* Move_ExtSSClock */
20414     mt = &moveTypes[i++];
20415     mt->name = "Extending subtree swapper";
20416     mt->shortName = "ExtSsClock";
20417     mt->subParams = YES;
20418     mt->tuningName[0] = "Extension probability";
20419     mt->shortTuningName[0] = "p_ext";
20420     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20421     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20422     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20423     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20424     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
20425     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
20426     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
20427     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
20428     mt->nApplicable = 8;
20429     mt->moveFxn = &Move_ExtSSClock;
20430     mt->relProposalProb = 0.0;
20431     mt->numTuningParams = 1;
20432     mt->tuningParam[0] = 0.5; /* extension probability */
20433     mt->minimum[0] = 0.00001;
20434     mt->maximum[0] = 0.99999;
20435     mt->parsimonyBased = NO;
20436     mt->level = STANDARD_USER;
20437     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20438
20439     /* Move_ExtTBR */
20440     mt = &moveTypes[i++];
20441     mt->name = "Extending TBR";
20442     mt->shortName = "ExtTBR";
20443     mt->subParams = YES;
20444     mt->tuningName[0] = "Extension probability";
20445     mt->shortTuningName[0] = "p_ext";
20446     mt->tuningName[1] = "Multiplier tuning parameter";
20447     mt->shortTuningName[1] = "lambda";
20448     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20449     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20450     mt->nApplicable = 2;
20451     mt->moveFxn = &Move_ExtTBR;
20452     mt->relProposalProb = 5.0;
20453     mt->numTuningParams = 2;
20454     mt->tuningParam[0] = 0.5; /* extension probability */
20455     mt->tuningParam[1] = 2.0 * log (1.05);   /* lambda */
20456     mt->minimum[0] = 0.00001;
20457     mt->maximum[0] = 0.99999;
20458     mt->minimum[1] = 0.00001;
20459     mt->maximum[1] = 100.0;
20460     mt->parsimonyBased = NO;
20461     mt->level = STANDARD_USER;
20462     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
20463
20464     /* Move_RateShape_M */
20465     mt = &moveTypes[i++];
20466     mt->name = "Multiplier";
20467     mt->shortName = "Multiplier";
20468     mt->tuningName[0] = "Multiplier tuning parameter";
20469     mt->shortTuningName[0] = "lambda";
20470     mt->applicableTo[0] = SHAPE_UNI;
20471     mt->applicableTo[1] = SHAPE_EXP;
20472     mt->nApplicable = 2;
20473     mt->moveFxn = &Move_RateShape_M;
20474     mt->relProposalProb = 1.0;
20475     mt->numTuningParams = 1;
20476     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
20477     mt->minimum[0] = 0.0001;
20478     mt->maximum[0] = 10.0;                 /* smaller */
20479     mt->parsimonyBased = NO;
20480     mt->level = STANDARD_USER;
20481     mt->Autotune = &AutotuneMultiplier;
20482     mt->targetRate = 0.25;
20483
20484     /* Move_GeneRate_Dir */
20485     mt = &moveTypes[i++];
20486     mt->name = "Dirichlet proposal";
20487     mt->shortName = "Dirichlet";
20488     mt->tuningName[0] = "Dirichlet parameter";
20489     mt->shortTuningName[0] = "alpha";
20490     mt->applicableTo[0] = GENETREERATEMULT_DIR;
20491     mt->nApplicable = 1;
20492     mt->moveFxn = &Move_GeneRate_Dir;
20493     mt->relProposalProb = 1.0;
20494     mt->numTuningParams = 1;
20495     mt->tuningParam[0] = 1000.0; /* alphaPi */
20496     mt->minimum[0] = 0.001;
20497     mt->maximum[0] = 1000000.0;
20498     mt->parsimonyBased = NO;
20499     mt->level = STANDARD_USER;
20500     mt->Autotune = &AutotuneDirichlet;
20501     mt->targetRate = 0.25;
20502
20503     /* Move_GeneTree1 */
20504     mt = &moveTypes[i++];
20505     mt->name = "Extending SPR move for gene trees in species trees";
20506     mt->shortName = "ExtSPRClockGS";
20507     mt->tuningName[0] = "Extension probability";
20508     mt->shortTuningName[0] = "prob";
20509     mt->applicableTo[0] = TOPOLOGY_SPECIESTREE;
20510     mt->nApplicable = 1;
20511     mt->moveFxn = &Move_GeneTree1;
20512     mt->relProposalProb = 10.0;
20513     mt->numTuningParams = 1;
20514     mt->tuningParam[0] = 0.5;       /* Tuning parameter value */
20515     mt->minimum[0] = 0.00001;       /* Minimum value of tuning param */
20516     mt->maximum[0] = 0.99999;       /* Maximum value of tuning param */
20517     mt->parsimonyBased = NO;        /* It does not use parsimony scores */
20518     mt->level = STANDARD_USER;
20519
20520     /* Move_GeneTree2 */
20521     mt = &moveTypes[i++];
20522     mt->name = "NNI move for gene trees in species trees";
20523     mt->shortName = "NNIClockGS";
20524     mt->applicableTo[0] = TOPOLOGY_SPECIESTREE;
20525     mt->nApplicable = 1;
20526     mt->moveFxn = &Move_GeneTree2;
20527     mt->relProposalProb = 10.0;
20528     mt->numTuningParams = 0;        /* No tuning parameters */
20529     mt->parsimonyBased = NO;        /* It does not use parsimony scores */
20530     mt->level = STANDARD_USER;
20531
20532     /* Move_GeneTree3 */
20533     mt = &moveTypes[i++];
20534     mt->name = "Parsimony-biased SPR for gene trees in species trees";
20535     mt->shortName = "ParsSPRClockGS";
20536     mt->subParams = YES;
20537     mt->tuningName[0] = "parsimony warp factor";
20538     mt->shortTuningName[0] = "warp";
20539     mt->tuningName[1] = "reweighting probability";
20540     mt->shortTuningName[1] = "r";
20541     mt->tuningName[2] = "typical branch length";
20542     mt->shortTuningName[2] = "v_t";
20543     mt->applicableTo[0] = TOPOLOGY_SPECIESTREE;
20544     mt->nApplicable = 1;
20545     mt->moveFxn = &Move_GeneTree3;
20546     mt->relProposalProb = 5.0;
20547     mt->numTuningParams = 3;
20548     mt->tuningParam[0] = 0.1;  /* warp */
20549     mt->tuningParam[1] = 0.05; /* upweight and downweight probability */
20550     mt->tuningParam[2] = 0.05; /* typical branch length */
20551     mt->minimum[0] = 0.0;
20552     mt->maximum[0] = 1.0;
20553     mt->minimum[1] = 0.0;
20554     mt->maximum[1] = 0.3;
20555     mt->minimum[2] = 0.0001;
20556     mt->maximum[2] = 0.5;
20557     mt->parsimonyBased = YES;
20558     mt->level = STANDARD_USER;
20559
20560     /* Move_Growth_M */
20561     mt = &moveTypes[i++];
20562     mt->name = "Multiplier";
20563     mt->shortName = "Multiplier";
20564     mt->tuningName[0] = "Multiplier tuning parameter";
20565     mt->shortTuningName[0] = "lambda";
20566     mt->applicableTo[0] = GROWTH_UNI;
20567     mt->applicableTo[1] = GROWTH_EXP;
20568     mt->applicableTo[2] = GROWTH_NORMAL;
20569     mt->nApplicable = 3;
20570     mt->moveFxn = &Move_Growth_M;
20571     mt->relProposalProb = 1.0;
20572     mt->numTuningParams = 1;
20573     mt->tuningParam[0] = 2.0 * log(1.5);  /* lambda */
20574     mt->minimum[0] = 0.0001;
20575     mt->maximum[0] = 20.0;
20576     mt->parsimonyBased = NO;
20577     mt->level = STANDARD_USER;
20578     mt->Autotune = &AutotuneMultiplier;
20579     mt->targetRate = 0.25;
20580
20581     /* Move_Local */
20582     mt = &moveTypes[i++];
20583     mt->name = "BAMBE's LOCAL";
20584     mt->shortName = "Local";
20585     mt->subParams = YES;
20586     mt->tuningName[0] = "Multiplier tuning parameter";
20587     mt->shortTuningName[0] = "lambda";
20588     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20589     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20590     mt->nApplicable = 2;
20591     mt->moveFxn = &Move_Local;
20592     mt->relProposalProb = 0.0;
20593     mt->numTuningParams = 1;
20594     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
20595     mt->minimum[0] = 0.00001;
20596     mt->maximum[0] = 100.0;
20597     mt->parsimonyBased = NO;
20598     mt->level = STANDARD_USER;
20599     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20600
20601     /* Move_LocalClock */
20602     mt = &moveTypes[i++];
20603     mt->name = "Modified LOCAL for clock trees";
20604     mt->shortName = "LocalClock";
20605     mt->subParams = YES;
20606     mt->tuningName[0] = "Multiplier tuning parameter";
20607     mt->shortTuningName[0] = "lambda";
20608     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20609     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20610     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20611     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20612     mt->nApplicable = 4;
20613     mt->moveFxn = &Move_LocalClock;
20614     mt->relProposalProb = 0.0;
20615     mt->numTuningParams = 1;
20616     mt->tuningParam[0] = 2.0 * log (2.0);  /* lambda */
20617     mt->minimum[0] = 0.00001;
20618     mt->maximum[0] = 100.0;
20619     mt->parsimonyBased = NO;
20620     mt->level = STANDARD_USER;
20621     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20622
20623     /* Move_NNI */
20624     mt = &moveTypes[i++];
20625     mt->name = "NNI move for parsimony trees";
20626     mt->shortName = "ParsNNI";
20627     mt->applicableTo[0] = TOPOLOGY_PARSIMONY_UNIFORM;
20628     mt->applicableTo[1] = TOPOLOGY_PARSIMONY_CONSTRAINED;
20629     mt->nApplicable = 2;
20630     mt->moveFxn = &Move_NNI;
20631     mt->relProposalProb = 10.0;
20632     mt->numTuningParams = 0;
20633     mt->parsimonyBased = NO;    /* no extra parsimony scores are needed */
20634     mt->level = STANDARD_USER;
20635     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20636
20637     /* Move_NNIClock */
20638     mt = &moveTypes[i++];
20639     mt->name = "NNI move for clock trees";
20640     mt->shortName = "NNIClock";
20641     mt->subParams = YES;
20642     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20643     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20644     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20645     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20646     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
20647     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
20648     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
20649     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
20650     mt->nApplicable = 8;
20651     mt->moveFxn = &Move_NNIClock;
20652     mt->relProposalProb = 12.0;
20653     mt->numTuningParams = 0;
20654     mt->parsimonyBased = NO;
20655     mt->level = STANDARD_USER;
20656     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20657
20658     /* Move_NNI */
20659     mt = &moveTypes[i++];
20660     mt->name = "NNI move";
20661     mt->shortName = "NNI";
20662     mt->subParams = YES;
20663     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20664     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20665     mt->nApplicable = 2;
20666     mt->moveFxn = &Move_NNI;
20667     mt->relProposalProb = 5.0;
20668     mt->numTuningParams = 0;
20669     mt->minimum[0] = 0.00001;
20670     mt->maximum[0] = 100.0;
20671     mt->parsimonyBased = NO;
20672     mt->level = STANDARD_USER;
20673     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20674
20675     /* Move_NNI_Hetero */
20676     mt = &moveTypes[i++];
20677     mt->name = "NNI move for trees with independent brlens";
20678     mt->shortName = "MultNNI";
20679     mt->subParams = YES;
20680     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HETERO;
20681     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HETERO;
20682     mt->nApplicable = 2; /* 3; */
20683     mt->moveFxn = &Move_NNI_Hetero;
20684     mt->relProposalProb = 15.0;
20685     mt->numTuningParams = 0;
20686     mt->minimum[0] = 0.00001;
20687     mt->maximum[0] = 100.0;
20688     mt->parsimonyBased = NO;
20689     mt->level = STANDARD_USER;
20690     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20691
20692     /* Move_NodeSlider */
20693     mt = &moveTypes[i++];
20694     mt->name = "Node slider (uniform on possible positions)";
20695     mt->shortName = "Nodeslider";
20696     mt->tuningName[0] = "Multiplier tuning parameter";
20697     mt->shortTuningName[0] = "lambda";
20698     mt->applicableTo[0] = BRLENS_UNI;
20699     mt->applicableTo[1] = BRLENS_EXP;
20700     mt->applicableTo[2] = BRLENS_GamDir;
20701     mt->applicableTo[3] = BRLENS_iGmDir;
20702     mt->applicableTo[4] = BRLENS_twoExp;
20703     mt->nApplicable = 5;  // was 2
20704     mt->moveFxn = &Move_NodeSlider;
20705     mt->relProposalProb = 7.0;
20706     mt->numTuningParams = 1;
20707     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
20708     mt->minimum[0] = 0.00001;
20709     mt->maximum[0] = 100.0;
20710     mt->parsimonyBased = NO;
20711     mt->level = STANDARD_USER;
20712
20713     /* Move_NodeSliderClock */
20714     mt = &moveTypes[i++];
20715     mt->name = "Node depth window slider (clock-constrained)";
20716     mt->shortName = "NodesliderClock";
20717     mt->tuningName[0] = "Window size";
20718     mt->shortTuningName[0] = "delta";
20719     mt->applicableTo[0] = BRLENS_CLOCK_UNI;
20720     mt->applicableTo[1] = BRLENS_CLOCK_COAL;
20721     mt->applicableTo[2] = BRLENS_CLOCK_BD;
20722     mt->applicableTo[3] = BRLENS_CLOCK_FOSSIL;
20723     mt->nApplicable = 4;
20724     mt->moveFxn = &Move_NodeSliderClock;
20725     mt->relProposalProb = 20.0;
20726     mt->numTuningParams = 1;
20727     mt->tuningParam[0] = 0.05; /* window size */
20728     mt->minimum[0] = 0.000001;
20729     mt->maximum[0] = 1.0;
20730     mt->parsimonyBased = NO;
20731     mt->level = STANDARD_USER;
20732     mt->Autotune = &AutotuneSlider;
20733     mt->targetRate = 0.25;
20734
20735     /* Move_NodeSliderGeneTree */
20736     mt = &moveTypes[i++];
20737     mt->name = "Node depth slider for gene trees";
20738     mt->shortName = "NodesliderGenetree";
20739     mt->tuningName[0] = "Window size";
20740     mt->shortTuningName[0] = "delta";
20741     mt->applicableTo[0] = BRLENS_CLOCK_SPCOAL;
20742     mt->nApplicable = 1;
20743     mt->moveFxn = &Move_NodeSliderGeneTree;
20744     mt->relProposalProb = 20.0;
20745     mt->numTuningParams = 1;
20746     mt->tuningParam[0] = 0.05; /* window size */
20747     mt->minimum[0] = 0.000001;
20748     mt->maximum[0] = 100.0;
20749     mt->parsimonyBased = NO;
20750     mt->level = STANDARD_USER;
20751     mt->Autotune = &AutotuneSlider;
20752     mt->targetRate = 0.25;
20753
20754     /* Move_Omega */
20755     mt = &moveTypes[i++];
20756     mt->name = "Sliding window";
20757     mt->shortName = "Slider";
20758     mt->tuningName[0] = "Sliding window size";
20759     mt->shortTuningName[0] = "delta";
20760     mt->applicableTo[0] = OMEGA_DIR;
20761     mt->nApplicable = 1;
20762     mt->moveFxn = &Move_Omega;
20763     mt->relProposalProb = 1.0;
20764     mt->numTuningParams = 1;
20765     mt->tuningParam[0] = 1.0; /* sliding window size */
20766     mt->minimum[0] = 0.000001;
20767     mt->maximum[0] = 100.0;
20768     mt->parsimonyBased = NO;
20769     mt->level = STANDARD_USER;
20770     mt->Autotune = &AutotuneSlider;
20771     mt->targetRate = 0.25;
20772
20773     /* Move_Omega_M */
20774     mt = &moveTypes[i++];
20775     mt->name = "Multiplier";
20776     mt->shortName = "Multiplier";
20777     mt->tuningName[0] = "Multiplier tuning parameter";
20778     mt->shortTuningName[0] = "lambda";
20779     mt->applicableTo[0] = OMEGA_DIR;
20780     mt->nApplicable = 1;
20781     mt->moveFxn = &Move_Omega_M;
20782     mt->relProposalProb = 0.0;
20783     mt->numTuningParams = 1;
20784     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
20785     mt->minimum[0] = 0.0001;
20786     mt->maximum[0] = 20.0;                 /* smaller */
20787     mt->parsimonyBased = NO;
20788     mt->level = STANDARD_USER;
20789     mt->Autotune = &AutotuneMultiplier;
20790     mt->targetRate = 0.25;
20791
20792     /* Move_OmegaBeta_M */
20793     mt = &moveTypes[i++];
20794     mt->name = "Multiplier";
20795     mt->shortName = "Multiplier";
20796     mt->paramName = "Omega_beta_M10";
20797     mt->tuningName[0] = "Multiplier tuning parameter";
20798     mt->shortTuningName[0] = "lambda";
20799     mt->applicableTo[0] = OMEGA_10UUB;
20800     mt->applicableTo[1] = OMEGA_10UUF;
20801     mt->applicableTo[2] = OMEGA_10UEB;
20802     mt->applicableTo[3] = OMEGA_10UEF;
20803     mt->applicableTo[4] = OMEGA_10UFB;
20804     mt->applicableTo[5] = OMEGA_10UFF;
20805     mt->applicableTo[6] = OMEGA_10EUB;
20806     mt->applicableTo[7] = OMEGA_10EUF;
20807     mt->applicableTo[8] = OMEGA_10EEB;
20808     mt->applicableTo[9] = OMEGA_10EEF;
20809     mt->applicableTo[10] = OMEGA_10EFB;
20810     mt->applicableTo[11] = OMEGA_10EFF;
20811     mt->nApplicable = 12;
20812     mt->moveFxn = &Move_OmegaBeta_M;
20813     mt->relProposalProb = 1.0;
20814     mt->numTuningParams = 1;
20815     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
20816     mt->minimum[0] = 0.0001;
20817     mt->maximum[0] = 20.0;                 /* smaller */
20818     mt->parsimonyBased = NO;
20819     mt->level = STANDARD_USER;
20820     mt->Autotune = &AutotuneMultiplier;
20821     mt->targetRate = 0.25;
20822
20823     /* Move_OmegaCat */
20824     mt = &moveTypes[i++];
20825     mt->name = "Dirichlet proposal";
20826     mt->shortName = "Dirichlet";
20827     mt->paramName = "Omega_pi";
20828     mt->tuningName[0] = "Dirichlet parameter";
20829     mt->shortTuningName[0] = "alpha";
20830     mt->applicableTo[0] = OMEGA_BUD;
20831     mt->applicableTo[1] = OMEGA_BED;
20832     mt->applicableTo[2] = OMEGA_BFD;
20833     mt->applicableTo[3] = OMEGA_FUD;
20834     mt->applicableTo[4] = OMEGA_FED;
20835     mt->applicableTo[5] = OMEGA_FFD;
20836     mt->applicableTo[6] = OMEGA_ED;
20837     mt->applicableTo[7] = OMEGA_FD;
20838     mt->applicableTo[8] = OMEGA_10UUB;
20839     mt->applicableTo[9] = OMEGA_10UEB;
20840     mt->applicableTo[10] = OMEGA_10UFB;
20841     mt->applicableTo[11] = OMEGA_10EUB;
20842     mt->applicableTo[12] = OMEGA_10EEB;
20843     mt->applicableTo[13] = OMEGA_10EFB;
20844     mt->applicableTo[14] = OMEGA_10FUB;
20845     mt->applicableTo[15] = OMEGA_10FEB;
20846     mt->applicableTo[16] = OMEGA_10FFB;
20847     mt->nApplicable = 17;
20848     mt->moveFxn = &Move_OmegaCat;
20849     mt->relProposalProb = 1.0;
20850     mt->numTuningParams = 1;
20851     mt->tuningParam[0] = 300.0;  /* alpha-pi */
20852     mt->minimum[0] = 0.001;
20853     mt->maximum[0] = 10000.0;
20854     mt->parsimonyBased = NO;
20855     mt->level = STANDARD_USER;
20856     mt->Autotune = &AutotuneDirichlet;
20857     mt->targetRate = 0.25;
20858
20859     /* Move_OmegaGamma_M */
20860     mt = &moveTypes[i++];
20861     mt->name = "Multiplier";
20862     mt->shortName = "Multiplier";
20863     mt->paramName = "Omega_shape_M10";
20864     mt->tuningName[0] = "Multiplier tuning parameter";
20865     mt->shortTuningName[0] = "lambda";
20866     mt->applicableTo[0] = OMEGA_10UUB;
20867     mt->applicableTo[1] = OMEGA_10UUF;
20868     mt->applicableTo[2] = OMEGA_10UEB;
20869     mt->applicableTo[3] = OMEGA_10UEF;
20870     mt->applicableTo[4] = OMEGA_10EUB;
20871     mt->applicableTo[5] = OMEGA_10EUF;
20872     mt->applicableTo[6] = OMEGA_10EEB;
20873     mt->applicableTo[7] = OMEGA_10EEF;
20874     mt->applicableTo[8] = OMEGA_10FUB;
20875     mt->applicableTo[9] = OMEGA_10FUF;
20876     mt->applicableTo[10] = OMEGA_10FEB;
20877     mt->applicableTo[11] = OMEGA_10FEF;
20878     mt->nApplicable = 12;
20879     mt->moveFxn = &Move_OmegaGamma_M;
20880     mt->relProposalProb = 1.0;
20881     mt->numTuningParams = 1;
20882     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
20883     mt->minimum[0] = 0.0001;
20884     mt->maximum[0] = 20.0;                 /* smaller */
20885     mt->parsimonyBased = NO;
20886     mt->level = STANDARD_USER;
20887     mt->Autotune = &AutotuneMultiplier;
20888     mt->targetRate = 0.25;
20889
20890     /* Move_OmegaM3 */
20891     mt = &moveTypes[i++];
20892     mt->name = "Sliding window";
20893     mt->shortName = "Slider";
20894     mt->tuningName[0] = "Sliding window size";
20895     mt->shortTuningName[0] = "delta";
20896     mt->applicableTo[0] = OMEGA_ED;
20897     mt->applicableTo[1] = OMEGA_EF;
20898     mt->nApplicable = 2;
20899     mt->moveFxn = &Move_OmegaM3;
20900     mt->relProposalProb = 1.0;
20901     mt->numTuningParams = 1;
20902     mt->tuningParam[0] = 0.1;  /* window size */
20903     mt->minimum[0] = 0.00001;
20904     mt->maximum[0] = 1.0;
20905     mt->parsimonyBased = NO;
20906     mt->level = STANDARD_USER;
20907     mt->Autotune = &AutotuneSlider;
20908     mt->targetRate = 0.25;
20909
20910     /* Move_OmegaPur : Let it be here so that omega moves are listed in logical order! */
20911     mt = &moveTypes[i++];
20912     mt->name = "Sliding window";
20913     mt->shortName = "Slider";
20914     mt->paramName = "Omega_pur";
20915     mt->tuningName[0] = "Sliding window size";
20916     mt->shortTuningName[0] = "delta";
20917     mt->applicableTo[0] = OMEGA_BUD;
20918     mt->applicableTo[1] = OMEGA_BUF;
20919     mt->applicableTo[2] = OMEGA_BED;
20920     mt->applicableTo[3] = OMEGA_BEF;
20921     mt->applicableTo[4] = OMEGA_BFD;
20922     mt->applicableTo[5] = OMEGA_BFF;
20923     mt->nApplicable = 6;
20924     mt->moveFxn = &Move_OmegaPur;
20925     mt->relProposalProb = 1.0;
20926     mt->numTuningParams = 1;
20927     mt->tuningParam[0] = 0.1;  /* window size */
20928     mt->minimum[0] = 0.00001;
20929     mt->maximum[0] = 1.0;
20930     mt->parsimonyBased = NO;
20931     mt->level = STANDARD_USER;
20932     mt->Autotune = &AutotuneSlider;
20933     mt->targetRate = 0.25;
20934
20935     /* Move_OmegaPos */
20936     mt = &moveTypes[i++];
20937     mt->name = "Sliding window";
20938     mt->shortName = "Slider";
20939     mt->paramName = "Omega_pos";
20940     mt->tuningName[0] = "Sliding window size";
20941     mt->shortTuningName[0] = "delta";
20942     mt->applicableTo[0] = OMEGA_BUD;
20943     mt->applicableTo[1] = OMEGA_BUF;
20944     mt->applicableTo[2] = OMEGA_BED;
20945     mt->applicableTo[3] = OMEGA_BEF;
20946     mt->applicableTo[4] = OMEGA_FUD;
20947     mt->applicableTo[5] = OMEGA_FUF;
20948     mt->applicableTo[6] = OMEGA_FED;
20949     mt->applicableTo[7] = OMEGA_FEF;
20950     mt->nApplicable = 8;
20951     mt->moveFxn = &Move_OmegaPos;
20952     mt->relProposalProb = 1.0;
20953     mt->numTuningParams = 1;
20954     mt->tuningParam[0] = 1.0;  /* window size */
20955     mt->minimum[0] = 0.00001;
20956     mt->maximum[0] = 100.0;
20957     mt->parsimonyBased = NO;
20958     mt->level = STANDARD_USER;
20959     mt->Autotune = &AutotuneSlider;
20960     mt->targetRate = 0.25;
20961
20962     /* Move_ParsEraser1 */
20963     mt = &moveTypes[i++];
20964     mt->name = "Parsimony-biased eraser version 1";
20965     mt->shortName = "pEraser1";
20966     mt->subParams = YES;
20967     mt->tuningName[0] = "Dirichlet parameter";
20968     mt->shortTuningName[0] = "alpha";
20969     mt->tuningName[1] = "parsimony warp factor";
20970     mt->shortTuningName[1] = "warp";
20971     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20972     mt->nApplicable = 1;
20973     mt->moveFxn = &Move_ParsEraser1;
20974     mt->relProposalProb = 0.0;
20975     mt->numTuningParams = 2;
20976     mt->tuningParam[0] = 0.5; /* alphaPi */
20977     mt->tuningParam[1] = 0.1; /* warp */
20978     mt->minimum[0] = 0.00001;
20979     mt->maximum[0] = 10000.0;
20980     mt->minimum[1] = 0.00001;
20981     mt->maximum[1] = 0.99999;
20982     mt->parsimonyBased = YES;
20983     mt->level = DEVELOPER;
20984     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
20985
20986     /* Move_ParsSPR asym */
20987     mt = &moveTypes[i++];
20988     mt->name = "Parsimony-biased SPR";
20989     mt->shortName = "ParsSPR";
20990     mt->subParams = YES;
20991     mt->tuningName[0] = "parsimony warp factor";
20992     mt->shortTuningName[0] = "warp";
20993     mt->tuningName[1] = "reweighting probability";
20994     mt->shortTuningName[1] = "r";
20995     mt->tuningName[2] = "typical branch length";
20996     mt->shortTuningName[2] = "v_t";
20997     mt->tuningName[3] = "multiplier tuning parameter";
20998     mt->shortTuningName[3] = "lambda";
20999     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21000     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21001     mt->nApplicable = 2;
21002     mt->moveFxn = &Move_ParsSPR;
21003     mt->relProposalProb = 5.0;
21004     mt->numTuningParams = 4;
21005     mt->tuningParam[0] = 0.1;              /* warp */
21006     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21007     mt->tuningParam[2] = 0.03;             /* typical branch length */
21008     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21009     mt->minimum[0] = 0.0;
21010     mt->maximum[0] = 1.0;
21011     mt->minimum[1] = 0.0;
21012     mt->maximum[1] = 0.3;
21013     mt->minimum[2] = 0.0001;
21014     mt->maximum[2] = 0.5;
21015     mt->minimum[3] = 2.0 * log (0.001);
21016     mt->maximum[3] = 2.0 * log (1000.);
21017     mt->parsimonyBased = YES;
21018     mt->level = STANDARD_USER;
21019     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21020
21021     /* Move_ParsSPR1 e^{-S} */
21022     mt = &moveTypes[i++];
21023     mt->name = "Parsimony-biased SPR variant 1";
21024     mt->shortName = "ParsSPR1";
21025     mt->subParams = YES;
21026     mt->tuningName[0] = "parsimony warp factor";
21027     mt->shortTuningName[0] = "warp";
21028     mt->tuningName[1] = "reweighting probability";
21029     mt->shortTuningName[1] = "r";
21030     mt->tuningName[2] = "typical branch length";
21031     mt->shortTuningName[2] = "v_t";
21032     mt->tuningName[3] = "multiplier tuning parameter";
21033     mt->shortTuningName[3] = "lambda";
21034     mt->tuningName[4] = "moving distance";
21035     mt->shortTuningName[4] = "d";
21036     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21037     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21038     mt->nApplicable = 2;
21039     mt->moveFxn = &Move_ParsSPR1;
21040     mt->relProposalProb = 0.0;
21041     mt->numTuningParams = 5;
21042     mt->tuningParam[0] = 0.5;              /* warp */
21043     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21044     mt->tuningParam[2] = 0.03;             /* typical branch length */
21045     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21046     mt->tuningParam[4] = 10.0;             /* distance to move picked branch */
21047     mt->minimum[0] = 0.0;
21048     mt->maximum[0] = 5.0;
21049     mt->minimum[1] = 0.0;
21050     mt->maximum[1] = 0.3;
21051     mt->minimum[2] = 0.0001;
21052     mt->maximum[2] = 0.5;
21053     mt->minimum[3] = 2.0 * log (0.001);
21054     mt->maximum[3] = 2.0 * log (1000.);
21055     mt->minimum[4] = 2.0;
21056     mt->maximum[4] = 1000.0;
21057     mt->parsimonyBased = YES;
21058     mt->level = DEVELOPER;
21059     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21060
21061     /* Move_ParsSPR2 S/N */
21062     mt = &moveTypes[i++];
21063     mt->name = "Parsimony-biased SPR variant 2";
21064     mt->shortName = "ParsSPR2";
21065     mt->subParams = YES;
21066     mt->tuningName[0] = "parsimony warp factor";
21067     mt->shortTuningName[0] = "warp";
21068     mt->tuningName[1] = "reweighting probability";
21069     mt->shortTuningName[1] = "r";
21070     mt->tuningName[2] = "typical branch length";
21071     mt->shortTuningName[2] = "v_t";
21072     mt->tuningName[3] = "multiplier tuning parameter";
21073     mt->shortTuningName[3] = "lambda";
21074     mt->tuningName[4] = "moving distance";
21075     mt->shortTuningName[4] = "d";
21076     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21077     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21078     mt->nApplicable = 2;
21079     mt->moveFxn = &Move_ParsSPR2;
21080     mt->relProposalProb = 0.0;
21081     mt->numTuningParams = 5;
21082     mt->tuningParam[0] = 0.1;              /* warp */
21083     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21084     mt->tuningParam[2] = 0.03;             /* typical branch length */
21085     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21086     mt->tuningParam[4] = 10.0;             /* distance to move picked branch */
21087     mt->minimum[0] = 0.0;
21088     mt->maximum[0] = 1.0;
21089     mt->minimum[1] = 0.0;
21090     mt->maximum[1] = 0.3;
21091     mt->minimum[2] = 0.0001;
21092     mt->maximum[2] = 0.5;
21093     mt->minimum[3] = 2.0 * log (0.001);
21094     mt->maximum[3] = 2.0 * log (1000.);
21095     mt->minimum[4] = 2.0;
21096     mt->maximum[4] = 1000.0;
21097     mt->parsimonyBased = YES;
21098     mt->level = DEVELOPER;
21099     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21100
21101     /* Move_ParsSPRClock */
21102     mt = &moveTypes[i++];
21103     mt->name = "Parsimony-biased SPR for clock trees";
21104     mt->shortName = "ParsSPRClock";
21105     mt->subParams = YES;
21106     mt->tuningName[0] = "parsimony warp factor";
21107     mt->shortTuningName[0] = "warp";
21108     mt->tuningName[1] = "reweighting probability";
21109     mt->shortTuningName[1] = "r";
21110     mt->tuningName[2] = "typical branch length";
21111     mt->shortTuningName[2] = "v_t";
21112     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
21113     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
21114     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
21115     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
21116     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
21117     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
21118     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
21119     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
21120     mt->nApplicable = 8;
21121     mt->moveFxn = &Move_ParsSPRClock;
21122     mt->relProposalProb = 8.0;
21123     mt->numTuningParams = 3;
21124     mt->tuningParam[0] = 0.1;  /* warp */
21125     mt->tuningParam[1] = 0.05; /* upweight and downweight probability */
21126     mt->tuningParam[2] = 0.03; /* typical branch length */
21127     mt->minimum[0] = 0.0;
21128     mt->maximum[0] = 1.0;
21129     mt->minimum[1] = 0.0;
21130     mt->maximum[1] = 0.3;
21131     mt->minimum[2] = 0.0001;
21132     mt->maximum[2] = 0.5;
21133     mt->parsimonyBased = YES;
21134     mt->level = STANDARD_USER;
21135     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
21136
21137     /* Move_ParsTBR1 e^{-S} */
21138     mt = &moveTypes[i++];
21139     mt->name = "Parsimony-biased TBR variant 1";
21140     mt->shortName = "ParsTBR1";
21141     mt->subParams = YES;
21142     mt->tuningName[0] = "parsimony warp factor";
21143     mt->shortTuningName[0] = "warp";
21144     mt->tuningName[1] = "reweighting probability";
21145     mt->shortTuningName[1] = "r";
21146     mt->tuningName[2] = "typical branch length";
21147     mt->shortTuningName[2] = "v_t";
21148     mt->tuningName[3] = "multiplier tuning parameter";
21149     mt->shortTuningName[3] = "lambda";
21150     mt->tuningName[4] = "moving distance";
21151     mt->shortTuningName[4] = "d";
21152     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21153     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21154     mt->nApplicable = 2;
21155     mt->moveFxn = &Move_ParsTBR1;
21156     mt->relProposalProb = 0.0;
21157     mt->numTuningParams = 5;
21158     mt->tuningParam[0] = 0.5;              /* warp */
21159     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21160     mt->tuningParam[2] = 0.05;             /* typical branch length */
21161     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21162     mt->tuningParam[4] = 5.0;              /* distance to move picked branch */
21163     mt->minimum[0] = 0.0;
21164     mt->maximum[0] = 5.0;
21165     mt->minimum[1] = 0.0;
21166     mt->maximum[1] = 0.3;
21167     mt->minimum[2] = 0.0001;
21168     mt->maximum[2] = 0.5;
21169     mt->minimum[3] = 2.0 * log (0.001);
21170     mt->maximum[3] = 2.0 * log (1000.);
21171     mt->minimum[4] = 2.0;
21172     mt->maximum[4] = 1000.0;
21173     mt->parsimonyBased = YES;
21174     mt->level = DEVELOPER;
21175     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
21176
21177     /* Move_ParsTBR2 S/N */
21178     mt = &moveTypes[i++];
21179     mt->name = "Parsimony-biased TBR variant 2";
21180     mt->shortName = "ParsTBR2";
21181     mt->subParams = YES;
21182     mt->tuningName[0] = "parsimony warp factor";
21183     mt->shortTuningName[0] = "warp";
21184     mt->tuningName[1] = "reweighting probability";
21185     mt->shortTuningName[1] = "r";
21186     mt->tuningName[2] = "typical branch length";
21187     mt->shortTuningName[2] = "v_t";
21188     mt->tuningName[3] = "multiplier tuning parameter";
21189     mt->shortTuningName[3] = "lambda";
21190     mt->tuningName[4] = "moving distance";
21191     mt->shortTuningName[4] = "d";
21192     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21193     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21194     mt->nApplicable = 2;
21195     mt->moveFxn = &Move_ParsTBR2;
21196     mt->relProposalProb = 0.0;
21197     mt->numTuningParams = 5;
21198     mt->tuningParam[0] = 0.1;              /* warp */
21199     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21200     mt->tuningParam[2] = 0.05;             /* typical branch length */
21201     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21202     mt->tuningParam[4] = 5.0;              /* distance to move picked branch */
21203     mt->minimum[0] = 0.0;
21204     mt->maximum[0] = 1.0;
21205     mt->minimum[1] = 0.0;
21206     mt->maximum[1] = 0.3;
21207     mt->minimum[2] = 0.0001;
21208     mt->maximum[2] = 0.5;
21209     mt->minimum[3] = 2.0 * log (0.001);
21210     mt->maximum[3] = 2.0 * log (1000.);
21211     mt->minimum[4] = 2.0;
21212     mt->maximum[4] = 1000.0;
21213     mt->parsimonyBased = YES;
21214     mt->level = DEVELOPER;
21215     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
21216
21217     /* Move_Pinvar */
21218     mt = &moveTypes[i++];
21219     mt->name = "Sliding window";
21220     mt->shortName = "Slider";
21221     mt->tuningName[0] = "Sliding window size";
21222     mt->shortTuningName[0] = "delta";
21223     mt->applicableTo[0] = PINVAR_UNI;
21224     mt->nApplicable = 1;
21225     mt->moveFxn = &Move_Pinvar;
21226     mt->relProposalProb = 1.0;
21227     mt->numTuningParams = 1;
21228     mt->tuningParam[0] = 0.1;  /* window size */
21229     mt->minimum[0] = 0.001;
21230     mt->maximum[0] = 0.999;
21231     mt->parsimonyBased = NO;
21232     mt->level = STANDARD_USER;
21233     mt->Autotune = &AutotuneSlider;
21234     mt->targetRate = 0.25;
21235
21236     /* Move_Popsize_M */
21237     mt = &moveTypes[i++];
21238     mt->name = "Multiplier";
21239     mt->shortName = "Multiplier";
21240     mt->tuningName[0] = "Multiplier tuning parameter";
21241     mt->shortTuningName[0] = "lambda";
21242     mt->applicableTo[0] = POPSIZE_UNI;
21243     mt->applicableTo[1] = POPSIZE_LOGNORMAL;
21244     mt->applicableTo[2] = POPSIZE_NORMAL;
21245     mt->applicableTo[3] = POPSIZE_GAMMA;
21246     mt->nApplicable = 4;
21247     mt->moveFxn = &Move_PopSize_M;
21248     mt->relProposalProb = 1.0;
21249     mt->numTuningParams = 1;
21250     mt->tuningParam[0] = 2.0 * log(1.5);  /* lambda */
21251     mt->minimum[0] = 0.00001;
21252     mt->maximum[0] = 100.0;
21253     mt->parsimonyBased = NO;
21254     mt->level = STANDARD_USER;
21255     mt->Autotune = &AutotuneSlider;
21256     mt->targetRate = 0.25;
21257
21258     /* Move_RateMult_Dir */
21259     mt = &moveTypes[i++];
21260     mt->name = "Dirichlet proposal";
21261     mt->shortName = "Dirichlet";
21262     mt->tuningName[0] = "Dirichlet parameter";
21263     mt->shortTuningName[0] = "alpha";
21264     mt->applicableTo[0] = RATEMULT_DIR;
21265     mt->nApplicable = 1;
21266     mt->moveFxn = &Move_RateMult_Dir;
21267     mt->relProposalProb = 0.75;
21268     mt->numTuningParams = 1;
21269     mt->tuningParam[0] = 50.0; /* alphaPi per site */
21270     mt->minimum[0] = 0.001;
21271     mt->maximum[0] = 10000.0;
21272     mt->parsimonyBased = NO;
21273     mt->level = STANDARD_USER;
21274     mt->Autotune = &AutotuneDirichlet;
21275     mt->targetRate = 0.25;
21276
21277     /* Move_RateMult_Slider */
21278     mt = &moveTypes[i++];
21279     mt->name = "Sliding window";
21280     mt->shortName = "Slider";
21281     mt->tuningName[0] = "Sliding window size";
21282     mt->shortTuningName[0] = "delta";
21283     mt->applicableTo[0] = RATEMULT_DIR;
21284     mt->nApplicable = 1;
21285     mt->moveFxn = &Move_RateMult_Slider;
21286     mt->relProposalProb = 0.75;
21287     mt->numTuningParams = 1;
21288     mt->tuningParam[0] = 0.05;  /* window size */
21289     mt->minimum[0] = 0.00001;
21290     mt->maximum[0] = 1.0;
21291     mt->parsimonyBased = NO;
21292     mt->level = STANDARD_USER;
21293     mt->Autotune = &AutotuneSlider;
21294     mt->targetRate = 0.25;
21295
21296     /* Move_Revmat_Dir */
21297     mt = &moveTypes[i++];
21298     mt->name = "Dirichlet proposal";
21299     mt->shortName = "Dirichlet";
21300     mt->tuningName[0] = "Dirichlet parameter";
21301     mt->shortTuningName[0] = "alpha";
21302     mt->applicableTo[0] = REVMAT_DIR;
21303     mt->nApplicable = 1;
21304     mt->moveFxn = &Move_Revmat_Dir;
21305     mt->relProposalProb = 0.5;
21306     mt->numTuningParams = 1;
21307     mt->tuningParam[0] = 100.0;  /* alphaPi per rate */
21308     mt->minimum[0] = 0.001;
21309     mt->maximum[0] = 10000.0;
21310     mt->parsimonyBased = NO;
21311     mt->level = STANDARD_USER;
21312     mt->Autotune = &AutotuneDirichlet;
21313     mt->targetRate = 0.25;
21314
21315     /* Move_Revmat_Slider */
21316     mt = &moveTypes[i++];
21317     mt->name = "Sliding window";
21318     mt->shortName = "Slider";
21319     mt->tuningName[0] = "Sliding window size";
21320     mt->shortTuningName[0] = "delta";
21321     mt->applicableTo[0] = REVMAT_DIR;
21322     mt->nApplicable = 1;
21323     mt->moveFxn = &Move_Revmat_Slider;
21324     mt->relProposalProb = 0.5;
21325     mt->numTuningParams = 1;
21326     mt->tuningParam[0] = 0.15;  /* window size */
21327     mt->minimum[0] = 0.00001;
21328     mt->maximum[0] = 1.0;
21329     mt->parsimonyBased = NO;
21330     mt->level = STANDARD_USER;
21331     mt->Autotune = &AutotuneSlider;
21332     mt->targetRate = 0.25;
21333
21334     /* Move_Revmat_DirMix */
21335     mt = &moveTypes[i++];
21336     mt->name = "Dirichlet proposal";
21337     mt->shortName = "Dirichlet";
21338     mt->tuningName[0] = "Dirichlet parameter";
21339     mt->shortTuningName[0] = "alpha";
21340     mt->applicableTo[0] = REVMAT_MIX;
21341     mt->nApplicable = 1;
21342     mt->moveFxn = &Move_Revmat_DirMix;
21343     mt->relProposalProb = 1.0;
21344     mt->numTuningParams = 1;
21345     mt->tuningParam[0] = 100.0;  /* alphaPi per rate */
21346     mt->minimum[0] = 0.01;
21347     mt->maximum[0] = 10000.0;
21348     mt->parsimonyBased = NO;
21349     mt->level = STANDARD_USER;
21350     mt->Autotune = &AutotuneDirichlet;
21351     mt->targetRate = 0.25;
21352     
21353     /* Move_Revmat_SplitMerge1 */
21354     mt = &moveTypes[i++];
21355     mt->name = "Split-merge move 1";
21356     mt->shortName = "Splitmerge1";
21357     mt->tuningName[0] = "Dirichlet parameter";
21358     mt->shortTuningName[0] = "alpha";
21359     mt->applicableTo[0] = REVMAT_MIX;
21360     mt->nApplicable = 1;
21361     mt->moveFxn = &Move_Revmat_SplitMerge1;
21362     mt->relProposalProb = 1.0;
21363     mt->numTuningParams = 1;
21364     mt->tuningParam[0] = 10.0;  /* alphaPi per rate */
21365     mt->minimum[0] = 0.5;
21366     mt->maximum[0] = 100.0;
21367     mt->parsimonyBased = NO;
21368     mt->level = STANDARD_USER;
21369     mt->Autotune = &AutotuneDirichlet;
21370     mt->targetRate = 0.25;
21371
21372     /* Move_Revmat_SplitMerge2 */
21373     mt = &moveTypes[i++];
21374     mt->name = "Split-merge move 2";
21375     mt->shortName = "Splitmerge2";
21376     mt->tuningName[0] = "Dirichlet parameter";
21377     mt->shortTuningName[0] = "alpha";
21378     mt->applicableTo[0] = REVMAT_MIX;
21379     mt->nApplicable = 1;
21380     mt->moveFxn = &Move_Revmat_SplitMerge2;
21381     mt->relProposalProb = 1.0;
21382     mt->numTuningParams = 1;
21383     mt->tuningParam[0] = 10.0;  /* alphaPi per rate */
21384     mt->minimum[0] = 0.5;
21385     mt->maximum[0] = 100.0;
21386     mt->parsimonyBased = NO;
21387     mt->level = STANDARD_USER;
21388     mt->Autotune = &AutotuneDirichlet;
21389     mt->targetRate = 0.25;
21390
21391     /* Move_Speciation */
21392     mt = &moveTypes[i++];
21393     mt->name = "Sliding window";
21394     mt->shortName = "Slider";
21395     mt->tuningName[0] = "Sliding window size";
21396     mt->shortTuningName[0] = "delta";
21397     mt->applicableTo[0] = SPECRATE_UNI;
21398     mt->applicableTo[1] = SPECRATE_EXP;
21399     mt->nApplicable = 2;
21400     mt->moveFxn = &Move_Speciation;
21401     mt->relProposalProb = 0.0;
21402     mt->numTuningParams = 1;
21403     mt->tuningParam[0] = 1.0;  /* window size */
21404     mt->minimum[0] = 0.00001;
21405     mt->maximum[0] = 100.0;
21406     mt->parsimonyBased = NO;
21407     mt->level = STANDARD_USER;
21408     mt->Autotune = &AutotuneSlider;
21409     mt->targetRate = 0.25;
21410
21411     /* Move_Speciation_M */
21412     mt = &moveTypes[i++];
21413     mt->name = "Multiplier";
21414     mt->shortName = "Multiplier";
21415     mt->tuningName[0] = "Multiplier tuning parameter";
21416     mt->shortTuningName[0] = "lambda";
21417     mt->applicableTo[0] = SPECRATE_UNI;
21418     mt->applicableTo[1] = SPECRATE_EXP;
21419     mt->nApplicable = 2;
21420     mt->moveFxn = &Move_Speciation_M;
21421     mt->relProposalProb = 3.0;
21422     mt->numTuningParams = 1;
21423     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21424     mt->minimum[0] = 0.00001;
21425     mt->maximum[0] = 20.0;                 /* smaller */
21426     mt->parsimonyBased = NO;
21427     mt->level = STANDARD_USER;
21428     mt->Autotune = &AutotuneMultiplier;
21429     mt->targetRate = 0.25;
21430
21431     /* Move_SpeciesTree */
21432     mt = &moveTypes[i++];
21433     mt->name = "Species tree move";
21434     mt->shortName = "Distmatrixmove";
21435     mt->tuningName[0] = "Divider of rate of truncated exponential";
21436     mt->shortTuningName[0] = "lambdadiv";
21437     mt->applicableTo[0] = SPECIESTREE_UNIFORM;
21438     mt->nApplicable = 1;
21439     mt->moveFxn = &Move_SpeciesTree;
21440     mt->relProposalProb = 10.0;
21441     mt->numTuningParams = 1;
21442     mt->tuningParam[0] = 1.2;       /* Default tuning parameter value */
21443     mt->minimum[0] = 0.00001;       /* Minimum value of tuning param */
21444     mt->maximum[0] = 1000.0;        /* Maximum value of tuning param */
21445     mt->parsimonyBased = NO;        /* It does not use parsimony scores */
21446     mt->level = STANDARD_USER;
21447     mt->Autotune = &AutotuneMultiplier; /* Autotune this move as a mutliplier move (larger is more bold) */
21448     mt->targetRate = 0.25;              /* Target acceptance rate */
21449
21450     /* Move_Statefreqs */
21451     mt = &moveTypes[i++];
21452     mt->name = "Dirichlet proposal";
21453     mt->shortName = "Dirichlet";
21454     mt->tuningName[0] = "Dirichlet parameter";
21455     mt->shortTuningName[0] = "alpha";
21456     mt->applicableTo[0] = PI_DIR;
21457     mt->nApplicable = 1;
21458     mt->moveFxn = &Move_Statefreqs;
21459     mt->relProposalProb = 0.5;
21460     mt->numTuningParams = 1;
21461     mt->tuningParam[0] = 100.0; /* alphaPi per state */
21462     mt->minimum[0] = 0.001;
21463     mt->maximum[0] = 10000.0;
21464     mt->parsimonyBased = NO;
21465     mt->level = STANDARD_USER;
21466     mt->Autotune = &AutotuneDirichlet;
21467     mt->targetRate = 0.25;
21468
21469     /* Move_Statefreqs_Slider */
21470     mt = &moveTypes[i++];
21471     mt->name = "Sliding window";
21472     mt->shortName = "Slider";
21473     mt->tuningName[0] = "Sliding window size";
21474     mt->shortTuningName[0] = "delta";
21475     mt->applicableTo[0] = PI_DIR;
21476     mt->nApplicable = 1;
21477     mt->moveFxn = &Move_Statefreqs_Slider;
21478     mt->relProposalProb = 0.5;
21479     mt->numTuningParams = 1;
21480     mt->tuningParam[0] = 0.20;  /* window size (change in proportions) */
21481     mt->minimum[0] = 0.00001;
21482     mt->maximum[0] = 1.0;
21483     mt->parsimonyBased = NO;
21484     mt->level = STANDARD_USER;
21485     mt->Autotune = &AutotuneSlider;
21486     mt->targetRate = 0.25;
21487
21488     /* Move_StatefreqsSymDirMultistate */
21489     mt = &moveTypes[i++];
21490     mt->name = "Dirichlet proposal";
21491     mt->shortName = "Dirichlet";
21492     mt->paramName = "Pi_symdir";
21493     mt->tuningName[0] = "Dirichlet parameter";
21494     mt->shortTuningName[0] = "alpha";
21495     mt->applicableTo[0] = SYMPI_FIX_MS;
21496     mt->applicableTo[1] = SYMPI_UNI_MS;
21497     mt->applicableTo[2] = SYMPI_EXP_MS;
21498     mt->nApplicable = 3;
21499     mt->moveFxn = &Move_StatefreqsSymDirMultistate;
21500     mt->relProposalProb = 5.0;
21501     mt->numTuningParams = 1;
21502     mt->tuningParam[0] = 50.0; /* alphaPi */
21503     mt->minimum[0] = 0.001;
21504     mt->maximum[0] = 10000.0;
21505     mt->parsimonyBased = NO;
21506     mt->level = STANDARD_USER;
21507     mt->Autotune = &AutotuneDirichlet;
21508     mt->targetRate = 0.25;
21509
21510     /* Move_SwitchRate */
21511     mt = &moveTypes[i++];
21512     mt->name = "Sliding window";
21513     mt->shortName = "Slider";
21514     mt->tuningName[0] = "Sliding window size";
21515     mt->shortTuningName[0] = "delta";
21516     mt->applicableTo[0] = SWITCH_UNI;
21517     mt->applicableTo[1] = SWITCH_EXP;
21518     mt->nApplicable = 2;
21519     mt->moveFxn = &Move_SwitchRate;
21520     mt->relProposalProb = 1.0;
21521     mt->numTuningParams = 1;
21522     mt->tuningParam[0] = 1.0;  /* window size */
21523     mt->minimum[0] = 0.00001;
21524     mt->maximum[0] = 100.0;
21525     mt->parsimonyBased = NO;
21526     mt->level = STANDARD_USER;
21527     mt->Autotune = &AutotuneSlider;
21528     mt->targetRate = 0.25;
21529
21530     /* Move_SwitchRate_M */
21531     mt = &moveTypes[i++];
21532     mt->name = "Multiplier";
21533     mt->shortName = "Multiplier";
21534     mt->tuningName[0] = "Multiplier tuning parameter";
21535     mt->shortTuningName[0] = "lambda";
21536     mt->applicableTo[0] = SWITCH_UNI;
21537     mt->applicableTo[1] = SWITCH_EXP;
21538     mt->nApplicable = 2;
21539     mt->moveFxn = &Move_SwitchRate_M;
21540     mt->relProposalProb = 0.0;
21541     mt->numTuningParams = 1;
21542     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
21543     mt->minimum[0] = 0.0001;
21544     mt->maximum[0] = 20.0;                 /* smaller */
21545     mt->parsimonyBased = NO;
21546     mt->level = STANDARD_USER;
21547     mt->Autotune = &AutotuneMultiplier;
21548     mt->targetRate = 0.25;
21549
21550     /* Move_Tratio_Dir */
21551     mt = &moveTypes[i++];
21552     mt->name = "Dirichlet proposal";
21553     mt->shortName = "Dirichlet";
21554     mt->tuningName[0] = "Dirichlet parameter";
21555     mt->shortTuningName[0] = "alpha";
21556     mt->applicableTo[0] = TRATIO_DIR;
21557     mt->nApplicable = 1;
21558     mt->moveFxn = &Move_Tratio_Dir;
21559     mt->relProposalProb = 1.0;
21560     mt->numTuningParams = 1;
21561     mt->tuningParam[0] = 50.0;  /* alphaPi */
21562     mt->minimum[0] = 0.001;
21563     mt->maximum[0] = 10000.0;
21564     mt->parsimonyBased = NO;
21565     mt->level = STANDARD_USER;
21566     mt->Autotune = &AutotuneDirichlet;
21567     mt->targetRate = 0.25;
21568
21569     /* Move_TreeStretch */
21570     mt = &moveTypes[i++];
21571     mt->name = "Tree stretch";
21572     mt->shortName = "TreeStretch";
21573     mt->tuningName[0] = "Multiplier tuning parameter";
21574     mt->shortTuningName[0] = "lambda";
21575     mt->applicableTo[0] = BRLENS_CLOCK_UNI;
21576     mt->applicableTo[1] = BRLENS_CLOCK_BD;
21577     mt->applicableTo[2] = BRLENS_CLOCK_COAL;
21578     mt->applicableTo[3] = BRLENS_CLOCK_FOSSIL;
21579     mt->nApplicable = 4;
21580     mt->moveFxn = &Move_TreeStretch;
21581     mt->relProposalProb = 3.0;
21582     mt->numTuningParams = 1;
21583     mt->tuningParam[0] = 2.0 * log(1.01); /* lambda */
21584     mt->minimum[0] = 0.0001;
21585     mt->maximum[0] = 2.0 * log(2.0);
21586     mt->parsimonyBased = NO;
21587     mt->level = STANDARD_USER;
21588     mt->Autotune = &AutotuneMultiplier;
21589     mt->targetRate = 0.25;
21590
21591     /* Move_TreeLen, by Jeremy Brown */
21592     mt = &moveTypes[i++];
21593     mt->name = "Whole treelength hit with multiplier";
21594     mt->shortName = "TLMultiplier";
21595     mt->tuningName[0] = "Multiplier tuning parameter";
21596     mt->shortTuningName[0] = "lambda";  
21597     mt->applicableTo[0] = BRLENS_UNI;
21598     mt->applicableTo[1] = BRLENS_EXP;
21599     mt->applicableTo[2] = BRLENS_GamDir;
21600     mt->applicableTo[3] = BRLENS_iGmDir;
21601     mt->applicableTo[4] = BRLENS_twoExp;
21602     mt->nApplicable = 5;  // was 2
21603     mt->moveFxn = &Move_TreeLen;
21604     mt->relProposalProb = 3.0;
21605     mt->numTuningParams = 1;
21606     mt->tuningParam[0] = 2.0 * log (2.0);  /* lambda */
21607     mt->minimum[0] = 0.0001;
21608     mt->maximum[0] = 100.0;                /* smaller */
21609     mt->parsimonyBased = NO;
21610     mt->level = STANDARD_USER;
21611     mt->Autotune = &AutotuneMultiplier;
21612     mt->targetRate = 0.25;
21613
21614     /* Move_AddDeleteCPPEvent */
21615     mt = &moveTypes[i++];
21616     mt->name = "Random addition/deletion of CPP event";
21617     mt->shortName = "Add_delete";
21618     mt->applicableTo[0] = CPPEVENTS;
21619     mt->nApplicable = 1;
21620     mt->moveFxn = &Move_AddDeleteCPPEvent;
21621     mt->relProposalProb = 1.0;
21622     mt->numTuningParams = 0;
21623     mt->parsimonyBased = NO;
21624     mt->level = STANDARD_USER;
21625
21626     /* Move_CPPEventPosition */
21627     mt = &moveTypes[i++];
21628     mt->name = "Random draw of CPP event position from prior";
21629     mt->shortName = "Prior_draw_pos";
21630     mt->applicableTo[0] = CPPEVENTS;
21631     mt->nApplicable = 1;
21632     mt->moveFxn = &Move_CPPEventPosition;
21633     mt->relProposalProb = 2.0;
21634     mt->numTuningParams = 0;
21635     mt->parsimonyBased = NO;
21636     mt->level = STANDARD_USER;
21637
21638     /* Move_CPPRate */
21639     mt = &moveTypes[i++];
21640     mt->name = "Multiplier";
21641     mt->shortName = "Multiplier";
21642     mt->tuningName[0] = "Multiplier tuning parameter";
21643     mt->shortTuningName[0] = "lambda";
21644     mt->applicableTo[0] = CPPRATE_EXP;
21645     mt->nApplicable = 1;
21646     mt->moveFxn = &Move_CPPRate;
21647     mt->relProposalProb = 2.0;
21648     mt->numTuningParams = 1;
21649     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21650     mt->minimum[0] = 0.0001;
21651     mt->maximum[0] = 20.0;                 /* smaller */
21652     mt->parsimonyBased = NO;
21653     mt->level = STANDARD_USER;
21654     mt->Autotune = &AutotuneMultiplier;
21655     mt->targetRate = 0.25;
21656
21657     /* Move_CPPRateMultiplier_M */
21658     mt = &moveTypes[i++];
21659     mt->name = "Random CPP rate multiplier hit with multiplier";
21660     mt->shortName = "Multiplier";
21661     mt->tuningName[0] = "Multiplier tuning parameter";
21662     mt->shortTuningName[0] = "lambda";
21663     mt->applicableTo[0] = CPPEVENTS;
21664     mt->nApplicable = 1;
21665     mt->moveFxn = &Move_CPPRateMultiplier_M;
21666     mt->relProposalProb = 0.0;
21667     mt->numTuningParams = 1;
21668     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21669     mt->minimum[0] = 0.0001;
21670     mt->maximum[0] = 20.0;                 /* smaller */
21671     mt->parsimonyBased = NO;
21672     mt->level = STANDARD_USER;
21673     mt->Autotune = &AutotuneMultiplier;
21674     mt->targetRate = 0.25;
21675
21676     /* Move_CPPRateMultiplierRnd */
21677     mt = &moveTypes[i++];
21678     mt->name = "Random draw of CPP rate multiplier from prior";
21679     mt->shortName = "Prior_draw_mult";
21680     mt->applicableTo[0] = CPPEVENTS;
21681     mt->nApplicable = 1;
21682     mt->moveFxn = &Move_CPPRateMultiplierRnd;
21683     mt->relProposalProb = 2.0;
21684     mt->numTuningParams = 0;
21685     mt->parsimonyBased = NO;
21686     mt->level = STANDARD_USER;
21687
21688     /* Move_Nu */
21689     mt = &moveTypes[i++];
21690     mt->name = "Multiplier";
21691     mt->shortName = "Multiplier";
21692     mt->tuningName[0] = "Multiplier tuning parameter";
21693     mt->shortTuningName[0] = "lambda";
21694     mt->applicableTo[0] = TK02VAR_EXP;
21695     mt->applicableTo[1] = TK02VAR_UNI;
21696     mt->nApplicable = 2;
21697     mt->moveFxn = &Move_Nu;
21698     mt->relProposalProb = 2.0;
21699     mt->numTuningParams = 1;
21700     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21701     mt->minimum[0] = 0.0001;
21702     mt->maximum[0] = 20.0;                 /* smaller */
21703     mt->parsimonyBased = NO;
21704     mt->level = STANDARD_USER;
21705     mt->Autotune = &AutotuneMultiplier;
21706     mt->targetRate = 0.25;
21707
21708     /* Move_TK02BranchRate */
21709     mt = &moveTypes[i++];
21710     mt->name = "Multiplier";
21711     mt->shortName = "Multiplier";
21712     mt->tuningName[0] = "Multiplier tuning parameter";
21713     mt->shortTuningName[0] = "lambda";
21714     mt->applicableTo[0] = TK02BRANCHRATES;
21715     mt->nApplicable = 1;
21716     mt->moveFxn = &Move_TK02BranchRate;
21717     mt->relProposalProb = 10.0;
21718     mt->numTuningParams = 1;
21719     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21720     mt->minimum[0] = 0.0001;
21721     mt->maximum[0] = 20.0;
21722     mt->parsimonyBased = NO;
21723     mt->level = STANDARD_USER;
21724     mt->Autotune = &AutotuneMultiplier;
21725     mt->targetRate = 0.25;
21726
21727     /* Move_IgrVar */
21728     mt = &moveTypes[i++];
21729     mt->name = "Multiplier";
21730     mt->shortName = "Multiplier";
21731     mt->tuningName[0] = "Multiplier tuning parameter";
21732     mt->shortTuningName[0] = "lambda";
21733     mt->applicableTo[0] = IGRVAR_EXP;
21734     mt->applicableTo[1] = IGRVAR_UNI;
21735     mt->nApplicable = 2;
21736     mt->moveFxn = &Move_IgrVar;
21737     mt->relProposalProb = 2.0;
21738     mt->numTuningParams = 1;
21739     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21740     mt->minimum[0] = 0.0001;
21741     mt->maximum[0] = 20.0;                 /* smaller */
21742     mt->parsimonyBased = NO;
21743     mt->level = STANDARD_USER;
21744     mt->Autotune = &AutotuneMultiplier;
21745     mt->targetRate = 0.25;
21746
21747     /* Move_IgrBranchRate */
21748     mt = &moveTypes[i++];
21749     mt->name = "Multiplier";
21750     mt->shortName = "Multiplier";
21751     mt->tuningName[0] = "Multiplier tuning parameter";
21752     mt->shortTuningName[0] = "lambda";
21753     mt->applicableTo[0] = IGRBRANCHRATES;
21754     mt->nApplicable = 1;
21755     mt->moveFxn = &Move_IgrBranchRate;
21756     mt->relProposalProb = 10.0;
21757     mt->numTuningParams = 1;
21758     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21759     mt->minimum[0] = 0.0001;
21760     mt->maximum[0] = 20.0;
21761     mt->parsimonyBased = NO;
21762     mt->level = STANDARD_USER;
21763     mt->Autotune = &AutotuneMultiplier;
21764     mt->targetRate = 0.25;
21765
21766     /* Move_MixedVar */
21767     mt = &moveTypes[i++];
21768     mt->name = "Multiplier";
21769     mt->shortName = "Multiplier";
21770     mt->tuningName[0] = "Multiplier tuning parameter";
21771     mt->shortTuningName[0] = "lambda";
21772     mt->applicableTo[0] = MIXEDVAR_EXP;
21773     mt->applicableTo[1] = MIXEDVAR_UNI;
21774     mt->nApplicable = 2;
21775     mt->moveFxn = &Move_MixedVar;
21776     mt->relProposalProb = 2.0;
21777     mt->numTuningParams = 1;
21778     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21779     mt->minimum[0] = 0.0001;
21780     mt->maximum[0] = 20.0;                 /* smaller */
21781     mt->parsimonyBased = NO;
21782     mt->level = STANDARD_USER;
21783     mt->Autotune = &AutotuneMultiplier;
21784     mt->targetRate = 0.25;
21785     
21786     /* Move_MixedBranchRate */
21787     mt = &moveTypes[i++];
21788     mt->name = "Multiplier";
21789     mt->shortName = "Multiplier";
21790     mt->tuningName[0] = "Multiplier tuning parameter";
21791     mt->shortTuningName[0] = "lambda";
21792     mt->applicableTo[0] = MIXEDBRCHRATES;
21793     mt->nApplicable = 1;
21794     mt->moveFxn = &Move_MixedBranchRate;
21795     mt->relProposalProb = 10.0;
21796     mt->numTuningParams = 1;
21797     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21798     mt->minimum[0] = 0.0001;
21799     mt->maximum[0] = 20.0;
21800     mt->parsimonyBased = NO;
21801     mt->level = STANDARD_USER;
21802     mt->Autotune = &AutotuneMultiplier;
21803     mt->targetRate = 0.25;
21804
21805     /* Move_RelaxedClockModel */
21806     mt = &moveTypes[i++];
21807     mt->name = "rjMCMC among Relaxed Clock Models";
21808     mt->shortName = "rjMCMC_RCL";
21809     mt->tuningName[0] = "sigma_TK over sigma_IGR";
21810     mt->shortTuningName[0] = "ratio";
21811     mt->tuningName[1] = "Sliding window size";
21812     mt->shortTuningName[1] = "delta";
21813     mt->applicableTo[0] = MIXEDBRCHRATES;
21814     mt->nApplicable = 1;
21815     mt->moveFxn = &Move_RelaxedClockModel;
21816     mt->relProposalProb = 5.0;
21817     mt->numTuningParams = 2;
21818     mt->tuningParam[0] = 100.0; /* TK/IGR var ratio */
21819     mt->tuningParam[1] = 10.0;  /* window size */
21820     mt->minimum[0] = 0.0001;
21821     mt->maximum[0] = 10000.0;
21822     mt->minimum[1] = 0.0001;
21823     mt->maximum[1] = 1000.0;
21824     mt->parsimonyBased = NO;
21825     mt->level = STANDARD_USER;
21826     
21827     numMoveTypes = i;
21828 }
21829
21830
21831 /* ShowModel: Display model on screen */
21832 int ShowModel (void)
21833 {
21834     int         i, j, ns;
21835
21836     MrBayesPrint ("%s   Model settings:\n\n", spacer);
21837     for (i=0; i<numCurrentDivisions; i++)
21838         {
21839         ns = 0;
21840
21841         if (numCurrentDivisions > 1)
21842             MrBayesPrint ("%s      Settings for partition %d --\n", spacer, i+1);
21843         else
21844             MrBayesPrint ("%s      Data not partitioned --\n", spacer);
21845         
21846         if (modelParams[i].dataType == DNA)
21847             {
21848             MrBayesPrint ("%s         Datatype  = DNA\n", spacer);
21849             ns = 4;
21850             }
21851         else if (modelParams[i].dataType == RNA)
21852             {
21853             MrBayesPrint ("%s         Datatype  = RNA\n", spacer);
21854             ns = 4;
21855             }
21856         else if (modelParams[i].dataType == PROTEIN)
21857             {
21858             MrBayesPrint ("%s         Datatype  = Protein\n", spacer);
21859             ns = 20;
21860             }
21861         else if (modelParams[i].dataType == RESTRICTION)
21862             {
21863             MrBayesPrint ("%s         Datatype  = Restriction\n", spacer);
21864             ns = 2;
21865             }
21866         else if (modelParams[i].dataType == STANDARD)
21867             {
21868             MrBayesPrint ("%s         Datatype  = Standard\n", spacer);
21869             ns = 10;
21870             }
21871         else if (modelParams[i].dataType == CONTINUOUS)
21872             {
21873             MrBayesPrint ("%s         Datatype  = Continuous\n", spacer);
21874             }
21875             
21876         if (modelSettings[i].dataType == CONTINUOUS)
21877             {
21878             /* begin description of continuous models */
21879               if (!strcmp(modelParams[i].brownCorPr, "Fixed") && AreDoublesEqual(modelParams[i].brownCorrFix, 0.0, ETA)==YES)
21880                 MrBayesPrint ("%s         Model     = Independent Brownian motion\n", spacer);
21881             else
21882                 MrBayesPrint ("%s         Model     = Correlated Brownian motion\n", spacer);
21883             /* end description of continuous models */
21884             }
21885         else
21886             {
21887             /* begin description of discrete models */
21888             if (!strcmp(modelParams[i].parsModel, "Yes"))
21889                 {
21890                 MrBayesPrint ("%s         Parsmodel = %s\n", spacer, modelParams[i].parsModel);
21891                 }
21892             else
21893                 {
21894                 /* dna characters in this partition */
21895                 if (modelSettings[i].dataType == DNA || modelSettings[i].dataType == RNA)
21896                     {
21897                     /* general form of the rate matrix */ 
21898                     MrBayesPrint ("%s         Nucmodel  = %s\n", spacer, modelParams[i].nucModel);
21899                 
21900                     /* constraints on rates of substitution */
21901                     MrBayesPrint ("%s         Nst       = %s\n", spacer, modelParams[i].nst);
21902                     if (!strcmp(modelParams[i].nst, "2"))
21903                         {
21904                         if (!strcmp(modelParams[i].tRatioPr,"Beta"))
21905                             {
21906                             MrBayesPrint ("%s                     Transition and transversion  rates, expressed\n", spacer);
21907                             MrBayesPrint ("%s                     as proportions of the rate sum, have a\n", spacer);
21908                             MrBayesPrint ("%s                     Beta(%1.2lf,%1.2lf) prior\n", spacer, modelParams[i].tRatioDir[0], modelParams[i].tRatioDir[1]);
21909                             }
21910                         else
21911                             {
21912                             MrBayesPrint ("%s                     Transition/transversion rate ratio is fixed to %1.2lf.\n", spacer, modelParams[i].tRatioFix);
21913                             }
21914                         }
21915                     else if (!strcmp(modelParams[i].nst, "6"))
21916                         {
21917                         if (!strcmp(modelParams[i].revMatPr,"Dirichlet"))
21918                             {
21919                             MrBayesPrint ("%s                     Substitution rates, expressed as proportions\n", spacer);
21920                             MrBayesPrint ("%s                     of the rate sum, have a Dirichlet prior\n", spacer);
21921                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
21922                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
21923                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5]);
21924                             }
21925                         else
21926                             {
21927                             MrBayesPrint ("%s                     Substitution rates are fixed to be \n", spacer);
21928                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf).\n", spacer,
21929                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
21930                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5]);
21931                             }
21932                         }
21933                     else if (!strcmp(modelParams[i].nst, "Mixed"))
21934                         {
21935                         if (!strcmp(modelParams[i].revMatPr,"Dirichlet"))
21936                             {
21937                             MrBayesPrint ("%s                     Substitution rates, expressed as proportions\n", spacer);
21938                             MrBayesPrint ("%s                     of the rate sum, have a Dirichlet prior\n", spacer);
21939                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
21940                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
21941                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5]);
21942                             }
21943                         else
21944                             {
21945                             MrBayesPrint ("%s                     Substitution rates are fixed to be \n", spacer);
21946                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf).\n", spacer,
21947                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
21948                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5]);
21949                             }
21950                         }
21951                     
21952                     if (!strcmp(modelParams[i].nucModel,"Codon"))
21953                         {
21954                         /* what is the distribution on the nonsyn./syn. rate ratio */
21955                         if (!strcmp(modelParams[i].omegaVar, "Equal"))
21956                             {
21957                             if (!strcmp(modelParams[i].omegaPr,"Dirichlet"))
21958                                 {
21959                                 MrBayesPrint ("%s                     Nonsynonymous and synonymous rates, expressed\n", spacer);
21960                                 MrBayesPrint ("%s                     as proportions of the rate sum, have a\n", spacer);
21961                                 MrBayesPrint ("%s                     Dirichlet(%1.2lf,%1.2lf) prior\n", spacer, modelParams[i].omegaDir[0], modelParams[i].omegaDir[1]);
21962                                 }
21963                             else
21964                                 {
21965                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio is fixed to %1.2lf.\n", spacer, modelParams[i].omegaFix);
21966                                 }
21967                             }
21968                         else if (!strcmp(modelParams[i].omegaVar, "Ny98"))
21969                             {
21970                             if (!strcmp(modelParams[i].ny98omega1pr, "Beta"))
21971                                 {
21972                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for purifying selection\n", spacer);
21973                                 MrBayesPrint ("%s                     (class 1) has a Beta(%1.2lf,%1.2lf) on the interval (0,1).\n", spacer, modelParams[i].ny98omega1Beta[0], modelParams[i].ny98omega1Beta[1]);
21974                                 }
21975                             else
21976                                 {
21977                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for purifying selection\n", spacer);
21978                                 MrBayesPrint ("%s                     (class 1) is fixed to %1.2lf.\n", spacer, modelParams[i].ny98omega1Fixed);
21979                                 }
21980                             MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for neutral selection\n", spacer);
21981                             MrBayesPrint ("%s                     (class 2) is fixed to 1.0.\n", spacer);
21982                             if (!strcmp(modelParams[i].ny98omega3pr, "Uniform"))
21983                                 {
21984                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for positive selection\n", spacer);
21985                                 MrBayesPrint ("%s                     is uniformly distributed on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].ny98omega3Uni[0], modelParams[i].ny98omega3Uni[1]);
21986                                 }
21987                             else if (!strcmp(modelParams[i].ny98omega3pr, "Exponential"))
21988                                 {
21989                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for positive selection\n", spacer);
21990                                 MrBayesPrint ("%s                     is exponentially distributed with parameter (%1.2lf).\n", spacer, modelParams[i].ny98omega3Exp);
21991                                 }
21992                             else
21993                                 {
21994                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for positive \n", spacer);
21995                                 MrBayesPrint ("%s                     selection is fixed to %1.2lf.\n", spacer, modelParams[i].ny98omega3Fixed);
21996                                 }
21997                             }
21998                         else if (!strcmp(modelParams[i].omegaVar, "M3"))
21999                             {
22000                             if (!strcmp(modelParams[i].m3omegapr, "Exponential"))
22001                                 {
22002                                 MrBayesPrint ("%s                     Nonsynonymous and synonymous rates for the tree classes of\n", spacer);
22003                                 MrBayesPrint ("%s                     omega are exponentially distributed random variables.\n", spacer);
22004                                 }
22005                             else if (!strcmp(modelParams[i].m3omegapr, "Fixed"))
22006                                 {
22007                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for the three omega\n", spacer);
22008                                 MrBayesPrint ("%s                     are fixed to %1.2lf, %1.2lf, and %1.2lf.\n", spacer, modelParams[i].m3omegaFixed[0], modelParams[i].m3omegaFixed[1], modelParams[i].m3omegaFixed[2]);
22009                                 }
22010                             }
22011                         else if (!strcmp(modelParams[i].omegaVar, "M10"))
22012                             {
22013                             MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for purifying \n", spacer);
22014                             MrBayesPrint ("%s                     selection (class 1) has a Beta(alpha1,beta1) on the \n", spacer);
22015                             MrBayesPrint ("%s                     interval (0,1). Nonsynonymous/synonymous rate ratio \n", spacer);
22016                             MrBayesPrint ("%s                     for positive selection (class 2) has an offset \n", spacer);
22017                             MrBayesPrint ("%s                     Gamma(alpha2,beta2) on the interval (1,Infinity).\n", spacer);
22018                             }
22019                             
22020                         /* genetic code that is used (if nucmodel=codon) */
22021                         MrBayesPrint ("%s         Code      = %s\n", spacer, modelParams[i].geneticCode);
22022                         }
22023                     }
22024                 /* amino acid characters in this partition */
22025                 else if (modelSettings[i].dataType == PROTEIN)
22026                     {
22027                     if (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA)
22028                         MrBayesPrint ("%s         Nucmodel  = %s\n", spacer, modelParams[i].nucModel);
22029                     /* constraints on rates of substitution in 20 X 20 matrix */
22030                     if (!strcmp(modelParams[i].aaModelPr, "Mixed"))
22031                         MrBayesPrint ("%s         Aamodel   = Mixture of models with fixed rate matrices\n", spacer);
22032                     else
22033                         MrBayesPrint ("%s         Aamodel   = %s\n", spacer, modelParams[i].aaModel);
22034                     /* revmat rates */
22035                     if (!strcmp(modelParams[i].aaModelPr, "Mixed"))
22036                         MrBayesPrint ("%s                     Substitution rates come from the mixture of models\n", spacer);
22037                     else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && (!strcmp(modelParams[i].aaModel, "Poisson") ||
22038                                 !strcmp(modelParams[i].aaModel, "Equalin")))
22039                         MrBayesPrint ("%s                     Substitution rates are fixed to be equal\n", spacer);
22040                     else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && strcmp(modelParams[i].aaModel, "Gtr")!=0)
22041                         MrBayesPrint ("%s                     Substitution rates are fixed to the %s rates\n", spacer, modelParams[i].aaModel);
22042                     else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && !strcmp(modelParams[i].aaModel, "Gtr"))
22043                         {
22044                         if (!strcmp(modelParams[i].aaRevMatPr,"Dirichlet"))
22045                             {
22046                             for (j=0; j<190; j++)
22047                                 if (AreDoublesEqual(modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[j], 0.00001) == NO)
22048                                     break;
22049                             if (j == 190)
22050                                 {
22051                                 MrBayesPrint ("%s                     Substitution rates have a Dirichlet(%1.2lf,%1.2lf,...) prior\n",
22052                                     spacer, modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[0]);
22053                                 }
22054                             else
22055                                 {
22056                                 MrBayesPrint ("%s                     Substitution rates have a Dirichlet(\n", spacer);
22057                                 for (j=0; j<190; j++)
22058                                     {
22059                                     if (j % 10 == 0)
22060                                         MrBayesPrint ("%s                        ", spacer);
22061                                     MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatDir[j]);
22062                                     if (j == 189)
22063                                         MrBayesPrint (") prior\n");
22064                                     else if ((j+1) % 10 == 0)
22065                                         MrBayesPrint (",\n");
22066                                     else
22067                                         MrBayesPrint (",");
22068                                     }
22069                                 }
22070                             }
22071                         else /* if (!strcmp(modelParams[i].aaRevMatPr,"Fixed")) */
22072                             {
22073                             for (j=0; j<190; j++)
22074                                 if (AreDoublesEqual(modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[j], 0.00001) == NO)
22075                                     break;
22076                             if (j == 190)
22077                                 {
22078                                 MrBayesPrint ("%s                     Substitution rates are fixed to (%1.1lf,%1.1lf,...)\n",
22079                                     spacer, modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[0]);
22080                                 }
22081                             else
22082                                 {
22083                                 MrBayesPrint ("%s                     Substitution rates are fixed to (\n", spacer);
22084                                 for (j=0; j<190; j++)
22085                                     {
22086                                     if (j % 10 == 0)
22087                                         MrBayesPrint ("%s                        ", spacer);
22088                                     MrBayesPrint ("%1.1lf", modelParams[i].aaRevMatFix[j]);
22089                                     if (j == 189)
22090                                         MrBayesPrint (") prior\n");
22091                                     else if ((j+1) % 10 == 0)
22092                                         MrBayesPrint (",\n");
22093                                     else
22094                                         MrBayesPrint (",");
22095                                     }
22096                                 }
22097                             }
22098                         }
22099                     }
22100                 /* restriction site or morphological characters in this partition */
22101                 else if (modelSettings[i].dataType == RESTRICTION || modelSettings[i].dataType == STANDARD)
22102                     {
22103                     /* what type of characters are sampled? */
22104                     MrBayesPrint ("%s         Coding    = %s\n", spacer, modelParams[i].codingString);
22105                     }
22106                     
22107                 /* is there rate variation in a single site across the tree? */
22108                 if (((modelSettings[i].dataType == DNA || modelSettings[i].dataType == RNA) && !strcmp(modelParams[i].nucModel, "4by4")) || modelSettings[i].dataType == PROTEIN)
22109                     {
22110                     /* do rates change on tree accoding to covarion model? */
22111                     MrBayesPrint ("%s         Covarion  = %s\n", spacer, modelParams[i].covarionModel);
22112                     if (!strcmp(modelParams[i].covarionModel, "Yes"))
22113                         {
22114                         /* distribution on switching parameters, if appropriate */
22115                         if (!strcmp(modelParams[i].covSwitchPr,"Uniform"))
22116                             {
22117                             MrBayesPrint ("%s                     Switching rates have independent uniform dist-\n", spacer);
22118                             MrBayesPrint ("%s                     ributions on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].covswitchUni[0], modelParams[i].covswitchUni[1]);
22119                             }
22120                         else if (!strcmp(modelParams[i].covSwitchPr,"Exponential"))
22121                             {
22122                             MrBayesPrint ("%s                     Switching rates have independent exponential\n", spacer);
22123                             MrBayesPrint ("%s                     distributions with parameters (%1.2lf).\n", spacer, modelParams[i].covswitchExp);
22124                             }
22125                         else
22126                             {
22127                             MrBayesPrint ("%s                     Switching rates are fixed to %1.2lf and %1.2lf.\n", spacer, modelParams[i].covswitchFix[0], modelParams[i].covswitchFix[0]);
22128                             }
22129                         ns *= 2;
22130                         }
22131                     }
22132
22133                 /* now, let's deal with variation in omega */
22134                 if ((modelParams[i].dataType == DNA || modelParams[i].dataType == RNA) && !strcmp(modelParams[i].nucModel,"Codon"))
22135                     {
22136                     MrBayesPrint ("%s         Omegavar  = %s\n", spacer, modelParams[i].omegaVar);
22137                     if (!strcmp(modelParams[i].geneticCode, "Universal"))
22138                         ns = 61;
22139                     else if (!strcmp(modelParams[i].geneticCode, "Vertmt"))
22140                         ns = 60;
22141                     else if (!strcmp(modelParams[i].geneticCode, "Invermt"))
22142                         ns = 62;
22143                     else if (!strcmp(modelParams[i].geneticCode, "Mycoplasma"))
22144                         ns = 62;
22145                     else if (!strcmp(modelParams[i].geneticCode, "Yeast"))
22146                         ns = 62;
22147                     else if (!strcmp(modelParams[i].geneticCode, "Ciliate"))
22148                         ns = 63;
22149                     else if (!strcmp(modelParams[i].geneticCode, "Echinoderm"))
22150                         ns = 62;
22151                     else if (!strcmp(modelParams[i].geneticCode, "Euplotid"))
22152                         ns = 62;
22153                     else if (!strcmp(modelParams[i].geneticCode, "Metmt"))
22154                         ns = 62;
22155                     }
22156
22157                 /* what assumptions are made about the state frequencies? */
22158                 if (modelParams[i].dataType != CONTINUOUS)
22159                     {
22160                     if (modelParams[i].dataType == STANDARD)
22161                         MrBayesPrint ("%s         # States  = Variable, up to 10\n", spacer);
22162                     else if (modelSettings[i].numStates != modelSettings[i].numModelStates)
22163                         MrBayesPrint ("%s         # States  = %d (in the model)\n", spacer, modelSettings[i].numModelStates);
22164                     else
22165                         MrBayesPrint ("%s         # States  = %d\n", spacer, ns);
22166                     if (modelSettings[i].dataType == STANDARD)
22167                         {
22168                         if (!strcmp(modelParams[i].symPiPr,"Fixed"))
22169                             {
22170                             if (AreDoublesEqual(modelParams[i].symBetaFix, -1.0, ETA)==YES)
22171                                 MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22172                             else
22173                                 MrBayesPrint ("%s                     Symmetric Dirichlet alpha is fixed to %1.2lf\n", spacer, modelParams[i].symBetaFix);
22174                             }
22175                         else if (!strcmp(modelParams[i].symPiPr,"Uniform"))
22176                             {
22177                             MrBayesPrint ("%s                     Symmetric Dirichlet alpha has a Uniform(%1.2lf,%1.2lf) prior\n", spacer, modelParams[i].symBetaUni[0], modelParams[i].symBetaUni[1]);
22178                             }
22179                         else
22180                             {
22181                             MrBayesPrint ("%s                     Symmetric Dirichlet alpha has a Exponential(%1.2lf) prior\n", spacer, modelParams[i].symBetaExp);
22182                             }
22183                         }
22184                     else if (modelSettings[i].dataType == RESTRICTION)
22185                         {
22186                         /* distribution on state frequencies for restriction site model */
22187                         if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
22188                             {
22189                             MrBayesPrint ("%s                     State frequencies have a Dirichlet (%1.2lf,%1.2lf) prior\n", spacer,
22190                                 modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1]);
22191                             }
22192                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Equal"))
22193                             {
22194                             MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22195                             }
22196                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"User"))
22197                             {
22198                             MrBayesPrint ("%s                     State frequencies have been fixed by the user\n", spacer);
22199                             }
22200                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Empirical"))
22201                             {
22202                             MrBayesPrint ("%s                     State frequencies have been fixed to the empirical frequencies in the data\n", spacer);
22203                             }
22204                         }
22205                     else if (modelSettings[i].dataType == PROTEIN)
22206                         {
22207                         /* distribution on state frequencies for aminoacid model */
22208                         if (!strcmp(modelParams[i].aaModelPr, "Fixed") && (strcmp(modelParams[i].aaModel, "Equalin")==0 ||
22209                             strcmp(modelParams[i].aaModel, "Gtr")==0))
22210                             {
22211                             if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
22212                                 {
22213                                 MrBayesPrint ("%s                     State frequencies have a Dirichlet prior\n", spacer);
22214                                 MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,", spacer,
22215                                     modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1], modelParams[i].stateFreqsDir[2],
22216                                     modelParams[i].stateFreqsDir[3], modelParams[i].stateFreqsDir[4]);
22217                                 MrBayesPrint ("%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,\n",
22218                                     modelParams[i].stateFreqsDir[5], modelParams[i].stateFreqsDir[6], modelParams[i].stateFreqsDir[7],
22219                                     modelParams[i].stateFreqsDir[8], modelParams[i].stateFreqsDir[9]);
22220                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,", spacer,
22221                                     modelParams[i].stateFreqsDir[10], modelParams[i].stateFreqsDir[11], modelParams[i].stateFreqsDir[12],
22222                                     modelParams[i].stateFreqsDir[13], modelParams[i].stateFreqsDir[14]);
22223                                 MrBayesPrint ("%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n",
22224                                     modelParams[i].stateFreqsDir[15], modelParams[i].stateFreqsDir[16], modelParams[i].stateFreqsDir[17],
22225                                     modelParams[i].stateFreqsDir[18], modelParams[i].stateFreqsDir[19]);
22226                                 }
22227                             else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Equal"))
22228                                 {
22229                                 MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22230                                 }
22231                             else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"User"))
22232                                 {
22233                                 MrBayesPrint ("%s                     State frequencies have been fixed by the user\n", spacer);
22234                                 }
22235                             else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Empirical"))
22236                                 {
22237                                 MrBayesPrint ("%s                     State frequencies have been fixed to the empirical frequencies in the data\n", spacer);
22238                                 }
22239                             }
22240                         else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && !strcmp(modelParams[i].aaModel, "Poisson"))
22241                             {
22242                             MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22243                             }
22244                         else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && strcmp(modelParams[i].aaModel, "Equalin") && strcmp(modelParams[i].aaModel, "Poisson"))
22245                             {
22246                             MrBayesPrint ("%s                     State frequencies are fixed to the %s frequencies\n", spacer, modelParams[i].aaModel);
22247                             }
22248                         else
22249                             {
22250                             MrBayesPrint ("%s                     State frequencies come from the mixture of models\n", spacer);
22251                             }
22252                         }
22253                     else
22254                         {
22255                         /* distribution on state frequencies for all other models */
22256                         if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
22257                             {
22258                             MrBayesPrint ("%s                     State frequencies have a Dirichlet prior\n", spacer);
22259                             if (!strcmp(modelParams[i].nucModel, "Doublet"))
22260                                 {
22261                                 MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,\n", spacer,
22262                                     modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1], modelParams[i].stateFreqsDir[2],
22263                                     modelParams[i].stateFreqsDir[3]);
22264                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf,\n", spacer,
22265                                     modelParams[i].stateFreqsDir[4], modelParams[i].stateFreqsDir[5], modelParams[i].stateFreqsDir[6],
22266                                     modelParams[i].stateFreqsDir[7]);
22267                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf,\n", spacer,
22268                                     modelParams[i].stateFreqsDir[8], modelParams[i].stateFreqsDir[9], modelParams[i].stateFreqsDir[10],
22269                                     modelParams[i].stateFreqsDir[11]);
22270                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
22271                                     modelParams[i].stateFreqsDir[12], modelParams[i].stateFreqsDir[13], modelParams[i].stateFreqsDir[14],
22272                                     modelParams[i].stateFreqsDir[15]);
22273                                 }
22274                             else if (!strcmp(modelParams[i].nucModel, "4by4"))
22275                                 {
22276                                 MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
22277                                     modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1], modelParams[i].stateFreqsDir[2],
22278                                     modelParams[i].stateFreqsDir[3]);
22279                                 }
22280                             }
22281                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Equal"))
22282                             {
22283                             MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22284                             }
22285                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"User"))
22286                             {
22287                             MrBayesPrint ("%s                     State frequencies have been fixed by the user\n", spacer);
22288                             }
22289                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Empirical"))
22290                             {
22291                             MrBayesPrint ("%s                     State frequencies have been fixed to the empirical frequencies in the data\n", spacer);
22292                             }
22293                         }
22294                     }
22295                 else
22296                     MrBayesPrint ("%s         # States  = Infinity\n", spacer);
22297
22298                 /* now, let's deal with rate variation across sites */
22299                 if (modelSettings[i].dataType != CONTINUOUS)
22300                     {
22301                     if (((modelSettings[i].dataType == DNA || modelSettings[i].dataType == RNA) && strcmp(modelParams[i].nucModel,"Codon")) ||
22302                           modelSettings[i].dataType == PROTEIN || modelSettings[i].dataType == RESTRICTION || modelSettings[i].dataType == STANDARD)
22303                         {
22304                         if (!strcmp(modelParams[i].covarionModel, "No"))
22305                             MrBayesPrint ("%s         Rates     = %s\n", spacer, modelParams[i].ratesModel);
22306                         else
22307                             {
22308                             if (!strcmp(modelParams[i].ratesModel, "Propinv"))
22309                                 MrBayesPrint ("%s         Rates     = Equal ", spacer);
22310                             else if (!strcmp(modelParams[i].ratesModel, "Invgamma"))
22311                                 MrBayesPrint ("%s         Rates     = Gamma ", spacer);
22312                             else
22313                                 MrBayesPrint ("%s         Rates     = %s ", spacer, modelParams[i].ratesModel);
22314                             MrBayesPrint ("(+ Propinv induced by covarion model)\n");
22315                             }
22316                         
22317                         if ((modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD) && !strcmp(modelParams[i].ratesModel, "Adgamma"))
22318                             {
22319                             
22320                             }
22321                         else
22322                             {
22323                             if (!strcmp(modelParams[i].ratesModel, "Gamma") || !strcmp(modelParams[i].ratesModel, "Invgamma") ||
22324                                 !strcmp(modelParams[i].ratesModel, "LNorm") || !strcmp(modelParams[i].ratesModel, "Adgamma"))
22325                                 {
22326                                 /* how many categories is the continuous gamma approximated by? */
22327                                 MrBayesPrint ("%s                     The distribution is approximated using %d categories.\n", spacer, modelParams[i].numGammaCats);
22328                                 if (!strcmp(modelParams[i].useGibbs,"Yes"))
22329                                     MrBayesPrint ("%s                     Rate categories sampled using Gibbs sampling.\n", spacer, modelParams[i].numGammaCats);
22330                                 else
22331                                     MrBayesPrint ("%s                     Likelihood summarized over all rate categories in each generation.\n", spacer, modelParams[i].numGammaCats);
22332                                 /* distribution on shape parameter, if appropriate */
22333                                 if (!strcmp(modelParams[i].shapePr,"Uniform"))
22334                                     {
22335                                     MrBayesPrint ("%s                     Shape parameter is uniformly distributed\n", spacer);
22336                                     MrBayesPrint ("%s                     on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].shapeUni[0], modelParams[i].shapeUni[1]);
22337                                     }
22338                                 else if (!strcmp(modelParams[i].shapePr,"Exponential"))
22339                                     {
22340                                     MrBayesPrint ("%s                     Shape parameter is exponentially\n", spacer);
22341                                     MrBayesPrint ("%s                     distributed with parameter (%1.2lf).\n", spacer, modelParams[i].shapeExp);
22342                                     }
22343                                 else
22344                                     {
22345                                     MrBayesPrint ("%s                     Shape parameter is fixed to %1.2lf.\n", spacer, modelParams[i].shapeFix);
22346                                     }
22347                                 }
22348                             if ((!strcmp(modelParams[i].ratesModel, "Propinv") || !strcmp(modelParams[i].ratesModel, "Invgamma")) && !strcmp(modelParams[i].covarionModel, "No"))
22349                                 {
22350                                 /* distribution on pInvar parameter, if appropriate */
22351                                 if (!strcmp(modelParams[i].pInvarPr,"Uniform"))
22352                                     {
22353                                     MrBayesPrint ("%s                     Proportion of invariable sites is uniformly dist-\n", spacer);
22354                                     MrBayesPrint ("%s                     ributed on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].pInvarUni[0], modelParams[i].pInvarUni[1]);
22355                                     }
22356                                 else
22357                                     {
22358                                     MrBayesPrint ("%s                     Proportion of invariable sites is fixed to %1.2lf.\n", spacer, modelParams[i].pInvarFix);
22359                                     }
22360                                 }
22361                             if (!strcmp(modelParams[i].ratesModel, "Adgamma"))
22362                                 {
22363                                 /* distribution on correlation parameter, if appropriate */
22364                                 if (!strcmp(modelParams[i].adGammaCorPr,"Uniform"))
22365                                     {
22366                                     MrBayesPrint ("%s                     Rate correlation parameter is uniformly dist-\n", spacer);
22367                                     MrBayesPrint ("%s                     ributed on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].corrUni[0], modelParams[i].corrUni[1]);
22368                                     }
22369                                 else
22370                                     {
22371                                     MrBayesPrint ("%s                     Rate correlation parameter is fixed to %1.2lf.\n", spacer, modelParams[i].corrFix);
22372                                     }
22373                                 }
22374                             }
22375                         }
22376                     }
22377                 }
22378             /* end description of discrete models */
22379             }
22380
22381         if (i != numCurrentDivisions - 1)
22382             MrBayesPrint ("\n");
22383         
22384         }
22385
22386     MrBayesPrint ("\n");
22387     ShowParameters (NO, NO, NO);
22388     
22389     return (NO_ERROR);
22390 }
22391
22392
22393 /*------------------------------------------------------------------------------
22394 |
22395 |   ShowMoves: Show applicable moves
22396 |
22397 ------------------------------------------------------------------------------*/
22398 int ShowMoves (int used)
22399 {
22400     int             i, k, run, chain, chainIndex, areRunsSame, areChainsSame, numPrintedMoves;
22401     MCMCMove        *mv;
22402     
22403     chainIndex = 0;
22404     numPrintedMoves = 0;
22405     for (i=0; i<numApplicableMoves; i++)
22406         {
22407         mv = moves[i];
22408         
22409         for (k=0; k<numGlobalChains; k++)
22410             {
22411             if (mv->relProposalProb[k] > 0.000001)
22412                 break;
22413             }
22414
22415         if (k == numGlobalChains && used == YES)
22416             continue;
22417
22418         if (k < numGlobalChains && used == NO)
22419             continue;
22420
22421         numPrintedMoves++;
22422         
22423         /* print move number and name */
22424         MrBayesPrint ("%s   %4d -- Move        = %s\n", spacer, numPrintedMoves, mv->name);
22425         
22426         /* print move type */
22427         MrBayesPrint ("%s           Type        = %s\n", spacer, mv->moveType->name);
22428
22429         /* print parameter */
22430         if (mv->parm->nSubParams > 0)
22431             MrBayesPrint ("%s           Parameters  = %s [param. %d] (%s)\n", spacer, mv->parm->name,
22432                 mv->parm->index+1, mv->parm->paramTypeName);
22433         else
22434             MrBayesPrint ("%s           Parameter   = %s [param. %d] (%s)\n", spacer, mv->parm->name,
22435                 mv->parm->index+1, mv->parm->paramTypeName);
22436         for (k=0; k<mv->parm->nSubParams; k++)
22437             MrBayesPrint ("%s                         %s [param. %d] (%s)\n", spacer, mv->parm->subParams[k]->name,
22438                 mv->parm->subParams[k]->index+1, mv->parm->subParams[k]->paramTypeName);
22439
22440         /* print tuning parameters */
22441         for (k=0; k<mv->moveType->numTuningParams; k++)
22442             {
22443             if (k==0)
22444                 MrBayesPrint ("%s           Tuningparam = %s (%s)\n", spacer, mv->moveType->shortTuningName[k], mv->moveType->tuningName[k]);
22445             else
22446                 MrBayesPrint ("%s                         %s (%s)\n", spacer, mv->moveType->shortTuningName[k], mv->moveType->tuningName[k]);
22447             }
22448         
22449         /* loop over tuning parameters */
22450         for (k=0; k<mv->moveType->numTuningParams; k++)
22451             {
22452             /* find if tuning parameters are different for different runs */
22453             areRunsSame = YES;
22454             for (run=1; run<chainParams.numRuns; run++)
22455                 {
22456                 for (chain=0; chain<chainParams.numChains; chain++)
22457                     {
22458                     chainIndex = run*chainParams.numChains + chain;
22459                     if (AreDoublesEqual (mv->tuningParam[chainIndex][k], mv->tuningParam[chain][k], 0.000001) == NO)
22460                         {
22461                         areRunsSame = NO;
22462                         break;
22463                         }
22464                     }
22465                 if (areRunsSame == NO)
22466                     break;
22467                 }
22468         
22469             /* now print values */
22470             for (run=0; run<chainParams.numRuns; run++)
22471                 {
22472                 if (areRunsSame == YES && run >= 1)
22473                     break;
22474
22475                 /* find out if chains are different within this run */
22476                 areChainsSame = YES;
22477                 for (chain=1; chain<chainParams.numChains; chain++)
22478                     {
22479                     chainIndex = run*chainParams.numChains + chain;
22480                     if (AreDoublesEqual (mv->tuningParam[chainIndex][k], mv->tuningParam[chainIndex-chain][k],0.000001) == NO)
22481                         {
22482                         areChainsSame = NO;
22483                         break;
22484                         }
22485                     }
22486                 /* now we can print the values */
22487                 for (chain=0; chain<chainParams.numChains; chain++)
22488                     {
22489                     chainIndex = run*chainParams.numChains + chain;
22490                     if (areChainsSame == YES && chain >= 1)
22491                         break;
22492                     
22493                     if (run == 0 && chain == 0)
22494                         MrBayesPrint ("%s%22s = %1.3lf", spacer, mv->moveType->shortTuningName[k], mv->tuningParam[chainIndex][k]);
22495                     else
22496                         MrBayesPrint ("%s                         %1.3lf", spacer, mv->tuningParam[chainIndex][k]);
22497
22498                     if (areChainsSame == NO && areRunsSame == YES)
22499                         MrBayesPrint ("  [chain %d]\n", chain+1);
22500                     else if (areChainsSame == YES && areRunsSame == NO)
22501                         MrBayesPrint ("  [run %d]\n", run+1);
22502                     else if (areChainsSame == NO && areRunsSame == NO)
22503                         MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
22504                     else
22505                         MrBayesPrint ("\n");
22506                     }
22507                 }
22508             }   /* next tuning parameter */
22509
22510         /* print target acceptance rate for autotuning */
22511         if (mv->moveType->targetRate > 0.0 && mv->moveType->targetRate < 1.0)
22512             {
22513
22514             /* first find out if the targets are different in different runs */         
22515             areRunsSame = YES;
22516             for (run=1; run<chainParams.numRuns; run++)
22517                 {
22518                 for (chain=0; chain<chainParams.numChains; chain++)
22519                     {
22520                     chainIndex = run*chainParams.numChains + chain;
22521                     if (AreDoublesEqual (mv->targetRate[chainIndex], mv->targetRate[chain], 0.000001) == NO)
22522                         {
22523                         areRunsSame = NO;
22524                         break;
22525                         }
22526                     }
22527                 if (areRunsSame == NO)
22528                     break;
22529                 }
22530         
22531             /* now print values */
22532             for (run=0; run<chainParams.numRuns; run++)
22533                 {
22534                 if (areRunsSame == YES && run >= 1)
22535                     break;
22536
22537                 /* find out if chains are different within this run */
22538                 areChainsSame = YES;
22539                 for (chain=1; chain<chainParams.numChains; chain++)
22540                     {
22541                     chainIndex = run*chainParams.numChains + chain;
22542                     if (AreDoublesEqual (mv->targetRate[chainIndex], mv->targetRate[chainIndex-chain], 0.000001) == NO)
22543                         {
22544                         areChainsSame = NO;
22545                         break;
22546                         }
22547                     }
22548                 /* now we can print the values */
22549                 for (chain=0; chain<chainParams.numChains; chain++)
22550                     {
22551                     chainIndex = run*chainParams.numChains + chain;
22552                     if (areChainsSame == YES && chain >= 1)
22553                         break;
22554                     
22555                     if (run == 0 && chain == 0)
22556                         MrBayesPrint ("%s           Targetrate  = %1.3lf", spacer, mv->targetRate[chainIndex]);
22557                     else
22558                         MrBayesPrint ("%s                         %1.3lf", spacer, mv->targetRate[chainIndex]);
22559
22560                     if (areChainsSame == NO && areRunsSame == YES)
22561                         MrBayesPrint ("  [chain %d]\n", chain+1);
22562                     else if (areChainsSame == YES && areRunsSame == NO)
22563                         MrBayesPrint ("  [run %d]\n", run+1);
22564                     else if (areChainsSame == NO && areRunsSame == NO)
22565                         MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
22566                     else
22567                         MrBayesPrint ("\n");
22568                     }
22569                 }
22570             }
22571
22572         
22573         /* finally print the relative proposal probability */
22574         
22575         /* first find out if the probabilities are different in different runs */           
22576         areRunsSame = YES;
22577         for (run=1; run<chainParams.numRuns; run++)
22578             {
22579             for (chain=0; chain<chainParams.numChains; chain++)
22580                 {
22581                 chainIndex = run*chainParams.numChains + chain;
22582                 if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[chain], 0.000001) == NO)
22583                     {
22584                     areRunsSame = NO;
22585                     break;
22586                     }
22587                 }
22588             if (areRunsSame == NO)
22589                 break;
22590             }
22591     
22592         /* now print values */
22593         for (run=0; run<chainParams.numRuns; run++)
22594             {
22595             if (areRunsSame == YES && run >= 1)
22596                 break;
22597
22598             /* find out if chains are different within this run */
22599             areChainsSame = YES;
22600             for (chain=1; chain<chainParams.numChains; chain++)
22601                 {
22602                 chainIndex = run*chainParams.numChains + chain;
22603                 if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[chainIndex-chain], 0.000001) == NO)
22604                     {
22605                     areChainsSame = NO;
22606                     break;
22607                     }
22608                 }
22609             /* now we can print the values */
22610             for (chain=0; chain<chainParams.numChains; chain++)
22611                 {
22612                 chainIndex = run*chainParams.numChains + chain;
22613                 if (areChainsSame == YES && chain >= 1)
22614                     break;
22615                 
22616                 if (run == 0 && chain == 0)
22617                     MrBayesPrint ("%s           Rel. prob.  = %1.1lf", spacer, mv->relProposalProb[chainIndex]);
22618                 else
22619                     MrBayesPrint ("%s                         %1.1lf", spacer, mv->relProposalProb[chainIndex]);
22620
22621                 if (areChainsSame == NO && areRunsSame == YES)
22622                     MrBayesPrint ("  [chain %d]\n", chain+1);
22623                 else if (areChainsSame == YES && areRunsSame == NO)
22624                     MrBayesPrint ("  [run %d]\n", run+1);
22625                 else if (areChainsSame == NO && areRunsSame == NO)
22626                     MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
22627                 else
22628                     MrBayesPrint ("\n");
22629                 }
22630             }
22631         MrBayesPrint ("\n");
22632         }   /* next move */
22633         
22634     if (numPrintedMoves == 0)
22635         {
22636         if (used == YES)
22637             {
22638             MrBayesPrint ("%s      No moves currently used for this analysis. All parameters\n", spacer);
22639             MrBayesPrint ("%s      will be fixed to their starting values.\n\n", spacer);
22640             }
22641         else
22642             {
22643             MrBayesPrint ("%s      No additional moves available for this model.\n\n", spacer);
22644             }
22645         }
22646
22647     return (NO_ERROR);
22648 }
22649
22650
22651 /*------------------------------------------------------------------------------
22652 |
22653 |   ShowParameters: Show parameter table and parameter info
22654 |
22655 ------------------------------------------------------------------------------*/
22656 int ShowParameters (int showStartVals, int showMoves, int showAllAvailable)
22657 {
22658     int             a, b, d, i, j, k, m, n, run, chain, shouldPrint, isSame, areRunsSame, areChainsSame, nValues,
22659                     chainIndex, refIndex, numPrinted, numMovedChains, printedCol, screenWidth=100;
22660     Param           *p;
22661     Model           *mp;
22662     ModelInfo       *ms;
22663     MrBFlt          *value, *refValue, *subValue;
22664     MCMCMove        *mv;
22665     
22666     MrBayesPrint ("%s   Active parameters: \n\n", spacer);
22667     if (numCurrentDivisions > 1)
22668         { 
22669         MrBayesPrint ("%s                          Partition(s)\n", spacer);
22670         MrBayesPrint ("%s      Parameters        ", spacer);
22671         for (i=0; i<numCurrentDivisions; i++)
22672             MrBayesPrint (" %2d", i+1);
22673         MrBayesPrint ("\n");
22674         MrBayesPrint ("%s      ------------------", spacer);
22675         for (i=0; i<numCurrentDivisions; i++)
22676             MrBayesPrint ("---");
22677         MrBayesPrint ("\n");
22678         }
22679     else
22680         {
22681         MrBayesPrint ("%s      Parameters\n", spacer);
22682         MrBayesPrint ("%s      ---------------------\n", spacer);
22683         }
22684     for (j=0; j<NUM_LINKED; j++)
22685         {
22686         shouldPrint = NO;
22687         for (i=0; i<numCurrentDivisions; i++)
22688             {
22689             if (activeParams[j][i] == -1)
22690                 {}
22691             else
22692                 shouldPrint = YES;
22693             }
22694         if (shouldPrint == NO)
22695             continue;
22696         
22697         if (j == P_TRATIO)
22698             {
22699             MrBayesPrint ("%s      Tratio            ", spacer);
22700             }
22701         else if (j == P_REVMAT)
22702             {
22703             MrBayesPrint ("%s      Revmat            ", spacer);
22704             }
22705         else if (j == P_OMEGA)
22706             {
22707             MrBayesPrint ("%s      Omega             ", spacer);
22708             }
22709         else if (j == P_PI)
22710             {
22711             MrBayesPrint ("%s      Statefreq         ", spacer);
22712             }
22713         else if (j == P_SHAPE)
22714             {
22715             MrBayesPrint ("%s      Shape             ", spacer);
22716             }
22717         else if (j == P_PINVAR)
22718             {
22719             MrBayesPrint ("%s      Pinvar            ", spacer);
22720             }
22721         else if (j == P_CORREL)
22722             {
22723             MrBayesPrint ("%s      Correlation       ", spacer);
22724             }
22725         else if (j == P_SWITCH)
22726             {
22727             MrBayesPrint ("%s      Switchrates       ", spacer);
22728             }
22729         else if (j == P_RATEMULT)
22730             {
22731             MrBayesPrint ("%s      Ratemultiplier    ", spacer);
22732             }
22733         else if (j == P_GENETREERATE)
22734             {
22735             MrBayesPrint ("%s      Generatemult      ", spacer);
22736             }
22737         else if (j == P_TOPOLOGY)
22738             {
22739             MrBayesPrint ("%s      Topology          ", spacer);
22740             }
22741         else if (j == P_BRLENS)
22742             {
22743             MrBayesPrint ("%s      Brlens            ", spacer);
22744             }
22745         else if (j == P_SPECRATE)
22746             {
22747             MrBayesPrint ("%s      Speciationrate    ", spacer);
22748             }
22749         else if (j == P_EXTRATE)
22750             {
22751             MrBayesPrint ("%s      Extinctionrate    ", spacer);
22752             }
22753         else if (j == P_FOSLRATE)
22754             {
22755             MrBayesPrint ("%s      Fossilizationrate ", spacer);
22756             }
22757         else if (j == P_POPSIZE)
22758             {
22759             MrBayesPrint ("%s      Popsize           ", spacer);
22760             }
22761         else if (j == P_GROWTH)
22762             {
22763             MrBayesPrint ("%s      Growthrate        ", spacer);
22764             } 
22765         else if (j == P_AAMODEL)
22766             {
22767             MrBayesPrint ("%s      Aamodel           ", spacer);
22768             }
22769         else if (j == P_BRCORR)
22770             {
22771             MrBayesPrint ("%s      Brownian corr.    ", spacer);
22772             }
22773         else if (j == P_BRSIGMA)
22774             {
22775             MrBayesPrint ("%s      Brownian sigma    ", spacer);
22776             }
22777         else if (j == P_CPPRATE)
22778             {
22779             MrBayesPrint ("%s      Cpprate           ", spacer);
22780             }
22781         else if (j == P_CPPMULTDEV)
22782             {
22783             MrBayesPrint ("%s      Cppmultdev        ", spacer);
22784             }
22785         else if (j == P_CPPEVENTS)
22786             {
22787             MrBayesPrint ("%s      Cppevents         ", spacer);
22788             }
22789         else if (j == P_TK02VAR)
22790             {
22791             MrBayesPrint ("%s      TK02var           ", spacer);
22792             }
22793         else if (j == P_TK02BRANCHRATES)
22794             {
22795             MrBayesPrint ("%s      TK02branchrates   ", spacer);
22796             }
22797         else if (j == P_IGRVAR)
22798             {
22799             MrBayesPrint ("%s      Igrvar            ", spacer);
22800             }
22801         else if (j == P_IGRBRANCHRATES)
22802             {
22803             MrBayesPrint ("%s      Igrbranchrates    ", spacer);
22804             }
22805         else if (j == P_MIXEDVAR)
22806             {
22807             MrBayesPrint ("%s      Mixedvar          ", spacer);
22808             }
22809         else if (j == P_MIXEDBRCHRATES)
22810             {
22811             MrBayesPrint ("%s      Mixedbranchrates  ", spacer);
22812             }
22813         else if (j == P_CLOCKRATE)
22814             {
22815             MrBayesPrint ("%s      Clockrate         ", spacer);
22816             }
22817         else if (j == P_SPECIESTREE)
22818             {
22819             MrBayesPrint ("%s      Speciestree       ", spacer);
22820             }
22821         else
22822             {
22823             MrBayesPrint ("%s      ERROR: Someone forgot to name parameter type %d", spacer, j);
22824             return (ERROR);
22825             }
22826         
22827         for (i=0; i<numCurrentDivisions; i++)
22828             {
22829             if (activeParams[j][i] == -1)
22830                 MrBayesPrint ("  .");
22831             else
22832                 MrBayesPrint (" %2d", activeParams[j][i]);
22833             }
22834         MrBayesPrint ("\n");
22835         }
22836     if (numCurrentDivisions > 1)
22837         { 
22838         MrBayesPrint ("%s      ------------------", spacer);
22839         for (i=0; i<numCurrentDivisions; i++)
22840             MrBayesPrint ("---");
22841         MrBayesPrint ("\n");
22842         }
22843     else
22844         {
22845         MrBayesPrint ("%s      ---------------------\n", spacer);
22846         }
22847     
22848     MrBayesPrint ("\n");
22849     
22850     if (numCurrentDivisions > 1)
22851         MrBayesPrint ("%s      Parameters can be linked or unlinked across partitions using 'link' and 'unlink'\n\n", spacer);
22852     
22853     for (i=0; i<numParams; i++)
22854         {
22855         p = &params[i];
22856         j = p->paramType;
22857         
22858         mp = &modelParams[p->relParts[0]];
22859         ms = &modelSettings[p->relParts[0]];
22860         
22861         /* print parameter number and name */
22862         MrBayesPrint ("%s   %4d --  Parameter  = %s\n", spacer, i+1, p->name);
22863         MrBayesPrint ("%s            Type       = %s\n", spacer, p->paramTypeName);
22864         /* print prior */
22865         if (j == P_TRATIO)
22866             {
22867             if (!strcmp(mp->tRatioPr,"Beta"))
22868                 MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf)\n", spacer, mp->tRatioDir[0], modelParams[i].tRatioDir[1]);
22869             else
22870                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->tRatioFix);
22871             }
22872         else if (j == P_REVMAT)
22873             {
22874             if (ms->numModelStates != 20)
22875                 {
22876                 if (!strcmp(mp->nst,"Mixed"))
22877                     {
22878                     MrBayesPrint ("%s            Prior      = All GTR submodels have equal probability\n", spacer); 
22879                     MrBayesPrint ("%s                         All revmat rates have a Symmetric Dirichlet(%1.2lf) prior\n", spacer, mp->revMatSymDir);
22880                     }
22881                 else if (!strcmp(mp->revMatPr,"Dirichlet"))
22882                     {
22883                     MrBayesPrint ("%s            Prior      = Dirichlet(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer, 
22884                     mp->revMatDir[0], mp->revMatDir[1], mp->revMatDir[2],
22885                     mp->revMatDir[3], mp->revMatDir[4], mp->revMatDir[5]);
22886                     }
22887                 else
22888                     MrBayesPrint ("%s            Prior      = Fixed(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer, 
22889                     mp->revMatFix[0], mp->revMatFix[1], mp->revMatFix[2],
22890                     mp->revMatFix[3], mp->revMatFix[4], mp->revMatFix[5]);
22891                 }
22892             else if (ms->numModelStates == 20)
22893                 {
22894                 if (!strcmp(mp->aaRevMatPr,"Dirichlet"))
22895                     MrBayesPrint ("%s            Prior      = Dirichlet\n", spacer);
22896                 else
22897                     MrBayesPrint ("%s            Prior      = Fixed(user-specified)\n", spacer);
22898                 }
22899             }
22900         else if (j == P_OMEGA)
22901             {
22902             if (!strcmp(mp->omegaVar,"Equal"))
22903                 {
22904                 if (!strcmp(mp->omegaPr,"Dirichlet"))
22905                     MrBayesPrint ("%s            Prior      = Dirichlet(%1.2lf,%1.2lf)\n", spacer, mp->omegaDir[0], mp->omegaDir[1]);
22906                 else
22907                     MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->omegaFix);
22908                 }
22909             else if (!strcmp(mp->omegaVar,"Ny98"))
22910                 {
22911                 if (!strcmp(mp->ny98omega1pr,"Beta"))
22912                     MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf) on omega(1)\n", spacer, mp->ny98omega1Beta[0], mp->ny98omega1Beta[1]);
22913                 else
22914                     MrBayesPrint ("%s            Prior      = Fixed(%1.2lf) on omega(1)\n", spacer, mp->ny98omega1Fixed);
22915                 MrBayesPrint ("%s                         Fixed(1.00) on omega(2)\n", spacer);
22916                 if (!strcmp(mp->ny98omega3pr,"Uniform"))
22917                     MrBayesPrint ("%s                         Uniform(%1.2lf,%1.2lf) on omega(3)\n", spacer, mp->ny98omega3Uni[0], mp->ny98omega3Uni[1]);
22918                 else if (!strcmp(mp->ny98omega3pr,"Exponential"))
22919                     MrBayesPrint ("%s                         Exponential(%1.2lf) on omega(3)\n", spacer, mp->ny98omega3Exp);
22920                 else
22921                     MrBayesPrint ("%s                         Fixed(%1.2lf) on omega(3)\n", spacer, mp->ny98omega3Fixed);
22922                 if (!strcmp(mp->codonCatFreqPr,"Dirichlet"))
22923                     MrBayesPrint ("%s                         Dirichlet(%1.2lf,%1.2lf,%1.2lf) on pi(-), pi(N), and pi(+)\n", spacer, mp->codonCatDir[0], mp->codonCatDir[1], mp->codonCatDir[2]);
22924                 else
22925                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf,%1.2lf) on pi(-), pi(N), and pi(+)\n", spacer, mp->codonCatFreqFix[0], mp->codonCatFreqFix[1], mp->codonCatFreqFix[2]);
22926                 }
22927             else if (!strcmp(mp->omegaVar,"M3"))
22928                 {
22929                 if (!strcmp(mp->m3omegapr,"Exponential"))
22930                     MrBayesPrint ("%s                         dN1, dN2, dN3, and dS are all exponential random variables\n", spacer);
22931                 else
22932                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf,%1.2lf) for the three selection categories\n", spacer, mp->m3omegaFixed[0], mp->m3omegaFixed[1], mp->m3omegaFixed[2]);
22933                 if (!strcmp(mp->codonCatFreqPr,"Dirichlet"))
22934                     MrBayesPrint ("%s                         Dirichlet(%1.2lf,%1.2lf,%1.2lf) on pi(1), pi(2), and pi(3)\n", spacer, mp->codonCatDir[0], mp->codonCatDir[1], mp->codonCatDir[2]);
22935                 else
22936                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf,%1.2lf) on pi(1), pi(2), and pi(3)\n", spacer, mp->codonCatFreqFix[0], mp->codonCatFreqFix[1], mp->codonCatFreqFix[2]);
22937                 }
22938             else if (!strcmp(mp->omegaVar,"M10"))
22939                 {
22940                 MrBayesPrint ("%s                         With probability pi(1), omega is drawn from a Beta(alpha1,beta1) \n", spacer);
22941                 MrBayesPrint ("%s                         distribution and with probability pi(2), omega is drawn from\n", spacer);
22942                 MrBayesPrint ("%s                         a Gamma(alpha2,beta2) distribution.\n", spacer);
22943                 if (!strcmp(mp->m10betapr,"Uniform"))
22944                     {
22945                     MrBayesPrint ("%s                         The parameters of the beta distribution each follow \n", spacer);
22946                     MrBayesPrint ("%s                         independent Uniform(%1.2lf,%1.2lf) priors\n", spacer, mp->m10betaUni[0], mp->m10betaUni[1]);
22947                     }
22948                 else if (!strcmp(mp->m10betapr,"Exponential"))
22949                     {
22950                     MrBayesPrint ("%s                         The parameters of the beta distribution each follow \n", spacer);
22951                     MrBayesPrint ("%s                         independent Exponential(%1.2lf) priors\n", spacer, mp->m10betaExp);
22952                     }
22953                 else
22954                     {
22955                     MrBayesPrint ("%s                         The parameters of the beta distribution are fixed to \n", spacer);
22956                     MrBayesPrint ("%s                         %1.2lf and %1.2lf\n", spacer, mp->m10betaFix[0], mp->m10betaFix[0]);
22957                     }
22958
22959                 if (!strcmp(mp->m10gammapr,"Uniform"))
22960                     {
22961                     MrBayesPrint ("%s                         The parameters of the gamma distribution each follow  \n", spacer);
22962                     MrBayesPrint ("%s                         independent Uniform(%1.2lf,%1.2lf) priors\n", spacer, mp->m10gammaUni[0], mp->m10gammaUni[1]);
22963                     }
22964                 else if (!strcmp(mp->m10gammapr,"Exponential"))
22965                     {
22966                     MrBayesPrint ("%s                         The parameters of the gamma distribution each follow \n", spacer);
22967                     MrBayesPrint ("%s                         independent Exponential(%1.2lf) priors\n", spacer, mp->m10gammaExp);
22968                     }
22969                 else
22970                     {
22971                     MrBayesPrint ("%s                         The parameters of the gamma distribution are fixed to \n", spacer);
22972                     MrBayesPrint ("%s                         %1.2lf and %1.2lf\n", spacer, mp->m10gammaFix[0], mp->m10gammaFix[0]);
22973                     }
22974
22975                 if (!strcmp(mp->codonCatFreqPr,"Dirichlet"))
22976                     MrBayesPrint ("%s                         Dirichlet(%1.2lf,%1.2lf) on pi(1) and pi(2)\n", spacer, mp->codonCatDir[0], mp->codonCatDir[1]);
22977                 else
22978                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf) on pi(1) and pi(2)\n", spacer, mp->codonCatFreqFix[0], mp->codonCatFreqFix[1]);
22979                 }
22980             }
22981         else if (j == P_PI)
22982             {
22983             if (ms->dataType == STANDARD)
22984                 {
22985                 if (!strcmp(mp->symPiPr, "Uniform"))
22986                     MrBayesPrint ("%s            Prior      = Symmetric dirichlet with uniform(%1.2lf,%1.2lf) variance parameter\n", spacer, mp->symBetaUni[0], mp->symBetaUni[1]);
22987                 else if (!strcmp(mp->symPiPr, "Exponential"))
22988                     MrBayesPrint ("%s            Prior      = Symmetric dirichlet with exponential(%1.2lf) variance parameter\n", spacer, mp->symBetaExp);
22989                 else
22990                     { /* mp->symBetaFix == -1 */
22991                     if (AreDoublesEqual(mp->symBetaFix, -1.0, ETA)==YES)
22992                         MrBayesPrint ("%s            Prior      = Symmetric dirichlet with all parameters equal to infinity\n", spacer);
22993                     else
22994                         MrBayesPrint ("%s            Prior      = Symmetric dirichlet with all parameters equal to %1.2lf\n", spacer, mp->symBetaFix);
22995                     }
22996                 }
22997             else if (ms->dataType == PROTEIN)
22998                 {
22999                 if (!strcmp(mp->aaModelPr, "Fixed") && (!strcmp(mp->aaModel, "Equalin") || !strcmp(mp->aaModel, "Gtr")))
23000                     {
23001                     if (!strcmp(mp->stateFreqPr,"Dirichlet"))
23002                         {
23003                         MrBayesPrint ("%s            Prior      = Dirichlet\n", spacer);
23004                         }
23005                     else if (!strcmp(mp->stateFreqPr,"Fixed") && !strcmp(mp->stateFreqsFixType,"Equal"))
23006                         {
23007                         MrBayesPrint ("%s            Prior      = Fixed (equal frequencies)\n", spacer);
23008                         }
23009                     else if (!strcmp(mp->stateFreqPr,"Fixed") && !strcmp(mp->stateFreqsFixType,"User"))
23010                         {
23011                         MrBayesPrint ("%s            Prior      = Fixed (user-specified)\n", spacer);
23012                         }
23013                     else if (!strcmp(mp->stateFreqPr,"Fixed") && !strcmp(mp->stateFreqsFixType,"Empirical"))
23014                         {
23015                         MrBayesPrint ("%s            Prior      = Fixed (empirical frequencies)\n", spacer);
23016                         }
23017                     }
23018                 else if (!strcmp(mp->aaModelPr, "Fixed") && !strcmp(mp->aaModel, "Poisson"))
23019                     {
23020                     MrBayesPrint ("%s            Prior      = Fixed (equal frequencies)\n", spacer);
23021                     }
23022                 else if (!strcmp(mp->aaModelPr, "Fixed") && strcmp(mp->aaModel, "Equalin") && strcmp(mp->aaModel, "Poisson"))
23023                     {
23024                     MrBayesPrint ("%s            Prior      = Fixed (%s frequencies)\n", spacer, mp->aaModel);
23025                     }
23026                 else
23027                     {
23028                     MrBayesPrint ("%s            Prior      = Fixed (from mixture of models)\n", spacer);
23029                     }
23030                 }
23031             else
23032                 {
23033                 if (!strcmp(mp->stateFreqPr,"Dirichlet"))
23034                     MrBayesPrint ("%s            Prior      = Dirichlet\n", spacer);
23035                 else
23036                     MrBayesPrint ("%s            Prior      = Fixed\n", spacer);
23037                 }
23038             }
23039         else if (j == P_SHAPE)
23040             {
23041             if (!strcmp(mp->shapePr,"Uniform"))
23042                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->shapeUni[0], mp->shapeUni[1]);
23043             else if (!strcmp(mp->shapePr,"Exponential"))
23044                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->shapeExp);
23045             else
23046                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->shapeFix);
23047             }
23048         else if (j == P_PINVAR)
23049             {
23050             if (!strcmp(mp->pInvarPr,"Uniform"))
23051                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->pInvarUni[0], mp->pInvarUni[1]);
23052             else
23053                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->pInvarFix);
23054             }
23055         else if (j == P_CORREL)
23056             {
23057             if (!strcmp(mp->adGammaCorPr,"Uniform"))
23058                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->corrUni[0], mp->corrUni[1]);
23059             else
23060                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->corrFix);
23061             }
23062         else if (j == P_SWITCH)
23063             {
23064             if (!strcmp(mp->covSwitchPr,"Uniform"))
23065                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->covswitchUni[0], mp->covswitchUni[1]);
23066             else if (!strcmp(mp->covSwitchPr,"Exponential"))
23067                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->covswitchExp);
23068             else
23069                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf,%1.2lf)\n", spacer, mp->covswitchFix[0], mp->covswitchFix[1]);
23070             }
23071         else if (j == P_RATEMULT)
23072             {
23073             if (!strcmp(mp->ratePr,"Fixed"))
23074                 MrBayesPrint ("%s            Prior      = Fixed(1.0)\n", spacer);
23075             else
23076                 {
23077                 MrBayesPrint ("%s            Prior      = Dirichlet(", spacer);
23078                 for (d=n=0; d<numCurrentDivisions; d++)
23079                     {
23080                     if (activeParams[j][d] == i+1)
23081                         n++;
23082                     }
23083                 for (d=m=0; d<numCurrentDivisions; d++)
23084                     {
23085                     if (activeParams[j][d] == i+1)
23086                         {
23087                         m++;
23088                         if (m < n)
23089                             MrBayesPrint ("%1.2lf,", modelParams[d].ratePrDir);
23090                         else
23091                             MrBayesPrint ("%1.2lf)\n", modelParams[d].ratePrDir);
23092                         }
23093                     }
23094                 }
23095             }
23096         else if (j == P_GENETREERATE)
23097             {
23098             if (!strcmp(mp->generatePr,"Fixed"))
23099                 MrBayesPrint ("%s            Prior      = Fixed(1.0)\n", spacer);
23100             else
23101                 {
23102                 MrBayesPrint ("%s            Prior      = Dirichlet(", spacer);
23103                 printedCol = (int)(strlen(spacer)) + 25 + 10;
23104                 for (n=0; n<numTrees-1; n++)
23105                     {
23106                     if (printedCol + 5 > screenWidth)
23107                         {
23108                         MrBayesPrint("\n%s                                   ", spacer);
23109                         printedCol = (int)(strlen(spacer)) + 25 + 10;
23110                         }
23111                     if (n == numTrees-2)
23112                         MrBayesPrint ("1.00)\n");
23113                     else
23114                         MrBayesPrint ("1.00,");
23115                     printedCol += 5;
23116                     }
23117                 }
23118             }
23119         else if (j == P_TOPOLOGY)
23120             {
23121             if (!strcmp(mp->topologyPr,"Uniform"))
23122                 MrBayesPrint ("%s            Prior      = All topologies equally probable a priori\n", spacer);
23123             else if (!strcmp(mp->topologyPr,"Speciestree"))
23124                 MrBayesPrint ("%s            Prior      = Topology constrained to fold within species tree\n", spacer);
23125             else if (!strcmp(mp->topologyPr,"Constraints"))
23126                 MrBayesPrint ("%s            Prior      = Prior on topologies obeys constraints\n", spacer);
23127             else
23128                 MrBayesPrint ("%s            Prior      = Prior is fixed to the topology of user tree '%s'\n", spacer,
23129                                                     userTree[mp->topologyFix]->name);
23130             }
23131         else if (j == P_BRLENS)
23132             {
23133             if (!strcmp(mp->parsModel, "Yes"))
23134                 MrBayesPrint ("%s            Prior      = Reconstructed using parsimony\n", spacer);
23135             else
23136                 {
23137                 if (!strcmp(mp->brlensPr,"Unconstrained"))
23138                     {
23139                     MrBayesPrint ("%s            Prior      = Unconstrained:%s", spacer, mp->unconstrainedPr);
23140                     if (!strcmp(mp->unconstrainedPr, "Uniform"))
23141                         MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->brlensUni[0], mp->brlensUni[1]);
23142                     else if (!strcmp(mp->unconstrainedPr, "Exponential"))
23143                         MrBayesPrint ("(%1.1lf)\n", mp->brlensExp);
23144                     else if (!strcmp(mp->unconstrainedPr, "twoExp"))
23145                         MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->brlens2Exp[0], mp->brlens2Exp[1]);
23146                     else
23147                         MrBayesPrint ("(%1.1lf,%1.4lf,%1.1lf,%1.1lf)\n", mp->brlensDir[0], mp->brlensDir[1], mp->brlensDir[2], mp->brlensDir[3]);
23148                     }
23149                 else if (!strcmp(mp->brlensPr, "Clock"))
23150                     {
23151                     MrBayesPrint ("%s            Prior      = Clock:%s\n", spacer, mp->clockPr);
23152                     if ((!strcmp(mp->clockPr,"Uniform") || !strcmp(mp->clockPr,"Fossilization")) && !strcmp(mp->nodeAgePr,"Unconstrained"))
23153                         {
23154                         MrBayesPrint ("%s                         Tree age has a %s distribution\n", spacer, mp->treeAgePr.name);
23155                         }
23156                     else if (!strcmp(mp->clockPr, "Birthdeath") && !strcmp(mp->nodeAgePr,"Unconstrained"))
23157                         {
23158                         MrBayesPrint ("%s                         Tree age has a Uniform(0,infinity) distribution\n", spacer);
23159                         }
23160                     if (!strcmp(mp->nodeAgePr,"Calibrated"))
23161                         {
23162                         b = 0;
23163                         for (a=0; a<numTaxa; a++)
23164                             {
23165                             if (taxaInfo[a].isDeleted == NO && tipCalibration[a].prior != unconstrained)
23166                                 b++;
23167                             }
23168                         for (a=0; a<numDefinedConstraints; a++)
23169                             {
23170                             if (mp->activeConstraints[a] == YES && nodeCalibration[a].prior != unconstrained)
23171                                 b++;
23172                             }
23173                         if (b > 1)
23174                             MrBayesPrint ("%s                         Node depths are constrained by the following age constraints:\n", spacer);
23175                         else
23176                             MrBayesPrint ("%s                         Node depths are calibrated by the following age constraint:\n", spacer);
23177                         for (a=0; a<numTaxa; a++)
23178                             {
23179                             if (taxaInfo[a].isDeleted == NO && tipCalibration[a].prior != unconstrained)
23180                                 {
23181                                 MrBayesPrint ("%s                         -- The age of terminal \"%s\" is %s\n", spacer, taxaNames[a],
23182                                     tipCalibration[a].name);
23183                                 }
23184                             }
23185                         for (a=b=0; a<numDefinedConstraints; a++)
23186                             {
23187                             if (mp->activeConstraints[a] == YES && nodeCalibration[a].prior != unconstrained)
23188                                 {
23189                                 MrBayesPrint ("%s                         -- The age of node '%s' is %s\n", spacer,
23190                                     constraintNames[a], nodeCalibration[a].name);
23191                                 for (k=0; k<numTaxa; k++)
23192                                     if (taxaInfo[k].isDeleted == NO && IsBitSet(k,definedConstraint[a]) == NO)
23193                                         break;
23194                                 if (k == numTaxa)
23195                                     b = 1;          /* root is calibrated */
23196                                 }
23197                             }
23198                         if (b == 0) /* we need to use default calibration for root for uniform and birthdeath */
23199                             {
23200                             if (!strcmp(mp->clockPr,"Uniform") || !strcmp(mp->clockPr,"Fossilization"))
23201                                 {
23202                                 MrBayesPrint ("%s                         -- Tree age has a %s distribution\n", spacer, mp->treeAgePr.name);
23203                                 }
23204                             else if (!strcmp(mp->clockPr,"Birthdeath"))
23205                                 {
23206                                 MrBayesPrint ("%s                         -- Tree age has a Uniform(0,infinity) distribution\n", spacer);
23207                                 }
23208                             }
23209                         }
23210                     else
23211                         MrBayesPrint ("%s                         Node ages are not constrained\n", spacer);
23212                     }
23213                 else
23214                     {
23215                     assert (!strcmp(mp->brlensPr, "Fixed"));
23216                     MrBayesPrint ("%s            Prior      = Fixed, branch lengths are fixed to the ones of the user tree '%s'\n", spacer,
23217                                                     userTree[mp->topologyFix]->name);
23218                     }
23219                 }
23220             }
23221         else if (j == P_SPECRATE)
23222             {
23223             if (!strcmp(mp->speciationPr,"Uniform"))
23224                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->speciationUni[0], mp->speciationUni[1]);
23225             else if (!strcmp(mp->speciationPr,"Exponential"))
23226                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->speciationExp);
23227             else
23228                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->speciationFix);
23229             }
23230         else if (j == P_EXTRATE)
23231             {
23232             if (!strcmp(mp->extinctionPr,"Beta"))
23233                 MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf)\n", spacer, mp->extinctionBeta[0], mp->extinctionBeta[1]);
23234             else
23235                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->extinctionFix);
23236             }
23237         else if (j == P_FOSLRATE)
23238             {
23239             if (!strcmp(mp->fossilizationPr,"Beta"))
23240                 MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf)\n", spacer, mp->fossilizationBeta[0], mp->fossilizationBeta[1]);
23241             else
23242                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->fossilizationFix);
23243             }
23244         else if (j == P_POPSIZE)
23245             {
23246             if (!strcmp(mp->popSizePr,"Uniform"))
23247                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->popSizeUni[0], mp->popSizeUni[1]);
23248             else if (!strcmp(mp->popSizePr,"Lognormal"))
23249                 MrBayesPrint ("%s            Prior      = Lognormal(%1.2lf,%1.2lf)\n", spacer, mp->popSizeLognormal[0], mp->popSizeLognormal[1]);
23250             else if (!strcmp(mp->popSizePr,"Normal"))
23251                 MrBayesPrint ("%s            Prior      = Truncated Normal(%1.2lf,%1.2lf)\n", spacer, mp->popSizeNormal[0], mp->popSizeNormal[1]);
23252             else if (!strcmp(mp->popSizePr,"Gamma"))
23253                 MrBayesPrint ("%s            Prior      = Gamma(%1.2lf,%1.2lf)\n", spacer, mp->popSizeGamma[0], mp->popSizeGamma[1]);
23254             else
23255                 MrBayesPrint ("%s            Prior      = Fixed(%1.5lf)\n", spacer, mp->popSizeFix);
23256             if (!strcmp(mp->topologyPr,"Speciestree"))
23257                 {
23258                 if (!strcmp(mp->popVarPr,"Equal") || !strcmp(mp->popSizePr,"Fixed"))
23259                     MrBayesPrint ("%s                         Population size the same across species tree\n", spacer);
23260                 else
23261                     MrBayesPrint ("%s                         Population size varies across branches in species tree\n", spacer);
23262                 }
23263             }
23264         else if (j == P_GROWTH)
23265             {
23266             if (!strcmp(mp->growthPr,"Uniform"))
23267                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->growthUni[0], mp->growthUni[1]);
23268             else if (!strcmp(mp->growthPr,"Exponential"))
23269                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->growthExp);
23270             else if (!strcmp(mp->growthPr,"Normal"))
23271                 MrBayesPrint ("%s            Prior      = Normal(%1.2lf,%1.2lf)\n", spacer, mp->growthNorm[0], mp->growthNorm[1]);
23272             else
23273                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->growthFix);
23274             } 
23275         else if (j == P_AAMODEL)
23276             {
23277             if (!strcmp(mp->aaModelPr,"Mixed"))
23278                 {
23279                 /* check to see if you have a uniform prior */
23280                 isSame = YES;
23281                 for (a=0; a<9; a++)
23282                     for (b=a+1; b<10; b++)
23283                             /* mp->aaModelPrProbs[a] != mp->aaModelPrProbs[b] */
23284                     if (AreDoublesEqual(mp->aaModelPrProbs[a], mp->aaModelPrProbs[b], ETA)==FALSE)
23285                             isSame = NO;
23286                 MrBayesPrint ("%s            Prior      = Poisson, Jones, Dayhoff, Mtrev, Mtmam, Wag, Rtrev,\n", spacer);
23287                 if (isSame == YES)
23288                     MrBayesPrint ("%s                         Cprev, Vt, and Blosum models have equal prior probability\n", spacer);
23289                 else
23290                     MrBayesPrint ("%s                         Cprev, Vt, and Blosum models have unequal prior probability\n", spacer);
23291                 }
23292             else
23293                 MrBayesPrint ("%s            Prior      = Fixed(%s)\n", spacer, mp->aaModel);
23294             }
23295         else if (j == P_BRCORR)
23296             {
23297             if (!strcmp(mp->brownCorPr,"Uniform"))
23298                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->brownCorrUni[0], mp->brownCorrUni[1]);
23299             else
23300                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->brownCorrFix);
23301             }
23302         else if (j == P_BRSIGMA)
23303             {
23304             if (!strcmp(mp->brownScalesPr,"Uniform"))
23305                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->brownScalesUni[0], mp->brownScalesUni[1]);
23306             else if (!strcmp(mp->brownScalesPr,"Gammamean"))
23307                 MrBayesPrint ("%s            Prior      = Gamma Mean=<char. ave.> Var=%1.2lf\n", spacer, mp->brownScalesGammaMean);
23308             else if (!strcmp(mp->brownScalesPr,"Gamma"))
23309                 MrBayesPrint ("%s            Prior      = Gamma Mean=%lf Var=%1.2lf\n", spacer, mp->brownScalesGamma[0], mp->brownScalesGamma[1]);
23310             else
23311                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->brownScalesFix);
23312             }
23313         else if (j == P_CPPRATE)
23314             {
23315             if (!strcmp(mp->cppRatePr,"Exponential"))
23316                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->cppRateExp);
23317             else
23318                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->cppRateFix);
23319             }
23320         else if (j == P_CPPMULTDEV)
23321             {
23322             if (!strcmp(mp->cppMultDevPr,"Fixed"))
23323                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->cppMultDevFix);
23324             }
23325         else if (j == P_CPPEVENTS)
23326             {
23327             MrBayesPrint ("%s            Prior      = Poisson (%s) [Events]\n", spacer, modelSettings[p->relParts[0]].cppRate->name);
23328             MrBayesPrint ("%s                         Lognormal (0.00,%1.2lf) [Rate multipliers]\n", spacer, mp->cppMultDevFix);
23329             }
23330         else if (j == P_TK02VAR)
23331             {
23332             if (!strcmp(mp->tk02varPr,"Uniform"))
23333                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->tk02varUni[0], mp->tk02varUni[1]);
23334             else if (!strcmp(mp->tk02varPr,"Exponential"))
23335                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->tk02varExp);
23336             else
23337                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->tk02varFix);
23338             }
23339         else if (j == P_TK02BRANCHRATES)
23340             {
23341             MrBayesPrint ("%s            Prior      = LogNormal (expectation = r_0, variance = %s * v) \n", spacer, modelSettings[p->relParts[0]].tk02var->name);
23342             MrBayesPrint ("%s                            [r_0 is beginning rate of branch, v is branch length]\n", spacer);
23343             }
23344         else if (j == P_IGRVAR)
23345             {
23346             if (!strcmp(mp->igrvarPr,"Uniform"))
23347                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->igrvarUni[0], mp->igrvarUni[1]);
23348             else if (!strcmp(mp->igrvarPr,"Exponential"))
23349                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->igrvarExp);
23350             else
23351                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->igrvarFix);
23352             }
23353         else if (j == P_IGRBRANCHRATES)
23354             {
23355             MrBayesPrint ("%s            Prior      = Gamma (expectation = v, variance = %s * v) \n", spacer, modelSettings[p->relParts[0]].igrvar->name);
23356             MrBayesPrint ("%s                            [where v is branch length]\n", spacer);
23357             }
23358         else if (j == P_MIXEDVAR)
23359             {
23360             if (!strcmp(mp->mixedvarPr,"Uniform"))
23361                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->mixedvarUni[0], mp->mixedvarUni[1]);
23362             else if (!strcmp(mp->mixedvarPr,"Exponential"))
23363                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->mixedvarExp);
23364             else
23365                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->mixedvarFix);
23366             }
23367         else if (j == P_MIXEDBRCHRATES)
23368             {
23369             MrBayesPrint ("%s            Prior      = Mixed TK02 and IGR (variance = %s * v)\n", spacer, modelSettings[p->relParts[0]].mixedvar->name);
23370             MrBayesPrint ("%s                            [where v is branch length]\n", spacer);
23371             MrBayesPrint ("%s                         Uniform prior on relaxed clock models [Pr(TK02)=Pr(IGR)=1/2]\n", spacer);
23372             }
23373         else if (j == P_CLOCKRATE)
23374             {
23375             if (!strcmp(mp->clockRatePr,"Normal"))
23376                 MrBayesPrint ("%s            Prior      = Normal(%1.6lf,%1.6lf)\n", spacer, mp->clockRateNormal[0], mp->clockRateNormal[1]);
23377             else if (!strcmp(mp->clockRatePr,"Lognormal"))
23378                 MrBayesPrint ("%s            Prior      = Lognormal(%1.2lf,%1.2lf)\n", spacer, mp->clockRateLognormal[0], mp->clockRateLognormal[1]);
23379             else if (!strcmp(mp->clockRatePr,"Gamma"))
23380                 MrBayesPrint ("%s            Prior      = Gamma(%1.2lf,%1.2lf)\n", spacer, mp->clockRateGamma[0], mp->clockRateGamma[1]);
23381             else if (!strcmp(mp->clockRatePr,"Exponential"))
23382                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->clockRateExp);
23383             else
23384                 MrBayesPrint ("%s            Prior      = Fixed(%1.6lf)\n", spacer, mp->clockRateFix);
23385             if (!strcmp(mp->clockVarPr,"Strict"))
23386                 MrBayesPrint ("%s                         The clock rate is constant (strict clock)\n", spacer);
23387             else if (!strcmp(mp->clockVarPr,"Cpp"))
23388                 MrBayesPrint ("%s                         The clock rate varies according to a CPP model\n", spacer);
23389             else if (!strcmp(mp->clockVarPr,"TK02"))
23390                 MrBayesPrint ("%s                         The clock rate varies according to a Brownian motion model\n", spacer);
23391             else if (!strcmp(mp->clockVarPr,"Igr"))
23392                 MrBayesPrint ("%s                         The clock rate varies according to an independent gamma (white noise) model\n", spacer);
23393             else /* if (!strcmp(mp->clockVarPr,"Mixed")) */
23394                 MrBayesPrint ("%s                         The clock rate varies according to mixed TK02 and IGR models\n", spacer);
23395             }
23396         else if (j == P_SPECIESTREE)
23397             {
23398             MrBayesPrint ("%s            Prior      = Uniform on topologies and branch lengths\n", spacer);
23399             }
23400                 
23401         /* print partitions */
23402         if (numCurrentDivisions > 1)
23403             {
23404             if (p->nRelParts == 1)
23405                 MrBayesPrint ("%s            Partition  = %d\n", spacer, p->relParts[0]+1);
23406             else if (p->nRelParts == 2)
23407                 {
23408                 MrBayesPrint ("%s            Partitions = %d and %d\n", spacer, p->relParts[0]+1, p->relParts[1]+1);                    
23409                 }
23410             else if (p->nRelParts == numCurrentDivisions)
23411                 {
23412                 MrBayesPrint ("%s            Partitions = All\n", spacer);                  
23413                 }           
23414             else /* if (p->nRelParts > 2) */
23415                 {
23416                 MrBayesPrint ("%s            Partitions = ", spacer);
23417                 for (j=0; j<p->nRelParts; j++)
23418                     {
23419                     if (j == p->nRelParts - 2)
23420                         MrBayesPrint ("%d, and ", p->relParts[j]+1);
23421                     else if (j == p->nRelParts - 1)
23422                         MrBayesPrint ("%d\n", p->relParts[j]+1);
23423                     else
23424                         MrBayesPrint ("%d, ", p->relParts[j]+1);
23425                     }               
23426                 }
23427             }
23428
23429         /* show subparams */
23430         if (p->nSubParams > 0)
23431             {
23432             if (p->nSubParams == 1)
23433                 MrBayesPrint ("%s            Subparam.  = %s\n", spacer, p->subParams[0]->name);
23434             else
23435                 {
23436                 printedCol = 0;
23437                 for (k=0; k<p->nSubParams; k++)
23438                     {
23439                     if (k == 0)
23440                         {
23441                         MrBayesPrint ("%s            Subparams  = %s", spacer, p->subParams[k]->name);
23442                         printedCol = (int)(strlen(spacer)) + 25 + (int)(strlen(p->subParams[k]->name));
23443                         }
23444                     else if (k == p->nSubParams - 1)
23445                         {
23446                         if (printedCol + 5 > screenWidth)
23447                             MrBayesPrint ("\n%s                         and ", spacer);
23448                         else if (printedCol + (int)(strlen(p->subParams[k]->name)) + 5 > screenWidth)
23449                             MrBayesPrint (" and \n%s                         ", spacer);
23450                         else
23451                             MrBayesPrint (" and ");
23452                         MrBayesPrint ("%s\n", p->subParams[k]->name);
23453                         }
23454                     else
23455                         {
23456                         if (printedCol + (int)(strlen(p->subParams[k]->name)) + 2 > screenWidth)
23457                             {
23458                             MrBayesPrint (", \n%s                         ", spacer);
23459                             printedCol = (int)(strlen(spacer)) + 25;
23460                             }
23461                         else
23462                             {
23463                             MrBayesPrint(", ");
23464                             printedCol += 2;
23465                             }
23466                         MrBayesPrint ("%s", p->subParams[k]->name);
23467                         printedCol += (int)strlen(p->subParams[k]->name);
23468                         }
23469                     }
23470                 }
23471             }
23472
23473         /* show used moves */
23474         if (showMoves == YES && (p->printParam == YES || p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS))
23475             {
23476             /* check if runs are same */
23477             areRunsSame = YES;
23478             for (run=1; run<chainParams.numRuns; run++)
23479                 {
23480                 for (chain=0; chain<chainParams.numChains; chain++)
23481                     {
23482                     for (k=0; k<numApplicableMoves; k++)
23483                         {
23484                         mv = moves[k];
23485                         if (mv->parm != p)
23486                             continue;
23487                         chainIndex = run*chainParams.numChains + chain;
23488                         refIndex = chain;
23489                         if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[refIndex], 0.000001) == NO)
23490                             areRunsSame = NO;
23491                         }
23492                     }
23493                 }
23494
23495             for (run=0; run<chainParams.numRuns; run++)
23496                 {
23497                 if (run > 0 && areRunsSame == YES)
23498                     continue;
23499                 
23500                 /* check if chains are same */
23501                 areChainsSame = YES;
23502                 for (chain=1; chain<chainParams.numChains; chain++)
23503                     {
23504                     for (k=0; k<numApplicableMoves; k++)
23505                         {
23506                         mv = moves[k];
23507                         if (mv->parm != p)
23508                             continue;
23509                         chainIndex = run*chainParams.numChains + chain;
23510                         refIndex = run*chainParams.numChains;
23511                         if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[refIndex], 0.000001) == NO)
23512                             areChainsSame = NO;
23513                         }
23514                     }
23515
23516                 /* now print moves */
23517                 for (chain=0; chain<chainParams.numChains; chain++)
23518                     {
23519                     if (chain > 0 && areChainsSame == YES)
23520                         continue;
23521                     if (run==0 && chain==0)
23522                         MrBayesPrint ("%s            Moves      = ", spacer);
23523                     else
23524                         MrBayesPrint ("%s                         ", spacer);
23525                     numPrinted = 0;
23526                     printedCol = (int)(strlen(spacer)) + 25;
23527                     for (k=0; k<numApplicableMoves; k++)
23528                         {
23529                         mv = moves[k];
23530                         if (mv->parm != p)
23531                             continue;
23532                         chainIndex = run*chainParams.numChains + chain;
23533                         if (mv->relProposalProb[chainIndex] <= 0.000001)
23534                             continue;
23535                         if (numPrinted == 0)
23536                             {
23537                             MrBayesPrint ("%s <prob %.1f>", mv->name, mv->relProposalProb[chainIndex]);
23538                             printedCol += 9 + (int)strlen(mv->name) + (int)(log10(mv->relProposalProb[chainIndex])) + 3;
23539                             }
23540                         else
23541                             {
23542                             if (printedCol + 11 + (int)(strlen(mv->name)) + (int)(log10(mv->relProposalProb[chainIndex])) + 3 > screenWidth)
23543                                 {
23544                                 MrBayesPrint(", \n%s                         ", spacer);
23545                                 printedCol = 25 + (int)(strlen(spacer));
23546                                 }
23547                             else
23548                                 {
23549                                 MrBayesPrint(", ");
23550                                 printedCol += 2;
23551                                 }
23552                             MrBayesPrint ("%s <prob %.1f>", mv->name, mv->relProposalProb[chainIndex]);
23553                             printedCol += (9 + (int)(strlen(mv->name)) + (int)(log10(mv->relProposalProb[chainIndex])) + 3);
23554                             }
23555                         numPrinted++;
23556                         }
23557
23558                     if (numPrinted == 0 && p->paramType == P_BRLENS)
23559                         {
23560                         for (k=0; k<numParams; k++)
23561                             if (params[k].tree == p->tree)
23562                                 break;
23563                         MrBayesPrint ("For moves, see param. '%s'", params[k].name);
23564                         }
23565                     else if (numPrinted == 0)
23566                         MrBayesPrint ("WARNING! No moves -- param. fixed to startvals");
23567
23568                     if (areRunsSame == YES && areChainsSame == YES)
23569                         MrBayesPrint ("\n");
23570                     else if (areRunsSame == YES && areChainsSame == NO)
23571                         MrBayesPrint (" [chain %d]\n", chain+1);
23572                     else if (areRunsSame == NO && areChainsSame == YES)
23573                         MrBayesPrint (" [run %d]\n", run+1);
23574                     else /* if (areRunsSame == NO && areChainsSame == NO) */
23575                             MrBayesPrint (" [run %d, chain %d]\n", run+1, chain+1);
23576                     }
23577                 }
23578             }
23579             
23580         /* show available moves */
23581         if (showAllAvailable == YES && (p->printParam == YES || p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS))
23582             {
23583             /* loop over moves */
23584             numPrinted = 0;
23585             printedCol = 0;
23586             for (k=0; k<numApplicableMoves; k++)
23587                 {
23588                 mv = moves[k];
23589                 if (mv->parm != p)
23590                     continue;
23591                 numMovedChains = 0;
23592                 for (run=0; run<chainParams.numRuns; run++)
23593                     {
23594                     for (chain=0; chain<chainParams.numChains; chain++)
23595                         {
23596                         chainIndex = run*chainParams.numChains + chain;
23597                         if (mv->relProposalProb[chainIndex] > 0.000001)
23598                             numMovedChains++;
23599                         }
23600                     }
23601                 if (numMovedChains == 0)
23602                     {
23603                     if (numPrinted == 0)
23604                         {
23605                         MrBayesPrint ("%s            Not used   = ", spacer);
23606                         printedCol = (int)(strlen(spacer)) + 25;
23607                         }
23608                     else if (printedCol + 2 + (int)(strlen(mv->moveType->shortName)) > screenWidth)
23609                         {
23610                         MrBayesPrint (", \n%s                         ", spacer);
23611                         printedCol = (int)(strlen(spacer)) + 25;
23612                         }
23613                     else
23614                         {
23615                         MrBayesPrint (", ");
23616                         printedCol += 2;
23617                         }
23618                     MrBayesPrint("%s", mv->moveType->shortName);
23619                     printedCol += (int)strlen(mv->moveType->shortName);
23620                     numPrinted++;
23621                     }
23622                 }
23623                 if (numPrinted > 0)
23624                     MrBayesPrint ("\n");
23625             }
23626
23627         /* show startvals */
23628         if (showStartVals == YES && (p->printParam == YES || p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS || p->paramType == P_SPECIESTREE || p->paramType == P_POPSIZE))
23629             {                   
23630             if (p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS || p->paramType == P_SPECIESTREE)
23631                 {
23632                 /* check if they are the same */
23633                 areRunsSame = YES;
23634                 if (p->paramType == P_TOPOLOGY)
23635                     {
23636                     for (run=1; run<chainParams.numRuns; run++)
23637                         {
23638                         for (chain=0; chain<chainParams.numChains; chain++)
23639                             {
23640                             if (AreTopologiesSame (GetTree (p, run*chainParams.numChains + chain, 0), GetTree (p, chain, 0)) == NO)
23641                                 {
23642                                 areRunsSame = NO;
23643                                 break;
23644                                 }
23645                             }
23646                         }
23647                     }
23648                 else if (p->paramType == P_BRLENS)
23649                     {
23650                     for (run=1; run<chainParams.numRuns; run++)
23651                         {
23652                         for (chain=0; chain<chainParams.numChains; chain++)
23653                             {
23654                             if (AreTreesSame (GetTree (p, run*chainParams.numChains + chain, 0), GetTree (p, chain, 0)) == NO)
23655                                 {
23656                                 areRunsSame = NO;
23657                                 break;
23658                                 }
23659                             }
23660                         }
23661                     }
23662                 else if (p->paramType == P_SPECIESTREE)
23663                     {
23664                     for (run=1; run<chainParams.numRuns; run++)
23665                         {
23666                         for (chain=0; chain<chainParams.numChains; chain++)
23667                             {
23668                             if (AreTreesSame (GetTree (p, run*chainParams.numChains + chain, 0), GetTree (p, chain, 0)) == NO)
23669                                 {
23670                                 areRunsSame = NO;
23671                                 break;
23672                                 }
23673                             }
23674                         }
23675                     }
23676                 
23677                 /* print trees */
23678                 for (run=0; run<chainParams.numRuns; run++)
23679                     {
23680                     if (run > 0 && areRunsSame == YES)
23681                         break;
23682                     for (chain=0; chain<chainParams.numChains; chain++)
23683                         {
23684                         if (run == 0 && chain == 0)
23685                             MrBayesPrint ("%s            Startvals  = tree '%s'", spacer, GetTree (p, run*chainParams.numChains+chain, 0)->name);
23686                         else
23687                             MrBayesPrint ("%s                         tree '%s'", spacer, GetTree (p, run*chainParams.numChains+chain, 0)->name);
23688                         if (chainParams.numChains > 1 && areRunsSame == YES)
23689                             MrBayesPrint ("  [chain %d]", chain+1);
23690                         else if (chainParams.numChains == 1 && areRunsSame == NO)
23691                             MrBayesPrint ("  [run %d]", run+1);
23692                         else if (areRunsSame == NO)
23693                             MrBayesPrint ("  [run %d, chain %d]", run+1, chain+1);
23694                         MrBayesPrint ("\n");
23695                         }
23696                     }               
23697                 }   /* end topology and brlens parameters */
23698
23699             else if (p->paramType == P_OMEGA && p->paramId != OMEGA_DIR && p->paramId != OMEGA_FIX &&
23700                      p->paramId != OMEGA_FFF && p->paramId != OMEGA_FF && p->paramId != OMEGA_10FFF)
23701                 {
23702                 /* we need to print values and subvalues for the category frequencies in a NY98-like model. */
23703                 areRunsSame = YES;
23704                 for (run=1; run<chainParams.numRuns; run++)
23705                     {
23706                     for (chain=0; chain<chainParams.numChains; chain++)
23707                         {
23708                         value = GetParamVals (p, run*chainParams.numRuns+chain, 0);
23709                         refValue = GetParamVals (p, chain, 0);
23710                         nValues = p->nValues;
23711                         for (k=0; k<nValues; k++)
23712                             {
23713                             if (AreDoublesEqual (value[k], refValue[k], 0.000001) == NO)
23714                                 {
23715                                 areRunsSame = NO;
23716                                 break;
23717                                 }
23718                             }
23719                         value = GetParamSubVals (p, run*chainParams.numRuns+chain, 0);
23720                         refValue = GetParamSubVals (p, chain, 0);
23721                         if (!strcmp(modelParams[p->relParts[0]].omegaVar, "M10"))
23722                             {
23723                             value += (mp->numM10BetaCats + mp->numM10GammaCats);
23724                             refValue += (mp->numM10BetaCats + mp->numM10GammaCats);
23725                             for (k=0; k<4; k++)
23726                                 {
23727                                 if (AreDoublesEqual (value[k + 4], refValue[k + 4], 0.000001) == NO)
23728                                     {
23729                                     areRunsSame = NO;
23730                                     break;
23731                                     }
23732                                 }
23733                             for (k=0; k<2; k++)
23734                                 {
23735                                 if (AreDoublesEqual (value[k], refValue[k], 0.000001) == NO)
23736                                     {
23737                                     areRunsSame = NO;
23738                                     break;
23739                                     }
23740                                 }                           
23741                             }
23742                         else
23743                             {
23744                             for (k=0; k<3; k++)
23745                                 {
23746                                 if (AreDoublesEqual (value[k], refValue[k], 0.000001) == NO)
23747                                     {
23748                                     areRunsSame = NO;
23749                                     break;
23750                                     }
23751                                 }
23752                             }
23753                         if (areRunsSame == NO)
23754                             break;
23755                         }
23756                     if (areRunsSame == NO)
23757                         break;
23758                     }
23759                 
23760                 /* now print values */
23761                 for (run=0; run<chainParams.numRuns; run++)
23762                     {
23763                     for (chain=0; chain<chainParams.numChains; chain++)
23764                         {
23765                         value = GetParamVals (p, run*chainParams.numRuns+chain, 0);
23766                         subValue = GetParamSubVals (p, run*chainParams.numRuns+chain, 0);
23767                         nValues = p->nValues;                       
23768                         if (run == 0 && chain == 0)
23769                             MrBayesPrint ("%s            Startvals  = (%1.3lf", spacer, value[0]);
23770                         else
23771                             MrBayesPrint ("%s                         (%1.3lf", spacer, value[0]);
23772                         for (k=1; k<nValues; k++)
23773                             {
23774                             MrBayesPrint (",%1.3lf", value[k]);
23775                             }
23776
23777                         if (!strcmp(modelParams[p->relParts[0]].omegaVar, "M10"))
23778                             {
23779                             for (k=0; k<4; k++)
23780                                 {
23781                                 MrBayesPrint (",%1.3lf", subValue[k + mp->numM10BetaCats+mp->numM10GammaCats+4]);
23782                                 }
23783                             for (k=0; k<2; k++)
23784                                 {
23785                                 MrBayesPrint (",%1.3lf", subValue[k + mp->numM10BetaCats+mp->numM10GammaCats]);
23786                                 }                   
23787                             }
23788                         else
23789                             {
23790                             for (k=0; k<3; k++)
23791                                 {
23792                                 MrBayesPrint (",%1.3lf", subValue[k]);
23793                                 }
23794                             }       
23795                         MrBayesPrint (")");
23796                         if (chainParams.numChains > 1 && areRunsSame == YES)
23797                             MrBayesPrint ("  [chain %d]\n", chain+1);
23798                         else if (chainParams.numChains == 1 && areRunsSame == NO)
23799                             MrBayesPrint ("  [run %d]\n", run+1);
23800                         else if (areRunsSame == NO)
23801                             MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
23802                         }
23803                     }
23804                 }
23805             else
23806                 {
23807                 /* run of the mill parameter */
23808                 if (p->paramType == P_CLOCKRATE)
23809                     {
23810                      for (j=0; j<numGlobalChains; j++)
23811                         {
23812                         if (UpdateClockRate(-1.0, j) == ERROR)
23813                             {
23814                             MrBayesPrint ("%s            Warning: There is no appropriate clock rate that would satisfy all calibrated trees for run:%d chain%d. Some of calibration, trees or clockprior needs to be changed. ", spacer, j/chainParams.numChains, j%chainParams.numChains);
23815                             }
23816                         }
23817                     }
23818                 areRunsSame = YES;
23819                 for (run=1; run<chainParams.numRuns; run++)
23820                     {
23821                     for (chain=0; chain<chainParams.numChains; chain++)
23822                         {
23823                         if ((p->paramType == P_PI && modelParams[p->relParts[0]].dataType != STANDARD))
23824                             {
23825                             nValues = p->nSubValues;
23826                             value = GetParamSubVals (p, run*chainParams.numChains+chain, 0);
23827                             refValue = GetParamSubVals (p, chain, 0);
23828                             }
23829                         else
23830                             {
23831                             nValues = p->nValues;
23832                             value = GetParamVals (p, run*chainParams.numChains+chain, 0);
23833                             refValue = GetParamVals (p, chain, 0);
23834                             }
23835                         for (k=0; k<nValues; k++)
23836                             {
23837                             if (AreDoublesEqual(value[k], refValue[k], 0.000001) == NO)
23838                                 {
23839                                 areRunsSame = NO;
23840                                 break;
23841                                 }                           
23842                             }
23843                         if (areRunsSame == NO)
23844                             break;                          
23845                         }
23846                     if (areRunsSame == NO)
23847                         break;
23848                     }
23849
23850                 /* print values */
23851                 for (run=0; run<chainParams.numRuns; run++)
23852                     {
23853                     if (run > 0 && areRunsSame == YES)
23854                         break;
23855                     areChainsSame = YES;
23856                     for (chain=1; chain<chainParams.numChains; chain++)
23857                         {
23858                         if ((p->paramType == P_PI && modelParams[p->relParts[0]].dataType != STANDARD))
23859                             {
23860                             nValues = p->nSubValues;
23861                             value = GetParamSubVals (p, run*chainParams.numChains+chain, 0);
23862                             refValue = GetParamSubVals (p, run*chainParams.numChains, 0);
23863                             }
23864                         else
23865                             {
23866                             nValues = p->nValues;
23867                             value = GetParamVals (p, run*chainParams.numChains+chain, 0);
23868                             refValue = GetParamVals (p, run*chainParams.numChains, 0);
23869                             }
23870                         for (k=0; k<nValues; k++)
23871                             {
23872                             if (AreDoublesEqual(value[k], refValue[k], 0.000001) == NO)
23873                                 {
23874                                 areChainsSame = NO;
23875                                 break;
23876                                 }                           
23877                             }
23878                         }
23879                     for (chain=0; chain<chainParams.numChains; chain++)
23880                         {
23881                         if (areChainsSame == YES && chain > 0)
23882                             continue;
23883
23884                         if ((p->paramType == P_PI && modelParams[p->relParts[0]].dataType != STANDARD))
23885                             {
23886                             nValues = p->nSubValues;
23887                             value = GetParamSubVals (p, run*chainParams.numChains+chain, 0);
23888                             }
23889                         else
23890                             {
23891                             nValues = p->nValues;
23892                             value = GetParamVals (p, run*chainParams.numChains+chain, 0);
23893                             }
23894
23895                         if (run == 0 && chain == 0)
23896                             MrBayesPrint ("%s            Startvals  = (%1.3lf", spacer, value[0]);
23897                         else
23898                             MrBayesPrint ("%s                         (%1.3lf", spacer, value[0]);
23899                         
23900                         for (k=1; k<nValues; k++)
23901                             {
23902                             if (k%10==0)
23903                                 MrBayesPrint (",\n%s                          %1.3lf", spacer, value[k]);
23904                             else
23905                                 MrBayesPrint (",%1.3lf", value[k]);
23906                             }
23907                         MrBayesPrint (")");
23908                         
23909                         if (areChainsSame == YES && areRunsSame == NO)
23910                             MrBayesPrint ("  [run %d]", run+1);
23911                         else if (areChainsSame == NO && areRunsSame == YES)
23912                             MrBayesPrint ("  [chain %d]", chain+1);
23913                         else if (areChainsSame == NO && areRunsSame == NO)
23914                             MrBayesPrint ("  [run %d, chain %d]", run+1, chain+1);
23915                         MrBayesPrint ("\n");
23916                         }   
23917                     }
23918                 }
23919             }   /* end print start values */
23920
23921         MrBayesPrint ("\n");
23922         }   /* next parameter */
23923
23924     return (NO_ERROR);
23925 }
23926
23927
23928 int Unlink (void)
23929 {
23930     return (NO_ERROR);
23931 }
23932
23933
23934 /*-------------------------------------------------
23935 |
23936 |   UpdateClockRate:    Update clockRate of the given chain. Above all it will enforce fixed clockrate prior if it is set.
23937 |                       Error will be returned if fixed clockrate prior may not be respected.
23938 |   @param clockRate    is the new clockRate to setup. Clock rate value could be set as positive, 0.0 or negative value. 
23939 |                       The function does the fallowing depending on one of this three values:
23940 |                        positive    - check that this 'positive' value is suitable rate. At the end re-enforce (update) the 'positive' value as clock rate on all trees. 
23941 |                        0.0         - check if current rate is suitable, if not update it with minimal suitable value. At the end re-enforce (update) the resulting clock rate on all trees. 
23942 |                        negative    - check if current rate is suitable, if not update it with minimal suitable value. At the end re-enforce (update) the resulting clock rate ONLY if clock rate was changed 
23943 |   @return             ERROR if clockRate can not be set up, NO_ERROR otherwise. 
23944 |
23945 --------------------------------------------------*/
23946 int UpdateClockRate (MrBFlt clockRate, int chain)
23947 {
23948     int         i, updateTrees;
23949     MrBFlt      *clockRatep;
23950     Tree        *t, *t_calibrated=NULL;
23951     MrBFlt      mintmp,maxtmp,minClockRate,maxClockRate;
23952
23953     clockRatep=NULL;
23954     minClockRate = 0.0;
23955     maxClockRate = MRBFLT_MAX;
23956
23957     for (i=0; i<numTrees; i++)
23958         {
23959         t = GetTreeFromIndex(i, chain, 0);
23960         if (t->isCalibrated == NO)
23961             continue;
23962
23963         if (clockRatep == NULL)
23964             {
23965             clockRatep = GetParamVals(modelSettings[t->relParts[0]].clockRate, chain, 0);
23966             t_calibrated = t;
23967             assert (clockRatep);
23968             }
23969
23970         findAllowedClockrate (t, &mintmp, &maxtmp);
23971
23972         if (minClockRate < mintmp)
23973             minClockRate = mintmp;
23974
23975         if (maxClockRate > maxtmp)
23976             maxClockRate = maxtmp;
23977
23978         }
23979     /* clock rate is the same for all trees of a given chain */
23980     if (clockRatep != NULL)
23981         {
23982         if (minClockRate > maxClockRate)
23983             {
23984             MrBayesPrint ("%s   ERROR: Calibrated trees require compatible clockrates but they are incompatible for run %d, chain %d.\n",
23985                           spacer, chain/chainParams.numChains + 1, chain%chainParams.numChains + 1);
23986             *clockRatep=0;
23987             return (ERROR);
23988             }
23989
23990         if (!strcmp(modelParams[t_calibrated->relParts[0]].clockRatePr, "Fixed"))
23991             {
23992             if (clockRate < 0.0 && AreDoublesEqual (*clockRatep, modelParams[t_calibrated->relParts[0]].clockRateFix, 0.0001) == YES)
23993                 {
23994                 updateTrees = NO;
23995                 }
23996             else
23997                 {
23998                 updateTrees = YES;
23999                 }
24000             *clockRatep = modelParams[t_calibrated->relParts[0]].clockRateFix;
24001             if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24002                 (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24003                 {
24004                 MrBayesPrint ("%s   ERROR: Calibrated trees require clockrate in range from %f to %f, while clockrate prior is fixed to %f for run %d chain %d.\n",
24005                               spacer, minClockRate, maxClockRate, *clockRatep, chain/chainParams.numChains + 1, chain%chainParams.numChains + 1);
24006                 *clockRatep=0;
24007                 return (ERROR);
24008                 }
24009             if (clockRate > 0.0)
24010                 {
24011                 if (AreDoublesEqual (*clockRatep, clockRate, 0.0001) == NO)
24012                     {
24013                     MrBayesPrint ("%s   ERROR: Requested clockrate:%f does not match fixed clockrate prior:%f.\n", spacer, clockRate, *clockRatep);
24014                     *clockRatep=0;
24015                     return (ERROR);
24016                     }
24017                 }
24018             }
24019         else {
24020             /* clock prior is not fixed */
24021             updateTrees = YES;
24022             if (clockRate > 0.0)
24023                 {
24024                 *clockRatep = clockRate;
24025                 if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24026                     (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24027                     {
24028                     MrBayesPrint ("%s   ERROR: Calibrated trees require clockrate in range from %f to %f, while requested clockrate is %f for run %d chain %d.\n",
24029                                   spacer, minClockRate, maxClockRate, clockRate, chain/chainParams.numChains + 1, chain%chainParams.numChains + 1);
24030                     *clockRatep=0;
24031                     return (ERROR);
24032                     }
24033                 }
24034             else if (clockRate == 0.0) 
24035                 {
24036                 if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24037                     (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24038                     {
24039                     *clockRatep = minClockRate;
24040                     }
24041                 }
24042             else // if (clockRate < 0.0)
24043                 {
24044                 if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24045                     (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24046                     {
24047                     *clockRatep = minClockRate;
24048                     }
24049                 else
24050                     {
24051                     updateTrees = NO;
24052                     }
24053                 }
24054             }
24055
24056         
24057         if (updateTrees == YES)
24058             {
24059             for (i=0; i<numTrees; i++)
24060                 {
24061                 t = GetTreeFromIndex(i, chain, 0);
24062                 if (t->isCalibrated == NO)
24063                     continue;
24064                 UpdateTreeWithClockrate (t,*clockRatep);
24065                 }
24066             }
24067         }
24068
24069     return (NO_ERROR);
24070 }
24071
24072
24073 /*----------------------------------------------
24074 |
24075 |   UpdateCppEvolLength: Recursive function to
24076 |      update evolLength of one node for Cpp
24077 |      relaxed clock model
24078 |
24079 -----------------------------------------------*/
24080 int UpdateCppEvolLength (int *nEvents, MrBFlt **pos, MrBFlt **rateMult, MrBFlt *evolLength, TreeNode *p, MrBFlt baseRate)
24081 {
24082     int     i;
24083     MrBFlt  endRate;
24084
24085     if (p != NULL)
24086         {
24087 #   ifdef DEBUG_CPP
24088         if (baseRate < POS_MIN || baseRate > POS_INFINITY)
24089             {
24090             printf ("baseRate out of bounds (%.15e for node %d\n", baseRate, p->index);
24091             return (ERROR);
24092             }
24093 #   endif
24094         p->upDateTi = YES;
24095         p->upDateCl = YES;
24096         if (nEvents[p->index] == 0)
24097             {
24098             evolLength[p->index] = p->length * baseRate;
24099             }
24100         else
24101             {
24102             /* note that event positions are from the top of the branch (more recent)
24103                to the bottom of the branch (older) */
24104             /* The algorithm below successively multiplies in the more basal rate multipliers,
24105                starting from the top of the branch. The length of the branch is first assumed
24106                to be 1.0; at the end we multiply the result with the true length of the branch. */
24107             evolLength[p->index] = pos[p->index][0] * rateMult[p->index][0];
24108             for (i=1; i<nEvents[p->index]; i++)
24109                 {
24110                 evolLength[p->index] += (pos[p->index][i] - pos[p->index][i-1]);
24111                 evolLength[p->index] *= rateMult[p->index][i];
24112                 }
24113             evolLength[p->index] += (1.0 - pos[p->index][nEvents[p->index]-1]);
24114             evolLength[p->index] *= baseRate;
24115             evolLength[p->index] *= p->length;
24116             }
24117
24118         /* calculate end rate; we can do this in any order */
24119         endRate = baseRate;
24120         for (i=0; i<nEvents[p->index]; i++)
24121             endRate *= rateMult[p->index][i];
24122
24123 #   ifdef DEBUG_CPP
24124         if (endRate < POS_MIN || endRate > POS_INFINITY)
24125             {
24126             printf ("endRate out of bounds (%.15e for node %d)\n", endRate, p->index);
24127             return (ERROR);
24128             }
24129         if (p->anc != NULL && p->anc->anc != NULL && (evolLength[p->index] < POS_MIN || evolLength[p->index] > POS_INFINITY))
24130             {
24131             printf ("Effective branch length out of bounds (%.15e for node %d)\n", evolLength[p->index], p->index);
24132             return (ERROR);
24133             }
24134 #   endif
24135         /* call left and right descendants */
24136         if (UpdateCppEvolLength (nEvents, pos, rateMult, evolLength, p->left, endRate)==ERROR)
24137             return (ERROR);
24138         if (UpdateCppEvolLength (nEvents, pos, rateMult, evolLength, p->right, endRate)==ERROR)
24139             return (ERROR);
24140         }
24141
24142     return (NO_ERROR);
24143 }
24144
24145
24146 /*-------------------------------------------------
24147  |
24148  |  UpdateCppEvolLengths: Recalculate effective
24149  |      evolutionary lengths and set update flags
24150  |      for Cpp relaxed clock model
24151  |
24152  --------------------------------------------------*/
24153 int UpdateCppEvolLengths (Param *param, TreeNode *p, int chain)
24154 {
24155     int         i, *nEvents;
24156     TreeNode    *q;
24157     MrBFlt      baseRate = 1.0, **pos, **rateMult, *evolLength;
24158     
24159     i = 2*chain + state[chain];
24160     nEvents = param->nEvents[i];
24161     pos = param->position[i];
24162     rateMult = param->rateMult[i];
24163     evolLength = GetParamSubVals (param, chain, state[chain]);
24164     
24165     q = p->anc;
24166     while (q->anc != NULL)
24167         {
24168         for (i=0; i<nEvents[q->index]; i++)
24169             baseRate *= rateMult[q->index][i];
24170         q = q->anc;
24171         }
24172     
24173     if (UpdateCppEvolLength (nEvents, pos, rateMult, evolLength, p, baseRate)==ERROR)
24174         return (ERROR);
24175     
24176     return(NO_ERROR);
24177 }
24178
24179
24180 /* UpdateTK02EvolLengths: update branch lengths for tk02 model */
24181 int UpdateTK02EvolLengths (Param *param, Tree *t, int chain)
24182 {
24183     int         i;
24184     MrBFlt      *tk02Rate, *brlens;
24185     TreeNode    *p;
24186     
24187     tk02Rate = GetParamVals (param, chain, state[chain]);
24188     brlens = GetParamSubVals (param, chain, state[chain]);
24189     for (i=0; i<t->nNodes-2; i++)
24190         {
24191         p = t->allDownPass[i];
24192         brlens[p->index] = p->length * (tk02Rate[p->index] + tk02Rate[p->anc->index]) / 2.0;
24193         }
24194     
24195     return (NO_ERROR);
24196 }
24197
24198
24199 /* UpdateIgrBranchLengths: update branch lengths for igr model */
24200 int UpdateIgrBrachLengths (Param *param, Tree *t, int chain)
24201 {
24202     int         i;
24203     MrBFlt      *igrRate, *brlens;
24204     TreeNode    *p;
24205     
24206     igrRate = GetParamVals (param, chain, state[chain]);
24207     brlens = GetParamSubVals (param, chain, state[chain]);
24208     for (i=0; i<t->nNodes-2; i++)
24209         {
24210         p = t->allDownPass[i];
24211         brlens[p->index] = p->length * igrRate[p->index];
24212         }
24213
24214     return (NO_ERROR);
24215 }
24216