| 1 | // Utilisation de SOPHYA pour faciliter les tests ... | 
|---|
| 2 | #include "sopnamsp.h" | 
|---|
| 3 | #include "machdefs.h" | 
|---|
| 4 |  | 
|---|
| 5 | /* ---------------------------------------------------------- | 
|---|
| 6 | Programme de lecture multi canaux pour BAORadio | 
|---|
| 7 | R. Ansari, C. Magneville | 
|---|
| 8 | V : Mai 2009 | 
|---|
| 9 | ---------------------------------------------------------- */ | 
|---|
| 10 |  | 
|---|
| 11 | // include standard c/c++ | 
|---|
| 12 | #include <math.h> | 
|---|
| 13 | #include <stdio.h> | 
|---|
| 14 | #include <stdlib.h> | 
|---|
| 15 | #include <string.h> | 
|---|
| 16 |  | 
|---|
| 17 | #include <iostream> | 
|---|
| 18 | #include <string> | 
|---|
| 19 |  | 
|---|
| 20 | #include "pexceptions.h" | 
|---|
| 21 | #include "tvector.h" | 
|---|
| 22 | #include "fioarr.h" | 
|---|
| 23 | // #include "tarrinit.h" | 
|---|
| 24 | #include "ntuple.h" | 
|---|
| 25 | #include "histinit.h" | 
|---|
| 26 | #include "matharr.h" | 
|---|
| 27 | #include "timestamp.h" | 
|---|
| 28 | /* | 
|---|
| 29 | #include "fftpserver.h" | 
|---|
| 30 | #include "fftwserver.h" | 
|---|
| 31 |  | 
|---|
| 32 | #include "FFTW/fftw3.h" | 
|---|
| 33 | */ | 
|---|
| 34 | // include sophya mesure ressource CPU/memoire ... | 
|---|
| 35 | #include "resusage.h" | 
|---|
| 36 | #include "ctimer.h" | 
|---|
| 37 | #include "timing.h" | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 | int Usage(bool fgshort=true); | 
|---|
| 41 | // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW) | 
|---|
| 42 | int ProcSVFiles(string& inoutpath, int imin, int imax, int istep, int jf1, int jf2, int nfreq, int card=1); | 
|---|
| 43 |  | 
|---|
| 44 | //---------------------------------------------------- | 
|---|
| 45 | //---------------------------------------------------- | 
|---|
| 46 | int main(int narg, char* arg[]) | 
|---|
| 47 | { | 
|---|
| 48 | if ((narg>1)&&(strcmp(arg[1],"-h")==0))  return Usage(false); | 
|---|
| 49 | if (narg<4) return Usage(true); | 
|---|
| 50 |  | 
|---|
| 51 | HiStatsInitiator _inia; | 
|---|
| 52 | //   TArrayInitiator  _inia; | 
|---|
| 53 |  | 
|---|
| 54 | int rc = 0; | 
|---|
| 55 | try { | 
|---|
| 56 | string inoutpath = arg[1]; | 
|---|
| 57 | int imin=0; | 
|---|
| 58 | int imax=0; | 
|---|
| 59 | int istep=1; | 
|---|
| 60 | sscanf(arg[2],"%d,%d,%d",&imin,&imax,&istep); | 
|---|
| 61 | int jf1=0; | 
|---|
| 62 | int jf2=0; | 
|---|
| 63 | int nfreq=0; | 
|---|
| 64 | sscanf(arg[3],"%d,%d,%d",&jf1,&jf2,&nfreq); | 
|---|
| 65 | cout << " ----- svv2mtx.cc Start - InOutPath= " << inoutpath << " IMin,Max,Step=" | 
|---|
| 66 | << imin << "," << imax << "," << istep << " JF=" << jf1 << "," << jf2 << "  ------- " << endl; | 
|---|
| 67 | int card=1; | 
|---|
| 68 | if (narg>4) card=atoi(arg[3]); | 
|---|
| 69 | ResourceUsage resu; | 
|---|
| 70 | rc=ProcSVFiles(inoutpath, imin, imax, istep, jf1, jf2, card); | 
|---|
| 71 | resu.Update(); | 
|---|
| 72 | cout << resu; | 
|---|
| 73 | } | 
|---|
| 74 | catch (PException& exc) { | 
|---|
| 75 | cerr << " svv2mtx.cc catched MiniFITSException " << exc.Msg() << endl; | 
|---|
| 76 | rc = 77; | 
|---|
| 77 | } | 
|---|
| 78 | catch (std::exception& sex) { | 
|---|
| 79 | cerr << "\n svv2mtx.cc std::exception :" | 
|---|
| 80 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 81 | << sex.what() << endl; | 
|---|
| 82 | rc = 78; | 
|---|
| 83 | } | 
|---|
| 84 | catch (...) { | 
|---|
| 85 | cerr << " svv2mtx.cc catched unknown (...) exception  " << endl; | 
|---|
| 86 | rc = 79; | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | cout << ">>>> svv2mtx.cc ------- END ----------- RC=" << rc << endl; | 
|---|
| 90 | return rc; | 
|---|
| 91 |  | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 | // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW) | 
|---|
| 97 | int ProcSVFiles(string& inoutpath, int imin, int imax, int istep, int jf1, int jf2, int nfreq, int card) | 
|---|
| 98 | { | 
|---|
| 99 | Timer tm("ProcSVFiles"); | 
|---|
| 100 | char fname[512]; | 
|---|
| 101 | // NTuple | 
|---|
| 102 | const char* nnames[10] = {"fcsm","ttsm","jfreq","s1","s2","s12","s12re","s12im","s12phi","s12mod"}; | 
|---|
| 103 | NTuple nt(10, nnames); | 
|---|
| 104 | double xnt[15]; | 
|---|
| 105 | uint_4 nmnt = 0; | 
|---|
| 106 | double ms1,ms2,ms12,ms12re,ms12im,ms12phi,ms12mod; | 
|---|
| 107 |  | 
|---|
| 108 | TMatrix<r_4> s1, s2; | 
|---|
| 109 | TMatrix<r_4> v12re, v12im, v12phi,v12mod; | 
|---|
| 110 | sa_size_t ncols = (imax-imin+1)/istep; | 
|---|
| 111 | sa_size_t nrows = 10; | 
|---|
| 112 | sa_size_t kc=0; | 
|---|
| 113 | for(int ifile=imin; ifile<=imax; ifile+=istep) { | 
|---|
| 114 | if (card==2) | 
|---|
| 115 | sprintf(fname, "%s/Ch34_%d.ppf",inoutpath.c_str(),ifile); | 
|---|
| 116 | else | 
|---|
| 117 | sprintf(fname, "%s/Ch12_%d.ppf",inoutpath.c_str(),ifile); | 
|---|
| 118 | cout << " ProcSVFiles[" << ifile << "] opening file " << fname << endl; | 
|---|
| 119 | PInPersist pin(fname); | 
|---|
| 120 | string tag1="specV1"; | 
|---|
| 121 | string tag2="specV2"; | 
|---|
| 122 | string tag12="visiV12"; | 
|---|
| 123 | if (card==2) { | 
|---|
| 124 | tag1 = "specV3"; | 
|---|
| 125 | tag2 = "specV4"; | 
|---|
| 126 | tag12="visiV34"; | 
|---|
| 127 | } | 
|---|
| 128 | TVector<r_4> sv1; | 
|---|
| 129 | TVector<r_4> sv2; | 
|---|
| 130 | TVector< complex<r_4> > vv12; | 
|---|
| 131 | pin >> PPFNameTag(tag1) >> sv1; | 
|---|
| 132 | pin >> PPFNameTag(tag2) >> sv2; | 
|---|
| 133 | pin >> PPFNameTag(tag12) >> vv12; | 
|---|
| 134 | if (ifile==imin) { | 
|---|
| 135 | nrows = sv1.Size(); | 
|---|
| 136 | cout << " ProcSVFiles/Info: Output s1,s2 matrix size NRows=NFreq=" | 
|---|
| 137 | << nrows << " NCols=NFiles=" << ncols << endl; | 
|---|
| 138 | s1.SetSize(nrows, ncols); | 
|---|
| 139 | s2.SetSize(nrows, ncols); | 
|---|
| 140 | nrows = vv12.Size(); | 
|---|
| 141 | cout << " ProcSVFiles/Info: Output v12 matrix size NRows=NFreq=" | 
|---|
| 142 | << nrows << " NCols=NFiles=" << ncols << endl; | 
|---|
| 143 | v12re.SetSize(nrows, ncols); | 
|---|
| 144 | v12im.SetSize(nrows, ncols); | 
|---|
| 145 | v12phi.SetSize(nrows, ncols); | 
|---|
| 146 | v12mod.SetSize(nrows, ncols); | 
|---|
| 147 | } | 
|---|
| 148 | s1.Column(kc) = sv1; | 
|---|
| 149 | s2.Column(kc) = sv2; | 
|---|
| 150 | v12re.Column(kc) = real(vv12); | 
|---|
| 151 | v12im.Column(kc) = imag(vv12); | 
|---|
| 152 | v12phi.Column(kc) = phase(vv12); | 
|---|
| 153 | v12mod.Column(kc) = module(vv12); | 
|---|
| 154 |  | 
|---|
| 155 | // Calcul moyenne dans des bandes en frequence | 
|---|
| 156 | int deltajf=(jf2-jf1)/nfreq; | 
|---|
| 157 | if (deltajf<1) deltajf=1; | 
|---|
| 158 | for(int kf=0; kf<nfreq; kf++) { | 
|---|
| 159 | sa_size_t jfstart=jf1+kf*deltajf; | 
|---|
| 160 | sa_size_t jfend=jfstart+deltajf; | 
|---|
| 161 | if (jfend>jf2)  break; | 
|---|
| 162 | nmnt=0;  ms1=ms2=ms12=ms12re=ms12im=ms12phi=ms12mod=0.; | 
|---|
| 163 | for(sa_size_t jf=jfstart; jf<jfend; jf++) { | 
|---|
| 164 | ms1 += s1(jf,kc); | 
|---|
| 165 | ms2 += s2(jf,kc); | 
|---|
| 166 | ms12re += v12re(jf,kc); | 
|---|
| 167 | ms12im += v12im(jf,kc); | 
|---|
| 168 | ms12phi += v12phi(jf,kc); | 
|---|
| 169 | ms12mod += v12mod(jf,kc); | 
|---|
| 170 | } | 
|---|
| 171 | nmnt = (jfend-jfstart); | 
|---|
| 172 | if (nmnt>0)  { | 
|---|
| 173 | double fnorm = (double)nmnt; | 
|---|
| 174 | xnt[0] = ((int_8)(sv1.Info()["StartFC"])+(int_8)(sv1.Info()["EndFC"]))*0.5; | 
|---|
| 175 | xnt[1] = ((int_8)(sv1.Info()["StartTT"])+(int_8)(sv1.Info()["EndTT"]))*0.5; | 
|---|
| 176 | xnt[2] = kf; | 
|---|
| 177 | xnt[3] = ms1/fnorm; | 
|---|
| 178 | xnt[4] = ms2/fnorm; | 
|---|
| 179 | xnt[5] = ms12/fnorm; | 
|---|
| 180 | xnt[6] = ms12re/fnorm; | 
|---|
| 181 | xnt[7] = ms12im/fnorm; | 
|---|
| 182 | xnt[8] = ms12phi/fnorm; | 
|---|
| 183 | xnt[9] = ms12mod/fnorm; | 
|---|
| 184 | nt.Fill(xnt); | 
|---|
| 185 | } | 
|---|
| 186 | } | 
|---|
| 187 | kc++; | 
|---|
| 188 |  | 
|---|
| 189 | } | 
|---|
| 190 | if (card==2) | 
|---|
| 191 | sprintf(fname, "%s/Ch34mtx.ppf",inoutpath.c_str()); | 
|---|
| 192 | else | 
|---|
| 193 | sprintf(fname, "%s/Ch12mtx.ppf",inoutpath.c_str()); | 
|---|
| 194 |  | 
|---|
| 195 | cout << nt; | 
|---|
| 196 | cout << "ProcSVFiles: Opening file " << fname << " for writing" << endl; | 
|---|
| 197 | POutPersist po(fname); | 
|---|
| 198 | string tag1="s1"; | 
|---|
| 199 | string tag2="s2"; | 
|---|
| 200 | string tag12r="v12re"; | 
|---|
| 201 | string tag12i="v12im"; | 
|---|
| 202 | string tag12p="v12phi"; | 
|---|
| 203 | string tagnt="nt12"; | 
|---|
| 204 | if (card==2) { | 
|---|
| 205 | tag1="s3"; | 
|---|
| 206 | tag2="s4"; | 
|---|
| 207 | tag12r="v34re"; | 
|---|
| 208 | tag12i="v34im"; | 
|---|
| 209 | tag12p="v34phi"; | 
|---|
| 210 | tagnt="nt34"; | 
|---|
| 211 | } | 
|---|
| 212 | po <<  PPFNameTag(tag1) << s1; | 
|---|
| 213 | po <<  PPFNameTag(tag2) << s2; | 
|---|
| 214 | po <<  PPFNameTag(tag12r) << v12re; | 
|---|
| 215 | po <<  PPFNameTag(tag12i) << v12im; | 
|---|
| 216 | po <<  PPFNameTag(tag12p) << v12phi; | 
|---|
| 217 | po <<  PPFNameTag(tagnt) << nt; | 
|---|
| 218 | cout << "ProcSVFiles: Matrices s1, s2, v12re, v12im, v12phi, NTuple nt written to file " << fname << endl; | 
|---|
| 219 | return 0; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 |  | 
|---|
| 223 |  | 
|---|
| 224 |  | 
|---|
| 225 | /* --Fonction-- */ | 
|---|
| 226 | int Usage(bool fgshort) | 
|---|
| 227 | { | 
|---|
| 228 | cout << " --- svv2mtx.cc : Read PPF files produced by mcrd to make matrices BAORadio" << endl; | 
|---|
| 229 | cout << " Usage:  mcrd InOutPath Imin,Imax,step NumFreq1,NumFreq2,NBinFreq [card=1]" << endl; | 
|---|
| 230 | if (fgshort) { | 
|---|
| 231 | cout << " mcrd -h for detailed instructions" << endl; | 
|---|
| 232 | return 1; | 
|---|
| 233 | } | 
|---|
| 234 | cout << " InOutPath : Input/Output directory name " << endl; | 
|---|
| 235 | cout << " Imin,Imax,IStep: Input PPF files sequence number \n" | 
|---|
| 236 | << "    FileNames=InOutPath/Ch12_II.fits Imin<=II<=Imax II+=IStep \n" | 
|---|
| 237 | << " NumFreq1,NumFreq2,NBinFreq: Freq Zone and number of frequency bins for ntuple\n" | 
|---|
| 238 | << " card=1 Ch12 , card=2 Ch34 " << endl; | 
|---|
| 239 | return 1; | 
|---|
| 240 | } | 
|---|