unload_text.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2009 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Base/Formats/PSRFITS/unload_text.h
10 
11 #ifndef __unload_text_h
12 #define __unload_text_h
13 
14 #include "FITSError.h"
15 #include "FilePtr.h"
16 
17 #include <fitsio.h>
18 #include <string.h>
19 #include <vector>
20 #include <iostream>
21 
22 template<class T>
23 void unload_text (fitsfile* fptr, const char* table, const char* column,
24  const T* instance, bool verbose = false)
25 {
26  // Move to the HDU named table
27  int status = 0;
28  fits_movnam_hdu (fptr, BINARY_TBL, const_cast<char*>(table), 0, &status);
29 
30  if (status)
31  throw FITSError (status, "unload_text",
32  "fits_movnam_hdu %s", table);
33 
34  int colnum = 0;
35  fits_get_colnum (fptr, CASEINSEN, const_cast<char*>(column),
36  &colnum, &status);
37 
38  int typecode = 0;
39  long repeat = 0;
40  long width = 0;
41 
42  fits_get_coltype (fptr, colnum, &typecode, &repeat, &width, &status);
43 
44  if (typecode != TSTRING)
45  throw Error (InvalidState, "unload_text",
46  "%s typecode != TSTRING", column);
47 
48  FilePtr stream = tmpfile();
49  if (!stream)
50  throw Error (FailedSys, "unload_text", "tmpfile");
51 
52  try
53  {
54  instance->unload (stream);
55  }
56  catch (Error& error)
57  {
58  throw error += "unload_text";
59  }
60 
61  // seek back to the start of the file
62  fseek (stream, 0, SEEK_SET);
63 
64  std::vector<char> text (repeat * 2);
65  char* temp = &(text[0]);
66 
67  int row = 0;
68  while (fgets (temp, repeat, stream) == temp)
69  {
70  row ++;
71 
72  // get rid of the newline
73  char* newline = strchr (temp, '\n');
74  if (newline)
75  *newline = '\0';
76 
77  if (verbose)
78  std::cerr << "unload_text row=" << row << " line='" << temp << "'" << std::endl;
79 
80  fits_write_col (fptr, TSTRING, colnum, row, 1, 1, &temp, &status);
81 
82  if (status)
83  throw FITSError (status, "unload_text",
84  "fits_write_col row=%d", row);
85  }
86 
87  if (verbose)
88  std::cerr << "unload_text wrote " << row << " rows" << std::endl;
89 }
90 
91 #endif
Angle get_declination() const
Get the DEC (J2000) at subint centre.
Definition: Pointing.C:103
double get_param(unsigned) const
Get the value of the specified model parameter.
Definition: PolnCalibratorExtension.C:285
double cal_frequency
Calibrator frequency.
Definition: CalInfoExtension.h:58
std::string get_param_description(unsigned) const
Get the description of the specified model parameter.
Definition: PolnCalibratorExtension.C:263
double get_reference_frequency() const
Get the reference frequency of the interpolator.
Definition: CalibrationInterpolatorExtension.h:107
float get_filtered_sum(unsigned ichan, unsigned ipol) const
Get the filtered sum of the specified channel and polarization.
Definition: SpectralKurtosis.C:130
void unload_sk_integrations(fitsfile *) const
Unload Spectral Kurtosis Integration data to the SPECKURT HDU.
Definition: unload_SpectralKurtosis.C:16
Loads and unloads PSRFITS archives.
Definition: FITSArchive.h:63
void unload_Integration(fitsfile *, int row, const Integration *) const
A function to write an integration to a row in a FITS file on disk.
Definition: unload_Integration.C:35
bool get_valid(unsigned ichan) const
Get the validity flag for the specified channel.
Definition: CalibratorStokes.C:88
double bmaj
Beam major axis length.
Definition: FITSHdrExtension.h:244
const Calibrator::Type * get_type() const
Get the type of the calibrator.
Definition: CalibrationInterpolatorExtension.C:74
Angle get_field_orientation() const
Get the orientation of the equal in-phase electric field vector.
Definition: Receiver.C:128
bool get_has_solver() const
Get if the covariances of the transformation parameters.
Definition: PolnCalibratorExtension.C:144
std::string stt_time
Start UT (hh:mm:ss)
Definition: FITSHdrExtension.h:217
Angle get_galactic_longitude() const
Get the Gal longitude at subint centre.
Definition: Pointing.C:114
Coherent dedispersion attributes specific to input frequency channel.
Definition: CoherentDedispersion.h:118
int get_ndigr(void) const
get_ndigr
Definition: DigitiserStatistics.h:62
static double unset_dm
Special value for no DM set.
Definition: FITSHdrExtension.h:235
double get_bandwidth() const
Bandwidth of output channel.
Definition: CoherentDedispersion.h:73
Angle get_parallactic_angle() const
Get the Parallactic angle at subint centre.
Definition: Pointing.C:158
double get_dispersion_measure() const
Dispersion measure used for coherent dedispersion.
Definition: CoherentDedispersion.h:169
std::string get_dig_mode(void) const
get dig_mode
Definition: DigitiserStatistics.h:86
unsigned get_nparam() const
Get the number of parameters describing each transformation.
Definition: PolnCalibratorExtension.C:128
Angle get_galactic_latitude() const
Get the Gal latitude at subint centre.
Definition: Pointing.C:125
std::string get_name() const
Get the name of the receiver.
Definition: Receiver.h:90
Transformation * get_transformation(unsigned c)
Get the transformation for the specified frequency channel.
Definition: PolnCalibratorExtension.C:157
virtual MJD get_epoch() const =0
Get the epoch of the rising edge of bin zero.
unsigned get_nchan_input() const
Get the number of frequency channels in input data.
Definition: CalibrationInterpolatorExtension.h:101
void unload_integrations(fitsfile *) const
Unload Integration data to the SUBINT HDU of the specified FITS file.
Definition: unload_integrations.C:26
unsigned get_nchan() const
Get the number of channels.
Definition: SpectralKurtosis.h:92
unsigned get_nsamp_overlap_neg() const
Number of complex time samples in wrap-around region, right-hand side.
Definition: CoherentDedispersion.h:88
std::string get_diglev(void) const
get diglev
Definition: DigitiserStatistics.h:80
double obsfreq
Observed Frequency.
Definition: FITSHdrExtension.h:223
double get_centre_frequency(unsigned ichan) const
Get the Profile centre frequency attribute of the given channel.
Definition: Integration.C:359
const Integration * get_Integration(const Archive *data, Index subint)
Return the requested profile, cloning and integrating when needed.
Definition: Index.C:118
double cal_phase
Calibrator phase.
Definition: CalInfoExtension.h:64
double get_centre_frequency() const
Centre frequency of input channel.
Definition: CoherentDedispersion.h:124
int get_nbit_data() const
Number of bits used to represent data.
Definition: CoherentDedispersion.h:177
int get_nbit_chirp() const
Number of bits used to represent chirp.
Definition: CoherentDedispersion.h:181
unsigned int get_nchan(void) const
Get the number of frequency channels.
Definition: FluxCalibratorExtension.C:65
Instrumental passband (or bandpass)
Definition: Passband.h:25
unsigned get_nparam() const
Get the number of model parameters.
Definition: PolnCalibratorExtension.C:241
double get_minimum_frequency() const
Get the minimum frequency of the interpolator.
Definition: CalibrationInterpolatorExtension.h:112
uint64_t get_filtered_hits(unsigned ichan) const
Get the filtered hits of the specified channel and polarization.
Definition: SpectralKurtosis.C:149
virtual unsigned get_nchan() const
Get the number of frequency channels.
Definition: CalibratorExtension.C:83
virtual const Calibrator::Type * get_type() const
Get the type of the calibrator.
Definition: CalibratorExtension.C:53
double stt_lst
Start LST.
Definition: FITSHdrExtension.h:220
The primary interface to pulsar observational data.
Definition: Archive.h:45
unsigned get_nchan() const
Get the number of frequency channels.
Definition: CalibratorStokes.C:67
Contains information about the receiver and receiver platform.
Definition: Receiver.h:28
char code(const std::string &telescope_name)
double get_variance(unsigned) const
Get the variance of the specified model parameter.
Definition: PolnCalibratorExtension.C:297
Angle get_right_ascension() const
Get the RA (J2000) at subint centre.
Definition: Pointing.C:92
double chan_dm
DM used for online dedispersion.
Definition: FITSHdrExtension.h:232
Angle get_position_angle() const
Get the Position angle of feed at subint centre.
Definition: Pointing.C:147
Stores the Stokes parameters of the reference source.
Definition: CalibratorStokes.h:28
int get_npar(void) const
get npar
Definition: DigitiserStatistics.h:68
int obsnchan
Observed number of channels.
Definition: FITSHdrExtension.h:229
Stores PSRFITS header extensions.
Definition: FITSHdrExtension.h:25
std::string pnt_id
Name or ID for pointing ctr (multibeam feeds)
Definition: FITSHdrExtension.h:168
unsigned get_nchan() const
Get the number of frequency channels in each passband.
Definition: Passband.C:47
Angle get_tracking_angle() const
Get the position angle tracked by the receiver.
Definition: Receiver.h:85
Coherent dedispersion attributes specific to output frequency channel.
Definition: CoherentDedispersion.h:62
Signal::Basis get_basis() const
Get the basis of the feed receptors.
Definition: Receiver.h:100
Stores pulsar parameters as uninterpreted text.
Definition: ObsDescription.h:24
double get_value() const
numerical value of the information
Definition: Pointing.h:149
double get_centre_frequency() const
Centre frequency of output channel.
Definition: CoherentDedispersion.h:68
Signal::Dimension get_domain() const
Domain in which the algorithm operates (time or frequency)
Definition: CoherentDedispersion.h:161
const std::vector< float > & get_passband(unsigned ipol, unsigned iband=0) const
Get the specified passband.
Definition: Passband.C:95
std::string get_description() const
Description of the algorithm.
Definition: CoherentDedispersion.h:165
Extra pointing information.
Definition: Pointing.h:125
double get_rotation_measure() const
Get the auxiliary rotation measure.
Definition: AuxColdPlasmaMeasures.C:41
Angle get_telescope_zenith() const
Get the Telescope zenith angle at subint centre.
Definition: Pointing.C:180
Record of phase-coherent dispersion removal algorithm.
Definition: CoherentDedispersion.h:27
float get_weight(unsigned ichan) const
Get the Profile weight attribute of the given channel.
Definition: Integration.C:388
Estimate< double > get_S_sys(unsigned receptor) const
Get the system equivalent flux density of the specified channel.
Definition: FluxCalibratorExtension.C:131
double ant_z
Antenna ITRF Z-coordinate.
Definition: ITRFExtension.h:80
International Terrestrial Reference Frame Extension.
Definition: ITRFExtension.h:27
std::string cal_mode
Cal mode (As defined by the ATNF TCS: OFF, SYNC, EXT1, EXT2)
Definition: CalInfoExtension.h:55
virtual double get_duration() const =0
Get the total time integrated (in seconds)
Angle get_telescope_azimuth() const
Get the Telescope azimuth at subint centre.
Definition: Pointing.C:169
unsigned get_M() const
Get the base integration factor used in the SK statistic.
Definition: SpectralKurtosis.C:105
Definition: MoreProfiles.h:24
Spectral Kurtosis Staticstics calculated during observation.
Definition: SpectralKurtosis.h:25
Array of Profiles integrated over the same time interval.
Definition: Integration.h:37
std::string project_ID
Project ID.
Definition: ObsExtension.h:84
double get_maximum_frequency() const
Get the maximum frequency of the interpolator.
Definition: CalibrationInterpolatorExtension.h:117
double ant_y
Antenna ITRF Y-coordinate.
Definition: ITRFExtension.h:77
Stores PSRFITS SUBINT header parameters.
Definition: FITSSUBHdrExtension.h:28
std::string ibeam
Beam number for multibeam systems (1=ctr beam)
Definition: FITSHdrExtension.h:163
double bmin
Beam minor axis length.
Definition: FITSHdrExtension.h:247
double get_local_sidereal_time() const
Get the LST (in seconds) at subint centre.
Definition: Pointing.C:72
double ant_x
Antenna ITRF X-coordinate.
Definition: ITRFExtension.h:74
CalibratorStokes::CouplingPoint get_coupling_point() const
The point where the reference source signal is coupled.
Definition: CalibrationInterpolatorExtension.h:69
Stores PolnCalibrator parameters in an Archive instance.
Definition: PolnCalibratorExtension.h:28
unsigned get_nsamp() const
Number of complex time samples in each cyclical convolution.
Definition: CoherentDedispersion.h:78
Stores digitizer histograms.
Definition: DigitiserCounts.h:25
std::string get_param_name(unsigned) const
Get the name of the specified model parameter.
Definition: PolnCalibratorExtension.C:248
double get_Index(unsigned subint) const
Get the custom index value associated with an Integration.
Definition: IntegrationOrder.C:68
double get_bandwidth() const
Bandwidth of input channel.
Definition: CoherentDedispersion.h:129
std::string stt_date
Start UT date (YYYY-MM-DD)
Definition: FITSHdrExtension.h:214
Solution * get_solution(unsigned c)
Get the solution for the specified frequency channel.
Definition: FluxCalibratorExtension.C:98
Observation Information Extension.
Definition: ObsExtension.h:29
Angle get_feed_angle() const
Get the Feed angle at subint centre.
Definition: Pointing.C:136
bool get_has_covariance() const
Get if the covariances of the transformation parameters.
Definition: PolnCalibratorExtension.C:133
unsigned get_npol() const
Get the number of polarizations.
Definition: SpectralKurtosis.h:87
Stores digitizer statistics.
Definition: DigitiserStatistics.h:25
unsigned get_nfit() const
Get the number of model parameters varied to find best fit.
Definition: PolnCalibratorExtension.C:351
double get_doppler_correction() const
Doppler shift correction applied to frequencies and bandwidths.
Definition: CoherentDedispersion.h:173
double cal_dutycycle
Calibrator duty-cycle.
Definition: CalInfoExtension.h:61
std::string observer
Observer name.
Definition: ObsExtension.h:78
Estimate< double > get_S_cal(unsigned receptor) const
Get the calibrator flux density of the specified channel.
Definition: FluxCalibratorExtension.C:151
unsigned get_nfree() const
Get the number of degrees of freedom.
Definition: PolnCalibratorExtension.C:341
virtual std::string get_name() const
Return the name of the calibrator type.
Definition: CalibratorType.h:46
std::string get_extension_name() const
Return the name of the Extension.
Definition: Archive.C:145
Flux Calibrator Extension.
Definition: FluxCalibratorExtension.h:28
bool get_valid(unsigned ichan) const
Return true if the transformation for the specified channel is valid.
Definition: PolnCalibratorExtension.C:110
Estimate< double > get_gain_ratio(unsigned receptor) const
Get the gain ratio of the specified channel.
Definition: FluxCalibratorExtension.C:183
unsigned get_nchan_input() const
Number of frequency channels in the input signal.
Definition: CoherentDedispersion.h:185
std::string trk_mode
Track mode (TRACK, SCANGC, SCANLAT)
Definition: FITSHdrExtension.h:211
MJD get_minimum_epoch() const
Get the minimum epoch of the interpolator.
Definition: CalibrationInterpolatorExtension.h:93
unsigned get_nsamp_overlap_pos() const
Number of complex time samples in wrap-around region, left-hand side.
Definition: CoherentDedispersion.h:83
const Type * ptr() const
double get_chisq() const
Get the best fit value of chi squared.
Definition: PolnCalibratorExtension.C:331
Tracking get_tracking_mode() const
Get the tracking mode of the receiver platform.
Definition: Receiver.h:80
double obsbw
Observed bandwidth.
Definition: FITSHdrExtension.h:226
std::string get_Unit() const
Return a string describing the units of this state.
Definition: IntegrationOrder.C:45
static unsigned verbose
A verbosity flag that can be set for debugging purposes.
Definition: IntegrationManager.h:38
bool has_scale() const
Returns true if scale and gain_ratio data are available.
Definition: FluxCalibratorExtension.h:89
static void delete_hdu(fitsfile *, const char *hdu_name)
Delete the HDU with the specified name.
Definition: delete_hdu.C:19
unsigned get_npol() const
Get the number of polarizations.
Definition: Passband.C:53
std::vector< std::vector< double > > get_covariance() const
Get the covariance matrix of the model paramters.
Definition: PolnCalibratorExtension.C:371
unsigned get_excision_threshold() const
Get the excision threshold in terms of std deviations.
Definition: SpectralKurtosis.C:120
double get_dispersion_measure() const
Get the auxiliary dispersion measure.
Definition: AuxColdPlasmaMeasures.C:29
MJD get_maximum_epoch() const
Get the maximum epoch of the interpolator.
Definition: CalibrationInterpolatorExtension.h:98
Defines the PSRCHIVE library.
Definition: CalSource.h:17
Stores Polarization Calibration Model Interpolator information.
Definition: CalibrationInterpolatorExtension.h:29
const Profile * get_Profile(const Archive *data, Index subint, Index pol, Index chan)
Return the requested profile, cloning and integrating when needed.
Definition: Index.C:24
const std::string & get_name() const
name of the information
Definition: Pointing.h:137
std::string coordmode
Coordinate mode (EQUAT, GAL, ECLIP, AZEL, HADEC)
Definition: FITSHdrExtension.h:205
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
Angle get_reference_source_phase() const
Get the phase of the reference source.
Definition: Receiver.h:122
Stokes< Estimate< float > > get_stokes(unsigned ichan) const
Get the Stokes parameters of the specified frequency channel.
Definition: CalibratorStokes.C:107
Stores parameters used to correct auxiliary dispersion and birefringence.
Definition: AuxColdPlasmaMeasures.h:24
CouplingPoint get_coupling_point() const
The point where the reference source signal is coupled.
Definition: CalibratorStokes.C:55
double equinox
Equinox of coordinates.
Definition: FITSHdrExtension.h:208
Estimate< double > get_scale(unsigned receptor) const
Get the flux scale of the specified channel.
Definition: FluxCalibratorExtension.C:171
static void unload(fitsfile *, const FITSHdrExtension *)
Unload FITSHdrExtension to the current HDU of the specified FITS file.
Definition: unload_FITSHdrExtension.C:18
virtual double get_folding_period() const =0
Get the folding or topocentric pulsar period (in seconds)
unsigned get_nchan_output() const
Number of frequency channels into which this channel was divided.
Definition: CoherentDedispersion.h:134
unsigned get_nsub_input() const
Get the number of epochs in input data.
Definition: CalibrationInterpolatorExtension.h:82
Stores information about the reference source (ATNF)
Definition: CalInfoExtension.h:28
float get_unfiltered_sum(unsigned ichan, unsigned ipol) const
Get the unfiltered sum of the specified channel and polarization.
Definition: SpectralKurtosis.C:167
Definition: FourthMoments.h:24
Alternative ways of ordering Integration instances.
Definition: IntegrationOrder.h:29
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
double bpa
Beam position angle.
Definition: FITSHdrExtension.h:241
int get_ncycsub(void) const
get ncycsub
Definition: DigitiserStatistics.h:74
Signal::Hand get_hand() const
Get the hand of the basis.
Definition: Receiver.h:117
Telescope pointing parameters recorded during the observation.
Definition: Pointing.h:27
MJD get_reference_epoch() const
Get the reference epoch of the interpolator.
Definition: CalibrationInterpolatorExtension.h:88
virtual unsigned get_size() const
get the size of the profile vector
Definition: MoreProfiles.C:44
unsigned get_nreceptor() const
Get the number of receptors in flux calibrator.
Definition: CalibrationInterpolatorExtension.h:75
bool get_native_scale() const
Returns true if scale is native, false if scale is relative.
Definition: CalibrationInterpolatorExtension.h:78
int cal_nstate
Number of different states during cal period.
Definition: CalInfoExtension.h:67
Intermediate storage of MEAL::Complex parameters.
Definition: PolnCalibratorExtension.h:135
unsigned get_nreceptor() const
Get the number of receptors.
Definition: FluxCalibratorExtension.C:90

Generated using doxygen 1.8.17