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
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 2D 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_2d(vector
<double> &v
,FILE *fp
=stdout
) {
39 fprintf(fp
,"(%g,%g)",v
[0],v
[1]);
40 for(int k
=2;(unsigned int) k
<v
.size();k
+=2) {
41 fprintf(fp
," (%g,%g)",v
[k
],v
[k
+1]);
46 /** \brief Prints a vector of positions.
48 * Prints a vector of positions as bracketed triplets.
49 * \param[in] v the vector to print.
50 * \param[in] fp the file stream to print to. */
51 inline void voro_print_positions(vector
<double> &v
,FILE *fp
=stdout
) {
53 fprintf(fp
,"(%g,%g,%g)",v
[0],v
[1],v
[2]);
54 for(int k
=3;(unsigned int) k
<v
.size();k
+=3) {
55 fprintf(fp
," (%g,%g,%g)",v
[k
],v
[k
+1],v
[k
+2]);
60 /** \brief Opens a file and checks the operation was successful.
62 * Opens a file, and checks the return value to ensure that the operation
64 * \param[in] filename the file to open.
65 * \param[in] mode the cstdio fopen mode to use.
66 * \return The file handle. */
67 inline FILE* safe_fopen(const char *filename
,const char *mode
) {
68 FILE *fp(fopen(filename
,mode
));
70 fprintf(stderr
,"voro++: Unable to open file '%s'\n",filename
);
71 exit(VOROPP_FILE_ERROR
);
76 void voro_print_vector(vector
<int> &v
,FILE *fp
=stdout
);
77 void voro_print_vector(vector
<double> &v
,FILE *fp
=stdout
);