int find_Pentagon(GSList **Pentagons, Ring5 *working) { // Pentagons are found by matching 5 pairs of primes p0 & p2 GSList *target = *Pentagons; int i,found; while(target != NULL) { found = 1; for(i=0; i<5; i++) { if( (working->nodes[i]->primes[0] != RPTR(target)->nodes[i]->primes[0])|| (working->nodes[i]->primes[2] != RPTR(target)->nodes[i]->primes[2])) { found=0; break; } } if(found==1) return 1; target = target->next; } return 0; }
int searchCubeLinkedList(GSList **Rings, GSList **Cubes, int Target) { // Conduct pairwise search of Rings list // Conditions for match // links match and are unique // all sides are unique // on match - inc found save cube to Cubes list int found,match; int info_r0[8], info_r1[8]; // arrays of side and link values for each ring. int i,j,k; // working indexes GSList *r0, *r1; // internal list pointers // setup found = 0; for(r0 = *Rings; r0 != NULL; r0 = g_slist_next(r0)) { // r0 side values info_r0[0] = RPTR(r0)->node_ptr[0]->primes[0]; info_r0[1] = RPTR(r0)->node_ptr[1]->primes[0]; info_r0[2] = RPTR(r0)->node_ptr[2]->primes[0]; info_r0[3] = RPTR(r0)->node_ptr[3]->primes[0]; // r0 link values info_r0[4] = RPTR(r0)->node_ptr[0]->primes[2]; info_r0[5] = RPTR(r0)->node_ptr[1]->primes[2]; info_r0[6] = RPTR(r0)->node_ptr[2]->primes[2]; info_r0[7] = RPTR(r0)->node_ptr[3]->primes[2]; for(r1 = g_slist_next(r0); r1 != NULL; r1 = g_slist_next(r1)) { // r1 side values info_r1[0] = RPTR(r1)->node_ptr[0]->primes[0]; info_r1[1] = RPTR(r1)->node_ptr[1]->primes[0]; info_r1[2] = RPTR(r1)->node_ptr[2]->primes[0]; info_r1[3] = RPTR(r1)->node_ptr[3]->primes[0]; // r1 link values info_r1[4] = RPTR(r1)->node_ptr[0]->primes[2]; info_r1[5] = RPTR(r1)->node_ptr[1]->primes[2]; info_r1[6] = RPTR(r1)->node_ptr[2]->primes[2]; info_r1[7] = RPTR(r1)->node_ptr[3]->primes[2]; // test for matching links if( (info_r0[4] == info_r1[4])&& (info_r0[5] == info_r1[5])&& (info_r0[6] == info_r1[6])&& (info_r0[7] == info_r1[7]) ) { // now test for unique side values match = 0; for(i=0; i<4; i++) { if(match == 1) break; for(j=0; j<4; j++) if(info_r0[i] == info_r1[j]) { match = 1; break; } } // for i if(match == 0) { found++; // create and fill a struct cube // contains 2 ring pointers and target value struct cube *newcube = malloc(sizeof(struct cube)); newcube->ring_ptr[0] = (struct ring *)(r0->data); newcube->ring_ptr[1] = (struct ring *)(r1->data); // set the array of primes for future use newcube->Signature[0] = RPTR(r0)->node_ptr[0]->primes[0]; newcube->Signature[1] = RPTR(r0)->node_ptr[1]->primes[0]; newcube->Signature[2] = RPTR(r0)->node_ptr[2]->primes[0]; newcube->Signature[3] = RPTR(r0)->node_ptr[3]->primes[0]; newcube->Signature[4] = RPTR(r0)->node_ptr[0]->primes[2]; newcube->Signature[5] = RPTR(r0)->node_ptr[1]->primes[2]; newcube->Signature[6] = RPTR(r0)->node_ptr[2]->primes[2]; newcube->Signature[7] = RPTR(r0)->node_ptr[3]->primes[2]; newcube->Signature[8] = RPTR(r1)->node_ptr[0]->primes[1]; newcube->Signature[9] = RPTR(r1)->node_ptr[1]->primes[1]; newcube->Signature[10] = RPTR(r1)->node_ptr[2]->primes[1]; newcube->Signature[11] = RPTR(r1)->node_ptr[3]->primes[1]; // Save the target value at the end of the array newcube->Signature[12] = Target; // -------------analyis variables------------- // copy identity to symmetry and qsort in place. for(k=0; k<12; k++) newcube->symmetry_array[k] = newcube->Signature[k]; qsort(newcube->symmetry_array, 12, sizeof(int), compare_int); newcube->group_id = -1; // not allocated *Cubes = g_slist_append(*Cubes, newcube); // -------------------------------------- } // found } // if matching links } //for r1 } // for r0 return found; }
int generalizedBeamformer(double *relpow, double *abspow, const cplx * const steer, const cplx * const Rptr, const int nsamp, const int nstat, const int prewhiten, const int grdpts_x, const int grdpts_y, const int nfft, const int nf, double dpow, const methodE method) { /* method: 0 == "bf, 1 == "capon" * start the code ------------------------------------------------- * This assumes that all stations and components have the same number of * time samples, nt */ int x, y, i, j, n; const cplx cplx_zero = {0., 0.}; double *p_n; /* we allocate the taper buffer, size nsamp! */ p_n = (double *) calloc((size_t) (grdpts_x * grdpts_y), sizeof(double)); if (p_n == NULL ) { return 1; } if (method == CAPON) { /* optimized way of abspow normalization */ dpow = 1.0; } /* in general, beamforming is done by simply computing the covariances of * the signal at different receivers and than steer the matrix R with * "weights" which are the trial-DOAs e.g., Kirlin & Done, 1999: * BF: P(f) = e.H R(f) e * CAPON: P(f) = 1/(e.H R(f)^-1 e) */ for (n = 0; n < nf; ++n) { double inv_fac; double white = 0.; for (x = 0; x < grdpts_x; ++x) { for (y = 0; y < grdpts_y; ++y) { double pow; cplx eHR_ne = cplx_zero; for (i = 0; i < nstat; ++i) { cplx R_ne = cplx_zero; for (j = 0; j < nstat; ++j) { const cplx s = STEER(n,x,y,j); const cplx r = RPTR(n,i,j); R_ne.re += r.re * s.re - r.im * s.im; R_ne.im += r.re * s.im + r.im * s.re; } eHR_ne.re += STEER(n,x,y,i).re * R_ne.re + STEER(n,x,y,i).im * R_ne.im ; /* eH, conjugate */ eHR_ne.im += STEER(n,x,y,i).re * R_ne.im - STEER(n,x,y,i).im * R_ne.re; /* eH, conjugate */ } pow = sqrt(eHR_ne.re * eHR_ne.re + eHR_ne.im * eHR_ne.im); pow = (method == CAPON) ? 1. / pow : pow; white = fmax(pow, white); P_N(x,y)= pow; ABSPOW(x,y) += pow; } } /* scale for each frequency individually */ if (prewhiten == 1) { inv_fac = 1. / (white * nf * nstat); } else { inv_fac = 1. / dpow; } for (x = 0; x < grdpts_x; ++x) { for (y = 0; y < grdpts_y; ++y) { RELPOW(x,y) += P_N(x,y) * inv_fac; } } } free((void *) p_n); return 0; }