1 /* drawTree.c */
2
3 #include "../Tree.h"
4 #include "../../timings.h"
5
6 /*--------------------------------------------------------------------*/
7 int
main(int argc,char * argv[])8 main ( int argc, char *argv[] )
9 /*
10 ----------------------------------------
11 draw the tree
12
13 created -- 99jan23, cca
14 ----------------------------------------
15 */
16 {
17 char coordflag, heightflag ;
18 char *inTagsFileName, *inTreeFileName, *outEPSfileName ;
19 double fontsize, radius, t1, t2 ;
20 double bbox[4], frame[4] ;
21 DV *xDV, *yDV ;
22 int ierr, msglvl, rc, tagsflag ;
23 IV *tagsIV ;
24 Tree *tree ;
25 FILE *msgFile ;
26
27 if ( argc != 19 ) {
28 fprintf(stdout,
29 "\n\n usage : %s msglvl msgFile inTreeFile inTagsFile outEPSfile "
30 "\n heightflag coordflag radius bbox[4] frame[4] tagflag fontsize"
31 "\n msglvl -- message level"
32 "\n msgFile -- message file"
33 "\n inTreeFile -- input file, must be *.treef or *.treeb"
34 "\n inTagsFile -- input file, must be *.ivf or *.ivb or none"
35 "\n outEPSfile -- output file"
36 "\n heightflag -- height flag"
37 "\n 'D' -- use depth metric"
38 "\n 'H' -- use height metric"
39 "\n coordflag -- coordinate flag"
40 "\n 'C' -- use (x,y) Cartesian coordinates"
41 "\n 'P' -- use (r,theta) polar coordinates"
42 "\n radius -- radius of node"
43 "\n bbox[4] -- bounding box"
44 "\n frame[4] -- frame for plot"
45 "\n fontsize -- size of fonts (in points)"
46 "\n tagflag -- if 1, draw labels, otherwise, do not"
47 "\n", argv[0]) ;
48 return(0) ;
49 }
50 msglvl = atoi(argv[1]) ;
51 if ( strcmp(argv[2], "stdout") == 0 ) {
52 msgFile = stdout ;
53 } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
54 fprintf(stderr, "\n fatal error in %s"
55 "\n unable to open file %s\n",
56 argv[0], argv[2]) ;
57 return(-1) ;
58 }
59 inTreeFileName = argv[3] ;
60 inTagsFileName = argv[4] ;
61 outEPSfileName = argv[5] ;
62 heightflag = argv[6][0] ;
63 coordflag = argv[7][0] ;
64 radius = atof(argv[8]) ;
65 bbox[0] = atof(argv[9]) ;
66 bbox[1] = atof(argv[10]) ;
67 bbox[2] = atof(argv[11]) ;
68 bbox[3] = atof(argv[12]) ;
69 frame[0] = atof(argv[13]) ;
70 frame[1] = atof(argv[14]) ;
71 frame[2] = atof(argv[15]) ;
72 frame[3] = atof(argv[16]) ;
73 fontsize = atof(argv[17]) ;
74 tagsflag = atoi(argv[18]) ;
75 fprintf(msgFile,
76 "\n %s "
77 "\n msglvl -- %d"
78 "\n msgFile -- %s"
79 "\n inTreeFile -- %s"
80 "\n inTagsFile -- %s"
81 "\n outEPSfile -- %s"
82 "\n heightflag -- %c"
83 "\n coordflag -- %d"
84 "\n radius -- %.3g"
85 "\n bbox -- %.3g %.3g %.3g %.3g"
86 "\n frame -- %.3g %.3g %.3g %.3g"
87 "\n fontsize -- %.3g"
88 "\n",
89 argv[0], msglvl, argv[2], inTreeFileName, inTagsFileName,
90 outEPSfileName, heightflag, coordflag, radius,
91 bbox[0], bbox[1], bbox[2], bbox[3],
92 frame[0], frame[1], frame[2], frame[3], fontsize, tagsflag) ;
93 fflush(msgFile) ;
94 /*
95 ------------------------
96 read in the Tree object
97 ------------------------
98 */
99 if ( strcmp(inTreeFileName, "none") == 0 ) {
100 fprintf(msgFile, "\n no file to read from") ;
101 exit(0) ;
102 }
103 tree = Tree_new() ;
104 MARKTIME(t1) ;
105 rc = Tree_readFromFile(tree, inTreeFileName) ;
106 /*
107 Tree_setFchSibRoot(tree) ;
108 */
109 Tree_leftJustify(tree) ;
110 MARKTIME(t2) ;
111 fprintf(msgFile, "\n CPU %9.5f : read in tree from file %s",
112 t2 - t1, inTreeFileName) ;
113 if ( rc != 1 ) {
114 fprintf(msgFile, "\n return value %d from Tree_readFromFile(%p,%s)",
115 rc, tree, inTreeFileName) ;
116 exit(-1) ;
117 }
118 fprintf(msgFile, "\n\n after reading Tree object from file %s",
119 inTreeFileName) ;
120 if ( msglvl > 2 ) {
121 Tree_writeForHumanEye(tree, msgFile) ;
122 } else {
123 Tree_writeStats(tree, msgFile) ;
124 }
125 fflush(msgFile) ;
126 if ( Tree_maxNchild(tree) > 2 ) {
127 fprintf(msgFile, "\n\n maximum number of children = %d",
128 Tree_maxNchild(tree)) ;
129 }
130 if ( strcmp(inTagsFileName, "none") != 0 ) {
131 /*
132 --------------------------
133 read in the tags IV object
134 --------------------------
135 */
136 tagsIV = IV_new() ;
137 MARKTIME(t1) ;
138 rc = IV_readFromFile(tagsIV, inTagsFileName) ;
139 MARKTIME(t2) ;
140 fprintf(msgFile, "\n CPU %9.5f : read in tagsIV from file %s",
141 t2 - t1, inTagsFileName) ;
142 if ( rc != 1 ) {
143 fprintf(msgFile, "\n return value %d from IV_readFromFile(%p,%s)",
144 rc, tagsIV, inTagsFileName) ;
145 exit(-1) ;
146 }
147 fprintf(msgFile, "\n\n after reading IV object from file %s",
148 inTagsFileName) ;
149 if ( msglvl > 2 ) {
150 IV_writeForHumanEye(tagsIV, msgFile) ;
151 } else {
152 IV_writeStats(tagsIV, msgFile) ;
153 }
154 fflush(msgFile) ;
155 if ( IV_size(tagsIV) != tree->n ) {
156 fprintf(stderr,
157 "\n fatal error, IV_size(tagsIV) = %d, tree->n = %d",
158 IV_size(tagsIV), tree->n) ;
159 exit(-1) ;
160 }
161 } else {
162 tagsIV = NULL ;
163 }
164 /*
165 -------------------------------
166 get the coordinates of the tree
167 -------------------------------
168 */
169 xDV = DV_new() ;
170 yDV = DV_new() ;
171 rc = Tree_getSimpleCoords(tree, heightflag, coordflag, xDV, yDV) ;
172 if ( rc != 1 ) {
173 fprintf(stderr, "\n error return %d from Tree_getSimpleCoords()",rc);
174 exit(-1) ;
175 }
176 if ( msglvl > 1 ) {
177 fprintf(msgFile, "\n\n x-coordinates") ;
178 DV_writeForHumanEye(xDV, msgFile) ;
179 fprintf(msgFile, "\n\n y-coordinates") ;
180 DV_writeForHumanEye(yDV, msgFile) ;
181 fflush(msgFile) ;
182 }
183 /*
184 -------------
185 draw the Tree
186 -------------
187 */
188 rc = Tree_drawToEPS(tree, outEPSfileName, xDV, yDV, radius, NULL,
189 tagsflag, fontsize, tagsIV, bbox, frame, NULL) ;
190 if ( rc != 1 ) {
191 fprintf(stderr, "\n error return %d from Tree_drawToEPSfile()", rc) ;
192 exit(-1) ;
193 }
194 /*
195 ---------------------
196 free the Tree object
197 ---------------------
198 */
199 Tree_free(tree) ;
200 if ( tagsIV != NULL ) {
201 IV_free(tagsIV) ;
202 }
203
204 fprintf(msgFile, "\n") ;
205 fclose(msgFile) ;
206
207 return(1) ; }
208
209 /*--------------------------------------------------------------------*/
210