| 1 | // Utilisation de SOPHYA pour faciliter les tests ... | 
|---|
| 2 | #include "sopnamsp.h" | 
|---|
| 3 | #include "machdefs.h" | 
|---|
| 4 |  | 
|---|
| 5 | // include standard c/c++ | 
|---|
| 6 | #include <math.h> | 
|---|
| 7 | #include <stdio.h> | 
|---|
| 8 |  | 
|---|
| 9 | #include <iostream> | 
|---|
| 10 | #include <string> | 
|---|
| 11 |  | 
|---|
| 12 | #include "pexceptions.h" | 
|---|
| 13 | #include "tvector.h" | 
|---|
| 14 | #include "fioarr.h" | 
|---|
| 15 | #include "tarrinit.h" | 
|---|
| 16 | #include "timestamp.h" | 
|---|
| 17 | #include "fftpserver.h" | 
|---|
| 18 | #include "fftwserver.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "FFTW/fftw3.h" | 
|---|
| 21 |  | 
|---|
| 22 | // include sophya mesure ressource CPU/memoire ... | 
|---|
| 23 | #include "resusage.h" | 
|---|
| 24 | #include "ctimer.h" | 
|---|
| 25 | #include "timing.h" | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | // include mini-fits lib | 
|---|
| 29 | #include "minifits.h" | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | inline r_4 Zmod2(complex<r_4> z) | 
|---|
| 33 | { return (z.real()*z.real()+z.imag()*z.imag()); } | 
|---|
| 34 |  | 
|---|
| 35 | int main(int narg, char* arg[]) | 
|---|
| 36 | { | 
|---|
| 37 | if (narg < 2) { | 
|---|
| 38 | cout << " Usage: mfits2spec file1.fits [file2.fits ...] " << endl; | 
|---|
| 39 | return 1; | 
|---|
| 40 | } | 
|---|
| 41 | cout << " ---------- mfits2spec.cc Start ------------- " << endl; | 
|---|
| 42 |  | 
|---|
| 43 | TArrayInitiator  _inia; | 
|---|
| 44 |  | 
|---|
| 45 | int rc = 0; | 
|---|
| 46 | try { | 
|---|
| 47 | ResourceUsage resu; | 
|---|
| 48 | TVector<float> spectre; | 
|---|
| 49 | sa_size_t nzm = 0;   // Nb de spectres moyennes | 
|---|
| 50 | for(int ifile=1; ifile<narg; ifile++) { | 
|---|
| 51 | string ffname = arg[ifile]; | 
|---|
| 52 | // -------------- Lecture de bytes | 
|---|
| 53 | cout << ifile <<"-Ouverture/lecture fichier " << ffname << endl; | 
|---|
| 54 | MiniFITSFile mff(ffname, MF_Read); | 
|---|
| 55 | cout << "... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() | 
|---|
| 56 | << " NAxis2=" << mff.NAxis2() << endl; | 
|---|
| 57 | if (mff.DataType() != MF_Byte) { | 
|---|
| 58 | cout << " PB : DataType!=MF_Byte --> skipping " << endl; | 
|---|
| 59 | } | 
|---|
| 60 | size_t sx = mff.NAxis1(); | 
|---|
| 61 | size_t sy = mff.NAxis2(); | 
|---|
| 62 |  | 
|---|
| 63 | Byte* data = new Byte[sx]; | 
|---|
| 64 | TVector<r_4> vx(sx); | 
|---|
| 65 | TVector< complex<r_4> > cfour; | 
|---|
| 66 | FFTPackServer ffts; | 
|---|
| 67 |  | 
|---|
| 68 | for(int j=0; j<sy; j++) { | 
|---|
| 69 | mff.ReadB(data, sx, j*sx); | 
|---|
| 70 | // On convertit en float | 
|---|
| 71 | for(sa_size_t ix=0; ix<vx.Size(); ix++)  vx(ix) = (r_4)(data[ix]); | 
|---|
| 72 | // On fait le FFT | 
|---|
| 73 | ffts.FFTForward(vx, cfour); | 
|---|
| 74 | if (!spectre.IsAllocated())  spectre.SetSize(cfour.Size()); | 
|---|
| 75 |  | 
|---|
| 76 | // On cumule les modules carres | 
|---|
| 77 | for(sa_size_t jf=1; jf<spectre.Size(); jf++) | 
|---|
| 78 | spectre(jf) += Zmod2(cfour(jf)); | 
|---|
| 79 | nzm++; | 
|---|
| 80 |  | 
|---|
| 81 | //      cout << " j=" << j << " data[0...3]=" << (int)data[0] << " , " | 
|---|
| 82 | //           << (int)data[1] << " , " <<  (int)data[2] << endl; | 
|---|
| 83 | } | 
|---|
| 84 | cout << "---- FIN lecture " << ffname << endl; | 
|---|
| 85 | } | 
|---|
| 86 | cout << "---- Ecriture spectre moyenne ds mspectre.ppf " << endl; | 
|---|
| 87 | spectre /= (r_4)(nzm); | 
|---|
| 88 | POutPersist po("mspectre.ppf"); | 
|---|
| 89 | po << spectre; | 
|---|
| 90 | cout << resu ; | 
|---|
| 91 | } | 
|---|
| 92 | catch (MiniFITSException& exc) { | 
|---|
| 93 | cerr << " mfits2spec.cc catched MiniFITSException " << exc.Msg() << endl; | 
|---|
| 94 | rc = 77; | 
|---|
| 95 | } | 
|---|
| 96 | catch (std::exception& sex) { | 
|---|
| 97 | cerr << "\n mfits2spec.cc std::exception :" | 
|---|
| 98 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 99 | << sex.what() << endl; | 
|---|
| 100 | rc = 78; | 
|---|
| 101 | } | 
|---|
| 102 | catch (...) { | 
|---|
| 103 | cerr << " mfits2spec.cc catched unknown (...) exception  " << endl; | 
|---|
| 104 | rc = 79; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | cout << ">>>> mfits2spec.cc ------- FIN ----------- RC=" << rc << endl; | 
|---|
| 108 | return rc; | 
|---|
| 109 |  | 
|---|
| 110 | } | 
|---|