[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>
|
---|
[3940] | 13 | #include <fstream>
|
---|
[3925] | 14 | #include <iostream>
|
---|
| 15 | #include <string>
|
---|
| 16 |
|
---|
| 17 | #include "pexceptions.h"
|
---|
| 18 | #include "tvector.h"
|
---|
| 19 | #include "fioarr.h"
|
---|
[3940] | 20 | #include "timing.h"
|
---|
[3925] | 21 |
|
---|
[3937] | 22 | /*
|
---|
| 23 | export TACQEXE=~/Reza/TAcq/Objs
|
---|
| 24 | ./CasA03Dec.csh > CasA03Dec.log 2>&1
|
---|
| 25 | */
|
---|
| 26 |
|
---|
[3925] | 27 | //--------------------------- Fonctions de ce fichier -------------------
|
---|
| 28 | void usage(void);
|
---|
| 29 | void usage(void)
|
---|
| 30 | {
|
---|
| 31 | cout<<"svv2mtx2_1012 [options] dir : lecture des fichiers acq de Pittsburgh Dec 2010"<<endl
|
---|
| 32 | <<" dir : repertoire ou se trouvent les fichiers d'acq"<<endl
|
---|
| 33 | <<" -D : visi is a duplicated one"<<endl
|
---|
| 34 | <<" -o visi.ppf : nom du ficher ppf pour ecrire la visi temps-frequence"<<endl
|
---|
[3940] | 35 | <<" -v v1,v2 : numero de voie acq pour cette visi [1-32]"<<endl
|
---|
| 36 | <<" on calcule <v1.conj(v2)>"<<endl
|
---|
| 37 | <<" -C : compute and store the complexe conjugated visi"<<endl
|
---|
| 38 | <<" dans ce cas on calcule <v2.conj(v1)>, le but est d'avoir toujours <E.conj(W)>"<<endl
|
---|
[3925] | 39 | <<" -t thr : numero de la thread ayant traite cette visi [0-N]"<<endl
|
---|
| 40 | <<" -r row : numero de la ligne de la matrice acq pour cette visi [0-Nrow["<<endl
|
---|
| 41 | <<" -f freq0 : 1ere frequence en MHz"<<endl
|
---|
| 42 | <<" -T it1,it2 : numero (temps) des fichiers a traiter [it1,it2]"<<endl
|
---|
[3927] | 43 | <<"ATTENTION: lancer ce prog depuis le repertoire ou doivent etre ecrits les fichiers de visi"<<endl;
|
---|
[3925] | 44 | }
|
---|
| 45 |
|
---|
| 46 | //----------------------------------------------------
|
---|
| 47 | int main(int narg, char* arg[])
|
---|
| 48 | {
|
---|
| 49 | // --- Decodage des arguments et traitement
|
---|
[3940] | 50 | int nmiss_stop = 1000; // on s'arrete si on a "nmiss_stop" fichiers consecutifs manquants
|
---|
[3925] | 51 | string outname = "";
|
---|
| 52 | int numthread = -1, numrow = -1;
|
---|
[3928] | 53 | bool dupli = false, doconj = false;
|
---|
[3925] | 54 | double freq0 = 0.;
|
---|
[3940] | 55 | int vacq1=-1, vacq2=-1;
|
---|
[3926] | 56 | int ifilmin=0, ifilmax=99999;
|
---|
[3925] | 57 |
|
---|
| 58 | char c;
|
---|
[3941] | 59 | while((c = getopt(narg,arg,"hDCo:t:r:f:T:v:")) != -1) {
|
---|
[3925] | 60 | switch (c) {
|
---|
[3940] | 61 | case 'v' :
|
---|
| 62 | sscanf(optarg,"%d,%d",&vacq1,&vacq2);
|
---|
| 63 | break;
|
---|
[3925] | 64 | case 'D' :
|
---|
| 65 | dupli = true;
|
---|
| 66 | break;
|
---|
[3928] | 67 | case 'C' :
|
---|
| 68 | doconj = true;
|
---|
| 69 | break;
|
---|
[3925] | 70 | case 'o' :
|
---|
| 71 | outname = optarg;
|
---|
| 72 | break;
|
---|
| 73 | case 't' :
|
---|
| 74 | numthread = atoi(optarg);
|
---|
| 75 | break;
|
---|
| 76 | case 'r' :
|
---|
| 77 | numrow = atoi(optarg);
|
---|
| 78 | break;
|
---|
| 79 | case 'f' :
|
---|
| 80 | freq0 = atof(optarg);
|
---|
| 81 | break;
|
---|
| 82 | case 'T' :
|
---|
| 83 | sscanf(optarg,"%d,%d",&ifilmin,&ifilmax);
|
---|
| 84 | if(ifilmin<0) ifilmin=0;
|
---|
| 85 | break;
|
---|
| 86 | case 'h' :
|
---|
| 87 | default :
|
---|
| 88 | usage(); return -1;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | if(optind>=narg) {usage(); return -1;}
|
---|
| 92 | string indir = arg[optind];
|
---|
| 93 |
|
---|
[3940] | 94 | cout<<"v1="<<vacq1<<" v2="<<vacq2<<" doconj="<<(int)doconj<<endl;
|
---|
[3925] | 95 | cout<<"thread="<<numthread<<endl; if(numthread<0) return -2;
|
---|
| 96 | cout<<"numrow="<<numrow<<endl; if(numrow<0) return -2;
|
---|
| 97 | cout<<"dupli="<<(int)dupli<<endl;
|
---|
| 98 | cout<<"outname="<<outname<<endl; if(outname.size()<=0) return -2;
|
---|
| 99 | cout<<"indir="<<indir<<endl;
|
---|
| 100 | cout<<"freq0="<<freq0<<" MHz"<<endl;
|
---|
| 101 | cout<<"request: file "<<ifilmin<<" to "<<ifilmax<<endl; if(ifilmax<ifilmin) return -3;
|
---|
| 102 |
|
---|
[3940] | 103 | InitTim();
|
---|
| 104 |
|
---|
[3925] | 105 | // --- recherche et comptage des fichiers de visibilites
|
---|
[3926] | 106 | // ATTENTION: il peut manquer des fichiers au debut ou dans la sequence
|
---|
[3940] | 107 | string flistname = outname; flistname += ".filelist";
|
---|
[3925] | 108 | int nfile = 0;
|
---|
| 109 | {
|
---|
[3940] | 110 | ofstream flistw(flistname.c_str(), ofstream::out);
|
---|
| 111 | cout<<"writing in file list in: "<<flistname<<" (is_open="<<flistw.is_open()<<")"<<endl;
|
---|
| 112 | if(!flistw) {cout<<"!!!!OPEN failed "<<flistname<<endl; return -4;}
|
---|
| 113 |
|
---|
| 114 | char str[4096];
|
---|
| 115 | struct stat buffer;
|
---|
[3926] | 116 | int ifmin2 = ifilmin, ifmax2 = ifilmax; ifilmax = -1;
|
---|
[3925] | 117 | bool foundfirst = false;
|
---|
[3940] | 118 | int nmiss = 0;
|
---|
[3926] | 119 | for(int ifile=ifmin2; ifile<=ifmax2; ifile++) {
|
---|
[3925] | 120 | sprintf(str, "%s/vismtx_%d_%d.ppf",indir.c_str(),numthread,ifile);
|
---|
| 121 | int status = stat(str,&buffer);
|
---|
| 122 | if(!foundfirst && status==0) {
|
---|
| 123 | cout<<"first file found: "<<str<<endl;
|
---|
| 124 | foundfirst = true;
|
---|
| 125 | if(ifile>ifilmin) ifilmin = ifile;
|
---|
| 126 | }
|
---|
| 127 | if(!foundfirst) continue;
|
---|
| 128 | if(ifile<ifilmin) continue;
|
---|
[3940] | 129 | if(foundfirst && status!=0) {
|
---|
| 130 | // On fait ca car "stst()" est extremement long si le fichier n'existe pas!
|
---|
| 131 | if(nmiss>nmiss_stop) break;
|
---|
| 132 | nmiss++;
|
---|
| 133 | continue;
|
---|
| 134 | }
|
---|
[3925] | 135 | nfile++;
|
---|
| 136 | ifilmax = ifile;
|
---|
[3940] | 137 | nmiss = 0;
|
---|
| 138 | flistw << string(str) <<endl;
|
---|
[3925] | 139 | }
|
---|
[3940] | 140 |
|
---|
| 141 | flistw.close();
|
---|
[3925] | 142 | cout<<"Found "<<nfile<<" files from "<<ifilmin<<" to "<<ifilmax<<endl;
|
---|
[3940] | 143 | if(nfile==0 || ifilmax<ifilmin) return -5;
|
---|
[3925] | 144 | }
|
---|
| 145 |
|
---|
[3940] | 146 | PrtTim("--- End of file number search");
|
---|
[3925] | 147 |
|
---|
| 148 | //--------------------------------------------------------------------
|
---|
| 149 | int rc = 0;
|
---|
| 150 | try {
|
---|
| 151 |
|
---|
[3940] | 152 | ifstream flistr(flistname.c_str(), ofstream::in);
|
---|
| 153 | if(!flistr) {cout<<"!!!!OPEN failed "<<flistname<<endl; return -6;}
|
---|
| 154 |
|
---|
[3925] | 155 | // --- read visibility files
|
---|
| 156 | TMatrix< complex<r_4> > MVisi;
|
---|
| 157 | TVector<r_8> MeanTT(nfile);
|
---|
[3941] | 158 | TVector<int_4> Npaqsum(nfile);
|
---|
[3925] | 159 | TVector<r_4> Freq;
|
---|
| 160 | string tudeb, tufin;
|
---|
| 161 | double tudeb_day, tufin_day;
|
---|
| 162 | int nfreq = 0;
|
---|
[3940] | 163 | int lpmod = nfile/25; if(lpmod<=0) lpmod=1;
|
---|
[3925] | 164 |
|
---|
[3927] | 165 | int_4 ntimefill = 0, ntimebad = 0;
|
---|
[3940] | 166 | bool foundfirst = true;
|
---|
| 167 | while(!flistr.eof()) {
|
---|
[3925] | 168 | // --- Lecture d'une visi elementaire (fichier acq)
|
---|
[3940] | 169 | string fname;
|
---|
| 170 | getline(flistr,fname);
|
---|
| 171 | if(fname.size()==0) continue;
|
---|
| 172 | if(ntimefill%lpmod==0) cout<<ntimefill<<" "<<" : "<<fname<<endl;
|
---|
[3925] | 173 | TMatrix< complex<r_4> > vismtx;
|
---|
[3926] | 174 | try {
|
---|
[3940] | 175 | PInPersist pin(fname);
|
---|
[3926] | 176 | pin >> vismtx;
|
---|
| 177 | } catch(...) {
|
---|
[3940] | 178 | cout<<"ERROR: bad file "<<fname<<endl;
|
---|
[3926] | 179 | ntimebad++;
|
---|
| 180 | continue;
|
---|
| 181 | }
|
---|
[3925] | 182 | tufin = (string)vismtx.Info()["DATEOBS"];
|
---|
| 183 |
|
---|
| 184 | // --- Time keeping and number of summed elementary visibilities
|
---|
[3926] | 185 | MeanTT(ntimefill) = (double)vismtx.Info()["MeanTT"]/125.e6;
|
---|
[3925] | 186 | uint_4 npaqsum = vismtx.Info()["NPAQSUM"];
|
---|
[3941] | 187 | Npaqsum(ntimefill) = npaqsum;
|
---|
[3925] | 188 |
|
---|
| 189 | // --- Initialisation purposes for the first read file
|
---|
[3940] | 190 | if(foundfirst) {
|
---|
| 191 | foundfirst = false;
|
---|
[3925] | 192 | tudeb = tufin;
|
---|
| 193 | printf("Reference Time: tt = %.5f sec, TU = %s\n",MeanTT(0),tudeb.c_str());
|
---|
| 194 | if(numrow>=vismtx.NRows()) {
|
---|
| 195 | cout<<"ERROR: requested numrow="<<numrow<<" => "<<vismtx.NRows()<<endl;
|
---|
| 196 | return -5;
|
---|
| 197 | }
|
---|
[3941] | 198 | // Frequency
|
---|
| 199 | nfreq = vismtx.NCols();
|
---|
| 200 | cout<<"vismtx: number of frequencies = "<<nfreq<<endl;
|
---|
| 201 | Freq.ReSize(nfreq); for(int i=0;i<nfreq;i++) Freq(i) = i;
|
---|
[3925] | 202 | // allocate visib matrice <f> vs t
|
---|
| 203 | cout<<"allocating visibility matrice ("<<nfile<<","<<nfreq<<") "
|
---|
| 204 | <<nfile*nfreq*sizeof(complex<r_4>)/1.e6<<" Mo"<<endl;
|
---|
| 205 | MVisi.ReSize(nfile,nfreq);
|
---|
| 206 | MVisi = complex<r_4>(0.,0.);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | // Fill time-freq visibility matrix
|
---|
[3941] | 210 | for(int c=0;c<nfreq;c++) {
|
---|
| 211 | MVisi(ntimefill,c) = vismtx(numrow,c) / complex<r_4>(npaqsum);
|
---|
| 212 | if(doconj) MVisi(ntimefill,c) = conj(MVisi(ntimefill,c));
|
---|
[3925] | 213 | }
|
---|
| 214 | ntimefill++;
|
---|
| 215 |
|
---|
| 216 | } // fin boucle sur le fichiers d'acq
|
---|
[3926] | 217 | cout<<"ntimefill = "<<ntimefill<<" / "<<nfile<<" , ntimebad="<<ntimebad<<" bad files"<<endl;
|
---|
[3940] | 218 | flistr.close();
|
---|
| 219 | string order = "rm -f "; order += flistname;
|
---|
| 220 | system(order.c_str());
|
---|
[3925] | 221 |
|
---|
| 222 | // --- keeping info with visi
|
---|
| 223 | {
|
---|
| 224 | // bricolo en unite de jours depuis le 0/12/2010 a 0h
|
---|
| 225 | int y,m,d,h,mn; double s;
|
---|
| 226 | sscanf(tudeb.c_str(),"%d-%d-%dT%d:%d:%lf",&y,&m,&d,&h,&mn,&s);
|
---|
| 227 | tudeb_day = (double)d + ((double)h + mn/60. + s/3600.)/24.;
|
---|
| 228 | sscanf(tufin.c_str(),"%d-%d-%dT%d:%d:%lf",&y,&m,&d,&h,&mn,&s);
|
---|
| 229 | tufin_day = (double)d + ((double)h + mn/60. + s/3600.)/24.;
|
---|
| 230 | }
|
---|
[3940] | 231 | DVList dvl;
|
---|
| 232 | dvl["vacq1"] = vacq1;
|
---|
| 233 | dvl["vacq2"] = vacq2;
|
---|
| 234 | dvl["nth"] = numthread;
|
---|
| 235 | dvl["row"] = numrow;
|
---|
| 236 | dvl["dir"] = indir;
|
---|
| 237 | dvl["dupli"] = (dupli) ? 1: 0;
|
---|
| 238 | dvl["isconj"] = (doconj) ? 1: 0;
|
---|
| 239 | dvl["TUobs_0"] = tudeb;
|
---|
| 240 | dvl["TUobs_N"] = tufin;
|
---|
| 241 | dvl["TUday_0"] = tudeb_day;
|
---|
| 242 | dvl["TUday_N"] = tufin_day;
|
---|
| 243 | dvl["TTag_0"] = MeanTT(0);
|
---|
| 244 | if(ntimefill>0) dvl["TTag_N"] = MeanTT(ntimefill-1);
|
---|
| 245 | dvl["freq0"] = freq0;
|
---|
| 246 | dvl["dfreq0"] = 500./8192.;
|
---|
[3941] | 247 | dvl["jfr1"] = 0;
|
---|
| 248 | dvl["jfr2"] = nfreq-1;
|
---|
| 249 | dvl["nfreq"] = nfreq;
|
---|
| 250 | dvl["ngrpfreq"] = 1;
|
---|
[3940] | 251 | dvl["ifilmin"] = ifilmin;
|
---|
| 252 | dvl["ifilmax"] = ifilmax;
|
---|
| 253 | dvl["ntimefill"] = ntimefill;
|
---|
| 254 | dvl["ntimebad"] = ntimebad;
|
---|
[3925] | 255 |
|
---|
| 256 | // --- writing visibility matrix to file
|
---|
[3940] | 257 | cout<<"writing visibility matrix to file "<<outname<<endl;
|
---|
| 258 | POutPersist pos(outname);
|
---|
| 259 | if(ntimefill>0) {
|
---|
| 260 | TVector<r_8> dum1(MeanTT(Range(0,ntimefill-1)));
|
---|
| 261 | pos.PutObject(dum1,"meantt");
|
---|
| 262 | TVector<int_4> dum2(Npaqsum(Range(0,ntimefill-1)));
|
---|
| 263 | pos.PutObject(dum2,"npaqsum");
|
---|
| 264 | TMatrix< complex<r_4> > dum3(MVisi(Range(0,ntimefill-1),Range(0,MVisi.NCols()-1)));
|
---|
| 265 | dum3.Info() = dvl;
|
---|
| 266 | pos.PutObject(dum3,"visi");
|
---|
[3941] | 267 | pos.PutObject(Freq,"ifreq");
|
---|
[3940] | 268 | }
|
---|
| 269 |
|
---|
[3925] | 270 | }
|
---|
| 271 |
|
---|
| 272 | //--------------------------------------------------------------------
|
---|
| 273 | catch(PException& exc) {
|
---|
| 274 | cerr<<" svv2mtx2_1210.cc catched PException "<<exc.Msg()<<endl;
|
---|
| 275 | rc = 77;
|
---|
| 276 | }
|
---|
| 277 | catch (std::exception& sex) {
|
---|
| 278 | cerr<<"\n svv2mtx2_1210.cc std::exception :"
|
---|
| 279 | <<(string)typeid(sex).name() << "\n msg= "<<sex.what()<<endl;
|
---|
| 280 | rc = 78;
|
---|
| 281 | }
|
---|
| 282 | catch(...) {
|
---|
| 283 | cerr<<" svv2mtx2_1210.cc catched unknown (...) exception "<<endl;
|
---|
| 284 | rc = 79;
|
---|
| 285 | }
|
---|
| 286 | cout<<">>>> svv2mtx2_1210.cc ------- END ----------- RC="<<rc<<endl;
|
---|
[3940] | 287 | PrtTim("--- End of job");
|
---|
[3925] | 288 | return rc;
|
---|
| 289 | }
|
---|
| 290 |
|
---|