p4autils.cc 5.8 KB
Newer Older
1 2 3 4 5 6 7
/* ---------------------------------------------------------- 
   Projet BAORadio/PAON4 - (C) LAL/IRFU  2008-2017

   Classes et fonctions utilitaires pour les programmes d'analyse PAON4
   R. Ansari    Fevrier 2017 
   ---------------------------------------------------------- */

8 9 10
#include <stdlib.h>
#include <stdio.h>

11 12 13 14 15 16
#include "p4autils.h"

P4AnaParams::P4AnaParams()
  : inpath5_("bao5/"), inpath6_("bao6/"), Imin_(0), Imax_(10), Istep_(1),
    fgreorderfreq_(false), gain_gnu_file_("gain.ppf"),
    outfile_("p4a.ppf"), Nmean_(10), prtlev_(0), 
17
    fgTFM_(false), TFMtimebin_(30), TFMfreqbin_(4), fgdtable_(false)
18 19 20 21 22 23 24 25
{
  
}

P4AnaParams::P4AnaParams(P4AnaParams const & a)
  : inpath5_(a.inpath5_), inpath6_(a.inpath6_), Imin_(a.Imin_), Imax_(a.Imax_), Istep_(a.Istep_),
    fgreorderfreq_(a.fgreorderfreq_), gain_gnu_file_(a.gain_gnu_file_),
    outfile_(a.outfile_), Nmean_(a.Nmean_), prtlev_(a.prtlev_), 
26
    fgTFM_(a.fgTFM_), TFMtimebin_(a.TFMtimebin_), TFMfreqbin_(a.TFMfreqbin_), 
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    fgdtable_(a.fgdtable_), fbands_(a.fbands_), lastargs_(a.lastargs_)
{
}

P4AnaParams& P4AnaParams::operator = (P4AnaParams const & a)
{
  inpath5_=a.inpath5_; inpath6_=a.inpath6_;
  Imin_=a.Imin_; Imax_=a.Imax_; Istep_=a.Istep_;
  fgreorderfreq_=a.fgreorderfreq_; gain_gnu_file_=a.gain_gnu_file_;
  outfile_=a.outfile_;  Nmean_=a.Nmean_;  prtlev_=a.prtlev_;
  fgTFM_=a.fgTFM_;  TFMfreqbin_=a.TFMfreqbin_; TFMtimebin_=a.TFMtimebin_;
  fgdtable_=a.fgdtable_;   fbands_=a.fbands_;  lastargs_=a.lastargs_;
  return *this;
}

int P4AnaParams::DecodeArgs(int narg, const char* arg[])
{
  // decodage arguments optionnel 
45
  while (narg>1) {
46 47 48
    string fbo = arg[1];
    if (fbo=="-inrange")  {   // specification numeros de fichiers de visi a traiter 
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
49
      sscanf(arg[2],"%d,%d,%d",&Imin_,&Imax_,&Istep_);   arg+=2; narg-=2;  lastargs_.clear(); 
50 51 52
    }
    else if (fbo=="-in5") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
53
      inpath5_=arg[2];   arg+=2; narg-=2;  lastargs_.clear(); 
54 55 56
    }
    else if (fbo=="-in6") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
57
      inpath6_=arg[2];   arg+=2; narg-=2; lastargs_.clear(); 
58 59 60
    }
    else if (fbo=="-gnu") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
61
      gain_gnu_file_=arg[2];   arg+=2; narg-=2; lastargs_.clear(); 
62 63 64
    }
    else if (fbo=="-nmean") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
65
      Nmean_=atoi(arg[2]);   arg+=2; narg-=2; lastargs_.clear(); 
66
    }
67
    else if (fbo=="-reorderfreq") {
68
      fgreorderfreq_=true;   arg++; narg--;  lastargs_.clear(); 
69 70 71
    }
    else if (fbo=="-o") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
72
      outfile_=arg[2];   arg+=2; narg-=2;  lastargs_.clear(); 
73
    }
74 75 76
    else if (fbo=="-tfm") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      int ja,jb;
77 78
      sscanf(arg[2],"%d,%d",&ja,&jb);  TFMtimebin_=ja;  TFMfreqbin_=jb;   fgTFM_=true;
      arg+=2; narg-=2;  lastargs_.clear(); 
79 80 81 82
    }
    else if (fbo=="-freq") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      double f0,df;
83 84 85 86 87 88 89 90
      sscanf(arg[2],"%lg,%lg",&f0,&df);   fbands_.push_back(P4FreqBand(f0,df));    fgdtable_=true;
      arg+=2; narg-=2;   lastargs_.clear(); 
    }
    else if (fbo=="-prt") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      prtlev_=atoi(arg[2]);   arg+=2; narg-=2;   lastargs_.clear(); 
    }
    else { arg++; narg--; lastargs_.push_back(fbo); }
91
  }
92
  // les arguments qui restent a la fin de la ligne de commande sont dans lastargs_ 
93 94 95 96 97 98 99
  return 0;
}

int P4AnaParams::UsageOptions()
{
  cout<< " P4AnaParams::UsageOptions(): -inrange -in5 -in6 -gnu -o -nmean -tfm -freq -prt \n"
      << "    [-inrange Imin,Imax[,Istep] ]  [-in5 InputPath_BAO5]   [-in6 InputPath_BAO6]  \n"
100
      << "    [-o outfilename] [-gnu gain_filename] [-nmean N] [-reorderfreq] \n"
101
      << "    [-tfm timebin,freqbin]  [-freq f0,df] [-prt level] \n"
102 103 104 105 106
      << " -inrange Imin,Imax[,Istep]  define range of visibilite matrices to be processed (Imin<=I<=Imax with step Istep) \n"
      << " -in5/6 InputPath_BAO5/6 : input file path for BAO5 and BAO6 \n"
      << " -o outfilename : specify output file name \n"
      << " -gnu gain_filename: gain g(nu) file name \n"
      << " -nmean N: compute average (and sigma...) using N visibility matrices \n"
107
      << " -reorderfreq: activate frequency reordering in VisiP4Reader, suitable for FFT firmware \n"
108 109 110
      << " -tfm timebin,freqbin : time-frequency maps, averaging timebin=nb of visi matrices, freqbin frequency components \n"
      << " -freq f0,df : definition of a frequency band centered on f0, with total width df (in MHz) \n"
      << "     several frequency bands can be specified by mutiple -freq options \n"
111
      << " -prt level: define print level  \n"
112 113 114 115 116 117 118 119 120 121
      << endl;
  return 0;
}

ostream& P4AnaParams::Print(ostream& os) const
{
  os<<" In5 path="<<inpath5_<<" In6 path="<<inpath6_<< "Range:"<<Imin_<<"<=I<="<<Imax_<<" (step="<<Istep_<<")"<<endl;
  if (fgreorderfreq_)  os<<" (frequency reordering for FFT firmware) ";
  os<<" Gain, g(nu) file:"<<gain_gnu_file_<<" OutFile="<<outfile_<<endl;
  os<<" Nmean="<<Nmean_<<" TFM: TimeBin="<<TFMtimebin_<<" FreqBin="<<TFMfreqbin_<<endl;
122 123
  if (fbands_.size()==0) os<<" No frequency band defined ..."<<endl;
  else for(size_t i=0; i<fbands_.size(); i++)  os<<"FreqBand["<<i<<"]: "<<fbands_[i]<<endl;
124 125
  return os;
}