コード例 #1
0
ファイル: ephorb.C プロジェクト: SkyTian13/psrchive
int main (int argc, char ** argv) try
{
  bool phase_periastron = false;
  bool longitude_periastron = false;
  bool longitude_ascending = false;

  MJD mjd;
  double duration = 0.0;

  char site = '7';
  double freq = 1400.0;

  int gotc = 0;
  while ((gotc = getopt(argc, argv, "hd:f:m:s:pPaA")) != -1)
  {
    switch (gotc)
    {
    case 'h':
      usage ();
      return 0;

    case 'd':
      duration = atof (optarg);
      break;

    case 'f':
      freq = atof (optarg);
      break;

    case 'm':
      mjd = MJD(optarg);
      break;

    case 's':
      site = optarg[0];
      break;

    case 'p':
      phase_periastron = true;
      break;

    case 'P':
      longitude_periastron = true;
      break;

    case 'A':
      longitude_ascending = true;
      break;

    }
  }

  if (optind >= argc)
  {
    cerr << "Please provide tempo parameter file" << endl;
    return -1;
  }

  if (mjd == 0.0)
  {
    time_t temp = time(NULL);
    struct tm date = *gmtime(&temp);
    fprintf (stderr, "\nUsing current date/time: %s\n", asctime(&date));
    mjd = MJD (date);
  }

  psrephem eph (argv[optind]);

  double epoch = mjd.in_days();

  if (duration)
  {
    unsigned nsteps = 100;
    for (unsigned i=0; i<nsteps; i++)
    {
      double hours = (duration * i) / nsteps;
      double seconds = hours * 3600.0;

      MJD t = mjd + seconds;

      cout << hours << " " << t.datestr("%H:%M:%S") << " "
	   << get_binlng_asc (t.in_days(), eph, freq, site) << endl;
    }
    return 0;
  }

  cout << "================================================" << endl;

  if ( phase_periastron )
    cout << "Binary phase (wrt periastron) = " 
	 << get_binphs_peri (epoch, eph, freq, site)*360.0 << " deg" << endl;
  
  if ( longitude_periastron )
    cout << "Longitude wrt periastron = " 
	 << get_binlng_peri (epoch, eph, freq, site) << " deg" << endl;
  
  if ( longitude_ascending )
    cout << "Longitude wrt ascending node = "
	 << get_binlng_asc (epoch, eph, freq, site) << " deg" << endl;
  
  cout << "================================================" << endl;

  if ( longitude_ascending )
    cout <<
      "\n"
      "Superior conjunction occurs when longitude wrt ascending node = 90 deg"
      "\n"
	 << endl;

  return 0;
}
catch (Error& error)
{
  cerr << "ephorb: error" << error << endl;
  return -1;
}
コード例 #2
0
ファイル: Mark4File.C プロジェクト: gitj/dspsr
MJD dsp::Mark4File::decode_date(uint64_t from)
{
  char *timecode = new char[8*channels]; // 8 bytes per channel

  MJD date;
  MJD current;
  utc_t utcdate;
  utc_t tmpdate;
  
  // Special lookup table, see documentation for Mark4 formaters.
  // 0=0, 1=1.25, 2=2.5, 3=3.75, 4=NA, 5=5.0, 6=6.25, 7=7.5, 8=8.75, 9=NA
  //Required for Mark4 standard format
  float time_code_table[] = {0,1.25,2.5,3.75,0.0,5.0,6.25,7.50,8.75,0.0};

  current.Construct(time(NULL));
  
  uint64_t inital_pos = lseek(fd, 0, SEEK_CUR);
  
  uint64_t next_sync = find_sync(fd, from);
  
  // Read the 8 bytes after the SYNC - and handle them as per modes
  lseek(fd,next_sync+4*channels,SEEK_SET);
  
  read(fd, timecode, 8*channels);

  int stepsize = channels/8;

  int julian = 0;
  int year   = 0;
  int day    = 0;
  int hour   = 0;
  int minute = 0;
  double second = 0.0;
  char tmp[4];
  
  switch(mode) {
    
  case VLBA:

    // Date format for VLBA = JJJSSSSS.ssss
    
    // JJJ
    tmp[0] = timecode[0*stepsize];
    tmp[1] = timecode[1*stepsize];
    tmp[2] = timecode[2*stepsize];
    tmp[3] = timecode[3*stepsize];
    julian += decode_bcd(tmp)*100;

    tmp[0] = timecode[4*stepsize];
    tmp[1] = timecode[5*stepsize];
    tmp[2] = timecode[6*stepsize];
    tmp[3] = timecode[7*stepsize];
    julian += decode_bcd(tmp)*10;

    tmp[0] = timecode[8*stepsize];
    tmp[1] = timecode[9*stepsize];
    tmp[2] = timecode[10*stepsize];
    tmp[3] = timecode[11*stepsize];
    julian += decode_bcd(tmp)*1;
    
    //SSSSS
    tmp[0] = timecode[12*stepsize];
    tmp[1] = timecode[13*stepsize];
    tmp[2] = timecode[14*stepsize];
    tmp[3] = timecode[15*stepsize];
    second += decode_bcd(tmp)*10000.0;

    tmp[0] = timecode[16*stepsize];
    tmp[1] = timecode[17*stepsize];
    tmp[2] = timecode[18*stepsize];
    tmp[3] = timecode[19*stepsize];
    second += decode_bcd(tmp)*1000.0;

    tmp[0] = timecode[20*stepsize];
    tmp[1] = timecode[21*stepsize];
    tmp[2] = timecode[22*stepsize];
    tmp[3] = timecode[23*stepsize];
    second += decode_bcd(tmp)*100.0;

    tmp[0] = timecode[24*stepsize];
    tmp[1] = timecode[25*stepsize];
    tmp[2] = timecode[26*stepsize];
    tmp[3] = timecode[27*stepsize];
    second += decode_bcd(tmp)*10.0;

    tmp[0] = timecode[28*stepsize];
    tmp[1] = timecode[29*stepsize];
    tmp[2] = timecode[30*stepsize];
    tmp[3] = timecode[31*stepsize];
    second += decode_bcd(tmp)*1.0;

    //.ssss
    tmp[0] = timecode[32*stepsize];
    tmp[1] = timecode[33*stepsize];
    tmp[2] = timecode[34*stepsize];
    tmp[3] = timecode[35*stepsize];
    second += decode_bcd(tmp)*0.1;

    tmp[0] = timecode[36*stepsize];
    tmp[1] = timecode[37*stepsize];
    tmp[2] = timecode[38*stepsize];
    tmp[3] = timecode[39*stepsize];
    second += decode_bcd(tmp)*0.01;

    tmp[0] = timecode[40*stepsize];
    tmp[1] = timecode[41*stepsize];
    tmp[2] = timecode[42*stepsize];
    tmp[3] = timecode[43*stepsize];
    second += decode_bcd(tmp)*0.001;

    tmp[0] = timecode[44*stepsize];
    tmp[1] = timecode[45*stepsize];
    tmp[2] = timecode[46*stepsize];
    tmp[3] = timecode[47*stepsize];
    second += decode_bcd(tmp)*0.0001;
    
    if(int(current.in_days())%1000 >= julian){
      // 2 most significant digits of 5 digit julian are correct
      julian += ( int(current.in_days())/1000)*1000;
    }
    else{
      julian += ( int(current.in_days())/1000 -1 )*1000;
    }

    date = MJD(julian,int(second), (second-int(second)));
    
    break;
    
  case Standard:
    
    // Date format for VLBA = YDDDHHMMSS.sss
    
    // Y
    tmp[0] = timecode[0*stepsize];
    tmp[1] = timecode[1*stepsize];
    tmp[2] = timecode[2*stepsize];
    tmp[3] = timecode[3*stepsize];
    year = decode_bcd(tmp);


    // DDD
    tmp[0] = timecode[4*stepsize];
    tmp[1] = timecode[5*stepsize];
    tmp[2] = timecode[6*stepsize];
    tmp[3] = timecode[7*stepsize];
    day += decode_bcd(tmp)*100;

    tmp[0] = timecode[8*stepsize];
    tmp[1] = timecode[9*stepsize];
    tmp[2] = timecode[10*stepsize];
    tmp[3] = timecode[11*stepsize];
    day += decode_bcd(tmp)*10;
    
    tmp[0] = timecode[12*stepsize];
    tmp[1] = timecode[13*stepsize];
    tmp[2] = timecode[14*stepsize];
    tmp[3] = timecode[15*stepsize];
    day += decode_bcd(tmp)*1;


    // HH
    tmp[0] = timecode[16*stepsize];
    tmp[1] = timecode[17*stepsize];
    tmp[2] = timecode[18*stepsize];
    tmp[3] = timecode[19*stepsize];
    hour += decode_bcd(tmp)*10;

    tmp[0] = timecode[20*stepsize];
    tmp[1] = timecode[21*stepsize];
    tmp[2] = timecode[22*stepsize];
    tmp[3] = timecode[23*stepsize];
    hour += decode_bcd(tmp)*1;

    // MM
    tmp[0] = timecode[24*stepsize];
    tmp[1] = timecode[25*stepsize];
    tmp[2] = timecode[26*stepsize];
    tmp[3] = timecode[27*stepsize];
    minute += decode_bcd(tmp)*10;

    tmp[0] = timecode[28*stepsize];
    tmp[1] = timecode[29*stepsize];
    tmp[2] = timecode[30*stepsize];
    tmp[3] = timecode[31*stepsize];
    minute += decode_bcd(tmp)*1;


    // SS
    tmp[0] = timecode[32*stepsize];
    tmp[1] = timecode[33*stepsize];
    tmp[2] = timecode[34*stepsize];
    tmp[3] = timecode[35*stepsize];
    second += decode_bcd(tmp)*10.0;

    tmp[0] = timecode[36*stepsize];
    tmp[1] = timecode[37*stepsize];
    tmp[2] = timecode[38*stepsize];
    tmp[3] = timecode[39*stepsize];
    second += decode_bcd(tmp)*1.0;


    // .sss
    tmp[0] = timecode[40*stepsize];
    tmp[1] = timecode[41*stepsize];
    tmp[2] = timecode[42*stepsize];
    tmp[3] = timecode[43*stepsize];
    second += decode_bcd(tmp)*0.1;

    tmp[0] = timecode[44*stepsize];
    tmp[1] = timecode[45*stepsize];
    tmp[2] = timecode[46*stepsize];
    tmp[3] = timecode[47*stepsize];
    second += decode_bcd(tmp)*0.01;

    tmp[0] = timecode[48*stepsize];
    tmp[1] = timecode[49*stepsize];
    tmp[2] = timecode[50*stepsize];
    tmp[3] = timecode[51*stepsize];
    second += time_code_table[decode_bcd(tmp)]*0.001;
    
    
    current.UTC(&tmpdate,0);

    if(tmpdate.tm_year%10 >= year){
      year += int(tmpdate.tm_year/10)*10;
    }else{
      year += int((tmpdate.tm_year/10)-1)*10;
    }
    
    utcdate.tm_year = year;
    utcdate.tm_yday = day;
    utcdate.tm_hour = hour;
    utcdate.tm_min  = minute;
    utcdate.tm_sec  = int(second);
    
    date  = MJD(utcdate);
    date +=  second-int(second); // add fractions of seconds.

    break;
 
   
  default:
    cerr << "Unknown mode - " << mode << endl;
    
  }
  
  //  cerr << "SEEK_CUR: " << lseek(fd,0,SEEK_CUR);
  //  lseek(fd,next_sync-8*channels,SEEK_SET);  // position of decoded time.
  //  cerr << "\t" << lseek(fd,0,SEEK_CUR)/channels << endl; 
  
  lseek(fd,inital_pos,SEEK_SET);  // restored original file pointer
  
  return date;
  
}
コード例 #3
0
ファイル: WAPPFile.C プロジェクト: UCBerkeleySETI/dspsr
void dsp::WAPPFile::open_file (const char* filename)
{
  header = malloc(sizeof(struct WAPP_HEADER));

  struct WAPP_HEADER* head = (struct WAPP_HEADER*) header;

#ifdef KEVINS_CODE
  fd=::open(filename,O_RDONLY);
  if(fd==-1)
    throw Error(FailedSys,"DSP::WAPPFile::Open_File","Could not open %s",filename);
  readheader(fd,head);
#else
  struct HEADERP* h = head_parse( filename );

  if (!h)
    throw Error (InvalidParam, "dsp::WAPPFile::open_file",
		 "not a WAPP file");


  fetch(src_name);
  fetch(obs_type);

  /* user-requested length of this integration (s) */
  fetch(obs_time);
  /* size (in bytes) of this header (nom =1024) */
  fetch(header_size);

  fetch(obs_date);
  fetch(start_time);

  /* user-requested sample time (us) */
  fetch(samp_time);
  fetch(wapp_time);

  fetch(num_lags);

  fetch(nifs);

  /* user-requested: 1 means 3-level; 2 mean 9-level  */
  fetch(level);

  fetch(lagformat);

  /* if we truncate data (0 no trunc)                 */
  /* for 16 bit lagmux modes, selects which 16 bits   */
  /* of the 32 are included as data                   */
  /* 0 is bits 15-0 1,16-1 2,17-2...7,22-7            */
  fetch(lagtrunc);

  fetch(cent_freq);

  fetch(bandwidth);

  fetch(freqinversion);

  /* requested ra J2000 (10000*hr+100*min+sec) */
  fetch(src_ra);

  /* requested dec J2000 (10000*deg+100*min+sec) */
  fetch(src_dec);

  fetch(start_az);
  fetch(start_za);
  fetch(start_ast);
  fetch(start_lst);

  /* user-requested: 1 means that data is sum of IFs  */
  fetch(sum);

  fetch(project_id);
  fetch(observers);

  fetch(psr_dm);

  fetch(dumptime);

  /* get number of bins which will be non zero in folding mode */
  fetch(nbins);

  // close_parse(h);
  fd = h->fd;
#endif

  cerr << "LEVEL=" << head->level << endl;

  // ////////////////////////////////////////////////////////////////////
  //
  // mode
  //
  /* what kind of observation is this */
  get_info()->set_mode(head->obs_type);

  // ////////////////////////////////////////////////////////////////////
  //
  // source
  //
  /* user-supplied source name (usually pulsar name) */
  get_info()->set_source (head->src_name);

  cerr << "Source = " << get_info()->get_source() << endl;

  // ////////////////////////////////////////////////////////////////////
  //
  // centre_frequency
  //
  /* user-supplied band center frequency (MHz) */
  get_info()->set_centre_frequency (head->cent_freq);

  // ////////////////////////////////////////////////////////////////////
  //
  // bandwidth
  //
  /* total bandwidth (MHz) for this observation */
  double bandwidth = head->bandwidth;
  /* 1 band is inverted, else band is not inverted    */
  if (head->freqinversion)
    bandwidth = -bandwidth;
  get_info()->set_bandwidth (bandwidth);

  // ////////////////////////////////////////////////////////////////////
  //
  // npol
  //
  /* user-requested: number of IFs to be recorded     */
  get_info()->set_npol (head->nifs);

  // ////////////////////////////////////////////////////////////////////
  //
  // state
  //
  if (head->nifs == 4)
    get_info()->set_state (Signal::Coherence);
  else if (head->nifs == 2)
    get_info()->set_state (Signal::PPQQ);
  else
    get_info()->set_state (Signal::Intensity);

  // ////////////////////////////////////////////////////////////////////
  //
  // nchan
  //
  /* user-requested number of lags per dump per spect */
  get_info()->set_nchan (head->num_lags);

  // ////////////////////////////////////////////////////////////////////
  //
  // nbit
  //
  /* 0=16 bit uint lags , 1=32 bit uint lags          */
  /* 2=32 bit float lags, 3=32 bit float spectra      */
  switch (head->lagformat) {
  case 0:
    get_info()->set_nbit (16);
    break;
  case 1:
    get_info()->set_nbit (32);
    break;
  case 3: /* timing mode data - not relevant, but needs to work! */
    break;
  case 4:
    get_info()->set_nbit (8);
    break;
  default:
    throw Error (InvalidState, "dsp::WAPPFile::open_file",
		 "lagformat variable in header should be 0, 1 or 4");
    break;
  }

  cerr << "WAPP nbit=" << get_info()->get_nbit() << endl;

  // ////////////////////////////////////////////////////////////////////
  //
  // start_time
  //

  /* built by WAPP from yyyymmdd */  
  string utc = head->obs_date;  utc += "-";

  /* UT seconds after midnight (start on 1-sec tick) [hh:mm:ss] */
  utc += head->start_time;

#if WVS_FIXES_STR2TM

  struct tm time;

  /* the str2tm function has been deprecated in favour of the standard C strptime */
  if (str2tm (&time, utc.c_str()) < 0)
    throw Error (InvalidState, "dsp::WAPPFile::open_file",
		 "Could not parse UTC from " + utc);

  MJD mjd (time);

#else

  // copied from WAPPArchive

  struct tm obs_date_greg;
  struct WAPP_HEADER* hdr = head;

  int rv = sscanf(hdr->obs_date, "%4d%2d%2d", 
      &obs_date_greg.tm_year, &obs_date_greg.tm_mon,
      &obs_date_greg.tm_mday);
  obs_date_greg.tm_year -= 1900;
  obs_date_greg.tm_mon -= 1;
  if (rv!=3) 
    throw Error (InvalidState, "dsp::WAPPFile::open_file",
        "Error converting obs_date string (rv=%d, obs_date=%s)", 
        rv, hdr->obs_date);
  rv = sscanf(hdr->start_time, "%2d:%2d:%2d", 
      &obs_date_greg.tm_hour, &obs_date_greg.tm_min, 
      &obs_date_greg.tm_sec);
  if (rv!=3) 
    throw Error (InvalidState, "dsp::WAPPFile::open_file",
        "Error converting start_time string (rv=%d, start_time=%s)", 
        rv, hdr->start_time);

  MJD mjd (obs_date_greg); 

#endif

  char buff[64];
  cerr << "UTC=" << utc << " MJD=" << mjd << " -> "
       << mjd.datestr (buff, 64, "%Y-%m-%d %H:%M:%S") << endl;

  // from sigproc-2.4
  /* for data between April 17 and May 8 inclusive, the start times are
     off by 0.5 days due to the ntp daemon not running... fix here.
     this also occured on May 17! hopefully will not happen again... */
  if ( ((mjd.intday() >= 52016) && (mjd.intday() <= 52039)) 
       || (mjd.intday() == 52046.0)) {
    cerr << "WARNING: MJD start time off by 0.5 days! fixed..." << endl;
    MJD half_day (0.5);
    mjd -= half_day;
  }

  get_info()->set_start_time (mjd);

  // ////////////////////////////////////////////////////////////////////
  //
  // rate
  //
  /* actual sample time (us) i.e. requested+dead time */
  double tsamp_us = head->wapp_time;

  // from sigproc-2.4
  tsamp_us += wappcorrect( mjd.in_days() );

  get_info()->set_rate ( 1e6 / tsamp_us );

  // ////////////////////////////////////////////////////////////////////
  //
  // telscope code
  //
  get_info()->set_telescope ("Arecibo");  // assume Arecibo

  string prefix="wapp";
  get_info()->set_machine("WAPP");	

  header_bytes = lseek(fd,0,SEEK_CUR);

  cerr << "header bytes=" << header_bytes << endl;

  set_total_samples();

}