[3715] | 1 | // Utilisation de SOPHYA pour faciliter les tests ...
|
---|
| 2 | #include "sopnamsp.h"
|
---|
| 3 | #include "machdefs.h"
|
---|
| 4 |
|
---|
| 5 | /* ----------------------------------------------------------
|
---|
| 6 | Projet BAORadio - (C) LAL/IRFU 2008-2010
|
---|
| 7 |
|
---|
| 8 | Programme de lecture des fichiers vecteurs/matrices de
|
---|
| 9 | visibilites produits par mcrd / vismfib
|
---|
| 10 | R. Ansari, C. Magneville - LAL/Irfu
|
---|
| 11 | V : Mai 2009
|
---|
| 12 | ---------------------------------------------------------- */
|
---|
| 13 |
|
---|
| 14 | // include standard c/c++
|
---|
| 15 | #include <math.h>
|
---|
| 16 | #include <stdio.h>
|
---|
| 17 | #include <stdlib.h>
|
---|
| 18 | #include <string.h>
|
---|
[3733] | 19 | #include <unistd.h>
|
---|
[3715] | 20 | #include <sys/stat.h>
|
---|
| 21 | #include <iostream>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
| 24 | #include "pexceptions.h"
|
---|
| 25 | #include "tvector.h"
|
---|
| 26 | #include "fioarr.h"
|
---|
| 27 |
|
---|
| 28 | //--------------------------- Fonctions de ce fichier -------------------
|
---|
| 29 | int Usage(void);
|
---|
| 30 | int Usage(void)
|
---|
| 31 | {
|
---|
[3733] | 32 | cout<<" --- svv2mtx2.cc : Read PPF files produced by visfmib"<<endl
|
---|
| 33 | <<" and make time(row) - mean_frequency(col) matrices"<<endl
|
---|
| 34 | <<"Usage: svv2mtx2 -T Imin,Imax -F NumFreq1,NumFreq2,NBinFreq -o svvdt2.ppf InOutPath"<<endl;
|
---|
[3715] | 35 | return 1;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | //----------------------------------------------------
|
---|
| 39 | int main(int narg, char* arg[])
|
---|
| 40 | {
|
---|
| 41 | // --- Decodage des arguments et traitement
|
---|
[3733] | 42 | string ppfoutname = "svvdt2.ppf";
|
---|
[3715] | 43 | int ifilmin=0, ifilmax=-1;
|
---|
| 44 | int jfr1=0, jfr2=0, nbinfreq=0;
|
---|
| 45 |
|
---|
[3733] | 46 | char c;
|
---|
| 47 | while((c = getopt(narg,arg,"hT:F:o:")) != -1) {
|
---|
| 48 | switch (c) {
|
---|
| 49 | case 'T' :
|
---|
| 50 | sscanf(optarg,"%d,%d",&ifilmin,&ifilmax);
|
---|
| 51 | break;
|
---|
| 52 | case 'F' :
|
---|
| 53 | sscanf(optarg,"%d,%d,%d",&jfr1,&jfr2,&nbinfreq);
|
---|
| 54 | break;
|
---|
| 55 | case 'o' :
|
---|
| 56 | ppfoutname = optarg;
|
---|
| 57 | break;
|
---|
| 58 | case 'h' :
|
---|
| 59 | default :
|
---|
| 60 | Usage(); return -1;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | if(optind>=narg) {Usage(); return -2;}
|
---|
| 64 | string inoutpath = arg[optind];
|
---|
| 65 | if(ifilmin<0) ifilmin=0;
|
---|
| 66 | if(nbinfreq<=0) nbinfreq=1;
|
---|
| 67 | cout<<"inoutpath="<<inoutpath<<endl;
|
---|
| 68 | cout<<"request: file "<<ifilmin<<" to "<<ifilmax<<endl;
|
---|
| 69 | cout<<"request: freq "<<jfr1<<" to "<<jfr2<<" grouped in "<<nbinfreq<<" bins"<<endl;
|
---|
| 70 | char str[2048];
|
---|
| 71 |
|
---|
[3715] | 72 | // --- recherche des fichiers de visibilites
|
---|
| 73 | int nfile = 0;
|
---|
| 74 | {
|
---|
| 75 | struct stat buffer;
|
---|
| 76 | int i1=ifilmin, i2=(ifilmax<ifilmin) ? 999999999: ifilmax;
|
---|
| 77 | for(int ifile=i1; ifile<=i2; ifile++) {
|
---|
| 78 | sprintf(str, "%s/vismtx%d.ppf",inoutpath.c_str(),ifile);
|
---|
| 79 | int status = stat(str,&buffer);
|
---|
| 80 | if(status) break;
|
---|
| 81 | ifilmax = ifile;
|
---|
| 82 | }
|
---|
| 83 | nfile = ifilmax-ifilmin+1;
|
---|
| 84 | cout<<"Found "<<nfile<<" files from "<<ifilmin<<" to "<<ifilmax<<endl;
|
---|
| 85 | if(nfile==0 || ifilmax<ifilmin) return -3;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | //--------------------------------------------------------------------
|
---|
| 90 | int rc = 0;
|
---|
| 91 | try {
|
---|
| 92 |
|
---|
| 93 | // --- read visibilities coding vector
|
---|
| 94 | cout<<"reading chanum vector"<<endl;
|
---|
| 95 | TVector<uint_4> chanum;
|
---|
| 96 | {
|
---|
| 97 | sprintf(str,"%s/chanum.ppf",inoutpath.c_str());
|
---|
| 98 | PInPersist pic(str);
|
---|
| 99 | pic >> chanum;
|
---|
| 100 | cout<<"number of visib is "<<chanum.Size()<<endl;
|
---|
| 101 | }
|
---|
| 102 | vector< TMatrix< complex<r_4> >* > vMVis;
|
---|
| 103 | for(int i=0;i<chanum.Size();i++) vMVis.push_back(new TMatrix< complex<r_4> >);
|
---|
| 104 |
|
---|
| 105 | // --- read visibility files
|
---|
| 106 | int nfreq0, nvisi, nmoyfreq = 0;
|
---|
| 107 | TVector<r_8> Ttag(nfile), Freq;
|
---|
| 108 | TVector<int_4> Npaqsum(nfile), NFreq;
|
---|
| 109 | for(int ifile=ifilmin; ifile<=ifilmax; ifile++) {
|
---|
| 110 | sprintf(str, "%s/vismtx%d.ppf",inoutpath.c_str(),ifile);
|
---|
| 111 | cout<<ifile<<" opening: "<<str<<endl;
|
---|
| 112 | PInPersist pin(str);
|
---|
| 113 | TMatrix< complex<r_4> > vismtx;
|
---|
| 114 | pin >> vismtx;
|
---|
| 115 |
|
---|
| 116 | Ttag(ifile-ifilmin) = (double)vismtx.Info()["MeanTT"]/125.e6;
|
---|
[3717] | 117 | if(ifile==ifilmin) printf("Reference TimeTag is %.2f = %.5f sec\n"
|
---|
| 118 | ,(double)vismtx.Info()["MeanTT"],Ttag(0));
|
---|
[3715] | 119 | uint_4 nmean = vismtx.Info()["NPAQSUM"];
|
---|
| 120 | Npaqsum(ifile-ifilmin) = (int_4)nmean;
|
---|
| 121 | nfreq0 = vismtx.NCols();
|
---|
| 122 | nvisi = vismtx.NRows();
|
---|
| 123 |
|
---|
| 124 | // --- For initialisation purposes
|
---|
| 125 | if (ifile==ifilmin) {
|
---|
| 126 | cout<<"vismtx: number of frequencies = "<<nfreq0
|
---|
| 127 | <<" , visib = "<<nvisi<<" , nmean = "<<nmean<<endl;
|
---|
| 128 | if(chanum.Size()!=nvisi)
|
---|
| 129 | throw ParmError("ERROR: nvisi != chanum.Size() !!!");
|
---|
| 130 | // how many average frequencies ?
|
---|
[3733] | 131 | if(jfr1<=0) jfr1=0;
|
---|
[3715] | 132 | if(jfr1>=nfreq0) jfr1=nfreq0-1;
|
---|
| 133 | if(jfr2<jfr1 || jfr2>=nfreq0) jfr2=nfreq0-1;
|
---|
| 134 | if(nbinfreq>jfr2-jfr1+1) nbinfreq=jfr2-jfr1+1;
|
---|
| 135 | nmoyfreq = (jfr2-jfr1+1)/nbinfreq;
|
---|
| 136 | if(nmoyfreq*nbinfreq<jfr2-jfr1+1) nmoyfreq++;
|
---|
[3733] | 137 | nbinfreq = (jfr2-jfr1+1) / nmoyfreq;
|
---|
| 138 | if(nmoyfreq*nbinfreq<jfr2-jfr1+1) nbinfreq++;
|
---|
[3715] | 139 | cout<<"frequency averaging: jfr1="<<jfr1<<" jfr2="<<jfr2
|
---|
| 140 | <<" nbinfreq="<<nbinfreq<<" (nmoyfreq="<<nmoyfreq<<")"<<endl;
|
---|
| 141 | // average frequencies value
|
---|
| 142 | Freq.ReSize(nbinfreq); Freq = 0.;
|
---|
| 143 | NFreq.ReSize(nbinfreq); NFreq = 0;
|
---|
| 144 | cout<<"Frequency average:"<<endl;
|
---|
| 145 | for(int i=0;i<nbinfreq;i++) {
|
---|
| 146 | Freq(i) = 0.;
|
---|
| 147 | int nj = 0;
|
---|
| 148 | for(int j=0;j<nmoyfreq;j++) {
|
---|
| 149 | int ip = jfr1 + i*nmoyfreq + j;
|
---|
| 150 | if(ip>=nfreq0) break;
|
---|
| 151 | Freq(i) += ip;
|
---|
| 152 | nj++;
|
---|
| 153 | }
|
---|
| 154 | if(nj>0) Freq(i) /= (double)nj;
|
---|
| 155 | NFreq(i) = nj;
|
---|
| 156 | cout<<" F("<<i<<") = "<<Freq(i)<<" (nj="<<NFreq(i)
|
---|
| 157 | <<" ["<<jfr1+i*nmoyfreq<<","<<jfr1+i*nmoyfreq+nj-1<<"])"<<endl;
|
---|
| 158 | }
|
---|
| 159 | // allocate visib matrice <f> vs t
|
---|
| 160 | cout<<"allocating "<<nvisi<<" visibility matrices ("<<nfile<<","<<nbinfreq<<") "
|
---|
| 161 | <<nvisi*nfile*nbinfreq*sizeof(complex<r_4>)/1.e6<<" Mo"<<endl;
|
---|
| 162 | for(int ivi=0;ivi<nvisi;ivi++) {
|
---|
| 163 | vMVis[ivi]->ReSize(nfile,nbinfreq);
|
---|
| 164 | (*vMVis[ivi]) = complex<r_4>(0.,0.);
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | // --- Fill visibility matrix
|
---|
| 169 | for(int ivi=0;ivi<nvisi;ivi++) {
|
---|
| 170 | for(int ifr=0;ifr<nbinfreq;ifr++) {
|
---|
| 171 | int nj = 0;
|
---|
| 172 | complex<r_8> v(0.,0.);
|
---|
| 173 | for(int j=0;j<nmoyfreq;j++) {
|
---|
| 174 | int ifrp = jfr1 + ifr*nmoyfreq + j;
|
---|
| 175 | if(ifrp>=nfreq0) break;
|
---|
| 176 | v += vismtx(ivi,ifrp);
|
---|
| 177 | nj++;
|
---|
| 178 | }
|
---|
| 179 | if(nj>0) v /= (double)nj;
|
---|
| 180 | (*vMVis[ivi])(ifile-ifilmin,ifr) = v / (double)nmean;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[3733] | 185 | sprintf(str, "%s/%s",inoutpath.c_str(),ppfoutname.c_str());
|
---|
[3715] | 186 | cout<<"writing visibility matrix to file "<<str<<endl;
|
---|
| 187 | POutPersist pos(str);
|
---|
| 188 | pos.PutObject(chanum,"chanum");
|
---|
| 189 | pos.PutObject(Ttag,"ttsec");
|
---|
| 190 | pos.PutObject(Npaqsum,"npaqsum");
|
---|
| 191 | pos.PutObject(Freq,"ifreq");
|
---|
| 192 | pos.PutObject(NFreq,"nifreq");
|
---|
| 193 | for(unsigned int i=0;i<vMVis.size();i++) {
|
---|
| 194 | sprintf(str,"visft%d",chanum(i));
|
---|
| 195 | pos.PutObject(*vMVis[i],str);
|
---|
| 196 | delete vMVis[i];
|
---|
| 197 | }
|
---|
| 198 | cout<<" -------- End of Job --------"<<endl;
|
---|
| 199 | }
|
---|
| 200 | //--------------------------------------------------------------------
|
---|
| 201 | catch(PException& exc) {
|
---|
| 202 | cerr<<" svv2mtx2.cc catched PException "<<exc.Msg()<<endl;
|
---|
| 203 | rc = 77;
|
---|
| 204 | }
|
---|
| 205 | catch (std::exception& sex) {
|
---|
| 206 | cerr<<"\n svv2mtx2.cc std::exception :"
|
---|
| 207 | <<(string)typeid(sex).name() << "\n msg= "<<sex.what()<<endl;
|
---|
| 208 | rc = 78;
|
---|
| 209 | }
|
---|
| 210 | catch(...) {
|
---|
| 211 | cerr<<" svv2mtx2.cc catched unknown (...) exception "<<endl;
|
---|
| 212 | rc = 79;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | cout<<">>>> svv2mtx2.cc ------- END ----------- RC="<<rc<<endl;
|
---|
| 216 | return rc;
|
---|
| 217 | }
|
---|