예제 #1
0
void merge(long n, T left[n], T right[n], T result[n*2], long start, long length)
{
	if (length < MIN_MERGE_SIZE*2L) {
		// Base case (sequential)
		seq_merge(n, left, right, result, start, length);
	} else {
		// Recursive case (decomposition)
		#pragma omp task 
		merge(n, left, right, result, start, length/2);

		#pragma omp task 
		merge(n, left, right, result, start + length/2, length/2);

	}
}
struct coord* coord_merge ( struct coord *c1, struct coord *c2) {

    struct coord *nc, *cc;
    struct seq *nseq;
    size_t i;
    if (c1==NULL) 
        err_printf("coord_merge","c1 is undefined!\n");
    if (c2==NULL)
        err_printf("coord_merge","c2 is undefined!\n");
    
    nseq=seq_merge(c1->seq, c2->seq);
    if (!nseq) {
        err_printf("coord_merge","couldn't merge sequences\n");
        return(NULL);
    }

    nc=coord_template(c1, c1->size+c2->size);
    nc->seq = nseq;
    if (!nc) {
        err_printf("coord_merge","Couldn't make new coord object\n");
        return(NULL);
    }
    if (c1->units!=c2->units) {
        cc = coord_template(c2, c2->size);
        if (c1->units==nm) {
            coord_a_2_nm(cc);
        } else {
            if (c1->units==angstrom) {
                coord_nm_2_a(cc);
            }
        }
    } else {
        cc = c2;
    }
    /* merge c1 and cc 
       nc takes on all characteristics (chainid, etc)
    */
    nc->units=c1->units;
    for (i = 0; i < ACQ_SIZ; i++)
        nc->pdb_acq[i] = c1->pdb_acq[i];
    nc->chain=c1->chain; 
    /* and all coordinates present in both structures */
    
    if ((c1->sec_typ) && (c2->sec_typ)) {
        memcpy (nc->sec_typ, c1->sec_typ, c1->size * sizeof (*nc->sec_typ));
        memcpy (nc->sec_typ+c1->size, c2->sec_typ, c2->size * sizeof (*nc->sec_typ));
    }
    if (c1->rp_ca && c2->rp_ca) {
        memcpy (nc->rp_ca, c1->rp_ca, c1->size * sizeof (*nc->rp_ca));
        memcpy (nc->rp_ca+c1->size, c2->rp_ca, c2->size * sizeof (*nc->rp_ca));
    }
    if (c1->rp_cb && c2->rp_cb) {
        memcpy (nc->rp_cb, c1->rp_cb, c1->size * sizeof (*c1->rp_cb));
        memcpy (nc->rp_cb+c1->size, c2->rp_cb, c2->size * sizeof (*c2->rp_cb));
    }
    if (c1->rp_n && c2->rp_n) {
        memcpy (nc->rp_n, c1->rp_n, c1->size * sizeof (*c1->rp_n));
        memcpy (nc->rp_n+c1->size, c2->rp_n, c2->size * sizeof (*nc->rp_n));
    }
    if (c1->rp_c && c2->rp_c) {
        memcpy (nc->rp_c, c1->rp_c, c1->size * sizeof (*c1->rp_c));
        memcpy (nc->rp_c+c1->size, c2->rp_c, c2->size * sizeof (*nc->rp_c));
    }

    if (c1->rp_o && c2->rp_o) {
        memcpy (nc->rp_o, c1->rp_o, c1->size * sizeof (*nc->rp_o));
        memcpy (nc->rp_o+c1->size, c2->rp_o, c2->size*sizeof(*nc->rp_o));
    }
    if (c1->orig && c2->orig) {
        short ofset, *ncp,*nce;
        /* pain in the neck, here */
        memcpy (nc->orig, c1->orig, c1->size * sizeof (*c1->orig));
        memcpy(nc->orig+c1->size, c2->orig, c2->size*sizeof(*nc->orig));
        /* We really don't want to do this every time... 
        ofset = nc->orig[c1->size-1];
        ncp=nc->orig+c1->size;
        nce=nc->orig+nc->size;
        do {
            *ncp+=ofset;
        } while (++ncp<nce);
        */
    }
    if (c1->icode && c2->icode) {
        memcpy (nc->icode, c1->icode, c1->size * sizeof(*c1->icode));
        memcpy (nc->icode+c1->size, c2->icode, c2->size * sizeof(*c2->icode));
    }
    if (c1->psi && c2->psi) {
        nc->psi = E_MALLOC (nc->size * sizeof (*c1->psi));
        memcpy (nc->psi, c1->psi, c1->size * sizeof (*c1->psi));
        memcpy (nc->psi+c1->size, c2->psi, c2->size * sizeof (*c2->psi));
    }
        
    if (c2->units!=cc->units)
        coord_destroy(cc);
    return(nc);
}