Esempio n. 1
0
/* Solve a log(1-P(a,x))=y for x given the value of a and
 * allowed fractional error in y of frac_err
 */
float invert_lcgf(float y,float a, float frac_err) {
  int j;
  float df,dx,dxold,f,fh,fl;
  float temp,xh,xl,rts;

  xh=(a+1.5f);
  xl=(float)(a-2.0*y*sqrt(a));
  fl=lcgf(a,xl)-y;
  fh=lcgf(a,xh)-y;

  BOINCASSERT(fl<=0);
  BOINCASSERT(fh>=0);

  rts=0.5f*(xh+xl);
  dxold=(float)fabs(xh-xl);
  dx=dxold;
  f=lcgf(a,rts)-y;
  df=dlcgf(a,rts);
  for (j=1;j<=ITMAX;j++) {
    if ((((rts-xh)*df-f)*((rts-xl)*df-f) >= 0.0)
        || (fabs(2.0*f)>fabs(dxold*df))) {
      dxold=dx;
      dx=0.5f*(xh-xl);
      rts=xl+dx;
      if ((xl==rts) || (xh==rts)) return rts;
    } else {
      dxold=dx;
      dx=f/df;
      temp=rts;
      rts-=dx;
      if (temp==rts) return rts;
    }
    f=lcgf(a,rts)-y;
    df=dlcgf(a,rts);
    if (fabs(f)<fabs(frac_err*y)) return rts;
    if (f<0.0)
      xl=rts;
    else
      xh=rts;
  }
  BOINCASSERT(ITMAX);
  return 0.0;
}
Esempio n. 2
0
float lcgf(float a, float x, long& timecalled, long& numcalls) {
 numcalls++; 
 static double mytime=0;
 long begintime = clock(); 
 float rv=lcgf(a,x);
 long endtime = clock();
 mytime+=(double)(endtime-begintime)/CLOCKS_PER_SEC;
 if (endtime < begintime) {
   mytime+=UINT_MAX;
 }
 timecalled=(long)mytime;
 return rv;
}
int make_wu_headers(std::vector<dr2_compact_block_t> &tapebuffer, telescope_id
tel, std::vector<workunit> &wuheader) {
  int procid=getpid();
  double receiver_freq;
  int bandno;
  FILE *tmpfile;
  char tmpstr[256];
  char buf[64];
  static const receiver_config &r(rcvr);
  static const settings &s(splitter_settings);
  bool group_is_vlar;

  if (!strncmp(s.splitter_cfg->data_type,"encoded",
     std::min(static_cast<size_t>(7),sizeof(s.splitter_cfg->data_type)))) {
    noencode=0;
  } else {
      noencode=1;
  }

  tapebuffer[0].header.samplerate*=1e+6;
  seconds sample_time(1.0/tapebuffer[0].header.samplerate);
  seti_time start_time(tapebuffer[0].header.data_time
           -tapebuffer[0].data.size()*0.5*sample_time);
  seti_time end_time(tapebuffer[tapebuffer.size()-1].header.data_time);


  workunit_grp wugrp;
  sprintf(wugrp.name,"%s.%ld.%d.%d.%d",
    tapebuffer[0].header.name,
    procid, 
    tapebuffer[0].header.dataseq,
    tel-AO_430,
    s.id);
  wugrp.receiver_cfg=r; 
  wugrp.recorder_cfg=s.recorder_cfg; 
  wugrp.splitter_cfg=s.splitter_cfg; 
  wugrp.analysis_cfg=s.analysis_cfg; 

  wugrp.data_desc.nsamples=NSAMPLES;
  wugrp.data_desc.true_angle_range=0;
  coordinate_t start_coord(cmap_interp(coord_history,start_time));
  coordinate_t end_coord(cmap_interp(coord_history,end_time));
  wugrp.data_desc.start_ra=start_coord.ra;
  wugrp.data_desc.end_ra=end_coord.ra;
  wugrp.data_desc.start_dec=start_coord.dec;
  wugrp.data_desc.end_dec=end_coord.dec;
  coordinate_t last_coord=start_coord;
  double sample_rate=tapebuffer[0].header.samplerate/NSTRIPS;

  // find the bracketing entries in the coordinate history
  std::map<seti_time,coordinate_t>::iterator above(coord_history.upper_bound(end_time));
  std::map<seti_time,coordinate_t>::iterator below(coord_history.lower_bound(start_time));
  std::map<seti_time,coordinate_t>::iterator p;
  if (above==coord_history.begin()) {
    above++;
  }
  if (below==coord_history.end()) {
    below=above;
    below--;
  }
  if (above==below) {
    below--;
  }
  // Calculate the angular distance the beam has traveled
  for (p=below;p!=above;p++)
  {
    wugrp.data_desc.true_angle_range+=angdist(last_coord,p->second);
    last_coord=p->second;
  }
  wugrp.data_desc.true_angle_range+=angdist(last_coord,end_coord);
  if (wugrp.data_desc.true_angle_range==0) wugrp.data_desc.true_angle_range=1e-10;
  // Calculate the number of unique signals that could be found in a workunit.
  // We will use these numbers to calculate thresholds.
  double numgauss=2.36368e+08/std::min(wugrp.data_desc.true_angle_range,10.0);
  double numpulse=std::min(4.52067e+10/std::min(wugrp.data_desc.true_angle_range,10.0),2.00382e+11);
  double numtrip=std::min(3.25215e+12/std::min(wugrp.data_desc.true_angle_range,10.0),1.44774e+13);

  // check for VLAR workunits
  if (wugrp.data_desc.true_angle_range < 0.12) {
    group_is_vlar=true;
  } else {
    group_is_vlar=false;
  }
    

  // if (useanalysiscfgid > 0) { 
  //   log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,"Re-reading analysis cfg id: %d (set by user):\n",useanalysiscfgid);
  //   s.analysis_cfg = useanalysiscfgid;
  //   }

  // Calculate a unique key to describe this analysis config.
  long keyuniq=floor(std::min(wugrp.data_desc.true_angle_range*100,1000.0)+0.5)+
    s.analysis_cfg.id*1024;
  if ((keyuniq>((s.analysis_cfg.id+1)*1024)) ||(keyuniq<(s.analysis_cfg.id)*1024)) {
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Invalid keyuniq value!\n");
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%d %d %f\n",keyuniq,s.analysis_cfg.id,wugrp.data_desc.true_angle_range);
     exit(1);
  }

  keyuniq*=-1;
  long save_keyuniq=keyuniq;
  splitter_settings.analysis_cfg=wugrp.analysis_cfg;
  sprintf(tmpstr,"where keyuniq=%d",keyuniq); 
  // Check if we've already done this analysis_config...
  // Fetch through splitter_settings, since it's alias (s) is const.
  splitter_settings.analysis_cfg.id=0;
  splitter_settings.analysis_cfg->fetch(tmpstr);

  if (s.analysis_cfg->id==0) {
    if (keyuniq != save_keyuniq) {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"keyuniq value changed!\n");
      exit(1);
    }

    // If not calculate the thresholds based upon the input analysis_config
    // Triplets are distributed exponentially...
    wugrp.analysis_cfg->triplet_thresh+=(log(numtrip)-29.0652);

    // Gaussians are based upon chisqr...
    double p_gauss=lcgf(32.0,wugrp.analysis_cfg->gauss_null_chi_sq_thresh*32.0);
    p_gauss-=(log(numgauss)-19.5358);
    wugrp.analysis_cfg->gauss_null_chi_sq_thresh=invert_lcgf(p_gauss,32,1e-4)*0.03125;

    // Pulses thresholds are log of the probability
    wugrp.analysis_cfg->pulse_thresh+=(log(numpulse)-24.7894);

    wugrp.analysis_cfg->keyuniq=keyuniq;
    wugrp.analysis_cfg->insert();
  } else {
    wugrp.analysis_cfg=s.analysis_cfg;
  }

  strlcpy(wugrp.data_desc.time_recorded,
      short_jd_string(start_time.jd().uval()),
      sizeof(wugrp.data_desc.time_recorded));
  wugrp.data_desc.time_recorded_jd=start_time.jd().uval();
  wugrp.data_desc.coords.clear();

  wugrp.data_desc.coords.push_back(start_coord);  
  for (p=below;p!=above;p++)
  {
     wugrp.data_desc.coords.push_back(p->second);  
  }
  wugrp.data_desc.coords.push_back(end_coord);

  wugrp.tape_info->id=0;
  sprintf(buf,"%d",tel-AO_ALFA_0_0);
  wugrp.tape_info->fetch(std::string("where name=\'")+tapebuffer[0].header.name+"\' and beam="+buf);
  wugrp.tape_info->start_time=tapebuffer[0].header.data_time.jd().uval();
  wugrp.tape_info->last_block_time=wugrp.tape_info->start_time;
  wugrp.tape_info->last_block_done=tapebuffer[0].header.dataseq;
  wugrp.tape_info->beam=tel-AO_ALFA_0_0;

  if (!nodb) {
    if (wugrp.tape_info.id) {
      if (!(wugrp.tape_info->update())) {
        char buf[1024];
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%s",sql_error_message());
	exit(1);
      }
    } else {
      strlcpy(wugrp.tape_info->name,tapebuffer[0].header.name,sizeof(wugrp.tape_info->name));
      wugrp.tape_info->insert();
    }
  }

  if (!nodb) {
    sqlint8_t wgid;
    if ((wgid=wugrp.insert())<=0) {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Workunit_grp insert failed\nwgid=%d\nSQLCODE=%d\nLAST_NON_ZERO_SQLCODE=%d\n",wgid,sql_error_code(),sql_last_error_code());
      exit( 1 );
    }
    wugrp.id=wgid;
  }
  int i; 
  wu_database_id.resize(NSTRIPS);
  bin_data.resize(NSTRIPS);
  wuheader.resize(NSTRIPS);
  for (i=0;i<NSTRIPS;i++) {
    bin_data[i].clear();
    wuheader[i].group_info=wugrp;
    wuheader[i].group_info.id=wugrp.id;
    sprintf(wuheader[i].name,"%s.%ld.%d.%ld.%d.%d",tapebuffer[0].header.name,
       procid, tapebuffer[0].header.dataseq,
       tel-AO_430,s.id,i);
    if (group_is_vlar) {
      strlcat(wuheader[i].name,".vlar",sizeof(wuheader[i].name));
    }
    wuheader[i].subband_desc.sample_rate=tapebuffer[0].header.samplerate/NSTRIPS;
 
    receiver_freq=tapebuffer[0].header.sky_freq;

    bandno=((i+NSTRIPS/2)%NSTRIPS)-NSTRIPS/2;

    wuheader[i].subband_desc.base=receiver_freq+
	       (double)(bandno)*wuheader[i].subband_desc.sample_rate;
    wuheader[i].subband_desc.center=receiver_freq+wuheader[i].subband_desc.sample_rate*NSTRIPS*((double)IFFT_LEN*bandno/FFT_LEN+(double)IFFT_LEN/(2*FFT_LEN)-1.0/(2*FFT_LEN));
    wuheader[i].subband_desc.number=i;

    if (!nodb ) {
      if (!(wu_database_id[i]=wuheader[i].id=wuheader[i].insert())) {
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Database error in make_wu_headers()\n");
        exit(EXIT_FAILURE);
      }
    }
	
    sprintf(tmpstr,"./wu_inbox/%s",wuheader[i].name);
    if ((tmpfile=fopen(tmpstr,"w"))) {
      fprintf(tmpfile,"<workunit>\n");
      fprintf(tmpfile,wuheader[i].print_xml().c_str());
      fclose(tmpfile);
    } else {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open file ./wu_inbox/%s, errno=%d\n",wuheader[i].name,errno);
      exit(1);
    }
    bin_data[i].reserve(wuheaders[i].group_info->recorder_cfg->bits_per_sample*
       wuheaders[i].group_info->data_desc.nsamples/8);
  }
  return(1);
}
Esempio n. 4
0
int ChooseGaussEvent(
  int ifft,
  float PeakPower,
  float TrueMean,
  float ChiSq,
  float null_ChiSq,
  int bin,
  float sigma,
  float PoTMaxPower,
  float fp_PoT[]
) {

#ifdef USE_MANUAL_CALLSTACK
  call_stack.enter("ChooseGaussEvent");
#endif 
  GAUSS_INFO gi;
  float scale_factor;
  bool report, chisqOK=(ChiSq <= swi.analysis_cfg.gauss_chi_sq_thresh);

  // gaussian info
  gi.bin              = bin;
  gi.fft_ind          = ifft;
  gi.g.chirp_rate     = ChirpFftPairs[analysis_state.icfft].ChirpRate;
  gi.g.fft_len        = ChirpFftPairs[analysis_state.icfft].FftLen;
  gi.g.sigma          = sigma;
  gi.g.peak_power     = PeakPower;
  gi.g.mean_power     = TrueMean;
  gi.g.chisqr         = ChiSq;
  gi.g.null_chisqr    = null_ChiSq;
  gi.g.freq           = cnvt_bin_hz(bin,  gi.g.fft_len);
  double t_offset=(((double)gi.fft_ind+0.5)/swi.analysis_cfg.gauss_pot_length)*
                  PoTInfo.WUDuration;
  gi.g.detection_freq =calc_detection_freq(gi.g.freq,gi.g.chirp_rate,t_offset);
  gi.g.time           = swi.time_recorded+t_offset/86400.0;
  gi.g.max_power      = PoTMaxPower;
  gi.score            = -13.0;
  time_to_ra_dec(gi.g.time, &gi.g.ra, &gi.g.decl);

  // Scale PoT down to 256 16 bit ints.
  //for (i=0; i<swi.analysis_cfg.gauss_pot_length; i++) gi.pot[i] = fp_PoT[i];   // ???
  scale_factor = static_cast<float>(gi.g.max_power) / 255.0f;
  if (gi.g.pot.size() != static_cast<size_t>(swi.analysis_cfg.gauss_pot_length)) {
    gi.g.pot.set_size(swi.analysis_cfg.gauss_pot_length);
  }
  float_to_uchar(fp_PoT, &(gi.g.pot[0]), swi.analysis_cfg.gauss_pot_length, scale_factor);

  if (!swi.analysis_cfg.gauss_null_chi_sq_thresh)
      swi.analysis_cfg.gauss_null_chi_sq_thresh=1.890;
  // Gauss score used for "best of" and graphics.
  // This score is now set to be based upon the probability that a signal
  // would occur due to noise and the probability that it is shaped like 
  // a Gaussian (normalized to 0 at thresholds).  Thanks to Tetsuji for
  // making me think about this. The Gaussian has 62 degrees of freedom and
  // the null hypothesis has 63 degrees of freedom when gauss_pot_length=64;
  //JWS: Calculate invariant terms once, ala Alex Kan and Przemyslaw Zych
  static float gauss_bins = static_cast<float>(swi.analysis_cfg.gauss_pot_length);
  static float gauss_dof = gauss_bins - 2.0f;
  static float null_dof = gauss_bins - 1.0f;
  static double score_offset = (
      lcgf(0.5*null_dof, swi.analysis_cfg.gauss_null_chi_sq_thresh*0.5*gauss_bins)
     -lcgf(0.5*gauss_dof, swi.analysis_cfg.gauss_chi_sq_thresh*0.5*gauss_bins)
      );
//R: same optimization as for GPU build: if there is reportable Gaussian already - 
//R: skip score calculation for all except new reportable Gaussians
  // Final thresholding first.
  report = chisqOK
        && (gi.g.peak_power >= gi.g.mean_power * swi.analysis_cfg.gauss_peak_power_thresh)
        && (gi.g.null_chisqr >= swi.analysis_cfg.gauss_null_chi_sq_thresh);
  if (gaussian_count==0||report) {
      gi.score = score_offset
          +lcgf(0.5*gauss_dof,std::max(gi.g.chisqr*0.5*gauss_bins,0.5*gauss_dof+1))
          -lcgf(0.5*null_dof,std::max(gi.g.null_chisqr*0.5*gauss_bins,0.5*null_dof+1));
  }
  // Only include "real" Gaussians (those meeting the chisqr threshold)
  // in the best Gaussian display. 
  if (gi.score > best_gauss->score && chisqOK) {
    *best_gauss = gi;
  }
  // Update gdata gauss info regardless of whether it is the
  // best thus far or even passes the final threshold.  If
  // a gaussian has made it this far, display it.
#ifdef BOINC_APP_GRAPHICS
  if (!nographics()) sah_graphics->gi.copy(&gi);
#endif


  analysis_state.FLOP_counter+=24.0;
  // Final reporting.
  if (report) {
      int retval=result_gaussian(gi);
#ifdef USE_MANUAL_CALLSTACK
      call_stack.exit();
#endif 
      return retval;
  }  
#ifdef USE_MANUAL_CALLSTACK
  call_stack.exit();
#endif 
  return 0;
}
int make_wu_headers(tapeheader_t tapeheader[],workunit wuheader[],
                    buffer_pos_t *start_of_wu) {
  int procid=getpid();
  int i,j,startframe=start_of_wu->frame;
  double receiver_freq;
  int bandno;
  SCOPE_STRING *lastpos;
  FILE *tmpfile;
  char tmpstr[256];
  char buf[64];
  static int HaveConfigTable=0;
  static ReceiverConfig_t ReceiverConfig;   
  static receiver_config r;
  static settings s;

  if(!HaveConfigTable) {
    sprintf(buf,"where s4_id=%d",gregorian?AOGREG_1420:AO_1420);
    r.fetch(std::string(buf));
    ReceiverConfig.ReceiverID=r.s4_id;
    strlcpy(ReceiverConfig.ReceiverName,r.name,
           sizeof(ReceiverConfig.ReceiverName));
    ReceiverConfig.Latitude=r.latitude;
    ReceiverConfig.Longitude=r.longitude;
    ReceiverConfig.WLongitude=-r.longitude;
    ReceiverConfig.Elevation=r.elevation;
    ReceiverConfig.Diameter=r.diameter;
    ReceiverConfig.BeamWidth=r.beam_width;
    ReceiverConfig.CenterFreq=r.center_freq;
    ReceiverConfig.AzOrientation=r.az_orientation;
    for (i=0;i<(sizeof(ReceiverConfig.ZenCorrCoeff)/sizeof(ReceiverConfig.ZenCorrCoeff[0]));i++) {
      ReceiverConfig.ZenCorrCoeff[i]=r.zen_corr_coeff[i];
      ReceiverConfig.AzCorrCoeff[i]=r.az_corr_coeff[i];
    }
    HaveConfigTable=1;
  }
  sprintf(buf,"where active=%d",app.id);
  if (!s.fetch(std::string(buf))) {
    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to find active settings for app.id=%d\n",app.id);
    exit(1);
  }
  if (s.receiver_cfg->id != r.id) {
    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Receiver config does not match settings (%d != %d)\n",s.receiver_cfg->id, r.id);
    exit(1);
  }
  s.recorder_cfg->fetch();
  s.splitter_cfg->fetch();
  s.analysis_cfg->fetch();
  if (!strncmp(s.splitter_cfg->data_type,"encoded",
     std::min(static_cast<size_t>(7),sizeof(s.splitter_cfg->data_type)))) {
    noencode=0;
  } else {
      noencode=1;
  }

  workunit_grp wugrp;
  sprintf(wugrp.name,"%s.%ld.%d.%ld.%d",tapeheader[startframe].name,
    procid, 
    (current_record-TAPE_RECORDS_IN_BUFFER)*8+startframe,
    start_of_wu->byte,s.id);
  wugrp.receiver_cfg=r;
  wugrp.recorder_cfg=s.recorder_cfg;
  wugrp.splitter_cfg=s.splitter_cfg;
  wugrp.analysis_cfg=s.analysis_cfg;

  wugrp.data_desc.start_ra=tapeheader[startframe+1].telstr.ra;
  wugrp.data_desc.start_dec=tapeheader[startframe+1].telstr.dec;
  wugrp.data_desc.end_ra=tapeheader[startframe+TAPE_FRAMES_PER_WU].telstr.ra;
  wugrp.data_desc.end_dec=tapeheader[startframe+TAPE_FRAMES_PER_WU].telstr.dec;
  wugrp.data_desc.nsamples=NSAMPLES;
  wugrp.data_desc.true_angle_range=0;
  {
    double sample_rate=tapeheader[startframe].samplerate/NSTRIPS;
    /* startframe+1 contains the first valid RA and Dec */
    TIME st=tapeheader[startframe+1].telstr.st;
    TIME et=tapeheader[startframe+TAPE_FRAMES_PER_WU].telstr.st;
    double diff=(et-st).jd*86400.0;
    for (j=2;j<TAPE_FRAMES_PER_WU;j++) {
      wugrp.data_desc.true_angle_range+=angdist(tapeheader[startframe+j-1].telstr,tapeheader[startframe+j].telstr);
    }
    wugrp.data_desc.true_angle_range*=(double)wugrp.data_desc.nsamples/(double)sample_rate/diff;
    if (wugrp.data_desc.true_angle_range==0) wugrp.data_desc.true_angle_range=1e-10;
  }
  // Calculate the number of unique signals that could be found in a workunit.
  // We will use these numbers to calculate thresholds.
  double numgauss=2.36368e+08/wugrp.data_desc.true_angle_range;
  double numpulse=std::min(4.52067e+10/wugrp.data_desc.true_angle_range,2.00382e+11);
  double numtrip=std::min(3.25215e+12/wugrp.data_desc.true_angle_range,1.44774e+13);

  

  // Calculate a unique key to describe this analysis config.
  long keyuniq=floor(std::min(wugrp.data_desc.true_angle_range*100,1000.0)+0.5)+
    s.analysis_cfg.id*1024.0;
  if ((keyuniq>(13*1024)) ||(keyuniq<12*1024)) {
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Invalid keyuniq value!\n");
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%d %d %f\n",keyuniq,s.analysis_cfg.id,wugrp.data_desc.true_angle_range);
     exit(1);
  }

  keyuniq*=-1;
  long save_keyuniq=keyuniq;
  s.analysis_cfg=wugrp.analysis_cfg;
  sprintf(tmpstr,"where keyuniq=%d",keyuniq); 
  // Check if we've already done this analysis_config...
  s.analysis_cfg.id=0;
  s.analysis_cfg->fetch(tmpstr);

  if (s.analysis_cfg->id==0) {
    if (keyuniq != save_keyuniq) {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"keyuniq value changed!\n");
      exit(1);
    }

    // If not calculate the thresholds based upon the input analysis_config
    // Triplets are distributed exponentially...
    wugrp.analysis_cfg->triplet_thresh+=(log(numtrip)-29.0652);

    // Gaussians are based upon chisqr...
    double p_gauss=lcgf(32.0,wugrp.analysis_cfg->gauss_null_chi_sq_thresh*32.0);
    p_gauss-=(log(numgauss)-19.5358);
    wugrp.analysis_cfg->gauss_null_chi_sq_thresh=invert_lcgf(p_gauss,32,1e-4)*0.03125;

    // Pulses thresholds are log of the probability
    wugrp.analysis_cfg->pulse_thresh+=(log(numpulse)-24.7894);

    wugrp.analysis_cfg->keyuniq=keyuniq;
    wugrp.analysis_cfg->insert();
  } else {
    wugrp.analysis_cfg=s.analysis_cfg;
  }

  strlcpy(wugrp.data_desc.time_recorded,
      short_jd_string(tapeheader[startframe+1].telstr.st.jd),
      sizeof(wugrp.data_desc.time_recorded));
  wugrp.data_desc.time_recorded_jd=tapeheader[startframe+1].telstr.st.jd;

  lastpos=&(tapeheader[startframe].telstr);
  coordinate_t tmpcoord;
  tmpcoord.time=tapeheader[startframe].telstr.st.jd;
  tmpcoord.ra=tapeheader[startframe].telstr.ra;
  tmpcoord.dec=tapeheader[startframe].telstr.dec;
  wugrp.data_desc.coords.push_back(tmpcoord);  

  for (j=1;j<TAPE_FRAMES_PER_WU;j++) {
    if ((tapeheader[startframe+j].telstr.st.jd-lastpos->st.jd) > (1.0/86400.0)) 
    {
      lastpos=&(tapeheader[startframe+j].telstr);
      tmpcoord.time=tapeheader[startframe+j].telstr.st.jd;
      tmpcoord.ra=tapeheader[startframe+j].telstr.ra;
      tmpcoord.dec=tapeheader[startframe+j].telstr.dec;
      wugrp.data_desc.coords.push_back(tmpcoord);  
    }
  }

  wugrp.tape_info->id=0;
  wugrp.tape_info->fetch(std::string("where name=\'")+tapeheader[startframe].name+"\'");
  wugrp.tape_info->start_time=tapeheader[startframe].st.jd;
  wugrp.tape_info->last_block_time=tapeheader[startframe].st.jd;
  wugrp.tape_info->last_block_done=tapeheader[startframe].frameseq;

  if (!nodb) {
    if (wugrp.tape_info.id) {
      if (!(wugrp.tape_info->update())) {
        char buf[1024];
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%s",sql_error_message());
	exit(1);
      }
    } else {
      strlcpy(wugrp.tape_info->name,tapeheader[startframe].name,sizeof(wugrp.tape_info->name));
      wugrp.tape_info->insert();
    }
  }

  if (!nodb) wugrp.insert();
  
  for (i=0;i<NSTRIPS;i++) {
    bin_data[i].clear();
    wuheader[i].group_info=wugrp;
    sprintf(wuheader[i].name,"%s.%ld.%d.%ld.%d.%d",tapeheader[startframe].name,
       procid, (current_record-TAPE_RECORDS_IN_BUFFER)*8+startframe,
       start_of_wu->byte,s.id,i);
    wuheader[i].subband_desc.sample_rate=tapeheader[startframe].samplerate/NSTRIPS;
 
    receiver_freq=tapeheader[startframe].centerfreq;

    bandno=((i+NSTRIPS/2)%NSTRIPS)-NSTRIPS/2;

    wuheader[i].subband_desc.base=receiver_freq+
	       (double)(bandno)*wuheader[i].subband_desc.sample_rate;
    wuheader[i].subband_desc.center=receiver_freq+wuheader[i].subband_desc.sample_rate*NSTRIPS*((double)IFFT_LEN*bandno/FFT_LEN+(double)IFFT_LEN/(2*FFT_LEN)-1.0/(2*FFT_LEN));
    wuheader[i].subband_desc.number=i;

    if (!nodb ) {
      if (!(wu_database_id[i]=wuheader[i].insert())) {
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Database error in make_wu_headers()\n");
        exit(EXIT_FAILURE);
      }
    }
	
    sprintf(tmpstr,"./wu_inbox/%s",wuheader[i].name);
    if ((tmpfile=fopen(tmpstr,"w"))) {
      fprintf(tmpfile,"<workunit>\n");
      fprintf(tmpfile,wuheader[i].print_xml().c_str());
      fclose(tmpfile);
    } else {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open file ./wu_inbox/%s, errno=%d\n",wuheader[i].name,errno);
      exit(1);
    }
    bin_data[i].reserve(wuheaders[i].group_info->recorder_cfg->bits_per_sample*
       wuheaders[i].group_info->data_desc.nsamples/8);
  }
  return(1);
}
Esempio n. 6
0
static float dlcgf(float a, float x) {
  return (lcgf(a,x+0.1f)-lcgf(a,x-0.1f))/0.2f;
}