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