1 | |
---|
2 | /*///////////////////////////////////////////////////////////////////////////// |
---|
3 | /////////////////////// 1e HEADER de DYNAMO (dynide.h) //////////////////////*/ |
---|
4 | /****************************************************************************** |
---|
5 | dynide.h : Include, DEfine, (Etc...) |
---|
6 | Ysys error #next=2 |
---|
7 | ******************************************************************************/ |
---|
8 | |
---|
9 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
10 | /* LES INCLUDES DE DYNAMO ET POUR TOUT LE MONDE */ |
---|
11 | //#include <iomanip.h> |
---|
12 | #include <iostream> |
---|
13 | |
---|
14 | #include <iomanip> |
---|
15 | #include <stdio.h> |
---|
16 | #include <string.h> |
---|
17 | //#include <fstream.h> |
---|
18 | #include <fstream> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <time.h> |
---|
21 | #include <math.h> |
---|
22 | #include <signal.h> |
---|
23 | #include <stdarg.h> |
---|
24 | //#include <ccomplex> |
---|
25 | #include <complex> |
---|
26 | //#include <complex.h> //pour octopus (Mandrake et ces pb de deprecated ...!?) |
---|
27 | |
---|
28 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
29 | /* DES DEFINES PROPRES A YAO */ |
---|
30 | #define BUFSIZE 1024 |
---|
31 | #define STRSIZE20 20 |
---|
32 | #define STRSIZE80 80 |
---|
33 | #define NB_MAX_ARG_CDE 20 /* nombre maxi d'arguments pour une commande */ |
---|
34 | #define ON 1 |
---|
35 | #define OFF 0 |
---|
36 | #define OK 1 |
---|
37 | #define KO 0 |
---|
38 | #define OUI 1 |
---|
39 | #define NON 0 |
---|
40 | #define PI 3.14159265358979323846 |
---|
41 | #define LG_MAX_NAME 24 /* longueur max d'un nom ou mot a usage divers */ |
---|
42 | |
---|
43 | using namespace std; |
---|
44 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
45 | |
---|
46 | #ifdef LINUXPC |
---|
47 | // ici les fonctions sont underscorees |
---|
48 | extern void *scpctl_; |
---|
49 | extern void *ctlcan_; |
---|
50 | extern void *canctl_; |
---|
51 | //extern "C" void m1qn3_ (void f(long *, long *, float [], float *, float [], long [], float [], double []), |
---|
52 | extern "C" void m1qn3_ (void f(int *, long *, float [], float *, float [], long [], float [], double []), |
---|
53 | void **, void **, void **, |
---|
54 | long *, float [], float *, float [], float *, float *, |
---|
55 | float *, long *, long *, long *, long *, long *, long [], float [], long *, |
---|
56 | long [], float [], double [] |
---|
57 | ); |
---|
58 | //#ifdef YO_M2QN1 ici, on ne sait pas encore si YO_M2QN1 va etre defini ... |
---|
59 | //extern "C" void m2qn1_ (void f(long *, long *, float [], float *, float [], long [], float [], double []), |
---|
60 | extern "C" void m2qn1_ (void f(int *, long *, float [], float *, float [], long [], float [], double []), |
---|
61 | long *, float [], float *, float [], float [], float *, float *, |
---|
62 | long *, long *, long *, long *, long *, float [], float [], |
---|
63 | long [], float [], long [], float [], double [] |
---|
64 | ); |
---|
65 | //#endif |
---|
66 | #else |
---|
67 | // la elles ne le sont pas |
---|
68 | extern void *scpctl; |
---|
69 | extern void *ctlcan; |
---|
70 | extern void *canctl; |
---|
71 | //extern "C" void m1qn3 (void f(long *, long *, float [], float *, float [], long [], float [], double []), |
---|
72 | extern "C" void m1qn3 (void f(int *, long *, float [], float *, float [], long [], float [], double []), |
---|
73 | void **, void **, void **, |
---|
74 | long *, float [], float *, float [], float *, float *, |
---|
75 | float *, long *, long *, long *, long *, long *, long [], float [], long *, |
---|
76 | long [], float [], double [] |
---|
77 | ); |
---|
78 | //#ifdef YO_M2QN1 ... idem ici, (ce ne devrait pas etre genant (?) ; |
---|
79 | //extern "C" void m2qn1 (void f(long *, long *, float [], float *, float [], long [], float [], double []), |
---|
80 | extern "C" void m2qn1 (void f(int *, long *, float [], float *, float [], long [], float [], double []), |
---|
81 | long *, float [], float *, float [], float [], float *, float *, |
---|
82 | long *, long *, long *, long *, long *, float [], float [], |
---|
83 | long [], float [], long [], float [], double [] |
---|
84 | ); |
---|
85 | //#endif |
---|
86 | #endif |
---|
87 | |
---|
88 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
89 | |
---|
90 | /*///////////////////////////////////////////////////////////////////////////// |
---|
91 | /////////////////////// 2e HEADER de DYNAMO (dynamo.h) //////////////////////*/ |
---|
92 | /****************************************************************************** |
---|
93 | dynamo.h : ici commence l'encapsulage ... |
---|
94 | ******************************************************************************/ |
---|
95 | |
---|
96 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
97 | /* DES ELEMENTS POUR M1QN3 */ |
---|
98 | /*#define Y3_M 8 ou en variable globale Y3m ? anywhere now this is done by the generator ! */ |
---|
99 | int Y3run(char vers); /* add first for "chloro" (Frederic) */ |
---|
100 | void Y3valstate_all(); /* add first for "atmos" (Cedric) */ |
---|
101 | int Y3windice; /* indice de travail pour l'affectation des tableaux Y3x et Y3g */ |
---|
102 | int Yc3_run(char vers); |
---|
103 | long Y3modo; /* mode de sortie de m1qn3 (a toute fin utile) */ |
---|
104 | |
---|
105 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
106 | /* DES PROTOTYPAGES POUR TOUS LE MONDE */ |
---|
107 | /*Des fonctions de services de Yao ------------------------------------------*/ |
---|
108 | template<class TypVal>int Yinv_tri_vect (int mat_dim, TypVal vect[], TypVal prod[], TypVal inf[], TypVal diag[], TypVal sup[]); |
---|
109 | template<class TypVal>int Yinv_tri_mat (int mat_dim, TypVal inf[], TypVal diag[], TypVal sup[], TypVal mat_inv[]); |
---|
110 | template<class TypReel>void Yvsmatt(int lig, int col, int max_col, TypReel vin[], TypReel Mat[], TypReel vout[]); |
---|
111 | //template<class TypReel>void YvsmattLuigi(int lig, int col, int max_col, TypReel vin[], TypReel Mat[], TypReel vout[]); |
---|
112 | template<class TypReel>void Yvsmat (int lig, int col, int max_col, TypReel vout[], TypReel Mat[], TypReel vin[]); |
---|
113 | template<class TypValA, class TypValB, class TypValX>void Ymxmat (int la, int cl, int cb, TypValA MatA[], TypValB MatB[], TypValX MatX[]); |
---|
114 | template<class TypReal> void Ycx_jac(complex<TypReal> derivee, int j, int i); |
---|
115 | template<class TypReal> void Ycxr_jac(complex<TypReal> derivee, int l, int c); |
---|
116 | |
---|
117 | /*Des fonctions standards de Yao (a completer au fur et a mesure selon les |
---|
118 | besoins ...?) -------------------------------------------------------------*/ |
---|
119 | template<class TypReal>void Yiorwf (char *nmmod, int w4, int w1, int w2, int w3, int wt, TypReal *valout, TypReal valin); |
---|
120 | int Yio_savestate (char *nmmod, char *oaxis, int pdt, char *filename); |
---|
121 | void Yrun(long Yit); |
---|
122 | void Ybasic_it(); |
---|
123 | void Yforwardrun(int itraj, int nbpas); //Yforwardrun(long Yit, int Ypas); |
---|
124 | int Yforward(int itraj, int topstop); //Yforward(int Ypas); |
---|
125 | int Yforward_order(); |
---|
126 | void Ycobs(); //Ycost(); |
---|
127 | void Ycostlms_all (); |
---|
128 | void Ybackwardrun(int itraj, int nbpas); //Ybackwardrun(long Yit, int Ypas); |
---|
129 | void Ybackward(int itraj, int topstop); //Ybackward(int Ypas); |
---|
130 | int Ybackward_order(); |
---|
131 | void Ylinward(int Ypas); |
---|
132 | void Yadjust(); |
---|
133 | void Yadjust_all (); |
---|
134 | int Yimod(char *nmmod); |
---|
135 | void Ysetting(char *codop); |
---|
136 | void Ydbg_ting(char *str, int nbi, char *nmmod); |
---|
137 | void Ydbg_beta(char *str, int nbi, char *nmmod); |
---|
138 | void Ydbg_nanf(char *str, int nbi, char *nmmod); |
---|
139 | int Ytesterrad_mod(char *nmmod, double YLTRes, double YAdRes); |
---|
140 | int Yset_modeltime (int time); //PLM, je ne traite que le repositionnement au debut du modele !!! (ARAR) |
---|
141 | int Yispace(char *spacename); |
---|
142 | int Yitraj(char *trajname); |
---|
143 | int Ytttt_pdt (int wxtraj, int topy, int wytraj); |
---|
144 | int Yactraj(int cdesc, char *cdes[]); |
---|
145 | int Yfarg(int(*fct)(int argc, char *argv[]), char *args); |
---|
146 | int Yrecup_cde (int *cdesc, char *cdeline, char *cdes[]); |
---|
147 | void Ylopera(); |
---|
148 | void Ylistobs(int itraj); |
---|
149 | int Yentry0 (int argc, char *argv[]); |
---|
150 | |
---|
151 | /*Des fonctions reseaux de neurones de Yao: celles-ci sont dans Dynnet.h ----*/ |
---|
152 | |
---|
153 | |
---|
154 | /* ///////////////////////////////////////////////////////////////////////// */ |
---|
155 | /* DES TYPES ET STRUCTURES DE DONNEES */ |
---|
156 | enum YCostKind /* les fonctions de cout : */ |
---|
157 | { COST_APPLI, /* fonction de cout propre à l'application */ |
---|
158 | COST_LMS /* fonction de cout lms standard de Yao */ |
---|
159 | }; |
---|
160 | enum YCostL2Kind /* les fonctions de cout : */ |
---|
161 | { //COSTL2_GRAD, /* */ |
---|
162 | //COSTL2_ONLY /* */ |
---|
163 | //,COSTL3_PROJECT /* */ |
---|
164 | //,COSTL3_NANACT /* */ |
---|
165 | //, |
---|
166 | WISHL2_NANACT /* */ |
---|
167 | ,WISHL2_DIFF /* */ |
---|
168 | ,WISHL2_QTEA /* */ |
---|
169 | ,COSTL2_WISHDIFF /* */ |
---|
170 | ,COSTL2_WISHQTEA /* */ |
---|
171 | ,COSTL2_GRAD /* */ |
---|
172 | }; |
---|
173 | enum YAdjustKind /* le type d'ajustement : */ |
---|
174 | { ADJUST_APPLI, /* fonction d'ajustement propre à l'application */ |
---|
175 | ADJUST_STD, /* fonction d'ajustement standard (et classique) de Yao */ |
---|
176 | ADJUST_M1QN3 /* M1QN3 (PLM: pas vraiment utile puisque c'est d'office forced avec m1qn3, but ...) */ |
---|
177 | }; |
---|
178 | enum YRunL1Kind /* type de run (run algo mode) au 1er niveau :*/ |
---|
179 | { RUNL1_STD, /* soit methode de base simple, standard */ |
---|
180 | RUNL1_M1QN3 /* soit 'a la maniere de' m1qn3 */ |
---|
181 | }; |
---|
182 | enum YRunL2Kind /* le mode de fonctionnement de run (run algo mode), 2ème niveau : */ |
---|
183 | { RUNL2_STD, /* soit algo de base simple, standard */ |
---|
184 | RUNL2_INCR /* soit algo incremental */ |
---|
185 | }; |
---|
186 | enum YioKind /* le cas d'io concerne : */ |
---|
187 | { YIO_LOADSTATE, /* chargement des etats (not yet) */ |
---|
188 | YIO_SAVESTATE, /* sauvegarde des etats */ |
---|
189 | YIO_LOADOBS, /* chargement des observations */ |
---|
190 | YIO_SAVEOBS, /* sauvegarde des observations (not yet & why?) */ |
---|
191 | YIO_OUTOOBS, /* copie state->obs */ |
---|
192 | YIO_OUTOEBX, /* copie state->ebauche (in the same arbobs) */ |
---|
193 | YIO_OBSTOUT, /* copie obs->state (not yet & why?) */ |
---|
194 | YIO_LISTOBS /* liste des observations */ |
---|
195 | }; |
---|
196 | /* type du run courant de trajectoire (pour hidjack)*/ |
---|
197 | enum YWardKind |
---|
198 | { FORWARD, |
---|
199 | BACKWARD, |
---|
200 | LINWARD |
---|
201 | }; |
---|
202 | /* structure d'un noeud de l'arborescence des observations */ |
---|
203 | struct Yst_nodo { |
---|
204 | int iind; /* indice pour l'indicateur t, m, s, i, j */ |
---|
205 | struct Yst_nodo *frere; |
---|
206 | struct Yst_nodo *fils; |
---|
207 | }; |
---|
208 | |
---|
209 | /* structure d'une trajectoire */ |
---|
210 | struct Yst_traj { |
---|
211 | char name[STRSIZE80+1]; |
---|
212 | char type; |
---|
213 | int nbuptime; |
---|
214 | float offtime; |
---|
215 | float dtime; // delta t |
---|
216 | float curtime; |
---|
217 | int toptime; // temps unitaire |
---|
218 | int nbsteptime; |
---|
219 | float stoptime; //=Ybegintime + offtime + (dt*nbsteptime) (nb: initialement, Ybegintime=0) |
---|
220 | int (*fward)(int nbt); |
---|
221 | int (*bward)(int nbt); |
---|
222 | int (*lward)(int nbt); |
---|
223 | int (*dfward)(int modop, char *nmmod, int All, int KeKo, int koleft, float pdx, float ptol, int yi, int yj, int yk); |
---|
224 | short isactiv; |
---|
225 | struct Yst_nodo *YRobs; //=NULL; // Racine de l'Arborescence des observations |
---|
226 | struct Yst_nodo *TRobs; // un pointeur sur le Time s/Root courant trouve |
---|
227 | }; |
---|
228 | /* structure d'un espace */ |
---|
229 | struct Yst_space { |
---|
230 | char name[STRSIZE80+1]; |
---|
231 | char type; |
---|
232 | int axi; |
---|
233 | int axj; |
---|
234 | int axk; |
---|
235 | char traj_name[STRSIZE80+1]; |
---|
236 | }; |
---|
237 | /* structure d'un operateur */ |
---|
238 | struct Yst_opera { |
---|
239 | char name[STRSIZE80+1]; |
---|
240 | char type; |
---|
241 | int axi; |
---|
242 | int axj; |
---|
243 | int axk; |
---|
244 | char traj_name[STRSIZE80+1]; |
---|
245 | short isactiv; |
---|
246 | }; |
---|
247 | /* structure d'un module */ |
---|
248 | struct Yst_modul { |
---|
249 | char Name[STRSIZE80+1]; |
---|
250 | void *Tadr; |
---|
251 | int dim; |
---|
252 | int axi; |
---|
253 | int axj; |
---|
254 | int axk; |
---|
255 | int nb_input; |
---|
256 | int nb_stout; |
---|
257 | int nb_time; |
---|
258 | int is_cout; |
---|
259 | int is_target; |
---|
260 | int deb_target; |
---|
261 | int end_target; |
---|
262 | double scoef; |
---|
263 | double bcoef; |
---|
264 | double pcoef; |
---|
265 | int ctrord; |
---|
266 | char space_name[STRSIZE80+1]; |
---|
267 | //short sys_flagobs; |
---|
268 | }; |
---|
269 | /* structure d'un reseau de neurone */ |
---|
270 | typedef enum {SigLin, SigSig} Activation; |
---|
271 | struct Yst_netward { |
---|
272 | char Name[STRSIZE80+1]; |
---|
273 | int nbweight; |
---|
274 | int nbinput; |
---|
275 | int nboutput; |
---|
276 | int maxcell; |
---|
277 | double *tweight; |
---|
278 | Activation activ; |
---|
279 | }; |
---|
280 | /* structure des definitions de valeurs */ |
---|
281 | struct Yst_defval { |
---|
282 | char Name[STRSIZE80+1]; |
---|
283 | char macro[STRSIZE80+1]; |
---|
284 | }; |
---|
285 | |
---|
286 | short Ysysdbg; /* reserved for system supervisor */ |
---|
287 | |
---|
288 | /* ///////////////////////////////////////////////////////////////////////// */ |
---|
289 | /* LES GLOBALES DE YAO ET POUR TOUT LE MONDE */ |
---|
290 | long Ytop0; /* un top global pour decompter le temps */ |
---|
291 | int YTemps; /* horloge des pas de temps a patir d'NBUPTIME */ |
---|
292 | //float YTotalCost; /* cout total */ |
---|
293 | double YTotalCost; /* cout total */ |
---|
294 | double YCoefGrad = 1.0; /* coeff de calcul du gradient (defaut=1) */ |
---|
295 | enum YCostKind YTypeCost=COST_LMS; /* le type de la fonction de cout (default=lms) */ |
---|
296 | enum YCostL2Kind YCaseCost=COSTL2_GRAD; //COSTL2_GRAD; /* */ |
---|
297 | enum YAdjustKind YTypeAdjust=ADJUST_STD; /* le type d'ajustement (default=standard) */ |
---|
298 | enum YRunL1Kind YAL1Run=RUNL1_STD; /* mode (algo) du run au 1er niveau (default=standard : definie par la commande run utilisee) */ |
---|
299 | enum YRunL2Kind YAL2Run=RUNL2_STD; /* mode (algo) du run au 2em niveau (default=standard : definie par la commande run utilisee) */ |
---|
300 | long YNbItRun; /* nombre d'itérations demande ((IO)niter p/m1qn3) */ |
---|
301 | long YItRun; /* l'iteration courante du run */ |
---|
302 | long YNbExtL; /* nombre de boucles externes pour les algo incrementaux */ |
---|
303 | int YDispTime; /* boolean pour l'affichage du temps */ |
---|
304 | int YDispCost; /* boolean pour l'affichage du cout */ |
---|
305 | char YPrompt[STRSIZE20+1]; /* le prompt pour la saisie des commandes */ |
---|
306 | int YEcho = ON; /* echo de la commande */ |
---|
307 | |
---|
308 | int Yi, Yj, Yk; /* indice de parcourt de l'espace gabarit */ |
---|
309 | int YY; /* The variable YY is used only as artifact (in the parallelization) for the bug of openMP |
---|
310 | * that does not allow to global variables passed to a function to conserve the value |
---|
311 | * of the calling function. |
---|
312 | * The value passed to the function is uncorrect (probably is the initialization value) */ |
---|
313 | |
---|
314 | int YY_RUNBRK=ON; /* gestion signal d'interruption pour breaker le run */ |
---|
315 | short YM_EXE; /* Mode d'execution: 'B': Batch; 'I': intercatif */ |
---|
316 | //int YM_GRADTEST = OFF; /* Mode test du gradient: pour tester les derivees (ne pas affecter */ |
---|
317 | /* les inputs des modules) */ |
---|
318 | int Yszint, Yszreal; /* tailles d'un int et d'un reel (initialises au debut de Dynamo.cpp */ |
---|
319 | FILE *Yiofp; /* file pointeur pour les fonctions d'entree/sortie */ |
---|
320 | short YioWrite, YioRead; /* flag (booleen) pour le mode de fonctionnement des fct d'entree/sortie */ |
---|
321 | short YioBin, YioAscii; /* flag pour le type de stockage des donnees: binaire ou ascii */ |
---|
322 | short YioState, YioTime, YioAxes; /* flag pour la convention, le format de stockage des donnees */ |
---|
323 | int YioszReal; /* taille d'un reel pour des valeurs (binaire?) a loader (en provenance de l'exterieur */ |
---|
324 | short YioModulot; /* modulo t pour les sauvegardes de donnees */ |
---|
325 | int YioInsertObsCtr=-1; /* compteur d'obs inserees (-1 pour savoir si y'a au moins 1 obs. Utile pour testad */ |
---|
326 | int YioOvrObsCtr; /* compteur d'obs overidees */ |
---|
327 | int YioSelectedCtr; /* compteur de selection */ |
---|
328 | int YioDi, YioDj, YioDk; /* dimension d'un espace exterieur a charger */ |
---|
329 | int Yiodi, Yiodj, Yiodk; /* decalage a appliquer sur les coordonnes d'un espace exterieur a charger */ |
---|
330 | char YioSep[STRSIZE20]="\n";/* chaine de caratères pour la separation de token dans les fct d'io (modifiable pas set_sep) */ |
---|
331 | int Ydmod; /* dimension du module en cours*/ |
---|
332 | short Ytestad_module; /* flag de test de l'adjoint par module */ |
---|
333 | double YLTRes, YAdRes; /* resultat des tests de l'adjoint par module */ |
---|
334 | double Yerrelmax; /* une erreur relative max */ |
---|
335 | int Ynbko, Ymaxko; /* nombre de ko et le max autorise */ |
---|
336 | double Ypzedi; /* un parametre de zero informatique */ |
---|
337 | enum YWardKind Ycurward; /* type du run courant de trajectoire (pour hidjack) */ |
---|
338 | int YNbBasicIntL = 1; /* nombre de boucle interne a basic_it, modifiable avec set_nb_basic_intern_loop (default=1) */ |
---|
339 | int YItBasicIntL; /* iteration de la boucle interne a basic_it */ |
---|
340 | |
---|
341 | /* multi-spatio-tempo : ---------*/ |
---|
342 | |
---|
343 | /* variables globales a gerer par changement de contexte ! */ |
---|
344 | float Ybegintime = 0.0; /* temps initial du modele global */ |
---|
345 | float Yendtime = 0.0; /* temps final du modele global */ |
---|
346 | #define MYMAXREEL 3.40282347e+38 |
---|
347 | int YidTraj; /* indice de la trajectoire courante*/ |
---|
348 | int YNBUPTIME, YNBALLTIME; |
---|
349 | int YA1, YA2, YA3; /* taille des axes de l'espace courant */ |
---|
350 | #define Yt YTemps /* temps courant de la trajectoire courante (toptime) */ |
---|
351 | int Ytps; /* variable pour la gestion du temps entre trajectoire */ |
---|
352 | |
---|
353 | // For the parallelization: all these global variables should be privates. |
---|
354 | // Yi, Yj, Yk is for the correct run of the computation loops. |
---|
355 | // YY is for the OpenMP bug that doesn't allow to call a function in a parallel region and mantain the thread value |
---|
356 | // of a global private variable. The value in the called function is not what should be. |
---|
357 | // Ytps is for the special case of multi_t so when two modules connected have different trajectory and |
---|
358 | // the should be translated with Ytttt_pdt() function. |
---|
359 | //#ifdef YO_PARALLEL |
---|
360 | #ifdef _OPENMP |
---|
361 | #pragma omp threadprivate(Yi, Yj, Yk, YY, Ytps) |
---|
362 | #endif |
---|
363 | |
---|
364 | |
---|
365 | |
---|
366 | /* certaines variables generees */ |
---|
367 | extern struct Yst_modul YTabMod[]; |
---|
368 | |
---|
369 | //============================================================================= |
---|
370 | // OU DOIS-JE METTRE Ygetval ??? |
---|
371 | //============================================================================= |
---|
372 | double Ygetval(char *codop) //creed pour dx random des fonctions de test |
---|
373 | { double val; //utilised par ... |
---|
374 | if (codop[0]=='R') /* rand in [-1, 1] * coef */ |
---|
375 | { //return(((double)rand()/RAND_MAX)*2-1); |
---|
376 | val = ((double)rand()/RAND_MAX)*2-1; |
---|
377 | if (strlen(codop)>1) |
---|
378 | { //si R est suivi d'autres caracteres, ce doit etre un coef a appliquer |
---|
379 | //sur le random (ex: si codop = "R0.15" alors val = val * 0.15 |
---|
380 | val = val * atof(codop+1); |
---|
381 | } |
---|
382 | return(val); |
---|
383 | } |
---|
384 | else |
---|
385 | return (0.0); |
---|
386 | } |
---|
387 | //============================================================================= |
---|
388 | void Ycreate_errnew() |
---|
389 | { printf("error on space allocation with new when crteating module; see your YAO administrator\n"); |
---|
390 | exit(-9); |
---|
391 | } |
---|
392 | //============================================================================= |
---|
393 | |
---|
394 | |
---|
395 | |
---|
396 | //============================================================================= |
---|
397 | // TOOL BOX 1 |
---|
398 | //============================================================================= |
---|
399 | |
---|
400 | //============================================================================= |
---|
401 | // deux fonctions inline MIN et MAX |
---|
402 | // Ymin : renvoie le MIN de 2 valeurs (dans le type de la 1ère) |
---|
403 | template<class TypVala, class TypValb>inline TypVala Ymin (TypVala a, TypValb b) |
---|
404 | { return (a<b)? a:b; |
---|
405 | } |
---|
406 | //----------------------------------------------------------------------------- |
---|
407 | // Ymax : renvoie le MAX de 2 valeurs (dans le type de la 1ère) |
---|
408 | template<class TypVala, class TypValb> TypVala Ymax (TypVala a, TypValb b) |
---|
409 | { return (a>b)? a:b; |
---|
410 | } |
---|
411 | |
---|
412 | //============================================================================= |
---|
413 | /* Ypr_tabr: affiche les elements d'un tableau de reels */ |
---|
414 | template<class TypReal>void Ypr_tabr (char *str, TypReal TabReal[], int nbelt, char *sep) |
---|
415 | { printf("%s", str); |
---|
416 | for(int i=0; i<nbelt;++i) printf("[%i] = % -23.15e%s", i, TabReal[i], sep); |
---|
417 | } |
---|
418 | //============================================================================= |
---|
419 | |
---|
420 | //============================================================================= |
---|
421 | // some singles lineare algebra functions |
---|
422 | /* Yprosca: produit scalaire (de 2 vecteurs) */ |
---|
423 | template<class TypReel>double Yprosca (TypReel a[], TypReel b[], int sz) |
---|
424 | { int i; |
---|
425 | double res=0.0, cal; |
---|
426 | //for (i=0; i<sz; ++i) res += a[i]*b[i]; |
---|
427 | for (i=0; i<sz; ++i) |
---|
428 | { cal = a[i]*b[i]; res += cal; |
---|
429 | //if (Ysysdbg) printf("Yprosca: % -23.15e <+= % -23.15e * % -23.15e \n", res, a[i], b[i]); |
---|
430 | } |
---|
431 | return(res); |
---|
432 | } |
---|
433 | |
---|
434 | //============================================================================= |
---|
435 | // some singles statiticals functions |
---|
436 | /* Ystat_moy: moyenne d'un tableau de valeurs */ |
---|
437 | template<class TypVal, class TypRes>void Ystat_moy (TypVal TabVal[], int nbelt, TypRes *moy) |
---|
438 | { *moy=0.0; |
---|
439 | for(int i=0; i<nbelt;++i) *moy += TabVal[i]; |
---|
440 | *moy = *moy/nbelt; |
---|
441 | } |
---|
442 | /* --------------------------------------------------------------------------*/ |
---|
443 | /* Ystat_mv: moyenne et variance d'un tableau de valeurs */ |
---|
444 | template<class TypVal, class TypRes>void Ystat_mv (TypVal TabVal[], int nbelt, TypRes *moy, TypRes *var) |
---|
445 | { |
---|
446 | /* moyenne */ |
---|
447 | Ystat_moy(TabVal, nbelt, moy); |
---|
448 | |
---|
449 | /* variance */ |
---|
450 | *var=0.0; |
---|
451 | for(int i=0; i<nbelt;++i) *var += pow((TabVal[i]-*moy),2); |
---|
452 | *var = *var/nbelt; |
---|
453 | } |
---|
454 | /* --------------------------------------------------------------------------*/ |
---|
455 | /* Ystat_norm1: normalisation d'un tableau de valeurs */ |
---|
456 | template<class TypVal, class TypRes>void Ystat_norm1 (TypVal TabVal[], int nbelt, TypRes moy, TypRes sig) |
---|
457 | { |
---|
458 | for(int i=0; i<nbelt;++i) TabVal[i] = (TabVal[i]-moy)/sig; |
---|
459 | } |
---|
460 | /* --------------------------------------------------------------------------*/ |
---|
461 | /* Ystat_denorm1: de-normalisation d'un tableau de valeurs */ |
---|
462 | template<class TypVal, class TypRes>void Ystat_denorm1 (TypVal TabVal[], int nbelt, TypRes moy, TypRes sig) |
---|
463 | { |
---|
464 | for(int i=0; i<nbelt;++i) TabVal[i] = TabVal[i]*sig + moy; |
---|
465 | } |
---|
466 | |
---|
467 | /*===========================================================================*/ |
---|
468 | /*===========================================================================*/ |
---|
469 | |
---|
470 | //FOR DEBUG |
---|
471 | //void Ytrobs (int indic, char *nmmod, int nout, int iaxe, int jaxe, int kaxe, int pdt, YREAL *vobs, YREAL *qtea) |
---|
472 | void Ytrobs (int indic, char *nmmod, int nout, int iaxe, int jaxe, int kaxe, int pdt, double *vobs, double *qtea) |
---|
473 | { printf("%i %s %i %i %i %i t=%i %e %e \n",indic, nmmod, nout, iaxe, jaxe, kaxe, pdt, *vobs, *qtea); |
---|
474 | } |
---|
475 | //void Ywlobs(void(*fct)(int i1, char *str, int i2, int i3, int i4, int i5, int i6, YREAL *r1, YREAL *r2), int indic); |
---|
476 | void Ywlobs(void(*fct)(int i1, char *str, int i2, int i3, int i4, int i5, int i6, double *r1, double *r2), int indic); |
---|
477 | |
---|
478 | |
---|
479 | //============================================================================= |
---|
480 | // GENERIC MODUL OBJECT FUNCTION |
---|
481 | //============================================================================= |
---|
482 | template <class TypVal, class TypClass> int Ysetstate_generic (char *nmmod, TypVal val, TypClass *pc[]) |
---|
483 | { int imod, nbs, axi, axj, axk; |
---|
484 | imod = Yimod(nmmod); |
---|
485 | nbs = YTabMod[imod].nb_stout; |
---|
486 | axi = YTabMod[imod].axi; |
---|
487 | axj = YTabMod[imod].axj; |
---|
488 | axk = YTabMod[imod].axk; |
---|
489 | |
---|
490 | //cas non tempo |
---|
491 | if (axk>0) |
---|
492 | { //cas 3D |
---|
493 | for (int Yw1=0; Yw1<axi; ++Yw1){ |
---|
494 | for (int Yw2=0; Yw2<axj; ++Yw2){ |
---|
495 | for (int Yw3=0; Yw3<axk; ++Yw3){ |
---|
496 | for (int Yws=0; Yws<nbs; ++Yws){ |
---|
497 | pc[Yw1*axj*axk+Yw2*axk+Yw3]->Ystate[Yws] = val;}}}} |
---|
498 | } |
---|
499 | else if (axj>0) |
---|
500 | { //cas 2D |
---|
501 | for (int Yw1=0; Yw1<axi; ++Yw1){ |
---|
502 | for (int Yw2=0; Yw2<axj; ++Yw2){ |
---|
503 | for (int Yws=0; Yws<nbs; ++Yws){ |
---|
504 | pc[Yw1*axj+Yw2]->Ystate[Yws] = val;}}} |
---|
505 | } |
---|
506 | else |
---|
507 | { //cas 1D |
---|
508 | for (int Yw1=0; Yw1<axi; ++Yw1){ |
---|
509 | for (int Yws=0; Yws<nbs; ++Yws){ |
---|
510 | pc[Yw1]->Ystate[Yws] = val;}} |
---|
511 | } |
---|
512 | return(1); //? |
---|
513 | } |
---|
514 | //============================================================================= |
---|
515 | template <class TypVal, class TypClass> int Ysetstatet_generic (char *nmmod, TypVal val, TypClass *pc[]) |
---|
516 | { int imod, nbs, axi, axj, axk, axt; |
---|
517 | imod = Yimod(nmmod); |
---|
518 | nbs = YTabMod[imod].nb_stout; |
---|
519 | axi = YTabMod[imod].axi; |
---|
520 | axj = YTabMod[imod].axj; |
---|
521 | axk = YTabMod[imod].axk; |
---|
522 | axt = YTabMod[imod].nb_time; |
---|
523 | |
---|
524 | //cas tempo |
---|
525 | if (axk>0) |
---|
526 | { //cas 3D |
---|
527 | for (int Yw1=0; Yw1<axi; ++Yw1){ |
---|
528 | for (int Yw2=0; Yw2<axj; ++Yw2){ |
---|
529 | for (int Yw3=0; Yw3<axk; ++Yw3){ |
---|
530 | for (int Ywt=0; Ywt<axt; ++Ywt){ |
---|
531 | for (int Yws=0; Yws<nbs; ++Yws){ |
---|
532 | //pc[Yw1][Yw2][3]->Ystate[Ywt][Yws] = val;}}}}} |
---|
533 | pc[Yw1*axj*axk+Yw2*axk+Yw3]->Ystate[Ywt][Yws] = val;}}}}} |
---|
534 | } |
---|
535 | else if (axj>0) |
---|
536 | { //cas 2D |
---|
537 | for (int Yw1=0; Yw1<axi; ++Yw1){ |
---|
538 | for (int Yw2=0; Yw2<axj; ++Yw2){ |
---|
539 | for (int Ywt=0; Ywt<axt; ++Ywt){ |
---|
540 | for (int Yws=0; Yws<nbs; ++Yws){ |
---|
541 | //pc[Yw1][Yw2]->Ystate[Ywt][Yws] = val;}}}} |
---|
542 | pc[Yw1*axj+Yw2]->Ystate[Ywt][Yws] = val;}}}} |
---|
543 | } |
---|
544 | else |
---|
545 | { //cas 1D |
---|
546 | for (int Yw1=0; Yw1<axi; ++Yw1){ |
---|
547 | for (int Ywt=0; Ywt<axt; ++Ywt){ |
---|
548 | for (int Yws=0; Yws<nbs; ++Yws){ |
---|
549 | pc[Yw1]->Ystate[Ywt][Yws] = val;}}} |
---|
550 | } |
---|
551 | return(1); //? |
---|
552 | } |
---|
553 | //============================================================================= |
---|
554 | //============================================================================= |
---|
555 | |
---|
556 | |
---|
557 | |
---|
558 | /*///////////////////////////////////////////////////////////////////////////*/ |
---|
559 | /* L'INCLUDE DE L'APPLI GENERATRICE et de son nom */ |
---|
560 | #include "Y1floater.h" |
---|
561 | #include "Y2floater.h" |
---|
562 | #define PRJNAME "floater" |
---|
563 | #define VERREF "YaoI V.9 01.11.2008 (release 01.11.2008) " |
---|
564 | |
---|
565 | //============================================================================= |
---|
566 | /* //////////////////////////////////////////////////////////////////////////// |
---|
567 | // DES FONCTIONS DE SERVICES (boite a outils) // |
---|
568 | //////////////////////////////////////////////////////////////////////////// */ |
---|
569 | |
---|
570 | /*===========================================================================*/ |
---|
571 | /* Yvsmat: multiplication d'une Sous-MATrice par un Vecteur */ |
---|
572 | /* --------------------------------------------------------------------------*/ |
---|
573 | /*template<class TypReel>void oldYvsmat (int lig, int col, int max_col, TypReel vout[], TypReel Mat[], TypReel vin[]) |
---|
574 | { int l, c, lmc; |
---|
575 | TypReel cal; |
---|
576 | for (l=0; l<lig; ++l) |
---|
577 | { vout[l] = 0.0; |
---|
578 | lmc=l*max_col; |
---|
579 | for (c=0; c<col; ++c) |
---|
580 | { //vout[l] += vin[c]* Mat[lmc+c]; |
---|
581 | cal = vin[c] * Mat[lmc+c]; vout[l] += cal; |
---|
582 | } |
---|
583 | } |
---|
584 | }*/ |
---|
585 | template<class TypReel> void Yvsmat (int lig, int col, int max_col, TypReel vout[], TypReel Mat[], TypReel vin[]) |
---|
586 | { int l, c; |
---|
587 | TypReel cal, *M; |
---|
588 | for (l=0; l<lig; ++l) |
---|
589 | { vout[l] = 0.0; |
---|
590 | M=&Mat[l*max_col]; |
---|
591 | for (c=0; c<col; ++c) |
---|
592 | { cal = vin[c] * M[c]; |
---|
593 | vout[l] += cal; |
---|
594 | } |
---|
595 | } |
---|
596 | } |
---|
597 | /*===========================================================================*/ |
---|
598 | /* Yvsmatt: multiplication d'une Sous-MATrice Transposee par un Vecteur */ |
---|
599 | /* --------------------------------------------------------------------------*/ |
---|
600 | /*template<class TypReel>void oldYvsmatt (int lig, int col, int max_col, TypReel vin[], TypReel Mat[], TypReel vout[]) |
---|
601 | { int l, c; |
---|
602 | TypReel cal; |
---|
603 | for (c=0; c<col; ++c) |
---|
604 | { vout[c] = 0.0; |
---|
605 | for (l=0; l<lig; ++l) |
---|
606 | { //vout[c] += vin[l]* Mat[(l*max_col)+c]; |
---|
607 | cal = vin[l]* Mat[(l*max_col)+c]; vout[c] += cal; |
---|
608 | //printf("xxxxxxxx> %e * %e +=> %e \n", vin[l], Mat[(l*max_col)+c], vout[c]); |
---|
609 | } |
---|
610 | } |
---|
611 | //if (Yi==0 && Yj==0 && Yk==0 && YTemps==2) |
---|
612 | // printf ("Yvmat: vin[%i]=%f Mat(%i,%i)=%f\n", l, vin[l], l, c, Mat[(l*max_col)+c]); |
---|
613 | }*/ |
---|
614 | template<class TypReel> void Yvsmatt (int lig, int col, int max_col, TypReel vin[], TypReel Mat[], TypReel vout[]) |
---|
615 | { int l, c; |
---|
616 | TypReel cal, *M; |
---|
617 | memset(vout,0,col*sizeof(TypReel)); |
---|
618 | for (l=0; l<lig; ++l) |
---|
619 | { M=&Mat[l*max_col]; |
---|
620 | for (c=0; c<col; ++c) |
---|
621 | { cal = vin[l] * M[c]; |
---|
622 | vout[c] += cal; |
---|
623 | } |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | // Juste pour le parallelisme: on est en train ici d'essayer de paralleliser la moltiplication Yvsmatt. |
---|
628 | // Cette solution n'est pas optimelle mais ça nous permet déjà de voir que le nested parallelism ne marche pas dans ce cas. |
---|
629 | // On fait pas assez de calcule dans cette fonction pour justifier l'overhead du au parallelisme. |
---|
630 | // On laisse cette fonction pour futures études. |
---|
631 | // Les amolioration à faire c'est des gérer mieu toutes les variables et trouver un moyen pour ne pas faire le dernier for: lastprivate ou du genre. |
---|
632 | /*template<class TypReel> void YvsmattLuigi (int lig, int col, int max_col, TypReel vin[], TypReel Mat[], TypReel vout[]) |
---|
633 | { |
---|
634 | TypReel v[col]; |
---|
635 | memset(vout,0,col*sizeof(TypReel)); |
---|
636 | memset(v,0,col*sizeof(TypReel)); |
---|
637 | #pragma omp parallel for |
---|
638 | //shared(v,col,lig,max_col, Mat, vin) private(vout) default(none) num_threads(1) |
---|
639 | for(int c=0; c<col; ++c){ |
---|
640 | TypReel *M; |
---|
641 | TypReel cal=0; |
---|
642 | M=&Mat[c]; |
---|
643 | for(int l=0; l<lig; ++l) |
---|
644 | cal += vin[l] * M[l*max_col]; |
---|
645 | //vout[c] += vin[l] * M[l*max_col]; |
---|
646 | v[c] = cal; |
---|
647 | } |
---|
648 | for(int c=0; c<col; ++c) |
---|
649 | vout[c] = v[c]; |
---|
650 | } |
---|
651 | */ |
---|
652 | |
---|
653 | /*===========================================================================*/ |
---|
654 | /* Ymxmat: multiplication de Matrices : X = A * B */ |
---|
655 | /* --------------------------------------------------------------------------*/ |
---|
656 | template<class TypValA, class TypValB, class TypValX>void Ymxmat (int la, int cl, int cb, TypValA MatA[], TypValB MatB[], TypValX MatX[]) |
---|
657 | { //la = nbre de lignes de A |
---|
658 | //cl = nombre de colonnes de A = nombre de lignes de B |
---|
659 | //cb = nombre de colonnes de B |
---|
660 | int l, n, c; |
---|
661 | int lxcl; |
---|
662 | TypValX cal; |
---|
663 | for (c=0; c<cb; ++c) |
---|
664 | { for (l=0; l<la; ++l) |
---|
665 | { cal = (TypValX)0.0; |
---|
666 | lxcl = l*cl; |
---|
667 | for (n=0; n<cl; ++n) |
---|
668 | { cal += MatA[lxcl+n] * MatB[c+n*cb]; |
---|
669 | } |
---|
670 | MatX[l*cb+c] = cal; |
---|
671 | } |
---|
672 | } |
---|
673 | } |
---|
674 | /*===========================================================================*/ |
---|
675 | /* Calcul de derivees complexes */ |
---|
676 | /*---------------------------------------------------------------------------*/ |
---|
677 | template<class TypReal> void Ycx_jac(complex<TypReal> derivee, int j, int i) |
---|
678 | { /* Peut etre utilised si le module n'a que des complexes |
---|
679 | en entrees-sorties. Les indices j, i a passer doivent |
---|
680 | correspondre a un indicage sur les complexes */ |
---|
681 | int l, c; |
---|
682 | l=j*2-2; c=i*2-2; |
---|
683 | Yjac[l ][c ] = real(derivee); |
---|
684 | Yjac[l+1][c ] = imag(derivee); |
---|
685 | Yjac[l ][c+1] = -Yjac[l+1][c ]; |
---|
686 | Yjac[l+1][c+1] = Yjac[l ][c ]; |
---|
687 | } |
---|
688 | //----------------------------------------------------------------------------- |
---|
689 | template<class TypReal> void Ycxr_jac(complex<TypReal> derivee, int l, int c) |
---|
690 | { /* Peut etre utilised lorsque le module melange reels et |
---|
691 | complexes en entrees-sorties. Les indices l, c a passer doivent |
---|
692 | correspondre a un indicage sur les reels */ |
---|
693 | Yjac[l-1][c-1] = real(derivee); |
---|
694 | Yjac[l ][c-1] = imag(derivee); |
---|
695 | Yjac[l-1][c ] = -Yjac[l ][c-1]; |
---|
696 | Yjac[l ][c ] = Yjac[l-1][c-1]; |
---|
697 | } |
---|
698 | |
---|
699 | /*===========================================================================*/ |
---|
700 | /* Inversion d'une matrice (carree) tri-diagonale |
---|
701 | input: mat_dim : dimension des vecteur et de la matrice |
---|
702 | inf : vecteur inferieur |
---|
703 | diag : vecteur diagonal |
---|
704 | sup : vecteur superieur |
---|
705 | output: mat_inv : la matrice inverse |
---|
706 | code retour : 0=Ok, 1=Ko */ |
---|
707 | /* ------------------------------------------------------------------------- */ |
---|
708 | template<class TypVal>int Yinv_tri_mat (int mat_dim, TypVal inf[], TypVal diag[], TypVal sup[], TypVal mat_inv[]) |
---|
709 | { /* Construction de la matrice inverse */ |
---|
710 | int i, j; |
---|
711 | TypVal *vect, *prod; //TypVal vect[mat_dim], prod[mat_dim]; |
---|
712 | vect = (TypVal*) calloc(mat_dim, sizeof(TypVal)); |
---|
713 | prod = (TypVal*) calloc(mat_dim, sizeof(TypVal)); |
---|
714 | |
---|
715 | for (i = 0; i < mat_dim; i++) |
---|
716 | { |
---|
717 | for (j = 0; j < mat_dim; j++) |
---|
718 | vect[j] = (TypVal)0; |
---|
719 | vect[i] = (TypVal)1; |
---|
720 | |
---|
721 | if (!Yinv_tri_vect (mat_dim, vect, prod, inf, diag, sup)) |
---|
722 | { cout << "~~~~~>Yinv_tri_vect: erreur 1: ????????????????????????\n"; |
---|
723 | return 0; /* csr: avant y'avait que if DEBUG_... */ |
---|
724 | } |
---|
725 | |
---|
726 | for (j = 0; j < mat_dim; j++) |
---|
727 | mat_inv[(j*mat_dim)+i] = prod[j]; |
---|
728 | } |
---|
729 | free(vect); free(prod); |
---|
730 | return 1; |
---|
731 | } |
---|
732 | /* -------------------- Inversion matrice (suite) !? ----------------------- */ |
---|
733 | template<class TypVal>int Yinv_tri_vect (int mat_dim, TypVal vect[], TypVal prod[], TypVal inf[], TypVal diag[], TypVal sup[]) |
---|
734 | { int i; |
---|
735 | TypVal bet; |
---|
736 | TypVal *R; //(TypVal) R[mat_dim]; |
---|
737 | R = (TypVal*) calloc(mat_dim, sizeof(TypVal)); |
---|
738 | |
---|
739 | if (diag[0] == (TypVal)0) |
---|
740 | { cout << "~~~~~>Yinv_tri_vect: erreur 1: ???????????????????????????\n"; |
---|
741 | return 0; |
---|
742 | } |
---|
743 | prod[0] = vect[0] / (bet = diag[0]); |
---|
744 | |
---|
745 | for (i = 1; i < mat_dim; i++) |
---|
746 | { |
---|
747 | R[i] = sup[i - 1] / bet; |
---|
748 | bet = diag[i] - inf[i] * R[i]; |
---|
749 | |
---|
750 | if (bet == (TypVal)0.0) |
---|
751 | { cout << "~~~~~>Yinv_tri_vect: erreur 2: ???????????????????????????\n"; |
---|
752 | return 0; |
---|
753 | } |
---|
754 | prod[i] = (vect[i] - inf[i] * prod[i - 1]) / bet; |
---|
755 | } |
---|
756 | |
---|
757 | for (i = (mat_dim - 2); i >= 0; i--) |
---|
758 | { prod[i] -= R[i + 1] * prod[i + 1]; |
---|
759 | } |
---|
760 | free(R); |
---|
761 | return 1; |
---|
762 | } |
---|
763 | |
---|
764 | |
---|
765 | /* //////////////////////////////////////////////////////////////////////////// |
---|
766 | // LES FONCTIONS STANDARS DE YAO // |
---|
767 | //////////////////////////////////////////////////////////////////////////// */ |
---|
768 | /* ---------------------------------------------------------------------------- |
---|
769 | //================== Help me if you can I'm feeling bad ==================== */ |
---|
770 | void Yhelp(char lang) |
---|
771 | { printf("\n Not include: user_fct, Not yet include : Yauto_fct\n"); |
---|
772 | |
---|
773 | if (lang=='f') /* ..................... FRANCAIS ..........................*/ |
---|
774 | { printf (" Abreviations: file: fichier; str: chaine de caractère; modname: nom de module\n"); |
---|
775 | printf (" nbpdt: nombre de pas de temps val: valeur entiere real: un reel\n"); |
---|
776 | printf (" nout: n° de sortie\n"); |
---|
777 | printf (" (I) (resp (B)): valable seulement en mode Interactif (resp Batch)\n"); |
---|
778 | printf (" [0 ou 1 au choix] {1 seul choix obligatoire}\n"); |
---|
779 | printf (" la saisie soit en minuscule soit en majuscule exclusivement est acceptee\n"); |
---|
780 | printf ("-----------------------------------------------------------------------------\n"); |
---|
781 | //divers |
---|
782 | printf (" help | aide|? : [e | f]: l'aide que vous venez d'afficher\n"); |
---|
783 | printf (" exit |quit|bye: pour en finir avec Yao \n"); |
---|
784 | printf (" ! : str: permet de passer la commande systeme contenue dans str\n"); |
---|
785 | printf (" echo : {on | off}: active ou pas l'affichage de la commande (B)\n"); |
---|
786 | printf (" set_prompt : str: pour avoir un prompt à son goût\n"); |
---|
787 | printf (" pause : marque une pause: se met en attente d'un RC pour continuer\n"); |
---|
788 | printf (" ltraj : liste des trajectoires avec certaines informations\n"); |
---|
789 | printf (" straj : schema des trajectoires (valide si offtime et dtime sont des entiers)\n"); |
---|
790 | printf (" pdt2pdt : fromtrajname steptime totrajname : (sous reserve) donne l'equivalence du\n"); |
---|
791 | printf (" : steptime de fromtrajname pour la trajectoire totrajname\n"); |
---|
792 | printf (" activ|unactiv : {trajname ,typetraj} [{trajname ,typetraj}[...]] [{only, less}]: activation\n"); |
---|
793 | printf (" : ou neutralisation de trajectoire (cf doc)\n"); |
---|
794 | printf (" lspace : liste des espaces avec certaines informations\n"); |
---|
795 | printf (" nmod : modname: donne le numero du module modname\n"); |
---|
796 | printf (" lmod : liste des modules avec certaines informations\n"); |
---|
797 | printf (" lval : liste des valeurs prédéfinies \n"); |
---|
798 | printf (" load_inst : file: execute les instructions contenues dans file\n"); |
---|
799 | printf (" goto : label: pour sauter les instructions suivantes jusqu'a la chaine 'label'\n"); |
---|
800 | //pour preparer un run |
---|
801 | printf (" set_begintime : val: affecte la valeur val au temps initial du modele global\n"); |
---|
802 | printf (" set_modeltime : 0: positionne toutes les trajectoires sur leur temps initial\n"); |
---|
803 | printf (" set_toptime : trajname val: affecte le temps unitaire courant de la trajectoire a val\n"); |
---|
804 | printf (" set_dtime : trajname val: affecte la valeur val au dt de la trajectoire\n"); |
---|
805 | printf (" set_offtime : trajname val: affecte val au decalage temporel de la trajectoire\n"); |
---|
806 | printf (" print_cost : [on | off |]: soit affiche le cout (YTotalCost) soit met a ON, OFF ou LAST\n"); |
---|
807 | printf (" le flag qui permet de l'afficher au cours (ou a la fin avec LAST) des iterations \n"); |
---|
808 | printf (" print_time : [on | off]: soit affiche le top de toutes les trajectoires, soit switch\n"); |
---|
809 | printf (" : le flag qui permet l'affichage du temps au cours d'itérations\n"); |
---|
810 | printf (" cost : {lms real | appli}: choix de la fonction de cout, et définition d'un\n"); |
---|
811 | printf (" coef pour la calculer qui s'applique à tous les modules, mais ... \n"); |
---|
812 | printf (" set_scoef : modname coef: positionne un coef pour modname en lieu et place de\n"); |
---|
813 | printf (" celui défini par cost\n"); |
---|
814 | printf (" set_bcoef : modname coef: positionne un coef pour modname pour le calcul du cout\n"); |
---|
815 | printf (" sur les termes d'ébauche\n"); |
---|
816 | printf (" set_pcoef : modname coef: positionne un coef ou %cage pour modname: utilisation :\n",'%'); |
---|
817 | printf (" 1: delta pour l'incremental; 2: ...\n"); |
---|
818 | printf (" adjust : {std | appli}: choix de la formule d'ajustement de ou des variables\n"); |
---|
819 | printf (" à minimiser\n"); |
---|
820 | printf (" testad : pdx [{-1, tol}] maxcase [zinfo]]: test de l'adjoint global [ou local]:\n"); |
---|
821 | printf (" < M'(Xo).dx, dy > = < dx, M*(Xo).dy >\n"); |
---|
822 | printf (" testdf : i j k codop [%c]pdx ptol [modname-ko]: fonction de vérification de la\n", '%'); |
---|
823 | printf (" programmation des dérivées au point ijk, au temps t=1,\n"); |
---|
824 | printf (" codop (reel, 0, N, R, r : cf doc) determine les valeurs des entrées des modules,\n"); |
---|
825 | printf (" pdx=une perturbation (en %ctage si %c) de x, et ptol une tolérance en %c.\n", '%', '%', '%'); |
---|
826 | printf (" testlt : pdx alpha fdec nbloop [modop]: test du lineaire tangent, et \n"); |
---|
827 | printf (" testof test de la fonction objective (cf doc...) avec dx = Xo*pdx, alpha : \n"); |
---|
828 | printf (" parametre de tendance, fdec : facteur de decroissance de alpha, nbloop :\n"); |
---|
829 | printf (" nombre de boucles de decroissance, et modop : un mode operatoire 0 ou 1\n"); |
---|
830 | printf (" set_iosep : chaine de caracteres: a utiliser comme separateur de token dans les fonction d'i/o\n"); |
---|
831 | printf (" outoobs : modname nout liste_pdt: Utilisation des états commes observations\n"); |
---|
832 | printf (" loadobs : cf paramètres dans la doc: Chargement d'observations à partir d'un fichier\n"); |
---|
833 | printf (" loadstate : cf paramètres dans la doc: Chargement d'états à partir d'un fichier\n"); |
---|
834 | printf (" savestate : objname nout oaxis t[%c] {A,B} {0,1,2,3} [filename]: sauvegarde de modules selon\n",'%'); |
---|
835 | printf (" objname (cf doc) pour la (ou toutes les (si 0)) sortie selon l'ordre oaxis des\n"); |
---|
836 | printf (" axes au (ou pour tous les si 0) pas de temps t (ou modulo(t)), en Ascii\n"); |
---|
837 | printf (" ou Binaire. puis vient: 0=>que la valeur, 1=>+les axes, 2=>+le temps, 3=1+2.\n"); |
---|
838 | printf (" les sorties se font dans filename ou à défaut, sur la sortie standard (écran)\n"); |
---|
839 | printf (" outoebx : modname nout liste_pdtI: Utilisation des états initiaux comme d'ebauche\n"); |
---|
840 | printf (" lobs : [trajname]: liste des observations limitee a trajname si precise\n"); |
---|
841 | printf (" sampleof/i : modulx infx supx dx moduly infy supy dy outfile: echantillonage de la fonction\n"); |
---|
842 | printf (" de cout pour une ou deux variables\n"); |
---|
843 | printf (" nnet : netname: donne le numero du réseau de neurones netname\n"); |
---|
844 | printf (" lnet : liste des réseaux de neurones avec certaines informations\n"); |
---|
845 | printf (" netload : netname filename : chargement du réseau netname avec le fichier filename\n"); |
---|
846 | printf (" setn_activ : netname activation : choix de la fonction d'activation pour le réseau\n"); |
---|
847 | printf (" netname. activaltion=SIGSIG => que sigmoide; avec SIGLIN les sorties\n"); |
---|
848 | printf (" sont linéaires\n"); |
---|
849 | printf (" setn_plin : dmin dmax th: positionne les parametres de la fonction\n"); |
---|
850 | printf (" lineair(O_NETWARD)\n"); |
---|
851 | printf (" setn_psig : mx dmin scale offset: positionne les paramètres de la\n"); |
---|
852 | printf (" fonction sigmoïde(O_NETWARD)\n"); |
---|
853 | printf (" forward : nbpdt: effectue une passe avant sur nbpdt pas de temps\n"); |
---|
854 | printf (" backward : nbpdt: effectue une passe arrière sur nbpdt pas de temps\n"); |
---|
855 | printf (" set_nbiter : val: positionne le nombre d'itérations (YNbIter) à effectuer\n"); |
---|
856 | printf (" par les fonctions run\n"); |
---|
857 | printf (" set_nbextl : val: positionne le nombre de boucles externes (YNbExtL) à effectuer\n"); |
---|
858 | printf (" par les algorithmes incrementaux\n"); |
---|
859 | printf (" run : Lance YNbIter fois l'itération 'de base': passe avant, calcul\n"); |
---|
860 | printf (" du cout, passe arrière, ajustement des variables\n"); |
---|
861 | printf (" runi : version incremental de run m avec YNbExtL boucles externes\n"); |
---|
862 | #ifdef YO_M1QN3 |
---|
863 | //pour m1qn3 (a aussi besoin de set_nbiter; le 1er mot se termine par un m) |
---|
864 | printf ("\n setm_io : val: Ces instructions \n"); |
---|
865 | printf (" setm_impres : val: concernent M1QN3.\n"); |
---|
866 | printf (" setm_mode : val: Il est préférable\n"); |
---|
867 | printf (" setm_nsim : val: de se repporter\n"); |
---|
868 | printf (" setm_dxmin : [real]: directement au chapitre\n"); |
---|
869 | printf (" setm_epsg : real: qui le concerne\n"); |
---|
870 | printf (" setm_ddf1 : real: dans la\n"); |
---|
871 | printf (" runm et runim : documen-\n\n"); |
---|
872 | printf (" runm2 & runim2: tation\n\n"); |
---|
873 | #endif |
---|
874 | //instructions des Modules |
---|
875 | printf (" setstate : modname real: affecte la valeur real à tous les états de toutes les\n"); |
---|
876 | printf (" occurences (ijkt) du modul modname\n"); |
---|
877 | printf (" setstate_all : real: affecte la valeur real à tous les états de tous les modules\n"); |
---|
878 | printf (" setepsi : modname real: affecte la valeur real à tous les epsilons de toutes les\n"); |
---|
879 | printf (" occurences (ijk) du modul modname\n"); |
---|
880 | printf (" setepsi_all : real: affecte la valeur real à tous les epsilons de tous les modules target\n"); |
---|
881 | printf ("-----------------------------------------------------------------------------\n"); |
---|
882 | } |
---|
883 | else if (lang=='e') /* ................... ANGLAIS ........................*/ |
---|
884 | { printf ("Abreviations: str: string; modname: modul name nstept: number of time step\n"); |
---|
885 | printf (" (I) (resp (B)): only for Interactive (resp Batch) mode\n"); |
---|
886 | printf (" nout: n° de out\n"); |
---|
887 | printf (" val: integer real: real\n"); |
---|
888 | printf (" [0 or 1 to choose] {must only one choice}\n"); |
---|
889 | printf (" both upper or lower case input is availuable but not mixed\n"); |
---|
890 | printf ("---------------------------------------------------------------------------\n"); |
---|
891 | //divers |
---|
892 | printf ("help | aide|? : [e | f]: ###\n"); |
---|
893 | printf ("exit |quit|bye: to get aways from Yao\n"); |
---|
894 | printf ("! : str: ### \n"); |
---|
895 | printf ("echo : {on | off}: ### n"); |
---|
896 | printf ("set_prompt : str: ### \n"); |
---|
897 | printf ("pause : ###\n"); |
---|
898 | printf ("ltraj : ###\n"); |
---|
899 | printf ("straj : ###\n"); |
---|
900 | printf ("pdt2pdt : fromtrajname steptime totrajname: ###\n"); |
---|
901 | printf ("activ|unactiv : {trajname ,typetraj} [{trajname ,typetraj}[...]] [{only, less}]: ###\n"); |
---|
902 | printf ("lspace : ###\n"); |
---|
903 | printf ("nmod : modname: ###\n"); |
---|
904 | printf ("lmod : ###\n"); |
---|
905 | printf ("lval : ###\n"); |
---|
906 | printf ("load_inst : file: ###\n"); |
---|
907 | printf ("goto : label: ###\n"); |
---|
908 | //pour preparer un run |
---|
909 | printf ("set_begintime : val: ###\n"); |
---|
910 | printf ("set_modeltime : 0: ###\n"); |
---|
911 | printf ("set_toptime : trajname val: ###\n"); |
---|
912 | printf ("set_dtime : trajname val: ###\n"); |
---|
913 | printf ("set_offtime : trajname val: ###\n"); |
---|
914 | printf ("print_cost : [on | off | last]: ###\n"); |
---|
915 | printf ("print_time : [on | off]: ###\n"); |
---|
916 | printf ("cost : {lms val | appli}: ###\n"); |
---|
917 | printf ("set_scoef : modname coef: ###\n"); |
---|
918 | printf ("set_bcoef : modname coef: ###\n"); |
---|
919 | printf ("set_pcoef : modname coef: ###\n"); |
---|
920 | printf ("adjust : {std | appli}: ###\n"); |
---|
921 | printf ("testad : pdx [{-1, tol}] maxcase [zinfo]]: ###\n"); |
---|
922 | printf ("testdf : i j k codop [%c]pdx ptol: ###\n", '%'); |
---|
923 | printf ("testlt : pdx alpha fdec nbloop [modop]: ###\n"); |
---|
924 | printf ("testof : pdx alpha fdec nbloop [modop]: ###\n"); |
---|
925 | printf ("set_iosep : chaine de caracteres: ###\n"); |
---|
926 | printf ("outoobs : modname nout liste_pdt: ###\n"); |
---|
927 | printf ("loadobs : cf paramètres dans la doc: ###\n"); |
---|
928 | printf ("loadstate : cf paramètres dans la doc: ###\n"); |
---|
929 | printf ("savestate : objname nout oaxis t[%c] {A,B} {0,1,2,3} [filename]: ###\n",'%'); |
---|
930 | printf ("outoebx : modname nout liste_pdtI: ###\n"); |
---|
931 | printf ("lobs : [trajname]:###\n"); |
---|
932 | printf ("sampleof/i : modulx infx supx dx moduly infy supy dy outfile: ###\n"); |
---|
933 | printf ("nnet : netname: ###\n"); |
---|
934 | printf ("lnet : ###\n"); |
---|
935 | printf ("netload : netname filename : ###\n"); |
---|
936 | printf ("setn_activ : netname activation : ###\n"); |
---|
937 | printf ("setn_plin : dmin dmax th: ###\n"); |
---|
938 | printf ("setn_psig : mx dmin scale offset: ###\n"); |
---|
939 | printf ("forward : nstept: ###\n"); |
---|
940 | printf ("backward : nstept: ###\n"); |
---|
941 | printf ("set_nbiter : val: ###\n"); |
---|
942 | printf ("set_nbextl : val: ###\n"); |
---|
943 | printf ("run : ###\n"); |
---|
944 | printf ("runi : ###\n"); |
---|
945 | #ifdef YO_M1QN3 |
---|
946 | //pour m1qn3 (also need set_nbiter; first word end letter is m) |
---|
947 | printf ("setm_io : val: ###\n"); |
---|
948 | printf ("setm_impres : val: ###\n"); |
---|
949 | printf ("setm_mode : val: ###\n"); |
---|
950 | printf ("setm_nsim : val: ###\n"); |
---|
951 | printf ("setm_dxmin : [real]: ###\n"); |
---|
952 | printf ("setm_epsg : real: ###\n"); |
---|
953 | printf ("setm_ddf1 : real: ###\n"); |
---|
954 | printf ("runm et runim : ###\n"); |
---|
955 | printf ("runm2 & runim2: ###\n"); |
---|
956 | #endif |
---|
957 | //modul instruction |
---|
958 | printf ("setstate : modname real: ###\n"); |
---|
959 | printf ("setstate_all : real: ###\n"); |
---|
960 | printf ("setepsi : modname real: ###\n"); |
---|
961 | printf ("setepsi_all : real: ###\n"); |
---|
962 | printf ("-----------------------------------------------------------------------------\n"); |
---|
963 | } |
---|
964 | printf("\n"); |
---|
965 | } |
---|
966 | |
---|
967 | /* ---------------------------------------------------------------------------- |
---|
968 | //=========== appelle d'une fonction sous la forme argc argv =============== */ |
---|
969 | // avec constitution des arguments |
---|
970 | int Yfarg(int(*fct)(int argc, char *argv[]), char *args) |
---|
971 | { int cdesc; |
---|
972 | char *cdes[NB_MAX_ARG_CDE]; |
---|
973 | char cdeline[BUFSIZE+1]; |
---|
974 | |
---|
975 | strcpy(cdeline, args); |
---|
976 | if (!Yrecup_cde (&cdesc, cdeline, cdes)) |
---|
977 | return(0); |
---|
978 | return(fct(cdesc, cdes)); |
---|
979 | } |
---|
980 | /* ---------------------------------------------------------------------------- |
---|
981 | //================ Indice d'une definition dans YTabDefval ================= */ |
---|
982 | int Yisdefval(char *name) |
---|
983 | { int wi; |
---|
984 | for (wi=0; wi<YNBDEFVAL; ++wi) |
---|
985 | { if (strcmp(name, YTabDefval[wi].Name) == 0) |
---|
986 | return (wi); |
---|
987 | } |
---|
988 | return(-1); |
---|
989 | } |
---|
990 | /*----------------------- liste des valeurs définies ------------------------*/ |
---|
991 | void Ylval() |
---|
992 | { |
---|
993 | printf (" | N° | nom | valeur | \n"); |
---|
994 | for (int w1=0; w1<YNBDEFVAL; ++w1) |
---|
995 | printf (" | %3i | %-12s | %8s |\n", w1+1, |
---|
996 | YTabDefval[w1].Name, YTabDefval[w1].macro); |
---|
997 | printf("\n"); |
---|
998 | } |
---|
999 | /* ---------------------------------------------------------------------------- |
---|
1000 | //=============== Valorisation du tableau Yting pour testdf ================ */ |
---|
1001 | void Ysetting(char *codop) |
---|
1002 | { |
---|
1003 | double val; |
---|
1004 | if (codop[0]=='N') /* input value = input indice */ |
---|
1005 | { for(int wi=0; wi<YMAX_NBI; ++wi) Yting[wi]=wi+1; |
---|
1006 | } |
---|
1007 | else if (codop[0]=='r') /* rand in [0, 1] */ |
---|
1008 | { for(int wi=0; wi<YMAX_NBI; ++wi) Yting[wi]=(double)rand()/RAND_MAX; |
---|
1009 | } |
---|
1010 | else if (codop[0]=='R') /* rand in [-1, 1] */ |
---|
1011 | { for(int wi=0; wi<YMAX_NBI; ++wi) Yting[wi]=((double)rand()/RAND_MAX)*2 -1; |
---|
1012 | } |
---|
1013 | else if ( codop[0]=='F' || codop[0]=='f') |
---|
1014 | {/*nb codop=='F' used for dfward: see testdf in Yao8.c (so don't use it here)*/ |
---|
1015 | } |
---|
1016 | else if (codop[0]=='U') |
---|
1017 | {/* the User must it-self feel Yting before calling testdf */ |
---|
1018 | } |
---|
1019 | else /* otherwise we considere it is a real */ |
---|
1020 | { val = atof(codop); |
---|
1021 | for(int wi=0; wi<YMAX_NBI; ++wi) Yting[wi]=val; |
---|
1022 | } |
---|
1023 | } |
---|
1024 | |
---|
1025 | /* ---------------------------------------------------------------------------- |
---|
1026 | //=============== test de l'erreur sur l'adjoint par module ================ */ |
---|
1027 | int Ytesterrad_mod(char *nmmod, double YLTRes, double YAdRes) |
---|
1028 | { double errel; |
---|
1029 | |
---|
1030 | /* max case demanded deja atteind */ |
---|
1031 | if (Ynbko>=Ymaxko) return(0); |
---|
1032 | |
---|
1033 | /* cas de valeurs proches d'un zero informatique ... ->ok !? */ |
---|
1034 | if (Yerrelmax!=-1) |
---|
1035 | if (fabs(YLTRes)<=Ypzedi && fabs(YAdRes)<=Ypzedi) |
---|
1036 | return(1); |
---|
1037 | |
---|
1038 | /* autres cas, on calcul et on test l'erreur relative */ |
---|
1039 | errel = (YLTRes-YAdRes)/YLTRes; |
---|
1040 | if (fabs(errel)>=Yerrelmax || Yerrelmax<0.0) |
---|
1041 | { printf (" %8s(%i %i %i; %i) % 23.15e - % 23.15e = % -23.15e relerr=% 21.15e\n", |
---|
1042 | nmmod, Yi+1, Yj+1, Yk+1, Yt+1, YLTRes, YAdRes, YLTRes-YAdRes, errel); |
---|
1043 | ++Ynbko; |
---|
1044 | //if (Ynbko>=Ymaxko) return(0); |
---|
1045 | } |
---|
1046 | return(1); |
---|
1047 | } |
---|
1048 | |
---|
1049 | /* ---------------------------------------------------------------------------- |
---|
1050 | //======================== Fonction pour le deboggage ====================== */ |
---|
1051 | void Ydbg_nanf(char *str, int nbi, char *nmmod) |
---|
1052 | { |
---|
1053 | for (int wi=0; wi<nbi; ++wi) |
---|
1054 | { |
---|
1055 | if (finite((double)Yting[wi]) == 0) |
---|
1056 | { printf("dbg: %s %s[%i]: (%i %i %i : %i) : NaN or Inf found for Yting !!!=> exit process\n", |
---|
1057 | str, nmmod, wi+1, Yi+1, Yj+1, Yk+1, Yt+1); |
---|
1058 | exit(0); |
---|
1059 | } |
---|
1060 | if (finite((double)Ytbeta[wi]) == 0) |
---|
1061 | { printf("dbg: %s %s[%i]: (%i %i %i : %i) : NaN or Inf found for Ytbeta !!!=> exit process\n", |
---|
1062 | str, nmmod, wi+1, Yi+1, Yj+1, Yk+1, Yt+1); |
---|
1063 | exit(0); |
---|
1064 | } |
---|
1065 | } |
---|
1066 | } |
---|
1067 | /* ------------------------------------------------------------------------- */ |
---|
1068 | void Ydbg_ting(char *str, int nbi, char *nmmod) |
---|
1069 | { |
---|
1070 | printf ("dbg: %s module %s : (%i %i %i ; %i) \n", str, nmmod, Yi+1, Yj+1, Yk+1, Yt+1); |
---|
1071 | for (int wi=0; wi<nbi; ++wi) |
---|
1072 | { printf("dbg: input [%i]: => %e \n", wi+1, Yting[wi]); |
---|
1073 | } |
---|
1074 | } |
---|
1075 | void Ydbg_ting_wrk(char *str, int nbi, char *nmmod) |
---|
1076 | { if(!strcmp(str, "F: ")) return; |
---|
1077 | if (Yt!=1) return; |
---|
1078 | printf ("dbg: %s module %s : (%i %i %i ; %i) \n", str, nmmod, Yi+1, Yj+1, Yk+1, Yt+1); |
---|
1079 | for (int wi=0; wi<nbi; ++wi) |
---|
1080 | { printf("dbg: input [%i]: => %22.16e \n", wi+1, Yting[wi]); |
---|
1081 | } |
---|
1082 | } |
---|
1083 | /* --------------------------------------------------------------------------*/ |
---|
1084 | void Ydbg_beta(char *str, int nbi, char *nmmod) |
---|
1085 | { printf ("dbg: %s module %s : (%i %i %i ; %i) \n", str, nmmod, Yi+1, Yj+1, Yk+1, Yt+1); |
---|
1086 | for (int wi=0; wi<nbi; ++wi) |
---|
1087 | { printf("dbg: grad [%i]: => %e \n", wi+1, Ytbeta[wi]); |
---|
1088 | } |
---|
1089 | } |
---|
1090 | |
---|
1091 | //============================= trajectoire : ... ==========================*/ |
---|
1092 | void Ydispcurstep(int itraj) /* not realy used because not practical */ |
---|
1093 | { /* pour voir la progression des trajectoires. |
---|
1094 | echelle de tps non respectee si dt n'est pas entier ! */ |
---|
1095 | int i, j; |
---|
1096 | float wtime; |
---|
1097 | float startime; |
---|
1098 | printf (" |"); |
---|
1099 | wtime = Ybegintime; |
---|
1100 | startime = Ybegintime + YTabTraj[itraj].offtime; |
---|
1101 | while (wtime < startime) |
---|
1102 | { printf(" "); ++wtime; |
---|
1103 | } |
---|
1104 | while (wtime < YTabTraj[itraj].curtime) |
---|
1105 | { for (i=0; i<YTabTraj[itraj].dtime; ++i) printf(" "); |
---|
1106 | wtime += YTabTraj[itraj].dtime; |
---|
1107 | } |
---|
1108 | if (wtime < YTabTraj[itraj].stoptime) |
---|
1109 | { for (j=1; j<YTabTraj[itraj].dtime; ++j) printf("_"); |
---|
1110 | printf("."); |
---|
1111 | } |
---|
1112 | printf("\n"); |
---|
1113 | } |
---|
1114 | /*-------------------------*/ |
---|
1115 | void Ystraj() |
---|
1116 | { int i, j; |
---|
1117 | float wtime; |
---|
1118 | float startime; |
---|
1119 | printf("\n\n representation graphique des trajectoires\n"); |
---|
1120 | printf("attention, echelle de temps non respectée si dt et offt ne sont pas entiers !\n\n"); |
---|
1121 | |
---|
1122 | for (i=0; i<YNBTRAJ;++i) |
---|
1123 | { printf(" %8s: |", YTabTraj[i].name); |
---|
1124 | wtime = Ybegintime; |
---|
1125 | startime = Ybegintime + YTabTraj[i].offtime; |
---|
1126 | while (wtime < startime) |
---|
1127 | { printf(" "); ++wtime; |
---|
1128 | } |
---|
1129 | while (wtime < YTabTraj[i].stoptime) |
---|
1130 | { for (j=1; j<YTabTraj[i].dtime; ++j) printf("_"); |
---|
1131 | printf("."); |
---|
1132 | wtime += YTabTraj[i].dtime; |
---|
1133 | } |
---|
1134 | printf("|\n\n"); |
---|
1135 | } |
---|
1136 | } |
---|
1137 | |
---|
1138 | //============== trajectoire : repositionnement sur le modele ===============*/ |
---|
1139 | int Yset_modeltime (int time) //PLM, je ne traite que le repositionnement au debut du modele !!! (ARAR) |
---|
1140 | { int wi; |
---|
1141 | for (wi=0; wi<YNBTRAJ; ++wi) |
---|
1142 | { YTabTraj[wi].toptime = YTabTraj[wi].nbuptime; |
---|
1143 | YTabTraj[wi].curtime = Ybegintime + YTabTraj[wi].offtime; |
---|
1144 | } |
---|
1145 | return(0); |
---|
1146 | } |
---|
1147 | //=================== trajectoire : recalcule de curtime ====================*/ |
---|
1148 | int Yupdcurtime(int itraj) |
---|
1149 | { |
---|
1150 | if (itraj<0 || itraj >= YNBTRAJ) return(-1); |
---|
1151 | YTabTraj[itraj].curtime = Ybegintime + YTabTraj[itraj].offtime |
---|
1152 | + (YTabTraj[itraj].toptime - YTabTraj[itraj].nbuptime) |
---|
1153 | * YTabTraj[itraj].dtime; |
---|
1154 | return(0); |
---|
1155 | } |
---|
1156 | /*=================== trajectoire : recalcule de stoptime ===================*/ |
---|
1157 | int Yupdstoptime(int itraj) |
---|
1158 | { |
---|
1159 | if (itraj<0 || itraj >= YNBTRAJ) return(-1); |
---|
1160 | YTabTraj[itraj].stoptime = Ybegintime + YTabTraj[itraj].offtime |
---|
1161 | + YTabTraj[itraj].dtime * YTabTraj[itraj].nbsteptime; |
---|
1162 | return(0); |
---|
1163 | } |
---|
1164 | /*============ Indice Trajectoire dans tableau des trajectoires =============*/ |
---|
1165 | int Yitraj(char *nmtraj) |
---|
1166 | { |
---|
1167 | for (int w1=0; w1<YNBTRAJ; ++w1) |
---|
1168 | if (strcmp(YTabTraj[w1].name, nmtraj) == 0) |
---|
1169 | return (w1); |
---|
1170 | return(-1); |
---|
1171 | } |
---|
1172 | /*--------------------------------------------- |
---|
1173 | int Yitrajimod(int imod) |
---|
1174 | {return(Yitraj(YTabSpace[Yispace(YTabMod[imod].space_name)].traj_name)); |
---|
1175 | } cf v */ |
---|
1176 | /*---------------------------------------------*/ |
---|
1177 | int Ypdt2pdt (int wxtraj, int topy, int wytraj) |
---|
1178 | { /* ATTENTION: cette fonction doit etre en phase |
---|
1179 | avec celle, de meme nom, qui est dans Yao8.c */ |
---|
1180 | float offy, offx, dty, dtx; |
---|
1181 | int topx, upty, uptx; |
---|
1182 | |
---|
1183 | offy = YTabTraj[wytraj].offtime; |
---|
1184 | offx = YTabTraj[wxtraj].offtime; |
---|
1185 | dty = YTabTraj[wytraj].dtime; |
---|
1186 | dtx = YTabTraj[wxtraj].dtime; |
---|
1187 | upty = YTabTraj[wytraj].nbuptime; |
---|
1188 | uptx = YTabTraj[wxtraj].nbuptime; |
---|
1189 | |
---|
1190 | topx = (int)( (offy + (topy-upty)*dty - dty - offx) / dtx ) + uptx + 1; |
---|
1191 | return(topx); |
---|
1192 | } |
---|
1193 | /*---------------------------------------------*/ |
---|
1194 | int Ytttt_pdt (int wxtraj, int topy, int wytraj) |
---|
1195 | { /* traduction du temps d'une trajectoire a l'autre mais en considerant |
---|
1196 | cette fois qu'on travaille avec des indices C et qu'on borne |
---|
1197 | le resultat au temps de la trajectoire */ |
---|
1198 | int topx; |
---|
1199 | topx = Ypdt2pdt(wxtraj, topy+1, wytraj) - 1; |
---|
1200 | if (topx < 0) topx = 0; |
---|
1201 | else if (topx >= YTabTraj[wxtraj].nbuptime + YTabTraj[wxtraj].nbsteptime) |
---|
1202 | topx = YTabTraj[wxtraj].nbuptime + YTabTraj[wxtraj].nbsteptime - 1; |
---|
1203 | |
---|
1204 | return(topx); |
---|
1205 | } |
---|
1206 | /*==================== liste du tableau des trajectoires ====================*/ |
---|
1207 | void Yltraj() |
---|
1208 | { |
---|
1209 | printf (" | id | traj name type| upt. offt. dt curt. topt. nbstept. stopt. act| \n"); |
---|
1210 | for (int w1=0; w1<YNBTRAJ; ++w1) |
---|
1211 | printf (" | %3i | %-10s %c | %2i %6.3f %6.3f %6.3f %2i %2i %6.3f %1i |\n", |
---|
1212 | w1+1, |
---|
1213 | YTabTraj[w1].name, |
---|
1214 | YTabTraj[w1].type, |
---|
1215 | YTabTraj[w1].nbuptime, |
---|
1216 | YTabTraj[w1].offtime, |
---|
1217 | YTabTraj[w1].dtime, |
---|
1218 | YTabTraj[w1].curtime, |
---|
1219 | YTabTraj[w1].toptime, |
---|
1220 | YTabTraj[w1].nbsteptime, |
---|
1221 | YTabTraj[w1].stoptime, |
---|
1222 | YTabTraj[w1].isactiv |
---|
1223 | ); |
---|
1224 | printf("\n"); |
---|
1225 | } |
---|
1226 | |
---|
1227 | /*================ activation ou desactivation de trajectoire ===============*/ |
---|
1228 | //syntax : {activ, unactiv} {trajname ,typetraj} [{trajname ,typetraj}[...]] [only] |
---|
1229 | //exemple: active Traj1 M Q Traj7 R only |
---|
1230 | int Yisa_typetraj(char typetraj) |
---|
1231 | { int w1; |
---|
1232 | for (w1=0; w1<YNBTRAJ; ++w1) |
---|
1233 | if (YTabTraj[w1].type == typetraj) |
---|
1234 | return (1); |
---|
1235 | return(0); |
---|
1236 | } |
---|
1237 | /*---------------------------------------------*/ |
---|
1238 | int Yactraj(int cdesc, char *cdes[]) |
---|
1239 | { |
---|
1240 | int w1, w2; int only=0; int less=0; int activ=0; |
---|
1241 | if (strcmp(cdes[0], "activ")==0 || strcmp(cdes[0], "ACTIV")== 0) |
---|
1242 | activ=1; |
---|
1243 | |
---|
1244 | /* verif trajname et/ou typetraj existe */ |
---|
1245 | for (w1=1; w1<cdesc; ++w1) |
---|
1246 | { if (strlen(cdes[w1])==1) //un caractere => doit etre un type de trajectoire |
---|
1247 | { if (!Yisa_typetraj(cdes[w1][0])) |
---|
1248 | { printf("(un)activ: trajectory type (%c) does not exist\n", cdes[w1][0]); |
---|
1249 | return(0); |
---|
1250 | } |
---|
1251 | } |
---|
1252 | else if (strcmp(cdes[w1], "ONLY") == 0 || strcmp(cdes[w1], "only") == 0) |
---|
1253 | { //only ou less doit etre le dernier token |
---|
1254 | if (w1 != cdesc-1) |
---|
1255 | { printf("(un)activ: \"only\" must be the last token\n"); |
---|
1256 | return(0); |
---|
1257 | } |
---|
1258 | only=1; |
---|
1259 | } |
---|
1260 | else if (strcmp(cdes[w1], "LESS") == 0 || strcmp(cdes[w1], "less") == 0) |
---|
1261 | { //only ou less doit etre le dernier token |
---|
1262 | if (w1 != cdesc-1) |
---|
1263 | { printf("(un)activ: \"less\" must be the last token\n"); |
---|
1264 | return(0); |
---|
1265 | } |
---|
1266 | less=1; |
---|
1267 | } |
---|
1268 | |
---|
1269 | else |
---|
1270 | { //ce doit etre le nom d'une trajectoire |
---|
1271 | if (Yitraj(cdes[w1])<0) |
---|
1272 | { printf("(un)activ: unknwon trajectory name (%s) \n", cdes[w1]); |
---|
1273 | return(0); |
---|
1274 | } |
---|
1275 | } |
---|
1276 | } |
---|
1277 | |
---|
1278 | //---------------------------------- |
---|
1279 | if (only) /* si only est utilised */ |
---|
1280 | { for (w1=0; w1<YNBTRAJ; ++w1) |
---|
1281 | { if (activ) YTabTraj[w1].isactiv = 0; //pour activ on commence par tout desactiver |
---|
1282 | else if (YTabTraj[w1].fward != NULL) //pour unactiv, on commence par tout activer |
---|
1283 | YTabTraj[w1].isactiv = 1; //sauf les traj non operationnelle |
---|
1284 | } |
---|
1285 | } |
---|
1286 | else if (less) /* si less est utilised */ |
---|
1287 | { for (w1=0; w1<YNBTRAJ; ++w1) |
---|
1288 | { if (!activ) YTabTraj[w1].isactiv = 0; //pour unactiv on commence par tout desactive |
---|
1289 | else if (YTabTraj[w1].fward != NULL) //pour active on commence par tout activer sauf les traj non operationnelle |
---|
1290 | YTabTraj[w1].isactiv = 1; |
---|
1291 | } |
---|
1292 | } |
---|
1293 | |
---|
1294 | //---------------------------------- |
---|
1295 | /* puis on va activer ou desactiver selon chaque token */ |
---|
1296 | for (w1=1; w1<cdesc; ++w1) |
---|
1297 | { if (strcmp(cdes[w1], "ONLY") == 0 || strcmp(cdes[w1], "only") == 0 |
---|
1298 | || strcmp(cdes[w1], "LESS") == 0 || strcmp(cdes[w1], "less") == 0) |
---|
1299 | break; |
---|
1300 | for (w2=0; w2<YNBTRAJ; ++w2) |
---|
1301 | { if ( strcmp(cdes[w1], YTabTraj[w2].name)==0 |
---|
1302 | || (strlen(cdes[w1])==1 && cdes[w1][0]==YTabTraj[w2].type) |
---|
1303 | ) |
---|
1304 | { /* on ne touche pas aux trajectoires non oprationnelles */ |
---|
1305 | if (YTabTraj[w2].fward == NULL) |
---|
1306 | continue; |
---|
1307 | if (activ) //pour activ on active sauf si less |
---|
1308 | { if (less) YTabTraj[w2].isactiv = 0; |
---|
1309 | else YTabTraj[w2].isactiv = 1; |
---|
1310 | } |
---|
1311 | else //pour unactiv, on desactive sauf si less |
---|
1312 | { if (less) YTabTraj[w2].isactiv = 1; |
---|
1313 | else YTabTraj[w2].isactiv = 0; |
---|
1314 | } |
---|
1315 | } |
---|
1316 | } |
---|
1317 | } |
---|
1318 | |
---|
1319 | return(1); |
---|
1320 | } |
---|
1321 | |
---|
1322 | /*======================= liste du tableau des espaces ======================*/ |
---|
1323 | void Ylspace() |
---|
1324 | { |
---|
1325 | printf (" | id | space name type | axi axj axk | traj name | \n"); |
---|
1326 | for (int w1=0; w1<YNBSPACE; ++w1) |
---|
1327 | printf (" | %3i | %-10s %c | %3i %3i %3i | %-10s|\n", w1+1, |
---|
1328 | YTabSpace[w1].name, YTabSpace[w1].type, |
---|
1329 | YTabSpace[w1].axi, YTabSpace[w1].axj, YTabSpace[w1].axk, |
---|
1330 | YTabSpace[w1].traj_name); |
---|
1331 | printf("\n"); |
---|
1332 | } |
---|
1333 | /*============== Indice espace dans tableau des espaces =====================*/ |
---|
1334 | int Yispace(char *nmspace) |
---|
1335 | { |
---|
1336 | for (int w1=0; w1<YNBSPACE; ++w1) |
---|
1337 | if (strcmp(YTabSpace[w1].name, nmspace) == 0) |
---|
1338 | return (w1); |
---|
1339 | return(-1); |
---|
1340 | } |
---|
1341 | /*---------------------------------------------*/ |
---|
1342 | int Yispaceimod(int imod) //!? |
---|
1343 | {return(Yispace(YTabMod[imod].space_name)); |
---|
1344 | } //!? |
---|
1345 | |
---|
1346 | |
---|
1347 | /*======================= liste du tableau des operateurs ===================*/ |
---|
1348 | void Ylopera() |
---|
1349 | { printf (" | id | opera name type | axi axj axk | traj name | act | \n"); |
---|
1350 | for (int w1=0; w1<YNBOPERA; ++w1) |
---|
1351 | printf (" | %3i | %-10s %c | %3i %3i %3i | %-10s| %1i |\n", w1+1, |
---|
1352 | YTabOpera[w1].name, YTabOpera[w1].type, |
---|
1353 | YTabOpera[w1].axi, YTabOpera[w1].axj, YTabOpera[w1].axk, |
---|
1354 | YTabOpera[w1].traj_name, YTabOpera[w1].isactiv); |
---|
1355 | printf("\n"); |
---|
1356 | } |
---|
1357 | /* ---------------- indice operateur dans tableau des operateurs ------------*/ |
---|
1358 | int Yiopera(char *nmopera) |
---|
1359 | { for (int w1=0; w1<YNBOPERA; ++w1) |
---|
1360 | if (strcmp(YTabOpera[w1].name, nmopera) == 0) |
---|
1361 | return (w1); |
---|
1362 | return(-1); |
---|
1363 | } |
---|
1364 | /*----------------- activation/desactivation d'operateurs -------------------*/ |
---|
1365 | void Yact_operator(char type, short etat) |
---|
1366 | { int w1; |
---|
1367 | for (w1=0; w1<YNBOPERA; ++w1) |
---|
1368 | if (YTabOpera[w1].type==type || type=='*') YTabOpera[w1].isactiv=etat; |
---|
1369 | } |
---|
1370 | /*---------------------------------------------*/ |
---|
1371 | int Yioperaimod(int imod) //!? |
---|
1372 | {return(Yiopera(YTabMod[imod].space_name)); |
---|
1373 | } //!? |
---|
1374 | |
---|
1375 | /*======================= Indice du tableau des operateurs ===================*/ |
---|
1376 | int Yitrajimod(int imod) |
---|
1377 | { //renvoie l'indice de la trajectoire a laquelle le |
---|
1378 | //module est rattached via un espace ou un operateur |
---|
1379 | int w1; |
---|
1380 | if ( (w1=Yioperaimod(imod)) >=0) |
---|
1381 | return(Yitraj(YTabOpera[w1].traj_name)); |
---|
1382 | else if ( (w1=Yispaceimod(imod)) >=0) |
---|
1383 | return(Yitraj(YTabSpace[w1].traj_name)); |
---|
1384 | else |
---|
1385 | { //unpossible case |
---|
1386 | printf ("Ysys error #1\n"); return(-9); |
---|
1387 | } |
---|
1388 | } |
---|
1389 | /* ---------------------------------------------------------------------------- |
---|
1390 | //================= Indice Module dans tableau des modules ================= */ |
---|
1391 | int Yimod(char *nmmod) |
---|
1392 | { for (int w1=0; w1<YNBMODUL; ++w1) |
---|
1393 | if (strcmp(YTabMod[w1].Name, nmmod) == 0) |
---|
1394 | return (w1); |
---|
1395 | return(-1); |
---|
1396 | } |
---|
1397 | /*================ print la liste du tableau des modules =================== */ |
---|
1398 | void Ylmod(int argc, char *argv[]) |
---|
1399 | { int all = 1; int target = 0; int cout = 0; |
---|
1400 | /* entete */ |
---|
1401 | //printf (" | id | nbi nbs | dim | axi axj axk | nbt | C T O | scoef bcoef pcoef | name / space\n"); |
---|
1402 | printf (" | id | nbi nbs | dim | axi axj axk | nbt | C T deb end | scoef bcoef pcoef | name / space\n"); |
---|
1403 | |
---|
1404 | /* positionnement de flag pour savoir ce qu'on doit printer */ |
---|
1405 | for(int wi=1; wi<argc; ++wi) |
---|
1406 | { if (!strcmp(argv[wi], "target") || !strcmp(argv[wi], "TARGET") ) {all=0; target=1;} |
---|
1407 | if (!strcmp(argv[wi], "cout") || !strcmp(argv[wi], "COUT") ) {all=0; cout=1;} |
---|
1408 | } |
---|
1409 | |
---|
1410 | /* boucle sur les modules pour l'affichage */ |
---|
1411 | for (int w1=0; w1<YNBMODUL; ++w1) |
---|
1412 | { |
---|
1413 | if( all || (target==1 && YTabMod[w1].is_target) || (cout==1 && YTabMod[w1].is_cout) ) |
---|
1414 | { //printf (" |%3i | %3i %3i | %3i | %3i %3i %3i |%4i | %1i %1i %1i | %5.4e %5.4e %5.4e | %s / %s\n", w1+1, |
---|
1415 | printf (" |%3i | %3i %3i | %3i | %3i %3i %3i |%4i | %1i %1i%3i %3i | %5.4e %5.4e %5.4e | %s / %s\n", w1+1, |
---|
1416 | YTabMod[w1].nb_input, YTabMod[w1].nb_stout, YTabMod[w1].dim, |
---|
1417 | YTabMod[w1].axi, YTabMod[w1].axj, YTabMod[w1].axk, YTabMod[w1].nb_time, |
---|
1418 | YTabMod[w1].is_cout, YTabMod[w1].is_target, YTabMod[w1].deb_target, YTabMod[w1].end_target, |
---|
1419 | YTabMod[w1].scoef, YTabMod[w1].bcoef, YTabMod[w1].pcoef, YTabMod[w1].Name, YTabMod[w1].space_name); |
---|
1420 | //YTabMod[w1].ctrord, |
---|
1421 | } |
---|
1422 | } |
---|
1423 | printf("\n"); |
---|
1424 | } |
---|
1425 | /*=================== liste association module/operateur =================== */ |
---|
1426 | void Ylmocop() |
---|
1427 | { int w1, w2; |
---|
1428 | printf (" ----- association list moduls/operators -----\n"); |
---|
1429 | for (w1=0; w1<YNBMODUL; ++w1) |
---|
1430 | { if (YTabMocop[w1][0] != -1) //y'a au moins un operateur associed |
---|
1431 | { printf ("%s: ", YTabMod[w1].Name); |
---|
1432 | w2=0; |
---|
1433 | while (w2<YNBOPERA && YTabMocop[w1][w2]!=-1) |
---|
1434 | { printf("%8s ", YTabOpera[YTabMocop[w1][w2]].name); |
---|
1435 | ++w2; |
---|
1436 | } |
---|
1437 | printf("\n"); |
---|
1438 | } |
---|
1439 | } |
---|
1440 | printf("\n"); |
---|
1441 | } |
---|
1442 | /* ---------------------------------------------------------------------------- |
---|
1443 | //================ Indice Reseaux dans tableau des Resaux ================== */ |
---|
1444 | #ifdef YO_NETWARD |
---|
1445 | int Yinet(char *nmnet) |
---|
1446 | { |
---|
1447 | for (int w1=0; w1<YNBNET; ++w1) |
---|
1448 | if (strcmp(YTabNet[w1].Name, nmnet) == 0) |
---|
1449 | return (w1); |
---|
1450 | return(-1); |
---|
1451 | } |
---|
1452 | //================ print la liste du tableau des reseaux =================== */ |
---|
1453 | void Ylnet () |
---|
1454 | { |
---|
1455 | char activ[10]; |
---|
1456 | printf (" | ind | nom | nbw | nbin | nbout | maxcell | tweight | factiv |\n"); |
---|
1457 | for (int w1=0; w1<YNBNET; ++w1) |
---|
1458 | { if (YTabNet[w1].activ==SigLin) sprintf(activ,"siglin"); |
---|
1459 | else if (YTabNet[w1].activ==SigSig) sprintf(activ,"sigsig"); |
---|
1460 | else sprintf(activ,"unknown!?"); |
---|
1461 | printf (" | %3i | %8s | %3i | %3i | %3i | %3i | %9p | %s |\n", w1+1, |
---|
1462 | YTabNet[w1].Name, YTabNet[w1].nbweight, |
---|
1463 | YTabNet[w1].nbinput, YTabNet[w1].nboutput, YTabNet[w1].maxcell, |
---|
1464 | YTabNet[w1].tweight, activ); |
---|
1465 | } |
---|
1466 | } |
---|
1467 | #endif |
---|
1468 | /* ---------------------------------------------------------------------------- |
---|
1469 | //======== positionnement des indices de parcourt des axes de l'espace ===== */ |
---|
1470 | int YsetPaxe(int dim, char *oaxis, int axe1, int axe2, int axe3, |
---|
1471 | int *axo1, int *axo2, int *axo3) |
---|
1472 | { |
---|
1473 | if (dim==3) |
---|
1474 | { |
---|
1475 | if (strcmp(oaxis, "ijk") == 0 || strcmp(oaxis, "IJK") == 0) |
---|
1476 | { *axo1=axe1; *axo2=axe2; *axo3=axe3;} |
---|
1477 | else if (strcmp(oaxis, "ikj") == 0 || strcmp(oaxis, "IKJ") == 0) |
---|
1478 | { *axo1=axe1; *axo2=axe3; *axo3=axe2;} |
---|
1479 | else if (strcmp(oaxis, "jik") == 0 || strcmp(oaxis, "JIK") == 0) |
---|
1480 | { *axo1=axe2; *axo2=axe1; *axo3=axe3;} |
---|
1481 | else if (strcmp(oaxis, "jki") == 0 || strcmp(oaxis, "JKI") == 0) |
---|
1482 | { *axo1=axe2; *axo2=axe3; *axo3=axe1;} |
---|
1483 | else if (strcmp(oaxis, "kij") == 0 || strcmp(oaxis, "KIJ") == 0) |
---|
1484 | { *axo1=axe3; *axo2=axe1; *axo3=axe2;} |
---|
1485 | else if (strcmp(oaxis, "kji") == 0 || strcmp(oaxis, "KJI") == 0) |
---|
1486 | { *axo1=axe3; *axo2=axe2; *axo3=axe1;} |
---|
1487 | else |
---|
1488 | return(0); |
---|
1489 | /* default when error : {*axo1=axe1; *axo2=axe2; *axo3=axe3;} */ |
---|
1490 | } |
---|
1491 | else if (dim==2) |
---|
1492 | { |
---|
1493 | if (strcmp(oaxis, "ij") == 0 || strcmp(oaxis, "IJ") == 0) |
---|
1494 | { *axo1=axe1; *axo2=axe2;} |
---|
1495 | else if (strcmp(oaxis, "ji") == 0 || strcmp(oaxis, "JI") == 0) |
---|
1496 | { *axo1=axe2; *axo2=axe1;} |
---|
1497 | else if (strcmp(oaxis, "ik") == 0 || strcmp(oaxis, "IK") == 0) |
---|
1498 | { *axo1=axe1; *axo2=axe3;} |
---|
1499 | else if (strcmp(oaxis, "ki") == 0 || strcmp(oaxis, "KI") == 0) |
---|
1500 | { *axo1=axe3; *axo2=axe1;} |
---|
1501 | else if (strcmp(oaxis, "jk") == 0 || strcmp(oaxis, "JK") == 0) |
---|
1502 | { *axo1=axe2; *axo2=axe3;} |
---|
1503 | else if (strcmp(oaxis, "kj") == 0 || strcmp(oaxis, "KJ") == 0) |
---|
1504 | { *axo1=axe3; *axo2=axe2;} |
---|
1505 | else |
---|
1506 | return(0); |
---|
1507 | } |
---|
1508 | else /* ...(dim==1) */ |
---|
1509 | { |
---|
1510 | if (strcmp(oaxis, "i") == 0 || strcmp(oaxis, "I") == 0) |
---|
1511 | { *axo1=axe1;} |
---|
1512 | else if (strcmp(oaxis, "j") == 0 || strcmp(oaxis, "J") == 0) |
---|
1513 | { *axo1=axe2;} |
---|
1514 | else if (strcmp(oaxis, "k") == 0 || strcmp(oaxis, "K") == 0) |
---|
1515 | { *axo1=axe3;} |
---|
1516 | else |
---|
1517 | return(0); |
---|
1518 | } |
---|
1519 | return(1); |
---|
1520 | } |
---|
1521 | |
---|
1522 | |
---|
1523 | /*---------------------------------------------------------------------------*/ |
---|
1524 | /* gestion des entrees - sorties et des observations pour Yao : */ |
---|
1525 | #include "Dyniob.h" |
---|
1526 | /*---------------------------------------------------------------------------*/ |
---|
1527 | |
---|
1528 | |
---|
1529 | /* ---------------------------------------------------------------------------- |
---|
1530 | //============================ FONCTIONS DE COUT =========================== */ |
---|
1531 | void Ycost() //TRobs, YNBUPTIME, YidTraj, YTemps doivent etre posisionned |
---|
1532 | { long curtop; |
---|
1533 | |
---|
1534 | if (TRobs==NULL) return; |
---|
1535 | |
---|
1536 | Ytrupdt = TRobs->iind; /* true pdt : temps initiaux et trajectoire*/ |
---|
1537 | if (Ytrupdt<0) Ytrupdt = -TRobs->iind-1; /* true pdt : cas ebauches */ |
---|
1538 | |
---|
1539 | Yact_operator('*', OFF); /* on desactive tous les operateurs */ |
---|
1540 | |
---|
1541 | /* traitement OPERATEURS HHHHH */ |
---|
1542 | YCaseCost = WISHL2_NANACT; /* pour WISH: ca mettra NAN (niveau module) */ |
---|
1543 | Ycobs_TR(TRobs->fils); /* puis ca active les operateurs associed au module (H, R, ...) */ |
---|
1544 | |
---|
1545 | Yforward_operator('H'); /* forward de tous les operateurs 'H' qui auront ete actived :M(x)->YS */ |
---|
1546 | |
---|
1547 | if (YAL2Run==RUNL2_STD) /* cas d'un run standard */ |
---|
1548 | { /* DIFFERENCE [H(M(x)) - Yo] : Ywish=Ystate-Obs */ |
---|
1549 | YCaseCost = WISHL2_DIFF; /* puis, avec ce flag, on va faire la difference sur la */ |
---|
1550 | Ycobs_TR(TRobs->fils); /* zone WISH (Ywish=Ystate-Obs) (uniquement la ou y'a des obs) */ |
---|
1551 | } |
---|
1552 | #ifdef YO_VARINCR |
---|
1553 | else if(YAL2Run==RUNL2_INCR) /* cas d'un run incremental */ |
---|
1554 | { //Ylinward_operator('H'); /* pour pousser le calculer du lineaire tangent sur H: H'M'(x)dx ->YG */ |
---|
1555 | //YCaseCost = WISHL2_QTEA; /* puis, avec ce flag, on va calculer l'ex qtea directement dans Ywish */ |
---|
1556 | //Ycobs_TR(TRobs->fils); /* (qtea)=Ywish = YG - (Y° - YS) = H'M'(Xk).dx - (y° - H(M(Xk)) */ |
---|
1557 | //qtea a deja ete valorised par Ylinward_flopobs |
---|
1558 | //on projete simplement YS->YW |
---|
1559 | YCaseCost = WISHL2_QTEA; /* puis, avec ce flag, on va projeter la zone qtea dans la */ |
---|
1560 | Ycobs_TR(TRobs->fils); /* zone WISH (Ywish=qtea = YG - (Y° -YS) = H'M'(Xk).dx - (y° - H(M(Xk)) (uniquement la ou y'a des obs) */ |
---|
1561 | } |
---|
1562 | #endif |
---|
1563 | |
---|
1564 | /* traitement OPERATEURS de covariance ('B' ou/et 'R', ou/et 'K') */ |
---|
1565 | if (TRobs->iind < 0) /* sur la partie ebauche */ |
---|
1566 | Yforward_operator('B'); /* lance tous les operateurs 'B' qui auront ete actived */ |
---|
1567 | else /* sur la trajectoire */ |
---|
1568 | Yforward_operator('R'); /* lance tous les operateurs 'R' qui auront ete actived */ |
---|
1569 | Yforward_operator('K'); /* ebauche et traj : lance tous les operateurs 'K' qui auront ete actived */ |
---|
1570 | |
---|
1571 | /* Calcul cout et gradient avec les zones Ywish en se rappelant que maintenant Ywish=Ystate-Obs |
---|
1572 | (ou dans le cas de l'incremental Ywish=Ystate+Ygrad-Obs): |
---|
1573 | mais eventuellement aussi avec les zones Ystate lorsqu'il y a un operateur 'R' */ |
---|
1574 | if (YAL2Run==RUNL2_STD) /* cas d'un run standard */ |
---|
1575 | { YCaseCost = COSTL2_WISHDIFF; /* puis avec ce flag */ |
---|
1576 | Ycobs_TR(TRobs->fils); /* on calcule : grad = costdiff(YW, YW||YS=COV(YW)) */ |
---|
1577 | } /* grad = coef*Ywish, et cout = coef*Ywish*COV(Ywish) */ |
---|
1578 | #ifdef YO_VARINCR |
---|
1579 | else if(YAL2Run==RUNL2_INCR) /* cas d'un run incremental */ |
---|
1580 | { YCaseCost = COSTL2_WISHQTEA; /* puis avec ce flag */ |
---|
1581 | Ycobs_TR(TRobs->fils); /* on calcule : grad = costdiff(qtea, YW||YS=COV(YW) */ |
---|
1582 | } /* grad = coef*qtea, et cout = coef*Yqtea*COV(Ywish) */ |
---|
1583 | #endif |
---|
1584 | |
---|
1585 | /* Retropropagation operateurs H actived */ |
---|
1586 | Ybackward_operator('H'); |
---|
1587 | |
---|
1588 | /* affichage du cout if required */ |
---|
1589 | if (YDispCost==ON) |
---|
1590 | { curtop = time((time_t *)NULL); |
---|
1591 | if (TRobs->iind < 0) /* partie ebauche*/ |
---|
1592 | { printf(" >>> Yiter %-3ld traj %-8s pdE=%i after %lds: Total cost = % -23.15e\n", |
---|
1593 | YItRun, YTabTraj[YidTraj].name, -TRobs->iind, curtop-Ytop0, YTotalCost); |
---|
1594 | } |
---|
1595 | else if(TRobs->iind < YNBUPTIME) /* partie temps initiaux */ |
---|
1596 | { printf(" >>> Yiter %-3ld traj %-8s pdI=%i after %lds: Total cost = % -23.15e\n", |
---|
1597 | YItRun, YTabTraj[YidTraj].name, TRobs->iind+1, curtop-Ytop0, YTotalCost); |
---|
1598 | } |
---|
1599 | else |
---|
1600 | { printf(" >>> Yiter %-3ld traj %-8s pdt=%i after %lds: Total cost = % -23.15e\n", |
---|
1601 | YItRun, YTabTraj[YidTraj].name, YTemps+1, curtop-Ytop0, YTotalCost); |
---|
1602 | } |
---|
1603 | } |
---|
1604 | |
---|
1605 | /* pour avancer sur cette liste des temps */ |
---|
1606 | TRobs = TRobs->frere; |
---|
1607 | } |
---|
1608 | /*---------------------------------------------------------------------------*/ |
---|
1609 | /* ---------- cout sur terme d'ebauche et observations initiales -----------*/ |
---|
1610 | void Ycostebx() |
---|
1611 | { |
---|
1612 | for (YidTraj=0; YidTraj<YNBTRAJ; ++YidTraj) |
---|
1613 | { TRobs = YTabTraj[YidTraj].TRobs; |
---|
1614 | YNBUPTIME = YTabTraj[YidTraj].nbuptime; |
---|
1615 | //while (TRobs!=NULL) |
---|
1616 | while (TRobs != NULL && TRobs->iind < YNBUPTIME) |
---|
1617 | { //printf("costebx: traj=%i Yt=%i \n", YidTraj, YTemps); |
---|
1618 | if (TRobs->iind >= 0) // partie temps initiaux |
---|
1619 | YTemps = TRobs->iind; |
---|
1620 | else // partie ebauche |
---|
1621 | YTemps = -TRobs->iind-1; |
---|
1622 | |
---|
1623 | Ycost(); |
---|
1624 | } |
---|
1625 | YTabTraj[YidTraj].TRobs = TRobs; //est-ce bien utile ? |
---|
1626 | } |
---|
1627 | } |
---|
1628 | /* ---------------------------------------------------------------------------- |
---|
1629 | //======================== FONCTIONS D'AJUSTEMENT ========================== */ |
---|
1630 | void Yadjust() |
---|
1631 | { |
---|
1632 | if (YTypeAdjust == ADJUST_APPLI) |
---|
1633 | adjust_target (); |
---|
1634 | else if (YTypeAdjust == ADJUST_STD) /* default */ |
---|
1635 | Yadjust_all (); |
---|
1636 | } |
---|
1637 | /*memo: for a kind of temperature |
---|
1638 | float epsi_fact; |
---|
1639 | epsi_fact = 0.0; //1.0; //0.02; |
---|
1640 | YS1_Ke(0) -= ( Epsi_Ke * pow(1-epsi_fact, YItRun) ) * YG1_Ke(0); |
---|
1641 | */ |
---|
1642 | /* ----------------------------------------------------------------------------*/ |
---|
1643 | #ifdef YO_VARINCR |
---|
1644 | void Yc_adjustd() /* cas de l'incremental: ajustement dx dans la boucle interne */ |
---|
1645 | { if (YTypeAdjust == ADJUST_APPLI) |
---|
1646 | adjust_target (); /* nb: le user peut tester les flags pour savoir dans quel cas il est */ |
---|
1647 | else if (YTypeAdjust == ADJUST_STD) /* default */ |
---|
1648 | Yc_adjustd_all (); |
---|
1649 | } |
---|
1650 | #endif |
---|
1651 | |
---|
1652 | |
---|
1653 | /* ---------------------------------------------------------------------------- |
---|
1654 | //============================= FONCTION FORWARD =========================== */ |
---|
1655 | int Yforward_elect() |
---|
1656 | { int wi; |
---|
1657 | int candidat = -1; |
---|
1658 | float wtime = MYMAXREEL; //DBL_MAX; //999999; |
---|
1659 | |
---|
1660 | for (wi=0; wi<YNBTRAJ; ++wi) //dans l'ordre des declaration |
---|
1661 | { if (YTabTraj[wi].curtime < wtime //qui est la + en retard |
---|
1662 | && YTabTraj[wi].toptime < YTabTraj[wi].nbuptime + YTabTraj[wi].nbsteptime //qui n'est pas en bout de course |
---|
1663 | && YTabTraj[wi].isactiv // qui est active |
---|
1664 | //&& YTabTraj[wi].curtime < Ystoptime ...!? ARAR |
---|
1665 | //&& YTabTraj[wi].curtime < Yendtime ...!? ARAR |
---|
1666 | ) |
---|
1667 | { candidat = wi; |
---|
1668 | wtime = YTabTraj[wi].curtime; |
---|
1669 | } |
---|
1670 | } |
---|
1671 | return(candidat); |
---|
1672 | } |
---|
1673 | /*---------------------------------------------------------------------------*/ |
---|
1674 | int Yforward(int itraj, int topstop) |
---|
1675 | { int itrajelue; int nbcall=0; |
---|
1676 | /* passe avant sur l'ensemble du modele global (i.e. sur ttes les trajectoires ) |
---|
1677 | de la ou on est positionned ! jusqu'a : 2 cas : |
---|
1678 | si itraj = -1: on ira jusqu'a la fin du modele (et topstop ne sert pas) |
---|
1679 | sinon, on s'arrete des que le toptime de la trajectoire passed en parametre |
---|
1680 | (qui sert donc de reference) a atteint le topstop (non inclus: i.e. on s'arrete avant) */ |
---|
1681 | |
---|
1682 | while ((itrajelue=Yforward_elect()) >= 0) // le while controle la progression |
---|
1683 | { //ici, on n'avance QUE d'UN PDT sur la trajectoire selectionnee ! |
---|
1684 | YTemps = YTabTraj[itrajelue].toptime; //(ctx pour les modules par exemple) |
---|
1685 | if (itrajelue==itraj && YTemps >= topstop) return(nbcall); //cf^ (eventuel arret sur une traj de ref) |
---|
1686 | YidTraj = itrajelue; //(ctx pour les modules par exemple) |
---|
1687 | |
---|
1688 | if (YDispTime) |
---|
1689 | { printf (" >>> Traj %s, Current forward time = %i \n", YTabTraj[itrajelue].name, YTemps+1); |
---|
1690 | //Ydispcurstep(itrajelue); |
---|
1691 | } |
---|
1692 | forward_before(0); //arar |
---|
1693 | YTabTraj[itrajelue].fward(0); //<-: forward_order (pour LA trajectoire selectionnee) |
---|
1694 | ++nbcall; |
---|
1695 | forward_after(0); //arar |
---|
1696 | {++YTabTraj[itrajelue].toptime; //<-: ++YTemps |
---|
1697 | YTabTraj[itrajelue].curtime += YTabTraj[itrajelue].dtime; //<-: multi |
---|
1698 | } |
---|
1699 | } |
---|
1700 | return(nbcall); |
---|
1701 | } |
---|
1702 | |
---|
1703 | /*...........................................................................*/ |
---|
1704 | void Yforwardrun(int itraj, int nbpdt) |
---|
1705 | { long topend; |
---|
1706 | Ytop0 = time((time_t *)NULL); |
---|
1707 | |
---|
1708 | if (YTabTraj[itraj].fward==NULL) |
---|
1709 | { printf("no forward function defined for that trajectory\n"); |
---|
1710 | return; |
---|
1711 | } |
---|
1712 | if (YTabTraj[itraj].toptime + nbpdt > YTabTraj[itraj].nbuptime + YTabTraj[itraj].nbsteptime ) |
---|
1713 | { printf ("required forward step out of upper limit: \n"); |
---|
1714 | printf (" current top (%i) + required step (%i) > top max (%i) \n", |
---|
1715 | YTabTraj[itraj].toptime, nbpdt, YTabTraj[itraj].nbuptime + YTabTraj[itraj].nbsteptime); |
---|
1716 | return; |
---|
1717 | } |
---|
1718 | |
---|
1719 | YidTraj = itraj; //(ctx pour les modules par exemple) |
---|
1720 | //YTemps = YTabTraj[itraj].toptime; //(ctx pour les modules par exemple) //- |
---|
1721 | |
---|
1722 | before_it(1); |
---|
1723 | for (int Ywt=1; Ywt<= nbpdt; ++Ywt) |
---|
1724 | { YTemps = YTabTraj[itraj].toptime; //(ctx pour les modules par exemple) //+ |
---|
1725 | if (YDispTime) printf (" >>> Traj %s, Current forward time = %i \n", YTabTraj[itraj].name, YTemps+1); |
---|
1726 | |
---|
1727 | forward_before(Ywt); |
---|
1728 | YTabTraj[itraj].fward(0); //<-: forward_order |
---|
1729 | forward_after(Ywt); |
---|
1730 | //++YTemps; //ctx //- |
---|
1731 | {++YTabTraj[itraj].toptime; //<-: ++YTemps |
---|
1732 | YTabTraj[itraj].curtime += YTabTraj[itraj].dtime; //<-: multi |
---|
1733 | } |
---|
1734 | } |
---|
1735 | topend = time((time_t *)NULL); /* time(&topend); topend = time((long *)NULL);*/ |
---|
1736 | printf("forward duration ....: %lds\n", topend-Ytop0); |
---|
1737 | return; |
---|
1738 | } |
---|
1739 | |
---|
1740 | /* ---------------------------------------------------------------------------- |
---|
1741 | //============== fonction de calcul du cout en passe avant ... ============= */ |
---|
1742 | void Yforwardcost() |
---|
1743 | { |
---|
1744 | long curtop; |
---|
1745 | int witraj; |
---|
1746 | int itrajelue; |
---|
1747 | |
---|
1748 | /* init ... */ |
---|
1749 | // YCaseCost = COSTL2_ONLY; ne devrait plus etre utile ici puisque reposisionned apres par Ycost !!! |
---|
1750 | YTotalCost = 0.0; //cout a 0 |
---|
1751 | |
---|
1752 | //TRobs = YRobs->fils; |
---|
1753 | for (witraj=0; witraj<YNBTRAJ; ++witraj) /* init des pointeurs des arbo d'obs supposed */ |
---|
1754 | { YTabTraj[witraj].TRobs = YTabTraj[witraj].YRobs->fils; /* inversed (i.e: ascending) */ |
---|
1755 | } |
---|
1756 | |
---|
1757 | /* Calcul du cout sur les termes d'ebauche et aux temps initiaux*/ |
---|
1758 | if (YTypeCost==COST_APPLI) /* l'utilisateur devra prendre totalement */ |
---|
1759 | { cost_function(-1); //(YUPTIME-1) /* en charge le calcul du cout ! */ |
---|
1760 | } |
---|
1761 | else |
---|
1762 | { /* a faire trajectoire par trajectoire (si obs il y a) */ |
---|
1763 | Ycostebx(); |
---|
1764 | } |
---|
1765 | |
---|
1766 | /*Puis on va calculer le cout en passe avant */ |
---|
1767 | Yset_modeltime(0); |
---|
1768 | before_it(1); //(YItRun); |
---|
1769 | |
---|
1770 | while ((itrajelue=Yforward_elect()) >= 0) // le while controle la progression |
---|
1771 | { //ici, on n'avance QUE d'UN PDT sur la trajectoire selectionnee ! |
---|
1772 | |
---|
1773 | YTemps = YTabTraj[itrajelue].toptime; //(ctx pour les modules par exemple) |
---|
1774 | YidTraj = itrajelue; //(ctx pour les modules par exemple) |
---|
1775 | YNBUPTIME = YTabTraj[itrajelue].nbuptime; |
---|
1776 | |
---|
1777 | if (YDispTime) |
---|
1778 | { printf (" >>> Traj %s, Current forwardcost time = %i \n", YTabTraj[itrajelue].name, YTemps+1); |
---|
1779 | //Ydispcurstep(itrajelue); |
---|
1780 | } |
---|
1781 | forward_before(0); //arar |
---|
1782 | if (YAL2Run==RUNL2_STD) |
---|
1783 | YTabTraj[itrajelue].fward(0); //<-: Yforward_order (); |
---|
1784 | #ifdef YO_VARINCR |
---|
1785 | else if (YAL2Run==RUNL2_INCR) |
---|
1786 | YTabTraj[itrajelue].lward(0); //<-: Ylinward_order (); |
---|
1787 | #endif |
---|
1788 | forward_after (0); //arar |
---|
1789 | |
---|
1790 | if (YTypeCost == COST_APPLI) /* l'utilisateur devra prendre totalement */ |
---|
1791 | cost_function (YTemps); /* en charge le calcul du cout ! */ |
---|
1792 | else |
---|
1793 | { TRobs = YTabTraj[itrajelue].TRobs; /* on se positionne sur le top d'obs courant de la trajectoire elue*/ |
---|
1794 | //Ycobs(); /* calcul du cout au pas de temps (YTemps) courant (s'il y a lieu) */ |
---|
1795 | //YTabTraj[itrajelue].TRobs = TRobs; /* pour avancer sur cette liste des temps */ |
---|
1796 | if (TRobs!=NULL && TRobs->iind==YTemps) //si cette traj a des obs au temps courant |
---|
1797 | { Ycost(); //calcul du cout |
---|
1798 | YTabTraj[itrajelue].TRobs = TRobs; /* pour avancer sur cette liste des temps */ |
---|
1799 | } |
---|
1800 | } |
---|
1801 | |
---|
1802 | {++YTabTraj[itrajelue].toptime; //<-: ++YTemps |
---|
1803 | YTabTraj[itrajelue].curtime += YTabTraj[itrajelue].dtime; //<-: multi |
---|
1804 | } |
---|
1805 | } |
---|
1806 | |
---|
1807 | if (YDispCost==2) //LAST |
---|
1808 | { curtop = time((time_t *)NULL); |
---|
1809 | printf(" >>> at iter %3ld after %lds: Total cost = % -23.15e\n", YItRun, curtop-Ytop0, YTotalCost); |
---|
1810 | } |
---|
1811 | } |
---|
1812 | |
---|
1813 | /* ---------------------------------------------------------------------------- |
---|
1814 | //============================ FONCTIONS BACKWARD ========================== */ |
---|
1815 | int Ybackward_elect() |
---|
1816 | { int wi; |
---|
1817 | int candidat = -1; |
---|
1818 | float wtime = -MYMAXREEL; //DBL_MAX; //999999; |
---|
1819 | float wprectime; |
---|
1820 | |
---|
1821 | for (wi=YNBTRAJ-1; wi>=0; --wi) |
---|
1822 | { wprectime = YTabTraj[wi].curtime - YTabTraj[wi].dtime; |
---|
1823 | if (wprectime > wtime |
---|
1824 | && YTabTraj[wi].toptime > YTabTraj[wi].nbuptime |
---|
1825 | && YTabTraj[wi].isactiv |
---|
1826 | //&& YTabTraj[wi].curtime > Ybegintime ...!? ARAR |
---|
1827 | ) |
---|
1828 | { candidat = wi; |
---|
1829 | wtime = wprectime; |
---|
1830 | } |
---|
1831 | } |
---|
1832 | return(candidat); |
---|
1833 | } |
---|
1834 | /*---------------------------------------------------------------------------*/ |
---|
1835 | void Ybackward(int itraj, int topstop) //meme principe que forward |
---|
1836 | { int itrajelue, wi; |
---|
1837 | |
---|
1838 | /* passe arriere sur l'ensemble du modele global (i.e. sur ttes les trajectoires ) |
---|
1839 | de la ou on est positionned ! */ |
---|
1840 | |
---|
1841 | //YCaseCost = COSTL2_GRAD; //opera |
---|
1842 | |
---|
1843 | for (wi=0; wi<YNBTRAJ; ++wi) /* init des pointeurs des arbo d'observations */ |
---|
1844 | { YTabTraj[wi].TRobs = YTabTraj[wi].YRobs->fils; //TRobs = YRobs->fils; |
---|
1845 | } |
---|
1846 | |
---|
1847 | /* passe arriere sur tout le modele global (i.e. sur ttes les trajectoires ) */ |
---|
1848 | while ((itrajelue=Ybackward_elect()) >= 0) // le while controle la progression |
---|
1849 | { //ici, on ne recule QUE d'UN PDT sur la trajectoire selectionnee ! |
---|
1850 | YidTraj = itrajelue; //(ctx pour les modules par exemple) |
---|
1851 | YTemps = YTabTraj[itrajelue].toptime; //(ctx pour les modules par exemple) |
---|
1852 | if (itrajelue==itraj && YTemps <= topstop) return; //eventuel arret sur une traj de ref |
---|
1853 | |
---|
1854 | {--YTemps; --YTabTraj[itrajelue].toptime; //<-: --YTemps |
---|
1855 | YTabTraj[itrajelue].curtime -= YTabTraj[itrajelue].dtime; //<-: multi |
---|
1856 | YNBUPTIME = YTabTraj[itrajelue].nbuptime; |
---|
1857 | } |
---|
1858 | if (YDispTime) |
---|
1859 | { printf (" >>> Traj %s, Current backward time = %i \n", YTabTraj[itrajelue].name, YTemps+1); |
---|
1860 | //Ydispcurstep(itrajelue); |
---|
1861 | } |
---|
1862 | |
---|
1863 | backward_before (0); /* arar *//* doit obligatoirement exister ds le user's global ? */ |
---|
1864 | /*---------------------*/ |
---|
1865 | if (YTypeCost == COST_APPLI) /* l'utilisateur devra prendre totalement */ |
---|
1866 | cost_function (YTemps); /* en charge le calcul du cout ! */ |
---|
1867 | else |
---|
1868 | { TRobs = YTabTraj[itrajelue].TRobs; /* on se positionne sur le top d'obs courant de la trajectoire elue */ |
---|
1869 | //YCaseCost = COSTL2_GRAD; |
---|
1870 | //Ycobs(); /* calcul du cout au pas de temps (YTemps) courant (s'il y a lieu) */ |
---|
1871 | //YTabTraj[itrajelue].TRobs = TRobs; /* pour avancer sur cette liste des temps */ |
---|
1872 | if (TRobs!=NULL && TRobs->iind==YTemps) /* si cette traj a des obs au temps courant */ |
---|
1873 | { Ycost(); /* calcul du cout */ |
---|
1874 | YTabTraj[itrajelue].TRobs = TRobs; /* pour avancer sur cette liste des temps */ |
---|
1875 | } |
---|
1876 | } |
---|
1877 | /*---------------------*/ |
---|
1878 | YTabTraj[itrajelue].bward(0); //<-: backward_order du modele sur la trajectoire |
---|
1879 | Yrazgrad_only(itrajelue); /* apres backprop, mise a 0 du gradient pour tous les modules qui n'ont pas de temps de la trajectoire ! */ |
---|
1880 | backward_after (0); /* arar */ /* doit obligatoirement exister ds le user's global ? */ |
---|
1881 | } |
---|
1882 | } |
---|
1883 | /*................................................................................*/ |
---|
1884 | void Ybackwardrun(int itraj, int nbpdt) |
---|
1885 | { long topend; |
---|
1886 | Ytop0 = time((time_t *)NULL); |
---|
1887 | |
---|
1888 | if (YTabTraj[itraj].bward==NULL) |
---|
1889 | { printf("no backward function defined for that trajectory\n"); |
---|
1890 | return; |
---|
1891 | } |
---|
1892 | if (YTabTraj[itraj].toptime - nbpdt < YTabTraj[itraj].nbuptime) |
---|
1893 | { printf ("required backward step out of lower limit: \n"); |
---|
1894 | printf (" current top (%i) - required step (%i) < nbuptime (%i) \n", |
---|
1895 | YTabTraj[itraj].toptime, nbpdt, YTabTraj[itraj].nbuptime); |
---|
1896 | return; |
---|
1897 | } |
---|
1898 | //YCaseCost = COSTL2_GRAD; ne devrait plus etre utile ici puisque reposisionned apres par Ycost !!! |
---|
1899 | TRobs = YTabTraj[itraj].YRobs->fils; //TRobs = YRobs->fils; init du pointeur sur l'arbo des observations |
---|
1900 | |
---|
1901 | YidTraj = itraj; //(ctx pour les modules par exemple) |
---|
1902 | YTemps = YTabTraj[itraj].toptime; //(ctx pour les modules par exemple) |
---|
1903 | YNBUPTIME = YTabTraj[itraj].nbuptime; |
---|
1904 | |
---|
1905 | for (int Ywt=1; Ywt<= nbpdt; ++Ywt) |
---|
1906 | { {--YTemps; --YTabTraj[itraj].toptime; //ctx //<-: --YTemps |
---|
1907 | YTabTraj[itraj].curtime -= YTabTraj[itraj].dtime; //<-: multi |
---|
1908 | } |
---|
1909 | if (YDispTime) printf (" >>> Traj %s, Current backward time = %i \n", YTabTraj[itraj].name, YTemps+1); |
---|
1910 | backward_before(Ywt); |
---|
1911 | if (YTypeCost == COST_APPLI) |
---|
1912 | cost_function (YTemps); |
---|
1913 | //else Ycobs(); |
---|
1914 | else //si cette traj a des obs au temps courant alors calcul du cout (?) |
---|
1915 | { if (TRobs!=NULL && TRobs->iind==YTemps) |
---|
1916 | Ycost(); //nb c'est Ycost qui avance TRobs (TRobs=TRobs->frere) |
---|
1917 | YTabTraj[itraj].TRobs = TRobs; //pour avancer sur cette liste des temps: est-ce bien utile |
---|
1918 | } //puisque, ici, il n'y a qu'une trajectoire. |
---|
1919 | YTabTraj[itraj].bward(0); //<-: backward_order |
---|
1920 | Yrazgrad_only(itraj); //razgrad_only que sur la trajectoire concernee ! |
---|
1921 | backward_after(Ywt); |
---|
1922 | } |
---|
1923 | after_it(1); |
---|
1924 | |
---|
1925 | topend = time((time_t *)NULL); |
---|
1926 | printf("backward duration ....: %lds\n", topend-Ytop0); |
---|
1927 | return; |
---|
1928 | } |
---|
1929 | |
---|
1930 | |
---|
1931 | /* ---------------------------------------------------------------------------- |
---|
1932 | //============================= FONCTIONS LINWARD ========================== */ |
---|
1933 | #ifdef YO_GRADTEST |
---|
1934 | #define YO_LINWARD |
---|
1935 | #endif |
---|
1936 | #ifdef YO_VARINCR |
---|
1937 | #define YO_LINWARD |
---|
1938 | #endif |
---|
1939 | #ifdef YO_LINWARD |
---|
1940 | void Ylinward(int bidon) //int bidon : pour rester compatible en attendant que tout soit termine !!! |
---|
1941 | { int itrajelue; |
---|
1942 | // passe avant lineaire sur l'ensemble du modele global (i.e. sur ttes les trajectoires ) |
---|
1943 | // de la ou on est positionned ! |
---|
1944 | while ((itrajelue=Yforward_elect()) >= 0) // le while controle la progression |
---|
1945 | { //ici, on n'avance QUE d'UN PDT sur la trajectoire selectionnee ! |
---|
1946 | |
---|
1947 | YTemps = YTabTraj[itrajelue].toptime; //(ctx pour les modules par exemple) |
---|
1948 | YidTraj = itrajelue; //(ctx pour les modules par exemple) |
---|
1949 | |
---|
1950 | if (YDispTime) printf (" >>> Traj %s, Current linward time = %i \n", YTabTraj[itrajelue].name, YTemps+1); |
---|
1951 | forward_before(0); //arar |
---|
1952 | YTabTraj[itrajelue].lward(0); //<-: linward_order |
---|
1953 | forward_after(0); //arar |
---|
1954 | {++YTabTraj[itrajelue].toptime; //<-: ++YTemps |
---|
1955 | YTabTraj[itrajelue].curtime += YTabTraj[itrajelue].dtime; //<-: multi |
---|
1956 | } |
---|
1957 | } |
---|
1958 | } |
---|
1959 | /* faut-il ou pas mettre les forward_before et forward_after ? */ |
---|
1960 | /*? plutot NON a priori car les etats sont deja calcules ! ...*/ |
---|
1961 | /* et finalement plutot OUI car qui sait si l'on aurait pas, */ |
---|
1962 | /* par exemple, besoin de forcage dans le calcul des derivees !*/ |
---|
1963 | /* et puis qui peut le + peut le - */ |
---|
1964 | #endif |
---|
1965 | /*---------------------------------------------------------------------------*/ |
---|
1966 | #ifdef YO_VARINCR |
---|
1967 | void Yset_qteaebx() //calcul de qtea sur la partie ebauche seulement |
---|
1968 | { int wi; |
---|
1969 | for (wi=0; wi<YNBTRAJ; ++wi) |
---|
1970 | { TRobs = YTabTraj[wi].YRobs->fils; |
---|
1971 | while (TRobs != NULL) |
---|
1972 | { if (TRobs->iind < 0) |
---|
1973 | { Yrovobs_TR(TRobs, Yc_dstar_all, 9); |
---|
1974 | } |
---|
1975 | TRobs = TRobs->frere; |
---|
1976 | } |
---|
1977 | } |
---|
1978 | } |
---|
1979 | /*---------------------------------------------------------------------------*/ |
---|
1980 | void Ylinward_flopobs(int bidon) //int bidon : pour rester compatible en attendant que tout soit termine !!! |
---|
1981 | { //YLINWARD sur le modele +, et en passant, si y'a des obs pour un modules : |
---|
1982 | // Forward+Linward des OPerateurs associed aux modules qui ont des OBS |
---|
1983 | int itrajelue, wi; |
---|
1984 | |
---|
1985 | for (wi=0; wi<YNBTRAJ; ++wi) /* init des pointeurs des arbo d'observations */ |
---|
1986 | { YTabTraj[wi].TRobs = YTabTraj[wi].YRobs->fils; //TRobs = YRobs->fils; |
---|
1987 | } |
---|
1988 | |
---|
1989 | /* passe avant lineaire sur l'ensemble du modele global (i.e. sur ttes les trajectoires ) |
---|
1990 | de la ou on est positionned ! */ |
---|
1991 | while ((itrajelue=Yforward_elect()) >= 0) // le while controle la progression |
---|
1992 | { //ici, on n'avance QUE d'UN PDT sur la trajectoire selectionnee ! |
---|
1993 | |
---|
1994 | YTemps = YTabTraj[itrajelue].toptime; //(ctx pour les modules par exemple) |
---|
1995 | YidTraj = itrajelue; //(ctx pour les modules par exemple) |
---|
1996 | |
---|
1997 | if (YDispTime) printf (" >>> Traj %s, Current linward time = %i \n", YTabTraj[itrajelue].name, YTemps+1); |
---|
1998 | forward_before(0); //arar |
---|
1999 | YTabTraj[itrajelue].lward(0); //<-: linward_order |
---|
2000 | |
---|
2001 | /* because opera ... */ |
---|
2002 | TRobs = YTabTraj[itrajelue].TRobs; /* on se positionne sur le top d'obs courant de la trajectoire elue */ |
---|
2003 | if (TRobs!=NULL && TRobs->iind==YTemps) /* si cette traj a des obs au temps courant */ |
---|
2004 | { |
---|
2005 | Yact_operator('*', OFF); |
---|
2006 | YCaseCost = WISHL2_NANACT; /* pour WISH: ca mettra NAN (niveau module) */ |
---|
2007 | Ycobs_TR(TRobs->fils); /* puis ca active les operateurs associed au module (H, R, ...) */ |
---|
2008 | |
---|
2009 | Yforward_operator('H'); /* il faut faire forward avant pour avoir les etats H(M(x)) ensuite on peut faire linward */ |
---|
2010 | Ylinward_operator('H'); /* je ne lance pas les autres operateurs (B,R,K) car ce sont des operateurs de covariance |
---|
2011 | dont les modules ne devraient pas etre cout (bien que plm, ce n'est pas verified) */ |
---|
2012 | Yrovobs_TR(TRobs, Yc_dstar_all, 0); /* pour calculer qtea=H'M'(Xk).dx - (y° - H(M(Xk)) */ |
---|
2013 | YTabTraj[itrajelue].TRobs = TRobs->frere; /* pour avancer sur cette liste des temps */ |
---|
2014 | } |
---|
2015 | |
---|
2016 | forward_after(0); //arar |
---|
2017 | {++YTabTraj[itrajelue].toptime; //<-: ++YTemps |
---|
2018 | YTabTraj[itrajelue].curtime += YTabTraj[itrajelue].dtime; //<-: multi |
---|
2019 | } |
---|
2020 | } |
---|
2021 | } |
---|
2022 | /* faut-il ou pas mettre les forward_before et forward_after ? */ |
---|
2023 | /*? plutot NON a priori car les etats sont deja calcules ! ...*/ |
---|
2024 | /* et finalement plutot OUI car qui sait si l'on aurait pas, */ |
---|
2025 | /* par exemple, besoin de forcage dans le calcul des derivees !*/ |
---|
2026 | /* et puis qui peut le + peut le - */ |
---|
2027 | #endif |
---|
2028 | /* ---------------------------------------------------------------------------- |
---|
2029 | //================================= Iteration de base ====================== */ |
---|
2030 | /* |
---|
2031 | void old_Ybasic_it() |
---|
2032 | { |
---|
2033 | long curtop; |
---|
2034 | |
---|
2035 | Yset_modeltime(0); |
---|
2036 | before_it(YItRun); // doit obligatoirement exister ds le user's global ? |
---|
2037 | |
---|
2038 | if(YAL2Run==RUNL2_STD) |
---|
2039 | Yforward (-1, 0); //Yforward (YNBSTEPTIME); |
---|
2040 | #ifdef YO_VARINCR |
---|
2041 | else if(YAL2Run==RUNL2_INCR) |
---|
2042 | { |
---|
2043 | Yset_qteaebx(); //pour calculer qtea sur la partie ebauche |
---|
2044 | Ylinward_flopobs(0); //Lineaire tangent pour calculer qtea=H'M'(Xk).dx - (y° - H(M(Xk)) sur la trajectoire |
---|
2045 | } |
---|
2046 | #endif |
---|
2047 | |
---|
2048 | Yrazgrad_all(); // avant fct de cout et backprop : sur tous les pas de temps, raz de tous les gradients de tous les modules |
---|
2049 | //YTotalCost = YTotGrCost = 0.0; // Raz aussi du Cout et de son Gradient total avant les calculs de cout |
---|
2050 | YTotalCost = 0.0; // Raz aussi du Cout avant les calculs de cout |
---|
2051 | Ybackward(-1, 0); // Ybackward (YNBSTEPTIME);// AD (adjoint):-> d*x =M*(X).dX : Yjac * YG -> Ytbeta |
---|
2052 | |
---|
2053 | // calcul du cout et gradient sur les termes d'ebauches et obs initiales |
---|
2054 | if (YTypeCost==COST_APPLI) // l'utilisateur devra prendre totalement |
---|
2055 | cost_function (-1); //(YUPTIME-1); // en charge le calcul du cout ! (partie<uptime) |
---|
2056 | else |
---|
2057 | { //Ycobx(); calcul du cout et gradient sur les termes d'ebauches et obs initiales |
---|
2058 | Ycostebx(); // calcul du cout et gradient sur les termes d'ebauches et obs initiales |
---|
2059 | } |
---|
2060 | |
---|
2061 | if (YDispCost==2) //LAST |
---|
2062 | { curtop = time((time_t *)NULL); |
---|
2063 | printf(" >>> at iter %3ld after %lds: Total cost = % -23.15e\n", YItRun, curtop-Ytop0, YTotalCost); |
---|
2064 | } |
---|
2065 | |
---|
2066 | if(YAL1Run==RUNL1_STD) |
---|
2067 | { if(YAL2Run==RUNL2_STD) |
---|
2068 | Yadjust(); |
---|
2069 | #ifdef YO_VARINCR |
---|
2070 | else if(YAL2Run==RUNL2_INCR) |
---|
2071 | Yc_adjustd(); |
---|
2072 | #endif |
---|
2073 | after_it(YItRun); // doit obligatoirement exister ds le user's global ? |
---|
2074 | } |
---|
2075 | } ----------------------------------------------------------------------------*/ |
---|
2076 | void Ybasic_it() |
---|
2077 | { |
---|
2078 | long curtop; |
---|
2079 | |
---|
2080 | double sumJ = 0.0; /* cumul (summation) de la fonction de cout J (i.e. YTotalCost) */ |
---|
2081 | YREAL *TGSumTarget=NULL; /* Tableau de cumul (SUMmation) des Gradients des Target */ |
---|
2082 | |
---|
2083 | before_it(YItRun); /* doit obligatoirement exister ds le user's global ? */ |
---|
2084 | |
---|
2085 | if (YNbBasicIntL>1) |
---|
2086 | { //YREAL *TGSumTarget=new YREAL[YSIZEPB]; // nb: ne pas declarer TGSumTarget ici, sinon ce reste local au if {!!!} |
---|
2087 | TGSumTarget = new (std::nothrow) YREAL[YSIZEPB]; // tableau de cumul des gradient des variables a controler |
---|
2088 | if (TGSumTarget==NULL){printf("Yao=>ABORT: pb on new TabYG in Ybasic_it (see Yao system administrator)\n"); exit(-9);} |
---|
2089 | memset(TGSumTarget, 0, YSIZEPB*sizeof(YREAL)); |
---|
2090 | } |
---|
2091 | |
---|
2092 | //for (int YItBasicIntL=1; YItBasicIntL<=YNbBasicIntL; ++YItBasicIntL) //BASIC INTERN LOOP ...................... |
---|
2093 | // |_> was local !!! |
---|
2094 | for (YItBasicIntL=1; YItBasicIntL<=YNbBasicIntL; ++YItBasicIntL) //BASIC INTERN LOOP ...................... |
---|
2095 | { |
---|
2096 | Yset_modeltime(0); |
---|
2097 | //before_it(YItRun); /* doit obligatoirement exister ds le user's global ? */ |
---|
2098 | |
---|
2099 | if(YAL2Run==RUNL2_STD) |
---|
2100 | Yforward (-1, 0); //Yforward (YNBSTEPTIME); |
---|
2101 | #ifdef YO_VARINCR |
---|
2102 | else if(YAL2Run==RUNL2_INCR) |
---|
2103 | { //nb:dans le cas incremental, le forward est supposed avoir deja ete fait par Yforwardcost dans la boucle externe |
---|
2104 | Yset_qteaebx(); //pour calculer qtea sur la partie ebauche (qtea = dx-(Xb-Xk) = YGo-(Xb-YSo)) |
---|
2105 | Ylinward_flopobs(0); //Lineaire tangent pour calculer qtea=H'M'(Xk).dx - (y° - H(M(Xk)) sur la trajectoire |
---|
2106 | } |
---|
2107 | #endif |
---|
2108 | |
---|
2109 | Yrazgrad_all(); /* avant fct de cout et backprop : sur tous les pas de temps, raz de tous les gradients de tous les modules */ |
---|
2110 | YTotalCost = 0.0; /* Raz aussi du Cout avant les calculs de cout */ |
---|
2111 | Ybackward(-1, 0); // Ybackward (YNBSTEPTIME);/* AD (adjoint):-> d*x =M*(X).dX : Yjac * YG -> Ytbeta */ |
---|
2112 | |
---|
2113 | /* calcul du cout et gradient sur les termes d'ebauches et obs initiales */ |
---|
2114 | if (YTypeCost==COST_APPLI) /* l'utilisateur devra prendre totalement */ |
---|
2115 | cost_function (-1); //(YUPTIME-1); /* en charge le calcul du cout ! (partie<uptime) */ |
---|
2116 | else |
---|
2117 | { //Ycobx(); calcul du cout et gradient sur les termes d'ebauches et obs initiales |
---|
2118 | Ycostebx(); /* calcul du cout et gradient sur les termes d'ebauches et obs initiales */ |
---|
2119 | } |
---|
2120 | |
---|
2121 | if (YNbBasicIntL>1) |
---|
2122 | { sumJ += YTotalCost; //cumul de la fonction de cout |
---|
2123 | //cumul des gradients |
---|
2124 | Y3windice=0; |
---|
2125 | YgradCTOtab_target(TGSumTarget); /* Cumul de YGo dans [TGSumTarget] */ |
---|
2126 | } |
---|
2127 | } //FIN INTERN LOOP .................................................................. |
---|
2128 | |
---|
2129 | if (YNbBasicIntL>1) |
---|
2130 | { //on transfert les cumuls de la fonction de cout dans la fonction de cout |
---|
2131 | YTotalCost = sumJ; |
---|
2132 | //on transfert les cumuls des gradients dans les zones YG |
---|
2133 | Y3windice=0; |
---|
2134 | YtabTOgrad_target(TGSumTarget); |
---|
2135 | if (YDispCost==ON) //=1 |
---|
2136 | { //curtop = time((time_t *)NULL); on affiche le cout cumule |
---|
2137 | printf(" >>> Cumul Total cost after basic internal loop = % -23.15e\n", YTotalCost); |
---|
2138 | } |
---|
2139 | } |
---|
2140 | |
---|
2141 | if (YDispCost==2) //LAST |
---|
2142 | { curtop = time((time_t *)NULL); |
---|
2143 | printf(" >>> at iter %3ld after %lds: Total cost = % -23.15e\n", YItRun, curtop-Ytop0, YTotalCost); |
---|
2144 | } |
---|
2145 | |
---|
2146 | if(YAL1Run==RUNL1_STD) |
---|
2147 | { if(YAL2Run==RUNL2_STD) |
---|
2148 | Yadjust(); |
---|
2149 | #ifdef YO_VARINCR |
---|
2150 | else if(YAL2Run==RUNL2_INCR) |
---|
2151 | Yc_adjustd(); |
---|
2152 | #endif |
---|
2153 | after_it(YItRun); /* doit obligatoirement exister ds le user's global ? */ |
---|
2154 | } |
---|
2155 | |
---|
2156 | if (YNbBasicIntL>1) delete[] TGSumTarget; /* on libere TGSumTarget */ |
---|
2157 | } |
---|
2158 | |
---|
2159 | /* ---------------------------------------------------------------------------- |
---|
2160 | //================================= FONCTION RUN =========================== */ |
---|
2161 | void Yrun(long Yit) |
---|
2162 | { |
---|
2163 | long topend; |
---|
2164 | Ytop0 = time((time_t *)NULL); |
---|
2165 | printf("\nstart run time: %s\n", ctime(&Ytop0)); |
---|
2166 | |
---|
2167 | YY_RUNBRK=OFF; /* pour gere le break d'un run en interactif */ |
---|
2168 | |
---|
2169 | /* YTypeMode=MODE_STD; gestion standard de l'adjust et de l'after_it */ |
---|
2170 | YAL1Run=RUNL1_STD; // Run niveau 1 standard |
---|
2171 | YAL2Run=RUNL2_STD; // Run niveau 2 standard |
---|
2172 | |
---|
2173 | for (YItRun=1; YItRun<=Yit; ++YItRun) |
---|
2174 | { Ybasic_it(); |
---|
2175 | if (YY_RUNBRK) break; |
---|
2176 | } |
---|
2177 | printf("\nstart run time ....: %s", ctime(&Ytop0)); |
---|
2178 | topend = time((time_t *)NULL); |
---|
2179 | printf(" end run time ....: %s", ctime(&topend)); |
---|
2180 | printf(" run duration ....: %lds\n\n", topend-Ytop0); |
---|
2181 | YY_RUNBRK=ON; |
---|
2182 | } |
---|
2183 | |
---|
2184 | /* ============================================================================ |
---|
2185 | // POUR RUNNER AVEC M1QN3 ... a voir a faire (commentaires: ../omean/) */ |
---|
2186 | #ifdef YO_M1QN3 |
---|
2187 | #include "Dynmqn.h" |
---|
2188 | #endif |
---|
2189 | |
---|
2190 | /* ============================================================================ |
---|
2191 | // FONCTIONS DE TEST POUR VALIDATION */ |
---|
2192 | #ifdef YO_GRADTEST |
---|
2193 | #include "Dyntst.h" |
---|
2194 | #endif |
---|
2195 | |
---|
2196 | /* ============================================================================ |
---|
2197 | // IMPLEMENTATION POUR L'ALGO L'INCREMENTAL */ |
---|
2198 | #ifdef YO_VARINCR |
---|
2199 | /* --------------------------------------------------------------------------*/ |
---|
2200 | void Yc_run(long Yit) //runi |
---|
2201 | { |
---|
2202 | //int witraj; |
---|
2203 | int extl, intl; |
---|
2204 | long topend; |
---|
2205 | Ytop0 = time((time_t *)NULL); |
---|
2206 | printf("\nstart run time: %s\n", ctime(&Ytop0)); |
---|
2207 | |
---|
2208 | YY_RUNBRK=OFF; /* pour gere le break d'un run en interactif */ |
---|
2209 | YAL1Run=RUNL1_STD; /* run de niveau 1 standard */ |
---|
2210 | YItRun = 1; /* init increment des iteration */ |
---|
2211 | |
---|
2212 | //INITIALISATION:-------------------------------------- |
---|
2213 | //1) On suppose X(k=0) initialised par l'utilisateur (setstate ou xuserfct) |
---|
2214 | //2) On suppose que les obs (y°) et les ebauches ebx (Xb) ont ete charges (comme Nal et d'hab) |
---|
2215 | // avec loadobs, outoobs, (loadstate) outoebx |
---|
2216 | //3) On suppose que l'utilisateur a positionned avec set_pcoef et pour chaque target module, |
---|
2217 | // les %ages qui serviront a initialiser les dx (avec la fct Ysetpdelta) dans la boucle externe |
---|
2218 | |
---|
2219 | //BOUCLE EXTERNE ET INTERNE:--------------------------- |
---|
2220 | //boucle EXTERNE: ..................................... |
---|
2221 | for (extl=1; extl<=YNbExtL; ++extl) |
---|
2222 | { printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ extern loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
---|
2223 | printf(" BE:%3i", extl); |
---|
2224 | |
---|
2225 | /* A) MD (Modele Direct):-> M(Xk) : states : [X] */ |
---|
2226 | YAL2Run=RUNL2_STD; /* run de niveau 2 standard pour forwardcost*/ |
---|
2227 | Yobs_reverse_time_lists(); // inversion de l'ordre du temps (descending->ascending) |
---|
2228 | Yforwardcost(); // passe avant (=>les YS sont calculed) avec calcul du cout sur la vraie fonction |
---|
2229 | Yobs_reverse_time_lists(); // re-inversion de l'ordre du temps (ascending->descending) |
---|
2230 | YAL2Run=RUNL2_INCR; /* mais run de niveau 2 incremental pour l'incremental */ |
---|
2231 | |
---|
2232 | //B) SET de dx : ca depend de X et pcoef |
---|
2233 | //for (witraj=0; witraj<YNBTRAJ; ++witraj) |
---|
2234 | // YdeltaEQPCstate_traj(witraj, "Y#T", 0, YTabTraj[witraj].nbuptime); |
---|
2235 | YdeltaEQPCstate_target(); //V7: YdeltaEQPCstate_all ("Y#T", 0, YUPTIME); //%1 |
---|
2236 | |
---|
2237 | //C) boucle INTERNE: ................................. |
---|
2238 | for (intl=1; intl<=Yit; ++intl) |
---|
2239 | { |
---|
2240 | printf(" BI:%3i", intl); |
---|
2241 | ++YItRun; |
---|
2242 | |
---|
2243 | //0) RAZ des zones Ygrad car ils vont etre propaged par le LT. en particulier |
---|
2244 | // et initialement les modules non target doivent avoir un dx=0 (isn-it). |
---|
2245 | Yrazgrad_all(); |
---|
2246 | |
---|
2247 | //1) Transfert dans la zone Ygrad des Ydelta initialement affectes par YdeltaEQPCstate, puis ...? |
---|
2248 | // car c'est cette zone la (Ygrad) qui est propagee par le LT. |
---|
2249 | YgradEQPdelta_target(1.0); |
---|
2250 | |
---|
2251 | //---------------------- |
---|
2252 | Ybasic_it(); |
---|
2253 | //---------------------- |
---|
2254 | if (YY_RUNBRK) break; |
---|
2255 | |
---|
2256 | }//fin boucle INTERNE .............................. |
---|
2257 | |
---|
2258 | //suite boucle EXTERNE ............................. |
---|
2259 | //D) Xk+1 = Xk + dx |
---|
2260 | Yc_adjustk_all (); |
---|
2261 | |
---|
2262 | if (YY_RUNBRK) break; |
---|
2263 | |
---|
2264 | }//fin boucle EXTERNE ................................. |
---|
2265 | printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ end extern loop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
2266 | |
---|
2267 | /* cout sur la vraie fonction */ |
---|
2268 | printf(" BE:%3i", extl-1); |
---|
2269 | YAL2Run=RUNL2_STD; /* run de niveau 2 standard pour forwardcost*/ |
---|
2270 | Yobs_reverse_time_lists(); // inversion de l'ordre du temps (descending->ascending) |
---|
2271 | Yforwardcost(); // passe avant avec calcul du cout |
---|
2272 | Yobs_reverse_time_lists(); // re-inversion de l'ordre du temps (ascending->descending) |
---|
2273 | |
---|
2274 | printf("\nstart run time ....: %s", ctime(&Ytop0)); |
---|
2275 | topend = time((time_t *)NULL); |
---|
2276 | printf(" end run time ....: %s", ctime(&topend)); |
---|
2277 | printf(" run duration ....: %lds\n\n", topend-Ytop0); |
---|
2278 | YY_RUNBRK=ON; |
---|
2279 | } |
---|
2280 | |
---|
2281 | // fin du code specifique pour l'INCREMENTAL (si YO_VARINCR) |
---|
2282 | #endif |
---|
2283 | /*-------------------------------------------------------------------------- */ |
---|
2284 | |
---|
2285 | |
---|
2286 | /* ---------------------------------------------------------------------------- |
---|
2287 | //============== echantillonnage fonction de cout pour plotting ============= */ |
---|
2288 | int Ysampleof(char *modP, double Pinf, double Psup, double dP, |
---|
2289 | char *modQ, double Qinf, double Qsup, double dQ, char *nmfile) |
---|
2290 | { |
---|
2291 | FILE *fpout; |
---|
2292 | int iPmod, iQmod; |
---|
2293 | YREAL Pval, Qval, SUPP, SUPQ; |
---|
2294 | long topend; |
---|
2295 | int iP=0, iQ=0; |
---|
2296 | int iPtraj, iQtraj; /* indices des trajectoires des modules */ |
---|
2297 | |
---|
2298 | /* INIT et VERIF */ |
---|
2299 | iPmod = Yimod(modP); |
---|
2300 | iQmod = Yimod(modQ); |
---|
2301 | |
---|
2302 | if (iPmod<0 || iQmod<0) |
---|
2303 | { printf("sampleof(i): unknown module (%s or %s)\n", modP, modQ); |
---|
2304 | return(0); |
---|
2305 | } |
---|
2306 | |
---|
2307 | if (iPmod==iQmod) |
---|
2308 | { printf("sampleof(i): Oh Oh! a modul with it-self !!! \n"); |
---|
2309 | } |
---|
2310 | |
---|
2311 | /*if (YioInsertObsCtr == -1) // il faut des obs pour pouvoir calculer un cout ! |
---|
2312 | { printf("sampleof(i): you may had load obs\n"); |
---|
2313 | return(0); |
---|
2314 | } cf ci-dessous */ |
---|
2315 | |
---|
2316 | if (Pinf>Psup || Qinf>Qsup) |
---|
2317 | { printf("sampleof(i): sup values must be greater (or equal) than inf values\n"); |
---|
2318 | return(0); |
---|
2319 | } |
---|
2320 | |
---|
2321 | if (dP<=0. || dQ<=0.) //pour pas boucler |
---|
2322 | { printf("sampleof(i): step values must be greater than 0\n"); |
---|
2323 | return(0); |
---|
2324 | } |
---|
2325 | |
---|
2326 | if ((fpout = fopen(nmfile, "w")) <= 0) |
---|
2327 | { printf ("sampleof(i): open file %s failed \n", nmfile); |
---|
2328 | return (0); |
---|
2329 | } |
---|
2330 | |
---|
2331 | Ytop0 = time((time_t *)NULL); |
---|
2332 | printf("\nstart sampleof(i) time: %s\n", ctime(&Ytop0)); |
---|
2333 | |
---|
2334 | iPtraj = Yitrajimod(iPmod); /* indice des traj */ |
---|
2335 | iQtraj = Yitrajimod(iQmod); /* des modules */ |
---|
2336 | |
---|
2337 | //Yobs_reverse_time_lists(); //inversion de l'ordre du temps -> ascending |
---|
2338 | if (Yobs_reverse_time_lists()==0) //inversion de l'ordre du temps -> ascending |
---|
2339 | { // il faut des obs pour pouvoir calculer un cout ! |
---|
2340 | printf("sampleof(i): you may had load obs\n"); |
---|
2341 | return(0); |
---|
2342 | } |
---|
2343 | YItRun =1; |
---|
2344 | |
---|
2345 | if (YAL2Run==RUNL2_INCR) |
---|
2346 | { Yset_modeltime(0); |
---|
2347 | before_it(YItRun); |
---|
2348 | Yforward(-1,0); //hyp:Xo initialised et on calcule YS pour avoir YSn = M(Xo) |
---|
2349 | } |
---|
2350 | |
---|
2351 | /* boucle de calcul du cout pour chaque couple de valeur sur la plage donnee */ |
---|
2352 | Qval = Qinf; |
---|
2353 | iQ = 0; |
---|
2354 | SUPQ = Qsup + (Qsup * 1.0e-16); //pb of machine precision !!?? |
---|
2355 | while (Qval <= SUPQ) |
---|
2356 | { if (YAL2Run==RUNL2_STD) |
---|
2357 | Ysetstate_mod (modQ, Qval); |
---|
2358 | #ifdef YO_VARINCR |
---|
2359 | else if (YAL2Run==RUNL2_INCR) |
---|
2360 | YgradEQval_traj(iQtraj, modQ, YTabMod[iQmod].deb_target, YTabMod[iQmod].end_target, Qval); |
---|
2361 | #endif |
---|
2362 | Pval = Pinf; |
---|
2363 | iP = 0; |
---|
2364 | SUPP = Psup + (Psup * 1.0e-16); //pb of machine precision !!?? |
---|
2365 | while (Pval <= SUPP) |
---|
2366 | { |
---|
2367 | if (YAL2Run==RUNL2_STD) |
---|
2368 | Ysetstate_mod (modP, Pval); |
---|
2369 | #ifdef YO_VARINCR |
---|
2370 | else if (YAL2Run==RUNL2_INCR) |
---|
2371 | YgradEQval_traj(iPtraj, modP, YTabMod[iPmod].deb_target, YTabMod[iPmod].end_target, Pval); |
---|
2372 | #endif |
---|
2373 | Yforwardcost(); //calcul du cout en passe avant |
---|
2374 | ++YItRun; |
---|
2375 | //fprintf(fpout, "%e \t", YTotalCost);fflush(fpout); |
---|
2376 | fprintf(fpout, "% 23.15e \t", YTotalCost);fflush(fpout); |
---|
2377 | printf("o"); fflush(stdout); |
---|
2378 | ++iP; |
---|
2379 | Pval = Pinf + (dP * iP); |
---|
2380 | } |
---|
2381 | fprintf(fpout, "\n"); printf("\n"); |
---|
2382 | ++iQ; |
---|
2383 | Qval = Qinf + (dQ * iQ); |
---|
2384 | } |
---|
2385 | printf("sampleof(i): dim deduced: %i lines, %i columns\n", iQ, iP); |
---|
2386 | |
---|
2387 | /* On laisse les choses comme on les a trouved */ |
---|
2388 | Yobs_reverse_time_lists(); // re-inversion de l'ordre du temps -> descending |
---|
2389 | |
---|
2390 | fclose (fpout); |
---|
2391 | |
---|
2392 | //printf("\nsampleof(i): completed,\n"); |
---|
2393 | printf("sampleof(i) start time ....: %s", ctime(&Ytop0)); |
---|
2394 | topend = time((time_t *)NULL); |
---|
2395 | printf(" sampleof(i) end time ....: %s", ctime(&topend)); |
---|
2396 | printf(" sampleof(i) duration ....: %lds\n\n", topend-Ytop0); |
---|
2397 | |
---|
2398 | return (1); |
---|
2399 | } |
---|
2400 | /*-------------------------------------------------------------------------- */ |
---|
2401 | /* ///////////////////////////////////////////////////////////////////////// */ |
---|
2402 | |
---|
2403 | |
---|
2404 | |
---|
2405 | |
---|
2406 | /* //////////////////////////////////////////////////////////////////////////// |
---|
2407 | //============================== INTERPRETEUR ================================= |
---|
2408 | // PROCEDURE RUN : c'est un interpréteur de fichier d'instructions !!! |
---|
2409 | // ou de commandes intercatives !!! |
---|
2410 | //============================================================================= |
---|
2411 | //////////////////////////////////////////////////////////////////////////// */ |
---|
2412 | /* SOME PROTOTYPAGE */ |
---|
2413 | //int Yrecup_cde (int *cdesc, char *cdeline, char *cdes[]); -> Dynamo.h |
---|
2414 | int Yinterprete_cde(int cdesc, char *cdes[]); |
---|
2415 | /* SOME OTHER GLOABLE */ |
---|
2416 | int Yrecurlev=0; /* niveau d'appel recursif de load_inst */ |
---|
2417 | int Yerr1tpret=0; /* flag d'erreur */ |
---|
2418 | char cdeline[BUFSIZE + 1]; /* ligne de commande lue */ |
---|
2419 | char *pcdeline; /* pointeur sur la ligne de commande lue */ |
---|
2420 | char *cdes[NB_MAX_ARG_CDE]; /* tableau des arguments de la commande */ |
---|
2421 | int cdesc; /* nombre d'argument de la commande */ |
---|
2422 | |
---|
2423 | /* __________________________________________________________________________*/ |
---|
2424 | void Ysignal(int isig) |
---|
2425 | { /* interception de ctrl C pour breaker un run en cours */ |
---|
2426 | if (YY_RUNBRK) exit(0); |
---|
2427 | printf("Break required; will act at next iteration\n"); |
---|
2428 | YY_RUNBRK=ON; |
---|
2429 | } |
---|
2430 | |
---|
2431 | /* __________________________________________________________________________*/ |
---|
2432 | int Yload_inst (FILE *fpinst, char *nmfile, int *nbenrlus) |
---|
2433 | { /* lecture et execution des instructions qui sont dans le fichier nmfile */ |
---|
2434 | int goinglabel=0; |
---|
2435 | char label[LG_MAX_NAME+1]; |
---|
2436 | int wi; |
---|
2437 | |
---|
2438 | while (fgets (cdeline, BUFSIZE, fpinst) != NULL) |
---|
2439 | { |
---|
2440 | ++*nbenrlus; |
---|
2441 | |
---|
2442 | if (cdeline[strlen(cdeline)-1] == '\n') |
---|
2443 | cdeline[strlen(cdeline)-1] = '\0'; |
---|
2444 | /* ?strupr(cdeline); */ |
---|
2445 | pcdeline = cdeline; |
---|
2446 | |
---|
2447 | /* positionnement en debut de ligne. i.e.: 1er caractere significatif */ |
---|
2448 | while (pcdeline[0] == ' ' || pcdeline[0] == '\t') ++pcdeline; |
---|
2449 | |
---|
2450 | if (pcdeline[0] == '#') /* commentaire en debut de ligne (#) */ |
---|
2451 | continue; |
---|
2452 | |
---|
2453 | wi=0; /* commentaire en fin de ligne (|)*/ |
---|
2454 | while (pcdeline[wi]!='\0') |
---|
2455 | { if (pcdeline[wi]=='|') {pcdeline[wi]='\0'; break;} |
---|
2456 | ++wi; |
---|
2457 | } |
---|
2458 | |
---|
2459 | if (pcdeline[0] == '!' && !goinglabel) /* commande systeme */ |
---|
2460 | { system (&pcdeline[1]); |
---|
2461 | continue; |
---|
2462 | } |
---|
2463 | if (YEcho && !goinglabel) printf ("Yao#>%s\n", cdeline); |
---|
2464 | if (!Yrecup_cde (&cdesc, pcdeline, cdes)) |
---|
2465 | { printf ("inst: file %s, commande %s, ligne %i : error found=>stop \n", nmfile, cdes[0], *nbenrlus); |
---|
2466 | return(0); |
---|
2467 | } |
---|
2468 | if (cdesc == 0) |
---|
2469 | continue; |
---|
2470 | |
---|
2471 | /* traitement d'un goto label */ |
---|
2472 | if (goinglabel) |
---|
2473 | { if (!strcmp(cdes[0], label)) goinglabel=0; |
---|
2474 | continue; |
---|
2475 | } |
---|
2476 | if (!strcmp(cdes[0], "GOTO") || !strcmp(cdes[0], "goto")) |
---|
2477 | { if (cdesc != 2) |
---|
2478 | { printf("inst: file %s, line %i, goto must be folling by one label \n", nmfile, *nbenrlus); |
---|
2479 | return (0); |
---|
2480 | } |
---|
2481 | strcpy(label, cdes[1]); |
---|
2482 | goinglabel = 1; |
---|
2483 | continue; |
---|
2484 | } |
---|
2485 | |
---|
2486 | /* inserer ici (si besoin) un upercase de l'instruction (cdes[0]) */ |
---|
2487 | if (!Yinterprete_cde(cdesc, cdes)) |
---|
2488 | { if(!Yerr1tpret) |
---|
2489 | printf ("inst: file %s, commande %s, ligne %i : error found=>stop \n", nmfile, cdes[0], *nbenrlus); |
---|
2490 | Yerr1tpret=1; |
---|
2491 | return(0); |
---|
2492 | } |
---|
2493 | } |
---|
2494 | |
---|
2495 | fclose(fpinst); |
---|
2496 | return(1); |
---|
2497 | } |
---|
2498 | |
---|
2499 | /* ============================================================================ |
---|
2500 | // LE PROGRAMME MAIN IT-SELF """"""""""""""""""""""""""""""""""""""""""""""" */ |
---|
2501 | int Yboot_appli (int argc, char *argv[]) |
---|
2502 | { |
---|
2503 | int wi; /* variable de travail local (indice de boucle, ...) */ |
---|
2504 | |
---|
2505 | /* SOME INIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
---|
2506 | Yszint = sizeof(int); /* taille d'un int */ |
---|
2507 | Yszreal = sizeof(YREAL); /* taille d'un reel pour les states (...) {float ou double} */ |
---|
2508 | srand( (unsigned)time( NULL ) ); |
---|
2509 | YDispTime = OFF; |
---|
2510 | YDispCost = OFF; |
---|
2511 | sprintf(YPrompt, "Yao:%s> ", PRJNAME); |
---|
2512 | |
---|
2513 | for (wi=0; wi<YNBTRAJ; ++wi) |
---|
2514 | { YTabTraj[wi].YRobs = (struct Yst_nodo*) malloc(sizeof(struct Yst_nodo)); /* init du Root des arborescences */ |
---|
2515 | YTabTraj[wi].YRobs->frere = YTabTraj[wi].YRobs->fils = NULL; /* d'observations pour chaque trajectoire */ |
---|
2516 | } |
---|
2517 | |
---|
2518 | memset(Yting, 0, YMAX_NBI*sizeof(YREAL)); // y'avait double au lieu |
---|
2519 | //memset(Yjac, 0, YMAX_NBS*YMAX_NBI*sizeof(YREAL)); // de YREAL et ca provoquait |
---|
2520 | memset(Yjac, 0, YMAX_JAC_NBS*YMAX_JAC_NBI*sizeof(YREAL)); // de YREAL et ca provoquait |
---|
2521 | memset(Ytbeta, 0, YMAX_NBI*sizeof(YREAL)); // un plantage quand on etait en float !!! |
---|
2522 | |
---|
2523 | /* pour intercepter ctrl C lors d'un run et l'arreter */ |
---|
2524 | signal(SIGINT, Ysignal); |
---|
2525 | |
---|
2526 | /* message de demarrage */ |
---|
2527 | printf ("\nStarting Yao : %s ", VERREF); |
---|
2528 | printf ("\nProject %s. \n(You are in ", PRJNAME); |
---|
2529 | if (sizeof(YREAL)==sizeof(double)) printf("double mode)\n"); else printf("float mode)\n"); |
---|
2530 | |
---|
2531 | #ifdef PARALLEL |
---|
2532 | cout << "This is a parallel version of the application, the max number of threads that the system supports are: " |
---|
2533 | << omp_get_max_threads() << "." << endl; |
---|
2534 | #endif |
---|
2535 | |
---|
2536 | /* CREATION DU MODELE: (le fait on systématiquement ou est-ce au user de */ |
---|
2537 | Ycreate_all (); /* le mettre dans les instructions? Quid Initialiser? */ |
---|
2538 | |
---|
2539 | /* Une fonction de demarrage pour l'appli specifique du user; */ |
---|
2540 | appli_start (argc, argv); |
---|
2541 | |
---|
2542 | return (0); |
---|
2543 | } |
---|
2544 | /*----------------------------------*/ |
---|
2545 | int Yentry1 (int argc, char *argv[]); //prototypage de Yentry1 qui prolonge Yentry0 ! |
---|
2546 | int Yentry0 (int argc, char *argv[]) |
---|
2547 | { |
---|
2548 | /* l'ancienne syntaxe etait : |
---|
2549 | // prjname :=> execution en batch avec le fichier prjname.i |
---|
2550 | // ou prjname nmfile :=> execution en batch avec le fichier nmfile |
---|
2551 | // ou prjname [] [-i] :=> execution en mode interactif */ |
---|
2552 | /* NOUVELLE SYNTAXE : |
---|
2553 | prjname [...] [-b -e -i [fichier_d'instruction]] |
---|
2554 | OPTION : |
---|
2555 | -b : boot de l'appli ((some init, Creat, appli_start) |
---|
2556 | sans execution d'instruction aucune. |
---|
2557 | -e : execution d'instructions (cf ci-apres) ce qui suppose que |
---|
2558 | le boot de l'appli (option -b) est deja fait. |
---|
2559 | Par defaut : -b et -e |
---|
2560 | |
---|
2561 | -i [nmfile] |
---|
2562 | si nmfile n'est pas fourni |
---|
2563 | alors : on execute en mode Interactif |
---|
2564 | si nmfile est fourni et qu'il ne correspond pas a un fichier existant |
---|
2565 | alors : on execute en mode Interactif |
---|
2566 | si nmfile est fourni et qu'il correspond a un fichier qui existe |
---|
2567 | alors : l'appli est lancee en Batch avec nmfile pour fichier d'instructions |
---|
2568 | Par defaut : on essaie de lancer en Batch avec prjname.i si il existe, sinon -> erreur |
---|
2569 | */ |
---|
2570 | /* gestion des options */ |
---|
2571 | int optb=0, opte=0, opti=0; |
---|
2572 | int wi=0; |
---|
2573 | while (wi<argc) //boucle de positionnement des options |
---|
2574 | { if (!strcmp(argv[wi], "-b")) |
---|
2575 | { optb=1; |
---|
2576 | } |
---|
2577 | else if (!strcmp(argv[wi], "-e")) |
---|
2578 | { opte=1; |
---|
2579 | } |
---|
2580 | else if (!strcmp(argv[wi], "-i")) |
---|
2581 | { opti=wi; //ici, on memorise l'indice de l'argument |
---|
2582 | } |
---|
2583 | ++wi; |
---|
2584 | } |
---|
2585 | /* gestion des options */ |
---|
2586 | if (optb==0 && opte==0) |
---|
2587 | { //par defaut :-> b et e |
---|
2588 | optb=opte=1; |
---|
2589 | } |
---|
2590 | if (opti>0 && !opte) |
---|
2591 | { //l'option -i n'a de sens que pour une execution |
---|
2592 | printf(" -i option has no sens without execution\n"); |
---|
2593 | return(0); |
---|
2594 | } |
---|
2595 | if (optb) |
---|
2596 | { Yboot_appli(argc, argv); //boot, ammorcage, init, creat de l'appli |
---|
2597 | } |
---|
2598 | //if (opti>0) //fichier d'instruction ...{} : c'est dans Yentry1 que ca se passe |
---|
2599 | if (opte) |
---|
2600 | { Yentry1(argc, argv); //execution de l'appli |
---|
2601 | } |
---|
2602 | |
---|
2603 | /* decoupage supplementaire pour pouvoir eviter d'allouer a chaque fois |
---|
2604 | un nouvel espace par Ycreate_all lorsque une appli est appeled plusieurs |
---|
2605 | fois par une autre, ... de plus, ainsi on evite que les modules soit remis |
---|
2606 | a 0 entre 2+ appels ... |
---|
2607 | Tout cela amene a definir un nouveau mode de lancement qu'on pourrait par |
---|
2608 | exemple appeler un mode de boot uniquement de l'appli : option "-b" |
---|
2609 | Donc l'option -b ne doit etre utilise qu'une et une seul fois pour toutes |
---|
2610 | puis ensuite, on devrait pouvoir utilise l'option -e autant de fois que necesaire !? */ |
---|
2611 | return(0); |
---|
2612 | } |
---|
2613 | /*----------------------------------*/ |
---|
2614 | int Yentry1 (int argc, char *argv[]) |
---|
2615 | { |
---|
2616 | char fileinst[STRSIZE80+1]; /* fichier d'instructions initial */ |
---|
2617 | FILE *fpinst=NULL; /* file pointeur du fichier d'instruction */ |
---|
2618 | int nbenrlus; /* nbr d'enr du fichier d'instruction lus */ |
---|
2619 | int wi=0; |
---|
2620 | |
---|
2621 | /* determination du mode d'execution (Interactif ou batch) et fichier d'instructions */ |
---|
2622 | YM_EXE=0; |
---|
2623 | while (wi<argc) |
---|
2624 | { //on recherche l'indication du fichier d'instruction qui desormais peut se trouver n'importe ou parmi les options |
---|
2625 | if (!strcmp(argv[wi], "-i")) |
---|
2626 | { ++wi; |
---|
2627 | if (wi<argc) |
---|
2628 | { strcpy (fileinst, argv[wi]); //le parametre qui suit -i pourrait etre un fichier d'instruction |
---|
2629 | if ((fpinst = fopen(fileinst, "r")) <= 0) //ce qui suit n'est pas un fichier qui |
---|
2630 | { YM_EXE = 'I'; //existe => mode d'execution Interactif ! |
---|
2631 | } |
---|
2632 | else //mode d'execution Batch |
---|
2633 | { YM_EXE = 'B'; |
---|
2634 | } |
---|
2635 | } |
---|
2636 | else //par d'argument apres -i => mode d'execution interactif ! |
---|
2637 | { YM_EXE = 'I'; |
---|
2638 | } |
---|
2639 | break; |
---|
2640 | } |
---|
2641 | ++wi; |
---|
2642 | } |
---|
2643 | if (YM_EXE==0) //=> -i n'a pas ete rencontre; si un fichier prjname.i existe, |
---|
2644 | { // on l'executera en mode Batch sinon erreur |
---|
2645 | sprintf (fileinst, "%s.i", PRJNAME); |
---|
2646 | if ((fpinst = fopen(fileinst, "r")) <= 0) |
---|
2647 | { printf ("instruction file %s not found \n", fileinst); |
---|
2648 | return(0); |
---|
2649 | } |
---|
2650 | YM_EXE = 'B'; |
---|
2651 | } |
---|
2652 | |
---|
2653 | /* Execution des instructions :~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
---|
2654 | if (YM_EXE=='B') |
---|
2655 | { nbenrlus=0; |
---|
2656 | ++Yrecurlev; |
---|
2657 | if (!Yload_inst(fpinst, fileinst, &nbenrlus)) // on s'arrete a la 1ere erreur, |
---|
2658 | { printf("-error found while file %s, line %i. sequence aborted \n", fileinst, nbenrlus); |
---|
2659 | exit(9); |
---|
2660 | } /* de toute facon, on s'arrete a la fin */ |
---|
2661 | } |
---|
2662 | else if (YM_EXE=='I') |
---|
2663 | { /* En mode INTERACTIF, on entre dans une boucle "sans fin..." */ |
---|
2664 | printf("\n\n"); |
---|
2665 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
---|
2666 | printf(" Yao welcome you friendly \n"); |
---|
2667 | printf(" and wish you a happy new year \n"); |
---|
2668 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); |
---|
2669 | while (1) |
---|
2670 | { printf("%s", YPrompt); /*le prompt */ |
---|
2671 | /* printf("yao> "); //le prompt */ |
---|
2672 | |
---|
2673 | /* récupération de la commande gets (cdeline); */ |
---|
2674 | fgets(cdeline, BUFSIZE, stdin); |
---|
2675 | |
---|
2676 | /* strupr (cdeline); */ |
---|
2677 | pcdeline = cdeline; |
---|
2678 | while (pcdeline[0] == ' ') ++pcdeline; |
---|
2679 | |
---|
2680 | /* commande systeme */ |
---|
2681 | if (pcdeline[0] == '!') |
---|
2682 | { system (&pcdeline[1]); |
---|
2683 | continue; |
---|
2684 | } |
---|
2685 | |
---|
2686 | /* commande yao */ |
---|
2687 | if (!Yrecup_cde(&cdesc, pcdeline, cdes)) |
---|
2688 | continue; |
---|
2689 | |
---|
2690 | if (cdesc == 0) |
---|
2691 | continue; |
---|
2692 | if (strcmp(cdes[0], "EXIT") == 0 || strcmp(cdes[0], "exit") == 0 || |
---|
2693 | strcmp(cdes[0], "QUIT") == 0 || strcmp(cdes[0], "quit") == 0 || |
---|
2694 | strcmp(cdes[0], "BYE") == 0 || strcmp(cdes[0], "bye") == 0 ) |
---|
2695 | { if (rand()%2==0) printf("\n I'LL BE BACK !\n\n"); |
---|
2696 | else printf("\n Yao c'est un truc de OUF !\n\n"); |
---|
2697 | return(0); //exit(0); |
---|
2698 | } |
---|
2699 | else |
---|
2700 | { Yerr1tpret=0; |
---|
2701 | if (!Yinterprete_cde(cdesc, cdes)) |
---|
2702 | { if (rand()%2==0) printf (" Yao, c'est plus fort que toi. \n"); |
---|
2703 | else printf (" Are you talking to me !? \n"); |
---|
2704 | } |
---|
2705 | } |
---|
2706 | } |
---|
2707 | } |
---|
2708 | else |
---|
2709 | printf ("unpossible case #@§?§???§§§\n"); |
---|
2710 | |
---|
2711 | return(0); |
---|
2712 | } |
---|
2713 | /* |
---|
2714 | int main(int argc, char *argv[]) |
---|
2715 | { PRJMAIN (argc, argv); |
---|
2716 | return(0); |
---|
2717 | } |
---|
2718 | */ |
---|
2719 | /* ========================================================================= */ |
---|
2720 | /* fonction de découpage de la commande par chaine de caractère dans un tableau */ |
---|
2721 | int Yrecup_cde (int *cdesc, char *cdeline, char *cdes[]) |
---|
2722 | { |
---|
2723 | int i; |
---|
2724 | i=strlen(cdeline) - 1; //printf("\n %i line=|%s|", i+1, cdeline); |
---|
2725 | |
---|
2726 | /* while (cdeline[i] == ' ' || cdeline[i] == '\t') --i; //je me positionne à la fin de la chaine pour y mettre '\0' */ |
---|
2727 | /* while (cdeline[i] == ' ' || cdeline[i] == '\t' || cdeline[i] == '\n') --i; //je me positionne à la fin de la chaine pour y mettre '\0' */ |
---|
2728 | /*while (cdeline[i] == '\n') --i; // je me positionne à la fin de la chaine pour y mettre '\0' */ |
---|
2729 | while (cdeline[i] == '\n' || cdeline[i] == ' ' || cdeline[i] == '\t') --i; /* je me positionne à la fin de la chaine pour y mettre '\0' */ |
---|
2730 | cdeline[i+1] = '\0'; |
---|
2731 | |
---|
2732 | i=0; /* je me repositionne au début de la chaine */ |
---|
2733 | *cdesc = 0; |
---|
2734 | while (cdeline[i] != '\0') /* tant qu'on a pas fini de balayer toute la chaine */ |
---|
2735 | { |
---|
2736 | if (*cdesc>=NB_MAX_ARG_CDE) /* verif qu'on ne depasse pas le nombre */ |
---|
2737 | { printf("too much arg in that order\n"); /* d'arguments defini */ |
---|
2738 | return(0); |
---|
2739 | } |
---|
2740 | |
---|
2741 | while (cdeline[i] == ' ' || cdeline[i] == '\t') ++i; /* je suis avant le prochain mot et je vais à sa rencontre */ |
---|
2742 | cdes[*cdesc]=&cdeline[i]; /* je suis dessus, je stock son adresse */ |
---|
2743 | ++*cdesc; /* j'incremente le nombre de mot trouves */ |
---|
2744 | |
---|
2745 | /* cas particulier pour le changement du prompt: on s'interrompt avant */ |
---|
2746 | if ((strcmp(cdes[0], "set_prompt")==0 || strcmp(cdes[0], "SET_PROMPT")==0) && (*cdesc==2)) return(1); |
---|
2747 | /* de meme, cas particulier pour le changement du separateur d'io: on s'interrompt avant */ |
---|
2748 | if ((strcmp(cdes[0], "set_iosep")==0 || strcmp(cdes[0], "SET_IOSEP")==0) && (*cdesc==2)) return(1); |
---|
2749 | |
---|
2750 | while (cdeline[i] != ' ' && cdeline[i] != '\0') |
---|
2751 | { ++i; /* j'avance sur le mot jusqu'à sa fin */ |
---|
2752 | if (cdeline[i] == '\t') break; /* (pour pouvoir passer ensuite au mot suivant) */ |
---|
2753 | } |
---|
2754 | if (cdeline[i] != '\0') |
---|
2755 | { cdeline[i] = '\0'; |
---|
2756 | ++i; |
---|
2757 | } |
---|
2758 | |
---|
2759 | } |
---|
2760 | return (1); |
---|
2761 | } |
---|
2762 | |
---|
2763 | /* ========================================================================= */ |
---|
2764 | /* fonction d'interpretation et de traduction de la commande */ |
---|
2765 | int Yinterprete_cde(int cdesc, char *cdes[]) |
---|
2766 | { |
---|
2767 | int w1, w2; |
---|
2768 | double ww1; |
---|
2769 | int codret = 1; /* init a pas d'erreur */ |
---|
2770 | |
---|
2771 | char fileinst[STRSIZE80+1]; /* un fichier d'instructions */ |
---|
2772 | FILE *fpinst; /* file pointeur du fichier d'instruction */ |
---|
2773 | int nbenrlus; /* nbr d'enr du fichier d'instruction lus */ |
---|
2774 | |
---|
2775 | int witraj; /* multi: indice de trajectoire */ |
---|
2776 | |
---|
2777 | //printf (">>>%s\n", cdes[0]); |
---|
2778 | |
---|
2779 | /* pre-traitement pour la substitution des mots definis */ |
---|
2780 | for (w1=0; w1<cdesc; ++w1) |
---|
2781 | { w2=Yisdefval(cdes[w1]); |
---|
2782 | if (w2 >=0 ) |
---|
2783 | { strcpy(cdes[w1], YTabDefval[w2].macro); |
---|
2784 | } |
---|
2785 | } |
---|
2786 | |
---|
2787 | /*---------------------------------------------------------*/ |
---|
2788 | if (strcmp(cdes[0], "LVAL") == 0 || strcmp(cdes[0], "lval") == 0) |
---|
2789 | { Ylval(); |
---|
2790 | } |
---|
2791 | else if (strcmp(cdes[0], "STRAJ") == 0 || strcmp(cdes[0], "straj") == 0) |
---|
2792 | { Ystraj(); |
---|
2793 | } |
---|
2794 | else if (strcmp(cdes[0], "PDT2PDT") == 0 || strcmp(cdes[0], "pdt2pdt") == 0) |
---|
2795 | { //syntax: pdt2pdt fromtraj steptime totraj |
---|
2796 | if (cdesc != 4) |
---|
2797 | { printf("pdt2pdt: syntax is: pdt2pdt fromtraj steptime totraj\n"); |
---|
2798 | return(1); |
---|
2799 | } |
---|
2800 | w1 = Yitraj(cdes[1]); |
---|
2801 | w2 = Yitraj(cdes[3]); |
---|
2802 | if (w1<0 || w2<0) |
---|
2803 | { printf("pdt2pdt: unknwon trajectory name (%s) or (%s) \n", cdes[1], cdes[3]); |
---|
2804 | return(0); |
---|
2805 | } |
---|
2806 | /*if (atoi(cdes[2])<=YTabTraj[w1].nbuptime) |
---|
2807 | { printf("pdt2pdt: steptime must be > nbuptime of trajectory %s\n", cdes[1]); |
---|
2808 | return(0); |
---|
2809 | } il ne s'agit ici que de verifier le comportement de la fonction de traduction Ypdt2pdt */ |
---|
2810 | printf("pdt %i [%i] of %s --is--> pdt %i [%i] for %s \n", atoi(cdes[2]), atoi(cdes[2])-1, cdes[1], |
---|
2811 | Ypdt2pdt(w2, atoi(cdes[2]), w1), Ypdt2pdt(w2, atoi(cdes[2]), w1)-1, |
---|
2812 | cdes[3]); |
---|
2813 | } |
---|
2814 | else if (strcmp(cdes[0], "SET_TOPTIME") == 0 || strcmp(cdes[0], "set_toptime") == 0) |
---|
2815 | { //syntax: set_toptime trajname integer |
---|
2816 | if (cdesc != 3) return(0); |
---|
2817 | |
---|
2818 | witraj = Yitraj(cdes[1]); |
---|
2819 | if (witraj<0) |
---|
2820 | { printf("set_toptime: unknwon trajectory name (%s) \n", cdes[1]); |
---|
2821 | return(0); |
---|
2822 | } |
---|
2823 | w1 = atoi(cdes[2]); |
---|
2824 | if (w1<YTabTraj[witraj].nbuptime || w1 >= YTabTraj[witraj].nbuptime + YTabTraj[witraj].nbsteptime) |
---|
2825 | { printf("set_toptime: value must be >=%d and <=%d\n", YTabTraj[witraj].nbuptime, |
---|
2826 | YTabTraj[witraj].nbuptime + YTabTraj[witraj].nbsteptime -1); |
---|
2827 | return(0); |
---|
2828 | } |
---|
2829 | YTabTraj[witraj].toptime = w1; |
---|
2830 | Yupdcurtime(witraj); |
---|
2831 | } |
---|
2832 | else if (strcmp(cdes[0], "SET_MODELTIME") == 0 || strcmp(cdes[0], "set_modeltime") == 0) |
---|
2833 | { |
---|
2834 | if (cdesc != 2) return(0); |
---|
2835 | w1 = atoi(cdes[1]); |
---|
2836 | if (w1!=0) |
---|
2837 | { printf("set_modeltime: work only with 0, found %s \n", cdes[1]); |
---|
2838 | return(0); |
---|
2839 | } |
---|
2840 | Yset_modeltime(w1); |
---|
2841 | } |
---|
2842 | else if (strcmp(cdes[0], "SET_NBITER") == 0 || strcmp(cdes[0], "set_nbiter") == 0) |
---|
2843 | { |
---|
2844 | if (cdesc != 2) return(0); |
---|
2845 | YNbItRun = atol(cdes[1]); |
---|
2846 | } |
---|
2847 | else if (strcmp(cdes[0], "SET_NBEXTL") == 0 || strcmp(cdes[0], "set_nbextl") == 0) |
---|
2848 | { |
---|
2849 | if (cdesc != 2) return(0); /* pas de test sur YO_VARINCR : */ |
---|
2850 | YNbExtL = atoi(cdes[1]); /* cela ne porte pa a concequence */ |
---|
2851 | } |
---|
2852 | else if (strcmp(cdes[0], "SET_NB_BASIC_INTERN_LOOP") == 0 || strcmp(cdes[0], "set_nb_basic_intern_loop") == 0) |
---|
2853 | { |
---|
2854 | if (cdesc != 2) return(0); |
---|
2855 | w1 = atoi(cdes[1]); |
---|
2856 | if (w1<=0) |
---|
2857 | { printf("the basic intern loop number must be positive \n"); |
---|
2858 | return(0); |
---|
2859 | } |
---|
2860 | YNbBasicIntL = w1; |
---|
2861 | } |
---|
2862 | else if (strcmp(cdes[0], "RUN") == 0 || strcmp(cdes[0], "run") == 0) |
---|
2863 | { |
---|
2864 | /* if (cdesc != 2) return(0); */ |
---|
2865 | if (YNbItRun<=0) |
---|
2866 | { printf("run: number of run iteration not seted; use set_nbiter please\n"); |
---|
2867 | return(0); |
---|
2868 | } |
---|
2869 | if (YioInsertObsCtr<0) |
---|
2870 | printf("run: warning : oh oh, run with no obs !!! \n"); |
---|
2871 | Yrun (YNbItRun); |
---|
2872 | } |
---|
2873 | else if (strcmp(cdes[0], "RUNI") == 0 || strcmp(cdes[0], "runi") == 0) |
---|
2874 | { |
---|
2875 | #ifdef YO_VARINCR |
---|
2876 | if (YNbItRun<=0) |
---|
2877 | { printf("runi: number of run iteration seted; use set_nbiter please\n"); |
---|
2878 | return(0); |
---|
2879 | } |
---|
2880 | if (YNbExtL<=0) |
---|
2881 | { printf("runi: number of extern loop not seted; use set_nbextl please\n"); |
---|
2882 | return(0); |
---|
2883 | } |
---|
2884 | if (YioInsertObsCtr<0) |
---|
2885 | printf("runi: warning : oh oh, run with no obs !!! \n"); |
---|
2886 | Yc_run(YNbItRun); |
---|
2887 | #else |
---|
2888 | printf("runi: incremental option (O_VARINCR) is not active \n"); |
---|
2889 | return(0); |
---|
2890 | #endif |
---|
2891 | } |
---|
2892 | else if (strcmp(cdes[0], "SET_DXALEA") == 0 || strcmp(cdes[0], "set_dxalea") == 0) |
---|
2893 | { //valorisation d'une grandeur aleatoire pour la determination de dx dans certaines fonctions de test |
---|
2894 | #ifdef YO_GRADTEST |
---|
2895 | if (cdesc == 1) //sans passage de parametre : |
---|
2896 | { Ydxalea[0] = '\0'; //-> neutralise l'alea |
---|
2897 | } |
---|
2898 | else //on prend tel quel le parametre passed ; pour bien faire, ce ne doit pas etre |
---|
2899 | { // n'importe quoi mais plm je ne controle pas ! |
---|
2900 | //je verifie seulement la longueur |
---|
2901 | if (strlen(cdes[1]) > STRSIZE20) |
---|
2902 | { printf("set_dxalea: too long parameter, max is %i \n", STRSIZE20); |
---|
2903 | return(0); |
---|
2904 | } |
---|
2905 | strcpy(Ydxalea, cdes[1]); |
---|
2906 | } |
---|
2907 | #else |
---|
2908 | printf("set_dxalea: GRADTEST option is not active \n"); |
---|
2909 | return(0); |
---|
2910 | #endif |
---|
2911 | } |
---|
2912 | else if (strcmp(cdes[0], "TESTDF") == 0 || strcmp(cdes[0], "testdf") == 0) |
---|
2913 | { //test des derivees des modules, |
---|
2914 | #ifdef YO_GRADTEST |
---|
2915 | if (sizeof(YREAL)!=sizeof(double)) |
---|
2916 | { printf("testdf: real format must be double (use option O_REAL double in .d)\n"); |
---|
2917 | return(0); |
---|
2918 | } |
---|
2919 | if (cdesc <8) |
---|
2920 | { printf("testdf error: syntaxe is : testdf i j k t codop [%c]pdx ptol [nmmod-ko-max][max]\n", '%'); |
---|
2921 | return(0); |
---|
2922 | } |
---|
2923 | Ytestdf(cdesc, cdes); |
---|
2924 | #else |
---|
2925 | printf("testdf: GRADTEST option is not active \n"); |
---|
2926 | return(0); |
---|
2927 | #endif |
---|
2928 | } |
---|
2929 | else if (strcmp(cdes[0], "TESTAD") == 0 || strcmp(cdes[0], "testad") == 0) |
---|
2930 | { //test de l'ADjoint |
---|
2931 | #ifdef YO_GRADTEST |
---|
2932 | if (sizeof(YREAL)!=sizeof(double)) |
---|
2933 | { printf("testad: real format must be double (use option O_REAL double in .d)\n"); |
---|
2934 | return(0); |
---|
2935 | } |
---|
2936 | if (cdesc == 2) |
---|
2937 | { if (YioInsertObsCtr != -1) |
---|
2938 | { printf("testad error: obs must not be used before global Adjoint test\n"); |
---|
2939 | //because: ca modifie le dy au cours de la redescente qui ne sera plus le meme |
---|
2940 | // que celui utilised lors du calcul de LTRes. |
---|
2941 | // Cette contrainte n'est pas utile pour testad_mod car le test est local. |
---|
2942 | return(0); |
---|
2943 | } |
---|
2944 | Ytestad (atof(cdes[1])); //Ytestad(atof(cdes[1]), 0.0, 0); |
---|
2945 | } |
---|
2946 | else if (cdesc == 4) |
---|
2947 | Ytestad_mod (atof(cdes[1]), atof(cdes[2]), atoi(cdes[3]), 0.0); |
---|
2948 | else if (cdesc == 5) |
---|
2949 | Ytestad_mod (atof(cdes[1]), atof(cdes[2]), atoi(cdes[3]), atof(cdes[4])); |
---|
2950 | else |
---|
2951 | { printf("testad error: syntaxe is : testad pdx [errelmax maxko][pzedi]\n"); |
---|
2952 | return(0); |
---|
2953 | } |
---|
2954 | #else |
---|
2955 | printf("testad: GRADTEST option is not active \n"); |
---|
2956 | return(0); |
---|
2957 | #endif |
---|
2958 | } |
---|
2959 | else if (strcmp(cdes[0], "TESTLT") == 0 || strcmp(cdes[0], "testlt") == 0) |
---|
2960 | { //test du Lineaire Tangent |
---|
2961 | #ifdef YO_GRADTEST |
---|
2962 | if (sizeof(YREAL)!=sizeof(double)) |
---|
2963 | { printf("testlt: real format must be double (use option O_REAL double in .d)\n"); |
---|
2964 | return(0); |
---|
2965 | } |
---|
2966 | if (cdesc==5) |
---|
2967 | Ytestlt(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atoi(cdes[4]), 1, 0); //0, 0); //default |
---|
2968 | else if (cdesc==6) |
---|
2969 | Ytestlt(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atoi(cdes[4]), atoi(cdes[5]), 0); |
---|
2970 | else if (cdesc==7) |
---|
2971 | Ytestlt(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atoi(cdes[4]), atoi(cdes[5]), atoi(cdes[6])); |
---|
2972 | else |
---|
2973 | { printf("testlt error: syntaxe is : testlt pdx alpha fdec nbloop [modop]\n"); |
---|
2974 | return(0); |
---|
2975 | } |
---|
2976 | #else |
---|
2977 | printf("testlt: GRADTEST option is not active \n"); |
---|
2978 | return(0); |
---|
2979 | #endif |
---|
2980 | } |
---|
2981 | else if (strcmp(cdes[0], "TESTOF") == 0 || strcmp(cdes[0], "testof") == 0) |
---|
2982 | { //test de l'Objective Fonction |
---|
2983 | #ifdef YO_GRADTEST |
---|
2984 | if (sizeof(YREAL)!=sizeof(double)) |
---|
2985 | { printf("testof: real format must be double (use option O_REAL double in .d)\n"); |
---|
2986 | return(0); |
---|
2987 | } |
---|
2988 | if (cdesc==5) |
---|
2989 | Ytestof(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atoi(cdes[4]), 1, 0); //0, 0); |
---|
2990 | else if (cdesc==6) |
---|
2991 | Ytestof(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atoi(cdes[4]), atoi(cdes[5]), 0); |
---|
2992 | else if (cdesc==7) |
---|
2993 | Ytestof(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atoi(cdes[4]), atoi(cdes[5]), atoi(cdes[6])); |
---|
2994 | else |
---|
2995 | { printf("testof error: syntaxe is : testof pdx alpha fdec nbloop [modop] \n"); |
---|
2996 | return(0); |
---|
2997 | } |
---|
2998 | #else |
---|
2999 | printf("testof: GRADTEST option is not active \n"); |
---|
3000 | return(0); |
---|
3001 | #endif |
---|
3002 | } |
---|
3003 | else if (strcmp(cdes[0], "FORWARD") == 0 || strcmp(cdes[0], "forward") == 0) |
---|
3004 | { //syntax: forward [trajname nbpdt] |
---|
3005 | if (cdesc!=1 && cdesc!=3) return(0); |
---|
3006 | if (cdesc==1) //forward sur le modele global: i.e du debut jusqu'a la 'fin' de |
---|
3007 | { //toutes les trajectoires sur tous les modeles (pour creer des obs par exemple) |
---|
3008 | //Yset_modeltime(0); en attendant de mettre cette instruction a disposition du user (fait pour 0) |
---|
3009 | before_it(1); |
---|
3010 | Yforward(-1, 0); |
---|
3011 | } |
---|
3012 | else //(cdesc==3) //forward trajname nbpdt: forward nbpdt sur une trajectoire particuliere |
---|
3013 | { witraj = Yitraj(cdes[1]); |
---|
3014 | if (witraj>=0) //cas de la syntaxe: forward trajname nbp :=> forward sur une traj particuliere |
---|
3015 | { w1 = atoi(cdes[2]); |
---|
3016 | if (w1<=0) |
---|
3017 | { printf("forward: bad step_time given, must be >=1\n"); |
---|
3018 | return(0); |
---|
3019 | } |
---|
3020 | Yforwardrun(witraj, w1); |
---|
3021 | } |
---|
3022 | else //cas de syntaxe: forward nbp trajname :=> trajname est la trajectoire de reference |
---|
3023 | { //pour avancer tout le modele de nbp pas de temps par rapport a cette trajectoire. |
---|
3024 | witraj = Yitraj(cdes[2]); |
---|
3025 | if (witraj<0) |
---|
3026 | { printf("forward: unknwon trajectory name (%s) \n", cdes[2]); |
---|
3027 | return(0); |
---|
3028 | } |
---|
3029 | w1 = atoi(cdes[1]); |
---|
3030 | if (w1<=0) |
---|
3031 | { printf("forward: bad step_time given, must be >=1\n"); |
---|
3032 | return(0); |
---|
3033 | } |
---|
3034 | before_it(1); |
---|
3035 | Yforward(witraj, YTabTraj[witraj].toptime + w1); |
---|
3036 | } |
---|
3037 | } |
---|
3038 | } |
---|
3039 | else if (strcmp(cdes[0], "BACKWARD") == 0 || strcmp(cdes[0], "backward") == 0) |
---|
3040 | { //syntax: backward [trajname nbpdt] |
---|
3041 | if (cdesc!=1 && cdesc!=3) return(0); |
---|
3042 | if (cdesc==1) //backward sur le modele global: i.e d'ou il est jusqu'au debut de |
---|
3043 | { //toutes les trajectoires sur tous les modeles |
---|
3044 | Ybackward(-1, 0); |
---|
3045 | after_it(1); |
---|
3046 | } |
---|
3047 | else //(cdesc==3) //2 cas possibles : |
---|
3048 | { witraj = Yitraj(cdes[1]); |
---|
3049 | if (witraj>=0) //cas de la syntaxe: backward trajname nbp :=> backward sur une traj particuliere |
---|
3050 | { w1 = atoi(cdes[2]); |
---|
3051 | if (w1<=0) |
---|
3052 | { printf("backward: bad step_time given, must be >=1\n"); |
---|
3053 | return(0); |
---|
3054 | } |
---|
3055 | Ybackwardrun(witraj, w1); |
---|
3056 | } |
---|
3057 | else //cas de syntaxe: backward nbp trajname :=> trajname est la trajectoire de reference |
---|
3058 | { //pour reculer tout le modele de nbp pas de temps par rapport a cette trajectoire. |
---|
3059 | witraj = Yitraj(cdes[2]); |
---|
3060 | if (witraj<0) |
---|
3061 | { printf("backward: unknwon trajectory name (%s) \n", cdes[2]); |
---|
3062 | return(0); |
---|
3063 | } |
---|
3064 | w1 = atoi(cdes[1]); |
---|
3065 | if (w1<=0) |
---|
3066 | { printf("backward: bad step_time given, must be >=1\n"); |
---|
3067 | return(0); |
---|
3068 | } |
---|
3069 | Ybackward(witraj, YTabTraj[witraj].toptime - w1); |
---|
3070 | after_it(1); |
---|
3071 | } |
---|
3072 | } |
---|
3073 | } |
---|
3074 | else if ( strcmp(cdes[0], "ACTIV") == 0 || strcmp(cdes[0], "activ") == 0 |
---|
3075 | || strcmp(cdes[0], "UNACTIV") == 0 || strcmp(cdes[0], "unactiv") == 0 ) |
---|
3076 | { //syntax: {activ, unactiv} {trajname ,typetraj} [{trajname ,typetraj}[...]] [only] |
---|
3077 | //exemple: active Traj1 M Q Traj7 R only |
---|
3078 | if (cdesc <2) return(0); |
---|
3079 | codret = Yactraj(cdesc, cdes); |
---|
3080 | return(codret); |
---|
3081 | } |
---|
3082 | else if (strcmp(cdes[0], "SET_BEGINTIME") == 0 || strcmp(cdes[0], "set_begintime") == 0) |
---|
3083 | { //syntax: set_begintime valeur |
---|
3084 | if (cdesc != 2) return(0); |
---|
3085 | ww1 = atof(cdes[1]); |
---|
3086 | if (ww1<0.0) |
---|
3087 | { printf("set_begintime: bad value given for set_begintime, must not be negativ \n"); |
---|
3088 | return(0); |
---|
3089 | } |
---|
3090 | Ybegintime = ww1; |
---|
3091 | for (w1=0; w1<YNBTRAJ; ++w1) {Yupdcurtime(w1);Yupdstoptime(w1);} |
---|
3092 | } |
---|
3093 | else if (strcmp(cdes[0], "SET_OFFTIME") == 0 || strcmp(cdes[0], "set_offtime") == 0) |
---|
3094 | { //syntax: set_offtime trajname valeur |
---|
3095 | if (cdesc != 3) return(0); |
---|
3096 | ww1 = atof(cdes[2]); |
---|
3097 | if (ww1<0.0) |
---|
3098 | { printf("set_offtime: bad value given for set_offtime, must not be negativ \n"); |
---|
3099 | return(0); |
---|
3100 | } |
---|
3101 | witraj = Yitraj(cdes[1]); |
---|
3102 | if (witraj<0) |
---|
3103 | { printf("set_offtime: unknwon trajectory name (%s) \n", cdes[1]); |
---|
3104 | return(0); |
---|
3105 | } |
---|
3106 | YTabTraj[witraj].offtime = ww1; |
---|
3107 | Yupdcurtime(witraj); Yupdstoptime(witraj); |
---|
3108 | } |
---|
3109 | else if (strcmp(cdes[0], "SET_DTIME") == 0 || strcmp(cdes[0], "set_dtime") == 0) |
---|
3110 | { //syntax: set_dtime trajname valeur |
---|
3111 | if (cdesc != 3) return(0); |
---|
3112 | ww1 = atof(cdes[2]); |
---|
3113 | if (ww1<=0.0) |
---|
3114 | { printf("set_dtime: bad value given for set_dtime, must be greater 0 \n"); |
---|
3115 | return(0); |
---|
3116 | } |
---|
3117 | witraj = Yitraj(cdes[1]); |
---|
3118 | if (witraj<0) |
---|
3119 | { printf("set_dtime: unknwon trajectory name (%s) \n", cdes[1]); |
---|
3120 | return(0); |
---|
3121 | } |
---|
3122 | YTabTraj[witraj].dtime = ww1; |
---|
3123 | Yupdcurtime(witraj);Yupdstoptime(witraj); |
---|
3124 | } |
---|
3125 | else if (strcmp(cdes[0], "PRINT_TIME") == 0 || strcmp(cdes[0], "print_time") == 0) |
---|
3126 | { |
---|
3127 | if (cdesc==1) |
---|
3128 | { printf ("^^^^^^^ CURRENT TRAJ TIME: "); |
---|
3129 | for (w1=0; w1<YNBTRAJ; ++w1) printf ("%s:->%d, ", YTabTraj[w1].name, YTabTraj[w1].toptime); |
---|
3130 | printf("\n"); |
---|
3131 | } |
---|
3132 | else if (strcmp(cdes[1], "ON") == 0 || strcmp(cdes[1], "on") == 0) |
---|
3133 | YDispTime = ON; |
---|
3134 | else |
---|
3135 | YDispTime = OFF; |
---|
3136 | } |
---|
3137 | else if (strcmp(cdes[0], "PRINT_COST") == 0 || strcmp(cdes[0], "print_cost") == 0) |
---|
3138 | { |
---|
3139 | if (cdesc==1) |
---|
3140 | printf ("^^^^^^^ TOTAL COST = % -23.15e \n", YTotalCost); |
---|
3141 | else if (strcmp(cdes[1], "ON") == 0 || strcmp(cdes[1], "on") == 0) |
---|
3142 | YDispCost = ON; //=1 |
---|
3143 | else if (strcmp(cdes[1], "LAST") == 0 || strcmp(cdes[1], "last") == 0) |
---|
3144 | YDispCost = 2; //=2 |
---|
3145 | else |
---|
3146 | YDispCost = OFF; //=0 |
---|
3147 | } |
---|
3148 | else if (strcmp(cdes[0], "COST") == 0 || strcmp(cdes[0], "cost") == 0) |
---|
3149 | { |
---|
3150 | if (cdesc<=1) return(0); |
---|
3151 | if (strcmp(cdes[1], "LMS") == 0 || strcmp(cdes[1], "lms") == 0) |
---|
3152 | { /*syntaxe: cost lms [val] */ |
---|
3153 | if (cdesc<2 || cdesc>3) return(0); |
---|
3154 | if (cdesc==3) |
---|
3155 | { if (!strtod(cdes[2], NULL)) return(0); |
---|
3156 | for(w1=0; w1<YNBMODUL;++w1) |
---|
3157 | YTabMod[w1].scoef = strtod(cdes[2], NULL); |
---|
3158 | } |
---|
3159 | YTypeCost = COST_LMS; |
---|
3160 | return(1); |
---|
3161 | } |
---|
3162 | else if (strcmp(cdes[1], "APPLI") == 0 || strcmp(cdes[1], "appli") == 0) |
---|
3163 | { |
---|
3164 | if (cdesc != 2) return(0); |
---|
3165 | YTypeCost = COST_APPLI; |
---|
3166 | return(1); |
---|
3167 | } |
---|
3168 | return(0); |
---|
3169 | } |
---|
3170 | else if (strcmp(cdes[0], "set_scoef") == 0 || strcmp(cdes[0], "SET_SCOEF") == 0) |
---|
3171 | { /* syntaxe: set_scoef nmmod scoef */ |
---|
3172 | if (cdesc != 3) return(0); |
---|
3173 | YTabMod[Yimod(cdes[1])].scoef = atof(cdes[2]); |
---|
3174 | } |
---|
3175 | else if (strcmp(cdes[0], "set_bcoef") == 0 || strcmp(cdes[0], "SET_BCOEF") == 0) |
---|
3176 | { /* syntaxe: set_bcoef nmmod bcoef */ |
---|
3177 | if (cdesc != 3) return(0); |
---|
3178 | YTabMod[Yimod(cdes[1])].bcoef = atof(cdes[2]); |
---|
3179 | } |
---|
3180 | else if (strcmp(cdes[0], "set_pcoef") == 0 || strcmp(cdes[0], "SET_PCOEF") == 0) |
---|
3181 | { /* syntaxe: set_pcoef nmmod pcoef */ |
---|
3182 | if (cdesc != 3) return(0); |
---|
3183 | YTabMod[Yimod(cdes[1])].pcoef = atof(cdes[2]); |
---|
3184 | } |
---|
3185 | else if (strcmp(cdes[0], "ADJUST") == 0 || strcmp(cdes[0], "adjust") == 0) |
---|
3186 | { |
---|
3187 | if (cdesc!=2) return(0); |
---|
3188 | if (strcmp(cdes[1], "STD") == 0 || strcmp(cdes[1], "std") == 0) |
---|
3189 | YTypeAdjust = ADJUST_STD; |
---|
3190 | else if (strcmp(cdes[1], "APPLI") == 0 || strcmp(cdes[1], "appli") == 0) |
---|
3191 | YTypeAdjust = ADJUST_APPLI; |
---|
3192 | else |
---|
3193 | return(0); |
---|
3194 | return(1); |
---|
3195 | } |
---|
3196 | else if (strcmp(cdes[0], "ECHO") == 0 || strcmp(cdes[0], "echo") == 0) |
---|
3197 | { |
---|
3198 | if (cdesc != 2) return(0); |
---|
3199 | if (strcmp(cdes[1], "ON") == 0 || strcmp(cdes[1], "on") == 0) |
---|
3200 | YEcho = ON; |
---|
3201 | if (strcmp(cdes[1], "OFF") == 0 || strcmp(cdes[1], "off") == 0) |
---|
3202 | YEcho = OFF; |
---|
3203 | } |
---|
3204 | else if (strcmp(cdes[0], "SETM_DXMIN") == 0 || strcmp(cdes[0], "setm_dxmin") == 0) |
---|
3205 | { |
---|
3206 | #ifdef YO_M1QN3 |
---|
3207 | if (cdesc==2) /* si 1 parametre est passed on considere qu'il */ |
---|
3208 | Y3dxmin[0] = atof(cdes[1]); /* s'agit du scalaire dxmin pour m1qn3 */ |
---|
3209 | else if (cdesc == 1) |
---|
3210 | { |
---|
3211 | #ifdef YO_M2QN1 /* si aucun parametre, on considere, a condition*/ |
---|
3212 | Y3valdxmin_all(); /* d'avoir M1QN2, que c'est un vecteur qu'il faut utiliser */ |
---|
3213 | #else |
---|
3214 | printf("setm_dxmin: m2qn1 (via o_m1qn3) option is not active \n"); |
---|
3215 | return(0); |
---|
3216 | #endif |
---|
3217 | } |
---|
3218 | #else |
---|
3219 | { printf("setm_dxmin: m1qn3 option is not active \n"); |
---|
3220 | return(0); |
---|
3221 | } |
---|
3222 | #endif |
---|
3223 | } |
---|
3224 | else if (strcmp(cdes[0], "SETM_DDF1") == 0 || strcmp(cdes[0], "setm_ddf1") == 0) |
---|
3225 | { |
---|
3226 | #ifdef YO_M1QN3 |
---|
3227 | if (cdesc != 2) return(0); |
---|
3228 | Y3ddf1 = atof(cdes[1]); |
---|
3229 | #else |
---|
3230 | printf("setm_ddf1: m1qn3 option is not active \n"); |
---|
3231 | return(0); |
---|
3232 | #endif |
---|
3233 | } |
---|
3234 | else if (strcmp(cdes[0], "SETM_EPSG") == 0 || strcmp(cdes[0], "setm_epsg") == 0) |
---|
3235 | { |
---|
3236 | #ifdef YO_M1QN3 |
---|
3237 | if (cdesc != 2) return(0); |
---|
3238 | Y3epsg = atof(cdes[1]); |
---|
3239 | #else |
---|
3240 | printf("setm_epsg: m1qn3 option is not active \n"); |
---|
3241 | return(0); |
---|
3242 | #endif |
---|
3243 | } |
---|
3244 | else if (strcmp(cdes[0], "SETM_IMPRES") == 0 || strcmp(cdes[0], "setm_impres") == 0) |
---|
3245 | { |
---|
3246 | #ifdef YO_M1QN3 |
---|
3247 | if (cdesc != 2) return(0); |
---|
3248 | Y3impres = atol(cdes[1]); |
---|
3249 | #else |
---|
3250 | printf("setm_impres: m1qn3 option is not active \n"); |
---|
3251 | return(0); |
---|
3252 | #endif |
---|
3253 | } |
---|
3254 | else if (strcmp(cdes[0], "SETM_IO") == 0 || strcmp(cdes[0], "setm_io") == 0) |
---|
3255 | { |
---|
3256 | #ifdef YO_M1QN3 |
---|
3257 | if (cdesc != 2) return(0); |
---|
3258 | Y3io = atol(cdes[1]); |
---|
3259 | #else |
---|
3260 | printf("setm_io: m1qn3 option is not active \n"); |
---|
3261 | return(0); |
---|
3262 | #endif |
---|
3263 | } |
---|
3264 | else if (strcmp(cdes[0], "SETM_MODE") == 0 || strcmp(cdes[0], "setm_mode") == 0) |
---|
3265 | { |
---|
3266 | #ifdef YO_M1QN3 |
---|
3267 | if (cdesc != 2) return(0); |
---|
3268 | Y3mode = atol(cdes[1]); |
---|
3269 | #else |
---|
3270 | printf("setm_mode: m1qn3 option is not active \n"); |
---|
3271 | return(0); |
---|
3272 | #endif |
---|
3273 | } |
---|
3274 | else if (strcmp(cdes[0], "SETM_NSIM") == 0 || strcmp(cdes[0], "setm_nsim") == 0) |
---|
3275 | { |
---|
3276 | #ifdef YO_M1QN3 |
---|
3277 | if (cdesc != 2) return(0); |
---|
3278 | Y3nsim = atol(cdes[1]); |
---|
3279 | #else |
---|
3280 | printf("setm_nsim: m1qn3 option is not active \n"); |
---|
3281 | return(0); |
---|
3282 | #endif |
---|
3283 | } |
---|
3284 | else if (strcmp(cdes[0], "SETM_XINF") == 0 || strcmp(cdes[0], "setm_xinf") == 0) |
---|
3285 | { |
---|
3286 | #ifdef YO_M2QN1 |
---|
3287 | Y3valxinf_all(); |
---|
3288 | #else |
---|
3289 | printf("setm_xinf: m2qn1 (via o_m1qn3) option is not active \n"); |
---|
3290 | return(0); |
---|
3291 | #endif |
---|
3292 | } |
---|
3293 | else if (strcmp(cdes[0], "SETM_XSUP") == 0 || strcmp(cdes[0], "setm_xsup") == 0) |
---|
3294 | { |
---|
3295 | #ifdef YO_M2QN1 |
---|
3296 | Y3valxsup_all(); |
---|
3297 | #else |
---|
3298 | printf("setm_xsup: m2qn1 (via o_m1qn3) option is not active \n"); |
---|
3299 | return(0); |
---|
3300 | #endif |
---|
3301 | } |
---|
3302 | else if (strcmp(cdes[0], "RUNM") == 0 || strcmp(cdes[0], "runm") == 0 |
---|
3303 | || strcmp(cdes[0], "RUNM2")== 0 || strcmp(cdes[0], "runm2")== 0) |
---|
3304 | { |
---|
3305 | #ifndef YO_M1QN3 |
---|
3306 | printf("runm(2): m1qn3 option is not active \n"); |
---|
3307 | return(0); |
---|
3308 | #endif |
---|
3309 | #ifndef YO_M2QN1 |
---|
3310 | if (strcmp(cdes[0], "RUNM2") == 0 || strcmp(cdes[0], "runm2") == 0) |
---|
3311 | { printf("runm2: m2qn1 (via o_m1qn3) option is not active \n"); |
---|
3312 | return(0); |
---|
3313 | } |
---|
3314 | #endif |
---|
3315 | |
---|
3316 | #ifdef YO_M1QN3 |
---|
3317 | if (YNbItRun<=0) |
---|
3318 | { printf("runm(2): number of run iteration not seted; use set_nbiter please\n"); |
---|
3319 | return(0); |
---|
3320 | } |
---|
3321 | if (Y3ddf1<=0) |
---|
3322 | { printf("runm(2): expected positive fcost decrease missed; use setm_ddf1\n"); |
---|
3323 | return(0); |
---|
3324 | } |
---|
3325 | if (YioInsertObsCtr<0) |
---|
3326 | printf("runm(2): warning : oh oh, run with no obs !!! \n"); |
---|
3327 | |
---|
3328 | YTypeAdjust = ADJUST_M1QN3; //d'office avec M1QN3 |
---|
3329 | if (strcmp(cdes[0], "RUNM") == 0 || strcmp(cdes[0], "runm") == 0) |
---|
3330 | return(Y3run ('0')); |
---|
3331 | else |
---|
3332 | return(Y3run ('2')); |
---|
3333 | #endif |
---|
3334 | } |
---|
3335 | else if (strcmp(cdes[0], "RUNIM") == 0 || strcmp(cdes[0], "runim") == 0 |
---|
3336 | || strcmp(cdes[0], "RUNIM2")== 0 || strcmp(cdes[0], "runim2")== 0) |
---|
3337 | { |
---|
3338 | #ifndef YO_M1QN3 |
---|
3339 | printf("runim(2): m1qn3 option is not active \n"); |
---|
3340 | return(0); |
---|
3341 | #endif |
---|
3342 | #ifndef YO_VARINCR |
---|
3343 | printf("runim(2): incremental option (O_VARINCR) is not active \n"); |
---|
3344 | return(0); |
---|
3345 | #endif |
---|
3346 | #ifndef YO_M2QN1 |
---|
3347 | if (strcmp(cdes[0], "RUNIM2") == 0 || strcmp(cdes[0], "runim2") == 0) |
---|
3348 | { printf("runim2: m2qn1 (via o_m1qn3) option is not active \n"); |
---|
3349 | return(0); |
---|
3350 | } |
---|
3351 | #endif |
---|
3352 | /* - - - - - - - - - - - - - - */ |
---|
3353 | #ifdef YO_M1QN3 |
---|
3354 | #ifdef YO_VARINCR |
---|
3355 | if (YNbItRun<=0) |
---|
3356 | { printf("runim(2): number of run iteration not seted; use set_nbiter please\n"); |
---|
3357 | return(0); |
---|
3358 | } |
---|
3359 | if (Y3ddf1<=0) |
---|
3360 | { printf("runim(2): expected positive fcost decrease missed; use setm_ddf1\n"); |
---|
3361 | return(0); |
---|
3362 | } |
---|
3363 | if (YNbExtL<=0) |
---|
3364 | { printf("runim(2): number of extern loop not seted; use set_nbextl please\n"); |
---|
3365 | return(0); |
---|
3366 | } |
---|
3367 | if (YioInsertObsCtr<0) |
---|
3368 | printf("runim(2): warning : oh oh, run with no obs !!! \n"); |
---|
3369 | |
---|
3370 | YTypeAdjust = ADJUST_M1QN3; //d'office avec M1QN3 |
---|
3371 | if (strcmp(cdes[0], "RUNIM") == 0 || strcmp(cdes[0], "runim") == 0) |
---|
3372 | return(Yc3_run ('0')); |
---|
3373 | else |
---|
3374 | return(Yc3_run ('2')); |
---|
3375 | #endif |
---|
3376 | #endif |
---|
3377 | } |
---|
3378 | else if (strcmp(cdes[0], "LTRAJ") == 0 || strcmp(cdes[0], "ltraj") == 0) |
---|
3379 | { Yltraj(); |
---|
3380 | } |
---|
3381 | else if (strcmp(cdes[0], "LSPACE") == 0 || strcmp(cdes[0], "lspace") == 0) |
---|
3382 | { Ylspace(); |
---|
3383 | } |
---|
3384 | else if (strcmp(cdes[0], "LOPERA") == 0 || strcmp(cdes[0], "lopera") == 0) |
---|
3385 | { Ylopera(); |
---|
3386 | } |
---|
3387 | else if (strcmp(cdes[0], "NMOD") == 0 || strcmp(cdes[0], "nmod") == 0) |
---|
3388 | { if (cdesc != 2) return(0); |
---|
3389 | printf("^^^^^^^ %i est le numero du module %s \n", Yimod(cdes[1])+1, cdes[1]); |
---|
3390 | } |
---|
3391 | else if (strcmp(cdes[0], "LMOD") == 0 || strcmp(cdes[0], "lmod") == 0) |
---|
3392 | { Ylmod(cdesc, cdes); |
---|
3393 | } |
---|
3394 | else if (strcmp(cdes[0], "LMOCOP") == 0 || strcmp(cdes[0], "lmocop") == 0) |
---|
3395 | { Ylmocop(); |
---|
3396 | } |
---|
3397 | else if (strcmp(cdes[0], "NNET") == 0 || strcmp(cdes[0], "nnet") == 0) |
---|
3398 | { |
---|
3399 | #ifdef YO_NETWARD |
---|
3400 | if (cdesc != 2) {printf("nnet: syntax is nnet name\n"); return(0);} |
---|
3401 | printf("^^^^^^^ %i est le numero du reseau %s \n", Yinet(cdes[1])+1, cdes[1]); |
---|
3402 | #else |
---|
3403 | printf("nnet: netward option is not active \n"); |
---|
3404 | return(0); |
---|
3405 | #endif |
---|
3406 | } |
---|
3407 | else if (strcmp(cdes[0], "LNET") == 0 || strcmp(cdes[0], "lnet") == 0) |
---|
3408 | { |
---|
3409 | #ifdef YO_NETWARD |
---|
3410 | Ylnet(); |
---|
3411 | #else |
---|
3412 | printf("nnet: netward option is not active \n"); |
---|
3413 | return(0); |
---|
3414 | #endif |
---|
3415 | } |
---|
3416 | else if (strcmp(cdes[0], "SAVESTATE") == 0 || strcmp(cdes[0], "savestate") == 0) |
---|
3417 | { /* syntaxe: [0] [1] [2] [3] [4] [5] [6] [7] |
---|
3418 | savestate objname s(ortie) oaxis pdt {a(scii), b(inaire)} {0, 1, 2, 3} [filename] */ |
---|
3419 | if (cdesc < 7) |
---|
3420 | { printf("savestate: syntax error: savestate objname numout oaxis pdt {A, B} {0, 1, 2, 3} [filename]\n"); |
---|
3421 | return(0); |
---|
3422 | } |
---|
3423 | |
---|
3424 | YioModulot = OFF; |
---|
3425 | if (cdes[4][strlen(cdes[4])-1] == '%') |
---|
3426 | { YioModulot = ON; |
---|
3427 | } |
---|
3428 | |
---|
3429 | //if (atoi(cdes[4])<0 || atoi(cdes[4])>YNBALLTIME) |
---|
3430 | if (atoi(cdes[4])<0) //pdt |
---|
3431 | { // les pas de temps vont de 1 a YNBALLTIME, |
---|
3432 | // et 0:=> tous les pas de temps (pour les modules temporise) |
---|
3433 | //printf("savestate: out of time, must be 0 (for all) or in [1, %i]\n", YNBALLTIME); |
---|
3434 | printf("savestate: out of time, must be 0 (for all) or greater\n"); |
---|
3435 | return(0); |
---|
3436 | } //test refait dans Yio_savestate, car il faut apprecier nballtime selon la trajectoire |
---|
3437 | |
---|
3438 | YioWrite = ON; /*=>*/ YioRead = OFF; /* on s'apprete a ecrire */ |
---|
3439 | |
---|
3440 | YioState = atoi(cdes[2]); /* si 0 alors tous les states sinon, que celle demandee */ |
---|
3441 | |
---|
3442 | YioAscii=YioBin=OFF; |
---|
3443 | if (cdes[5][0]=='a' || cdes[5][0]=='A') YioAscii=ON; |
---|
3444 | else if (cdes[5][0]=='b' || cdes[5][0]=='B') YioBin =ON; |
---|
3445 | |
---|
3446 | YioAxes=YioTime=OFF; |
---|
3447 | if (cdes[6][0]=='1') YioAxes=ON; |
---|
3448 | else if (cdes[6][0]=='2') YioTime=ON; |
---|
3449 | else if (cdes[6][0]=='3') {YioAxes=ON; YioTime=ON;} |
---|
3450 | |
---|
3451 | if (cdesc==7) |
---|
3452 | { if (YioBin) |
---|
3453 | { printf("savestate: only ascii coding allowed if no file provided\n"); |
---|
3454 | return(0); |
---|
3455 | } |
---|
3456 | codret = Yio_savestate(cdes[1], cdes[3], atoi(cdes[4]), "stdout"); |
---|
3457 | } |
---|
3458 | else if (cdesc==8) |
---|
3459 | codret = Yio_savestate(cdes[1], cdes[3], atoi(cdes[4]), cdes[7]); |
---|
3460 | else |
---|
3461 | { printf("savestate: syntax error\n"); |
---|
3462 | return(0); |
---|
3463 | } |
---|
3464 | return(codret); |
---|
3465 | } |
---|
3466 | else if ( strcmp(cdes[0], "LOADSTATE") == 0 || strcmp(cdes[0], "loadstate") == 0 |
---|
3467 | || strcmp(cdes[0], "LOADOBS") == 0 || strcmp(cdes[0], "loadobs") == 0) |
---|
3468 | { /* syntaxe: [0] [1] [2] [3] [4] [5] [6] [7] [8] |
---|
3469 | load... nmmod s(ortie) oaxis pdt {a(scii), b(inaire)} {0, 1} nmfile {f(loat), d(ouble) |
---|
3470 | cas YioAxes ----- cas non YioAxes ----- |
---|
3471 | di dj dk Di di Dj dj Dk dk |
---|
3472 | [9] [10] [11] [9] [10] [11] [12] [13] [14] |
---|
3473 | */ |
---|
3474 | if (cdesc < 9) |
---|
3475 | { printf("%s: syntax error #1\n", cdes[0]); |
---|
3476 | return(0); |
---|
3477 | } |
---|
3478 | //if (atoi(cdes[4])<0 || atoi(cdes[4])>YNBALLTIME) |
---|
3479 | if (atoi(cdes[4])<0) |
---|
3480 | { /* les pas de temps vont de 1 a YNBALLTIME, |
---|
3481 | et 0:=> tous les pas de temps (pour les modules temporise) */ |
---|
3482 | //printf("%s: out of time, must be 0 (for all) or in [1, %i]\n", cdes[0], YNBALLTIME); |
---|
3483 | printf("%s: out of time, must be 0 (for all) or greater\n", cdes[0]); |
---|
3484 | return(0); |
---|
3485 | } |
---|
3486 | |
---|
3487 | YioWrite = OFF; /*=>*/ YioRead = ON; /* on s'apprete a lire */ |
---|
3488 | |
---|
3489 | YioState = atoi(cdes[2]); /* si 0 alors tous les states sinon, que celle demandee */ |
---|
3490 | |
---|
3491 | YioAscii=YioBin=OFF; |
---|
3492 | if (cdes[5][0]=='a' || cdes[5][0]=='A') YioAscii=ON; |
---|
3493 | else if (cdes[5][0]=='b' || cdes[5][0]=='B') YioBin =ON; |
---|
3494 | else |
---|
3495 | { printf("%s: error on coding type, must be A for ascii or B fo Binary\n", cdes[0]); |
---|
3496 | return(0); |
---|
3497 | } |
---|
3498 | |
---|
3499 | YioAxes=OFF; |
---|
3500 | if (cdes[6][0]=='1') YioAxes=ON; |
---|
3501 | |
---|
3502 | YioTime=OFF; |
---|
3503 | if (cdes[4][0]=='0') YioTime=ON; |
---|
3504 | |
---|
3505 | if (cdes[8][0]=='f' || cdes[8][0]=='F') YioszReal=sizeof(float); |
---|
3506 | else if (cdes[8][0]=='d' || cdes[8][0]=='D') YioszReal=sizeof(double); |
---|
3507 | else |
---|
3508 | { printf("%s: error on real type, must be F for float or D for double\n", cdes[0]); |
---|
3509 | return(0); |
---|
3510 | } |
---|
3511 | |
---|
3512 | /* prise en compte eventuelle d'un décalage */ |
---|
3513 | //was: YioDi=YA1; #ifdef YA2 YioDj=YA2; #endif #ifdef YA3 YioDk=YA3; #endif |
---|
3514 | /* multi : |
---|
3515 | if (cdes[1][0] != '*') |
---|
3516 | { wimod = Yimod(cdes[1]); |
---|
3517 | if (wimod<0) |
---|
3518 | { printf("%s: unknwon modul name (%s) \n", cdes[0], cdes[1]); |
---|
3519 | return(0); |
---|
3520 | } |
---|
3521 | YioDi=YTabMod[wimod].axi; YioDj=YTabMod[wimod].axj;YioDk=YTabMod[wimod].axk; |
---|
3522 | }*/ |
---|
3523 | YioDi=YioDj=YioDk=0; /* multi: lors du load on positonnera ces valeurs selon le module |
---|
3524 | dans la mesure ou le user ne les aura pas valoriseed */ |
---|
3525 | Yiodi=Yiodj=Yiodk=0; |
---|
3526 | if (!YioAxes) /* Di di Dj dj Dk dk */ |
---|
3527 | { /* [9] [10] [11] [12] [13] [14] */ |
---|
3528 | if (cdesc==10 || cdesc==12 || cdesc==14 || cdesc>15) |
---|
3529 | { printf("%s: syntax error #2\n", cdes[0]); |
---|
3530 | return(0); |
---|
3531 | } |
---|
3532 | if (cdesc>10) |
---|
3533 | { YioDi=atoi(cdes[9]); Yiodi=atoi(cdes[10]);} |
---|
3534 | if (cdesc>12) |
---|
3535 | { YioDj=atoi(cdes[11]); Yiodj=atoi(cdes[12]);} |
---|
3536 | if (cdesc>14) |
---|
3537 | { YioDk=atoi(cdes[13]); Yiodk=atoi(cdes[14]);} |
---|
3538 | } |
---|
3539 | else /*(YioAxes : di dj dk */ |
---|
3540 | { /* [9] [10] [11] */ |
---|
3541 | if (cdesc>12) |
---|
3542 | { printf("%s: syntax error #3\n", cdes[0]); |
---|
3543 | return(0); |
---|
3544 | } |
---|
3545 | if (cdesc>9) |
---|
3546 | { Yiodi=atoi(cdes[9]);} |
---|
3547 | if (cdesc>10) |
---|
3548 | { Yiodj=atoi(cdes[10]);} |
---|
3549 | if (cdesc>11) |
---|
3550 | { Yiodk=atoi(cdes[11]);} |
---|
3551 | } |
---|
3552 | |
---|
3553 | if (strcmp(cdes[0], "LOADSTATE") == 0 || strcmp(cdes[0], "loadstate") == 0) |
---|
3554 | { codret = Yio_load(YIO_LOADSTATE, cdes[1], cdes[3], atoi(cdes[4]), cdes[7]); |
---|
3555 | } |
---|
3556 | else if (strcmp(cdes[0], "LOADOBS") == 0 || strcmp(cdes[0], "loadobs") == 0) |
---|
3557 | { codret = Yio_load(YIO_LOADOBS, cdes[1], cdes[3], atoi(cdes[4]), cdes[7]); |
---|
3558 | } |
---|
3559 | return(codret); |
---|
3560 | } |
---|
3561 | else if ( !strcmp(cdes[0], "OUTOOBS") || !strcmp(cdes[0], "outoobs") |
---|
3562 | || !strcmp(cdes[0], "OUTOEBX") || !strcmp(cdes[0], "outoebx") ) |
---|
3563 | { /* syntaxe: [0] [1] [2] [3] [4] ... |
---|
3564 | outoobs nmmod s(ortie) pdt1 pdt2 ... |
---|
3565 | outoebx nmmod s(ortie) pdt1 pdt2 ... */ |
---|
3566 | if (cdesc < 4) |
---|
3567 | { printf("%s: syntax error, argument missing\n", cdes[0]); |
---|
3568 | return(0); |
---|
3569 | } |
---|
3570 | |
---|
3571 | if (strcmp(cdes[0], "OUTOOBS") == 0 || strcmp(cdes[0], "outoobs") == 0) |
---|
3572 | { codret = Youtoobs(YIO_OUTOOBS, cdesc, cdes); |
---|
3573 | } |
---|
3574 | else if (strcmp(cdes[0], "OUTOEBX") == 0 || strcmp(cdes[0], "outoebx") == 0) |
---|
3575 | { codret = Youtoobs(YIO_OUTOEBX, cdesc, cdes); |
---|
3576 | } |
---|
3577 | return(codret); |
---|
3578 | } |
---|
3579 | else if (strcmp(cdes[0], "lobs") == 0 || strcmp(cdes[0], "LOBS") == 0) |
---|
3580 | { /* syntaxe: lobs [trajname] */ |
---|
3581 | if (cdesc >2) return(0); |
---|
3582 | if (cdesc==1) Ylistobs(YNBTRAJ); |
---|
3583 | else |
---|
3584 | { w1 = Yitraj(cdes[1]); |
---|
3585 | if (w1<0) |
---|
3586 | { printf ("lobs %s: unknwon trajectorie name \n", cdes[1]); |
---|
3587 | return(0); |
---|
3588 | } |
---|
3589 | Ylistobs(w1); |
---|
3590 | } |
---|
3591 | } |
---|
3592 | else if (strcmp(cdes[0], "setn_psig") == 0 || strcmp(cdes[0], "SETN_PSIG") == 0) |
---|
3593 | { |
---|
3594 | #ifdef YO_NETWARD |
---|
3595 | /* syntaxe: setn_psig mx dmin scale offset */ |
---|
3596 | if (cdesc != 5) return(0); |
---|
3597 | Ynet_setpsig(atof(cdes[1]), atof(cdes[2]), atof(cdes[3]), atof(cdes[4])); |
---|
3598 | #else |
---|
3599 | printf("netward option is not active \n"); |
---|
3600 | return(0); |
---|
3601 | #endif |
---|
3602 | } |
---|
3603 | else if (strcmp(cdes[0], "setn_plin") == 0 || strcmp(cdes[0], "SETN_PLIN") == 0) |
---|
3604 | { |
---|
3605 | #ifdef YO_NETWARD |
---|
3606 | /* syntaxe: setn_plin dmin dmax th */ |
---|
3607 | if (cdesc != 4) return(0); |
---|
3608 | Ynet_setplin(atof(cdes[1]), atof(cdes[2]), atof(cdes[3])); |
---|
3609 | #else |
---|
3610 | printf("netward option is not active \n"); |
---|
3611 | return(0); |
---|
3612 | #endif |
---|
3613 | } |
---|
3614 | else if (strcmp(cdes[0], "setn_activ") == 0 || strcmp(cdes[0], "SETN_ACTIV") == 0) |
---|
3615 | { |
---|
3616 | #ifdef YO_NETWARD |
---|
3617 | /* syntaxe: setn_activ nmnet {siglin sigsig} */ |
---|
3618 | if (cdesc != 3) return(0); |
---|
3619 | if (Yinet(cdes[1])<0) |
---|
3620 | { printf("setn_activ: bad netward name\n"); return(0); |
---|
3621 | } |
---|
3622 | if (strcmp(cdes[2],"siglin")==0 || strcmp(cdes[2],"SIGLIN")==0) |
---|
3623 | YTabNet[Yinet(cdes[1])].activ = SigLin; |
---|
3624 | else if (strcmp(cdes[2],"sigsig")==0 || strcmp(cdes[2],"SIGSIG")==0) |
---|
3625 | YTabNet[Yinet(cdes[1])].activ = SigSig; |
---|
3626 | else |
---|
3627 | { printf("setn_activ: bad function name\n"); return(0); |
---|
3628 | } |
---|
3629 | #else |
---|
3630 | printf("netward option is not active \n"); |
---|
3631 | return(0); |
---|
3632 | #endif |
---|
3633 | } |
---|
3634 | else if (strcmp(cdes[0], "dispn_plin") == 0 || strcmp(cdes[0], "DISPN_PLIN") == 0) |
---|
3635 | { |
---|
3636 | #ifdef YO_NETWARD |
---|
3637 | Ynet_displin(); |
---|
3638 | #else |
---|
3639 | printf("netward option is not active \n"); |
---|
3640 | return(0); |
---|
3641 | #endif |
---|
3642 | } |
---|
3643 | else if (strcmp(cdes[0], "dispn_psig") == 0 || strcmp(cdes[0], "DISPN_PSIG") == 0) |
---|
3644 | { |
---|
3645 | #ifdef YO_NETWARD |
---|
3646 | Ynet_dispsig(); |
---|
3647 | #else |
---|
3648 | printf("netward option is not active \n"); |
---|
3649 | return(0); |
---|
3650 | #endif |
---|
3651 | } |
---|
3652 | else if (strcmp(cdes[0], "set_prompt") == 0 || strcmp(cdes[0], "SET_PROMPT") == 0) |
---|
3653 | { |
---|
3654 | if (cdesc==2) |
---|
3655 | strncpy(YPrompt, cdes[1], STRSIZE20); |
---|
3656 | else |
---|
3657 | YPrompt[0]='\0'; |
---|
3658 | } |
---|
3659 | else if (strcmp(cdes[0], "SET_IOSEP") == 0 || strcmp(cdes[0], "set_iosep") == 0) |
---|
3660 | { |
---|
3661 | /*if (cdesc==1) |
---|
3662 | { YioSep[0]='\0'; |
---|
3663 | return(1); |
---|
3664 | } |
---|
3665 | if (cdesc!=2) |
---|
3666 | { printf("set_iosep: need no more than a single string parameter\n"); icicicici |
---|
3667 | return(0); |
---|
3668 | } |
---|
3669 | if (cdes[1][0]!='"' || cdes[1][strlen(cdes[1])-1]!='"') |
---|
3670 | { printf("set_iosep: string parameter must be delimited by \"\n"); |
---|
3671 | return(0); |
---|
3672 | } |
---|
3673 | strcpy(YioSep, cdes[1]);*/ |
---|
3674 | if (cdesc==2) |
---|
3675 | { //strncpy(YioSep, cdes[1], STRSIZE20); |
---|
3676 | //on va copier caractere par caractere jusqu'à STRSIZE20 maximum |
---|
3677 | //en substituant certains caracteres speciaux (\n, \t, ..?) par leur equivalent |
---|
3678 | w1=w2=0; |
---|
3679 | while (cdes[1][w1]!='\0' && w1<STRSIZE20) |
---|
3680 | { if (cdes[1][w1]=='\\') |
---|
3681 | { if (cdes[1][w1+1]=='n') {YioSep[w2]='\n'; w1+=2; ++w2; continue;} //new line |
---|
3682 | else if (cdes[1][w1+1]=='t') {YioSep[w2]='\t'; w1+=2; ++w2; continue;} //horizontal tab |
---|
3683 | //...??? cf .../UDEV/specar.c |
---|
3684 | } |
---|
3685 | YioSep[w2]=cdes[1][w1]; ++w1; ++w2; |
---|
3686 | } |
---|
3687 | } |
---|
3688 | else |
---|
3689 | YioSep[0]='\0'; |
---|
3690 | } |
---|
3691 | else if (strcmp(cdes[0], "LOAD_INST") == 0 || strcmp(cdes[0], "load_inst") == 0) |
---|
3692 | { |
---|
3693 | strcpy(fileinst, cdes[1]); |
---|
3694 | if ((fpinst = fopen(fileinst, "r")) <= 0) |
---|
3695 | { printf ("file %s not found \n", fileinst); |
---|
3696 | return(0); |
---|
3697 | } |
---|
3698 | nbenrlus = 0; |
---|
3699 | ++Yrecurlev; |
---|
3700 | if (!Yload_inst(fpinst, fileinst, &nbenrlus)) // on s'arrete a la 1ere erreur, |
---|
3701 | { for (w1=0; w1<Yrecurlev; ++w1) printf("-"); |
---|
3702 | printf("error found while file %s, line %i. sequence aborted \n", fileinst, nbenrlus); |
---|
3703 | --Yrecurlev; |
---|
3704 | return(0); |
---|
3705 | } |
---|
3706 | --Yrecurlev; |
---|
3707 | return(1); |
---|
3708 | } |
---|
3709 | else if (strcmp(cdes[0], "SAMPLEOF") == 0 || strcmp(cdes[0], "sampleof") == 0) |
---|
3710 | { //syntaxe: sampleof modP Pinf Psup dP modQ Qinf Qsup dQ nmfile |
---|
3711 | if (cdesc != 10) |
---|
3712 | { printf("sampleof: syntax error: sampleof modP Pinf Psup dP modQ Qinf Qsup dQ nmfile\n"); |
---|
3713 | return(0); |
---|
3714 | } |
---|
3715 | YAL2Run=RUNL2_STD; |
---|
3716 | return(Ysampleof(cdes[1], atof(cdes[2]), atof(cdes[3]), atof(cdes[4]), |
---|
3717 | cdes[5], atof(cdes[6]), atof(cdes[7]), atof(cdes[8]), cdes[9])); |
---|
3718 | } |
---|
3719 | else if (strcmp(cdes[0], "SAMPLEOFI") == 0 || strcmp(cdes[0], "sampleofi") == 0) |
---|
3720 | { //syntaxe: sampleofi modP Pinf Psup dP modQ Qinf Qsup dQ nmfile |
---|
3721 | #ifdef YO_VARINCR |
---|
3722 | if (cdesc != 10) |
---|
3723 | { printf("sampleofi: syntax error: sampleofi modP Pinf Psup dP modQ Qinf Qsup dQ nmfile\n"); |
---|
3724 | return(0); |
---|
3725 | } |
---|
3726 | YAL2Run=RUNL2_INCR; |
---|
3727 | return(Ysampleof(cdes[1], atof(cdes[2]), atof(cdes[3]), atof(cdes[4]), |
---|
3728 | cdes[5], atof(cdes[6]), atof(cdes[7]), atof(cdes[8]), cdes[9])); |
---|
3729 | #else |
---|
3730 | printf("incremental option (VARINCR) is not active \n"); |
---|
3731 | return(0); |
---|
3732 | #endif |
---|
3733 | } |
---|
3734 | else if ( strcmp(cdes[0], "HELP") == 0 || strcmp(cdes[0], "help") == 0 |
---|
3735 | || strcmp(cdes[0], "AIDE") == 0 || strcmp(cdes[0], "aide") == 0 || cdes[0][0]=='?' |
---|
3736 | ) |
---|
3737 | { |
---|
3738 | if (cdesc>1) |
---|
3739 | { if (cdes[1][0]=='e' || cdes[1][0]=='E' ) |
---|
3740 | Yhelp('e'); |
---|
3741 | else |
---|
3742 | Yhelp('f'); |
---|
3743 | } |
---|
3744 | else |
---|
3745 | Yhelp('f'); |
---|
3746 | } |
---|
3747 | else if (!strcmp(cdes[0], "setstate") || !strcmp(cdes[0], "SETSTATE")) |
---|
3748 | { if (cdesc!=3) return(0); |
---|
3749 | if (Yimod(cdes[1])<0) |
---|
3750 | { printf("setstate: unknown modul %s \n", cdes[1]); |
---|
3751 | return (0); |
---|
3752 | } |
---|
3753 | return(Ysetstate_mod(cdes[1], atof(cdes[2]))); |
---|
3754 | } |
---|
3755 | else if (!strcmp(cdes[0], "setstate_all") || !strcmp(cdes[0], "SETSTATE_ALL")) |
---|
3756 | { if (cdesc!=3) return(0); |
---|
3757 | return(Ysetstate_mod("Y#A", atof(cdes[1]))); |
---|
3758 | } |
---|
3759 | else if (strcmp(cdes[0], "PAUSE") == 0 || strcmp(cdes[0], "pause") == 0) |
---|
3760 | { getchar(); |
---|
3761 | } |
---|
3762 | else if (strcmp(cdes[0], "YBID") == 0 || strcmp(cdes[0], "ybid") == 0) |
---|
3763 | { |
---|
3764 | // Ytryrov(); |
---|
3765 | } |
---|
3766 | else /* sinon il peut s'agit d'une auto ou d'une user fonction */ |
---|
3767 | if (!Yauto_call(cdesc, cdes)) |
---|
3768 | if (!Yuser_call(cdesc, cdes)) |
---|
3769 | codret = 0; |
---|
3770 | |
---|
3771 | return(codret); |
---|
3772 | } |
---|
3773 | |
---|
3774 | /* //////////////////////////////////////////////////////////////////////////////// |
---|
3775 | ///////////////////////////// fin fichier Yao.cpp ///////////////////////////////// |
---|
3776 | //////////////////////////////////////////////////////////////////////////////// */ |
---|
3777 | |
---|