load_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/load_text.h
10 
11 #ifndef __load_text_h
12 #define __load_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 load_text (fitsfile* fptr, const char* table, const char* column,
24  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  long numrows = 0;
35  fits_get_num_rows (fptr, &numrows, &status);
36 
37  if (status)
38  throw FITSError (status, "load_text",
39  "fits_get_num_rows %s", table);
40 
41  if (!numrows)
42  throw Error (InvalidParam, "load_text", "no rows in table");
43 
44  int colnum = 0;
45  fits_get_colnum (fptr, CASEINSEN, const_cast<char*>(column),
46  &colnum, &status);
47 
48  int typecode = 0;
49  long repeat = 0;
50  long width = 0;
51 
52  fits_get_coltype (fptr, colnum, &typecode, &repeat, &width, &status);
53 
54  if (typecode != TSTRING)
55  throw Error (InvalidState, "load_text",
56  "%s typecode != TSTRING", column);
57 
58  std::vector<char> text (repeat);
59  char* temp = &(text[0]);
60 
61  FilePtr stream = tmpfile();
62 
63  for (int row=1; row <= numrows; row++)
64  {
65  int anynul = 0;
66  fits_read_col (fptr, TSTRING, colnum, row, 1, 1, 0,
67  &temp, &anynul, &status);
68 
69  if (status)
70  throw FITSError (status, "load_text", "fits_read_col");
71 
72  char* newline = strchr (temp, '\n');
73  if (newline)
74  *newline = '\0';
75 
76  fprintf (stream, "%s\n", temp);
77  }
78 
79  fseek (stream, 0, SEEK_SET);
80 
81  instance->load (stream);
82 
83  if (verbose)
84  {
85  std::cerr << "load_text loaded" << std::endl;
86  instance->unload (stderr);
87  }
88 }
89 
90 #endif
double evaluate(std::vector< double > *grad=0) const
void fit(const Pulsar::Parameters *model, std::vector< toa > &data, Pulsar::Parameters *postfit=NULL, bool track=false, Tempo::toa::State min_state=Tempo::toa::Normal)
double cal_frequency
Calibrator frequency.
Definition: CalInfoExtension.h:58
void set_centre_frequency(double val)
Centre frequency of output channel.
Definition: CoherentDedispersion.h:70
Loads and unloads PSRFITS archives.
Definition: FITSArchive.h:63
Draw a set of profiles for subints stacked ontop of eachother.
Definition: LinePhasePlot.h:36
Warning warning
Warning messages filter.
Definition: Pulsar.C:12
void load_Pointing(fitsfile *, int row, Integration *)
Definition: load_Pointing.C:46
void covariance(Scalar *function, unsigned index, std::vector< unsigned > &imap, std::vector< std::vector< double > > &covar)
Coherent dedispersion attributes specific to input frequency channel.
Definition: CoherentDedispersion.h:118
int get_ndigr(void) const
get_ndigr
Definition: DigitiserStatistics.h:62
void resize(unsigned nbin)
Resize the data area.
Definition: MoreProfiles.C:82
virtual void add_extension(Extension *extension)
Add an Extension to the Archive instance.
Definition: Archive.C:186
Transformation * get_transformation(unsigned c)
Get the transformation for the specified frequency channel.
Definition: PolnCalibratorExtension.C:157
unsigned get_nparam() const
void set_bandwidth(double val)
Bandwidth of input channel.
Definition: CoherentDedispersion.h:131
void set_nsamp_overlap_neg(unsigned val)
Number of complex time samples in wrap-around region, right-hand side.
Definition: CoherentDedispersion.h:90
virtual unsigned get_nchan() const
Get the number of frequency channels.
Definition: CalibratorExtension.C:83
void load_Plasma(fitsfile *, int row, Integration *)
Definition: load_Plasma.C:17
char code(const std::string &telescope_name)
virtual void print(std::string &text) const
Value get_Value(const Type &value)
int get_npar(void) const
get npar
Definition: DigitiserStatistics.h:68
virtual void add_extension(Extension *extension)
Add an Extension to the Integration instance.
Definition: Integration.C:90
Type * release()
Stores PSRFITS header extensions.
Definition: FITSHdrExtension.h:25
Type * get() const
void set_value(const Type &value)
Coherent dedispersion attributes specific to output frequency channel.
Definition: CoherentDedispersion.h:62
ReferenceFluxDensity
Extra pointing information.
Definition: Pointing.h:125
Spectral Kurtosis Staticstics calculated during observation.
Definition: SpectralKurtosis.h:25
Array of Profiles integrated over the same time interval.
Definition: Integration.h:37
static bool verbose
void load_state(fitsfile *)
Definition: load_integration_state.C:284
void set_has_solver(bool)
Set if the covariances of the transformation parameters.
Definition: PolnCalibratorExtension.C:150
void set_nfree(unsigned)
Set the number of degress of freedom.
Definition: PolnCalibratorExtension.C:346
Stores PSRFITS SUBINT header parameters.
Definition: FITSSUBHdrExtension.h:28
void set_variance(unsigned index, double value)
Stores PolnCalibrator parameters in an Archive instance.
Definition: PolnCalibratorExtension.h:28
Stores digitizer histograms.
Definition: DigitiserCounts.h:25
void set_nfit(unsigned)
Set the number of model parameters varied to find best fit.
Definition: PolnCalibratorExtension.C:356
void load_SpectralKurtosis(fitsfile *, int row, Integration *)
Definition: load_SpectralKurtosis.C:18
Stores digitizer statistics.
Definition: DigitiserStatistics.h:25
bool verbose
Definition: timer++.C:25
virtual Integration * load_Integration(const char *filename, unsigned subint)
Load the specified Integration from filename, returning new instance.
Definition: load_Integration.C:37
void set_covariance(const std::vector< std::vector< double > > &)
Set the covariance matrix of the model paramters.
Definition: PolnCalibratorExtension.C:399
bool get_valid(unsigned ichan) const
Return true if the transformation for the specified channel is valid.
Definition: PolnCalibratorExtension.C:110
void set_nsamp_overlap_pos(unsigned val)
Number of complex time samples in wrap-around region, left-hand side.
Definition: CoherentDedispersion.h:85
static unsigned verbose
A verbosity flag that can be set for debugging purposes.
Definition: IntegrationManager.h:38
void set_centre_frequency(double val)
Centre frequency of input channel.
Definition: CoherentDedispersion.h:126
const std::string get_message() const
Defines the PSRCHIVE library.
Definition: CalSource.h:17
Stores Polarization Calibration Model Interpolator information.
Definition: CalibrationInterpolatorExtension.h:29
void set_variance(unsigned, double)
Set the variance of the specified model parameter.
Definition: PolnCalibratorExtension.C:304
const std::string & get_name() const
name of the information
Definition: Pointing.h:137
Stores parameters used to correct auxiliary dispersion and birefringence.
Definition: AuxColdPlasmaMeasures.h:24
MJD get_start_time() const
Get the start time.
Definition: FITSHdrExtension.h:125
void load_Pointing_columns(fitsfile *fptr)
Load additional Pointing::Info column information, if any.
Definition: load_Pointing_columns.C:14
void set_chisq(double)
Set the best fit value of chi squared.
Definition: PolnCalibratorExtension.C:336
unsigned get_nchan_output() const
Number of frequency channels into which this channel was divided.
Definition: CoherentDedispersion.h:134
Stores information about the reference source (ATNF)
Definition: CalInfoExtension.h:28
void set_argument(unsigned dimension, Argument *axis)
void set_bandwidth(double val)
Bandwidth of output channel.
Definition: CoherentDedispersion.h:75
void set_nsamp(unsigned val)
Number of complex time samples in each cyclical convolution.
Definition: CoherentDedispersion.h:80
void set_has_covariance(bool)
Set if the covariances of the transformation parameters.
Definition: PolnCalibratorExtension.C:138
Definition: FourthMoments.h:24
int get_ncycsub(void) const
get ncycsub
Definition: DigitiserStatistics.h:74
Telescope pointing parameters recorded during the observation.
Definition: Pointing.h:27

Generated using doxygen 1.8.17