Пример #1
0
void max_rz_file_harmonics(FILE * fftfile, int num_harmonics,
                             int lobin,
                             double rin, double zin,
                             double *rout, double *zout, rderivs derivs[],
                             double maxpow[])
/* Return the Fourier frequency and Fourier f-dot that      */
/* maximizes the power of the candidate in 'fftfile'.       */
/* WARNING: not tested */
{
   int i;
   double maxz, rin_int, rin_frac;
   int kern_half_width, filedatalen, extra = 10;
   int* r_offset;
   fcomplex** filedata;

   r_offset = (int*)malloc(sizeof(int)*num_harmonics);
   filedata = (fcomplex**)malloc(sizeof(fcomplex*)*num_harmonics);
   maxz = fabs(zin*num_harmonics) + 4.0;
   kern_half_width = z_resp_halfwidth(maxz, HIGHACC);
   filedatalen = 2 * kern_half_width + extra;

   for (i=1;i<=num_harmonics;i++) {
       rin_frac = modf(rin*i, &rin_int);
       r_offset[i-1] = (int) rin_int - filedatalen / 2 + lobin;
       filedata[i-1] = read_fcomplex_file(fftfile, r_offset[i-1], filedatalen);
   }
   rin_frac = modf(rin, &rin_int);
   max_rz_arr_harmonics(filedata, num_harmonics,
                        r_offset,
                        filedatalen, rin_frac + filedatalen / 2,
                        zin, rout, zout, derivs,
                        maxpow);

   *rout += r_offset[0];
   for (i=1;i<=num_harmonics;i++) {
       vect_free(filedata[i-1]);
   }
   free(r_offset);
   free(filedata);
}
Пример #2
0
// FIXME: this shouldn't be a #define, or it shouldn't be here
void optimize_accelcand(accelcand * cand, accelobs * obs)
{
   int ii;
   int *r_offset;
   fcomplex **data;
   double r, z;

   cand->pows = gen_dvect(cand->numharm);
   cand->hirs = gen_dvect(cand->numharm);
   cand->hizs = gen_dvect(cand->numharm);
   r_offset = (int*) malloc(sizeof(int)*cand->numharm);
   data = (fcomplex**) malloc(sizeof(fcomplex*)*cand->numharm);
   cand->derivs = (rderivs *) malloc(sizeof(rderivs) * cand->numharm);

   if (obs->use_harmonic_polishing) {
       if (obs->mmap_file || obs->dat_input) {
           for(ii=0;ii<cand->numharm;ii++) {
               r_offset[ii]=obs->lobin;
               data[ii] = obs->fft;
           }
           max_rz_arr_harmonics(data,
                                cand->numharm,
                                r_offset,
                                obs->numbins,
                                cand->r-obs->lobin,
                                cand->z,
                                &r,
                                &z,
                                cand->derivs,
                                cand->pows);
       } else {
           max_rz_file_harmonics(obs->fftfile,
                                 cand->numharm,
                                 obs->lobin,
                                 cand->r-obs->lobin,
                                 cand->z,
                                 &r,
                                 &z,
                                 cand->derivs,
                                 cand->pows);
       }
       for(ii=0;ii<cand->numharm;ii++) {
           cand->hirs[ii]=(r+obs->lobin)*(ii+1);
           cand->hizs[ii]=z*(ii+1);
       }
   } else {
       for (ii = 0; ii < cand->numharm; ii++) {
          if (obs->mmap_file || obs->dat_input)
             cand->pows[ii] = max_rz_arr(obs->fft,
                                         obs->numbins,
                                         cand->r * (ii + 1) - obs->lobin,
                                         cand->z * (ii + 1),
                                         &(cand->hirs[ii]),
                                         &(cand->hizs[ii]), &(cand->derivs[ii]));
          else
             cand->pows[ii] = max_rz_file(obs->fftfile,
                                          cand->r * (ii + 1) - obs->lobin,
                                          cand->z * (ii + 1),
                                          &(cand->hirs[ii]),
                                          &(cand->hizs[ii]), &(cand->derivs[ii]));
          cand->hirs[ii] += obs->lobin;
       }
   }
   free(r_offset);
   free(data);

   cand->sigma = candidate_sigma(cand->power, cand->numharm,
                                 obs->numindep[twon_to_index(cand->numharm)]);
}