static void write_xplor(const char *file,real *data,int *ibox,real dmin[],real dmax[]) { XplorMap *xm; int i,j,k,n; snew(xm,1); xm->Nx = ibox[XX]; xm->Ny = ibox[YY]; xm->Nz = ibox[ZZ]; snew(xm->ed,xm->Nx*xm->Ny*xm->Nz); n=0; for(k=0; (k<xm->Nz); k++) for(j=0; (j<xm->Ny); j++) for(i=0; (i<xm->Nx); i++) xm->ed[n++] = data[index3(ibox,i,j,k)]; xm->cell[0] = dmax[XX]-dmin[XX]; xm->cell[1] = dmax[YY]-dmin[YY]; xm->cell[2] = dmax[ZZ]-dmin[ZZ]; xm->cell[3] = xm->cell[4] = xm->cell[5] = 90; clear_ivec(xm->dmin); xm->dmax[XX] = ibox[XX]-1; xm->dmax[YY] = ibox[YY]-1; xm->dmax[ZZ] = ibox[ZZ]-1; lo_write_xplor(xm,file); sfree(xm->ed); sfree(xm); }
TypeSpec ASTindex::typecheck (TypeSpec expected) { typecheck_children (); const char *indextype = ""; TypeSpec t = lvalue()->typespec(); if (t.is_structure()) { error ("Cannot use [] indexing on a struct"); return TypeSpec(); } if (t.is_closure()) { error ("Cannot use [] indexing on a closure"); return TypeSpec(); } if (index3()) { if (! t.is_array() && ! t.elementtype().is_matrix()) error ("[][][] only valid for a matrix array"); m_typespec = TypeDesc::FLOAT; } else if (t.is_array()) { indextype = "array"; m_typespec = t.elementtype(); if (index2()) { if (t.aggregate() == TypeDesc::SCALAR) error ("can't use [][] on a simple array"); m_typespec = TypeDesc::FLOAT; } } else if (t.aggregate() == TypeDesc::VEC3) { indextype = "component"; TypeDesc tnew = t.simpletype(); tnew.aggregate = TypeDesc::SCALAR; tnew.vecsemantics = TypeDesc::NOXFORM; m_typespec = tnew; if (index2()) error ("can't use [][] on a %s", type_c_str(t)); } else if (t.aggregate() == TypeDesc::MATRIX44) { indextype = "component"; TypeDesc tnew = t.simpletype(); tnew.aggregate = TypeDesc::SCALAR; tnew.vecsemantics = TypeDesc::NOXFORM; m_typespec = tnew; if (! index2()) error ("must use [][] on a matrix, not just []"); } else { error ("can only use [] indexing for arrays or multi-component types"); return TypeSpec(); } // Make sure the indices (children 1+) are integers for (size_t c = 1; c < nchildren(); ++c) if (! child(c)->typespec().is_int()) error ("%s index must be an integer, not a %s", indextype, type_c_str(index()->typespec())); // If the thing we're indexing is an lvalue, so is the indexed element m_is_lvalue = lvalue()->is_lvalue(); return m_typespec; }
/* * Performs the calculations for a single particle for grid_mpole * Equivalent to the calculations in the grid_mpole method in pmestuff.f */ void mpole_math(double* fmp, int* igrid, double* qgrid, double* thetai1, double* thetai2, double* thetai3, int bsorder, int nfft1, int nfft2, int nfft3, int npole, int n, int m){ int i, j, k; int i0, j0, k0; int it1, it2, it3; int igrd0, jgrd0, kgrd0; double v0, u0, t0; double v1, u1, t1; double v2, u2, t2; double term0, term1, term2; igrd0 = igrid[index2(0, m, 3, maxatm)]; jgrd0 = igrid[index2(1, m, 3, maxatm)]; kgrd0 = igrid[index2(2, m, 3, maxatm)]; k0 = kgrd0; for (it3 = 0; it3 < bsorder; ++it3){ k0 = k0 + 1; k = k0 + 1 + (nfft3-intsign(nfft3,k0))/2; v0 = thetai3[index3(0,it3,m, 4,bsorder,n)]; v1 = thetai3[index3(1,it3,m, 4,bsorder,n)]; v2 = thetai3[index3(2,it3,m, 4,bsorder,n)]; j0 = jgrd0; for (it2 = 0; it2 < bsorder; ++it2){ j0 = j0 + 1; j = j0 + 1 + (nfft2-intsign(nfft2,j0))/2; u0 = thetai2[index3(0,it2,m, 4,bsorder,n)]; u1 = thetai2[index3(1,it2,m, 4,bsorder,n)]; u2 = thetai2[index3(2,it2,m, 4,bsorder,n)]; term0 = fmp[index2(0,m, 10, maxatm)]*u0*v0 + fmp[index2(2,m, 10, maxatm)]*u1*v0 + fmp[index2(3,m, 10, maxatm)]*u0*v1 + fmp[index2(5,m, 10, maxatm)]*u2*v0 + fmp[index2(6,m, 10, maxatm)]*u0*v2 + fmp[index2(9,m, 10, maxatm)]*u1*v1; term1 = fmp[index2(1,m, 10, maxatm)]*u0*v0 + fmp[index2(7,m, 10, maxatm)]*u1*v0 + fmp[index2(8,m, 10, maxatm)]*u0*v1; term2 = fmp[index2(4,m, 10, maxatm)] * u0 * v0; i0 = igrd0; for (it1 = 0; it1 < bsorder; ++it1){ i0 = i0 + 1; i = i0 + 1 + (nfft1-intsign(nfft1,i0))/2; t0 = thetai1[index3(0,it1,m, 4,bsorder,n)]; t1 = thetai1[index3(1,it1,m, 4,bsorder,n)]; t2 = thetai1[index3(2,it1,m, 4,bsorder,n)]; qgrid[index4(0,i-1,j-1,k-1,2, nfft3,nfft2,nfft1)] = qgrid[index4(0,i-1,j-1,k-1,2, nfft3,nfft2,nfft1)] + term0*t0 + term1*t1 + term2*t2; } } } }
void testCopy() { std::unique_ptr< QgsVectorLayer > vl = qgis::make_unique< QgsVectorLayer >( "Point", QString(), QStringLiteral( "memory" ) ); for ( QgsFeature f : _pointFeatures() ) vl->dataProvider()->addFeature( f ); std::unique_ptr< QgsSpatialIndexKDBush > index( new QgsSpatialIndexKDBush( *vl->dataProvider() ) ); // create copy of the index std::unique_ptr< QgsSpatialIndexKDBush > indexCopy( new QgsSpatialIndexKDBush( *index ) ); QVERIFY( index->d == indexCopy->d ); QVERIFY( index->d->ref == 2 ); // test that copied index works QList<QgsSpatialIndexKDBushData> fids = indexCopy->intersects( QgsRectangle( 0, 0, 10, 10 ) ); QVERIFY( fids.count() == 1 ); QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) ); // check that the index is still shared QVERIFY( index->d == indexCopy->d ); QVERIFY( index->d->ref == 2 ); index.reset(); // test that copied index still works fids = indexCopy->intersects( QgsRectangle( 0, 0, 10, 10 ) ); QVERIFY( fids.count() == 1 ); QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) ); QVERIFY( indexCopy->d->ref == 1 ); // assignment operator std::unique_ptr< QgsVectorLayer > vl2 = qgis::make_unique< QgsVectorLayer >( "Point", QString(), QStringLiteral( "memory" ) ); QgsSpatialIndexKDBush index3( *vl2->dataProvider() ); QVERIFY( index3.size() == 0 ); fids = index3.intersects( QgsRectangle( 0, 0, 10, 10 ) ); QVERIFY( fids.count() == 0 ); QVERIFY( index3.d->ref == 1 ); index3 = *indexCopy; QVERIFY( index3.d == indexCopy->d ); QVERIFY( index3.d->ref == 2 ); fids = index3.intersects( QgsRectangle( 0, 0, 10, 10 ) ); QVERIFY( fids.count() == 1 ); QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) ); indexCopy.reset(); QVERIFY( index3.d->ref == 1 ); }
static void do_sham(const char *fn, const char *ndx, const char *xpmP, const char *xpm, const char *xpm2, const char *xpm3, const char *pdb, const char *logf, int n, int neig, real **eig, gmx_bool bGE, int nenerT, real **enerT, real Tref, real pmax, real gmax, real *emin, real *emax, int nlevels, real pmin, int *idim, int *ibox, gmx_bool bXmin, real *xmin, gmx_bool bXmax, real *xmax) { FILE *fp; real *min_eig, *max_eig; real *axis_x, *axis_y, *axis_z, *axis = NULL; double *P; real **PP, *W, *E, **WW, **EE, *S, **SS, *M, *bE; rvec xxx; char *buf; double *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf, Mmin, Mmax; real *delta; int i, j, k, imin, len, index, d, *nbin, *bindex, bi; int *nxyz, maxbox; t_blocka *b; gmx_bool bOutside; unsigned int flags; t_rgb rlo = { 0, 0, 0 }; t_rgb rhi = { 1, 1, 1 }; /* Determine extremes for the eigenvectors */ snew(min_eig, neig); snew(max_eig, neig); snew(nxyz, neig); snew(bfac, neig); snew(delta, neig); for (i = 0; (i < neig); i++) { /* Check for input constraints */ min_eig[i] = max_eig[i] = eig[i][0]; for (j = 0; (j < n); j++) { min_eig[i] = min(min_eig[i], eig[i][j]); max_eig[i] = max(max_eig[i], eig[i][j]); delta[i] = (max_eig[i]-min_eig[i])/(2.0*ibox[i]); } /* Add some extra space, half a bin on each side, unless the * user has set the limits. */ if (bXmax) { if (max_eig[i] > xmax[i]) { gmx_warning("Your xmax[%d] value %f is smaller than the largest data point %f", i, xmax[i], max_eig[i]); } max_eig[i] = xmax[i]; } else { max_eig[i] += delta[i]; } if (bXmin) { if (min_eig[i] < xmin[i]) { gmx_warning("Your xmin[%d] value %f is larger than the smallest data point %f", i, xmin[i], min_eig[i]); } min_eig[i] = xmin[i]; } else { min_eig[i] -= delta[i]; } bfac[i] = ibox[i]/(max_eig[i]-min_eig[i]); } /* Do the binning */ bref = 1/(BOLTZ*Tref); snew(bE, n); if (bGE || nenerT == 2) { Emin = 1e8; for (j = 0; (j < n); j++) { if (bGE) { bE[j] = bref*enerT[0][j]; } else { bE[j] = (bref - 1/(BOLTZ*enerT[1][j]))*enerT[0][j]; } Emin = min(Emin, bE[j]); } } else { Emin = 0; } len = 1; for (i = 0; (i < neig); i++) { len = len*ibox[i]; } printf("There are %d bins in the %d-dimensional histogram. Beta-Emin = %g\n", len, neig, Emin); snew(P, len); snew(W, len); snew(E, len); snew(S, len); snew(M, len); snew(nbin, len); snew(bindex, n); /* Loop over projections */ for (j = 0; (j < n); j++) { /* Loop over dimensions */ bOutside = FALSE; for (i = 0; (i < neig); i++) { nxyz[i] = bfac[i]*(eig[i][j]-min_eig[i]); if (nxyz[i] < 0 || nxyz[i] >= ibox[i]) { bOutside = TRUE; } } if (!bOutside) { index = indexn(neig, ibox, nxyz); range_check(index, 0, len); /* Compute the exponential factor */ if (enerT) { efac = exp(-bE[j]+Emin); } else { efac = 1; } /* Apply the bin volume correction for a multi-dimensional distance */ for (i = 0; i < neig; i++) { if (idim[i] == 2) { efac /= eig[i][j]; } else if (idim[i] == 3) { efac /= sqr(eig[i][j]); } else if (idim[i] == -1) { efac /= sin(DEG2RAD*eig[i][j]); } } /* Update the probability */ P[index] += efac; /* Update the energy */ if (enerT) { E[index] += enerT[0][j]; } /* Statistics: which "structure" in which bin */ nbin[index]++; bindex[j] = index; } } /* Normalize probability */ normalize_p_e(len, P, nbin, E, pmin); Pmax = 0; /* Compute boundaries for the Free energy */ Wmin = 1e8; imin = -1; Wmax = -1e8; /* Recompute Emin: it may have changed due to averaging */ Emin = 1e8; Emax = -1e8; for (i = 0; (i < len); i++) { if (P[i] != 0) { Pmax = max(P[i], Pmax); W[i] = -BOLTZ*Tref*log(P[i]); if (W[i] < Wmin) { Wmin = W[i]; imin = i; } Emin = min(E[i], Emin); Emax = max(E[i], Emax); Wmax = max(W[i], Wmax); } } if (pmax > 0) { Pmax = pmax; } if (gmax > 0) { Wmax = gmax; } else { Wmax -= Wmin; } Winf = Wmax+1; Einf = Emax+1; Smin = Emin-Wmax; Smax = Emax-Smin; Sinf = Smax+1; /* Write out the free energy as a function of bin index */ fp = gmx_ffopen(fn, "w"); for (i = 0; (i < len); i++) { if (P[i] != 0) { W[i] -= Wmin; S[i] = E[i]-W[i]-Smin; fprintf(fp, "%5d %10.5e %10.5e %10.5e\n", i, W[i], E[i], S[i]); } else { W[i] = Winf; E[i] = Einf; S[i] = Sinf; } } gmx_ffclose(fp); /* Organize the structures in the bins */ snew(b, 1); snew(b->index, len+1); snew(b->a, n); b->index[0] = 0; for (i = 0; (i < len); i++) { b->index[i+1] = b->index[i]+nbin[i]; nbin[i] = 0; } for (i = 0; (i < n); i++) { bi = bindex[i]; b->a[b->index[bi]+nbin[bi]] = i; nbin[bi]++; } /* Consistency check */ /* This no longer applies when we allow the plot to be smaller than the sampled space. for(i=0; (i<len); i++) { if (nbin[i] != (b->index[i+1] - b->index[i])) gmx_fatal(FARGS,"nbin[%d] = %d, should be %d",i,nbin[i], b->index[i+1] - b->index[i]); } */ /* Write the index file */ fp = gmx_ffopen(ndx, "w"); for (i = 0; (i < len); i++) { if (nbin[i] > 0) { fprintf(fp, "[ %d ]\n", i); for (j = b->index[i]; (j < b->index[i+1]); j++) { fprintf(fp, "%d\n", b->a[j]+1); } } } gmx_ffclose(fp); snew(axis_x, ibox[0]+1); snew(axis_y, ibox[1]+1); snew(axis_z, ibox[2]+1); maxbox = max(ibox[0], max(ibox[1], ibox[2])); snew(PP, maxbox*maxbox); snew(WW, maxbox*maxbox); snew(EE, maxbox*maxbox); snew(SS, maxbox*maxbox); for (i = 0; (i < min(neig, 3)); i++) { switch (i) { case 0: axis = axis_x; break; case 1: axis = axis_y; break; case 2: axis = axis_z; break; default: break; } for (j = 0; j <= ibox[i]; j++) { axis[j] = min_eig[i] + j/bfac[i]; } } pick_minima(logf, ibox, neig, len, W); if (gmax <= 0) { gmax = Winf; } flags = MAT_SPATIAL_X | MAT_SPATIAL_Y; if (neig == 2) { /* Dump to XPM file */ snew(PP, ibox[0]); for (i = 0; (i < ibox[0]); i++) { snew(PP[i], ibox[1]); for (j = 0; j < ibox[1]; j++) { PP[i][j] = P[i*ibox[1]+j]; } WW[i] = &(W[i*ibox[1]]); EE[i] = &(E[i*ibox[1]]); SS[i] = &(S[i*ibox[1]]); } fp = gmx_ffopen(xpmP, "w"); write_xpm(fp, flags, "Probability Distribution", "", "PC1", "PC2", ibox[0], ibox[1], axis_x, axis_y, PP, 0, Pmax, rlo, rhi, &nlevels); gmx_ffclose(fp); fp = gmx_ffopen(xpm, "w"); write_xpm(fp, flags, "Gibbs Energy Landscape", "G (kJ/mol)", "PC1", "PC2", ibox[0], ibox[1], axis_x, axis_y, WW, 0, gmax, rlo, rhi, &nlevels); gmx_ffclose(fp); fp = gmx_ffopen(xpm2, "w"); write_xpm(fp, flags, "Enthalpy Landscape", "H (kJ/mol)", "PC1", "PC2", ibox[0], ibox[1], axis_x, axis_y, EE, emin ? *emin : Emin, emax ? *emax : Einf, rlo, rhi, &nlevels); gmx_ffclose(fp); fp = gmx_ffopen(xpm3, "w"); write_xpm(fp, flags, "Entropy Landscape", "TDS (kJ/mol)", "PC1", "PC2", ibox[0], ibox[1], axis_x, axis_y, SS, 0, Sinf, rlo, rhi, &nlevels); gmx_ffclose(fp); } else if (neig == 3) { /* Dump to PDB file */ fp = gmx_ffopen(pdb, "w"); for (i = 0; (i < ibox[0]); i++) { xxx[XX] = 3*(i+0.5-ibox[0]/2); for (j = 0; (j < ibox[1]); j++) { xxx[YY] = 3*(j+0.5-ibox[1]/2); for (k = 0; (k < ibox[2]); k++) { xxx[ZZ] = 3*(k+0.5-ibox[2]/2); index = index3(ibox, i, j, k); if (P[index] > 0) { fprintf(fp, "%-6s%5u %-4.4s%3.3s %4d %8.3f%8.3f%8.3f%6.2f%6.2f\n", "ATOM", (index+1) %10000, "H", "H", (index+1)%10000, xxx[XX], xxx[YY], xxx[ZZ], 1.0, W[index]); } } } } gmx_ffclose(fp); write_xplor("out.xplor", W, ibox, min_eig, max_eig); nxyz[XX] = imin/(ibox[1]*ibox[2]); nxyz[YY] = (imin-nxyz[XX]*ibox[1]*ibox[2])/ibox[2]; nxyz[ZZ] = imin % ibox[2]; for (i = 0; (i < ibox[0]); i++) { snew(WW[i], maxbox); for (j = 0; (j < ibox[1]); j++) { WW[i][j] = W[index3(ibox, i, j, nxyz[ZZ])]; } } snew(buf, strlen(xpm)+4); sprintf(buf, "%s", xpm); sprintf(&buf[strlen(xpm)-4], "12.xpm"); fp = gmx_ffopen(buf, "w"); write_xpm(fp, flags, "Gibbs Energy Landscape", "W (kJ/mol)", "PC1", "PC2", ibox[0], ibox[1], axis_x, axis_y, WW, 0, gmax, rlo, rhi, &nlevels); gmx_ffclose(fp); for (i = 0; (i < ibox[0]); i++) { for (j = 0; (j < ibox[2]); j++) { WW[i][j] = W[index3(ibox, i, nxyz[YY], j)]; } } sprintf(&buf[strlen(xpm)-4], "13.xpm"); fp = gmx_ffopen(buf, "w"); write_xpm(fp, flags, "SHAM Energy Landscape", "kJ/mol", "PC1", "PC3", ibox[0], ibox[2], axis_x, axis_z, WW, 0, gmax, rlo, rhi, &nlevels); gmx_ffclose(fp); for (i = 0; (i < ibox[1]); i++) { for (j = 0; (j < ibox[2]); j++) { WW[i][j] = W[index3(ibox, nxyz[XX], i, j)]; } } sprintf(&buf[strlen(xpm)-4], "23.xpm"); fp = gmx_ffopen(buf, "w"); write_xpm(fp, flags, "SHAM Energy Landscape", "kJ/mol", "PC2", "PC3", ibox[1], ibox[2], axis_y, axis_z, WW, 0, gmax, rlo, rhi, &nlevels); gmx_ffclose(fp); sfree(buf); } }
static void pick_minima(const char *logfile, int *ibox, int ndim, int len, real W[]) { FILE *fp; int i, j, k, nmin; t_minimum *mm, this_min; int *this_point; int loopmax, loopcounter; snew(mm, len); nmin = 0; fp = gmx_ffopen(logfile, "w"); /* Loop over each element in the array of dimenion ndim seeking * minima with respect to every dimension. Specialized loops for * speed with ndim == 2 and ndim == 3. */ switch (ndim) { case 0: /* This is probably impossible to reach anyway. */ break; case 2: for (i = 0; (i < ibox[0]); i++) { for (j = 0; (j < ibox[1]); j++) { /* Get the index of this point in the flat array */ this_min.index = index2(ibox, i, j); this_min.ener = W[this_min.index]; if (is_local_minimum_from_below(&this_min, i, 0, index2(ibox, i-1, j ), W) && is_local_minimum_from_above(&this_min, i, ibox[0]-1, index2(ibox, i+1, j ), W) && is_local_minimum_from_below(&this_min, j, 0, index2(ibox, i, j-1), W) && is_local_minimum_from_above(&this_min, j, ibox[1]-1, index2(ibox, i, j+1), W)) { add_minimum(fp, nmin, &this_min, mm); nmin++; } } } break; case 3: for (i = 0; (i < ibox[0]); i++) { for (j = 0; (j < ibox[1]); j++) { for (k = 0; (k < ibox[2]); k++) { /* Get the index of this point in the flat array */ this_min.index = index3(ibox, i, j, k); this_min.ener = W[this_min.index]; if (is_local_minimum_from_below(&this_min, i, 0, index3(ibox, i-1, j, k ), W) && is_local_minimum_from_above(&this_min, i, ibox[0]-1, index3(ibox, i+1, j, k ), W) && is_local_minimum_from_below(&this_min, j, 0, index3(ibox, i, j-1, k ), W) && is_local_minimum_from_above(&this_min, j, ibox[1]-1, index3(ibox, i, j+1, k ), W) && is_local_minimum_from_below(&this_min, k, 0, index3(ibox, i, j, k-1), W) && is_local_minimum_from_above(&this_min, k, ibox[2]-1, index3(ibox, i, j, k+1), W)) { add_minimum(fp, nmin, &this_min, mm); nmin++; } } } } break; default: /* Note this treats ndim == 1 and ndim > 3 */ /* Set up an ndim-dimensional vector to loop over the points * on the grid. (0,0,0, ... 0) is an acceptable place to * start. */ snew(this_point, ndim); /* Determine the number of points of the ndim-dimensional * grid. */ loopmax = ibox[0]; for (i = 1; i < ndim; i++) { loopmax *= ibox[i]; } loopcounter = 0; while (loopmax > loopcounter) { gmx_bool bMin = TRUE; /* Get the index of this_point in the flat array */ this_min.index = indexn(ndim, ibox, this_point); this_min.ener = W[this_min.index]; /* Is this_point a minimum from above and below in each * dimension? */ for (i = 0; bMin && (i < ndim); i++) { /* Save the index of this_point within the curent * dimension so we can change that index in the * this_point array for use with indexn(). */ int index = this_point[i]; this_point[i]--; bMin = bMin && is_local_minimum_from_below(&this_min, index, 0, indexn(ndim, ibox, this_point), W); this_point[i] += 2; bMin = bMin && is_local_minimum_from_above(&this_min, index, ibox[i]-1, indexn(ndim, ibox, this_point), W); this_point[i]--; } if (bMin) { add_minimum(fp, nmin, &this_min, mm); nmin++; } /* update global loop counter */ loopcounter++; /* Avoid underflow of this_point[i] */ if (loopmax > loopcounter) { /* update this_point non-recursively */ i = ndim-1; this_point[i]++; while (ibox[i] == this_point[i]) { this_point[i] = 0; i--; /* this_point[i] cannot underflow because * loopmax > loopcounter. */ this_point[i]++; } } } sfree(this_point); break; } qsort(mm, nmin, sizeof(mm[0]), comp_minima); fprintf(fp, "Minima sorted after energy\n"); for (i = 0; (i < nmin); i++) { print_minimum(fp, i, &mm[i]); } gmx_ffclose(fp); sfree(mm); }
bus_model* model_loader::load(const string& elements_filename, const string& vertices_filename, const string& tex_coords_filename, const string& bone_weights_filename, const string& bone_indices_filename, const string& matrices_filename) { stringstream elements_buffer, vertices_buffer, tc_buffer, bweights_buffer, bindices_buffer, bm_buffer; if(!f->file_to_buffer(elements_filename, elements_buffer)) { a2e_error("couldn't open elements file: %s!", elements_filename); return nullptr; } if(!f->file_to_buffer(vertices_filename, vertices_buffer)) { a2e_error("couldn't open vertices file: %s!", vertices_filename); return nullptr; } if(!f->file_to_buffer(tex_coords_filename, tc_buffer)) { a2e_error("couldn't open tex coords file: %s!", tex_coords_filename); return nullptr; } if(!f->file_to_buffer(bone_weights_filename, bweights_buffer)) { a2e_error("couldn't open bone weights file: %s!", bone_weights_filename); return nullptr; } if(!f->file_to_buffer(bone_indices_filename, bindices_buffer)) { a2e_error("couldn't open bone indices file: %s!", bone_indices_filename); return nullptr; } if(!f->file_to_buffer(matrices_filename, bm_buffer)) { a2e_error("couldn't open matrices file: %s!", matrices_filename); return nullptr; } stringstream normals_buffer; if(!f->file_to_buffer(e->data_path("NI-Nrms.txt"), normals_buffer)) { a2e_error("couldn't open normals file: %s!", "NI-Nrms.txt"); return nullptr; } // bus_model* bmodel = new bus_model(); static const float model_scale = 1.0f/10.0f; // read elements while(!elements_buffer.eof() && elements_buffer.good()) { unsigned int i1, i2, i3; elements_buffer >> i1; elements_buffer >> i2; elements_buffer >> i3; bmodel->indices.push_back(index3(i1, i2, i3)); } // read vertices while(!vertices_buffer.eof() && vertices_buffer.good()) { float x, y, z; vertices_buffer >> x; vertices_buffer >> y; vertices_buffer >> z; bmodel->vertices.push_back(float3(x, y, z)); } // read tex coords while(!tc_buffer.eof() && tc_buffer.good()) { float u, v; tc_buffer >> u; tc_buffer >> v; bmodel->tex_coords.push_back(coord(u, v)); } // read normals while(!normals_buffer.eof() && normals_buffer.good()) { float x, y, z; normals_buffer >> x; normals_buffer >> y; normals_buffer >> z; bmodel->normals.push_back(float3(x, y, z)); } // read bone weights while(!bweights_buffer.eof() && bweights_buffer.good()) { float wx, wy, wz, ww; bweights_buffer >> wx; bweights_buffer >> wy; bweights_buffer >> wz; bweights_buffer >> ww; bmodel->bone_weights.push_back(float4(wx, wy, wz, ww)); } // read bone indices while(!bindices_buffer.eof() && bindices_buffer.good()) { unsigned int ix, iy, iz, iw; bindices_buffer >> ix; bindices_buffer >> iy; bindices_buffer >> iz; bindices_buffer >> iw; bmodel->bone_indices.push_back(uint4(ix, iy, iz, iw)); } // read inverse matrices size_t m_index = 0; while(!bm_buffer.eof() && bm_buffer.good()) { if(m_index >= PLAYERS_BONE_COUNT) { a2e_error("too many matrices!"); return nullptr; } matrix4f m; for(size_t i = 0; i < 16; i++) { bm_buffer >> m.data[i]; } bmodel->matrices[m_index] = m; bmodel->matrices[m_index][3] *= model_scale; bmodel->matrices[m_index][7] *= model_scale; bmodel->matrices[m_index][11] *= model_scale; bmodel->joint_positions[m_index].set(-m.data[3], -m.data[7], -m.data[11], 1.0f); m_index++; } if(m_index != PLAYERS_BONE_COUNT) { a2e_error("too few matrices!"); return nullptr; } for(auto& vertex : bmodel->vertices) { vertex *= model_scale; } a2e_debug("model (%s, %s, %s) read: #indices: %u, #vertices: %u, #normals, %u, #tex coords: %u", elements_filename, vertices_filename, tex_coords_filename, bmodel->indices.size(), bmodel->vertices.size(), bmodel->normals.size(), bmodel->tex_coords.size()); return bmodel; }
std::vector< toppers::xml::container::object* > cfg1_out::xml_parser_init( std::string input_file ) { SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto; bool doNamespaces = true; bool doSchema = true; bool schemaFullChecking = false; bool identityConstraintChecking = true; bool namespacePrefixes = true; bool recognizeNEL = false; // Initialize the XML4C2 system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { std::vector<toppers::xml::container::object*> object_array; fatal( _("Error during initialization! Message:\n%" ), toNative(toCatch.getMessage())); return object_array; } // // Create a SAX parser object. Then, according to what we were told on // the command line, set it to validate or not. // SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces); parser->setFeature(XMLUni::fgXercesSchema, doSchema); parser->setFeature(XMLUni::fgXercesHandleMultipleImports, true); parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking); parser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, identityConstraintChecking); parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes); if (valScheme == SAX2XMLReader::Val_Auto) { parser->setFeature(XMLUni::fgSAX2CoreValidation, true); parser->setFeature(XMLUni::fgXercesDynamic, true); } if (valScheme == SAX2XMLReader::Val_Never) { parser->setFeature(XMLUni::fgSAX2CoreValidation, false); } if (valScheme == SAX2XMLReader::Val_Always) { parser->setFeature(XMLUni::fgSAX2CoreValidation, true); parser->setFeature(XMLUni::fgXercesDynamic, false); } /* External Schema file */ // XMLファイルのチェック namespace fs = boost::filesystem; if( !fs::exists( input_file ) ) { fatal( _("'%1%` is not exist."), input_file ); } /* 設定ファイルがある場合はパラメータ名のチェックを行う */ std::string paraname( get_global_string( "ini-file" ) ); std::string strAUTOSARVersion; std::string strSchema; std::string strSchemaLocation; std::string strContainerPath; std::string strModuleName; //std::cout << "AUTOSAR ini-file (ini file name):[" << paraname << "]" << std::endl; if( !paraname.empty() ) { strAUTOSARVersion = get_global_string( "XML_AUTOSARVersion" ); if( strAUTOSARVersion.empty() ) { strAUTOSARVersion = "4"; warning( _( " \"AUTOSARVersion\" parameter is not found in AUTOSAR ini-file. Use default value." ) ); } strSchema = get_global_string( "XML_Schema" ); if( strSchema.empty() ) { strSchema = "AUTOSAR_4-0-3_STRICT.xsd"; warning( _( " \"Schema\" parameter is not found in AUTOSAR ini-file. Use default value." ) ); } strSchemaLocation = get_global_string( "XML_SchemaLocation" ); if( strSchemaLocation.empty() ) { strSchemaLocation = "http://autosar.org/schema/r4.0"; warning( _( " \"SchemaLocation\" parameter is not found in AUTOSAR ini-file. Use default value." ) ); } strContainerPath = get_global_string( "XML_ContainerPath" ); if( strContainerPath.empty() ) { strContainerPath = "/AUTOSAR/EcucDefs"; warning( _( " \"ContainerPath\" parameter is not found in AUTOSAR ini-file. Use default value." ) ); } } toppers::global( "XML_AUTOSARVersion" ) = strAUTOSARVersion; toppers::global( "XML_Schema" ) = strSchema; toppers::global( "XML_SchemaLocation" ) = strSchemaLocation; toppers::global( "XML_ContainerPath" ) = strContainerPath; // XMLファイルの中にxsi:schemaLocation属性があればその要素を取得 std::string sstr( "xsi:schemaLocation" ); std::string buf; toppers::read( input_file, buf ); std::list<std::string> results; string::size_type index( buf.find( sstr ) ); if( index != string::npos ) { string::size_type index2( buf.substr( index ).find( "\"" ) ); string::size_type index3( buf.substr( index+index2+1 ).find( "\"" ) ); sstr = buf.substr( index+index2+1, index3 ); split( results, sstr, boost::is_space() ); } // スキーマファイルのチェック std::ostringstream ostream; if( results.size() == 2 && fs::exists( results.back() ) ) { ostream << sstr; } else { ostream << get_global_string( "XML_SchemaLocation" ) << " " << fs::absolute( get_global_string( "cfg-directory" ).c_str() ).string() << "/" << get_global_string( "XML_Schema" ); } XMLCh* str (XMLString::transcode (ostream.str().c_str())); parser->setProperty(XMLUni::fgXercesSchemaExternalSchemaLocation, str); // // Create our SAX handler object and install it on the parser, as the // document and error handler. // SAX2Handlers handler; parser->setContentHandler(&handler); parser->setErrorHandler(&handler); //reset error count first handler.resetErrors(); handler.filename = input_file; try { parser->parse(input_file.c_str()); } catch (const OutOfMemoryException&) { warning("OutOfMemoryException"); } catch (const XMLException& e) { warning( _("\nError during parsing: '%'\nException message is: \n%\n"), input_file, toNative(e.getMessage())); } catch (...) { warning( _("\nUnexpected exception during parsing: '%'\n"), input_file); } delete parser; XMLPlatformUtils::Terminate(); return handler.object_array; }
MojErr MojDbIndexTest::defaultValuesTest() { MojDbIndex index(NULL, NULL); MojRefCountedPtr<TestIndex> storageIndex(new TestIndex(false)); MojAllocCheck(storageIndex.get()); TestIndex& ti = *storageIndex; MojObject prop; MojErr err = prop.putString(MojDbIndex::NameKey, _T("foo")); MojTestErrCheck(err); err = prop.putInt(MojDbIndex::DefaultKey, 100); MojTestErrCheck(err); err = index.addProp(prop); MojTestErrCheck(err); MojDbReq req; err = index.open(storageIndex.get(), (MojInt64) 0, req); MojTestErrCheck(err); err = put(index, 1, _T("{\"bar\":1}"), NULL); MojTestErrCheck(err); MojTestAssert(ti.m_putCount == 1 && ti.m_delCount == 0 && ti.m_set.size() == 1); err = put(index, 1, _T("{\"foo\":5}"), NULL); MojTestErrCheck(err); MojTestAssert(ti.m_putCount == 2 && ti.m_delCount == 0 && ti.m_set.size() == 2); err = put(index, 1, _T("{\"foo\":{\"bar\":3}}"), NULL); MojTestErrCheck(err); MojTestAssert(ti.m_putCount == 3 && ti.m_delCount == 0 && ti.m_set.size() == 3); err = index.close(); MojTestErrCheck(err); MojDbIndex index2(NULL, NULL); MojRefCountedPtr<TestIndex> storageIndex2(new TestIndex(false)); MojAllocCheck(storageIndex2.get()); TestIndex& ti2 = *storageIndex2; MojObject prop2; err = prop2.putString(MojDbIndex::NameKey, _T("bar")); MojTestErrCheck(err); err = index2.addProp(prop2); MojTestErrCheck(err); err = index2.open(storageIndex2.get(), (MojInt64) 0, req); MojTestErrCheck(err); err = put(index2, 1, _T("{\"bar\":1}"), NULL); MojTestErrCheck(err); MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1); err = put(index2, 1, _T("{\"foo\":5}"), NULL); MojTestErrCheck(err); MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1); err = put(index2, 1, _T("{\"foo\":{\"bar\":3}}"), NULL); MojTestErrCheck(err); MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1); err = index2.close(); MojTestErrCheck(err); MojDbIndex index3(NULL, NULL); MojRefCountedPtr<TestIndex> storageIndex3(new TestIndex(false)); MojAllocCheck(storageIndex3.get()); TestIndex& ti3 = *storageIndex3; MojObject prop3; err = prop3.putString(MojDbIndex::NameKey, _T("bar")); MojTestErrCheck(err); err = index3.addProp(prop3); MojTestErrCheck(err); err = prop3.putString(MojDbIndex::NameKey, _T("foo")); MojTestErrCheck(err); err = prop3.putInt(MojDbIndex::DefaultKey, 100); MojTestErrCheck(err); err = index3.addProp(prop3); MojTestErrCheck(err); err = index3.open(storageIndex3.get(), (MojInt64) 0, req); MojTestErrCheck(err); err = put(index3, 1, _T("{\"bar\":1}"), NULL); MojTestErrCheck(err); MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1); err = put(index3, 1, _T("{\"foo\":5}"), NULL); MojTestErrCheck(err); MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1); err = put(index3, 1, _T("{\"foo\":{\"bar\":3}}"), NULL); MojTestErrCheck(err); MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1); err = put(index3, 1, _T("{\"foo\":5, \"bar\":5}"), NULL); MojTestErrCheck(err); MojTestAssert(ti3.m_putCount == 2 && ti3.m_delCount == 0 && ti3.m_set.size() == 2); err = index3.close(); MojTestErrCheck(err); return MojErrNone; }
/*function to run recursive loop to calculate final lPPAs for Occam's window approach without recording all models*/ void final_lPPA_recur(int nsamp, int nmod, int nmodcol, int incmods, int *totmods, int currsamp, int *r1, int m1, int *currmods, double curr_lPPA, int curr_hyp, int **models_num, int **hyp, double **lPPA_mat, int **multfact, int *uni, int *uni_ind, int string, double lpriornull, double lprioralt) { /*'nsamp' is the number of samples 'nmod' is the number of models 'nmodcol' is the number of samples plus model indicators (the number of columns of 'models_num') 'incmods' is INITIAL arbitrary number of models corresponding to the amount of memory made available for models_num 'totmods' is CURRENT arbitrary number of models corresponding to the amount of memory made available for models_num (may need to be extended during run or cut down at the end) 'currsamp' denotes the sample (i.e. column in 'lPDM_int_mat') that was changed at the previous level of the recursion 'r1' denotes current number of models in adjusted model set 'm1' is current model in model set that is being compared to 'currmods' is model structure at the previous level of the recursion 'curr_lPPA' is the log[P'(D|M)] for the current model at the previous level of the hierarchy 'curr_hyp' is the null/alt status of the model at the previous level of the hierarchy 'models_num' is matrix for storing model choices 'hyp' is a binary vector of length 'incmods', with 0=null and 1=alt 'lPPA_mat' is an output vector of log[P'(M|D)]s corresponding to the set of output models 'multfact' is a vector of multiplication factors 'uni' and 'uni_ind' are intermediate matrices for use in calculations 'string' is binary recording criteria type 'lprior*' represent the prior information for null and alternative models*/ int i,j,k,l,q,d,temp_hyp; double temp_lPPA; int *currmods1 = (int *) Calloc(nmodcol,int); for(i=0;i<nmodcol;i++) currmods1[i]=currmods[i]; //start loop for(i=currsamp;i<nsamp;i++) { j=currmods[i]; if(uni_ind[index2(j,i,nmod)]>0) { for(k=0;k<uni_ind[index2(j,i,nmod)];k++) { q=0; for(l=0;l<nsamp;l++) if(currmods[l+nsamp]==currmods[i+nsamp]) q++; if(q==1) { for(l=0;l<nmodcol;l++) currmods1[l]=currmods[l]; currmods1[i]=uni[index3(j,k,i,nmod,nmod)]; temp_lPPA=curr_lPPA; if(string==0) temp_hyp=calc_lessstring_single(nsamp,currmods1); else temp_hyp=calc_string_single(nsamp,currmods1); if(temp_hyp!=curr_hyp) { if(temp_hyp==1) temp_lPPA+=(lprioralt-lpriornull); else temp_lPPA+=(lpriornull-lprioralt); //update model set for(l=0;l<nmodcol;l++) (*models_num)[index2_col(*r1,l,nmodcol)]=currmods1[l]; (*lPPA_mat)[*r1]=temp_lPPA; (*hyp)[*r1]=temp_hyp; (*multfact)[*r1]=1; *r1=*r1+1; //increase size of output vectors if necessary if(*r1>(*totmods-1)) realloc_approx_new(nmodcol,totmods,incmods,models_num,hyp,lPPA_mat,multfact); //now enter further recursion if necessary if((i+1)<nsamp) { //just check next sample is independent q=i+1; d=2; while(q<nsamp&&d!=1) { d=0; for(l=0;l<nsamp;l++) if(currmods1[l+nsamp]==currmods1[q+nsamp]) d++; if(d==1) final_lPPA_recur(nsamp,nmod,nmodcol,incmods,totmods,q,r1,*r1,currmods1,temp_lPPA,temp_hyp,models_num,hyp,lPPA_mat,multfact,uni,uni_ind,string,lpriornull,lprioralt); q++; } } } else { (*multfact)[m1]++; //now enter further recursion if necessary if((i+1)<nsamp) { //just check next sample is independent q=i+1; d=2; while(q<nsamp&&d!=1) { d=0; for(l=0;l<nsamp;l++) if(currmods1[l+nsamp]==currmods1[q+nsamp]) d++; if(d==1) final_lPPA_recur(nsamp,nmod,nmodcol,incmods,totmods,q,r1,m1,currmods1,temp_lPPA,temp_hyp,models_num,hyp,lPPA_mat,multfact,uni,uni_ind,string,lpriornull,lprioralt); q++; } } } } } } } //free memory from the heap Free(currmods1); return; }
static void pick_minima(const char *logfile,int *ibox,int ndim,int len,real W[]) { FILE *fp; int i,j,k,ijk,nmin; gmx_bool bMin; t_minimum *mm; snew(mm,len); nmin = 0; fp = ffopen(logfile,"w"); for(i=0; (i<ibox[0]); i++) { for(j=0; (j<ibox[1]); j++) { if (ndim == 3) { for(k=0; (k<ibox[2]); k++) { ijk = index3(ibox,i,j,k); bMin = (((i == 0) || ((i > 0) && (W[ijk] < W[index3(ibox,i-1,j,k)]))) && ((i == ibox[0]-1) || ((i < ibox[0]-1) && (W[ijk] < W[index3(ibox,i+1,j,k)]))) && ((j == 0) || ((j > 0) && (W[ijk] < W[index3(ibox,i,j-1,k)]))) && ((j == ibox[1]-1) || ((j < ibox[1]-1) && (W[ijk] < W[index3(ibox,i,j+1,k)]))) && ((k == 0) || ((k > 0) && (W[ijk] < W[index3(ibox,i,j,k-1)]))) && ((k == ibox[2]-1) || ((k < ibox[2]-1) && (W[ijk] < W[index3(ibox,i,j,k+1)])))); if (bMin) { fprintf(fp,"Minimum %d at index %6d energy %10.3f\n", nmin,ijk,W[ijk]); mm[nmin].index = ijk; mm[nmin].ener = W[ijk]; nmin++; } } } else { ijk = index2(ibox,i,j); bMin = (((i == 0) || ((i > 0) && (W[ijk] < W[index2(ibox,i-1,j)]))) && ((i == ibox[0]-1) || ((i < ibox[0]-1) && (W[ijk] < W[index2(ibox,i+1,j)]))) && ((j == 0) || ((j > 0) && (W[ijk] < W[index2(ibox,i,j-1)]))) && ((j == ibox[1]-1) || ((j < ibox[1]-1) && (W[ijk] < W[index2(ibox,i,j+1)])))); if (bMin) { fprintf(fp,"Minimum %d at index %6d energy %10.3f\n", nmin,ijk,W[ijk]); mm[nmin].index = ijk; mm[nmin].ener = W[ijk]; nmin++; } } } } qsort(mm,nmin,sizeof(mm[0]),comp_minima); fprintf(fp,"Minima sorted after energy\n"); for(i=0; (i<nmin); i++) { fprintf(fp,"Minimum %d at index %6d energy %10.3f\n", i,mm[i].index,mm[i].ener); } ffclose(fp); sfree(mm); }