source: altifloat/src/Yworkdir/Yfloater_delta.cpp @ 99

Last change on this file since 99 was 99, checked in by jbrlod, 11 years ago

bug in run_inc corrected

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