1 |
francois |
979 |
// 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.hh |
8 |
|
|
* \brief Header file for the small helper functions. */ |
9 |
|
|
|
10 |
|
|
#ifndef VOROPP_COMMON_HH |
11 |
|
|
#define VOROPP_COMMON_HH |
12 |
|
|
|
13 |
|
|
#include <cstdio> |
14 |
|
|
#include <cstdlib> |
15 |
|
|
#include <vector> |
16 |
|
|
|
17 |
|
|
#include "config.hh" |
18 |
|
|
|
19 |
|
|
namespace voro { |
20 |
|
|
|
21 |
|
|
/** \brief Function for printing fatal error messages and exiting. |
22 |
|
|
* |
23 |
|
|
* Function for printing fatal error messages and exiting. |
24 |
|
|
* \param[in] p a pointer to the message to print. |
25 |
|
|
* \param[in] status the status code to return with. */ |
26 |
|
|
inline void voro_fatal_error(const char *p,int status) { |
27 |
|
|
fprintf(stderr,"voro++: %s\n",p); |
28 |
|
|
exit(status); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
/** \brief Prints a vector of positions. |
32 |
|
|
* |
33 |
|
|
* Prints a vector of positions as bracketed triplets. |
34 |
|
|
* \param[in] v the vector to print. |
35 |
|
|
* \param[in] fp the file stream to print to. */ |
36 |
|
|
inline void voro_print_positions(std::vector<double> &v,FILE *fp=stdout) { |
37 |
|
|
if(v.size()>0) { |
38 |
|
|
fprintf(fp,"(%g,%g,%g)",v[0],v[1],v[2]); |
39 |
|
|
for(int k=3;(unsigned int) k<v.size();k+=3) { |
40 |
|
|
fprintf(fp," (%g,%g,%g)",v[k],v[k+1],v[k+2]); |
41 |
|
|
} |
42 |
|
|
} |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
/** \brief Opens a file and checks the operation was successful. |
46 |
|
|
* |
47 |
|
|
* Opens a file, and checks the return value to ensure that the operation |
48 |
|
|
* was successful. |
49 |
|
|
* \param[in] filename the file to open. |
50 |
|
|
* \param[in] mode the cstdio fopen mode to use. |
51 |
|
|
* \return The file handle. */ |
52 |
|
|
inline FILE* safe_fopen(const char *filename,const char *mode) { |
53 |
|
|
FILE *fp=fopen(filename,mode); |
54 |
|
|
if(fp==NULL) { |
55 |
|
|
fprintf(stderr,"voro++: Unable to open file '%s'\n",filename); |
56 |
|
|
exit(VOROPP_FILE_ERROR); |
57 |
|
|
} |
58 |
|
|
return fp; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void voro_print_vector(std::vector<int> &v,FILE *fp=stdout); |
62 |
|
|
void voro_print_vector(std::vector<double> &v,FILE *fp=stdout); |
63 |
|
|
void voro_print_face_vertices(std::vector<int> &v,FILE *fp=stdout); |
64 |
|
|
|
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
#endif |