1 | #include "diabolo.h"
|
---|
2 | #include "foyer.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | void fit_foyer(void);
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 | #define indicemax 500
|
---|
10 |
|
---|
11 | static int bolo,indice;
|
---|
12 |
|
---|
13 | static double carte[nb_max_bolo][6]; // pour sommer chaque subscan
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 | //-------------------- fonction exec de la fenetre : foyer -------------------------------
|
---|
18 |
|
---|
19 |
|
---|
20 | void exec_foyer(int fen,int item,double valeur,...)
|
---|
21 | {
|
---|
22 |
|
---|
23 | switch(item)
|
---|
24 | {
|
---|
25 | case ouverture : gg->trace_ouvert=gg->trace_ouvert | 16 ;
|
---|
26 | selectgra(fen);
|
---|
27 |
|
---|
28 | graph->taille_graduations=7;
|
---|
29 | indice=0;
|
---|
30 | bolo=litD(fen,foy_bolo,0);
|
---|
31 | break;
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | case fermeture : gg->trace_ouvert=gg->trace_ouvert & (255-16); // enleve le 16
|
---|
38 | break;
|
---|
39 |
|
---|
40 | case foy_pas :
|
---|
41 | case foy_bolo : bolo=litD(fen,foy_bolo,0);
|
---|
42 | fit_foyer();
|
---|
43 | break;
|
---|
44 | default : break;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | void trace_foyer(double *y)
|
---|
51 | {
|
---|
52 | int j;
|
---|
53 | // gg->compte_subscan contient le N° de subscan et est negatif entre 2 subscans
|
---|
54 |
|
---|
55 |
|
---|
56 | if( (gg->compte_subscan<1) ou (gg->compte_subscan>6) )
|
---|
57 | {
|
---|
58 | if(indice>0)
|
---|
59 | {
|
---|
60 | int s=-gg->compte_subscan;
|
---|
61 | if( (s>=1) && (s<=6) )
|
---|
62 | {
|
---|
63 | for(j=0;j<nb_max_bolo;j++) carte[j][s-1]/=(double)indice;
|
---|
64 | printf("-> valeur x[%d]=%g \n",bolo,carte[bolo-1][s-1]);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | if( (indice>0) && (gg->compte_subscan==-6) ) fit_foyer();
|
---|
68 | indice=0;
|
---|
69 | // printf("ne trace pas un point (entre 2 subscans) \n");
|
---|
70 | return;
|
---|
71 | }
|
---|
72 |
|
---|
73 | if(indice==0)
|
---|
74 | {
|
---|
75 | printf("debut subscan %d ",gg->compte_subscan);
|
---|
76 | selectgra(fenetre_annexe);
|
---|
77 | graph->couleur_trace=gg->compte_subscan+1;
|
---|
78 | style(fenetre_annexe);
|
---|
79 | for(j=0;j<nb_max_bolo;j++) carte[j][gg->compte_subscan-1]=0;
|
---|
80 | }
|
---|
81 |
|
---|
82 | printf("%d ",indice);
|
---|
83 |
|
---|
84 | for(j=0;j<nb_max_bolo;j++) carte[j][gg->compte_subscan-1]+=y[j];
|
---|
85 |
|
---|
86 | trace(fenetre_annexe,indice,y[bolo-1]);
|
---|
87 | if(indice<indicemax) indice++;
|
---|
88 | }
|
---|
89 |
|
---|
90 | #define xcorr(x) (((x)-1)*pas)
|
---|
91 |
|
---|
92 |
|
---|
93 | void fit_foyer(void)
|
---|
94 | {
|
---|
95 | double a,b,c,y0,y1,y2,xmini,x;
|
---|
96 | int i;
|
---|
97 | double pas=litD(fenetre_annexe,foy_pas,0);
|
---|
98 | char ss[255];
|
---|
99 |
|
---|
100 | // x=0,1,2
|
---|
101 |
|
---|
102 | y0=0.5*(carte[bolo-1][0]+carte[bolo-1][5]);
|
---|
103 | y1=0.5*(carte[bolo-1][1]+carte[bolo-1][4]);
|
---|
104 | y2=0.5*(carte[bolo-1][2]+carte[bolo-1][3]);
|
---|
105 | c=y0;
|
---|
106 | a=0.5*(c-2*y1+y2);
|
---|
107 | b=y1-c-a;
|
---|
108 | // cherche le minimum
|
---|
109 | xmini=-0.5*b/a;
|
---|
110 | xmini=xcorr(xmini);
|
---|
111 |
|
---|
112 | efface(fenetre_annexe);
|
---|
113 | selectgra(fenetre_annexe);
|
---|
114 | graph->couleur_trace=rouge;
|
---|
115 | graph->couleur_texte=violet;graph->taille_texte=16;
|
---|
116 | graph->type_symbole=rondplein;graph->taille_symbole=5;graph->ligne_trace=0;
|
---|
117 | style(fenetre_annexe);
|
---|
118 |
|
---|
119 | for(i=0;i<3;i++) trace(fenetre_annexe,xcorr(i),carte[bolo-1][i]);
|
---|
120 | for(i=0;i<3;i++) trace(fenetre_annexe,xcorr(i),carte[bolo-1][5-i]);
|
---|
121 |
|
---|
122 | graph->type_symbole=rien;graph->ligne_trace=1;
|
---|
123 | graph->couleur_trace=bleu;
|
---|
124 | style(fenetre_annexe);
|
---|
125 |
|
---|
126 | for(x=-0.4;x<2.4;x+=0.05) trace(fenetre_annexe,xcorr(x),a*x*x+b*x+c);
|
---|
127 |
|
---|
128 | autox(fenetre_annexe);autoy(fenetre_annexe);retrace(fenetre_annexe);
|
---|
129 |
|
---|
130 | place(fenetre_annexe,-0.9,3*a+b+c);
|
---|
131 |
|
---|
132 | sprintf(ss,"correction %4.1f",xmini);
|
---|
133 | texte(fenetre_annexe,0,ss);
|
---|
134 |
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|