Reset platonic code.
[voro++.git] / branches / 2d_boundary / src / common.hh
blobe13b60dfdb1e2e23f7567080999061e175d9deac
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 : May 18th 2011
7 /** \file common.hh
8 * \brief Header file for the small helper functions. */
10 #ifndef VOROPP_COMMON_HH
11 #define VOROPP_COMMON_HH
13 #include <cstdio>
14 #include <cstdlib>
15 #include <vector>
16 using namespace std;
18 #include "config.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);
27 exit(status);
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) {
36 if(v.size()>0) {
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
47 * was successful.
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));
53 if(fp==NULL) {
54 fprintf(stderr,"voro++: Unable to open file '%s'\n",filename);
55 exit(VOROPP_FILE_ERROR);
57 return fp;
60 void voropp_print_vector(vector<int> &v,FILE *fp=stdout);
61 void voropp_print_vector(vector<double> &v,FILE *fp=stdout);
63 #endif