| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <string.h> | 
|---|
| 3 |  | 
|---|
| 4 | #include "branap.h" | 
|---|
| 5 | #include "minifits.h" | 
|---|
| 6 | #include "strutilxx.h" | 
|---|
| 7 | #include "sopnamsp.h" | 
|---|
| 8 |  | 
|---|
| 9 | //-------------------------------------------------------------- | 
|---|
| 10 | // Projet BAORadio - (C) LAL/IRFU  2008-2010 | 
|---|
| 11 | // Classe de gestion des parametres programmes d'analyse | 
|---|
| 12 | //-------------------------------------------------------------- | 
|---|
| 13 |  | 
|---|
| 14 | /* --Methode-- */ | 
|---|
| 15 | BRAnaParam::BRAnaParam(uint_4 nmean, uint_4 nzon, uint_4 npaqz) | 
|---|
| 16 | { | 
|---|
| 17 | outpath_="./"; | 
|---|
| 18 | nmean_=nmean; | 
|---|
| 19 | nbloc_=1; | 
|---|
| 20 | imin_=imax_=0; | 
|---|
| 21 | istep_=1; | 
|---|
| 22 | freqmin_=freqmax_=0; | 
|---|
| 23 | nbinfreq_=1; | 
|---|
| 24 | paqsize_=16424; | 
|---|
| 25 | nzones_=nzon; | 
|---|
| 26 | npaqinzone_=npaqz; | 
|---|
| 27 | prtlevel_=0; | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | /* --Methode-- */ | 
|---|
| 31 | int BRAnaParam::DecodeArgs(int narg, char* arg[]) | 
|---|
| 32 | { | 
|---|
| 33 | if ((narg>1)&&(strcmp(arg[1],"-h")==0))  return Usage(false); | 
|---|
| 34 | if (narg<5) return Usage(true); | 
|---|
| 35 |  | 
|---|
| 36 | bool okarg=false; | 
|---|
| 37 | int ka=1; | 
|---|
| 38 | while (ka<(narg-1)) { | 
|---|
| 39 | if (strcmp(arg[ka],"-act")==0) { | 
|---|
| 40 | action_=arg[ka+1]; | 
|---|
| 41 | ka+=2; | 
|---|
| 42 | } | 
|---|
| 43 | else if (strcmp(arg[ka],"-out")==0) { | 
|---|
| 44 | outpath_=arg[ka+1]; | 
|---|
| 45 | size_t lenp=outpath_.size(); | 
|---|
| 46 | if ((lenp>0)&&(outpath_[lenp-1]!='/'))  outpath_+='/'; | 
|---|
| 47 | ka+=2; | 
|---|
| 48 | } | 
|---|
| 49 | else if (strcmp(arg[ka],"-nmean")==0) { | 
|---|
| 50 | nmean_=atoi(arg[ka+1]); | 
|---|
| 51 | ka+=2; | 
|---|
| 52 | } | 
|---|
| 53 | else if (strcmp(arg[ka],"-nbloc")==0) { | 
|---|
| 54 | nbloc_=atoi(arg[ka+1]); | 
|---|
| 55 | ka+=2; | 
|---|
| 56 | } | 
|---|
| 57 | else if (strcmp(arg[ka],"-freq")==0) { | 
|---|
| 58 | sscanf(arg[ka+1],"%d,%d,%d",&freqmin_,&freqmax_,&nbinfreq_); | 
|---|
| 59 | ka+=2; | 
|---|
| 60 | } | 
|---|
| 61 | else if (strcmp(arg[ka],"-zones")==0) { | 
|---|
| 62 | int nzon=4; | 
|---|
| 63 | int npaqz=128; | 
|---|
| 64 | sscanf(arg[ka+1],"%d,%d",&nzon,&npaqz); | 
|---|
| 65 | nzones_=nzon;  npaqinzone_=npaqz; | 
|---|
| 66 | ka+=2; | 
|---|
| 67 | } | 
|---|
| 68 | else if (strcmp(arg[ka],"-prtlev")==0) { | 
|---|
| 69 | prtlevel_=atoi(arg[ka+1]); | 
|---|
| 70 | ka+=2; | 
|---|
| 71 | } | 
|---|
| 72 | else if (strcmp(arg[ka],"-in")==0) { | 
|---|
| 73 | if ((narg-ka)<4)  { | 
|---|
| 74 | cout << " BRAnaParam::DecodeArgs() / Argument error " << endl; | 
|---|
| 75 | return Usage(true); | 
|---|
| 76 | } | 
|---|
| 77 | sscanf(arg[ka+1],"%d,%d,%d",&imin_,&imax_,&istep_);  ka+=2; | 
|---|
| 78 | while(ka<(narg-1)) { | 
|---|
| 79 | string inpath = arg[ka]; | 
|---|
| 80 | size_t lenp=inpath.size(); | 
|---|
| 81 | if (lenp<1)  inpath="./"; | 
|---|
| 82 | if ((lenp>0)&&(inpath[lenp-1]!='/'))  inpath+='/'; | 
|---|
| 83 | vector<string> fiblist; | 
|---|
| 84 | string sa1 = arg[ka+1]; | 
|---|
| 85 | FillVStringFrString(sa1, fiblist, ','); | 
|---|
| 86 | char dbuff[32]; | 
|---|
| 87 | for(size_t i=0; i<fiblist.size(); i++) { | 
|---|
| 88 | sprintf(dbuff,"Fiber%d/",(int)atoi(fiblist[i].c_str())); | 
|---|
| 89 | dirlist_.push_back(inpath+dbuff); | 
|---|
| 90 | } | 
|---|
| 91 | ka += 2; | 
|---|
| 92 | } | 
|---|
| 93 | okarg=true; | 
|---|
| 94 | } | 
|---|
| 95 | else ka++; | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | if (!okarg) { | 
|---|
| 99 | cout << " BRAnaParam::DecodeArgs() / Argument error " << endl; | 
|---|
| 100 | return Usage(true); | 
|---|
| 101 | } | 
|---|
| 102 | return 0; | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | /* --Methode-- */ | 
|---|
| 106 | int BRAnaParam::Usage(bool fgshort) | 
|---|
| 107 | { | 
|---|
| 108 | cout << " --- BRAnaParam : Reading/Processing BAORadio FITS files parameters " << endl; | 
|---|
| 109 | cout << " Usage:  prgname [-act ACT] [-out OutPath] [-nmean NMean] [-zones NZones,nPaqinZone] \n" | 
|---|
| 110 | << "                 [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] [-prtlev lev] \n" | 
|---|
| 111 | << "         -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] \n" << endl; | 
|---|
| 112 | if (fgshort) { | 
|---|
| 113 | cout << " prgname -h for detailed instructions" << endl; | 
|---|
| 114 | return 5; | 
|---|
| 115 | } | 
|---|
| 116 | cout << " -act Action: cube3d or vis or viscktt  \n" | 
|---|
| 117 | << "    cube3d: create 3D fits cubes, vis: compute visibilites,  \n" | 
|---|
| 118 | << "    viscktt: compute visibilities and check TimeTag/FrameCounter\n " | 
|---|
| 119 | << " -out OutPath: Output directory name \n" | 
|---|
| 120 | << " -nmean NMean: Number of packet used for spectra/visibility computation \n" | 
|---|
| 121 | << " -nbloc NBloc: Number of MemMgr blocs in output file\n" | 
|---|
| 122 | << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone \n" | 
|---|
| 123 | << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n" | 
|---|
| 124 | << " -prtlev lev : Print level (0,1,2...) \n" | 
|---|
| 125 | << " -in : input files/directory definition : \n" | 
|---|
| 126 | << "       Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n" | 
|---|
| 127 | << "       InPath: Input directerory fits files in InPath/FiberJJ directory \n" | 
|---|
| 128 | << "       FiberList: List of fiber numbers (JJ - Ex: 2,1,4 )  \n" << endl; | 
|---|
| 129 | return 1; | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 | /* --Fonction-- */ | 
|---|
| 133 | int BRAnaParam::PaqSizeFromFits() | 
|---|
| 134 | { | 
|---|
| 135 | uint_4 paqsz, npaqf; | 
|---|
| 136 | char flnm[1024]; | 
|---|
| 137 | sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_); | 
|---|
| 138 | return DecodeMiniFitsHeader(flnm,paqsize_, npaqinfile_); | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | /* --Fonction-- */ | 
|---|
| 142 | ostream& BRAnaParam::Print(ostream& os) | 
|---|
| 143 | { | 
|---|
| 144 | os << " BRAnaParam::Print() dirlist_.size()=" << dirlist_.size() << " Input directories: " << endl; | 
|---|
| 145 | for(size_t k=0; k< dirlist_.size(); k++) | 
|---|
| 146 | cout << k+1 << " :  " << dirlist_[k] << endl; | 
|---|
| 147 | cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_ << endl; | 
|---|
| 148 | cout << " OutPath= " << outpath_ << endl; | 
|---|
| 149 | cout << " Action=" << action_ << "  NMean=" << nmean_ << " NBloc=" << nbloc_ << endl; | 
|---|
| 150 | cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl; | 
|---|
| 151 | cout << " PaqSize=" << paqsize_ << "  -  NZones=" << nzones_ << " NPaqZone=" << npaqinzone_ | 
|---|
| 152 | << " PrtLevel=" << prtlevel_ << endl; | 
|---|
| 153 | return os; | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | /* --Fonction-- */ | 
|---|
| 157 | int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq) | 
|---|
| 158 | { | 
|---|
| 159 | cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl; | 
|---|
| 160 | MiniFITSFile mff(filename, MF_Read); | 
|---|
| 161 | cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() | 
|---|
| 162 | << " NAxis2=" << mff.NAxis2() << endl; | 
|---|
| 163 | paqsz = mff.NAxis1(); | 
|---|
| 164 | npaq = mff.NAxis2(); | 
|---|
| 165 | return 0; | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|