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