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

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

add info, cmv 13/12/2010

File size: 4.5 KB
RevLine 
[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
20// > chanum_1210 -f 1375.0610351 -o CasA02Dec.txt crt*/CasA02Dec/chanum_*.ppf
21// > chanum_1210 -f 1375.0610351 -o Crab03Dec.txt crt*/Crab03Dec/chanum_*.ppf
22// > chanum_1210 -f 1382.5378418 -o Sun03Dec.txt crt*/Sun03Dec/chanum_*.ppf
23// > chanum_1210 -f 1390.0146484 -o CasA03Dec.txt crt*/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.txt : 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.txt";
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 if(!ftxt) {cout<<"!!!!OPENING failed "<<outname<<endl; return -3;}
95 int dupli = 0, ndupli = 0;
96 nvisi = 0;
97 for(uint_4 i=0;i<vcode.size();i++) {
98 char str[128];
[3927]99 sprintf(str,"${EXE}/svv2mtx2_1210 -T 0,99999 -F 0,9999,1 -f %.7f",freq0);
[3925]100 string argu = str;
101 uint_4 ip = IVcode(i);
102 uint_4 vcode_prec = (i>0) ? vcode[IVcode(i-1)]: 99999999;
103 uint_4 vcode_suiv = (i<vcode.size()-1) ? vcode[IVcode(i+1)]: 99999999;
104 uint_4 v1 = vcode[ip]/1000, v2 = vcode[ip]%100;
105 if(v1>v2) {swap(v1,v2); argu += " -c";} // faut-il conjuger ?
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 // nom du fichier de sortie avec gestion des duplications
109 if(vcode_suiv==vcode[ip] || vcode_prec!=vcode[ip]) argu += " -D";
110 if(vcode_prec==vcode[ip]) { dupli++; argu += " -D"; }
111 else { ndupli+=dupli; dupli=0; }
112 sprintf(str," -o visi%d_%02d_%02d.ppf",dupli,v1,v2); argu += str;
113 argu += " "; argu += vdir[ip]; // repertoire des fichiers acq
114 ftxt << argu <<endl;
115 nvisi++;
116 cout<<i<<" "<<ip<<" "<<vcode[ip]<<" "<<v1<<","<<v2<<" th="<<vnth[ip]<<" ro="<<vrow[ip]<<" du="<<dupli<<" "<<vdir[ip]<<endl;
117 }
118 cout<<"nvisi tot="<<nvisi<<", number of duplicate="<<ndupli<<", nvisi="<<nvisi-ndupli<<" / 528"<<endl;
119
120 return 0;
121}
122
123//-------------------------------------------------
124int decode_numthread(string filein,string& dir)
125{
126 unsigned int p = filein.rfind("chanum_");
127 if(p>=filein.size()) return -1;
128 if(p<=1) dir = ""; else dir = filein.substr(0,p-1);
129 const char * c = (filein.c_str() + p);
130 int nth = -2;
131 sscanf(c,"chanum_%d.ppf",&nth);
132 //cout<<"\""<<filein<<"\" "<<p<<" \""<<c<<"\" "<<nth<<" \""<<dir<<"\""<<endl;
133 return nth;
134}
135
Note: See TracBrowser for help on using the repository browser.