[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 -------------------
|
---|
| 21 | void usage(void);
|
---|
| 22 | void usage(void)
|
---|
| 23 | {
|
---|
| 24 | cout<<"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 | //----------------------------------------------------
|
---|
| 36 | int 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.;
|
---|
[3926] | 43 | int ifilmin=0, ifilmax=99999;
|
---|
[3925] | 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
|
---|
[3926] | 91 | // ATTENTION: il peut manquer des fichiers au debut ou dans la sequence
|
---|
| 92 | struct stat buffer;
|
---|
[3925] | 93 | int nfile = 0;
|
---|
| 94 | {
|
---|
[3926] | 95 | int ifmin2 = ifilmin, ifmax2 = ifilmax; ifilmax = -1;
|
---|
[3925] | 96 | bool foundfirst = false;
|
---|
[3926] | 97 | for(int ifile=ifmin2; ifile<=ifmax2; ifile++) {
|
---|
[3925] | 98 | sprintf(str, "%s/vismtx_%d_%d.ppf",indir.c_str(),numthread,ifile);
|
---|
| 99 | int status = stat(str,&buffer);
|
---|
| 100 | if(!foundfirst && status==0) {
|
---|
| 101 | cout<<"first file found: "<<str<<endl;
|
---|
| 102 | foundfirst = true;
|
---|
| 103 | if(ifile>ifilmin) ifilmin = ifile;
|
---|
| 104 | }
|
---|
| 105 | if(!foundfirst) continue;
|
---|
| 106 | if(ifile<ifilmin) continue;
|
---|
[3926] | 107 | if(foundfirst && status!=0) continue;
|
---|
[3925] | 108 | nfile++;
|
---|
| 109 | ifilmax = ifile;
|
---|
| 110 | }
|
---|
| 111 | cout<<"Found "<<nfile<<" files from "<<ifilmin<<" to "<<ifilmax<<endl;
|
---|
| 112 | if(nfile==0 || ifilmax<ifilmin) return -4;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | //--------------------------------------------------------------------
|
---|
| 117 | int rc = 0;
|
---|
| 118 | try {
|
---|
| 119 |
|
---|
| 120 | // --- read visibility files
|
---|
| 121 | TMatrix< complex<r_4> > MVisi;
|
---|
| 122 | TVector<r_8> MeanTT(nfile);
|
---|
| 123 | TVector<r_4> Freq;
|
---|
| 124 | TVector<int_4> Npaqsum(nfile);
|
---|
| 125 | string tudeb, tufin;
|
---|
| 126 | double tudeb_day, tufin_day;
|
---|
| 127 | int nfreq = 0;
|
---|
| 128 | int lpmod = nfile/10; if(lpmod<=0) lpmod=1;
|
---|
| 129 |
|
---|
[3926] | 130 | int ntimefill = 0, ntimebad = 0;
|
---|
[3925] | 131 | for(int ifile=ifilmin; ifile<=ifilmax; ifile++) {
|
---|
| 132 |
|
---|
| 133 | // --- Lecture d'une visi elementaire (fichier acq)
|
---|
| 134 | sprintf(str, "%s/vismtx_%d_%d.ppf",indir.c_str(),numthread,ifile);
|
---|
[3926] | 135 | int status = stat(str,&buffer);
|
---|
| 136 | if(status) continue; // fichier inexistant
|
---|
[3925] | 137 | if(ifile==ifilmin || ifile==ifilmax || (ifile-ifilmin)%lpmod==0)
|
---|
[3926] | 138 | cout<<ntimefill<<" "<<ifile<<" opening: "<<str<<endl;
|
---|
[3925] | 139 | TMatrix< complex<r_4> > vismtx;
|
---|
[3926] | 140 | try {
|
---|
| 141 | PInPersist pin(str);
|
---|
| 142 | pin >> vismtx;
|
---|
| 143 | } catch(...) {
|
---|
| 144 | cout<<"ERROR: bad file "<<str<<endl;
|
---|
| 145 | ntimebad++;
|
---|
| 146 | continue;
|
---|
| 147 | }
|
---|
[3925] | 148 | tufin = (string)vismtx.Info()["DATEOBS"];
|
---|
| 149 |
|
---|
| 150 | // --- Time keeping and number of summed elementary visibilities
|
---|
[3926] | 151 | MeanTT(ntimefill) = (double)vismtx.Info()["MeanTT"]/125.e6;
|
---|
[3925] | 152 | uint_4 npaqsum = vismtx.Info()["NPAQSUM"];
|
---|
| 153 |
|
---|
| 154 | // --- Initialisation purposes for the first read file
|
---|
| 155 | if (ifile==ifilmin) {
|
---|
| 156 |
|
---|
| 157 | tudeb = tufin;
|
---|
| 158 | printf("Reference Time: tt = %.5f sec, TU = %s\n",MeanTT(0),tudeb.c_str());
|
---|
| 159 | if(numrow>=vismtx.NRows()) {
|
---|
| 160 | cout<<"ERROR: requested numrow="<<numrow<<" => "<<vismtx.NRows()<<endl;
|
---|
| 161 | return -5;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | // frequency grouping
|
---|
| 165 | int nfreq0 = vismtx.NCols();
|
---|
| 166 | cout<<"vismtx: number of frequencies = "<<nfreq0<<endl;
|
---|
| 167 | if(jfr1<=0) jfr1=0; if(jfr1>=nfreq0) jfr1=nfreq0-1;
|
---|
| 168 | if(jfr2<jfr1 || jfr2>=nfreq0) jfr2=nfreq0-1;
|
---|
| 169 | cout<<"frequency from jfr1="<<jfr1<<" to jfr2="<<jfr2<<" grouped by "<<ngrpfreq<<endl;
|
---|
| 170 | nfreq = 0; for(int i=jfr1;i<=jfr2;i+=ngrpfreq) nfreq++;
|
---|
| 171 | cout<<"frequency from [jfr1="<<jfr1<<" , jfr2="<<jfr2<<"] grouped by "<<ngrpfreq
|
---|
| 172 | <<": total of "<<nfreq<<" freq"<<endl;
|
---|
| 173 | Freq.ReSize(nfreq); Freq = 0.;
|
---|
| 174 | for(int i=0;i<nfreq;i++) {
|
---|
| 175 | int nf=0;
|
---|
| 176 | for(int j=0; j<ngrpfreq; j++) {
|
---|
| 177 | int f = jfr1 + i*ngrpfreq + j;
|
---|
| 178 | if(f>jfr2) break;
|
---|
| 179 | Freq(i) += f;
|
---|
| 180 | nf++;
|
---|
| 181 | }
|
---|
| 182 | if(nf>0) Freq(i) /= (double)nf;
|
---|
| 183 | else {cout<<"ERROR: last freq bin with 0 freq in it"<<endl; return -6;}
|
---|
| 184 | if(i<4 || i>nfreq-4) cout<<" F("<<i<<") = "<<Freq(i)<<" nf="<<nf<<endl;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | // allocate visib matrice <f> vs t
|
---|
| 188 | cout<<"allocating visibility matrice ("<<nfile<<","<<nfreq<<") "
|
---|
| 189 | <<nfile*nfreq*sizeof(complex<r_4>)/1.e6<<" Mo"<<endl;
|
---|
| 190 | MVisi.ReSize(nfile,nfreq);
|
---|
| 191 | MVisi = complex<r_4>(0.,0.);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | // Fill time-freq visibility matrix
|
---|
| 195 | for(int i=0;i<nfreq;i++) {
|
---|
| 196 | int nf=0;
|
---|
| 197 | for(int j=0; j<ngrpfreq; j++) {
|
---|
| 198 | int f = jfr1 + i*ngrpfreq + j;
|
---|
| 199 | if(f>jfr2) break;
|
---|
[3926] | 200 | MVisi(ntimefill,i) += vismtx(numrow,f);
|
---|
[3925] | 201 | nf++;
|
---|
| 202 | }
|
---|
[3926] | 203 | Npaqsum(ntimefill) = nf * npaqsum;
|
---|
| 204 | MVisi(ntimefill,i) /= double(Npaqsum(ntimefill));
|
---|
[3925] | 205 | }
|
---|
| 206 | ntimefill++;
|
---|
| 207 |
|
---|
| 208 | } // fin boucle sur le fichiers d'acq
|
---|
[3926] | 209 | cout<<"ntimefill = "<<ntimefill<<" / "<<nfile<<" , ntimebad="<<ntimebad<<" bad files"<<endl;
|
---|
[3925] | 210 |
|
---|
| 211 | // --- keeping info with visi
|
---|
| 212 | {
|
---|
| 213 | // bricolo en unite de jours depuis le 0/12/2010 a 0h
|
---|
| 214 | int y,m,d,h,mn; double s;
|
---|
| 215 | sscanf(tudeb.c_str(),"%d-%d-%dT%d:%d:%lf",&y,&m,&d,&h,&mn,&s);
|
---|
| 216 | tudeb_day = (double)d + ((double)h + mn/60. + s/3600.)/24.;
|
---|
| 217 | sscanf(tufin.c_str(),"%d-%d-%dT%d:%d:%lf",&y,&m,&d,&h,&mn,&s);
|
---|
| 218 | tufin_day = (double)d + ((double)h + mn/60. + s/3600.)/24.;
|
---|
| 219 | }
|
---|
| 220 | MVisi.Info()["nth"] = numthread;
|
---|
| 221 | MVisi.Info()["row"] = numrow;
|
---|
| 222 | MVisi.Info()["dir"] = indir;
|
---|
| 223 | MVisi.Info()["dupli"] = (dupli) ? 1: 0;
|
---|
| 224 | MVisi.Info()["TUobs_0"] = tudeb;
|
---|
| 225 | MVisi.Info()["TUobs_N"] = tufin;
|
---|
| 226 | MVisi.Info()["TUday_0"] = tudeb_day;
|
---|
| 227 | MVisi.Info()["TUday_N"] = tufin_day;
|
---|
| 228 | MVisi.Info()["TTag_0"] = MeanTT(0);
|
---|
| 229 | MVisi.Info()["TTag_N"] = MeanTT(MeanTT.Size()-1);
|
---|
| 230 | MVisi.Info()["freq0"] = freq0;
|
---|
| 231 | MVisi.Info()["dfreq0"] = 500./8192.;
|
---|
| 232 | MVisi.Info()["jfr1"] = jfr1;
|
---|
| 233 | MVisi.Info()["jfr2"] = jfr2;
|
---|
| 234 | MVisi.Info()["ngrpfreq"] = ngrpfreq;
|
---|
| 235 | MVisi.Info()["ifilmin"] = ifilmin;
|
---|
| 236 | MVisi.Info()["ifilmax"] = ifilmax;
|
---|
| 237 |
|
---|
| 238 | // --- writing visibility matrix to file
|
---|
| 239 | sprintf(str,"%s",outname.c_str());
|
---|
| 240 | cout<<"writing visibility matrix to file "<<str<<endl;
|
---|
| 241 | POutPersist pos(str);
|
---|
| 242 | pos.PutObject(MeanTT,"meantt");
|
---|
| 243 | pos.PutObject(Npaqsum,"npaqsum");
|
---|
| 244 | pos.PutObject(Freq,"ifreq");
|
---|
| 245 | pos.PutObject(MVisi,"visi");
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | //--------------------------------------------------------------------
|
---|
| 249 | catch(PException& exc) {
|
---|
| 250 | cerr<<" svv2mtx2_1210.cc catched PException "<<exc.Msg()<<endl;
|
---|
| 251 | rc = 77;
|
---|
| 252 | }
|
---|
| 253 | catch (std::exception& sex) {
|
---|
| 254 | cerr<<"\n svv2mtx2_1210.cc std::exception :"
|
---|
| 255 | <<(string)typeid(sex).name() << "\n msg= "<<sex.what()<<endl;
|
---|
| 256 | rc = 78;
|
---|
| 257 | }
|
---|
| 258 | catch(...) {
|
---|
| 259 | cerr<<" svv2mtx2_1210.cc catched unknown (...) exception "<<endl;
|
---|
| 260 | rc = 79;
|
---|
| 261 | }
|
---|
| 262 | cout<<">>>> svv2mtx2_1210.cc ------- END ----------- RC="<<rc<<endl;
|
---|
| 263 | return rc;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | /*
|
---|
| 268 | openppf visi1_01_05.ppf
|
---|
| 269 |
|
---|
| 270 | print visi 5
|
---|
| 271 |
|
---|
| 272 | n/plot ifreq.val%n ! ! "cpts"
|
---|
| 273 |
|
---|
| 274 | n/plot npaqsum.val%n ! ! "cpts"
|
---|
| 275 |
|
---|
| 276 | n/plot meantt.val%n ! ! "cpts"
|
---|
| 277 | cp meantt dmeantt
|
---|
| 278 | c++exec dmeantt=0.; for(int i=1;i<dmeantt.Size();i++) dmeantt(i)=meantt(i)-meantt(i-1);
|
---|
| 279 | n/plot dmeantt.val%n n>0 ! "cpts nsta"
|
---|
| 280 |
|
---|
| 281 | imag visi "cdmod"
|
---|
| 282 | imag visi "cdreal"
|
---|
| 283 | imag visi "cdimag"
|
---|
| 284 | imag visi "cdphas"
|
---|
| 285 |
|
---|
| 286 | */
|
---|