File: cmdl.cc

package info (click to toggle)
purify 2.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 58,688 kB
  • sloc: cpp: 8,410; python: 375; makefile: 7
file content (191 lines) | stat: -rw-r--r-- 5,031 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "purify/config.h"
#include "cmdl.h"

namespace purify {

std::string usage() {
  return "Purify: A program that will reconstruct images from radio interferometers using PADMM. "
         "\n\n"
         "--help: Print this information. \n\n"
         "--measurement_set: path of measurement set. (required) \n\n"
         "--noise: path of measurement_set with Stokes V noise estimate. (Assumes Stokes V of "
         "measurement set). \n\n"
         "--name: path of file output. (required) \n\n"
         "--niters: number of iterations. \n\n"
         "--stokes: choice of stokes I, Q, U, or V (I is default). \n\n"
         "--cellsize: the dimensions of a pixel in arcseconds. \n\n"
         "--size: image size in pixels. \n\n"
         "--width: image width in pixels. \n\n"
         "--height: image height in pixels. \n\n"
         "--beta: valued used to set the stepsize of PADMM\n\n"
         "--noadapt: Choose not to update the stepsize. \n\n"
         "--diagnostic: Save diagnostic information to log file.\n\n"
         "--l2_bound: Factor to multiply the l2 bound by.\n\n"
         "--relative_variation: The convergence criteria on relative variation (default is 1e-3).\n\n"
         "--residual_convergence: Factor to multiply the l2 bound by for convergence. (default is 1)"
         "--relative_gamma_adapt: Relative difference criteria for adapting the stepsize gamma (default 0.01).\n\n"
         "--power_iterations: Maximum iterations for the power method.\n\n"
         "--primary_beam: Choice of primary beam model. (none is the only option).\n\n"
         "--fft_grid_correction: Choose calculate the gridding correction using an FFT rather than "
         "analytic formula. \n\n"
         "--kernel: Type of gridding kernel to use, kb, gauss, pswf, box. (kb is default) \n\n"
         "--kernel_support: Support of kernel in grid cells. (4 is the default) \n\n"
         "--logging_level: Determines the output logging level for sopt and purify. (\"debug\" is "
         "the default) \n\n";
}

Params parse_cmdl(int argc, char **argv) {
  Params params;
  opterr = 0;

  int c;

  while(1) {
    /* getopt_long stores the option index here. */
    int option_index = 0;

    c = getopt_long(argc, argv, "a:bc:defghijklmnopqrst", long_options, &option_index);

    /* Detect the end of the options. */
    if(c == -1)
      break;

    switch(c) {
    case 0:
      /* If this option set a flag, do nothing else now. */
      if(long_options[option_index].flag != 0)
        break;
      printf("option %s", long_options[option_index].name);
      if(optarg)
        printf(" with arg %s", optarg);
      printf("\n");
      break;

    case 'z':
      std::cout << usage();
      std::exit(0);
      break;

    case 'a':
      params.visfile = optarg;
      break;

    case 'b':
      params.noisefile = optarg;
      break;

    case 'c':
      params.name = optarg;
      break;

    case 'd':
      params.niters = std::stoi(optarg);
      break;
    
    case 'e':
      params.name = params.stokes;
      break;

    case 'f':
      params.width = std::stoi(optarg);
      params.height = std::stoi(optarg);
      break;

    case 'g':
      params.beta = std::stod(optarg);
      break;

    case 'h':
      params.adapt_gamma = false;
      break;

    case 'i':
      params.n_mu = std::stod(optarg);
      break;

    case 'j':
      params.run_diagnostic = true;
      break;

    case 'k':
      params.power_method_iterations = std::stoi(optarg);
      if(params.power_method_iterations < 0)
        params.power_method_iterations = 1;
      break;

    case 'l':
      params.use_w_term = true;
      break;

    case 'm':
      params.energy_fraction = std::stod(optarg);
      if(params.energy_fraction <= 0 or params.energy_fraction > 1) {
        std::printf("Wrong energy fraction! %f", params.energy_fraction);
        params.energy_fraction = 1;
      }
      break;

    case 'n':
      params.primary_beam = optarg;
      break;

    case 'o':
      params.fft_grid_correction = true;
      break;

    case 'p':
      params.width = std::stoi(optarg);
      break;

    case 'q':
      params.height = std::stoi(optarg);
      break;

    case 'r':
      params.kernel = optarg;
      break;

    case 's':
      params.J = std::stoi(optarg);
      break;

    case 't':
      params.sopt_logging_level = optarg;
break;

    case 'u':
      params.cellsizex = std::stod(optarg);
      params.cellsizey = std::stod(optarg);
      break;

    case 'v':
      params.relative_variation = std::stod(optarg);
      break;

    case 'w':
      params.residual_convergence = std::stod(optarg);
      break;

    case 'x':
      params.relative_gamma_adapt = std::stod(optarg);
      break;

    case 'y':
      params.adapt_iter = std::stod(optarg);
      break;

    case '1':
      params.fftw_plan = optarg;
      break;

    case '?':
      /* getopt_long already printed an error message. */
      break;

    default:
      abort();
    }
  }
  return params;
}
};