MNE-CPP  0.1.9
A Framework for Electrophysiology
dipole_fit_settings.cpp
1 
2 
3 #include "dipole_fit_settings.h"
4 
5 using namespace Eigen;
6 using namespace INVERSELIB;
7 
8 //=============================================================================================================
9 // STATIC DEFINITIONS
10 //=============================================================================================================
11 
12 /*
13  * Basics...
14  */
15 #define MALLOC(x,t) (t *)malloc((x)*sizeof(t))
16 #define REALLOC(x,y,t) (t *)((x == NULL) ? malloc((y)*sizeof(t)) : realloc((x),(y)*sizeof(t)))
17 
18 #define X 0
19 #define Y 1
20 #define Z 2
21 
22 #ifndef PROGRAM_VERSION
23 #define PROGRAM_VERSION "1.00"
24 #endif
25 
26 
27 //=============================================================================================================
28 // STATIC DEFINITIONS ToDo make members
29 //=============================================================================================================
30 
31 //=============================================================================================================
32 // DEFINE MEMBER METHODS
33 //=============================================================================================================
34 
35 DipoleFitSettings::DipoleFitSettings()
36 {
37  initMembers();
38 }
39 
40 //=============================================================================================================
41 
42 DipoleFitSettings::DipoleFitSettings(int *argc,char **argv)
43 {
44  initMembers();
45 
46  if (!check_args(argc,argv))
47  return;
48 
49 // mne_print_version_info(stderr,argv[0],PROGRAM_VERSION,__DATE__,__TIME__);
50  printf("%s version %s compiled at %s %s\n",argv[0],PROGRAM_VERSION,__DATE__,__TIME__);
51 
52  checkIntegrity();
53 }
54 
55 //=============================================================================================================
56 
57 DipoleFitSettings::~DipoleFitSettings()
58 {
59  //ToDo Garbage collection
60 }
61 
62 //=============================================================================================================
63 
64 void DipoleFitSettings::initMembers()
65 {
66  // Init origin
67  r0 << 0.0f,0.0f,0.04f;
68 
69  filter.filter_on = true;
70  filter.size = 4096;
71  filter.taper_size = 2048;
72  filter.highpass = 0.0;
73  filter.highpass_width = 0.0;
74  filter.lowpass = 40.0;
75  filter.lowpass_width = 5.0;
76  filter.eog_highpass = 0.0;
77  filter.eog_highpass_width = 0.0;
78  filter.eog_lowpass = 40.0;
79  filter.eog_lowpass_width = 5.0;
80 
81  accurate = false;
83  guess_rad = 0.080f;
84  guess_mindist = 0.010f;
85  guess_exclude = 0.020f;
86  guess_grid = 0.010f;
87 
88  grad_std = 5e-13f;
89  mag_std = 20e-15f;
90  eeg_std = 0.2e-6f;
91  diagnoise = false;
92 
93  is_raw = false;
94  badname = NULL;
95  include_meg = false;
96  include_eeg = false;
97  tmin = -2*BIG_TIME;
98  tmax = 2*BIG_TIME;
99  tstep = -1.0;
100  integ = 0.0;
101  bmin = BIG_TIME;
102  bmax = BIG_TIME;
103  do_baseline = false;
104  setno = 1;
105  verbose = false;
106  omit_data_proj = false;
107 
108 
109  eeg_sphere_rad = 0.09f;
110  scale_eeg_pos = false;
111  mag_reg = 0.1f;
112  fit_mag_dipoles = false;
113 
114  grad_reg = 0.1f;
115  eeg_reg = 0.1f;
116 
117  bool gui = false;
118 }
119 
120 //=============================================================================================================
121 
122 void DipoleFitSettings::checkIntegrity()
123 {
124  do_baseline = (bmin < BIG_TIME && bmax < BIG_TIME);
125 
126  if (measname.isEmpty()) {
127  qCritical ("Data file name missing. Please specify one using the --meas option.");
128  return;
129  }
130  if (dipname.isEmpty() && bdipname.isEmpty()) {
131  qCritical ("Output file name missing. Please use the --dip or --bdip options to do this.");
132  return;
133  }
134  if (guessname.isEmpty()) {
135  if (bemname.isEmpty() && !guess_surfname.isEmpty() && mriname.isEmpty()) {
136  qCritical ("Please specify the MRI/head coordinate transformation with the --mri option");
137  return;
138  }
139  }
140  if (!include_meg && !include_eeg) {
141  qCritical ("Specify one or both of the --eeg and --meg options");
142  return;
143  }
144  if (!omit_data_proj)
145  projnames.prepend(measname);
146  printf("\n");
147 
148  if (!bemname.isEmpty())
149  printf("BEM : %s\n",bemname.toUtf8().data());
150  else {
151  printf("Sphere model : origin at (% 7.2f % 7.2f % 7.2f) mm\n",
152  1000*r0[X],1000*r0[Y],1000*r0[Z]);
153  }
154  printf("Using %s MEG coil definitions.\n",accurate ? "accurate" : "standard");
155  if (!mriname.isEmpty())
156  printf("MRI transform : %s\n",mriname.toUtf8().data());
157  if (!guessname.isEmpty())
158  printf("Guesses : %s\n",guessname.toUtf8().data());
159  else {
160  if (!guess_surfname.isEmpty())
161  printf("Guess space bounded by %s\n",guess_surfname.toUtf8().data());
162  else
163  printf("Spherical guess space, rad = %.1f mm\n",1000*guess_rad);
164  printf("Guess grid : %6.1f mm\n",1000*guess_grid);
165  if (guess_mindist > 0.0)
166  printf("Guess mindist : %6.1f mm\n",1000*guess_mindist);
167  if (guess_exclude > 0)
168  printf("Guess exclude : %6.1f mm\n",1000*guess_exclude);
169  }
170  printf("Data : %s\n",measname.toUtf8().data());
171  if (projnames.size() > 0) {
172  printf("SSP sources :\n");
173  for (int k = 0; k < projnames.size(); k++)
174  printf("\t%s\n",projnames[k].toUtf8().data());
175  }
176  if (badname)
177  printf("Bad channels : %s\n",badname);
178  if (do_baseline)
179  printf("Baseline : %10.2f ... %10.2f ms\n", 1000*bmin,1000*bmax);
180  if (!noisename.isEmpty()) {
181  printf("Noise covariance : %s\n",noisename.toUtf8().data());
182  if (include_meg) {
183  if (mag_reg > 0.0)
184  printf("\tNoise-covariange regularization (mag) : %-5.2f\n",mag_reg);
185  if (grad_reg > 0.0)
186  printf("\tNoise-covariange regularization (grad) : %-5.2f\n",grad_reg);
187  }
188  if (include_eeg && eeg_reg > 0.0)
189  printf("\tNoise-covariange regularization (EEG) : %-5.2f\n",eeg_reg);
190  }
191  if (fit_mag_dipoles)
192  printf("Fit data with magnetic dipoles\n");
193  if (!dipname.isEmpty())
194  printf("dip output : %s\n",dipname.toUtf8().data());
195  if (!bdipname.isEmpty())
196  printf("bdip output : %s\n",bdipname.toUtf8().data());
197  printf("\n");
198 }
199 
200 //=============================================================================================================
201 
202 void DipoleFitSettings::usage(char *name)
203 {
204  printf("usage: %s [options]\n",name);
205  printf("This is a program for sequential single dipole fitting.\n");
206  printf("\nInput data:\n\n");
207  printf("\t--meas name specify an evoked-response data file\n");
208  printf("\t--set no evoked data set number to use (default: 1)\n");
209  printf("\t--bad name take bad channel list from here\n");
210 
211  printf("\nModality selection:\n\n");
212  printf("\t--meg employ MEG data in fitting\n");
213  printf("\t--eeg employ EEG data in fitting\n");
214 
215  printf("\nTime scale selection:\n\n");
216  printf("\t--tmin time/ms specify the starting analysis time\n");
217  printf("\t--tmax time/ms specify the ending analysis time\n");
218  printf("\t--tstep time/ms specify the time step between frames (default 1/(sampling frequency))\n");
219  printf("\t--integ time/ms specify the time integration for each frame (default 0)\n");
220 
221  printf("\nPreprocessing:\n\n");
222  printf("\t--bmin time/ms specify the baseline starting time (evoked data only)\n");
223  printf("\t--bmax time/ms specify the baseline ending time (evoked data only)\n");
224  printf("\t--proj name Load the linear projection from here\n");
225  printf("\t Multiple projections can be specified.\n");
226  printf("\t The data file will be automatically included, unless --noproj is present.\n");
227  printf("\t--noproj Do not load the projection from the data file, just those given with the --proj option.\n");
228  printf("\n\tFiltering (raw data only):\n\n");
229  printf("\t--filtersize size desired filter length (default = %d)\n",filter.size);
230  printf("\t--highpass val/Hz highpass corner (default = %6.1f Hz)\n",filter.highpass);
231  printf("\t--lowpass val/Hz lowpass corner (default = %6.1f Hz)\n",filter.lowpass);
232  printf("\t--lowpassw val/Hz lowpass transition width (default = %6.1f Hz)\n",filter.lowpass_width);
233  printf("\t--filteroff do not filter the data\n");
234 
235  printf("\nNoise specification:\n\n");
236  printf("\t--noise name take the noise-covariance matrix from here\n");
237  printf("\t--gradnoise val specify a gradiometer noise value in fT/cm\n");
238  printf("\t--magnoise val specify a gradiometer noise value in fT\n");
239  printf("\t--eegnoise val specify an EEG value in uV\n");
240  printf("\t NOTE: The above will be used only if --noise is missing\n");
241  printf("\t--diagnoise omit off-diagonal terms from the noise-covariance matrix\n");
242  printf("\t--reg amount Apply regularization to the noise-covariance matrix (same fraction for all channels).\n");
243  printf("\t--gradreg amount Apply regularization to the MEG noise-covariance matrix (planar gradiometers, default = %6.2f).\n",grad_reg);
244  printf("\t--magreg amount Apply regularization to the EEG noise-covariance matrix (axial gradiometers and magnetometers, default = %6.2f).\n",mag_reg);
245  printf("\t--eegreg amount Apply regularization to the EEG noise-covariance matrix (default = %6.2f).\n",eeg_reg);
246 
247  printf("\nForward model:\n\n");
248  printf("\t--mri name take head/MRI coordinate transform from here (Neuromag MRI description file)\n");
249  printf("\t--bem name BEM model name\n");
250  printf("\t--origin x:y:z/mm use a sphere model with this origin (head coordinates/mm)\n");
251  printf("\t--eegscalp scale the electrode locations to the surface of the scalp when using a sphere model\n");
252  printf("\t--eegmodels name read EEG sphere model specifications from here.\n");
253  printf("\t--eegmodel name name of the EEG sphere model to use (default : Default)\n");
254  printf("\t--eegrad val radius of the scalp surface to use in EEG sphere model (default : %7.1f mm)\n",1000*eeg_sphere_rad);
255  printf("\t--accurate use accurate coil definitions in MEG forward computation\n");
256 
257  printf("\nFitting parameters:\n\n");
258  printf("\t--guess name The source space of initial guesses.\n");
259  printf("\t If not present, the values below are used to generate the guess grid.\n");
260  printf("\t--guesssurf name Read the inner skull surface from this fif file to generate the guesses.\n");
261  printf("\t--guessrad value Radius of a spherical guess volume if neither of the above is present (default : %.1f mm)\n",1000*guess_rad);
262  printf("\t--exclude dist/mm Exclude points which are closer than this distance from the CM of the inner skull surface (default = %6.1f mm).\n",1000*guess_exclude);
263  printf("\t--mindist dist/mm Exclude points which are closer than this distance from the inner skull surface (default = %6.1f mm).\n",1000*guess_mindist);
264  printf("\t--grid dist/mm Source space grid size (default = %6.1f mm).\n",1000*guess_grid);
265  printf("\t--magdip Fit magnetic dipoles instead of current dipoles.\n");
266  printf("\nOutput:\n\n");
267  printf("\t--dip name xfit dip format output file name\n");
268  printf("\t--bdip name xfit bdip format output file name\n");
269  printf("\nGeneral:\n\n");
270  printf("\t--gui Enables the gui.\n");
271  printf("\t--help print this info.\n");
272  printf("\t--version print version info.\n\n");
273  return;
274 }
275 
276 //=============================================================================================================
277 
278 bool DipoleFitSettings::check_unrecognized_args(int argc, char **argv)
279 {
280  if ( argc > 1 ) {
281  printf("Unrecognized arguments : ");
282  for (int k = 1; k < argc; k++)
283  printf("%s ",argv[k]);
284  printf("\n");
285  qCritical ("Check the command line.");
286  return false;
287  }
288  return true;
289 }
290 
291 //=============================================================================================================
292 
293 bool DipoleFitSettings::check_args (int *argc,char **argv)
294 {
295  int found;
296  float fval;
297  int ival,filter_size;
298 
299  for (int k = 0; k < *argc; k++) {
300  found = 0;
301  if (strcmp(argv[k],"--gui") == 0) {
302  found = 1;
303  gui = true;
304  }
305  else if (strcmp(argv[k],"--version") == 0) {
306  printf("%s version %s compiled at %s %s\n",
307  argv[0],PROGRAM_VERSION,__DATE__,__TIME__);
308  exit(0);
309  }
310  else if (strcmp(argv[k],"--help") == 0) {
311  usage(argv[0]);
312  exit(1);
313  }
314  else if (strcmp(argv[k],"--guess") == 0) {
315  found = 2;
316  if (k == *argc - 1) {
317  qCritical ("--guess: argument required.");
318  return false;
319  }
320  guessname = QString(argv[k+1]);
321  }
322  else if (strcmp(argv[k],"--gsurf") == 0) {
323  found = 2;
324  if (k == *argc - 1) {
325  qCritical ("--gsurf: argument required.");
326  return false;
327  }
328  guess_surfname = strdup(argv[k+1]);
329  }
330  else if (strcmp(argv[k],"--guesssurf") == 0) {
331  found = 2;
332  if (k == *argc - 1) {
333  qCritical ("--guesssurf: argument required.");
334  return false;
335  }
336  guess_surfname = strdup(argv[k+1]);
337  }
338  else if (strcmp(argv[k],"--guessrad") == 0) {
339  found = 2;
340  if (k == *argc - 1) {
341  qCritical ("--guessrad: argument required.");
342  return false;
343  }
344  if (sscanf(argv[k+1],"%f",&fval) != 1) {
345  qCritical ("Could not interpret the radius.");
346  return false;
347  }
348  if (fval <= 0.0) {
349  qCritical ("Radius should be positive");
350  return false;
351  }
352  guess_rad = fval/1000.0;
353  }
354  else if (strcmp(argv[k],"--mindist") == 0) {
355  found = 2;
356  if (k == *argc - 1) {
357  qCritical ("--mindist: argument required.");
358  return false;
359  }
360  if (sscanf(argv[k+1],"%f",&fval) != 1) {
361  qCritical ("Could not interpret the distance.");
362  return false;
363  }
364  guess_mindist = fval/1000.0;
365  if (guess_mindist <= 0.0)
366  guess_mindist = 0.0;
367  }
368  else if (strcmp(argv[k],"--exclude") == 0) {
369  found = 2;
370  if (k == *argc - 1) {
371  qCritical ("--exclude: argument required.");
372  return false;
373  }
374  if (sscanf(argv[k+1],"%f",&fval) != 1) {
375  qCritical ("Could not interpret the distance.");
376  return false;
377  }
378  guess_exclude = fval/1000.0;
379  if (guess_exclude <= 0.0)
380  guess_exclude = 0.0;
381  }
382  else if (strcmp(argv[k],"--grid") == 0) {
383  found = 2;
384  if (k == *argc - 1) {
385  qCritical ("--grid: argument required.");
386  return false;
387  }
388  if (sscanf(argv[k+1],"%f",&fval) != 1) {
389  qCritical ("Could not interpret the distance.");
390  return false;
391  }
392  if (fval <= 0.0) {
393  qCritical ("Grid spacing should be positive");
394  return false;
395  }
396  guess_grid = guess_grid/1000.0;
397  }
398  else if (strcmp(argv[k],"--mri") == 0) {
399  found = 2;
400  if (k == *argc - 1) {
401  qCritical ("--mri: argument required.");
402  return false;
403  }
404  mriname = QString(argv[k+1]);
405  }
406  else if (strcmp(argv[k],"--bem") == 0) {
407  found = 2;
408  if (k == *argc - 1) {
409  qCritical ("--bem: argument required.");
410  return false;
411  }
412  bemname = QString(argv[k+1]);
413  }
414  else if (strcmp(argv[k],"--accurate") == 0) {
415  found = 1;
416  accurate = true;
417  }
418  else if (strcmp(argv[k],"--meg") == 0) {
419  found = 1;
420  include_meg = true;
421  }
422  else if (strcmp(argv[k],"--eeg") == 0) {
423  found = 1;
424  include_eeg = true;
425  }
426  else if (strcmp(argv[k],"--origin") == 0) {
427  found = 2;
428  if (k == *argc - 1) {
429  qCritical ("--origin: argument required.");
430  return false;
431  }
432  if (sscanf(argv[k+1],"%f:%f:%f",r0[X],r0[Y],r0[Z]) != 3) {
433  qCritical ("Could not interpret the origin.");
434  return false;
435  }
436  r0[X] = r0[X]/1000.0;
437  r0[Y] = r0[Y]/1000.0;
438  r0[Z] = r0[Z]/1000.0;
439  }
440  else if (strcmp(argv[k],"--eegrad") == 0) {
441  found = 2;
442  if (k == *argc - 1) {
443  qCritical ("--eegrad: argument required.");
444  return false;
445  }
446  if (sscanf(argv[k+1],"%g",&eeg_sphere_rad) != 1) {
447  qCritical () << "Incomprehensible radius:" << argv[k+1];
448  return false;
449  }
450  if (eeg_sphere_rad <= 0) {
451  qCritical ("Radius must be positive");
452  return false;
453  }
454  eeg_sphere_rad = eeg_sphere_rad/1000.0;
455  }
456  else if (strcmp(argv[k],"--eegmodels") == 0) {
457  found = 2;
458  if (k == *argc - 1) {
459  qCritical ("--eegmodels: argument required.");
460  return false;
461  }
462  eeg_model_file = QString(argv[k+1]);
463  }
464  else if (strcmp(argv[k],"--eegmodel") == 0) {
465  found = 2;
466  if (k == *argc - 1) {
467  qCritical ("--eegmodel: argument required.");
468  return false;
469  }
470  eeg_model_name = QString(argv[k+1]);
471  }
472  else if (strcmp(argv[k],"--eegscalp") == 0) {
473  found = 1;
474  scale_eeg_pos = true;
475  }
476  else if (strcmp(argv[k],"--meas") == 0) {
477  found = 2;
478  if (k == *argc - 1) {
479  qCritical ("--meas: argument required.");
480  return false;
481  }
482  measname = QString(argv[k+1]);
483  is_raw = false;
484  }
485  else if (strcmp(argv[k],"--raw") == 0) {
486  found = 2;
487  if (k == *argc - 1) {
488  qCritical ("--raw: argument required.");
489  return false;
490  }
491  measname = QString(argv[k+1]);
492  is_raw = true;
493  }
494  else if (strcmp(argv[k],"--proj") == 0) {
495  found = 2;
496  if (k == *argc - 1) {
497  qCritical ("--proj: argument required.");
498  return false;
499  }
500  projnames.append(QString(argv[k+1]));
501  }
502  else if (strcmp(argv[k],"--noproj") == 0) {
503  found = 1;
504  omit_data_proj = true;
505  }
506  else if (strcmp(argv[k],"--bad") == 0) {
507  found = 2;
508  if (k == *argc - 1) {
509  qCritical ("--bad: argument required.");
510  return false;
511  }
512  badname = strdup(argv[k+1]);
513  }
514  else if (strcmp(argv[k],"--noise") == 0) {
515  found = 2;
516  if (k == *argc - 1) {
517  qCritical ("--noise: argument required.");
518  return false;
519  }
520  noisename = QString(argv[k+1]);
521  }
522  else if (strcmp(argv[k],"--gradnoise") == 0) {
523  found = 2;
524  if (k == *argc - 1) {
525  qCritical ("--gradnoise: argument required.");
526  return false;
527  }
528  if (sscanf(argv[k+1],"%g",&fval) != 1) {
529  qCritical() << "Incomprehensible value:" << argv[k+1];
530  return false;
531  }
532  if (fval < 0.0) {
533  qCritical ("Value should be positive");
534  return false;
535  }
536  grad_std = 1e-13*fval;
537  }
538  else if (strcmp(argv[k],"--magnoise") == 0) {
539  found = 2;
540  if (k == *argc - 1) {
541  qCritical ("--magnoise: argument required.");
542  return false;
543  }
544  if (sscanf(argv[k+1],"%g",&fval) != 1) {
545  qCritical() << "Incomprehensible value:" << argv[k+1];
546  return false;
547  }
548  if (fval < 0.0) {
549  qCritical ("Value should be positive");
550  return false;
551  }
552  mag_std = 1e-15*fval;
553  }
554  else if (strcmp(argv[k],"--eegnoise") == 0) {
555  found = 2;
556  if (k == *argc - 1) {
557  qCritical ("--eegnoise: argument required.");
558  return false;
559  }
560  if (sscanf(argv[k+1],"%g",&fval) != 1) {
561  qCritical () << "Incomprehensible value:" << argv[k+1];
562  return false;
563  }
564  if (fval < 0.0) {
565  qCritical ("Value should be positive");
566  return false;
567  }
568  eeg_std = 1e-6*fval;
569  }
570  else if (strcmp(argv[k],"--diagnoise") == 0) {
571  found = 1;
572  diagnoise = true;
573  }
574  else if (strcmp(argv[k],"--eegreg") == 0) {
575  found = 2;
576  if (k == *argc - 1) {
577  qCritical ("--eegreg: argument required.");
578  return false;
579  }
580  if (sscanf(argv[k+1],"%g",&fval) != 1) {
581  qCritical () << "Incomprehensible value:" << argv[k+1];
582  return false;
583  }
584  if (fval < 0 || fval > 1) {
585  qCritical ("Regularization value should be positive and smaller than one.");
586  return false;
587  }
588  eeg_reg = fval;
589  }
590  else if (strcmp(argv[k],"--magreg") == 0) {
591  found = 2;
592  if (k == *argc - 1) {
593  qCritical ("--magreg: argument required.");
594  return false;
595  }
596  if (sscanf(argv[k+1],"%g",&fval) != 1) {
597  qCritical () << "Incomprehensible value:" << argv[k+1];
598  return false;
599  }
600  if (fval < 0 || fval > 1) {
601  qCritical ("Regularization value should be positive and smaller than one.");
602  return false;
603  }
604  mag_reg = fval;
605  }
606  else if (strcmp(argv[k],"--gradreg") == 0) {
607  found = 2;
608  if (k == *argc - 1) {
609  qCritical ("--gradreg: argument required.");
610  return false;
611  }
612  if (sscanf(argv[k+1],"%g",&fval) != 1) {
613  qCritical () << "Incomprehensible value:" << argv[k+1] ;
614  return false;
615  }
616  if (fval < 0 || fval > 1) {
617  qCritical ("Regularization value should be positive and smaller than one.");
618  return false;
619  }
620  grad_reg = fval;
621  }
622  else if (strcmp(argv[k],"--reg") == 0) {
623  found = 2;
624  if (k == *argc - 1) {
625  qCritical ("--reg: argument required.");
626  return false;
627  }
628  if (sscanf(argv[k+1],"%g",&fval) != 1) {
629  qCritical () << "Incomprehensible value:" << argv[k+1];
630  return false;
631  }
632  if (fval < 0 || fval > 1) {
633  qCritical ("Regularization value should be positive and smaller than one.");
634  return false;
635  }
636  grad_reg = fval;
637  mag_reg = fval;
638  eeg_reg = fval;
639  }
640  else if (strcmp(argv[k],"--tstep") == 0) {
641  found = 2;
642  if (k == *argc - 1) {
643  qCritical ("--tstep: argument required.");
644  return false;
645  }
646  if (sscanf(argv[k+1],"%g",&fval) != 1) {
647  qCritical() << "Incomprehensible tstep:" << argv[k+1];
648  return false;
649  }
650  if (fval < 0.0) {
651  qCritical ("Time step should be positive");
652  return false;
653  }
654  tstep = fval/1000.0;
655  }
656  else if (strcmp(argv[k],"--integ") == 0) {
657  found = 2;
658  if (k == *argc - 1) {
659  qCritical ("--integ: argument required.");
660  return false;
661  }
662  if (sscanf(argv[k+1],"%g",&fval) != 1) {
663  qCritical() << "Incomprehensible integration time:" << argv[k+1];
664  return false;
665  }
666  if (fval <= 0.0) {
667  qCritical ("Integration time should be positive.");
668  return false;
669  }
670  integ = fval/1000.0f;
671  }
672  else if (strcmp(argv[k],"--tmin") == 0) {
673  found = 2;
674  if (k == *argc - 1) {
675  qCritical ("--tmin: argument required.");
676  return false;
677  }
678  if (sscanf(argv[k+1],"%g",&fval) != 1) {
679  qCritical() << "Incomprehensible tmin:" << argv[k+1];
680  return false;
681  }
682  tmin = fval/1000.0f;
683  }
684  else if (strcmp(argv[k],"--tmax") == 0) {
685  found = 2;
686  if (k == *argc - 1) {
687  qCritical ("--tmax: argument required.");
688  return false;
689  }
690  if (sscanf(argv[k+1],"%g",&fval) != 1) {
691  qCritical() << "Incomprehensible tmax:" << argv[k+1];
692  return false;
693  }
694  tmax = fval/1000.0;
695  }
696  else if (strcmp(argv[k],"--bmin") == 0) {
697  found = 2;
698  if (k == *argc - 1) {
699  qCritical ("--bmin: argument required.");
700  return false;
701  }
702  if (sscanf(argv[k+1],"%g",&fval) != 1) {
703  qCritical() << "Incomprehensible bmin:" << argv[k+1];
704  return false;
705  }
706  bmin = fval/1000.0f;
707  }
708  else if (strcmp(argv[k],"--bmax") == 0) {
709  found = 2;
710  if (k == *argc - 1) {
711  qCritical ("--bmax: argument required.");
712  return false;
713  }
714  if (sscanf(argv[k+1],"%g",&fval) != 1) {
715  qCritical() << "Incomprehensible bmax:" << argv[k+1];
716  return false;
717  }
718  bmax = fval/1000.0f;
719  }
720  else if (strcmp(argv[k],"--set") == 0) {
721  found = 2;
722  if (k == *argc - 1) {
723  qCritical ("--set: argument required.");
724  return false;
725  }
726  if (sscanf(argv[k+1],"%d",&setno) != 1) {
727  qCritical() << "Incomprehensible data set number:" << argv[k+1];
728  return false;
729  }
730  if (setno <= 0) {
731  qCritical ("Data set number must be > 0");
732  return false;
733  }
734  }
735  else if (strcmp(argv[k],"--filteroff") == 0) {
736  found = 1;
737  filter.filter_on = false;
738  }
739  else if (strcmp(argv[k],"--lowpass") == 0) {
740  found = 2;
741  if (k == *argc - 1) {
742  qCritical ("--lowpass: argument required.");
743  return false;
744  }
745  if (sscanf(argv[k+1],"%g",&fval) != 1) {
746  qCritical() << "Illegal number:" << argv[k+1];
747  return false;
748  }
749  if (fval <= 0) {
750  qCritical ("Lowpass corner must be positive");
751  return false;
752  }
753  filter.lowpass = fval;
754  }
755  else if (strcmp(argv[k],"--lowpassw") == 0) {
756  found = 2;
757  if (k == *argc - 1) {
758  qCritical ("--lowpassw: argument required.");
759  return false;
760  }
761  if (sscanf(argv[k+1],"%g",&fval) != 1) {
762  qCritical() << "Illegal number:" << argv[k+1];
763  return false;
764  }
765  if (fval <= 0) {
766  qCritical ("Lowpass width must be positive");
767  return false;
768  }
769  filter.lowpass_width = fval;
770  }
771  else if (strcmp(argv[k],"--highpass") == 0) {
772  found = 2;
773  if (k == *argc - 1) {
774  qCritical ("--highpass: argument required.");
775  return false;
776  }
777  if (sscanf(argv[k+1],"%g",&fval) != 1) {
778  qCritical() << "Illegal number:" << argv[k+1];
779  return false;
780  }
781  if (fval <= 0) {
782  qCritical ("Highpass corner must be positive");
783  return false;
784  }
785  filter.highpass = fval;
786  }
787  else if (strcmp(argv[k],"--filtersize") == 0) {
788  found = 2;
789  if (k == *argc - 1) {
790  qCritical ("--filtersize: argument required.");
791  return false;
792  }
793  if (sscanf(argv[k+1],"%d",&ival) != 1) {
794  qCritical() << "Illegal number:" << argv[k+1];
795  return false;
796  }
797  if (ival < 1024) {
798  qCritical ("Filtersize should be at least 1024.");
799  return false;
800  }
801  for (filter_size = 1024; filter_size < ival; filter_size = 2*filter_size)
802  ;
803  filter.size = filter_size;
804  filter.taper_size = filter_size/2;
805  }
806  else if (strcmp(argv[k],"--magdip") == 0) {
807  found = 1;
808  fit_mag_dipoles = true;
809  }
810  else if (strcmp(argv[k],"--dip") == 0) {
811  found = 2;
812  if (k == *argc - 1) {
813  qCritical ("--dip: argument required.");
814  return false;
815  }
816  dipname = QString(argv[k+1]);
817  }
818  else if (strcmp(argv[k],"--bdip") == 0) {
819  found = 2;
820  if (k == *argc - 1) {
821  qCritical ("--bdip: argument required.");
822  return false;
823  }
824  bdipname = QString(argv[k+1]);
825  }
826  else if (strcmp(argv[k],"--verbose") == 0) {
827  found = 1;
828  verbose = true;
829  }
830  if (found) {
831  for (int p = k; p < *argc-found; p++)
832  argv[p] = argv[p+found];
833  *argc = *argc - found;
834  k = k - found;
835  }
836  }
837  return check_unrecognized_args(*argc,argv);
838 }
Dipole Fit Setting class declaration.