C     Working array size calculator
C
C     Copyright (C), Sergei Nikolaev, 1992-2004, sam@cvmlib.com
C

CDEC$ DEFINE DECFTN

      INTEGER*4 FUNCTION NPOLY (M, N)
CDEC$ IF DEFINED (FTN_EXPORTS)
CDEC$     ATTRIBUTES DLLEXPORT::NPOLY
CDEC$ ENDIF
      INTEGER*4 M, N

CDEC$ IF .NOT. DEFINED (DECFTN)
      INTEGER*4   FLOOR, CEILING
      EXTERNAL    FLOOR, CEILING
CDEC$ ENDIF

      NPOLY = 0
      IF (M .GT. 0 .AND. N .GT. 1) THEN
          NPOLY  = (FLOOR (DFLOAT (N - 1) /
     1              DFLOAT (CEILING (DSQRT (DFLOAT (N - 1)))))
     2                                               + 2) * M * M
      ENDIF
      RETURN
      END !FUNCTION NPOLY
