| 1 | /*    Projet BAORadio | 
|---|
| 2 | (C) LAL / Univ. Paris Sud ,   IRFU   2007-2010 | 
|---|
| 3 | Programme de lecture des paquets Acquisition BAORadio | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | // include standard c/c++ | 
|---|
| 7 | #include <math.h> | 
|---|
| 8 | #include <stdio.h> | 
|---|
| 9 | #include <typeinfo> | 
|---|
| 10 | #include <iostream> | 
|---|
| 11 | #include <string> | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | // include mini-fits lib et manipulation de paquets AcqBAORadio | 
|---|
| 15 | #include "minifits.h" | 
|---|
| 16 | #include "brpaqu.h" | 
|---|
| 17 |  | 
|---|
| 18 | int main(int narg, char* arg[]) | 
|---|
| 19 | { | 
|---|
| 20 | if (narg < 2) { | 
|---|
| 21 | cout << " Usage: tstrdfits file1.fits [file2.fits ...] " << endl; | 
|---|
| 22 | return 1; | 
|---|
| 23 | } | 
|---|
| 24 | cout << " ---------- tstrdfits.cc Start ------------- " << endl; | 
|---|
| 25 | int rc = 0; | 
|---|
| 26 | int maxprt = 7; | 
|---|
| 27 | try { | 
|---|
| 28 | int paqsz = 0; | 
|---|
| 29 | int nprt = 0; | 
|---|
| 30 | BRPaquet paq; | 
|---|
| 31 | BRPaqChecker pcheck; | 
|---|
| 32 | Byte* data=NULL; | 
|---|
| 33 | //---- Boucle sur les fichiers a lire ---- | 
|---|
| 34 | for(int ifile=1; ifile<narg; ifile++) { | 
|---|
| 35 | string ffname = arg[ifile]; | 
|---|
| 36 | // -------------- Lecture de bytes | 
|---|
| 37 | cout << ifile <<"-Ouverture/lecture fichier " << ffname << endl; | 
|---|
| 38 | MiniFITSFile mff(ffname, MF_Read); | 
|---|
| 39 | cout << "... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() | 
|---|
| 40 | << " NAxis2=" << mff.NAxis2() << endl; | 
|---|
| 41 | if (mff.DataType() != MF_Byte) { | 
|---|
| 42 | cout << " PB : DataType!=MF_Byte --> skipping " << endl; | 
|---|
| 43 | } | 
|---|
| 44 | if (paqsz == 0)  {  // premier passage, on fixe la taille de paquet et on alloue le buffer | 
|---|
| 45 | paqsz = mff.NAxis1(); | 
|---|
| 46 | cout << " tstrdfits/ Allocating data , PaqSz=" << paqsz << endl; | 
|---|
| 47 | data = new Byte[paqsz]; | 
|---|
| 48 | for(int ib=0; ib<paqsz; ib++) data[ib]=0; | 
|---|
| 49 | paq.Set(data, paqsz); | 
|---|
| 50 | } | 
|---|
| 51 | else {   // Sinon, on verifie que les differents fichiers ont la meme taille de paquet | 
|---|
| 52 | if (paqsz != mff.NAxis1()) { | 
|---|
| 53 | cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()" << " --> skipping " << endl; | 
|---|
| 54 | continue; | 
|---|
| 55 | } | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | size_t sx = mff.NAxis1(); | 
|---|
| 59 | size_t sy = mff.NAxis2(); | 
|---|
| 60 | // On construit un paquet sur | 
|---|
| 61 | // Boucle de lecture des paquets dans le fichier | 
|---|
| 62 | for(int j=0; j<sy; j++) { | 
|---|
| 63 | mff.ReadB(data, sx, j*sx);    // Lecture du paquet | 
|---|
| 64 | pcheck.Check(paq);            // Verification, comptage des paquets OK | 
|---|
| 65 | if ((j%55==0)&&(nprt<maxprt)) {    // Impression optionnel du contenu du paquet | 
|---|
| 66 | paq.Print();    nprt++; | 
|---|
| 67 | } | 
|---|
| 68 | } | 
|---|
| 69 | cout << "---- FIN lecture fichier " << ffname << endl; | 
|---|
| 70 | } | 
|---|
| 71 | cout << "-------- FIN boucle de lecture des fichiers ----------" << endl; | 
|---|
| 72 | cout << pcheck; | 
|---|
| 73 | cout << "------------------------------------------------------" << endl; | 
|---|
| 74 | delete[] data; | 
|---|
| 75 | } | 
|---|
| 76 | catch (MiniFITSException& exc) { | 
|---|
| 77 | cerr << " tstrdfits.cc catched MiniFITSException " << exc.Msg() << endl; | 
|---|
| 78 | rc = 77; | 
|---|
| 79 | } | 
|---|
| 80 | catch (std::exception& sex) { | 
|---|
| 81 | cerr << "\n tstrdfits.cc std::exception :" | 
|---|
| 82 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 83 | << sex.what() << endl; | 
|---|
| 84 | rc = 78; | 
|---|
| 85 | } | 
|---|
| 86 | catch (...) { | 
|---|
| 87 | cerr << " tstrdfits.cc catched unknown (...) exception  " << endl; | 
|---|
| 88 | rc = 79; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | cout << ">>>> tstrdfits.cc ------- FIN ----------- RC=" << rc << endl; | 
|---|
| 92 | return rc; | 
|---|
| 93 |  | 
|---|
| 94 | } | 
|---|