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