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 
49 {
50  public:
52  virtual ~MHO_MK4StationInterface();
53 
59  void SetVexFile(const std::string& vex) { fVexFile = vex; }
60 
66  void SetStationFile(const std::string& station) { fStationFile = station; }
67 
73  mk4_sdata* GetStationData() { return fStation; };
74 
81 
87  multitone_pcal_type* GetPCalObject() { return &fAllPCalData; }
88 
89  private:
97  std::string getstr(const char* char_array, std::size_t max_size)
98  {
99  return std::string(char_array, std::min(strlen(char_array), max_size));
100  }
101 
105  void ReadStationFile();
109  void ReadVexFile();
110 
111  //pcal stuff
118  void ExtractPCal(int n309, type_309** t309);
128  void FillPCalArray(const std::string& pol, int pol_idx, multitone_pcal_type* pc, int n309, type_309** t309);
129 
130  //builds a visibility channel axis from the ovex info for each pol
136  std::map< std::string, channel_axis_type > ConstructPerPolChannelAxis();
137 
143  std::map< std::string, std::vector< mho_json > > ConstructChannelInfo();
144 
145  //converts a mk4 channel id into its components, returns true if successful
156  bool ExtractChannelInfo(const std::string& ch_name, std::string& fgroup, std::string& sb, std::string& pol, int& index);
163  std::string FreqGroupFromMK4ChannelID(std::string id) const;
170  std::string PolFromMK4ChannelID(std::string id) const;
177  std::string SidebandFromMK4ChannelId(std::string id) const;
184  int IndexFromMK4ChannelId(std::string id) const;
185 
186  //converts uint32_t counts to complex double
196  std::complex< double > ComputePhasor(uint32_t real, uint32_t imag, double acc_period, double sample_period);
197 
198  //returns a vector of freq group codes found in the 309 data
199  std::vector< std::string > GetFreqGroups(int n309, type_309** t309);
200  //returns a vector of pols and tone-count for each pol found in 309 data
201  std::vector< std::pair< std::string, int > > GetFreqGroupPolInfo(int n309, type_309** t309, const std::string& fg,
202  bool& same_size);
203 
204  bool fHaveStation;
205  struct mk4_sdata* fStation;
206  std::string fStationName;
207  std::string fStationCode;
208  std::string fStationMK4ID;
209 
210  //all pcal data
211  multitone_pcal_type fAllPCalData;
212 
213  std::string fStationFile;
214  std::string fVexFile;
215  std::string fRootCode;
216  std::size_t fNCoeffs;
217  std::size_t fNIntervals;
218  std::size_t fNCoord;
219 
220  //vex info
221  bool fHaveVex;
222  mho_json fVex;
223 
224  //comparison predicate for sorting channel frequency info
225  struct ChannelLess
226  {
227  bool operator()(const mho_json& a, const mho_json& b) const
228  {
229  double a_freq = a["sky_freq"].get< double >();
230  double b_freq = b["sky_freq"].get< double >();
231  double a_bw = a["bandwidth"].get< double >();
232  double b_bw = b["bandwidth"].get< double >();
233  std::string a_sb = a["net_sideband"].get< std::string >();
234  std::string b_sb = b["net_sideband"].get< std::string >();
235 
236  double a_sgn = 0;
237  if(a_sb == "L")
238  {
239  a_sgn = -1.0;
240  }
241  if(a_sb == "U")
242  {
243  a_sgn = 1.0;
244  }
245 
246  double b_sgn = 0;
247  if(b_sb == "L")
248  {
249  b_sgn = -1.0;
250  }
251  if(b_sb == "U")
252  {
253  b_sgn = 1.0;
254  }
255 
256  double a_center_freq = a_freq + a_bw * a_sgn / 2.0;
257  double b_center_freq = b_freq + b_bw * b_sgn / 2.0;
258 
259  return a_center_freq < b_center_freq;
260  }
261  };
262 
263  ChannelLess fChannelPredicate;
264 };
265 
266 } // namespace hops
267 
268 #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:49
MHO_MK4StationInterface()
Definition: MHO_MK4StationInterface.cc:37
void SetVexFile(const std::string &vex)
Setter for vex file.
Definition: MHO_MK4StationInterface.hh:59
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:73
virtual ~MHO_MK4StationInterface()
Definition: MHO_MK4StationInterface.cc:47
void SetStationFile(const std::string &station)
Setter for station file.
Definition: MHO_MK4StationInterface.hh:66
multitone_pcal_type * GetPCalObject()
Getter for pcal object.
Definition: MHO_MK4StationInterface.hh:87
Class MHO_TableContainer.
Definition: MHO_TableContainer.hh:36
#define min(a, b)
Definition: max555.c:9
Definition: mk4_data.h:108
Definition: MHO_ChannelLabeler.hh:17
MHO_TableContainer< pcal_phasor_type, multitone_pcal_axis_type > multitone_pcal_type
Definition: MHO_StationContainers.hh:30
Definition: type_309.h:33
Definition: vex.h:28