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 | fgdatafft_=false; fgsinglechannel_=false;
|
---|
28 | prtlevel_=0;
|
---|
29 | nbcalgrp_=1;
|
---|
30 | nthreads_=1;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /* --Methode-- */
|
---|
34 | int BRAnaParam::DecodeArgs(int narg, char* arg[])
|
---|
35 | {
|
---|
36 | if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
|
---|
37 | if (narg<5) return Usage(true);
|
---|
38 |
|
---|
39 | bool okarg=false;
|
---|
40 | int ka=1;
|
---|
41 | while (ka<(narg-1)) {
|
---|
42 | if (strcmp(arg[ka],"-act")==0) {
|
---|
43 | action_=arg[ka+1];
|
---|
44 | ka+=2;
|
---|
45 | }
|
---|
46 | else if (strcmp(arg[ka],"-out")==0) {
|
---|
47 | outpath_=arg[ka+1];
|
---|
48 | size_t lenp=outpath_.size();
|
---|
49 | if ((lenp>0)&&(outpath_[lenp-1]!='/')) outpath_+='/';
|
---|
50 | ka+=2;
|
---|
51 | }
|
---|
52 | else if (strcmp(arg[ka],"-nmean")==0) {
|
---|
53 | nmean_=atoi(arg[ka+1]);
|
---|
54 | ka+=2;
|
---|
55 | }
|
---|
56 | else if (strcmp(arg[ka],"-nbloc")==0) {
|
---|
57 | nbloc_=atoi(arg[ka+1]);
|
---|
58 | ka+=2;
|
---|
59 | }
|
---|
60 | else if (strcmp(arg[ka],"-freq")==0) {
|
---|
61 | sscanf(arg[ka+1],"%d,%d,%d",&freqmin_,&freqmax_,&nbinfreq_);
|
---|
62 | ka+=2;
|
---|
63 | }
|
---|
64 | else if (strcmp(arg[ka],"-zones")==0) {
|
---|
65 | int nzon=4;
|
---|
66 | int npaqz=128;
|
---|
67 | sscanf(arg[ka+1],"%d,%d",&nzon,&npaqz);
|
---|
68 | nzones_=nzon; npaqinzone_=npaqz;
|
---|
69 | ka+=2;
|
---|
70 | }
|
---|
71 | else if (strcmp(arg[ka],"-prtlev")==0) {
|
---|
72 | prtlevel_=atoi(arg[ka+1]);
|
---|
73 | ka+=2;
|
---|
74 | }
|
---|
75 | else if (strcmp(arg[ka],"-nthr")==0) {
|
---|
76 | nthreads_=atoi(arg[ka+1]);
|
---|
77 | ka+=2;
|
---|
78 | }
|
---|
79 | else if (strcmp(arg[ka],"-nvcal")==0) {
|
---|
80 | nbcalgrp_=atoi(arg[ka+1]);
|
---|
81 | ka+=2;
|
---|
82 | }
|
---|
83 | else if (strcmp(arg[ka],"-in")==0) {
|
---|
84 | if ((narg-ka)<4) {
|
---|
85 | cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
|
---|
86 | return Usage(true);
|
---|
87 | }
|
---|
88 | sscanf(arg[ka+1],"%d,%d,%d",&imin_,&imax_,&istep_); ka+=2;
|
---|
89 | while(ka<(narg-1)) {
|
---|
90 | string inpath = arg[ka];
|
---|
91 | size_t lenp=inpath.size();
|
---|
92 | if (lenp<1) inpath="./";
|
---|
93 | if ((lenp>0)&&(inpath[lenp-1]!='/')) inpath+='/';
|
---|
94 | vector<string> fiblist;
|
---|
95 | string sa1 = arg[ka+1];
|
---|
96 | FillVStringFrString(sa1, fiblist, ',');
|
---|
97 | char dbuff[32];
|
---|
98 | for(size_t i=0; i<fiblist.size(); i++) {
|
---|
99 | sprintf(dbuff,"Fiber%d/",(int)atoi(fiblist[i].c_str()));
|
---|
100 | dirlist_.push_back(inpath+dbuff);
|
---|
101 | }
|
---|
102 | ka += 2;
|
---|
103 | }
|
---|
104 | okarg=true;
|
---|
105 | }
|
---|
106 | else ka++;
|
---|
107 | }
|
---|
108 |
|
---|
109 | if (!okarg) {
|
---|
110 | cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
|
---|
111 | return Usage(true);
|
---|
112 | }
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /* --Methode-- */
|
---|
117 | int BRAnaParam::Usage(bool fgshort)
|
---|
118 | {
|
---|
119 | cout << " --- BRAnaParam : Reading/Processing BAORadio FITS files parameters " << endl;
|
---|
120 | cout << " Usage: prgname [-act ACT] [-out OutPath] [-nmean NMean] [-zones NZones,nPaqinZone] \n"
|
---|
121 | << " [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] \n"
|
---|
122 | << " [-prtlev lev] [-nvcal n] [-nthr n] \n"
|
---|
123 | << " -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] \n" << endl;
|
---|
124 | if (fgshort) {
|
---|
125 | cout << " prgname -h for detailed instructions" << endl;
|
---|
126 | return 5;
|
---|
127 | }
|
---|
128 | cout << " -act Action: cube3d or vis or viscktt or mspec \n"
|
---|
129 | << " cube3d: create 3D fits cubes, vis: compute visibilites, \n"
|
---|
130 | << " viscktt: compute visibilities and check TimeTag/FrameCounter\n "
|
---|
131 | << " mspec: compute and save mean spectra for each channel \n "
|
---|
132 | << " -out OutPath: Output directory name \n"
|
---|
133 | << " -nmean NMean: Number of packet used for spectra/visibility computation \n"
|
---|
134 | << " -nbloc NBloc: Number of MemMgr blocs in output file\n"
|
---|
135 | << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone \n"
|
---|
136 | << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n"
|
---|
137 | << " -prtlev lev : Print level (0,1,2...) \n"
|
---|
138 | << " -nvcal n : number of BRVisibilityCalculator objects running in parallel in BRVisCalcGroup (default=1) \n"
|
---|
139 | << " -nthr n : number of threads for parallel execution in BRVisibilityCalculator (default=1) \n"
|
---|
140 | << " -in : input files/directory definition : \n"
|
---|
141 | << " Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n"
|
---|
142 | << " InPath: Input directerory fits files in InPath/FiberJJ directory \n"
|
---|
143 | << " FiberList: List of fiber numbers (JJ - Ex: 2,1,4 ) \n" << endl;
|
---|
144 | return 1;
|
---|
145 | }
|
---|
146 |
|
---|
147 | /* --Fonction-- */
|
---|
148 | int BRAnaParam::PaqSizeFromFits()
|
---|
149 | {
|
---|
150 | uint_4 paqsz, npaqf;
|
---|
151 | char flnm[1024];
|
---|
152 | sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_);
|
---|
153 | return DecodeMiniFitsHeader(flnm,paqsize_, npaqinfile_,fgdatafft_, fgsinglechannel_);
|
---|
154 | }
|
---|
155 |
|
---|
156 | /* --Fonction-- */
|
---|
157 | ostream& BRAnaParam::Print(ostream& os)
|
---|
158 | {
|
---|
159 | os << " BRAnaParam::Print() dirlist_.size()=" << dirlist_.size() << " Input directories: " << endl;
|
---|
160 | for(size_t k=0; k< dirlist_.size(); k++)
|
---|
161 | cout << k+1 << " : " << dirlist_[k] << endl;
|
---|
162 | cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_ << endl;
|
---|
163 | cout << " OutPath= " << outpath_ << endl;
|
---|
164 | cout << " Action=" << action_ << " NMean=" << nmean_ << " NBloc=" << nbloc_ << endl;
|
---|
165 | cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl;
|
---|
166 | cout << " PaqSize=" << paqsize_ << " - NZones=" << nzones_ << " NPaqZone=" << npaqinzone_
|
---|
167 | << " PrtLevel=" << prtlevel_ << endl;
|
---|
168 | cout << " AcqMode: " << ((fgdatafft_)?" Data_FFT " : " Data_Raw " )
|
---|
169 | << ((fgsinglechannel_)?" SingleChannel " : " TwoChannels " ) << endl;
|
---|
170 | cout << " NbVisibCalculator in Group: " << nbcalgrp_ << " with N//threads: " << nthreads_ << endl;
|
---|
171 |
|
---|
172 |
|
---|
173 | return os;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /* --Fonction-- */
|
---|
177 | int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq,
|
---|
178 | bool& fgdatafft, bool& fgsinglechannel)
|
---|
179 | {
|
---|
180 | cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl;
|
---|
181 | MiniFITSFile mff(filename, MF_Read);
|
---|
182 | string acqmode=mff.GetKeyValue("ACQMODE");
|
---|
183 | cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
|
---|
184 | << " NAxis2=" << mff.NAxis2() << " AcqMode=" << acqmode << endl;
|
---|
185 | paqsz = mff.NAxis1();
|
---|
186 | npaq = mff.NAxis2();
|
---|
187 | if (acqmode.substr(0,3)=="fft") fgdatafft=true;
|
---|
188 | if (acqmode.find("1c") < acqmode.length()) fgsinglechannel=true;
|
---|
189 | return 0;
|
---|
190 | }
|
---|
191 |
|
---|