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