source: branches/port5/SL/TREE_READ/TreeTools.cxx

Last change on this file was 6030, checked in by westram, 16 years ago
  • renamed defines
File size: 2.6 KB
Line 
1// ============================================================ //
2//                                                              //
3//   File      : TreeTools.cxx                                  //
4//   Purpose   :                                                //
5//                                                              //
6//   Institute of Microbiology (Technical University Munich)    //
7//   www.arb-home.de                                            //
8//                                                              //
9// ============================================================ //
10
11#include "TreeRead.h"
12
13#include <time.h>
14
15
16void TREE_scale(GBT_TREE *tree, double length_scale, double bootstrap_scale) {
17    if (tree->leftson) {
18        if (tree->leftlen <= TREE_DEFLEN_MARKER) tree->leftlen  = TREE_DEFLEN;
19        else                                     tree->leftlen *= length_scale;
20       
21        TREE_scale(tree->leftson, length_scale, bootstrap_scale);
22    }
23    if (tree->rightson) {
24        if (tree->rightlen <= TREE_DEFLEN_MARKER) tree->rightlen  = TREE_DEFLEN; 
25        else                                      tree->rightlen *= length_scale;
26       
27        TREE_scale(tree->rightson, length_scale, bootstrap_scale);
28    }
29
30    if (tree->remark_branch) {
31        const char *end          = 0;
32        double      bootstrap    = strtod(tree->remark_branch, (char**)&end);
33        bool        is_bootstrap = end[0] == '%' && end[1] == 0;
34
35        freeset(tree->remark_branch, 0);
36
37        if (is_bootstrap) {
38            bootstrap = bootstrap*bootstrap_scale+0.5;
39            tree->remark_branch  = GBS_global_string_copy("%i%%", (int)bootstrap);
40        }
41    }
42}
43
44
45static char *dated_info(const char *info) {
46    char *dated_info = 0;
47    time_t      date;
48    if (time(&date) != -1)  {
49        char *dstr = ctime(&date);
50        char *nl   = strchr(dstr, '\n');
51       
52        if (nl) nl[0] = 0; // cut off LF
53
54        dated_info = GBS_global_string_copy("%s: %s", dstr, info);
55    }
56    else {
57        dated_info = strdup(info);
58    }
59    return dated_info;
60}
61
62char *TREE_log_action_to_tree_comment(const char *comment, const char *action) {
63    size_t clen = comment ? strlen(comment) : 0;
64    size_t alen = strlen(action);
65
66    GBS_strstruct *new_comment = GBS_stropen(clen+alen+100);
67
68    if (comment) {
69        GBS_strcat(new_comment, comment);
70        if (comment[clen-1] != '\n') GBS_chrcat(new_comment, '\n');
71    }
72
73    char *dated_action = dated_info(action);
74    GBS_strcat(new_comment, dated_action);
75    GBS_chrcat(new_comment, '\n');
76
77    free(dated_action);
78
79    return GBS_strclose(new_comment);
80}
Note: See TracBrowser for help on using the repository browser.