FITSOutputFile.h
1 /***************************************************************************
2  *
3  * Copyright (C) 2015 by Matthew Kerr
4  * Licensed under the Academic Free License version 2.1
5  *
6  ***************************************************************************/
7 
8 // This is a bit a of kluge. Use a psrchive/FITSArchive to handle writing
9 // out all of the extensions -- this way we can take advantage of the
10 // development done there. This all happens in "write header".
11 
12 // Then we do the data separately, writing rows directly through cfitsio.
13 
14 // NB -- we need to deal with the reference spectrum, somehow. It would
15 // be a REALLY GOOD idea to set tblk to the same value as the Rescale
16 // operation!
17 
18 // Recall the PSRFITS output is in TPF order.
19 
20 // TODO -- since the user can set nbit/nsblk, the instance can be made
21 // inconsistent if these methods are called after initialize
22 
23 #ifndef __FITSOutputFile_h
24 #define __FITSOutputFile_h
25 
26 #include "dsp/OutputFile.h"
27 #include <fitsio.h>
28 
29 namespace dsp {
30 
31  class FITSDigitizer;
32 
33  int get_colnum (fitsfile* fptr, const char* label);
34 
36  class FITSOutputFile : public OutputFile
37  {
38  public:
39 
41  FITSOutputFile (const char* filename=0);
42 
43  ~FITSOutputFile ();
44 
47 
49  void set_nsblk ( unsigned nblk );
50 
52  void set_nbit ( unsigned _nbit );
53 
55  void set_atnf ( bool );
56 
58  void set_upper_sideband_output ( bool );
59 
61  void set_mangle_output ( bool );
62 
64  void set_max_length( double );
65 
66  protected:
67 
69  virtual void operation ();
70 
72  void write_header ();
73 
75  void finalize_fits ();
76 
78  std::string get_extension () const;
79 
81  virtual int64_t unload_bytes (const void* buffer, uint64_t bytes);
82 
84  void write_bytes (int colnum, int isub, int offset, unsigned bytes_to_write, unsigned char** buffer);
85 
87  unsigned nsblk;
88 
90  unsigned nbblk;
91 
93  double tblk;
94 
96  unsigned nbit;
97 
99  unsigned npol;
100 
102  unsigned nchan;
103 
105  double max_length;
106 
108  std::vector<float> dat_wts;
109 
111  std::vector<float> dat_scl;
112 
114  std::vector<float> dat_offs;
115 
117  std::vector<double> dat_freq;
118 
120  fitsfile* fptr;
121 
123  unsigned isub;
124 
125  private:
126 
128  unsigned offset;
129 
131  int64_t written;
132 
134  int64_t max_bytes;
135 
137  void initialize ();
138 
140  void write_row ();
141 
143  bool use_atnf;
144 
146  bool mangle_output;
147  std::string mangled_output_filename;
148 
150  int64_t samples_written;
151 
153  bool upper_sideband_output;
154 
155  };
156 
157 }
158 
159 #endif
160 
void set_coordmode(const std::string &mode)
void set_date_str(const std::string &date)
unsigned nchan
convenience store channel nuumber
Definition: FITSOutputFile.h:107
unsigned nsblk
samples per block (FITS row)
Definition: FITSOutputFile.h:92
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
unsigned nbblk
bytes per block
Definition: FITSOutputFile.h:95
void set_nsblk(unsigned nblk)
Set the number of samples per output block.
Definition: FITSOutputFile.C:150
void write_bytes(int colnum, int isub, int offset, unsigned bytes_to_write, unsigned char **buffer)
Interface to CFITSIO with error checking and bookkeeping.
Definition: FITSOutputFile.C:121
void set_obsnchan(int set_obsnchan)
FITSOutputFile(const char *filename=0)
Construct and open file.
Definition: FITSOutputFile.C:90
void set_basis(Signal::Basis basis)
std::vector< double > dat_freq
buffer for channel frequencies
Definition: FITSOutputFile.h:122
void set_name(const std::string &_name)
void write_header()
Write out all of the FITS extensions.
Definition: FITSOutputFile.C:172
void set_argument(Signal::Argument)
double max_length
maximum length of output file
Definition: FITSOutputFile.h:110
Pure virtual base class of all objects that can unload BitSeries data.
Definition: OutputFile.h:30
virtual int64_t unload_bytes(const void *buffer, uint64_t bytes)
Write nbyte bytes with cfitsio.
Definition: FITSOutputFile.C:504
std::string output_filename
The name of the output file.
Definition: OutputFile.h:59
void set_reference_spectrum(FITSDigitizer *)
Use Rescale callback to set reference spectrum.
Definition: FITSOutputFile.C:600
const ScalarMath pow(const ScalarMath &x, const ScalarMath &y)
unsigned isub
current subint
Definition: FITSOutputFile.h:128
Type * get() const
std::vector< float > dat_offs
buffer for channel offsets
Definition: FITSOutputFile.h:119
writes BitSeries data to a PSRFITS "search mode" file
Definition: FITSOutputFile.h:41
void set_nbit(unsigned _nbit)
Set the number of bits per output sample.
Definition: FITSOutputFile.C:158
void set_name(const std::string &name)
void set_mangle_output(bool)
Set output mangling.
Definition: FITSOutputFile.C:140
std::vector< float > dat_wts
buffer for channels weights
Definition: FITSOutputFile.h:113
virtual void operation()
Need a custom implementation of operation to handle FITS I/O.
Definition: FITSOutputFile.C:460
void finalize_fits()
Write metadata after data output and close fits file.
Definition: FITSOutputFile.C:575
fitsfile * fptr
FITS file handle.
Definition: FITSOutputFile.h:125
unsigned npol
convenience store npol
Definition: FITSOutputFile.h:104
std::string get_extension() const
Get the extension to be added to the end of new filenames.
Definition: FITSOutputFile.C:167
Converts floating point values to N-bit PSRFITS search-mode format.
Definition: FITSDigitizer.h:25
std::vector< float > dat_scl
buffer for channel scales
Definition: FITSOutputFile.h:116
void set_downconversion_corrected(bool corrected=true)
void set_obsfreq(double set_obsfreq)
void set_atnf(bool)
Set the output filename convention.
Definition: FITSOutputFile.C:130
const std::string get_message() const
void set_max_length(double)
Set length of output file (seconds)
Definition: FITSOutputFile.C:145
unsigned nbit
bits per sample
Definition: FITSOutputFile.h:101
double tblk
time per block
Definition: FITSOutputFile.h:98
void set_obsbw(double set_obsbw)
void set_upper_sideband_output(bool)
Set the output to upper sideband.
Definition: FITSOutputFile.C:135

Generated using doxygen 1.8.17