1 // Voro++, a 3D cell-based Voronoi library
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
8 * \brief Header file for the small helper functions. */
10 #ifndef VOROPP_COMMON_HH
11 #define VOROPP_COMMON_HH
22 /** \brief Function for printing fatal error messages and exiting.
24 * Function for printing fatal error messages and exiting.
25 * \param[in] p a pointer to the message to print.
26 * \param[in] status the status code to return with. */
27 inline void voro_fatal_error(const char *p
,int status
) {
28 fprintf(stderr
,"voro++: %s\n",p
);
32 /** \brief Prints a vector of positions.
34 * Prints a vector of positions as bracketed triplets.
35 * \param[in] v the vector to print.
36 * \param[in] fp the file stream to print to. */
37 inline void voro_print_positions(vector
<double> &v
,FILE *fp
=stdout
) {
39 fprintf(fp
,"(%g,%g,%g)",v
[0],v
[1],v
[2]);
40 for(int k
=3;(unsigned int) k
<v
.size();k
+=3) {
41 fprintf(fp
," (%g,%g,%g)",v
[k
],v
[k
+1],v
[k
+2]);
46 /** \brief Opens a file and checks the operation was successful.
48 * Opens a file, and checks the return value to ensure that the operation
50 * \param[in] filename the file to open.
51 * \param[in] mode the cstdio fopen mode to use.
52 * \return The file handle. */
53 inline FILE* safe_fopen(const char *filename
,const char *mode
) {
54 FILE *fp
=fopen(filename
,mode
);
56 fprintf(stderr
,"voro++: Unable to open file '%s'\n",filename
);
57 exit(VOROPP_FILE_ERROR
);
62 void voro_print_vector(vector
<int> &v
,FILE *fp
=stdout
);
63 void voro_print_vector(vector
<double> &v
,FILE *fp
=stdout
);
64 void voro_print_face_vertices(vector
<int> &v
,FILE *fp
=stdout
);