source: Sophya/trunk/AddOn/TAcq/svv2mtx.cc@ 3646

Last change on this file since 3646 was 3646, checked in by ansari, 16 years ago

Ajout du programme svv2mtx.cc de lecture des fichiers de mcrd.cc pour faire des tableaux 2D (matrices) temps-frequence + corrections mineures, Reza 09/06/2009

File size: 6.2 KB
RevLine 
[3646]1// Utilisation de SOPHYA pour faciliter les tests ...
2#include "sopnamsp.h"
3#include "machdefs.h"
4
5/* ----------------------------------------------------------
6 Programme de lecture multi canaux pour BAORadio
7 R. Ansari, C. Magneville
8 V : Mai 2009
9 ---------------------------------------------------------- */
10
11// include standard c/c++
12#include <math.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17#include <iostream>
18#include <string>
19
20#include "pexceptions.h"
21#include "tvector.h"
22#include "fioarr.h"
23// #include "tarrinit.h"
24#include "ntuple.h"
25#include "histinit.h"
26#include "matharr.h"
27#include "timestamp.h"
28/*
29#include "fftpserver.h"
30#include "fftwserver.h"
31
32#include "FFTW/fftw3.h"
33*/
34// include sophya mesure ressource CPU/memoire ...
35#include "resusage.h"
36#include "ctimer.h"
37#include "timing.h"
38
39
40int Usage(bool fgshort=true);
41// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
42int ProcSVFiles(string& inoutpath, int imin, int imax, int istep, int jf1, int jf2, int card=1);
43
44//----------------------------------------------------
45//----------------------------------------------------
46int main(int narg, char* arg[])
47{
48 if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
49 if (narg<4) return Usage(true);
50
51 HiStatsInitiator _inia;
52 // TArrayInitiator _inia;
53
54 int rc = 0;
55 try {
56 string inoutpath = arg[1];
57 int imin=0;
58 int imax=0;
59 int istep=1;
60 sscanf(arg[2],"%d,%d,%d",&imin,&imax,&istep);
61 int jf1=0;
62 int jf2=0;
63 sscanf(arg[3],"%d,%d",&jf1,&jf2);
64 cout << " ----- svv2mtx.cc Start - InOutPath= " << inoutpath << " IMin,Max,Step="
65 << imin << "," << imax << "," << istep << " JF=" << jf1 << "," << jf2 << " ------- " << endl;
66 int card=1;
67 if (narg>4) card=atoi(arg[3]);
68 ResourceUsage resu;
69 rc=ProcSVFiles(inoutpath, imin, imax, istep, jf1, jf2, card);
70 resu.Update();
71 cout << resu;
72 }
73 catch (PException& exc) {
74 cerr << " svv2mtx.cc catched MiniFITSException " << exc.Msg() << endl;
75 rc = 77;
76 }
77 catch (std::exception& sex) {
78 cerr << "\n svv2mtx.cc std::exception :"
79 << (string)typeid(sex).name() << "\n msg= "
80 << sex.what() << endl;
81 rc = 78;
82 }
83 catch (...) {
84 cerr << " svv2mtx.cc catched unknown (...) exception " << endl;
85 rc = 79;
86 }
87
88 cout << ">>>> svv2mtx.cc ------- END ----------- RC=" << rc << endl;
89 return rc;
90
91}
92
93
94
95// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
96int ProcSVFiles(string& inoutpath, int imin, int imax, int istep, int jf1, int jf2, int card)
97{
98 Timer tm("ProcSVFiles");
99 char fname[512];
100// NTuple
101 const char* nnames[8] = {"fcs","tts","s1","s2","s12","s12re","s12im","s12phi"};
102 NTuple nt(8, nnames);
103 double xnt[10];
104 uint_4 nmnt = 0;
105 double ms1,ms2,ms12,ms12re,ms12im,ms12phi;
106
107 TMatrix<r_4> s1, s2;
108 TMatrix<r_4> v12re, v12im, v12phi;
109 sa_size_t ncols = (imax-imin+1)/istep;
110 sa_size_t nrows = 10;
111 sa_size_t kc=0;
112 for(int ifile=imin; ifile<=imax; ifile+=istep) {
113 if (card==2)
114 sprintf(fname, "%s/Ch34_%d.ppf",inoutpath.c_str(),ifile);
115 else
116 sprintf(fname, "%s/Ch12_%d.ppf",inoutpath.c_str(),ifile);
117 cout << " ProcSVFiles[" << ifile << "] opening file " << fname << endl;
118 PInPersist pin(fname);
119 string tag1="specV1";
120 string tag2="specV2";
121 string tag12="visiV12";
122 if (card==2) {
123 tag1 = "specV3";
124 tag2 = "specV4";
125 tag12="visiV34";
126 }
127 TVector<r_4> sv1;
128 TVector<r_4> sv2;
129 TVector< complex<r_4> > vv12;
130 pin >> PPFNameTag(tag1) >> sv1;
131 pin >> PPFNameTag(tag2) >> sv2;
132 pin >> PPFNameTag(tag12) >> vv12;
133 if (ifile==imin) {
134 nrows = sv1.Size();
135 cout << " ProcSVFiles/Info: Output s1,s2 matrix size NRows=NFreq="
136 << nrows << " NCols=NFiles=" << ncols << endl;
137 s1.SetSize(nrows, ncols);
138 s2.SetSize(nrows, ncols);
139 nrows = vv12.Size();
140 cout << " ProcSVFiles/Info: Output v12 matrix size NRows=NFreq="
141 << nrows << " NCols=NFiles=" << ncols << endl;
142 v12re.SetSize(nrows, ncols);
143 v12im.SetSize(nrows, ncols);
144 v12phi.SetSize(nrows, ncols);
145 }
146 s1.Column(kc) = sv1;
147 s2.Column(kc) = sv2;
148 v12re.Column(kc) = real(vv12);
149 v12im.Column(kc) = imag(vv12);
150 v12phi.Column(kc) = phase(vv12);
151 nmnt=0; ms1=ms2=ms12=ms12re=ms12im=ms12phi=0.;
152 for(sa_size_t jf=jf1; jf<=jf2; jf++) {
153 ms1 += s1(jf,kc);
154 ms2 += s2(jf,kc);
155 ms12re += v12re(jf,kc);
156 ms12im += v12im(jf,kc);
157 ms12phi += v12phi(jf,kc);
158 }
159 nmnt = (jf2-jf1+1);
160 if (nmnt>0) {
161 double fnorm = (double)nmnt;
162 xnt[0] = kc;
163 xnt[1] = 0;
164 xnt[2] = ms1 /= fnorm;
165 xnt[3] = ms2 /= fnorm;
166 xnt[4] = ms12 /= fnorm;
167 xnt[5] = ms12re /= fnorm;
168 xnt[6] = ms12im /= fnorm;
169 xnt[7] = ms12phi /= fnorm;
170 nt.Fill(xnt);
171 }
172
173 kc++;
174
175 }
176 if (card==2)
177 sprintf(fname, "%s/Ch34mtx.ppf",inoutpath.c_str());
178 else
179 sprintf(fname, "%s/Ch12mtx.ppf",inoutpath.c_str());
180
181 cout << nt;
182 cout << "ProcSVFiles: Opening file " << fname << " for writing" << endl;
183 POutPersist po(fname);
184 string tag1="s1";
185 string tag2="s2";
186 string tag12r="v12re";
187 string tag12i="v12im";
188 string tag12p="v12phi";
189 string tagnt="nt12";
190 if (card==2) {
191 tag1="s3";
192 tag2="s4";
193 tag12r="v34re";
194 tag12i="v34im";
195 tag12p="v34phi";
196 tagnt="nt34";
197 }
198 po << PPFNameTag(tag1) << s1;
199 po << PPFNameTag(tag2) << s2;
200 po << PPFNameTag(tag12r) << v12re;
201 po << PPFNameTag(tag12i) << v12im;
202 po << PPFNameTag(tag12p) << v12phi;
203 po << PPFNameTag(tagnt) << nt;
204 cout << "ProcSVFiles: Matrices s1, s2, v12re, v12im, v12phi, NTuple nt written to file " << fname << endl;
205 return 0;
206}
207
208
209
210
211/* --Fonction-- */
212int Usage(bool fgshort)
213{
214 cout << " --- svv2mtx.cc : Read PPF files produced by mcrd to make matrices BAORadio" << endl;
215 cout << " Usage: mcrd InOutPath Imin,Imax,step NumFreq1,NumFreq2 [card=1]" << endl;
216 if (fgshort) {
217 cout << " mcrd -h for detailed instructions" << endl;
218 return 1;
219 }
220 cout << " InOutPath : Input/Output directory name " << endl;
221 cout << " Imin,Imax,IStep: Input PPF files sequence number \n"
222 << " FileNames=InOutPath/Ch12_II.fits Imin<=II<=Imax II+=IStep \n"
223 << " card=1 Ch12 , card=2 Ch34 " << endl;
224 return 1;
225}
Note: See TracBrowser for help on using the repository browser.