HOPS
HOPS class reference
MHO_MK4StationInterface.hh
Go to the documentation of this file.
1 #ifndef MHO_MK4StationInterface_HH__
2 #define MHO_MK4StationInterface_HH__
3 
4 #include <cstdlib>
5 #include <cstring>
6 #include <map>
7 #include <set>
8 #include <string>
9 #include <vector>
10 
12 #include "MHO_MK4VexInterface.hh"
13 
14 #include "MHO_Message.hh"
15 
16 //forward declaration of mk4_corel and vex structs
17 //we do this to keep the mk4 structures from 'leaking' into the new code via includes,
18 //We want to make sure any interface to the old mk4 IO libraries is kept only
19 //within the MK4Interface library (and primarily in the .cc files).
20 #ifndef HOPS3_USE_CXX
21 extern "C"
22 {
23 #endif
27  struct mk4_sdata;
31  struct type_309;
32 #ifndef HOPS3_USE_CXX
33 }
34 #endif
35 
36 namespace hops
37 {
38 
48 {
49  public:
51  virtual ~MHO_MK4StationInterface();
52 
58  void SetVexFile(const std::string& vex) { fVexFile = vex; }
59 
65  void SetStationFile(const std::string& station) { fStationFile = station; }
66 
72  mk4_sdata* GetStationData() { return fStation; };
73 
80 
86  multitone_pcal_type* GetPCalObject() { return &fAllPCalData; }
87 
88  private:
96  std::string getstr(const char* char_array, std::size_t max_size)
97  {
98  return std::string(char_array, std::min(strlen(char_array), max_size));
99  }
100 
104  void ReadStationFile();
108  void ReadVexFile();
109 
110  //pcal stuff
117  void ExtractPCal(int n309, type_309** t309);
127  void FillPCalArray(const std::string& pol, int pol_idx, multitone_pcal_type* pc, int n309, type_309** t309);
128 
129  //builds a visibility channel axis from the ovex info for each pol
135  std::map< std::string, channel_axis_type > ConstructPerPolChannelAxis();
136 
142  std::map< std::string, std::vector< mho_json > > ConstructChannelInfo();
143 
144  //converts a mk4 channel id into its components, returns true if successful
155  bool ExtractChannelInfo(const std::string& ch_name, std::string& fgroup, std::string& sb, std::string& pol, int& index);
162  std::string FreqGroupFromMK4ChannelID(std::string id) const;
169  std::string PolFromMK4ChannelID(std::string id) const;
176  std::string SidebandFromMK4ChannelId(std::string id) const;
183  int IndexFromMK4ChannelId(std::string id) const;
184 
185  //converts uint32_t counts to complex double
195  std::complex< double > ComputePhasor(uint32_t real, uint32_t imag, double acc_period, double sample_period);
196 
197  //returns a vector of freq group codes found in the 309 data
198  std::vector< std::string > GetFreqGroups(int n309, type_309** t309);
199  //returns a vector of pols and tone-count for each pol found in 309 data
200  std::vector< std::pair< std::string, int > > GetFreqGroupPolInfo(int n309, type_309** t309, const std::string& fg,
201  bool& same_size);
202 
209  void TagPCalStartTime(int n309, type_309** t309);
210 
214  bool ROTIsCentroid() const;
215 
219  bool TonesInDescendingOrder(type_309* t309, int start, int stop) const;
220 
224  static int DaysInYear(int year);
225 
226  bool fHaveStation;
227  struct mk4_sdata* fStation;
228  std::string fStationName;
229  std::string fStationCode;
230  std::string fStationMK4ID;
231 
232  //all pcal data
233  multitone_pcal_type fAllPCalData;
234 
235  std::string fStationFile;
236  std::string fVexFile;
237  std::string fRootCode;
238  std::size_t fNCoeffs;
239  std::size_t fNIntervals;
240  std::size_t fNCoord;
241 
242  //vex info
243  bool fHaveVex;
244  mho_json fVex;
245 
246  //comparison predicate for sorting channel frequency info
247  struct ChannelLess
248  {
249  bool operator()(const mho_json& a, const mho_json& b) const
250  {
251  double a_freq = a["sky_freq"].get< double >();
252  double b_freq = b["sky_freq"].get< double >();
253  double a_bw = a["bandwidth"].get< double >();
254  double b_bw = b["bandwidth"].get< double >();
255  std::string a_sb = a["net_sideband"].get< std::string >();
256  std::string b_sb = b["net_sideband"].get< std::string >();
257 
258  double a_sgn = 0;
259  if(a_sb == "L")
260  {
261  a_sgn = -1.0;
262  }
263  if(a_sb == "U")
264  {
265  a_sgn = 1.0;
266  }
267 
268  double b_sgn = 0;
269  if(b_sb == "L")
270  {
271  b_sgn = -1.0;
272  }
273  if(b_sb == "U")
274  {
275  b_sgn = 1.0;
276  }
277 
278  double a_center_freq = a_freq + a_bw * a_sgn / 2.0;
279  double b_center_freq = b_freq + b_bw * b_sgn / 2.0;
280 
281  return a_center_freq < b_center_freq;
282  }
283  };
284 
285  ChannelLess fChannelPredicate;
286 };
287 
288 } // namespace hops
289 
290 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
MHO_MK4StationInterface converts a mk4 station file (type_3xx) to HOPS4 format.
Definition: MHO_MK4StationInterface.hh:48
MHO_MK4StationInterface()
Definition: MHO_MK4StationInterface.cc:37
void SetVexFile(const std::string &vex)
Setter for vex file.
Definition: MHO_MK4StationInterface.hh:58
station_coord_type * ExtractStationFile()
Extracts station coordinate data from files and allocates memory for it.
Definition: MHO_MK4StationInterface.cc:69
mk4_sdata * GetStationData()
Getter for station data.
Definition: MHO_MK4StationInterface.hh:72
virtual ~MHO_MK4StationInterface()
Definition: MHO_MK4StationInterface.cc:47
void SetStationFile(const std::string &station)
Setter for station file.
Definition: MHO_MK4StationInterface.hh:65
multitone_pcal_type * GetPCalObject()
Getter for pcal object.
Definition: MHO_MK4StationInterface.hh:86
Class MHO_TableContainer.
Definition: MHO_TableContainer.hh:36
#define min(a, b)
Definition: max555.c:9
Definition: mk4_data.h:108
Definition: MHO_AdhocFlagging.hh:18
MHO_TableContainer< pcal_phasor_type, multitone_pcal_axis_type > multitone_pcal_type
Definition: MHO_StationContainers.hh:30
Definition: type_309.h:34
Definition: vex.h:28