1 | #include "machdefs.h"
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <iostream.h>
|
---|
5 | #include <math.h>
|
---|
6 |
|
---|
7 | #include <typeinfo>
|
---|
8 |
|
---|
9 | #include <vector>
|
---|
10 | #include <string>
|
---|
11 |
|
---|
12 | #include "piacmd.h"
|
---|
13 | #include "nobjmgr.h"
|
---|
14 | #include "pistdimgapp.h"
|
---|
15 | #include "servnobjm.h"
|
---|
16 | #include "tvector.h"
|
---|
17 | #include "pitvmaad.h"
|
---|
18 | #include "fftpserver.h"
|
---|
19 | #include "bruit.h"
|
---|
20 | #include "piscdrawwdg.h"
|
---|
21 | #include "ctimer.h"
|
---|
22 |
|
---|
23 | extern "C" {
|
---|
24 | void sopiamodule_init();
|
---|
25 | void sopiamodule_end();
|
---|
26 | }
|
---|
27 |
|
---|
28 | void SophyaFFT(string& nom, string& nomout, string dopt);
|
---|
29 |
|
---|
30 | class sopiamoduleExecutor : public CmdExecutor {
|
---|
31 | public:
|
---|
32 | sopiamoduleExecutor();
|
---|
33 | virtual ~sopiamoduleExecutor();
|
---|
34 | virtual int Execute(string& keyw, vector<string>& args, string& toks);
|
---|
35 | };
|
---|
36 |
|
---|
37 | /* --Methode-- */
|
---|
38 | sopiamoduleExecutor::sopiamoduleExecutor()
|
---|
39 | {
|
---|
40 |
|
---|
41 | PIACmd * mpiac;
|
---|
42 | NamedObjMgr omg;
|
---|
43 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
44 |
|
---|
45 | string hgrp = "SophyaCmd";
|
---|
46 | string kw = "powerspec";
|
---|
47 | string usage = "FFT on a vector -> Plots power spectrum ";
|
---|
48 | usage += "\n Usage: fftp vecName vecFFT [graphic_att] ";
|
---|
49 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 | /* --Methode-- */
|
---|
54 | sopiamoduleExecutor::~sopiamoduleExecutor()
|
---|
55 | {
|
---|
56 | }
|
---|
57 |
|
---|
58 | /* --Methode-- */
|
---|
59 | int sopiamoduleExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
60 | {
|
---|
61 |
|
---|
62 | if (kw == "powerspec") {
|
---|
63 | if (tokens.size() < 2) {
|
---|
64 | cout << "Usage: powerspec nameVec vecFFT [graphic_att]" << endl;
|
---|
65 | return(0);
|
---|
66 | }
|
---|
67 | if (tokens.size() < 3) tokens.push_back((string)"n");
|
---|
68 | SophyaFFT(tokens[0], tokens[1], tokens[2]);
|
---|
69 | }
|
---|
70 |
|
---|
71 | return(0);
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | static sopiamoduleExecutor * piaerex = NULL;
|
---|
76 | /* Nouvelle-Fonction */
|
---|
77 | void sopiamodule_init()
|
---|
78 | {
|
---|
79 | // Fonction d'initialisation du module
|
---|
80 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
|
---|
81 | if (piaerex) delete piaerex;
|
---|
82 | piaerex = new sopiamoduleExecutor;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* Nouvelle-Fonction */
|
---|
86 | void sopiamodule_end()
|
---|
87 | {
|
---|
88 | // Desactivation du module
|
---|
89 | if (piaerex) delete piaerex;
|
---|
90 | piaerex = NULL;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | /* --Methode-- */
|
---|
95 | void SophyaFFT(string& nom, string& nomout, string dopt)
|
---|
96 | {
|
---|
97 | Timer tm("powerspec");
|
---|
98 | NamedObjMgr omg;
|
---|
99 | AnyDataObj* obj=omg.GetObj(nom);
|
---|
100 | if (obj == NULL) {
|
---|
101 | cout << "SophyaFFT() Error , Pas d'objet de nom " << nom << endl;
|
---|
102 | return;
|
---|
103 | }
|
---|
104 |
|
---|
105 | Vector* vin = dynamic_cast<Vector *>(obj);
|
---|
106 | if (vin == NULL) {
|
---|
107 | cout << "SophyaFFT() Error , Objet n'est pas un vecteur " << endl;
|
---|
108 | return;
|
---|
109 | }
|
---|
110 | TVector< complex<double> > * vout = new TVector< complex<double> > ;
|
---|
111 | FFTPackServer ffts;
|
---|
112 | cout << "SophyaFFT() - Computing FFT of vector size " << vin->NElts() << endl;
|
---|
113 | ffts.FFTForward(*vin, *vout);
|
---|
114 | // cout << " SophyaFFT - FFT done " << endl;
|
---|
115 | // tm.Split(" FFT done ");
|
---|
116 |
|
---|
117 | omg.AddObj(vout, nomout);
|
---|
118 | omg.DisplayObj(nomout, dopt);
|
---|
119 | return;
|
---|
120 |
|
---|
121 | }
|
---|