std::string date2string(double ddate) { if (ddate < 10000101 || ddate > 99991231) { std::cout << "Error: date2String() -- input not in expected format." << std::endl; return "0.0.0000"; } int rest (static_cast<int>(ddate)); int y = static_cast<int>(floor(rest / 10000.0)); rest = rest % (y * 10000); int m = static_cast<int>(floor(rest / 100.0)); if (m < 1 || m > 12) std::cout << "Warning: date2String() -- month not in [1:12]" << std::endl; rest = rest % (m * 100); int d = rest; if (d < 1 || d > 31) std::cout << "Warning: date2String() -- day not in [1:31]" << std::endl; std::string day = number2str(d); if (d < 10) day = "0" + day; std::string month = number2str(m); if (m < 10) month = "0" + month; std::string s = number2str(y) + "-" + month + "-" + day; return s; }
bool ProjectData::isUniqueMeshName(std::string &name) { int count(0); bool isUnique(false); std::string cpName; while (!isUnique) { isUnique = true; cpName = name; count++; // If the original name already exists we start to add numbers to name for // as long as it takes to make the name unique. if (count > 1) cpName = cpName + "-" + number2str(count); for (std::map<std::string, MeshLib::CFEMesh*>::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it) if ( cpName.compare(it->first) == 0 ) isUnique = false; } // At this point cpName is a unique name and isUnique is true. // If cpName is not the original name, "name" is changed and isUnique is set to false, // indicating that a vector with the original name already exists. if (count > 1) { isUnique = false; name = cpName; } return isUnique; }
bool GEOObjects::isUniquePointVecName(std::string &name) { int count = 0; bool isUnique = false; std::string cpName; while (!isUnique) { isUnique = true; cpName = name; count++; // If the original name already exists we start to add numbers to name for // as long as it takes to make the name unique. if (count > 1) cpName = cpName + "-" + number2str(count); for (size_t i = 0; i < _pnt_vecs.size(); i++) if ( cpName.compare(_pnt_vecs[i]->getName()) == 0 ) isUnique = false; } // At this point cpName is a unique name and isUnique is true. // If cpName is not the original name, "name" is changed and isUnique is set to false, // indicating that a vector with the original name already exists. if (count > 1) { isUnique = false; name = cpName; } return isUnique; }
char * dumpMapName( char * prefix ) { static int dumpCtr = 0; static char name[MAX_NAME_LENGTH]; QString str = "/dev/null"; QFileInfo fi; do { str = QString( QString( prefix ) + number2str( dumpCtr ) + ".png" ); fi = str; dumpCtr++; } while( fi.exists()); strncpy( name, str.ascii(), MAX_NAME_LENGTH ); return( name ); }
SurfaceGrid::SurfaceGrid(Surface const*const sfc) : AABB(sfc->getAABB()), _triangles_in_grid_box(NULL) { double delta[3] = {0.0, 0.0, 0.0}; for (size_t k(0); k<3; k++) { // make the bounding box a little bit bigger, // such that the node with maximal coordinates fits into the grid _max_pnt[k] += std::abs(_max_pnt[k]) * 1e-6; if (fabs(_max_pnt[k]) < std::numeric_limits<double>::epsilon()) { _max_pnt[k] = (_max_pnt[k] - _min_pnt[k]) * (1.0 + 1e-6); } delta[k] = _max_pnt[k] - _min_pnt[k]; } if (delta[0] < std::numeric_limits<double>::epsilon()) { const double max_delta(std::max(delta[1], delta[2])); _min_pnt[0] -= max_delta * 0.5e-3; _max_pnt[0] += max_delta * 0.5e-3; delta[0] = _max_pnt[0] - _min_pnt[0]; } if (delta[1] < std::numeric_limits<double>::epsilon()) { const double max_delta(std::max(delta[0], delta[2])); _min_pnt[1] -= max_delta * 0.5e-3; _max_pnt[1] += max_delta * 0.5e-3; delta[1] = _max_pnt[1] - _min_pnt[1]; } if (delta[2] < std::numeric_limits<double>::epsilon()) { const double max_delta(std::max(delta[0], delta[1])); _min_pnt[2] -= max_delta * 0.5e-3; _max_pnt[2] += max_delta * 0.5e-3; delta[2] = _max_pnt[2] - _min_pnt[2]; } const size_t n_triangles(sfc->getNTriangles()); const size_t n_tris_per_box(5); // *** condition: n_triangles / (_n_steps[0] * _n_steps[1] * _n_steps[2]) < n_tris_per_box // *** with _n_steps[1] = _n_steps[0] * delta[1]/delta[0], _n_steps[2] = _n_steps[0] * delta[2]/delta[0] if (fabs(delta[0]) < std::numeric_limits<double>::epsilon() || fabs(delta[1]) < std::numeric_limits<double>::epsilon() || fabs(delta[2]) < std::numeric_limits<double>::epsilon()) { // 1d case y = z = 0 if (fabs(delta[1]) < std::numeric_limits<double>::epsilon() && fabs(delta[2]) < std::numeric_limits<double>::epsilon()) { _n_steps[0] = static_cast<size_t>(ceil(n_triangles / (double)n_tris_per_box)); _n_steps[1] = 1; _n_steps[2] = 1; } else { // 1d case x = z = 0 if (fabs(delta[0]) < std::numeric_limits<double>::epsilon() && fabs(delta[2]) < std::numeric_limits<double>::epsilon()) { _n_steps[0] = 1; _n_steps[1] = static_cast<size_t>(ceil(n_triangles / (double)n_tris_per_box)); _n_steps[2] = 1; } else { // 1d case x = y = 0 if (fabs(delta[0]) < std::numeric_limits<double>::epsilon() && fabs(delta[1]) < std::numeric_limits<double>::epsilon()) { _n_steps[0] = 1; _n_steps[1] = 1; _n_steps[2] = static_cast<size_t>(ceil(n_triangles / (double)n_tris_per_box)); } else { // 2d cases // y = 0 if (fabs(delta[1]) < std::numeric_limits<double>::epsilon()) { _n_steps[0] = static_cast<size_t>(ceil(sqrt(n_triangles * delta[0] / (n_tris_per_box*delta[2])))); _n_steps[1] = 1; _n_steps[2] = static_cast<size_t>(ceil(_n_steps[0] * delta[2] / delta[0])); } else { // z = 0 if (fabs(delta[2]) < std::numeric_limits<double>::epsilon()) { _n_steps[0] = static_cast<size_t>(ceil(sqrt(n_triangles * delta[0] / (n_tris_per_box*delta[1])))); _n_steps[1] = static_cast<size_t>(ceil(_n_steps[0] * delta[1] / delta[0])); _n_steps[2] = 1; } else { // x = 0 _n_steps[0] = 1; _n_steps[1] = static_cast<size_t>(ceil(sqrt((double)n_triangles/n_tris_per_box * delta[1] / delta[2]))); _n_steps[2] = static_cast<size_t>(ceil(n_triangles * delta[2] / (n_tris_per_box*delta[1]))); } } } } } } else { // 3d case _n_steps[0] = static_cast<size_t>(ceil(pow(n_triangles * delta[0]*delta[0] / (n_tris_per_box*delta[1]*delta[2]), 1. / 3.))); _n_steps[1] = static_cast<size_t>(ceil(_n_steps[0] * std::min(delta[1] / delta[0], 100.0))); _n_steps[2] = static_cast<size_t>(ceil(_n_steps[0] * std::min(delta[2] / delta[0], 100.0))); } const size_t n_plane (_n_steps[0]*_n_steps[1]); _triangles_in_grid_box = new std::vector<Triangle const*> [n_plane*_n_steps[2]]; // some frequently used expressions to fill the grid vectors for (size_t k(0); k<3; k++) { _step_sizes[k] = delta[k] / _n_steps[k]; _inverse_step_sizes[k] = 1.0 / _step_sizes[k]; } #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH // write the grid as gli file std::string fname("SurfaceGrid.gli"); std::ofstream os_sfc(fname.c_str()); writeSurfaceGridData(os_sfc); os_sfc.close(); #endif #endif // fill the grid vectors size_t i_min, i_max, j_min, j_max, k_min, k_max; for (size_t l(0); l<n_triangles; l++) { Triangle const*const tri((*sfc)[l]); Point const& pnt (*(tri->getPoint(0))); i_min = i_max = static_cast<size_t>((pnt[0]-_min_pnt[0]) * _inverse_step_sizes[0]); j_min = j_max = static_cast<size_t>((pnt[1]-_min_pnt[1]) * _inverse_step_sizes[1]); k_min = k_max = static_cast<size_t>((pnt[2]-_min_pnt[2]) * _inverse_step_sizes[2]); if (i_min >= _n_steps[0] || j_min >= _n_steps[1] || k_min >= _n_steps[2]) { std::cout << "error computing indices " << "\n"; } for (size_t m(1); m<3; m++) { Point const& pnt (*(tri->getPoint(m))); const size_t i (static_cast<size_t>((pnt[0]-_min_pnt[0]) * _inverse_step_sizes[0])); const size_t j (static_cast<size_t>((pnt[1]-_min_pnt[1]) * _inverse_step_sizes[1])); const size_t k (static_cast<size_t>((pnt[2]-_min_pnt[2]) * _inverse_step_sizes[2])); if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) { std::cout << "error computing indices " << "\n"; } if (i < i_min) i_min = i; if (i_max < i) i_max = i; if (j < j_min) j_min = j; if (j_max < j) j_max = j; if (k < k_min) k_min = k; if (k_max < k) k_max = k; } for (size_t i(i_min); i<=i_max; i++) { for (size_t j(j_min); j<=j_max; j++) { for (size_t k(k_min); k<=k_max; k++) { _triangles_in_grid_box[i + j*_n_steps[0]+k*n_plane].push_back (tri); } } } } #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH // write the triangles per grid cell as gli if (_n_steps[2]*_n_steps[1]*_n_steps[0] > 1000) return; for (std::size_t k(0); k<_n_steps[2]; k++) { for (std::size_t j(0); j<_n_steps[1]; j++) { for (std::size_t i(0); i<_n_steps[0]; i++) { const std::size_t cell_id( k*_n_steps[0]*_n_steps[1] + j*_n_steps[0] + i ); if (_triangles_in_grid_box[cell_id].empty()) continue; std::string fname("SurfaceGrid-"); fname += number2str(sfc) + "-"; fname += number2str(i) + "-"; fname += number2str(j) + "-"; fname += number2str(k) + ".tin"; std::ofstream os_tri(fname.c_str()); writeTrianglesInGridCell(i,j,k,os_tri); os_tri.close(); } } } #endif #endif }
static int mail_user(struct offenderlist *offender, struct configparams *config) { struct usage *lptr; FILE *fp; int cnt, status; char timebuf[MAXTIMELEN]; char numbuf[3][MAXNUMLEN]; struct util_dqblk *dqb; char *to = NULL; if (offender->offender_type == USRQUOTA) { to = lookup_user(config, offender->offender_name); if (!to) return -1; } else { struct adminstable *admin; if (!(admin = bsearch(offender->offender_name, adminstable, adminscnt, sizeof(struct adminstable), admin_name_cmp))) { errstr(_("Administrator for a group %s not found. Cancelling mail.\n"), offender->offender_name); return -1; } to = sstrdup(admin->adminname); } if (!(fp = run_mailer(config->mail_cmd))) { if (to) free(to); return -1; } fprintf(fp, "From: %s\n", config->from); fprintf(fp, "Reply-To: %s\n", config->support); fprintf(fp, "Subject: %s\n", config->subject); fprintf(fp, "To: %s\n", to); if (should_cc(offender, config)) { char *cc_to = lookup_user(config, config->cc_to); if (cc_to) { fprintf(fp, "Cc: %s\n", config->cc_to); free(cc_to); } } if ((config->charset)[0] != '\0') { /* are we supposed to set the encoding */ fprintf(fp, "MIME-Version: 1.0\n"); fprintf(fp, "Content-Type: text/plain; charset=%s\n", config->charset); fprintf(fp, "Content-Disposition: inline\n"); fprintf(fp, "Content-Transfer-Encoding: 8bit\n"); } fprintf(fp, "\n"); free(to); if (offender->offender_type == USRQUOTA) if (config->user_message) format_print(fp, config->user_message, offender->offender_name); else fputs(DEF_USER_MESSAGE, fp); else if (config->group_message) format_print(fp, config->group_message, offender->offender_name); else fprintf(fp, DEF_GROUP_MESSAGE, offender->offender_name); if (!(flags & FL_NODETAILS)) { for (lptr = offender->usage; lptr; lptr = lptr->next) { dqb = &lptr->dq_dqb; for (cnt = 0; cnt < qtab_i; cnt++) if (!strcmp(quotatable[cnt].devname, lptr->devicename)) { fprintf(fp, "\n%s (%s)\n", quotatable[cnt].devdesc, quotatable[cnt].devname); break; } if (cnt == qtab_i) /* Description not found? */ fprintf(fp, "\n%s\n", lptr->devicename); fprintf(fp, _("\n Block limits File limits\n")); fprintf(fp, _("Filesystem used soft hard grace used soft hard grace\n")); if (strlen(lptr->devicename) > 15) fprintf(fp, "%s\n%15s", lptr->devicename, ""); else fprintf(fp, "%-15s", lptr->devicename); if (dqb->dqb_bsoftlimit && dqb->dqb_bsoftlimit <= toqb(dqb->dqb_curspace)) difftime2str(dqb->dqb_btime, timebuf); else timebuf[0] = '\0'; space2str(toqb(dqb->dqb_curspace), numbuf[0], flags & FL_SHORTNUMS); space2str(dqb->dqb_bsoftlimit, numbuf[1], flags & FL_SHORTNUMS); space2str(dqb->dqb_bhardlimit, numbuf[2], flags & FL_SHORTNUMS); fprintf(fp, "%c%c %7s %7s %7s %6s", dqb->dqb_bsoftlimit && toqb(dqb->dqb_curspace) >= dqb->dqb_bsoftlimit ? '+' : '-', dqb->dqb_isoftlimit && dqb->dqb_curinodes >= dqb->dqb_isoftlimit ? '+' : '-', numbuf[0], numbuf[1], numbuf[2], timebuf); if (dqb->dqb_isoftlimit && dqb->dqb_isoftlimit <= dqb->dqb_curinodes) difftime2str(dqb->dqb_itime, timebuf); else timebuf[0] = '\0'; number2str(dqb->dqb_curinodes, numbuf[0], flags & FL_SHORTNUMS); number2str(dqb->dqb_isoftlimit, numbuf[1], flags & FL_SHORTNUMS); number2str(dqb->dqb_ihardlimit, numbuf[2], flags & FL_SHORTNUMS); fprintf(fp, " %7s %5s %5s %6s\n\n", numbuf[0], numbuf[1], numbuf[2], timebuf); } } if (offender->offender_type == USRQUOTA) if (config->user_signature) format_print(fp, config->user_signature, offender->offender_name); else fprintf(fp, DEF_USER_SIGNATURE, config->support, config->phone); else if (config->group_signature) format_print(fp, config->group_signature, offender->offender_name); else fprintf(fp, DEF_GROUP_SIGNATURE, config->support, config->phone); fclose(fp); if (wait(&status) < 0) /* Wait for mailer */ errstr(_("Cannot wait for mailer: %s\n"), strerror(errno)); else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) errstr(_("Warning: Mailer exitted abnormally.\n")); return 0; }