[3925] | 1 | // Lecture des fichiers chanum_?.ppf et recherche des visibilites ecrites dans les matrices d'acq
|
---|
| 2 | // > make OBJ=$CMVPROG/obj/ EXE=$CMVPROG/exe/ chanum_1210
|
---|
| 3 | #include "sopnamsp.h"
|
---|
| 4 | #include "machdefs.h"
|
---|
| 5 | #include <math.h>
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <stdlib.h>
|
---|
| 8 | #include <string.h>
|
---|
| 9 | #include <unistd.h>
|
---|
| 10 | #include <sys/stat.h>
|
---|
| 11 | #include <fstream>
|
---|
| 12 | #include <iostream>
|
---|
| 13 | #include <string>
|
---|
| 14 | #include <algorithm>
|
---|
| 15 |
|
---|
| 16 | #include "pexceptions.h"
|
---|
| 17 | #include "tvector.h"
|
---|
| 18 | #include "nbtrixx.h"
|
---|
| 19 |
|
---|
[3935] | 20 | // > chanum_1210 -f 1375.0610351 -F 0,8888,5 -o CasA02Dec.csh ../../crt*/PittsDec10/CasA02Dec/chanum_*.ppf
|
---|
| 21 | // > chanum_1210 -f 1375.0610351 -F 0,8888,5 -o Crab03Dec.csh ../../crt*/PittsDec10/Crab03Dec/chanum_*.ppf
|
---|
| 22 | // > chanum_1210 -f 1382.5378418 -F 0,8888,5 -o Sun03Dec.csh ../../crt*/PittsDec10/Sun03Dec/chanum_*.ppf
|
---|
| 23 | // > chanum_1210 -f 1390.0146484 -F 0,8888,5 -o CasA03Dec.csh ../../crt*/PittsDec10/CasA03Dec/chanum_*.ppf
|
---|
[3925] | 24 |
|
---|
| 25 | int decode_numthread(string filein,string& dir);
|
---|
| 26 |
|
---|
| 27 | //--------------------------- Fonctions de ce fichier -------------------
|
---|
| 28 | void usage(void);
|
---|
| 29 | void usage(void)
|
---|
| 30 | {
|
---|
| 31 | cout<<"Usage: chanum_1210 [options] chanum_?.ppf ..."<<endl
|
---|
[3935] | 32 | <<" -f F0MHz : 1ere frequence pour cette acquisition (def=0.)"<<endl
|
---|
| 33 | <<" -F if0,if1,idf : selection freq de if0 a if1 moyenne par idf (def=\"0,8888,1\")"<<endl
|
---|
| 34 | <<" -T it0,it1 : selection fichier temps de it0 a it1 (def=\"0,999999\")"<<endl
|
---|
[3928] | 35 | <<" -o fichier.csh : nom du fichier de sortie pour les commandes a lancer"<<endl;
|
---|
[3925] | 36 | }
|
---|
| 37 |
|
---|
| 38 | //----------------------------------------------------
|
---|
| 39 | int main(int narg, char* arg[])
|
---|
| 40 | {
|
---|
[3928] | 41 | string outname = "chanum_1210.csh";
|
---|
[3935] | 42 | string selfreq = "0,8888,1", seltime = "0,999999";
|
---|
[3925] | 43 | double freq0 = 0.;
|
---|
| 44 |
|
---|
| 45 | char c;
|
---|
[3935] | 46 | while((c = getopt(narg,arg,"hO:o:f:F:T:")) != -1) {
|
---|
[3925] | 47 | switch (c) {
|
---|
| 48 | case 'f' :
|
---|
| 49 | freq0 = atof(optarg);
|
---|
| 50 | break;
|
---|
| 51 | case 'o' :
|
---|
| 52 | outname = optarg;
|
---|
| 53 | break;
|
---|
[3935] | 54 | case 'F' :
|
---|
| 55 | selfreq = optarg;
|
---|
| 56 | break;
|
---|
| 57 | case 'T' :
|
---|
| 58 | seltime = optarg;
|
---|
| 59 | break;
|
---|
[3925] | 60 | case 'h' :
|
---|
| 61 | default :
|
---|
| 62 | usage(); return -1;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | if(optind>=narg) {usage(); return -2;}
|
---|
| 66 |
|
---|
| 67 | vector<uint_4> vcode, vnth, vrow;
|
---|
| 68 | vector<string> vdir;
|
---|
| 69 | int nvisi = 0;
|
---|
| 70 | for(int ifile=optind;ifile<narg;ifile++) {
|
---|
| 71 | // --- lecture file
|
---|
| 72 | string filein = arg[ifile];
|
---|
| 73 | cout<<"..file: "<<filein<<endl;
|
---|
| 74 | struct stat buffer;
|
---|
| 75 | int status = stat(filein.c_str(),&buffer);
|
---|
| 76 | if(status) {cout<<"!!!UNKNOWN FILE"<<endl; continue;}
|
---|
| 77 | PInPersist pin(filein);
|
---|
| 78 | TVector<uint_4> chanpairnum;
|
---|
| 79 | if(pin.GotoNameTag("chanpairnum")) pin.GetObject(chanpairnum,"chanpairnum");
|
---|
| 80 | else {cout<<"!!!UNKNOWN OBJECTchanpairnum "<<endl; continue;}
|
---|
| 81 | // --- decodage repertoire et num thread
|
---|
| 82 | string dir;
|
---|
| 83 | int nth = decode_numthread(filein,dir);
|
---|
| 84 | if(nth<0) {cout<<"!!!DECODING PB for thread number"<<endl; continue;}
|
---|
| 85 | // --- lecture des paires et des infos
|
---|
| 86 | for(int row=0;row<chanpairnum.Size();row++) {
|
---|
| 87 | vcode.push_back(chanpairnum(row));
|
---|
| 88 | vnth.push_back(nth);
|
---|
| 89 | vrow.push_back(row);
|
---|
| 90 | vdir.push_back(dir);
|
---|
| 91 | nvisi++;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | cout<<"nread="<<nvisi<<endl;
|
---|
| 95 |
|
---|
| 96 | // sort
|
---|
| 97 | TVector<uint_4> Vcode(vcode), IVcode(vcode.size());
|
---|
| 98 | TabSortInd(Vcode.Size(),Vcode.Data(),IVcode.Data());
|
---|
| 99 |
|
---|
| 100 | // ecriture
|
---|
[3935] | 101 | {
|
---|
[3925] | 102 | ofstream ftxt(outname.c_str(), ofstream::out);
|
---|
| 103 | cout<<"writing in "<<outname<<" (is_open="<<ftxt.is_open()<<")"<<endl;
|
---|
[3928] | 104 | ftxt << "#!/bin/csh" <<endl;
|
---|
[3925] | 105 | if(!ftxt) {cout<<"!!!!OPENING failed "<<outname<<endl; return -3;}
|
---|
| 106 | int dupli = 0, ndupli = 0;
|
---|
| 107 | nvisi = 0;
|
---|
| 108 | for(uint_4 i=0;i<vcode.size();i++) {
|
---|
[3935] | 109 | char str[512];
|
---|
| 110 | sprintf(str,"${TACQEXE}/svv2mtx2_1210 -f %.7f -T %s -F %s"
|
---|
| 111 | ,freq0,seltime.c_str(),selfreq.c_str());
|
---|
[3925] | 112 | string argu = str;
|
---|
| 113 | uint_4 ip = IVcode(i);
|
---|
| 114 | uint_4 vcode_prec = (i>0) ? vcode[IVcode(i-1)]: 99999999;
|
---|
| 115 | uint_4 vcode_suiv = (i<vcode.size()-1) ? vcode[IVcode(i+1)]: 99999999;
|
---|
| 116 | uint_4 v1 = vcode[ip]/1000, v2 = vcode[ip]%100;
|
---|
| 117 | sprintf(str," -t %d",vnth[ip]); argu += str; // numero de threads
|
---|
| 118 | sprintf(str," -r %d",vrow[ip]); argu += str; // ligne de la matrice acq
|
---|
[3928] | 119 | // L'acq fait: <v1.conj(v2)>
|
---|
| 120 | // Si v1 et v2 sont de parites differentes donc de cylindres differents
|
---|
| 121 | // on veut toujours avoir une visi <E.conj(W)> cad <impair.conj(pair)>
|
---|
| 122 | bool doconj = false;
|
---|
| 123 | if( v1%2==0 && v2%2!=0 ) {argu += " -C"; doconj = true;} // v1 pair et v2 impair
|
---|
[3925] | 124 | // nom du fichier de sortie avec gestion des duplications
|
---|
[3928] | 125 | if(vcode_suiv==vcode[ip] || vcode_prec==vcode[ip]) argu += " -D";
|
---|
| 126 | if(vcode_prec==vcode[ip]) {
|
---|
| 127 | dupli++;
|
---|
| 128 | if(i==vcode.size()-1) ndupli += dupli;
|
---|
| 129 | } else {
|
---|
| 130 | ndupli += dupli;
|
---|
| 131 | dupli = 0;
|
---|
| 132 | }
|
---|
[3925] | 133 | sprintf(str," -o visi%d_%02d_%02d.ppf",dupli,v1,v2); argu += str;
|
---|
| 134 | argu += " "; argu += vdir[ip]; // repertoire des fichiers acq
|
---|
| 135 | ftxt << argu <<endl;
|
---|
| 136 | nvisi++;
|
---|
[3928] | 137 | cout<<i<<" "<<ip<<" "<<vcode[ip]<<" "<<v1<<","<<v2<<" th="<<vnth[ip]<<" ro="<<vrow[ip]
|
---|
| 138 | <<" du="<<dupli<<" cj="<<doconj<<" "<<vdir[ip]<<endl;
|
---|
[3925] | 139 | }
|
---|
| 140 | cout<<"nvisi tot="<<nvisi<<", number of duplicate="<<ndupli<<", nvisi="<<nvisi-ndupli<<" / 528"<<endl;
|
---|
[3928] | 141 | ftxt << "exit 0" <<endl;
|
---|
[3935] | 142 | }
|
---|
[3925] | 143 |
|
---|
[3935] | 144 | // script should be executable
|
---|
| 145 | string chmod = "chmod a+x "; chmod += outname;
|
---|
| 146 | system(chmod.c_str());
|
---|
| 147 |
|
---|
[3928] | 148 | return 0;
|
---|
[3925] | 149 | }
|
---|
| 150 |
|
---|
| 151 | //-------------------------------------------------
|
---|
| 152 | int decode_numthread(string filein,string& dir)
|
---|
| 153 | {
|
---|
| 154 | unsigned int p = filein.rfind("chanum_");
|
---|
| 155 | if(p>=filein.size()) return -1;
|
---|
| 156 | if(p<=1) dir = ""; else dir = filein.substr(0,p-1);
|
---|
| 157 | const char * c = (filein.c_str() + p);
|
---|
| 158 | int nth = -2;
|
---|
| 159 | sscanf(c,"chanum_%d.ppf",&nth);
|
---|
| 160 | //cout<<"\""<<filein<<"\" "<<p<<" \""<<c<<"\" "<<nth<<" \""<<dir<<"\""<<endl;
|
---|
| 161 | return nth;
|
---|
| 162 | }
|
---|
| 163 |
|
---|