/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: y_stat.c,v 1.2 1997/09/25 18:26:25 ae59 Exp $ */
/*
$Log: y_stat.c,v $
 * Revision 1.2  1997/09/25  18:26:25  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:58  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : y_stat.c                              */
/*                                                              */
/*      Entry           : a_VOID y_stat(d,s,z,dim,e_args)       */
/*                        y_dscp d;                             */
/*                        a_VOID s;                             */
/*                        size_t z;                             */
/*                        a_byte dim;                           */
/*                        e_list                                */
/*                                                              */
/*      Arguments       : d - descriptor of dynamic array       */
/*                        s - static array                      */
/*                        z - size of static array              */
/*                        dim - dimension of static array       */
/*                        ... - list of a_intg pairs lb,ub      */
/*                                                              */
/*      Function value  : address of descriptor of dynamic array*/
/*                                                              */
/*      Description     : copy static array to dynamic array    */
/*                        (descriptor is initialized)           */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : cast to size_t at stride/elnum calc. =b=   */
/*      1991-05-29 : descrtype * replaced by y_dscp             */
/*      1990-12-12 : byte replaced by a_byte                    */
/*      1990-11-22 : E_TPUSH+E_TPOPP                            */
/*      1990-08-10 : consider C_P_7 if LINT_ARGS defined        */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif

#ifdef LINT_ARGS
#if C_P_7
local a_VOID y_stat(y_dscp d,a_VOID s,size_t z,a_byte dim,...)
#else
local a_VOID y_stat(d,s,z,dim,e_args)

y_dscp d;
a_VOID s;
size_t z;
a_byte dim;
e_list
#endif
#else
local a_VOID y_stat(d,s,z,dim,e_args)

y_dscp d;
a_VOID s;
size_t z;
a_byte dim;
e_list
#endif
        {
        int k;        /* !!! must be int !!! */
        va_list e_argv;

        E_TPUSH("y_stat")

        /* destroy-flag must not be TRUE since address of       */
        /* static array is assigned to array-component of       */
        /* dynamic array descriptor                             */
        ((y_desc *)d)->destroy = ((y_desc *)d)->subarr = FALSE;

        ((y_desc *)d)->numdim = dim;
        ((y_desc *)d)->elsize = z;

        /* read lower and upper bounds from argument list       */
        e_open(dim);
        ((y_desc *)d)->fd[0].lbound = e_ref(a_intg);
        ((y_desc *)d)->fd[0].ubound = e_ref(a_intg);
        for (k=1;k<dim;k++)
           {
           ((y_desc *)d)->fd[k].lbound = e_ref(a_intg);
           ((y_desc *)d)->fd[k].ubound = e_ref(a_intg);
           }
        e_shut;

        /* determine stride and number of elements      */
        k = dim-1;
        ((y_desc *)d)->elnum = ((y_desc *)d)->fd[k].stride = 1;
        for (;k>0;k--)
           {
           ((y_desc *)d)->elnum *= (size_t) ((((y_desc *)d)->fd[k].ubound-
                                    ((y_desc *)d)->fd[k].lbound+1));
           ((y_desc *)d)->fd[k-1].stride = ((y_desc *)d)->elnum;
           }
        ((y_desc *)d)->elnum *= (size_t) ((((y_desc *)d)->fd[0].ubound-
                                 ((y_desc *)d)->fd[0].lbound+1));

        /* assign static array to array component       */
        ((y_desc *)d)->array = (char *)s;

        E_TPOPP("y_stat")
        return((char *)d);
        }
