std::string dsp::FilenameEpoch::get_filename (const PhaseSeries* data) { MJD epoch = data->get_start_time(); if (Observation::verbose) cerr << "dsp::FilenameEpoch::get_filename epoch=" << epoch.printall() << endl; if (integer_seconds) { // ensure that the epoch is rounded up into the current division epoch = data->get_mid_time (false); DEBUG("dsp::FilenameEpoch::get_filename mid_time=" << epoch.printall()); unsigned seconds = epoch.get_secs(); unsigned divisions = seconds / integer_seconds; epoch = MJD (epoch.intday(), divisions * integer_seconds, 0.0); if (Observation::verbose) cerr << "dsp::FilenameEpoch::get_filename division_start=" << epoch.printall() << endl; } vector<char> fname (FILENAME_MAX); char* filename = &fname[0]; if (!epoch.datestr( filename, FILENAME_MAX, datestr_pattern.c_str() )) throw Error (FailedSys, "dsp::PhaseSeriesUnloader::get_filename", "error MJD::datestr(" + datestr_pattern + ")"); if (report_unload) cerr << "unloading " << tostring(data->get_integration_length(),2) << " seconds: " << filename << endl; return filename; }
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; }
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(); }