p4autils.cc 5.33 KB
Newer Older
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
/* ---------------------------------------------------------- 
   Projet BAORadio/PAON4 - (C) LAL/IRFU  2008-2017

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

#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), 
    fgTFM_(false), TFMfreqbin_(), TFMtimebin_(30), fgdtable_(false)
{
  
}

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_), 
    fgTFM_(a.fgTFM_), TFMfreqbin_(a.TFMfreqbin_), TFMtimebin_(a.TFMtimebin_),
    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 
  bool fgoptarg=true;
  while (fgoptarg&&(narg>1)) {
    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; }
      sscanf(arg[2],"%d,%d,%d",&Imin_,&Imax_,&Istep_);   arg+=2; narg-=2; 
    }
    else if (fbo=="-in5") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      inpath5_=arg[2];   arg+=2; narg-=2; 
    }
    else if (fbo=="-in6") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      inpath6_=arg[2];   arg+=2; narg-=2; 
    }
    else if (fbo=="-gnu") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      gain_gnu_file_=arg[2];   arg+=2; narg-=2; 
    }
    else if (fbo=="-nmean") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      Nmean_=atoi(arg[2]);   arg+=2; narg-=2; 
    }
65 66 67 68 69 70 71
    else if (fbo=="-reorderfreq") {
      fgreorderfreq_=true;   arg++; narg--; 
    }
    else if (fbo=="-o") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      outfile_=arg[2];   arg+=2; narg-=2; 
    }
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    else if (fbo=="-tfm") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      int ja,jb;
      sscanf(arg[2],"%d,%d",&ja,&jb);  TFMtimebin_=ja;  TFMfreqbin_=jb;   fgTFM_=true;  arg+=2; narg-=2; 
    }
    else if (fbo=="-freq") {
      if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl;  return -1; }
      double f0,df;
      sscanf(arg[2],"%lg,%lg",&f0,&df);   fbands_.push_back(P4FreqBand(f0,df));    fgdtable_=true;  arg+=2; narg-=2; 
    }    
    else fgoptarg=false;
  }
  // les arguments qui restent a la fin de la ligne de commande:
  for(int k=1; k<narg; k++) lastargs_.push_back(arg[k]);
  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"
93 94
      << "    [-o outfilename] [-gnu gain_filename] [-nmean N] [-reorderfreq] \n"
      << "     [-tfm timebin,freqbin]  [-freq f0,df] [-prt level] \n"
95 96 97 98 99
      << " -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"
100
      << " -reorderfreq: activate frequency reordering in VisiP4Reader, suitable for FFT firmware \n"
101 102 103
      << " -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"
104
      << " -prt level: define print level  \n"
105 106 107 108 109 110 111 112 113 114 115 116 117
      << 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;
  for(size_t i=0; i<fbands_.size(); i++)  os<<"FreqBand["<<i<<"]: "<<fbands_[i]<<endl;
  return os;
}