/* MUKPO3.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"

/* Table of constant values */

static integer c__1 = 1;

/* Subroutine */ int mmukpo3_(ndimax, npoint, xyztab, ndim, uktab, distot, 
	iercod)
integer *ndimax, *npoint;
doublereal *xyztab;
integer *ndim;
doublereal *uktab, *distot;
integer *iercod;
{
    /* Format strings */
    static char fmt_10001[] = "(1x,\002!!! Mauvaise repartition des PAL : np\
t=\002,i4,\002/tot=\002,i4)";

    /* System generated locals */
    integer xyztab_dim1, xyztab_offset, i__1;

    /* Builtin functions */
    integer s__wsfe(), do__fio(), e__wsfe();

    /* Local variables */
    static logical idbg;
    static doublereal dist;
    static integer i__;
    static doublereal dsmax;
    extern /* Subroutine */ int mmeps1_();
/*    static integer ji, ibb, imp;*/
    static integer ibb, imp;
    extern integer mnfndeb_();
    extern /* Subroutine */ int maermsg_(), mgenmsg_();
    extern integer mnfnimp_();
    extern /* Subroutine */ int mgsomsg_();
    static doublereal eps1;
    extern /* Subroutine */ int mdsptpt_();
    static doublereal dst0, dst1;

    /* Fortran I/O blocks */
    static cilist io___11 = { 0, 0, 0, fmt_10001, 0 };




/* < */
/* **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 : */
/*     ---------- */
/*     Init. des param. de lissage / absc. curv. reduite sur polygone des 
pt*/

/*     MOTS CLES : */
/*     ----------- */
/*       TOUS , MATH_ACCES :: */
/*      POINTS_A_LISSER& , INITIALISATION , &PARAMETRE,&ABMSCISSE_CURVILIG
NE*/

/*     ARGUMENTS D'ENTREE : */
/*     -------------------- */
/*       NDIMAX: format / Dimension */
/*       NPOINT: Nombre de points a traiter */
/*       XYZTAB: Le tableau des points. */
/*       NDIM  : Dimension utile des points . */

/*     ARGUMENTS DE SORTIE : */
/*     --------------------- */
/*       UKTAB : Le tableau des parametres. */
/*       DISTOT: longueur polygonale totale */
/*       IERCOD: 0 ok  ,-254 distot est trop petit */
/*                       173 Table insuffisamment dimensionnee */

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

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

/*     DESCRIPTION/REMARQUES/LIMITATIONS : */
/*     ----------------------------------- */
/*       . niveau de debug = 3 */

/* $    HISTORIQUE DES MODIFICATIONS : */
/*     ------------------------------ */
/*       .12-10-89 : JG ; INTRO DU DIAG. SUR LA MAUVAISE REPARTITION DES 
*/
/*                        POINTS */
/*       .25-08-89 : JG ; VERSION ORIGINALE */
/* > */
/* ***********************************************************************
 */


/*      DIMENSION PTDIF(NDIMX) */

    /* Parameter adjustments */
    --uktab;
    xyztab_dim1 = *ndimax;
    xyztab_offset = xyztab_dim1 + 1;
    xyztab -= xyztab_offset;

    /* Function Body */
    ibb = mnfndeb_();
    imp = mnfnimp_();
    idbg = ibb >= 3;
    if (idbg) {
	mgenmsg_("MMUKPO3", 7L);
    }
    *iercod = 0;
    mmeps1_(&eps1);
    if (*ndim > 3 || *ndim > *ndimax) {
	goto L9173;
    }

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

    *distot = 0.;
    uktab[1] = 0.;
    i__1 = *npoint;
    for (i__ = 2; i__ <= i__1; ++i__) {

	mdsptpt_(ndim, &xyztab[1 + i__ * xyztab_dim1], &xyztab[1 + (i__ - 1)
		 * xyztab_dim1], &dist);
	*distot += dist;
	uktab[i__] = *distot;

/* L2000: */
    }

    if (*distot <= eps1) {
	goto L9254;
    }

    if (*npoint >= 2 && idbg) {
	dsmax = *distot * 10 / (*npoint - 1);
	dst0 = uktab[2] - uktab[1];
	i__1 = *npoint;
	for (i__ = 2; i__ <= i__1; ++i__) {
	    dst1 = uktab[i__] - uktab[i__ - 1];
	    if (dst1 > dsmax || dst0 > dst1 * 10 || dst1 > dst0 * 10) {
		io___11.ciunit = imp;
		s__wsfe(&io___11);
		do__fio(&c__1, (char *)&i__, (ftnlen)sizeof(integer));
		do__fio(&c__1, (char *)&(*npoint), (ftnlen)sizeof(integer));
		e__wsfe();
	    }
	    dst0 = dst1;
/* L3000: */
	}
    }

    i__1 = *npoint - 1;
    for (i__ = 2; i__ <= i__1; ++i__) {
	uktab[i__] /= *distot;
/* L4000: */
    }

    uktab[*npoint] = 1.;

    goto L9999;

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

L9173:
    *iercod = 173;
    goto L9999;

L9254:
    *iercod = -254;

L9999:
    if (*iercod != 0) {
	maermsg_("MMUKPO3", iercod, 7L);
    }
    if (idbg) {
	mgsomsg_("MMUKPO3", 7L);
    }
    return 0;
} /* mmukpo3_ */

