Voro++
|
00001 // Voro++, a 3D cell-based Voronoi library 00002 // 00003 // Author : Chris H. Rycroft (LBL / UC Berkeley) 00004 // Email : chr@alum.mit.edu 00005 // Date : August 30th 2011 00006 00007 /** \file common.hh 00008 * \brief Header file for the small helper functions. */ 00009 00010 #ifndef VOROPP_COMMON_HH 00011 #define VOROPP_COMMON_HH 00012 00013 #include <cstdio> 00014 #include <cstdlib> 00015 #include <vector> 00016 using namespace std; 00017 00018 #include "config.hh" 00019 00020 namespace voro { 00021 00022 /** \brief Function for printing fatal error messages and exiting. 00023 * 00024 * Function for printing fatal error messages and exiting. 00025 * \param[in] p a pointer to the message to print. 00026 * \param[in] status the status code to return with. */ 00027 inline void voro_fatal_error(const char *p,int status) { 00028 fprintf(stderr,"voro++: %s\n",p); 00029 exit(status); 00030 } 00031 00032 /** \brief Prints a vector of positions. 00033 * 00034 * Prints a vector of positions as bracketed triplets. 00035 * \param[in] v the vector to print. 00036 * \param[in] fp the file stream to print to. */ 00037 inline void voro_print_positions(vector<double> &v,FILE *fp=stdout) { 00038 if(v.size()>0) { 00039 fprintf(fp,"(%g,%g,%g)",v[0],v[1],v[2]); 00040 for(int k=3;(unsigned int) k<v.size();k+=3) { 00041 fprintf(fp," (%g,%g,%g)",v[k],v[k+1],v[k+2]); 00042 } 00043 } 00044 } 00045 00046 /** \brief Opens a file and checks the operation was successful. 00047 * 00048 * Opens a file, and checks the return value to ensure that the operation 00049 * was successful. 00050 * \param[in] filename the file to open. 00051 * \param[in] mode the cstdio fopen mode to use. 00052 * \return The file handle. */ 00053 inline FILE* safe_fopen(const char *filename,const char *mode) { 00054 FILE *fp=fopen(filename,mode); 00055 if(fp==NULL) { 00056 fprintf(stderr,"voro++: Unable to open file '%s'\n",filename); 00057 exit(VOROPP_FILE_ERROR); 00058 } 00059 return fp; 00060 } 00061 00062 void voro_print_vector(vector<int> &v,FILE *fp=stdout); 00063 void voro_print_vector(vector<double> &v,FILE *fp=stdout); 00064 void voro_print_face_vertices(vector<int> &v,FILE *fp=stdout); 00065 00066 } 00067 00068 #endif