/* -- translate down by 'h' scaled points in output buffer -- */ void bskip(float h) { if (h == 0) return; bposy -= h * cfmt.scale; a2b("0 %.2f T\n", -h); }
void transliterate(char *chat, int lang) { int i=0,j=0; char *buf = malloc(strlen(chat)*sizeof(char)); char *charBuf = malloc(sizeof(char)); buf[0] = '\0'; for(;i<strlen(chat);i++) { if((int)chat[i]>0) { charBuf[0] = chat[i]; strcat(buf,charBuf); } else if((int)chat[i]==-32) { char *tmp = malloc(5*sizeof(char)); j = 0; tmp[j] = chat[i]; j++; while((int)chat[i+j]<0 && (int)chat[i+j]!=-32) { tmp[j] = chat[i+j]; j++; } tmp[j--] = '\0'; a2b(tmp,lang); strcat(buf,tmp); if(tmp!=NULL) free(tmp); i+=j; } } strcpy(chat,buf); if(buf!=NULL) free(buf); return; }
template <class T> void TestTriDiv_A2() { const int N = 10; tmv::Matrix<T> m(N,N); for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) m(i,j) = T(0.4+0.02*i-0.05*j); m.diag().addToAll(5); m.diag(1).addToAll(T(0.32)); m.diag(-1).addToAll(T(0.91)); tmv::Matrix<std::complex<T> > cm(m); cm += std::complex<T>(10,2); cm.diag(1) *= std::complex<T>(T(-0.5),T(-0.8)); cm.diag(-1) *= std::complex<T>(T(-0.7),T(0.1)); tmv::UpperTriMatrix<T,tmv::NonUnitDiag> a1(m); tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag> ca1(cm); tmv::UpperTriMatrix<T,tmv::UnitDiag> a2(m); tmv::UpperTriMatrix<std::complex<T>,tmv::UnitDiag> ca2(cm); tmv::UpperTriMatrixView<T> a1v = a1.view(); tmv::UpperTriMatrixView<T> a2v = a2.view(); tmv::UpperTriMatrixView<std::complex<T> > ca1v = ca1.view(); tmv::UpperTriMatrixView<std::complex<T> > ca2v = ca2.view(); tmv::LowerTriMatrixView<T> a1t = a1.transpose(); tmv::LowerTriMatrixView<T> a2t = a2.transpose(); tmv::LowerTriMatrixView<std::complex<T> > ca1t = ca1.transpose(); tmv::LowerTriMatrixView<std::complex<T> > ca2t = ca2.transpose(); TestMatrixDivArith1(tmv::LU,a1v,a2t,ca1v,ca2t,"L/U"); TestMatrixDivArith1(tmv::LU,a1t,a2v,ca1t,ca2v,"U/L"); TestMatrixDivArith1(tmv::LU,a2v,a1t,ca2v,ca1t,"L/U"); TestMatrixDivArith1(tmv::LU,a2t,a1v,ca2t,ca1v,"U/L"); #if (XTEST & 2) tmv::UpperTriMatrix<T,tmv::NonUnitDiag> a1b(m); tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag> ca1b(cm); tmv::UpperTriMatrix<T,tmv::UnitDiag> a2b(m); tmv::UpperTriMatrix<std::complex<T>,tmv::UnitDiag> ca2b(cm); tmv::UpperTriMatrixView<T> a1bv = a1b.view(); tmv::UpperTriMatrixView<T> a2bv = a2b.view(); tmv::UpperTriMatrixView<std::complex<T> > ca1bv = ca1b.view(); tmv::UpperTriMatrixView<std::complex<T> > ca2bv = ca2b.view(); tmv::LowerTriMatrixView<T> a1bt = a1b.transpose(); tmv::LowerTriMatrixView<T> a2bt = a2b.transpose(); tmv::LowerTriMatrixView<std::complex<T> > ca1bt = ca1b.transpose(); tmv::LowerTriMatrixView<std::complex<T> > ca2bt = ca2b.transpose(); TestMatrixDivArith1(tmv::LU,a1v,a1bt,ca1v,ca1bt,"L/U"); TestMatrixDivArith1(tmv::LU,a1t,a1bv,ca1t,ca1bv,"U/L"); TestMatrixDivArith1(tmv::LU,a2v,a2bt,ca2v,ca2bt,"L/U"); TestMatrixDivArith1(tmv::LU,a2t,a2bv,ca2t,ca2bv,"U/L"); #endif }
void linearOffsetMatcher::match(matchingDest &dest) { int nPer=a.getNodesPer(); //FIXME: getLocFace is O(nFaces), so this loop is O(nFaces^2)! // The only thing that saves us is that nFaces is small-- // for nFaces=10000, this loop takes less than 10 seconds. CkPrintf("FEM_Add_Linear_Periodic> Performing O(n^2) face matching loop (n=%d), (tol=%.1g)\n",nFaces,minTol); for (int fa=0;fa<nFaces;fa++) { CkVector3d bfaceCen=a2b(a.getFaceLoc(fa)); int fb=b.getLocFace(bfaceCen,minTol); //<- the slow step dest.facesIdentical(fa,fb); for (int i=0;i<nPer;i++) { int na=a.getNode(fa,i); if (na!=-1) { int nb=b.getLocNode(fb,a2b(a.getNodeLoc(na)),minTol); dest.nodesIdentical(na,nb); } } } CkPrintf("FEM_Add_Linear_Periodic> Faces matched\n"); }
void FromDaylightString(T &sbv, const std::string &s) { sbv.clearBits(); int length = s.length(); int nBits; if (s[length - 1] == '\n') length -= 1; // 4 bytes in the ascii correspond to 3 bytes in the binary // plus there's one extra ascii byte for the pad marker length -= 1; nBits = (3 * length / 4) * 8; switch (s[length]) { case '1': nBits -= 16; break; case '2': nBits -= 8; break; case '3': break; default: throw "ValueError bad daylight fingerprint string"; } int i = 0, nBitsDone = 0; while (i < length) { char bytes[3]; a2b(s.c_str() + i, bytes); for (int j = 0; j < 3 && nBitsDone < nBits; j++) { unsigned char query = 0x80; for (int k = 0; k < 8; k++) { if (bytes[j] & query) { sbv.setBit(nBitsDone); } query >>= 1; nBitsDone++; } } i += 4; } }
static void solver_from_dimacs_stream(Z3_context c, Z3_solver s, std::istream& is) { init_solver(c, s); ast_manager& m = to_solver_ref(s)->get_manager(); std::stringstream err; sat::solver solver(to_solver_ref(s)->get_params(), m.limit()); if (!parse_dimacs(is, err, solver)) { SET_ERROR_CODE(Z3_PARSER_ERROR, err.str().c_str()); return; } sat2goal s2g; ref<sat2goal::mc> mc; atom2bool_var a2b(m); for (unsigned v = 0; v < solver.num_vars(); ++v) { a2b.insert(m.mk_const(symbol(v), m.mk_bool_sort()), v); } goal g(m); s2g(solver, a2b, to_solver_ref(s)->get_params(), g, mc); for (unsigned i = 0; i < g.size(); ++i) { to_solver_ref(s)->assert_expr(g.form(i)); } }
/* return the next character */ char *glyph_out(char *p) { int i1, i2, i3, i4; char **g, *q; g = NULL; i1 = (unsigned char) *p++ - 0xc2; i2 = (unsigned char) *p++ - 0x80; if (i1 >= 0xe0 - 0xc2) { i3 = (unsigned char) *p++ - 0x80; if (i1 >= 0xf0 - 0xc2) i4 = (unsigned char) *p++ - 0x80; else i4 = -1; } else { i3 = -1; i4 = -1; } if (i1 >= 0 && i2 >= 0) { g = (char **) utf_1[i1]; if (g) { g = (char **) g[i2]; if (i3 >= 0 && g) { g = (char **) g[i3]; if (i4 >= 0 && g) g = (char **) g[i4]; } } q = (char *) g; } else { q = NULL; } if (!q) q = ".notdef"; a2b("/%s", q); return p; }
void read_ascii(char* asciifile, char* binfile = 0) { Ascii2Bin a2b(asciifile, binfile); }
static void parseGNS(un8 index, char *value) { un8 i, fix; if (*value == 0) return; switch (index) { case GPS_GNS_MODE: /* One character per system, N: no fix */ fix = 0; for (i = 0; value[i] != 0; i++) { fix |= (value[i] != 'N'); } veVariantUn8(&local.fix, fix); return; case GPS_GNS_LATITUDE: errno = 0; veVariantFloat(&local.latitude, toDeg((float)atof(value))); if (errno) veVariantInvalidate(&local.latitude); return; case GPS_GNS_LAT_NORTH_SOUTH: /* North is positive, south is negative */ if (value[0] == 'S') local.latitude.value.Float *= -1; return; case GPS_GNS_LONGITUDE: errno = 0; veVariantFloat(&local.longitude, toDeg((float)atof(value))); if (errno) veVariantInvalidate(&local.longitude); return; case GPS_GNS_LONG_EAST_WEST: /* East is positive, west is negative */ if (value[0] == 'W') local.longitude.value.Float *= -1; return; case GPS_GNS_UTC_TIME: memset(&local.time, 0, sizeof(struct tm)); local.time.tm_hour = a2b(*value++) * 10; local.time.tm_hour += a2b(*value++); local.time.tm_min = a2b(*value++) * 10; local.time.tm_min += a2b(*value++); local.time.tm_sec = a2b(*value++ ) * 10; local.time.tm_sec += a2b(*value++); return; case GPS_GNS_ALTITUDE: errno = 0; veVariantFloat(&local.altitude, (float)atof(value)); if (errno) veVariantInvalidate(&local.altitude); return; case GPS_GNS_NR_OF_SATELITES: errno = 0; veVariantUn8(&local.nrOfSats, (un8)atol(value)); if (errno) veVariantInvalidate(&local.nrOfSats); return; } }
/* * RMC Recommended Minimum Navigation Information * * 1 2 3 4 5 6 7 8 9 10 11 * | | | | | | | | | | | * hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,xxxx,x.x,a * * 1) Time (UTC) * 2) Status, V = Navigation receiver warning * 3) Latitude * 4) N or S * 5) Longitude * 6) E or W * 7) Speed over ground, knots * 8) Track made good, degrees true * 9) Date, ddmmyy * 10) Magnetic Variation, degrees * 11) E or W */ static void parseRMC(un8 index, char *value) { if (*value == 0) return; switch (index) { case GPS_RMC_STATUS: /* A: fix; V: no fix */ veVariantUn8(&local.fix, value[0] == 'A'); return; case GPS_RMC_LATITUDE: errno = 0; veVariantFloat(&local.latitude, toDeg((float)atof(value))); if (errno) veVariantInvalidate(&local.latitude); return; case GPS_RMC_LAT_NORTH_SOUTH: /* North is positive, south is negative */ if (value[0] == 'S') local.latitude.value.Float *= -1; return; case GPS_RMC_LONGITUDE: errno = 0; veVariantFloat(&local.longitude, toDeg((float)atof(value))); if (errno) veVariantInvalidate(&local.longitude); return; case GPS_RMC_LONG_EAST_WEST: /* East is positive, west is negative */ if (value[0] == 'W') local.longitude.value.Float *= -1; return; case GPS_RMC_VARIATION: errno = 0; veVariantFloat(&local.variation, toDeg((float)atof(value))); if (errno) veVariantInvalidate(&local.variation); return; case GPS_RMC_VAR_EAST_WEST: /* East is positive, west is negative */ if (value[0] == 'W') local.variation.value.Float *= -1; return; case GPS_RMC_UTC_TIME: memset(&local.time, 0, sizeof(struct tm)); local.time.tm_hour = a2b(*value++) * 10; local.time.tm_hour += a2b(*value++); local.time.tm_min = a2b(*value++) * 10; local.time.tm_min += a2b(*value++); local.time.tm_sec = a2b(*value++ ) * 10; local.time.tm_sec += a2b(*value++); return; case GPS_RMC_UTC_DATE: local.time.tm_mday = a2b(*value++) * 10; local.time.tm_mday += a2b(*value++); local.time.tm_mon = a2b(*value++) * 10; local.time.tm_mon += a2b(*value++) - 1; /* 0-11 */ local.time.tm_year = a2b(*value++) * 10; local.time.tm_year += a2b(*value++) + 100; /* Since 1900 */ veVariantUn32(&local.timestamp, (un32)mktime(&local.time)); return; case GPS_RMC_SPEED: errno = 0; veVariantFloat(&local.speed, (float)atof(value)); if (errno) { veVariantInvalidate(&local.speed); return; } /* Knots to m/s */ local.speed.value.Float *= (1852.0 / 3600.0); return; case GPS_RMC_TRUE_COURSE: /* Prevent bouncing when not moving */ if (!veVariantIsValid(&local.speed) || local.speed.value.Float == 0) { veVariantInvalidate(&local.course); return; } errno = 0; veVariantFloat(&local.course, (float)atof(value)); if (errno) veVariantInvalidate(&local.course); return; } }
/* -- output the header or footer -- */ static float headfooter(int header, float pwidth, float pheight) { char tmp[2048], str[TEX_BUF_SZ + 512]; char *p, *q, *r, *outbuf_sav, *mbf_sav; float size, y, wsize; struct FONTSPEC *f, f_sav; int cft_sav, dft_sav, outbufsz_sav; if (header) { p = cfmt.header; f = &cfmt.font_tb[HEADERFONT]; size = f->size; y = -size; } else { p = cfmt.footer; f = &cfmt.font_tb[FOOTERFONT]; size = f->size; y = - (pheight - cfmt.topmargin - cfmt.botmargin) + size; } if (*p == '-') { if (pagenum == 1) return 0; p++; } get_str_font(&cft_sav, &dft_sav); memcpy(&f_sav, &cfmt.font_tb[0], sizeof f_sav); str_font(f - cfmt.font_tb); output(fout, "%.1f F%d ", size, f->fnum); outft = f - cfmt.font_tb; /* may have 2 lines */ wsize = size; if ((r = strstr(p, "\\n")) != NULL) { if (!header) y += size; wsize += size; *r = '\0'; } mbf_sav = mbf; outbuf_sav = outbuf; outbufsz_sav = outbufsz; outbuf = tmp; outbufsz = sizeof tmp; for (;;) { tex_str(p); strcpy(tmp, tex_buf); format_hf(str, tmp); /* left side */ p = str; if ((q = strchr(p, '\t')) != NULL) { if (q != p) { *q = '\0'; output(fout, "%.1f %.1f M ", p_fmt->leftmargin, y); mbf = tmp; str_out(p, A_LEFT); a2b("\n"); if (svg) svg_write(tmp, strlen(tmp)); else fputs(tmp, fout); } p = q + 1; } if ((q = strchr(p, '\t')) != NULL) *q = '\0'; /* center */ if (q != p) { output(fout, "%.1f %.1f M ", pwidth * 0.5, y); mbf = tmp; str_out(p, A_CENTER); a2b("\n"); if (svg) svg_write(tmp, strlen(tmp)); else fputs(tmp, fout); } /* right side */ if (q) { p = q + 1; if (*p != '\0') { output(fout, "%.1f %.1f M ", pwidth - p_fmt->rightmargin, y); mbf = tmp; str_out(p, A_RIGHT); a2b("\n"); if (svg) svg_write(tmp, strlen(tmp)); else fputs(tmp, fout); } } if (!r) break; *r = '\\'; p = r + 2; r = NULL; y -= size; } /* restore the buffer and fonts */ outbuf = outbuf_sav; outbufsz = outbufsz_sav; mbf = mbf_sav; memcpy(&cfmt.font_tb[0], &f_sav, sizeof cfmt.font_tb[0]); set_str_font(cft_sav, dft_sav); return wsize; }