int main(int argc, char *argv[]) { Matrix *A = createMatrix(3, 2); A->data[0] = 1.2; A->data[1] = 2.3; A->data[2] = 3.4; A->data[3] = 4.5; A->data[4] = 5.6; A->data[5] = 6.7; printmat(A); Matrix *B = createMatrix(2, 3); B->data[0] = 5.5; B->data[1] = 6.6; B->data[2] = 7.7; B->data[3] = 1.2; B->data[4] = 2.1; B->data[5] = 3.3; printmat(B); Matrix *C = createMatrix(3, 3); matrixmult(A, B, C); printmat(C); destroyMatrix(A); destroyMatrix(B); destroyMatrix(C); return 0; }
int main() { mat4 A, B, C, I; vec4 a, c; I = mat4::identity(); a = vec4(10); test (a * I == a, "vec4 * mat4 (Identity matrix)"); test (I * a == a, "mat4 * vec4 (Identity matrix)"); a = vec4(1, 2, 3, 4); A = mat4(vec4(1, 2, 3, 4), vec4(0, 1, 0, 0), vec4(0, 0, 1, 0), vec4(0, 0, 0, 1)); c = vec4(1, 4, 6, 8); test (a * A == c, "vec4 * mat4"); c = vec4(30, 2, 3, 4); test (A * a == c, "mat4 * vec4"); B = mat4(vec4(1, 5, 7, 6), vec4(2, 4, 6, 7), vec4(3, 2, 8, 1), vec4(5, 7, 3, 4)); C = mat4(vec4(34, 47, 55, 39), vec4(2, 4, 6, 7), vec4(3, 2, 8, 1), vec4(5, 7, 3, 4)); test (A * B == C, "mat4 * mat4"); C = mat4(vec4(1, 7, 10, 10), vec4(2, 8, 12, 15), vec4(3, 8, 17, 13), vec4(5, 17, 18, 24)); test (B * A == C, "mat4 * mat4 (other order)"); C = mat4(vec4(1, 2, 3, 5), vec4(5, 4, 2, 7), vec4(7, 6, 8, 3), vec4(6, 7, 1, 4)); test (transpose(B) == C, "transpose"); a = vec4(0, 0, 1, 1); const vec3 temp = vec3(0, 0, 1); test (a * mat4::rotationmatrix(14, temp) == a, "rotation matrix parallel"); test (!(dot(mat4::rotationmatrix(90, vec3(0, 1, 0)) * a, vec4(1, 0, 0, 1)) < 1), "rotation matrix perpindicular"); test (vec3(mat4::rotationmatrix(45, vec3(1, 1, 0)) * a) == vec3(.5, -.5, sqrtf(.5)), "arbitrary rotation"); test (invert(I) == I, "invert identity"); A = mat4(vec4(1, 0, 0, 0), vec4(2, 1, 1, 0), vec4(0, 2, 1, 0), vec4(0, 3, 2, 1)); puts("# A"); printmat(A); C = mat4(vec4(1, 0, 0, 0), vec4(2, -1, 1, 0), vec4(-4, 2, -1, 0), vec4(2, -1, -1, 1)); puts("# Goal"); printmat(C); puts("# A^-1"); printmat(invert(A)); test (invert(A) == C, "invert"); test (A * invert(A) == I, "AA^-1 = I"); done(); return 0; }
void dbout1(double *x, double *y, double *P, double *H, double *R, int n, int m) { printf("x=[\n"); printmat(x,n,1); printf("];\n"); printf("y=[\n"); printmat(y,m,1); printf("];\n"); printf("P=[\n"); printmat(P,n,n); printf("];\n"); printf("H=[\n"); printmat(H,m,n); printf("];\n"); printf("R=[\n"); printmat(R,m,m); printf("];\n"); }
void dbout2(double *x, double *P, int n) { printf("xu=[\n"); printmat(x,n,1); printf("];\n"); printf("Pu=[\n"); printmat(P,n,n); printf("];\n"); printf("K=P*H'/(H*P*H'+R);\n"); printf("xd=x+K*y;\n"); printf("Pd=P-K*H*P\n"); printf("xu-xd,Pu-Pd\n"); }
/* Function: matrix_test Perform matrix manipulation. Parameters: N - Dimensions of the matrix. C - memory for result matrix. A - input matrix B - operator matrix (not changed during operations) Returns: A CRC value that captures all results calculated in the function. In particular, crc of the value calculated on the result matrix after each step by <matrix_sum>. Operation: 1 - Add a constant value to all elements of a matrix. 2 - Multiply a matrix by a constant. 3 - Multiply a matrix by a vector. 4 - Multiply a matrix by a matrix. 5 - Add a constant value to all elements of a matrix. After the last step, matrix A is back to original contents. */ ee_s16 matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val) { ee_u16 crc=0; MATDAT clipval=matrix_big(val); matrix_add_const(N,A,val); /* make sure data changes */ #if CORE_DEBUG printmat(A,N,"matrix_add_const"); #endif matrix_mul_const(N,C,A,val); crc=crc16(matrix_sum(N,C,clipval),crc); #if CORE_DEBUG printmatC(C,N,"matrix_mul_const"); #endif matrix_mul_vect(N,C,A,B); crc=crc16(matrix_sum(N,C,clipval),crc); #if CORE_DEBUG printmatC(C,N,"matrix_mul_vect"); #endif matrix_mul_matrix(N,C,A,B); crc=crc16(matrix_sum(N,C,clipval),crc); #if CORE_DEBUG printmatC(C,N,"matrix_mul_matrix"); #endif matrix_mul_matrix_bitextract(N,C,A,B); crc=crc16(matrix_sum(N,C,clipval),crc); #if CORE_DEBUG printmatC(C,N,"matrix_mul_matrix_bitextract"); #endif matrix_add_const(N,A,-val); /* return matrix to initial value */ return crc; }
double conchi(double *a, int m, int n) /* a is m rows n columns. contingency chisq */ { double *rsum, *csum, ee, tot=0, chsq=0, y ; int i,j,k ; ZALLOC(rsum,m,double) ; ZALLOC(csum,n,double) ; for (i=0; i<m; i++) { for (j=0; j<n; j++) { k = i*n+j ; rsum[i] += a[k] ; csum[j] += a[k] ; tot += a[k] ; } } if (tot < 0.001) fatalx("(conchi) no data\n") ; for (i=0; i<m; i++) { for (j=0; j<n; j++) { k = i*n+j ; ee = rsum[i]*csum[j]/tot ; if (ee < EPS2) { printf("bad conchi\n") ; printmat(a, m, n) ; fatalx("(conchi) zero row or column sum\n") ; } y = a[k]-ee ; chsq += (y*y)/ee ; } } free(rsum) ; free(csum) ; return chsq ; }
#include<stdio.h> #define max 50 #define e 0.00001/*e is the prescribed accuracy*/ main() { float a[max][max],x[max]; int n,i,j; int gauss_seidel(float [][max],float [],int); void printmat(float [][max],int); printf("Enter the order of the matrix(n x n) : "); scanf("%d",&n); if(n>0) { /*The user enters the augmented matrix*/ printf("\nEnter the augmented matrix row wise :-\n"); for(i=0;i<n;i++) { printf("\nEnter row %d :-\n",i+1); for(j=0;j<(n+1);j++) { printf("Enter element %d: ",j+1); scanf("%f",&a[i][j]); } } printf("\nThe augmented matrix entered is :-\n"); printmat(a,n); if(gauss_seidel(a,x,n))/*The gauss_seidel function return true value */ { printf("\nThe solutions of the given equations are->\n"); for(i=0;i<n;i++) printf("\ntx[%d]=%10.2f\n",i+1,x[i]); } } else printf("\nNo solution."); }
void DebugStiffnessKernel::get_dynamical_matrices(double qx, double qy, double_complex *U0, double_complex *U, double_complex *V, double_complex dU) { StiffnessKernel::get_dynamical_matrices(qx, qy, U0, U, V); printf("U0: \n"); printmat(dim_, U0); printf("\nU: \n"); printmat(dim_, U); printf("\nV: \n"); printmat(dim_, U); printf("\n"); }
int main(int argc, char *argv[]) { Matrix A = { {1.2, 2.3, 3.4, 4.5, 5.6, 6.7}, 3, 2}; Matrix B = { {5.5, 6.6, 7.7, 1.2, 2.1, 3.3}, 2, 3}; printmat(A); printmat(B); Matrix C = matrixmult(A, B); printmat(C); return 0; }
/* Function : matrix_init Initialize the memory block for matrix benchmarking. Parameters: blksize - Size of memory to be initialized. memblk - Pointer to memory block. seed - Actual values chosen depend on the seed parameter. p - pointers to <mat_params> containing initialized matrixes. Returns: Matrix dimensions. Note: The seed parameter MUST be supplied from a source that cannot be determined at compile time */ ee_u32 core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed, mat_params * p) { ee_u32 N = 0; MATDAT *A; MATDAT *B; ee_s32 order = 1; MATDAT val; ee_u32 i = 0, j = 0; if (seed == 0) seed = 1; while (j < blksize) { i++; j = i * i * 2 * 4; } N = i - 1; A = (MATDAT *) align_mem(memblk); B = A + N * N; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { seed = ((order * seed) % 65536); val = (seed + order); val = matrix_clip(val, 0); B[i * N + j] = val; val = (val + order); val = matrix_clip(val, 1); A[i * N + j] = val; order++; } } p->A = A; p->B = B; p->C = (MATRES *) align_mem(B + N * N); p->N = N; #if CORE_DEBUG printmat(A, N, "A"); printmat(B, N, "B"); #endif return N; }
BOOST_FIXTURE_TEST_CASE(test_bow, test::Peppers) { VocabularyPtr vocabulary(test::load<vis::Vocabulary>(VOCABULARY_FILE)); BowHog extractor(*vocabulary); arma::fvec descriptors = extractor.extract(image); float sum = arma::sum(descriptors); printmat(descriptors); printvar(sum); BOOST_CHECK_EQUAL(extractor.numWords(), descriptors.size()); BOOST_CHECK_CLOSE_FRACTION(sum, 1., 0.1); }
int main() { lapack_int m = 3, n = 4; lapack_int ret; double *A = new double[m * n]; double *U = new double[m * m]; double *VT = new double[n * n]; double *S = new double[std::min(m, n)]; double *superb = new double[std::min(m, n)]; //setting A matrix A[0 + 0 * m] = 1; A[0 + 1 * m] = 2; A[0 + 2 * m] = 3; A[0 + 3 * m] = 4; A[1 + 0 * m] = 5; A[1 + 1 * m] = 6; A[1 + 2 * m] = 7; A[1 + 3 * m] = 8; A[2 + 0 * m] = 9; A[2 + 1 * m] = 10; A[2 + 2 * m] = 11; A[2 + 3 * m] = 12; printf("A ="); printmat(m, n, A, m); printf("\n"); ret = LAPACKE_dgesvd(LAPACK_COL_MAJOR, 'A', 'A', m, n, A, m, S, U, m, VT, n, superb); //print out some results. printf("#singular values\n"); printf("S ="); printmat(std::min(m, n), 1, S, 1); printf("\n"); printf("#U matrix\n"); printf("U ="); printmat(m, m, U, m); printf("\n"); printf("#V^t matrix\n"); printf("Vt ="); printmat(n, n, VT, n); printf("\n"); printf("#You can check result by octave/matlab by\n"); printf("[u, s, v] = svd (A) \n"); printf("#u*s*v' should be equal to A\n"); printf("u*s*v' \n"); printf("U*diag(S,%d,%d)*Vt \n",m,n); delete[]superb; delete[]S; delete[]VT; delete[]U; delete[]A; }
void multmat(mat x,mat y,mat &z) { createmat(x); colnum(x); createmat(y); colnum(y); z.mu=x.mu;z.nu=y.nu;z.tu=0; int arow=0,brow=0,crow=0,ccol=0,tp=0,t=0,q=0,p=0; int h=0; int ctemp[500]={0}; if(x.tu*y.tu!=0) { for(arow=1;arow<=x.mu;++arow) { for(h=0;h<=22;h++)ctemp[h]=0;//当前行各元素累加器清零 z.rpos[arow]=z.tu+1; if(arow<x.mu)tp=x.rpos[arow+1]; else{tp=x.tu+1;} for(p=x.rpos[arow];p<tp;++p) { brow=x.data[p].j; if(brow<y.mu)t=y.rpos[brow+1]; else t=y.tu+1; for(q=y.rpos[brow];q<t;++q) { ccol=y.data[q].j; ctemp[ccol]+=x.data[p].e*y.data[q].e; }//for q }//求得z中第crow(=arow)行的非零元 for(ccol=1;ccol<=z.nu;++ccol) if(ctemp[ccol]) { if(++z.tu>maxsize)printf("抱歉,矩阵的乘积越界"); z.data[z.tu].i=arow; z.data[z.tu].j=ccol; z.data[z.tu].e=ctemp[ccol]; }//if }//for arow }//if printf("现在我们得到了结果(阵列形式):\n"); printmat(z); }
int randis(double *a, int n) { /* a should be prob dis summing to 1 */ int i ; double t, y ; static int nfirst=0 ; ++nfirst ; t = DRAND2() ; for (i=0; i<n; i++) { t -= a[i] ; if (t<=0.0) return i ; } if (nfirst==1) { printf("pos t: %15.9f\n",t) ; for (i=0; i<n ; i++) { printf("zzrand %4d %9.3f\n",i, a[i]) ; } } printf("probable bug (randis)\n") ; printmat(a, 1, n) ; return n-1 ; }
int main() { blasint n = 3; double alpha, beta; double *A = new double[n * n]; double *B = new double[n * n]; double *C = new double[n * n]; A[0 + 0 * n] = 1; A[0 + 1 * n] = 8; A[0 + 2 * n] = 3; A[1 + 0 * n] = 2; A[1 + 1 * n] = 10; A[1 + 2 * n] = 8; A[2 + 0 * n] = 9; A[2 + 1 * n] = -5; A[2 + 2 * n] = -1; B[0 + 0 * n] = 9; B[0 + 1 * n] = 8; B[0 + 2 * n] = 3; B[1 + 0 * n] = 3; B[1 + 1 * n] = 11; B[1 + 2 * n] = 2.3; B[2 + 0 * n] = -8; B[2 + 1 * n] = 6; B[2 + 2 * n] = 1; C[0 + 0 * n] = 3; C[0 + 1 * n] = 3; C[0 + 2 * n] = 1.2; C[1 + 0 * n] = 8; C[1 + 1 * n] = 4; C[1 + 2 * n] = 8; C[2 + 0 * n] = 6; C[2 + 1 * n] = 1; C[2 + 2 * n] = -2; printf("# dgemm demo...\n"); printf("A ="); printmat(n, n, A, n); printf("\n"); printf("B ="); printmat(n, n, B, n); printf("\n"); printf("C ="); printmat(n, n, C, n); printf("\n"); alpha = 3.0; beta = -2.0; cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, alpha, A, n, B, n, beta, C, n); printf("alpha = %5.3e\n", alpha); printf("beta = %5.3e\n", beta); printf("ans="); printmat(n, n, C, n); printf("\n"); printf("#check by Matlab/Octave by:\n"); printf("alpha * A * B + beta * C\n"); delete[]C; delete[]B; delete[]A; }
int mmcase0(int MFLOP, int CACHESIZE, char TA, char TB, int M, int N, int K, SCALAR alpha, int lda, int ldb, SCALAR beta, int ldc) { char *pc; #ifdef TREAL char *form="%4d %c %c %4d %4d %4d %5.1f %5.1f %6.2f %5.1f %5.2f %3s\n"; #define MALPH alpha #define MBETA beta TYPE betinv, bet=beta; #else #define MALPH *alpha, alpha[1] #define MBETA *beta, beta[1] char *form="%4d %c %c %4d %4d %4d %5.1f %5.1f %5.1f %5.1f %6.2f %6.1f %4.2f %3s\n"; TYPE betinv[2], *bet=beta; #endif int nreps, incA, incB, incC, inc, nmat, k; TYPE *c, *C, *a, *A, *b, *B, *st; int ii, jj, i, j=0, PASSED, nerrs; double t0, t1, t2, t3, mflop, mf, mops; TYPE maxval, f1, ferr; static TYPE feps=0.0; static int itst=1; enum ATLAS_TRANS TAc, TBc; void *vp; #ifdef TCPLX if (*beta == 0.0 && beta[1] == 0.0) betinv[0] = betinv[1] = 0.0; else if (beta[1] == 0.0) { betinv[0] = 1 / *beta; betinv[1] = 0.0; } else { t0 = *beta; t1 = beta[1]; if (Mabs(t1) <= Mabs(t0)) { t2 = t1 / t0; betinv[0] = t0 = 1.0 / (t0 + t1*t2); betinv[1] = -t0 * t2; } else { t2 = t0 / t1; betinv[1] = t0 = -1.0 / (t1 + t0*t2); betinv[0] = -t2 * t0; } } mops = ( ((8.0*M)*N)*K ) / 1000000.0; #else if (beta != 0.0) betinv = 1.0 / beta; else betinv = beta; mops = ( ((2.0*M)*N)*K ) / 1000000.0; #endif nreps = MFLOP / mops; if (nreps < 1) nreps = 1; if (TA == 'n' || TA == 'N') { TAc = AtlasNoTrans; incA = lda * K; } else { if (TA == 'c' || TA == 'C') TAc = AtlasConjTrans; else TAc = AtlasTrans; incA = lda * M; } if (TB == 'n' || TB == 'N') { incB = ldb * N; TBc = AtlasNoTrans; } else { incB = ldb * K; if (TB == 'c' || TB == 'C') TBc = AtlasConjTrans; else TBc = AtlasTrans; } incC = ldc*N; inc = incA + incB + incC; i = M*K + K*N + M*N; /* amount of inc actually referenced */ /* This is a hack; change to use of flushcache instead. */ nmat = ((CACHESIZE/ATL_sizeof) + i)/i; vp = malloc(ATL_MulBySize(nmat*inc)+ATL_Cachelen); ATL_assert(vp); C = c = ATL_AlignPtr(vp); a = A = C + incC; b = B = A + incA; st = C + nmat*inc; matgen(inc, nmat, C, inc, M*N); #ifdef DEBUG printmat("A0", M, K, A, lda); printmat("B0", K, N, B, ldb); printmat("C0", M, N, C, ldc); #endif t0 = time00(); for (k=nreps; k; k--) { trusted_gemm(TAc, TBc, M, N, K, alpha, a, lda, b, ldb, bet, c, ldc); c += inc; a += inc; b += inc; if (c == st) { c = C; a = A; b = B; if (bet == beta) bet = betinv; else bet = beta; } } t1 = time00() - t0; t1 /= nreps; if (t1 <= 0.0) mflop = t1 = 0.0; else /* flop rates actually 8MNK+12MN & 2MNK + 2MN, resp */ mflop = mops / t1; printf(form, itst, TA, TB, M, N, K, MALPH, MBETA, t1, mflop, 1.0, "---"); #ifdef DEBUG printmat("C", M, N, C, ldc); #endif matgen(inc, nmat, C, inc, M*N); t0 = time00(); for (k=nreps; k; k--) { test_gemm(TAc, TBc, M, N, K, alpha, a, lda, b, ldb, bet, c, ldc); c += inc; a += inc; b += inc; if (c == st) { c = C; a = A; b = B; if (bet == beta) bet = betinv; else bet = beta; } } t2 = time00() - t0; t2 /= nreps; if (t2 <= 0.0) t2 = mflop = 0.0; else mflop = mops / t2; pc = "---"; if (t1 == t2) t3 = 1.0; else if (t2 != 0.0) t3 = t1/t2; else t3 = 0.0; printf(form, itst++, TA, TB, M, N, K, MALPH, MBETA, t2, mflop, t3, pc); free(vp); return(1); }
int mmcase(int TEST, int CACHESIZE, char TA, char TB, int M, int N, int K, SCALAR alpha, TYPE *A, int lda, TYPE *B, int ldb, SCALAR beta, TYPE *C, int ldc, TYPE *D, int ldd) { char *pc; #ifdef TREAL char *form="%4d %c %c %4d %4d %4d %5.1f %5.1f %6.2f %5.1f %5.2f %3s\n"; #define MALPH alpha #define MBETA beta #else #define MALPH *alpha, alpha[1] #define MBETA *beta, beta[1] char *form="%4d %c %c %4d %4d %4d %5.1f %5.1f %5.1f %5.1f %6.2f %6.1f %4.2f %3s\n"; #endif int ii, jj, i, j=0, PASSED, nerrs; double t0, t1, t2, t3, mflop; TYPE maxval, f1, ferr; static TYPE feps=0.0; static int itst=1; /*int *L2, nL2=(1.3*L2SIZE)/sizeof(int);*/ enum ATLAS_TRANS TAc, TBc; double l2ret; if (!TEST) D = C; /*if (nL2) L2 = malloc(nL2*sizeof(int));*/ l2ret = ATL_flushcache( CACHESIZE ); if (TA == 'n' || TA == 'N') { matgen(M, K, A, lda, K*1112); TAc = AtlasNoTrans; } else { matgen(K, M, A, lda, K*1112); if (TA == 'c' || TA == 'C') TAc = AtlasConjTrans; else TAc = AtlasTrans; } if (TB == 'n' || TB == 'N') { matgen(K, N, B, ldb, N*2238); TBc = AtlasNoTrans; } else { matgen(N, K, B, ldb, N*2238); if (TB == 'c' || TB == 'C') TBc = AtlasConjTrans; else TBc = AtlasTrans; } matgen(M, N, C, ldc, M*N); #ifdef DEBUG printmat("A0", M, K, A, lda); printmat("B0", K, N, B, ldb); printmat("C0", M, N, C, ldc); #endif /* if (L2) { for (i=0; i != nL2; i++) L2[i] = 0.0; for (i=0; i != nL2; i++) j += L2[i]; }*/ /* invalidate L2 cache */ l2ret = ATL_flushcache( -1 ); t0 = time00(); trusted_gemm(TAc, TBc, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); t1 = time00() - t0; if (t1 <= 0.0) mflop = t1 = 0.0; else /* flop rates actually 8MNK+12MN & 2MNK + 2MN, resp */ #ifdef TCPLX mflop = ( ((8.0*M)*N)*K ) / (t1*1000000.0); #else mflop = ( ((2.0*M)*N)*K ) / (t1*1000000.0); #endif printf(form, itst, TA, TB, M, N, K, MALPH, MBETA, t1, mflop, 1.0, "---"); #ifdef DEBUG printmat("C", M, N, C, ldc); #endif #ifndef TIMEONLY matgen(M, N, D, ldd, M*N); /* invalidate L2 cache */ l2ret = ATL_flushcache( -1 ); t0 = time00(); test_gemm(TAc, TBc, M, N, K, alpha, A, lda, B, ldb, beta, D, ldd); t2 = time00() - t0; if (t2 <= 0.0) t2 = mflop = 0.0; else #ifdef TCPLX mflop = ( ((8.0*M)*N)*K ) / (t2*1000000.0); #else mflop = ( ((2.0*M)*N)*K ) / (t2*1000000.0); #endif #ifdef DEBUG printmat("D", M, N, D, ldd); #endif if (TEST) { if (feps == 0.0) { #if 0 f1 = feps = 0.5; do { feps = f1; f1 *= 0.5; maxval = 1.0 + f1; } while (maxval != 1.0); printf("feps=%e\n",feps); #else feps = EPS; #endif #ifdef DEBUG printf("feps=%e\n",feps); #endif } #ifdef TREAL ferr = 2.0 * (Mabs(alpha) * 2.0*K*feps + Mabs(beta) * feps) + feps; #else f1 = Mabs(*alpha) + Mabs(alpha[1]); maxval = Mabs(*beta) + Mabs(beta[1]); ferr = 2.0 * (f1*8.0*K*feps + maxval*feps) + feps; #endif PASSED = 1; maxval = 0.0; pc = "YES"; nerrs = ii = jj = 0; for (j=0; j != N; j++) { for (i=0; i != M SHIFT; i++) { f1 = D[i] - C[i]; if (f1 < 0.0) f1 = -f1; if (f1 > ferr) { nerrs++; PASSED = 0; pc = "NO!"; if (f1 > maxval) { maxval=f1; ii = i+1; jj = j+1; } } } D += ldd SHIFT; C += ldc SHIFT; } if (maxval != 0.0) fprintf(stderr, "ERROR: nerr=%d, i=%d, j=%d, maxval=%e\n", nerrs, ii,jj, maxval); } else pc = "---"; if (t1 == t2) t3 = 1.0; else if (t2 != 0.0) t3 = t1/t2; else t3 = 0.0; printf(form, itst++, TA, TB, M, N, K, MALPH, MBETA, t2, mflop, t3, pc); #else itst++; PASSED = 1; #endif /*free(L2);*/ l2ret = ATL_flushcache( 0 ); return(PASSED); }
spact() /* Computes cohomology group H^i(P,M) or H^i(Q,M) */ { int i,j,k,l,m,n,ie,ct,cl,fg,wi,wj,*p,*q,*r,*nrpf,*v1,*v2, **swop,homcl,c; char inp; inp= (ch1 && act) ? 0 : 1; /* inp as in calcfm in case ch1 */ if (ingp(inp) == -1) return(-1); if (ch1 && act) { inf3offset=ftell(ip); fclose(ip);} ct=ngens; j=exp; for (i=1;i<=dim;i++) { j++; wt[j]=swt[i]; d1[j]=(sd1[i]>0) ? sd1[i]+exp : 0; d2[j]=sd2[i]; } printf("Computing matrices.\n"); /* Matrices for all pcp gens of P or Q are now computed */ if (maxm<2*facexp) { fprintf(stderr,"Not enough mat space. Increase MSP (of MV or MM).\n"); return(-1); } for (i=facexp;i>=1;i--) if (wt[i]==1) { if (i>ct) { swop=mat[i]; mat[i]=mat[ct]; mat[ct]=swop; for (j=1;j<=dim;j++) if (d2[exp+j]==ct) d2[exp+j]=i; } inv(mat[i],mat[facexp+i]); ct--; } if (ct!=0) {fprintf(stderr,"No of pgens wrong.\n"); return(-1); } for (i=2;i<=facexp;i++) if (wt[i]>1) { p= (d1[i]==d2[i]) ? *powptr[d1[i]] : *(comptr[d1[i]]+d2[i]); q=p+ *p-2; *cp=0; while (--q>p) { k= *(q+1); for (j=1;j<=k;j++) cp[++(*cp)]= *q+facexp; q--; } if (d1[i]==d2[i]) for (j=1;j<=prime;j++) cp[++(*cp)]=d1[i]; else { cp[++(*cp)]=d1[i]+facexp; cp[++(*cp)]=d2[i]+facexp; cp[++(*cp)]=d1[i]; cp[++(*cp)]=d2[i]; } prod(cp,mat[i]); inv(mat[i],mat[i+facexp]); } if (act==0) { op=fopen(outf2,"w"); fprintf(op,"%3d%3d%3d\n",prime,dim,facexp); for (i=1;i<=facexp;i++) printmat(mat[i]); fclose(op); } printf("Computing full pcp.\n"); /* pcp of P or Q in dual action on module is computed from the matrices. */ v1=mat[facexp+1][1]; v2=mat[facexp+1][2]; for (i=1;i<=dim;i++) v1[i]=0; ie=exp; for (i=1;i<=dim;i++) { if (i>1) v1[i-1]=0; v1[i]=1; ie++; for (j=1;j<=facexp;j++) if (comm(v1,v2,mat[j])) { *(comptr[ie]+j)=rpf+1; nrpf=rpf+2; l=0; for (k=1;k<=dim;k++) if ((m=v2[k])!=0) { *(nrpf++)=k+exp; *(nrpf++)=m; l+=2; } *(rpf+1)=l; m= *(nrpf-2); if (d1[m]==ie && d2[m]==j) *rpf=m; else *rpf=0; rpf=nrpf; } } if (ch1==0) { printf("Computing P-homs.\n"); fflush(stdout); homcl=0; /* Hom-P(FM,M) will now be computed as dual of tensor product, using NQA */ if (matcl+1>=mcl) { fprintf(stderr,"Class too big. Increase MCL.\n"); return(-1); } for (cl=matcl+1;cl>1;cl--) { printf("cl=%d.\n",cl); for (fg=facexp+1;dpth[fg]==1 && fg<=exp;fg++) for (i=exp+1;i<=exp+dim;i++) if (wt[i]+1==cl) { if (intgen(i,fg)== -1) return(-1); if ((k=wt[i]+wt[fg])>homcl) { homcl=k; if (homcl+1>=mcl) { fprintf(stderr,"Class too big. Increase MCL.\n"); return(-1); } } } while (fg<=exp) { for (i=exp+1;i<=exp+dim;i++) if (wt[i]+dpth[fg]==cl) { if (dpth[d1[fg]]==dpth[fg]-1) { if (assoc(i,d1[fg],d2[fg])) if (subrel(i,fg)== -1) return(-1); } else if (intgen(i,fg)== -1) return(-1); if ((k=wt[i]+wt[fg])>homcl) { homcl=k; if (homcl+1>=mcl) { fprintf(stderr,"Class too big. Increase MCL.\n"); return(-1); } } } fg++; } for (i=1;i<=facexp;i++) { wi=wt[i]; for (j=facexp+1;j<=exp;j++) { wj=dpth[j]; if (wi+wj>=cl) break; for (k=exp+1;k<=exp+dim;k++) if (wi+wj+wt[k]==cl) if (assoc(k,j,i)) { if ((l=prnrel())==0) goto nextcl; if (l== -1) return(-1); } } } nextcl:; } bgc(); rsp=rpb-rel+1; printf("Computing extensions. nng,homcl=%d,%d\n",nng,homcl); fflush(stdout); stage=2; onng=nng; chpdim=0; chsdim=0; extno=pcptr+ptrsp-onng-1; for (i=1;i<=nng;i++) extno[i]=0; } else { stage=4; printf("Computing first cohomology group.\n"); homcl=matcl; if (homcl+1>=mcl) { fprintf(stderr,"Class too big. Increase MCL.\n"); return(-1); } } /* H^2 or H^1 will now be computed */ for (cl=homcl+1;cl>=2;cl--) { printf("cl=%d\n",cl); if (cl<=matcl+1) { for (i=1;i<=facexp;i++) if (wt[i]==1) for (j=exp+1;j<=exp+dim;j++) if (wt[j]+1==cl) if (intgen(j,i)== -1) return(-1); for (i=1;i<=facexp;i++) { wi=wt[i]; if (wi>1) for (j=exp+1;j<=exp+dim;j++) if (wi+wt[j]==cl) if (assoc(j,d1[i],d2[i])) if (subrel(j,i)== -1) return(-1); } } for (i=1;i<=facexp;i++) for (j=i;j<=facexp;j++) for (k=exp+1;k<=exp+dim;k++) if ((i==j && wt[i]+1+wt[k]==cl) || (i!=j && wt[i]+wt[j]+wt[k]==cl)) if (assoc(k,j,i)) if (ch1) { if ((l=prnrel())==0) goto ncl; if (l== -1) return(-1); } else { l=prnrel(); if (l== -1) return(-1); if (l>1) nchg(); } ncl:; } if (ch1) printf("Cohomology grp has dim %d\n",nng); /* We now no longer need the data for Q in the back of rel. */ rpb=rel+rspk-1; if (act) { if (ch1) onng=nng; else unlink(outf1); } else { if (stage>2) {onng=nng; strcpy(outf1,outf0);} outgp(); if (ch1) { ipcopy=fopen(outf1,"r"); opcopy=fopen(outcopy,"w"); while ((c=getc(ipcopy))!= -1) putc(c,opcopy); fclose(ipcopy); fclose(opcopy); } } return(0); }
int main(int argc, char *argv[]) { int i,j/*,k,test*/; int ndomain,total,add; int gottrans; int T_FLAG; /* char c; */ char *env; char *deffile,*keyword,*value; FILE *PARMS,*TRANS,*PDB; struct parameters *parms; struct domain_loc *domain; if(argc<2) exit_error(); /* get environment variable */ if((env=getenv("STAMPDIR"))==NULL) { fprintf(stderr,"error: environment variable STAMPDIR must be set\n"); exit(-1); } parms=(struct parameters*)malloc(sizeof(struct parameters)); strcpy(parms[0].stampdir,env); /* read in default parameters from $STAMPDIR/stamp.defaults */ deffile=(char*)malloc(1000*sizeof(char)); #if defined(_MSC_VER) sprintf(deffile,"%s\\stamp.defaults",env); #else sprintf(deffile,"%s/stamp.defaults",env); #endif if((PARMS=fopen(deffile,"r"))==NULL) { fprintf(stderr,"error: default parameter file %s does not exist\n",deffile); exit(-1); } if(getpars(PARMS,parms)==-1) exit(-1); fclose(PARMS); /* define DSSP directory file name */ sprintf(&parms[0].dsspfile[0],"%s/dssp.directories",env); /* now search the command line for commands */ keyword=(char*)malloc(1000*sizeof(char)); value=(char*)malloc(1000*sizeof(char)); for(i=1; i<argc; ++i) { if(argv[i][0]!='-') exit_error(); strcpy(keyword,&argv[i][1]); if(i+1<argc) strcpy(value,argv[i+1]); else strcpy(value,"none"); for(j=0; j<strlen(keyword); ++j) keyword[j]=ltou(keyword[j]); /* change to upper case */ T_FLAG=(value[0]=='Y' || value[0]=='y' || value[0]=='1' || value[0]=='T' || value[0]=='t' || value[0]=='o' || value[0]=='O'); /* enables one to write '1', 'YES', 'Yes', 'yes', 'T_FLAG', 'True' or 'true' to * set any boolean parmsiable to one */ if((strcmp(&argv[i][1],"l")==0) || (strcmp(&argv[i][1],"f")==0) || (strcmp(&argv[i][1],"p")==0)) { if(i+1>=argc) exit_error(); /* listfile name */ strcpy(parms[0].listfile,argv[i+1]); i++; } else if(strcmp(&argv[i][1],"P")==0) { /* want to read in parameter file */ if(i+1>=argc) exit_error(); if((PARMS=fopen(argv[i+1],"r"))==NULL) { fprintf(stderr,"error opening file %s\n",argv[i+1]); exit(-1); } if(getpars(PARMS,parms)==-1) exit(-1); fclose(PARMS); i++; } else if(strcmp(&argv[i][1],"o")==0) { /* output file */ if(i+1>=argc) exit_error(); strcpy(parms[0].logfile,argv[i+1]); i++; } else if(strcmp(&argv[i][1],"help")==0) { help_exit_error(); } else if((strcmp(&argv[i][1],"V")==0) || (strcmp(&argv[i][1],"v")==0)) { parms[0].verbose=1; strcpy(parms[0].logfile,"stdout"); } else if(strcmp(&argv[i][1],"s")==0) { parms[0].SCAN=1; parms[0].TREEWISE=parms[0].PAIRWISE=0; } else if(strcmp(&argv[i][1],"n")==0) { if(i+1>=argc) exit_error(); sscanf(argv[i+1],"%d",&parms[0].NPASS); i++; if(parms[0].NPASS!=1 && parms[0].NPASS!=2) exit_error(); } else if(strcmp(keyword,"PAIRPEN") == 0 || strcmp(keyword,"PEN")==0 || strcmp(keyword,"SECOND_PAIRPEN")==0) { sscanf(value,"%f",&parms[0].second_PAIRPEN); i++; } else if(strcmp(keyword,"FIRST_PAIRPEN")==0) { sscanf(value,"%f",&parms[0].first_PAIRPEN); i++; } else if(strcmp(keyword,"MAXPITER") == 0 || strcmp(keyword,"MAXSITER") == 0) { sscanf(value,"%d",&parms[0].MAXPITER); i++; } else if(strcmp(keyword,"MAXTITER") == 0) { sscanf(value,"%d",&parms[0].MAXTITER); i++; } else if(strcmp(keyword,"TREEPEN") == 0 || strcmp(keyword,"SECOND_TREEPEN")==0) { sscanf(value,"%f",&parms[0].second_TREEPEN); i++; } else if(strcmp(keyword,"FIRST_TREEPEN")==0) { sscanf(value,"%f",&parms[0].first_TREEPEN); i++; } else if(strcmp(keyword,"SCORETOL") == 0) { sscanf(value,"%f",&parms[0].SCORETOL); i++; } else if(strcmp(keyword,"CLUSTMETHOD") == 0) { sscanf(value,"%d",&parms[0].CLUSTMETHOD); i++; } else if(strcmp(keyword,"E1") == 0 || strcmp(keyword,"SECOND_E1")==0) { sscanf(value,"%f",&parms[0].second_E1); i++; } else if(strcmp(keyword,"E2") == 0 || strcmp(keyword,"SECOND_E2")==0) { sscanf(value,"%f",&parms[0].second_E2); i++; } else if(strcmp(keyword,"FIRST_E1")==0) { sscanf(value,"%f",&parms[0].first_E1); i++; } else if(strcmp(keyword,"FIRST_E2")==0) { sscanf(value,"%f",&parms[0].first_E2); i++; } else if(strcmp(keyword,"NPASS")==0) { sscanf(value,"%d",&parms[0].NPASS); i++; if(parms[0].NPASS!=1 && parms[0].NPASS!=2) { fprintf(stderr,"error: NPASS must be either 1 or 2\n"); return -1; } } else if(strcmp(keyword,"CUTOFF") == 0 || strcmp(keyword,"SECOND_CUTOFF")==0) { sscanf(value,"%f",&parms[0].second_CUTOFF); i++; } else if(strcmp(keyword,"FIRST_CUTOFF")==0) { sscanf(value,"%f",&parms[0].first_CUTOFF); i++; } else if(strcmp(keyword,"TREEPLOT") == 0) { parms[0].TREEPLOT=T_FLAG; i++; } else if(strcmp(keyword,"PAIRPLOT") == 0) { parms[0].PAIRPLOT=T_FLAG; i++; } else if(strcmp(keyword,"NALIGN") == 0) { sscanf(value,"%d",&parms[0].NALIGN); i++; } else if(strcmp(keyword,"DISPALL") == 0) { parms[0].DISPALL=T_FLAG; i++; } else if(strcmp(keyword,"HORIZ") ==0) { parms[0].HORIZ=T_FLAG; i++; } else if(strcmp(keyword,"ADD") ==0) { sscanf(value,"%f",&parms[0].ADD); i++; } else if(strcmp(keyword,"NMEAN") ==0) { sscanf(value,"%f",&parms[0].NMEAN); i++; } else if(strcmp(keyword,"NSD") ==0) { sscanf(value,"%f",&parms[0].NSD); i++; } else if(strcmp(keyword,"STATS") ==0) { parms[0].STATS=T_FLAG; i++; } else if(strcmp(keyword,"NA") == 0) { sscanf(value,"%f",&parms[0].NA); i++; } else if(strcmp(keyword,"NB") == 0) { sscanf(value,"%f",&parms[0].NB); i++; } else if(strcmp(keyword,"NASD") == 0) { sscanf(value,"%f",&parms[0].NASD); i++; } else if(strcmp(keyword,"NBSD") == 0) { sscanf(value,"%f",&parms[0].NBSD); i++; } else if(strcmp(keyword,"PAIRWISE") == 0) { parms[0].PAIRWISE=T_FLAG; i++; } else if(strcmp(keyword,"TREEWISE") == 0) { parms[0].TREEWISE=T_FLAG; i++; } else if(strcmp(keyword,"ORDFILE") == 0) { strcpy(parms[0].ordfile,value); i++; } else if(strcmp(keyword,"TREEFILE") == 0) { strcpy(parms[0].treefile,value); i++; } else if(strcmp(keyword,"PLOTFILE") == 0) { strcpy(parms[0].plotfile,value); i++; } else if(strcmp(keyword,"PREFIX") == 0 || strcmp(keyword,"TRANSPREFIX")==0 || strcmp(keyword,"STAMPPREFIX")==0) { strcpy(parms[0].transprefix,value); i++; } else if(strcmp(keyword,"MATFILE") == 0) { strcpy(parms[0].matfile,value); i++; } else if(strcmp(keyword,"THRESH") ==0) { sscanf(value,"%f",&parms[0].THRESH); i++; } else if(strcmp(keyword,"TREEALIGN")==0) { parms[0].TREEALIGN=T_FLAG; i++; } else if(strcmp(keyword,"TREEALLALIGN")==0) { parms[0].TREEALLALIGN=T_FLAG; i++; } else if(strcmp(keyword,"PAIRALIGN")==0 || strcmp(keyword,"SCANALIGN")==0) { parms[0].PAIRALIGN=T_FLAG; i++; } else if(strcmp(keyword,"PAIRALLALIGN")==0 || strcmp(keyword,"SCANALLALIGN")==0) { parms[0].PAIRALLALIGN=T_FLAG; i++; } else if(strcmp(keyword,"PRECISION")==0) { sscanf(value,"%d",&parms[0].PRECISION); i++; } else if(strcmp(keyword,"MAX_SEQ_LEN")==0) { sscanf(value,"%d",&parms[0].MAX_SEQ_LEN); i++; } else if(strcmp(keyword,"ROUGHFIT")==0) { parms[0].ROUGHFIT=T_FLAG; i++; } else if(strcmp(keyword,"ROUGH")==0) { parms[0].ROUGHFIT=1; } else if(strcmp(keyword,"ROUGHOUT")==0) { parms[0].roughout=1; } else if(strcmp(keyword,"ROUGHOUTFILE")==0) { if(i+1>=argc) exit_error(); strcpy(&parms[0].roughoutfile[0],argv[i+1]); i++; parms[0].roughout=1; } else if(strcmp(keyword,"BOOLCUT")==0 || strcmp(keyword,"SECOND_BOOLCUT")==0) { sscanf(value,"%f",&parms[0].second_BOOLCUT); i++; } else if(strcmp(keyword,"FIRST_BOOLCUT")==0) { sscanf(value,"%f",&parms[0].first_BOOLCUT); i++; } else if(strcmp(keyword,"SCANSLIDE")==0) { sscanf(value,"%d",&parms[0].SCANSLIDE); i++; } else if(strcmp(keyword,"SCAN")==0) { parms[0].SCAN=T_FLAG; i++; if(T_FLAG) parms[0].PAIRWISE=parms[0].TREEWISE=0; } else if(strcmp(keyword,"SCANMODE")==0) { sscanf(value,"%d",&parms[0].SCANMODE); i++; if(parms[0].SCANMODE==1) parms[0].PAIRALIGN=1; } else if(strcmp(keyword,"SCANCUT")==0) { sscanf(value,"%f",&parms[0].SCANCUT); i++; } else if(strcmp(keyword,"SECSCREEN")==0) { parms[0].SECSCREEN=T_FLAG; i++; } else if(strcmp(keyword,"SECSCREENMAX")==0) { sscanf(value,"%f",&parms[0].SECSCREENMAX); i++; } else if(strcmp(keyword,"SCANTRUNC")==0) { parms[0].SCANTRUNC=T_FLAG; i++; } else if(strcmp(keyword,"SCANTRUNCFACTOR")==0) { sscanf(value,"%f",&parms[0].SCANTRUNCFACTOR); i++; } else if(strcmp(keyword,"DATABASE")==0) { strcpy(&parms[0].database[0],value); i++; } else if(strcmp(keyword,"SCANFILE")==0) { strcpy(&parms[0].scanfile[0],value); i++; } else if(strcmp(keyword,"LOGFILE")==0) { strcpy(&parms[0].logfile[0],value); i++; } else if(strcmp(keyword,"SECTYPE")==0) { sscanf(value,"%d",&parms[0].SECTYPE); i++; } else if(strcmp(keyword,"SCANSEC")==0) { sscanf(value,"%d",&parms[0].SCANSEC); i++; } else if(strcmp(keyword,"SECFILE")==0) { strcpy(&parms[0].secfile[0],value); i++; parms[0].SECTYPE=2; } else if(strcmp(keyword,"BOOLEAN")==0) { parms[0].BOOLEAN=T_FLAG; i++; } else if(strcmp(keyword,"BOOLMETHOD")==0) { sscanf(value,"%d",&parms[0].BOOLMETHOD); i++; } else if(strcmp(keyword,"LISTFILE")==0) { strcpy(&parms[0].listfile[0],value); i++; } else if(strcmp(keyword,"STAMPDIR")==0) { strcpy(&parms[0].stampdir[0],value); i++; } else if(strcmp(keyword,"CLUST")==0) { parms[0].CLUST=T_FLAG; i++; } else if(strcmp(keyword,"COLUMNS")==0) { sscanf(value,"%d",&parms[0].COLUMNS); i++; } else if(strcmp(keyword,"SW")==0) { sscanf(value,"%d",&parms[0].SW); i++; } else if(strcmp(keyword,"CCFACTOR")==0) { sscanf(value,"%f",&parms[0].CCFACTOR); i++; } else if(strcmp(keyword,"CCADD")==0) { parms[0].CCADD=T_FLAG; i++; } else if(strcmp(keyword,"MINFIT")==0) { sscanf(value,"%d",&parms[0].MINFIT); i++; } else if(strcmp(keyword,"ROUGHALIGN")==0) { strcpy(parms[0].roughalign,value); i++; } else if(strcmp(keyword,"FIRST_THRESH")==0) { sscanf(value,"%f",&parms[0].first_THRESH); i++; } else if(strcmp(keyword,"MIN_FRAC")==0) { sscanf(value,"%f",&parms[0].MIN_FRAC); i++; } else if(strcmp(keyword,"SCORERISE")==0) { parms[0].SCORERISE=T_FLAG; i++; } else if(strcmp(keyword,"SKIPAHEAD")==0) { parms[0].SKIPAHEAD=T_FLAG; i++; } else if(strcmp(keyword,"SCANSCORE")==0) { sscanf(value,"%d",&parms[0].SCANSCORE); i++; } else if(strcmp(keyword,"PAIROUTPUT")==0) { parms[0].PAIROUTPUT=T_FLAG; i++; } else if(strcmp(keyword,"ALLPAIRS")==0) { parms[0].ALLPAIRS=T_FLAG; i++; } else if (strcmp(keyword,"ATOMTYPE")==0) { parms[0].ATOMTYPE=T_FLAG; i++; } else if(strcmp(keyword,"DSSP")==0) { parms[0].DSSP=T_FLAG; i++; } else if(strcmp(keyword,"SLOWSCAN")==0) { parms[0].SLOWSCAN=T_FLAG; i++; } else if(strcmp(keyword,"SLOW")==0) { parms[0].SLOWSCAN=1; } else if(strcmp(keyword,"CUT")==0) { parms[0].CO=1; } else if(strcmp(&argv[i][1],"slide")==0) { if(i+1>=argc) exit_error(); sscanf(argv[i+1],"%d",&parms[0].SCANSLIDE); i++; } else if(strcmp(&argv[i][1],"d")==0) { /* database file */ if(i+1>=argc) exit_error(); strcpy(&parms[0].database[0],argv[i+1]); i++; } else if(strcmp(&argv[i][1],"pen1")==0) { if(i+1>=argc) exit_error(); sscanf(argv[i+1],"%f",&parms[0].first_PAIRPEN); i++; } else if(strcmp(&argv[i][1],"pen2")==0) { if(i+1>=argc) exit_error(); sscanf(argv[i+1],"%f",&parms[0].second_PAIRPEN); i++; } else if(strcmp(&argv[i][1],"prefix")==0) { if(i+1>=argc) exit_error(); strcpy(&parms[0].transprefix[0],argv[i+1]); i++; } else if(strcmp(&argv[i][1],"scancut")==0) { if(i+1>=argc) exit_error(); sscanf(argv[i+1],"%f",&parms[0].SCANCUT); i++; } else if(strcmp(&argv[i][1],"opd")==0) { parms[0].opd=1; } else { exit_error(); } } free(keyword); free(value); /* make the names of all the output files using the prefix */ sprintf(&parms[0].ordfile[0],"%s.ord",parms[0].transprefix); sprintf(&parms[0].treefile[0],"%s.tree",parms[0].transprefix); sprintf(&parms[0].plotfile[0],"%s.plot",parms[0].transprefix); sprintf(&parms[0].matfile[0],"%s.mat",parms[0].transprefix); sprintf(&parms[0].roughalign[0],"%s_align.rough",parms[0].transprefix); sprintf(&parms[0].scanfile[0],"%s.scan",parms[0].transprefix); if(strcmp(parms[0].logfile,"stdout")==0 || strcmp(parms[0].logfile,"STDOUT")==0) { parms[0].LOG=stdout; } else if(strcmp(parms[0].logfile,"silent")==0 || strcmp(parms[0].logfile,"SILENT")==0) { #if defined(_MSC_VER) parms[0].LOG=stdout; #else parms[0].LOG=fopen("/dev/null","w"); #endif } else { if((parms[0].LOG=fopen(parms[0].logfile,"w"))==NULL) { fprintf(stderr,"error opening file %s\n",parms[0].logfile); exit(-1); } } if(strcmp(parms[0].logfile,"silent")==0) { printf("\nSTAMP Structural Alignment of Multiple Proteins\n"); printf(" by Robert B. Russell & Geoffrey J. Barton \n"); printf(" Please cite PROTEINS, v14, 309-323, 1992\n\n"); } fprintf(parms[0].LOG,"-------------------------------------------------------------------------------\n"); fprintf(parms[0].LOG," S t A M P\n"); fprintf(parms[0].LOG," Structural Alignment of\n"); fprintf(parms[0].LOG," Multiple Proteins\n"); fprintf(parms[0].LOG," By Robert B. Russell & Geoffrey J. Barton \n"); fprintf(parms[0].LOG," Last Modified: %s\n",lastmod); fprintf(parms[0].LOG," Please cite Ref: Russell and GJ Barton, PROTEINS, v14, 309-323, 1992\n"); fprintf(parms[0].LOG,"-------------------------------------------------------------------------------\n\n"); fprintf(parms[0].LOG,"STAMPDIR has been set to %s\n\n\n",parms[0].stampdir); /* read in coordinate locations and initial transformations */ if((TRANS = fopen(parms[0].listfile,"r")) == NULL) { fprintf(stderr,"error: file %s does not exist\n",parms[0].listfile); exit(-1); } /* determine the number of domains specified */ ndomain=count_domain(TRANS); domain=(struct domain_loc*)malloc(ndomain*sizeof(struct domain_loc)); rewind(TRANS); if(getdomain(TRANS,domain,&ndomain,ndomain,&gottrans,parms[0].stampdir,parms[0].DSSP,parms[0].LOG)==-1) exit(-1); fclose(TRANS); fprintf(parms[0].LOG,"Details of this run:\n"); if(parms[0].PAIRWISE) fprintf(parms[0].LOG,"PAIRWISE mode specified\n"); if(parms[0].TREEWISE) fprintf(parms[0].LOG,"TREEWISE mode specified\n"); if(parms[0].SCAN) fprintf(parms[0].LOG,"SCAN mode specified\n"); if(!parms[0].SCAN) { /* if no MINFIT has been given, then take the smallest length and divide it by two */ if(parms[0].MINFIT==-1) { parms[0].MINFIT=parms[0].MAXLEN; for(i=0; i<ndomain; ++i) if(domain[i].ncoords<parms[0].MINFIT) parms[0].MINFIT=domain[i].ncoords; parms[0].MINFIT/=2; } fprintf(parms[0].LOG," pairwise score file: %s\n",parms[0].matfile); if(parms[0].TREEWISE) { fprintf(parms[0].LOG," tree order file: %s\n",parms[0].ordfile); fprintf(parms[0].LOG," tree file: %s\n",parms[0].treefile); fprintf(parms[0].LOG," tree plot file: %s\n",parms[0].plotfile); } } else { fprintf(parms[0].LOG," SCANMODE set to %d\n",parms[0].SCANMODE); fprintf(parms[0].LOG," SCANSCORE set to %d\n",parms[0].SCANSCORE); fprintf(parms[0].LOG," (see documentation for an explanation)\n"); if(parms[0].opd==1) fprintf(parms[0].LOG," Domains will be skipped after the first match is found\n"); if(parms[0].SCANMODE==1) { fprintf(parms[0].LOG," Transformations for Sc values greater than %f are to be output\n",parms[0].SCANCUT); fprintf(parms[0].LOG," to the file %s\n",parms[0].transprefix); } else { fprintf(parms[0].LOG," Only the scores are to be output to the file %s\n",parms[0].scanfile); } fprintf(parms[0].LOG," secondary structures are "); switch(parms[0].SCANSEC) { case 0: fprintf(parms[0].LOG," not to be considered\n"); break; case 1: fprintf(parms[0].LOG," to be from DSSP\n"); break; case 2: fprintf(parms[0].LOG," to be read in from %s\n",parms[0].secfile); break; default: fprintf(parms[0].LOG," not to be considered\n"); } if(parms[0].SECSCREEN) { fprintf(parms[0].LOG," An initial screen on secondary structure content is to performed when possible\n"); fprintf(parms[0].LOG," Secondary structure summaries farther than %6.2f %% apart result in\n",parms[0].SECSCREENMAX); fprintf(parms[0].LOG," a comparison being ignored\n"); } fprintf(parms[0].LOG," Initial fits are to be performed by aligning the N-terminus of the query\n with every %d residue of the database sequence\n",parms[0].SCANSLIDE); fprintf(parms[0].LOG," of the query along the database structure.\n"); if(parms[0].SCANTRUNC) { fprintf(parms[0].LOG," If sequences in the database are > %5.3f x the query sequence length\n",parms[0].SCANTRUNCFACTOR); fprintf(parms[0].LOG," then a fraction of the the database structure, corresponding to this\n"); fprintf(parms[0].LOG," of length %5.3f x the query, will be considered\n",parms[0].SCANTRUNCFACTOR); fprintf(parms[0].LOG," comparisons are to be ignored if the database structure is less than\n %6.4f x the length of the query structure\n",parms[0].MIN_FRAC); } fprintf(parms[0].LOG," Domain database file to be scanned %s\n",parms[0].database); } if(parms[0].TREEWISE) fprintf(parms[0].LOG," output files prefix: %s\n",parms[0].transprefix); fprintf(parms[0].LOG,"\n\nParameters:\n"); fprintf(parms[0].LOG,"Rossmann and Argos parameters:\n"); if(parms[0].NPASS==2) { fprintf(parms[0].LOG," Two fits are to be performed, the first fit with:\n"); fprintf(parms[0].LOG," E1=%7.3f,",parms[0].first_E1); fprintf(parms[0].LOG," E2=%7.3f,",parms[0].first_E2); fprintf(parms[0].LOG," CUT=%7.3f,",parms[0].first_CUTOFF); fprintf(parms[0].LOG," PAIRPEN=%7.3f,",parms[0].first_PAIRPEN); fprintf(parms[0].LOG," TREEPEN=%7.3f\n",parms[0].first_TREEPEN); /* fprintf(parms[0].LOG," E1=%7.3f, E2=%7.3f, CUT=%7.3f, PAIRPEN=%7.3f, TREEPEN=%7.3f\n", parms[0].first_E1,parms[0].first_E2,parms[0].first_CUTOFF,parms[0].first_PAIRPEN,parms[0].first_TREEPEN); */ fprintf(parms[0].LOG," The second fit with:\n"); } else fprintf(parms[0].LOG," One fit is to performed with:\n"); fprintf(parms[0].LOG," E1=%7.3f, E2=%7.3f, CUT=%7.3f, PAIRPEN=%7.3f, TREEPEN=%7.3f\n", parms[0].second_E1,parms[0].second_E2,parms[0].second_CUTOFF,parms[0].second_PAIRPEN,parms[0].second_TREEPEN); if(parms[0].BOOLEAN) { fprintf(parms[0].LOG," BOOLEAN mode specified\n"); fprintf(parms[0].LOG," A boolean matrix will be calculated corresponding to whether\n"); fprintf(parms[0].LOG," positions have Pij values greater than:\n"); if(parms[0].NPASS==2) fprintf(parms[0].LOG," %7.3f, for the first fit and\n",parms[0].first_BOOLCUT); fprintf(parms[0].LOG," %7.3f",parms[0].second_BOOLCUT); if(parms[0].NPASS==2) fprintf(parms[0].LOG," for the second fit.\n"); else fprintf(parms[0].LOG,".\n"); fprintf(parms[0].LOG," In the multiple case, this criteria must be satisfied for *all*\n"); fprintf(parms[0].LOG," possible pairwise comparisons\n"); } if(parms[0].SW==1) { fprintf(parms[0].LOG," Corner cutting is to be performed\n"); fprintf(parms[0].LOG," Corner cutting length: %6.2f\n",parms[0].CCFACTOR); if(parms[0].CCADD) fprintf(parms[0].LOG," The length difference is to be added to this value\n"); } else { fprintf(parms[0].LOG," The entire SW matrix is to be calculated and used\n"); } fprintf(parms[0].LOG," The minimum length of alignment to be evaluated further is %3d residues\n",parms[0].MINFIT); fprintf(parms[0].LOG,"\n"); fprintf(parms[0].LOG," Convergence tolerance SCORETOL= %f %%\n", parms[0].SCORETOL); fprintf(parms[0].LOG," Other parameters:\n"); fprintf(parms[0].LOG," MAX_SEQ_LEN=%d, MAXPITER=%d, MAXTITER=%d\n", parms[0].MAX_SEQ_LEN,parms[0].MAXPITER,parms[0].MAXTITER); fprintf(parms[0].LOG," PAIRPLOT (SCANPLOT) = %d, TREEPLOT = %d, PAIRALIGN (SCANALIGN) = %d, TREEALIGN = %d\n", parms[0].PAIRPLOT,parms[0].TREEPLOT,parms[0].PAIRALIGN,parms[0].TREEALIGN); fprintf(parms[0].LOG," PAIRALLALIGN (SCANALLALIGN) = %d, TREEALLALIGN = %d\n",parms[0].PAIRALLALIGN,parms[0].TREEALLALIGN); if(!parms[0].BOOLEAN) { fprintf(parms[0].LOG,"\n\nDetails of Confidence value calculations:\n"); if(parms[0].STATS) fprintf(parms[0].LOG," actual mean and standard deviations are to be\n used for determination of Pij' values.\n"); else { fprintf(parms[0].LOG," pre-set mean and standard deviations are to be used\n and multiple comparisons are to be corrected.\n"); fprintf(parms[0].LOG," mean Xt = %f, standard deviation SDt = %f\n", parms[0].NMEAN,parms[0].NSD); fprintf(parms[0].LOG," for the multiple case:\n"); fprintf(parms[0].LOG," pairwise means are to be calculated from:\n Xp = exp(%6.4f * log(length) + %6.4f)\n",parms[0].NA,parms[0].NB); fprintf(parms[0].LOG," and pairwise standard deviations from:\n SDp = exp(%6.4f * log(length) + %6.4f)\n",parms[0].NASD,parms[0].NBSD); fprintf(parms[0].LOG," the mean to be used is calculated from: \n Xc = (Xm/Xp) * Xt).\n"); fprintf(parms[0].LOG," and the standard deviation from: \n SDc = (SDm/SDp)*SDt).\n"); } /* End of if(parms[0].STATS) */ } else { fprintf(parms[0].LOG," Positional values will consist of one's or zeros depending on whether\n"); fprintf(parms[0].LOG," a position satisfies the BOOLEAN criterion above\n"); fprintf(parms[0].LOG," The score (Sp) for each alignment will be a sum of these positions.\n"); } /* end of if(parms[0].BOOLEAN */ if(!parms[0].SCAN && parms[0].TREEWISE) { fprintf(parms[0].LOG,"\n\nTree is to be generated by "); if(parms[0].CLUSTMETHOD==0) fprintf(parms[0].LOG,"1/rms values.\n"); if(parms[0].CLUSTMETHOD==1) { fprintf(parms[0].LOG,"scores from path tracings modified as follows:\n"); fprintf(parms[0].LOG," Sc = (Sp/Lp) * ((Lp-ia)/La) * ((Lp-ib)/Lb),\n"); fprintf(parms[0].LOG," where Sp is the actual score, Lp is the path length.\n"); fprintf(parms[0].LOG," and La & Lb are the lengths of the structures considered.\n"); } /* End of if(parms[0].METHOD==2) */ } fprintf(parms[0].LOG,"\n\n"); fprintf(parms[0].LOG,"Reading coordinates...\n"); for(i=0; i<ndomain; ++i) { fprintf(parms[0].LOG,"Domain %3d %s %s\n ",i+1,domain[i].filename,domain[i].id); if((PDB=openfile(domain[i].filename,"r"))==NULL) { fprintf(stderr,"error opening file %s\n",domain[i].filename); exit(-1); } domain[i].ncoords=0; domain[i].coords=(int**)malloc(parms[0].MAX_SEQ_LEN*sizeof(int*)); domain[i].aa=(char*)malloc((parms[0].MAX_SEQ_LEN+1)*sizeof(char)); domain[i].numb=(struct brookn*)malloc((parms[0].MAX_SEQ_LEN)*sizeof(struct brookn)); total=0; fprintf(parms[0].LOG," "); for(j=0; j<domain[i].nobj; ++j) { if(!parms[0].DSSP) { if(igetca(PDB,&domain[i].coords[total],&domain[i].aa[total],&domain[i].numb[total], &add,domain[i].start[j],domain[i].end[j],domain[i].type[j],(parms[0].MAX_SEQ_LEN-total), domain[i].reverse[j],parms[0].PRECISION,parms[0].ATOMTYPE,parms[0].LOG)==-1) { fprintf(stderr,"Error in domain %s object %d \n",domain[i].id,j+1); exit(-1); } } else { if(igetcadssp(PDB,&domain[i].coords[total],&domain[i].aa[total],&domain[i].numb[total], &add,domain[i].start[j],domain[i].end[j],domain[i].type[j],(parms[0].MAX_SEQ_LEN-total), domain[i].reverse[j],parms[0].PRECISION,parms[0].LOG)==-1) exit(-1); } switch(domain[i].type[j]) { case 1: fprintf(parms[0].LOG," all residues"); break; case 2: fprintf(parms[0].LOG," chain %c",domain[i].start[j].cid); break; case 3: fprintf(parms[0].LOG," from %c %4d %c to %c %4d %c", domain[i].start[j].cid,domain[i].start[j].n,domain[i].start[j].in, domain[i].end[j].cid,domain[i].end[j].n,domain[i].end[j].in); break; } fprintf(parms[0].LOG,"%4d CAs ",add); total+=add; closefile(PDB,domain[i].filename); PDB=openfile(domain[i].filename,"r"); } domain[i].ncoords=total; fprintf(parms[0].LOG,"=> %4d CAs in total\n",domain[i].ncoords); fprintf(parms[0].LOG,"Applying the transformation... \n"); printmat(domain[i].R,domain[i].V,3,parms[0].LOG); fprintf(parms[0].LOG," ...to these coordinates.\n"); matmult(domain[i].R,domain[i].V,domain[i].coords,domain[i].ncoords,parms[0].PRECISION); closefile(PDB,domain[i].filename); } fprintf(parms[0].LOG,"\n\n"); fprintf(parms[0].LOG,"Secondary structure...\n"); for(i=0; i<ndomain; ++i) domain[i].sec=(char*)malloc(parms[0].MAX_SEQ_LEN*sizeof(char)); switch(parms[0].SECTYPE) { case 0: { fprintf(parms[0].LOG,"No secondary structure assignment will be considered\n"); for(i=0; i<ndomain; ++i) { for(j=0; j<domain[i].ncoords; ++j) domain[i].sec[j]='?'; domain[i].sec[j]='\0'; } parms[0].SECSCREEN=0; } break; case 1: { fprintf(parms[0].LOG,"Will try to find Kabsch and Sander DSSP assignments\n"); if(getks(domain,ndomain,parms)!=0) parms[0].SECSCREEN=0; } break; case 2: { fprintf(parms[0].LOG,"Reading in secondary structure assignments from file: %s\n",parms[0].secfile); if(getsec(domain,ndomain,parms)!=0) parms[0].SECSCREEN=0; } break; default: { fprintf(stderr,"error: unrecognised secondary structure assignment option\n"); exit(-1); } } fprintf(parms[0].LOG,"\n\n"); if(parms[0].SCAN) { i=0; fprintf(parms[0].LOG,"Scanning with domain %s\n",&(domain[i].id[0])); if(strcmp(parms[0].logfile,"silent")==0) { printf("Results of scan will be written to file %s\n",parms[0].scanfile); printf("Fits = no. of fits performed, Sc = STAMP score, RMS = RMS deviation\n"); printf("Align = alignment length, Nfit = residues fitted, Eq. = equivalent residues\n"); printf("Secs = no. equiv. secondary structures, %%I = seq. identity, %%S = sec. str. identity\n"); printf("P(m) = P value (p=1/10) calculated after Murzin (1993), JMB, 230, 689-694\n"); printf("\n"); printf(" Domain1 Domain2 Fits Sc RMS Len1 Len2 Align Fit Eq. Secs %%I %%S P(m)\n"); } if(parms[0].SLOWSCAN==1) { if(slow_scan(domain[i],parms)==-1) exit(-1); } else { if(scan(domain[i],parms)==-1) exit(-1); } if(strcmp(parms[0].logfile,"silent")==0) printf("See the file %s.scan\n",parms[0].transprefix); fprintf(parms[0].LOG,"\n"); } else { if(parms[0].ROUGHFIT) if(roughfit(domain,ndomain,parms)==-1) exit(-1); if(parms[0].PAIRWISE) if(pairwise(domain,ndomain,parms)==-1) exit(-1); if(parms[0].TREEWISE) if(treewise(domain,ndomain,parms)==-1) exit(-1); } /* end of if(parms[0].SCAN... */ /* freeing memory to keep purify happy */ /* for(i=0; i<ndomain; ++i) { free(domain[i].aa); free(domain[i].sec); free(domain[i].v); free(domain[i].V); for(j=0; j<3; ++j) { free(domain[i].R[j]); free(domain[i].r[j]); } free(domain[i].R); free(domain[i].r); for(j=0; j<domain[i].ncoords; ++j) free(domain[i].coords[j]); free(domain[i].coords); free(domain[i].type); free(domain[i].start); free(domain[i].end); free(domain[i].reverse); free(domain[i].numb); } */ free(domain); exit(0); }
int main() { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD cmd, scan, scf; scan.X = 20; scan.Y = 2; char com[100]; char* command; int fcmd = FOREGROUND_GREEN | FOREGROUND_INTENSITY, fst = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY, fer = FOREGROUND_RED | FOREGROUND_INTENSITY, fhelp = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY, fini = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE; int size = -1, status = 0, row = -1, col = -1; double newel, a, b, sum, colsum, dgsum, check1 = 1, check2 = 1, check3 = 1; SetConsoleCursorPosition(hConsole, scan); SetConsoleTextAttribute(hConsole, fst); printf ("enter size of matrix in a range [1 ... 13] "); while (size < 1 || size > 13){ scan.Y = 4; SetConsoleCursorPosition(hConsole, scan); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); SetConsoleCursorPosition(hConsole, scan); scanf("%i", &size); fflush(stdin); if (size >= 1 && size <= 13) break; scan.Y = 3; SetConsoleCursorPosition(hConsole, scan); SetConsoleTextAttribute(hConsole, fer); printf ("invalid input, try again or enter 0 to exit program "); if (size == 0) return 0; fflush(stdin); SetConsoleTextAttribute(hConsole, fst); } scf.X = 5; scf.Y = size + 9; cmd.X = 5; cmd.Y = size + 8; double arr[size][size]; double* p = &arr; double cop[size][size]; double* v = &cop;; drawinterface(size); settonull(p, size); printmat(p, size); while (status != 2){ SetConsoleTextAttribute(hConsole, fcmd); SetConsoleCursorPosition(hConsole, cmd); command = gets(com); SetConsoleCursorPosition(hConsole, scf); printf (" "); fflush(stdin); status = 0; if (strcmp(command, "end") == 0){ return 0; } if (strcmp(command, "clear") == 0){ drawinterface(size); settonull(p, size); printmat(p, size); } if (strcmp(command, "random") == 0){ copymat(p, v, size); do { SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); check1 = scanf("%lf", &a); fflush(stdin); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf(" "); scf.Y--; SetConsoleCursorPosition(hConsole, scf); printf(" "); if (a < 0 || a >= 10 || check1 == 0){ SetConsoleTextAttribute(hConsole, fer); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf("invalid range start input, try again"); scf.Y--; SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); } else status = 1; } while (status != 1); status = 0; do { SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); check2 = scanf("%lf", &b); fflush(stdin); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf(" "); scf.Y--; SetConsoleCursorPosition(hConsole, scf); printf(" "); if (b < 0 || b >= 10 || check2 == 0){ SetConsoleTextAttribute(hConsole, fer); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf("invalid range finish input, try again"); scf.Y--; SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); } else status = 1; } while (status != 1); status = 0; scf.X = 5; scf.Y = size + 9; status = 0; if (a > b) random(p, size, b, a); else random (p, size, a, b); drawinterface(size); printmatd(p, v, size); } if (strcmp(command, "change") == 0){ copymat(p, v, size); do { SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); check1 = scanf("%i", &row); fflush(stdin); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf(" "); scf.Y--; SetConsoleCursorPosition(hConsole, scf); printf(" "); if (row < 0 || row >= size || check1 == 0){ SetConsoleTextAttribute(hConsole, fer); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf("invalid row input, try again"); scf.Y--; SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); } else status = 1; } while (status != 1); status = 0; do { SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); check2 = scanf("%i", &col); fflush(stdin); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf(" "); scf.Y--; SetConsoleCursorPosition(hConsole, scf); printf(" "); if (col < 0 || col >= size || check2 == 0){ SetConsoleTextAttribute(hConsole, fer); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf("invalid col input, try again"); scf.Y--; SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); } else status = 1; } while (status != 1); status = 0; do { SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); check3 = scanf("%lf", &newel); fflush(stdin); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf(" "); scf.Y--; SetConsoleCursorPosition(hConsole, scf); printf(" "); if (newel < 0 || newel >= 10 || check3 == 0){ SetConsoleTextAttribute(hConsole, fer); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf("invalid new element input, try again, use only numbers in range [0 ... 10)"); scf.Y--; SetConsoleTextAttribute(hConsole, fst); SetConsoleCursorPosition(hConsole, scf); } else status = 1; } while (status != 1); status = 0; scf.X = 5; scf.Y = size + 9; change(p, size, row, col, newel); drawinterface(size); printmatd(p, v, size); row = -1; col = - 1; } if (strcmp(command, "display") == 0){ copymat(p, v, size); drawinterface(size); mirH(p, size); printmatd(p, v, size); } if (strcmp(command, "transpose") == 0){ copymat(p, v, size); drawinterface(size); transposeSide(p, size); printmatd(p, v, size); } if (strcmp(command, "rotate") == 0){ copymat(p, v, size); drawinterface(size); printbrotate(p, size); rotateCW90(p, size); printarotate(p, size); } if (strcmp(command, "sum") == 0){ scf.X = 27; scf.Y = size + 3; sum = summat(p, size); drawinterface(size); printmat(p, size); SetConsoleCursorPosition(hConsole, scf); SetConsoleTextAttribute(hConsole, fini); printf ("matrix sum = %lf", sum); sum = 0; scf.X = 5; scf.Y = size + 9; } if (strcmp(command, "colsum") == 0){ while (status != 1){ SetConsoleCursorPosition(hConsole, scf); SetConsoleTextAttribute(hConsole, fst); check1 = scanf("%i", &col); fflush(stdin); SetConsoleCursorPosition(hConsole, scf); printf (" "); scf.Y++; SetConsoleCursorPosition(hConsole, scf); printf(" "); scf.Y--; if (col < 0 || col >= size || check1 == 0){ scf.Y++; SetConsoleCursorPosition(hConsole, scf); SetConsoleTextAttribute(hConsole, fer); printf("invalid col input, try again"); scf.Y--; } else status = 1; } status = 0; scf.X = 27; scf.Y = size + 3; colsum = sumcol(p, size, col); drawinterface(size); printmatcol(p, size, col); SetConsoleCursorPosition(hConsole, scf); SetConsoleTextAttribute(hConsole, fini); printf ("colsum = %lf", colsum); colsum = 0; scf.X = 5; scf.Y = size + 9; } if (strcmp(command, "diagsum") == 0){ scf.X = 20; scf.Y = size + 3; dgsum = undsum(p, size); drawinterface(size); printmatdg(p, size); SetConsoleCursorPosition(hConsole, scf); SetConsoleTextAttribute(hConsole, fini); printf ("sum under main diagonal = %lf", dgsum); dgsum = 0; scf.X = 5; scf.Y = size + 9; } if (strcmp(command, "swingfirst") == 0){ copymat(p, v, size); swfminmax(p, size); drawinterface(size); printmatd(p, v, size); } if (strcmp(command, "swinglast") == 0){ copymat(p, v, size); swlminmax(p, size); drawinterface(size); printmatd(p, v, size); } if (strcmp(command, "swingcols") == 0){ copymat(p, v, size); swcol(p, size); drawinterface(size); printmatd(p, v, size); } if (strcmp(command, "help") == 0) { printmat(p, size); callhelp(size); SetConsoleCursorPosition(hConsole, cmd); printf(" "); } if (strcmp(command, "end") != 0 && strcmp(command, "change") != 0 && strcmp(command, "clear") != 0 && strcmp(command, "random") != 0 && strcmp(command, "display") != 0 && strcmp(command, "transpose") != 0 && strcmp(command, "rotate") != 0 && strcmp(command, "sum") != 0 && strcmp(command, "colsum") != 0 && strcmp(command, "diagsum") != 0 && strcmp(command, "swingfirst") != 0 && strcmp(command, "swinglast") != 0 && strcmp(command, "swingcols") != 0 && strcmp(command, "help") != 0){ SetConsoleCursorPosition(hConsole, cmd); SetConsoleTextAttribute(hConsole, fer); printf (" "); SetConsoleCursorPosition(hConsole, scf); printf ("error, no command such as this"); SetConsoleTextAttribute(hConsole, fcmd); printf(" -> "); SetConsoleTextAttribute(hConsole, fhelp); printf ("use help if you don`t know any commands"); } } }
int32_t main() { mat33 m, mr, mp; vec3 b; vec3 sol; mat22 m2, mr2, mp2; vec2 b2; vec2 sol2; triangle t; mesh * msh; m[0][0] = 1.0; m[0][1] = 2.0; m[0][2] = 3.0; m[1][0] = 1.0; m[1][1] = 5.0; m[1][2] = 6.0; m[2][0] = 2.0; m[2][1] = 3.0; m[2][2] = 1.0; b[0] = 10.0; b[1] = 5.0; b[2] = 15.0; printmat((double *)m, 3, 3); printvec(b, 3); if (solsyst3(m, b, sol) == 0) printf("determinant nul\n"); printvec(sol, 3); multmat3vec3(m, sol, b); printvec(b, 3); invmat3(m, mr); printmat((double *)mr, 3, 3); multmat3mat3(m, mr, mp); printmat((double *)mp, 3, 3); m2[0][0] = 1.0; m2[0][1] = 2.0; m2[1][0] = 1.0; m2[1][1] = 5.0; b2[0] = 10.0; b2[1] = 5.0; printmat((double *)m2, 2, 2); printvec(b2, 2); if (solsyst2(m2, b2, sol2) == 0) printf("determinant nul\n"); printvec(sol2, 2); multmat2vec2(m2, sol2, b2); printvec(b2, 2); invmat2(m2, mr2); printmat((double *)mr2, 2, 2); multmat2mat2(m2, mr2, mp2); printmat((double *)mp2, 2, 2); t.xa = 1.0; t.ya = 1.0; t.xb = 2.0; t.yb = 1.0; t.xc = 1.0; t.yc = 2.0; if (inittriangle(&t) == 0) printf("mauvais triangle\n"); printtriangle(&t); msh = readmesh("essai.msh"); printmesh(msh); freemesh(msh); }
void addmat(mat x,mat y,mat &z) { createmat(x); createmat(y); z.mu=x.mu;z.nu=x.nu;z.tu=0; int k,ce=0; int pa=1,pb=1,pc=1; for(k=1;k<=x.mu;k++) { while(x.data[pa].i<k)pa++; while(y.data[pb].i<k)pb++; while(x.data[pa].i==k&&y.data[pb].i==k)//行列值都相等的元素 { if(x.data[pa].j==y.data[pb].j) { ce=x.data[pa].e+y.data[pb].e; if(ce)//和不为0 { z.data[pc].i=k; z.data[pc].j=x.data[pa].j; z.data[pc].e=ce; pa++;pb++;pc++; } else { pa++; pb++; } }//if else if(x.data[pa].j>y.data[pb].j) { z.data[pc].i=k; z.data[pc].j=y.data[pb].j; z.data[pc].e=y.data[pb].e; pb++;pc++; } else { z.data[pc].i=k; z.data[pc].j=x.data[pa].j; z.data[pc].e=x.data[pa].e; pa++;pc++; } }//while while(x.data[pa].i==k)//插入x中剩余的元素(第k行) { z.data[pc].i=k; z.data[pc].j=x.data[pa].j; z.data[pc].e=x.data[pa].e; pa++;pc++; } while(y.data[pb].i==k)//插入y中剩余的元素(第k行) { z.data[pc].i=k; z.data[pc].j=y.data[pb].j; z.data[pc].e=y.data[pb].e; pb++;pc++; } }//for z.tu=pc; printf("现在我们得到了结果(阵列形式):\n"); printmat(z); }
void fill_phi_buffer(int ndof, int nx, int xlo_loc, int xhi_loc, int ny, int ylo_loc, int yhi_loc, StiffnessKernel *kernel, double_complex **phi_q, bool normalize, Error *error) { // printf("Called fill_phi_buffer\n"); // TAS kernel->pre_compute(); int nu = ndof/3; int idq = 0; for (int i = xlo_loc; i <= xhi_loc; i++) { double qx = (i <= int((nx)/2)) ? (2.0*M_PI*(i)/nx) : (2.0*M_PI*(i-nx)/nx); for (int j = ylo_loc; j <= yhi_loc; j++) { double qy = (j <= int((ny)/2)) ? (2.0*M_PI*(j)/ny) : (2.0*M_PI*(j-ny)/ny); // This is where our GFunctions^-1 are imported from // surface_stiffness. kernel->get_stiffness_matrix(nx, ny, qx, qy, phi_q[idq]); // Sanity check 1: Check if matrix is Hermitian. #if 1 // If compliance is ever infinite in a certain direction, this will // false positive. if (!_is_Hermitian(ndof, phi_q[idq], 1e-6)) { // tol for debugging char errstr[1024]; sprintf(errstr, "Kernel is not Hermitian at q = 2 pi " "(%f, %f)!\n", qx/(2.0*M_PI), qy/(2.0*M_PI)); printf("here is the un hermitian matrix:\n"); printmat(ndof,phi_q[idq]); printf(" nu %d ndof %d\n",nu, ndof); double_complex myout[144]; conj_transpose(ndof, myout, phi_q[idq]); printf("here is the cctrans: \n"); printmat(ndof, myout); for (int i=0; i<ndof*ndof; i++) myout[i] -= (phi_q[idq])[i]; printf("here is the difference which should be 0\n"); printmat(ndof, myout); error->all(FLERR,errstr); } #endif // Sanity check 2: Check if matrix is positive definite. // (FIXME!!! Requires LAPACK.) #if GFMD_CHECK_POSITIVE_DEFINITE char name[1024]; sprintf(name, "phi(%f,%f)", qx/(2.0*M_PI), qy/(2.0*M_PI)); warn_positive_definite(name, ndof, phi_q[idq], error); #endif idq++; } } if (normalize) { int nxy_loc = (xhi_loc-xlo_loc+1)*(yhi_loc-ylo_loc+1); int ndof_sq = ndof*ndof; // Divide phi_q by (nx*ny) to reduce float operation after FFT. double inv_nxny = 1.0/double(nx*ny); for (int idq = 0; idq < nxy_loc; idq++) { for (int idim = 0; idim < ndof_sq; idim++) { // Premptively divide for later conven. phi_q[idq][idim] *= inv_nxny; } } } kernel->post_compute(); }
int gammamatrices(doublecomplex *pgamma[], int nummat) { int i,j,k; int N=0,n, ntmp,d, matsize=0, check=0; doublecomplex *gens[3], **tmp, **tmp2, *tmp3, *test; tmp = (doublecomplex**) malloc(sizeof(doublecomplex*)*3); tmp2 = (doublecomplex**) malloc(sizeof(doublecomplex*)*3); for(j=0;j<3;j++) { tmp[j] = (doublecomplex*) malloc(sizeof(doublecomplex)*4); memset(tmp[j], 0, sizeof(doublecomplex)*4); tmp2[j] = (doublecomplex*) malloc(sizeof(doublecomplex)*4); memset(tmp2[j], 0, sizeof(doublecomplex)*4); gens[j] = (doublecomplex*) malloc(sizeof(doublecomplex)*4); memset(gens[j], 0, sizeof(doublecomplex)*4); } tmp3 = (doublecomplex*) malloc(sizeof(doublecomplex)*4); memset(tmp3, 0, sizeof(doublecomplex)*4); RepsSUn(gens, 2, 2, 3, 2.0); /* * if there are only 2 matrices gammamatrices correspond to first 2 pauli matrices, generated by RepsSUn; in this case only * next if-loop is executed */ if(nummat==2) { for(i=0;i<2;i++) { memcpy(pgamma[i], gens[i], sizeof(doublecomplex)*4); } return 0; } //define number of gamma matrices; 2*N+n - dimensional for(i=1;i<20;i++) { for(j=1;j<4;j++) { if((nummat/(2.*i+j)) == 1.0) { N=i; n=j; break; } } if(N!=0) break; } /* * generating \gamma-matrices step by step; at each iteration dimension is increased by one */ for(i=1;i<(N+1);i++) { matsize=pow(2,i+1); d=2*i+3; if(d<(2*N+n)) ntmp=2; else ntmp=n-1; for(j=0;j<(2*(i-1)+3);j++) { free(tmp2[j]); } tmp2 = (doublecomplex**) malloc(sizeof(doublecomplex*)*(2*i+(ntmp+1))); for(j=0;j<(2*i+ntmp+1);j++) { tmp2[j] = (doublecomplex*) malloc(sizeof(doublecomplex)*matsize*matsize); memset(tmp2[j], 0, sizeof(doublecomplex)*matsize*matsize); } //special case where i=1 -> for n=0 no cross product; for n!=0 empty tmp-matrices!! if(i==1) { if(!ntmp) { for(j=0;j<2;j++) memcpy(tmp[j], gens[j], sizeof(doublecomplex)*4); AddMat8(tmp[2], gens[2], -1.0, 2); break; } else { //cross product with d-ntmp gammas and sigma1 for(k=0;k<(2*i+1);k++) { Multilambda(tmp2[k], gens[k], gens[0], 2, 2); } //cross product with unity and sigma2 (and sigma 3 if ntmp=2) for(k=0;k<2;k++) { tmp3[k*(int)(pow(2,i))+k].r = 1.0; } for(j=(2*i+1);j<(2*i+1+ntmp);j++) { if(j==(d-2)) Multilambda(tmp2[j], tmp3, gens[1], 2, 2); if(j==(d-1)) Multilambda(tmp2[j], tmp3, gens[2], 2, 2); } } } else { //cross product with d-ntmp gammas and sigma1 for(k=0;k<(2*i+1);k++) { Multilambda(tmp2[k], tmp[k], gens[0], pow(2,i), 2); } //cross product with unity and sigma2 (and sigma 3 if ntmp=2) if(ntmp!=0) { tmp3 = realloc(tmp3, sizeof(doublecomplex)*pow(2,i)*pow(2,i)); memset(tmp3, 0, sizeof(doublecomplex)*pow(2,i)*pow(2,i)); for(k=0;k<(int)(pow(2,i));k++) { tmp3[k*(int)(pow(2,i))+k].r = 1.0; } for(j=(2*i+1);j<(2*i+1+ntmp);j++) { if(j==(d-2)) Multilambda(tmp2[j], tmp3, gens[1], pow(2,i), 2); if(j==(d-1)) Multilambda(tmp2[j], tmp3, gens[2], pow(2,i), 2); } } } //copy temporary result from matrices tmp2 -> tmp for(j=0;j<(2*(i-1)+3);j++) { free(tmp[j]); } tmp = (doublecomplex**) malloc(sizeof(doublecomplex*)*(2*i+(ntmp+1))); for(j=0;j<(2*i+ntmp+1);j++) { tmp[j] = (doublecomplex*) malloc(sizeof(doublecomplex)*matsize*matsize); memcpy(tmp[j], tmp2[j], sizeof(doublecomplex)*matsize*matsize); } } if(N==1 && n==1) matsize=pow(2,N); else matsize=pow(2,N+1); // test for correctness of generated \gamma-matrices test = (doublecomplex*) malloc(sizeof(doublecomplex)*matsize*matsize); for(i=0;i<nummat;i++) { for(j=i;j<nummat;j++) { memset(test, 0, sizeof(doublecomplex)*matsize*matsize); AntiComm(test, tmp[i], tmp[j], matsize, 1.0); if(i!=j) { check = ScanMatrixZero(test, matsize); if(check!=0) { printf("------------- GammaMatrices computation -------------------------------\n"); printf("Error in Computation! Element of test[%d*nummat+%d] is not zero!\n", i,j); printmat("AntiComm:", test, matsize); } } else { check = ScanMatrixDiag(test, matsize); if(check!=0) { printf("------------- GammaMatrices computation -------------------------------\n"); printf("Error in Computation! Element of test[%d*nummat+%d]) is not zero / 2!\n", i,j); printmat("AntiComm:", test, matsize); } } } } //copy result to external matrices for(i=0;i<nummat;i++) { memcpy(pgamma[i], tmp[i], sizeof(doublecomplex)*matsize*matsize); } free(test); free(tmp3); for(i=0;i<nummat;i++) { free(tmp[i]); free(tmp2[i]); } for(i=0;i<3;i++) { free(gens[i]); } return 0; }