source: Sophya/trunk/AddOn/TAcq/chanum_1210.cc@ 3928

Last change on this file since 3928 was 3928, checked in by cmv, 15 years ago

gestion de la conjugaison complexe pour visi # de <E.conj(W)>, cmv 17/12/2010

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