source: Sophya/trunk/AddOn/TAcq/mcrd.cc@ 3640

Last change on this file since 3640 was 3640, checked in by ansari, 16 years ago

Correction et ameliorations multiples - en particulier mcrd.cc, brproc.cc et brfitsrd.cc, Reza 27/05/2009

File size: 4.3 KB
Line 
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 "timestamp.h"
25#include "fftpserver.h"
26#include "fftwserver.h"
27
28#include "FFTW/fftw3.h"
29
30// include sophya mesure ressource CPU/memoire ...
31#include "resusage.h"
32#include "ctimer.h"
33#include "timing.h"
34
35
36// include mini-fits lib , et structure paquet BAORadio
37#include "minifits.h"
38#include "brpaqu.h"
39#include "brfitsrd.h"
40#include "brproc.h"
41
42
43//--- Fonctions de ce fichier
44int DecodeMiniFitsHeader(string& filename, uint_4& paqsz, uint_4& npaq, bool fgnotrl=false)
45{
46 MiniFITSFile mff(filename, MF_Read);
47 cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
48 << " NAxis2=" << mff.NAxis2() << endl;
49 paqsz = mff.NAxis1();
50 npaq = mff.NAxis2();
51 if (fgnotrl) paqsz += 16;
52 return 0;
53}
54
55//----------------------------------------------------
56//----------------------------------------------------
57int main(int narg, char* arg[])
58{
59 if (narg < 4) {
60 cout << " --- Reading/Processing BAORadio FITS files" << endl;
61 cout << " Usage: mcrd ACT OutPPF -infits DirName Imin Imax [NZones,NbPaqinZone] " << endl;
62 cout << " ACT= notrl FITS files without frame trailer \n"
63 << " OutPPF : Output PPF file name (without .ppf)" << endl;
64 cout << " -infiles DirName Imin Imax : Input fits directory and sequence numbers \n"
65 << " FileNames=DirName/signalII.fits Imin<=II<=Imax \n"
66 << " - NZones,NbPaqinZone : Number of Zones and number of paquets in one zone\n"
67 << " of the RAcqMemZoneMgr memory manager (default = 4,128) " << endl;
68 return 1;
69 }
70
71 TArrayInitiator _inia;
72
73 int rc = 0;
74 try {
75 string act = arg[1];
76 string outname = arg[2];
77 vector<string> infiles;
78 if ((strcmp(arg[3],"-infits")!=0) || (narg<7)) {
79 cout << " mcrd/Error arguments - type mcrd for help" << endl;
80 return 2;
81 }
82 char nbuff[1024];
83 char* dirname = arg[4];
84 int imin = atoi(arg[5]);
85 int imax = atoi(arg[6]);
86 for(int ii=imin; ii<=imax; ii++) {
87 sprintf(nbuff,"%s/signal%d.fits",dirname,ii);
88 infiles.push_back(nbuff);
89 }
90 int nzones = 4;
91 int npaqz = 128;
92 if (narg>7) sscanf(arg[7],"%d,%d",&nzones,&npaqz);
93
94 cout << " ---------- mcrd.cc Start - ACT= " << act << " ------------- " << endl;
95 ResourceUsage resu;
96 bool fgnotrl=false; // fichier fits avec Trailer de frame (> mai 2009)
97 if (act=="notrl") fgnotrl=true; // fichier fits SANS trailer
98
99 uint_4 paqsz, npaqf;
100 DecodeMiniFitsHeader(infiles[0],paqsz, npaqf, fgnotrl);
101
102 cout << " mcrd: NZones=" << nzones << " NbPaq=" << npaqz << "(in file=" << npaqf
103 << " ) PaqSz=" << paqsz << endl;
104
105 RAcqMemZoneMgr mmgr(nzones, npaqz, paqsz, sizeof(complex<r_4>)*paqsz);
106 mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
107
108 BRFitsReader reader(mmgr, infiles, fgnotrl);
109 BRProcARaw2C proc(mmgr, outname, npaqf, 1, npaqf*infiles.size()/npaqz);
110
111 cout << " mcrd.cc : Starting threads (reader, proc) ... " << endl;
112 reader.start();
113 proc.start();
114 sleep(1);
115 cout << " mcrd.cc : Waiting for reader thread to finish ... " << endl;
116 reader.join();
117 cout << " mcrd.cc : Reader finished, waiting for process thread to finish ... " << endl;
118 sleep(2);
119 mmgr.Stop();
120 proc.join();
121 mmgr.Print(cout);
122 cout << resu ;
123 }
124 catch (MiniFITSException& exc) {
125 cerr << " mcrd.cc catched MiniFITSException " << exc.Msg() << endl;
126 rc = 77;
127 }
128 catch (std::exception& sex) {
129 cerr << "\n mcrd.cc std::exception :"
130 << (string)typeid(sex).name() << "\n msg= "
131 << sex.what() << endl;
132 rc = 78;
133 }
134 catch (...) {
135 cerr << " mcrd.cc catched unknown (...) exception " << endl;
136 rc = 79;
137 }
138
139 cout << ">>>> mcrd.cc ------- FIN ----------- RC=" << rc << endl;
140 return rc;
141
142}
Note: See TracBrowser for help on using the repository browser.