source: Sophya/trunk/AddOn/TAcq/svv2mtx2_1210.cc@ 3925

Last change on this file since 3925 was 3925, checked in by cmv, 15 years ago

decodage des chanum_\?.ppf et visi temps-frequence pour Pittsburgh Dec 10, reza+cmv 13/12/2010

File size: 8.5 KB
RevLine 
[3925]1// lecture des fichiers acq de Pittsburgh Dec 2010
2// et ecriture des matrices de visi temps-frequence
3// > make OBJ=$CMVPROG/obj/ EXE=$CMVPROG/exe/ chanum_1210 svv2mtx2_1210
4
5#include "sopnamsp.h"
6#include "machdefs.h"
7#include <math.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12#include <sys/stat.h>
13#include <iostream>
14#include <string>
15
16#include "pexceptions.h"
17#include "tvector.h"
18#include "fioarr.h"
19
20//--------------------------- Fonctions de ce fichier -------------------
21void usage(void);
22void usage(void)
23{
24cout<<"svv2mtx2_1012 [options] dir : lecture des fichiers acq de Pittsburgh Dec 2010"<<endl
25 <<" dir : repertoire ou se trouvent les fichiers d'acq"<<endl
26 <<" -D : visi is a duplicated one"<<endl
27 <<" -o visi.ppf : nom du ficher ppf pour ecrire la visi temps-frequence"<<endl
28 <<" -t thr : numero de la thread ayant traite cette visi [0-N]"<<endl
29 <<" -r row : numero de la ligne de la matrice acq pour cette visi [0-Nrow["<<endl
30 <<" -f freq0 : 1ere frequence en MHz"<<endl
31 <<" -T it1,it2 : numero (temps) des fichiers a traiter [it1,it2]"<<endl
32 <<" -F if1,if2,ngrpfreq : numero des frequences [if1,if2] de [0,N[ a traiter et regroupement par ngrpfreq"<<endl;
33}
34
35//----------------------------------------------------
36int main(int narg, char* arg[])
37{
38 // --- Decodage des arguments et traitement
39 string outname = "";
40 int numthread = -1, numrow = -1;
41 bool dupli = false;
42 double freq0 = 0.;
43 int ifilmin=0, ifilmax=999999;
44 int jfr1=0, jfr2=-1, ngrpfreq=1;
45 char str[2048];
46
47 char c;
48 while((c = getopt(narg,arg,"hDo:t:r:f:T:F:")) != -1) {
49 switch (c) {
50 case 'D' :
51 dupli = true;
52 break;
53 case 'o' :
54 outname = optarg;
55 break;
56 case 't' :
57 numthread = atoi(optarg);
58 break;
59 case 'r' :
60 numrow = atoi(optarg);
61 break;
62 case 'f' :
63 freq0 = atof(optarg);
64 break;
65 case 'T' :
66 sscanf(optarg,"%d,%d",&ifilmin,&ifilmax);
67 if(ifilmin<0) ifilmin=0;
68 break;
69 case 'F' :
70 sscanf(optarg,"%d,%d,%d",&jfr1,&jfr2,&ngrpfreq);
71 if(ngrpfreq<=0) ngrpfreq=1;
72 break;
73 case 'h' :
74 default :
75 usage(); return -1;
76 }
77 }
78 if(optind>=narg) {usage(); return -1;}
79 string indir = arg[optind];
80
81 cout<<"thread="<<numthread<<endl; if(numthread<0) return -2;
82 cout<<"numrow="<<numrow<<endl; if(numrow<0) return -2;
83 cout<<"dupli="<<(int)dupli<<endl;
84 cout<<"outname="<<outname<<endl; if(outname.size()<=0) return -2;
85 cout<<"indir="<<indir<<endl;
86 cout<<"freq0="<<freq0<<" MHz"<<endl;
87 cout<<"request: file "<<ifilmin<<" to "<<ifilmax<<endl; if(ifilmax<ifilmin) return -3;
88 cout<<"request: freq "<<jfr1<<" to "<<jfr2<<" grouped by "<<ngrpfreq<<endl;
89
90 // --- recherche et comptage des fichiers de visibilites
91 int nfile = 0;
92 {
93 struct stat buffer;
94 int i2 = ifilmax; ifilmax = 0;
95 bool foundfirst = false;
96 for(int ifile=0; ifile<=i2; ifile++) {
97 sprintf(str, "%s/vismtx_%d_%d.ppf",indir.c_str(),numthread,ifile);
98 int status = stat(str,&buffer);
99 if(!foundfirst && status==0) {
100 cout<<"first file found: "<<str<<endl;
101 foundfirst = true;
102 if(ifile>ifilmin) ifilmin = ifile;
103 }
104 if(!foundfirst) continue;
105 if(ifile<ifilmin) continue;
106 if(foundfirst && status) break;
107 nfile++;
108 ifilmax = ifile;
109 }
110 cout<<"Found "<<nfile<<" files from "<<ifilmin<<" to "<<ifilmax<<endl;
111 if(nfile==0 || ifilmax<ifilmin) return -4;
112 }
113
114
115 //--------------------------------------------------------------------
116 int rc = 0;
117 try {
118
119 // --- read visibility files
120 TMatrix< complex<r_4> > MVisi;
121 TVector<r_8> MeanTT(nfile);
122 TVector<r_4> Freq;
123 TVector<int_4> Npaqsum(nfile);
124 string tudeb, tufin;
125 double tudeb_day, tufin_day;
126 int nfreq = 0;
127 int lpmod = nfile/10; if(lpmod<=0) lpmod=1;
128
129 int ntimefill = 0;
130 for(int ifile=ifilmin; ifile<=ifilmax; ifile++) {
131
132 // --- Lecture d'une visi elementaire (fichier acq)
133 sprintf(str, "%s/vismtx_%d_%d.ppf",indir.c_str(),numthread,ifile);
134 if(ifile==ifilmin || ifile==ifilmax || (ifile-ifilmin)%lpmod==0)
135 cout<<ifile<<" opening: "<<str<<endl;
136 PInPersist pin(str);
137 TMatrix< complex<r_4> > vismtx;
138 pin >> vismtx;
139 tufin = (string)vismtx.Info()["DATEOBS"];
140
141 // --- Time keeping and number of summed elementary visibilities
142 MeanTT(ifile-ifilmin) = (double)vismtx.Info()["MeanTT"]/125.e6;
143 uint_4 npaqsum = vismtx.Info()["NPAQSUM"];
144
145 // --- Initialisation purposes for the first read file
146 if (ifile==ifilmin) {
147
148 tudeb = tufin;
149 printf("Reference Time: tt = %.5f sec, TU = %s\n",MeanTT(0),tudeb.c_str());
150 if(numrow>=vismtx.NRows()) {
151 cout<<"ERROR: requested numrow="<<numrow<<" => "<<vismtx.NRows()<<endl;
152 return -5;
153 }
154
155 // frequency grouping
156 int nfreq0 = vismtx.NCols();
157 cout<<"vismtx: number of frequencies = "<<nfreq0<<endl;
158 if(jfr1<=0) jfr1=0; if(jfr1>=nfreq0) jfr1=nfreq0-1;
159 if(jfr2<jfr1 || jfr2>=nfreq0) jfr2=nfreq0-1;
160 cout<<"frequency from jfr1="<<jfr1<<" to jfr2="<<jfr2<<" grouped by "<<ngrpfreq<<endl;
161 nfreq = 0; for(int i=jfr1;i<=jfr2;i+=ngrpfreq) nfreq++;
162 cout<<"frequency from [jfr1="<<jfr1<<" , jfr2="<<jfr2<<"] grouped by "<<ngrpfreq
163 <<": total of "<<nfreq<<" freq"<<endl;
164 Freq.ReSize(nfreq); Freq = 0.;
165 for(int i=0;i<nfreq;i++) {
166 int nf=0;
167 for(int j=0; j<ngrpfreq; j++) {
168 int f = jfr1 + i*ngrpfreq + j;
169 if(f>jfr2) break;
170 Freq(i) += f;
171 nf++;
172 }
173 if(nf>0) Freq(i) /= (double)nf;
174 else {cout<<"ERROR: last freq bin with 0 freq in it"<<endl; return -6;}
175 if(i<4 || i>nfreq-4) cout<<" F("<<i<<") = "<<Freq(i)<<" nf="<<nf<<endl;
176 }
177
178 // allocate visib matrice <f> vs t
179 cout<<"allocating visibility matrice ("<<nfile<<","<<nfreq<<") "
180 <<nfile*nfreq*sizeof(complex<r_4>)/1.e6<<" Mo"<<endl;
181 MVisi.ReSize(nfile,nfreq);
182 MVisi = complex<r_4>(0.,0.);
183 }
184
185 // Fill time-freq visibility matrix
186 for(int i=0;i<nfreq;i++) {
187 int nf=0;
188 for(int j=0; j<ngrpfreq; j++) {
189 int f = jfr1 + i*ngrpfreq + j;
190 if(f>jfr2) break;
191 MVisi(ifile-ifilmin,i) += vismtx(numrow,f);
192 nf++;
193 }
194 Npaqsum(ifile-ifilmin) = nf * npaqsum;
195 MVisi(ifile-ifilmin,i) /= double(Npaqsum(ifile-ifilmin));
196 }
197 ntimefill++;
198
199 } // fin boucle sur le fichiers d'acq
200 cout<<"ntimefill = "<<ntimefill<<" / "<<nfile<<endl;
201
202 // --- keeping info with visi
203 {
204 // bricolo en unite de jours depuis le 0/12/2010 a 0h
205 int y,m,d,h,mn; double s;
206 sscanf(tudeb.c_str(),"%d-%d-%dT%d:%d:%lf",&y,&m,&d,&h,&mn,&s);
207 tudeb_day = (double)d + ((double)h + mn/60. + s/3600.)/24.;
208 sscanf(tufin.c_str(),"%d-%d-%dT%d:%d:%lf",&y,&m,&d,&h,&mn,&s);
209 tufin_day = (double)d + ((double)h + mn/60. + s/3600.)/24.;
210 }
211 MVisi.Info()["nth"] = numthread;
212 MVisi.Info()["row"] = numrow;
213 MVisi.Info()["dir"] = indir;
214 MVisi.Info()["dupli"] = (dupli) ? 1: 0;
215 MVisi.Info()["TUobs_0"] = tudeb;
216 MVisi.Info()["TUobs_N"] = tufin;
217 MVisi.Info()["TUday_0"] = tudeb_day;
218 MVisi.Info()["TUday_N"] = tufin_day;
219 MVisi.Info()["TTag_0"] = MeanTT(0);
220 MVisi.Info()["TTag_N"] = MeanTT(MeanTT.Size()-1);
221 MVisi.Info()["freq0"] = freq0;
222 MVisi.Info()["dfreq0"] = 500./8192.;
223 MVisi.Info()["jfr1"] = jfr1;
224 MVisi.Info()["jfr2"] = jfr2;
225 MVisi.Info()["ngrpfreq"] = ngrpfreq;
226 MVisi.Info()["ifilmin"] = ifilmin;
227 MVisi.Info()["ifilmax"] = ifilmax;
228
229 // --- writing visibility matrix to file
230 sprintf(str,"%s",outname.c_str());
231 cout<<"writing visibility matrix to file "<<str<<endl;
232 POutPersist pos(str);
233 pos.PutObject(MeanTT,"meantt");
234 pos.PutObject(Npaqsum,"npaqsum");
235 pos.PutObject(Freq,"ifreq");
236 pos.PutObject(MVisi,"visi");
237 }
238
239 //--------------------------------------------------------------------
240 catch(PException& exc) {
241 cerr<<" svv2mtx2_1210.cc catched PException "<<exc.Msg()<<endl;
242 rc = 77;
243 }
244 catch (std::exception& sex) {
245 cerr<<"\n svv2mtx2_1210.cc std::exception :"
246 <<(string)typeid(sex).name() << "\n msg= "<<sex.what()<<endl;
247 rc = 78;
248 }
249 catch(...) {
250 cerr<<" svv2mtx2_1210.cc catched unknown (...) exception "<<endl;
251 rc = 79;
252 }
253 cout<<">>>> svv2mtx2_1210.cc ------- END ----------- RC="<<rc<<endl;
254 return rc;
255}
256
257
258/*
259openppf visi1_01_05.ppf
260
261print visi 5
262
263n/plot ifreq.val%n ! ! "cpts"
264
265n/plot npaqsum.val%n ! ! "cpts"
266
267n/plot meantt.val%n ! ! "cpts"
268cp meantt dmeantt
269c++exec dmeantt=0.; for(int i=1;i<dmeantt.Size();i++) dmeantt(i)=meantt(i)-meantt(i-1);
270n/plot dmeantt.val%n n>0 ! "cpts nsta"
271
272imag visi "cdmod"
273imag visi "cdreal"
274imag visi "cdimag"
275imag visi "cdphas"
276
277 */
Note: See TracBrowser for help on using the repository browser.