Exemple of calculation routine CGEC (Avis and Avio gates)

SUBROUTINE CGEC(U,Y,PARA)
    PARAMETER(NBCM=$NBCM)
    DIMENSION Y(*),U(*),PARA(*)
C-----index of the current controller (INURE),
C-----current number of calls of the controller n (INUAP(n))
    COMMON/P1/ILNPS,INURE,INUAP(NBCM),IREGS
    COMMON/P2/INU,INY,INZ,DTU,DTY,DTZ
C-----Equations de Goussard
C-----Affectations
C-----PARA(1) en degres, ALFMAX en radiants
    ALFMAX=PARA(1)*0.01745
C-----Dec est negatif dans la formule de Goussard
    Dec=-PARA(2)
    R=PARA(3)
    HA=PARA(4)
C-----CHUTE > 0 si ca descend vers l'aval
    CHUTE=PARA(5)
C-----On met un filtre d'ordre 1 : S/E = (1-a)Z-1 / 1-aZ-1 (FILTRE = a)
    FILTRE=PARA(6)
C-----Calcul pour cette methode
C-----Y(1) est en tirant d'eau (mode TYS obligatoire sur le fichier .REG)
    Z=Y(1)-CHUTE-HA
C-----Initialisation de Zold au premier appel
    IF(INUAP(INURE).EQ.1) PARA(10)=Z
    Z=FILTRE*PARA(10)+(1.0-FILTRE)*Z
C-----On stocke Zold filtré dans PARA(10) pour le filtre
    PARA(10)=Z
    IF (Z.GE.0.) THEN
        ALFA=0.
    ELSEIF (Z.LE.Dec) THEN
        ALFA=ALFMAX
    ELSE
        ALFA=0.
        IF(Dec.NE.0.) ALFA=SIN(ALFMAX)*Z/Dec
        ALFA=MIN(ALFA,1.)
        ALFA=MAX(ALFA,-1.)
        ALFA=ASIN(ALFA)
    ENDIF
C-----Calcul de U
    ALFB=0.
    IF(R.NE.0.) ALFB=HA/R
    ALFB=MIN(ALFB,1.)
    ALFB=MAX(ALFB,-1.)
    ALFB=ACOS(ALFB)
C-----Calcul de la commande
    U(1)=HA-R*COS(ALFA+ALFB)
C-----Si plusieurs U (SIMO) on duplique la meme ouverture
C-----(interessant dans le cas de plusieurs vannes identiques en parallele
C      en mode V par exemple)
    IF(INU.GT.1) THEN
        DO 10 I=2,INU
            U(I)=U(1)
        10    CONTINUE
    ENDIF
END