Voro++
common.cc
Go to the documentation of this file.
1 // Voro++, a 3D cell-based Voronoi library
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
6 
7 /** \file common.cc
8  * \brief Implementations of the small helper functions. */
9 
10 #include "common.hh"
11 
12 namespace voro {
13 
14 /** \brief Prints a vector of integers.
15  *
16  * Prints a vector of integers.
17  * \param[in] v the vector to print.
18  * \param[in] fp the file stream to print to. */
19 void voro_print_vector(std::vector<int> &v,FILE *fp) {
20  int k=0,s=v.size();
21  while(k+4<s) {
22  fprintf(fp,"%d %d %d %d ",v[k],v[k+1],v[k+2],v[k+3]);
23  k+=4;
24  }
25  if(k+3<=s) {
26  if(k+4==s) fprintf(fp,"%d %d %d %d",v[k],v[k+1],v[k+2],v[k+3]);
27  else fprintf(fp,"%d %d %d",v[k],v[k+1],v[k+2]);
28  } else {
29  if(k+2==s) fprintf(fp,"%d %d",v[k],v[k+1]);
30  else fprintf(fp,"%d",v[k]);
31  }
32 }
33 
34 /** \brief Prints a vector of doubles.
35  *
36  * Prints a vector of doubles.
37  * \param[in] v the vector to print.
38  * \param[in] fp the file stream to print to. */
39 void voro_print_vector(std::vector<double> &v,FILE *fp) {
40  int k=0,s=v.size();
41  while(k+4<s) {
42  fprintf(fp,"%g %g %g %g ",v[k],v[k+1],v[k+2],v[k+3]);
43  k+=4;
44  }
45  if(k+3<=s) {
46  if(k+4==s) fprintf(fp,"%g %g %g %g",v[k],v[k+1],v[k+2],v[k+3]);
47  else fprintf(fp,"%g %g %g",v[k],v[k+1],v[k+2]);
48  } else {
49  if(k+2==s) fprintf(fp,"%g %g",v[k],v[k+1]);
50  else fprintf(fp,"%g",v[k]);
51  }
52 }
53 
54 /** \brief Prints a vector a face vertex information.
55  *
56  * Prints a vector of face vertex information. A value is read, which
57  * corresponds to the number of vertices in the next face. The routine reads
58  * this number of values and prints them as a bracked list. This is repeated
59  * until the end of the vector is reached.
60  * \param[in] v the vector to interpret and print.
61  * \param[in] fp the file stream to print to. */
62 void voro_print_face_vertices(std::vector<int> &v,FILE *fp) {
63  int j,k=0,l;
64  if(v.size()>0) {
65  l=v[k++];
66  if(l<=1) {
67  if(l==1) fprintf(fp,"(%d)",v[k++]);
68  else fputs("()",fp);
69  } else {
70  j=k+l;
71  fprintf(fp,"(%d",v[k++]);
72  while(k<j) fprintf(fp,",%d",v[k++]);
73  fputs(")",fp);
74  }
75  while((unsigned int) k<v.size()) {
76  l=v[k++];
77  if(l<=1) {
78  if(l==1) fprintf(fp," (%d)",v[k++]);
79  else fputs(" ()",fp);
80  } else {
81  j=k+l;
82  fprintf(fp," (%d",v[k++]);
83  while(k<j) fprintf(fp,",%d",v[k++]);
84  fputs(")",fp);
85  }
86  }
87  }
88 }
89 
90 }
Header file for the small helper functions.