/* MVACRI.f -- translated by f2c (version 19960827).
   You must link the resulting object file with the libraries:
	-lf2c -lm   (in that order)
*/

#include "Data_f2c.h"

/* Subroutine */ int mmvacri_(ndimen, ncourb, ncftab, ordher, tabcbr, tdecop, 
	ncoefs, math1, math2, math3, tvcint, iercod)
integer *ndimen, *ncourb, *ncftab, *ordher;
doublereal *tabcbr, *tdecop;
integer *ncoefs;
doublereal *math1, *math2, *math3, *tvcint;
integer *iercod;
{
    /* System generated locals */
/*    integer tabcbr_dim1, tabcbr_dim2, tabcbr_offset, i__1, i__2, i__3, i__4;*/
    integer tabcbr_dim1, tabcbr_dim2, tabcbr_offset, i__1, i__2, i__3;
    doublereal d__1, d__2;

    /* Builtin functions */
    double pow__di();

    /* Local variables */
    static doublereal cteh2, cteh3;
    static integer d__, e, i__, j, l;
    static doublereal mfact;
    static integer order;
    static doublereal mfact1, mfact2, somau1, somau2, somau3, ctenor;
    static integer aux1, aux2, aux3;
    static doublereal som1, som2, som3;



/* < */
/* **NOTICE */
/*  THIS SOFTWARE IS THE PROPERTY OF CISIGRAPH. */
/*  THIS CODE MUST NOT BE DISTRIBUTED OR COPIED WITHOUT THE PRIOR */
/*  WRITTEN PERMISSION OF CISIGRAPH AND IS ONLY TO BE USED ON THE */
/*  SITE WHERE IT IS INSTALLED BY CISIGRAPH */
/* **NOTICE */

/* ***********************************************************************
 */

/*     FONCTION : */
/*     ---------- */
/*       CALCUL LES VALEURS DES CRITERES INTEGRAUX */

/*     MOTS CLES : */
/*     ----------- */
/*      RESERVE, LISSAGE, CALCUL, CRITERES */

/*     ARGUMENTS D'ENTREE : */
/*     -------------------- */
/*       NDIMEN: DIMENSION DE L'ESPACE */
/*       NCOURB: NOMBRE DE COURBES */
/*       ORDHER : ORDRE DES POLYNOMES D'HERMITE (ORDRE DE CONTINUITE) */
/*       NCFTAB : Table des COEFFICIENTS DE chaque COURBE */
/*                POUR UNE DE SES NDIM COMPOSANTS;(DEGRE+1 DE LA COURBE) 
*/
/*       TABCBR : TABLE DES COEFFICIENTS DE LA COURBE POLYNOMIALE PAR */
/*                MORCEAUX */
/*       TDECOP : TABLE DE DECOUPE */
/*       NCOEFS : Nombre maximum de coeef pour formater les tableaux */
/*       MATH1,MATH2,MATH3 : MATRICE DES CRITERES INTEGRAUX POUR UNE */
/*                           COMPOSANTE */
/*     ARGUMENTS DE SORTIE : */
/*     --------------------- */
/*      TVCINT : TABLE DES VALEURS DES CRITERES INTEGRAUX */

/*     COMMONS UTILISES : */
/*     ------------------ */


/*     REFERENCES APPELEES : */
/*     --------------------- */


/*     DESCRIPTION/REMARQUES/LIMITATIONS : */
/*     ----------------------------------- */


/* $    HISTORIQUE DES MODIFICATIONS : */
/*     ------------------------------ */
/*     18-09-95 : KHN/PMN; ECRITURE VERSION ORIGINALE. */
/*     15/01/99 : PMN : On utilise que la partie utile */
/* > */
/* ***********************************************************************
 */
/*                            DECLARATIONS */
/* ***********************************************************************
 */



/* ***********************************************************************
 */
/*                      INITIALISATIONS */
/* ***********************************************************************
 */

    /* Parameter adjustments */
    tvcint -= 4;
    --ncftab;
    --math3;
    --math2;
    --math1;
    tabcbr_dim1 = *ndimen;
    tabcbr_dim2 = *ncoefs;
    tabcbr_offset = tabcbr_dim1 * (tabcbr_dim2 + 1) + 1;
    tabcbr -= tabcbr_offset;

    /* Function Body */
    *iercod = 0;

/* ***********************************************************************
 */
/*                     TRAITEMENT */
/* ***********************************************************************
 */

    aux1 = *ordher + 1;
    aux3 = aux1 + 1;
    aux2 = aux1 << 1;
    i__1 = *ncourb;
    for (e = 1; e <= i__1; ++e) {
	ctenor = (tdecop[e] - tdecop[e - 1]) / 2;
/* Computing 3rd power */
	d__1 = ctenor, d__2 = d__1;
	cteh2 = d__2 * (d__1 * d__1);
/* Computing 2nd power */
	d__1 = ctenor;
	cteh3 = cteh2 * (d__1 * d__1);
	som1 = 0.;
	som2 = 0.;
	som3 = 0.;
	i__2 = *ndimen;
	for (d__ = 1; d__ <= i__2; ++d__) {
	    i__3 = ncftab[e];
	    for (i__ = 1; i__ <= i__3; ++i__) {
		if (i__ <= aux1) {
		    order = i__ - 1;
		} else {
		    if (i__ <= aux2) {
			order = i__ - aux3;
		    } else {
			order = 0;
		    }
		}
		mfact1 = pow__di(&ctenor, &order);
		somau1 = 0.;
		somau2 = 0.;
		somau3 = 0.;
/*		i__4 = *ncoefs; PMN */
		for (j = 1; j <= i__3; ++j) {
		    if (j <= aux1) {
			order = j - 1;
		    } else {
			if (j <= aux2) {
			    order = j - aux3;
			} else {
			    order = 0;
			}
		    }
		    mfact2 = pow__di(&ctenor, &order);
		    mfact = mfact1 * mfact2;
		    if (i__ >= j) {
			l = i__ * (i__ - 1) / 2 + j;
		    } else {
			l = j * (j - 1) / 2 + i__;
		    }
		    somau1 += mfact / ctenor * math1[l] * tabcbr[d__ + (j + e 
			    * tabcbr_dim2) * tabcbr_dim1];
		    somau2 += mfact / cteh2 * math2[l] * tabcbr[d__ + (j + e *
			     tabcbr_dim2) * tabcbr_dim1];
		    somau3 += mfact / cteh3 * math3[l] * tabcbr[d__ + (j + e *
			     tabcbr_dim2) * tabcbr_dim1];
		}
		som1 += somau1 * tabcbr[d__ + (i__ + e * tabcbr_dim2) * 
			tabcbr_dim1];
		som2 += somau2 * tabcbr[d__ + (i__ + e * tabcbr_dim2) * 
			tabcbr_dim1];
		som3 += somau3 * tabcbr[d__ + (i__ + e * tabcbr_dim2) * 
			tabcbr_dim1];
	    }
	}
     /* Le critere peut s'annuler et donc etre negatif a une erreur pres*/ 
        if (som1 < 0) {som1 =0.;}
        if (som2 < 0) {som2 =0.;}
	if (som3 < 0) {som3 =0.;}

	tvcint[e * 3 + 1] = som1;
	tvcint[e * 3 + 2] = som2;
	tvcint[e * 3 + 3] = som3;
    }


    goto L9999;

/* ***********************************************************************
 */
/*                   TRAJTEMENT DES ERREURS */
/* ***********************************************************************
 */


/* ***********************************************************************
 */
/*                   RETOUR PROGRAMME APPELANT */
/* ***********************************************************************
 */

L9999:

 return 0   ;
} /* mmvacri_ */

