Open source Very Long Baseline Interferometry
OpenVLBI
vlbi_server.h
1 /* OpenVLBI - Open Source Very Long Baseline Interferometry
2 * Copyright © 2017-2022 Ilia Platone
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #ifndef VLBI_SERVER_H
20 #define VLBI_SERVER_H
21 
22 #include <vlbi.h>
23 #include <dsp.h>
24 
25 #ifdef _WIN32
26 #define restrict __restrict
27 extern ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim, FILE *restrict stream);
28 #endif
29 
30 namespace VLBI
31 {
32 
50 typedef enum
51 {
61 
65 class Server
66 {
67  public:
71  Server(void);
75  virtual ~Server(void);
76 
82  virtual int Init(int argc, char** argv)
83  {
84  (void)argc;
85  (void)argv;
86  return 1;
87  }
88 
92  virtual void Parse(void);
93 
98  void addContext(const char *name);
99 
104  void delContext(const char *name);
105 
110  void setContext(const char *name);
111 
116  vlbi_context getContext(void);
117 
122  inline char* currentContext(void)
123  {
124  return context;
125  }
126 
133  void addModel(const char *name, char *format, char *b64);
134 
140  dsp_stream_p getModel(const char *name);
141 
148  char* getModel(const char *name, char *format);
149 
154  void delModel(const char *name);
155 
161  int getModels(char** names);
162 
168  void addNode(const char *name, char *b64);
169 
175  void addNodes(const char *name, char *b64);
176 
186  void addNode(const char *name, dsp_location *locations, void *buf, int len, timespec starttime, bool geo);
187 
192  void delNode(const char *name);
193 
199  void CopyNode(const char *name, const char *node);
200 
206  void Plot(const char *name, int flags);
207 
214  void Idft(const char *name, const char *magnitude, const char *phase);
215 
222  void Dft(const char *name, const char *magnitude, const char *phase);
223 
230  void Mask(const char *name, const char *model, const char *mask);
231 
238  void Stack(const char *name, const char *model1, const char *model2);
239 
245  void Copy(const char *name, const char *model);
246 
253  void Diff(const char *name, const char *model1, const char *model2);
254 
261  void Convolute(const char *name, const char *model1, const char *model2);
262 
269  void LowPass(const char *name, const char *node, double freq);
270 
277  void HighPass(const char *name, const char *node, double freq);
278 
286  void BandPass(const char *name, const char *node, double lofreq, double hifreq);
287 
295  void BandReject(const char *name, const char *node, double lofreq, double hifreq);
296 
301  void Shift(const char *name);
302 
307  inline virtual void setRa(double value)
308  {
309  Ra = value;
310  }
311 
316  inline virtual void setDec(double value)
317  {
318  Dec = value;
319  }
320 
325  inline virtual void setFreq(double value)
326  {
327  Freq = value;
328  }
329 
334  inline virtual void setSampleRate(double value)
335  {
336  SampleRate = value;
337  }
338 
343  inline virtual void setBps(int value)
344  {
345  Bps = value;
346  }
347 
352  inline virtual void setWidth(int value)
353  {
354  w = value;
355  }
356 
361  inline virtual void setHeight(int value)
362  {
363  h = value;
364  }
365 
370  inline double getRa(void)
371  {
372  return Ra;
373  }
374 
379  inline double getDec(void)
380  {
381  return Dec;
382  }
383 
388  inline double getFreq(void)
389  {
390  return Freq;
391  }
392 
397  inline double getSampleRate(void)
398  {
399  return SampleRate;
400  }
401 
406  void setCorrelationOrder(int order);
407 
412  inline double getBps(void)
413  {
414  return Bps;
415  }
416 
421  inline double getWidth(void)
422  {
423  return w;
424  }
425 
430  inline double getHeight(void)
431  {
432  return h;
433  }
434 
439  void setInput(FILE* in)
440  {
441  input = in;
442  }
443 
448  inline FILE* getInput()
449  {
450  return input;
451  }
452 
457  void setOutput(FILE* out)
458  {
459  output = out;
460  }
461 
466  inline FILE* getOutput()
467  {
468  return output;
469  }
470 
475  inline void setDelegate(vlbi_func2_t func)
476  {
477  delegate = func;
478  }
479 
484  inline vlbi_func2_t getDelegate() { return delegate; }
485 
486  private:
487  vlbi_func2_t delegate;
488  double Ra;
489  double Dec;
490  double Freq;
491  double SampleRate;
492  int Bps;
493  int w;
494  int h;
495  FILE *input, *output;
496  char *context;
497  char *tmpdir { nullptr };
498 };
499 extern VLBI::Server *server;
501 };
502 
503 #endif //VLBI_SERVER_H
VLBI::Server::getRa
double getRa(void)
get the current right ascension coordinate
Definition: vlbi_server.h:370
VLBI::Server::setDec
virtual void setDec(double value)
set the target declination coordinate, do this before calling Plot()
Definition: vlbi_server.h:316
VLBI::Server::getInput
FILE * getInput()
get the input stream
Definition: vlbi_server.h:448
VLBI::Server::BandReject
void BandReject(const char *name, const char *node, double lofreq, double hifreq)
Apply a band reject filter on a node buffer.
VLBI::Server::Convolute
void Convolute(const char *name, const char *model1, const char *model2)
Convolute a model with a convolution matrix model.
VLBI::Server::Stack
void Stack(const char *name, const char *model1, const char *model2)
Stack a model with another model.
VLBI::Server::addContext
void addContext(const char *name)
add a new OpenVLBI context by giving it a name. VLBI::Server has an internal context collection
VLBI::Server::Copy
void Copy(const char *name, const char *model)
Copy a model into another model.
VLBI::Server::Parse
virtual void Parse(void)
main() creates a loop that calls Parse(), you can use this one, which uses the standard syntax or ove...
VLBI::Server::BandPass
void BandPass(const char *name, const char *node, double lofreq, double hifreq)
Apply a band pass filter on a node buffer.
VLBI::Server::CopyNode
void CopyNode(const char *name, const char *node)
Copy a node into another node.
dsp_location_t
The location type.
Definition: dsp.h:340
VLBI::Server::setFreq
virtual void setFreq(double value)
set the frequency observed, do this before calling Plot()
Definition: vlbi_server.h:325
VLBI::Server::Mask
void Mask(const char *name, const char *model, const char *mask)
Mask a model with another model by multiplication.
VLBI::Server::setInput
void setInput(FILE *in)
set the input stream
Definition: vlbi_server.h:439
VLBI::Server::Plot
void Plot(const char *name, int flags)
Plot the current observation into a new model.
VLBI::Server::getModels
int getModels(char **names)
get the names of all the models of the current context.
VLBI::Server::setBps
virtual void setBps(int value)
set the bytes per sample, do this before calling addNode()
Definition: vlbi_server.h:343
VLBI::Server::getDelegate
vlbi_func2_t getDelegate()
get the current delegate function
Definition: vlbi_server.h:484
VLBI::plot_flags_uv_coverage
@ plot_flags_uv_coverage
This will fill all baselines projected pixels with ones.
Definition: vlbi_server.h:55
VLBI::vlbi_plot_flags
vlbi_plot_flags
Flags that characterize a plot.
Definition: vlbi_server.h:50
VLBI::Server::HighPass
void HighPass(const char *name, const char *node, double freq)
Apply a high pass filter on a node buffer.
VLBI::Server::setHeight
virtual void setHeight(int value)
set the plot height, do this before calling Plot()
Definition: vlbi_server.h:361
VLBI::Server::Diff
void Diff(const char *name, const char *model1, const char *model2)
Diff a model with another model.
VLBI::Server::getSampleRate
double getSampleRate(void)
get the current sample rate
Definition: vlbi_server.h:397
VLBI::Server::delNode
void delNode(const char *name)
delete from the current context an existing node by name.
dsp_stream_t
Contains a set of informations and data relative to a buffer and how to use it.
Definition: dsp.h:375
vlbi_func2_t
double(* vlbi_func2_t)(double, double)
The delegate function type to pass to vlbi_plot_uv_plane.
Definition: vlbi.h:342
VLBI::Server::getContext
vlbi_context getContext(void)
Obtain the current OpenVLBI context object.
VLBI::Server::Shift
void Shift(const char *name)
Shift a model by its dimension in-place.
VLBI::Server::delContext
void delContext(const char *name)
delete an existing OpenVLBI context by name.
VLBI::Server::getFreq
double getFreq(void)
get the current frequency
Definition: vlbi_server.h:388
VLBI::Server::addNode
void addNode(const char *name, char *b64)
Create a new node from a monodimensional image FITS file, give it a name and add it to the current co...
VLBI::Server::getHeight
double getHeight(void)
get the plot height
Definition: vlbi_server.h:430
VLBI::plot_flags_synced
@ plot_flags_synced
This indicates that the nodes are synced already and no delay calculation will be done.
Definition: vlbi_server.h:57
VLBI::plot_flags_custom_delegate
@ plot_flags_custom_delegate
This will use a custom visibility delegate.
Definition: vlbi_server.h:59
vlbi_context
void * vlbi_context
the OpenVLBI context object type
Definition: vlbi.h:345
VLBI::Server::LowPass
void LowPass(const char *name, const char *node, double freq)
Apply a low pass filter on a node buffer.
VLBI::Server::getModel
dsp_stream_p getModel(const char *name)
Obtain the dsp_stream_p object of a model by passing its name.
VLBI::Server::addModel
void addModel(const char *name, char *format, char *b64)
Create a new model from a picture, give it a name and add it to the current context.
VLBI::Server::setSampleRate
virtual void setSampleRate(double value)
set the sampling frequency, do this before calling Plot()
Definition: vlbi_server.h:334
VLBI::Server::getDec
double getDec(void)
get the current declination coordinate
Definition: vlbi_server.h:379
VLBI::Server::setOutput
void setOutput(FILE *out)
set the output stream
Definition: vlbi_server.h:457
VLBI::Server::getBps
double getBps(void)
get the bytes per sample
Definition: vlbi_server.h:412
VLBI::Server::addNodes
void addNodes(const char *name, char *b64)
Create as many nodes as the rows number of an SDFITS file, give it a name and add it to the current c...
VLBI::Server::~Server
virtual ~Server(void)
Destructor, destroys this object.
VLBI::Server::Server
Server(void)
Constructor, initializes all the internal variables.
VLBI::Server::Dft
void Dft(const char *name, const char *magnitude, const char *phase)
Save the magnitude and phase to new models obtained by the fourier transform of the model passed.
VLBI::plot_flags_moving_baseline
@ plot_flags_moving_baseline
This indicates that the nodes have a positional stream companion.
Definition: vlbi_server.h:53
VLBI::Server::setDelegate
void setDelegate(vlbi_func2_t func)
set the delegate function
Definition: vlbi_server.h:475
VLBI::Server::Idft
void Idft(const char *name, const char *magnitude, const char *phase)
Obtain an inverse fourier transform from the magnitude and phase models passed.
VLBI::Server::getOutput
FILE * getOutput()
get the output stream
Definition: vlbi_server.h:466
VLBI::Server::delModel
void delModel(const char *name)
delete from the current context an existing model by name.
VLBI::Server::setCorrelationOrder
void setCorrelationOrder(int order)
set the current correlation order
VLBI::Server::setWidth
virtual void setWidth(int value)
set the plot width, do this before calling Plot()
Definition: vlbi_server.h:352
VLBI::Server::Init
virtual int Init(int argc, char **argv)
Called immediately after main(), can be overriden to add your custom arguments.
Definition: vlbi_server.h:82
VLBI::Server
Inherit this class to create an OpenVLBI server application.
Definition: vlbi_server.h:65
VLBI::Server::setRa
virtual void setRa(double value)
set the target right ascension coordinate, do this before calling Plot()
Definition: vlbi_server.h:307
VLBI::Server::setContext
void setContext(const char *name)
set the current OpenVLBI context by passing its name.
VLBI::Server::getWidth
double getWidth(void)
get the plot width
Definition: vlbi_server.h:421
VLBI::Server::currentContext
char * currentContext(void)
Obtain the name current OpenVLBI context.
Definition: vlbi_server.h:122